Skip to content

Commit

Permalink
feat: default return route (#1327)
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Richardson <mike.richardson@ontario.ca>
  • Loading branch information
NB-MikeRichardson committed Mar 20, 2023
1 parent 343ce6a commit dbfebb4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ describe('V1 Proofs - Connectionless - Indy', () => {
}
})

test('Faber starts with connection-less proof requests to Alice', async () => {
// new method to test the return route and mediator together
const connectionlessTest = async (returnRoute?: boolean) => {
const {
holderAgent: aliceAgent,
issuerAgent: faberAgent,
Expand Down Expand Up @@ -134,6 +135,7 @@ describe('V1 Proofs - Connectionless - Indy', () => {

await aliceAgent.proofs.acceptRequest({
proofRecordId: aliceProofExchangeRecord.id,
useReturnRoute: returnRoute,
proofFormats: { indy: requestedCredentials.proofFormats.indy },
})

Expand All @@ -143,6 +145,7 @@ describe('V1 Proofs - Connectionless - Indy', () => {
state: ProofState.PresentationReceived,
})

const sentPresentationMessage = aliceAgent.proofs.findPresentationMessage(aliceProofExchangeRecord.id)
// assert presentation is valid
expect(faberProofExchangeRecord.isVerified).toBe(true)

Expand All @@ -154,6 +157,11 @@ describe('V1 Proofs - Connectionless - Indy', () => {
threadId: aliceProofExchangeRecord.threadId,
state: ProofState.Done,
})
return sentPresentationMessage
}

test('Faber starts with connection-less proof requests to Alice', async () => {
await connectionlessTest()
})

test('Faber starts with connection-less proof requests to Alice with auto-accept enabled', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/credentials/CredentialsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ export class CredentialsApi<CPs extends CredentialProtocol[]> implements Credent
serviceParams: {
service: recipientService.resolvedDidCommService,
senderKey: ourService.resolvedDidCommService.recipientKeys[0],
returnRoute: true,
returnRoute: false, // hard wire to be false since it's the end of the protocol so not needed here
},
})
)
Expand Down
7 changes: 2 additions & 5 deletions packages/core/src/modules/proofs/ProofsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,26 +341,23 @@ export class ProofsApi<PPs extends ProofProtocol[]> implements ProofsApi<PPs> {
autoAcceptProof: options.autoAcceptProof,
goalCode: options.goalCode,
})

// Set and save ~service decorator to record (to remember our verkey)
message.service = ourService
await this.didCommMessageRepository.saveOrUpdateAgentMessage(this.agentContext, {
agentMessage: message,
role: DidCommMessageRole.Sender,
associatedRecordId: proofRecord.id,
})

await this.messageSender.sendMessageToService(
new OutboundMessageContext(message, {
agentContext: this.agentContext,
serviceParams: {
service: recipientService.resolvedDidCommService,
senderKey: ourService.resolvedDidCommService.recipientKeys[0],
returnRoute: true,
returnRoute: options.useReturnRoute ?? true, // defaults to true if missing
},
})
)

return proofRecord
}
// Cannot send message without connectionId or ~service decorator
Expand Down Expand Up @@ -495,7 +492,7 @@ export class ProofsApi<PPs extends ProofProtocol[]> implements ProofsApi<PPs> {
serviceParams: {
service: recipientService.resolvedDidCommService,
senderKey: ourService.resolvedDidCommService.recipientKeys[0],
returnRoute: true,
returnRoute: false, // hard wire to be false since it's the end of the protocol so not needed here
},
})
)
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/modules/proofs/ProofsApiOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ export interface RequestProofOptions<PPs extends ProofProtocol[] = ProofProtocol
*/
export interface AcceptProofRequestOptions<PPs extends ProofProtocol[] = ProofProtocol[]> extends BaseOptions {
proofRecordId: string

/**
* whether to enable return routing on the send presentation message. This value only
* has an effect for connectionless exchanges.
*/
useReturnRoute?: boolean
proofFormats?: ProofFormatPayload<ProofFormatsFromProtocols<PPs>, 'acceptRequest'>

goalCode?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('V2 Connectionless Proofs - Indy', () => {
}
})

test('Faber starts with connection-less proof requests to Alice', async () => {
const connectionlessTest = async (returnRoute?: boolean) => {
const {
issuerAgent: faberAgent,
issuerReplay: faberReplay,
Expand Down Expand Up @@ -128,8 +128,9 @@ describe('V2 Connectionless Proofs - Indy', () => {
proofRecordId: aliceProofExchangeRecord.id,
})

await aliceAgent.proofs.acceptRequest({
aliceProofExchangeRecord = await aliceAgent.proofs.acceptRequest({
proofRecordId: aliceProofExchangeRecord.id,
useReturnRoute: returnRoute,
proofFormats: { indy: requestedCredentials.proofFormats.indy },
})

Expand All @@ -139,17 +140,24 @@ describe('V2 Connectionless Proofs - Indy', () => {
state: ProofState.PresentationReceived,
})

const sentPresentationMessage = aliceAgent.proofs.findPresentationMessage(aliceProofExchangeRecord.id)

// assert presentation is valid
expect(faberProofExchangeRecord.isVerified).toBe(true)

// Faber accepts presentation
await faberAgent.proofs.acceptPresentation({ proofRecordId: faberProofExchangeRecord.id })

// Alice waits till it receives presentation ack
// Alice waits until it receives presentation ack
aliceProofExchangeRecord = await waitForProofExchangeRecordSubject(aliceReplay, {
threadId: aliceProofExchangeRecord.threadId,
state: ProofState.Done,
})
return sentPresentationMessage
}

test('Faber starts with connection-less proof requests to Alice', async () => {
await connectionlessTest()
})

test('Faber starts with connection-less proof requests to Alice with auto-accept enabled', async () => {
Expand Down

0 comments on commit dbfebb4

Please sign in to comment.