From f6f01510a8d3a6cf8c536436902869600877925a Mon Sep 17 00:00:00 2001 From: Filip Burlacu Date: Wed, 26 Apr 2023 15:19:19 -0400 Subject: [PATCH] feat: new component for data models - DIDs, signatures, JSON-LD component/models/: - did: afgo's DID and DID Doc models. - ld: JSON-LD support - data models, context stores, LD-Proofs, canonicalization, etc. - signature: signing APIs used in DID Docs etc. - util: utility data models needed for other model implementations, but not specific to a given model. Signed-off-by: Filip Burlacu --- cmd/aries-agent-mobile/go.mod | 2 + cmd/aries-agent-rest/go.mod | 2 + cmd/aries-js-worker/go.mod | 2 + .../kmscrypto}/mock/crypto/mock_crypto.go | 30 +-- {pkg/doc => component/models}/did/doc.go | 32 +-- {pkg/doc => component/models}/did/doc_test.go | 46 ++-- .../models/did/endpoint}/endpoint.go | 7 +- .../models/did/endpoint}/endpoint_test.go | 2 +- {pkg/doc => component/models}/did/helpers.go | 0 {pkg/doc => component/models}/did/legacy.go | 0 .../models}/did/legacy_test.go | 6 +- {pkg/doc => component/models}/did/schema.go | 0 .../models}/did/serialize_default.go | 0 .../models}/did/serialize_interop.go | 0 .../models}/did/testdata/invalid_doc.jsonld | 0 .../models}/did/testdata/valid_doc.jsonld | 0 .../did/testdata/valid_doc_resolution.jsonld | 0 .../did/testdata/valid_doc_v0.11.jsonld | 0 .../did/testdata/valid_doc_with_base.jsonld | 0 .../valid_doc_with_service_endpoint.jsonld | 0 component/models/go.mod | 50 +++++ component/models/go.sum | 123 +++++++++++ .../models/ld/context}/document.go | 2 +- .../ld/context}/embed/embed_contexts.go | 2 +- .../ed25519-signature-2018-v1.jsonld | 0 .../ed25519-signature-2020-v1.jsonld | 0 .../credential-application.jsonld | 0 .../credential-response.jsonld | 0 .../presentation-submission_v1.jsonld | 0 .../ns.did.ai/secp256k1-2019_v1.jsonld | 0 .../ns.did.ai/x25519-2019_v1.jsonld | 0 .../third_party/w3.org/credentials_v1.jsonld | 0 .../embed/third_party/w3.org/did_v1.jsonld | 0 .../embed/third_party/w3.org/odrl.jsonld | 0 .../w3c-ccg.github.io/did_docres_v1.jsonld | 0 .../w3c-ccg.github.io/did_v0.11.jsonld | 0 .../w3c-ccg.github.io/did_v1.jsonld | 0 .../w3c-ccg.github.io/ldp-bbs2020_v1.jsonld | 0 .../w3c-ccg.github.io/lds-jws2020_v1.jsonld | 0 .../revocationList2020.jsonld | 0 .../revocationList2021.jsonld | 0 .../w3c-ccg.github.io/security_v1.jsonld | 0 .../w3c-ccg.github.io/security_v2.jsonld | 0 .../w3c-ccg.github.io/wallet-v1.jsonld | 0 .../ld/context}/remote/remote_provider.go | 4 +- .../context}/remote/remote_provider_test.go | 8 +- .../ld/documentloader}/document_loader.go | 31 +-- .../documentloader}/document_loader_test.go | 91 ++++---- .../models/ld/mock}/mock_context_store.go | 50 ++--- .../ld/mock/mock_remote_provider_store.go | 105 +++++++++ component/models/ld/mock/mock_service.go | 79 +++++++ .../models/ld/processor}/processor.go | 34 +-- .../models/ld/processor}/processor_test.go | 132 ++++++------ .../testdata/canonized_incorrect_rdf.nq | 0 .../canonized_incorrect_rdf_all_filtered.nq | 0 .../canonized_incorrect_rdf_filtered.nq | 0 .../testdata/canonized_json_credential.nq | 0 .../testdata/canonized_json_credential_2.nq | 0 .../canonized_json_credential_filtered.nq | 0 .../canonized_json_credential_not_filtered.nq | 0 .../testdata/canonized_jsonld_proof.nq | 0 .../testdata/canonized_sample_vp.nq | 0 .../testdata/canonized_sample_vp_2.nq | 0 .../canonized_sample_vp_extra_context.nq | 0 .../testdata/canonized_sample_vp_filtered.nq | 0 .../contexts/extra_jsonld_context.jsonld | 0 ...rdf_messing_up_label_prefix_counter.jsonld | 0 ...messing_up_label_prefix_counter_str.jsonld | 0 .../jsonld_multiple_invalid_rdfs.jsonld | 0 .../testdata/jsonld_proof_sample.jsonld | 0 .../testdata/jsonld_sample_1.jsonld | 0 .../jsonld_with_2_known_invalid_rdfs.jsonld | 0 .../testdata/jsonld_with_incorrect_rdf.jsonld | 0 .../vc_with_incorrect_contexts.jsonld | 0 .../testdata/vc_with_proper_contexts.jsonld | 0 .../testdata/vc_with_proper_contexts_2.jsonld | 0 .../models/ld}/proof/data.go | 12 +- .../models/ld}/proof/data_test.go | 28 +-- .../models/ld}/proof/jws.go | 12 +- .../models/ld}/proof/jws_test.go | 14 +- .../models/ld}/proof/proof.go | 6 +- .../models/ld}/proof/proof_test.go | 12 +- .../ld}/proof/testdata/valid_doc.jsonld | 0 .../models/ld}/proof/utils.go | 0 .../models/ld}/proof/utils_test.go | 8 +- .../models/ld/store}/context_store.go | 6 +- .../models/ld/store}/context_store_test.go | 56 ++--- .../models/ld/store}/remote_provider_store.go | 2 +- .../ld/store}/remote_provider_store_test.go | 62 +++--- ...ustbloc-authorization-credential_v1.jsonld | 0 .../trustbloc-examples_v1.jsonld | 0 .../w3.org/credentials-examples_v1.jsonld | 0 .../contexts/third_party/w3.org/odrl.jsonld | 0 .../w3c-ccg.github.io/citizenship_v1.jsonld | 0 .../revocation-list-2021.jsonld | 0 .../models/ld/testutil}/document_loader.go | 22 +- .../ld/testutil}/document_loader_test.go | 8 +- component/models/signature/api/api.go | 38 ++++ .../models}/signature/signer/signer.go | 16 +- .../models/signature/signer/signer_default.go | 20 ++ .../models/signature/signer/signer_interop.go | 21 ++ .../models}/signature/signer/signer_test.go | 36 ++-- .../signer/testdata/valid_doc.jsonld | 0 .../public_key_verifier.go | 2 +- .../public_key_verifier_test.go | 4 +- .../suite/bbsblssignature2020/suite.go | 10 +- .../suite/bbsblssignature2020/suite_test.go | 8 +- .../testdata/expected_doc.jsonld | 0 .../testdata/vc_doc.jsonld | 0 .../public_key_verifier.go | 2 +- .../public_key_verifier_test.go | 6 +- .../suite/bbsblssignatureproof2020/signer.go | 38 ++-- .../suite/bbsblssignatureproof2020/suite.go | 10 +- .../bbsblssignatureproof2020/suite_test.go | 10 +- .../testdata/case16_reveal_doc.jsonld | 15 ++ .../testdata/case16_vc.jsonld | 41 ++++ .../testdata/case18_reveal_doc.jsonld | 15 ++ .../testdata/case18_vc.jsonld | 28 +++ .../testdata/doc_with_many_proofs.jsonld | 58 +++++ .../testdata/expected_doc.rdf | 18 ++ .../testdata/vc_doc.jsonld | 36 ++++ .../public_key_verifier.go | 2 +- .../public_key_verifier_test.go | 18 +- .../ecdsasecp256k1signature2019/suite.go | 10 +- .../ecdsasecp256k1signature2019/suite_test.go | 0 .../public_key_verifier.go | 2 +- .../public_key_verifier_test.go | 16 +- .../suite/ed25519signature2018/suite.go | 10 +- .../ed25519signature2018/suite_crypto_test.go | 16 +- .../suite/ed25519signature2018/suite_test.go | 0 .../public_key_verifier.go | 2 +- .../public_key_verifier_test.go | 16 +- .../suite/ed25519signature2020/suite.go | 10 +- .../ed25519signature2020/suite_crypto_test.go | 16 +- .../suite/ed25519signature2020/suite_test.go | 0 .../public_key_verifier.go | 2 +- .../public_key_verifier_test.go | 10 +- .../suite/jsonwebsignature2020/suite.go | 10 +- .../jsonwebsignature2020/suite_crypto_test.go | 17 +- .../suite/jsonwebsignature2020/suite_test.go | 0 .../models}/signature/suite/suite.go | 6 +- .../models}/signature/suite/suite_crypto.go | 6 +- .../signature/suite/suite_crypto_test.go | 6 +- .../models}/signature/suite/suite_test.go | 6 +- .../models/signature/util}/api.go | 2 +- .../util}/internal/signer/crypto_signer.go | 4 +- .../internal/signer/crypto_signer_test.go | 12 +- .../signature/util}/internal/signer/ecdsa.go | 0 .../util}/internal/signer/ecdsa_test.go | 0 .../util}/internal/signer/ed25519.go | 0 .../util}/internal/signer/ed25519_test.go | 0 .../signature/util}/internal/signer/rsa.go | 0 .../util}/internal/signer/rsa_test.go | 0 .../models/signature/util}/signer.go | 11 +- .../models/signature/util}/signer_test.go | 19 +- .../models/signature/util}/utils.go | 4 +- .../models/signature/util}/utils_test.go | 4 +- .../signature/verifier/public_key_verifier.go | 4 +- .../verifier/public_key_verifier_test.go | 24 +-- .../verifier/testdata/valid_doc.jsonld | 0 .../models}/signature/verifier/verifier.go | 38 +--- .../signature/verifier/verifier_test.go | 17 +- .../models/util/maphelpers/maphelpers.go | 23 ++ .../models/util/time}/time.go | 6 +- .../models/util/time}/time_test.go | 2 +- .../storageutil/mock/storage/storage.go | 2 + go.mod | 7 +- go.sum | 2 - pkg/common/model/model.go | 52 +++++ pkg/doc/did/did.go | 204 ++++++++++++++++++ pkg/doc/did/helpers_test.go | 3 +- pkg/doc/jose/common.go | 4 +- pkg/doc/jose/common_test.go | 2 +- pkg/doc/jose/decrypter.go | 2 +- pkg/doc/jose/encrypter.go | 2 +- pkg/doc/jose/encrypter_decrypter_test.go | 4 +- pkg/doc/jose/jwk/jwksupport/jwk.go | 5 +- pkg/doc/jsonld/validate.go | 8 +- pkg/doc/jwt/verifier.go | 2 +- pkg/doc/jwt/verifier_test.go | 2 +- pkg/doc/ld/ld.go | 61 ++++++ pkg/doc/ldcontext/embed/embed.go | 14 ++ pkg/doc/ldcontext/ldcontext.go | 14 ++ pkg/doc/ldcontext/remote/remote.go | 33 +++ pkg/doc/signature/jsonld/jsonld.go | 72 +++++++ pkg/doc/signature/proof/ldproof.go | 97 +++++++++ pkg/doc/signature/signer/api.go | 24 +++ pkg/doc/signature/signer/signer_default.go | 19 -- pkg/doc/signature/signer/signer_interop.go | 20 -- pkg/doc/signature/suite/api.go | 73 +++++++ .../bbsblssignature2020.go | 39 ++++ .../bbsblssignatureproof2020.go | 34 +++ .../bbsblssignatureproof2020/signer_test.go | 47 ++-- .../ecdsasecp256k1signature2019.go | 32 +++ .../ed25519signature2018.go | 37 ++++ .../ed25519signature2018.go | 37 ++++ .../jsonwebsignature2020.go | 42 ++++ pkg/doc/signature/verifier/api.go | 131 +++++++++++ pkg/doc/util/jwkkid/kid_creator.go | 5 +- pkg/doc/util/signature/signature.go | 46 ++++ pkg/doc/util/timewrapper.go | 53 +++++ .../verifiable/credential_jwt_proof_test.go | 4 +- pkg/doc/verifiable/linked_data_proof.go | 2 +- .../framework/aries/api/vdr/mocks.gen.go | 2 +- pkg/internal/gomocks/store/did/mocks.gen.go | 2 +- pkg/internal/ldtestutil/ldtestutil.go | 32 +++ pkg/mock/crypto/crypto.go | 25 +++ pkg/mock/diddoc/mock_diddoc.go | 16 +- pkg/mock/kms/kms.go | 36 ++++ pkg/mock/kms/mock_kms.go | 175 --------------- pkg/mock/ld/ld.go | 30 +++ pkg/mock/ld/mock_remote_provider_store.go | 105 --------- pkg/mock/ld/mock_service.go | 79 ------- pkg/mock/secretlock/mock_secretlock.go | 35 --- pkg/mock/secretlock/secretlock.go | 12 ++ pkg/mock/storage/storage.go | 31 +++ pkg/store/ld/ld.go | 51 +++++ scripts/check_lint.sh | 3 + scripts/check_unit.sh | 7 + test/bdd/go.mod | 2 + 220 files changed, 2677 insertions(+), 1074 deletions(-) rename {pkg => component/kmscrypto}/mock/crypto/mock_crypto.go (91%) rename {pkg/doc => component/models}/did/doc.go (97%) rename {pkg/doc => component/models}/did/doc_test.go (97%) rename {pkg/common/model => component/models/did/endpoint}/endpoint.go (98%) rename {pkg/common/model => component/models/did/endpoint}/endpoint_test.go (99%) rename {pkg/doc => component/models}/did/helpers.go (100%) rename {pkg/doc => component/models}/did/legacy.go (100%) rename {pkg/doc => component/models}/did/legacy_test.go (93%) rename {pkg/doc => component/models}/did/schema.go (100%) rename {pkg/doc => component/models}/did/serialize_default.go (100%) rename {pkg/doc => component/models}/did/serialize_interop.go (100%) rename {pkg/doc => component/models}/did/testdata/invalid_doc.jsonld (100%) rename {pkg/doc => component/models}/did/testdata/valid_doc.jsonld (100%) rename {pkg/doc => component/models}/did/testdata/valid_doc_resolution.jsonld (100%) rename {pkg/doc => component/models}/did/testdata/valid_doc_v0.11.jsonld (100%) rename {pkg/doc => component/models}/did/testdata/valid_doc_with_base.jsonld (100%) rename {pkg/doc => component/models}/did/testdata/valid_doc_with_service_endpoint.jsonld (100%) create mode 100644 component/models/go.mod create mode 100644 component/models/go.sum rename {pkg/doc/ldcontext => component/models/ld/context}/document.go (96%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/embed_contexts.go (98%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/digitalbazaar.github.io/ed25519-signature-2018-v1.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/digitalbazaar.github.io/ed25519-signature-2020-v1.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/identity.foundation/credential-application.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/identity.foundation/credential-response.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/identity.foundation/presentation-submission_v1.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/ns.did.ai/secp256k1-2019_v1.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/ns.did.ai/x25519-2019_v1.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/w3.org/credentials_v1.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/w3.org/did_v1.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/w3.org/odrl.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/w3c-ccg.github.io/did_docres_v1.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/w3c-ccg.github.io/did_v0.11.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/w3c-ccg.github.io/did_v1.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/w3c-ccg.github.io/ldp-bbs2020_v1.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/w3c-ccg.github.io/lds-jws2020_v1.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/w3c-ccg.github.io/revocationList2020.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/w3c-ccg.github.io/revocationList2021.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/w3c-ccg.github.io/security_v1.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/w3c-ccg.github.io/security_v2.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/embed/third_party/w3c-ccg.github.io/wallet-v1.jsonld (100%) rename {pkg/doc/ldcontext => component/models/ld/context}/remote/remote_provider.go (93%) rename {pkg/doc/ldcontext => component/models/ld/context}/remote/remote_provider_test.go (90%) rename {pkg/doc/ld => component/models/ld/documentloader}/document_loader.go (82%) rename {pkg/doc/ld => component/models/ld/documentloader}/document_loader_test.go (69%) rename {pkg/mock/ld => component/models/ld/mock}/mock_context_store.go (61%) create mode 100644 component/models/ld/mock/mock_remote_provider_store.go create mode 100644 component/models/ld/mock/mock_service.go rename {pkg/doc/signature/jsonld => component/models/ld/processor}/processor.go (92%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/processor_test.go (78%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/canonized_incorrect_rdf.nq (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/canonized_incorrect_rdf_all_filtered.nq (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/canonized_incorrect_rdf_filtered.nq (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/canonized_json_credential.nq (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/canonized_json_credential_2.nq (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/canonized_json_credential_filtered.nq (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/canonized_json_credential_not_filtered.nq (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/canonized_jsonld_proof.nq (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/canonized_sample_vp.nq (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/canonized_sample_vp_2.nq (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/canonized_sample_vp_extra_context.nq (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/canonized_sample_vp_filtered.nq (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/contexts/extra_jsonld_context.jsonld (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/invalid_rdf_messing_up_label_prefix_counter.jsonld (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/invalid_rdf_messing_up_label_prefix_counter_str.jsonld (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/jsonld_multiple_invalid_rdfs.jsonld (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/jsonld_proof_sample.jsonld (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/jsonld_sample_1.jsonld (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/jsonld_with_2_known_invalid_rdfs.jsonld (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/jsonld_with_incorrect_rdf.jsonld (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/vc_with_incorrect_contexts.jsonld (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/vc_with_proper_contexts.jsonld (100%) rename {pkg/doc/signature/jsonld => component/models/ld/processor}/testdata/vc_with_proper_contexts_2.jsonld (100%) rename {pkg/doc/signature => component/models/ld}/proof/data.go (92%) rename {pkg/doc/signature => component/models/ld}/proof/data_test.go (82%) rename {pkg/doc/signature => component/models/ld}/proof/jws.go (91%) rename {pkg/doc/signature => component/models/ld}/proof/jws_test.go (90%) rename {pkg/doc/signature => component/models/ld}/proof/proof.go (97%) rename {pkg/doc/signature => component/models/ld}/proof/proof_test.go (97%) rename {pkg/doc/signature => component/models/ld}/proof/testdata/valid_doc.jsonld (100%) rename {pkg/doc/signature => component/models/ld}/proof/utils.go (100%) rename {pkg/doc/signature => component/models/ld}/proof/utils_test.go (92%) rename {pkg/store/ld => component/models/ld/store}/context_store.go (97%) rename {pkg/store/ld => component/models/ld/store}/context_store_test.go (86%) rename {pkg/store/ld => component/models/ld/store}/remote_provider_store.go (99%) rename {pkg/store/ld => component/models/ld/store}/remote_provider_store_test.go (80%) rename {pkg/internal/ldtestutil => component/models/ld/testutil}/contexts/third_party/trustbloc.github.io/trustbloc-authorization-credential_v1.jsonld (100%) rename {pkg/internal/ldtestutil => component/models/ld/testutil}/contexts/third_party/trustbloc.github.io/trustbloc-examples_v1.jsonld (100%) rename {pkg/internal/ldtestutil => component/models/ld/testutil}/contexts/third_party/w3.org/credentials-examples_v1.jsonld (100%) rename {pkg/internal/ldtestutil => component/models/ld/testutil}/contexts/third_party/w3.org/odrl.jsonld (100%) rename {pkg/internal/ldtestutil => component/models/ld/testutil}/contexts/third_party/w3c-ccg.github.io/citizenship_v1.jsonld (100%) rename {pkg/internal/ldtestutil => component/models/ld/testutil}/contexts/third_party/w3c-ccg.github.io/revocation-list-2021.jsonld (100%) rename {pkg/internal/ldtestutil => component/models/ld/testutil}/document_loader.go (79%) rename {pkg/internal/ldtestutil => component/models/ld/testutil}/document_loader_test.go (65%) create mode 100644 component/models/signature/api/api.go rename {pkg/doc => component/models}/signature/signer/signer.go (91%) create mode 100644 component/models/signature/signer/signer_default.go create mode 100644 component/models/signature/signer/signer_interop.go rename {pkg/doc => component/models}/signature/signer/signer_test.go (71%) rename {pkg/doc => component/models}/signature/signer/testdata/valid_doc.jsonld (100%) rename {pkg/doc => component/models}/signature/suite/bbsblssignature2020/public_key_verifier.go (85%) rename {pkg/doc => component/models}/signature/suite/bbsblssignature2020/public_key_verifier_test.go (89%) rename {pkg/doc => component/models}/signature/suite/bbsblssignature2020/suite.go (85%) rename {pkg/doc => component/models}/signature/suite/bbsblssignature2020/suite_test.go (85%) rename {pkg/doc => component/models}/signature/suite/bbsblssignature2020/testdata/expected_doc.jsonld (100%) rename {pkg/doc => component/models}/signature/suite/bbsblssignature2020/testdata/vc_doc.jsonld (100%) rename {pkg/doc => component/models}/signature/suite/bbsblssignatureproof2020/public_key_verifier.go (86%) rename {pkg/doc => component/models}/signature/suite/bbsblssignatureproof2020/public_key_verifier_test.go (88%) rename {pkg/doc => component/models}/signature/suite/bbsblssignatureproof2020/signer.go (86%) rename {pkg/doc => component/models}/signature/suite/bbsblssignatureproof2020/suite.go (87%) rename {pkg/doc => component/models}/signature/suite/bbsblssignatureproof2020/suite_test.go (83%) create mode 100644 component/models/signature/suite/bbsblssignatureproof2020/testdata/case16_reveal_doc.jsonld create mode 100644 component/models/signature/suite/bbsblssignatureproof2020/testdata/case16_vc.jsonld create mode 100644 component/models/signature/suite/bbsblssignatureproof2020/testdata/case18_reveal_doc.jsonld create mode 100644 component/models/signature/suite/bbsblssignatureproof2020/testdata/case18_vc.jsonld create mode 100644 component/models/signature/suite/bbsblssignatureproof2020/testdata/doc_with_many_proofs.jsonld create mode 100644 component/models/signature/suite/bbsblssignatureproof2020/testdata/expected_doc.rdf create mode 100644 component/models/signature/suite/bbsblssignatureproof2020/testdata/vc_doc.jsonld rename {pkg/doc => component/models}/signature/suite/ecdsasecp256k1signature2019/public_key_verifier.go (85%) rename {pkg/doc => component/models}/signature/suite/ecdsasecp256k1signature2019/public_key_verifier_test.go (66%) rename {pkg/doc => component/models}/signature/suite/ecdsasecp256k1signature2019/suite.go (84%) rename {pkg/doc => component/models}/signature/suite/ecdsasecp256k1signature2019/suite_test.go (100%) rename {pkg/doc => component/models}/signature/suite/ed25519signature2018/public_key_verifier.go (83%) rename {pkg/doc => component/models}/signature/suite/ed25519signature2018/public_key_verifier_test.go (62%) rename {pkg/doc => component/models}/signature/suite/ed25519signature2018/suite.go (83%) rename {pkg/doc => component/models}/signature/suite/ed25519signature2018/suite_crypto_test.go (79%) rename {pkg/doc => component/models}/signature/suite/ed25519signature2018/suite_test.go (100%) rename {pkg/doc => component/models}/signature/suite/ed25519signature2020/public_key_verifier.go (83%) rename {pkg/doc => component/models}/signature/suite/ed25519signature2020/public_key_verifier_test.go (62%) rename {pkg/doc => component/models}/signature/suite/ed25519signature2020/suite.go (83%) rename {pkg/doc => component/models}/signature/suite/ed25519signature2020/suite_crypto_test.go (79%) rename {pkg/doc => component/models}/signature/suite/ed25519signature2020/suite_test.go (100%) rename {pkg/doc => component/models}/signature/suite/jsonwebsignature2020/public_key_verifier.go (92%) rename {pkg/doc => component/models}/signature/suite/jsonwebsignature2020/public_key_verifier_test.go (88%) rename {pkg/doc => component/models}/signature/suite/jsonwebsignature2020/suite.go (86%) rename {pkg/doc => component/models}/signature/suite/jsonwebsignature2020/suite_crypto_test.go (78%) rename {pkg/doc => component/models}/signature/suite/jsonwebsignature2020/suite_test.go (100%) rename {pkg/doc => component/models}/signature/suite/suite.go (89%) rename {pkg/doc => component/models}/signature/suite/suite_crypto.go (80%) rename {pkg/doc => component/models}/signature/suite/suite_crypto_test.go (76%) rename {pkg/doc => component/models}/signature/suite/suite_test.go (91%) rename {pkg/doc/util/signature => component/models/signature/util}/api.go (96%) rename {pkg/doc/util/signature => component/models/signature/util}/internal/signer/crypto_signer.go (96%) rename {pkg/doc/util/signature => component/models/signature/util}/internal/signer/crypto_signer_test.go (88%) rename {pkg/doc/util/signature => component/models/signature/util}/internal/signer/ecdsa.go (100%) rename {pkg/doc/util/signature => component/models/signature/util}/internal/signer/ecdsa_test.go (100%) rename {pkg/doc/util/signature => component/models/signature/util}/internal/signer/ed25519.go (100%) rename {pkg/doc/util/signature => component/models/signature/util}/internal/signer/ed25519_test.go (100%) rename {pkg/doc/util/signature => component/models/signature/util}/internal/signer/rsa.go (100%) rename {pkg/doc/util/signature => component/models/signature/util}/internal/signer/rsa_test.go (100%) rename {pkg/doc/util/signature => component/models/signature/util}/signer.go (90%) rename {pkg/doc/util/signature => component/models/signature/util}/signer_test.go (88%) rename {pkg/doc/util/signature => component/models/signature/util}/utils.go (89%) rename {pkg/doc/util/signature => component/models/signature/util}/utils_test.go (93%) rename {pkg/doc => component/models}/signature/verifier/public_key_verifier.go (98%) rename {pkg/doc => component/models}/signature/verifier/public_key_verifier_test.go (96%) rename {pkg/doc => component/models}/signature/verifier/testdata/valid_doc.jsonld (100%) rename {pkg/doc => component/models}/signature/verifier/verifier.go (71%) rename {pkg/doc => component/models}/signature/verifier/verifier_test.go (89%) create mode 100644 component/models/util/maphelpers/maphelpers.go rename {pkg/doc/util => component/models/util/time}/time.go (96%) rename {pkg/doc/util => component/models/util/time}/time_test.go (99%) rename pkg/mock/storage/mock_store.go => component/storageutil/mock/storage/storage.go (97%) create mode 100644 pkg/common/model/model.go create mode 100644 pkg/doc/did/did.go create mode 100644 pkg/doc/ld/ld.go create mode 100644 pkg/doc/ldcontext/embed/embed.go create mode 100644 pkg/doc/ldcontext/ldcontext.go create mode 100644 pkg/doc/ldcontext/remote/remote.go create mode 100644 pkg/doc/signature/jsonld/jsonld.go create mode 100644 pkg/doc/signature/proof/ldproof.go create mode 100644 pkg/doc/signature/signer/api.go delete mode 100644 pkg/doc/signature/signer/signer_default.go delete mode 100644 pkg/doc/signature/signer/signer_interop.go create mode 100644 pkg/doc/signature/suite/api.go create mode 100644 pkg/doc/signature/suite/bbsblssignature2020/bbsblssignature2020.go create mode 100644 pkg/doc/signature/suite/bbsblssignatureproof2020/bbsblssignatureproof2020.go create mode 100644 pkg/doc/signature/suite/ecdsasecp256k1signature2019/ecdsasecp256k1signature2019.go create mode 100644 pkg/doc/signature/suite/ed25519signature2018/ed25519signature2018.go create mode 100644 pkg/doc/signature/suite/ed25519signature2020/ed25519signature2018.go create mode 100644 pkg/doc/signature/suite/jsonwebsignature2020/jsonwebsignature2020.go create mode 100644 pkg/doc/signature/verifier/api.go create mode 100644 pkg/doc/util/signature/signature.go create mode 100644 pkg/doc/util/timewrapper.go create mode 100644 pkg/internal/ldtestutil/ldtestutil.go create mode 100644 pkg/mock/crypto/crypto.go create mode 100644 pkg/mock/kms/kms.go delete mode 100644 pkg/mock/kms/mock_kms.go create mode 100644 pkg/mock/ld/ld.go delete mode 100644 pkg/mock/ld/mock_remote_provider_store.go delete mode 100644 pkg/mock/ld/mock_service.go delete mode 100644 pkg/mock/secretlock/mock_secretlock.go create mode 100644 pkg/mock/secretlock/secretlock.go create mode 100644 pkg/mock/storage/storage.go create mode 100644 pkg/store/ld/ld.go diff --git a/cmd/aries-agent-mobile/go.mod b/cmd/aries-agent-mobile/go.mod index 23a9eb022..76061803e 100644 --- a/cmd/aries-agent-mobile/go.mod +++ b/cmd/aries-agent-mobile/go.mod @@ -34,6 +34,7 @@ require ( github.com/gorilla/mux v1.7.3 // indirect github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0 // indirect github.com/hyperledger/aries-framework-go/component/log v0.0.0 // indirect + github.com/hyperledger/aries-framework-go/component/models v0.0.0 // indirect github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20221025204933-b807371b6f1e // indirect github.com/hyperledger/ursa-wrapper-go v0.3.1 // indirect github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect @@ -72,6 +73,7 @@ replace ( github.com/hyperledger/aries-framework-go => ../../ github.com/hyperledger/aries-framework-go/component/kmscrypto => ../../component/kmscrypto github.com/hyperledger/aries-framework-go/component/log => ../../component/log + github.com/hyperledger/aries-framework-go/component/models => ../../component/models // github.com/hyperledger/aries-framework-go/component/storage/edv => ../../component/storage/edv // TODO (#2815) remove this once the wallet package doesn't import edv github.com/hyperledger/aries-framework-go/component/storageutil => ../../component/storageutil github.com/hyperledger/aries-framework-go/spi => ../../spi diff --git a/cmd/aries-agent-rest/go.mod b/cmd/aries-agent-rest/go.mod index 5125a260f..218522a68 100644 --- a/cmd/aries-agent-rest/go.mod +++ b/cmd/aries-agent-rest/go.mod @@ -38,6 +38,7 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0 // indirect github.com/hyperledger/aries-framework-go/component/log v0.0.0 // indirect + github.com/hyperledger/aries-framework-go/component/models v0.0.0 // indirect github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20221025204933-b807371b6f1e // indirect github.com/hyperledger/ursa-wrapper-go v0.3.1 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect @@ -109,6 +110,7 @@ replace ( github.com/hyperledger/aries-framework-go => ../.. github.com/hyperledger/aries-framework-go/component/kmscrypto => ../../component/kmscrypto github.com/hyperledger/aries-framework-go/component/log => ../../component/log + github.com/hyperledger/aries-framework-go/component/models => ../../component/models // github.com/hyperledger/aries-framework-go/component/storage/edv => ../../component/storage/edv // TODO (#2815) remove this once the wallet package doesn't import edv github.com/hyperledger/aries-framework-go/component/storage/leveldb => ../../component/storage/leveldb github.com/hyperledger/aries-framework-go/component/storageutil => ../../component/storageutil diff --git a/cmd/aries-js-worker/go.mod b/cmd/aries-js-worker/go.mod index 07cb872b3..0be5afcc8 100644 --- a/cmd/aries-js-worker/go.mod +++ b/cmd/aries-js-worker/go.mod @@ -32,6 +32,7 @@ require ( github.com/gorilla/mux v1.7.3 // indirect github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0 // indirect github.com/hyperledger/aries-framework-go/component/log v0.0.0 // indirect + github.com/hyperledger/aries-framework-go/component/models v0.0.0 // indirect github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20221025204933-b807371b6f1e // indirect github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20221025204933-b807371b6f1e // indirect github.com/hyperledger/ursa-wrapper-go v0.3.1 // indirect @@ -73,6 +74,7 @@ replace ( github.com/hyperledger/aries-framework-go => ../.. github.com/hyperledger/aries-framework-go/component/kmscrypto => ../../component/kmscrypto github.com/hyperledger/aries-framework-go/component/log => ../../component/log + github.com/hyperledger/aries-framework-go/component/models => ../../component/models github.com/hyperledger/aries-framework-go/component/storage/edv => ../../component/storage/edv // TODO (#2815) remove this once the wallet package doesn't import edv github.com/hyperledger/aries-framework-go/component/storage/indexeddb => ../../component/storage/indexeddb github.com/hyperledger/aries-framework-go/component/storageutil => ../../component/storageutil diff --git a/pkg/mock/crypto/mock_crypto.go b/component/kmscrypto/mock/crypto/mock_crypto.go similarity index 91% rename from pkg/mock/crypto/mock_crypto.go rename to component/kmscrypto/mock/crypto/mock_crypto.go index 88c5e480b..b05820d0d 100644 --- a/pkg/mock/crypto/mock_crypto.go +++ b/component/kmscrypto/mock/crypto/mock_crypto.go @@ -7,7 +7,7 @@ SPDX-License-Identifier: Apache-2.0 package crypto import ( - cryptoapi "github.com/hyperledger/aries-framework-go/pkg/crypto" + cryptoapi "github.com/hyperledger/aries-framework-go/spi/crypto" ) // SignFunc mocks Crypto's Sign() function, it's useful for executing custom signing with the help of SignKey. @@ -116,22 +116,25 @@ func (c *Crypto) SignMulti(messages [][]byte, kh interface{}) ([]byte, error) { // VerifyMulti returns a mocked BBS+ verify result. // returns: -// error in case of errors or nil if signature verification was successful +// +// error in case of errors or nil if signature verification was successful func (c *Crypto) VerifyMulti(messages [][]byte, signature []byte, kh interface{}) error { return c.BBSVerifyErr } // VerifyProof returns a mocked BBS+ verify signature proof result. // returns: -// error in case of errors or nil if signature proof verification was successful +// +// error in case of errors or nil if signature proof verification was successful func (c *Crypto) VerifyProof(revealedMessages [][]byte, proof, nonce []byte, signerPubKH interface{}) error { return c.VerifyProofErr } // DeriveProof returns a mocked BBS+ signature proof value and a mocked error. // returns: -// signature proof in []byte -// error in case of errors +// +// signature proof in []byte +// error in case of errors func (c *Crypto) DeriveProof(messages [][]byte, bbsSignature, nonce []byte, revealedIndexes []int, signerPubKH interface{}) ([]byte, error) { if c.DeriveProofFn != nil { @@ -143,25 +146,28 @@ func (c *Crypto) DeriveProof(messages [][]byte, bbsSignature, nonce []byte, reve // Blind returns a mocked blinded vals and a mocked error. // returns: -// blinded values in []byte -// error in case of errors +// +// blinded values in []byte +// error in case of errors func (c *Crypto) Blind(kh interface{}, values ...map[string]interface{}) ([][]byte, error) { return c.BlindValue, c.BlindError } // GetCorrectnessProof returns a mocked correctness proof value and a mocked error. // returns: -// correctness proof in []byte -// error in case of errors +// +// correctness proof in []byte +// error in case of errors func (c *Crypto) GetCorrectnessProof(kh interface{}) ([]byte, error) { return c.GetCorrectnessProofValue, c.GetCorrectnessProofError } // SignWithSecrets returns the mocked signature and correctness proof values and a mocked error. // returns: -// signature in []byte -// correctness proof in []byte -// error in case of errors +// +// signature in []byte +// correctness proof in []byte +// error in case of errors func (c *Crypto) SignWithSecrets(kh interface{}, values map[string]interface{}, secrets []byte, correctnessProof []byte, nonces [][]byte, did string) ([]byte, []byte, error) { return c.SignWithSecretsValue, c.SignWithSecretsProof, c.SignWithSecretsError diff --git a/pkg/doc/did/doc.go b/component/models/did/doc.go similarity index 97% rename from pkg/doc/did/doc.go rename to component/models/did/doc.go index 56cafe7d4..3882c2a56 100644 --- a/pkg/doc/did/doc.go +++ b/component/models/did/doc.go @@ -21,12 +21,12 @@ import ( "github.com/multiformats/go-multibase" "github.com/xeipuuv/gojsonschema" - "github.com/hyperledger/aries-framework-go/pkg/common/log" - "github.com/hyperledger/aries-framework-go/pkg/common/model" - "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" - sigproof "github.com/hyperledger/aries-framework-go/pkg/doc/signature/proof" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" + "github.com/hyperledger/aries-framework-go/component/log" + "github.com/hyperledger/aries-framework-go/component/models/did/endpoint" + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" + sigproof "github.com/hyperledger/aries-framework-go/component/models/ld/proof" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" ) const ( @@ -377,7 +377,7 @@ type Service struct { Priority interface{} `json:"priority,omitempty"` RecipientKeys []string `json:"recipientKeys,omitempty"` RoutingKeys []string `json:"routingKeys,omitempty"` - ServiceEndpoint model.Endpoint `json:"serviceEndpoint"` + ServiceEndpoint endpoint.Endpoint `json:"serviceEndpoint"` Accept []string `json:"accept,omitempty"` Properties map[string]interface{} `json:"properties,omitempty"` recipientKeysRelativeURL map[string]bool @@ -675,14 +675,14 @@ func populateServices(didID, baseURI string, rawServices []map[string]interface{ routingKeys, routingKeysRelativeURL = populateKeys(routingKeys, didID, baseURI) } - var sp model.Endpoint + var sp endpoint.Endpoint //nolint:nestif if epEntry, ok := rawService[jsonldServicePoint]; ok { uriStr, ok := epEntry.(string) // for now handling DIDComm V1 or V2 only. if ok { // DIDComm V1 format. - sp = model.NewDIDCommV1Endpoint(uriStr) + sp = endpoint.NewDIDCommV1Endpoint(uriStr) } else if epEntry != nil { // DIDComm V2 format (first valid entry for now). entries, ok := epEntry.([]interface{}) if ok && len(entries) > 0 { @@ -691,14 +691,14 @@ func populateServices(didID, baseURI string, rawServices []map[string]interface{ epURI := stringEntry(firstEntry["uri"]) epAccept := stringArray(firstEntry["accept"]) epRoutingKeys := stringArray(firstEntry["routingKeys"]) - sp = model.NewDIDCommV2Endpoint([]model.DIDCommV2Endpoint{ + sp = endpoint.NewDIDCommV2Endpoint([]endpoint.DIDCommV2Endpoint{ {URI: epURI, Accept: epAccept, RoutingKeys: epRoutingKeys}, }) } } coreServices, ok := epEntry.(map[string]interface{}) // DID Core if ok && len(coreServices) > 0 { - sp = model.NewDIDCoreEndpoint(coreServices) + sp = endpoint.NewDIDCoreEndpoint(coreServices) } } } @@ -1208,7 +1208,7 @@ func (doc *Doc) MarshalJSON() ([]byte, error) { } // VerifyProof verifies document proofs. -func (doc *Doc) VerifyProof(suites []verifier.SignatureSuite, jsonldOpts ...jsonld.ProcessorOpts) error { +func (doc *Doc) VerifyProof(suites []verifier.SignatureSuite, jsonldOpts ...processor.Opts) error { if len(doc.Proof) == 0 { return ErrProofNotFound } @@ -1360,8 +1360,8 @@ func populateRawServices(services []Service, didID, baseURI string) []map[string logger.Debugf("URI field of DIDComm V2 endpoint missing or invalid, it will be ignored: %w", err) } - if services[i].ServiceEndpoint.Type() == model.DIDCommV2 { - services[i].ServiceEndpoint = model.NewDIDCommV2Endpoint([]model.DIDCommV2Endpoint{ + if services[i].ServiceEndpoint.Type() == endpoint.DIDCommV2 { + services[i].ServiceEndpoint = endpoint.NewDIDCommV2Endpoint([]endpoint.DIDCommV2Endpoint{ {URI: sepURI, Accept: sepAccept, RoutingKeys: sepRoutingKeys}, }) } @@ -1384,7 +1384,7 @@ func populateRawServices(services []Service, didID, baseURI string) []map[string rawService[jsonldType] = services[i].Type - if services[i].ServiceEndpoint.Type() == model.DIDCommV2 { //nolint: gocritic + if services[i].ServiceEndpoint.Type() == endpoint.DIDCommV2 { //nolint: gocritic serviceEndpointMap := []map[string]interface{}{{"uri": sepURI}} if len(sepAccept) > 0 { serviceEndpointMap[0]["accept"] = sepAccept @@ -1395,7 +1395,7 @@ func populateRawServices(services []Service, didID, baseURI string) []map[string } rawService[jsonldServicePoint] = serviceEndpointMap - } else if services[i].ServiceEndpoint.Type() == model.DIDCommV1 { + } else if services[i].ServiceEndpoint.Type() == endpoint.DIDCommV1 { rawService[jsonldServicePoint] = sepURI } else { bytes, err := services[i].ServiceEndpoint.MarshalJSON() diff --git a/pkg/doc/did/doc_test.go b/component/models/did/doc_test.go similarity index 97% rename from pkg/doc/did/doc_test.go rename to component/models/did/doc_test.go index 5db0301dc..eec05674e 100644 --- a/pkg/doc/did/doc_test.go +++ b/component/models/did/doc_test.go @@ -23,14 +23,14 @@ import ( gojose "github.com/go-jose/go-jose/v3" "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/common/model" - "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/signer" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite/ed25519signature2018" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite/ed25519signature2020" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" - "github.com/hyperledger/aries-framework-go/pkg/internal/ldtestutil" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" + "github.com/hyperledger/aries-framework-go/component/models/did/endpoint" + "github.com/hyperledger/aries-framework-go/component/models/ld/testutil" + "github.com/hyperledger/aries-framework-go/component/models/signature/signer" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite/ed25519signature2018" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite/ed25519signature2020" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" ) const pemPK = `-----BEGIN PUBLIC KEY----- @@ -153,7 +153,7 @@ func TestValidWithDocBase(t *testing.T) { ID: "did:example:123456789abcdefghi#inbox", Type: "SocialWebInboxService", relativeURL: true, - ServiceEndpoint: model.NewDIDCommV1Endpoint("https://social.example.com/83hfh37dj"), + ServiceEndpoint: endpoint.NewDIDCommV1Endpoint("https://social.example.com/83hfh37dj"), Properties: map[string]interface{}{"spamCost": map[string]interface{}{"amount": "0.50", "currency": "USD"}}, }, { @@ -163,7 +163,7 @@ func TestValidWithDocBase(t *testing.T) { relativeURL: true, RecipientKeys: []string{"did:example:123456789abcdefghi#key2"}, RoutingKeys: []string{"did:example:123456789abcdefghi#key2"}, - ServiceEndpoint: model.NewDIDCommV1Endpoint("https://agent.example.com/"), + ServiceEndpoint: endpoint.NewDIDCommV1Endpoint("https://agent.example.com/"), Properties: map[string]interface{}{}, recipientKeysRelativeURL: map[string]bool{"did:example:123456789abcdefghi#key2": true}, routingKeysRelativeURL: map[string]bool{"did:example:123456789abcdefghi#key2": true}, @@ -420,7 +420,7 @@ func TestValid(t *testing.T) { { ID: "did:example:123456789abcdefghi#inbox", Type: []interface{}{"SocialWebInboxService"}, - ServiceEndpoint: model.NewDIDCommV1Endpoint("https://social.example.com/83hfh37dj"), + ServiceEndpoint: endpoint.NewDIDCommV1Endpoint("https://social.example.com/83hfh37dj"), Properties: map[string]interface{}{"spamCost": map[string]interface{}{"amount": "0.50", "currency": "USD"}}, }, { @@ -429,7 +429,7 @@ func TestValid(t *testing.T) { Priority: float64(0), RecipientKeys: []string{"did:example:123456789abcdefghi#key2"}, RoutingKeys: []string{"did:example:123456789abcdefghi#key2"}, - ServiceEndpoint: model.NewDIDCommV1Endpoint("https://agent.example.com/"), + ServiceEndpoint: endpoint.NewDIDCommV1Endpoint("https://agent.example.com/"), Properties: map[string]interface{}{}, recipientKeysRelativeURL: map[string]bool{"did:example:123456789abcdefghi#key2": false}, routingKeysRelativeURL: map[string]bool{"did:example:123456789abcdefghi#key2": false}, @@ -439,7 +439,7 @@ func TestValid(t *testing.T) { Type: "DIDCommMessaging", Priority: float64(0), RecipientKeys: []string{"did:example:123456789abcdefghi#key2"}, - ServiceEndpoint: model.NewDIDCommV2Endpoint([]model.DIDCommV2Endpoint{{ + ServiceEndpoint: endpoint.NewDIDCommV2Endpoint([]endpoint.DIDCommV2Endpoint{{ URI: "https://agent.example.com/", Accept: []string{"didcomm/v2"}, RoutingKeys: []string{"did:example:123456789abcdefghi#key2"}, @@ -1390,17 +1390,17 @@ func TestVerifyProof(t *testing.T) { doc, err := ParseDocument(signedDoc) require.Nil(t, err) require.NotNil(t, doc) - err = doc.VerifyProof([]verifier.SignatureSuite{s}, ldtestutil.WithDocumentLoader(t)) + err = doc.VerifyProof([]verifier.SignatureSuite{s}, testutil.WithDocumentLoader(t)) require.NoError(t, err) // error - no suites are passed, verifier is not created - err = doc.VerifyProof([]verifier.SignatureSuite{}, ldtestutil.WithDocumentLoader(t)) + err = doc.VerifyProof([]verifier.SignatureSuite{}, testutil.WithDocumentLoader(t)) require.Error(t, err) require.Contains(t, err.Error(), "create verifier") // error - doc with invalid proof value doc.Proof[0].ProofValue = []byte("invalid") - err = doc.VerifyProof([]verifier.SignatureSuite{s}, ldtestutil.WithDocumentLoader(t)) + err = doc.VerifyProof([]verifier.SignatureSuite{s}, testutil.WithDocumentLoader(t)) require.NotNil(t, err) require.Contains(t, err.Error(), "ed25519: invalid signature") @@ -1408,7 +1408,7 @@ func TestVerifyProof(t *testing.T) { doc, err = ParseDocument([]byte(d)) require.NoError(t, err) require.NotNil(t, doc) - err = doc.VerifyProof([]verifier.SignatureSuite{s}, ldtestutil.WithDocumentLoader(t)) + err = doc.VerifyProof([]verifier.SignatureSuite{s}, testutil.WithDocumentLoader(t)) require.Equal(t, ErrProofNotFound, err) require.Contains(t, err.Error(), "proof not found") } @@ -1430,17 +1430,17 @@ func TestVerifyProofWithEd25519signature2020(t *testing.T) { doc, err := ParseDocument(signedDoc) require.Nil(t, err) require.NotNil(t, doc) - err = doc.VerifyProof([]verifier.SignatureSuite{s}, ldtestutil.WithDocumentLoader(t)) + err = doc.VerifyProof([]verifier.SignatureSuite{s}, testutil.WithDocumentLoader(t)) require.NoError(t, err) // error - no suites are passed, verifier is not created - err = doc.VerifyProof([]verifier.SignatureSuite{}, ldtestutil.WithDocumentLoader(t)) + err = doc.VerifyProof([]verifier.SignatureSuite{}, testutil.WithDocumentLoader(t)) require.Error(t, err) require.Contains(t, err.Error(), "create verifier") // error - doc with invalid proof value doc.Proof[0].ProofValue = []byte("invalid") - err = doc.VerifyProof([]verifier.SignatureSuite{s}, ldtestutil.WithDocumentLoader(t)) + err = doc.VerifyProof([]verifier.SignatureSuite{s}, testutil.WithDocumentLoader(t)) require.NotNil(t, err) require.Contains(t, err.Error(), "ed25519: invalid signature") @@ -1448,7 +1448,7 @@ func TestVerifyProofWithEd25519signature2020(t *testing.T) { doc, err = ParseDocument([]byte(d)) require.NoError(t, err) require.NotNil(t, doc) - err = doc.VerifyProof([]verifier.SignatureSuite{s}, ldtestutil.WithDocumentLoader(t)) + err = doc.VerifyProof([]verifier.SignatureSuite{s}, testutil.WithDocumentLoader(t)) require.Equal(t, ErrProofNotFound, err) require.Contains(t, err.Error(), "proof not found") } @@ -2032,7 +2032,7 @@ func createSignedDidDocument(t *testing.T, privKey, pubKey []byte) []byte { s := signer.New(ed25519signature2018.New( suite.WithSigner(getSigner(privKey)))) - signedDoc, err := s.Sign(context, jsonDoc, ldtestutil.WithDocumentLoader(t)) + signedDoc, err := s.Sign(context, jsonDoc, testutil.WithDocumentLoader(t)) require.NoError(t, err) return signedDoc @@ -2059,7 +2059,7 @@ func createSignedDidDocumentWithEd25519signature2020(t *testing.T, privKey, pubK s := signer.New(ed25519signature2020.New( suite.WithSigner(getSigner(privKey)))) - signedDoc, err := s.Sign(context, jsonDoc, ldtestutil.WithDocumentLoader(t)) + signedDoc, err := s.Sign(context, jsonDoc, testutil.WithDocumentLoader(t)) require.NoError(t, err) return signedDoc diff --git a/pkg/common/model/endpoint.go b/component/models/did/endpoint/endpoint.go similarity index 98% rename from pkg/common/model/endpoint.go rename to component/models/did/endpoint/endpoint.go index 4b1323e50..e37b0c54c 100644 --- a/pkg/common/model/endpoint.go +++ b/component/models/did/endpoint/endpoint.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package model +package endpoint import ( "encoding/json" @@ -13,7 +13,7 @@ import ( ) // EndpointType endpoint type. -type EndpointType int +type EndpointType int // nolint: golint const ( // DIDCommV1 type. @@ -81,7 +81,8 @@ func NewDIDCoreEndpoint(genericEndpoint interface{}) Endpoint { // 1- DIDComm V2 URI (currently the first element's URI). TODO enhance API to pass in an optional index. // 2- DIDComm V1 URI // 3- DIDCore's first element printed as string for now. (not used by AFGO at the time of this writing, but can be -// enhanced if needed). +// +// enhanced if needed). func (s *Endpoint) URI() (string, error) { // TODO for now, returning URI of first element. Add mechanism to fetch from appropriate index. if len(s.rawDIDCommV2) > 0 { diff --git a/pkg/common/model/endpoint_test.go b/component/models/did/endpoint/endpoint_test.go similarity index 99% rename from pkg/common/model/endpoint_test.go rename to component/models/did/endpoint/endpoint_test.go index 4fe796adf..f8313c3fe 100644 --- a/pkg/common/model/endpoint_test.go +++ b/component/models/did/endpoint/endpoint_test.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package model +package endpoint import ( "fmt" diff --git a/pkg/doc/did/helpers.go b/component/models/did/helpers.go similarity index 100% rename from pkg/doc/did/helpers.go rename to component/models/did/helpers.go diff --git a/pkg/doc/did/legacy.go b/component/models/did/legacy.go similarity index 100% rename from pkg/doc/did/legacy.go rename to component/models/did/legacy.go diff --git a/pkg/doc/did/legacy_test.go b/component/models/did/legacy_test.go similarity index 93% rename from pkg/doc/did/legacy_test.go rename to component/models/did/legacy_test.go index 935116226..c9bc7fbb0 100644 --- a/pkg/doc/did/legacy_test.go +++ b/component/models/did/legacy_test.go @@ -12,7 +12,7 @@ import ( "github.com/mitchellh/mapstructure" "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/common/model" + "github.com/hyperledger/aries-framework-go/component/models/did/endpoint" ) func TestToLegacyRawDoc(t *testing.T) { @@ -57,7 +57,7 @@ func TestPopulateRawServicesLegacy(t *testing.T) { Priority: 0, RecipientKeys: []string{"key1"}, RoutingKeys: []string{"key2"}, - ServiceEndpoint: model.NewDIDCommV1Endpoint("https://agent.example.com/"), + ServiceEndpoint: endpoint.NewDIDCommV1Endpoint("https://agent.example.com/"), Properties: map[string]interface{}{}, }, { @@ -67,7 +67,7 @@ func TestPopulateRawServicesLegacy(t *testing.T) { relativeURL: true, RecipientKeys: []string{"did:example:123456789abcdefghi#key1"}, RoutingKeys: []string{"did:example:123456789abcdefghi#key2"}, - ServiceEndpoint: model.NewDIDCommV1Endpoint("https://agent.example.com/"), + ServiceEndpoint: endpoint.NewDIDCommV1Endpoint("https://agent.example.com/"), Properties: map[string]interface{}{}, recipientKeysRelativeURL: map[string]bool{"did:example:123456789abcdefghi#key1": true}, routingKeysRelativeURL: map[string]bool{"did:example:123456789abcdefghi#key2": true}, diff --git a/pkg/doc/did/schema.go b/component/models/did/schema.go similarity index 100% rename from pkg/doc/did/schema.go rename to component/models/did/schema.go diff --git a/pkg/doc/did/serialize_default.go b/component/models/did/serialize_default.go similarity index 100% rename from pkg/doc/did/serialize_default.go rename to component/models/did/serialize_default.go diff --git a/pkg/doc/did/serialize_interop.go b/component/models/did/serialize_interop.go similarity index 100% rename from pkg/doc/did/serialize_interop.go rename to component/models/did/serialize_interop.go diff --git a/pkg/doc/did/testdata/invalid_doc.jsonld b/component/models/did/testdata/invalid_doc.jsonld similarity index 100% rename from pkg/doc/did/testdata/invalid_doc.jsonld rename to component/models/did/testdata/invalid_doc.jsonld diff --git a/pkg/doc/did/testdata/valid_doc.jsonld b/component/models/did/testdata/valid_doc.jsonld similarity index 100% rename from pkg/doc/did/testdata/valid_doc.jsonld rename to component/models/did/testdata/valid_doc.jsonld diff --git a/pkg/doc/did/testdata/valid_doc_resolution.jsonld b/component/models/did/testdata/valid_doc_resolution.jsonld similarity index 100% rename from pkg/doc/did/testdata/valid_doc_resolution.jsonld rename to component/models/did/testdata/valid_doc_resolution.jsonld diff --git a/pkg/doc/did/testdata/valid_doc_v0.11.jsonld b/component/models/did/testdata/valid_doc_v0.11.jsonld similarity index 100% rename from pkg/doc/did/testdata/valid_doc_v0.11.jsonld rename to component/models/did/testdata/valid_doc_v0.11.jsonld diff --git a/pkg/doc/did/testdata/valid_doc_with_base.jsonld b/component/models/did/testdata/valid_doc_with_base.jsonld similarity index 100% rename from pkg/doc/did/testdata/valid_doc_with_base.jsonld rename to component/models/did/testdata/valid_doc_with_base.jsonld diff --git a/pkg/doc/did/testdata/valid_doc_with_service_endpoint.jsonld b/component/models/did/testdata/valid_doc_with_service_endpoint.jsonld similarity index 100% rename from pkg/doc/did/testdata/valid_doc_with_service_endpoint.jsonld rename to component/models/did/testdata/valid_doc_with_service_endpoint.jsonld diff --git a/component/models/go.mod b/component/models/go.mod new file mode 100644 index 000000000..9e26092ca --- /dev/null +++ b/component/models/go.mod @@ -0,0 +1,50 @@ +// Copyright Gen Digital Inc. All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 + +module github.com/hyperledger/aries-framework-go/component/models + +go 1.19 + +require ( + github.com/btcsuite/btcd v0.22.0-beta + github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce + github.com/go-jose/go-jose/v3 v3.0.1-0.20221117193127-916db76e8214 + github.com/google/tink/go v1.7.0 + github.com/google/uuid v1.3.0 + github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0-20220322085443-50e8f9bd208b + github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230417184158-344a7f82c4c2 + github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20220322085443-50e8f9bd208b + github.com/hyperledger/aries-framework-go/spi v0.0.0-20230417184158-344a7f82c4c2 + github.com/mitchellh/mapstructure v1.5.0 + github.com/multiformats/go-multibase v0.1.1 + github.com/piprate/json-gold v0.4.2 + github.com/stretchr/testify v1.8.1 + github.com/xeipuuv/gojsonschema v1.2.0 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/hyperledger/ursa-wrapper-go v0.3.1 // indirect + github.com/kilic/bls12-381 v0.1.1-0.20210503002446-7b7597926c69 // indirect + github.com/mr-tron/base58 v1.1.3 // indirect + github.com/multiformats/go-base32 v0.0.3 // indirect + github.com/multiformats/go-base36 v0.1.0 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/pquerna/cachecontrol v0.1.0 // indirect + github.com/teserakt-io/golang-ed25519 v0.0.0-20210104091850-3888c087a4c8 // indirect + github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect + github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect + golang.org/x/crypto v0.1.0 // indirect + golang.org/x/sys v0.1.0 // indirect + google.golang.org/protobuf v1.28.1 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) + +replace github.com/hyperledger/aries-framework-go/component/storageutil => ../storageutil + +replace github.com/hyperledger/aries-framework-go/component/kmscrypto => ../kmscrypto + +replace github.com/hyperledger/aries-framework-go/spi => ../../spi diff --git a/component/models/go.sum b/component/models/go.sum new file mode 100644 index 000000000..1aa1faa54 --- /dev/null +++ b/component/models/go.sum @@ -0,0 +1,123 @@ +github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= +github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= +github.com/btcsuite/btcd v0.22.0-beta h1:LTDpDKUM5EeOFBPM8IXpinEcmZ6FWfNZbE3lfrfdnWo= +github.com/btcsuite/btcd v0.22.0-beta/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA= +github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= +github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= +github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce h1:YtWJF7RHm2pYCvA5t0RPmAaLUhREsKuKd+SLhxFbFeQ= +github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:0DVlHczLPewLcPGEIeUEzfOJhqGPQ0mJJRDBtD307+o= +github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= +github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= +github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I= +github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= +github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= +github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= +github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= +github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/go-jose/go-jose/v3 v3.0.1-0.20221117193127-916db76e8214 h1:w5li6eMV6NCHh1YVbKRM/gMCVtZ2w7mnwq78eNnHXQQ= +github.com/go-jose/go-jose/v3 v3.0.1-0.20221117193127-916db76e8214/go.mod h1:RNkWWRld676jZEYoV3+XK8L2ZnNSvIsxFMht0mSX+u8= +github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= +github.com/google/tink/go v1.7.0 h1:6Eox8zONGebBFcCBqkVmt60LaWZa6xg1cl/DwAh/J1w= +github.com/google/tink/go v1.7.0/go.mod h1:GAUOd+QE3pgj9q8VKIGTCP33c/B7eb4NhxLcgTJZStM= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230417184158-344a7f82c4c2 h1:fKaNw6yi5PIXRDmEiOPNIErS6Mv92m03JcAE7wxj/Bk= +github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230417184158-344a7f82c4c2/go.mod h1:CvYs4l8X2NrrF93weLOu5RTOIJeVdoZITtjEflyuTyM= +github.com/hyperledger/ursa-wrapper-go v0.3.1 h1:Do+QrVNniY77YK2jTIcyWqj9rm/Yb5SScN0bqCjiibA= +github.com/hyperledger/ursa-wrapper-go v0.3.1/go.mod h1:nPSAuMasIzSVciQo22PedBk4Opph6bJ6ia3ms7BH/mk= +github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= +github.com/kilic/bls12-381 v0.1.1-0.20210503002446-7b7597926c69 h1:kMJlf8z8wUcpyI+FQJIdGjAhfTww1y0AbQEv86bpVQI= +github.com/kilic/bls12-381 v0.1.1-0.20210503002446-7b7597926c69/go.mod h1:tlkavyke+Ac7h8R3gZIjI5LKBcvMlSWnXNMgT3vZXo8= +github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mr-tron/base58 v1.1.3 h1:v+sk57XuaCKGXpWtVBX8YJzO7hMGx4Aajh4TQbdEFdc= +github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= +github.com/multiformats/go-base32 v0.0.3 h1:tw5+NhuwaOjJCC5Pp82QuXbrmLzWg7uxlMFp8Nq/kkI= +github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= +github.com/multiformats/go-base36 v0.1.0 h1:JR6TyF7JjGd3m6FbLU2cOxhC0Li8z8dLNGQ89tUg4F4= +github.com/multiformats/go-base36 v0.1.0/go.mod h1:kFGE83c6s80PklsHO9sRn2NCoffoRdUUOENyW/Vv6sM= +github.com/multiformats/go-multibase v0.1.1 h1:3ASCDsuLX8+j4kx58qnJ4YFq/JWTJpCyDW27ztsVTOI= +github.com/multiformats/go-multibase v0.1.1/go.mod h1:ZEjHE+IsUrgp5mhlEAYjMtZwK1k4haNkcaPg9aoe1a8= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= +github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/piprate/json-gold v0.4.2 h1:Rq8V+637HOFcj20KdTqW/g/llCwX2qtau0g5d1pD79o= +github.com/piprate/json-gold v0.4.2/go.mod h1:OK1z7UgtBZk06n2cDE2OSq1kffmjFFp5/2yhLLCz9UM= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA= +github.com/pquerna/cachecontrol v0.1.0 h1:yJMy84ti9h/+OEWa752kBTKv4XC30OtVVHYv/8cTqKc= +github.com/pquerna/cachecontrol v0.1.0/go.mod h1:NrUG3Z7Rdu85UNR3vm7SOsl1nFIeSiQnrHV5K9mBcUI= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/teserakt-io/golang-ed25519 v0.0.0-20210104091850-3888c087a4c8 h1:RBkacARv7qY5laaXGlF4wFB/tk5rnthhPb8oIBGoagY= +github.com/teserakt-io/golang-ed25519 v0.0.0-20210104091850-3888c087a4c8/go.mod h1:9PdLyPiZIiW3UopXyRnPYyjUXSpiQNHRLu8fOsR3o8M= +github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c= +github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= +github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= +github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= +golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= +golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= +golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/doc/ldcontext/document.go b/component/models/ld/context/document.go similarity index 96% rename from pkg/doc/ldcontext/document.go rename to component/models/ld/context/document.go index ba19cabd0..f4ce943fa 100644 --- a/pkg/doc/ldcontext/document.go +++ b/component/models/ld/context/document.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package ldcontext +package context import "encoding/json" diff --git a/pkg/doc/ldcontext/embed/embed_contexts.go b/component/models/ld/context/embed/embed_contexts.go similarity index 98% rename from pkg/doc/ldcontext/embed/embed_contexts.go rename to component/models/ld/context/embed/embed_contexts.go index 3dec46ec0..a69ec5b1b 100644 --- a/pkg/doc/ldcontext/embed/embed_contexts.go +++ b/component/models/ld/context/embed/embed_contexts.go @@ -9,7 +9,7 @@ package embed import ( _ "embed" //nolint:gci // required for go:embed - "github.com/hyperledger/aries-framework-go/pkg/doc/ldcontext" + ldcontext "github.com/hyperledger/aries-framework-go/component/models/ld/context" ) // nolint:gochecknoglobals // required for go:embed diff --git a/pkg/doc/ldcontext/embed/third_party/digitalbazaar.github.io/ed25519-signature-2018-v1.jsonld b/component/models/ld/context/embed/third_party/digitalbazaar.github.io/ed25519-signature-2018-v1.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/digitalbazaar.github.io/ed25519-signature-2018-v1.jsonld rename to component/models/ld/context/embed/third_party/digitalbazaar.github.io/ed25519-signature-2018-v1.jsonld diff --git a/pkg/doc/ldcontext/embed/third_party/digitalbazaar.github.io/ed25519-signature-2020-v1.jsonld b/component/models/ld/context/embed/third_party/digitalbazaar.github.io/ed25519-signature-2020-v1.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/digitalbazaar.github.io/ed25519-signature-2020-v1.jsonld rename to component/models/ld/context/embed/third_party/digitalbazaar.github.io/ed25519-signature-2020-v1.jsonld diff --git a/pkg/doc/ldcontext/embed/third_party/identity.foundation/credential-application.jsonld b/component/models/ld/context/embed/third_party/identity.foundation/credential-application.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/identity.foundation/credential-application.jsonld rename to component/models/ld/context/embed/third_party/identity.foundation/credential-application.jsonld diff --git a/pkg/doc/ldcontext/embed/third_party/identity.foundation/credential-response.jsonld b/component/models/ld/context/embed/third_party/identity.foundation/credential-response.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/identity.foundation/credential-response.jsonld rename to component/models/ld/context/embed/third_party/identity.foundation/credential-response.jsonld diff --git a/pkg/doc/ldcontext/embed/third_party/identity.foundation/presentation-submission_v1.jsonld b/component/models/ld/context/embed/third_party/identity.foundation/presentation-submission_v1.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/identity.foundation/presentation-submission_v1.jsonld rename to component/models/ld/context/embed/third_party/identity.foundation/presentation-submission_v1.jsonld diff --git a/pkg/doc/ldcontext/embed/third_party/ns.did.ai/secp256k1-2019_v1.jsonld b/component/models/ld/context/embed/third_party/ns.did.ai/secp256k1-2019_v1.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/ns.did.ai/secp256k1-2019_v1.jsonld rename to component/models/ld/context/embed/third_party/ns.did.ai/secp256k1-2019_v1.jsonld diff --git a/pkg/doc/ldcontext/embed/third_party/ns.did.ai/x25519-2019_v1.jsonld b/component/models/ld/context/embed/third_party/ns.did.ai/x25519-2019_v1.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/ns.did.ai/x25519-2019_v1.jsonld rename to component/models/ld/context/embed/third_party/ns.did.ai/x25519-2019_v1.jsonld diff --git a/pkg/doc/ldcontext/embed/third_party/w3.org/credentials_v1.jsonld b/component/models/ld/context/embed/third_party/w3.org/credentials_v1.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/w3.org/credentials_v1.jsonld rename to component/models/ld/context/embed/third_party/w3.org/credentials_v1.jsonld diff --git a/pkg/doc/ldcontext/embed/third_party/w3.org/did_v1.jsonld b/component/models/ld/context/embed/third_party/w3.org/did_v1.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/w3.org/did_v1.jsonld rename to component/models/ld/context/embed/third_party/w3.org/did_v1.jsonld diff --git a/pkg/doc/ldcontext/embed/third_party/w3.org/odrl.jsonld b/component/models/ld/context/embed/third_party/w3.org/odrl.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/w3.org/odrl.jsonld rename to component/models/ld/context/embed/third_party/w3.org/odrl.jsonld diff --git a/pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/did_docres_v1.jsonld b/component/models/ld/context/embed/third_party/w3c-ccg.github.io/did_docres_v1.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/did_docres_v1.jsonld rename to component/models/ld/context/embed/third_party/w3c-ccg.github.io/did_docres_v1.jsonld diff --git a/pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/did_v0.11.jsonld b/component/models/ld/context/embed/third_party/w3c-ccg.github.io/did_v0.11.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/did_v0.11.jsonld rename to component/models/ld/context/embed/third_party/w3c-ccg.github.io/did_v0.11.jsonld diff --git a/pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/did_v1.jsonld b/component/models/ld/context/embed/third_party/w3c-ccg.github.io/did_v1.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/did_v1.jsonld rename to component/models/ld/context/embed/third_party/w3c-ccg.github.io/did_v1.jsonld diff --git a/pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/ldp-bbs2020_v1.jsonld b/component/models/ld/context/embed/third_party/w3c-ccg.github.io/ldp-bbs2020_v1.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/ldp-bbs2020_v1.jsonld rename to component/models/ld/context/embed/third_party/w3c-ccg.github.io/ldp-bbs2020_v1.jsonld diff --git a/pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/lds-jws2020_v1.jsonld b/component/models/ld/context/embed/third_party/w3c-ccg.github.io/lds-jws2020_v1.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/lds-jws2020_v1.jsonld rename to component/models/ld/context/embed/third_party/w3c-ccg.github.io/lds-jws2020_v1.jsonld diff --git a/pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/revocationList2020.jsonld b/component/models/ld/context/embed/third_party/w3c-ccg.github.io/revocationList2020.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/revocationList2020.jsonld rename to component/models/ld/context/embed/third_party/w3c-ccg.github.io/revocationList2020.jsonld diff --git a/pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/revocationList2021.jsonld b/component/models/ld/context/embed/third_party/w3c-ccg.github.io/revocationList2021.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/revocationList2021.jsonld rename to component/models/ld/context/embed/third_party/w3c-ccg.github.io/revocationList2021.jsonld diff --git a/pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/security_v1.jsonld b/component/models/ld/context/embed/third_party/w3c-ccg.github.io/security_v1.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/security_v1.jsonld rename to component/models/ld/context/embed/third_party/w3c-ccg.github.io/security_v1.jsonld diff --git a/pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/security_v2.jsonld b/component/models/ld/context/embed/third_party/w3c-ccg.github.io/security_v2.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/security_v2.jsonld rename to component/models/ld/context/embed/third_party/w3c-ccg.github.io/security_v2.jsonld diff --git a/pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/wallet-v1.jsonld b/component/models/ld/context/embed/third_party/w3c-ccg.github.io/wallet-v1.jsonld similarity index 100% rename from pkg/doc/ldcontext/embed/third_party/w3c-ccg.github.io/wallet-v1.jsonld rename to component/models/ld/context/embed/third_party/w3c-ccg.github.io/wallet-v1.jsonld diff --git a/pkg/doc/ldcontext/remote/remote_provider.go b/component/models/ld/context/remote/remote_provider.go similarity index 93% rename from pkg/doc/ldcontext/remote/remote_provider.go rename to component/models/ld/context/remote/remote_provider.go index 9e0c2a24a..e52113371 100644 --- a/pkg/doc/ldcontext/remote/remote_provider.go +++ b/component/models/ld/context/remote/remote_provider.go @@ -13,8 +13,8 @@ import ( "net/http" "time" - "github.com/hyperledger/aries-framework-go/pkg/common/log" - "github.com/hyperledger/aries-framework-go/pkg/doc/ldcontext" + "github.com/hyperledger/aries-framework-go/component/log" + ldcontext "github.com/hyperledger/aries-framework-go/component/models/ld/context" ) const defaultTimeout = time.Minute diff --git a/pkg/doc/ldcontext/remote/remote_provider_test.go b/component/models/ld/context/remote/remote_provider_test.go similarity index 90% rename from pkg/doc/ldcontext/remote/remote_provider_test.go rename to component/models/ld/context/remote/remote_provider_test.go index 709766fad..c19de0a2f 100644 --- a/pkg/doc/ldcontext/remote/remote_provider_test.go +++ b/component/models/ld/context/remote/remote_provider_test.go @@ -16,14 +16,14 @@ import ( "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/doc/ldcontext/remote" - "github.com/hyperledger/aries-framework-go/pkg/internal/ldtestutil" + "github.com/hyperledger/aries-framework-go/component/models/ld/context/remote" + "github.com/hyperledger/aries-framework-go/component/models/ld/testutil" ) func TestProvider_Contexts(t *testing.T) { t.Run("Success", func(t *testing.T) { resp := remote.Response{ - Documents: ldtestutil.Contexts(), + Documents: testutil.Contexts(), } respBytes, err := json.Marshal(resp) @@ -41,7 +41,7 @@ func TestProvider_Contexts(t *testing.T) { contexts, err := p.Contexts() require.NoError(t, err) require.NotNil(t, contexts) - require.Equal(t, len(ldtestutil.Contexts()), len(contexts)) + require.Equal(t, len(testutil.Contexts()), len(contexts)) }) t.Run("Response error during HTTP do", func(t *testing.T) { diff --git a/pkg/doc/ld/document_loader.go b/component/models/ld/documentloader/document_loader.go similarity index 82% rename from pkg/doc/ld/document_loader.go rename to component/models/ld/documentloader/document_loader.go index 2e99cf911..7a51e8a93 100644 --- a/pkg/doc/ld/document_loader.go +++ b/component/models/ld/documentloader/document_loader.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package ld +package documentloader import ( "errors" @@ -12,9 +12,9 @@ import ( jsonld "github.com/piprate/json-gold/ld" - "github.com/hyperledger/aries-framework-go/pkg/doc/ldcontext" - "github.com/hyperledger/aries-framework-go/pkg/doc/ldcontext/embed" - "github.com/hyperledger/aries-framework-go/pkg/store/ld" + ldcontext "github.com/hyperledger/aries-framework-go/component/models/ld/context" + "github.com/hyperledger/aries-framework-go/component/models/ld/context/embed" + ldstore "github.com/hyperledger/aries-framework-go/component/models/ld/store" "github.com/hyperledger/aries-framework-go/spi/storage" ) @@ -23,13 +23,13 @@ var ErrContextNotFound = errors.New("context not found") // provider contains dependencies for the JSON-LD document loader. type provider interface { - JSONLDContextStore() ld.ContextStore - JSONLDRemoteProviderStore() ld.RemoteProviderStore + JSONLDContextStore() ldstore.ContextStore + JSONLDRemoteProviderStore() ldstore.RemoteProviderStore } // DocumentLoader is an implementation of ld.DocumentLoader backed by storage. type DocumentLoader struct { - store ld.ContextStore + store ldstore.ContextStore remoteDocumentLoader jsonld.DocumentLoader } @@ -41,7 +41,7 @@ type DocumentLoader struct { // // By default, missing contexts are not fetched from the remote URL. Use WithRemoteDocumentLoader() option // to specify a custom loader that can resolve context documents from the network. -func NewDocumentLoader(ctx provider, opts ...DocumentLoaderOpts) (*DocumentLoader, error) { +func NewDocumentLoader(ctx provider, opts ...Opts) (*DocumentLoader, error) { loaderOpts := &documentLoaderOpts{} for i := range opts { @@ -65,7 +65,10 @@ func NewDocumentLoader(ctx provider, opts ...DocumentLoaderOpts) (*DocumentLoade }, nil } -func prepareContexts(providerStore ld.RemoteProviderStore, opts *documentLoaderOpts) ([]ldcontext.Document, error) { +func prepareContexts( + providerStore ldstore.RemoteProviderStore, + opts *documentLoaderOpts, +) ([]ldcontext.Document, error) { m := make(map[string]ldcontext.Document) for _, c := range append(embed.Contexts, opts.extraContexts...) { @@ -134,19 +137,19 @@ type documentLoaderOpts struct { remoteProviders []RemoteProvider } -// DocumentLoaderOpts configures DocumentLoader during creation. -type DocumentLoaderOpts func(opts *documentLoaderOpts) +// Opts configures DocumentLoader during creation. +type Opts func(opts *documentLoaderOpts) // WithRemoteDocumentLoader specifies loader for fetching JSON-LD context documents from remote URLs. // Documents are fetched with this loader only if they are not found in the underlying storage. -func WithRemoteDocumentLoader(loader jsonld.DocumentLoader) DocumentLoaderOpts { +func WithRemoteDocumentLoader(loader jsonld.DocumentLoader) Opts { return func(opts *documentLoaderOpts) { opts.remoteDocumentLoader = loader } } // WithExtraContexts sets the extra contexts (in addition to embedded) for preloading into the underlying storage. -func WithExtraContexts(contexts ...ldcontext.Document) DocumentLoaderOpts { +func WithExtraContexts(contexts ...ldcontext.Document) Opts { return func(opts *documentLoaderOpts) { opts.extraContexts = contexts } @@ -159,7 +162,7 @@ type RemoteProvider interface { } // WithRemoteProvider adds a remote JSON-LD context provider to the list of providers. -func WithRemoteProvider(provider RemoteProvider) DocumentLoaderOpts { +func WithRemoteProvider(provider RemoteProvider) Opts { return func(opts *documentLoaderOpts) { opts.remoteProviders = append(opts.remoteProviders, provider) } diff --git a/pkg/doc/ld/document_loader_test.go b/component/models/ld/documentloader/document_loader_test.go similarity index 69% rename from pkg/doc/ld/document_loader_test.go rename to component/models/ld/documentloader/document_loader_test.go index 86ce78b30..e23247ce5 100644 --- a/pkg/doc/ld/document_loader_test.go +++ b/component/models/ld/documentloader/document_loader_test.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package ld_test +package documentloader_test import ( "encoding/json" @@ -15,13 +15,12 @@ import ( jsonld "github.com/piprate/json-gold/ld" "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/doc/ld" - "github.com/hyperledger/aries-framework-go/pkg/doc/ldcontext" - "github.com/hyperledger/aries-framework-go/pkg/doc/ldcontext/embed" - mockldstore "github.com/hyperledger/aries-framework-go/pkg/mock/ld" - mockprovider "github.com/hyperledger/aries-framework-go/pkg/mock/provider" - mockstorage "github.com/hyperledger/aries-framework-go/pkg/mock/storage" - ldstore "github.com/hyperledger/aries-framework-go/pkg/store/ld" + ldcontext "github.com/hyperledger/aries-framework-go/component/models/ld/context" + "github.com/hyperledger/aries-framework-go/component/models/ld/context/embed" + "github.com/hyperledger/aries-framework-go/component/models/ld/documentloader" + mockldstore "github.com/hyperledger/aries-framework-go/component/models/ld/mock" + "github.com/hyperledger/aries-framework-go/component/models/ld/store" + mockstorage "github.com/hyperledger/aries-framework-go/component/storageutil/mock/storage" "github.com/hyperledger/aries-framework-go/spi/storage" ) @@ -40,7 +39,7 @@ func TestNewDocumentLoader(t *testing.T) { t.Run("Load embedded contexts by default", func(t *testing.T) { store := mockldstore.NewMockContextStore() - loader, err := ld.NewDocumentLoader(createMockProvider(withContextStore(store))) + loader, err := documentloader.NewDocumentLoader(createMockProvider(withContextStore(store))) require.NoError(t, err) require.NotNil(t, loader) @@ -57,8 +56,8 @@ func TestNewDocumentLoader(t *testing.T) { store := mockldstore.NewMockContextStore() - loader, err := ld.NewDocumentLoader(createMockProvider(withContextStore(store)), - ld.WithExtraContexts(extraContext)) + loader, err := documentloader.NewDocumentLoader(createMockProvider(withContextStore(store)), + documentloader.WithExtraContexts(extraContext)) require.NoError(t, err) require.NotNil(t, loader) @@ -82,10 +81,10 @@ func TestNewDocumentLoader(t *testing.T) { contextStore := mockldstore.NewMockContextStore() remoteProviderStore := mockldstore.NewMockRemoteProviderStore() - loader, err := ld.NewDocumentLoader(createMockProvider( + loader, err := documentloader.NewDocumentLoader(createMockProvider( withContextStore(contextStore), withRemoteProviderStore(remoteProviderStore), - ), ld.WithRemoteProvider(p)) + ), documentloader.WithRemoteProvider(p)) require.NoError(t, err) require.NotNil(t, loader) @@ -94,8 +93,8 @@ func TestNewDocumentLoader(t *testing.T) { }) t.Run("Fail to get contexts from the remote provider", func(t *testing.T) { - loader, err := ld.NewDocumentLoader(createMockProvider(), - ld.WithRemoteProvider(&mockRemoteProvider{ErrContexts: errors.New("contexts error")})) + loader, err := documentloader.NewDocumentLoader(createMockProvider(), + documentloader.WithRemoteProvider(&mockRemoteProvider{ErrContexts: errors.New("contexts error")})) require.Nil(t, loader) require.Error(t, err) @@ -115,8 +114,8 @@ func TestNewDocumentLoader(t *testing.T) { store := mockldstore.NewMockRemoteProviderStore() store.ErrSave = errors.New("save error") - loader, err := ld.NewDocumentLoader(createMockProvider(withRemoteProviderStore(store)), - ld.WithRemoteProvider(p)) + loader, err := documentloader.NewDocumentLoader(createMockProvider(withRemoteProviderStore(store)), + documentloader.WithRemoteProvider(p)) require.Nil(t, loader) require.Error(t, err) @@ -127,7 +126,7 @@ func TestNewDocumentLoader(t *testing.T) { store := mockldstore.NewMockContextStore() store.ErrImport = errors.New("import error") - loader, err := ld.NewDocumentLoader(createMockProvider(withContextStore(store))) + loader, err := documentloader.NewDocumentLoader(createMockProvider(withContextStore(store))) require.Nil(t, loader) require.Error(t, err) @@ -154,7 +153,7 @@ func TestLoadDocument(t *testing.T) { }, } - loader, err := ld.NewDocumentLoader(createMockProvider(withContextStore(store))) + loader, err := documentloader.NewDocumentLoader(createMockProvider(withContextStore(store))) require.NotNil(t, loader) require.NoError(t, err) @@ -168,8 +167,8 @@ func TestLoadDocument(t *testing.T) { store := mockldstore.NewMockContextStore() store.Store.ErrGet = storage.ErrDataNotFound - loader, err := ld.NewDocumentLoader(createMockProvider(withContextStore(store)), - ld.WithRemoteDocumentLoader(&mockRemoteDocumentLoader{})) + loader, err := documentloader.NewDocumentLoader(createMockProvider(withContextStore(store)), + documentloader.WithRemoteDocumentLoader(&mockRemoteDocumentLoader{})) require.NotNil(t, loader) require.NoError(t, err) @@ -186,21 +185,21 @@ func TestLoadDocument(t *testing.T) { store := mockldstore.NewMockContextStore() store.Store.ErrGet = storage.ErrDataNotFound - loader, err := ld.NewDocumentLoader(createMockProvider(withContextStore(store))) + loader, err := documentloader.NewDocumentLoader(createMockProvider(withContextStore(store))) require.NotNil(t, loader) require.NoError(t, err) rd, err := loader.LoadDocument("https://example.com/context.jsonld") require.Nil(t, rd) - require.EqualError(t, err, ld.ErrContextNotFound.Error()) + require.EqualError(t, err, documentloader.ErrContextNotFound.Error()) }) t.Run("Fail to get context from store", func(t *testing.T) { store := mockldstore.NewMockContextStore() store.Store.ErrGet = errors.New("get error") - loader, err := ld.NewDocumentLoader(createMockProvider(withContextStore(store))) + loader, err := documentloader.NewDocumentLoader(createMockProvider(withContextStore(store))) require.NotNil(t, loader) require.NoError(t, err) @@ -215,8 +214,9 @@ func TestLoadDocument(t *testing.T) { store := mockldstore.NewMockContextStore() store.Store.ErrGet = storage.ErrDataNotFound - loader, err := ld.NewDocumentLoader(createMockProvider(withContextStore(store)), - ld.WithRemoteDocumentLoader(&mockRemoteDocumentLoader{ErrLoadDocument: errors.New("load document error")})) + loader, err := documentloader.NewDocumentLoader(createMockProvider(withContextStore(store)), + documentloader.WithRemoteDocumentLoader(&mockRemoteDocumentLoader{ + ErrLoadDocument: errors.New("load document error")})) require.NotNil(t, loader) require.NoError(t, err) @@ -230,8 +230,8 @@ func TestLoadDocument(t *testing.T) { t.Run("Fail to save fetched remote document", func(t *testing.T) { store := mockldstore.NewMockContextStore() - loader, err := ld.NewDocumentLoader(createMockProvider(withContextStore(store)), - ld.WithRemoteDocumentLoader(&mockRemoteDocumentLoader{})) + loader, err := documentloader.NewDocumentLoader(createMockProvider(withContextStore(store)), + documentloader.WithRemoteDocumentLoader(&mockRemoteDocumentLoader{})) require.NotNil(t, loader) require.NoError(t, err) @@ -260,10 +260,23 @@ func assertContextInStore(t *testing.T, store storage.Store, url, value string) require.Equal(t, value, rd.Document.(map[string]interface{})["@context"]) } -func createMockProvider(opts ...providerOptionFn) *mockprovider.Provider { - p := &mockprovider.Provider{ - ContextStoreValue: mockldstore.NewMockContextStore(), - RemoteProviderStoreValue: mockldstore.NewMockRemoteProviderStore(), +type provider struct { + ContextStore store.ContextStore + RemoteProviderStore store.RemoteProviderStore +} + +func (p *provider) JSONLDContextStore() store.ContextStore { + return p.ContextStore +} + +func (p *provider) JSONLDRemoteProviderStore() store.RemoteProviderStore { + return p.RemoteProviderStore +} + +func createMockProvider(opts ...providerOptionFn) *provider { + p := &provider{ + ContextStore: mockldstore.NewMockContextStore(), + RemoteProviderStore: mockldstore.NewMockRemoteProviderStore(), } for i := range opts { @@ -273,17 +286,17 @@ func createMockProvider(opts ...providerOptionFn) *mockprovider.Provider { return p } -type providerOptionFn func(opts *mockprovider.Provider) +type providerOptionFn func(opts *provider) -func withContextStore(store ldstore.ContextStore) providerOptionFn { - return func(p *mockprovider.Provider) { - p.ContextStoreValue = store +func withContextStore(contextStore store.ContextStore) providerOptionFn { + return func(p *provider) { + p.ContextStore = contextStore } } -func withRemoteProviderStore(store ldstore.RemoteProviderStore) providerOptionFn { - return func(p *mockprovider.Provider) { - p.RemoteProviderStoreValue = store +func withRemoteProviderStore(providerStore store.RemoteProviderStore) providerOptionFn { + return func(p *provider) { + p.RemoteProviderStore = providerStore } } diff --git a/pkg/mock/ld/mock_context_store.go b/component/models/ld/mock/mock_context_store.go similarity index 61% rename from pkg/mock/ld/mock_context_store.go rename to component/models/ld/mock/mock_context_store.go index da8b31732..eb3c2839a 100644 --- a/pkg/mock/ld/mock_context_store.go +++ b/component/models/ld/mock/mock_context_store.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package ld +package mock import ( "bytes" @@ -13,14 +13,14 @@ import ( jsonld "github.com/piprate/json-gold/ld" - "github.com/hyperledger/aries-framework-go/pkg/doc/ldcontext" - mockstorage "github.com/hyperledger/aries-framework-go/pkg/mock/storage" - "github.com/hyperledger/aries-framework-go/pkg/store/ld" + "github.com/hyperledger/aries-framework-go/component/models/ld/context" + "github.com/hyperledger/aries-framework-go/component/models/ld/store" + mockstorage "github.com/hyperledger/aries-framework-go/component/storageutil/mock/storage" "github.com/hyperledger/aries-framework-go/spi/storage" ) -// MockContextStore is a mock JSON-LD context store. -type MockContextStore struct { +// ContextStore is a mock JSON-LD context store. +type ContextStore struct { Store *mockstorage.MockStore ErrGet error ErrPut error @@ -28,9 +28,9 @@ type MockContextStore struct { ErrDelete error } -// NewMockContextStore returns a new instance of MockContextStore. -func NewMockContextStore() *MockContextStore { - return &MockContextStore{ +// NewMockContextStore returns a new instance of ContextStore. +func NewMockContextStore() *ContextStore { + return &ContextStore{ Store: &mockstorage.MockStore{ Store: make(map[string]mockstorage.DBEntry), }, @@ -38,12 +38,12 @@ func NewMockContextStore() *MockContextStore { } // Get returns JSON-LD remote document from the underlying storage by context url. -func (m *MockContextStore) Get(u string) (*jsonld.RemoteDocument, error) { - if m.ErrGet != nil { - return nil, m.ErrGet +func (s *ContextStore) Get(u string) (*jsonld.RemoteDocument, error) { + if s.ErrGet != nil { + return nil, s.ErrGet } - b, err := m.Store.Get(u) + b, err := s.Store.Get(u) if err != nil { return nil, fmt.Errorf("get context from store: %w", err) } @@ -58,9 +58,9 @@ func (m *MockContextStore) Get(u string) (*jsonld.RemoteDocument, error) { } // Put saves JSON-LD remote document into the underlying storage under key u (context url). -func (m *MockContextStore) Put(u string, rd *jsonld.RemoteDocument) error { - if m.ErrPut != nil { - return m.ErrPut +func (s *ContextStore) Put(u string, rd *jsonld.RemoteDocument) error { + if s.ErrPut != nil { + return s.ErrPut } b, err := json.Marshal(rd) @@ -68,7 +68,7 @@ func (m *MockContextStore) Put(u string, rd *jsonld.RemoteDocument) error { return fmt.Errorf("marshal remote document: %w", err) } - if err := m.Store.Put(u, b); err != nil { + if err := s.Store.Put(u, b); err != nil { return fmt.Errorf("put remote document: %w", err) } @@ -76,9 +76,9 @@ func (m *MockContextStore) Put(u string, rd *jsonld.RemoteDocument) error { } // Import imports contexts into the underlying storage. -func (m *MockContextStore) Import(documents []ldcontext.Document) error { - if m.ErrImport != nil { - return m.ErrImport +func (s *ContextStore) Import(documents []context.Document) error { + if s.ErrImport != nil { + return s.ErrImport } for _, d := range documents { @@ -97,7 +97,7 @@ func (m *MockContextStore) Import(documents []ldcontext.Document) error { return fmt.Errorf("marshal remote document: %w", err) } - if err = m.Store.Put(d.URL, b, storage.Tag{Name: ld.ContextRecordTag}); err != nil { + if err = s.Store.Put(d.URL, b, storage.Tag{Name: store.ContextRecordTag}); err != nil { return fmt.Errorf("put context document: %w", err) } } @@ -106,13 +106,13 @@ func (m *MockContextStore) Import(documents []ldcontext.Document) error { } // Delete deletes context documents in the underlying storage. -func (m *MockContextStore) Delete(documents []ldcontext.Document) error { - if m.ErrDelete != nil { - return m.ErrDelete +func (s *ContextStore) Delete(documents []context.Document) error { + if s.ErrDelete != nil { + return s.ErrDelete } for _, d := range documents { - if err := m.Store.Delete(d.URL); err != nil { + if err := s.Store.Delete(d.URL); err != nil { return fmt.Errorf("delete context document: %w", err) } } diff --git a/component/models/ld/mock/mock_remote_provider_store.go b/component/models/ld/mock/mock_remote_provider_store.go new file mode 100644 index 000000000..ad0111e9d --- /dev/null +++ b/component/models/ld/mock/mock_remote_provider_store.go @@ -0,0 +1,105 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package mock + +import ( + "github.com/google/uuid" + + "github.com/hyperledger/aries-framework-go/component/models/ld/store" + mockstorage "github.com/hyperledger/aries-framework-go/component/storageutil/mock/storage" + "github.com/hyperledger/aries-framework-go/spi/storage" +) + +// RemoteProviderStore is a mock remote JSON-LD context provider store. +type RemoteProviderStore struct { + Store *mockstorage.MockStore + ErrGet error + ErrGetAll error + ErrSave error + ErrDelete error +} + +// NewMockRemoteProviderStore returns a new instance of RemoteProviderStore. +func NewMockRemoteProviderStore() *RemoteProviderStore { + return &RemoteProviderStore{ + Store: &mockstorage.MockStore{ + Store: make(map[string]mockstorage.DBEntry), + }, + } +} + +// Get returns a remote provider record from the underlying storage. +func (s *RemoteProviderStore) Get(id string) (*store.RemoteProviderRecord, error) { + if s.ErrGet != nil { + return nil, s.ErrGet + } + + b, err := s.Store.Get(id) + if err != nil { + return nil, err + } + + return &store.RemoteProviderRecord{ + ID: id, + Endpoint: string(b), + }, nil +} + +// GetAll returns all remote provider records from the underlying storage. +func (s *RemoteProviderStore) GetAll() ([]store.RemoteProviderRecord, error) { + if s.ErrGetAll != nil { + return nil, s.ErrGetAll + } + + var records []store.RemoteProviderRecord + + for k, v := range s.Store.Store { + records = append(records, store.RemoteProviderRecord{ + ID: k, + Endpoint: string(v.Value), + }) + } + + return records, nil +} + +// Save creates a new remote provider record and saves it to the underlying storage. +// If the record with specified endpoint already exists it is returned to the caller. +func (s *RemoteProviderStore) Save(endpoint string) (*store.RemoteProviderRecord, error) { + if s.ErrSave != nil { + return nil, s.ErrSave + } + + for k, v := range s.Store.Store { + if string(v.Value) == endpoint { + return &store.RemoteProviderRecord{ + ID: k, + Endpoint: string(v.Value), + }, nil + } + } + + id := uuid.New().String() + + if err := s.Store.Put(id, []byte(endpoint), storage.Tag{Name: store.RemoteProviderRecordTag}); err != nil { + return nil, err + } + + return &store.RemoteProviderRecord{ + ID: id, + Endpoint: endpoint, + }, nil +} + +// Delete deletes a remote provider record in the underlying storage. +func (s *RemoteProviderStore) Delete(id string) error { + if s.ErrDelete != nil { + return s.ErrDelete + } + + return s.Store.Delete(id) +} diff --git a/component/models/ld/mock/mock_service.go b/component/models/ld/mock/mock_service.go new file mode 100644 index 000000000..6f798d91a --- /dev/null +++ b/component/models/ld/mock/mock_service.go @@ -0,0 +1,79 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package mock + +import ( + "github.com/hyperledger/aries-framework-go/component/models/ld/context" + "github.com/hyperledger/aries-framework-go/component/models/ld/context/remote" + "github.com/hyperledger/aries-framework-go/component/models/ld/store" +) + +// Service is a mock JSON-LD service. +type Service struct { + ProviderID string + RemoteProviderRecords []store.RemoteProviderRecord + ErrAddContexts error + ErrAddRemoteProvider error + ErrRefreshRemoteProvider error + ErrDeleteRemoteProvider error + ErrGetAllRemoteProviders error + ErrRefreshAllRemoteProviders error +} + +// AddContexts adds JSON-LD contexts to the underlying storage. +func (s *Service) AddContexts(documents []context.Document) error { + if s.ErrAddContexts != nil { + return s.ErrAddContexts + } + + return nil +} + +// AddRemoteProvider adds remote provider and JSON-LD contexts from that provider. +func (s *Service) AddRemoteProvider(providerEndpoint string, opts ...remote.ProviderOpt) (string, error) { + if s.ErrAddRemoteProvider != nil { + return "", s.ErrAddRemoteProvider + } + + return s.ProviderID, nil +} + +// RefreshRemoteProvider updates contexts from the remote provider. +func (s *Service) RefreshRemoteProvider(providerID string, opts ...remote.ProviderOpt) error { + if s.ErrRefreshRemoteProvider != nil { + return s.ErrRefreshRemoteProvider + } + + return nil +} + +// DeleteRemoteProvider deletes remote provider and contexts from that provider. +func (s *Service) DeleteRemoteProvider(providerID string, opts ...remote.ProviderOpt) error { + if s.ErrDeleteRemoteProvider != nil { + return s.ErrDeleteRemoteProvider + } + + return nil +} + +// GetAllRemoteProviders gets all remote providers. +func (s *Service) GetAllRemoteProviders() ([]store.RemoteProviderRecord, error) { + if s.ErrGetAllRemoteProviders != nil { + return nil, s.ErrGetAllRemoteProviders + } + + return s.RemoteProviderRecords, nil +} + +// RefreshAllRemoteProviders updates contexts from all remote providers. +func (s *Service) RefreshAllRemoteProviders(opts ...remote.ProviderOpt) error { + if s.ErrRefreshAllRemoteProviders != nil { + return s.ErrRefreshAllRemoteProviders + } + + return s.ErrRefreshAllRemoteProviders +} diff --git a/pkg/doc/signature/jsonld/processor.go b/component/models/ld/processor/processor.go similarity index 92% rename from pkg/doc/signature/jsonld/processor.go rename to component/models/ld/processor/processor.go index 1a38b2a79..7a2d92614 100644 --- a/pkg/doc/signature/jsonld/processor.go +++ b/component/models/ld/processor/processor.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package jsonld +package processor import ( "errors" @@ -14,8 +14,8 @@ import ( "github.com/google/uuid" "github.com/piprate/json-gold/ld" - "github.com/hyperledger/aries-framework-go/pkg/common/log" - "github.com/hyperledger/aries-framework-go/pkg/common/utils" + "github.com/hyperledger/aries-framework-go/component/log" + "github.com/hyperledger/aries-framework-go/component/models/util/maphelpers" ) const ( @@ -38,11 +38,11 @@ type processorOpts struct { externalContexts []string } -// ProcessorOpts are the options for JSON LD operations on docs (like canonicalization or compacting). -type ProcessorOpts func(opts *processorOpts) +// Opts are the options for JSON LD operations on docs (like canonicalization or compacting). +type Opts func(opts *processorOpts) // WithRemoveAllInvalidRDF option for removing all invalid RDF dataset from normalize document. -func WithRemoveAllInvalidRDF() ProcessorOpts { +func WithRemoveAllInvalidRDF() Opts { return func(opts *processorOpts) { opts.removeInvalidRDF = true } @@ -50,21 +50,21 @@ func WithRemoveAllInvalidRDF() ProcessorOpts { // WithFrameBlankNodes option for transforming blank node identifiers into nodes. // For example, _:c14n0 is transformed into . -func WithFrameBlankNodes() ProcessorOpts { +func WithFrameBlankNodes() Opts { return func(opts *processorOpts) { opts.frameBlankNodes = true } } // WithDocumentLoader option is for passing custom JSON-LD document loader. -func WithDocumentLoader(loader ld.DocumentLoader) ProcessorOpts { +func WithDocumentLoader(loader ld.DocumentLoader) Opts { return func(opts *processorOpts) { opts.documentLoader = loader } } // WithExternalContext option is for definition of external context when doing JSON-LD operations. -func WithExternalContext(context ...string) ProcessorOpts { +func WithExternalContext(context ...string) Opts { return func(opts *processorOpts) { opts.externalContexts = context } @@ -72,7 +72,7 @@ func WithExternalContext(context ...string) ProcessorOpts { // WithValidateRDF option validates result view and fails if any invalid RDF dataset found. // This option will take precedence when used in conjunction with 'WithRemoveAllInvalidRDF' option. -func WithValidateRDF() ProcessorOpts { +func WithValidateRDF() Opts { return func(opts *processorOpts) { opts.validateRDF = true } @@ -99,7 +99,7 @@ func Default() *Processor { } // GetCanonicalDocument returns canonized document of given json ld. -func (p *Processor) GetCanonicalDocument(doc map[string]interface{}, opts ...ProcessorOpts) ([]byte, error) { +func (p *Processor) GetCanonicalDocument(doc map[string]interface{}, opts ...Opts) ([]byte, error) { procOptions := prepareOpts(opts) ldOptions := ld.NewJsonLdOptions("") @@ -154,7 +154,7 @@ func AppendExternalContexts(context interface{}, extraContexts ...string) []inte // Compact compacts given json ld object. func (p *Processor) Compact(input, context map[string]interface{}, - opts ...ProcessorOpts) (map[string]interface{}, error) { + opts ...Opts) (map[string]interface{}, error) { procOptions := prepareOpts(opts) ldOptions := ld.NewJsonLdOptions("") @@ -179,7 +179,7 @@ func (p *Processor) Compact(input, context map[string]interface{}, // Frame makes a frame from the inputDoc using frameDoc. func (p *Processor) Frame(inputDoc map[string]interface{}, frameDoc map[string]interface{}, - opts ...ProcessorOpts) (map[string]interface{}, error) { + opts ...Opts) (map[string]interface{}, error) { procOptions := prepareOpts(opts) ldOptions := ld.NewJsonLdOptions("") @@ -247,7 +247,7 @@ func removeDuplicateIDs(inputDoc map[string]interface{}, proc *ld.JsonLdProcesso var randomIds map[string]string if len(duplicatedIDs) > 0 { - inputDocCopy = utils.CopyMap(inputDoc) + inputDocCopy = maphelpers.CopyMap(inputDoc) randomIds = make(map[string]string) @@ -400,7 +400,7 @@ func (p *Processor) normalizeFilteredDataset(view string) (string, error) { } func fromRDF(docStatements []string, context interface{}, - opts ...ProcessorOpts) (map[string]interface{}, error) { + opts ...Opts) (map[string]interface{}, error) { procOptions := prepareOpts(opts) ldOptions := ld.NewJsonLdOptions("") @@ -426,7 +426,7 @@ func fromRDF(docStatements []string, context interface{}, } // prepareOpts prepare processorOpts from given CanonicalizationOpts arguments. -func prepareOpts(opts []ProcessorOpts) *processorOpts { +func prepareOpts(opts []Opts) *processorOpts { procOpts := &processorOpts{} for _, opt := range opts { @@ -437,7 +437,7 @@ func prepareOpts(opts []ProcessorOpts) *processorOpts { } func (p *Processor) transformBlankNodes(docMap map[string]interface{}, - opts ...ProcessorOpts) (map[string]interface{}, error) { + opts ...Opts) (map[string]interface{}, error) { procOptions := prepareOpts(opts) if !procOptions.frameBlankNodes { diff --git a/pkg/doc/signature/jsonld/processor_test.go b/component/models/ld/processor/processor_test.go similarity index 78% rename from pkg/doc/signature/jsonld/processor_test.go rename to component/models/ld/processor/processor_test.go index 2c47c0683..e5545d87e 100644 --- a/pkg/doc/signature/jsonld/processor_test.go +++ b/component/models/ld/processor/processor_test.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package jsonld_test +package processor_test import ( _ "embed" @@ -14,15 +14,15 @@ import ( "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/doc/ldcontext" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" - "github.com/hyperledger/aries-framework-go/pkg/internal/ldtestutil" + ldcontext "github.com/hyperledger/aries-framework-go/component/models/ld/context" + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" + "github.com/hyperledger/aries-framework-go/component/models/ld/testutil" ) const defaultAlgorithm = "URDNA2015" func TestGetCanonicalDocument(t *testing.T) { - loader, err := ldtestutil.DocumentLoader(ldcontext.Document{ + loader, err := testutil.DocumentLoader(ldcontext.Document{ URL: "http://localhost:8652/dummy.jsonld", Content: extraJSONLDContext, }) @@ -34,31 +34,31 @@ func TestGetCanonicalDocument(t *testing.T) { doc string result string err string - opts []jsonld.ProcessorOpts + opts []processor.Opts }{ { name: "canonizing document with 1 incorrect RDF", doc: jsonLDWithIncorrectRDF, result: canonizedIncorrectRDFFiltered, - opts: []jsonld.ProcessorOpts{jsonld.WithRemoveAllInvalidRDF()}, + opts: []processor.Opts{processor.WithRemoveAllInvalidRDF()}, }, { name: "canonizing document with 1 incorrect RDF", doc: jsonLDWithIncorrectRDF, result: canonizedIncorrectRDF, - opts: []jsonld.ProcessorOpts{}, + opts: []processor.Opts{}, }, { name: "canonizing valid document 1", doc: jsonLDSample1, result: canonizedIncorrectRDFFiltered, - opts: []jsonld.ProcessorOpts{jsonld.WithRemoveAllInvalidRDF()}, + opts: []processor.Opts{processor.WithRemoveAllInvalidRDF()}, }, { name: "canonizing valid document 1", doc: jsonLDSample1, result: canonizedIncorrectRDFFiltered, - opts: []jsonld.ProcessorOpts{}, + opts: []processor.Opts{}, }, { name: "canonizing sample proof document", @@ -69,24 +69,24 @@ func TestGetCanonicalDocument(t *testing.T) { name: "canonizing sample document with multiple incorrect RDFs 1", doc: jsonLDMultipleInvalidRDFs, result: canonizedSampleVPFiltered, - opts: []jsonld.ProcessorOpts{jsonld.WithRemoveAllInvalidRDF()}, + opts: []processor.Opts{processor.WithRemoveAllInvalidRDF()}, }, { name: "canonizing sample document with extra context", doc: jsonLDMultipleInvalidRDFs, result: canonizedSampleVPExtraContext, - opts: []jsonld.ProcessorOpts{ - jsonld.WithRemoveAllInvalidRDF(), - jsonld.WithExternalContext("https://trustbloc.github.io/context/vc/examples-v1.jsonld"), + opts: []processor.Opts{ + processor.WithRemoveAllInvalidRDF(), + processor.WithExternalContext("https://trustbloc.github.io/context/vc/examples-v1.jsonld"), }, }, { name: "canonizing sample document with extra dummy context and in-memory document loader", doc: jsonLDMultipleInvalidRDFs, result: canonizedSampleVPExtraContext, - opts: []jsonld.ProcessorOpts{ - jsonld.WithRemoveAllInvalidRDF(), - jsonld.WithExternalContext("http://localhost:8652/dummy.jsonld"), + opts: []processor.Opts{ + processor.WithRemoveAllInvalidRDF(), + processor.WithExternalContext("http://localhost:8652/dummy.jsonld"), }, }, { @@ -98,19 +98,19 @@ func TestGetCanonicalDocument(t *testing.T) { name: "canonizing sample document with incorrect RDFs causing node label miss match issue (array type)", doc: invalidRDFMessingUpLabelPrefixCounter, result: canonizedSampleVP2, - opts: []jsonld.ProcessorOpts{jsonld.WithRemoveAllInvalidRDF()}, + opts: []processor.Opts{processor.WithRemoveAllInvalidRDF()}, }, { name: "canonizing sample document with incorrect RDFs causing node label miss match issue (string type)", doc: invalidRDFMessingUpLabelPrefixCounterString, result: canonizedSampleVP2, - opts: []jsonld.ProcessorOpts{jsonld.WithRemoveAllInvalidRDF()}, + opts: []processor.Opts{processor.WithRemoveAllInvalidRDF()}, }, { name: "canonizing document with 1 incorrect RDF11", doc: jsonLDWith2KnownInvalidRDFs, result: canonizedIncorrectRDFAllFiltered, - opts: []jsonld.ProcessorOpts{jsonld.WithRemoveAllInvalidRDF()}, + opts: []processor.Opts{processor.WithRemoveAllInvalidRDF()}, }, { name: "canonizing sample VC document with proper context", @@ -121,7 +121,7 @@ func TestGetCanonicalDocument(t *testing.T) { name: "canonizing sample VC document with proper context but remove all invalid RDF", doc: vcWithProperContexts, result: canonizedJSONCredential, - opts: []jsonld.ProcessorOpts{jsonld.WithRemoveAllInvalidRDF()}, + opts: []processor.Opts{processor.WithRemoveAllInvalidRDF()}, }, { name: "canonizing sample VC document with proper context 2", @@ -132,25 +132,25 @@ func TestGetCanonicalDocument(t *testing.T) { name: "canonizing sample VC document with proper context 2 but remove all invalid RDF", doc: vcWithProperContexts2, result: canonizedJSONCredential2, - opts: []jsonld.ProcessorOpts{jsonld.WithRemoveAllInvalidRDF()}, + opts: []processor.Opts{processor.WithRemoveAllInvalidRDF()}, }, { name: "canonizing sample VC document with proper context 2 with in-memory document loader", doc: vcWithProperContexts2, result: canonizedJSONCredential2, - opts: []jsonld.ProcessorOpts{jsonld.WithDocumentLoader(loader)}, + opts: []processor.Opts{processor.WithDocumentLoader(loader)}, }, { name: "canonizing sample VC document with improper context", doc: vcWithIncorrectContexts, result: canonizedJSONCredentialNotFiltered, - opts: []jsonld.ProcessorOpts{}, + opts: []processor.Opts{}, }, { name: "canonizing sample VC document with improper context but remove all invalid RDF", doc: vcWithIncorrectContexts, result: canonizedJSONCredentialFiltered, - opts: []jsonld.ProcessorOpts{jsonld.WithRemoveAllInvalidRDF()}, + opts: []processor.Opts{processor.WithRemoveAllInvalidRDF()}, }, { name: "canonizing empty document", @@ -161,15 +161,15 @@ func TestGetCanonicalDocument(t *testing.T) { name: "canonizing document with 1 incorrect RDF with validation option", doc: jsonLDWith2KnownInvalidRDFs, result: canonizedIncorrectRDFAllFiltered, - opts: []jsonld.ProcessorOpts{jsonld.WithValidateRDF()}, - err: jsonld.ErrInvalidRDFFound.Error(), + opts: []processor.Opts{processor.WithValidateRDF()}, + err: processor.ErrInvalidRDFFound.Error(), }, { name: "canonizing document with 1 incorrect RDF with validation & remove all invalid RDF option", doc: jsonLDWith2KnownInvalidRDFs, result: canonizedIncorrectRDFAllFiltered, - opts: []jsonld.ProcessorOpts{jsonld.WithValidateRDF(), jsonld.WithRemoveAllInvalidRDF()}, - err: jsonld.ErrInvalidRDFFound.Error(), + opts: []processor.Opts{processor.WithValidateRDF(), processor.WithRemoveAllInvalidRDF()}, + err: processor.ErrInvalidRDFFound.Error(), }, } @@ -182,8 +182,8 @@ func TestGetCanonicalDocument(t *testing.T) { err := json.Unmarshal([]byte(tc.doc), &jsonldDoc) require.NoError(t, err) - response, err := jsonld.NewProcessor(defaultAlgorithm).GetCanonicalDocument(jsonldDoc, - append([]jsonld.ProcessorOpts{jsonld.WithDocumentLoader(loader)}, tc.opts...)...) + response, err := processor.NewProcessor(defaultAlgorithm).GetCanonicalDocument(jsonldDoc, + append([]processor.Opts{processor.WithDocumentLoader(loader)}, tc.opts...)...) if tc.err != "" { require.Error(t, err) require.Contains(t, err.Error(), tc.err) @@ -217,7 +217,7 @@ func TestCompact(t *testing.T) { }, } - compactedDoc, err := jsonld.Default().Compact(doc, context) + compactedDoc, err := processor.Default().Compact(doc, context) if err != nil { log.Println("Error when compacting JSON-LD document:", err) return @@ -230,7 +230,7 @@ func TestCompact(t *testing.T) { } func TestProcessor_Frame(t *testing.T) { - processor := jsonld.Default() + processor := processor.Default() var doc map[string]interface{} @@ -255,7 +255,7 @@ func TestProcessor_Frame(t *testing.T) { err = json.Unmarshal([]byte(frameJSON), &frameDoc) require.NoError(t, err) - framedView, err := processor.Frame(doc, frameDoc, ldtestutil.WithDocumentLoader(t)) + framedView, err := processor.Frame(doc, frameDoc, testutil.WithDocumentLoader(t)) require.NoError(t, err) require.Equal(t, map[string]interface{}{ @@ -271,7 +271,7 @@ func TestProcessor_Frame(t *testing.T) { require.True(t, ok) subjectMap["id"] = issuerMap["id"] - framedView, err = processor.Frame(doc, frameDoc, ldtestutil.WithDocumentLoader(t)) + framedView, err = processor.Frame(doc, frameDoc, testutil.WithDocumentLoader(t)) require.NoError(t, err) require.Equal(t, map[string]interface{}{ @@ -292,7 +292,7 @@ func TestProcessor_Frame(t *testing.T) { // clear the ID, to test empty-ID handling doc["id"] = "" - framedView, err = processor.Frame(doc, frameDoc, ldtestutil.WithDocumentLoader(t)) + framedView, err = processor.Frame(doc, frameDoc, testutil.WithDocumentLoader(t)) require.NoError(t, err) require.Equal(t, []interface{}{ @@ -326,30 +326,30 @@ func TestTransformBlankNodes(t *testing.T) { ge = "" ) - at := jsonld.TransformBlankNode(a) + at := processor.TransformBlankNode(a) require.Equal(t, ae, at) - bt := jsonld.TransformBlankNode(b) + bt := processor.TransformBlankNode(b) require.Equal(t, be, bt) - ct := jsonld.TransformBlankNode(c) + ct := processor.TransformBlankNode(c) require.Equal(t, ce, ct) - dt := jsonld.TransformBlankNode(d) + dt := processor.TransformBlankNode(d) require.Equal(t, de, dt) - et := jsonld.TransformBlankNode(e) + et := processor.TransformBlankNode(e) require.Equal(t, ee, et) - ft := jsonld.TransformBlankNode(f) + ft := processor.TransformBlankNode(f) require.Equal(t, fe, ft) - gt := jsonld.TransformBlankNode(g) + gt := processor.TransformBlankNode(g) require.Equal(t, ge, gt) } func BenchmarkGetCanonicalDocument(b *testing.B) { - loader, err := ldtestutil.DocumentLoader(ldcontext.Document{ + loader, err := testutil.DocumentLoader(ldcontext.Document{ URL: "http://localhost:8652/dummy.jsonld", Content: extraJSONLDContext, }) @@ -360,31 +360,31 @@ func BenchmarkGetCanonicalDocument(b *testing.B) { name string doc string result string - opts []jsonld.ProcessorOpts + opts []processor.Opts }{ { name: "canonizing document with 1 incorrect RDF", doc: jsonLDWithIncorrectRDF, result: canonizedIncorrectRDFFiltered, - opts: []jsonld.ProcessorOpts{jsonld.WithRemoveAllInvalidRDF()}, + opts: []processor.Opts{processor.WithRemoveAllInvalidRDF()}, }, { name: "canonizing document with 1 incorrect RDF", doc: jsonLDWithIncorrectRDF, result: canonizedIncorrectRDF, - opts: []jsonld.ProcessorOpts{}, + opts: []processor.Opts{}, }, { name: "canonizing valid document 1", doc: jsonLDSample1, result: canonizedIncorrectRDFFiltered, - opts: []jsonld.ProcessorOpts{jsonld.WithRemoveAllInvalidRDF()}, + opts: []processor.Opts{processor.WithRemoveAllInvalidRDF()}, }, { name: "canonizing valid document 1", doc: jsonLDSample1, result: canonizedIncorrectRDFFiltered, - opts: []jsonld.ProcessorOpts{}, + opts: []processor.Opts{}, }, { name: "canonizing sample proof document", @@ -395,24 +395,24 @@ func BenchmarkGetCanonicalDocument(b *testing.B) { name: "canonizing sample document with multiple incorrect RDFs 1", doc: jsonLDMultipleInvalidRDFs, result: canonizedSampleVPFiltered, - opts: []jsonld.ProcessorOpts{jsonld.WithRemoveAllInvalidRDF()}, + opts: []processor.Opts{processor.WithRemoveAllInvalidRDF()}, }, { name: "canonizing sample document with extra context", doc: jsonLDMultipleInvalidRDFs, result: canonizedSampleVPExtraContext, - opts: []jsonld.ProcessorOpts{ - jsonld.WithRemoveAllInvalidRDF(), - jsonld.WithExternalContext("https://trustbloc.github.io/context/vc/examples-v1.jsonld"), + opts: []processor.Opts{ + processor.WithRemoveAllInvalidRDF(), + processor.WithExternalContext("https://trustbloc.github.io/context/vc/examples-v1.jsonld"), }, }, { name: "canonizing sample document with extra dummy context and in-memory document loader", doc: jsonLDMultipleInvalidRDFs, result: canonizedSampleVPExtraContext, - opts: []jsonld.ProcessorOpts{ - jsonld.WithRemoveAllInvalidRDF(), - jsonld.WithExternalContext("http://localhost:8652/dummy.jsonld"), + opts: []processor.Opts{ + processor.WithRemoveAllInvalidRDF(), + processor.WithExternalContext("http://localhost:8652/dummy.jsonld"), }, }, { @@ -424,19 +424,19 @@ func BenchmarkGetCanonicalDocument(b *testing.B) { name: "canonizing sample document with incorrect RDFs causing node label miss match issue (array type)", doc: invalidRDFMessingUpLabelPrefixCounter, result: canonizedSampleVP2, - opts: []jsonld.ProcessorOpts{jsonld.WithRemoveAllInvalidRDF()}, + opts: []processor.Opts{processor.WithRemoveAllInvalidRDF()}, }, { name: "canonizing sample document with incorrect RDFs causing node label miss match issue (string type)", doc: invalidRDFMessingUpLabelPrefixCounterString, result: canonizedSampleVP2, - opts: []jsonld.ProcessorOpts{jsonld.WithRemoveAllInvalidRDF()}, + opts: []processor.Opts{processor.WithRemoveAllInvalidRDF()}, }, { name: "canonizing document with 1 incorrect RDF11", doc: jsonLDWith2KnownInvalidRDFs, result: canonizedIncorrectRDFAllFiltered, - opts: []jsonld.ProcessorOpts{jsonld.WithRemoveAllInvalidRDF()}, + opts: []processor.Opts{processor.WithRemoveAllInvalidRDF()}, }, { name: "canonizing sample VC document with proper context", @@ -447,7 +447,7 @@ func BenchmarkGetCanonicalDocument(b *testing.B) { name: "canonizing sample VC document with proper context but remove all invalid RDF", doc: vcWithProperContexts, result: canonizedJSONCredential, - opts: []jsonld.ProcessorOpts{jsonld.WithRemoveAllInvalidRDF()}, + opts: []processor.Opts{processor.WithRemoveAllInvalidRDF()}, }, { name: "canonizing sample VC document with proper context 2", @@ -458,25 +458,25 @@ func BenchmarkGetCanonicalDocument(b *testing.B) { name: "canonizing sample VC document with proper context 2 but remove all invalid RDF", doc: vcWithProperContexts2, result: canonizedJSONCredential2, - opts: []jsonld.ProcessorOpts{jsonld.WithRemoveAllInvalidRDF()}, + opts: []processor.Opts{processor.WithRemoveAllInvalidRDF()}, }, { name: "canonizing sample VC document with proper context 2 with in-memory document loader", doc: vcWithProperContexts2, result: canonizedJSONCredential2, - opts: []jsonld.ProcessorOpts{jsonld.WithDocumentLoader(loader)}, + opts: []processor.Opts{processor.WithDocumentLoader(loader)}, }, { name: "canonizing sample VC document with improper context", doc: vcWithIncorrectContexts, result: canonizedJSONCredentialNotFiltered, - opts: []jsonld.ProcessorOpts{}, + opts: []processor.Opts{}, }, { name: "canonizing sample VC document with improper context but remove all invalid RDF", doc: vcWithIncorrectContexts, result: canonizedJSONCredentialFiltered, - opts: []jsonld.ProcessorOpts{jsonld.WithRemoveAllInvalidRDF()}, + opts: []processor.Opts{processor.WithRemoveAllInvalidRDF()}, }, { name: "canonizing empty document", @@ -494,8 +494,8 @@ func BenchmarkGetCanonicalDocument(b *testing.B) { err := json.Unmarshal([]byte(tc.doc), &jsonldDoc) require.NoError(b, err) - response, err := jsonld.NewProcessor(defaultAlgorithm).GetCanonicalDocument(jsonldDoc, - append([]jsonld.ProcessorOpts{jsonld.WithDocumentLoader(loader)}, tc.opts...)...) + response, err := processor.NewProcessor(defaultAlgorithm).GetCanonicalDocument(jsonldDoc, + append([]processor.Opts{processor.WithDocumentLoader(loader)}, tc.opts...)...) require.NoError(b, err) require.EqualValues(b, tc.result, string(response)) } diff --git a/pkg/doc/signature/jsonld/testdata/canonized_incorrect_rdf.nq b/component/models/ld/processor/testdata/canonized_incorrect_rdf.nq similarity index 100% rename from pkg/doc/signature/jsonld/testdata/canonized_incorrect_rdf.nq rename to component/models/ld/processor/testdata/canonized_incorrect_rdf.nq diff --git a/pkg/doc/signature/jsonld/testdata/canonized_incorrect_rdf_all_filtered.nq b/component/models/ld/processor/testdata/canonized_incorrect_rdf_all_filtered.nq similarity index 100% rename from pkg/doc/signature/jsonld/testdata/canonized_incorrect_rdf_all_filtered.nq rename to component/models/ld/processor/testdata/canonized_incorrect_rdf_all_filtered.nq diff --git a/pkg/doc/signature/jsonld/testdata/canonized_incorrect_rdf_filtered.nq b/component/models/ld/processor/testdata/canonized_incorrect_rdf_filtered.nq similarity index 100% rename from pkg/doc/signature/jsonld/testdata/canonized_incorrect_rdf_filtered.nq rename to component/models/ld/processor/testdata/canonized_incorrect_rdf_filtered.nq diff --git a/pkg/doc/signature/jsonld/testdata/canonized_json_credential.nq b/component/models/ld/processor/testdata/canonized_json_credential.nq similarity index 100% rename from pkg/doc/signature/jsonld/testdata/canonized_json_credential.nq rename to component/models/ld/processor/testdata/canonized_json_credential.nq diff --git a/pkg/doc/signature/jsonld/testdata/canonized_json_credential_2.nq b/component/models/ld/processor/testdata/canonized_json_credential_2.nq similarity index 100% rename from pkg/doc/signature/jsonld/testdata/canonized_json_credential_2.nq rename to component/models/ld/processor/testdata/canonized_json_credential_2.nq diff --git a/pkg/doc/signature/jsonld/testdata/canonized_json_credential_filtered.nq b/component/models/ld/processor/testdata/canonized_json_credential_filtered.nq similarity index 100% rename from pkg/doc/signature/jsonld/testdata/canonized_json_credential_filtered.nq rename to component/models/ld/processor/testdata/canonized_json_credential_filtered.nq diff --git a/pkg/doc/signature/jsonld/testdata/canonized_json_credential_not_filtered.nq b/component/models/ld/processor/testdata/canonized_json_credential_not_filtered.nq similarity index 100% rename from pkg/doc/signature/jsonld/testdata/canonized_json_credential_not_filtered.nq rename to component/models/ld/processor/testdata/canonized_json_credential_not_filtered.nq diff --git a/pkg/doc/signature/jsonld/testdata/canonized_jsonld_proof.nq b/component/models/ld/processor/testdata/canonized_jsonld_proof.nq similarity index 100% rename from pkg/doc/signature/jsonld/testdata/canonized_jsonld_proof.nq rename to component/models/ld/processor/testdata/canonized_jsonld_proof.nq diff --git a/pkg/doc/signature/jsonld/testdata/canonized_sample_vp.nq b/component/models/ld/processor/testdata/canonized_sample_vp.nq similarity index 100% rename from pkg/doc/signature/jsonld/testdata/canonized_sample_vp.nq rename to component/models/ld/processor/testdata/canonized_sample_vp.nq diff --git a/pkg/doc/signature/jsonld/testdata/canonized_sample_vp_2.nq b/component/models/ld/processor/testdata/canonized_sample_vp_2.nq similarity index 100% rename from pkg/doc/signature/jsonld/testdata/canonized_sample_vp_2.nq rename to component/models/ld/processor/testdata/canonized_sample_vp_2.nq diff --git a/pkg/doc/signature/jsonld/testdata/canonized_sample_vp_extra_context.nq b/component/models/ld/processor/testdata/canonized_sample_vp_extra_context.nq similarity index 100% rename from pkg/doc/signature/jsonld/testdata/canonized_sample_vp_extra_context.nq rename to component/models/ld/processor/testdata/canonized_sample_vp_extra_context.nq diff --git a/pkg/doc/signature/jsonld/testdata/canonized_sample_vp_filtered.nq b/component/models/ld/processor/testdata/canonized_sample_vp_filtered.nq similarity index 100% rename from pkg/doc/signature/jsonld/testdata/canonized_sample_vp_filtered.nq rename to component/models/ld/processor/testdata/canonized_sample_vp_filtered.nq diff --git a/pkg/doc/signature/jsonld/testdata/contexts/extra_jsonld_context.jsonld b/component/models/ld/processor/testdata/contexts/extra_jsonld_context.jsonld similarity index 100% rename from pkg/doc/signature/jsonld/testdata/contexts/extra_jsonld_context.jsonld rename to component/models/ld/processor/testdata/contexts/extra_jsonld_context.jsonld diff --git a/pkg/doc/signature/jsonld/testdata/invalid_rdf_messing_up_label_prefix_counter.jsonld b/component/models/ld/processor/testdata/invalid_rdf_messing_up_label_prefix_counter.jsonld similarity index 100% rename from pkg/doc/signature/jsonld/testdata/invalid_rdf_messing_up_label_prefix_counter.jsonld rename to component/models/ld/processor/testdata/invalid_rdf_messing_up_label_prefix_counter.jsonld diff --git a/pkg/doc/signature/jsonld/testdata/invalid_rdf_messing_up_label_prefix_counter_str.jsonld b/component/models/ld/processor/testdata/invalid_rdf_messing_up_label_prefix_counter_str.jsonld similarity index 100% rename from pkg/doc/signature/jsonld/testdata/invalid_rdf_messing_up_label_prefix_counter_str.jsonld rename to component/models/ld/processor/testdata/invalid_rdf_messing_up_label_prefix_counter_str.jsonld diff --git a/pkg/doc/signature/jsonld/testdata/jsonld_multiple_invalid_rdfs.jsonld b/component/models/ld/processor/testdata/jsonld_multiple_invalid_rdfs.jsonld similarity index 100% rename from pkg/doc/signature/jsonld/testdata/jsonld_multiple_invalid_rdfs.jsonld rename to component/models/ld/processor/testdata/jsonld_multiple_invalid_rdfs.jsonld diff --git a/pkg/doc/signature/jsonld/testdata/jsonld_proof_sample.jsonld b/component/models/ld/processor/testdata/jsonld_proof_sample.jsonld similarity index 100% rename from pkg/doc/signature/jsonld/testdata/jsonld_proof_sample.jsonld rename to component/models/ld/processor/testdata/jsonld_proof_sample.jsonld diff --git a/pkg/doc/signature/jsonld/testdata/jsonld_sample_1.jsonld b/component/models/ld/processor/testdata/jsonld_sample_1.jsonld similarity index 100% rename from pkg/doc/signature/jsonld/testdata/jsonld_sample_1.jsonld rename to component/models/ld/processor/testdata/jsonld_sample_1.jsonld diff --git a/pkg/doc/signature/jsonld/testdata/jsonld_with_2_known_invalid_rdfs.jsonld b/component/models/ld/processor/testdata/jsonld_with_2_known_invalid_rdfs.jsonld similarity index 100% rename from pkg/doc/signature/jsonld/testdata/jsonld_with_2_known_invalid_rdfs.jsonld rename to component/models/ld/processor/testdata/jsonld_with_2_known_invalid_rdfs.jsonld diff --git a/pkg/doc/signature/jsonld/testdata/jsonld_with_incorrect_rdf.jsonld b/component/models/ld/processor/testdata/jsonld_with_incorrect_rdf.jsonld similarity index 100% rename from pkg/doc/signature/jsonld/testdata/jsonld_with_incorrect_rdf.jsonld rename to component/models/ld/processor/testdata/jsonld_with_incorrect_rdf.jsonld diff --git a/pkg/doc/signature/jsonld/testdata/vc_with_incorrect_contexts.jsonld b/component/models/ld/processor/testdata/vc_with_incorrect_contexts.jsonld similarity index 100% rename from pkg/doc/signature/jsonld/testdata/vc_with_incorrect_contexts.jsonld rename to component/models/ld/processor/testdata/vc_with_incorrect_contexts.jsonld diff --git a/pkg/doc/signature/jsonld/testdata/vc_with_proper_contexts.jsonld b/component/models/ld/processor/testdata/vc_with_proper_contexts.jsonld similarity index 100% rename from pkg/doc/signature/jsonld/testdata/vc_with_proper_contexts.jsonld rename to component/models/ld/processor/testdata/vc_with_proper_contexts.jsonld diff --git a/pkg/doc/signature/jsonld/testdata/vc_with_proper_contexts_2.jsonld b/component/models/ld/processor/testdata/vc_with_proper_contexts_2.jsonld similarity index 100% rename from pkg/doc/signature/jsonld/testdata/vc_with_proper_contexts_2.jsonld rename to component/models/ld/processor/testdata/vc_with_proper_contexts_2.jsonld diff --git a/pkg/doc/signature/proof/data.go b/component/models/ld/proof/data.go similarity index 92% rename from pkg/doc/signature/proof/data.go rename to component/models/ld/proof/data.go index c196ddd2a..79021b733 100644 --- a/pkg/doc/signature/proof/data.go +++ b/component/models/ld/proof/data.go @@ -9,7 +9,7 @@ import ( "errors" "fmt" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" ) const jsonldContext = "@context" @@ -18,7 +18,7 @@ const jsonldContext = "@context" type signatureSuite interface { // GetCanonicalDocument will return normalized/canonical version of the document - GetCanonicalDocument(doc map[string]interface{}, opts ...jsonld.ProcessorOpts) ([]byte, error) + GetCanonicalDocument(doc map[string]interface{}, opts ...processor.Opts) ([]byte, error) // GetDigest returns document digest GetDigest(doc []byte) []byte @@ -43,7 +43,7 @@ const ( // In case of "proofValue", the standard Create Verify Hash algorithm is used. // In case of "jws", verify data is built as JSON Web Signature (JWS) with detached payload. func CreateVerifyData(suite signatureSuite, jsonldDoc map[string]interface{}, proof *Proof, - opts ...jsonld.ProcessorOpts) ([]byte, error) { + opts ...processor.Opts) ([]byte, error) { switch proof.SignatureRepresentation { case SignatureProofValue: return CreateVerifyHash(suite, jsonldDoc, proof.JSONLdObject(), opts...) @@ -57,7 +57,7 @@ func CreateVerifyData(suite signatureSuite, jsonldDoc map[string]interface{}, pr // CreateVerifyHash returns data that is used to generate or verify a digital signature // Algorithm steps are described here https://w3c-dvcg.github.io/ld-signatures/#create-verify-hash-algorithm func CreateVerifyHash(suite signatureSuite, jsonldDoc, proofOptions map[string]interface{}, - opts ...jsonld.ProcessorOpts) ([]byte, error) { + opts ...processor.Opts) ([]byte, error) { // in order to generate canonical form we need context // if context is not passed, use document's context // spec doesn't mention anything about context @@ -84,7 +84,7 @@ func CreateVerifyHash(suite signatureSuite, jsonldDoc, proofOptions map[string]i } func prepareCanonicalProofOptions(suite signatureSuite, proofOptions map[string]interface{}, - opts ...jsonld.ProcessorOpts) ([]byte, error) { + opts ...processor.Opts) ([]byte, error) { value, ok := proofOptions[jsonldCreated] if !ok || value == nil { return nil, errors.New("created is missing") @@ -113,7 +113,7 @@ func prepareCanonicalProofOptions(suite signatureSuite, proofOptions map[string] } func prepareCanonicalDocument(suite signatureSuite, jsonldObject map[string]interface{}, - opts ...jsonld.ProcessorOpts) ([]byte, error) { + opts ...processor.Opts) ([]byte, error) { // copy document object without proof docCopy := GetCopyWithoutProof(jsonldObject) diff --git a/pkg/doc/signature/proof/data_test.go b/component/models/ld/proof/data_test.go similarity index 82% rename from pkg/doc/signature/proof/data_test.go rename to component/models/ld/proof/data_test.go index 53eedf075..36770aca1 100644 --- a/pkg/doc/signature/proof/data_test.go +++ b/component/models/ld/proof/data_test.go @@ -14,9 +14,9 @@ import ( "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" - "github.com/hyperledger/aries-framework-go/pkg/doc/util" - "github.com/hyperledger/aries-framework-go/pkg/internal/ldtestutil" + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" + "github.com/hyperledger/aries-framework-go/component/models/ld/testutil" + afgotime "github.com/hyperledger/aries-framework-go/component/models/util/time" ) func TestCreateVerifyHashAlgorithm(t *testing.T) { @@ -30,13 +30,13 @@ func TestCreateVerifyHashAlgorithm(t *testing.T) { err := json.Unmarshal([]byte(validDoc), &doc) require.NoError(t, err) - normalizedDoc, err := CreateVerifyHash(&mockSignatureSuite{}, doc, proofOptions, ldtestutil.WithDocumentLoader(t)) + normalizedDoc, err := CreateVerifyHash(&mockSignatureSuite{}, doc, proofOptions, testutil.WithDocumentLoader(t)) require.NoError(t, err) require.NotEmpty(t, normalizedDoc) // test error due to missing proof option delete(proofOptions, jsonldCreated) - normalizedDoc, err = CreateVerifyHash(&mockSignatureSuite{}, doc, proofOptions, ldtestutil.WithDocumentLoader(t)) + normalizedDoc, err = CreateVerifyHash(&mockSignatureSuite{}, doc, proofOptions, testutil.WithDocumentLoader(t)) require.NotNil(t, err) require.Nil(t, normalizedDoc) require.Contains(t, err.Error(), "created is missing") @@ -64,7 +64,7 @@ func TestPrepareCanonicalProofOptions(t *testing.T) { } canonicalProofOptions, err := prepareCanonicalProofOptions( - &mockSignatureSuite{}, proofOptions, ldtestutil.WithDocumentLoader(t)) + &mockSignatureSuite{}, proofOptions, testutil.WithDocumentLoader(t)) require.NoError(t, err) require.NotEmpty(t, canonicalProofOptions) @@ -72,7 +72,7 @@ func TestPrepareCanonicalProofOptions(t *testing.T) { // test missing created delete(proofOptions, jsonldCreated) canonicalProofOptions, err = prepareCanonicalProofOptions( - &mockSignatureSuite{}, proofOptions, ldtestutil.WithDocumentLoader(t)) + &mockSignatureSuite{}, proofOptions, testutil.WithDocumentLoader(t)) require.NotNil(t, err) require.Nil(t, canonicalProofOptions) @@ -85,7 +85,7 @@ func TestCreateVerifyData(t *testing.T) { p := &Proof{ Type: "type", - Created: util.NewTime(created), + Created: afgotime.NewTime(created), Creator: "key1", } @@ -94,26 +94,26 @@ func TestCreateVerifyData(t *testing.T) { require.NoError(t, err) p.SignatureRepresentation = SignatureProofValue - normalizedDoc, err := CreateVerifyData(&mockSignatureSuite{}, doc, p, ldtestutil.WithDocumentLoader(t)) + normalizedDoc, err := CreateVerifyData(&mockSignatureSuite{}, doc, p, testutil.WithDocumentLoader(t)) require.NoError(t, err) require.NotEmpty(t, normalizedDoc) p.SignatureRepresentation = SignatureProofValue normalizedDoc, err = CreateVerifyData( - &mockSignatureSuite{compactProof: true}, doc, p, ldtestutil.WithDocumentLoader(t)) + &mockSignatureSuite{compactProof: true}, doc, p, testutil.WithDocumentLoader(t)) require.NoError(t, err) require.NotEmpty(t, normalizedDoc) p.SignatureRepresentation = SignatureJWS p.JWS = "jws header.." - normalizedDoc, err = CreateVerifyData(&mockSignatureSuite{}, doc, p, ldtestutil.WithDocumentLoader(t)) + normalizedDoc, err = CreateVerifyData(&mockSignatureSuite{}, doc, p, testutil.WithDocumentLoader(t)) require.NoError(t, err) require.NotEmpty(t, normalizedDoc) // unsupported signature representation p.SignatureRepresentation = SignatureRepresentation(-1) - signature, err := CreateVerifyData(&mockSignatureSuite{}, doc, p, ldtestutil.WithDocumentLoader(t)) + signature, err := CreateVerifyData(&mockSignatureSuite{}, doc, p, testutil.WithDocumentLoader(t)) require.Error(t, err) require.Contains(t, err.Error(), "unsupported signature representation") @@ -126,8 +126,8 @@ type mockSignatureSuite struct { // GetCanonicalDocument will return normalized/canonical version of the document. func (s *mockSignatureSuite) GetCanonicalDocument(doc map[string]interface{}, - opts ...jsonld.ProcessorOpts) ([]byte, error) { - return jsonld.Default().GetCanonicalDocument(doc, opts...) + opts ...processor.Opts) ([]byte, error) { + return processor.Default().GetCanonicalDocument(doc, opts...) } // GetDigest returns document digest. diff --git a/pkg/doc/signature/proof/jws.go b/component/models/ld/proof/jws.go similarity index 91% rename from pkg/doc/signature/proof/jws.go rename to component/models/ld/proof/jws.go index d32ea1277..3ee55aca6 100644 --- a/pkg/doc/signature/proof/jws.go +++ b/component/models/ld/proof/jws.go @@ -11,7 +11,7 @@ import ( "errors" "strings" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" ) const ( @@ -67,7 +67,7 @@ func getJWTHeader(jwt string) (string, error) { // JSON and Signature documents and by preliminary JSON-LD compacting of JSON document. // The current implementation is based on the https://github.com/digitalbazaar/jsonld-signatures. func createVerifyJWS(suite signatureSuite, jsonldDoc map[string]interface{}, p *Proof, - opts ...jsonld.ProcessorOpts) ([]byte, error) { + opts ...processor.Opts) ([]byte, error) { proofOptions := p.JSONLdObject() canonicalProofOptions, err := prepareJWSProof(suite, proofOptions, opts...) @@ -95,7 +95,7 @@ func createVerifyJWS(suite signatureSuite, jsonldDoc map[string]interface{}, p * } func prepareJWSProof(suite signatureSuite, proofOptions map[string]interface{}, - opts ...jsonld.ProcessorOpts) ([]byte, error) { + opts ...processor.Opts) ([]byte, error) { // TODO proof contexts shouldn't be hardcoded in jws, should be passed in jsonld doc by author [Issue#1833] proofOptions[jsonldContext] = []interface{}{securityContext, securityContextJWK2020} proofOptionsCopy := make(map[string]interface{}, len(proofOptions)) @@ -111,7 +111,7 @@ func prepareJWSProof(suite signatureSuite, proofOptions map[string]interface{}, } func prepareDocumentForJWS(suite signatureSuite, jsonldObject map[string]interface{}, - opts ...jsonld.ProcessorOpts) ([]byte, error) { + opts ...processor.Opts) ([]byte, error) { // copy document object without proof doc := GetCopyWithoutProof(jsonldObject) @@ -129,10 +129,10 @@ func prepareDocumentForJWS(suite signatureSuite, jsonldObject map[string]interfa } func getCompactedWithSecuritySchema(docMap map[string]interface{}, - opts ...jsonld.ProcessorOpts) (map[string]interface{}, error) { + opts ...processor.Opts) (map[string]interface{}, error) { contextMap := map[string]interface{}{ "@context": securityContext, } - return jsonld.Default().Compact(docMap, contextMap, opts...) + return processor.Default().Compact(docMap, contextMap, opts...) } diff --git a/pkg/doc/signature/proof/jws_test.go b/component/models/ld/proof/jws_test.go similarity index 90% rename from pkg/doc/signature/proof/jws_test.go rename to component/models/ld/proof/jws_test.go index 80098cdd8..503f62200 100644 --- a/pkg/doc/signature/proof/jws_test.go +++ b/component/models/ld/proof/jws_test.go @@ -13,8 +13,8 @@ import ( "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/doc/util" - "github.com/hyperledger/aries-framework-go/pkg/internal/ldtestutil" + "github.com/hyperledger/aries-framework-go/component/models/ld/testutil" + afgotime "github.com/hyperledger/aries-framework-go/component/models/util/time" ) func Test_getJWTHeader(t *testing.T) { @@ -34,7 +34,7 @@ func Test_createVerifyJWS(t *testing.T) { p := &Proof{ Type: "Ed25519Signature2018", - Created: util.NewTime(created), + Created: afgotime.NewTime(created), JWS: "eyJ0eXAiOiJK..gFWFOEjXk", ProofPurpose: "assertionMethod", } @@ -44,19 +44,19 @@ func Test_createVerifyJWS(t *testing.T) { require.NoError(t, err) // happy path - no proof compaction - proofVerifyData, err := createVerifyJWS(&mockSignatureSuite{}, doc, p, ldtestutil.WithDocumentLoader(t)) + proofVerifyData, err := createVerifyJWS(&mockSignatureSuite{}, doc, p, testutil.WithDocumentLoader(t)) require.NoError(t, err) require.NotEmpty(t, proofVerifyData) // happy path - with proof compaction proofVerifyData, err = createVerifyJWS( - &mockSignatureSuite{compactProof: true}, doc, p, ldtestutil.WithDocumentLoader(t)) + &mockSignatureSuite{compactProof: true}, doc, p, testutil.WithDocumentLoader(t)) require.NoError(t, err) require.NotEmpty(t, proofVerifyData) // artificial example - failure of doc canonization doc["type"] = 777 - proofVerifyData, err = createVerifyJWS(&mockSignatureSuite{}, doc, p, ldtestutil.WithDocumentLoader(t)) + proofVerifyData, err = createVerifyJWS(&mockSignatureSuite{}, doc, p, testutil.WithDocumentLoader(t)) require.Error(t, err) require.Contains(t, err.Error(), "invalid type value") require.Empty(t, proofVerifyData) @@ -64,7 +64,7 @@ func Test_createVerifyJWS(t *testing.T) { // invalid JWT passed (we need to read a header from it to prepare verify data) doc["type"] = "Ed25519Signature2018" p.JWS = "invalid jws" - proofVerifyData, err = createVerifyJWS(&mockSignatureSuite{}, doc, p, ldtestutil.WithDocumentLoader(t)) + proofVerifyData, err = createVerifyJWS(&mockSignatureSuite{}, doc, p, testutil.WithDocumentLoader(t)) require.Error(t, err) require.Contains(t, err.Error(), "invalid JWT") require.Empty(t, proofVerifyData) diff --git a/pkg/doc/signature/proof/proof.go b/component/models/ld/proof/proof.go similarity index 97% rename from pkg/doc/signature/proof/proof.go rename to component/models/ld/proof/proof.go index 415be79fd..aa7bda23d 100644 --- a/pkg/doc/signature/proof/proof.go +++ b/component/models/ld/proof/proof.go @@ -12,7 +12,7 @@ import ( "github.com/multiformats/go-multibase" - "github.com/hyperledger/aries-framework-go/pkg/doc/util" + afgotime "github.com/hyperledger/aries-framework-go/component/models/util/time" ) const ( @@ -45,7 +45,7 @@ const ( // Proof is cryptographic proof of the integrity of the DID Document. type Proof struct { Type string - Created *util.TimeWrapper + Created *afgotime.TimeWrapper Creator string VerificationMethod string ProofValue []byte @@ -63,7 +63,7 @@ type Proof struct { func NewProof(emap map[string]interface{}) (*Proof, error) { created := stringEntry(emap[jsonldCreated]) - timeValue, err := util.ParseTimeWrapper(created) + timeValue, err := afgotime.ParseTimeWrapper(created) if err != nil { return nil, err } diff --git a/pkg/doc/signature/proof/proof_test.go b/component/models/ld/proof/proof_test.go similarity index 97% rename from pkg/doc/signature/proof/proof_test.go rename to component/models/ld/proof/proof_test.go index 4465b6970..a1da543df 100644 --- a/pkg/doc/signature/proof/proof_test.go +++ b/component/models/ld/proof/proof_test.go @@ -13,7 +13,7 @@ import ( "github.com/multiformats/go-multibase" "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/doc/util" + afgotime "github.com/hyperledger/aries-framework-go/component/models/util/time" ) const ( @@ -383,7 +383,7 @@ func TestProof_JSONLdObject(t *testing.T) { p := &Proof{ Type: "Ed25519Signature2020", - Created: util.NewTime(created), + Created: afgotime.NewTime(created), Creator: "creator", ProofValue: proofValueBytes, JWS: "test.jws.value", @@ -408,7 +408,7 @@ func TestProof_JSONLdObject(t *testing.T) { created, err = time.Parse(time.RFC3339Nano, "2018-03-15T00:00:00.972Z") require.NoError(t, err) - p.Created = util.NewTime(created) + p.Created = afgotime.NewTime(created) pJSONLd = p.JSONLdObject() r.Equal("2018-03-15T00:00:00.972Z", pJSONLd["created"]) @@ -416,7 +416,7 @@ func TestProof_JSONLdObject(t *testing.T) { created, err = time.Parse(time.RFC3339Nano, "2018-03-15T00:00:00.000Z") require.NoError(t, err) - p.Created, err = util.ParseTimeWrapper("2018-03-15T00:00:00.000Z") + p.Created, err = afgotime.ParseTimeWrapper("2018-03-15T00:00:00.000Z") require.NoError(t, err) pJSONLd = p.JSONLdObject() @@ -427,7 +427,7 @@ func TestProof_JSONLdObject(t *testing.T) { capability := "http://edv.com/foo/zcaps/1" p := &Proof{ Type: "Ed25519Signature2018", - Created: util.NewTime(created), + Created: afgotime.NewTime(created), Creator: "creator", ProofValue: proofValueBytes, JWS: "test.jws.value", @@ -448,7 +448,7 @@ func TestProof_JSONLdObject(t *testing.T) { t.Run("not included", func(t *testing.T) { p := &Proof{ Type: "Ed25519Signature2018", - Created: util.NewTime(created), + Created: afgotime.NewTime(created), Creator: "creator", ProofValue: proofValueBytes, JWS: "test.jws.value", diff --git a/pkg/doc/signature/proof/testdata/valid_doc.jsonld b/component/models/ld/proof/testdata/valid_doc.jsonld similarity index 100% rename from pkg/doc/signature/proof/testdata/valid_doc.jsonld rename to component/models/ld/proof/testdata/valid_doc.jsonld diff --git a/pkg/doc/signature/proof/utils.go b/component/models/ld/proof/utils.go similarity index 100% rename from pkg/doc/signature/proof/utils.go rename to component/models/ld/proof/utils.go diff --git a/pkg/doc/signature/proof/utils_test.go b/component/models/ld/proof/utils_test.go similarity index 92% rename from pkg/doc/signature/proof/utils_test.go rename to component/models/ld/proof/utils_test.go index c3adfa810..f01251e0e 100644 --- a/pkg/doc/signature/proof/utils_test.go +++ b/component/models/ld/proof/utils_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/doc/util" + afgotime "github.com/hyperledger/aries-framework-go/component/models/util/time" ) func TestAddManyProofs(t *testing.T) { @@ -24,7 +24,7 @@ func TestAddManyProofs(t *testing.T) { now := time.Now() proof1 := Proof{ Creator: "creator-1", - Created: util.NewTime(now), + Created: afgotime.NewTime(now), ProofValue: []byte("proof"), Type: "Ed25519Signature2018", } @@ -38,7 +38,7 @@ func TestAddManyProofs(t *testing.T) { proof2 := Proof{ Creator: "creator-2", - Created: util.NewTime(now), + Created: afgotime.NewTime(now), ProofValue: []byte("proof"), Type: "Ed25519Signature2018", } @@ -86,7 +86,7 @@ func TestAddSingleProof(t *testing.T) { now := time.Now() proof := Proof{ Creator: "creator-2", - Created: util.NewTime(now), + Created: afgotime.NewTime(now), ProofValue: []byte("proof #2"), Type: "Ed25519Signature2018", } diff --git a/pkg/store/ld/context_store.go b/component/models/ld/store/context_store.go similarity index 97% rename from pkg/store/ld/context_store.go rename to component/models/ld/store/context_store.go index 821382356..636472c9c 100644 --- a/pkg/store/ld/context_store.go +++ b/component/models/ld/store/context_store.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package ld +package store import ( "bytes" @@ -14,8 +14,8 @@ import ( jsonld "github.com/piprate/json-gold/ld" - "github.com/hyperledger/aries-framework-go/pkg/common/log" - "github.com/hyperledger/aries-framework-go/pkg/doc/ldcontext" + "github.com/hyperledger/aries-framework-go/component/log" + ldcontext "github.com/hyperledger/aries-framework-go/component/models/ld/context" "github.com/hyperledger/aries-framework-go/spi/storage" ) diff --git a/pkg/store/ld/context_store_test.go b/component/models/ld/store/context_store_test.go similarity index 86% rename from pkg/store/ld/context_store_test.go rename to component/models/ld/store/context_store_test.go index b89d272ea..f5bccbc6a 100644 --- a/pkg/store/ld/context_store_test.go +++ b/component/models/ld/store/context_store_test.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package ld_test +package store_test import ( "bytes" @@ -15,10 +15,10 @@ import ( jsonld "github.com/piprate/json-gold/ld" "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/doc/ldcontext" - "github.com/hyperledger/aries-framework-go/pkg/doc/ldcontext/embed" - mockstorage "github.com/hyperledger/aries-framework-go/pkg/mock/storage" - "github.com/hyperledger/aries-framework-go/pkg/store/ld" + ldcontext "github.com/hyperledger/aries-framework-go/component/models/ld/context" + "github.com/hyperledger/aries-framework-go/component/models/ld/context/embed" + ldstore "github.com/hyperledger/aries-framework-go/component/models/ld/store" + mockstorage "github.com/hyperledger/aries-framework-go/component/storageutil/mock/storage" "github.com/hyperledger/aries-framework-go/spi/storage" ) @@ -40,7 +40,7 @@ func TestNewContextStore(t *testing.T) { t.Run("Success", func(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() - store, err := ld.NewContextStore(storageProvider) + store, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) require.NotNil(t, store) @@ -51,7 +51,7 @@ func TestNewContextStore(t *testing.T) { storageProvider.ErrOpenStoreHandle = errors.New("open store error") storageProvider.ErrSetStoreConfig = errors.New("set store config error") - store, err := ld.NewContextStore(storageProvider) + store, err := ldstore.NewContextStore(storageProvider) require.Nil(t, store) require.Error(t, err) @@ -62,7 +62,7 @@ func TestNewContextStore(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.ErrSetStoreConfig = errors.New("set store config error") - store, err := ld.NewContextStore(storageProvider) + store, err := ldstore.NewContextStore(storageProvider) require.Nil(t, store) require.Error(t, err) @@ -76,7 +76,7 @@ func TestContextStoreImpl_Get(t *testing.T) { setSampleContextInStore(t, storageProvider.Store) - contextStore, err := ld.NewContextStore(storageProvider) + contextStore, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) rd, err := contextStore.Get("https://example.com/context.jsonld") @@ -89,7 +89,7 @@ func TestContextStoreImpl_Get(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrGet = errors.New("get error") - contextStore, err := ld.NewContextStore(storageProvider) + contextStore, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) rd, err := contextStore.Get("https://example.com/context.jsonld") @@ -104,7 +104,7 @@ func TestContextStoreImpl_Put(t *testing.T) { t.Run("Success", func(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() - contextStore, err := ld.NewContextStore(storageProvider) + contextStore, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) rd := getRemoteDocument(t, json.RawMessage(sampleJSONLDContext)) @@ -119,7 +119,7 @@ func TestContextStoreImpl_Put(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrPut = errors.New("put error") - contextStore, err := ld.NewContextStore(storageProvider) + contextStore, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) rd := getRemoteDocument(t, json.RawMessage(sampleJSONLDContext)) @@ -141,7 +141,7 @@ func TestContextStoreImpl_Import(t *testing.T) { storageProvider := &mockstorage.MockStoreProvider{Custom: store} - contextStore, err := ld.NewContextStore(storageProvider) + contextStore, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) err = contextStore.Import(embed.Contexts) @@ -173,7 +173,7 @@ func TestContextStoreImpl_Import(t *testing.T) { }, } - contextStore, err := ld.NewContextStore(storageProvider) + contextStore, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) err = contextStore.Import(contexts) @@ -193,7 +193,7 @@ func TestContextStoreImpl_Import(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrQuery = errors.New("query error") - contextStore, err := ld.NewContextStore(storageProvider) + contextStore, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) err = contextStore.Import(embed.Contexts) @@ -205,7 +205,7 @@ func TestContextStoreImpl_Import(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrNext = errors.New("next error") - contextStore, err := ld.NewContextStore(storageProvider) + contextStore, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) err = contextStore.Import(embed.Contexts) @@ -219,7 +219,7 @@ func TestContextStoreImpl_Import(t *testing.T) { setSampleContextInStore(t, storageProvider.Store) - contextStore, err := ld.NewContextStore(storageProvider) + contextStore, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) err = contextStore.Import(embed.Contexts) @@ -233,7 +233,7 @@ func TestContextStoreImpl_Import(t *testing.T) { setSampleContextInStore(t, storageProvider.Store) - contextStore, err := ld.NewContextStore(storageProvider) + contextStore, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) err = contextStore.Import(embed.Contexts) @@ -245,7 +245,7 @@ func TestContextStoreImpl_Import(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrValue = errors.New("value error") - contextStore, err := ld.NewContextStore(storageProvider) + contextStore, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) err = contextStore.Import([]ldcontext.Document{ @@ -262,7 +262,7 @@ func TestContextStoreImpl_Import(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrPut = errors.New("error") - contextStore, err := ld.NewContextStore(storageProvider) + contextStore, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) err = contextStore.Import(embed.Contexts) @@ -277,7 +277,7 @@ func TestContextStoreImpl_Delete(t *testing.T) { setSampleContextInStore(t, storageProvider.Store) - store, err := ld.NewContextStore(storageProvider) + store, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) contexts := []ldcontext.Document{ @@ -296,7 +296,7 @@ func TestContextStoreImpl_Delete(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrQuery = errors.New("query error") - store, err := ld.NewContextStore(storageProvider) + store, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) contexts := []ldcontext.Document{ @@ -315,7 +315,7 @@ func TestContextStoreImpl_Delete(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrNext = errors.New("next error") - store, err := ld.NewContextStore(storageProvider) + store, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) contexts := []ldcontext.Document{ @@ -336,7 +336,7 @@ func TestContextStoreImpl_Delete(t *testing.T) { setSampleContextInStore(t, storageProvider.Store) - store, err := ld.NewContextStore(storageProvider) + store, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) contexts := []ldcontext.Document{ @@ -357,7 +357,7 @@ func TestContextStoreImpl_Delete(t *testing.T) { setSampleContextInStore(t, storageProvider.Store) - store, err := ld.NewContextStore(storageProvider) + store, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) contexts := []ldcontext.Document{ @@ -376,7 +376,7 @@ func TestContextStoreImpl_Delete(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrValue = errors.New("value error") - store, err := ld.NewContextStore(storageProvider) + store, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) contexts := []ldcontext.Document{ @@ -397,7 +397,7 @@ func TestContextStoreImpl_Delete(t *testing.T) { setSampleContextInStore(t, storageProvider.Store) - store, err := ld.NewContextStore(storageProvider) + store, err := ldstore.NewContextStore(storageProvider) require.NoError(t, err) contexts := []ldcontext.Document{ @@ -435,7 +435,7 @@ func setSampleContextInStore(t *testing.T, store storage.Store) { b, err := json.Marshal(rd) require.NoError(t, err) - err = store.Put(sampleContextURL, b, storage.Tag{Name: ld.ContextRecordTag}) + err = store.Put(sampleContextURL, b, storage.Tag{Name: ldstore.ContextRecordTag}) require.NoError(t, err) } diff --git a/pkg/store/ld/remote_provider_store.go b/component/models/ld/store/remote_provider_store.go similarity index 99% rename from pkg/store/ld/remote_provider_store.go rename to component/models/ld/store/remote_provider_store.go index c19d3d7ed..1763fda24 100644 --- a/pkg/store/ld/remote_provider_store.go +++ b/component/models/ld/store/remote_provider_store.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package ld +package store import ( "fmt" diff --git a/pkg/store/ld/remote_provider_store_test.go b/component/models/ld/store/remote_provider_store_test.go similarity index 80% rename from pkg/store/ld/remote_provider_store_test.go rename to component/models/ld/store/remote_provider_store_test.go index c8d893954..f8a84120c 100644 --- a/pkg/store/ld/remote_provider_store_test.go +++ b/component/models/ld/store/remote_provider_store_test.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package ld_test +package store_test import ( "errors" @@ -12,8 +12,8 @@ import ( "github.com/stretchr/testify/require" - mockstorage "github.com/hyperledger/aries-framework-go/pkg/mock/storage" - "github.com/hyperledger/aries-framework-go/pkg/store/ld" + ldstore "github.com/hyperledger/aries-framework-go/component/models/ld/store" + mockstorage "github.com/hyperledger/aries-framework-go/component/storageutil/mock/storage" "github.com/hyperledger/aries-framework-go/spi/storage" ) @@ -21,7 +21,7 @@ func TestNewRemoteProviderStore(t *testing.T) { t.Run("Success", func(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() - store, err := ld.NewRemoteProviderStore(storageProvider) + store, err := ldstore.NewRemoteProviderStore(storageProvider) require.NoError(t, err) require.NotNil(t, store) @@ -31,7 +31,7 @@ func TestNewRemoteProviderStore(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.ErrOpenStoreHandle = errors.New("open store error") - store, err := ld.NewRemoteProviderStore(storageProvider) + store, err := ldstore.NewRemoteProviderStore(storageProvider) require.Nil(t, store) require.Error(t, err) @@ -42,7 +42,7 @@ func TestNewRemoteProviderStore(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.ErrSetStoreConfig = errors.New("set store config error") - store, err := ld.NewRemoteProviderStore(storageProvider) + store, err := ldstore.NewRemoteProviderStore(storageProvider) require.Nil(t, store) require.Error(t, err) @@ -54,10 +54,10 @@ func TestRemoteProviderStoreImpl_Get(t *testing.T) { t.Run("Success", func(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() - err := storageProvider.Store.Put("id", []byte("endpoint"), storage.Tag{Name: ld.RemoteProviderRecordTag}) + err := storageProvider.Store.Put("id", []byte("endpoint"), storage.Tag{Name: ldstore.RemoteProviderRecordTag}) require.NoError(t, err) - store, err := ld.NewRemoteProviderStore(storageProvider) + store, err := ldstore.NewRemoteProviderStore(storageProvider) require.NoError(t, err) record, err := store.Get("id") @@ -71,7 +71,7 @@ func TestRemoteProviderStoreImpl_Get(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrGet = errors.New("get error") - store, err := ld.NewRemoteProviderStore(storageProvider) + store, err := ldstore.NewRemoteProviderStore(storageProvider) require.NoError(t, err) record, err := store.Get("id") @@ -86,13 +86,13 @@ func TestRemoteProviderStoreImpl_GetAll(t *testing.T) { t.Run("Success", func(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() - err := storageProvider.Store.Put("id", []byte("endpoint"), storage.Tag{Name: ld.RemoteProviderRecordTag}) + err := storageProvider.Store.Put("id", []byte("endpoint"), storage.Tag{Name: ldstore.RemoteProviderRecordTag}) require.NoError(t, err) - err = storageProvider.Store.Put("id2", []byte("endpoint2"), storage.Tag{Name: ld.RemoteProviderRecordTag}) + err = storageProvider.Store.Put("id2", []byte("endpoint2"), storage.Tag{Name: ldstore.RemoteProviderRecordTag}) require.NoError(t, err) - store, err := ld.NewRemoteProviderStore(storageProvider) + store, err := ldstore.NewRemoteProviderStore(storageProvider) require.NoError(t, err) records, err := store.GetAll() @@ -105,7 +105,7 @@ func TestRemoteProviderStoreImpl_GetAll(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrQuery = errors.New("query error") - store, err := ld.NewRemoteProviderStore(storageProvider) + store, err := ldstore.NewRemoteProviderStore(storageProvider) require.NoError(t, err) records, err := store.GetAll() @@ -119,7 +119,7 @@ func TestRemoteProviderStoreImpl_GetAll(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrNext = errors.New("next error") - store, err := ld.NewRemoteProviderStore(storageProvider) + store, err := ldstore.NewRemoteProviderStore(storageProvider) require.NoError(t, err) records, err := store.GetAll() @@ -133,10 +133,10 @@ func TestRemoteProviderStoreImpl_GetAll(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrKey = errors.New("key error") - err := storageProvider.Store.Put("id", []byte("endpoint"), storage.Tag{Name: ld.RemoteProviderRecordTag}) + err := storageProvider.Store.Put("id", []byte("endpoint"), storage.Tag{Name: ldstore.RemoteProviderRecordTag}) require.NoError(t, err) - store, err := ld.NewRemoteProviderStore(storageProvider) + store, err := ldstore.NewRemoteProviderStore(storageProvider) require.NoError(t, err) records, err := store.GetAll() @@ -150,10 +150,10 @@ func TestRemoteProviderStoreImpl_GetAll(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrValue = errors.New("value error") - err := storageProvider.Store.Put("id", []byte("endpoint"), storage.Tag{Name: ld.RemoteProviderRecordTag}) + err := storageProvider.Store.Put("id", []byte("endpoint"), storage.Tag{Name: ldstore.RemoteProviderRecordTag}) require.NoError(t, err) - store, err := ld.NewRemoteProviderStore(storageProvider) + store, err := ldstore.NewRemoteProviderStore(storageProvider) require.NoError(t, err) records, err := store.GetAll() @@ -168,7 +168,7 @@ func TestRemoteProviderStoreImpl_Save(t *testing.T) { t.Run("Save new remote provider record", func(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() - store, err := ld.NewRemoteProviderStore(storageProvider) + store, err := ldstore.NewRemoteProviderStore(storageProvider) require.NoError(t, err) record, err := store.Save("endpoint") @@ -181,10 +181,10 @@ func TestRemoteProviderStoreImpl_Save(t *testing.T) { t.Run("Return existing remote provider record", func(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() - err := storageProvider.Store.Put("id", []byte("endpoint"), storage.Tag{Name: ld.RemoteProviderRecordTag}) + err := storageProvider.Store.Put("id", []byte("endpoint"), storage.Tag{Name: ldstore.RemoteProviderRecordTag}) require.NoError(t, err) - store, err := ld.NewRemoteProviderStore(storageProvider) + store, err := ldstore.NewRemoteProviderStore(storageProvider) require.NoError(t, err) record, err := store.Save("endpoint") @@ -199,7 +199,7 @@ func TestRemoteProviderStoreImpl_Save(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrQuery = errors.New("query error") - store, err := ld.NewRemoteProviderStore(storageProvider) + store, err := ldstore.NewRemoteProviderStore(storageProvider) require.NoError(t, err) record, err := store.Save("endpoint") @@ -213,7 +213,7 @@ func TestRemoteProviderStoreImpl_Save(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrNext = errors.New("next error") - store, err := ld.NewRemoteProviderStore(storageProvider) + store, err := ldstore.NewRemoteProviderStore(storageProvider) require.NoError(t, err) record, err := store.Save("endpoint") @@ -227,10 +227,10 @@ func TestRemoteProviderStoreImpl_Save(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrKey = errors.New("key error") - err := storageProvider.Store.Put("id", []byte("endpoint"), storage.Tag{Name: ld.RemoteProviderRecordTag}) + err := storageProvider.Store.Put("id", []byte("endpoint"), storage.Tag{Name: ldstore.RemoteProviderRecordTag}) require.NoError(t, err) - store, err := ld.NewRemoteProviderStore(storageProvider) + store, err := ldstore.NewRemoteProviderStore(storageProvider) require.NoError(t, err) record, err := store.Save("endpoint") @@ -244,10 +244,10 @@ func TestRemoteProviderStoreImpl_Save(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrValue = errors.New("value error") - err := storageProvider.Store.Put("id", []byte("endpoint"), storage.Tag{Name: ld.RemoteProviderRecordTag}) + err := storageProvider.Store.Put("id", []byte("endpoint"), storage.Tag{Name: ldstore.RemoteProviderRecordTag}) require.NoError(t, err) - store, err := ld.NewRemoteProviderStore(storageProvider) + store, err := ldstore.NewRemoteProviderStore(storageProvider) require.NoError(t, err) record, err := store.Save("endpoint") @@ -261,7 +261,7 @@ func TestRemoteProviderStoreImpl_Save(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrPut = errors.New("put error") - store, err := ld.NewRemoteProviderStore(storageProvider) + store, err := ldstore.NewRemoteProviderStore(storageProvider) require.NoError(t, err) record, err := store.Save("endpoint") @@ -276,10 +276,10 @@ func TestRemoteProviderStoreImpl_Delete(t *testing.T) { t.Run("Delete remote provider record", func(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() - err := storageProvider.Store.Put("id", []byte("endpoint"), storage.Tag{Name: ld.RemoteProviderRecordTag}) + err := storageProvider.Store.Put("id", []byte("endpoint"), storage.Tag{Name: ldstore.RemoteProviderRecordTag}) require.NoError(t, err) - store, err := ld.NewRemoteProviderStore(storageProvider) + store, err := ldstore.NewRemoteProviderStore(storageProvider) require.NoError(t, err) err = store.Delete("id") @@ -292,7 +292,7 @@ func TestRemoteProviderStoreImpl_Delete(t *testing.T) { storageProvider := mockstorage.NewMockStoreProvider() storageProvider.Store.ErrDelete = errors.New("delete error") - store, err := ld.NewRemoteProviderStore(storageProvider) + store, err := ldstore.NewRemoteProviderStore(storageProvider) require.NoError(t, err) err = store.Delete("id") diff --git a/pkg/internal/ldtestutil/contexts/third_party/trustbloc.github.io/trustbloc-authorization-credential_v1.jsonld b/component/models/ld/testutil/contexts/third_party/trustbloc.github.io/trustbloc-authorization-credential_v1.jsonld similarity index 100% rename from pkg/internal/ldtestutil/contexts/third_party/trustbloc.github.io/trustbloc-authorization-credential_v1.jsonld rename to component/models/ld/testutil/contexts/third_party/trustbloc.github.io/trustbloc-authorization-credential_v1.jsonld diff --git a/pkg/internal/ldtestutil/contexts/third_party/trustbloc.github.io/trustbloc-examples_v1.jsonld b/component/models/ld/testutil/contexts/third_party/trustbloc.github.io/trustbloc-examples_v1.jsonld similarity index 100% rename from pkg/internal/ldtestutil/contexts/third_party/trustbloc.github.io/trustbloc-examples_v1.jsonld rename to component/models/ld/testutil/contexts/third_party/trustbloc.github.io/trustbloc-examples_v1.jsonld diff --git a/pkg/internal/ldtestutil/contexts/third_party/w3.org/credentials-examples_v1.jsonld b/component/models/ld/testutil/contexts/third_party/w3.org/credentials-examples_v1.jsonld similarity index 100% rename from pkg/internal/ldtestutil/contexts/third_party/w3.org/credentials-examples_v1.jsonld rename to component/models/ld/testutil/contexts/third_party/w3.org/credentials-examples_v1.jsonld diff --git a/pkg/internal/ldtestutil/contexts/third_party/w3.org/odrl.jsonld b/component/models/ld/testutil/contexts/third_party/w3.org/odrl.jsonld similarity index 100% rename from pkg/internal/ldtestutil/contexts/third_party/w3.org/odrl.jsonld rename to component/models/ld/testutil/contexts/third_party/w3.org/odrl.jsonld diff --git a/pkg/internal/ldtestutil/contexts/third_party/w3c-ccg.github.io/citizenship_v1.jsonld b/component/models/ld/testutil/contexts/third_party/w3c-ccg.github.io/citizenship_v1.jsonld similarity index 100% rename from pkg/internal/ldtestutil/contexts/third_party/w3c-ccg.github.io/citizenship_v1.jsonld rename to component/models/ld/testutil/contexts/third_party/w3c-ccg.github.io/citizenship_v1.jsonld diff --git a/pkg/internal/ldtestutil/contexts/third_party/w3c-ccg.github.io/revocation-list-2021.jsonld b/component/models/ld/testutil/contexts/third_party/w3c-ccg.github.io/revocation-list-2021.jsonld similarity index 100% rename from pkg/internal/ldtestutil/contexts/third_party/w3c-ccg.github.io/revocation-list-2021.jsonld rename to component/models/ld/testutil/contexts/third_party/w3c-ccg.github.io/revocation-list-2021.jsonld diff --git a/pkg/internal/ldtestutil/document_loader.go b/component/models/ld/testutil/document_loader.go similarity index 79% rename from pkg/internal/ldtestutil/document_loader.go rename to component/models/ld/testutil/document_loader.go index 62e13659d..0731c7794 100644 --- a/pkg/internal/ldtestutil/document_loader.go +++ b/component/models/ld/testutil/document_loader.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package ldtestutil +package testutil import ( _ "embed" //nolint:gci // required for go:embed @@ -13,11 +13,11 @@ import ( "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/doc/ld" - "github.com/hyperledger/aries-framework-go/pkg/doc/ldcontext" - ldprocessor "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" - mockldstore "github.com/hyperledger/aries-framework-go/pkg/mock/ld" - ldstore "github.com/hyperledger/aries-framework-go/pkg/store/ld" + ldcontext "github.com/hyperledger/aries-framework-go/component/models/ld/context" + "github.com/hyperledger/aries-framework-go/component/models/ld/documentloader" + mockldstore "github.com/hyperledger/aries-framework-go/component/models/ld/mock" + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" + ldstore "github.com/hyperledger/aries-framework-go/component/models/ld/store" ) // nolint:gochecknoglobals // required for go:embed @@ -66,17 +66,17 @@ var testContexts = []ldcontext.Document{ //nolint:gochecknoglobals // embedded t } // WithDocumentLoader returns an option with a custom JSON-LD document loader preloaded with embedded contexts. -func WithDocumentLoader(t *testing.T) ldprocessor.ProcessorOpts { +func WithDocumentLoader(t *testing.T) processor.Opts { t.Helper() loader, err := createTestDocumentLoader() require.NoError(t, err) - return ldprocessor.WithDocumentLoader(loader) + return processor.WithDocumentLoader(loader) } // DocumentLoader returns JSON-LD document loader preloaded with embedded contexts and provided extra contexts. -func DocumentLoader(extraContexts ...ldcontext.Document) (*ld.DocumentLoader, error) { +func DocumentLoader(extraContexts ...ldcontext.Document) (*documentloader.DocumentLoader, error) { return createTestDocumentLoader(extraContexts...) } @@ -98,7 +98,7 @@ func (m *mockProvider) JSONLDRemoteProviderStore() ldstore.RemoteProviderStore { return m.RemoteProviderStore } -func createTestDocumentLoader(extraContexts ...ldcontext.Document) (*ld.DocumentLoader, error) { +func createTestDocumentLoader(extraContexts ...ldcontext.Document) (*documentloader.DocumentLoader, error) { contexts := append(testContexts, extraContexts...) p := &mockProvider{ @@ -106,7 +106,7 @@ func createTestDocumentLoader(extraContexts ...ldcontext.Document) (*ld.Document RemoteProviderStore: mockldstore.NewMockRemoteProviderStore(), } - loader, err := ld.NewDocumentLoader(p, ld.WithExtraContexts(contexts...)) + loader, err := documentloader.NewDocumentLoader(p, documentloader.WithExtraContexts(contexts...)) if err != nil { return nil, fmt.Errorf("create document loader: %w", err) } diff --git a/pkg/internal/ldtestutil/document_loader_test.go b/component/models/ld/testutil/document_loader_test.go similarity index 65% rename from pkg/internal/ldtestutil/document_loader_test.go rename to component/models/ld/testutil/document_loader_test.go index 3f522b818..1b12bbf96 100644 --- a/pkg/internal/ldtestutil/document_loader_test.go +++ b/component/models/ld/testutil/document_loader_test.go @@ -4,23 +4,23 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package ldtestutil_test +package testutil_test import ( "testing" "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/internal/ldtestutil" + "github.com/hyperledger/aries-framework-go/component/models/ld/testutil" ) func TestWithDocumentLoader(t *testing.T) { - opt := ldtestutil.WithDocumentLoader(t) + opt := testutil.WithDocumentLoader(t) require.NotNil(t, opt) } func TestDocumentLoader(t *testing.T) { - loader, err := ldtestutil.DocumentLoader() + loader, err := testutil.DocumentLoader() require.NotNil(t, loader) require.NoError(t, err) } diff --git a/component/models/signature/api/api.go b/component/models/signature/api/api.go new file mode 100644 index 000000000..ddba2f73d --- /dev/null +++ b/component/models/signature/api/api.go @@ -0,0 +1,38 @@ +/* +Copyright Gen Digital Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" +) + +// SignatureSuite encapsulates signature suite methods required for signature verification. +type SignatureSuite interface { + + // GetCanonicalDocument will return normalized/canonical version of the document + GetCanonicalDocument(doc map[string]interface{}, opts ...processor.Opts) ([]byte, error) + + // GetDigest returns document digest + GetDigest(doc []byte) []byte + + // Verify will verify signature against public key + Verify(pubKey *PublicKey, doc []byte, signature []byte) error + + // Accept registers this signature suite with the given signature type + Accept(signatureType string) bool + + // CompactProof indicates weather to compact the proof doc before canonization + CompactProof() bool +} + +// PublicKey contains a result of public key resolution. +type PublicKey struct { + Type string + Value []byte + JWK *jwk.JWK +} diff --git a/pkg/doc/signature/signer/signer.go b/component/models/signature/signer/signer.go similarity index 91% rename from pkg/doc/signature/signer/signer.go rename to component/models/signature/signer/signer.go index eaee0a3b6..5e266ab89 100644 --- a/pkg/doc/signature/signer/signer.go +++ b/component/models/signature/signer/signer.go @@ -12,8 +12,8 @@ import ( "fmt" "time" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/proof" + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" + "github.com/hyperledger/aries-framework-go/component/models/ld/proof" ) const defaultProofPurpose = "assertionMethod" @@ -21,7 +21,7 @@ const defaultProofPurpose = "assertionMethod" // SignatureSuite encapsulates signature suite methods required for signing documents. type SignatureSuite interface { // GetCanonicalDocument will return normalized/canonical version of the document - GetCanonicalDocument(doc map[string]interface{}, opts ...jsonld.ProcessorOpts) ([]byte, error) + GetCanonicalDocument(doc map[string]interface{}, opts ...processor.Opts) ([]byte, error) // GetDigest returns document digest GetDigest(doc []byte) []byte @@ -64,7 +64,11 @@ func New(signatureSuites ...SignatureSuite) *DocumentSigner { } // Sign will sign JSON LD document. -func (signer *DocumentSigner) Sign(context *Context, jsonLdDoc []byte, opts ...jsonld.ProcessorOpts) ([]byte, error) { +func (signer *DocumentSigner) Sign( + context *Context, + jsonLdDoc []byte, + opts ...processor.Opts, +) ([]byte, error) { var jsonLdObject map[string]interface{} err := json.Unmarshal(jsonLdDoc, &jsonLdObject) @@ -87,7 +91,7 @@ func (signer *DocumentSigner) Sign(context *Context, jsonLdDoc []byte, opts ...j // signObject is a helper method that operates on JSON LD objects. func (signer *DocumentSigner) signObject(context *Context, jsonLdObject map[string]interface{}, - opts []jsonld.ProcessorOpts) error { + opts []processor.Opts) error { if err := isValidContext(context); err != nil { return err } @@ -126,7 +130,7 @@ func (signer *DocumentSigner) signObject(context *Context, jsonLdObject map[stri p.JWS = proof.CreateDetachedJWTHeader(suite.Alg()) + ".." } - message, err := proof.CreateVerifyData(suite, jsonLdObject, p, append(opts, jsonld.WithValidateRDF())...) + message, err := proof.CreateVerifyData(suite, jsonLdObject, p, append(opts, processor.WithValidateRDF())...) if err != nil { return err } diff --git a/component/models/signature/signer/signer_default.go b/component/models/signature/signer/signer_default.go new file mode 100644 index 000000000..568ade9e2 --- /dev/null +++ b/component/models/signature/signer/signer_default.go @@ -0,0 +1,20 @@ +//go:build !ACAPyInterop +// +build !ACAPyInterop + +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package signer + +import ( + "time" + + afgotime "github.com/hyperledger/aries-framework-go/component/models/util/time" +) + +func wrapTime(t time.Time) *afgotime.TimeWrapper { + return &afgotime.TimeWrapper{Time: t} +} diff --git a/component/models/signature/signer/signer_interop.go b/component/models/signature/signer/signer_interop.go new file mode 100644 index 000000000..4a558e189 --- /dev/null +++ b/component/models/signature/signer/signer_interop.go @@ -0,0 +1,21 @@ +//go:build ACAPyInterop +// +build ACAPyInterop + +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package signer + +import ( + "time" + + afgotime "github.com/hyperledger/aries-framework-go/component/models/util/time" +) + +func wrapTime(t time.Time) *afgotime.TimeWrapper { + tw, _ := afgotime.ParseTimeWrapper(t.Format(time.RFC3339)) + return tw +} diff --git a/pkg/doc/signature/signer/signer_test.go b/component/models/signature/signer/signer_test.go similarity index 71% rename from pkg/doc/signature/signer/signer_test.go rename to component/models/signature/signer/signer_test.go index 0ce3be8a9..8734eb5c5 100644 --- a/pkg/doc/signature/signer/signer_test.go +++ b/component/models/signature/signer/signer_test.go @@ -12,17 +12,17 @@ import ( "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/proof" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite/ed25519signature2018" - "github.com/hyperledger/aries-framework-go/pkg/doc/util/signature" - "github.com/hyperledger/aries-framework-go/pkg/internal/ldtestutil" - kmsapi "github.com/hyperledger/aries-framework-go/pkg/kms" - "github.com/hyperledger/aries-framework-go/pkg/kms/localkms" - mockkms "github.com/hyperledger/aries-framework-go/pkg/mock/kms" - "github.com/hyperledger/aries-framework-go/pkg/mock/storage" - "github.com/hyperledger/aries-framework-go/pkg/secretlock/noop" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/kms/localkms" + mockkms "github.com/hyperledger/aries-framework-go/component/kmscrypto/mock/kms" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/secretlock/noop" + "github.com/hyperledger/aries-framework-go/component/models/ld/proof" + "github.com/hyperledger/aries-framework-go/component/models/ld/testutil" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite/ed25519signature2018" + signature "github.com/hyperledger/aries-framework-go/component/models/signature/util" + "github.com/hyperledger/aries-framework-go/component/storageutil/mock/storage" + kmsapi "github.com/hyperledger/aries-framework-go/spi/kms" ) const signatureType = "Ed25519Signature2018" @@ -37,12 +37,12 @@ func TestDocumentSigner_Sign(t *testing.T) { require.NoError(t, err) s := New(ed25519signature2018.New(suite.WithSigner(signer))) - signedDoc, err := s.Sign(context, []byte(validDoc), ldtestutil.WithDocumentLoader(t)) + signedDoc, err := s.Sign(context, []byte(validDoc), testutil.WithDocumentLoader(t)) require.NoError(t, err) require.NotNil(t, signedDoc) context.SignatureRepresentation = proof.SignatureJWS - signedJWSDoc, err := s.Sign(context, []byte(validDoc), ldtestutil.WithDocumentLoader(t)) + signedJWSDoc, err := s.Sign(context, []byte(validDoc), testutil.WithDocumentLoader(t)) require.NoError(t, err) require.NotNil(t, signedJWSDoc) @@ -75,7 +75,7 @@ func TestDocumentSigner_SignErrors(t *testing.T) { s := New(ed25519signature2018.New(suite.WithSigner(signer))) // test invalid json - signedDoc, err := s.Sign(context, []byte("not json"), ldtestutil.WithDocumentLoader(t)) + signedDoc, err := s.Sign(context, []byte("not json"), testutil.WithDocumentLoader(t)) require.NotNil(t, err) require.Nil(t, signedDoc) require.Contains(t, err.Error(), "failed to unmarshal json ld document") @@ -83,7 +83,7 @@ func TestDocumentSigner_SignErrors(t *testing.T) { // test for signature suite not supported context = getSignatureContext() context.SignatureType = "non-existent" - signedDoc, err = s.Sign(context, []byte(validDoc), ldtestutil.WithDocumentLoader(t)) + signedDoc, err = s.Sign(context, []byte(validDoc), testutil.WithDocumentLoader(t)) require.NotNil(t, err) require.Nil(t, signedDoc) require.Contains(t, err.Error(), "signature type non-existent not supported") @@ -99,7 +99,7 @@ func TestDocumentSigner_SignErrors(t *testing.T) { require.NoError(t, err) context = getSignatureContext() - signedDoc, err = s.Sign(context, invalidDocBytes, ldtestutil.WithDocumentLoader(t)) + signedDoc, err = s.Sign(context, invalidDocBytes, testutil.WithDocumentLoader(t)) require.NotNil(t, err) require.Nil(t, signedDoc) require.Contains(t, err.Error(), "invalid context") @@ -108,7 +108,7 @@ func TestDocumentSigner_SignErrors(t *testing.T) { context = getSignatureContext() s = New(ed25519signature2018.New( suite.WithSigner(signature.GetEd25519Signer([]byte("invalid"), nil)))) - signedDoc, err = s.Sign(context, []byte(validDoc), ldtestutil.WithDocumentLoader(t)) + signedDoc, err = s.Sign(context, []byte(validDoc), testutil.WithDocumentLoader(t)) require.NotNil(t, err) require.Nil(t, signedDoc) require.Contains(t, err.Error(), "bad private key length") @@ -119,7 +119,7 @@ func TestDocumentSigner_isValidContext(t *testing.T) { context := getSignatureContext() context.SignatureType = "" - signedDoc, err := s.Sign(context, []byte(validDoc), ldtestutil.WithDocumentLoader(t)) + signedDoc, err := s.Sign(context, []byte(validDoc), testutil.WithDocumentLoader(t)) require.NotNil(t, err) require.Nil(t, signedDoc) require.Contains(t, err.Error(), "signature type is missing") diff --git a/pkg/doc/signature/signer/testdata/valid_doc.jsonld b/component/models/signature/signer/testdata/valid_doc.jsonld similarity index 100% rename from pkg/doc/signature/signer/testdata/valid_doc.jsonld rename to component/models/signature/signer/testdata/valid_doc.jsonld diff --git a/pkg/doc/signature/suite/bbsblssignature2020/public_key_verifier.go b/component/models/signature/suite/bbsblssignature2020/public_key_verifier.go similarity index 85% rename from pkg/doc/signature/suite/bbsblssignature2020/public_key_verifier.go rename to component/models/signature/suite/bbsblssignature2020/public_key_verifier.go index 74de49047..e81c0fc18 100644 --- a/pkg/doc/signature/suite/bbsblssignature2020/public_key_verifier.go +++ b/component/models/signature/suite/bbsblssignature2020/public_key_verifier.go @@ -6,7 +6,7 @@ SPDX-License-Identifier: Apache-2.0 package bbsblssignature2020 -import "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" +import "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" const g2PubKeyType = "Bls12381G2Key2020" diff --git a/pkg/doc/signature/suite/bbsblssignature2020/public_key_verifier_test.go b/component/models/signature/suite/bbsblssignature2020/public_key_verifier_test.go similarity index 89% rename from pkg/doc/signature/suite/bbsblssignature2020/public_key_verifier_test.go rename to component/models/signature/suite/bbsblssignature2020/public_key_verifier_test.go index e1d3b70d4..37c9d98da 100644 --- a/pkg/doc/signature/suite/bbsblssignature2020/public_key_verifier_test.go +++ b/component/models/signature/suite/bbsblssignature2020/public_key_verifier_test.go @@ -12,8 +12,8 @@ import ( "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" - sigverifier "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" + sigverifier "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" ) //nolint:lll diff --git a/pkg/doc/signature/suite/bbsblssignature2020/suite.go b/component/models/signature/suite/bbsblssignature2020/suite.go similarity index 85% rename from pkg/doc/signature/suite/bbsblssignature2020/suite.go rename to component/models/signature/suite/bbsblssignature2020/suite.go index 477dc5fdc..fb03ffadf 100644 --- a/pkg/doc/signature/suite/bbsblssignature2020/suite.go +++ b/component/models/signature/suite/bbsblssignature2020/suite.go @@ -15,14 +15,14 @@ package bbsblssignature2020 // It uses BLS12-381 pairing-friendly curve (https://tools.ietf.org/html/draft-irtf-cfrg-pairing-friendly-curves-03). import ( - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite" + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" ) // Suite implements BbsBlsSignature2020 signature suite. type Suite struct { suite.SignatureSuite - jsonldProcessor *jsonld.Processor + jsonldProcessor *processor.Processor } const ( @@ -33,7 +33,7 @@ const ( // New an instance of Linked Data Signatures for JWS suite. func New(opts ...suite.Opt) *Suite { - s := &Suite{jsonldProcessor: jsonld.NewProcessor(rdfDataSetAlg)} + s := &Suite{jsonldProcessor: processor.NewProcessor(rdfDataSetAlg)} suite.InitSuiteOptions(&s.SignatureSuite, opts...) @@ -42,7 +42,7 @@ func New(opts ...suite.Opt) *Suite { // GetCanonicalDocument will return normalized/canonical version of the document. // BbsBlsSignature2020 signature suite uses RDF Dataset Normalization as canonicalization algorithm. -func (s *Suite) GetCanonicalDocument(doc map[string]interface{}, opts ...jsonld.ProcessorOpts) ([]byte, error) { +func (s *Suite) GetCanonicalDocument(doc map[string]interface{}, opts ...processor.Opts) ([]byte, error) { return s.jsonldProcessor.GetCanonicalDocument(doc, opts...) } diff --git a/pkg/doc/signature/suite/bbsblssignature2020/suite_test.go b/component/models/signature/suite/bbsblssignature2020/suite_test.go similarity index 85% rename from pkg/doc/signature/suite/bbsblssignature2020/suite_test.go rename to component/models/signature/suite/bbsblssignature2020/suite_test.go index 8b35d5cb0..2e422484f 100644 --- a/pkg/doc/signature/suite/bbsblssignature2020/suite_test.go +++ b/component/models/signature/suite/bbsblssignature2020/suite_test.go @@ -13,9 +13,9 @@ import ( "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" - "github.com/hyperledger/aries-framework-go/pkg/internal/ldtestutil" + "github.com/hyperledger/aries-framework-go/component/models/ld/testutil" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" ) //nolint:gochecknoglobals @@ -46,7 +46,7 @@ func TestSuite(t *testing.T) { }, blsSuite) require.NoError(t, err) - err = v.Verify([]byte(vcDoc), ldtestutil.WithDocumentLoader(t)) + err = v.Verify([]byte(vcDoc), testutil.WithDocumentLoader(t)) require.NoError(t, err) require.Equal(t, expectedDoc, blsVerifier.doc) diff --git a/pkg/doc/signature/suite/bbsblssignature2020/testdata/expected_doc.jsonld b/component/models/signature/suite/bbsblssignature2020/testdata/expected_doc.jsonld similarity index 100% rename from pkg/doc/signature/suite/bbsblssignature2020/testdata/expected_doc.jsonld rename to component/models/signature/suite/bbsblssignature2020/testdata/expected_doc.jsonld diff --git a/pkg/doc/signature/suite/bbsblssignature2020/testdata/vc_doc.jsonld b/component/models/signature/suite/bbsblssignature2020/testdata/vc_doc.jsonld similarity index 100% rename from pkg/doc/signature/suite/bbsblssignature2020/testdata/vc_doc.jsonld rename to component/models/signature/suite/bbsblssignature2020/testdata/vc_doc.jsonld diff --git a/pkg/doc/signature/suite/bbsblssignatureproof2020/public_key_verifier.go b/component/models/signature/suite/bbsblssignatureproof2020/public_key_verifier.go similarity index 86% rename from pkg/doc/signature/suite/bbsblssignatureproof2020/public_key_verifier.go rename to component/models/signature/suite/bbsblssignatureproof2020/public_key_verifier.go index 7820ca6ed..9c942bea6 100644 --- a/pkg/doc/signature/suite/bbsblssignatureproof2020/public_key_verifier.go +++ b/component/models/signature/suite/bbsblssignatureproof2020/public_key_verifier.go @@ -6,7 +6,7 @@ SPDX-License-Identifier: Apache-2.0 package bbsblssignatureproof2020 -import "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" +import "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" const g2PubKeyType = "Bls12381G2Key2020" diff --git a/pkg/doc/signature/suite/bbsblssignatureproof2020/public_key_verifier_test.go b/component/models/signature/suite/bbsblssignatureproof2020/public_key_verifier_test.go similarity index 88% rename from pkg/doc/signature/suite/bbsblssignatureproof2020/public_key_verifier_test.go rename to component/models/signature/suite/bbsblssignatureproof2020/public_key_verifier_test.go index 4ed91ce56..56bd47839 100644 --- a/pkg/doc/signature/suite/bbsblssignatureproof2020/public_key_verifier_test.go +++ b/component/models/signature/suite/bbsblssignatureproof2020/public_key_verifier_test.go @@ -12,9 +12,9 @@ import ( "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite/bbsblssignatureproof2020" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite/bbsblssignatureproof2020" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" ) //nolint:lll diff --git a/pkg/doc/signature/suite/bbsblssignatureproof2020/signer.go b/component/models/signature/suite/bbsblssignatureproof2020/signer.go similarity index 86% rename from pkg/doc/signature/suite/bbsblssignatureproof2020/signer.go rename to component/models/signature/suite/bbsblssignatureproof2020/signer.go index 3c736c1cb..061a60d86 100644 --- a/pkg/doc/signature/suite/bbsblssignatureproof2020/signer.go +++ b/component/models/signature/suite/bbsblssignatureproof2020/signer.go @@ -12,10 +12,10 @@ import ( "fmt" "strings" - "github.com/hyperledger/aries-framework-go/pkg/crypto/primitive/bbs12381g2pub" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/proof" - sigverifier "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/primitive/bbs12381g2pub" + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" + "github.com/hyperledger/aries-framework-go/component/models/ld/proof" + sigverifier "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" ) const ( @@ -33,7 +33,7 @@ type keyResolver interface { // SelectiveDisclosure creates selective disclosure from the input doc which must have a BBS+ proof // (with BbsBlsSignature2020 type). func (s *Suite) SelectiveDisclosure(doc map[string]interface{}, revealDoc map[string]interface{}, - nonce []byte, resolver keyResolver, opts ...jsonld.ProcessorOpts) (map[string]interface{}, error) { + nonce []byte, resolver keyResolver, opts ...processor.Opts) (map[string]interface{}, error) { docWithoutProof, rawProofs, err := prepareDocAndProof(doc, opts...) if err != nil { return nil, fmt.Errorf("preparing doc failed: %w", err) @@ -76,7 +76,7 @@ func (s *Suite) SelectiveDisclosure(doc map[string]interface{}, revealDoc map[st } func prepareDocAndProof(doc map[string]interface{}, - opts ...jsonld.ProcessorOpts) (map[string]interface{}, interface{}, error) { + opts ...processor.Opts) (map[string]interface{}, interface{}, error) { docCompacted, err := getCompactedWithSecuritySchema(doc, opts...) if err != nil { return nil, nil, fmt.Errorf("compact doc with security schema: %w", err) @@ -169,7 +169,7 @@ type verificationData struct { } func buildVerificationData(blsProof map[string]interface{}, docVerData *docVerificationData, - opts ...jsonld.ProcessorOpts) (*verificationData, error) { + opts ...processor.Opts) (*verificationData, error) { proofStatements, err := createVerifyProofData(blsProof, opts...) if err != nil { return nil, fmt.Errorf("create verify proof data: %w", err) @@ -196,15 +196,15 @@ func buildVerificationData(blsProof map[string]interface{}, docVerData *docVerif } func buildDocVerificationData(docCompacted, revealDoc map[string]interface{}, - opts ...jsonld.ProcessorOpts) (*docVerificationData, error) { + opts ...processor.Opts) (*docVerificationData, error) { documentStatements, transformedStatements, err := createVerifyDocumentData(docCompacted, opts...) if err != nil { return nil, fmt.Errorf("create verify document data: %w", err) } - optionsWithBlankFrames := append(opts, jsonld.WithFrameBlankNodes()) + optionsWithBlankFrames := append(opts, processor.WithFrameBlankNodes()) - revealDocumentResult, err := jsonld.Default().Frame(docCompacted, revealDoc, optionsWithBlankFrames...) + revealDocumentResult, err := processor.Default().Frame(docCompacted, revealDoc, optionsWithBlankFrames...) if err != nil { return nil, fmt.Errorf("frame doc with reveal doc: %w", err) } @@ -235,12 +235,12 @@ func buildDocVerificationData(docCompacted, revealDoc map[string]interface{}, } func getCompactedWithSecuritySchema(docMap map[string]interface{}, - opts ...jsonld.ProcessorOpts) (map[string]interface{}, error) { + opts ...processor.Opts) (map[string]interface{}, error) { contextMap := map[string]interface{}{ "@context": securityContext, } - return jsonld.Default().Compact(docMap, contextMap, opts...) + return processor.Default().Compact(docMap, contextMap, opts...) } func getProofs(appProofs interface{}) ([]map[string]interface{}, error) { @@ -266,8 +266,8 @@ func getProofs(appProofs interface{}) ([]map[string]interface{}, error) { } func createVerifyDocumentData(doc map[string]interface{}, - opts ...jsonld.ProcessorOpts) ([]string, []string, error) { - docBytes, err := jsonld.Default().GetCanonicalDocument(doc, opts...) + opts ...processor.Opts) ([]string, []string, error) { + docBytes, err := processor.Default().GetCanonicalDocument(doc, opts...) if err != nil { return nil, nil, fmt.Errorf("canonicalizing document failed: %w", err) } @@ -276,14 +276,14 @@ func createVerifyDocumentData(doc map[string]interface{}, transformedStatements := make([]string, len(documentStatements)) for i, row := range documentStatements { - transformedStatements[i] = jsonld.TransformBlankNode(row) + transformedStatements[i] = processor.TransformBlankNode(row) } return documentStatements, transformedStatements, nil } -func createVerifyRevealData(doc map[string]interface{}, opts ...jsonld.ProcessorOpts) ([]string, error) { - docBytes, err := jsonld.Default().GetCanonicalDocument(doc, opts...) +func createVerifyRevealData(doc map[string]interface{}, opts ...processor.Opts) ([]string, error) { + docBytes, err := processor.Default().GetCanonicalDocument(doc, opts...) if err != nil { return nil, err } @@ -305,7 +305,7 @@ func splitMessageIntoLines(msg string) []string { return msgs } -func createVerifyProofData(proofMap map[string]interface{}, opts ...jsonld.ProcessorOpts) ([]string, error) { +func createVerifyProofData(proofMap map[string]interface{}, opts ...processor.Opts) ([]string, error) { proofMapCopy := make(map[string]interface{}, len(proofMap)-1) for k, v := range proofMap { @@ -314,7 +314,7 @@ func createVerifyProofData(proofMap map[string]interface{}, opts ...jsonld.Proce } } - proofBytes, err := jsonld.Default().GetCanonicalDocument(proofMapCopy, opts...) + proofBytes, err := processor.Default().GetCanonicalDocument(proofMapCopy, opts...) if err != nil { return nil, err } diff --git a/pkg/doc/signature/suite/bbsblssignatureproof2020/suite.go b/component/models/signature/suite/bbsblssignatureproof2020/suite.go similarity index 87% rename from pkg/doc/signature/suite/bbsblssignatureproof2020/suite.go rename to component/models/signature/suite/bbsblssignatureproof2020/suite.go index 01d0d582a..56c8462af 100644 --- a/pkg/doc/signature/suite/bbsblssignatureproof2020/suite.go +++ b/component/models/signature/suite/bbsblssignatureproof2020/suite.go @@ -17,14 +17,14 @@ package bbsblssignatureproof2020 import ( "strings" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite" + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" ) // Suite implements BbsBlsSignatureProof2020 signature suite. type Suite struct { suite.SignatureSuite - jsonldProcessor *jsonld.Processor + jsonldProcessor *processor.Processor } const ( @@ -35,7 +35,7 @@ const ( // New an instance of Linked Data Signatures for the suite. func New(opts ...suite.Opt) *Suite { - s := &Suite{jsonldProcessor: jsonld.NewProcessor(rdfDataSetAlg)} + s := &Suite{jsonldProcessor: processor.NewProcessor(rdfDataSetAlg)} suite.InitSuiteOptions(&s.SignatureSuite, opts...) @@ -44,7 +44,7 @@ func New(opts ...suite.Opt) *Suite { // GetCanonicalDocument will return normalized/canonical version of the document. // BbsBlsSignatureProof2020 signature suite uses RDF Dataset Normalization as canonicalization algorithm. -func (s *Suite) GetCanonicalDocument(doc map[string]interface{}, opts ...jsonld.ProcessorOpts) ([]byte, error) { +func (s *Suite) GetCanonicalDocument(doc map[string]interface{}, opts ...processor.Opts) ([]byte, error) { if v, ok := doc["type"]; ok { docType, ok := v.(string) diff --git a/pkg/doc/signature/suite/bbsblssignatureproof2020/suite_test.go b/component/models/signature/suite/bbsblssignatureproof2020/suite_test.go similarity index 83% rename from pkg/doc/signature/suite/bbsblssignatureproof2020/suite_test.go rename to component/models/signature/suite/bbsblssignatureproof2020/suite_test.go index 955e653f9..e482fc176 100644 --- a/pkg/doc/signature/suite/bbsblssignatureproof2020/suite_test.go +++ b/component/models/signature/suite/bbsblssignatureproof2020/suite_test.go @@ -13,10 +13,10 @@ import ( "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite/bbsblssignatureproof2020" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" - "github.com/hyperledger/aries-framework-go/pkg/internal/ldtestutil" + "github.com/hyperledger/aries-framework-go/component/models/ld/testutil" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite/bbsblssignatureproof2020" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" ) //nolint:gochecknoglobals @@ -47,7 +47,7 @@ func TestSuite(t *testing.T) { }, blsSuite) require.NoError(t, err) - err = v.Verify([]byte(vcDoc), ldtestutil.WithDocumentLoader(t)) + err = v.Verify([]byte(vcDoc), testutil.WithDocumentLoader(t)) require.NoError(t, err) require.Equal(t, expectedDoc, blsVerifier.doc) diff --git a/component/models/signature/suite/bbsblssignatureproof2020/testdata/case16_reveal_doc.jsonld b/component/models/signature/suite/bbsblssignatureproof2020/testdata/case16_reveal_doc.jsonld new file mode 100644 index 000000000..474900311 --- /dev/null +++ b/component/models/signature/suite/bbsblssignatureproof2020/testdata/case16_reveal_doc.jsonld @@ -0,0 +1,15 @@ +{ + "@context": [ + "https://www.w3.org/2018/credentials/v1", + "https://w3id.org/citizenship/v1", + "https://w3id.org/security/bbs/v1" + ], + "type": ["VerifiableCredential", "PermanentResidentCard"], + "credentialSubject": { + "@explicit": true, + "type": ["PermanentResident", "Person"], + "givenName": {}, + "familyName": {}, + "gender": {} + } +} \ No newline at end of file diff --git a/component/models/signature/suite/bbsblssignatureproof2020/testdata/case16_vc.jsonld b/component/models/signature/suite/bbsblssignatureproof2020/testdata/case16_vc.jsonld new file mode 100644 index 000000000..c03b6f1d6 --- /dev/null +++ b/component/models/signature/suite/bbsblssignatureproof2020/testdata/case16_vc.jsonld @@ -0,0 +1,41 @@ +{ + "@context": [ + "https://www.w3.org/2018/credentials/v1", + "https://w3id.org/security/bbs/v1", + "https://w3id.org/citizenship/v1" + ], + "id": "https://issuer.oidp.uscis.gov/credentials/83627465", + "type": [ + "VerifiableCredential", + "PermanentResidentCard" + ], + "name": "Permanent Resident Card", + "description": "Government of Example Permanent Resident Card.", + "issuanceDate": "2019-12-03T12:19:52Z", + "expirationDate": "2029-12-03T12:19:52Z", + "credentialSubject": { + "id": "did:example:b34ca6cd37bbf23", + "type": [ + "PermanentResident", + "Person" + ], + "givenName": "JOHN", + "familyName": "SMITH", + "gender": "Male", + "image": "data:image/png;base64,iVBORw0KGgo...kJggg==", + "residentSince": "2015-01-01", + "lprCategory": "C09", + "lprNumber": "999-999-999", + "commuterClassification": "C1", + "birthCountry": "Bahamas", + "birthDate": "1958-07-17" + }, + "issuer": "did:key:zUC724vuGvHpnCGFG1qqpXb81SiBLu3KLSqVzenwEZNPoY35i2Bscb8DLaVwHvRFs6F2NkNNXRcPWvqnPDUd9ukdjLkjZd3u9zzL4wDZDUpkPAatLDGLEYVo8kkAzuAKJQMr7N2", + "proof": { + "type": "BbsBlsSignature2020", + "created": "2021-02-23T19:31:12Z", + "proofPurpose": "assertionMethod", + "proofValue": "qPrB+1BLsVSeOo1ci8dMF+iR6aa5Q6iwV/VzXo2dw94ctgnQGxaUgwb8Hd68IiYTVabQXR+ZPuwJA//GOv1OwXRHkHqXg9xPsl8HcaXaoWERanxYClgHCfy4j76Vudr14U5AhT3v8k8f0oZD+zBIUQ==", + "verificationMethod": "did:key:zUC724vuGvHpnCGFG1qqpXb81SiBLu3KLSqVzenwEZNPoY35i2Bscb8DLaVwHvRFs6F2NkNNXRcPWvqnPDUd9ukdjLkjZd3u9zzL4wDZDUpkPAatLDGLEYVo8kkAzuAKJQMr7N2#zUC724vuGvHpnCGFG1qqpXb81SiBLu3KLSqVzenwEZNPoY35i2Bscb8DLaVwHvRFs6F2NkNNXRcPWvqnPDUd9ukdjLkjZd3u9zzL4wDZDUpkPAatLDGLEYVo8kkAzuAKJQMr7N2" + } +} \ No newline at end of file diff --git a/component/models/signature/suite/bbsblssignatureproof2020/testdata/case18_reveal_doc.jsonld b/component/models/signature/suite/bbsblssignatureproof2020/testdata/case18_reveal_doc.jsonld new file mode 100644 index 000000000..2ce88cf28 --- /dev/null +++ b/component/models/signature/suite/bbsblssignatureproof2020/testdata/case18_reveal_doc.jsonld @@ -0,0 +1,15 @@ +{ + "@context": [ + "https://www.w3.org/2018/credentials/v1", + "https://www.w3.org/2018/credentials/examples/v1", + "https://w3id.org/security/bbs/v1" + ], + "type": ["UniversityDegreeCredential", "VerifiableCredential"], + "@explicit": true, + "issuer": {}, + "issuanceDate": {}, + "credentialSubject": { + "@explicit": true, + "degree": {} + } +} \ No newline at end of file diff --git a/component/models/signature/suite/bbsblssignatureproof2020/testdata/case18_vc.jsonld b/component/models/signature/suite/bbsblssignatureproof2020/testdata/case18_vc.jsonld new file mode 100644 index 000000000..2a8a65e62 --- /dev/null +++ b/component/models/signature/suite/bbsblssignatureproof2020/testdata/case18_vc.jsonld @@ -0,0 +1,28 @@ +{ + "@context": [ + "https://www.w3.org/2018/credentials/v1", + "https://www.w3.org/2018/credentials/examples/v1", + "https://w3id.org/security/bbs/v1" + ], + "id": "http://example.gov/credentials/3732", + "type": [ + "VerifiableCredential", + "UniversityDegreeCredential" + ], + "issuanceDate": "2020-03-10T04:24:12.164Z", + "credentialSubject": { + "id": "did:key:z5TcESXuYUE9aZWYwSdrUEGK1HNQFHyTt4aVpaCTVZcDXQmUheFwfNZmRksaAbBneNm5KyE52SdJeRCN1g6PJmF31GsHWwFiqUDujvasK3wTiDr3vvkYwEJHt7H5RGEKYEp1ErtQtcEBgsgY2DA9JZkHj1J9HZ8MRDTguAhoFtR4aTBQhgnkP4SwVbxDYMEZoF2TMYn3s#zUC7LTa4hWtaE9YKyDsMVGiRNqPMN3s4rjBdB3MFi6PcVWReNfR72y3oGW2NhNcaKNVhMobh7aHp8oZB3qdJCs7RebM2xsodrSm8MmePbN25NTGcpjkJMwKbcWfYDX7eHCJjPGM", + "degree": { + "type": "BachelorDegree", + "name": "Bachelor of Science and Arts" + } + }, + "issuer": "did:key:zUC724vuGvHpnCGFG1qqpXb81SiBLu3KLSqVzenwEZNPoY35i2Bscb8DLaVwHvRFs6F2NkNNXRcPWvqnPDUd9ukdjLkjZd3u9zzL4wDZDUpkPAatLDGLEYVo8kkAzuAKJQMr7N2", + "proof": { + "type": "BbsBlsSignature2020", + "created": "2021-02-23T19:36:07Z", + "proofPurpose": "assertionMethod", + "proofValue": "qSjCNJzoDV3hv3gBPoUNN9m5lj8saDBBxC0iDHuFTXXz4PbbUhecmn/L3rPoGuySNatqC4I8VE22xQy0RAowIxoZCC+B2mZQIAb+/JGlXeAlWgEQc71WipfvsfqSn+KmR/rN1FREOy3rtSltyQ92rA==", + "verificationMethod": "did:key:zUC724vuGvHpnCGFG1qqpXb81SiBLu3KLSqVzenwEZNPoY35i2Bscb8DLaVwHvRFs6F2NkNNXRcPWvqnPDUd9ukdjLkjZd3u9zzL4wDZDUpkPAatLDGLEYVo8kkAzuAKJQMr7N2#zUC724vuGvHpnCGFG1qqpXb81SiBLu3KLSqVzenwEZNPoY35i2Bscb8DLaVwHvRFs6F2NkNNXRcPWvqnPDUd9ukdjLkjZd3u9zzL4wDZDUpkPAatLDGLEYVo8kkAzuAKJQMr7N2" + } +} \ No newline at end of file diff --git a/component/models/signature/suite/bbsblssignatureproof2020/testdata/doc_with_many_proofs.jsonld b/component/models/signature/suite/bbsblssignatureproof2020/testdata/doc_with_many_proofs.jsonld new file mode 100644 index 000000000..5e0f4ce12 --- /dev/null +++ b/component/models/signature/suite/bbsblssignatureproof2020/testdata/doc_with_many_proofs.jsonld @@ -0,0 +1,58 @@ +{ + "@context": [ + "https://www.w3.org/2018/credentials/v1", + "https://w3id.org/citizenship/v1", + "https://w3id.org/security/bbs/v1" + ], + "id": "https://issuer.oidp.uscis.gov/credentials/83627465", + "type": [ + "VerifiableCredential", + "PermanentResidentCard" + ], + "issuer": "did:example:489398593", + "identifier": "83627465", + "name": "Permanent Resident Card", + "description": "Government of Example Permanent Resident Card.", + "issuanceDate": "2019-12-03T12:19:52Z", + "expirationDate": "2029-12-03T12:19:52Z", + "credentialSubject": { + "id": "did:example:b34ca6cd37bbf23", + "type": [ + "PermanentResident", + "Person" + ], + "givenName": "JOHN", + "familyName": "SMITH", + "gender": "Male", + "image": "data:image/png;base64,iVBORw0KGgokJggg==", + "residentSince": "2015-01-01", + "lprCategory": "C09", + "lprNumber": "999-999-999", + "commuterClassification": "C1", + "birthCountry": "Bahamas", + "birthDate": "1958-07-17" + }, + "proof": [ + { + "type": "BbsBlsSignature2020", + "created": "2020-12-06T19:23:10Z", + "proofPurpose": "assertionMethod", + "proofValue": "mjj3Xd3+KxmbQo85PFDjQJ7dAZlhj8A8W1Um8Vk7Xoiv6+jWRx5d8s0rgPk5dAXy6HwaJ4fQOde/MBb7E4QaGMlfK6y5eEKDUYzoGG0DScWIvaGcSZug6DwvWVXi+214P5MtlKnNwO6gJdemEgj8T/A==", + "verificationMethod": "did:example:489398593#test" + }, + { + "created": "2010-01-01T19:23:24Z", + "jws": "eyJhbGciOiJFZERTQSIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..lrkhpRH4tWl6KzQKHlcyAwSm8qUTXIMSKmD3QASF_uI5QW8NWLxLebXmnQpIM8H7umhLA6dINSYVowcaPdpwBw", + "proofPurpose": "assertionMethod", + "type": "Ed25519Signature2018", + "verificationMethod": "did:example:123456#key1" + }, + { + "created": "2021-01-11T16:04:13.154596+02:00", + "proofPurpose": "assertionMethod", + "proofValue": "hR-MODvfO20merTlcBbBQcwrv_Hpj5hXRJSmkAt_9RaC9mQ5QMkh0LGeyhzwUPjkYKLW7npcfXpxoH8Qb8YMFfp1Bu7h7oICwkBcBi-C1YUncKFmsBvDtjzOCkBs_QrtH_ZW_dsSzt7oloOHqgzfHQ", + "type": "BbsBlsSignature2020", + "verificationMethod": "did:example:123456#key2" + } + ] +} \ No newline at end of file diff --git a/component/models/signature/suite/bbsblssignatureproof2020/testdata/expected_doc.rdf b/component/models/signature/suite/bbsblssignatureproof2020/testdata/expected_doc.rdf new file mode 100644 index 000000000..44cdf61ee --- /dev/null +++ b/component/models/signature/suite/bbsblssignatureproof2020/testdata/expected_doc.rdf @@ -0,0 +1,18 @@ +_:c14n0 "2020-12-06T19:23:10Z"^^ . +_:c14n0 . +_:c14n0 . +_:c14n0 . + "SMITH" . + "Male" . + "JOHN" . + . + . + "Government of Example Permanent Resident Card." . + "83627465" . + "Permanent Resident Card" . + . + . + . + "2029-12-03T12:19:52Z"^^ . + "2019-12-03T12:19:52Z"^^ . + . diff --git a/component/models/signature/suite/bbsblssignatureproof2020/testdata/vc_doc.jsonld b/component/models/signature/suite/bbsblssignatureproof2020/testdata/vc_doc.jsonld new file mode 100644 index 000000000..5a13bfa05 --- /dev/null +++ b/component/models/signature/suite/bbsblssignatureproof2020/testdata/vc_doc.jsonld @@ -0,0 +1,36 @@ +{ + "@context": [ + "https://www.w3.org/2018/credentials/v1", + "https://w3id.org/citizenship/v1", + "https://w3id.org/security/bbs/v1" + ], + "id": "https://issuer.oidp.uscis.gov/credentials/83627465", + "type": [ + "PermanentResidentCard", + "VerifiableCredential" + ], + "description": "Government of Example Permanent Resident Card.", + "identifier": "83627465", + "name": "Permanent Resident Card", + "credentialSubject": { + "id": "did:example:b34ca6cd37bbf23", + "type": [ + "Person", + "PermanentResident" + ], + "familyName": "SMITH", + "gender": "Male", + "givenName": "JOHN" + }, + "expirationDate": "2029-12-03T12:19:52Z", + "issuanceDate": "2019-12-03T12:19:52Z", + "issuer": "did:example:489398593", + "proof": { + "created": "2020-12-06T19:23:10Z", + "nonce": "bm9uY2U=", + "proofPurpose": "assertionMethod", + "proofValue": "ABkB/wbvj3hl666VoVa0OoBPw/vBqSAJzGCSA/jmyXu3ou2awUn4C9pQA+QNNkbqQwqloyPEqcFxpS7zok6xYA1pUOx5igu1eYBorAv9+kIOCPONGcW2rsXvZOO2hdn4GWT9xc2ir675V61HhqFF0ETZLkNzH+N5NZOUaiXG2gegI2EjVk8M0TaBJ1bUxb5ZZ0qhnLM1AAAAdIj56X6YvHWghzNhFyUt8FbMDSpTk3i4lujEP0M0OHGEm+hNUhJj2r0ZA4lDsD/tBAAAAAJPSSQ/NOVm7iXCoX2STQESM2yWKrDRErWI+mfzn5wmAklSgf0VA5BunaiRNYh57MA6CJ94cagGixys6rCZ42N7p8F4Yp4pUPpJE3EvHhc63YWRK6y3/smRM+Y3OgVJAcPmpYOjTB7owrHLxNRC7+E+AAAACRp7vxsK7oY3WdStSIA5RcrvMl0tUW5r5e8o4HpOvD2ANlZcne08y6wbRHYFtA22J7pbTliW1NJyLYUj18gOYfg0S+w20OYscVAShjYIwpjRvvvvHpCmIiU0/WD9fOOBPXAeFQJogHPCHM+oKO6YlUS4qmXl/No7oHCedyh11Ty/Bi2x8dRLDXPFpLt3D7dZUg96mkJ5LbGQ35soqepPreYv3JWKh75r6wJny7kN2nNQ0/2CYpMTTNqewxz0XSMVQ0X2ztsCKX9+npiqVWDNe77pT3BYyT3ZUWeV2geJfGTXcpyn7+rAdD0GddYIleYXXVSr4I4/tzEYWWKC2xKsGBwRXq64T//cOdbzEt5i60aPVs9QIsecysZ2gIjuoeVEMg==", + "type": "BbsBlsSignatureProof2020", + "verificationMethod": "did:example:489398593#test" + } +} \ No newline at end of file diff --git a/pkg/doc/signature/suite/ecdsasecp256k1signature2019/public_key_verifier.go b/component/models/signature/suite/ecdsasecp256k1signature2019/public_key_verifier.go similarity index 85% rename from pkg/doc/signature/suite/ecdsasecp256k1signature2019/public_key_verifier.go rename to component/models/signature/suite/ecdsasecp256k1signature2019/public_key_verifier.go index 49258a4c7..c4d40412e 100644 --- a/pkg/doc/signature/suite/ecdsasecp256k1signature2019/public_key_verifier.go +++ b/component/models/signature/suite/ecdsasecp256k1signature2019/public_key_verifier.go @@ -7,7 +7,7 @@ SPDX-License-Identifier: Apache-2.0 package ecdsasecp256k1signature2019 import ( - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" ) // NewPublicKeyVerifier creates a signature verifier that verifies a ECDSA secp256k1 signature diff --git a/pkg/doc/signature/suite/ecdsasecp256k1signature2019/public_key_verifier_test.go b/component/models/signature/suite/ecdsasecp256k1signature2019/public_key_verifier_test.go similarity index 66% rename from pkg/doc/signature/suite/ecdsasecp256k1signature2019/public_key_verifier_test.go rename to component/models/signature/suite/ecdsasecp256k1signature2019/public_key_verifier_test.go index 8dd2ad728..908546ac7 100644 --- a/pkg/doc/signature/suite/ecdsasecp256k1signature2019/public_key_verifier_test.go +++ b/component/models/signature/suite/ecdsasecp256k1signature2019/public_key_verifier_test.go @@ -12,15 +12,15 @@ import ( gojose "github.com/go-jose/go-jose/v3" "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto" - "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" - "github.com/hyperledger/aries-framework-go/pkg/doc/util/signature" - kmsapi "github.com/hyperledger/aries-framework-go/pkg/kms" - "github.com/hyperledger/aries-framework-go/pkg/kms/localkms" - mockkms "github.com/hyperledger/aries-framework-go/pkg/mock/kms" - "github.com/hyperledger/aries-framework-go/pkg/mock/storage" - "github.com/hyperledger/aries-framework-go/pkg/secretlock/noop" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/kms/localkms" + mockkms "github.com/hyperledger/aries-framework-go/component/kmscrypto/mock/kms" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/secretlock/noop" + signature "github.com/hyperledger/aries-framework-go/component/models/signature/util" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" + "github.com/hyperledger/aries-framework-go/component/storageutil/mock/storage" + kmsapi "github.com/hyperledger/aries-framework-go/spi/kms" ) func TestPublicKeyVerifier_Verify(t *testing.T) { diff --git a/pkg/doc/signature/suite/ecdsasecp256k1signature2019/suite.go b/component/models/signature/suite/ecdsasecp256k1signature2019/suite.go similarity index 84% rename from pkg/doc/signature/suite/ecdsasecp256k1signature2019/suite.go rename to component/models/signature/suite/ecdsasecp256k1signature2019/suite.go index a460d7d86..e3c899c2f 100644 --- a/pkg/doc/signature/suite/ecdsasecp256k1signature2019/suite.go +++ b/component/models/signature/suite/ecdsasecp256k1signature2019/suite.go @@ -14,14 +14,14 @@ package ecdsasecp256k1signature2019 import ( "crypto/sha256" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite" + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" ) // Suite implements EcdsaSecp256k1Signature2019 signature suite. type Suite struct { suite.SignatureSuite - jsonldProcessor *jsonld.Processor + jsonldProcessor *processor.Processor } const ( @@ -32,7 +32,7 @@ const ( // New an instance of Linked Data Signatures for JWS suite. func New(opts ...suite.Opt) *Suite { - s := &Suite{jsonldProcessor: jsonld.NewProcessor(rdfDataSetAlg)} + s := &Suite{jsonldProcessor: processor.NewProcessor(rdfDataSetAlg)} suite.InitSuiteOptions(&s.SignatureSuite, opts...) @@ -41,7 +41,7 @@ func New(opts ...suite.Opt) *Suite { // GetCanonicalDocument will return normalized/canonical version of the document. // EcdsaSecp256k1Signature2019 signature suite uses RDF Dataset Normalization as canonicalization algorithm. -func (s *Suite) GetCanonicalDocument(doc map[string]interface{}, opts ...jsonld.ProcessorOpts) ([]byte, error) { +func (s *Suite) GetCanonicalDocument(doc map[string]interface{}, opts ...processor.Opts) ([]byte, error) { return s.jsonldProcessor.GetCanonicalDocument(doc, opts...) } diff --git a/pkg/doc/signature/suite/ecdsasecp256k1signature2019/suite_test.go b/component/models/signature/suite/ecdsasecp256k1signature2019/suite_test.go similarity index 100% rename from pkg/doc/signature/suite/ecdsasecp256k1signature2019/suite_test.go rename to component/models/signature/suite/ecdsasecp256k1signature2019/suite_test.go diff --git a/pkg/doc/signature/suite/ed25519signature2018/public_key_verifier.go b/component/models/signature/suite/ed25519signature2018/public_key_verifier.go similarity index 83% rename from pkg/doc/signature/suite/ed25519signature2018/public_key_verifier.go rename to component/models/signature/suite/ed25519signature2018/public_key_verifier.go index 39a8c0866..da1345547 100644 --- a/pkg/doc/signature/suite/ed25519signature2018/public_key_verifier.go +++ b/component/models/signature/suite/ed25519signature2018/public_key_verifier.go @@ -7,7 +7,7 @@ SPDX-License-Identifier: Apache-2.0 package ed25519signature2018 import ( - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" ) // NewPublicKeyVerifier creates a signature verifier that verifies a Ed25519 signature diff --git a/pkg/doc/signature/suite/ed25519signature2018/public_key_verifier_test.go b/component/models/signature/suite/ed25519signature2018/public_key_verifier_test.go similarity index 62% rename from pkg/doc/signature/suite/ed25519signature2018/public_key_verifier_test.go rename to component/models/signature/suite/ed25519signature2018/public_key_verifier_test.go index ba37a4c6c..f952e8e19 100644 --- a/pkg/doc/signature/suite/ed25519signature2018/public_key_verifier_test.go +++ b/component/models/signature/suite/ed25519signature2018/public_key_verifier_test.go @@ -11,14 +11,14 @@ import ( "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" - "github.com/hyperledger/aries-framework-go/pkg/doc/util/signature" - kmsapi "github.com/hyperledger/aries-framework-go/pkg/kms" - "github.com/hyperledger/aries-framework-go/pkg/kms/localkms" - mockkms "github.com/hyperledger/aries-framework-go/pkg/mock/kms" - "github.com/hyperledger/aries-framework-go/pkg/mock/storage" - "github.com/hyperledger/aries-framework-go/pkg/secretlock/noop" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/kms/localkms" + mockkms "github.com/hyperledger/aries-framework-go/component/kmscrypto/mock/kms" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/secretlock/noop" + signature "github.com/hyperledger/aries-framework-go/component/models/signature/util" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" + "github.com/hyperledger/aries-framework-go/component/storageutil/mock/storage" + kmsapi "github.com/hyperledger/aries-framework-go/spi/kms" ) func TestPublicKeyVerifier_Verify(t *testing.T) { diff --git a/pkg/doc/signature/suite/ed25519signature2018/suite.go b/component/models/signature/suite/ed25519signature2018/suite.go similarity index 83% rename from pkg/doc/signature/suite/ed25519signature2018/suite.go rename to component/models/signature/suite/ed25519signature2018/suite.go index aff594e0e..c07f85825 100644 --- a/pkg/doc/signature/suite/ed25519signature2018/suite.go +++ b/component/models/signature/suite/ed25519signature2018/suite.go @@ -14,14 +14,14 @@ package ed25519signature2018 import ( "crypto/sha256" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite" + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" ) // Suite implements ed25519 signature suite. type Suite struct { suite.SignatureSuite - jsonldProcessor *jsonld.Processor + jsonldProcessor *processor.Processor } const ( @@ -32,7 +32,7 @@ const ( // New an instance of ed25519 signature suite. func New(opts ...suite.Opt) *Suite { - s := &Suite{jsonldProcessor: jsonld.NewProcessor(rdfDataSetAlg)} + s := &Suite{jsonldProcessor: processor.NewProcessor(rdfDataSetAlg)} suite.InitSuiteOptions(&s.SignatureSuite, opts...) @@ -41,7 +41,7 @@ func New(opts ...suite.Opt) *Suite { // GetCanonicalDocument will return normalized/canonical version of the document // Ed25519Signature2018 signature SignatureSuite uses RDF Dataset Normalization as canonicalization algorithm. -func (s *Suite) GetCanonicalDocument(doc map[string]interface{}, opts ...jsonld.ProcessorOpts) ([]byte, error) { +func (s *Suite) GetCanonicalDocument(doc map[string]interface{}, opts ...processor.Opts) ([]byte, error) { return s.jsonldProcessor.GetCanonicalDocument(doc, opts...) } diff --git a/pkg/doc/signature/suite/ed25519signature2018/suite_crypto_test.go b/component/models/signature/suite/ed25519signature2018/suite_crypto_test.go similarity index 79% rename from pkg/doc/signature/suite/ed25519signature2018/suite_crypto_test.go rename to component/models/signature/suite/ed25519signature2018/suite_crypto_test.go index c363658f5..39480a505 100644 --- a/pkg/doc/signature/suite/ed25519signature2018/suite_crypto_test.go +++ b/component/models/signature/suite/ed25519signature2018/suite_crypto_test.go @@ -13,14 +13,14 @@ import ( "github.com/google/tink/go/keyset" "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite" - sigverifier "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" - kmsapi "github.com/hyperledger/aries-framework-go/pkg/kms" - "github.com/hyperledger/aries-framework-go/pkg/kms/localkms" - mockkms "github.com/hyperledger/aries-framework-go/pkg/mock/kms" - "github.com/hyperledger/aries-framework-go/pkg/mock/storage" - "github.com/hyperledger/aries-framework-go/pkg/secretlock/noop" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/kms/localkms" + mockkms "github.com/hyperledger/aries-framework-go/component/kmscrypto/mock/kms" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/secretlock/noop" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" + sigverifier "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" + "github.com/hyperledger/aries-framework-go/component/storageutil/mock/storage" + kmsapi "github.com/hyperledger/aries-framework-go/spi/kms" ) func TestNewCryptoSignerAndVerifier(t *testing.T) { diff --git a/pkg/doc/signature/suite/ed25519signature2018/suite_test.go b/component/models/signature/suite/ed25519signature2018/suite_test.go similarity index 100% rename from pkg/doc/signature/suite/ed25519signature2018/suite_test.go rename to component/models/signature/suite/ed25519signature2018/suite_test.go diff --git a/pkg/doc/signature/suite/ed25519signature2020/public_key_verifier.go b/component/models/signature/suite/ed25519signature2020/public_key_verifier.go similarity index 83% rename from pkg/doc/signature/suite/ed25519signature2020/public_key_verifier.go rename to component/models/signature/suite/ed25519signature2020/public_key_verifier.go index 783689137..45ff56f87 100644 --- a/pkg/doc/signature/suite/ed25519signature2020/public_key_verifier.go +++ b/component/models/signature/suite/ed25519signature2020/public_key_verifier.go @@ -7,7 +7,7 @@ SPDX-License-Identifier: Apache-2.0 package ed25519signature2020 import ( - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" ) // NewPublicKeyVerifier creates a signature verifier that verifies a Ed25519 signature diff --git a/pkg/doc/signature/suite/ed25519signature2020/public_key_verifier_test.go b/component/models/signature/suite/ed25519signature2020/public_key_verifier_test.go similarity index 62% rename from pkg/doc/signature/suite/ed25519signature2020/public_key_verifier_test.go rename to component/models/signature/suite/ed25519signature2020/public_key_verifier_test.go index 19995bd35..2e92e59cf 100644 --- a/pkg/doc/signature/suite/ed25519signature2020/public_key_verifier_test.go +++ b/component/models/signature/suite/ed25519signature2020/public_key_verifier_test.go @@ -11,14 +11,14 @@ import ( "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" - "github.com/hyperledger/aries-framework-go/pkg/doc/util/signature" - kmsapi "github.com/hyperledger/aries-framework-go/pkg/kms" - "github.com/hyperledger/aries-framework-go/pkg/kms/localkms" - mockkms "github.com/hyperledger/aries-framework-go/pkg/mock/kms" - "github.com/hyperledger/aries-framework-go/pkg/mock/storage" - "github.com/hyperledger/aries-framework-go/pkg/secretlock/noop" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/kms/localkms" + mockkms "github.com/hyperledger/aries-framework-go/component/kmscrypto/mock/kms" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/secretlock/noop" + signature "github.com/hyperledger/aries-framework-go/component/models/signature/util" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" + "github.com/hyperledger/aries-framework-go/component/storageutil/mock/storage" + kmsapi "github.com/hyperledger/aries-framework-go/spi/kms" ) func TestPublicKeyVerifier_Verify(t *testing.T) { diff --git a/pkg/doc/signature/suite/ed25519signature2020/suite.go b/component/models/signature/suite/ed25519signature2020/suite.go similarity index 83% rename from pkg/doc/signature/suite/ed25519signature2020/suite.go rename to component/models/signature/suite/ed25519signature2020/suite.go index bb99f3d43..8487650d3 100644 --- a/pkg/doc/signature/suite/ed25519signature2020/suite.go +++ b/component/models/signature/suite/ed25519signature2020/suite.go @@ -14,14 +14,14 @@ package ed25519signature2020 import ( "crypto/sha256" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite" + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" ) // Suite implements ed25519 signature suite. type Suite struct { suite.SignatureSuite - jsonldProcessor *jsonld.Processor + jsonldProcessor *processor.Processor } const ( @@ -32,7 +32,7 @@ const ( // New an instance of ed25519 signature suite. func New(opts ...suite.Opt) *Suite { - s := &Suite{jsonldProcessor: jsonld.NewProcessor(rdfDataSetAlg)} + s := &Suite{jsonldProcessor: processor.NewProcessor(rdfDataSetAlg)} suite.InitSuiteOptions(&s.SignatureSuite, opts...) @@ -41,7 +41,7 @@ func New(opts ...suite.Opt) *Suite { // GetCanonicalDocument will return normalized/canonical version of the document // Ed25519Signature2020 signature SignatureSuite uses RDF Dataset Normalization as canonicalization algorithm. -func (s *Suite) GetCanonicalDocument(doc map[string]interface{}, opts ...jsonld.ProcessorOpts) ([]byte, error) { +func (s *Suite) GetCanonicalDocument(doc map[string]interface{}, opts ...processor.Opts) ([]byte, error) { return s.jsonldProcessor.GetCanonicalDocument(doc, opts...) } diff --git a/pkg/doc/signature/suite/ed25519signature2020/suite_crypto_test.go b/component/models/signature/suite/ed25519signature2020/suite_crypto_test.go similarity index 79% rename from pkg/doc/signature/suite/ed25519signature2020/suite_crypto_test.go rename to component/models/signature/suite/ed25519signature2020/suite_crypto_test.go index 4f13b6183..7dbaf71d7 100644 --- a/pkg/doc/signature/suite/ed25519signature2020/suite_crypto_test.go +++ b/component/models/signature/suite/ed25519signature2020/suite_crypto_test.go @@ -13,14 +13,14 @@ import ( "github.com/google/tink/go/keyset" "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite" - sigverifier "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" - kmsapi "github.com/hyperledger/aries-framework-go/pkg/kms" - "github.com/hyperledger/aries-framework-go/pkg/kms/localkms" - mockkms "github.com/hyperledger/aries-framework-go/pkg/mock/kms" - "github.com/hyperledger/aries-framework-go/pkg/mock/storage" - "github.com/hyperledger/aries-framework-go/pkg/secretlock/noop" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/kms/localkms" + mockkms "github.com/hyperledger/aries-framework-go/component/kmscrypto/mock/kms" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/secretlock/noop" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" + sigverifier "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" + "github.com/hyperledger/aries-framework-go/component/storageutil/mock/storage" + kmsapi "github.com/hyperledger/aries-framework-go/spi/kms" ) func TestNewCryptoSignerAndVerifier(t *testing.T) { diff --git a/pkg/doc/signature/suite/ed25519signature2020/suite_test.go b/component/models/signature/suite/ed25519signature2020/suite_test.go similarity index 100% rename from pkg/doc/signature/suite/ed25519signature2020/suite_test.go rename to component/models/signature/suite/ed25519signature2020/suite_test.go diff --git a/pkg/doc/signature/suite/jsonwebsignature2020/public_key_verifier.go b/component/models/signature/suite/jsonwebsignature2020/public_key_verifier.go similarity index 92% rename from pkg/doc/signature/suite/jsonwebsignature2020/public_key_verifier.go rename to component/models/signature/suite/jsonwebsignature2020/public_key_verifier.go index 0bf395d2a..6a7d35a8d 100644 --- a/pkg/doc/signature/suite/jsonwebsignature2020/public_key_verifier.go +++ b/component/models/signature/suite/jsonwebsignature2020/public_key_verifier.go @@ -7,7 +7,7 @@ SPDX-License-Identifier: Apache-2.0 package jsonwebsignature2020 import ( - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" ) // NewPublicKeyVerifier creates a signature verifier that verifies a Ed25519 / EC (P-256, P-384, P-521, secp256k1) / RSA diff --git a/pkg/doc/signature/suite/jsonwebsignature2020/public_key_verifier_test.go b/component/models/signature/suite/jsonwebsignature2020/public_key_verifier_test.go similarity index 88% rename from pkg/doc/signature/suite/jsonwebsignature2020/public_key_verifier_test.go rename to component/models/signature/suite/jsonwebsignature2020/public_key_verifier_test.go index ef7597815..30469db06 100644 --- a/pkg/doc/signature/suite/jsonwebsignature2020/public_key_verifier_test.go +++ b/component/models/signature/suite/jsonwebsignature2020/public_key_verifier_test.go @@ -15,11 +15,11 @@ import ( gojose "github.com/go-jose/go-jose/v3" "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto" - "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" - sigverifier "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" - "github.com/hyperledger/aries-framework-go/pkg/doc/util/signature" - kmsapi "github.com/hyperledger/aries-framework-go/pkg/kms" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" + signature "github.com/hyperledger/aries-framework-go/component/models/signature/util" + sigverifier "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" + kmsapi "github.com/hyperledger/aries-framework-go/spi/kms" ) func TestPublicKeyVerifier_Verify_EC(t *testing.T) { diff --git a/pkg/doc/signature/suite/jsonwebsignature2020/suite.go b/component/models/signature/suite/jsonwebsignature2020/suite.go similarity index 86% rename from pkg/doc/signature/suite/jsonwebsignature2020/suite.go rename to component/models/signature/suite/jsonwebsignature2020/suite.go index 13a972f45..6be188f18 100644 --- a/pkg/doc/signature/suite/jsonwebsignature2020/suite.go +++ b/component/models/signature/suite/jsonwebsignature2020/suite.go @@ -22,14 +22,14 @@ package jsonwebsignature2020 import ( "crypto/sha256" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite" + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" ) // Suite implements jsonWebSignature2020 signature suite. type Suite struct { suite.SignatureSuite - jsonldProcessor *jsonld.Processor + jsonldProcessor *processor.Processor } const ( @@ -40,7 +40,7 @@ const ( // New an instance of Linked Data Signatures for JWS suite. func New(opts ...suite.Opt) *Suite { - s := &Suite{jsonldProcessor: jsonld.NewProcessor(rdfDataSetAlg)} + s := &Suite{jsonldProcessor: processor.NewProcessor(rdfDataSetAlg)} suite.InitSuiteOptions(&s.SignatureSuite, opts...) @@ -49,7 +49,7 @@ func New(opts ...suite.Opt) *Suite { // GetCanonicalDocument will return normalized/canonical version of the document // Ed25519Signature2018 signature SignatureSuite uses RDF Dataset Normalization as canonicalization algorithm. -func (s *Suite) GetCanonicalDocument(doc map[string]interface{}, opts ...jsonld.ProcessorOpts) ([]byte, error) { +func (s *Suite) GetCanonicalDocument(doc map[string]interface{}, opts ...processor.Opts) ([]byte, error) { return s.jsonldProcessor.GetCanonicalDocument(doc, opts...) } diff --git a/pkg/doc/signature/suite/jsonwebsignature2020/suite_crypto_test.go b/component/models/signature/suite/jsonwebsignature2020/suite_crypto_test.go similarity index 78% rename from pkg/doc/signature/suite/jsonwebsignature2020/suite_crypto_test.go rename to component/models/signature/suite/jsonwebsignature2020/suite_crypto_test.go index 9f107037c..456fd7b63 100644 --- a/pkg/doc/signature/suite/jsonwebsignature2020/suite_crypto_test.go +++ b/component/models/signature/suite/jsonwebsignature2020/suite_crypto_test.go @@ -13,14 +13,15 @@ import ( "github.com/google/tink/go/keyset" "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite" - sigverifier "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" - kmsapi "github.com/hyperledger/aries-framework-go/pkg/kms" - "github.com/hyperledger/aries-framework-go/pkg/kms/localkms" - mockkms "github.com/hyperledger/aries-framework-go/pkg/mock/kms" - "github.com/hyperledger/aries-framework-go/pkg/mock/storage" - "github.com/hyperledger/aries-framework-go/pkg/secretlock/noop" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/kms/localkms" + mockkms "github.com/hyperledger/aries-framework-go/component/kmscrypto/mock/kms" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/secretlock/noop" + sigverifier "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" + "github.com/hyperledger/aries-framework-go/component/storageutil/mock/storage" + kmsapi "github.com/hyperledger/aries-framework-go/spi/kms" + + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" ) func TestNewCryptoSignerAndVerifier(t *testing.T) { diff --git a/pkg/doc/signature/suite/jsonwebsignature2020/suite_test.go b/component/models/signature/suite/jsonwebsignature2020/suite_test.go similarity index 100% rename from pkg/doc/signature/suite/jsonwebsignature2020/suite_test.go rename to component/models/signature/suite/jsonwebsignature2020/suite_test.go diff --git a/pkg/doc/signature/suite/suite.go b/component/models/signature/suite/suite.go similarity index 89% rename from pkg/doc/signature/suite/suite.go rename to component/models/signature/suite/suite.go index c4690af04..75f6be7ea 100644 --- a/pkg/doc/signature/suite/suite.go +++ b/component/models/signature/suite/suite.go @@ -9,7 +9,7 @@ package suite import ( "errors" - sigverifier "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" + "github.com/hyperledger/aries-framework-go/component/models/signature/api" ) // SignatureSuite defines general signature suite structure. @@ -28,7 +28,7 @@ type signer interface { type verifier interface { // Verify will verify a signature. - Verify(pubKeyValue *sigverifier.PublicKey, doc, signature []byte) error + Verify(pubKeyValue *api.PublicKey, doc, signature []byte) error } // Opt is the SignatureSuite option. @@ -65,7 +65,7 @@ func InitSuiteOptions(suite *SignatureSuite, opts ...Opt) *SignatureSuite { } // Verify will verify a signature. -func (s *SignatureSuite) Verify(pubKeyValue *sigverifier.PublicKey, doc, signature []byte) error { +func (s *SignatureSuite) Verify(pubKeyValue *api.PublicKey, doc, signature []byte) error { if s.Verifier == nil { return ErrVerifierNotDefined } diff --git a/pkg/doc/signature/suite/suite_crypto.go b/component/models/signature/suite/suite_crypto.go similarity index 80% rename from pkg/doc/signature/suite/suite_crypto.go rename to component/models/signature/suite/suite_crypto.go index bdf32a258..e506e9e7c 100644 --- a/pkg/doc/signature/suite/suite_crypto.go +++ b/component/models/signature/suite/suite_crypto.go @@ -7,8 +7,8 @@ SPDX-License-Identifier: Apache-2.0 package suite import ( - "github.com/hyperledger/aries-framework-go/pkg/crypto" - sigverifier "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" + "github.com/hyperledger/aries-framework-go/component/models/signature/api" + "github.com/hyperledger/aries-framework-go/spi/crypto" ) // CryptoSigner defines signer based on crypto. @@ -48,6 +48,6 @@ func NewCryptoVerifier(cr crypto.Crypto) *CryptoVerifier { } // Verify will verify a signature. -func (v *CryptoVerifier) Verify(kh *sigverifier.PublicKey, msg, signature []byte) error { +func (v *CryptoVerifier) Verify(kh *api.PublicKey, msg, signature []byte) error { return v.cr.Verify(signature, msg, kh) } diff --git a/pkg/doc/signature/suite/suite_crypto_test.go b/component/models/signature/suite/suite_crypto_test.go similarity index 76% rename from pkg/doc/signature/suite/suite_crypto_test.go rename to component/models/signature/suite/suite_crypto_test.go index 08f96a0c6..1c86f9821 100644 --- a/pkg/doc/signature/suite/suite_crypto_test.go +++ b/component/models/signature/suite/suite_crypto_test.go @@ -12,8 +12,8 @@ import ( "github.com/stretchr/testify/require" - sigverifier "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" - "github.com/hyperledger/aries-framework-go/pkg/mock/crypto" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/mock/crypto" + "github.com/hyperledger/aries-framework-go/component/models/signature/api" ) func TestNewCryptoSigner(t *testing.T) { @@ -35,7 +35,7 @@ func TestNewCryptoVerifier(t *testing.T) { }) require.NotNil(t, cryptoVerifier) - err := cryptoVerifier.Verify(&sigverifier.PublicKey{}, []byte("msg"), []byte("signature")) + err := cryptoVerifier.Verify(&api.PublicKey{}, []byte("msg"), []byte("signature")) require.Error(t, err) require.EqualError(t, err, "verify error") } diff --git a/pkg/doc/signature/suite/suite_test.go b/component/models/signature/suite/suite_test.go similarity index 91% rename from pkg/doc/signature/suite/suite_test.go rename to component/models/signature/suite/suite_test.go index 59d3fd53a..88fbb2348 100644 --- a/pkg/doc/signature/suite/suite_test.go +++ b/component/models/signature/suite/suite_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" - sigverifier "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" + "github.com/hyperledger/aries-framework-go/component/models/signature/api" ) func TestSignatureSuite_Sign(t *testing.T) { @@ -43,7 +43,7 @@ func TestSignatureSuite_Sign(t *testing.T) { } func TestSignatureSuite_Verify(t *testing.T) { - pubKey := &sigverifier.PublicKey{ + pubKey := &api.PublicKey{ Type: "some type", Value: []byte("any key"), } @@ -101,6 +101,6 @@ type mockVerifier struct { verifyError error } -func (v *mockVerifier) Verify(_ *sigverifier.PublicKey, _, _ []byte) error { +func (v *mockVerifier) Verify(_ *api.PublicKey, _, _ []byte) error { return v.verifyError } diff --git a/pkg/doc/util/signature/api.go b/component/models/signature/util/api.go similarity index 96% rename from pkg/doc/util/signature/api.go rename to component/models/signature/util/api.go index ad3be49c0..2531a0af3 100644 --- a/pkg/doc/util/signature/api.go +++ b/component/models/signature/util/api.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package signature +package util // Signer defines generic signer. type Signer interface { diff --git a/pkg/doc/util/signature/internal/signer/crypto_signer.go b/component/models/signature/util/internal/signer/crypto_signer.go similarity index 96% rename from pkg/doc/util/signature/internal/signer/crypto_signer.go rename to component/models/signature/util/internal/signer/crypto_signer.go index b60dcf5f2..4c9259382 100644 --- a/pkg/doc/util/signature/internal/signer/crypto_signer.go +++ b/component/models/signature/util/internal/signer/crypto_signer.go @@ -16,8 +16,8 @@ import ( "github.com/btcsuite/btcd/btcec" - cryptoapi "github.com/hyperledger/aries-framework-go/pkg/crypto" - kmsapi "github.com/hyperledger/aries-framework-go/pkg/kms" + cryptoapi "github.com/hyperledger/aries-framework-go/spi/crypto" + kmsapi "github.com/hyperledger/aries-framework-go/spi/kms" ) // CryptoSigner defines signer based on crypto. diff --git a/pkg/doc/util/signature/internal/signer/crypto_signer_test.go b/component/models/signature/util/internal/signer/crypto_signer_test.go similarity index 88% rename from pkg/doc/util/signature/internal/signer/crypto_signer_test.go rename to component/models/signature/util/internal/signer/crypto_signer_test.go index 1125930ad..9187738e0 100644 --- a/pkg/doc/util/signature/internal/signer/crypto_signer_test.go +++ b/component/models/signature/util/internal/signer/crypto_signer_test.go @@ -17,12 +17,12 @@ import ( "github.com/google/tink/go/keyset" "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto" - kmsapi "github.com/hyperledger/aries-framework-go/pkg/kms" - "github.com/hyperledger/aries-framework-go/pkg/kms/localkms" - mockkms "github.com/hyperledger/aries-framework-go/pkg/mock/kms" - "github.com/hyperledger/aries-framework-go/pkg/mock/storage" - "github.com/hyperledger/aries-framework-go/pkg/secretlock/noop" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/kms/localkms" + mockkms "github.com/hyperledger/aries-framework-go/component/kmscrypto/mock/kms" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/secretlock/noop" + "github.com/hyperledger/aries-framework-go/component/storageutil/mock/storage" + kmsapi "github.com/hyperledger/aries-framework-go/spi/kms" ) func TestNewCryptoSigner(t *testing.T) { diff --git a/pkg/doc/util/signature/internal/signer/ecdsa.go b/component/models/signature/util/internal/signer/ecdsa.go similarity index 100% rename from pkg/doc/util/signature/internal/signer/ecdsa.go rename to component/models/signature/util/internal/signer/ecdsa.go diff --git a/pkg/doc/util/signature/internal/signer/ecdsa_test.go b/component/models/signature/util/internal/signer/ecdsa_test.go similarity index 100% rename from pkg/doc/util/signature/internal/signer/ecdsa_test.go rename to component/models/signature/util/internal/signer/ecdsa_test.go diff --git a/pkg/doc/util/signature/internal/signer/ed25519.go b/component/models/signature/util/internal/signer/ed25519.go similarity index 100% rename from pkg/doc/util/signature/internal/signer/ed25519.go rename to component/models/signature/util/internal/signer/ed25519.go diff --git a/pkg/doc/util/signature/internal/signer/ed25519_test.go b/component/models/signature/util/internal/signer/ed25519_test.go similarity index 100% rename from pkg/doc/util/signature/internal/signer/ed25519_test.go rename to component/models/signature/util/internal/signer/ed25519_test.go diff --git a/pkg/doc/util/signature/internal/signer/rsa.go b/component/models/signature/util/internal/signer/rsa.go similarity index 100% rename from pkg/doc/util/signature/internal/signer/rsa.go rename to component/models/signature/util/internal/signer/rsa.go diff --git a/pkg/doc/util/signature/internal/signer/rsa_test.go b/component/models/signature/util/internal/signer/rsa_test.go similarity index 100% rename from pkg/doc/util/signature/internal/signer/rsa_test.go rename to component/models/signature/util/internal/signer/rsa_test.go diff --git a/pkg/doc/util/signature/signer.go b/component/models/signature/util/signer.go similarity index 90% rename from pkg/doc/util/signature/signer.go rename to component/models/signature/util/signer.go index 0be06791a..338ad8c24 100644 --- a/pkg/doc/util/signature/signer.go +++ b/component/models/signature/util/signer.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package signature +package util import ( "crypto/ecdsa" @@ -12,10 +12,11 @@ import ( "crypto/rsa" "errors" - cryptoapi "github.com/hyperledger/aries-framework-go/pkg/crypto" - "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" - "github.com/hyperledger/aries-framework-go/pkg/doc/util/signature/internal/signer" - kmsapi "github.com/hyperledger/aries-framework-go/pkg/kms" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" + cryptoapi "github.com/hyperledger/aries-framework-go/spi/crypto" + kmsapi "github.com/hyperledger/aries-framework-go/spi/kms" + + "github.com/hyperledger/aries-framework-go/component/models/signature/util/internal/signer" ) // NewCryptoSigner creates a new signer based on crypto if possible. diff --git a/pkg/doc/util/signature/signer_test.go b/component/models/signature/util/signer_test.go similarity index 88% rename from pkg/doc/util/signature/signer_test.go rename to component/models/signature/util/signer_test.go index 05e0ebf3b..a1744a8a5 100644 --- a/pkg/doc/util/signature/signer_test.go +++ b/component/models/signature/util/signer_test.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package signature +package util import ( "crypto/ecdsa" @@ -19,14 +19,15 @@ import ( "github.com/go-jose/go-jose/v3" "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto" - "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" - "github.com/hyperledger/aries-framework-go/pkg/doc/util/signature/internal/signer" - kmsapi "github.com/hyperledger/aries-framework-go/pkg/kms" - "github.com/hyperledger/aries-framework-go/pkg/kms/localkms" - mockkms "github.com/hyperledger/aries-framework-go/pkg/mock/kms" - "github.com/hyperledger/aries-framework-go/pkg/mock/storage" - "github.com/hyperledger/aries-framework-go/pkg/secretlock/noop" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/kms/localkms" + mockkms "github.com/hyperledger/aries-framework-go/component/kmscrypto/mock/kms" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/secretlock/noop" + "github.com/hyperledger/aries-framework-go/component/storageutil/mock/storage" + kmsapi "github.com/hyperledger/aries-framework-go/spi/kms" + + "github.com/hyperledger/aries-framework-go/component/models/signature/util/internal/signer" ) func TestNewCryptoSigner(t *testing.T) { diff --git a/pkg/doc/util/signature/utils.go b/component/models/signature/util/utils.go similarity index 89% rename from pkg/doc/util/signature/utils.go rename to component/models/signature/util/utils.go index 1284fe9b1..18b477193 100644 --- a/pkg/doc/util/signature/utils.go +++ b/component/models/signature/util/utils.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package signature +package util import ( "crypto/elliptic" @@ -12,7 +12,7 @@ import ( "github.com/btcsuite/btcd/btcec" - kmsapi "github.com/hyperledger/aries-framework-go/pkg/kms" + kmsapi "github.com/hyperledger/aries-framework-go/spi/kms" ) // MapECCurveToKeyType makes a mapping of Elliptic Curve to KeyType of kms. diff --git a/pkg/doc/util/signature/utils_test.go b/component/models/signature/util/utils_test.go similarity index 93% rename from pkg/doc/util/signature/utils_test.go rename to component/models/signature/util/utils_test.go index 0e229aae2..dc0b4b784 100644 --- a/pkg/doc/util/signature/utils_test.go +++ b/component/models/signature/util/utils_test.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package signature +package util import ( "crypto/elliptic" @@ -13,7 +13,7 @@ import ( "github.com/btcsuite/btcd/btcec" "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/kms" + "github.com/hyperledger/aries-framework-go/spi/kms" ) func TestMapECCurveToKeyType(t *testing.T) { diff --git a/pkg/doc/signature/verifier/public_key_verifier.go b/component/models/signature/verifier/public_key_verifier.go similarity index 98% rename from pkg/doc/signature/verifier/public_key_verifier.go rename to component/models/signature/verifier/public_key_verifier.go index 89f9f686d..ea9a5fbea 100644 --- a/pkg/doc/signature/verifier/public_key_verifier.go +++ b/component/models/signature/verifier/public_key_verifier.go @@ -22,8 +22,8 @@ import ( "github.com/btcsuite/btcd/btcec" gojose "github.com/go-jose/go-jose/v3" - "github.com/hyperledger/aries-framework-go/pkg/crypto/primitive/bbs12381g2pub" - "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/primitive/bbs12381g2pub" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" ) // PublicKeyVerifier makes signature verification using the public key diff --git a/pkg/doc/signature/verifier/public_key_verifier_test.go b/component/models/signature/verifier/public_key_verifier_test.go similarity index 96% rename from pkg/doc/signature/verifier/public_key_verifier_test.go rename to component/models/signature/verifier/public_key_verifier_test.go index 450e40efa..1c586d7a8 100644 --- a/pkg/doc/signature/verifier/public_key_verifier_test.go +++ b/component/models/signature/verifier/public_key_verifier_test.go @@ -19,14 +19,14 @@ import ( gojose "github.com/go-jose/go-jose/v3" "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto" - "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" - "github.com/hyperledger/aries-framework-go/pkg/doc/util/signature" - kmsapi "github.com/hyperledger/aries-framework-go/pkg/kms" - "github.com/hyperledger/aries-framework-go/pkg/kms/localkms" - mockkms "github.com/hyperledger/aries-framework-go/pkg/mock/kms" - "github.com/hyperledger/aries-framework-go/pkg/mock/storage" - "github.com/hyperledger/aries-framework-go/pkg/secretlock/noop" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/kms/localkms" + mockkms "github.com/hyperledger/aries-framework-go/component/kmscrypto/mock/kms" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/secretlock/noop" + "github.com/hyperledger/aries-framework-go/component/models/signature/util" + mockstore "github.com/hyperledger/aries-framework-go/component/storageutil/mock/storage" + kmsapi "github.com/hyperledger/aries-framework-go/spi/kms" ) func TestNewPublicKeyVerifier(t *testing.T) { @@ -308,7 +308,7 @@ func TestNewECDSAES256SignatureVerifier(t *testing.T) { for _, test := range tests { tc := test t.Run(tc.curveName, func(t *testing.T) { - keyType, err := signature.MapECCurveToKeyType(tc.curve) + keyType, err := util.MapECCurveToKeyType(tc.curve) require.NoError(t, err) signer, err := newCryptoSigner(keyType) @@ -584,8 +584,8 @@ func (v testSignatureVerifier) Verify(*PublicKey, []byte, []byte) error { return v.verifyResult } -func newCryptoSigner(keyType kmsapi.KeyType) (signature.Signer, error) { - p, err := mockkms.NewProviderForKMS(storage.NewMockStoreProvider(), &noop.NoLock{}) +func newCryptoSigner(keyType kmsapi.KeyType) (util.Signer, error) { + p, err := mockkms.NewProviderForKMS(mockstore.NewMockStoreProvider(), &noop.NoLock{}) if err != nil { return nil, err } @@ -600,5 +600,5 @@ func newCryptoSigner(keyType kmsapi.KeyType) (signature.Signer, error) { return nil, err } - return signature.NewCryptoSigner(tinkCrypto, localKMS, keyType) + return util.NewCryptoSigner(tinkCrypto, localKMS, keyType) } diff --git a/pkg/doc/signature/verifier/testdata/valid_doc.jsonld b/component/models/signature/verifier/testdata/valid_doc.jsonld similarity index 100% rename from pkg/doc/signature/verifier/testdata/valid_doc.jsonld rename to component/models/signature/verifier/testdata/valid_doc.jsonld diff --git a/pkg/doc/signature/verifier/verifier.go b/component/models/signature/verifier/verifier.go similarity index 71% rename from pkg/doc/signature/verifier/verifier.go rename to component/models/signature/verifier/verifier.go index b15d7cfa4..3bc888ffd 100644 --- a/pkg/doc/signature/verifier/verifier.go +++ b/component/models/signature/verifier/verifier.go @@ -10,42 +10,24 @@ import ( "errors" "fmt" - "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/proof" + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" + "github.com/hyperledger/aries-framework-go/component/models/ld/proof" + "github.com/hyperledger/aries-framework-go/component/models/signature/api" ) -// SignatureSuite encapsulates signature suite methods required for signature verification. -type SignatureSuite interface { - - // GetCanonicalDocument will return normalized/canonical version of the document - GetCanonicalDocument(doc map[string]interface{}, opts ...jsonld.ProcessorOpts) ([]byte, error) - - // GetDigest returns document digest - GetDigest(doc []byte) []byte - - // Verify will verify signature against public key - Verify(pubKey *PublicKey, doc []byte, signature []byte) error +// TODO pull SignatureSuite interface and PublicKey type out into an API package - // Accept registers this signature suite with the given signature type - Accept(signatureType string) bool - - // CompactProof indicates weather to compact the proof doc before canonization - CompactProof() bool -} +// SignatureSuite encapsulates signature suite methods required for signature verification. +type SignatureSuite = api.SignatureSuite // PublicKey contains a result of public key resolution. -type PublicKey struct { - Type string - Value []byte - JWK *jwk.JWK -} +type PublicKey = api.PublicKey // keyResolver encapsulates key resolution. type keyResolver interface { // Resolve will return public key bytes and the type of public key - Resolve(id string) (*PublicKey, error) + Resolve(id string) (*api.PublicKey, error) } // DocumentVerifier implements JSON LD document proof verification. @@ -67,7 +49,7 @@ func New(resolver keyResolver, suites ...SignatureSuite) (*DocumentVerifier, err } // Verify will verify document proofs. -func (dv *DocumentVerifier) Verify(jsonLdDoc []byte, opts ...jsonld.ProcessorOpts) error { +func (dv *DocumentVerifier) Verify(jsonLdDoc []byte, opts ...processor.Opts) error { var jsonLdObject map[string]interface{} err := json.Unmarshal(jsonLdDoc, &jsonLdObject) @@ -79,7 +61,7 @@ func (dv *DocumentVerifier) Verify(jsonLdDoc []byte, opts ...jsonld.ProcessorOpt } // VerifyObject will verify document proofs for JSON LD object. -func (dv *DocumentVerifier) VerifyObject(jsonLdObject map[string]interface{}, opts ...jsonld.ProcessorOpts) error { +func (dv *DocumentVerifier) VerifyObject(jsonLdObject map[string]interface{}, opts ...processor.Opts) error { proofs, err := proof.GetProofs(jsonLdObject) if err != nil { return err diff --git a/pkg/doc/signature/verifier/verifier_test.go b/component/models/signature/verifier/verifier_test.go similarity index 89% rename from pkg/doc/signature/verifier/verifier_test.go rename to component/models/signature/verifier/verifier_test.go index 1ccc3dd3e..bc9e4f517 100644 --- a/pkg/doc/signature/verifier/verifier_test.go +++ b/component/models/signature/verifier/verifier_test.go @@ -15,9 +15,10 @@ import ( "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/proof" - "github.com/hyperledger/aries-framework-go/pkg/kms" + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" + "github.com/hyperledger/aries-framework-go/component/models/ld/proof" + "github.com/hyperledger/aries-framework-go/component/models/signature/api" + "github.com/hyperledger/aries-framework-go/spi/kms" ) //go:embed testdata/valid_doc.jsonld @@ -26,7 +27,7 @@ var validDoc string //nolint:gochecknoglobals func TestVerify(t *testing.T) { // happy path okKeyResolver := &testKeyResolver{ - publicKey: &PublicKey{ + publicKey: &api.PublicKey{ Type: kms.ED25519, Value: []byte("signature"), }, @@ -140,11 +141,11 @@ func Test_getProofVerifyValue(t *testing.T) { } type testKeyResolver struct { - publicKey *PublicKey + publicKey *api.PublicKey err error } -func (r *testKeyResolver) Resolve(string) (*PublicKey, error) { +func (r *testKeyResolver) Resolve(string) (*api.PublicKey, error) { return r.publicKey, r.err } @@ -158,7 +159,7 @@ type testSignatureSuite struct { compactProof bool } -func (s *testSignatureSuite) GetCanonicalDocument(map[string]interface{}, ...jsonld.ProcessorOpts) ([]byte, error) { +func (s *testSignatureSuite) GetCanonicalDocument(map[string]interface{}, ...processor.Opts) ([]byte, error) { return s.canonicalDocument, s.canonicalDocumentError } @@ -166,7 +167,7 @@ func (s *testSignatureSuite) GetDigest([]byte) []byte { return s.digest } -func (s *testSignatureSuite) Verify(*PublicKey, []byte, []byte) error { +func (s *testSignatureSuite) Verify(*api.PublicKey, []byte, []byte) error { return s.verifyError } diff --git a/component/models/util/maphelpers/maphelpers.go b/component/models/util/maphelpers/maphelpers.go new file mode 100644 index 000000000..f7480d54f --- /dev/null +++ b/component/models/util/maphelpers/maphelpers.go @@ -0,0 +1,23 @@ +/* +Copyright Gen Digital Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package maphelpers + +// CopyMap performs shallow copy of map and nested maps. +func CopyMap(m map[string]interface{}) map[string]interface{} { + cm := make(map[string]interface{}) + + for k, v := range m { + vm, ok := v.(map[string]interface{}) + if ok { + cm[k] = CopyMap(vm) + } else { + cm[k] = v + } + } + + return cm +} diff --git a/pkg/doc/util/time.go b/component/models/util/time/time.go similarity index 96% rename from pkg/doc/util/time.go rename to component/models/util/time/time.go index 5bfb50835..2b8fec484 100644 --- a/pkg/doc/util/time.go +++ b/component/models/util/time/time.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package util +package time import ( "encoding/json" @@ -15,7 +15,7 @@ import ( // unmarshalled from JSON, it saves the string literal, which it uses when marshalling. // If a TimeWrapper is created using NewTime or a struct literal, it marshals with the default // time.RFC3339 format. -type TimeWrapper struct { +type TimeWrapper struct { // nolint:golint time.Time timeStr string } @@ -26,7 +26,7 @@ type TimeWrapper struct { // while TimeWithTrailingZeroMsec marshals to the initial 2018-03-15T00:00:00.000Z value. // // Deprecated: use TimeWrapper instead. -type TimeWithTrailingZeroMsec = TimeWrapper +type TimeWithTrailingZeroMsec = TimeWrapper // nolint:golint // NewTime creates a TimeWrapper wrapped around the given time.Time. // It functions as a normal time.Time object. diff --git a/pkg/doc/util/time_test.go b/component/models/util/time/time_test.go similarity index 99% rename from pkg/doc/util/time_test.go rename to component/models/util/time/time_test.go index 3670552e2..681918099 100644 --- a/pkg/doc/util/time_test.go +++ b/component/models/util/time/time_test.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package util +package time import ( "encoding/json" diff --git a/pkg/mock/storage/mock_store.go b/component/storageutil/mock/storage/storage.go similarity index 97% rename from pkg/mock/storage/mock_store.go rename to component/storageutil/mock/storage/storage.go index e1fe77481..e7a874ae9 100644 --- a/pkg/mock/storage/mock_store.go +++ b/component/storageutil/mock/storage/storage.go @@ -3,6 +3,8 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ +// Package storage provides an alternative implementation of a mock Store, supporting most of a MemStore's behaviour +// with the added ability to override return values. package storage import ( diff --git a/go.mod b/go.mod index a426ad8a9..bf75984a3 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,6 @@ require ( github.com/PaesslerAG/jsonpath v0.1.1 github.com/VictoriaMetrics/fastcache v1.5.7 github.com/bluele/gcache v0.0.0-20190518031135-bc40bd653833 - github.com/btcsuite/btcd v0.22.0-beta github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce github.com/cenkalti/backoff/v4 v4.0.2 github.com/go-jose/go-jose/v3 v3.0.1-0.20221117193127-916db76e8214 @@ -22,6 +21,7 @@ require ( github.com/gorilla/mux v1.7.3 github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0-20230420151605-a45b1b02336f github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230417184158-344a7f82c4c2 + github.com/hyperledger/aries-framework-go/component/models v0.0.0 github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20221025204933-b807371b6f1e github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20220322085443-50e8f9bd208b github.com/hyperledger/aries-framework-go/spi v0.0.0-20230417184158-344a7f82c4c2 @@ -45,6 +45,7 @@ require ( ) require ( + github.com/btcsuite/btcd v0.22.0-beta // indirect github.com/cespare/xxhash/v2 v2.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/golang/snappy v0.0.4 // indirect @@ -73,8 +74,12 @@ replace github.com/hyperledger/aries-framework-go/component/kmscrypto => ./compo replace github.com/hyperledger/aries-framework-go/component/log => ./component/log +replace github.com/hyperledger/aries-framework-go/component/models => ./component/models + replace github.com/hyperledger/aries-framework-go/spi => ./spi +replace github.com/hyperledger/aries-framework-go/component/storageutil => ./component/storageutil + go 1.19 //replace github.com/square/go-jose/v3 => github.com/go-jose/go-jose/v3 v3.0.1-0.20221117193127-916db76e8214 diff --git a/go.sum b/go.sum index 12941beed..e176600c9 100644 --- a/go.sum +++ b/go.sum @@ -68,8 +68,6 @@ github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= 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/storageutil v0.0.0-20220322085443-50e8f9bd208b h1:IoD7+sHQRLMouwHjhrOj5vhg+rPt/aKl4P+WiBZVHVk= -github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20220322085443-50e8f9bd208b/go.mod h1:yLgRpVlZ2heeeOpTgvEnG/yHL9q1keUu5ILQ6s2qpLU= github.com/hyperledger/aries-framework-go/test/component v0.0.0-20220428211718-66cc046674a1 h1:vxZ0DlFNLjgxMdBESLZu895AsI1JWL2SJerphwIn8Po= github.com/hyperledger/ursa-wrapper-go v0.3.1 h1:Do+QrVNniY77YK2jTIcyWqj9rm/Yb5SScN0bqCjiibA= github.com/hyperledger/ursa-wrapper-go v0.3.1/go.mod h1:nPSAuMasIzSVciQo22PedBk4Opph6bJ6ia3ms7BH/mk= diff --git a/pkg/common/model/model.go b/pkg/common/model/model.go new file mode 100644 index 000000000..7672bf3ba --- /dev/null +++ b/pkg/common/model/model.go @@ -0,0 +1,52 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package model + +import ( + "github.com/hyperledger/aries-framework-go/component/models/did/endpoint" +) + +// EndpointType endpoint type. +type EndpointType = endpoint.EndpointType + +const ( + // DIDCommV1 type. + DIDCommV1 = endpoint.DIDCommV1 + // DIDCommV2 type. + DIDCommV2 = endpoint.DIDCommV2 + // Generic type. + Generic = endpoint.Generic +) + +// ServiceEndpoint api for fetching ServiceEndpoint content based off of a DIDComm V1, V2 or DIDCore format. +type ServiceEndpoint = endpoint.ServiceEndpoint + +// Endpoint contains endpoint specific content. Content of ServiceEndpoint api above will be used by priority: +// 1- DIDcomm V2 +// 2- DIDComm V1 +// 3- DIDCore +// To force lower priority endpoint content, avoid setting higher priority data during Unmarshal() execution. +type Endpoint = endpoint.Endpoint + +// DIDCommV2Endpoint contains ServiceEndpoint data specifically for DIDcommV2 and is wrapped in Endpoint as an array. +type DIDCommV2Endpoint = endpoint.DIDCommV2Endpoint + +// NewDIDCommV2Endpoint creates a DIDCommV2 endpoint with the given array of endpoints. At the time of writing this +// comment, only the first endpoint is effective in the API. Additional logic is required to use a different index. +func NewDIDCommV2Endpoint(endpoints []DIDCommV2Endpoint) Endpoint { + return endpoint.NewDIDCommV2Endpoint(endpoints) +} + +// NewDIDCommV1Endpoint creates a DIDCommV1 endpoint. +func NewDIDCommV1Endpoint(uri string) Endpoint { + return endpoint.NewDIDCommV1Endpoint(uri) +} + +// NewDIDCoreEndpoint creates a generic DIDCore endpoint. +func NewDIDCoreEndpoint(genericEndpoint interface{}) Endpoint { + return endpoint.NewDIDCoreEndpoint(genericEndpoint) +} diff --git a/pkg/doc/did/did.go b/pkg/doc/did/did.go new file mode 100644 index 000000000..49f0a21cd --- /dev/null +++ b/pkg/doc/did/did.go @@ -0,0 +1,204 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. +SPDX-License-Identifier: Apache-2.0 +*/ + +package did + +import ( + "time" + + "github.com/multiformats/go-multibase" + + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" + didmodel "github.com/hyperledger/aries-framework-go/component/models/did" +) + +const ( + // ContextV1 of the DID document is the current V1 context name. + ContextV1 = didmodel.ContextV1 + // ContextV1Old of the DID document representing the old/legacy V1 context name. + ContextV1Old = didmodel.ContextV1Old +) + +// ErrDIDDocumentNotExist error did doc not exist. +var ErrDIDDocumentNotExist = didmodel.ErrDIDDocumentNotExist + +// DID is parsed according to the generic syntax: https://w3c.github.io/did-core/#generic-did-syntax +type DID = didmodel.DID + +// Parse parses the string according to the generic DID syntax. +// See https://w3c.github.io/did-core/#generic-did-syntax. +func Parse(did string) (*DID, error) { + return didmodel.Parse(did) +} + +// DIDURL holds a DID URL. +type DIDURL = didmodel.DIDURL // nolint:golint + +// ParseDIDURL parses a DID URL string into a DIDURL object. +func ParseDIDURL(didURL string) (*DIDURL, error) { + return didmodel.ParseDIDURL(didURL) +} + +// Context represents JSON-LD representation-specific DID-core @context, which +// must be either a string, or a list containing maps and/or strings. +type Context = didmodel.Context + +// DocResolution did resolution. +type DocResolution = didmodel.DocResolution + +// MethodMetadata method metadata. +type MethodMetadata = didmodel.MethodMetadata + +// ProtocolOperation info. +type ProtocolOperation = didmodel.ProtocolOperation + +// DocumentMetadata document metadata. +type DocumentMetadata = didmodel.DocumentMetadata + +// ParseDocumentResolution parse document resolution. +func ParseDocumentResolution(data []byte) (*DocResolution, error) { + return didmodel.ParseDocumentResolution(data) +} + +// Doc DID Document definition. +type Doc = didmodel.Doc + +// VerificationMethod DID doc verification method. +// The value of the verification method is defined either as raw public key bytes (Value field) or as JSON Web Key. +// In the first case the Type field can hold additional information to understand the nature of the raw public key. +type VerificationMethod = didmodel.VerificationMethod + +// NewVerificationMethodFromBytesWithMultibase creates a new VerificationMethod based on +// raw public key bytes with multibase. +func NewVerificationMethodFromBytesWithMultibase(id, keyType, controller string, value []byte, + encoding multibase.Encoding) *VerificationMethod { + return didmodel.NewVerificationMethodFromBytesWithMultibase(id, keyType, controller, value, encoding) +} + +// NewVerificationMethodFromBytes creates a new VerificationMethod based on raw public key bytes. +func NewVerificationMethodFromBytes(id, keyType, controller string, value []byte) *VerificationMethod { + return didmodel.NewVerificationMethodFromBytes(id, keyType, controller, value) +} + +// NewVerificationMethodFromJWK creates a new VerificationMethod based on JSON Web Key. +func NewVerificationMethodFromJWK(id, keyType, controller string, j *jwk.JWK) (*VerificationMethod, error) { + return didmodel.NewVerificationMethodFromJWK(id, keyType, controller, j) +} + +// Service DID doc service. +type Service = didmodel.Service + +// VerificationRelationship defines a verification relationship between DID subject and a verification method. +type VerificationRelationship = didmodel.VerificationRelationship + +const ( + // VerificationRelationshipGeneral is a special case of verification relationship: when a verification method + // defined in Verification is not used by any Verification. + VerificationRelationshipGeneral = didmodel.VerificationRelationshipGeneral + + // Authentication defines verification relationship. + Authentication = didmodel.Authentication + + // AssertionMethod defines verification relationship. + AssertionMethod = didmodel.AssertionMethod + + // CapabilityDelegation defines verification relationship. + CapabilityDelegation = didmodel.CapabilityDelegation + + // CapabilityInvocation defines verification relationship. + CapabilityInvocation = didmodel.CapabilityInvocation + + // KeyAgreement defines verification relationship. + KeyAgreement = didmodel.KeyAgreement +) + +// Verification authentication verification. +type Verification = didmodel.Verification + +// NewEmbeddedVerification creates a new verification method with embedded verification method. +func NewEmbeddedVerification(vm *VerificationMethod, r VerificationRelationship) *Verification { + return didmodel.NewEmbeddedVerification(vm, r) +} + +// NewReferencedVerification creates a new verification method with referenced verification method. +func NewReferencedVerification(vm *VerificationMethod, r VerificationRelationship) *Verification { + return didmodel.NewReferencedVerification(vm, r) +} + +// Proof is cryptographic proof of the integrity of the DID Document. +type Proof = didmodel.Proof + +// ParseDocument creates an instance of DIDDocument by reading a JSON document from bytes. +func ParseDocument(data []byte) (*Doc, error) { // nolint:funlen,gocyclo + return didmodel.ParseDocument(data) +} + +// ErrProofNotFound is returned when proof is not found. +var ErrProofNotFound = didmodel.ErrProofNotFound + +// ErrKeyNotFound is returned when key is not found. +var ErrKeyNotFound = didmodel.ErrKeyNotFound + +// DocOption provides options to build DID Doc. +type DocOption = didmodel.DocOption + +// WithVerificationMethod DID doc VerificationMethod. +func WithVerificationMethod(pubKey []VerificationMethod) DocOption { + return didmodel.WithVerificationMethod(pubKey) +} + +// WithAuthentication sets the verification methods for authentication: https://w3c.github.io/did-core/#authentication. +func WithAuthentication(auth []Verification) DocOption { + return didmodel.WithAuthentication(auth) +} + +// WithAssertion sets the verification methods for assertion: https://w3c.github.io/did-core/#assertion. +func WithAssertion(assertion []Verification) DocOption { + return didmodel.WithAssertion(assertion) +} + +// WithKeyAgreement sets the verification methods for KeyAgreement: https://w3c.github.io/did-core/#key-agreement. +func WithKeyAgreement(keyAgreement []Verification) DocOption { + return didmodel.WithKeyAgreement(keyAgreement) +} + +// WithService DID doc services. +func WithService(svc []Service) DocOption { + return didmodel.WithService(svc) +} + +// WithCreatedTime DID doc created time. +func WithCreatedTime(t time.Time) DocOption { + return didmodel.WithCreatedTime(t) +} + +// WithUpdatedTime DID doc updated time. +func WithUpdatedTime(t time.Time) DocOption { + return didmodel.WithUpdatedTime(t) +} + +// BuildDoc creates the DID Doc from options. +func BuildDoc(opts ...DocOption) *Doc { + return didmodel.BuildDoc(opts...) +} + +// LookupService returns the service from the given DIDDoc matching the given service type. +func LookupService(didDoc *Doc, serviceType string) (*Service, bool) { + return didmodel.LookupService(didDoc, serviceType) +} + +// LookupDIDCommRecipientKeys gets the DIDComm recipient keys from the did doc which match the given parameters. +// DIDComm recipient keys are encoded as did:key identifiers. +// See: +// - https://github.com/hyperledger/aries-rfcs/blob/master/features/0067-didcomm-diddoc-conventions/README.md +// - https://github.com/hyperledger/aries-rfcs/blob/master/features/0360-use-did-key/README.md +func LookupDIDCommRecipientKeys(didDoc *Doc) ([]string, bool) { + return didmodel.LookupDIDCommRecipientKeys(didDoc) +} + +// LookupPublicKey returns the public key with the given id from the given DID Doc. +func LookupPublicKey(id string, didDoc *Doc) (*VerificationMethod, bool) { + return didmodel.LookupPublicKey(id, didDoc) +} diff --git a/pkg/doc/did/helpers_test.go b/pkg/doc/did/helpers_test.go index d791695d4..a417897f2 100644 --- a/pkg/doc/did/helpers_test.go +++ b/pkg/doc/did/helpers_test.go @@ -11,7 +11,8 @@ import ( "github.com/stretchr/testify/require" - . "github.com/hyperledger/aries-framework-go/pkg/doc/did" + . "github.com/hyperledger/aries-framework-go/component/models/did" + mockdiddoc "github.com/hyperledger/aries-framework-go/pkg/mock/diddoc" ) diff --git a/pkg/doc/jose/common.go b/pkg/doc/jose/common.go index aafd18ae8..e902cedf1 100644 --- a/pkg/doc/jose/common.go +++ b/pkg/doc/jose/common.go @@ -7,8 +7,8 @@ SPDX-License-Identifier: Apache-2.0 package jose import ( - "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/composite/ecdh" - "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto/primitive/composite/ecdh" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" ) // IANA registered JOSE headers (https://tools.ietf.org/html/rfc7515#section-4.1) diff --git a/pkg/doc/jose/common_test.go b/pkg/doc/jose/common_test.go index b103b4b65..dbdf6ca1d 100644 --- a/pkg/doc/jose/common_test.go +++ b/pkg/doc/jose/common_test.go @@ -14,7 +14,7 @@ import ( "github.com/go-jose/go-jose/v3" "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" ) func TestHeaders_GetJWK(t *testing.T) { diff --git a/pkg/doc/jose/decrypter.go b/pkg/doc/jose/decrypter.go index e029c1331..35e13a385 100644 --- a/pkg/doc/jose/decrypter.go +++ b/pkg/doc/jose/decrypter.go @@ -16,12 +16,12 @@ import ( "github.com/google/tink/go/keyset" ecdhpb "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto/primitive/proto/ecdh_aead_go_proto" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" cryptoapi "github.com/hyperledger/aries-framework-go/pkg/crypto" "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/composite" "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/composite/api" "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/composite/ecdh" "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/composite/keyio" - "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" "github.com/hyperledger/aries-framework-go/pkg/doc/jose/kid/resolver" "github.com/hyperledger/aries-framework-go/pkg/kms" ) diff --git a/pkg/doc/jose/encrypter.go b/pkg/doc/jose/encrypter.go index bfb28377d..4febdd4a8 100644 --- a/pkg/doc/jose/encrypter.go +++ b/pkg/doc/jose/encrypter.go @@ -28,13 +28,13 @@ import ( ecdhpb "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto/primitive/proto/ecdh_aead_go_proto" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" cryptoapi "github.com/hyperledger/aries-framework-go/pkg/crypto" "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto" "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/aead/subtle" "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/composite" "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/composite/api" "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/composite/ecdh" - "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" "github.com/hyperledger/aries-framework-go/pkg/internal/cryptoutil" ) diff --git a/pkg/doc/jose/encrypter_decrypter_test.go b/pkg/doc/jose/encrypter_decrypter_test.go index 8c6156962..02ba7d0b5 100644 --- a/pkg/doc/jose/encrypter_decrypter_test.go +++ b/pkg/doc/jose/encrypter_decrypter_test.go @@ -29,14 +29,14 @@ import ( "github.com/stretchr/testify/require" ecdhpb "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto/primitive/proto/ecdh_aead_go_proto" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/util/jwkkid" cryptoapi "github.com/hyperledger/aries-framework-go/pkg/crypto" "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto" "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/composite/ecdh" "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/composite/keyio" ariesjose "github.com/hyperledger/aries-framework-go/pkg/doc/jose" - "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" "github.com/hyperledger/aries-framework-go/pkg/doc/jose/kid/resolver" - "github.com/hyperledger/aries-framework-go/pkg/doc/util/jwkkid" "github.com/hyperledger/aries-framework-go/pkg/doc/util/kmsdidkey" "github.com/hyperledger/aries-framework-go/pkg/kms" mockkms "github.com/hyperledger/aries-framework-go/pkg/mock/kms" diff --git a/pkg/doc/jose/jwk/jwksupport/jwk.go b/pkg/doc/jose/jwk/jwksupport/jwk.go index c6023314a..aa8b38d15 100644 --- a/pkg/doc/jose/jwk/jwksupport/jwk.go +++ b/pkg/doc/jose/jwk/jwksupport/jwk.go @@ -7,11 +7,10 @@ SPDX-License-Identifier: Apache-2.0 package jwksupport import ( + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk/jwksupport" "github.com/hyperledger/aries-framework-go/spi/crypto" - - "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" - "github.com/hyperledger/aries-framework-go/pkg/kms" + "github.com/hyperledger/aries-framework-go/spi/kms" ) // JWKFromKey creates a JWK from an opaque key struct. diff --git a/pkg/doc/jsonld/validate.go b/pkg/doc/jsonld/validate.go index fd42a7447..357be746e 100644 --- a/pkg/doc/jsonld/validate.go +++ b/pkg/doc/jsonld/validate.go @@ -13,7 +13,7 @@ import ( "github.com/piprate/json-gold/ld" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" "github.com/hyperledger/aries-framework-go/pkg/doc/util/json" ) @@ -78,11 +78,11 @@ func ValidateJSONLD(doc string, options ...ValidateOpts) error { return fmt.Errorf("convert JSON-LD doc to map: %w", err) } - jsonldProc := jsonld.Default() + jsonldProc := processor.Default() docCompactedMap, err := jsonldProc.Compact(docMap, - nil, jsonld.WithDocumentLoader(opts.jsonldDocumentLoader), - jsonld.WithExternalContext(opts.externalContext...)) + nil, processor.WithDocumentLoader(opts.jsonldDocumentLoader), + processor.WithExternalContext(opts.externalContext...)) if err != nil { return fmt.Errorf("compact JSON-LD document: %w", err) } diff --git a/pkg/doc/jwt/verifier.go b/pkg/doc/jwt/verifier.go index 4c9fba5bf..7287589a3 100644 --- a/pkg/doc/jwt/verifier.go +++ b/pkg/doc/jwt/verifier.go @@ -16,8 +16,8 @@ import ( "golang.org/x/crypto/ed25519" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" "github.com/hyperledger/aries-framework-go/pkg/doc/jose" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" kmsapi "github.com/hyperledger/aries-framework-go/pkg/kms" ) diff --git a/pkg/doc/jwt/verifier_test.go b/pkg/doc/jwt/verifier_test.go index 82bb703db..7e203b1ce 100644 --- a/pkg/doc/jwt/verifier_test.go +++ b/pkg/doc/jwt/verifier_test.go @@ -23,9 +23,9 @@ import ( "github.com/pkg/errors" "github.com/stretchr/testify/require" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" "github.com/hyperledger/aries-framework-go/pkg/doc/jose" "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" "github.com/hyperledger/aries-framework-go/pkg/kms" ) diff --git a/pkg/doc/ld/ld.go b/pkg/doc/ld/ld.go new file mode 100644 index 000000000..39d57af23 --- /dev/null +++ b/pkg/doc/ld/ld.go @@ -0,0 +1,61 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package ld + +import ( + jsonld "github.com/piprate/json-gold/ld" + + ldcontext "github.com/hyperledger/aries-framework-go/component/models/ld/context" + "github.com/hyperledger/aries-framework-go/component/models/ld/documentloader" + ldstore "github.com/hyperledger/aries-framework-go/component/models/ld/store" +) + +// ErrContextNotFound is returned when JSON-LD context document is not found in the underlying storage. +var ErrContextNotFound = documentloader.ErrContextNotFound + +// provider contains dependencies for the JSON-LD document loader. +type provider interface { + JSONLDContextStore() ldstore.ContextStore + JSONLDRemoteProviderStore() ldstore.RemoteProviderStore +} + +// DocumentLoader is an implementation of ld.DocumentLoader backed by storage. +type DocumentLoader = documentloader.DocumentLoader + +// NewDocumentLoader returns a new DocumentLoader instance. +// +// Embedded contexts (`ldcontext/embed/third_party`) are preloaded into the underlying storage. +// Additional contexts can be set using WithExtraContexts() option or provided by one or more remote providers. +// Use multiple WithRemoteProvider() options for setting up more than one remote JSON-LD context provider. +// +// By default, missing contexts are not fetched from the remote URL. Use WithRemoteDocumentLoader() option +// to specify a custom loader that can resolve context documents from the network. +func NewDocumentLoader(ctx provider, opts ...DocumentLoaderOpts) (*DocumentLoader, error) { + return documentloader.NewDocumentLoader(ctx, opts...) +} + +// DocumentLoaderOpts configures DocumentLoader during creation. +type DocumentLoaderOpts = documentloader.Opts + +// WithRemoteDocumentLoader specifies loader for fetching JSON-LD context documents from remote URLs. +// Documents are fetched with this loader only if they are not found in the underlying storage. +func WithRemoteDocumentLoader(loader jsonld.DocumentLoader) DocumentLoaderOpts { + return documentloader.WithRemoteDocumentLoader(loader) +} + +// WithExtraContexts sets the extra contexts (in addition to embedded) for preloading into the underlying storage. +func WithExtraContexts(contexts ...ldcontext.Document) DocumentLoaderOpts { + return documentloader.WithExtraContexts(contexts...) +} + +// RemoteProvider defines a remote JSON-LD context provider. +type RemoteProvider = documentloader.RemoteProvider + +// WithRemoteProvider adds a remote JSON-LD context provider to the list of providers. +func WithRemoteProvider(provider RemoteProvider) DocumentLoaderOpts { + return documentloader.WithRemoteProvider(provider) +} diff --git a/pkg/doc/ldcontext/embed/embed.go b/pkg/doc/ldcontext/embed/embed.go new file mode 100644 index 000000000..9b5fa47ca --- /dev/null +++ b/pkg/doc/ldcontext/embed/embed.go @@ -0,0 +1,14 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package embed + +import ( + embedcontexts "github.com/hyperledger/aries-framework-go/component/models/ld/context/embed" +) + +// Contexts contains JSON-LD contexts embedded into a Go binary. +var Contexts = embedcontexts.Contexts // nolint:gochecknoglobals diff --git a/pkg/doc/ldcontext/ldcontext.go b/pkg/doc/ldcontext/ldcontext.go new file mode 100644 index 000000000..f3698d10c --- /dev/null +++ b/pkg/doc/ldcontext/ldcontext.go @@ -0,0 +1,14 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package ldcontext + +import ( + "github.com/hyperledger/aries-framework-go/component/models/ld/context" +) + +// Document is a JSON-LD context document with associated metadata. +type Document = context.Document diff --git a/pkg/doc/ldcontext/remote/remote.go b/pkg/doc/ldcontext/remote/remote.go new file mode 100644 index 000000000..71c0a12e6 --- /dev/null +++ b/pkg/doc/ldcontext/remote/remote.go @@ -0,0 +1,33 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package remote + +import ( + "github.com/hyperledger/aries-framework-go/component/models/ld/context/remote" +) + +// Provider is a remote JSON-LD context provider. +type Provider = remote.Provider + +// NewProvider returns a new instance of the remote provider. +func NewProvider(endpoint string, opts ...ProviderOpt) *Provider { + return remote.NewProvider(endpoint, opts...) +} + +// Response represents a response from the remote source with JSON-LD context documents. +type Response = remote.Response + +// ProviderOpt configures the remote context provider. +type ProviderOpt = remote.ProviderOpt + +// HTTPClient represents an HTTP client. +type HTTPClient = remote.HTTPClient + +// WithHTTPClient configures an HTTP client. +func WithHTTPClient(client HTTPClient) ProviderOpt { + return remote.WithHTTPClient(client) +} diff --git a/pkg/doc/signature/jsonld/jsonld.go b/pkg/doc/signature/jsonld/jsonld.go new file mode 100644 index 000000000..31da98bd4 --- /dev/null +++ b/pkg/doc/signature/jsonld/jsonld.go @@ -0,0 +1,72 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package jsonld + +import ( + "github.com/piprate/json-gold/ld" + + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" +) + +// ErrInvalidRDFFound is returned when normalized view contains invalid RDF. +var ErrInvalidRDFFound = processor.ErrInvalidRDFFound + +// ProcessorOpts are the options for JSON LD operations on docs (like canonicalization or compacting). +type ProcessorOpts = processor.Opts + +// WithRemoveAllInvalidRDF option for removing all invalid RDF dataset from normalize document. +func WithRemoveAllInvalidRDF() ProcessorOpts { + return processor.WithRemoveAllInvalidRDF() +} + +// WithFrameBlankNodes option for transforming blank node identifiers into nodes. +// For example, _:c14n0 is transformed into . +func WithFrameBlankNodes() ProcessorOpts { + return processor.WithFrameBlankNodes() +} + +// WithDocumentLoader option is for passing custom JSON-LD document loader. +func WithDocumentLoader(loader ld.DocumentLoader) ProcessorOpts { + return processor.WithDocumentLoader(loader) +} + +// WithExternalContext option is for definition of external context when doing JSON-LD operations. +func WithExternalContext(context ...string) ProcessorOpts { + return processor.WithExternalContext(context...) +} + +// WithValidateRDF option validates result view and fails if any invalid RDF dataset found. +// This option will take precedence when used in conjunction with 'WithRemoveAllInvalidRDF' option. +func WithValidateRDF() ProcessorOpts { + return processor.WithValidateRDF() +} + +// Processor is JSON-LD processor for aries. +// processing mode JSON-LD 1.0 {RFC: https://www.w3.org/TR/2014/REC-json-ld-20140116} +type Processor = processor.Processor + +// NewProcessor returns new JSON-LD processor for aries. +func NewProcessor(algorithm string) *Processor { + return processor.NewProcessor(algorithm) +} + +// Default returns new JSON-LD processor with default RDF dataset algorithm. +func Default() *Processor { + return processor.Default() +} + +// AppendExternalContexts appends external context(s) to the JSON-LD context which can have one +// or several contexts already. +func AppendExternalContexts(context interface{}, extraContexts ...string) []interface{} { + return processor.AppendExternalContexts(context, extraContexts...) +} + +// TransformBlankNode replaces blank node identifiers in the RDF statements. +// For example, transform from "_:c14n0" to "urn:bnid:_:c14n0". +func TransformBlankNode(row string) string { + return processor.TransformBlankNode(row) +} diff --git a/pkg/doc/signature/proof/ldproof.go b/pkg/doc/signature/proof/ldproof.go new file mode 100644 index 000000000..957ae5aad --- /dev/null +++ b/pkg/doc/signature/proof/ldproof.go @@ -0,0 +1,97 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. +SPDX-License-Identifier: Apache-2.0 +*/ + +package proof + +import ( + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" + ldproof "github.com/hyperledger/aries-framework-go/component/models/ld/proof" +) + +// signatureSuite encapsulates signature suite methods required for normalizing document. +type signatureSuite interface { + + // GetCanonicalDocument will return normalized/canonical version of the document + GetCanonicalDocument(doc map[string]interface{}, opts ...processor.Opts) ([]byte, error) + + // GetDigest returns document digest + GetDigest(doc []byte) []byte + + // CompactProof indicates weather to compact the proof doc before canonization + CompactProof() bool +} + +// SignatureRepresentation defines a representation of signature value. +type SignatureRepresentation = ldproof.SignatureRepresentation + +const ( + // SignatureProofValue uses "proofValue" field in a Proof to put/read a digital signature. + SignatureProofValue = ldproof.SignatureProofValue + + // SignatureJWS uses "jws" field in a Proof as an element for representation of detached JSON Web Signatures. + SignatureJWS = ldproof.SignatureJWS +) + +// Proof is cryptographic proof of the integrity of the DID Document. +type Proof = ldproof.Proof + +// NewProof creates new proof. +func NewProof(emap map[string]interface{}) (*Proof, error) { + return ldproof.NewProof(emap) +} + +// DecodeProofValue decodes proofValue basing on proof type. +func DecodeProofValue(s, proofType string) ([]byte, error) { + return ldproof.DecodeProofValue(s, proofType) +} + +// EncodeProofValue decodes proofValue basing on proof type. +func EncodeProofValue(proofValue []byte, proofType string) string { + return ldproof.EncodeProofValue(proofValue, proofType) +} + +// CreateVerifyData creates data that is used to generate or verify a digital signature. +// It depends on the signature value holder type. +// In case of "proofValue", the standard Create Verify Hash algorithm is used. +// In case of "jws", verify data is built as JSON Web Signature (JWS) with detached payload. +func CreateVerifyData(suite signatureSuite, jsonldDoc map[string]interface{}, proof *Proof, + opts ...processor.Opts) ([]byte, error) { + return ldproof.CreateVerifyData(suite, jsonldDoc, proof, opts...) +} + +// CreateVerifyHash returns data that is used to generate or verify a digital signature +// Algorithm steps are described here https://w3c-dvcg.github.io/ld-signatures/#create-verify-hash-algorithm +func CreateVerifyHash(suite signatureSuite, jsonldDoc, proofOptions map[string]interface{}, + opts ...processor.Opts) ([]byte, error) { + return ldproof.CreateVerifyHash(suite, jsonldDoc, proofOptions, opts...) +} + +// CreateDetachedJWTHeader creates detached JWT header. +func CreateDetachedJWTHeader(alg string) string { + return ldproof.CreateDetachedJWTHeader(alg) +} + +// GetJWTSignature returns signature part of JWT. +func GetJWTSignature(jwt string) ([]byte, error) { + return ldproof.GetJWTSignature(jwt) +} + +// GetProofs gets proof(s) from LD Object. +func GetProofs(jsonLdObject map[string]interface{}) ([]*Proof, error) { + return ldproof.GetProofs(jsonLdObject) +} + +// AddProof adds a proof to LD Object. +func AddProof(jsonLdObject map[string]interface{}, proof *Proof) error { + return ldproof.AddProof(jsonLdObject, proof) +} + +// GetCopyWithoutProof gets copy of JSON LD Object without proofs (signatures). +func GetCopyWithoutProof(jsonLdObject map[string]interface{}) map[string]interface{} { + return ldproof.GetCopyWithoutProof(jsonLdObject) +} + +// ErrProofNotFound is returned when proof is not found. +var ErrProofNotFound = ldproof.ErrProofNotFound diff --git a/pkg/doc/signature/signer/api.go b/pkg/doc/signature/signer/api.go new file mode 100644 index 000000000..4625ff6e4 --- /dev/null +++ b/pkg/doc/signature/signer/api.go @@ -0,0 +1,24 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. +SPDX-License-Identifier: Apache-2.0 +*/ + +package signer + +import ( + "github.com/hyperledger/aries-framework-go/component/models/signature/signer" +) + +// SignatureSuite encapsulates signature suite methods required for signing documents. +type SignatureSuite = signer.SignatureSuite + +// DocumentSigner implements signing of JSONLD documents. +type DocumentSigner = signer.DocumentSigner + +// Context holds signing options and private key. +type Context = signer.Context + +// New returns new instance of document verifier. +func New(signatureSuites ...SignatureSuite) *DocumentSigner { + return signer.New(signatureSuites...) +} diff --git a/pkg/doc/signature/signer/signer_default.go b/pkg/doc/signature/signer/signer_default.go deleted file mode 100644 index 4a85368d2..000000000 --- a/pkg/doc/signature/signer/signer_default.go +++ /dev/null @@ -1,19 +0,0 @@ -// +build !ACAPyInterop - -/* -Copyright SecureKey Technologies Inc. All Rights Reserved. - -SPDX-License-Identifier: Apache-2.0 -*/ - -package signer - -import ( - "time" - - "github.com/hyperledger/aries-framework-go/pkg/doc/util" -) - -func wrapTime(t time.Time) *util.TimeWrapper { - return &util.TimeWrapper{Time: t} -} diff --git a/pkg/doc/signature/signer/signer_interop.go b/pkg/doc/signature/signer/signer_interop.go deleted file mode 100644 index cbf4a73ee..000000000 --- a/pkg/doc/signature/signer/signer_interop.go +++ /dev/null @@ -1,20 +0,0 @@ -// +build ACAPyInterop - -/* -Copyright SecureKey Technologies Inc. All Rights Reserved. - -SPDX-License-Identifier: Apache-2.0 -*/ - -package signer - -import ( - "time" - - "github.com/hyperledger/aries-framework-go/pkg/doc/util" -) - -func wrapTime(t time.Time) *util.TimeWrapper { - tw, _ := util.ParseTimeWrapper(t.Format(time.RFC3339)) - return tw -} diff --git a/pkg/doc/signature/suite/api.go b/pkg/doc/signature/suite/api.go new file mode 100644 index 000000000..23d43b2a6 --- /dev/null +++ b/pkg/doc/signature/suite/api.go @@ -0,0 +1,73 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package suite + +import ( + "github.com/hyperledger/aries-framework-go/component/models/signature/api" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" + "github.com/hyperledger/aries-framework-go/spi/crypto" +) + +// SignatureSuite defines general signature suite structure. +type SignatureSuite = suite.SignatureSuite + +type signer interface { + // Sign will sign document and return signature + Sign(data []byte) ([]byte, error) + // Alg return alg. + Alg() string +} + +type verifier interface { + // Verify will verify a signature. + Verify(pubKeyValue *api.PublicKey, doc, signature []byte) error +} + +// Opt is the SignatureSuite option. +type Opt = suite.Opt + +// WithSigner defines a signer for the Signature Suite. +func WithSigner(s signer) Opt { + return suite.WithSigner(s) +} + +// WithVerifier defines a verifier for the Signature Suite. +func WithVerifier(v verifier) Opt { + return suite.WithVerifier(v) +} + +// WithCompactProof indicates that proof compaction is needed, by default it is not done. +func WithCompactProof() Opt { + return suite.WithCompactProof() +} + +// InitSuiteOptions initializes signature suite with options. +func InitSuiteOptions(signatureSuite *SignatureSuite, opts ...Opt) *SignatureSuite { + return suite.InitSuiteOptions(signatureSuite, opts...) +} + +// CryptoSigner defines signer based on crypto. +type CryptoSigner = suite.CryptoSigner + +// NewCryptoSigner creates a new CryptoSigner. +func NewCryptoSigner(cr crypto.Crypto, kh interface{}) *CryptoSigner { + return suite.NewCryptoSigner(cr, kh) +} + +// CryptoVerifier defines signature verifier based on crypto. +type CryptoVerifier = suite.CryptoVerifier + +// NewCryptoVerifier creates a new CryptoVerifier. +func NewCryptoVerifier(cr crypto.Crypto) *CryptoVerifier { + return suite.NewCryptoVerifier(cr) +} + +// ErrSignerNotDefined is returned when Sign() is called but signer option is not defined. +var ErrSignerNotDefined = suite.ErrSignerNotDefined + +// ErrVerifierNotDefined is returned when Verify() is called but verifier option is not defined. +var ErrVerifierNotDefined = suite.ErrVerifierNotDefined diff --git a/pkg/doc/signature/suite/bbsblssignature2020/bbsblssignature2020.go b/pkg/doc/signature/suite/bbsblssignature2020/bbsblssignature2020.go new file mode 100644 index 000000000..54e5cbdf5 --- /dev/null +++ b/pkg/doc/signature/suite/bbsblssignature2020/bbsblssignature2020.go @@ -0,0 +1,39 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +// Package bbsblssignature2020 implements the BBS+ Signature Suite 2020 signature suite +// (https://w3c-ccg.github.io/ldp-bbs2020) in conjunction with the signing and verification algorithms of the +// Linked Data Proofs. +// It uses the RDF Dataset Normalization Algorithm to transform the input document into its canonical form. +// It uses SHA-256 [RFC6234] as the statement digest algorithm. +// It uses BBS+ signature algorithm (https://mattrglobal.github.io/bbs-signatures-spec/). +// It uses BLS12-381 pairing-friendly curve (https://tools.ietf.org/html/draft-irtf-cfrg-pairing-friendly-curves-03). +package bbsblssignature2020 + +import ( + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite/bbsblssignature2020" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" +) + +// Suite implements BbsBlsSignature2020 signature suite. +type Suite = bbsblssignature2020.Suite + +const ( + // SignatureType is the BbsBlsSignature2020 type string. + SignatureType = "BbsBlsSignature2020" +) + +// New an instance of Linked Data Signatures for JWS suite. +func New(opts ...suite.Opt) *Suite { + return bbsblssignature2020.New(opts...) +} + +// NewG2PublicKeyVerifier creates a signature verifier that verifies a BbsBlsSignature2020 signature +// taking Bls12381G2Key2020 public key bytes as input. +func NewG2PublicKeyVerifier() *verifier.PublicKeyVerifier { + return bbsblssignature2020.NewG2PublicKeyVerifier() +} diff --git a/pkg/doc/signature/suite/bbsblssignatureproof2020/bbsblssignatureproof2020.go b/pkg/doc/signature/suite/bbsblssignatureproof2020/bbsblssignatureproof2020.go new file mode 100644 index 000000000..43a3b1365 --- /dev/null +++ b/pkg/doc/signature/suite/bbsblssignatureproof2020/bbsblssignatureproof2020.go @@ -0,0 +1,34 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +// Package bbsblssignatureproof2020 implements the BBS+ Signature Proof Suite 2020 signature suite +// (https://w3c-ccg.github.io/ldp-bbs2020) in conjunction with the signing and verification algorithms of the +// Linked Data Proofs. +// It uses the RDF Dataset Normalization Algorithm to transform the input document into its canonical form. +// It uses SHA-256 [RFC6234] as the statement digest algorithm. +// It uses BBS+ signature algorithm (https://mattrglobal.github.io/bbs-signatures-spec/). +// It uses BLS12-381 pairing-friendly curve (https://tools.ietf.org/html/draft-irtf-cfrg-pairing-friendly-curves-03). +package bbsblssignatureproof2020 + +import ( + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite/bbsblssignatureproof2020" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" +) + +// Suite implements BbsBlsSignatureProof2020 signature suite. +type Suite = bbsblssignatureproof2020.Suite + +// New an instance of Linked Data Signatures for the suite. +func New(opts ...suite.Opt) *Suite { + return bbsblssignatureproof2020.New(opts...) +} + +// NewG2PublicKeyVerifier creates a signature verifier that verifies a BbsBlsSignatureProof2020 signature +// taking Bls12381G2Key2020 public key bytes as input. +func NewG2PublicKeyVerifier(nonce []byte) *verifier.PublicKeyVerifier { + return bbsblssignatureproof2020.NewG2PublicKeyVerifier(nonce) +} diff --git a/pkg/doc/signature/suite/bbsblssignatureproof2020/signer_test.go b/pkg/doc/signature/suite/bbsblssignatureproof2020/signer_test.go index 4da5e7a75..a32be4132 100644 --- a/pkg/doc/signature/suite/bbsblssignatureproof2020/signer_test.go +++ b/pkg/doc/signature/suite/bbsblssignatureproof2020/signer_test.go @@ -16,10 +16,11 @@ import ( "github.com/btcsuite/btcutil/base58" "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite/bbsblssignatureproof2020" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" + "github.com/hyperledger/aries-framework-go/component/models/ld/testutil" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite/bbsblssignatureproof2020" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" + "github.com/hyperledger/aries-framework-go/pkg/doc/verifiable" - "github.com/hyperledger/aries-framework-go/pkg/internal/ldtestutil" ) //nolint:gochecknoglobals @@ -36,7 +37,7 @@ var ( docWithManyProofsJSON string //nolint:unused // re-enable test that uses this var (#2562) ) -//nolint +// nolint func TestSuite_SelectiveDisclosure(t *testing.T) { // pkBase58 from did:key:zUC724vuGvHpnCGFG1qqpXb81SiBLu3KLSqVzenwEZNPoY35i2Bscb8DLaVwHvRFs6F2NkNNXRcPWvqnPDUd9ukdjLkjZd3u9zzL4wDZDUpkPAatLDGLEYVo8kkAzuAKJQMr7N2 pkBase58 := "nEP2DEdbRaQ2r5Azeatui9MG6cj7JUHa8GD7khub4egHJREEuvj4Y8YG8w51LnhPEXxVV1ka93HpSLkVzeQuuPE1mH9oCMrqoHXAKGBsuDT1yJvj9cKgxxLCXiRRirCycki" @@ -61,7 +62,7 @@ func TestSuite_SelectiveDisclosure(t *testing.T) { t.Run("single BBS+ signature", func(t *testing.T) { docWithSelectiveDisclosure, err := s.SelectiveDisclosure(docMap, revealDocMap, nonce, - pubKeyResolver, ldtestutil.WithDocumentLoader(t)) + pubKeyResolver, testutil.WithDocumentLoader(t)) require.NoError(t, err) require.NotEmpty(t, docWithSelectiveDisclosure) require.Contains(t, docWithSelectiveDisclosure, proofField) @@ -93,7 +94,7 @@ func TestSuite_SelectiveDisclosure(t *testing.T) { } docWithSelectiveDisclosure, err := s.SelectiveDisclosure(docWithSeveralProofsMap, revealDocMap, nonce, - compositeResolver, ldtestutil.WithDocumentLoader(t)) + compositeResolver, testutil.WithDocumentLoader(t)) require.NoError(t, err) require.NotEmpty(t, docWithSelectiveDisclosure) require.Contains(t, docWithSelectiveDisclosure, proofField) @@ -114,7 +115,7 @@ func TestSuite_SelectiveDisclosure(t *testing.T) { docMap["bad"] = "example" docMap["proof"] = "example" - _, err := s.SelectiveDisclosure(docMap, revealDocMap, nonce, pubKeyResolver, ldtestutil.WithDocumentLoader(t)) + _, err := s.SelectiveDisclosure(docMap, revealDocMap, nonce, pubKeyResolver, testutil.WithDocumentLoader(t)) require.Error(t, err) }) @@ -128,7 +129,7 @@ func TestSuite_SelectiveDisclosure(t *testing.T) { } docWithSelectiveDisclosure, err := s.SelectiveDisclosure(docMapWithoutProof, revealDocMap, nonce, - pubKeyResolver, ldtestutil.WithDocumentLoader(t)) + pubKeyResolver, testutil.WithDocumentLoader(t)) require.Error(t, err) require.Contains(t, err.Error(), "document does not have a proof") require.Empty(t, docWithSelectiveDisclosure) @@ -146,7 +147,7 @@ func TestSuite_SelectiveDisclosure(t *testing.T) { } docWithSelectiveDisclosure, err := s.SelectiveDisclosure(docMapWithInvalidProof, revealDocMap, nonce, - pubKeyResolver, ldtestutil.WithDocumentLoader(t)) + pubKeyResolver, testutil.WithDocumentLoader(t)) require.Error(t, err) require.EqualError(t, err, "get BLS proofs: read document proofs: proof is not map or array of maps") require.Empty(t, docWithSelectiveDisclosure) @@ -174,7 +175,7 @@ func TestSuite_SelectiveDisclosure(t *testing.T) { } docWithSelectiveDisclosure, err := s.SelectiveDisclosure(docMapWithInvalidProofValue, revealDocMap, nonce, - pubKeyResolver, ldtestutil.WithDocumentLoader(t)) + pubKeyResolver, testutil.WithDocumentLoader(t)) require.Error(t, err) require.EqualError(t, err, "generate signature proof: derive BBS+ proof: parse signature: invalid size of signature") //nolint:lll require.Empty(t, docWithSelectiveDisclosure) @@ -202,7 +203,7 @@ func TestSuite_SelectiveDisclosure(t *testing.T) { } docWithSelectiveDisclosure, err := s.SelectiveDisclosure(docMapWithInvalidProofType, revealDocMap, nonce, - pubKeyResolver, ldtestutil.WithDocumentLoader(t)) + pubKeyResolver, testutil.WithDocumentLoader(t)) require.Error(t, err) require.EqualError(t, err, "no BbsBlsSignature2020 proof present") require.Empty(t, docWithSelectiveDisclosure) @@ -214,7 +215,7 @@ func TestSuite_SelectiveDisclosure(t *testing.T) { } docWithSelectiveDisclosure, err := s.SelectiveDisclosure(docMap, revealDocMap, nonce, - failingPublicKeyResolver, ldtestutil.WithDocumentLoader(t)) + failingPublicKeyResolver, testutil.WithDocumentLoader(t)) require.Error(t, err) require.EqualError(t, err, "generate signature proof: get public key and signature: resolve public key of BBS+ signature: public key not found") //nolint:lll require.Empty(t, docWithSelectiveDisclosure) @@ -228,7 +229,7 @@ func TestSuite_SelectiveDisclosure(t *testing.T) { require.NoError(t, err) docWithSelectiveDisclosure, err := s.SelectiveDisclosure(case18DocMap, case18RevealDocMap, case19Nonce, - pubKeyResolver, ldtestutil.WithDocumentLoader(t)) + pubKeyResolver, testutil.WithDocumentLoader(t)) require.NoError(t, err) require.NotEmpty(t, docWithSelectiveDisclosure) require.Contains(t, docWithSelectiveDisclosure, proofField) @@ -244,7 +245,7 @@ func TestSuite_SelectiveDisclosure(t *testing.T) { pubKeyFetcher := verifiable.SingleKey(pubKeyBytes, "Bls12381G2Key2020") - loader, err := ldtestutil.DocumentLoader() + loader, err := testutil.DocumentLoader() require.NoError(t, err) _, err = verifiable.ParseCredential(case18DerivationBytes, verifiable.WithPublicKeyFetcher(pubKeyFetcher), @@ -260,3 +261,21 @@ func toMap(t *testing.T, doc string) map[string]interface{} { return docMap } + +type testKeyResolver struct { + publicKey *verifier.PublicKey + variants map[string]*verifier.PublicKey + err error +} + +func (r *testKeyResolver) Resolve(id string) (*verifier.PublicKey, error) { + if r.err != nil { + return nil, r.err + } + + if len(r.variants) > 0 { + return r.variants[id], nil + } + + return r.publicKey, r.err +} diff --git a/pkg/doc/signature/suite/ecdsasecp256k1signature2019/ecdsasecp256k1signature2019.go b/pkg/doc/signature/suite/ecdsasecp256k1signature2019/ecdsasecp256k1signature2019.go new file mode 100644 index 000000000..def33f369 --- /dev/null +++ b/pkg/doc/signature/suite/ecdsasecp256k1signature2019/ecdsasecp256k1signature2019.go @@ -0,0 +1,32 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +// Package ecdsasecp256k1signature2019 implements the EcdsaSecp256k1Signature2019 signature suite +// for the Linked Data Signatures specification (https://w3c-dvcg.github.io/lds-ecdsa-secp256k1-2019/). +// It uses the RDF Dataset Normalization Algorithm to transform the input document into its canonical form. +// It uses SHA-256 [RFC6234] as the message digest algorithm. +// Supported signature algorithms depend on the signer/verifier provided as options to the New(). +package ecdsasecp256k1signature2019 + +import ( + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite/ecdsasecp256k1signature2019" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" +) + +// Suite implements EcdsaSecp256k1Signature2019 signature suite. +type Suite = ecdsasecp256k1signature2019.Suite + +// New an instance of Linked Data Signatures for JWS suite. +func New(opts ...suite.Opt) *Suite { + return ecdsasecp256k1signature2019.New(opts...) +} + +// NewPublicKeyVerifier creates a signature verifier that verifies a ECDSA secp256k1 signature +// taking Ed25519 public key bytes as input. +func NewPublicKeyVerifier() *verifier.PublicKeyVerifier { + return ecdsasecp256k1signature2019.NewPublicKeyVerifier() +} diff --git a/pkg/doc/signature/suite/ed25519signature2018/ed25519signature2018.go b/pkg/doc/signature/suite/ed25519signature2018/ed25519signature2018.go new file mode 100644 index 000000000..b8d80fd15 --- /dev/null +++ b/pkg/doc/signature/suite/ed25519signature2018/ed25519signature2018.go @@ -0,0 +1,37 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. +SPDX-License-Identifier: Apache-2.0 +*/ + +// Package ed25519signature2018 implements the Ed25519Signature2018 signature suite +// for the Linked Data Signatures [LD-SIGNATURES] specification. +// It uses the RDF Dataset Normalization Algorithm [RDF-DATASET-NORMALIZATION] +// to transform the input document into its canonical form. +// It uses SHA-256 [RFC6234] as the message digest algorithm and +// Ed25519 [ED25519] as the signature algorithm. +package ed25519signature2018 + +import ( + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite/ed25519signature2018" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" +) + +// Suite implements ed25519 signature suite. +type Suite = ed25519signature2018.Suite + +const ( + // SignatureType is the signature type for ed25519 keys. + SignatureType = ed25519signature2018.SignatureType +) + +// New an instance of ed25519 signature suite. +func New(opts ...suite.Opt) *Suite { + return ed25519signature2018.New(opts...) +} + +// NewPublicKeyVerifier creates a signature verifier that verifies a Ed25519 signature +// taking Ed25519 public key bytes as input. +func NewPublicKeyVerifier() *verifier.PublicKeyVerifier { + return ed25519signature2018.NewPublicKeyVerifier() +} diff --git a/pkg/doc/signature/suite/ed25519signature2020/ed25519signature2018.go b/pkg/doc/signature/suite/ed25519signature2020/ed25519signature2018.go new file mode 100644 index 000000000..2bad8b981 --- /dev/null +++ b/pkg/doc/signature/suite/ed25519signature2020/ed25519signature2018.go @@ -0,0 +1,37 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. +SPDX-License-Identifier: Apache-2.0 +*/ + +// Package ed25519signature2020 implements the Ed25519Signature2020 signature suite +// for the Linked Data Signatures [LD-SIGNATURES] specification. +// It uses the RDF Dataset Normalization Algorithm [RDF-DATASET-NORMALIZATION] +// to transform the input document into its canonical form. +// It uses SHA-256 [RFC6234] as the message digest algorithm and +// Ed25519 [ED25519] as the signature algorithm. +package ed25519signature2020 + +import ( + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite/ed25519signature2020" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" +) + +// Suite implements ed25519 signature suite. +type Suite = ed25519signature2020.Suite + +const ( + // SignatureType is the signature type for ed25519 keys. + SignatureType = ed25519signature2020.SignatureType +) + +// New an instance of ed25519 signature suite. +func New(opts ...suite.Opt) *Suite { + return ed25519signature2020.New(opts...) +} + +// NewPublicKeyVerifier creates a signature verifier that verifies a Ed25519 signature +// taking Ed25519 public key bytes as input. +func NewPublicKeyVerifier() *verifier.PublicKeyVerifier { + return ed25519signature2020.NewPublicKeyVerifier() +} diff --git a/pkg/doc/signature/suite/jsonwebsignature2020/jsonwebsignature2020.go b/pkg/doc/signature/suite/jsonwebsignature2020/jsonwebsignature2020.go new file mode 100644 index 000000000..0b9fb0138 --- /dev/null +++ b/pkg/doc/signature/suite/jsonwebsignature2020/jsonwebsignature2020.go @@ -0,0 +1,42 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. +SPDX-License-Identifier: Apache-2.0 +*/ + +// Package jsonwebsignature2020 implements the JsonWebSignature2020 signature suite +// for the Linked Data Signatures specification (https://github.com/transmute-industries/lds-jws2020). +// It uses the RDF Dataset Normalization Algorithm +// to transform the input document into its canonical form. +// It uses SHA-256 [RFC6234] as the message digest algorithm. +// Supported signature algorithms depend on the signer/verifier provided as options to the New(). +// According to the suite specification, signer/verifier must support the following algorithms: +// kty | crvOrSize | alg +// OKP | Ed25519 | EdDSA +// EC | secp256k1 | ES256K +// RSA | 2048 | PS256 +// EC | P-256 | ES256 +// EC | P-384 | ES384 +// EC | P-521 | ES512 +package jsonwebsignature2020 + +import ( + "github.com/hyperledger/aries-framework-go/component/models/signature/suite" + "github.com/hyperledger/aries-framework-go/component/models/signature/suite/jsonwebsignature2020" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" +) + +// Suite implements jsonWebSignature2020 signature suite. +type Suite = jsonwebsignature2020.Suite + +// New an instance of Linked Data Signatures for JWS suite. +func New(opts ...suite.Opt) *Suite { + return jsonwebsignature2020.New(opts...) +} + +// NewPublicKeyVerifier creates a signature verifier that verifies a Ed25519 / EC (P-256, P-384, P-521, secp256k1) / RSA +// signature taking public key bytes and / or JSON Web Key as input. +// The list of Supported JWS algorithms of JsonWebSignature2020 is defined here: +// https://github.com/transmute-industries/lds-jws2020#supported-jws-algs +func NewPublicKeyVerifier() *verifier.PublicKeyVerifier { + return jsonwebsignature2020.NewPublicKeyVerifier() +} diff --git a/pkg/doc/signature/verifier/api.go b/pkg/doc/signature/verifier/api.go new file mode 100644 index 000000000..ba1678a90 --- /dev/null +++ b/pkg/doc/signature/verifier/api.go @@ -0,0 +1,131 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. +SPDX-License-Identifier: Apache-2.0 +*/ + +package verifier + +import ( + "github.com/hyperledger/aries-framework-go/component/models/signature/api" + "github.com/hyperledger/aries-framework-go/component/models/signature/verifier" +) + +// TODO pull SignatureSuite interface and PublicKey type out into an API package + +// SignatureSuite encapsulates signature suite methods required for signature verification. +type SignatureSuite = api.SignatureSuite + +// PublicKey contains a result of public key resolution. +type PublicKey = api.PublicKey + +// keyResolver encapsulates key resolution. +type keyResolver interface { + // Resolve will return public key bytes and the type of public key + Resolve(id string) (*api.PublicKey, error) +} + +// DocumentVerifier implements JSON LD document proof verification. +type DocumentVerifier = verifier.DocumentVerifier + +// New returns new instance of document verifier. +func New(resolver keyResolver, suites ...SignatureSuite) (*DocumentVerifier, error) { + return verifier.New(resolver, suites...) +} + +// PublicKeyVerifier makes signature verification using the public key +// based on one or several signature algorithms. +type PublicKeyVerifier = verifier.PublicKeyVerifier + +// PublicKeyVerifierOpt is the PublicKeyVerifier functional option. +type PublicKeyVerifierOpt = verifier.PublicKeyVerifierOpt + +// NewPublicKeyVerifier creates a new PublicKeyVerifier based on single signature algorithm. +func NewPublicKeyVerifier(sigAlg SignatureVerifier, opts ...PublicKeyVerifierOpt) *PublicKeyVerifier { + return verifier.NewPublicKeyVerifier(sigAlg, opts...) +} + +// NewCompositePublicKeyVerifier creates a new PublicKeyVerifier based on one or more signature algorithms. +func NewCompositePublicKeyVerifier(verifiers []SignatureVerifier, opts ...PublicKeyVerifierOpt) *PublicKeyVerifier { + return verifier.NewCompositePublicKeyVerifier(verifiers, opts...) +} + +// WithExactPublicKeyType option is used to check the type of the PublicKey. +func WithExactPublicKeyType(jwkType string) PublicKeyVerifierOpt { + return verifier.WithExactPublicKeyType(jwkType) +} + +// SignatureVerifier make signature verification of a certain algorithm (e.g. Ed25519 or ECDSA secp256k1). +type SignatureVerifier = verifier.SignatureVerifier + +// Ed25519SignatureVerifier verifies a Ed25519 signature taking Ed25519 public key bytes as input. +type Ed25519SignatureVerifier = verifier.Ed25519SignatureVerifier + +// NewEd25519SignatureVerifier creates a new Ed25519SignatureVerifier. +func NewEd25519SignatureVerifier() *Ed25519SignatureVerifier { + return verifier.NewEd25519SignatureVerifier() +} + +// RSAPS256SignatureVerifier verifies a Ed25519 signature taking RSA public key bytes as input. +type RSAPS256SignatureVerifier = verifier.RSAPS256SignatureVerifier + +// NewRSAPS256SignatureVerifier creates a new RSAPS256SignatureVerifier. +func NewRSAPS256SignatureVerifier() *RSAPS256SignatureVerifier { + return verifier.NewRSAPS256SignatureVerifier() +} + +// RSARS256SignatureVerifier verifies a Ed25519 signature taking RSA public key bytes as input. +type RSARS256SignatureVerifier = verifier.RSARS256SignatureVerifier + +// NewRSARS256SignatureVerifier creates a new RSARS256SignatureVerifier. +func NewRSARS256SignatureVerifier() *RSARS256SignatureVerifier { + return verifier.NewRSARS256SignatureVerifier() +} + +// ECDSASignatureVerifier verifies elliptic curve signatures. +type ECDSASignatureVerifier = verifier.ECDSASignatureVerifier + +// NewECDSASecp256k1SignatureVerifier creates a new signature verifier that verifies a ECDSA secp256k1 signature +// taking public key bytes and JSON Web Key as input. +func NewECDSASecp256k1SignatureVerifier() *ECDSASignatureVerifier { + return verifier.NewECDSASecp256k1SignatureVerifier() +} + +// NewECDSAES256SignatureVerifier creates a new signature verifier that verifies a ECDSA P-256 signature +// taking public key bytes and JSON Web Key as input. +func NewECDSAES256SignatureVerifier() *ECDSASignatureVerifier { + return verifier.NewECDSAES256SignatureVerifier() +} + +// NewECDSAES384SignatureVerifier creates a new signature verifier that verifies a ECDSA P-384 signature +// taking public key bytes and JSON Web Key as input. +func NewECDSAES384SignatureVerifier() *ECDSASignatureVerifier { + return verifier.NewECDSAES384SignatureVerifier() +} + +// NewECDSAES521SignatureVerifier creates a new signature verifier that verifies a ECDSA P-521 signature +// taking public key bytes and JSON Web Key as input. +func NewECDSAES521SignatureVerifier() *ECDSASignatureVerifier { + return verifier.NewECDSAES521SignatureVerifier() +} + +// NewBBSG2SignatureVerifier creates a new BBSG2SignatureVerifier. +func NewBBSG2SignatureVerifier() *BBSG2SignatureVerifier { + return verifier.NewBBSG2SignatureVerifier() +} + +// BBSG2SignatureVerifier is a signature verifier that verifies a BBS+ Signature +// taking Bls12381G2Key2020 public key bytes as input. +// The reference implementation https://github.com/mattrglobal/bls12381-key-pair supports public key bytes only, +// JWK is not supported. +type BBSG2SignatureVerifier = verifier.BBSG2SignatureVerifier + +// NewBBSG2SignatureProofVerifier creates a new BBSG2SignatureProofVerifier. +func NewBBSG2SignatureProofVerifier(nonce []byte) *BBSG2SignatureProofVerifier { + return verifier.NewBBSG2SignatureProofVerifier(nonce) +} + +// BBSG2SignatureProofVerifier is a signature verifier that verifies a BBS+ Signature Proof +// taking Bls12381G2Key2020 public key bytes as input. +// The reference implementation https://github.com/mattrglobal/bls12381-key-pair supports public key bytes only, +// JWK is not supported. +type BBSG2SignatureProofVerifier = verifier.BBSG2SignatureProofVerifier diff --git a/pkg/doc/util/jwkkid/kid_creator.go b/pkg/doc/util/jwkkid/kid_creator.go index 3c82c8c87..b568913ef 100644 --- a/pkg/doc/util/jwkkid/kid_creator.go +++ b/pkg/doc/util/jwkkid/kid_creator.go @@ -7,10 +7,9 @@ SPDX-License-Identifier: Apache-2.0 package jwkkid import ( + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/util/jwkkid" - - "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" - "github.com/hyperledger/aries-framework-go/pkg/kms" + "github.com/hyperledger/aries-framework-go/spi/kms" ) // CreateKID creates a KID value based on the marshalled keyBytes of type kt. This function should be called for diff --git a/pkg/doc/util/signature/signature.go b/pkg/doc/util/signature/signature.go new file mode 100644 index 000000000..198b3177b --- /dev/null +++ b/pkg/doc/util/signature/signature.go @@ -0,0 +1,46 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package signature + +import ( + "crypto/ed25519" + "crypto/elliptic" + + "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" + "github.com/hyperledger/aries-framework-go/component/models/signature/util" + cryptoapi "github.com/hyperledger/aries-framework-go/spi/crypto" + kmsapi "github.com/hyperledger/aries-framework-go/spi/kms" +) + +// Signer defines generic signer. +type Signer = util.Signer + +// NewCryptoSigner creates a new signer based on crypto if possible. +func NewCryptoSigner(crypto cryptoapi.Crypto, kms kmsapi.KeyManager, keyType kmsapi.KeyType) (Signer, error) { + return util.NewCryptoSigner(crypto, kms, keyType) +} + +// NewSigner creates a new signer. +func NewSigner(keyType kmsapi.KeyType) (Signer, error) { + return util.NewSigner(keyType) +} + +// GetSigner returns a new Signer based on privateKey. +// For case ed25519.PrivateKey pubKey is nil. +func GetSigner(privateKeyJWK *jwk.JWK) (Signer, error) { + return util.GetSigner(privateKeyJWK) +} + +// GetEd25519Signer returns Ed25519 Signer with predefined private and public keys. +func GetEd25519Signer(privKey ed25519.PrivateKey, pubKey ed25519.PublicKey) Signer { + return util.GetEd25519Signer(privKey, pubKey) +} + +// MapECCurveToKeyType makes a mapping of Elliptic Curve to KeyType of kms. +func MapECCurveToKeyType(curve elliptic.Curve) (kmsapi.KeyType, error) { + return util.MapECCurveToKeyType(curve) +} diff --git a/pkg/doc/util/timewrapper.go b/pkg/doc/util/timewrapper.go new file mode 100644 index 000000000..72e20d3e7 --- /dev/null +++ b/pkg/doc/util/timewrapper.go @@ -0,0 +1,53 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package util + +import ( + "time" + + afgotime "github.com/hyperledger/aries-framework-go/component/models/util/time" +) + +// TimeWrapper overrides marshalling of time.Time. If a TimeWrapper is created from a time string, or +// unmarshalled from JSON, it saves the string literal, which it uses when marshalling. +// If a TimeWrapper is created using NewTime or a struct literal, it marshals with the default +// time.RFC3339 format. +type TimeWrapper = afgotime.TimeWrapper + +// TimeWithTrailingZeroMsec overrides marshalling of time.Time. It keeps a format of initial unmarshalling +// in case when date has zero a fractional second (e.g. ".000"). +// For example, time.Time marshals 2018-03-15T00:00:00.000Z to 2018-03-15T00:00:00Z +// while TimeWithTrailingZeroMsec marshals to the initial 2018-03-15T00:00:00.000Z value. +// +// Deprecated: use TimeWrapper instead. +type TimeWithTrailingZeroMsec = afgotime.TimeWithTrailingZeroMsec + +// NewTime creates a TimeWrapper wrapped around the given time.Time. +// It functions as a normal time.Time object. +func NewTime(t time.Time) *TimeWrapper { + return afgotime.NewTime(t) +} + +// NewTimeWithTrailingZeroMsec creates a TimeWrapper wrapped around the given time.Time. +// +// Deprecated: use NewTime instead. For sub-zero precision, +// use ParseTimeWrapper on a string with the desired precision. +func NewTimeWithTrailingZeroMsec(t time.Time, _ int) *TimeWrapper { + return afgotime.NewTimeWithTrailingZeroMsec(t, 0) +} + +// ParseTimeWithTrailingZeroMsec parses a formatted string and returns the time value it represents. +// +// Deprecated: use ParseTimeWrapper instead. +func ParseTimeWithTrailingZeroMsec(timeStr string) (*TimeWrapper, error) { + return afgotime.ParseTimeWithTrailingZeroMsec(timeStr) +} + +// ParseTimeWrapper parses a formatted string and returns the time value it represents. +func ParseTimeWrapper(timeStr string) (*TimeWrapper, error) { + return afgotime.ParseTimeWrapper(timeStr) +} diff --git a/pkg/doc/verifiable/credential_jwt_proof_test.go b/pkg/doc/verifiable/credential_jwt_proof_test.go index bee417e46..0cbd433f2 100644 --- a/pkg/doc/verifiable/credential_jwt_proof_test.go +++ b/pkg/doc/verifiable/credential_jwt_proof_test.go @@ -14,7 +14,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/common/model" + "github.com/hyperledger/aries-framework-go/component/models/did/endpoint" "github.com/hyperledger/aries-framework-go/pkg/doc/did" "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" "github.com/hyperledger/aries-framework-go/pkg/kms" @@ -249,7 +249,7 @@ func createDIDKeyFetcher(t *testing.T, pub ed25519.PublicKey, didID string) Publ { ID: fmt.Sprintf(didServiceID, id, 1), Type: "did-communication", - ServiceEndpoint: model.NewDIDCommV1Endpoint("http://localhost:47582"), + ServiceEndpoint: endpoint.NewDIDCommV1Endpoint("http://localhost:47582"), Priority: 0, RecipientKeys: []string{pubKeyID}, }, diff --git a/pkg/doc/verifiable/linked_data_proof.go b/pkg/doc/verifiable/linked_data_proof.go index 1bd6f8b9b..c42c71f0e 100644 --- a/pkg/doc/verifiable/linked_data_proof.go +++ b/pkg/doc/verifiable/linked_data_proof.go @@ -11,8 +11,8 @@ import ( "strings" "time" + "github.com/hyperledger/aries-framework-go/component/models/ld/proof" "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/proof" "github.com/hyperledger/aries-framework-go/pkg/doc/signature/signer" "github.com/hyperledger/aries-framework-go/pkg/doc/signature/verifier" ) diff --git a/pkg/internal/gomocks/framework/aries/api/vdr/mocks.gen.go b/pkg/internal/gomocks/framework/aries/api/vdr/mocks.gen.go index 8d3dd2238..e2d831f84 100644 --- a/pkg/internal/gomocks/framework/aries/api/vdr/mocks.gen.go +++ b/pkg/internal/gomocks/framework/aries/api/vdr/mocks.gen.go @@ -8,7 +8,7 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" - did "github.com/hyperledger/aries-framework-go/pkg/doc/did" + did "github.com/hyperledger/aries-framework-go/component/models/did" vdr "github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr" ) diff --git a/pkg/internal/gomocks/store/did/mocks.gen.go b/pkg/internal/gomocks/store/did/mocks.gen.go index e85919bc1..0e333b870 100644 --- a/pkg/internal/gomocks/store/did/mocks.gen.go +++ b/pkg/internal/gomocks/store/did/mocks.gen.go @@ -8,7 +8,7 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" - did "github.com/hyperledger/aries-framework-go/pkg/doc/did" + did "github.com/hyperledger/aries-framework-go/component/models/did" ) // MockConnectionStore is a mock of ConnectionStore interface. diff --git a/pkg/internal/ldtestutil/ldtestutil.go b/pkg/internal/ldtestutil/ldtestutil.go new file mode 100644 index 000000000..97d084d08 --- /dev/null +++ b/pkg/internal/ldtestutil/ldtestutil.go @@ -0,0 +1,32 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package ldtestutil + +import ( + "testing" + + "github.com/hyperledger/aries-framework-go/component/models/ld/testutil" + + ldcontext "github.com/hyperledger/aries-framework-go/component/models/ld/context" + "github.com/hyperledger/aries-framework-go/component/models/ld/documentloader" + "github.com/hyperledger/aries-framework-go/component/models/ld/processor" +) + +// WithDocumentLoader returns an option with a custom JSON-LD document loader preloaded with embedded contexts. +func WithDocumentLoader(t *testing.T) processor.Opts { + return testutil.WithDocumentLoader(t) +} + +// DocumentLoader returns JSON-LD document loader preloaded with embedded contexts and provided extra contexts. +func DocumentLoader(extraContexts ...ldcontext.Document) (*documentloader.DocumentLoader, error) { + return testutil.DocumentLoader(extraContexts...) +} + +// Contexts returns test JSON-LD contexts. +func Contexts() []ldcontext.Document { + return testutil.Contexts() +} diff --git a/pkg/mock/crypto/crypto.go b/pkg/mock/crypto/crypto.go new file mode 100644 index 000000000..e60cc14db --- /dev/null +++ b/pkg/mock/crypto/crypto.go @@ -0,0 +1,25 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package crypto + +import ( + mockcrypto "github.com/hyperledger/aries-framework-go/component/kmscrypto/mock/crypto" +) + +// SignFunc mocks Crypto's Sign() function, it's useful for executing custom signing with the help of SignKey. +type SignFunc = mockcrypto.SignFunc + +// BBSSignFunc mocks Crypto's BBSSign() function, it's useful for executing custom BBS+ signing with the help of +// Signing private Key. +type BBSSignFunc = mockcrypto.BBSSignFunc + +// DeriveProofFunc mocks Crypto's DeriveProofFunc() function, it's useful for executing custom BBS+ signing with the +// help of Signing public Key. +type DeriveProofFunc = mockcrypto.DeriveProofFunc + +// Crypto mock. +type Crypto = mockcrypto.Crypto diff --git a/pkg/mock/diddoc/mock_diddoc.go b/pkg/mock/diddoc/mock_diddoc.go index bbce5cd25..f84ee1ecf 100644 --- a/pkg/mock/diddoc/mock_diddoc.go +++ b/pkg/mock/diddoc/mock_diddoc.go @@ -13,7 +13,7 @@ import ( "github.com/btcsuite/btcutil/base58" "github.com/stretchr/testify/require" - "github.com/hyperledger/aries-framework-go/pkg/common/model" + "github.com/hyperledger/aries-framework-go/component/models/did/endpoint" "github.com/hyperledger/aries-framework-go/pkg/doc/did" "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" "github.com/hyperledger/aries-framework-go/pkg/vdr/fingerprint" @@ -29,14 +29,14 @@ func GetMockDIDDoc(t *testing.T, isDIDCommV2 bool) *did.Doc { services := []did.Service{ { - ServiceEndpoint: model.NewDIDCommV1Endpoint("https://localhost:8090"), + ServiceEndpoint: endpoint.NewDIDCommV1Endpoint("https://localhost:8090"), RoutingKeys: []string{MockDIDKey(t)}, Type: "did-communication", Priority: 0, RecipientKeys: []string{MockDIDKey(t)}, }, { - ServiceEndpoint: model.NewDIDCommV1Endpoint("https://localhost:9090"), + ServiceEndpoint: endpoint.NewDIDCommV1Endpoint("https://localhost:9090"), RoutingKeys: []string{MockDIDKey(t)}, Type: "did-communication", Priority: 1, @@ -45,7 +45,7 @@ func GetMockDIDDoc(t *testing.T, isDIDCommV2 bool) *did.Doc { } if isDIDCommV2 { - services[0].ServiceEndpoint = model.NewDIDCommV2Endpoint([]model.DIDCommV2Endpoint{ + services[0].ServiceEndpoint = endpoint.NewDIDCommV2Endpoint([]endpoint.DIDCommV2Endpoint{ { URI: "https://localhost:8090", Accept: []string{"didcomm/v2"}, @@ -118,13 +118,13 @@ func GetLegacyInteropMockDIDDoc(t *testing.T, id string, ed25519PubKey []byte) * ID: peerDID, Service: []did.Service{ { - ServiceEndpoint: model.NewDIDCommV1Endpoint("https://localhost:8090"), + ServiceEndpoint: endpoint.NewDIDCommV1Endpoint("https://localhost:8090"), Type: "did-communication", Priority: 0, RecipientKeys: []string{pubKeyBase58}, }, { - ServiceEndpoint: model.NewDIDCommV1Endpoint("https://localhost:8090"), + ServiceEndpoint: endpoint.NewDIDCommV1Endpoint("https://localhost:8090"), Type: "IndyAgent", Priority: 0, RecipientKeys: []string{pubKeyBase58}, @@ -178,7 +178,7 @@ func GetMockDIDDocWithDIDCommV2Bloc(t *testing.T, id string) *did.Doc { ID: peerDID, Service: []did.Service{ { - ServiceEndpoint: model.NewDIDCommV2Endpoint([]model.DIDCommV2Endpoint{{ + ServiceEndpoint: endpoint.NewDIDCommV2Endpoint([]endpoint.DIDCommV2Endpoint{{ URI: "https://localhost:8090", Accept: []string{"didcomm/v2"}, RoutingKeys: []string{MockDIDKey(t)}, @@ -244,7 +244,7 @@ func GetMockIndyDoc(t *testing.T) *did.Doc { Type: "IndyAgent", Priority: 0, RecipientKeys: []string{"6SFxbqdqGKtVVmLvXDnq9JP4ziZCG2fJzETpMYHt1VNx"}, - ServiceEndpoint: model.NewDIDCommV1Endpoint("https://localhost:8090"), + ServiceEndpoint: endpoint.NewDIDCommV1Endpoint("https://localhost:8090"), }, }, Authentication: []did.Verification{ diff --git a/pkg/mock/kms/kms.go b/pkg/mock/kms/kms.go new file mode 100644 index 000000000..73d738d61 --- /dev/null +++ b/pkg/mock/kms/kms.go @@ -0,0 +1,36 @@ +/* + Copyright SecureKey Technologies Inc. All Rights Reserved. + + SPDX-License-Identifier: Apache-2.0 +*/ + +package kms + +import ( + "github.com/google/tink/go/keyset" + + mockkms "github.com/hyperledger/aries-framework-go/component/kmscrypto/mock/kms" + "github.com/hyperledger/aries-framework-go/spi/secretlock" + "github.com/hyperledger/aries-framework-go/spi/storage" +) + +// KeyManager mocks a local Key Management Service + ExportableKeyManager. +type KeyManager = mockkms.KeyManager + +// CreateMockAESGCMKeyHandle is a utility function that returns a mock key (for tests only, not registered in Tink). +func CreateMockAESGCMKeyHandle() (*keyset.Handle, error) { + return mockkms.CreateMockAESGCMKeyHandle() +} + +// CreateMockED25519KeyHandle is a utility function that returns a mock key (for tests only, not registered in Tink). +func CreateMockED25519KeyHandle() (*keyset.Handle, error) { + return mockkms.CreateMockED25519KeyHandle() +} + +// Provider provides mock Provider implementation. +type Provider = mockkms.Provider + +// NewProviderForKMS creates a new mock Provider to create a KMS. +func NewProviderForKMS(storeProvider storage.Provider, secretLock secretlock.Service) (*Provider, error) { + return mockkms.NewProviderForKMS(storeProvider, secretLock) +} diff --git a/pkg/mock/kms/mock_kms.go b/pkg/mock/kms/mock_kms.go deleted file mode 100644 index 9cba07df5..000000000 --- a/pkg/mock/kms/mock_kms.go +++ /dev/null @@ -1,175 +0,0 @@ -/* - Copyright SecureKey Technologies Inc. All Rights Reserved. - - SPDX-License-Identifier: Apache-2.0 -*/ - -package kms - -import ( - "fmt" - - "github.com/golang/protobuf/proto" - "github.com/google/tink/go/keyset" - tinkpb "github.com/google/tink/go/proto/tink_go_proto" - "github.com/google/tink/go/testkeyset" - "github.com/google/tink/go/testutil" - - kmsservice "github.com/hyperledger/aries-framework-go/pkg/kms" - "github.com/hyperledger/aries-framework-go/pkg/secretlock" - "github.com/hyperledger/aries-framework-go/spi/storage" -) - -// KeyManager mocks a local Key Management Service + ExportableKeyManager. -type KeyManager struct { - CreateKeyID string - CreateKeyValue *keyset.Handle - CreateKeyErr error - CreateKeyFn func(kt kmsservice.KeyType) (string, interface{}, error) - GetKeyValue *keyset.Handle - GetKeyErr error - RotateKeyID string - RotateKeyValue *keyset.Handle - RotateKeyErr error - ExportPubKeyBytesErr error - ExportPubKeyBytesValue []byte - ExportPubKeyTypeValue kmsservice.KeyType - CrAndExportPubKeyValue []byte - CrAndExportPubKeyID string - CrAndExportPubKeyErr error - PubKeyBytesToHandleErr error - PubKeyBytesToHandleValue *keyset.Handle - ImportPrivateKeyErr error - ImportPrivateKeyID string - ImportPrivateKeyValue *keyset.Handle -} - -// Create a new mock ey/keyset/key handle for the type kt. -func (k *KeyManager) Create(kt kmsservice.KeyType, opts ...kmsservice.KeyOpts) (string, interface{}, error) { - if k.CreateKeyErr != nil { - return "", nil, k.CreateKeyErr - } - - if k.CreateKeyFn != nil { - return k.CreateKeyFn(kt) - } - - return k.CreateKeyID, k.CreateKeyValue, nil -} - -// Get a mock key handle for the given keyID. -func (k *KeyManager) Get(keyID string) (interface{}, error) { - if k.GetKeyErr != nil { - return nil, k.GetKeyErr - } - - return k.GetKeyValue, nil -} - -// Rotate returns a mocked rotated keyset handle and its ID. -func (k *KeyManager) Rotate(kt kmsservice.KeyType, keyID string, - opts ...kmsservice.KeyOpts) (string, interface{}, error) { - if k.RotateKeyErr != nil { - return "", nil, k.RotateKeyErr - } - - return k.RotateKeyID, k.RotateKeyValue, nil -} - -// ExportPubKeyBytes will return a mocked []bytes public key. -func (k *KeyManager) ExportPubKeyBytes(keyID string) ([]byte, kmsservice.KeyType, error) { - if k.ExportPubKeyBytesErr != nil { - return nil, "", k.ExportPubKeyBytesErr - } - - return k.ExportPubKeyBytesValue, k.ExportPubKeyTypeValue, nil -} - -// CreateAndExportPubKeyBytes return a mocked kid and []byte public key. -func (k *KeyManager) CreateAndExportPubKeyBytes(kt kmsservice.KeyType, - opts ...kmsservice.KeyOpts) (string, []byte, error) { - if k.CrAndExportPubKeyErr != nil { - return "", nil, k.CrAndExportPubKeyErr - } - - return k.CrAndExportPubKeyID, k.CrAndExportPubKeyValue, nil -} - -// PubKeyBytesToHandle will return a mocked keyset.Handle representing a public key handle. -func (k *KeyManager) PubKeyBytesToHandle(pubKey []byte, keyType kmsservice.KeyType, - opts ...kmsservice.KeyOpts) (interface{}, error) { - if k.PubKeyBytesToHandleErr != nil { - return nil, k.PubKeyBytesToHandleErr - } - - return k.PubKeyBytesToHandleValue, nil -} - -// ImportPrivateKey will emulate importing a private key and returns a mocked keyID, private key handle. -func (k *KeyManager) ImportPrivateKey(privKey interface{}, keyType kmsservice.KeyType, - opts ...kmsservice.PrivateKeyOpts) (string, interface{}, error) { - if k.ImportPrivateKeyErr != nil { - return "", nil, k.ImportPrivateKeyErr - } - - return k.ImportPrivateKeyID, k.ImportPrivateKeyValue, nil -} - -func createMockKeyHandle(ks *tinkpb.Keyset) (*keyset.Handle, error) { - primaryKey := ks.Key[0] - - if primaryKey.OutputPrefixType == tinkpb.OutputPrefixType_RAW { - return nil, fmt.Errorf("expect a non-raw key") - } - - return testkeyset.NewHandle(ks) -} - -// CreateMockAESGCMKeyHandle is a utility function that returns a mock key (for tests only, not registered in Tink). -func CreateMockAESGCMKeyHandle() (*keyset.Handle, error) { - ks := testutil.NewTestAESGCMKeyset(tinkpb.OutputPrefixType_TINK) - - return createMockKeyHandle(ks) -} - -// CreateMockED25519KeyHandle is a utility function that returns a mock key (for tests only, not registered in Tink). -func CreateMockED25519KeyHandle() (*keyset.Handle, error) { - serializedKey, err := proto.Marshal(testutil.NewED25519PrivateKey()) - if err != nil { - return nil, err - } - - ks := testutil.NewTestKeyset(testutil.NewKeyData(testutil.ED25519SignerTypeURL, serializedKey, - tinkpb.KeyData_ASYMMETRIC_PRIVATE), tinkpb.OutputPrefixType_TINK) - - return createMockKeyHandle(ks) -} - -// Provider provides mock Provider implementation. -type Provider struct { - storeProvider kmsservice.Store - secretLock secretlock.Service -} - -// StorageProvider return a storage provider. -func (p *Provider) StorageProvider() kmsservice.Store { - return p.storeProvider -} - -// SecretLock returns a secret lock service. -func (p *Provider) SecretLock() secretlock.Service { - return p.secretLock -} - -// NewProviderForKMS creates a new mock Provider to create a KMS. -func NewProviderForKMS(storeProvider storage.Provider, secretLock secretlock.Service) (*Provider, error) { - kmsStore, err := kmsservice.NewAriesProviderWrapper(storeProvider) - if err != nil { - return nil, err - } - - return &Provider{ - storeProvider: kmsStore, - secretLock: secretLock, - }, nil -} diff --git a/pkg/mock/ld/ld.go b/pkg/mock/ld/ld.go new file mode 100644 index 000000000..8ab7e6191 --- /dev/null +++ b/pkg/mock/ld/ld.go @@ -0,0 +1,30 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package ld + +import ( + "github.com/hyperledger/aries-framework-go/component/models/ld/mock" +) + +// MockContextStore is a mock JSON-LD context store. +type MockContextStore = mock.ContextStore + +// NewMockContextStore returns a new instance of MockContextStore. +func NewMockContextStore() *MockContextStore { + return mock.NewMockContextStore() +} + +// MockRemoteProviderStore is a mock remote JSON-LD context provider store. +type MockRemoteProviderStore = mock.RemoteProviderStore + +// NewMockRemoteProviderStore returns a new instance of MockRemoteProviderStore. +func NewMockRemoteProviderStore() *MockRemoteProviderStore { + return mock.NewMockRemoteProviderStore() +} + +// MockService is a mock JSON-LD service. +type MockService = mock.Service diff --git a/pkg/mock/ld/mock_remote_provider_store.go b/pkg/mock/ld/mock_remote_provider_store.go deleted file mode 100644 index 14c7d4d23..000000000 --- a/pkg/mock/ld/mock_remote_provider_store.go +++ /dev/null @@ -1,105 +0,0 @@ -/* -Copyright SecureKey Technologies Inc. All Rights Reserved. - -SPDX-License-Identifier: Apache-2.0 -*/ - -package ld - -import ( - "github.com/google/uuid" - - mockstorage "github.com/hyperledger/aries-framework-go/pkg/mock/storage" - "github.com/hyperledger/aries-framework-go/pkg/store/ld" - "github.com/hyperledger/aries-framework-go/spi/storage" -) - -// MockRemoteProviderStore is a mock remote JSON-LD context provider store. -type MockRemoteProviderStore struct { - Store *mockstorage.MockStore - ErrGet error - ErrGetAll error - ErrSave error - ErrDelete error -} - -// NewMockRemoteProviderStore returns a new instance of MockRemoteProviderStore. -func NewMockRemoteProviderStore() *MockRemoteProviderStore { - return &MockRemoteProviderStore{ - Store: &mockstorage.MockStore{ - Store: make(map[string]mockstorage.DBEntry), - }, - } -} - -// Get returns a remote provider record from the underlying storage. -func (m *MockRemoteProviderStore) Get(id string) (*ld.RemoteProviderRecord, error) { - if m.ErrGet != nil { - return nil, m.ErrGet - } - - b, err := m.Store.Get(id) - if err != nil { - return nil, err - } - - return &ld.RemoteProviderRecord{ - ID: id, - Endpoint: string(b), - }, nil -} - -// GetAll returns all remote provider records from the underlying storage. -func (m *MockRemoteProviderStore) GetAll() ([]ld.RemoteProviderRecord, error) { - if m.ErrGetAll != nil { - return nil, m.ErrGetAll - } - - var records []ld.RemoteProviderRecord - - for k, v := range m.Store.Store { - records = append(records, ld.RemoteProviderRecord{ - ID: k, - Endpoint: string(v.Value), - }) - } - - return records, nil -} - -// Save creates a new remote provider record and saves it to the underlying storage. -// If the record with specified endpoint already exists it is returned to the caller. -func (m *MockRemoteProviderStore) Save(endpoint string) (*ld.RemoteProviderRecord, error) { - if m.ErrSave != nil { - return nil, m.ErrSave - } - - for k, v := range m.Store.Store { - if string(v.Value) == endpoint { - return &ld.RemoteProviderRecord{ - ID: k, - Endpoint: string(v.Value), - }, nil - } - } - - id := uuid.New().String() - - if err := m.Store.Put(id, []byte(endpoint), storage.Tag{Name: ld.RemoteProviderRecordTag}); err != nil { - return nil, err - } - - return &ld.RemoteProviderRecord{ - ID: id, - Endpoint: endpoint, - }, nil -} - -// Delete deletes a remote provider record in the underlying storage. -func (m *MockRemoteProviderStore) Delete(id string) error { - if m.ErrDelete != nil { - return m.ErrDelete - } - - return m.Store.Delete(id) -} diff --git a/pkg/mock/ld/mock_service.go b/pkg/mock/ld/mock_service.go deleted file mode 100644 index 72487fb87..000000000 --- a/pkg/mock/ld/mock_service.go +++ /dev/null @@ -1,79 +0,0 @@ -/* -Copyright SecureKey Technologies Inc. All Rights Reserved. - -SPDX-License-Identifier: Apache-2.0 -*/ - -package ld - -import ( - "github.com/hyperledger/aries-framework-go/pkg/doc/ldcontext" - "github.com/hyperledger/aries-framework-go/pkg/doc/ldcontext/remote" - "github.com/hyperledger/aries-framework-go/pkg/store/ld" -) - -// MockService is a mock JSON-LD service. -type MockService struct { - ProviderID string - RemoteProviderRecords []ld.RemoteProviderRecord - ErrAddContexts error - ErrAddRemoteProvider error - ErrRefreshRemoteProvider error - ErrDeleteRemoteProvider error - ErrGetAllRemoteProviders error - ErrRefreshAllRemoteProviders error -} - -// AddContexts adds JSON-LD contexts to the underlying storage. -func (m *MockService) AddContexts(documents []ldcontext.Document) error { - if m.ErrAddContexts != nil { - return m.ErrAddContexts - } - - return nil -} - -// AddRemoteProvider adds remote provider and JSON-LD contexts from that provider. -func (m *MockService) AddRemoteProvider(providerEndpoint string, opts ...remote.ProviderOpt) (string, error) { - if m.ErrAddRemoteProvider != nil { - return "", m.ErrAddRemoteProvider - } - - return m.ProviderID, nil -} - -// RefreshRemoteProvider updates contexts from the remote provider. -func (m *MockService) RefreshRemoteProvider(providerID string, opts ...remote.ProviderOpt) error { - if m.ErrRefreshRemoteProvider != nil { - return m.ErrRefreshRemoteProvider - } - - return nil -} - -// DeleteRemoteProvider deletes remote provider and contexts from that provider. -func (m *MockService) DeleteRemoteProvider(providerID string, opts ...remote.ProviderOpt) error { - if m.ErrDeleteRemoteProvider != nil { - return m.ErrDeleteRemoteProvider - } - - return nil -} - -// GetAllRemoteProviders gets all remote providers. -func (m *MockService) GetAllRemoteProviders() ([]ld.RemoteProviderRecord, error) { - if m.ErrGetAllRemoteProviders != nil { - return nil, m.ErrGetAllRemoteProviders - } - - return m.RemoteProviderRecords, nil -} - -// RefreshAllRemoteProviders updates contexts from all remote providers. -func (m *MockService) RefreshAllRemoteProviders(opts ...remote.ProviderOpt) error { - if m.ErrRefreshAllRemoteProviders != nil { - return m.ErrRefreshAllRemoteProviders - } - - return m.ErrRefreshAllRemoteProviders -} diff --git a/pkg/mock/secretlock/mock_secretlock.go b/pkg/mock/secretlock/mock_secretlock.go deleted file mode 100644 index 9cd902c54..000000000 --- a/pkg/mock/secretlock/mock_secretlock.go +++ /dev/null @@ -1,35 +0,0 @@ -/* -Copyright SecureKey Technologies Inc. All Rights Reserved. - -SPDX-License-Identifier: Apache-2.0 -*/ - -package secretlock - -import "github.com/hyperledger/aries-framework-go/pkg/secretlock" - -// MockSecretLock mocking a Secret Lock service. -type MockSecretLock struct { - ValEncrypt string - ValDecrypt string - ErrEncrypt error - ErrDecrypt error -} - -// Encrypt req for master key in keyURI. -func (m *MockSecretLock) Encrypt(keyURI string, req *secretlock.EncryptRequest) (*secretlock.EncryptResponse, error) { - if m.ErrEncrypt != nil { - return nil, m.ErrEncrypt - } - - return &secretlock.EncryptResponse{Ciphertext: m.ValEncrypt}, nil -} - -// Decrypt req for master key in keyURI. -func (m *MockSecretLock) Decrypt(keyURI string, req *secretlock.DecryptRequest) (*secretlock.DecryptResponse, error) { - if m.ErrDecrypt != nil { - return nil, m.ErrDecrypt - } - - return &secretlock.DecryptResponse{Plaintext: m.ValDecrypt}, nil -} diff --git a/pkg/mock/secretlock/secretlock.go b/pkg/mock/secretlock/secretlock.go new file mode 100644 index 000000000..175ea6ab0 --- /dev/null +++ b/pkg/mock/secretlock/secretlock.go @@ -0,0 +1,12 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package secretlock + +import "github.com/hyperledger/aries-framework-go/component/kmscrypto/mock/secretlock" + +// MockSecretLock mocking a Secret Lock service. +type MockSecretLock = secretlock.MockSecretLock diff --git a/pkg/mock/storage/storage.go b/pkg/mock/storage/storage.go new file mode 100644 index 000000000..939092023 --- /dev/null +++ b/pkg/mock/storage/storage.go @@ -0,0 +1,31 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. +SPDX-License-Identifier: Apache-2.0 +*/ + +package storage + +import ( + mockstore "github.com/hyperledger/aries-framework-go/component/storageutil/mock/storage" + "github.com/hyperledger/aries-framework-go/spi/storage" +) + +// MockStoreProvider mock store provider. +type MockStoreProvider = mockstore.MockStoreProvider + +// NewMockStoreProvider new store provider instance. +func NewMockStoreProvider() *MockStoreProvider { + return mockstore.NewMockStoreProvider() +} + +// NewCustomMockStoreProvider new mock store provider instance +// from existing mock store. +func NewCustomMockStoreProvider(customStore storage.Store) *MockStoreProvider { + return mockstore.NewCustomMockStoreProvider(customStore) +} + +// DBEntry is a value plus optional tags that are associated with some key. +type DBEntry = mockstore.DBEntry + +// MockStore mock store. +type MockStore = mockstore.MockStore diff --git a/pkg/store/ld/ld.go b/pkg/store/ld/ld.go new file mode 100644 index 000000000..7ead55653 --- /dev/null +++ b/pkg/store/ld/ld.go @@ -0,0 +1,51 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package ld + +import ( + "github.com/hyperledger/aries-framework-go/component/models/ld/store" + "github.com/hyperledger/aries-framework-go/spi/storage" +) + +const ( + // ContextStoreName is a JSON-LD context store name. + ContextStoreName = store.ContextStoreName + + // ContextRecordTag is a tag associated with every record in the store. + ContextRecordTag = store.ContextRecordTag + + // RemoteProviderStoreName is a remote provider store name. + RemoteProviderStoreName = store.RemoteProviderStoreName + + // RemoteProviderRecordTag is a tag associated with every record in the store. + RemoteProviderRecordTag = store.RemoteProviderRecordTag +) + +// ContextStore represents a repository for JSON-LD context operations. +type ContextStore = store.ContextStore + +// ContextStoreImpl is a default implementation of JSON-LD context repository. +type ContextStoreImpl = store.ContextStoreImpl + +// NewContextStore returns a new instance of ContextStoreImpl. +func NewContextStore(storageProvider storage.Provider) (*ContextStoreImpl, error) { + return store.NewContextStore(storageProvider) +} + +// RemoteProviderRecord is a record in store with remote provider info. +type RemoteProviderRecord = store.RemoteProviderRecord + +// RemoteProviderStore represents a repository for remote context provider operations. +type RemoteProviderStore = store.RemoteProviderStore + +// RemoteProviderStoreImpl is a default implementation of remote provider repository. +type RemoteProviderStoreImpl = store.RemoteProviderStoreImpl + +// NewRemoteProviderStore returns a new instance of RemoteProviderStoreImpl. +func NewRemoteProviderStore(storageProvider storage.Provider) (*RemoteProviderStoreImpl, error) { + return store.NewRemoteProviderStore(storageProvider) +} diff --git a/scripts/check_lint.sh b/scripts/check_lint.sh index c5faa78c5..0deebc67d 100755 --- a/scripts/check_lint.sh +++ b/scripts/check_lint.sh @@ -43,6 +43,9 @@ echo "done linting component/storageutil" echo "linting component/kmscrypto.." ${DOCKER_CMD} run --rm -e GOPROXY=${GOPROXY} -v $(pwd):/opt/workspace -w /opt/workspace/component/kmscrypto ${GOLANGCI_LINT_IMAGE} golangci-lint run -c ../../.golangci.yml echo "done linting component/kmscrypto" +echo "linting component/models.." +${DOCKER_CMD} run --rm -e GOPROXY=${GOPROXY} -v $(pwd):/opt/workspace -w /opt/workspace/component/models ${GOLANGCI_LINT_IMAGE} golangci-lint run -c ../../.golangci.yml +echo "done linting component/models" echo "linting component/storage/edv.." ${DOCKER_CMD} run --rm -e GOPROXY=${GOPROXY} -v $(pwd):/opt/workspace -w /opt/workspace/component/storage/edv ${GOLANGCI_LINT_IMAGE} golangci-lint run -c ../../../.golangci.yml echo "done linting component/storage/edv" diff --git a/scripts/check_unit.sh b/scripts/check_unit.sh index ea88437e1..e9293655a 100755 --- a/scripts/check_unit.sh +++ b/scripts/check_unit.sh @@ -93,6 +93,13 @@ $GO_TEST_CMD $PKGS -count=1 -race -coverprofile=profile.out -covermode=atomic -t amend_coverage_file cd ../.. +# Running models unit tests +cd component/models +PKGS=$(go list github.com/hyperledger/aries-framework-go/component/models/... 2> /dev/null) +$GO_TEST_CMD $PKGS -count=1 -race -coverprofile=profile.out -covermode=atomic -timeout=10m +amend_coverage_file +cd ../.. + if [ "$SKIP_DOCKER" = true ]; then echo "Skipping edv unit tests" else diff --git a/test/bdd/go.mod b/test/bdd/go.mod index 7d1a6b6d9..fdaca0eaa 100644 --- a/test/bdd/go.mod +++ b/test/bdd/go.mod @@ -51,6 +51,7 @@ require ( github.com/google/tink/go v1.7.0 // indirect github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0 // indirect github.com/hyperledger/aries-framework-go/component/log v0.0.0 // indirect + github.com/hyperledger/aries-framework-go/component/models v0.0.0 // indirect github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20221025204933-b807371b6f1e // indirect github.com/hyperledger/ursa-wrapper-go v0.3.1 // indirect github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect @@ -100,6 +101,7 @@ replace ( github.com/hyperledger/aries-framework-go => ../.. github.com/hyperledger/aries-framework-go/component/kmscrypto => ../../component/kmscrypto github.com/hyperledger/aries-framework-go/component/log => ../../component/log + github.com/hyperledger/aries-framework-go/component/models => ../../component/models github.com/hyperledger/aries-framework-go/component/storage/leveldb => ../../component/storage/leveldb github.com/hyperledger/aries-framework-go/component/storageutil => ../../component/storageutil github.com/hyperledger/aries-framework-go/spi => ../../spi