Skip to content

Commit

Permalink
fix: add v1 oob proof proposal test
Browse files Browse the repository at this point in the history
Signed-off-by: Pritam Singh <[email protected]>
  • Loading branch information
Zzocker committed Mar 9, 2023
1 parent 0d97681 commit cb4badf
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/anoncreds/src/protocols/proofs/v1/V1ProofProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ export class V1ProofProtocol extends BaseProofProtocol implements ProofProtocol<

let proofRecord = await this.findByThreadAndConnectionId(agentContext, proofRequestMessage.threadId, connection?.id)

if (!proofRecord) {
// Proof request not bound to any connection: requests_attach in OOB msg
proofRecord = await this.findByThreadAndConnectionId(messageContext.agentContext, proofRequestMessage.threadId)
if (proofRecord) proofRecord.connectionId = connection?.id
}

const requestAttachment = proofRequestMessage.getRequestAttachmentById(INDY_PROOF_REQUEST_ATTACHMENT_ID)
if (!requestAttachment) {
throw new AriesFrameworkError(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
import type { EventReplaySubject } from '../../../../../../core/tests'
import type { AnonCredsTestsAgent } from '../../../../../tests/legacyAnonCredsSetup'

import { ProofState } from '../../../../../../core/src'
import { testLogger, waitForProofExchangeRecord } from '../../../../../../core/tests'
import { setupAnonCredsTests } from '../../../../../tests/legacyAnonCredsSetup'
import { issueLegacyAnonCredsCredential, setupAnonCredsTests } from '../../../../../tests/legacyAnonCredsSetup'
import { V1PresentationMessage, V1ProposePresentationMessage, V1RequestPresentationMessage } from '../messages'

describe('Present Proof', () => {
let faberAgent: AnonCredsTestsAgent
let faberReplay: EventReplaySubject
let aliceAgent: AnonCredsTestsAgent
let aliceReplay: EventReplaySubject
let aliceConnectionId: string
let faberConnectionId: string
let credentialDefinitionId: string

beforeAll(async () => {
testLogger.test('Initializing the agents')
;({
issuerAgent: faberAgent,
issuerReplay: faberReplay,
holderAgent: aliceAgent,
holderReplay: aliceReplay,
credentialDefinitionId,
holderIssuerConnectionId: aliceConnectionId,
issuerHolderConnectionId: faberConnectionId,
} = await setupAnonCredsTests({
issuerName: 'Faber - V1 Indy Proof Request',
holderName: 'Alice - V1 Indy Proof Request',
Expand Down Expand Up @@ -103,4 +111,114 @@ describe('Present Proof', () => {
protocolVersion: 'v1',
})
})

test('Alice Creates oob proof proposal for Faber', async () => {
await issueLegacyAnonCredsCredential({
issuerAgent: faberAgent,
issuerReplay: faberReplay,
holderAgent: aliceAgent,
holderReplay: aliceReplay,
issuerHolderConnectionId: faberConnectionId,
offer: {
credentialDefinitionId,
attributes: [
{
name: 'name',
value: 'Alice',
},
{
name: 'age',
value: '99',
},
],
},
})
testLogger.test('Alice creates oob proof proposal for Faber')
const { message } = await aliceAgent.proofs.createProofProposal({
protocolVersion: 'v1',
proofFormats: {
indy: {
name: 'ProofRequest',
version: '1.0',
attributes: [
{
name: 'name',
value: 'John',
credentialDefinitionId,
referent: '0',
},
],
predicates: [
{
name: 'age',
predicate: '>=',
threshold: 50,
credentialDefinitionId,
},
],
},
},
comment: 'V1 propose proof test',
})
const { outOfBandInvitation } = await aliceAgent.oob.createInvitation({
messages: [message],
autoAcceptConnection: true,
})
await faberAgent.oob.receiveInvitation(outOfBandInvitation)
testLogger.test('Faber waits for proof proposal message from Alice')
let faberProofExchangeRecord = await waitForProofExchangeRecord(faberAgent, {
state: ProofState.ProposalReceived,
})

// Faber accepts the presentation proposal from Alice
testLogger.test('Faber accepts presentation proposal from Alice')
faberProofExchangeRecord = await faberAgent.proofs.acceptProposal({
proofRecordId: faberProofExchangeRecord.id,
})

// ALice waits for presentation request from Faber
testLogger.test('Alice waits for presentation request from Faber')
let aliceProofExchangeRecord = await waitForProofExchangeRecord(aliceAgent, {
state: ProofState.RequestReceived,
})
expect(aliceProofExchangeRecord.connectionId).not.toBeNull()

// Alice retrieves the requested credentials and accepts the presentation
testLogger.test('Alice accepts presentation request from Faber')
const requestedCredentials = await aliceAgent.proofs.selectCredentialsForRequest({
proofRecordId: aliceProofExchangeRecord.id,
})
await aliceAgent.proofs.acceptRequest({
proofRecordId: aliceProofExchangeRecord.id,
proofFormats: { indy: requestedCredentials.proofFormats.indy },
})

// Faber waits for the presentation from Alice
testLogger.test('Faber waits for presentation from Alice')
faberProofExchangeRecord = await waitForProofExchangeRecord(faberAgent, {
threadId: aliceProofExchangeRecord.threadId,
state: ProofState.PresentationReceived,
})

// Faber accepts the presentation provided by Alice
testLogger.test('Faber accepts the presentation provided by Alice')
await faberAgent.proofs.acceptPresentation({
proofRecordId: faberProofExchangeRecord.id,
})

// Alice waits utils she received a presentation acknowledgement
testLogger.test('Alice waits until she receives a presentation acknowledgement')
aliceProofExchangeRecord = await waitForProofExchangeRecord(aliceAgent, {
threadId: aliceProofExchangeRecord.threadId,
state: ProofState.Done,
})

const proposalMessage = await aliceAgent.proofs.findProposalMessage(aliceProofExchangeRecord.id)
const requestMessage = await aliceAgent.proofs.findRequestMessage(aliceProofExchangeRecord.id)
const presentationMessage = await aliceAgent.proofs.findPresentationMessage(aliceProofExchangeRecord.id)

expect(proposalMessage).toBeInstanceOf(V1ProposePresentationMessage)
expect(requestMessage).toBeInstanceOf(V1RequestPresentationMessage)
expect(presentationMessage).toBeInstanceOf(V1PresentationMessage)
})
})

0 comments on commit cb4badf

Please sign in to comment.