Skip to content

Commit

Permalink
feat: added declined proof state and decline method for presentations
Browse files Browse the repository at this point in the history
Signed-off-by: seajensen <[email protected]>
  • Loading branch information
sabejensen authored Oct 31, 2021
1 parent b1e2b8c commit e5aedd0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/src/modules/proofs/ProofState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export enum ProofState {
RequestReceived = 'request-received',
PresentationSent = 'presentation-sent',
PresentationReceived = 'presentation-received',
Declined = 'declined',
Done = 'done',
}
11 changes: 11 additions & 0 deletions packages/core/src/modules/proofs/ProofsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,17 @@ export class ProofsModule {
}
}

/**
* Declines a proof request as holder
* @param proofRecordId the id of the proof request to be declined
* @returns proof record that was declined
*/
public async declineRequest(proofRecordId: string) {
const proofRecord = await this.proofService.getById(proofRecordId)
await this.proofService.declineRequest(proofRecord)
return proofRecord
}

/**
* Accept a presentation as prover (by sending a presentation acknowledgement message) to the connection
* associated with the proof record.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('ProofState', () => {
expect(ProofState.RequestReceived).toBe('request-received')
expect(ProofState.PresentationSent).toBe('presentation-sent')
expect(ProofState.PresentationReceived).toBe('presentation-received')
expect(ProofState.Declined).toBe('declined')
expect(ProofState.Done).toBe('done')
})
})
12 changes: 12 additions & 0 deletions packages/core/src/modules/proofs/services/ProofService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ export class ProofService {
return { message: proposalMessage, proofRecord }
}

/**
* Decline a proof request
* @param proofRecord The proof request to be declined
*/
public async declineRequest(proofRecord: ProofRecord): Promise<ProofRecord> {
proofRecord.assertState(ProofState.RequestReceived)

await this.updateState(proofRecord, ProofState.Declined)

return proofRecord
}

/**
* Process a received {@link ProposePresentationMessage}. This will not accept the presentation proposal
* or send a presentation request. It will only create a new, or update the existing proof record with
Expand Down

0 comments on commit e5aedd0

Please sign in to comment.