From 99124515b69cbc0f6f7de6bdbe827b3c6bbaf4c8 Mon Sep 17 00:00:00 2001 From: Florin Birsan Date: Fri, 17 Sep 2021 17:22:34 +0300 Subject: [PATCH] fix: mobile bindings missing Orb options Signed-off-by: Florin Birsan --- .../pkg/wrappers/command/aries.go | 2 + .../pkg/wrappers/command/document_loader.go | 90 -------- .../pkg/wrappers/command/introduce_test.go | 6 +- .../contexts/citizenship_v1.jsonld | 0 .../contexts/credentials-examples_v1.jsonld | 0 .../contexts/examples_v1.jsonld | 0 .../{ => testdata}/contexts/governance.jsonld | 0 .../contexts/lds-jws2020-v1.jsonld | 0 .../{ => testdata}/contexts/odrl.jsonld | 0 .../pkg/wrappers/command/vcwallet_test.go | 193 +++++++----------- .../pkg/wrappers/config/options.go | 2 + 11 files changed, 84 insertions(+), 209 deletions(-) delete mode 100644 cmd/agent-mobile/pkg/wrappers/command/document_loader.go rename cmd/agent-mobile/pkg/wrappers/command/{ => testdata}/contexts/citizenship_v1.jsonld (100%) rename cmd/agent-mobile/pkg/wrappers/command/{ => testdata}/contexts/credentials-examples_v1.jsonld (100%) rename cmd/agent-mobile/pkg/wrappers/command/{ => testdata}/contexts/examples_v1.jsonld (100%) rename cmd/agent-mobile/pkg/wrappers/command/{ => testdata}/contexts/governance.jsonld (100%) rename cmd/agent-mobile/pkg/wrappers/command/{ => testdata}/contexts/lds-jws2020-v1.jsonld (100%) rename cmd/agent-mobile/pkg/wrappers/command/{ => testdata}/contexts/odrl.jsonld (100%) diff --git a/cmd/agent-mobile/pkg/wrappers/command/aries.go b/cmd/agent-mobile/pkg/wrappers/command/aries.go index d2079d6c..b2769fcd 100644 --- a/cmd/agent-mobile/pkg/wrappers/command/aries.go +++ b/cmd/agent-mobile/pkg/wrappers/command/aries.go @@ -91,6 +91,8 @@ func NewAries(opts *config.Options) (*Aries, error) { } sdkCommandHandlers, err := sdkcontroller.GetCommandHandlers(context, + sdkcontroller.WithDidAnchorOrigin(opts.DidAnchorOrigin), + sdkcontroller.WithSidetreeToken(opts.SidetreeToken), sdkcontroller.WithBlocDomain(opts.TrustblocDomain), sdkcontroller.WithMessageHandler(msgHandler), sdkcontroller.WithNotifier(notifier.NewNotifier(notifications)), diff --git a/cmd/agent-mobile/pkg/wrappers/command/document_loader.go b/cmd/agent-mobile/pkg/wrappers/command/document_loader.go deleted file mode 100644 index cd05986d..00000000 --- a/cmd/agent-mobile/pkg/wrappers/command/document_loader.go +++ /dev/null @@ -1,90 +0,0 @@ -/* -Copyright SecureKey Technologies Inc. All Rights Reserved. - -SPDX-License-Identifier: Apache-2.0 -*/ - -package command - -import ( - _ "embed" //nolint:gci // required for go:embed - "testing" - - "github.com/hyperledger/aries-framework-go/pkg/doc/ld" - "github.com/hyperledger/aries-framework-go/pkg/doc/ldcontext" - mockldstore "github.com/hyperledger/aries-framework-go/pkg/mock/ld" - ldstore "github.com/hyperledger/aries-framework-go/pkg/store/ld" - "github.com/stretchr/testify/require" -) - -// nolint:gochecknoglobals // embedded test contexts -var ( - //go:embed contexts/credentials-examples_v1.jsonld - credentialExamples []byte - //go:embed contexts/examples_v1.jsonld - vcExamples []byte - //go:embed contexts/odrl.jsonld - odrl []byte - //go:embed contexts/citizenship_v1.jsonld - citizenship []byte - //go:embed contexts/governance.jsonld - governance []byte - //go:embed contexts/lds-jws2020-v1.jsonld - jws2020 []byte -) - -// DocumentLoader returns a document loader with preloaded test contexts. -func DocumentLoader(t *testing.T) *ld.DocumentLoader { - t.Helper() - - ldStore := &mockLDStoreProvider{ - ContextStore: mockldstore.NewMockContextStore(), - RemoteProviderStore: mockldstore.NewMockRemoteProviderStore(), - } - - loader, err := ld.NewDocumentLoader(ldStore, - ld.WithExtraContexts( - ldcontext.Document{ - URL: "https://www.w3.org/2018/credentials/examples/v1", - Content: credentialExamples, - }, - ldcontext.Document{ - URL: "https://trustbloc.github.io/context/vc/examples-v1.jsonld", - Content: vcExamples, - }, - ldcontext.Document{ - URL: "https://www.w3.org/ns/odrl.jsonld", - Content: odrl, - }, - ldcontext.Document{ - URL: "https://w3id.org/citizenship/v1", - DocumentURL: "https://w3c-ccg.github.io/citizenship-vocab/contexts/citizenship-v1.jsonld", - Content: citizenship, - }, - ldcontext.Document{ - URL: "https://trustbloc.github.io/context/governance/context.jsonld", - Content: governance, - }, - ldcontext.Document{ - URL: "https://w3c-ccg.github.io/lds-jws2020/contexts/lds-jws2020-v1.json", - Content: jws2020, - }, - ), - ) - require.NoError(t, err) - - return loader -} - -type mockLDStoreProvider struct { - ContextStore ldstore.ContextStore - RemoteProviderStore ldstore.RemoteProviderStore -} - -func (p *mockLDStoreProvider) JSONLDContextStore() ldstore.ContextStore { - return p.ContextStore -} - -func (p *mockLDStoreProvider) JSONLDRemoteProviderStore() ldstore.RemoteProviderStore { - return p.RemoteProviderStore -} diff --git a/cmd/agent-mobile/pkg/wrappers/command/introduce_test.go b/cmd/agent-mobile/pkg/wrappers/command/introduce_test.go index 3b56f179..517156a7 100644 --- a/cmd/agent-mobile/pkg/wrappers/command/introduce_test.go +++ b/cmd/agent-mobile/pkg/wrappers/command/introduce_test.go @@ -39,11 +39,7 @@ func getAgent() (*Aries, error) { return NewAries(opts) } -func getAgentWithOpts(t *testing.T) (*Aries, error) { - t.Helper() - - opts := &config.Options{DocumentLoader: DocumentLoader(t)} - +func getAgentWithOpts(opts *config.Options) (*Aries, error) { return NewAries(opts) } diff --git a/cmd/agent-mobile/pkg/wrappers/command/contexts/citizenship_v1.jsonld b/cmd/agent-mobile/pkg/wrappers/command/testdata/contexts/citizenship_v1.jsonld similarity index 100% rename from cmd/agent-mobile/pkg/wrappers/command/contexts/citizenship_v1.jsonld rename to cmd/agent-mobile/pkg/wrappers/command/testdata/contexts/citizenship_v1.jsonld diff --git a/cmd/agent-mobile/pkg/wrappers/command/contexts/credentials-examples_v1.jsonld b/cmd/agent-mobile/pkg/wrappers/command/testdata/contexts/credentials-examples_v1.jsonld similarity index 100% rename from cmd/agent-mobile/pkg/wrappers/command/contexts/credentials-examples_v1.jsonld rename to cmd/agent-mobile/pkg/wrappers/command/testdata/contexts/credentials-examples_v1.jsonld diff --git a/cmd/agent-mobile/pkg/wrappers/command/contexts/examples_v1.jsonld b/cmd/agent-mobile/pkg/wrappers/command/testdata/contexts/examples_v1.jsonld similarity index 100% rename from cmd/agent-mobile/pkg/wrappers/command/contexts/examples_v1.jsonld rename to cmd/agent-mobile/pkg/wrappers/command/testdata/contexts/examples_v1.jsonld diff --git a/cmd/agent-mobile/pkg/wrappers/command/contexts/governance.jsonld b/cmd/agent-mobile/pkg/wrappers/command/testdata/contexts/governance.jsonld similarity index 100% rename from cmd/agent-mobile/pkg/wrappers/command/contexts/governance.jsonld rename to cmd/agent-mobile/pkg/wrappers/command/testdata/contexts/governance.jsonld diff --git a/cmd/agent-mobile/pkg/wrappers/command/contexts/lds-jws2020-v1.jsonld b/cmd/agent-mobile/pkg/wrappers/command/testdata/contexts/lds-jws2020-v1.jsonld similarity index 100% rename from cmd/agent-mobile/pkg/wrappers/command/contexts/lds-jws2020-v1.jsonld rename to cmd/agent-mobile/pkg/wrappers/command/testdata/contexts/lds-jws2020-v1.jsonld diff --git a/cmd/agent-mobile/pkg/wrappers/command/contexts/odrl.jsonld b/cmd/agent-mobile/pkg/wrappers/command/testdata/contexts/odrl.jsonld similarity index 100% rename from cmd/agent-mobile/pkg/wrappers/command/contexts/odrl.jsonld rename to cmd/agent-mobile/pkg/wrappers/command/testdata/contexts/odrl.jsonld diff --git a/cmd/agent-mobile/pkg/wrappers/command/vcwallet_test.go b/cmd/agent-mobile/pkg/wrappers/command/vcwallet_test.go index 5981dbce..d3d9052c 100644 --- a/cmd/agent-mobile/pkg/wrappers/command/vcwallet_test.go +++ b/cmd/agent-mobile/pkg/wrappers/command/vcwallet_test.go @@ -7,18 +7,22 @@ SPDX-License-Identifier: Apache-2.0 package command // nolint:testpackage // uses internal implementation details import ( + _ "embed" //nolint:gci // required for go:embed "encoding/json" "fmt" "testing" + "github.com/trustbloc/agent-sdk/cmd/agent-mobile/pkg/wrappers/config" "github.com/trustbloc/agent-sdk/cmd/agent-mobile/pkg/wrappers/models" cmdvcwallet "github.com/hyperledger/aries-framework-go/pkg/controller/command/vcwallet" - + "github.com/hyperledger/aries-framework-go/pkg/doc/ld" + "github.com/hyperledger/aries-framework-go/pkg/doc/ldcontext" + mockldstore "github.com/hyperledger/aries-framework-go/pkg/mock/ld" + ldstore "github.com/hyperledger/aries-framework-go/pkg/store/ld" "github.com/stretchr/testify/require" ) -// nolint: lll const ( sampleUserAuth = `{"userID":"user1", "localKMSPassphrase": "fakepassphrase"}` sampleUDCVC = `{ @@ -126,68 +130,84 @@ const ( ], "required": true }` - sampleKeyContentBase58 = `{ - "@context": ["https://w3id.org/wallet/v1"], - "id": "did:key:z6MknC1wwS6DEYwtGbZZo2QvjQjkh2qSBjb4GYmbye8dv4S5#z6MknC1wwS6DEYwtGbZZo2QvjQjkh2qSBjb4GYmbye8dv4S5", - "controller": "did:example:123456789abcdefghi", - "type": "Ed25519VerificationKey2018", - "privateKeyBase58":"2MP5gWCnf67jvW3E4Lz8PpVrDWAXMYY1sDxjnkEnKhkkbKD7yP2mkVeyVpu5nAtr3TeDgMNjBPirk2XcQacs3dvZ" - }` - sampleDIDResolutionResponse = `{ - "@context": [ - "https://w3id.org/wallet/v1", - "https://w3id.org/did-resolution/v1" - ], - "id": "did:key:z6MknC1wwS6DEYwtGbZZo2QvjQjkh2qSBjb4GYmbye8dv4S5", - "type": ["DIDResolutionResponse"], - "name": "Farming Sensor DID Document", - "image": "https://via.placeholder.com/150", - "description": "An IoT device in the middle of a corn field.", - "tags": ["professional"], - "correlation": ["4058a72a-9523-11ea-bb37-0242ac130002"], - "created": "2017-06-18T21:19:10Z", - "expires": "2026-06-18T21:19:10Z", - "didDocument": { - "@context": [ - "https://w3id.org/did/v0.11" - ], - "id": "did:key:z6MknC1wwS6DEYwtGbZZo2QvjQjkh2qSBjb4GYmbye8dv4S5", - "publicKey": [ - { - "id": "did:key:z6MknC1wwS6DEYwtGbZZo2QvjQjkh2qSBjb4GYmbye8dv4S5#z6MknC1wwS6DEYwtGbZZo2QvjQjkh2qSBjb4GYmbye8dv4S5", - "type": "Ed25519VerificationKey2018", - "controller": "did:key:z6MknC1wwS6DEYwtGbZZo2QvjQjkh2qSBjb4GYmbye8dv4S5", - "publicKeyBase58": "8jkuMBqmu1TRA6is7TT5tKBksTZamrLhaXrg9NAczqeh" - } - ], - "authentication": [ - "did:key:z6MknC1wwS6DEYwtGbZZo2QvjQjkh2qSBjb4GYmbye8dv4S5#z6MknC1wwS6DEYwtGbZZo2QvjQjkh2qSBjb4GYmbye8dv4S5" - ], - "assertionMethod": [ - "did:key:z6MknC1wwS6DEYwtGbZZo2QvjQjkh2qSBjb4GYmbye8dv4S5#z6MknC1wwS6DEYwtGbZZo2QvjQjkh2qSBjb4GYmbye8dv4S5" - ], - "capabilityDelegation": [ - "did:key:z6MknC1wwS6DEYwtGbZZo2QvjQjkh2qSBjb4GYmbye8dv4S5#z6MknC1wwS6DEYwtGbZZo2QvjQjkh2qSBjb4GYmbye8dv4S5" - ], - "capabilityInvocation": [ - "did:key:z6MknC1wwS6DEYwtGbZZo2QvjQjkh2qSBjb4GYmbye8dv4S5#z6MknC1wwS6DEYwtGbZZo2QvjQjkh2qSBjb4GYmbye8dv4S5" - ], - "keyAgreement": [ - { - "id": "did:key:z6MknC1wwS6DEYwtGbZZo2QvjQjkh2qSBjb4GYmbye8dv4S5#z6LSmjNfS5FC9W59JtPZq7fHgrjThxsidjEhZeMxCarbR998", - "type": "X25519KeyAgreementKey2019", - "controller": "did:key:z6MknC1wwS6DEYwtGbZZo2QvjQjkh2qSBjb4GYmbye8dv4S5", - "publicKeyBase58": "B4CVumSL43MQDW1oJU9LNGWyrpLbw84YgfeGi8D4hmNN" - } - ] - } - }` ) +// nolint:gochecknoglobals // embedded test contexts +var ( + //go:embed testdata/contexts/credentials-examples_v1.jsonld + credentialExamples []byte + //go:embed testdata/contexts/examples_v1.jsonld + vcExamples []byte + //go:embed testdata/contexts/odrl.jsonld + odrl []byte + //go:embed testdata/contexts/citizenship_v1.jsonld + citizenship []byte + //go:embed testdata/contexts/governance.jsonld + governance []byte + //go:embed testdata/contexts/lds-jws2020-v1.jsonld + jws2020 []byte +) + +// DocumentLoader returns a document loader with preloaded test contexts. +func DocumentLoader(t *testing.T) *ld.DocumentLoader { + t.Helper() + + ldStore := &mockLDStoreProvider{ + ContextStore: mockldstore.NewMockContextStore(), + RemoteProviderStore: mockldstore.NewMockRemoteProviderStore(), + } + + loader, err := ld.NewDocumentLoader(ldStore, + ld.WithExtraContexts( + ldcontext.Document{ + URL: "https://www.w3.org/2018/credentials/examples/v1", + Content: credentialExamples, + }, + ldcontext.Document{ + URL: "https://trustbloc.github.io/context/vc/examples-v1.jsonld", + Content: vcExamples, + }, + ldcontext.Document{ + URL: "https://www.w3.org/ns/odrl.jsonld", + Content: odrl, + }, + ldcontext.Document{ + URL: "https://w3id.org/citizenship/v1", + DocumentURL: "https://w3c-ccg.github.io/citizenship-vocab/contexts/citizenship-v1.jsonld", + Content: citizenship, + }, + ldcontext.Document{ + URL: "https://trustbloc.github.io/context/governance/context.jsonld", + Content: governance, + }, + ldcontext.Document{ + URL: "https://w3c-ccg.github.io/lds-jws2020/contexts/lds-jws2020-v1.json", + Content: jws2020, + }, + ), + ) + require.NoError(t, err) + + return loader +} + +type mockLDStoreProvider struct { + ContextStore ldstore.ContextStore + RemoteProviderStore ldstore.RemoteProviderStore +} + +func (p *mockLDStoreProvider) JSONLDContextStore() ldstore.ContextStore { + return p.ContextStore +} + +func (p *mockLDStoreProvider) JSONLDRemoteProviderStore() ldstore.RemoteProviderStore { + return p.RemoteProviderStore +} + func getVCWalletController(t *testing.T) *VCWallet { t.Helper() - a, err := getAgentWithOpts(t) + a, err := getAgentWithOpts(&config.Options{DocumentLoader: DocumentLoader(t)}) require.NotNil(t, a) require.NoError(t, err) @@ -488,58 +508,3 @@ func TestVCWallet_Add_Get_GetAll(t *testing.T) { require.NotNil(t, resp.Error) }) } - -// nolint: lll -func TestVCWallet_Issue(t *testing.T) { - vcwalletController := getVCWalletController(t) - require.NotNil(t, vcwalletController) - - var tokenResponse cmdvcwallet.UnlockWalletResponse - - // create profile - createProfilePayload := sampleUserAuth - createProfileReq := &models.RequestEnvelope{Payload: []byte(createProfilePayload)} - createProfileResp := vcwalletController.CreateProfile(createProfileReq) - require.NotNil(t, createProfileResp) - require.Nil(t, createProfileResp.Error) - require.Equal(t, - ``, - string(createProfileResp.Payload)) - - // open the wallet - openPayload := sampleUserAuth - openReq := &models.RequestEnvelope{Payload: []byte(openPayload)} - - openResp := vcwalletController.Open(openReq) - require.NotNil(t, openResp) - require.Nil(t, openResp.Error) - - if err := json.Unmarshal(openResp.Payload, &tokenResponse); err != nil { - t.Fail() - } else { - require.NotNil(t, - tokenResponse.Token) - require.NotEqual(t, - ``, - tokenResponse.Token) - } - - // add proper content - addPayload := fmt.Sprintf(`{"userID":"user1", "auth": "%s", "contentType":"key", "content":%s}`, tokenResponse.Token, sampleKeyContentBase58) - - addContent(t, vcwalletController, addPayload) - - addPayload = fmt.Sprintf(`{"userID":"user1", "auth": "%s", "contentType":"didResolutionResponse", "content":%s}`, tokenResponse.Token, sampleDIDResolutionResponse) - - addContent(t, vcwalletController, addPayload) -} - -func addContent(t *testing.T, vcwalletController *VCWallet, addPayload string) { - t.Helper() - - addReq := &models.RequestEnvelope{Payload: []byte(addPayload)} - addResp := vcwalletController.Add(addReq) - - require.NotNil(t, addResp) - require.Nil(t, addResp.Error) -} diff --git a/cmd/agent-mobile/pkg/wrappers/config/options.go b/cmd/agent-mobile/pkg/wrappers/config/options.go index db269228..3636478a 100644 --- a/cmd/agent-mobile/pkg/wrappers/config/options.go +++ b/cmd/agent-mobile/pkg/wrappers/config/options.go @@ -25,6 +25,8 @@ type Options struct { TrustblocDomain string TrustblocResolver string WebsocketURL string + SidetreeToken string + DidAnchorOrigin string Logger api.LoggerProvider Storage api.Provider DocumentLoader ld.DocumentLoader