Skip to content

Commit

Permalink
Merge pull request trustbloc#1618 from aholovko/wallet_cli_metadata
Browse files Browse the repository at this point in the history
feat: wallet cli metadata
  • Loading branch information
fqutishat authored Mar 5, 2024
2 parents a7fd81f + 93a0ff9 commit 927d107
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 70 deletions.
3 changes: 3 additions & 0 deletions component/wallet-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ 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
--authentication-method string wallet authentication method (default "system_pin")
--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,key (default "ion")
-h, --help help for create
--leveldb-path string leveldb path
--mongodb-connection-string string mongodb connection string
--name string wallet name (default "wallet-cli")
--version string wallet version (default "0.1")
```

Examples:
Expand Down
29 changes: 13 additions & 16 deletions component/wallet-cli/cmd/attest_wallet_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,16 @@ func NewAttestWalletCommand() *cobra.Command {
},
}

var didInfo *wallet.DIDInfo

if flags.walletDIDIndex != -1 {
didInfo = w.DIDs()[flags.walletDIDIndex]
} else {
didInfo = w.DIDs()[len(w.DIDs())-1]
}

attestationService, err := attestation.NewService(
&attestationServiceProvider{
&attestationProvider{
storageProvider: svc.StorageProvider(),
httpClient: httpClient,
documentLoader: svc.DocumentLoader(),
cryptoSuite: svc.CryptoSuite(),
wallet: w,
},
flags.attestationURL,
didInfo,
w.SignatureType(),
flags.walletDIDIndex,
)
if err != nil {
return fmt.Errorf("create attestation service: %w", err)
Expand All @@ -90,25 +82,30 @@ func NewAttestWalletCommand() *cobra.Command {
return cmd
}

type attestationServiceProvider struct {
type attestationProvider struct {
storageProvider storageapi.Provider
httpClient *http.Client
documentLoader ld.DocumentLoader
cryptoSuite api.Suite
wallet *wallet.Wallet
}

func (p *attestationServiceProvider) StorageProvider() storageapi.Provider {
func (p *attestationProvider) StorageProvider() storageapi.Provider {
return p.storageProvider
}

func (p *attestationServiceProvider) HTTPClient() *http.Client {
func (p *attestationProvider) HTTPClient() *http.Client {
return p.httpClient
}

func (p *attestationServiceProvider) DocumentLoader() ld.DocumentLoader {
func (p *attestationProvider) DocumentLoader() ld.DocumentLoader {
return p.documentLoader
}

func (p *attestationServiceProvider) CryptoSuite() api.Suite {
func (p *attestationProvider) CryptoSuite() api.Suite {
return p.cryptoSuite
}

func (p *attestationProvider) Wallet() *wallet.Wallet {
return p.wallet
}
18 changes: 15 additions & 3 deletions component/wallet-cli/cmd/create_wallet_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ import (
)

type createCommandFlags struct {
walletFlags *walletFlags
didMethod string
didKeyType string
walletFlags *walletFlags
didMethod string
didKeyType string
name string
version string
authenticationMethod string
}

func NewCreateWalletCommand() *cobra.Command {
Expand Down Expand Up @@ -65,6 +68,9 @@ func NewCreateWalletCommand() *cobra.Command {
provider,
wallet.WithNewDID(flags.didMethod),
wallet.WithKeyType(kmsapi.KeyType(flags.didKeyType)),
wallet.WithName(flags.name),
wallet.WithVersion(flags.version),
wallet.WithAuthenticationMethod(flags.authenticationMethod),
)
if err != nil {
return err
Expand All @@ -76,6 +82,9 @@ func NewCreateWalletCommand() *cobra.Command {
}

slog.Info("wallet created successfully",
"name", w.Name(),
"version", w.Version(),
"authentication_method", w.AuthenticationMethod(),
"signature_type", w.SignatureType(),
slog.Group("did", dids...),
)
Expand All @@ -89,6 +98,9 @@ func NewCreateWalletCommand() *cobra.Command {
cmd.Flags().StringVar(&flags.walletFlags.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")
cmd.Flags().StringVar(&flags.name, "name", "wallet-cli", "wallet name")
cmd.Flags().StringVar(&flags.version, "version", "0.1", "wallet version")
cmd.Flags().StringVar(&flags.authenticationMethod, "authentication-method", "system_pin", "wallet authentication method")

return cmd
}
Expand Down
6 changes: 3 additions & 3 deletions component/wallet-cli/cmd/oidc4vci_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,15 @@ func NewOIDC4VCICommand() *cobra.Command {
}

attestationService, err := attestation.NewService(
&attestationServiceProvider{
&attestationProvider{
storageProvider: svc.StorageProvider(),
httpClient: httpClient,
documentLoader: svc.DocumentLoader(),
cryptoSuite: svc.CryptoSuite(),
wallet: w,
},
flags.attestationURL,
w.DIDs()[walletDIDIndex],
w.SignatureType(),
walletDIDIndex,
)
if err != nil {
return fmt.Errorf("create attestation service: %w", err)
Expand Down
6 changes: 3 additions & 3 deletions component/wallet-cli/cmd/oidc4vp_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ func NewOIDC4VPCommand() *cobra.Command {
}

attestationService, err := attestation.NewService(
&attestationServiceProvider{
&attestationProvider{
storageProvider: svc.StorageProvider(),
httpClient: httpClient,
documentLoader: svc.DocumentLoader(),
cryptoSuite: svc.CryptoSuite(),
wallet: w,
},
flags.attestationURL,
w.DIDs()[walletDIDIndex],
w.SignatureType(),
walletDIDIndex,
)
if err != nil {
return fmt.Errorf("create attestation service: %w", err)
Expand Down
27 changes: 21 additions & 6 deletions component/wallet-cli/pkg/attestation/attestation_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/trustbloc/logutil-go/pkg/log"
"io"
"net/http"
"time"
Expand All @@ -22,13 +21,13 @@ import (
"github.com/trustbloc/kms-go/doc/jose"
storageapi "github.com/trustbloc/kms-go/spi/storage"
"github.com/trustbloc/kms-go/wrapper/api"
"github.com/trustbloc/logutil-go/pkg/log"
"github.com/trustbloc/vc-go/jwt"
"github.com/trustbloc/vc-go/verifiable"
"go.uber.org/zap"

jwssigner "github.com/trustbloc/vcs/component/wallet-cli/pkg/signer"
"github.com/trustbloc/vcs/component/wallet-cli/pkg/wallet"
vcsverifiable "github.com/trustbloc/vcs/pkg/doc/verifiable"
kmssigner "github.com/trustbloc/vcs/pkg/kms/signer"
)

Expand All @@ -46,6 +45,7 @@ type Service struct {
documentLoader ld.DocumentLoader
signer jose.Signer
httpClient *http.Client
wallet *wallet.Wallet
walletDID string
attestationEndpoint string
}
Expand All @@ -55,24 +55,36 @@ type provider interface {
HTTPClient() *http.Client
DocumentLoader() ld.DocumentLoader
CryptoSuite() api.Suite
Wallet() *wallet.Wallet
}

func NewService(
p provider,
attestationEndpoint string,
didInfo *wallet.DIDInfo,
signatureType vcsverifiable.SignatureType,
walletDIDIndex int,
) (*Service, error) {
store, err := p.StorageProvider().OpenStore(attestationStore)
if err != nil {
return nil, fmt.Errorf("open attestation store: %w", err)
}

var didInfo *wallet.DIDInfo

dids := p.Wallet().DIDs()

if walletDIDIndex != -1 {
didInfo = dids[walletDIDIndex]
} else {
didInfo = dids[len(dids)-1]
}

signer, err := p.CryptoSuite().FixedKeyMultiSigner(didInfo.KeyID)
if err != nil {
return nil, fmt.Errorf("create signer: %w", err)
}

signatureType := p.Wallet().SignatureType()

jwsSigner := jwssigner.NewJWSSigner(
fmt.Sprintf("%s#%s", didInfo.ID, didInfo.KeyID),
string(signatureType),
Expand All @@ -84,6 +96,7 @@ func NewService(
documentLoader: p.DocumentLoader(),
signer: jwsSigner,
httpClient: p.HTTPClient(),
wallet: p.Wallet(),
walletDID: didInfo.ID,
attestationEndpoint: attestationEndpoint,
}, nil
Expand Down Expand Up @@ -166,10 +179,12 @@ func (s *Service) attestationInit(ctx context.Context) (*AttestWalletInitRespons
"wallet_authentication",
},
WalletAuthentication: map[string]interface{}{
"wallet_id": s.walletDID,
"wallet_id": s.walletDID,
"authentication_method": s.wallet.AuthenticationMethod(),
},
WalletMetadata: map[string]interface{}{
"wallet_name": "wallet-cli",
"wallet_name": s.wallet.Name(),
"wallet_version": s.wallet.Version(),
},
}

Expand Down
Loading

0 comments on commit 927d107

Please sign in to comment.