Skip to content

Commit

Permalink
fix(present-proof): fixed the pex tests
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <[email protected]>
  • Loading branch information
berendsliedrecht committed Dec 19, 2023
1 parent 4ae6e7b commit 436b922
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 400 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export class PresentationExchangeService {

// Get all the credentials associated with the input descriptors
const credentialsForSubject = Object.values(subjectInputDescriptorsToCredentials)
.flatMap((credentials) => credentials)
.flat()
.map(getSphereonOriginalVerifiableCredential)

const presentationDefinitionForSubject: PresentationDefinition = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export async function selectCredentialsForRequest(
verifiableCredential: selectResultsRaw.verifiableCredential?.map((encoded) => {
const credentialRecord = credentialRecords.find((record) => {
const originalVc = getSphereonOriginalVerifiableCredential(record.credential)

return deepEquality(originalVc, encoded)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type {
ProofFormatAutoRespondRequestOptions,
ProofFormatAutoRespondPresentationOptions,
} from '../ProofFormatServiceOptions'
import type { PresentationSubmission as PexPresentationSubmission, PresentationSubmission } from '@sphereon/pex-models'
import type { PresentationSubmission } from '@sphereon/pex-models'

import { Attachment, AttachmentData } from '../../../../decorators/attachment/Attachment'
import { AriesFrameworkError } from '../../../../error'
Expand Down Expand Up @@ -158,7 +158,7 @@ export class PresentationExchangeProofFormatService implements ProofFormatServic
attachmentId,
})

const { presentation_definition: presentationDefinition } = requestAttachment.getDataAsJson<{
const { presentation_definition: presentationDefinition, options } = requestAttachment.getDataAsJson<{
presentation_definition: PresentationDefinition
options?: { challenge?: string; domain?: string }
}>()
Expand All @@ -183,6 +183,8 @@ export class PresentationExchangeProofFormatService implements ProofFormatServic
const presentation = await ps.createPresentation(agentContext, {
presentationDefinition,
credentialsForInputDescriptor: credentials,
challenge: options?.challenge,
domain: options?.domain,
})

if (presentation.verifiablePresentations.length > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import { getIndySdkModules } from '../../../../../../../indy-sdk/tests/setupIndy
import { agentDependencies, getAgentConfig } from '../../../../../../tests'
import { Agent } from '../../../../../agent/Agent'
import { PresentationExchangeModule, PresentationExchangeService } from '../../../../presentation-exchange'
import {
W3cJsonLdVerifiableCredential,
W3cCredentialRecord,
W3cCredentialRepository,
CREDENTIALS_CONTEXT_V1_URL,
W3cJsonLdVerifiablePresentation,
} from '../../../../vc'
import { ProofsModule } from '../../../ProofsModule'
import { ProofState } from '../../../models'
import { V2ProofProtocol } from '../../../protocol'
Expand All @@ -29,19 +36,53 @@ const mockPresentationDefinition = (): PresentationDefinition => ({
constraints: {
fields: [
{
path: [
'$.credentialSubject.dateOfBirth',
'$.credentialSubject.dob',
'$.vc.credentialSubject.dateOfBirth',
'$.vc.credentialSubject.dob',
],
path: ['$.credentialSubject.id'],
},
],
},
},
],
})

const mockCredentialRecord = new W3cCredentialRecord({
tags: {},
credential: new W3cJsonLdVerifiableCredential({
id: 'did:some:id',
context: [CREDENTIALS_CONTEXT_V1_URL, 'https://www.w3.org/2018/credentials/examples/v1'],
type: ['VerifiableCredential', 'UniversityDegreeCredential'],
issuer: 'did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL',
issuanceDate: '2017-10-22T12:23:48Z',
credentialSubject: {
id: 'did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL',
},
proof: {
type: 'Ed25519Signature2020',
created: '2021-11-13T18:19:39Z',
verificationMethod: 'https://example.edu/issuers/14#key-1',
proofPurpose: 'assertionMethod',
proofValue: 'z58DAdFfa9SkqZMVPxAQpic7ndSayn1PzZs6ZjWp1CktyGesjuTSwRdoWhAfGFCF5bppETSTojQCrfFPP2oumHKtz',
},
}),
})

jest.spyOn(W3cCredentialRepository.prototype, 'getAll').mockResolvedValue([mockCredentialRecord])
jest.spyOn(PresentationExchangeService.prototype, 'createPresentation').mockResolvedValue({
presentationSubmission: { id: 'did:id', definition_id: 'my-id', descriptor_map: [] },
verifiablePresentations: [
new W3cJsonLdVerifiablePresentation({
verifiableCredential: [mockCredentialRecord.credential],
proof: {
type: 'Ed25519Signature2020',
created: '2021-11-13T18:19:39Z',
verificationMethod: 'https://example.edu/issuers/14#key-1',
proofPurpose: 'assertionMethod',
proofValue: 'z58DAdFfa9SkqZMVPxAQpic7ndSayn1PzZs6ZjWp1CktyGesjuTSwRdoWhAfGFCF5bppETSTojQCrfFPP2oumHKtz',
},
}),
],
presentationSubmissionLocation: 0,
})

describe('Presentation Exchange ProofFormatService', () => {
let pexFormatService: ProofFormatService<PresentationExchangeProofFormat>
let agent: Agent
Expand Down Expand Up @@ -98,7 +139,12 @@ describe('Presentation Exchange ProofFormatService', () => {
id: expect.any(String),
mimeType: 'application/json',
data: {
json: presentationDefinition,
json: {
options: {
challenge: 'TODO',
},
presentation_definition: presentationDefinition,
},
},
})

Expand All @@ -120,20 +166,41 @@ describe('Presentation Exchange ProofFormatService', () => {
const { attachment, format } = await pexFormatService.acceptRequest(agent.context, {
proofRecord: mockProofRecord(),
requestAttachment,
proofFormats: { presentationExchange: { credentials: [] } },
proofFormats: { presentationExchange: { credentials: [mockCredentialRecord] } },
})

expect(attachment).toMatchObject({
id: expect.any(String),
mimeType: 'application/json',
data: {
json: {},
json: {
presentation_submission: {
id: expect.any(String),
definition_id: expect.any(String),
descriptor_map: [],
},
context: expect.any(Array),
type: expect.any(Array),
verifiableCredential: [
{
context: expect.any(Array),
id: expect.any(String),
type: expect.any(Array),
issuer: expect.any(String),
issuanceDate: expect.any(String),
credentialSubject: {
id: expect.any(String),
},
proof: expect.any(Object),
},
],
},
},
})

expect(format).toMatchObject({
attachmentId: expect.any(String),
format: 'dif/presentation-exchange/definitions@v1.0',
format: 'dif/presentation-exchange/submission@v1.0',
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe('Present Proof', () => {
let issuerAgent: Agent<ReturnType<typeof getJsonLdModules>>
let verifierAgent: Agent<ReturnType<typeof getJsonLdModules>>

let verifierProverConnectionId: string
let issuerProverConnectionId: string
let proverVerifierConnectionId: string

Expand All @@ -55,7 +54,6 @@ describe('Present Proof', () => {
holderAgent: proverAgent,
issuerAgent,
verifierAgent,
verifierHolderConnectionId: verifierProverConnectionId,
issuerHolderConnectionId: issuerProverConnectionId,
holderVerifierConnectionId: proverVerifierConnectionId,
} = await setupJsonLdTests({
Expand Down
Loading

0 comments on commit 436b922

Please sign in to comment.