Skip to content

Commit

Permalink
feat(proofs): delete associated didcomm messages (openwallet-foundati…
Browse files Browse the repository at this point in the history
…on#1021)

Signed-off-by: Timo Glastra <[email protected]>
Signed-off-by: Ariel Gentile <[email protected]>
  • Loading branch information
TimoGlastra authored and genaris committed Sep 16, 2022
1 parent b9136d0 commit 1b05d5e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ export interface CredentialProtocolMsgReturnType<MessageType extends AgentMessag
}

export interface DeleteCredentialOptions {
deleteAssociatedCredentials: boolean
deleteAssociatedDidCommMessages: boolean
deleteAssociatedCredentials?: boolean
deleteAssociatedDidCommMessages?: boolean
}
20 changes: 20 additions & 0 deletions packages/core/src/modules/proofs/ProofService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type {
CreateProposalOptions,
CreateRequestAsResponseOptions,
CreateRequestOptions,
DeleteProofOptions,
FormatRequestedCredentialReturn,
FormatRetrievedCredentialOptions,
GetRequestedCredentialsForProofRequestOptions,
Expand Down Expand Up @@ -216,6 +217,25 @@ export abstract class ProofService<PFs extends ProofFormat[] = ProofFormat[]> {
})
}

public async delete(
agentContext: AgentContext,
proofRecord: ProofRecord,
options?: DeleteProofOptions
): Promise<void> {
await this.proofRepository.delete(agentContext, proofRecord)

const deleteAssociatedDidCommMessages = options?.deleteAssociatedDidCommMessages ?? true

if (deleteAssociatedDidCommMessages) {
const didCommMessages = await this.didCommMessageRepository.findByQuery(agentContext, {
associatedRecordId: proofRecord.id,
})
for (const didCommMessage of didCommMessages) {
await this.didCommMessageRepository.delete(agentContext, didCommMessage)
}
}
}

public abstract getRequestedCredentialsForProofRequest(
agentContext: AgentContext,
options: GetRequestedCredentialsForProofRequestOptions
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/modules/proofs/ProofsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {
CreateProofRequestFromProposalOptions,
FormatRequestedCredentialReturn,
FormatRetrievedCredentialOptions,
DeleteProofOptions,
} from './models/ProofServiceOptions'
import type { ProofRecord } from './repository/ProofRecord'

Expand Down Expand Up @@ -510,9 +511,10 @@ export class ProofsApi<
*
* @param proofId the proof record id
*/
public async deleteById(proofId: string) {
public async deleteById(proofId: string, options?: DeleteProofOptions) {
const proofRecord = await this.getById(proofId)
return await this.proofRepository.delete(this.agentContext, proofRecord)
const service = this.getService(proofRecord.protocolVersion)
return service.delete(this.agentContext, proofRecord, options)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ export interface ProofRequestFromProposalOptions<PFs extends ProofFormat[]> {
proofRecord: ProofRecord
proofFormats: ProofFormatPayload<PFs, 'createProofRequestFromProposal'>
}

export interface DeleteProofOptions {
deleteAssociatedDidCommMessages?: boolean
}

0 comments on commit 1b05d5e

Please sign in to comment.