From 1aa6b694ec9ac35d496951cc86c5d459edbfb224 Mon Sep 17 00:00:00 2001 From: Bob Stasyszyn Date: Wed, 24 Jan 2024 14:12:12 -0500 Subject: [PATCH] feat: Add option for attestation request in wallet CLI Signed-off-by: Bob Stasyszyn --- .../pkg/attestation/attestation_client.go | 46 +++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/component/wallet-cli/pkg/attestation/attestation_client.go b/component/wallet-cli/pkg/attestation/attestation_client.go index 9823028ce..efaf1c26a 100644 --- a/component/wallet-cli/pkg/attestation/attestation_client.go +++ b/component/wallet-cli/pkg/attestation/attestation_client.go @@ -55,10 +55,28 @@ func NewClient(config *Config) *Client { } } -func (c *Client) GetAttestationVC(ctx context.Context) (*verifiable.Credential, error) { +type options struct { + attestationRequest *AttestWalletInitRequest +} + +type Opt func(*options) + +func WithAttestationRequest(value *AttestWalletInitRequest) Opt { + return func(o *options) { + o.attestationRequest = value + } +} + +func (c *Client) GetAttestationVC(ctx context.Context, opts ...Opt) (*verifiable.Credential, error) { logger.Debug("get attestation vc", zap.String("walletDID", c.walletDID)) - initResp, err := c.attestationInit(ctx) + options := &options{} + + for _, opt := range opts { + opt(options) + } + + initResp, err := c.attestationInit(ctx, options.attestationRequest) if err != nil { return nil, fmt.Errorf("attestation init: %w", err) } @@ -80,19 +98,21 @@ func (c *Client) GetAttestationVC(ctx context.Context) (*verifiable.Credential, return attestationVC, nil } -func (c *Client) attestationInit(ctx context.Context) (*AttestWalletInitResponse, error) { +func (c *Client) attestationInit(ctx context.Context, req *AttestWalletInitRequest) (*AttestWalletInitResponse, error) { logger.Debug("attestation init started", zap.String("walletDID", c.walletDID)) - req := &AttestWalletInitRequest{ - Assertions: []string{ - "wallet_authentication", - }, - WalletAuthentication: map[string]interface{}{ - "wallet_id": c.walletDID, - }, - WalletMetadata: map[string]interface{}{ - "wallet_name": "wallet-cli", - }, + if req == nil { + req = &AttestWalletInitRequest{ + Assertions: []string{ + "wallet_authentication", + }, + WalletAuthentication: map[string]interface{}{ + "wallet_id": c.walletDID, + }, + WalletMetadata: map[string]interface{}{ + "wallet_name": "wallet-cli", + }, + } } body, err := json.Marshal(req)