Skip to content

Commit

Permalink
feat(w3cCredentials)!: add jwt vc support (#1468)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra authored May 29, 2023
1 parent 5075658 commit 25c76ae
Show file tree
Hide file tree
Showing 174 changed files with 5,285 additions and 1,311 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ import {
checkValidCredentialValueEncoding,
encodeCredentialValue,
assertNoDuplicateGroupsNamesInProofRequest,
unqualifiedCredentialDefinitionIdRegex,
unqualifiedSchemaIdRegex,
getRevocationRegistriesForRequest,
getRevocationRegistriesForProof,
} from '../utils'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function migrateCredentialExchangeRecordToV0_4<Agent extends BaseAg
migrateIndyCredentialTypeToAnonCredsCredential(agent, credentialRecord)
migrateIndyCredentialMetadataToAnonCredsMetadata(agent, credentialRecord)

// Save updated did record
// Save updated record
await credentialRepository.update(agent.context, credentialRecord)

agent.config.logger.debug(
Expand Down
85 changes: 49 additions & 36 deletions packages/bbs-signatures/tests/bbs-signatures.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import type { W3cCredentialRepository } from '../../core/src/modules/vc/repository'
import type { AgentContext, Wallet } from '@aries-framework/core'
import type { W3cCredentialRepository } from '../../core/src/modules/vc/repository/W3cCredentialRepository'
import type { AgentContext, W3cJwtCredentialService, Wallet } from '@aries-framework/core'

import {
W3cCredentialService,
W3cJsonLdVerifiablePresentation,
VERIFICATION_METHOD_TYPE_ED25519_VERIFICATION_KEY_2018,
KeyType,
JsonTransformer,
DidKey,
SigningProviderRegistry,
W3cVerifiableCredential,
W3cCredentialService,
W3cCredential,
CredentialIssuancePurpose,
VERIFICATION_METHOD_TYPE_BLS12381G2_KEY_2020,
orArrayToArray,
vcLibraries,
LinkedDataProof,
W3cPresentation,
W3cVerifiablePresentation,
Ed25519Signature2018,
TypedArrayEncoder,
W3cJsonLdVerifiableCredential,
} from '@aries-framework/core'

import { SignatureSuiteRegistry } from '../../core/src/modules/vc/SignatureSuiteRegistry'
import { W3cCredentialsModuleConfig } from '../../core/src/modules/vc/W3cCredentialsModuleConfig'
import { customDocumentLoader } from '../../core/src/modules/vc/__tests__/documentLoader'
import { SignatureSuiteRegistry } from '../../core/src/modules/vc/data-integrity/SignatureSuiteRegistry'
import { W3cJsonLdCredentialService } from '../../core/src/modules/vc/data-integrity/W3cJsonLdCredentialService'
import { customDocumentLoader } from '../../core/src/modules/vc/data-integrity/__tests__/documentLoader'
import { LinkedDataProof } from '../../core/src/modules/vc/data-integrity/models/LinkedDataProof'
import { getAgentConfig, getAgentContext } from '../../core/tests/helpers'
import { IndySdkWallet } from '../../indy-sdk/src'
import { indySdk } from '../../indy-sdk/tests/setupIndySdkModule'
Expand Down Expand Up @@ -63,6 +63,7 @@ const agentConfig = getAgentConfig('BbsSignaturesE2eTest')
describeSkipNode17And18('BBS W3cCredentialService', () => {
let wallet: Wallet
let agentContext: AgentContext
let w3cJsonLdCredentialService: W3cJsonLdCredentialService
let w3cCredentialService: W3cCredentialService
const seed = TypedArrayEncoder.fromString('testseed000000000000000000000001')
const privateKey = TypedArrayEncoder.fromString('testseed000000000000000000000001')
Expand All @@ -74,13 +75,17 @@ describeSkipNode17And18('BBS W3cCredentialService', () => {
agentConfig,
wallet,
})
w3cCredentialService = new W3cCredentialService(
{} as unknown as W3cCredentialRepository,
w3cJsonLdCredentialService = new W3cJsonLdCredentialService(
signatureSuiteRegistry,
new W3cCredentialsModuleConfig({
documentLoader: customDocumentLoader,
})
)
w3cCredentialService = new W3cCredentialService(
{} as unknown as W3cCredentialRepository,
w3cJsonLdCredentialService,
{} as unknown as W3cJwtCredentialService
)
})

afterAll(async () => {
Expand All @@ -90,24 +95,24 @@ describeSkipNode17And18('BBS W3cCredentialService', () => {
describe('Utility methods', () => {
describe('getKeyTypesByProofType', () => {
it('should return the correct key types for BbsBlsSignature2020 proof type', async () => {
const keyTypes = w3cCredentialService.getKeyTypesByProofType('BbsBlsSignature2020')
const keyTypes = w3cJsonLdCredentialService.getKeyTypesByProofType('BbsBlsSignature2020')
expect(keyTypes).toEqual([KeyType.Bls12381g2])
})
it('should return the correct key types for BbsBlsSignatureProof2020 proof type', async () => {
const keyTypes = w3cCredentialService.getKeyTypesByProofType('BbsBlsSignatureProof2020')
const keyTypes = w3cJsonLdCredentialService.getKeyTypesByProofType('BbsBlsSignatureProof2020')
expect(keyTypes).toEqual([KeyType.Bls12381g2])
})
})

describe('getVerificationMethodTypesByProofType', () => {
it('should return the correct key types for BbsBlsSignature2020 proof type', async () => {
const verificationMethodTypes =
w3cCredentialService.getVerificationMethodTypesByProofType('BbsBlsSignature2020')
w3cJsonLdCredentialService.getVerificationMethodTypesByProofType('BbsBlsSignature2020')
expect(verificationMethodTypes).toEqual([VERIFICATION_METHOD_TYPE_BLS12381G2_KEY_2020])
})
it('should return the correct key types for BbsBlsSignatureProof2020 proof type', async () => {
const verificationMethodTypes =
w3cCredentialService.getVerificationMethodTypesByProofType('BbsBlsSignatureProof2020')
w3cJsonLdCredentialService.getVerificationMethodTypesByProofType('BbsBlsSignatureProof2020')
expect(verificationMethodTypes).toEqual([VERIFICATION_METHOD_TYPE_BLS12381G2_KEY_2020])
})
})
Expand All @@ -130,13 +135,14 @@ describeSkipNode17And18('BBS W3cCredentialService', () => {

const credential = JsonTransformer.fromJSON(credentialJson, W3cCredential)

const vc = await w3cCredentialService.signCredential(agentContext, {
const vc = await w3cJsonLdCredentialService.signCredential(agentContext, {
format: 'ldp_vc',
credential,
proofType: 'BbsBlsSignature2020',
verificationMethod: verificationMethod,
})

expect(vc).toBeInstanceOf(W3cVerifiableCredential)
expect(vc).toBeInstanceOf(W3cJsonLdVerifiableCredential)
expect(vc.issuer).toEqual(issuerDidKey.did)
expect(Array.isArray(vc.proof)).toBe(false)
expect(vc.proof).toBeInstanceOf(LinkedDataProof)
Expand All @@ -148,23 +154,23 @@ describeSkipNode17And18('BBS W3cCredentialService', () => {

describe('verifyCredential', () => {
it('should verify the credential successfully', async () => {
const result = await w3cCredentialService.verifyCredential(agentContext, {
const result = await w3cJsonLdCredentialService.verifyCredential(agentContext, {
credential: JsonTransformer.fromJSON(
BbsBlsSignature2020Fixtures.TEST_LD_DOCUMENT_SIGNED,
W3cVerifiableCredential
W3cJsonLdVerifiableCredential
),
proofPurpose: new purposes.AssertionProofPurpose(),
})

expect(result.verified).toEqual(true)
expect(result.isValid).toEqual(true)
})
})

describe('deriveProof', () => {
it('should derive proof successfully', async () => {
const credentialJson = BbsBlsSignature2020Fixtures.TEST_LD_DOCUMENT_SIGNED

const vc = JsonTransformer.fromJSON(credentialJson, W3cVerifiableCredential)
const vc = JsonTransformer.fromJSON(credentialJson, W3cJsonLdVerifiableCredential)

const revealDocument = {
'@context': [
Expand All @@ -182,33 +188,39 @@ describeSkipNode17And18('BBS W3cCredentialService', () => {
},
}

const result = await w3cCredentialService.deriveProof(agentContext, {
const result = await w3cJsonLdCredentialService.deriveProof(agentContext, {
credential: vc,
revealDocument: revealDocument,
verificationMethod: verificationMethod,
})

// result.proof = result.proof as LinkedDataProof
expect(orArrayToArray(result.proof)[0].verificationMethod).toBe(
result.proof = result.proof as LinkedDataProof
expect(result.proof.verificationMethod).toBe(
'did:key:zUC74VEqqhEHQcgv4zagSPkqFJxuNWuoBPKjJuHETEUeHLoSqWt92viSsmaWjy82y2cgguc8e9hsGBifnVK67pQ4gve3m6iSboDkmJjxVEb1d6mRAx5fpMAejooNzNqqbTMVeUN#zUC74VEqqhEHQcgv4zagSPkqFJxuNWuoBPKjJuHETEUeHLoSqWt92viSsmaWjy82y2cgguc8e9hsGBifnVK67pQ4gve3m6iSboDkmJjxVEb1d6mRAx5fpMAejooNzNqqbTMVeUN'
)
})
})

describe('verifyDerived', () => {
it('should verify the derived proof successfully', async () => {
const result = await w3cCredentialService.verifyCredential(agentContext, {
credential: JsonTransformer.fromJSON(BbsBlsSignature2020Fixtures.TEST_VALID_DERIVED, W3cVerifiableCredential),
const result = await w3cJsonLdCredentialService.verifyCredential(agentContext, {
credential: JsonTransformer.fromJSON(
BbsBlsSignature2020Fixtures.TEST_VALID_DERIVED,
W3cJsonLdVerifiableCredential
),
proofPurpose: new purposes.AssertionProofPurpose(),
})
expect(result.verified).toEqual(true)
expect(result.isValid).toEqual(true)
})
})

describe('createPresentation', () => {
it('should create a presentation successfully', async () => {
const vc = JsonTransformer.fromJSON(BbsBlsSignature2020Fixtures.TEST_VALID_DERIVED, W3cVerifiableCredential)
const result = await w3cCredentialService.createPresentation({ credentials: vc })
const vc = JsonTransformer.fromJSON(
BbsBlsSignature2020Fixtures.TEST_VALID_DERIVED,
W3cJsonLdVerifiableCredential
)
const result = await w3cCredentialService.createPresentation({ credentials: [vc] })

expect(result).toBeInstanceOf(W3cPresentation)

Expand Down Expand Up @@ -236,31 +248,32 @@ describeSkipNode17And18('BBS W3cCredentialService', () => {
date: new Date().toISOString(),
})

const verifiablePresentation = await w3cCredentialService.signPresentation(agentContext, {
const verifiablePresentation = await w3cJsonLdCredentialService.signPresentation(agentContext, {
format: 'ldp_vp',
presentation: presentation,
purpose: purpose,
signatureType: 'Ed25519Signature2018',
proofPurpose: purpose,
proofType: 'Ed25519Signature2018',
challenge: 'e950bfe5-d7ec-4303-ad61-6983fb976ac9',
verificationMethod: verificationMethod,
})

expect(verifiablePresentation).toBeInstanceOf(W3cVerifiablePresentation)
expect(verifiablePresentation).toBeInstanceOf(W3cJsonLdVerifiablePresentation)
})
})

describe('verifyPresentation', () => {
it('should successfully verify a presentation containing a single verifiable credential bbs', async () => {
const vp = JsonTransformer.fromJSON(
BbsBlsSignature2020Fixtures.TEST_VP_DOCUMENT_SIGNED,
W3cVerifiablePresentation
W3cJsonLdVerifiablePresentation
)

const result = await w3cCredentialService.verifyPresentation(agentContext, {
const result = await w3cJsonLdCredentialService.verifyPresentation(agentContext, {
presentation: vp,
challenge: 'e950bfe5-d7ec-4303-ad61-6983fb976ac9',
})

expect(result.verified).toBe(true)
expect(result.isValid).toBe(true)
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/cheqd/tests/cheqd-did-registrar.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CheqdDidCreateOptions } from '../src'
import type { DidDocument } from '@aries-framework/core'

import { Agent, TypedArrayEncoder, JsonTransformer } from '@aries-framework/core'
import { Agent, TypedArrayEncoder } from '@aries-framework/core'
import { generateKeyPairFromSeed } from '@stablelib/ed25519'

import { getAgentOptions } from '../../core/tests/helpers'
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/agent/__tests__/AgentMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('AgentMessage', () => {
} catch (error) {
const thrownError = error as ClassValidationError
expect(thrownError.message).toEqual(
'CustomProtocolMessage: Failed to validate class.\nAn instance of CustomProtocolMessage has failed the validation:\n - property type has failed the following constraints: isValidMessageType \n'
'CustomProtocolMessage: Failed to validate class.\nAn instance of CustomProtocolMessage has failed the validation:\n - property type has failed the following constraints: type does not match the expected message type (only minor version may be lower) \n'
)
expect(thrownError.validationErrors).toMatchObject([
{
Expand Down
Loading

0 comments on commit 25c76ae

Please sign in to comment.