From 5dc5d0d07e49934c90570ca0cc84496191c8a05c Mon Sep 17 00:00:00 2001 From: Firas Qutishat Date: Wed, 11 Oct 2023 13:26:33 -0400 Subject: [PATCH] chore: add enable-send-all-credentials to wallet cli Signed-off-by: Firas Qutishat --- component/wallet-cli/README.md | 6 ++++++ component/wallet-cli/cmd/oidc4vp_cmd.go | 6 ++++++ component/wallet-cli/pkg/oidc4vp/oidc4vp_flow.go | 13 +++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/component/wallet-cli/README.md b/component/wallet-cli/README.md index c57e7a9fa..4f010daeb 100644 --- a/component/wallet-cli/README.md +++ b/component/wallet-cli/README.md @@ -139,6 +139,7 @@ To enable HTTP tracing between `wallet-cli` and `vcs`, append the `--enable-trac Use the `oidc4vp` command to present Verifiable Credential to the Verifier: ```bash --enable-linked-domain-verification enables linked domain verification + --enable-send-all-credentials enables send all credentials in wallet --enable-tracing enables http tracing -h, --help help for oidc4vp --leveldb-path string leveldb path @@ -154,6 +155,11 @@ Examples: ./wallet-cli oidc4vp --leveldb-path "/mnt/wallet.db" --qr-code-path "qr.png" --enable-linked-domain-verification ``` +* Present All VC from wallet to the Verifier: +```bash +./wallet-cli oidc4vp --leveldb-path "/mnt/wallet.db" --qr-code-path "qr.png" --enable-send-all-credentials +``` + ## Contributing We appreciate your help! For contributors, please follow our [community contribution guidelines](https://github.com/trustbloc/community/blob/main/CONTRIBUTING.md) to understand our code of conduct and the process for submitting pull requests. diff --git a/component/wallet-cli/cmd/oidc4vp_cmd.go b/component/wallet-cli/cmd/oidc4vp_cmd.go index d9b16cc51..87ca4633f 100644 --- a/component/wallet-cli/cmd/oidc4vp_cmd.go +++ b/component/wallet-cli/cmd/oidc4vp_cmd.go @@ -33,6 +33,7 @@ type oidc4vpCommandFlags struct { qrCodePath string walletDIDIndex int enableLinkedDomainVerification bool + enableSendAllCredInWallet bool enableTracing bool } @@ -145,6 +146,10 @@ func NewOIDC4VPCommand() *cobra.Command { opts = append(opts, oidc4vp.WithLinkedDomainVerification()) } + if flags.enableSendAllCredInWallet { + opts = append(opts, oidc4vp.WithSendAllCredInWallet()) + } + if flow, err = oidc4vp.NewFlow(provider, opts...); err != nil { return err } @@ -168,6 +173,7 @@ func createFlags(cmd *cobra.Command, flags *oidc4vpCommandFlags) { cmd.Flags().StringVar(&flags.qrCodePath, "qr-code-path", "", "path to file with qr code") cmd.Flags().BoolVar(&flags.enableLinkedDomainVerification, "enable-linked-domain-verification", false, "enables linked domain verification") + cmd.Flags().BoolVar(&flags.enableSendAllCredInWallet, "enable-send-all-credentials", false, "enables send all credentials in wallet") cmd.Flags().IntVar(&flags.walletDIDIndex, "wallet-did-index", -1, "index of wallet did, if not set the most recently created DID is used") cmd.Flags().BoolVar(&flags.enableTracing, "enable-tracing", false, "enables http tracing") diff --git a/component/wallet-cli/pkg/oidc4vp/oidc4vp_flow.go b/component/wallet-cli/pkg/oidc4vp/oidc4vp_flow.go index d10f00106..32d51128f 100644 --- a/component/wallet-cli/pkg/oidc4vp/oidc4vp_flow.go +++ b/component/wallet-cli/pkg/oidc4vp/oidc4vp_flow.go @@ -55,6 +55,7 @@ type Flow struct { walletKMSKeyID string requestURI string enableLinkedDomainVerification bool + sendAllCredInWallet bool } type provider interface { @@ -101,6 +102,7 @@ func NewFlow(p provider, opts ...Opt) (*Flow, error) { walletKMSKeyID: walletDIDInfo.KeyID, requestURI: o.requestURI, enableLinkedDomainVerification: o.enableLinkedDomainVerification, + sendAllCredInWallet: o.sendAllCredInWallet, }, nil } @@ -289,7 +291,7 @@ func (f *Flow) sendAuthorizationResponse( presentationSubmission *presexch.PresentationSubmission ) - if len(credentials) == 1 { + if len(credentials) > 1 && !f.sendAllCredInWallet { credential := credentials[0] presentation, err := presentationDefinition.CreateVP( @@ -321,7 +323,7 @@ func (f *Flow) sendAuthorizationResponse( if err != nil { return fmt.Errorf("create vp token: %w", err) } - } else if len(credentials) > 1 { + } else if len(credentials) > 1 && f.sendAllCredInWallet { var ( vpTokens []string presentations []*verifiable.Presentation @@ -633,6 +635,7 @@ type options struct { walletDIDIndex int requestURI string enableLinkedDomainVerification bool + sendAllCredInWallet bool } type Opt func(opts *options) @@ -654,3 +657,9 @@ func WithLinkedDomainVerification() Opt { opts.enableLinkedDomainVerification = true } } + +func WithSendAllCredInWallet() Opt { + return func(opts *options) { + opts.sendAllCredInWallet = true + } +}