From 938a8896933d162cd5f4522e81dea94feafad29e Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Tue, 31 May 2022 09:18:41 +0200 Subject: [PATCH] refactor: move signatures suites to vc module (#801) Signed-off-by: Timo Glastra --- .../src/modules/dids/domain/keyDidDocument.ts | 2 +- .../modules/dids/methods/sov/SovDidResolver.ts | 2 +- .../core/src/modules/vc/SignatureSuiteRegistry.ts | 7 ++++--- .../core/src/modules/vc/W3cCredentialService.ts | 15 +++++++++------ .../vc/__tests__/W3cCredentialService.test.ts | 5 +++-- .../src/modules/vc/__tests__/documentLoader.ts | 8 ++------ .../{utils/jsonld.ts => modules/vc/jsonldUtil.ts} | 10 +++++----- .../modules/vc/libraries}/jsonld-signatures.ts | 4 ++++ .../{types => src/modules/vc/libraries}/jsonld.ts | 8 ++++++++ .../{types => src/modules/vc/libraries}/vc.ts | 4 ++++ .../models/credential/W3cVerifiableCredential.ts | 5 ++--- .../proof-purposes/CredentialIssuancePurpose.ts | 5 ++--- .../signature-suites/JwsLinkedDataSignature.ts | 10 +++++----- .../signature-suites/bbs/BbsBlsSignature2020.ts | 15 ++++++++------- .../bbs/BbsBlsSignatureProof2020.ts | 15 ++++++++------- .../vc}/signature-suites/bbs/deriveProof.ts | 11 ++++++----- .../vc}/signature-suites/bbs/index.ts | 0 .../signature-suites/bbs/types/CanonizeOptions.ts | 2 +- .../bbs/types/CreateProofOptions.ts | 6 +++--- .../bbs/types/CreateVerifyDataOptions.ts | 4 ++-- .../bbs/types/DeriveProofOptions.ts | 4 ++-- .../bbs/types/DidDocumentPublicKey.ts | 0 .../bbs/types/GetProofsOptions.ts | 4 ++-- .../signature-suites/bbs/types/GetProofsResult.ts | 2 +- .../signature-suites/bbs/types/GetTypeOptions.ts | 2 +- .../vc}/signature-suites/bbs/types/JsonWebKey.ts | 0 .../signature-suites/bbs/types/KeyPairOptions.ts | 0 .../signature-suites/bbs/types/KeyPairSigner.ts | 0 .../signature-suites/bbs/types/KeyPairVerifier.ts | 0 .../bbs/types/SignatureSuiteOptions.ts | 4 ++-- .../bbs/types/SuiteSignOptions.ts | 4 ++-- .../bbs/types/VerifyProofOptions.ts | 6 +++--- .../bbs/types/VerifyProofResult.ts | 0 .../bbs/types/VerifySignatureOptions.ts | 4 ++-- .../vc}/signature-suites/bbs/types/index.ts | 0 .../ed25519/Ed25519Signature2018.ts | 9 +++++---- .../vc}/signature-suites/ed25519/constants.ts | 0 .../vc}/signature-suites/ed25519/context.ts | 0 .../vc}/signature-suites/index.ts | 0 packages/core/src/utils/index.ts | 3 ++- packages/core/src/utils/validators.ts | 2 ++ 41 files changed, 102 insertions(+), 80 deletions(-) rename packages/core/src/{utils/jsonld.ts => modules/vc/jsonldUtil.ts} (95%) rename packages/core/{types => src/modules/vc/libraries}/jsonld-signatures.ts (72%) rename packages/core/{types => src/modules/vc/libraries}/jsonld.ts (72%) rename packages/core/{types => src/modules/vc/libraries}/vc.ts (71%) rename packages/core/src/{crypto => modules/vc}/signature-suites/JwsLinkedDataSignature.ts (97%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/BbsBlsSignature2020.ts (97%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/BbsBlsSignatureProof2020.ts (97%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/deriveProof.ts (92%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/index.ts (100%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/types/CanonizeOptions.ts (94%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/types/CreateProofOptions.ts (85%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/types/CreateVerifyDataOptions.ts (90%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/types/DeriveProofOptions.ts (91%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/types/DidDocumentPublicKey.ts (100%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/types/GetProofsOptions.ts (91%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/types/GetProofsResult.ts (93%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/types/GetTypeOptions.ts (93%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/types/JsonWebKey.ts (100%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/types/KeyPairOptions.ts (100%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/types/KeyPairSigner.ts (100%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/types/KeyPairVerifier.ts (100%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/types/SignatureSuiteOptions.ts (92%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/types/SuiteSignOptions.ts (90%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/types/VerifyProofOptions.ts (83%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/types/VerifyProofResult.ts (100%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/types/VerifySignatureOptions.ts (94%) rename packages/core/src/{crypto => modules/vc}/signature-suites/bbs/types/index.ts (100%) rename packages/core/src/{crypto => modules/vc}/signature-suites/ed25519/Ed25519Signature2018.ts (97%) rename packages/core/src/{crypto => modules/vc}/signature-suites/ed25519/constants.ts (100%) rename packages/core/src/{crypto => modules/vc}/signature-suites/ed25519/context.ts (100%) rename packages/core/src/{crypto => modules/vc}/signature-suites/index.ts (100%) diff --git a/packages/core/src/modules/dids/domain/keyDidDocument.ts b/packages/core/src/modules/dids/domain/keyDidDocument.ts index 1ef38b2bd1..537cb97d3d 100644 --- a/packages/core/src/modules/dids/domain/keyDidDocument.ts +++ b/packages/core/src/modules/dids/domain/keyDidDocument.ts @@ -1,8 +1,8 @@ import type { VerificationMethod } from './verificationMethod/VerificationMethod' import { KeyType, Key } from '../../../crypto' -import { ED25519_SUITE_CONTEXT_URL_2018 } from '../../../crypto/signature-suites/ed25519/constants' import { SECURITY_CONTEXT_BBS_URL, SECURITY_X25519_CONTEXT_URL } from '../../vc/constants' +import { ED25519_SUITE_CONTEXT_URL_2018 } from '../../vc/signature-suites/ed25519/constants' import { DidDocumentBuilder } from './DidDocumentBuilder' import { getBls12381g1VerificationMethod } from './key-type/bls12381g1' diff --git a/packages/core/src/modules/dids/methods/sov/SovDidResolver.ts b/packages/core/src/modules/dids/methods/sov/SovDidResolver.ts index 694987c059..5f02c8dd4c 100644 --- a/packages/core/src/modules/dids/methods/sov/SovDidResolver.ts +++ b/packages/core/src/modules/dids/methods/sov/SovDidResolver.ts @@ -4,10 +4,10 @@ import type { ParsedDid, DidResolutionResult } from '../../types' import { convertPublicKeyToX25519 } from '@stablelib/ed25519' -import { ED25519_SUITE_CONTEXT_URL_2018 } from '../../../../crypto/signature-suites/ed25519/constants' import { TypedArrayEncoder } from '../../../../utils/TypedArrayEncoder' import { getFullVerkey } from '../../../../utils/did' import { SECURITY_X25519_CONTEXT_URL } from '../../../vc/constants' +import { ED25519_SUITE_CONTEXT_URL_2018 } from '../../../vc/signature-suites/ed25519/constants' import { DidDocumentService } from '../../domain' import { DidDocumentBuilder } from '../../domain/DidDocumentBuilder' import { DidCommV1Service } from '../../domain/service/DidCommV1Service' diff --git a/packages/core/src/modules/vc/SignatureSuiteRegistry.ts b/packages/core/src/modules/vc/SignatureSuiteRegistry.ts index 469d0a4aaf..0d5404aa44 100644 --- a/packages/core/src/modules/vc/SignatureSuiteRegistry.ts +++ b/packages/core/src/modules/vc/SignatureSuiteRegistry.ts @@ -1,9 +1,10 @@ -import { suites } from '../../../types/jsonld-signatures' import { KeyType } from '../../crypto' -import { Ed25519Signature2018 } from '../../crypto/signature-suites' -import { BbsBlsSignature2020, BbsBlsSignatureProof2020 } from '../../crypto/signature-suites/bbs' import { AriesFrameworkError } from '../../error' +import { suites } from './libraries/jsonld-signatures' +import { Ed25519Signature2018 } from './signature-suites' +import { BbsBlsSignature2020, BbsBlsSignatureProof2020 } from './signature-suites/bbs' + const LinkedDataSignature = suites.LinkedDataSignature export interface SuiteInfo { diff --git a/packages/core/src/modules/vc/W3cCredentialService.ts b/packages/core/src/modules/vc/W3cCredentialService.ts index 103df55af5..c1bf89d930 100644 --- a/packages/core/src/modules/vc/W3cCredentialService.ts +++ b/packages/core/src/modules/vc/W3cCredentialService.ts @@ -1,5 +1,5 @@ import type { Key } from '../../crypto/Key' -import type { DocumentLoaderResult } from '../../utils' +import type { DocumentLoaderResult } from './jsonldUtil' import type { W3cVerifyCredentialResult } from './models' import type { CreatePresentationOptions, @@ -12,24 +12,27 @@ import type { } from './models/W3cCredentialServiceOptions' import type { VerifyPresentationResult } from './models/presentation/VerifyPresentationResult' -import jsonld, { documentLoaderNode, documentLoaderXhr } from '../../../types/jsonld' -import vc from '../../../types/vc' +import { inject } from 'tsyringe' + import { InjectionSymbols } from '../../constants' import { createWalletKeyPairClass } from '../../crypto/WalletKeyPair' -import { deriveProof } from '../../crypto/signature-suites/bbs' import { AriesFrameworkError } from '../../error' -import { inject, injectable } from '../../plugins' -import { JsonTransformer, orArrayToArray, w3cDate } from '../../utils' +import { injectable } from '../../plugins' +import { JsonTransformer } from '../../utils' import { isNodeJS, isReactNative } from '../../utils/environment' import { Wallet } from '../../wallet' import { DidResolverService, VerificationMethod } from '../dids' import { getKeyDidMappingByVerificationMethod } from '../dids/domain/key-type' import { SignatureSuiteRegistry } from './SignatureSuiteRegistry' +import { orArrayToArray, w3cDate } from './jsonldUtil' +import jsonld, { documentLoaderNode, documentLoaderXhr } from './libraries/jsonld' +import vc from './libraries/vc' import { W3cVerifiableCredential } from './models' import { W3cPresentation } from './models/presentation/W3Presentation' import { W3cVerifiablePresentation } from './models/presentation/W3cVerifiablePresentation' import { W3cCredentialRecord, W3cCredentialRepository } from './repository' +import { deriveProof } from './signature-suites/bbs' @injectable() export class W3cCredentialService { diff --git a/packages/core/src/modules/vc/__tests__/W3cCredentialService.test.ts b/packages/core/src/modules/vc/__tests__/W3cCredentialService.test.ts index 401d158e51..20a28c5e19 100644 --- a/packages/core/src/modules/vc/__tests__/W3cCredentialService.test.ts +++ b/packages/core/src/modules/vc/__tests__/W3cCredentialService.test.ts @@ -1,16 +1,17 @@ import type { AgentConfig } from '../../../agent/AgentConfig' import { getAgentConfig } from '../../../../tests/helpers' -import { purposes } from '../../../../types/jsonld-signatures' import { KeyType } from '../../../crypto' import { Key } from '../../../crypto/Key' -import { JsonTransformer, orArrayToArray } from '../../../utils' +import { JsonTransformer } from '../../../utils/JsonTransformer' import { IndyWallet } from '../../../wallet/IndyWallet' import { WalletError } from '../../../wallet/error' import { DidKey, DidResolverService } from '../../dids' import { DidRepository } from '../../dids/repository' import { IndyLedgerService } from '../../ledger/services/IndyLedgerService' import { W3cCredentialService } from '../W3cCredentialService' +import { orArrayToArray } from '../jsonldUtil' +import { purposes } from '../libraries/jsonld-signatures' import { W3cCredential, W3cVerifiableCredential } from '../models' import { LinkedDataProof } from '../models/LinkedDataProof' import { W3cPresentation } from '../models/presentation/W3Presentation' diff --git a/packages/core/src/modules/vc/__tests__/documentLoader.ts b/packages/core/src/modules/vc/__tests__/documentLoader.ts index 91a76bf879..6816beded2 100644 --- a/packages/core/src/modules/vc/__tests__/documentLoader.ts +++ b/packages/core/src/modules/vc/__tests__/documentLoader.ts @@ -1,11 +1,7 @@ -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore -// eslint-disable-next-line import/no-extraneous-dependencies - import type { JsonObject } from '../../../types' -import type { DocumentLoaderResult } from '../../../utils' +import type { DocumentLoaderResult } from '../jsonldUtil' -import jsonld from '../../../../types/jsonld' +import jsonld from '../libraries/jsonld' import { BBS_V1, EXAMPLES_V1, ODRL, SCHEMA_ORG, VACCINATION_V1 } from './contexts' import { X25519_V1 } from './contexts/X25519_v1' diff --git a/packages/core/src/utils/jsonld.ts b/packages/core/src/modules/vc/jsonldUtil.ts similarity index 95% rename from packages/core/src/utils/jsonld.ts rename to packages/core/src/modules/vc/jsonldUtil.ts index 86c1ba7aea..1581291abf 100644 --- a/packages/core/src/utils/jsonld.ts +++ b/packages/core/src/modules/vc/jsonldUtil.ts @@ -1,9 +1,9 @@ -import type { GetProofsOptions, GetProofsResult, GetTypeOptions } from '../crypto/signature-suites/bbs' -import type { JsonObject, JsonValue } from '../types' -import type { SingleOrArray } from './type' +import type { JsonObject, JsonValue } from '../../types' +import type { SingleOrArray } from '../../utils/type' +import type { GetProofsOptions, GetProofsResult, GetTypeOptions } from './signature-suites/bbs' -import jsonld from '../../types/jsonld' -import { SECURITY_CONTEXT_URL } from '../modules/vc/constants' +import { SECURITY_CONTEXT_URL } from './constants' +import jsonld from './libraries/jsonld' export type JsonLdDoc = Record export interface VerificationMethod extends JsonObject { diff --git a/packages/core/types/jsonld-signatures.ts b/packages/core/src/modules/vc/libraries/jsonld-signatures.ts similarity index 72% rename from packages/core/types/jsonld-signatures.ts rename to packages/core/src/modules/vc/libraries/jsonld-signatures.ts index c930e2bfe6..6257b8e2db 100644 --- a/packages/core/types/jsonld-signatures.ts +++ b/packages/core/src/modules/vc/libraries/jsonld-signatures.ts @@ -1,7 +1,11 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + import { suites as JsonLdSuites, purposes as JsonLdPurposes, constants as JsonLdConstants, + // No type definitions available for this library + // eslint-disable-next-line @typescript-eslint/ban-ts-comment //@ts-ignore } from '@digitalcredentials/jsonld-signatures' diff --git a/packages/core/types/jsonld.ts b/packages/core/src/modules/vc/libraries/jsonld.ts similarity index 72% rename from packages/core/types/jsonld.ts rename to packages/core/src/modules/vc/libraries/jsonld.ts index 3e54d97b10..4e95767af4 100644 --- a/packages/core/types/jsonld.ts +++ b/packages/core/src/modules/vc/libraries/jsonld.ts @@ -1,7 +1,15 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +// No type definitions available for this library +// eslint-disable-next-line @typescript-eslint/ban-ts-comment //@ts-ignore import jsonld from '@digitalcredentials/jsonld' +// No type definitions available for this library +// eslint-disable-next-line @typescript-eslint/ban-ts-comment //@ts-ignore import nodeDocumentLoader from '@digitalcredentials/jsonld/lib/documentLoaders/node' +// No type definitions available for this library +// eslint-disable-next-line @typescript-eslint/ban-ts-comment //@ts-ignore import xhrDocumentLoader from '@digitalcredentials/jsonld/lib/documentLoaders/xhr' diff --git a/packages/core/types/vc.ts b/packages/core/src/modules/vc/libraries/vc.ts similarity index 71% rename from packages/core/types/vc.ts rename to packages/core/src/modules/vc/libraries/vc.ts index ca6196528d..21c4a38df4 100644 --- a/packages/core/types/vc.ts +++ b/packages/core/src/modules/vc/libraries/vc.ts @@ -1,3 +1,7 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +// No type definitions available for this package +// eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore import vc from '@digitalcredentials/vc' diff --git a/packages/core/src/modules/vc/models/credential/W3cVerifiableCredential.ts b/packages/core/src/modules/vc/models/credential/W3cVerifiableCredential.ts index e2d1b1afe3..4fbce4e41e 100644 --- a/packages/core/src/modules/vc/models/credential/W3cVerifiableCredential.ts +++ b/packages/core/src/modules/vc/models/credential/W3cVerifiableCredential.ts @@ -3,9 +3,8 @@ import type { W3cCredentialOptions } from './W3cCredential' import { instanceToPlain, plainToInstance, Transform, TransformationType } from 'class-transformer' -import { orArrayToArray } from '../../../../utils' -import { SingleOrArray } from '../../../../utils/type' -import { IsInstanceOrArrayOfInstances } from '../../../../utils/validators' +import { IsInstanceOrArrayOfInstances, SingleOrArray } from '../../../../utils' +import { orArrayToArray } from '../../jsonldUtil' import { LinkedDataProof, LinkedDataProofTransformer } from '../LinkedDataProof' import { W3cCredential } from './W3cCredential' diff --git a/packages/core/src/modules/vc/proof-purposes/CredentialIssuancePurpose.ts b/packages/core/src/modules/vc/proof-purposes/CredentialIssuancePurpose.ts index c4127374e7..305a017fe8 100644 --- a/packages/core/src/modules/vc/proof-purposes/CredentialIssuancePurpose.ts +++ b/packages/core/src/modules/vc/proof-purposes/CredentialIssuancePurpose.ts @@ -1,8 +1,7 @@ import type { JsonObject } from '../../../types' -import type { DocumentLoader, Proof } from '../../../utils' +import type { Proof, DocumentLoader } from '../jsonldUtil' -import jsonld from '../../../../types/jsonld' -import { suites, purposes } from '../../../../types/jsonld-signatures' +import { suites, purposes } from '../libraries/jsonld-signatures' const AssertionProofPurpose = purposes.AssertionProofPurpose const LinkedDataProof = suites.LinkedDataProof diff --git a/packages/core/src/crypto/signature-suites/JwsLinkedDataSignature.ts b/packages/core/src/modules/vc/signature-suites/JwsLinkedDataSignature.ts similarity index 97% rename from packages/core/src/crypto/signature-suites/JwsLinkedDataSignature.ts rename to packages/core/src/modules/vc/signature-suites/JwsLinkedDataSignature.ts index e062d503da..226c0e5ecc 100644 --- a/packages/core/src/crypto/signature-suites/JwsLinkedDataSignature.ts +++ b/packages/core/src/modules/vc/signature-suites/JwsLinkedDataSignature.ts @@ -1,12 +1,12 @@ /*! * Copyright (c) 2020-2021 Digital Bazaar, Inc. All rights reserved. */ -import type { DocumentLoader, Proof, VerificationMethod } from '../../utils' -import type { LdKeyPair } from '../LdKeyPair' +import type { LdKeyPair } from '../../../crypto/LdKeyPair' +import type { DocumentLoader, Proof, VerificationMethod } from '../jsonldUtil' -import { suites } from '../../../types/jsonld-signatures' -import { AriesFrameworkError } from '../../error' -import { TypedArrayEncoder, JsonEncoder } from '../../utils' +import { AriesFrameworkError } from '../../../error' +import { TypedArrayEncoder, JsonEncoder } from '../../../utils' +import { suites } from '../libraries/jsonld-signatures' const LinkedDataSignature = suites.LinkedDataSignature export interface JwsLinkedDataSignatureOptions { diff --git a/packages/core/src/crypto/signature-suites/bbs/BbsBlsSignature2020.ts b/packages/core/src/modules/vc/signature-suites/bbs/BbsBlsSignature2020.ts similarity index 97% rename from packages/core/src/crypto/signature-suites/bbs/BbsBlsSignature2020.ts rename to packages/core/src/modules/vc/signature-suites/bbs/BbsBlsSignature2020.ts index 094d697e57..789260e8c6 100644 --- a/packages/core/src/crypto/signature-suites/bbs/BbsBlsSignature2020.ts +++ b/packages/core/src/modules/vc/signature-suites/bbs/BbsBlsSignature2020.ts @@ -11,8 +11,8 @@ * limitations under the License. */ -import type { JsonObject } from '../../../types' -import type { DocumentLoader, Proof, VerificationMethod } from '../../../utils' +import type { JsonObject } from '../../../../types' +import type { DocumentLoader, Proof, VerificationMethod } from '../../jsonldUtil' import type { SignatureSuiteOptions, CreateProofOptions, @@ -23,11 +23,12 @@ import type { SuiteSignOptions, } from './types' -import jsonld from '../../../../types/jsonld' -import { suites } from '../../../../types/jsonld-signatures' -import { AriesFrameworkError } from '../../../error' -import { SECURITY_CONTEXT_BBS_URL, SECURITY_CONTEXT_URL } from '../../../modules/vc/constants' -import { w3cDate, TypedArrayEncoder } from '../../../utils' +import { AriesFrameworkError } from '../../../../error' +import { TypedArrayEncoder } from '../../../../utils' +import { SECURITY_CONTEXT_BBS_URL, SECURITY_CONTEXT_URL } from '../../constants' +import { w3cDate } from '../../jsonldUtil' +import jsonld from '../../libraries/jsonld' +import { suites } from '../../libraries/jsonld-signatures' /** * A BBS+ signature suite for use with BLS12-381 key pairs diff --git a/packages/core/src/crypto/signature-suites/bbs/BbsBlsSignatureProof2020.ts b/packages/core/src/modules/vc/signature-suites/bbs/BbsBlsSignatureProof2020.ts similarity index 97% rename from packages/core/src/crypto/signature-suites/bbs/BbsBlsSignatureProof2020.ts rename to packages/core/src/modules/vc/signature-suites/bbs/BbsBlsSignatureProof2020.ts index c785986435..2eec683b1f 100644 --- a/packages/core/src/crypto/signature-suites/bbs/BbsBlsSignatureProof2020.ts +++ b/packages/core/src/modules/vc/signature-suites/bbs/BbsBlsSignatureProof2020.ts @@ -11,8 +11,9 @@ * limitations under the License. */ -import type { JsonObject } from '../../../types' -import type { DocumentLoader, Proof } from '../../../utils' +import type { JsonObject } from '../../../../types' +import type { Proof } from '../../jsonldUtil' +import type { DocumentLoader } from '../../libraries/jsonld' import type { DeriveProofOptions, VerifyProofOptions, CreateVerifyDataOptions, CanonizeOptions } from './types' import type { VerifyProofResult } from './types/VerifyProofResult' @@ -20,11 +21,11 @@ import { blsCreateProof, blsVerifyProof } from '@mattrglobal/bbs-signatures' import { Bls12381G2KeyPair } from '@mattrglobal/bls12381-key-pair' import { randomBytes } from '@stablelib/random' -import jsonld from '../../../../types/jsonld' -import { suites } from '../../../../types/jsonld-signatures' -import { AriesFrameworkError } from '../../../error' -import { SECURITY_CONTEXT_URL } from '../../../modules/vc/constants' -import { TypedArrayEncoder } from '../../../utils' +import { AriesFrameworkError } from '../../../../error' +import { TypedArrayEncoder } from '../../../../utils' +import { SECURITY_CONTEXT_URL } from '../../constants' +import jsonld from '../../libraries/jsonld' +import { suites } from '../../libraries/jsonld-signatures' import { BbsBlsSignature2020 } from './BbsBlsSignature2020' diff --git a/packages/core/src/crypto/signature-suites/bbs/deriveProof.ts b/packages/core/src/modules/vc/signature-suites/bbs/deriveProof.ts similarity index 92% rename from packages/core/src/crypto/signature-suites/bbs/deriveProof.ts rename to packages/core/src/modules/vc/signature-suites/bbs/deriveProof.ts index 012b15d323..de0ac5a67a 100644 --- a/packages/core/src/crypto/signature-suites/bbs/deriveProof.ts +++ b/packages/core/src/modules/vc/signature-suites/bbs/deriveProof.ts @@ -11,12 +11,13 @@ * limitations under the License. */ -import type { JsonObject } from '../../../types' +import type { JsonObject } from '../../../../types' -import jsonld from '../../../../types/jsonld' -import { SECURITY_PROOF_URL } from '../../../modules/vc/constants' -import { W3cVerifiableCredential } from '../../../modules/vc/models' -import { JsonTransformer, getProofs, getTypeInfo } from '../../../utils' +import { JsonTransformer } from '../../../../utils' +import { SECURITY_PROOF_URL } from '../../constants' +import { getProofs, getTypeInfo } from '../../jsonldUtil' +import jsonld from '../../libraries/jsonld' +import { W3cVerifiableCredential } from '../../models' /** * Derives a proof from a document featuring a supported linked data proof diff --git a/packages/core/src/crypto/signature-suites/bbs/index.ts b/packages/core/src/modules/vc/signature-suites/bbs/index.ts similarity index 100% rename from packages/core/src/crypto/signature-suites/bbs/index.ts rename to packages/core/src/modules/vc/signature-suites/bbs/index.ts diff --git a/packages/core/src/crypto/signature-suites/bbs/types/CanonizeOptions.ts b/packages/core/src/modules/vc/signature-suites/bbs/types/CanonizeOptions.ts similarity index 94% rename from packages/core/src/crypto/signature-suites/bbs/types/CanonizeOptions.ts rename to packages/core/src/modules/vc/signature-suites/bbs/types/CanonizeOptions.ts index 856baecbde..551dc0f777 100644 --- a/packages/core/src/crypto/signature-suites/bbs/types/CanonizeOptions.ts +++ b/packages/core/src/modules/vc/signature-suites/bbs/types/CanonizeOptions.ts @@ -11,7 +11,7 @@ * limitations under the License. */ -import type { DocumentLoader } from '../../../../utils' +import type { DocumentLoader } from '../../../jsonldUtil' /** * Options for canonizing a document diff --git a/packages/core/src/crypto/signature-suites/bbs/types/CreateProofOptions.ts b/packages/core/src/modules/vc/signature-suites/bbs/types/CreateProofOptions.ts similarity index 85% rename from packages/core/src/crypto/signature-suites/bbs/types/CreateProofOptions.ts rename to packages/core/src/modules/vc/signature-suites/bbs/types/CreateProofOptions.ts index 60e06c0185..38f54dbceb 100644 --- a/packages/core/src/crypto/signature-suites/bbs/types/CreateProofOptions.ts +++ b/packages/core/src/modules/vc/signature-suites/bbs/types/CreateProofOptions.ts @@ -11,9 +11,9 @@ * limitations under the License. */ -import type { ProofPurpose } from '../../../../modules/vc/proof-purposes/ProofPurpose' -import type { JsonObject } from '../../../../types' -import type { DocumentLoader } from '../../../../utils' +import type { JsonObject } from '../../../../../types' +import type { DocumentLoader } from '../../../jsonldUtil' +import type { ProofPurpose } from '../../../proof-purposes/ProofPurpose' /** * Options for creating a proof diff --git a/packages/core/src/crypto/signature-suites/bbs/types/CreateVerifyDataOptions.ts b/packages/core/src/modules/vc/signature-suites/bbs/types/CreateVerifyDataOptions.ts similarity index 90% rename from packages/core/src/crypto/signature-suites/bbs/types/CreateVerifyDataOptions.ts rename to packages/core/src/modules/vc/signature-suites/bbs/types/CreateVerifyDataOptions.ts index ba493b44a2..204dafd5e0 100644 --- a/packages/core/src/crypto/signature-suites/bbs/types/CreateVerifyDataOptions.ts +++ b/packages/core/src/modules/vc/signature-suites/bbs/types/CreateVerifyDataOptions.ts @@ -11,8 +11,8 @@ * limitations under the License. */ -import type { JsonObject } from '../../../../types' -import type { DocumentLoader } from '../../../../utils' +import type { JsonObject } from '../../../../../types' +import type { DocumentLoader } from '../../../jsonldUtil' /** * Options for creating a proof diff --git a/packages/core/src/crypto/signature-suites/bbs/types/DeriveProofOptions.ts b/packages/core/src/modules/vc/signature-suites/bbs/types/DeriveProofOptions.ts similarity index 91% rename from packages/core/src/crypto/signature-suites/bbs/types/DeriveProofOptions.ts rename to packages/core/src/modules/vc/signature-suites/bbs/types/DeriveProofOptions.ts index 68a1322e5f..c726180f9d 100644 --- a/packages/core/src/crypto/signature-suites/bbs/types/DeriveProofOptions.ts +++ b/packages/core/src/modules/vc/signature-suites/bbs/types/DeriveProofOptions.ts @@ -11,8 +11,8 @@ * limitations under the License. */ -import type { JsonObject } from '../../../../types' -import type { DocumentLoader, Proof } from '../../../../utils' +import type { JsonObject } from '../../../../../types' +import type { DocumentLoader, Proof } from '../../../jsonldUtil' /** * Options for creating a proof diff --git a/packages/core/src/crypto/signature-suites/bbs/types/DidDocumentPublicKey.ts b/packages/core/src/modules/vc/signature-suites/bbs/types/DidDocumentPublicKey.ts similarity index 100% rename from packages/core/src/crypto/signature-suites/bbs/types/DidDocumentPublicKey.ts rename to packages/core/src/modules/vc/signature-suites/bbs/types/DidDocumentPublicKey.ts diff --git a/packages/core/src/crypto/signature-suites/bbs/types/GetProofsOptions.ts b/packages/core/src/modules/vc/signature-suites/bbs/types/GetProofsOptions.ts similarity index 91% rename from packages/core/src/crypto/signature-suites/bbs/types/GetProofsOptions.ts rename to packages/core/src/modules/vc/signature-suites/bbs/types/GetProofsOptions.ts index 5dae685de7..41b9fa935f 100644 --- a/packages/core/src/crypto/signature-suites/bbs/types/GetProofsOptions.ts +++ b/packages/core/src/modules/vc/signature-suites/bbs/types/GetProofsOptions.ts @@ -11,8 +11,8 @@ * limitations under the License. */ -import type { JsonObject } from '../../../../types' -import type { DocumentLoader } from '../../../../utils' +import type { JsonObject } from '../../../../../types' +import type { DocumentLoader } from '../../../jsonldUtil' /** * Options for getting a proof from a JSON-LD document diff --git a/packages/core/src/crypto/signature-suites/bbs/types/GetProofsResult.ts b/packages/core/src/modules/vc/signature-suites/bbs/types/GetProofsResult.ts similarity index 93% rename from packages/core/src/crypto/signature-suites/bbs/types/GetProofsResult.ts rename to packages/core/src/modules/vc/signature-suites/bbs/types/GetProofsResult.ts index d96eb8b814..6e24011b74 100644 --- a/packages/core/src/crypto/signature-suites/bbs/types/GetProofsResult.ts +++ b/packages/core/src/modules/vc/signature-suites/bbs/types/GetProofsResult.ts @@ -11,7 +11,7 @@ * limitations under the License. */ -import type { JsonArray, JsonObject } from '../../../../types' +import type { JsonArray, JsonObject } from '../../../../../types' /** * Result for getting proofs from a JSON-LD document diff --git a/packages/core/src/crypto/signature-suites/bbs/types/GetTypeOptions.ts b/packages/core/src/modules/vc/signature-suites/bbs/types/GetTypeOptions.ts similarity index 93% rename from packages/core/src/crypto/signature-suites/bbs/types/GetTypeOptions.ts rename to packages/core/src/modules/vc/signature-suites/bbs/types/GetTypeOptions.ts index 5dd396da4b..0dd40cb546 100644 --- a/packages/core/src/crypto/signature-suites/bbs/types/GetTypeOptions.ts +++ b/packages/core/src/modules/vc/signature-suites/bbs/types/GetTypeOptions.ts @@ -11,7 +11,7 @@ * limitations under the License. */ -import type { DocumentLoader } from '../../../../utils' +import type { DocumentLoader } from '../../../jsonldUtil' /** * Options for getting the type from a JSON-LD document diff --git a/packages/core/src/crypto/signature-suites/bbs/types/JsonWebKey.ts b/packages/core/src/modules/vc/signature-suites/bbs/types/JsonWebKey.ts similarity index 100% rename from packages/core/src/crypto/signature-suites/bbs/types/JsonWebKey.ts rename to packages/core/src/modules/vc/signature-suites/bbs/types/JsonWebKey.ts diff --git a/packages/core/src/crypto/signature-suites/bbs/types/KeyPairOptions.ts b/packages/core/src/modules/vc/signature-suites/bbs/types/KeyPairOptions.ts similarity index 100% rename from packages/core/src/crypto/signature-suites/bbs/types/KeyPairOptions.ts rename to packages/core/src/modules/vc/signature-suites/bbs/types/KeyPairOptions.ts diff --git a/packages/core/src/crypto/signature-suites/bbs/types/KeyPairSigner.ts b/packages/core/src/modules/vc/signature-suites/bbs/types/KeyPairSigner.ts similarity index 100% rename from packages/core/src/crypto/signature-suites/bbs/types/KeyPairSigner.ts rename to packages/core/src/modules/vc/signature-suites/bbs/types/KeyPairSigner.ts diff --git a/packages/core/src/crypto/signature-suites/bbs/types/KeyPairVerifier.ts b/packages/core/src/modules/vc/signature-suites/bbs/types/KeyPairVerifier.ts similarity index 100% rename from packages/core/src/crypto/signature-suites/bbs/types/KeyPairVerifier.ts rename to packages/core/src/modules/vc/signature-suites/bbs/types/KeyPairVerifier.ts diff --git a/packages/core/src/crypto/signature-suites/bbs/types/SignatureSuiteOptions.ts b/packages/core/src/modules/vc/signature-suites/bbs/types/SignatureSuiteOptions.ts similarity index 92% rename from packages/core/src/crypto/signature-suites/bbs/types/SignatureSuiteOptions.ts rename to packages/core/src/modules/vc/signature-suites/bbs/types/SignatureSuiteOptions.ts index d3f2ba95ba..34209afdda 100644 --- a/packages/core/src/crypto/signature-suites/bbs/types/SignatureSuiteOptions.ts +++ b/packages/core/src/modules/vc/signature-suites/bbs/types/SignatureSuiteOptions.ts @@ -11,8 +11,8 @@ * limitations under the License. */ -import type { JsonArray } from '../../../../types' -import type { LdKeyPair } from '../../../LdKeyPair' +import type { LdKeyPair } from '../../../../../crypto/LdKeyPair' +import type { JsonArray } from '../../../../../types' import type { KeyPairSigner } from './KeyPairSigner' import type { Bls12381G2KeyPair } from '@mattrglobal/bls12381-key-pair' diff --git a/packages/core/src/crypto/signature-suites/bbs/types/SuiteSignOptions.ts b/packages/core/src/modules/vc/signature-suites/bbs/types/SuiteSignOptions.ts similarity index 90% rename from packages/core/src/crypto/signature-suites/bbs/types/SuiteSignOptions.ts rename to packages/core/src/modules/vc/signature-suites/bbs/types/SuiteSignOptions.ts index 9bed5d5644..a754325972 100644 --- a/packages/core/src/crypto/signature-suites/bbs/types/SuiteSignOptions.ts +++ b/packages/core/src/modules/vc/signature-suites/bbs/types/SuiteSignOptions.ts @@ -11,8 +11,8 @@ * limitations under the License. */ -import type { JsonObject } from '../../../../types' -import type { DocumentLoader } from '../../../../utils' +import type { JsonObject } from '../../../../../types' +import type { DocumentLoader } from '../../../jsonldUtil' /** * Options for signing using a signature suite diff --git a/packages/core/src/crypto/signature-suites/bbs/types/VerifyProofOptions.ts b/packages/core/src/modules/vc/signature-suites/bbs/types/VerifyProofOptions.ts similarity index 83% rename from packages/core/src/crypto/signature-suites/bbs/types/VerifyProofOptions.ts rename to packages/core/src/modules/vc/signature-suites/bbs/types/VerifyProofOptions.ts index ba3538e7d4..4bf5f0c953 100644 --- a/packages/core/src/crypto/signature-suites/bbs/types/VerifyProofOptions.ts +++ b/packages/core/src/modules/vc/signature-suites/bbs/types/VerifyProofOptions.ts @@ -11,9 +11,9 @@ * limitations under the License. */ -import type { ProofPurpose } from '../../../../modules/vc/proof-purposes/ProofPurpose' -import type { JsonObject } from '../../../../types' -import type { DocumentLoader, Proof } from '../../../../utils' +import type { JsonObject } from '../../../../../types' +import type { DocumentLoader, Proof } from '../../../jsonldUtil' +import type { ProofPurpose } from '../../../proof-purposes/ProofPurpose' /** * Options for verifying a proof diff --git a/packages/core/src/crypto/signature-suites/bbs/types/VerifyProofResult.ts b/packages/core/src/modules/vc/signature-suites/bbs/types/VerifyProofResult.ts similarity index 100% rename from packages/core/src/crypto/signature-suites/bbs/types/VerifyProofResult.ts rename to packages/core/src/modules/vc/signature-suites/bbs/types/VerifyProofResult.ts diff --git a/packages/core/src/crypto/signature-suites/bbs/types/VerifySignatureOptions.ts b/packages/core/src/modules/vc/signature-suites/bbs/types/VerifySignatureOptions.ts similarity index 94% rename from packages/core/src/crypto/signature-suites/bbs/types/VerifySignatureOptions.ts rename to packages/core/src/modules/vc/signature-suites/bbs/types/VerifySignatureOptions.ts index 02eb2c54b1..a1597b59e8 100644 --- a/packages/core/src/crypto/signature-suites/bbs/types/VerifySignatureOptions.ts +++ b/packages/core/src/modules/vc/signature-suites/bbs/types/VerifySignatureOptions.ts @@ -11,8 +11,8 @@ * limitations under the License. */ -import type { JsonObject } from '../../../../types' -import type { DocumentLoader, Proof, VerificationMethod } from '../../../../utils' +import type { JsonObject } from '../../../../../types' +import type { DocumentLoader, Proof, VerificationMethod } from '../../../jsonldUtil' /** * Options for verifying a signature diff --git a/packages/core/src/crypto/signature-suites/bbs/types/index.ts b/packages/core/src/modules/vc/signature-suites/bbs/types/index.ts similarity index 100% rename from packages/core/src/crypto/signature-suites/bbs/types/index.ts rename to packages/core/src/modules/vc/signature-suites/bbs/types/index.ts diff --git a/packages/core/src/crypto/signature-suites/ed25519/Ed25519Signature2018.ts b/packages/core/src/modules/vc/signature-suites/ed25519/Ed25519Signature2018.ts similarity index 97% rename from packages/core/src/crypto/signature-suites/ed25519/Ed25519Signature2018.ts rename to packages/core/src/modules/vc/signature-suites/ed25519/Ed25519Signature2018.ts index d32f747056..18eb3321dc 100644 --- a/packages/core/src/crypto/signature-suites/ed25519/Ed25519Signature2018.ts +++ b/packages/core/src/modules/vc/signature-suites/ed25519/Ed25519Signature2018.ts @@ -1,9 +1,10 @@ -import type { DocumentLoader, JsonLdDoc, Proof, VerificationMethod } from '../../../utils' +import type { DocumentLoader, JsonLdDoc, Proof, VerificationMethod } from '../../jsonldUtil' import type { JwsLinkedDataSignatureOptions } from '../JwsLinkedDataSignature' -import jsonld from '../../../../types/jsonld' -import { CREDENTIALS_CONTEXT_V1_URL, SECURITY_CONTEXT_URL } from '../../../modules/vc/constants' -import { TypedArrayEncoder, MultiBaseEncoder, _includesContext } from '../../../utils' +import { MultiBaseEncoder, TypedArrayEncoder } from '../../../../utils' +import { CREDENTIALS_CONTEXT_V1_URL, SECURITY_CONTEXT_URL } from '../../constants' +import { _includesContext } from '../../jsonldUtil' +import jsonld from '../../libraries/jsonld' import { JwsLinkedDataSignature } from '../JwsLinkedDataSignature' import { ED25519_SUITE_CONTEXT_URL_2018, ED25519_SUITE_CONTEXT_URL_2020 } from './constants' diff --git a/packages/core/src/crypto/signature-suites/ed25519/constants.ts b/packages/core/src/modules/vc/signature-suites/ed25519/constants.ts similarity index 100% rename from packages/core/src/crypto/signature-suites/ed25519/constants.ts rename to packages/core/src/modules/vc/signature-suites/ed25519/constants.ts diff --git a/packages/core/src/crypto/signature-suites/ed25519/context.ts b/packages/core/src/modules/vc/signature-suites/ed25519/context.ts similarity index 100% rename from packages/core/src/crypto/signature-suites/ed25519/context.ts rename to packages/core/src/modules/vc/signature-suites/ed25519/context.ts diff --git a/packages/core/src/crypto/signature-suites/index.ts b/packages/core/src/modules/vc/signature-suites/index.ts similarity index 100% rename from packages/core/src/crypto/signature-suites/index.ts rename to packages/core/src/modules/vc/signature-suites/index.ts diff --git a/packages/core/src/utils/index.ts b/packages/core/src/utils/index.ts index 318ad5d39f..95ebc0b554 100644 --- a/packages/core/src/utils/index.ts +++ b/packages/core/src/utils/index.ts @@ -9,4 +9,5 @@ export * from './regex' export * from './indyProofRequest' export * from './VarintEncoder' export * from './Hasher' -export * from './jsonld' +export * from './validators' +export * from './type' diff --git a/packages/core/src/utils/validators.ts b/packages/core/src/utils/validators.ts index 47997bc482..e81c5543bf 100644 --- a/packages/core/src/utils/validators.ts +++ b/packages/core/src/utils/validators.ts @@ -4,6 +4,7 @@ import type { ValidationOptions } from 'class-validator' import { isString, ValidateBy, isInstance, buildMessage } from 'class-validator' export interface IsInstanceOrArrayOfInstancesValidationOptions extends ValidationOptions { + // eslint-disable-next-line @typescript-eslint/no-explicit-any classType: new (...args: any[]) => any } @@ -60,6 +61,7 @@ export function IsInstanceOrArrayOfInstances( ) } +// eslint-disable-next-line @typescript-eslint/no-explicit-any export function isStringArray(value: any): value is string[] { return Array.isArray(value) && value.every((v) => typeof v === 'string') }