Skip to content

Commit

Permalink
fix(present-proof): isolated tests
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <[email protected]>
  • Loading branch information
berendsliedrecht committed Jan 10, 2024
1 parent 40c9bb6 commit 4a6a2a7
Showing 1 changed file with 115 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ describe('Present Proof', () => {
let issuerProverConnectionId: string
let proverVerifierConnectionId: string

let verifierProofExchangeRecord: ProofExchangeRecord
let proverProofExchangeRecord: ProofExchangeRecord

let didCommMessageRepository: DidCommMessageRepository

beforeAll(async () => {
testLogger.test('Initializing the agents')
;({
Expand Down Expand Up @@ -98,7 +93,7 @@ describe('Present Proof', () => {
state: ProofState.ProposalReceived,
})

proverProofExchangeRecord = await proverAgent.proofs.proposeProof({
await proverAgent.proofs.proposeProof({
connectionId: proverVerifierConnectionId,
protocolVersion: 'v2',
proofFormats: {
Expand All @@ -113,9 +108,10 @@ describe('Present Proof', () => {
})

testLogger.test('Verifier waits for presentation from the Prover')
verifierProofExchangeRecord = await verifierPresentationRecordPromise
const verifierProofExchangeRecord = await verifierPresentationRecordPromise

didCommMessageRepository = proverAgent.dependencyManager.resolve<DidCommMessageRepository>(DidCommMessageRepository)
const didCommMessageRepository =
proverAgent.dependencyManager.resolve<DidCommMessageRepository>(DidCommMessageRepository)

const proposal = await didCommMessageRepository.findAgentMessage(verifierAgent.context, {
associatedRecordId: verifierProofExchangeRecord.id,
Expand Down Expand Up @@ -153,20 +149,42 @@ describe('Present Proof', () => {
})

test(`Verifier accepts the Proposal send by the Prover`, async () => {
testLogger.test('Prover sends proof proposal to a Verifier')

let proverProofExchangeRecord = await proverAgent.proofs.proposeProof({
connectionId: proverVerifierConnectionId,
protocolVersion: 'v2',
proofFormats: {
presentationExchange: {
presentationDefinition: {
id: 'e950bfe5-d7ec-4303-ad61-6983fb976ac9',
input_descriptors: [TEST_INPUT_DESCRIPTORS_CITIZENSHIP],
},
},
},
comment: 'V2 Presentation Exchange propose proof test',
})

const verifierPresentationRecordPromise = waitForProofExchangeRecord(verifierAgent, {
state: ProofState.ProposalReceived,
})

const proverPresentationRecordPromise = waitForProofExchangeRecord(proverAgent, {
threadId: verifierProofExchangeRecord.threadId,
threadId: proverProofExchangeRecord.threadId,
state: ProofState.RequestReceived,
})

testLogger.test('Verifier accepts presentation proposal from the Prover')
let verifierProofExchangeRecord = await verifierPresentationRecordPromise
verifierProofExchangeRecord = await verifierAgent.proofs.acceptProposal({
proofRecordId: verifierProofExchangeRecord.id,
})

testLogger.test('Prover waits for proof request from the Verifier')
proverProofExchangeRecord = await proverPresentationRecordPromise

didCommMessageRepository = proverAgent.dependencyManager.resolve<DidCommMessageRepository>(DidCommMessageRepository)
const didCommMessageRepository =
proverAgent.dependencyManager.resolve<DidCommMessageRepository>(DidCommMessageRepository)

const request = await didCommMessageRepository.findAgentMessage(proverAgent.context, {
associatedRecordId: proverProofExchangeRecord.id,
Expand Down Expand Up @@ -214,6 +232,40 @@ describe('Present Proof', () => {
})

test(`Prover accepts presentation request from the Verifier`, async () => {
testLogger.test('Prover sends proof proposal to a Verifier')

let proverProofExchangeRecord = await proverAgent.proofs.proposeProof({
connectionId: proverVerifierConnectionId,
protocolVersion: 'v2',
proofFormats: {
presentationExchange: {
presentationDefinition: {
id: 'e950bfe5-d7ec-4303-ad61-6983fb976ac9',
input_descriptors: [TEST_INPUT_DESCRIPTORS_CITIZENSHIP],
},
},
},
comment: 'V2 Presentation Exchange propose proof test',
})

const verifierProposalReceivedPresentationRecordPromise = waitForProofExchangeRecord(verifierAgent, {
state: ProofState.ProposalReceived,
})

const proverPresentationRecordPromise = waitForProofExchangeRecord(proverAgent, {
threadId: proverProofExchangeRecord.threadId,
state: ProofState.RequestReceived,
})

testLogger.test('Verifier accepts presentation proposal from the Prover')
let verifierProofExchangeRecord = await verifierProposalReceivedPresentationRecordPromise
verifierProofExchangeRecord = await verifierAgent.proofs.acceptProposal({
proofRecordId: verifierProofExchangeRecord.id,
})

testLogger.test('Prover waits for proof request from the Verifier')
proverProofExchangeRecord = await proverPresentationRecordPromise

// Prover retrieves the requested credentials and accepts the presentation request
testLogger.test('Prover accepts presentation request from Verifier')

Expand All @@ -230,100 +282,14 @@ describe('Present Proof', () => {
testLogger.test('Verifier waits for presentation from the Prover')
verifierProofExchangeRecord = await verifierPresentationRecordPromise

const didCommMessageRepository =
verifierAgent.dependencyManager.resolve<DidCommMessageRepository>(DidCommMessageRepository)

const presentation = await didCommMessageRepository.findAgentMessage(verifierAgent.context, {
associatedRecordId: verifierProofExchangeRecord.id,
messageClass: V2PresentationMessage,
})

// {
// "@type":"https://didcomm.org/present-proof/2.0/presentation",
// "last_presentation":true,
// "formats":[
// {
// "attach_id":"97cf1dbf-2ce0-4641-9083-00f4aec99478",
// "format":"dif/presentation-exchange/[email protected]"
// }
// ],
// "presentations~attach":[
// {
// "@id":"97cf1dbf-2ce0-4641-9083-00f4aec99478",
// "mime-type":"application/json",
// "data":{
// "json":{
// "presentation_submission":{
// "id":"dHOs_n7UF7QAbJvEovHeW",
// "definition_id":"e950bfe5-d7ec-4303-ad61-6983fb976ac9",
// "descriptor_map":[
// {
// "id":"citizenship_input_1",
// "format":"ldp_vp",
// "path":"$",
// "path_nested":{
// "id":"citizenship_input_1",
// "format":"ldp_vc ",
// "path":"$.verifiableCredential[0]"
// }
// }
// ]
// },
// "context":[
// "https://www.w3.org/2018/credentials/v1"
// ],
// "type":[
// "VerifiableP resentation"
// ],
// "holder":"did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL",
// "verifiableCredential":[
// {
// "@context":[
// "https://www.w3.org/2018/credentials/v1",
// "https://www.w3.org/2018/credentials/examples/v1"
// ],
// "type":[
// "Verifiab leCredential",
// "UniversityDegreeCredential"
// ],
// "issuer":"did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL",
// "issuanceDate":"2017-10-22T12:23:48Z",
// "credentialSubject":{
// "id":"did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38Eef XmgDL",
// "degree":{
// "type":"BachelorDegree",
// "name":"Bachelor of Science and Arts"
// }
// },
// "proof":{
// "verificationMethod":"di d:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL#z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL",
// "type":"E d25519Signature2018",
// "created":"2023-12-19T12:38:36Z",
// "proofPurpose":"assertionMethod",
// "jws":"eyJhbGciOiJFZERTQSIs ImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..U3oPjRgz-fTd_kkUtNgWKh-FRWWkKdy0iSgOiGA1d7IyImuL1URQwJjd3UlJAkFf1kl7NeakiCtZ cFfxkPpECQ"
// }
// }
// ],
// "proof":{
// "verificationMethod":"did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL#z6Mkgg342Yc puk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL",
// "type":"Ed25519Signature2018",
// "created":"2023-12-19T12:38:37Z",
// "proofPurpos e":"authentication",
// "challenge":"273899451763000636595367",
// "jws":"eyJhbGciOiJFZERTQSIsImI2NCI6ZmFsc2UsImNyaXQiOlsi YjY0Il19..X_pR5Evhj-byuMkhJfXfoj9HO03iLKtltq64A4cueuLAH-Ix5D-G9g7r4xec9ysyga8GS2tZQl0OK4W9LJcOAQ"
// }
// }
// }
// }
// ],
// "@id":"2cdf aa16-d132-4778-9d6f-622fc0e0fa84",
// "~thread":{
// "thid":"e03cfab3-7ab1-477f-9df7-dc7ede70b952"
// },
// "~please_ack":{
// "on":[
// " RECEIPT"
// ]
// }
// }

expect(presentation).toMatchObject({
type: 'https://didcomm.org/present-proof/2.0/presentation',
formats: [
Expand Down Expand Up @@ -403,6 +369,56 @@ describe('Present Proof', () => {
})

test(`Verifier accepts the presentation provided by the Prover`, async () => {
testLogger.test('Prover sends proof proposal to a Verifier')

let proverProofExchangeRecord = await proverAgent.proofs.proposeProof({
connectionId: proverVerifierConnectionId,
protocolVersion: 'v2',
proofFormats: {
presentationExchange: {
presentationDefinition: {
id: 'e950bfe5-d7ec-4303-ad61-6983fb976ac9',
input_descriptors: [TEST_INPUT_DESCRIPTORS_CITIZENSHIP],
},
},
},
comment: 'V2 Presentation Exchange propose proof test',
})

const verifierProposalReceivedPresentationRecordPromise = waitForProofExchangeRecord(verifierAgent, {
state: ProofState.ProposalReceived,
})

const proverPresentationRecordPromise = waitForProofExchangeRecord(proverAgent, {
threadId: proverProofExchangeRecord.threadId,
state: ProofState.RequestReceived,
})

testLogger.test('Verifier accepts presentation proposal from the Prover')
let verifierProofExchangeRecord = await verifierProposalReceivedPresentationRecordPromise
verifierProofExchangeRecord = await verifierAgent.proofs.acceptProposal({
proofRecordId: verifierProofExchangeRecord.id,
})

testLogger.test('Prover waits for proof request from the Verifier')
proverProofExchangeRecord = await proverPresentationRecordPromise

// Prover retrieves the requested credentials and accepts the presentation request
testLogger.test('Prover accepts presentation request from Verifier')

const verifierPresentationRecordPromise = waitForProofExchangeRecord(verifierAgent, {
threadId: verifierProofExchangeRecord.threadId,
state: ProofState.PresentationReceived,
})

await proverAgent.proofs.acceptRequest({
proofRecordId: proverProofExchangeRecord.id,
})

// Verifier waits for the presentation from the Prover
testLogger.test('Verifier waits for presentation from the Prover')
verifierProofExchangeRecord = await verifierPresentationRecordPromise

const proverProofExchangeRecordPromise = waitForProofExchangeRecord(proverAgent, {
threadId: proverProofExchangeRecord.threadId,
state: ProofState.Done,
Expand Down

0 comments on commit 4a6a2a7

Please sign in to comment.