From c9c7aa822d2826c8e4cca7f0c7cc83fa746e8952 Mon Sep 17 00:00:00 2001 From: Volodymyr Kubiv Date: Tue, 13 Jun 2023 17:17:00 +0300 Subject: [PATCH] fix(sdk,app)!: performance of json-ld VCs Signed-off-by: Volodymyr Kubiv --- .../credential/inquirer.go | 12 +- .../credential/inquirer_test.go | 28 ++- cmd/wallet-sdk-gomobile/docs/usage.md | 3 +- cmd/wallet-sdk-gomobile/go.mod | 2 +- .../openid4ci/interaction.go | 18 +- .../openid4ci/interaction_test.go | 15 ++ .../openid4vp/interaction.go | 15 +- .../openid4vp/interaction_test.go | 17 ++ .../kotlin/walletsdk/openid4ci/OpenID4CI.kt | 2 + .../kotlin/walletsdk/openid4vp/OpenID4VP.kt | 2 + demo/app/ios/Runner/OpenID4VP.swift | 2 +- .../ios/Runner/Tests/IntegrationTest.swift | 5 +- demo/app/lib/assets/issuerAuthFlowConfig.json | 70 +++--- go.mod | 2 +- pkg/common/contexts/citizenship_v1.jsonld | 54 +++++ .../contexts/credentials-examples_v1.jsonld | 47 ++++ pkg/common/contexts/examples_v1.jsonld | 16 ++ pkg/common/contexts/lds-jws2020-v1.jsonld | 53 +++++ pkg/common/contexts/odrl.jsonld | 200 ++++++++++++++++++ pkg/common/doc_loader.go | 93 ++++++++ pkg/common/doc_loader_test.go | 40 ++++ pkg/openid4vp/openid4vp.go | 14 +- pkg/openid4vp/openid4vp_test.go | 5 +- pkg/openid4vp/opts.go | 20 +- test/integration/openid4vp_test.go | 13 +- 25 files changed, 658 insertions(+), 90 deletions(-) create mode 100644 pkg/common/contexts/citizenship_v1.jsonld create mode 100644 pkg/common/contexts/credentials-examples_v1.jsonld create mode 100644 pkg/common/contexts/examples_v1.jsonld create mode 100644 pkg/common/contexts/lds-jws2020-v1.jsonld create mode 100644 pkg/common/contexts/odrl.jsonld create mode 100644 pkg/common/doc_loader.go create mode 100644 pkg/common/doc_loader_test.go diff --git a/cmd/wallet-sdk-gomobile/credential/inquirer.go b/cmd/wallet-sdk-gomobile/credential/inquirer.go index a90bff74..1d8c88a6 100644 --- a/cmd/wallet-sdk-gomobile/credential/inquirer.go +++ b/cmd/wallet-sdk-gomobile/credential/inquirer.go @@ -17,11 +17,13 @@ import ( "github.com/hyperledger/aries-framework-go/component/models/presexch" afgoverifiable "github.com/hyperledger/aries-framework-go/component/models/verifiable" + "github.com/hyperledger/aries-framework-go/component/storageutil/mem" "github.com/piprate/json-gold/ld" "github.com/trustbloc/wallet-sdk/cmd/wallet-sdk-gomobile/verifiable" "github.com/trustbloc/wallet-sdk/cmd/wallet-sdk-gomobile/wrapper" goapi "github.com/trustbloc/wallet-sdk/pkg/api" + "github.com/trustbloc/wallet-sdk/pkg/common" "github.com/trustbloc/wallet-sdk/pkg/credentialquery" ) @@ -32,7 +34,7 @@ type Inquirer struct { } // NewInquirer returns a new Inquirer. -func NewInquirer(opts *InquirerOpts) *Inquirer { +func NewInquirer(opts *InquirerOpts) (*Inquirer, error) { if opts == nil { opts = &InquirerOpts{} } @@ -52,7 +54,11 @@ func NewInquirer(opts *InquirerOpts) *Inquirer { httpClient.Timeout = goapi.DefaultHTTPTimeout } - goAPIDocumentLoader = ld.NewDefaultDocumentLoader(httpClient) + var err error + goAPIDocumentLoader, err = common.CreateJSONLDDocumentLoader(httpClient, mem.NewProvider()) + if err != nil { + return nil, wrapper.ToMobileError(err) + } } var goDIDResolver goapi.DIDResolver @@ -63,7 +69,7 @@ func NewInquirer(opts *InquirerOpts) *Inquirer { return &Inquirer{ goAPICredentialQuery: credentialquery.NewInstance(goAPIDocumentLoader), goDIDResolver: goDIDResolver, - } + }, nil } // GetSubmissionRequirements returns information about VCs matching requirements. diff --git a/cmd/wallet-sdk-gomobile/credential/inquirer_test.go b/cmd/wallet-sdk-gomobile/credential/inquirer_test.go index 61a0a28c..0c557b70 100644 --- a/cmd/wallet-sdk-gomobile/credential/inquirer_test.go +++ b/cmd/wallet-sdk-gomobile/credential/inquirer_test.go @@ -52,12 +52,14 @@ func TestNewInquirer(t *testing.T) { t.Run("Using the default network-based document loader", func(t *testing.T) { opts := credential.NewInquirerOpts().SetHTTPTimeoutNanoseconds(0) - inquirer := credential.NewInquirer(opts) + inquirer, err := credential.NewInquirer(opts) + require.NoError(t, err) require.NotNil(t, inquirer) }) t.Run("Default opts", func(t *testing.T) { - inquirer := credential.NewInquirer(nil) + inquirer, err := credential.NewInquirer(nil) + require.NoError(t, err) require.NotNil(t, inquirer) }) } @@ -80,7 +82,8 @@ func TestInstance_GetSubmissionRequirements(t *testing.T) { opts.SetDIDResolver(&mocksDIDResolver{}) t.Run("Success", func(t *testing.T) { - query := credential.NewInquirer(opts) + query, err := credential.NewInquirer(opts) + require.NoError(t, err) requirements, err := query.GetSubmissionRequirements(multiInputPD, createCredJSONArray(t, contents)) @@ -106,7 +109,8 @@ func TestInstance_GetSubmissionRequirements(t *testing.T) { }) t.Run("Success nested requirements", func(t *testing.T) { - query := credential.NewInquirer(opts) + query, err := credential.NewInquirer(opts) + require.NoError(t, err) requirements, err := query.GetSubmissionRequirements(nestedRequirementsPD, createCredJSONArray(t, contents)) @@ -134,9 +138,10 @@ func TestInstance_GetSubmissionRequirements(t *testing.T) { }) t.Run("PD parse failed", func(t *testing.T) { - query := credential.NewInquirer(opts) + query, err := credential.NewInquirer(opts) + require.NoError(t, err) - _, err := query.GetSubmissionRequirements(nil, + _, err = query.GetSubmissionRequirements(nil, createCredJSONArray(t, [][]byte{universityDegreeVCJWT, permanentResidentCardVC}), ) @@ -144,9 +149,10 @@ func TestInstance_GetSubmissionRequirements(t *testing.T) { }) t.Run("PD validation failed", func(t *testing.T) { - query := credential.NewInquirer(opts) + query, err := credential.NewInquirer(opts) + require.NoError(t, err) - _, err := query.GetSubmissionRequirements([]byte("{}"), + _, err = query.GetSubmissionRequirements([]byte("{}"), createCredJSONArray(t, [][]byte{universityDegreeVCJWT, permanentResidentCardVC}), ) @@ -154,7 +160,8 @@ func TestInstance_GetSubmissionRequirements(t *testing.T) { }) t.Run("Nil credentials", func(t *testing.T) { - query := credential.NewInquirer(opts) + query, err := credential.NewInquirer(opts) + require.NoError(t, err) submissionRequirements, err := query.GetSubmissionRequirements(nil, nil) @@ -178,7 +185,8 @@ func TestInstance_GetSubmissionRequirementsCitizenship(t *testing.T) { opts.SetDIDResolver(&mocksDIDResolver{}) t.Run("Success", func(t *testing.T) { - query := credential.NewInquirer(opts) + query, err := credential.NewInquirer(opts) + require.NoError(t, err) requirements, err := query.GetSubmissionRequirements(citizenshipPD, createCredJSONArray(t, contents)) diff --git a/cmd/wallet-sdk-gomobile/docs/usage.md b/cmd/wallet-sdk-gomobile/docs/usage.md index 3d99867a..33ee7365 100644 --- a/cmd/wallet-sdk-gomobile/docs/usage.md +++ b/cmd/wallet-sdk-gomobile/docs/usage.md @@ -1145,7 +1145,8 @@ let opts = Openid4vpNewOpts().setActivityLogger(activityLogger) // Optional, but var newInteractionError: NSError? let interaction = Openid4vpNewInteraction(args, opts, &newInteractionError) let query = interaction.getQuery() -let inquirer = CredentialNewInquirer(nil) +var newInquirerError: NSError? +let inquirer = CredentialNewInquirer(nil, &newInquirerError) let savedCredentials = VerifiableCredentialsArray() // Would need some actual credentials for this to work // Use this code to display information about the verifier. diff --git a/cmd/wallet-sdk-gomobile/go.mod b/cmd/wallet-sdk-gomobile/go.mod index cbd7b278..e823fa76 100644 --- a/cmd/wallet-sdk-gomobile/go.mod +++ b/cmd/wallet-sdk-gomobile/go.mod @@ -13,6 +13,7 @@ require ( github.com/hyperledger/aries-framework-go v0.3.3-0.20230615141038-5d444d6c36de github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0-20230615141038-5d444d6c36de github.com/hyperledger/aries-framework-go/component/models v0.0.0-20230615141038-5d444d6c36de + github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20230427134832-0c9969493bd3 github.com/hyperledger/aries-framework-go/component/vdr v0.0.0-20230615141038-5d444d6c36de github.com/hyperledger/aries-framework-go/spi v0.0.0-20230615141038-5d444d6c36de github.com/piprate/json-gold v0.5.1-0.20230111113000-6ddbe6e6f19f @@ -41,7 +42,6 @@ require ( github.com/hyperledger/aries-framework-go-ext/component/vdr/longform v0.0.0-20221209153644-5a3273a805c1 // 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/storageutil v0.0.0-20230427134832-0c9969493bd3 // indirect github.com/hyperledger/fabric-amcl v0.0.0-20230602173724-9e02669dceb2 // indirect github.com/hyperledger/ursa-wrapper-go v0.3.1 // indirect github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect diff --git a/cmd/wallet-sdk-gomobile/openid4ci/interaction.go b/cmd/wallet-sdk-gomobile/openid4ci/interaction.go index c55cd470..5e51c30f 100644 --- a/cmd/wallet-sdk-gomobile/openid4ci/interaction.go +++ b/cmd/wallet-sdk-gomobile/openid4ci/interaction.go @@ -12,6 +12,7 @@ import ( "errors" afgoverifiable "github.com/hyperledger/aries-framework-go/component/models/verifiable" + "github.com/hyperledger/aries-framework-go/component/storageutil/mem" "github.com/trustbloc/wallet-sdk/cmd/wallet-sdk-gomobile/api" "github.com/trustbloc/wallet-sdk/cmd/wallet-sdk-gomobile/otel" @@ -55,7 +56,10 @@ func NewInteraction(args *InteractionArgs, opts *InteractionOpts) (*Interaction, opts.AddHeader(oTel.TraceHeader()) } - goAPIClientConfig := createGoAPIClientConfig(args, opts) + goAPIClientConfig, err := createGoAPIClientConfig(args, opts) + if err != nil { + return nil, wrapper.ToMobileErrorWithTrace(err, oTel) + } goAPIInteraction, err := openid4cigoapi.NewInteraction(args.initiateIssuanceURI, goAPIClientConfig) if err != nil { @@ -213,7 +217,7 @@ func (i *Interaction) createSigner(vm *api.VerificationMethod) (*common.JWSSigne func createGoAPIClientConfig(config *InteractionArgs, opts *InteractionOpts, -) *openid4cigoapi.ClientConfig { +) (*openid4cigoapi.ClientConfig, error) { activityLogger := createGoAPIActivityLogger(opts.activityLogger) httpClient := wrapper.NewHTTPClient(opts.httpTimeout, opts.additionalHeaders, opts.disableHTTPClientTLSVerification) @@ -233,9 +237,17 @@ func createGoAPIClientConfig(config *InteractionArgs, } goAPIClientConfig.DocumentLoader = documentLoaderWrapper + } else { + dlHTTPClient := wrapper.NewHTTPClient(opts.httpTimeout, api.Headers{}, opts.disableHTTPClientTLSVerification) + + var err error + goAPIClientConfig.DocumentLoader, err = common.CreateJSONLDDocumentLoader(dlHTTPClient, mem.NewProvider()) + if err != nil { + return nil, err + } } - return goAPIClientConfig + return goAPIClientConfig, nil } func createGoAPIActivityLogger(mobileAPIActivityLogger api.ActivityLogger) goapi.ActivityLogger { diff --git a/cmd/wallet-sdk-gomobile/openid4ci/interaction_test.go b/cmd/wallet-sdk-gomobile/openid4ci/interaction_test.go index 9e09a9a4..5a7e3612 100644 --- a/cmd/wallet-sdk-gomobile/openid4ci/interaction_test.go +++ b/cmd/wallet-sdk-gomobile/openid4ci/interaction_test.go @@ -84,6 +84,21 @@ func TestNewInteraction(t *testing.T) { require.NotNil(t, interaction) }) + t.Run("Success HTTP timeout", func(t *testing.T) { + kms, err := localkms.NewKMS(localkms.NewMemKMSStore()) + require.NoError(t, err) + + resolver := &mockResolver{keyWriter: kms} + + requiredArgs := openid4ci.NewInteractionArgs(createTestRequestURI("example.com"), kms.GetCrypto(), resolver) + opts := openid4ci.NewInteractionOpts() + opts.SetHTTPTimeoutNanoseconds((10 * time.Second).Nanoseconds()) + + interaction, err := openid4ci.NewInteraction(requiredArgs, opts) + require.NoError(t, err) + require.NotNil(t, interaction) + }) + t.Run("Failed, args is nil", func(t *testing.T) { interaction, err := openid4ci.NewInteraction(nil, nil) require.Error(t, err) diff --git a/cmd/wallet-sdk-gomobile/openid4vp/interaction.go b/cmd/wallet-sdk-gomobile/openid4vp/interaction.go index e7bb8607..50aa3661 100644 --- a/cmd/wallet-sdk-gomobile/openid4vp/interaction.go +++ b/cmd/wallet-sdk-gomobile/openid4vp/interaction.go @@ -15,6 +15,7 @@ import ( "github.com/hyperledger/aries-framework-go/component/models/jwt" "github.com/hyperledger/aries-framework-go/component/models/presexch" afgoverifiable "github.com/hyperledger/aries-framework-go/component/models/verifiable" + "github.com/hyperledger/aries-framework-go/component/storageutil/mem" "github.com/piprate/json-gold/ld" "github.com/trustbloc/wallet-sdk/cmd/wallet-sdk-gomobile/api" @@ -92,11 +93,23 @@ func NewInteraction(args *Args, opts *Opts) (*Interaction, error) { //nolint:fun goAPIDocumentLoader = &wrapper.DocumentLoaderWrapper{ DocumentLoader: opts.documentLoader, } + } else { + dlHTTPClient := wrapper.NewHTTPClient(opts.httpTimeout, api.Headers{}, opts.disableHTTPClientTLSVerification) + + var err error + goAPIDocumentLoader, err = common.CreateJSONLDDocumentLoader(dlHTTPClient, mem.NewProvider()) + if err != nil { + return nil, wrapper.ToMobileErrorWithTrace(err, oTel) + } } inquirerOpts := credential.NewInquirerOpts() inquirerOpts.SetDocumentLoader(opts.documentLoader) - inquirer := credential.NewInquirer(inquirerOpts) + + inquirer, err := credential.NewInquirer(inquirerOpts) + if err != nil { + return nil, err + } return &Interaction{ ldDocumentLoader: opts.documentLoader, diff --git a/cmd/wallet-sdk-gomobile/openid4vp/interaction_test.go b/cmd/wallet-sdk-gomobile/openid4vp/interaction_test.go index 63d732ae..60065ae0 100644 --- a/cmd/wallet-sdk-gomobile/openid4vp/interaction_test.go +++ b/cmd/wallet-sdk-gomobile/openid4vp/interaction_test.go @@ -94,6 +94,23 @@ func TestOpenID4VP_GetQuery(t *testing.T) { require.NotNil(t, instance) require.Empty(t, instance.OTelTraceID()) }) + + t.Run("With Document loader", func(t *testing.T) { + requiredArgs := NewArgs( + requestObjectJWT, + &mockCrypto{}, + &mocksDIDResolver{}, + ) + + // Note: in-depth testing of opts functionality is done in the integration tests. + opts := NewOpts() + opts.SetDocumentLoader(&documentLoaderWrapper{goAPIDocumentLoader: testutil.DocumentLoader(t)}) + + instance, err := NewInteraction(requiredArgs, opts) + require.NoError(t, err) + require.NotNil(t, instance) + require.NotEmpty(t, instance.OTelTraceID()) + }) }) t.Run("GetQuery success", func(t *testing.T) { diff --git a/demo/app/android/app/src/main/kotlin/walletsdk/openid4ci/OpenID4CI.kt b/demo/app/android/app/src/main/kotlin/walletsdk/openid4ci/OpenID4CI.kt index e269855b..088b407d 100644 --- a/demo/app/android/app/src/main/kotlin/walletsdk/openid4ci/OpenID4CI.kt +++ b/demo/app/android/app/src/main/kotlin/walletsdk/openid4ci/OpenID4CI.kt @@ -4,6 +4,7 @@ import dev.trustbloc.wallet.sdk.api.* import dev.trustbloc.wallet.sdk.display.* import dev.trustbloc.wallet.sdk.openid4ci.* import dev.trustbloc.wallet.sdk.otel.Otel +import dev.trustbloc.wallet.sdk.stderr.MetricsLogger import dev.trustbloc.wallet.sdk.verifiable.Credential import dev.trustbloc.wallet.sdk.verifiable.CredentialsArray @@ -23,6 +24,7 @@ class OpenID4CI constructor( val opts = InteractionOpts() opts.addHeader(trace.traceHeader()) opts.setActivityLogger(activityLogger) + opts.setMetricsLogger(MetricsLogger()) newInteraction = Interaction(args, opts) } diff --git a/demo/app/android/app/src/main/kotlin/walletsdk/openid4vp/OpenID4VP.kt b/demo/app/android/app/src/main/kotlin/walletsdk/openid4vp/OpenID4VP.kt index f97a0219..d3070bf2 100644 --- a/demo/app/android/app/src/main/kotlin/walletsdk/openid4vp/OpenID4VP.kt +++ b/demo/app/android/app/src/main/kotlin/walletsdk/openid4vp/OpenID4VP.kt @@ -14,6 +14,7 @@ import dev.trustbloc.wallet.sdk.openid4vp.Args import dev.trustbloc.wallet.sdk.openid4vp.VerifierDisplayData import dev.trustbloc.wallet.sdk.otel.Otel import dev.trustbloc.wallet.sdk.verifiable.CredentialsArray +import dev.trustbloc.wallet.sdk.stderr.MetricsLogger import java.lang.Exception class OpenID4VP constructor( @@ -39,6 +40,7 @@ class OpenID4VP constructor( val opts = Opts() opts.setActivityLogger(activityLogger) opts.addHeader(trace.traceHeader()) + opts.setMetricsLogger(MetricsLogger()) val interaction = Interaction(args, opts) diff --git a/demo/app/ios/Runner/OpenID4VP.swift b/demo/app/ios/Runner/OpenID4VP.swift index 1bc628f4..0f44584c 100644 --- a/demo/app/ios/Runner/OpenID4VP.swift +++ b/demo/app/ios/Runner/OpenID4VP.swift @@ -53,7 +53,7 @@ public class OpenID4VP { throw OpenID4VPError.runtimeError("OpenID4VP interaction not properly initialized, call processAuthorizationRequest first") } - return try CredentialNewInquirer(CredentialInquirerOpts()?.setDIDResolver(didResolver))!.getSubmissionRequirements(vpQueryContent, credentials: storedCredentials) + return try CredentialNewInquirer(CredentialInquirerOpts()?.setDIDResolver(didResolver), nil)!.getSubmissionRequirements(vpQueryContent, credentials: storedCredentials) } /** diff --git a/demo/app/ios/Runner/Tests/IntegrationTest.swift b/demo/app/ios/Runner/Tests/IntegrationTest.swift index 215923ae..7cba7382 100644 --- a/demo/app/ios/Runner/Tests/IntegrationTest.swift +++ b/demo/app/ios/Runner/Tests/IntegrationTest.swift @@ -69,7 +69,10 @@ class IntegrationTest: XCTestCase { let vpInteraction = Openid4vpNewInteraction(openID4VPArgs, opts, nil)! let credentialsQuery = try vpInteraction.getQuery() - let inquirer = CredentialNewInquirer(nil)! + + var newInquirerError: NSError? + let inquirer = CredentialNewInquirer(nil, &newInquirerError)! + XCTAssertNil(newInquirerError) let submissionRequirements = try inquirer.getSubmissionRequirements( credentialsQuery, credentials: issuedCreds) diff --git a/demo/app/lib/assets/issuerAuthFlowConfig.json b/demo/app/lib/assets/issuerAuthFlowConfig.json index 195ea31f..dc63bde7 100644 --- a/demo/app/lib/assets/issuerAuthFlowConfig.json +++ b/demo/app/lib/assets/issuerAuthFlowConfig.json @@ -1,49 +1,65 @@ { - "https://api-gateway.dev.trustbloc.dev/issuer/bank_issuer/v1.0": - { - "scopes": ["openid","profile"], - "clientID": "oidc4vc_client", - "redirectURI": "trustbloc-wallet://openid4vci/authcodeflow/callback" - }, - "https://api-gateway.stg.trustbloc.dev/issuer/bank_issuer/v1.0": - { - "scopes": ["openid","profile"], + "https://api-gateway.dev.trustbloc.dev/issuer/bank_issuer/v1.0": { + "scopes": [ + "openid", + "profile" + ], "clientID": "oidc4vc_client", "redirectURI": "trustbloc-wallet://openid4vci/authcodeflow/callback" }, - "https://api-gateway.dev.trustbloc.dev/issuer/pr_card_issuer_jwtsd/v1.0": - { - "scopes": ["openid","profile"], + "https://api-gateway.stg.trustbloc.dev/issuer/bank_issuer/v1.0": { + "scopes": [ + "openid", + "profile" + ], "clientID": "oidc4vc_client", "redirectURI": "trustbloc-wallet://openid4vci/authcodeflow/callback" }, - "https://api-gateway.stg.trustbloc.dev/issuer/pr_card_issuer_jwtsd/v1.0": - { - "scopes": ["openid","profile"], + "https://api-gateway.dev.trustbloc.dev/issuer/pr_card_issuer_jwtsd/v1.0": { + "scopes": [ + "openid", + "profile" + ], "clientID": "oidc4vc_client", "redirectURI": "trustbloc-wallet://openid4vci/authcodeflow/callback" }, - "https://api-gateway.dev.trustbloc.dev/issuer/vaccination_certificate_issuer/v1.0": - { - "scopes": ["openid","profile"], + "https://api-gateway.stg.trustbloc.dev/issuer/pr_card_issuer_jwtsd/v1.0": { + "scopes": [ + "openid", + "profile" + ], "clientID": "oidc4vc_client", "redirectURI": "trustbloc-wallet://openid4vci/authcodeflow/callback" }, - "https://api-gateway.stg.trustbloc.dev/issuer/vaccination_certificate_issuer/v1.0": - { - "scopes": ["openid","profile"], + "https://api-gateway.dev.trustbloc.dev/issuer/vaccination_certificate_issuer/v1.0": { + "scopes": [ + "openid", + "profile" + ], "clientID": "oidc4vc_client", "redirectURI": "trustbloc-wallet://openid4vci/authcodeflow/callback" }, - "https://api-gateway.dev.trustbloc.dev/vcs-localkms/issuer/university_degree_issuer_bbs/v1.0": - { - "scopes": ["openid","profile"], + "https://api-gateway.stg.trustbloc.dev/issuer/vaccination_certificate_issuer/v1.0": { + "scopes": [ + "openid", + "profile" + ], "clientID": "oidc4vc_client", "redirectURI": "trustbloc-wallet://openid4vci/authcodeflow/callback" }, - "https://api-gateway.stg.trustbloc.dev/vcs-localkms/issuer/university_degree_issuer_bbs/v1.0": - { - "scopes": ["openid","profile"], + "https://api-gateway.dev.trustbloc.dev/vcs-localkms/issuer/university_degree_issuer_bbs/v1.0": { + "scopes": [ + "openid", + "profile" + ], + "clientID": "oidc4vc_client", + "redirectURI": "trustbloc-wallet://openid4vci/authcodeflow/callback" + }, + "https://api-gateway.stg.trustbloc.dev/vcs-localkms/issuer/university_degree_issuer_bbs/v1.0": { + "scopes": [ + "openid", + "profile" + ], "clientID": "oidc4vc_client", "redirectURI": "trustbloc-wallet://openid4vci/authcodeflow/callback" } diff --git a/go.mod b/go.mod index 8dc6989f..6d33d951 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/hyperledger/aries-framework-go-ext/component/vdr/longform v0.0.0-20221209153644-5a3273a805c1 github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0-20230615141038-5d444d6c36de github.com/hyperledger/aries-framework-go/component/models v0.0.0-20230615141038-5d444d6c36de + github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20230427134832-0c9969493bd3 github.com/hyperledger/aries-framework-go/component/vdr v0.0.0-20230615141038-5d444d6c36de github.com/hyperledger/aries-framework-go/spi v0.0.0-20230615141038-5d444d6c36de github.com/piprate/json-gold v0.5.1-0.20230111113000-6ddbe6e6f19f @@ -41,7 +42,6 @@ require ( github.com/golang/snappy v0.0.4 // 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/storageutil v0.0.0-20230427134832-0c9969493bd3 // indirect github.com/hyperledger/fabric-amcl v0.0.0-20230602173724-9e02669dceb2 // indirect github.com/hyperledger/ursa-wrapper-go v0.3.1 // indirect github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect diff --git a/pkg/common/contexts/citizenship_v1.jsonld b/pkg/common/contexts/citizenship_v1.jsonld new file mode 100644 index 00000000..a493be8b --- /dev/null +++ b/pkg/common/contexts/citizenship_v1.jsonld @@ -0,0 +1,54 @@ +{ + "@context": { + "@version": 1.1, + "@protected": true, + + "name": "http://schema.org/name", + "description": "http://schema.org/description", + "identifier": "http://schema.org/identifier", + "image": {"@id": "http://schema.org/image", "@type": "@id"}, + + "PermanentResidentCard": { + "@id": "https://w3id.org/citizenship#PermanentResidentCard", + "@context": { + "@version": 1.1, + "@protected": true, + + "id": "@id", + "type": "@type", + + "description": "http://schema.org/description", + "name": "http://schema.org/name", + "identifier": "http://schema.org/identifier", + "image": {"@id": "http://schema.org/image", "@type": "@id"} + } + }, + + "PermanentResident": { + "@id": "https://w3id.org/citizenship#PermanentResident", + "@context": { + "@version": 1.1, + "@protected": true, + + "id": "@id", + "type": "@type", + + "ctzn": "https://w3id.org/citizenship#", + "schema": "http://schema.org/", + "xsd": "http://www.w3.org/2001/XMLSchema#", + + "birthCountry": "ctzn:birthCountry", + "birthDate": {"@id": "schema:birthDate", "@type": "xsd:dateTime"}, + "commuterClassification": "ctzn:commuterClassification", + "familyName": "schema:familyName", + "gender": "schema:gender", + "givenName": "schema:givenName", + "lprCategory": "ctzn:lprCategory", + "lprNumber": "ctzn:lprNumber", + "residentSince": {"@id": "ctzn:residentSince", "@type": "xsd:dateTime"} + } + }, + + "Person": "http://schema.org/Person" + } +} \ No newline at end of file diff --git a/pkg/common/contexts/credentials-examples_v1.jsonld b/pkg/common/contexts/credentials-examples_v1.jsonld new file mode 100644 index 00000000..a2ac5e05 --- /dev/null +++ b/pkg/common/contexts/credentials-examples_v1.jsonld @@ -0,0 +1,47 @@ +{ + "@context": [{ + "@version": 1.1 + },"https://www.w3.org/ns/odrl.jsonld", { + "ex": "https://example.org/examples#", + "schema": "http://schema.org/", + "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", + + "3rdPartyCorrelation": "ex:3rdPartyCorrelation", + "AllVerifiers": "ex:AllVerifiers", + "Archival": "ex:Archival", + "BachelorDegree": "ex:BachelorDegree", + "Child": "ex:Child", + "CLCredentialDefinition2019": "ex:CLCredentialDefinition2019", + "CLSignature2019": "ex:CLSignature2019", + "IssuerPolicy": "ex:IssuerPolicy", + "HolderPolicy": "ex:HolderPolicy", + "Mother": "ex:Mother", + "RelationshipCredential": "ex:RelationshipCredential", + "UniversityDegreeCredential": "ex:UniversityDegreeCredential", + "ZkpExampleSchema2018": "ex:ZkpExampleSchema2018", + + "issuerData": "ex:issuerData", + "attributes": "ex:attributes", + "signature": "ex:signature", + "signatureCorrectnessProof": "ex:signatureCorrectnessProof", + "primaryProof": "ex:primaryProof", + "nonRevocationProof": "ex:nonRevocationProof", + + "alumniOf": {"@id": "schema:alumniOf", "@type": "rdf:HTML"}, + "child": {"@id": "ex:child", "@type": "@id"}, + "degree": "ex:degree", + "degreeType": "ex:degreeType", + "degreeSchool": "ex:degreeSchool", + "college": "ex:college", + "name": {"@id": "schema:name", "@type": "rdf:HTML"}, + "givenName": "schema:givenName", + "familyName": "schema:familyName", + "parent": {"@id": "ex:parent", "@type": "@id"}, + "referenceId": "ex:referenceId", + "documentPresence": "ex:documentPresence", + "evidenceDocument": "ex:evidenceDocument", + "spouse": "schema:spouse", + "subjectPresence": "ex:subjectPresence", + "verifier": {"@id": "ex:verifier", "@type": "@id"} + }] +} \ No newline at end of file diff --git a/pkg/common/contexts/examples_v1.jsonld b/pkg/common/contexts/examples_v1.jsonld new file mode 100644 index 00000000..0630a913 --- /dev/null +++ b/pkg/common/contexts/examples_v1.jsonld @@ -0,0 +1,16 @@ +{ + "@context": { + "@version": 1.1, + + "id": "@id", + "type": "@type", + + "ex": "https://example.org/examples#", + + "image": {"@id": "http://schema.org/image", "@type": "@id"}, + + "CredentialStatusList2017": "ex:CredentialStatusList2017", + "DocumentVerification": "ex:DocumentVerification", + "SupportingActivity": "ex:SupportingActivity" + } +} \ No newline at end of file diff --git a/pkg/common/contexts/lds-jws2020-v1.jsonld b/pkg/common/contexts/lds-jws2020-v1.jsonld new file mode 100644 index 00000000..871dda8e --- /dev/null +++ b/pkg/common/contexts/lds-jws2020-v1.jsonld @@ -0,0 +1,53 @@ +{ + "@context": { + "JsonWebKey2020": "https://w3id.org/security#JsonWebKey2020", + "JsonWebSignature2020": { + "@id": "https://w3id.org/security#JsonWebSignature2020", + "@context": { + "@protected": true, + + "id": "@id", + "type": "@type", + + "challenge": "https://w3id.org/security#challenge", + "created": { + "@id": "http://purl.org/dc/terms/created", + "@type": "http://www.w3.org/2001/XMLSchema#dateTime" + }, + "domain": "https://w3id.org/security#domain", + "expires": { + "@id": "https://w3id.org/security#expiration", + "@type": "http://www.w3.org/2001/XMLSchema#dateTime" + }, + "jws": "https://w3id.org/security#jws", + "nonce": "https://w3id.org/security#nonce", + "proofPurpose": { + "@id": "https://w3id.org/security#proofPurpose", + "@type": "@vocab", + "@context": { + "@protected": true, + + "id": "@id", + "type": "@type", + + "assertionMethod": { + "@id": "https://w3id.org/security#assertionMethod", + "@type": "@id", + "@container": "@set" + }, + "authentication": { + "@id": "https://w3id.org/security#authenticationMethod", + "@type": "@id", + "@container": "@set" + } + } + }, + "proofValue": "https://w3id.org/security#proofValue", + "verificationMethod": { + "@id": "https://w3id.org/security#verificationMethod", + "@type": "@id" + } + } + } + } +} \ No newline at end of file diff --git a/pkg/common/contexts/odrl.jsonld b/pkg/common/contexts/odrl.jsonld new file mode 100644 index 00000000..8f29ccf7 --- /dev/null +++ b/pkg/common/contexts/odrl.jsonld @@ -0,0 +1,200 @@ +{ + "@context": { + "odrl": "http://www.w3.org/ns/odrl/2/", + "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", + "rdfs": "http://www.w3.org/2000/01/rdf-schema#", + "owl": "http://www.w3.org/2002/07/owl#", + "skos": "http://www.w3.org/2004/02/skos/core#", + "dct": "http://purl.org/dc/terms/", + "xsd": "http://www.w3.org/2001/XMLSchema#", + "vcard": "http://www.w3.org/2006/vcard/ns#", + "foaf": "http://xmlns.com/foaf/0.1/", + "schema": "http://schema.org/", + "cc": "http://creativecommons.org/ns#", + + "uid": "@id", + "type": "@type", + + "Policy": "odrl:Policy", + "Rule": "odrl:Rule", + "profile": {"@type": "@id", "@id": "odrl:profile"}, + + "inheritFrom": {"@type": "@id", "@id": "odrl:inheritFrom"}, + + "ConflictTerm": "odrl:ConflictTerm", + "conflict": {"@type": "@vocab", "@id": "odrl:conflict"}, + "perm": "odrl:perm", + "prohibit": "odrl:prohibit", + "invalid": "odrl:invalid", + + "Agreement": "odrl:Agreement", + "Assertion": "odrl:Assertion", + "Offer": "odrl:Offer", + "Privacy": "odrl:Privacy", + "Invitation": "odrl:Invitation", + "Set": "odrl:Set", + "Ticket": "odrl:Ticket", + + "Asset": "odrl:Asset", + "AssetCollection": "odrl:AssetCollection", + "relation": {"@type": "@id", "@id": "odrl:relation"}, + "hasPolicy": {"@type": "@id", "@id": "odrl:hasPolicy"}, + + "target": {"@type": "@id", "@id": "odrl:target"}, + "output": {"@type": "@id", "@id": "odrl:output"}, + + "partOf": {"@type": "@id", "@id": "odrl:partOf"}, + "source": {"@type": "@id", "@id": "odrl:source"}, + + "Party": "odrl:Party", + "PartyCollection": "odrl:PartyCollection", + "function": {"@type": "@vocab", "@id": "odrl:function"}, + "PartyScope": "odrl:PartyScope", + + "assignee": {"@type": "@id", "@id": "odrl:assignee"}, + "assigner": {"@type": "@id", "@id": "odrl:assigner"}, + "assigneeOf": {"@type": "@id", "@id": "odrl:assigneeOf"}, + "assignerOf": {"@type": "@id", "@id": "odrl:assignerOf"}, + "attributedParty": {"@type": "@id", "@id": "odrl:attributedParty"}, + "attributingParty": {"@type": "@id", "@id": "odrl:attributingParty"}, + "compensatedParty": {"@type": "@id", "@id": "odrl:compensatedParty"}, + "compensatingParty": {"@type": "@id", "@id": "odrl:compensatingParty"}, + "consentingParty": {"@type": "@id", "@id": "odrl:consentingParty"}, + "consentedParty": {"@type": "@id", "@id": "odrl:consentedParty"}, + "informedParty": {"@type": "@id", "@id": "odrl:informedParty"}, + "informingParty": {"@type": "@id", "@id": "odrl:informingParty"}, + "trackingParty": {"@type": "@id", "@id": "odrl:trackingParty"}, + "trackedParty": {"@type": "@id", "@id": "odrl:trackedParty"}, + "contractingParty": {"@type": "@id", "@id": "odrl:contractingParty"}, + "contractedParty": {"@type": "@id", "@id": "odrl:contractedParty"}, + + "Action": "odrl:Action", + "action": {"@type": "@vocab", "@id": "odrl:action"}, + "includedIn": {"@type": "@id", "@id": "odrl:includedIn"}, + "implies": {"@type": "@id", "@id": "odrl:implies"}, + + "Permission": "odrl:Permission", + "permission": {"@type": "@id", "@id": "odrl:permission"}, + + "Prohibition": "odrl:Prohibition", + "prohibition": {"@type": "@id", "@id": "odrl:prohibition"}, + + "obligation": {"@type": "@id", "@id": "odrl:obligation"}, + + "use": "odrl:use", + "grantUse": "odrl:grantUse", + "aggregate": "odrl:aggregate", + "annotate": "odrl:annotate", + "anonymize": "odrl:anonymize", + "archive": "odrl:archive", + "concurrentUse": "odrl:concurrentUse", + "derive": "odrl:derive", + "digitize": "odrl:digitize", + "display": "odrl:display", + "distribute": "odrl:distribute", + "execute": "odrl:execute", + "extract": "odrl:extract", + "give": "odrl:give", + "index": "odrl:index", + "install": "odrl:install", + "modify": "odrl:modify", + "move": "odrl:move", + "play": "odrl:play", + "present": "odrl:present", + "print": "odrl:print", + "read": "odrl:read", + "reproduce": "odrl:reproduce", + "sell": "odrl:sell", + "stream": "odrl:stream", + "textToSpeech": "odrl:textToSpeech", + "transfer": "odrl:transfer", + "transform": "odrl:transform", + "translate": "odrl:translate", + + "Duty": "odrl:Duty", + "duty": {"@type": "@id", "@id": "odrl:duty"}, + "consequence": {"@type": "@id", "@id": "odrl:consequence"}, + "remedy": {"@type": "@id", "@id": "odrl:remedy"}, + + "acceptTracking": "odrl:acceptTracking", + "attribute": "odrl:attribute", + "compensate": "odrl:compensate", + "delete": "odrl:delete", + "ensureExclusivity": "odrl:ensureExclusivity", + "include": "odrl:include", + "inform": "odrl:inform", + "nextPolicy": "odrl:nextPolicy", + "obtainConsent": "odrl:obtainConsent", + "reviewPolicy": "odrl:reviewPolicy", + "uninstall": "odrl:uninstall", + "watermark": "odrl:watermark", + + "Constraint": "odrl:Constraint", + "LogicalConstraint": "odrl:LogicalConstraint", + "constraint": {"@type": "@id", "@id": "odrl:constraint"}, + "refinement": {"@type": "@id", "@id": "odrl:refinement"}, + "Operator": "odrl:Operator", + "operator": {"@type": "@vocab", "@id": "odrl:operator"}, + "RightOperand": "odrl:RightOperand", + "rightOperand": "odrl:rightOperand", + "rightOperandReference":{"@type": "xsd:anyURI", "@id": "odrl:rightOperandReference"}, + "LeftOperand": "odrl:LeftOperand", + "leftOperand": {"@type": "@vocab", "@id": "odrl:leftOperand"}, + "unit": "odrl:unit", + "dataType": {"@type": "xsd:anyType", "@id": "odrl:datatype"}, + "status": "odrl:status", + + "absolutePosition": "odrl:absolutePosition", + "absoluteSpatialPosition": "odrl:absoluteSpatialPosition", + "absoluteTemporalPosition":"odrl:absoluteTemporalPosition", + "absoluteSize": "odrl:absoluteSize", + "count": "odrl:count", + "dateTime": "odrl:dateTime", + "delayPeriod": "odrl:delayPeriod", + "deliveryChannel": "odrl:deliveryChannel", + "elapsedTime": "odrl:elapsedTime", + "event": "odrl:event", + "fileFormat": "odrl:fileFormat", + "industry": "odrl:industry:", + "language": "odrl:language", + "media": "odrl:media", + "meteredTime": "odrl:meteredTime", + "payAmount": "odrl:payAmount", + "percentage": "odrl:percentage", + "product": "odrl:product", + "purpose": "odrl:purpose", + "recipient": "odrl:recipient", + "relativePosition": "odrl:relativePosition", + "relativeSpatialPosition": "odrl:relativeSpatialPosition", + "relativeTemporalPosition":"odrl:relativeTemporalPosition", + "relativeSize": "odrl:relativeSize", + "resolution": "odrl:resolution", + "spatial": "odrl:spatial", + "spatialCoordinates": "odrl:spatialCoordinates", + "systemDevice": "odrl:systemDevice", + "timeInterval": "odrl:timeInterval", + "unitOfCount": "odrl:unitOfCount", + "version": "odrl:version", + "virtualLocation": "odrl:virtualLocation", + + "eq": "odrl:eq", + "gt": "odrl:gt", + "gteq": "odrl:gteq", + "lt": "odrl:lt", + "lteq": "odrl:lteq", + "neq": "odrl:neg", + "isA": "odrl:isA", + "hasPart": "odrl:hasPart", + "isPartOf": "odrl:isPartOf", + "isAllOf": "odrl:isAllOf", + "isAnyOf": "odrl:isAnyOf", + "isNoneOf": "odrl:isNoneOf", + "or": "odrl:or", + "xone": "odrl:xone", + "and": "odrl:and", + "andSequence": "odrl:andSequence", + + "policyUsage": "odrl:policyUsage" + + } +} \ No newline at end of file diff --git a/pkg/common/doc_loader.go b/pkg/common/doc_loader.go new file mode 100644 index 00000000..bbbec2d8 --- /dev/null +++ b/pkg/common/doc_loader.go @@ -0,0 +1,93 @@ +package common + +import ( + _ "embed" //nolint:gci // required for go:embed + "fmt" + "net/http" + + ldcontext "github.com/hyperledger/aries-framework-go/component/models/ld/context" + lddocloader "github.com/hyperledger/aries-framework-go/component/models/ld/documentloader" + "github.com/hyperledger/aries-framework-go/spi/storage" + jsonld "github.com/piprate/json-gold/ld" + + ldstore "github.com/hyperledger/aries-framework-go/component/models/ld/store" + "github.com/hyperledger/aries-framework-go/pkg/doc/ld" +) + +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/lds-jws2020-v1.jsonld + jws2020 []byte +) + +// CreateJSONLDDocumentLoader creates document loader with pre cached contexts. +func CreateJSONLDDocumentLoader(httpClient *http.Client, storageProvider storage.Provider, +) (jsonld.DocumentLoader, error) { + contextStore, err := ldstore.NewContextStore(storageProvider) + if err != nil { + return nil, fmt.Errorf("create JSON-LD context store: %w", err) + } + + remoteProviderStore, err := ldstore.NewRemoteProviderStore(storageProvider) + if err != nil { + return nil, fmt.Errorf("create remote provider store: %w", err) + } + + ldStore := &ldStoreProvider{ + ContextStore: contextStore, + RemoteProviderStore: remoteProviderStore, + } + + additionalContexts := []ldcontext.Document{ + { + URL: "https://www.w3.org/2018/credentials/examples/v1", + Content: credentialExamples, + }, + { + URL: "https://trustbloc.github.io/context/vc/examples-v1.jsonld", + Content: vcExamples, + }, + { + URL: "https://www.w3.org/ns/odrl.jsonld", + Content: odrl, + }, + { + URL: "https://w3id.org/citizenship/v1", + DocumentURL: "https://w3c-ccg.github.io/citizenship-vocab/contexts/citizenship-v1.jsonld", + Content: citizenship, + }, + { + URL: "https://w3c-ccg.github.io/lds-jws2020/contexts/lds-jws2020-v1.json", + Content: jws2020, + }, + } + + documentLoader, err := ld.NewDocumentLoader(ldStore, + ld.WithRemoteDocumentLoader(jsonld.NewDefaultDocumentLoader(httpClient)), + lddocloader.WithExtraContexts(additionalContexts...)) + if err != nil { + return nil, fmt.Errorf("new document loader: %w", err) + } + + return documentLoader, nil +} + +type ldStoreProvider struct { + ContextStore ldstore.ContextStore + RemoteProviderStore ldstore.RemoteProviderStore +} + +func (p *ldStoreProvider) JSONLDContextStore() ldstore.ContextStore { + return p.ContextStore +} + +func (p *ldStoreProvider) JSONLDRemoteProviderStore() ldstore.RemoteProviderStore { + return p.RemoteProviderStore +} diff --git a/pkg/common/doc_loader_test.go b/pkg/common/doc_loader_test.go new file mode 100644 index 00000000..b6587f6a --- /dev/null +++ b/pkg/common/doc_loader_test.go @@ -0,0 +1,40 @@ +package common_test + +import ( + "net/http" + "testing" + + "github.com/hyperledger/aries-framework-go/component/storageutil/mem" + "github.com/hyperledger/aries-framework-go/component/storageutil/mock/storage" + "github.com/stretchr/testify/require" + + "github.com/trustbloc/wallet-sdk/pkg/common" +) + +func TestCreateJSONLDDocumentLoader(t *testing.T) { + t.Run("Success", func(t *testing.T) { + loader, err := common.CreateJSONLDDocumentLoader(&http.Client{}, mem.NewProvider()) + require.NoError(t, err) + require.NotNil(t, loader) + }) + + t.Run("Fail context store", func(t *testing.T) { + store := storage.NewMockStoreProvider() + store.FailNamespace = "ldcontexts" + + loader, err := common.CreateJSONLDDocumentLoader(&http.Client{}, store) + require.Error(t, err) + require.Contains(t, err.Error(), "create JSON-LD context store") + require.Nil(t, loader) + }) + + t.Run("Fail context store", func(t *testing.T) { + store := storage.NewMockStoreProvider() + store.FailNamespace = "remoteproviders" + + loader, err := common.CreateJSONLDDocumentLoader(&http.Client{}, store) + require.Error(t, err) + require.Contains(t, err.Error(), "create remote provider store") + require.Nil(t, loader) + }) +} diff --git a/pkg/openid4vp/openid4vp.go b/pkg/openid4vp/openid4vp.go index 1d44645e..7f8802f1 100644 --- a/pkg/openid4vp/openid4vp.go +++ b/pkg/openid4vp/openid4vp.go @@ -85,19 +85,7 @@ func New( documentLoader ld.DocumentLoader, opts ...Opt, ) *Interaction { - client, activityLogger, metricsLogger, networkDocumentLoaderHTTPTimeout := processOpts(opts) - - if documentLoader == nil { - httpClient := &http.Client{} - - if networkDocumentLoaderHTTPTimeout != nil { - httpClient.Timeout = *networkDocumentLoaderHTTPTimeout - } else { - httpClient.Timeout = api.DefaultHTTPTimeout - } - - documentLoader = ld.NewDefaultDocumentLoader(httpClient) - } + client, activityLogger, metricsLogger := processOpts(opts) return &Interaction{ authorizationRequest: authorizationRequest, diff --git a/pkg/openid4vp/openid4vp_test.go b/pkg/openid4vp/openid4vp_test.go index a230b428..c35df112 100644 --- a/pkg/openid4vp/openid4vp_test.go +++ b/pkg/openid4vp/openid4vp_test.go @@ -17,7 +17,6 @@ import ( "net/url" "strings" "testing" - "time" "github.com/google/uuid" "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose" @@ -68,9 +67,7 @@ func (f *failingMetricsLogger) Log(metricsEvent *api.MetricsEvent) error { func TestOpenID4VP_GetQuery(t *testing.T) { t.Run("Inline Request Object", func(t *testing.T) { - opt := WithNetworkDocumentLoaderHTTPTimeout(time.Second * 10) - - instance := New(requestObjectJWT, &jwtSignatureVerifierMock{}, nil, nil, nil, opt) + instance := New(requestObjectJWT, &jwtSignatureVerifierMock{}, nil, nil, nil) query, err := instance.GetQuery() require.NoError(t, err) diff --git a/pkg/openid4vp/opts.go b/pkg/openid4vp/opts.go index 5076620a..109030d8 100644 --- a/pkg/openid4vp/opts.go +++ b/pkg/openid4vp/opts.go @@ -8,7 +8,6 @@ package openid4vp import ( "net/http" - "time" noopactivitylogger "github.com/trustbloc/wallet-sdk/pkg/activitylogger/noop" "github.com/trustbloc/wallet-sdk/pkg/api" @@ -16,10 +15,9 @@ import ( ) type opts struct { - httpClient httpClient - activityLogger api.ActivityLogger - metricsLogger api.MetricsLogger - networkDocumentLoaderHTTPTimeout *time.Duration // Only used if the default network-based loader is used. + httpClient httpClient + activityLogger api.ActivityLogger + metricsLogger api.MetricsLogger } // An Opt is a single option for an OpenID4VP instance. @@ -51,15 +49,7 @@ func WithMetricsLogger(metricsLogger api.MetricsLogger) Opt { } } -// WithNetworkDocumentLoaderHTTPTimeout sets the timeout for HTTP calls made by the default network-based -// document loader. This option is only used if no document loader was explicitly set via the New function. -func WithNetworkDocumentLoaderHTTPTimeout(timeout time.Duration) Opt { - return func(opts *opts) { - opts.networkDocumentLoaderHTTPTimeout = &timeout - } -} - -func processOpts(options []Opt) (httpClient, api.ActivityLogger, api.MetricsLogger, *time.Duration) { +func processOpts(options []Opt) (httpClient, api.ActivityLogger, api.MetricsLogger) { opts := mergeOpts(options) if opts.httpClient == nil { @@ -74,7 +64,7 @@ func processOpts(options []Opt) (httpClient, api.ActivityLogger, api.MetricsLogg opts.metricsLogger = noopmetricslogger.NewMetricsLogger() } - return opts.httpClient, opts.activityLogger, opts.metricsLogger, opts.networkDocumentLoaderHTTPTimeout + return opts.httpClient, opts.activityLogger, opts.metricsLogger } func mergeOpts(options []Opt) *opts { diff --git a/test/integration/openid4vp_test.go b/test/integration/openid4vp_test.go index 88d410c0..e4e09239 100644 --- a/test/integration/openid4vp_test.go +++ b/test/integration/openid4vp_test.go @@ -23,7 +23,6 @@ import ( "github.com/trustbloc/wallet-sdk/cmd/wallet-sdk-gomobile/localkms" "github.com/trustbloc/wallet-sdk/cmd/wallet-sdk-gomobile/openid4vp" "github.com/trustbloc/wallet-sdk/cmd/wallet-sdk-gomobile/verifiable" - "github.com/trustbloc/wallet-sdk/internal/testutil" "github.com/trustbloc/wallet-sdk/test/integration/pkg/helpers" "github.com/trustbloc/wallet-sdk/test/integration/pkg/metricslogger" "github.com/trustbloc/wallet-sdk/test/integration/pkg/setup/oidc4vp" @@ -150,8 +149,7 @@ func TestOpenID4VPFullFlow(t *testing.T) { issuedCredentials, issuersInfo := testHelper.IssueCredentials(t, vcsAPIDirectURL, tc.issuerProfileIDs, - tc.claimData, - &documentLoaderReverseWrapper{DocumentLoader: testutil.DocumentLoader(t)}) + tc.claimData, nil) println("Issued", issuedCredentials.Length(), "credentials") for k := 0; k < issuedCredentials.Length(); k++ { cred, _ := issuedCredentials.AtIndex(k).Serialize() @@ -174,14 +172,12 @@ func TestOpenID4VPFullFlow(t *testing.T) { activityLogger := mem.NewActivityLogger() - docLoader := &documentLoaderReverseWrapper{DocumentLoader: testutil.DocumentLoader(t)} - metricsLogger := metricslogger.NewMetricsLogger() interactionRequiredArgs := openid4vp.NewArgs(initiateURL, testHelper.KMS.GetCrypto(), didResolver) interactionOptionalArgs := openid4vp.NewOpts() - interactionOptionalArgs.SetDocumentLoader(docLoader) + interactionOptionalArgs.SetActivityLogger(activityLogger) interactionOptionalArgs.SetMetricsLogger(metricsLogger) interactionOptionalArgs.DisableHTTPClientTLSVerify() @@ -202,10 +198,9 @@ func TestOpenID4VPFullFlow(t *testing.T) { require.Equal(t, "test purpose.", displayData.Purpose()) require.Equal(t, "", displayData.LogoURI()) - inquirerOpts := credential.NewInquirerOpts(). - SetDocumentLoader(docLoader).SetDIDResolver(didResolver) + inquirerOpts := credential.NewInquirerOpts().SetDIDResolver(didResolver) - inquirer := credential.NewInquirer(inquirerOpts) + inquirer, err := credential.NewInquirer(inquirerOpts) require.NoError(t, err) requirements, err := inquirer.GetSubmissionRequirements(query, issuedCredentials)