Skip to content

Commit

Permalink
feat: add support for did:key to wallet cli, improvements for args ha…
Browse files Browse the repository at this point in the history
…ndling and logging (#1465)

Signed-off-by: Andrii Holovko <[email protected]>
  • Loading branch information
aholovko authored Oct 10, 2023
1 parent c3c85ed commit bf33da5
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 197 deletions.
36 changes: 18 additions & 18 deletions component/wallet-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ the Wallet. Therefore, prior to engaging in the OIDC4VCI flow, it's essential to

Wallet can be created using `create` command. The following CLI arguments are supported:
```bash
--context-provider-url string json-ld context provider url
--did-key-type string did key types supported: ED25519,ECDSAP256DER,ECDSAP384DER (default "ED25519")
--did-method string wallet did methods supported: ion,jwk (default "ion")
--did-method string wallet did methods supported: ion,jwk,key (default "ion")
-h, --help help for create
--leveldb-path string leveldb path
--mongodb-connection-string string mongodb connection string
--storage-type string storage types supported: mem,leveldb,mongodb (default "leveldb")
```

Examples:

* Create wallet with default parameters (leveldb storage, ED25519 key type, did:ion method):
* Create wallet using leveldb storage option and default parameters (ED25519 key type, did:ion method):
```bash
./wallet-cli create --leveldb-path "/mnt/wallet.db"
```
Expand All @@ -59,22 +59,22 @@ used for this purpose. The following CLI arguments are supported:
```bash
--client-id string vcs oauth2 client
--credential-format string supported credential formats: ldp_vc,jwt_vc_json-ld (default "ldp_vc")
--credential-offer-url string credential offer url
--credential-offer string openid credential offer
--credential-type string credential type
--demo-issuer-url string demo issuer url for downloading qr code automatically
--discoverable-client-id enable discoverable client id scheme for dynamic client registration
--enable-discoverable-client-id enables discoverable client id scheme for dynamic client registration
--enable-tracing enables http tracing
--grant-type string supported grant types: authorization_code,urn:ietf:params:oauth:grant-type:pre-authorized_code (default "authorization_code")
-h, --help help for oidc4vci
--issuer-state string issuer state in wallet-initiated flow
--leveldb-path string leveldb path
--login string user login on issuer IdP
--mongodb-connection-string string mongodb connection string
--password string user password on issuer IdP
--pin string pin for pre-authorized code flow
--qr-code-path string path to file with qr code
--redirect-uri string callback where the authorization code should be sent (default "http://127.0.0.1/callback")
--scopes strings vcs oauth2 scopes (default [openid])
--storage-type string storage types supported: mem,leveldb,mongodb (default "leveldb")
--user-login string user login on issuer IdP
--user-password string user password on issuer IdP
--wallet-did-index int index of wallet did, if not set the most recently created DID is used (default -1)
```
Expand All @@ -87,27 +87,27 @@ Examples:
* Receive VC from the Issuer using authorization code flow:
```bash
./wallet-cli oidc4vci --leveldb-path "/mnt/wallet.db" --qr-code-path "/mnt/qr.png" --grant-type authorization_code --scopes openid --redirect-uri http://127.0.0.1/callback --client-id oidc4vc_client --credential-type PermanentResidentCard --credential-format ldp_vc
./wallet-cli oidc4vci --leveldb-path "/mnt/wallet.db" --qr-code-path "/mnt/qr.png" --grant-type authorization_code --client-id oidc4vc_client --credential-type PermanentResidentCard --credential-format ldp_vc
```
### Presenting Verifiable Credential using OIDC4VP exchange protocol
Use the `oidc4vp` command to present Verifiable Credential to the Verifier:
```bash
-h, --help help for oidc4vp
--leveldb-path string leveldb path
--linked-domain-verification enable linked domain verification
--mongodb-connection-string string mongodb connection string
--qr-code-path string path to file with qr code
--storage-type string storage types supported: mem,leveldb,mongodb (default "leveldb")
--wallet-did-index int index of wallet did, if not set the most recently created DID is used (default -1)
--enable-linked-domain-verification enables linked domain verification
--enable-tracing enables http tracing
-h, --help help for oidc4vp
--leveldb-path string leveldb path
--mongodb-connection-string string mongodb connection string
--qr-code-path string path to file with qr code
--wallet-did-index int index of wallet did, if not set the most recently created DID is used (default -1)
```
Examples:
* Present VC to the Verifier with enabled linked domain verification:
* Present VC to the Verifier with linked domain verification:
```bash
./wallet-cli oidc4vp --leveldb-path "/mnt/wallet.db" --qr-code-path "/mnt/qr.png" --linked-domain-verification
./wallet-cli oidc4vp --leveldb-path "/mnt/wallet.db" --qr-code-path "/mnt/qr.png" --enable-linked-domain-verification
```
## Contributing
Expand Down
48 changes: 23 additions & 25 deletions component/wallet-cli/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package cmd
import (
"crypto/tls"
"fmt"
"log/slog"

"github.com/piprate/json-gold/ld"
vdrapi "github.com/trustbloc/did-go/vdr/api"
Expand All @@ -22,9 +23,8 @@ import (
)

type serviceFlags struct {
storageType string
mongoDBConnectionString string
levelDBPath string
mongoDBConnectionString string
contextProviderURL string
}

Expand All @@ -36,39 +36,37 @@ type services struct {
}

func initServices(flags *serviceFlags, tlsConfig *tls.Config) (*services, error) {
var storageOpts []storage.Opt

switch flags.storageType {
case "mem":
break
case "leveldb":
if flags.levelDBPath == "" {
return nil, fmt.Errorf("--leveldb-path is required when storage type is leveldb")
}

storageOpts = append(storageOpts, storage.WithDBPath(flags.levelDBPath))
case "mongodb":
if flags.mongoDBConnectionString == "" {
return nil, fmt.Errorf("--mongodb-connection-string is required when storage type is mongodb")
}

storageOpts = append(storageOpts, storage.WithConnectionString(flags.mongoDBConnectionString))
default:
return nil, fmt.Errorf("unsupported storage type: %s", flags.storageType)
var (
storageType string
opts []storage.Opt
)

if flags.levelDBPath != "" {
storageType = "leveldb"
opts = append(opts, storage.WithDBPath(flags.levelDBPath))
} else if flags.mongoDBConnectionString != "" {
storageType = "mongodb"
opts = append(opts, storage.WithConnectionString(flags.mongoDBConnectionString))
} else {
return nil, fmt.Errorf("either --leveldb-path or --mongodb-connection-string must be specified")
}

storageProvider, err := storage.NewProvider(flags.storageType, storageOpts...)
slog.Info("initializing storage provider",
"storage_type", storageType,
)

storageProvider, err := storage.NewProvider(storageType, opts...)
if err != nil {
return nil, err
}

var opts []ldutil.Opt
var ldOpts []ldutil.Opt

if flags.contextProviderURL != "" {
opts = append(opts, ldutil.WithRemoteProviderURL(flags.contextProviderURL))
ldOpts = append(ldOpts, ldutil.WithRemoteProviderURL(flags.contextProviderURL))
}

documentLoader, err := ldutil.DocumentLoader(storageProvider, opts...)
documentLoader, err := ldutil.DocumentLoader(storageProvider, ldOpts...)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions component/wallet-cli/cmd/create_wallet_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewCreateWalletCommand() *cobra.Command {

var dids []any
for i, did := range w.DIDs() {
dids = append(dids, fmt.Sprintf("%d", i), did)
dids = append(dids, fmt.Sprintf("%d", i), did.ID)
}

slog.Info("wallet created successfully",
Expand All @@ -79,10 +79,10 @@ func NewCreateWalletCommand() *cobra.Command {
},
}

cmd.Flags().StringVar(&flags.serviceFlags.storageType, "storage-type", "leveldb", "storage types supported: mem,leveldb,mongodb")
cmd.Flags().StringVar(&flags.serviceFlags.levelDBPath, "leveldb-path", "", "leveldb path")
cmd.Flags().StringVar(&flags.serviceFlags.mongoDBConnectionString, "mongodb-connection-string", "", "mongodb connection string")
cmd.Flags().StringVar(&flags.didMethod, "did-method", "ion", "wallet did methods supported: ion,jwk")
cmd.Flags().StringVar(&flags.serviceFlags.contextProviderURL, "context-provider-url", "", "json-ld context provider url")
cmd.Flags().StringVar(&flags.didMethod, "did-method", "ion", "wallet did methods supported: ion,jwk,key")
cmd.Flags().StringVar(&flags.didKeyType, "did-key-type", "ED25519", "did key types supported: ED25519,ECDSAP256DER,ECDSAP384DER")

return cmd
Expand Down
Loading

0 comments on commit bf33da5

Please sign in to comment.