Skip to content

Commit

Permalink
refactor: move signatures suites to vc module (#801)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <timo@animo.id>
  • Loading branch information
TimoGlastra committed Jul 3, 2022
1 parent e53ee42 commit 938a889
Show file tree
Hide file tree
Showing 41 changed files with 102 additions and 80 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/modules/dids/domain/keyDidDocument.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/modules/vc/SignatureSuiteRegistry.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
15 changes: 9 additions & 6 deletions packages/core/src/modules/vc/W3cCredentialService.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
8 changes: 2 additions & 6 deletions packages/core/src/modules/vc/__tests__/documentLoader.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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<string, unknown>
export interface VerificationMethod extends JsonObject {
Expand Down
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@
* 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'

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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* limitations under the License.
*/

import type { DocumentLoader } from '../../../../utils'
import type { DocumentLoader } from '../../../jsonldUtil'

/**
* Options for canonizing a document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 938a889

Please sign in to comment.