Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add enable-send-all-credentials to wallet cli #1469

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions component/wallet-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions component/wallet-cli/cmd/oidc4vp_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type oidc4vpCommandFlags struct {
qrCodePath string
walletDIDIndex int
enableLinkedDomainVerification bool
enableSendAllCredInWallet bool
enableTracing bool
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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")
Expand Down
13 changes: 11 additions & 2 deletions component/wallet-cli/pkg/oidc4vp/oidc4vp_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type Flow struct {
walletKMSKeyID string
requestURI string
enableLinkedDomainVerification bool
sendAllCredInWallet bool
}

type provider interface {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -633,6 +635,7 @@ type options struct {
walletDIDIndex int
requestURI string
enableLinkedDomainVerification bool
sendAllCredInWallet bool
}

type Opt func(opts *options)
Expand All @@ -654,3 +657,9 @@ func WithLinkedDomainVerification() Opt {
opts.enableLinkedDomainVerification = true
}
}

func WithSendAllCredInWallet() Opt {
return func(opts *options) {
opts.sendAllCredInWallet = true
}
}
Loading