diff --git a/component/wallet-cli/go.mod b/component/wallet-cli/go.mod index 7cda5859f..be5990007 100644 --- a/component/wallet-cli/go.mod +++ b/component/wallet-cli/go.mod @@ -11,7 +11,6 @@ require ( github.com/golang/mock v1.6.0 github.com/google/uuid v1.3.0 github.com/henvic/httpretty v0.1.0 - github.com/hyperledger/aries-framework-go v0.3.3-0.20230810150537-71e132ba5968 github.com/hyperledger/aries-framework-go-ext/component/storage/mongodb v0.0.0-20220728172020-0a8903e45149 github.com/hyperledger/aries-framework-go-ext/component/vdr/jwk v0.0.0-20221213152252-f0c83a5a922c github.com/hyperledger/aries-framework-go-ext/component/vdr/longform v0.0.0-20221201213446-c4c1e76daa49 @@ -87,9 +86,9 @@ require ( github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-retryablehttp v0.7.4 // indirect github.com/hashicorp/hcl v1.0.0 // indirect + github.com/hyperledger/aries-framework-go v0.3.3-0.20230810150537-71e132ba5968 // indirect github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc3.0.20221104150937-07bfbe450122 // indirect github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230427134832-0c9969493bd3 // indirect - github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20221025204933-b807371b6f1e // indirect github.com/hyperledger/fabric-amcl v0.0.0-20230602173724-9e02669dceb2 // indirect github.com/hyperledger/ursa-wrapper-go v0.3.1 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect diff --git a/component/wallet-cli/go.sum b/component/wallet-cli/go.sum index 88d0f366d..ce8855136 100644 --- a/component/wallet-cli/go.sum +++ b/component/wallet-cli/go.sum @@ -577,8 +577,6 @@ github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230427134832-0c github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230427134832-0c9969493bd3/go.mod h1:CvYs4l8X2NrrF93weLOu5RTOIJeVdoZITtjEflyuTyM= github.com/hyperledger/aries-framework-go/component/models v0.0.0-20230810150537-71e132ba5968 h1:W8F1CA8P/bNb92P/JMYG2nWqv0bxLL58/Q8Rw9nsNyI= github.com/hyperledger/aries-framework-go/component/models v0.0.0-20230810150537-71e132ba5968/go.mod h1:AJkRLmQB1/umL5GfXw/XIarGaH/XCQOL/6wlGtqdDpA= -github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20221025204933-b807371b6f1e h1:/hrQfwJvHJrwV2FSmfnRp5L6yKY9DqDFqwYyb+oVuDU= -github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20221025204933-b807371b6f1e/go.mod h1:ACGP1L+WeecDtyA0Mi2E1kqtPLIGrCWPSJ43q2elwX8= github.com/hyperledger/aries-framework-go/component/storage/leveldb v0.0.0-20221202141134-083803ecf0a3 h1:GF7p/WrgKrhq7d0d9b6nkuW/sidMOwla9Muj4g+BgSY= github.com/hyperledger/aries-framework-go/component/storage/leveldb v0.0.0-20221202141134-083803ecf0a3/go.mod h1:i/bnCdoiv0a9fgHQtd+EiAxmCdaJKE3JYrgDUACKgyE= github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20230427134832-0c9969493bd3 h1:JGYA9l5zTlvsvfnXT9hYPpCokAjmVKX0/r7njba7OX4= diff --git a/component/wallet-cli/pkg/walletrunner/wallet.go b/component/wallet-cli/pkg/walletrunner/wallet.go index b8c71ad41..da0ef226e 100644 --- a/component/wallet-cli/pkg/walletrunner/wallet.go +++ b/component/wallet-cli/pkg/walletrunner/wallet.go @@ -7,15 +7,15 @@ SPDX-License-Identifier: Apache-2.0 package walletrunner import ( - "errors" + "encoding/json" "fmt" "strings" + "sync" "time" "github.com/google/uuid" - "github.com/hyperledger/aries-framework-go/pkg/wallet" + "github.com/hyperledger/aries-framework-go/component/models/verifiable" "github.com/hyperledger/aries-framework-go/spi/kms" - "github.com/trustbloc/vcs/component/wallet-cli/internal/vdrutil" vcs "github.com/trustbloc/vcs/pkg/doc/verifiable" ) @@ -31,7 +31,21 @@ const ( didMethodION = "ion" ) -func (s *Service) GetWallet() *wallet.Wallet { +// Wallet provides verifiable credential storing, fetching, and presentation definition querying. +type Wallet interface { + // Open opens wallet. + Open(passPhrase string) string + // Close closes wallet. + Close() bool + // Add adds a marshalled credential to the wallet. + Add(content json.RawMessage) error + // GetAll returns all stored credentials. + GetAll() (map[string]json.RawMessage, error) + // Query runs the given presentation definition on the stored credentials. + Query(pdBytes []byte) ([]*verifiable.Presentation, error) +} + +func (s *Service) GetWallet() Wallet { return s.wallet } @@ -69,12 +83,9 @@ func (s *Service) CreateWallet() error { s.wallet = w } - token, err := s.wallet.Open(wallet.WithUnlockByPassphrase(s.vcProviderConf.WalletParams.Passphrase)) - if err != nil { - if !errors.Is(err, wallet.ErrAlreadyUnlocked) { - return fmt.Errorf("unlock wallet: %w", err) - } - } + var err error + + token := s.wallet.Open(s.vcProviderConf.WalletParams.Passphrase) if token != "" { s.vcProviderConf.WalletParams.Token = token @@ -134,24 +145,21 @@ func (s *Service) CreateWallet() error { return nil } -func newWallet(shouldCreate bool, userID string, passphrase string, services *ariesServices) (*wallet.Wallet, error) { - if shouldCreate { - err := wallet.CreateProfile(userID, services, wallet.WithPassphrase(passphrase)) - if err != nil { - return nil, fmt.Errorf("user profile create failed: %w", err) - } - } - - w, err := wallet.New(userID, services) +func newWallet(shouldCreate bool, userID string, passphrase string, services *ariesServices) (Wallet, error) { + store, err := services.storageProvider.OpenStore("wallet:credential") if err != nil { - return nil, fmt.Errorf("create wallet failed: %w", err) + return nil, err } - return w, nil + return &walletImpl{ + credStore: store, + ldLoader: services.documentLoader, + storeLock: sync.RWMutex{}, + }, nil } func (s *Service) SaveCredentialInWallet(vc []byte) error { - err := s.wallet.Add(s.vcProviderConf.WalletParams.Token, wallet.Credential, vc) + err := s.wallet.Add(vc) if err != nil { return fmt.Errorf("wallet add credential failed: %w", err) } diff --git a/component/wallet-cli/pkg/walletrunner/wallet_impl.go b/component/wallet-cli/pkg/walletrunner/wallet_impl.go new file mode 100644 index 000000000..6c7c9ef03 --- /dev/null +++ b/component/wallet-cli/pkg/walletrunner/wallet_impl.go @@ -0,0 +1,215 @@ +/* +Copyright Gen Digital Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package walletrunner + +import ( + "crypto/sha256" + "encoding/base64" + "encoding/hex" + "encoding/json" + "errors" + "fmt" + "strings" + "sync" + + "github.com/hyperledger/aries-framework-go/component/models/presexch" + "github.com/hyperledger/aries-framework-go/component/models/verifiable" + "github.com/hyperledger/aries-framework-go/spi/storage" + "github.com/piprate/json-gold/ld" +) + +type walletImpl struct { + credStore storage.Store + ldLoader ld.DocumentLoader + storeLock sync.RWMutex +} + +func (w *walletImpl) Open(string) string { + return "token" +} + +func (w *walletImpl) Close() bool { + return true +} + +const credentialTag = "credential" + +func (w *walletImpl) Add(content json.RawMessage) error { + key, err := getContentID(content) + if err != nil { + return err + } + + w.storeLock.Lock() + defer w.storeLock.Unlock() + + err = w.credStore.Put(key, content, storage.Tag{Name: credentialTag}) + if err != nil { + return err + } + + return nil +} + +type contentID struct { + ID string `json:"id"` +} + +func getContentID(content json.RawMessage) (string, error) { + key, err := getJWTContentID(string(content)) + if err == nil && strings.TrimSpace(key) != "" { + return key, nil + } + + var cid contentID + if err := json.Unmarshal(content, &cid); err != nil { + return "", fmt.Errorf("failed to read content to be saved : %w", err) + } + + key = cid.ID + if strings.TrimSpace(key) == "" { + // use document hash as key to avoid duplicates if id is missing + digest := sha256.Sum256(content) + + key = hex.EncodeToString(digest[0:]) + } + + return key, nil +} + +type hasJTI struct { + JTI string `json:"jti"` +} + +func getJWTContentID(jwtStr string) (string, error) { + parts := strings.Split(unQuote(jwtStr), ".") + if len(parts) != 3 { // nolint: gomnd + return "", nil // assume not a jwt + } + + credBytes, err := base64.RawURLEncoding.DecodeString(parts[1]) + if err != nil { + return "", fmt.Errorf("decode base64 JWT data: %w", err) + } + + cred := &hasJTI{} + + err = json.Unmarshal(credBytes, cred) + if err != nil { + return "", fmt.Errorf("failed to unmarshal JWT data: %w", err) + } + + if cred.JTI == "" { + return "", fmt.Errorf("JWT data has no ID") + } + + return cred.JTI, nil +} + +func unQuote(s string) string { + if len(s) <= 1 { + return s + } + + if s[0] == '"' && s[len(s)-1] == '"' { + return s[1 : len(s)-1] + } + + return s +} + +func (w *walletImpl) GetAll() (map[string]json.RawMessage, error) { + w.storeLock.RLock() + defer w.storeLock.RUnlock() + + iter, err := w.credStore.Query(credentialTag) + if err != nil { + return nil, err + } + + result := make(map[string]json.RawMessage) + + for { + ok, err := iter.Next() + if err != nil { + return nil, err + } + + if !ok { + break + } + + key, err := iter.Key() + if err != nil { + return nil, err + } + + val, err := iter.Value() + if err != nil { + return nil, err + } + + result[key] = val + } + + return result, nil +} + +func (w *walletImpl) Query(pdBytes []byte) ([]*verifiable.Presentation, error) { + vcContents, err := w.GetAll() + if err != nil { + return nil, fmt.Errorf("failed to query credentials: %w", err) + } + + if len(vcContents) == 0 { + return nil, errors.New("no result found") + } + + creds, err := parseCredentialContents(vcContents, w.ldLoader) + if err != nil { + return nil, err + } + + var presDefinition presexch.PresentationDefinition + + err = json.Unmarshal(pdBytes, &presDefinition) + if err != nil { + return nil, err + } + + result, err := presDefinition.CreateVP(creds, w.ldLoader, verifiable.WithDisabledProofCheck(), + verifiable.WithJSONLDDocumentLoader(w.ldLoader)) + + if errors.Is(err, presexch.ErrNoCredentials) { + return nil, errors.New("no result found") + } + + if err != nil { + return nil, err + } + + return []*verifiable.Presentation{result}, nil +} + +func parseCredentialContents( + raws map[string]json.RawMessage, + documentLoader ld.DocumentLoader, +) ([]*verifiable.Credential, error) { + var result []*verifiable.Credential + + for _, raw := range raws { + vc, err := verifiable.ParseCredential(raw, verifiable.WithDisabledProofCheck(), + verifiable.WithJSONLDDocumentLoader(documentLoader)) + if err != nil { + return nil, err + } + + result = append(result, vc) + } + + return result, nil +} diff --git a/component/wallet-cli/pkg/walletrunner/wallet_runner.go b/component/wallet-cli/pkg/walletrunner/wallet_runner.go index eb7a85dcb..fe45155ea 100644 --- a/component/wallet-cli/pkg/walletrunner/wallet_runner.go +++ b/component/wallet-cli/pkg/walletrunner/wallet_runner.go @@ -36,7 +36,6 @@ import ( "github.com/hyperledger/aries-framework-go/component/vdr/httpbinding" "github.com/hyperledger/aries-framework-go/component/vdr/key" "github.com/hyperledger/aries-framework-go/component/vdr/web" - "github.com/hyperledger/aries-framework-go/pkg/wallet" kmsapi "github.com/hyperledger/aries-framework-go/spi/kms" "github.com/hyperledger/aries-framework-go/spi/secretlock" "github.com/hyperledger/aries-framework-go/spi/storage" @@ -104,7 +103,7 @@ var extraContexts = []ldcontext.Document{ //nolint:gochecknoglobals type Service struct { ariesServices *ariesServices - wallet *wallet.Wallet + wallet Wallet vcProvider vcprovider.VCProvider vcProviderConf *vcprovider.Config httpClient *http.Client diff --git a/component/wallet-cli/pkg/walletrunner/wallet_runner_oidc4ci.go b/component/wallet-cli/pkg/walletrunner/wallet_runner_oidc4ci.go index 5a2ab1905..04b2d3813 100644 --- a/component/wallet-cli/pkg/walletrunner/wallet_runner_oidc4ci.go +++ b/component/wallet-cli/pkg/walletrunner/wallet_runner_oidc4ci.go @@ -27,7 +27,6 @@ import ( "github.com/hyperledger/aries-framework-go/component/models/jwt" "github.com/hyperledger/aries-framework-go/component/models/verifiable" didkey "github.com/hyperledger/aries-framework-go/component/vdr/key" - "github.com/hyperledger/aries-framework-go/pkg/wallet" "github.com/samber/lo" "golang.org/x/oauth2" @@ -216,7 +215,7 @@ func (s *Service) RunOIDC4CI(config *OIDC4CIConfig, hooks *Hooks) error { } s.print("Adding credential to wallet") - if err = s.wallet.Add(s.vcProviderConf.WalletParams.Token, wallet.Credential, b); err != nil { + if err = s.wallet.Add(b); err != nil { return fmt.Errorf("add credential: %w", err) } @@ -378,7 +377,7 @@ func (s *Service) RunOIDC4CIWalletInitiated(config *OIDC4CIConfig, hooks *Hooks) } s.print("Adding credential to wallet") - if err = s.wallet.Add(s.vcProviderConf.WalletParams.Token, wallet.Credential, b); err != nil { + if err = s.wallet.Add(b); err != nil { return fmt.Errorf("add credential: %w", err) } diff --git a/component/wallet-cli/pkg/walletrunner/wallet_runner_oidc4ci_pre_auth.go b/component/wallet-cli/pkg/walletrunner/wallet_runner_oidc4ci_pre_auth.go index 2e8e74a0f..f6e63c6eb 100644 --- a/component/wallet-cli/pkg/walletrunner/wallet_runner_oidc4ci_pre_auth.go +++ b/component/wallet-cli/pkg/walletrunner/wallet_runner_oidc4ci_pre_auth.go @@ -19,7 +19,6 @@ import ( "time" "github.com/hyperledger/aries-framework-go/component/models/verifiable" - "github.com/hyperledger/aries-framework-go/pkg/wallet" "github.com/samber/lo" "golang.org/x/oauth2" @@ -133,7 +132,7 @@ func (s *Service) RunOIDC4CIPreAuth(config *OIDC4CIConfig) (*verifiable.Credenti s.print("Adding credential to wallet") - if err = s.wallet.Add(s.vcProviderConf.WalletParams.Token, wallet.Credential, b); err != nil { + if err = s.wallet.Add(b); err != nil { return nil, fmt.Errorf("add credential to wallet: %w", err) } diff --git a/component/wallet-cli/pkg/walletrunner/wallet_runner_oidc4vp.go b/component/wallet-cli/pkg/walletrunner/wallet_runner_oidc4vp.go index 6aa755eae..be0e0db68 100644 --- a/component/wallet-cli/pkg/walletrunner/wallet_runner_oidc4vp.go +++ b/component/wallet-cli/pkg/walletrunner/wallet_runner_oidc4vp.go @@ -27,7 +27,6 @@ import ( "github.com/hyperledger/aries-framework-go/component/models/presexch" "github.com/hyperledger/aries-framework-go/component/models/verifiable" didkey "github.com/hyperledger/aries-framework-go/component/vdr/key" - "github.com/hyperledger/aries-framework-go/pkg/wallet" "github.com/hyperledger/aries-framework-go/spi/crypto" "github.com/hyperledger/aries-framework-go/spi/kms" @@ -146,7 +145,7 @@ func (s *Service) RunOIDC4VPFlow(authorizationRequest string, hooks *OIDC4VPHook type VPFlowExecutor struct { tlsConfig *tls.Config ariesServices *ariesServices - wallet *wallet.Wallet + wallet Wallet walletToken string walletDidID []string walletDidKeyID []string @@ -296,10 +295,7 @@ func (e *VPFlowExecutor) QueryCredentialFromWalletSingleVP() error { } // This query will always return one VP - so far no plans to change this - vps, err := e.wallet.Query(e.walletToken, &wallet.QueryParams{ - Type: "PresentationExchange", - Query: []json.RawMessage{pdBytes}, - }) + vps, err := e.wallet.Query(pdBytes) if err != nil { return fmt.Errorf("query vc using presentation definition: %w", err) @@ -322,10 +318,7 @@ func (e *VPFlowExecutor) QueryCredentialFromWalletMultiVP() error { // This query will always return one VP - so far no plans to change this // We will only use this to get relevant credentials from wallet - legacyVP, err := e.wallet.Query(e.walletToken, &wallet.QueryParams{ - Type: "PresentationExchange", - Query: []json.RawMessage{pdBytes}, - }) + legacyVP, err := e.wallet.Query(pdBytes) if err != nil { return fmt.Errorf("query credentials from wallet: %w", err) } diff --git a/go.mod b/go.mod index 79ead19d3..368845714 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,6 @@ require ( github.com/golang/mock v1.6.0 github.com/google/tink/go v1.7.0 github.com/google/uuid v1.3.0 - github.com/hyperledger/aries-framework-go v0.3.3-0.20230810150537-71e132ba5968 github.com/hyperledger/aries-framework-go-ext/component/storage/mongodb v0.0.0-20220728172020-0a8903e45149 github.com/hyperledger/aries-framework-go-ext/component/vdr/orb v1.0.0-rc5.0.20221201213446-c4c1e76daa49 github.com/hyperledger/aries-framework-go/component/didconfig v0.0.0-20230622211121-852ce35730b4 @@ -126,6 +125,7 @@ require ( github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-retryablehttp v0.7.4 // indirect github.com/hashicorp/hcl v1.0.0 // indirect + github.com/hyperledger/aries-framework-go v0.3.3-0.20230810150537-71e132ba5968 // indirect github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc3.0.20221104150937-07bfbe450122 // indirect github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230427134832-0c9969493bd3 // indirect github.com/hyperledger/fabric-amcl v0.0.0-20230602173724-9e02669dceb2 // indirect @@ -171,7 +171,6 @@ require ( github.com/prometheus/common v0.37.0 // indirect github.com/prometheus/procfs v0.8.0 // indirect github.com/redis/go-redis/extra/rediscmd/v9 v9.0.2 // indirect - github.com/rs/cors v1.8.2 // indirect github.com/shopspring/decimal v1.3.1 // indirect github.com/sirupsen/logrus v1.9.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect diff --git a/go.sum b/go.sum index cffe541b6..4aad9e6cd 100644 --- a/go.sum +++ b/go.sum @@ -956,7 +956,6 @@ github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6po github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U= -github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= diff --git a/pkg/kms/key/creator_test.go b/pkg/kms/key/creator_test.go index 742b14026..7c3ee6a42 100644 --- a/pkg/kms/key/creator_test.go +++ b/pkg/kms/key/creator_test.go @@ -12,12 +12,13 @@ import ( "errors" "testing" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/kms/localkms" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/secretlock/noop" "github.com/stretchr/testify/require" "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/primitive/bbs12381g2pub" mockkms "github.com/hyperledger/aries-framework-go/component/kmscrypto/mock/kms" "github.com/hyperledger/aries-framework-go/component/storageutil/mem" - "github.com/hyperledger/aries-framework-go/pkg/framework/aries" "github.com/hyperledger/aries-framework-go/spi/kms" "github.com/trustbloc/vcs/pkg/kms/key" @@ -132,13 +133,13 @@ func TestCryptoKeyCreator(t *testing.T) { func newKMS(t *testing.T) kms.KeyManager { t.Helper() - a, err := aries.New(aries.WithStoreProvider(mem.NewProvider())) + p, err := mockkms.NewProviderForKMS(mem.NewProvider(), &noop.NoLock{}) require.NoError(t, err) - ctx, err := a.Context() + keyManager, err := localkms.New("local-lock://custom/master/key/", p) require.NoError(t, err) - return ctx.KMS() + return keyManager } type kmsMock struct { diff --git a/pkg/service/oidc4vp/oidc4vp_service_test.go b/pkg/service/oidc4vp/oidc4vp_service_test.go index ab0a9a71c..5bfd98899 100644 --- a/pkg/service/oidc4vp/oidc4vp_service_test.go +++ b/pkg/service/oidc4vp/oidc4vp_service_test.go @@ -34,10 +34,7 @@ import ( "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" util "github.com/hyperledger/aries-framework-go/component/models/util/time" "github.com/hyperledger/aries-framework-go/component/models/verifiable" - "github.com/hyperledger/aries-framework-go/component/storageutil/mem" ariesmockstorage "github.com/hyperledger/aries-framework-go/component/storageutil/mock/storage" - "github.com/hyperledger/aries-framework-go/pkg/framework/aries" - ariescontext "github.com/hyperledger/aries-framework-go/pkg/framework/context" ariescrypto "github.com/hyperledger/aries-framework-go/spi/crypto" "github.com/hyperledger/aries-framework-go/spi/kms" @@ -244,12 +241,15 @@ func TestService_InitiateOidcInteraction(t *testing.T) { } func TestService_VerifyOIDCVerifiablePresentation(t *testing.T) { - agent := newAgent(t) + keyManager := createKMS(t) + + crypto, err := tinkcrypto.New() + require.NoError(t, err) txManager := NewMockTransactionManager(gomock.NewController(t)) profileService := NewMockProfileService(gomock.NewController(t)) presentationVerifier := NewMockPresentationVerifier(gomock.NewController(t)) - vp, pd, issuer, pubKeyFetcher, loader := newVPWithPD(t, agent) + vp, pd, issuer, pubKeyFetcher, loader := newVPWithPD(t, keyManager, crypto) s := oidc4vp.NewService(&oidc4vp.Config{ EventSvc: &mockEvent{}, @@ -343,8 +343,8 @@ func TestService_VerifyOIDCVerifiablePresentation(t *testing.T) { testLoader := testutil.DocumentLoader(t) - vp1, issuer1, pubKeyFetcher1 := newVPWithPS(t, agent, mergedPS, "PhDDegree") - vp2, issuer2, pubKeyFetcher2 := newVPWithPS(t, agent, mergedPS, "BachelorDegree") + vp1, issuer1, pubKeyFetcher1 := newVPWithPS(t, keyManager, crypto, mergedPS, "PhDDegree") + vp2, issuer2, pubKeyFetcher2 := newVPWithPS(t, keyManager, crypto, mergedPS, "BachelorDegree") combinedFetcher := func(issuerID string, keyID string) (*verifier.PublicKey, error) { switch issuerID { @@ -430,8 +430,8 @@ func TestService_VerifyOIDCVerifiablePresentation(t *testing.T) { testLoader := testutil.DocumentLoader(t) - vp1, issuer1, pubKeyFetcher1 := newVPWithPS(t, agent, mergedPS, "PhDDegree") - vp2, issuer2, pubKeyFetcher2 := newVPWithPS(t, agent, mergedPS, "BachelorDegree") + vp1, issuer1, pubKeyFetcher1 := newVPWithPS(t, keyManager, crypto, mergedPS, "PhDDegree") + vp2, issuer2, pubKeyFetcher2 := newVPWithPS(t, keyManager, crypto, mergedPS, "BachelorDegree") combinedFetcher := func(issuerID string, keyID string) (*verifier.PublicKey, error) { switch issuerID { @@ -792,14 +792,14 @@ func (m *mockEvent) Publish(_ context.Context, _ string, _ ...*spi.Event) error return nil } -func newVPWithPD(t *testing.T, agent *ariescontext.Provider) ( +func newVPWithPD(t *testing.T, keyManager kms.KeyManager, crypto ariescrypto.Crypto) ( *verifiable.Presentation, *presexch.PresentationDefinition, string, verifiable.PublicKeyFetcher, *lddocloader.DocumentLoader) { uri := randomURI() customType := "CustomType" - expected, issuer, pubKeyFetcher := newSignedJWTVC(t, agent, []string{uri}, "", "") + expected, issuer, pubKeyFetcher := newSignedJWTVC(t, keyManager, crypto, []string{uri}, "", "") expected.Types = append(expected.Types, customType) defs := &presexch.PresentationDefinition{ @@ -822,9 +822,10 @@ func newVPWithPD(t *testing.T, agent *ariescontext.Provider) ( ), defs, issuer, pubKeyFetcher, docLoader } -func newVPWithPS(t *testing.T, agent *ariescontext.Provider, ps *presexch.PresentationSubmission, value string) ( +func newVPWithPS(t *testing.T, keyManager kms.KeyManager, crypto ariescrypto.Crypto, + ps *presexch.PresentationSubmission, value string) ( *verifiable.Presentation, string, verifiable.PublicKeyFetcher) { - expected, issuer, pubKeyFetcher := newSignedJWTVC(t, agent, nil, "degree", value) + expected, issuer, pubKeyFetcher := newSignedJWTVC(t, keyManager, crypto, nil, "degree", value) return newVP(t, ps, expected, @@ -895,16 +896,16 @@ func newDegreeVC(issuer string, degreeType string, ctx []string) *verifiable.Cre } func newSignedJWTVC(t *testing.T, - agent *ariescontext.Provider, ctx []string, + keyManager kms.KeyManager, crypto ariescrypto.Crypto, ctx []string, vcType string, value string) (*verifiable.Credential, string, verifiable.PublicKeyFetcher) { t.Helper() - keyID, kh, err := agent.KMS().Create(kms.ED25519Type) + keyID, kh, err := keyManager.Create(kms.ED25519Type) require.NoError(t, err) - signer := suite.NewCryptoSigner(agent.Crypto(), kh) + signer := suite.NewCryptoSigner(crypto, kh) - pubKey, kt, err := agent.KMS().ExportPubKeyBytes(keyID) + pubKey, kt, err := keyManager.ExportPubKeyBytes(keyID) require.NoError(t, err) require.Equal(t, kms.ED25519Type, kt) @@ -967,18 +968,6 @@ func createTestDocumentLoader(t *testing.T, contextURL string, types ...string) return loader } -func newAgent(t *testing.T) *ariescontext.Provider { - t.Helper() - - a, err := aries.New(aries.WithStoreProvider(mem.NewProvider())) - require.NoError(t, err) - - ctx, err := a.Context() - require.NoError(t, err) - - return ctx -} - func toMap(t *testing.T, v interface{}) map[string]interface{} { bits, err := json.Marshal(v) require.NoError(t, err) diff --git a/test/bdd/go.mod b/test/bdd/go.mod index 9f5411afb..7c7306775 100644 --- a/test/bdd/go.mod +++ b/test/bdd/go.mod @@ -11,7 +11,6 @@ require ( github.com/google/uuid v1.3.0 github.com/gorilla/mux v1.8.0 github.com/greenpau/go-calculator v1.0.1 - github.com/hyperledger/aries-framework-go v0.3.3-0.20230810150537-71e132ba5968 github.com/hyperledger/aries-framework-go-ext/component/vdr/orb v1.0.0-rc5.0.20221201213446-c4c1e76daa49 github.com/hyperledger/aries-framework-go/component/models v0.0.0-20230810150537-71e132ba5968 github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20230427134832-0c9969493bd3 @@ -92,6 +91,7 @@ require ( github.com/hashicorp/golang-lru v0.5.4 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/henvic/httpretty v0.1.0 // indirect + github.com/hyperledger/aries-framework-go v0.3.3-0.20230810150537-71e132ba5968 // indirect github.com/hyperledger/aries-framework-go-ext/component/storage/mongodb v0.0.0-20220728172020-0a8903e45149 // indirect github.com/hyperledger/aries-framework-go-ext/component/vdr/jwk v0.0.0-20221213152252-f0c83a5a922c // indirect github.com/hyperledger/aries-framework-go-ext/component/vdr/longform v0.0.0-20221201213446-c4c1e76daa49 // indirect @@ -99,7 +99,6 @@ require ( github.com/hyperledger/aries-framework-go/component/didconfig v0.0.0-20230622211121-852ce35730b4 // indirect github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0-20230622082138-3ffab1691857 // indirect github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230427134832-0c9969493bd3 // indirect - github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20221025204933-b807371b6f1e // indirect github.com/hyperledger/aries-framework-go/component/storage/leveldb v0.0.0-20221202141134-083803ecf0a3 // indirect github.com/hyperledger/fabric-amcl v0.0.0-20230602173724-9e02669dceb2 // indirect github.com/hyperledger/ursa-wrapper-go v0.3.1 // indirect diff --git a/test/bdd/go.sum b/test/bdd/go.sum index 8f812a319..98c125f87 100644 --- a/test/bdd/go.sum +++ b/test/bdd/go.sum @@ -610,8 +610,6 @@ github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230427134832-0c github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230427134832-0c9969493bd3/go.mod h1:CvYs4l8X2NrrF93weLOu5RTOIJeVdoZITtjEflyuTyM= github.com/hyperledger/aries-framework-go/component/models v0.0.0-20230810150537-71e132ba5968 h1:W8F1CA8P/bNb92P/JMYG2nWqv0bxLL58/Q8Rw9nsNyI= github.com/hyperledger/aries-framework-go/component/models v0.0.0-20230810150537-71e132ba5968/go.mod h1:AJkRLmQB1/umL5GfXw/XIarGaH/XCQOL/6wlGtqdDpA= -github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20221025204933-b807371b6f1e h1:/hrQfwJvHJrwV2FSmfnRp5L6yKY9DqDFqwYyb+oVuDU= -github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20221025204933-b807371b6f1e/go.mod h1:ACGP1L+WeecDtyA0Mi2E1kqtPLIGrCWPSJ43q2elwX8= github.com/hyperledger/aries-framework-go/component/storage/leveldb v0.0.0-20221202141134-083803ecf0a3 h1:GF7p/WrgKrhq7d0d9b6nkuW/sidMOwla9Muj4g+BgSY= github.com/hyperledger/aries-framework-go/component/storage/leveldb v0.0.0-20221202141134-083803ecf0a3/go.mod h1:i/bnCdoiv0a9fgHQtd+EiAxmCdaJKE3JYrgDUACKgyE= github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20230427134832-0c9969493bd3 h1:JGYA9l5zTlvsvfnXT9hYPpCokAjmVKX0/r7njba7OX4= diff --git a/test/bdd/pkg/v1/oidc4vc/oidc4ci.go b/test/bdd/pkg/v1/oidc4vc/oidc4ci.go index e831372a8..f8d006b26 100644 --- a/test/bdd/pkg/v1/oidc4vc/oidc4ci.go +++ b/test/bdd/pkg/v1/oidc4vc/oidc4ci.go @@ -19,7 +19,6 @@ import ( "github.com/google/uuid" "github.com/hyperledger/aries-framework-go/component/models/verifiable" - "github.com/hyperledger/aries-framework-go/pkg/wallet" "github.com/ory/fosite" "github.com/samber/lo" "golang.org/x/oauth2" @@ -485,8 +484,7 @@ func getOrgAuthTokenKey(org string) string { } func (s *Steps) checkIssuedCredential() error { - credentialMap, err := s.walletRunner.GetWallet().GetAll( - s.walletRunner.GetConfig().WalletParams.Token, wallet.Credential) + credentialMap, err := s.walletRunner.GetWallet().GetAll() if err != nil { return fmt.Errorf("wallet.GetAll(): %w", err) } diff --git a/test/bdd/pkg/v1/oidc4vc/oidc4vp.go b/test/bdd/pkg/v1/oidc4vc/oidc4vp.go index da5a492ae..e52bf3d4f 100644 --- a/test/bdd/pkg/v1/oidc4vc/oidc4vp.go +++ b/test/bdd/pkg/v1/oidc4vc/oidc4vp.go @@ -18,8 +18,6 @@ import ( "github.com/hyperledger/aries-framework-go/component/models/presexch" "github.com/hyperledger/aries-framework-go/component/models/verifiable" - "github.com/hyperledger/aries-framework-go/pkg/wallet" - "github.com/trustbloc/vcs/component/wallet-cli/pkg/walletrunner" vcs "github.com/trustbloc/vcs/pkg/doc/verifiable" "github.com/trustbloc/vcs/pkg/event/spi" @@ -161,8 +159,7 @@ func (s *Steps) validateRetrievedInteractionsClaim(claimsBytes []byte) error { } // Check whether credentials are known. - credentialMap, err := s.walletRunner.GetWallet().GetAll( - s.walletRunner.GetConfig().WalletParams.Token, wallet.Credential) + credentialMap, err := s.walletRunner.GetWallet().GetAll() if err != nil { return fmt.Errorf("wallet.GetAll(): %w", err) } diff --git a/test/stress/go.mod b/test/stress/go.mod index 55e95dfc7..9fac7fe7d 100644 --- a/test/stress/go.mod +++ b/test/stress/go.mod @@ -92,7 +92,6 @@ require ( github.com/hyperledger/aries-framework-go/component/didconfig v0.0.0-20230622211121-852ce35730b4 // indirect github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0-20230622082138-3ffab1691857 // indirect github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230427134832-0c9969493bd3 // indirect - github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20221025204933-b807371b6f1e // indirect github.com/hyperledger/aries-framework-go/component/storage/leveldb v0.0.0-20221202141134-083803ecf0a3 // indirect github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20230427134832-0c9969493bd3 // indirect github.com/hyperledger/aries-framework-go/component/vdr v0.0.0-20230622171716-43af8054a539 // indirect diff --git a/test/stress/go.sum b/test/stress/go.sum index 9d8820b22..e9522b6e7 100644 --- a/test/stress/go.sum +++ b/test/stress/go.sum @@ -593,8 +593,6 @@ github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230427134832-0c github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230427134832-0c9969493bd3/go.mod h1:CvYs4l8X2NrrF93weLOu5RTOIJeVdoZITtjEflyuTyM= github.com/hyperledger/aries-framework-go/component/models v0.0.0-20230810150537-71e132ba5968 h1:W8F1CA8P/bNb92P/JMYG2nWqv0bxLL58/Q8Rw9nsNyI= github.com/hyperledger/aries-framework-go/component/models v0.0.0-20230810150537-71e132ba5968/go.mod h1:AJkRLmQB1/umL5GfXw/XIarGaH/XCQOL/6wlGtqdDpA= -github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20221025204933-b807371b6f1e h1:/hrQfwJvHJrwV2FSmfnRp5L6yKY9DqDFqwYyb+oVuDU= -github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20221025204933-b807371b6f1e/go.mod h1:ACGP1L+WeecDtyA0Mi2E1kqtPLIGrCWPSJ43q2elwX8= github.com/hyperledger/aries-framework-go/component/storage/leveldb v0.0.0-20221202141134-083803ecf0a3 h1:GF7p/WrgKrhq7d0d9b6nkuW/sidMOwla9Muj4g+BgSY= github.com/hyperledger/aries-framework-go/component/storage/leveldb v0.0.0-20221202141134-083803ecf0a3/go.mod h1:i/bnCdoiv0a9fgHQtd+EiAxmCdaJKE3JYrgDUACKgyE= github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20230427134832-0c9969493bd3 h1:JGYA9l5zTlvsvfnXT9hYPpCokAjmVKX0/r7njba7OX4=