Skip to content

Commit

Permalink
refactor(proofs)!: rename ProofRecord to ProofExchangeRecord (#1071)
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 authored Oct 25, 2022
1 parent d4fd1ae commit f777b3d
Show file tree
Hide file tree
Showing 42 changed files with 919 additions and 1,393 deletions.
4 changes: 2 additions & 2 deletions demo/src/Alice.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ConnectionRecord, CredentialExchangeRecord, ProofRecord } from '@aries-framework/core'
import type { ConnectionRecord, CredentialExchangeRecord, ProofExchangeRecord } from '@aries-framework/core'

import { BaseAgent } from './BaseAgent'
import { greenText, Output, redText } from './OutputClass'
Expand Down Expand Up @@ -51,7 +51,7 @@ export class Alice extends BaseAgent {
})
}

public async acceptProofRequest(proofRecord: ProofRecord) {
public async acceptProofRequest(proofRecord: ProofExchangeRecord) {
const requestedCredentials = await this.agent.proofs.autoSelectCredentialsForProofRequest({
proofRecordId: proofRecord.id,
config: {
Expand Down
4 changes: 2 additions & 2 deletions demo/src/AliceInquirer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CredentialExchangeRecord, ProofRecord } from '@aries-framework/core'
import type { CredentialExchangeRecord, ProofExchangeRecord } from '@aries-framework/core'

import { clear } from 'console'
import { textSync } from 'figlet'
Expand Down Expand Up @@ -78,7 +78,7 @@ export class AliceInquirer extends BaseInquirer {
}
}

public async acceptProofRequest(proofRecord: ProofRecord) {
public async acceptProofRequest(proofRecord: ProofExchangeRecord) {
const confirm = await inquirer.prompt([this.inquireConfirmation(Title.ProofRequestTitle)])
if (confirm.options === ConfirmOptions.No) {
await this.alice.agent.proofs.declineRequest(proofRecord.id)
Expand Down
4 changes: 2 additions & 2 deletions demo/src/Listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
BasicMessageStateChangedEvent,
CredentialExchangeRecord,
CredentialStateChangedEvent,
ProofRecord,
ProofExchangeRecord,
ProofStateChangedEvent,
} from '@aries-framework/core'
import type BottomBar from 'inquirer/lib/ui/bottom-bar'
Expand Down Expand Up @@ -78,7 +78,7 @@ export class Listener {
})
}

private async newProofRequestPrompt(proofRecord: ProofRecord, aliceInquirer: AliceInquirer) {
private async newProofRequestPrompt(proofRecord: ProofExchangeRecord, aliceInquirer: AliceInquirer) {
this.turnListenerOn()
await aliceInquirer.acceptProofRequest(proofRecord)
this.turnListenerOff()
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/modules/proofs/ProofEvents.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BaseEvent } from '../../agent/Events'
import type { ProofState } from './models/ProofState'
import type { ProofRecord } from './repository'
import type { ProofExchangeRecord } from './repository'

export enum ProofEventTypes {
ProofStateChanged = 'ProofStateChanged',
Expand All @@ -9,7 +9,7 @@ export enum ProofEventTypes {
export interface ProofStateChangedEvent extends BaseEvent {
type: typeof ProofEventTypes.ProofStateChanged
payload: {
proofRecord: ProofRecord
proofRecord: ProofExchangeRecord
previousState: ProofState | null
}
}
8 changes: 4 additions & 4 deletions packages/core/src/modules/proofs/ProofResponseCoordinator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AgentContext } from '../../agent/context/AgentContext'
import type { ProofRecord } from './repository'
import type { ProofExchangeRecord } from './repository'

import { injectable } from '../../plugins'

Expand Down Expand Up @@ -34,7 +34,7 @@ export class ProofResponseCoordinator {
/**
* Checks whether it should automatically respond to a proposal
*/
public shouldAutoRespondToProposal(agentContext: AgentContext, proofRecord: ProofRecord) {
public shouldAutoRespondToProposal(agentContext: AgentContext, proofRecord: ProofExchangeRecord) {
const autoAccept = ProofResponseCoordinator.composeAutoAccept(
proofRecord.autoAcceptProof,
agentContext.config.autoAcceptProofs
Expand All @@ -54,7 +54,7 @@ export class ProofResponseCoordinator {
/**
* Checks whether it should automatically respond to a request
*/
public shouldAutoRespondToRequest(agentContext: AgentContext, proofRecord: ProofRecord) {
public shouldAutoRespondToRequest(agentContext: AgentContext, proofRecord: ProofExchangeRecord) {
const autoAccept = ProofResponseCoordinator.composeAutoAccept(
proofRecord.autoAcceptProof,
agentContext.config.autoAcceptProofs
Expand All @@ -74,7 +74,7 @@ export class ProofResponseCoordinator {
/**
* Checks whether it should automatically respond to a presentation of proof
*/
public shouldAutoRespondToPresentation(agentContext: AgentContext, proofRecord: ProofRecord) {
public shouldAutoRespondToPresentation(agentContext: AgentContext, proofRecord: ProofExchangeRecord) {
const autoAccept = ProofResponseCoordinator.composeAutoAccept(
proofRecord.autoAcceptProof,
agentContext.config.autoAcceptProofs
Expand Down
52 changes: 31 additions & 21 deletions packages/core/src/modules/proofs/ProofService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type {
ProofRequestFromProposalOptions,
} from './models/ProofServiceOptions'
import type { ProofState } from './models/ProofState'
import type { ProofRecord, ProofRepository } from './repository'
import type { ProofExchangeRecord, ProofRepository } from './repository'

import { JsonTransformer } from '../../utils/JsonTransformer'

Expand Down Expand Up @@ -64,7 +64,11 @@ export abstract class ProofService<PFs extends ProofFormat[] = ProofFormat[]> {
return await this.wallet.generateNonce()
}

public emitStateChangedEvent(agentContext: AgentContext, proofRecord: ProofRecord, previousState: ProofState | null) {
public emitStateChangedEvent(
agentContext: AgentContext,
proofRecord: ProofExchangeRecord,
previousState: ProofState | null
) {
const clonedProof = JsonTransformer.clone(proofRecord)

this.eventEmitter.emit<ProofStateChangedEvent>(agentContext, {
Expand All @@ -84,15 +88,15 @@ export abstract class ProofService<PFs extends ProofFormat[] = ProofFormat[]> {
* @param newState The state to update to
*
*/
public async updateState(agentContext: AgentContext, proofRecord: ProofRecord, newState: ProofState) {
public async updateState(agentContext: AgentContext, proofRecord: ProofExchangeRecord, newState: ProofState) {
const previousState = proofRecord.state
proofRecord.state = newState
await this.proofRepository.update(agentContext, proofRecord)

this.emitStateChangedEvent(agentContext, proofRecord, previousState)
}

public update(agentContext: AgentContext, proofRecord: ProofRecord) {
public update(agentContext: AgentContext, proofRecord: ProofExchangeRecord) {
return this.proofRepository.update(agentContext, proofRecord)
}

Expand All @@ -107,7 +111,7 @@ export abstract class ProofService<PFs extends ProofFormat[] = ProofFormat[]> {
abstract createProposal(
agentContext: AgentContext,
options: CreateProposalOptions<PFs>
): Promise<{ proofRecord: ProofRecord; message: AgentMessage }>
): Promise<{ proofRecord: ProofExchangeRecord; message: AgentMessage }>

/**
* Create a proposal message in response to a received proof request message
Expand All @@ -122,7 +126,7 @@ export abstract class ProofService<PFs extends ProofFormat[] = ProofFormat[]> {
abstract createProposalAsResponse(
agentContext: AgentContext,
options: CreateProposalAsResponseOptions<PFs>
): Promise<{ proofRecord: ProofRecord; message: AgentMessage }>
): Promise<{ proofRecord: ProofExchangeRecord; message: AgentMessage }>

/**
* Process a received proposal message (does not accept yet)
Expand All @@ -142,48 +146,54 @@ export abstract class ProofService<PFs extends ProofFormat[] = ProofFormat[]> {
* 4. Loop through all format services to process proposal message
* 5. Save & return record
*/
abstract processProposal(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofRecord>
abstract processProposal(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofExchangeRecord>

abstract createRequest(
agentContext: AgentContext,
options: CreateRequestOptions<PFs>
): Promise<{ proofRecord: ProofRecord; message: AgentMessage }>
): Promise<{ proofRecord: ProofExchangeRecord; message: AgentMessage }>

abstract createRequestAsResponse(
agentContext: AgentContext,
options: CreateRequestAsResponseOptions<PFs>
): Promise<{ proofRecord: ProofRecord; message: AgentMessage }>
): Promise<{ proofRecord: ProofExchangeRecord; message: AgentMessage }>

abstract processRequest(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofRecord>
abstract processRequest(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofExchangeRecord>

abstract createPresentation(
agentContext: AgentContext,
options: CreatePresentationOptions<PFs>
): Promise<{ proofRecord: ProofRecord; message: AgentMessage }>
): Promise<{ proofRecord: ProofExchangeRecord; message: AgentMessage }>

abstract processPresentation(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofRecord>
abstract processPresentation(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofExchangeRecord>

abstract createAck(
agentContext: AgentContext,
options: CreateAckOptions
): Promise<{ proofRecord: ProofRecord; message: AgentMessage }>
): Promise<{ proofRecord: ProofExchangeRecord; message: AgentMessage }>

abstract processAck(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofRecord>
abstract processAck(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofExchangeRecord>

abstract createProblemReport(
agentContext: AgentContext,
options: CreateProblemReportOptions
): Promise<{ proofRecord: ProofRecord; message: AgentMessage }>
): Promise<{ proofRecord: ProofExchangeRecord; message: AgentMessage }>

abstract processProblemReport(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofRecord>
abstract processProblemReport(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofExchangeRecord>

public abstract shouldAutoRespondToProposal(agentContext: AgentContext, proofRecord: ProofRecord): Promise<boolean>
public abstract shouldAutoRespondToProposal(
agentContext: AgentContext,
proofRecord: ProofExchangeRecord
): Promise<boolean>

public abstract shouldAutoRespondToRequest(agentContext: AgentContext, proofRecord: ProofRecord): Promise<boolean>
public abstract shouldAutoRespondToRequest(
agentContext: AgentContext,
proofRecord: ProofExchangeRecord
): Promise<boolean>

public abstract shouldAutoRespondToPresentation(
agentContext: AgentContext,
proofRecord: ProofRecord
proofRecord: ProofExchangeRecord
): Promise<boolean>

public abstract registerHandlers(
Expand All @@ -204,7 +214,7 @@ export abstract class ProofService<PFs extends ProofFormat[] = ProofFormat[]> {
public async saveOrUpdatePresentationMessage(
agentContext: AgentContext,
options: {
proofRecord: ProofRecord
proofRecord: ProofExchangeRecord
message: AgentMessage
role: DidCommMessageRole
}
Expand All @@ -218,7 +228,7 @@ export abstract class ProofService<PFs extends ProofFormat[] = ProofFormat[]> {

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

0 comments on commit f777b3d

Please sign in to comment.