Skip to content

Commit

Permalink
feat: add oob proof proposal
Browse files Browse the repository at this point in the history
Signed-off-by: Pritam Singh <[email protected]>
  • Loading branch information
Zzocker committed Mar 7, 2023
1 parent 953069a commit d760d9a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class V1ProofProtocol extends BaseProofProtocol implements ProofProtocol<

// Create record
const proofRecord = new ProofExchangeRecord({
connectionId: connectionRecord.id,
connectionId: connectionRecord?.id,
threadId: message.threadId,
parentThreadId: message.thread?.parentThreadId,
state: ProofState.ProposalSent,
Expand Down
21 changes: 21 additions & 0 deletions packages/core/src/modules/proofs/ProofsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
AcceptProofOptions,
AcceptProofProposalOptions,
AcceptProofRequestOptions,
CreateProofProposalOptions,
CreateProofRequestOptions,
DeleteProofOptions,
FindProofPresentationMessageReturn,
Expand Down Expand Up @@ -164,6 +165,26 @@ export class ProofsApi<PPs extends ProofProtocol[]> implements ProofsApi<PPs> {
return proofRecord
}

/**
* Initiate a new presentation exchange as prover by sending an out of band proof proposal message
*
* @param options multiple properties like protocol version, proof Formats to build the proof request
* @returns the message itself and the proof record associated with the sent request message
*/
public async createProofProposal(options: CreateProofProposalOptions<PPs>): Promise<{
message: AgentMessage
proofRecord: ProofExchangeRecord
}> {
const protocol = this.getProtocol(options.protocolVersion)
return await protocol.createProposal(this.agentContext, {
proofFormats: options.proofFormats,
autoAcceptProof: options.autoAcceptProof,
goalCode: options.goalCode,
comment: options.comment,
parentThreadId: options.parentThreadId,
})
}

/**
* Accept a presentation proposal as verifier (by sending a presentation request message) to the connection
* associated with the proof record.
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/modules/proofs/ProofsApiOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ export interface ProposeProofOptions<PPs extends ProofProtocol[] = ProofProtocol
parentThreadId?: string
}

/**
* Interface for ProofsApi.createProofProposal. Will create an out of band request.
*/
export interface CreateProofProposalOptions<PPs extends ProofProtocol[] = ProofProtocol[]> extends BaseOptions {
protocolVersion: ProofsProtocolVersionType<PPs>
proofFormats: ProofFormatPayload<ProofFormatsFromProtocols<PPs>, 'createProposal'>

goalCode?: string
parentThreadId?: string
}

/**
* Interface for ProofsApi.acceptProposal. Will send a request
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ interface BaseOptions {
}

export interface CreateProofProposalOptions<PFs extends ProofFormatService[]> extends BaseOptions {
connectionRecord: ConnectionRecord
connectionRecord?: ConnectionRecord
proofFormats: ProofFormatPayload<ExtractProofFormats<PFs>, 'createProposal'>
parentThreadId?: string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class V2ProofProtocol<PFs extends ProofFormatService[] = ProofFormatServi
}

const proofRecord = new ProofExchangeRecord({
connectionId: connectionRecord.id,
connectionId: connectionRecord?.id,
threadId: uuid(),
parentThreadId,
state: ProofState.ProposalSent,
Expand Down Expand Up @@ -396,6 +396,11 @@ export class V2ProofProtocol<PFs extends ProofFormatService[] = ProofFormatServi
connection?.id
)

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

const formatServices = this.getFormatServicesFromMessage(requestMessage.formats)
if (formatServices.length === 0) {
throw new AriesFrameworkError(`Unable to process request. No supported formats`)
Expand Down

0 comments on commit d760d9a

Please sign in to comment.