Skip to content

Commit b5fc7a6

Browse files
authored
refactor!: prefix DIDComm module and main classes (openwallet-foundation#2361)
Signed-off-by: Ariel Gentile <gentilester@gmail.com>
1 parent a4bdf6d commit b5fc7a6

File tree

785 files changed

+15588
-14435
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

785 files changed

+15588
-14435
lines changed

.changeset/fuzzy-nails-think.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@credo-ts/action-menu": minor
3+
"@credo-ts/anoncreds": minor
4+
"@credo-ts/question-answer": minor
5+
"@credo-ts/cheqd": minor
6+
"@credo-ts/drpc": minor
7+
"@credo-ts/didcomm": minor
8+
9+
---
10+
11+
- All `didcomm` package modules, APIs, models and services that are used for dependency injection now are prefixed with `DidComm` in its naming
12+
- DIDComm-related events have also changed their text string to make it possible to distinguish them from events triggered by other protocols
13+
- DIDComm credentials module API has been updated to use the term `credentialExchangeRecord` instead of `credentialRecord`, since it is usually confused with W3cCredentialRecords (and potentially other kind of credential records we might have). I took this opportunity to also update `declineOffer` options structure to match DIDComm proofs module API
14+
- DIDComm-related records were renamed, but their type is still the original one (e.g. `CredentialRecord`, `BasicMessageRecord`). Probably it's worth to take this major release to do the migration, but I'm afraid that it will be a bit risky, so I'm hesitating to do so or leaving it for some other major upgrade (if we think it's actually needed)

.changeset/purple-donkeys-camp.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ Previously:
3232
config,
3333
dependencies: agentDependencies,
3434
modules: {
35-
connections: new ConnectionsModule({
35+
connections: new DidCommConnectionsModule({
3636
autoAcceptConnections: true,
3737
})
3838
})
39-
this.agent.registerInboundTransport(new HttpInboundTransport({ port }))
39+
this.agent.registerInboundTransport(new DidCommHttpInboundTransport({ port }))
4040
this.agent.registerOutboundTransport(new HttpOutboundTransport())
4141

4242
```
@@ -57,10 +57,10 @@ Now:
5757
dependencies: agentDependencies,
5858
modules: {
5959
...getDefaultDidcommModules({ endpoints: ['https://myendpoint'] }),
60-
connections: new ConnectionsModule({
60+
connections: new DidCommConnectionsModule({
6161
autoAcceptConnections: true,
6262
})
6363
})
64-
agent.modules.didcomm.registerInboundTransport(new HttpInboundTransport({ port }))
65-
agent.modules.didcomm.registerOutboundTransport(new HttpOutboundTransport())
64+
agent.modules.didcomm.registerInboundTransport(new DidCommHttpInboundTransport({ port }))
65+
agent.modules.didcomm.registerOutboundTransport(new DidCommHttpOutboundTransport())
6666
```

demo/src/Alice.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import type { ConnectionRecord, CredentialExchangeRecord, ProofExchangeRecord } from '@credo-ts/didcomm'
1+
import type {
2+
DidCommConnectionRecord,
3+
DidCommCredentialExchangeRecord,
4+
DidCommProofExchangeRecord,
5+
} from '@credo-ts/didcomm'
26

37
import { BaseAgent } from './BaseAgent'
48
import { Output, greenText, redText } from './OutputClass'
@@ -35,7 +39,7 @@ export class Alice extends BaseAgent {
3539
return connectionRecord
3640
}
3741

38-
private async waitForConnection(connectionRecord: ConnectionRecord) {
42+
private async waitForConnection(connectionRecord: DidCommConnectionRecord) {
3943
const record = await this.agent.modules.connections.returnWhenIsConnected(connectionRecord.id)
4044
this.connected = true
4145
console.log(greenText(Output.ConnectionEstablished))
@@ -47,19 +51,19 @@ export class Alice extends BaseAgent {
4751
this.connectionRecordFaberId = await this.waitForConnection(connectionRecord)
4852
}
4953

50-
public async acceptCredentialOffer(credentialRecord: CredentialExchangeRecord) {
54+
public async acceptCredentialOffer(credentialExchangeRecord: DidCommCredentialExchangeRecord) {
5155
await this.agent.modules.credentials.acceptOffer({
52-
credentialRecordId: credentialRecord.id,
56+
credentialExchangeRecordId: credentialExchangeRecord.id,
5357
})
5458
}
5559

56-
public async acceptProofRequest(proofRecord: ProofExchangeRecord) {
60+
public async acceptProofRequest(proofExchangeRecord: DidCommProofExchangeRecord) {
5761
const requestedCredentials = await this.agent.modules.proofs.selectCredentialsForRequest({
58-
proofRecordId: proofRecord.id,
62+
proofExchangeRecordId: proofExchangeRecord.id,
5963
})
6064

6165
await this.agent.modules.proofs.acceptRequest({
62-
proofRecordId: proofRecord.id,
66+
proofExchangeRecordId: proofExchangeRecord.id,
6367
proofFormats: requestedCredentials.proofFormats,
6468
})
6569
console.log(greenText('\nProof request accepted!\n'))

demo/src/AliceInquirer.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CredentialExchangeRecord, ProofExchangeRecord } from '@credo-ts/didcomm'
1+
import type { DidCommCredentialExchangeRecord, DidCommProofExchangeRecord } from '@credo-ts/didcomm'
22

33
import { clear } from 'console'
44
import { textSync } from 'figlet'
@@ -69,21 +69,23 @@ export class AliceInquirer extends BaseInquirer {
6969
await this.processAnswer()
7070
}
7171

72-
public async acceptCredentialOffer(credentialRecord: CredentialExchangeRecord) {
72+
public async acceptCredentialOffer(credentialExchangeRecord: DidCommCredentialExchangeRecord) {
7373
const confirm = await prompt([this.inquireConfirmation(Title.CredentialOfferTitle)])
7474
if (confirm.options === ConfirmOptions.No) {
75-
await this.alice.agent.modules.credentials.declineOffer(credentialRecord.id)
75+
await this.alice.agent.modules.credentials.declineOffer({
76+
credentialExchangeRecordId: credentialExchangeRecord.id,
77+
})
7678
} else if (confirm.options === ConfirmOptions.Yes) {
77-
await this.alice.acceptCredentialOffer(credentialRecord)
79+
await this.alice.acceptCredentialOffer(credentialExchangeRecord)
7880
}
7981
}
8082

81-
public async acceptProofRequest(proofRecord: ProofExchangeRecord) {
83+
public async acceptProofRequest(proofExchangeRecord: DidCommProofExchangeRecord) {
8284
const confirm = await prompt([this.inquireConfirmation(Title.ProofRequestTitle)])
8385
if (confirm.options === ConfirmOptions.No) {
84-
await this.alice.agent.modules.proofs.declineRequest({ proofRecordId: proofRecord.id })
86+
await this.alice.agent.modules.proofs.declineRequest({ proofExchangeRecordId: proofExchangeRecord.id })
8587
} else if (confirm.options === ConfirmOptions.Yes) {
86-
await this.alice.acceptProofRequest(proofRecord)
88+
await this.alice.acceptProofRequest(proofExchangeRecord)
8789
}
8890
}
8991

demo/src/BaseAgent.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import type { DidCommModuleConfigOptions } from '@credo-ts/didcomm'
22
import type { IndyVdrPoolConfig } from '@credo-ts/indy-vdr'
33

44
import {
5-
AnonCredsCredentialFormatService,
5+
AnonCredsDidCommCredentialFormatService,
6+
AnonCredsDidCommProofFormatService,
67
AnonCredsModule,
7-
AnonCredsProofFormatService,
8-
LegacyIndyCredentialFormatService,
9-
LegacyIndyProofFormatService,
10-
V1CredentialProtocol,
11-
V1ProofProtocol,
8+
DidCommCredentialV1Protocol,
9+
DidCommProofV1Protocol,
10+
LegacyIndyDidCommCredentialFormatService,
11+
LegacyIndyDidCommProofFormatService,
1212
} from '@credo-ts/anoncreds'
1313
import { AskarModule } from '@credo-ts/askar'
1414
import {
@@ -20,18 +20,18 @@ import {
2020
} from '@credo-ts/cheqd'
2121
import { Agent, DidsModule } from '@credo-ts/core'
2222
import {
23-
AutoAcceptCredential,
24-
AutoAcceptProof,
25-
ConnectionsModule,
26-
CredentialsModule,
27-
HttpOutboundTransport,
28-
ProofsModule,
29-
V2CredentialProtocol,
30-
V2ProofProtocol,
23+
DidCommAutoAcceptCredential,
24+
DidCommAutoAcceptProof,
25+
DidCommConnectionsModule,
26+
DidCommCredentialV2Protocol,
27+
DidCommCredentialsModule,
28+
DidCommHttpOutboundTransport,
29+
DidCommProofV2Protocol,
30+
DidCommProofsModule,
3131
getDefaultDidcommModules,
3232
} from '@credo-ts/didcomm'
3333
import { IndyVdrAnonCredsRegistry, IndyVdrIndyDidResolver, IndyVdrModule } from '@credo-ts/indy-vdr'
34-
import { HttpInboundTransport, agentDependencies } from '@credo-ts/node'
34+
import { DidCommHttpInboundTransport, agentDependencies } from '@credo-ts/node'
3535
import { anoncreds } from '@hyperledger/anoncreds-nodejs'
3636
import { indyVdr } from '@hyperledger/indy-vdr-nodejs'
3737
import { askar } from '@openwallet-foundation/askar-nodejs'
@@ -67,8 +67,8 @@ export class BaseAgent {
6767
dependencies: agentDependencies,
6868
modules: getAskarAnonCredsIndyModules({ endpoints: [`http://localhost:${this.port}`] }, { id: name, key: name }),
6969
})
70-
this.agent.modules.didcomm.registerInboundTransport(new HttpInboundTransport({ port }))
71-
this.agent.modules.didcomm.registerOutboundTransport(new HttpOutboundTransport())
70+
this.agent.modules.didcomm.registerInboundTransport(new DidCommHttpInboundTransport({ port }))
71+
this.agent.modules.didcomm.registerOutboundTransport(new DidCommHttpOutboundTransport())
7272
}
7373

7474
public async initializeAgent() {
@@ -82,33 +82,33 @@ function getAskarAnonCredsIndyModules(
8282
didcommConfig: DidCommModuleConfigOptions,
8383
askarStoreConfig: AskarModuleConfigStoreOptions
8484
) {
85-
const legacyIndyCredentialFormatService = new LegacyIndyCredentialFormatService()
86-
const legacyIndyProofFormatService = new LegacyIndyProofFormatService()
85+
const legacyIndyCredentialFormatService = new LegacyIndyDidCommCredentialFormatService()
86+
const legacyIndyProofFormatService = new LegacyIndyDidCommProofFormatService()
8787

8888
return {
8989
...getDefaultDidcommModules(didcommConfig),
90-
connections: new ConnectionsModule({
90+
connections: new DidCommConnectionsModule({
9191
autoAcceptConnections: true,
9292
}),
93-
credentials: new CredentialsModule({
94-
autoAcceptCredentials: AutoAcceptCredential.ContentApproved,
93+
credentials: new DidCommCredentialsModule({
94+
autoAcceptCredentials: DidCommAutoAcceptCredential.ContentApproved,
9595
credentialProtocols: [
96-
new V1CredentialProtocol({
96+
new DidCommCredentialV1Protocol({
9797
indyCredentialFormat: legacyIndyCredentialFormatService,
9898
}),
99-
new V2CredentialProtocol({
100-
credentialFormats: [legacyIndyCredentialFormatService, new AnonCredsCredentialFormatService()],
99+
new DidCommCredentialV2Protocol({
100+
credentialFormats: [legacyIndyCredentialFormatService, new AnonCredsDidCommCredentialFormatService()],
101101
}),
102102
],
103103
}),
104-
proofs: new ProofsModule({
105-
autoAcceptProofs: AutoAcceptProof.ContentApproved,
104+
proofs: new DidCommProofsModule({
105+
autoAcceptProofs: DidCommAutoAcceptProof.ContentApproved,
106106
proofProtocols: [
107-
new V1ProofProtocol({
107+
new DidCommProofV1Protocol({
108108
indyProofFormat: legacyIndyProofFormatService,
109109
}),
110-
new V2ProofProtocol({
111-
proofFormats: [legacyIndyProofFormatService, new AnonCredsProofFormatService()],
110+
new DidCommProofV2Protocol({
111+
proofFormats: [legacyIndyProofFormatService, new AnonCredsDidCommProofFormatService()],
112112
}),
113113
],
114114
}),

demo/src/Faber.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { RegisterCredentialDefinitionReturnStateFinished } from '@credo-ts/anoncreds'
2-
import type { ConnectionRecord, ConnectionStateChangedEvent } from '@credo-ts/didcomm'
2+
import type { DidCommConnectionRecord, DidCommConnectionStateChangedEvent } from '@credo-ts/didcomm'
33
import type { IndyVdrRegisterCredentialDefinitionOptions, IndyVdrRegisterSchemaOptions } from '@credo-ts/indy-vdr'
44
import type BottomBar from 'inquirer/lib/ui/bottom-bar'
55

66
import { TypedArrayEncoder, utils } from '@credo-ts/core'
7-
import { ConnectionEventTypes } from '@credo-ts/didcomm'
7+
import { DidCommConnectionEventTypes } from '@credo-ts/didcomm'
88
import { ui } from 'inquirer'
99

1010
import { transformPrivateKeyToPrivateJwk } from '@credo-ts/askar'
@@ -103,17 +103,20 @@ export class Faber extends BaseAgent {
103103
console.log('Waiting for Alice to finish connection...')
104104

105105
const getConnectionRecord = (outOfBandId: string) =>
106-
new Promise<ConnectionRecord>((resolve, reject) => {
106+
new Promise<DidCommConnectionRecord>((resolve, reject) => {
107107
// Timeout of 20 seconds
108108
const timeoutId = setTimeout(() => reject(new Error(redText(Output.MissingConnectionRecord))), 20000)
109109

110110
// Start listener
111-
this.agent.events.on<ConnectionStateChangedEvent>(ConnectionEventTypes.ConnectionStateChanged, (e) => {
112-
if (e.payload.connectionRecord.outOfBandId !== outOfBandId) return
111+
this.agent.events.on<DidCommConnectionStateChangedEvent>(
112+
DidCommConnectionEventTypes.DidCommConnectionStateChanged,
113+
(e) => {
114+
if (e.payload.connectionRecord.outOfBandId !== outOfBandId) return
113115

114-
clearTimeout(timeoutId)
115-
resolve(e.payload.connectionRecord)
116-
})
116+
clearTimeout(timeoutId)
117+
resolve(e.payload.connectionRecord)
118+
}
119+
)
117120

118121
// Also retrieve the connection record by invitation if the event has already fired
119122
void this.agent.modules.connections.findAllByOutOfBandId(outOfBandId).then(([connectionRecord]) => {

demo/src/Listener.ts

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { Agent } from '@credo-ts/core'
22
import type {
3-
BasicMessageStateChangedEvent,
4-
CredentialExchangeRecord,
5-
CredentialStateChangedEvent,
6-
ProofExchangeRecord,
7-
ProofStateChangedEvent,
3+
DidCommBasicMessageStateChangedEvent,
4+
DidCommCredentialExchangeRecord,
5+
DidCommCredentialStateChangedEvent,
6+
DidCommProofExchangeRecord,
7+
DidCommProofStateChangedEvent,
88
} from '@credo-ts/didcomm'
99
import type BottomBar from 'inquirer/lib/ui/bottom-bar'
1010
import type { Alice } from './Alice'
@@ -13,12 +13,12 @@ import type { Faber } from './Faber'
1313
import type { FaberInquirer } from './FaberInquirer'
1414

1515
import {
16-
BasicMessageEventTypes,
17-
BasicMessageRole,
18-
CredentialEventTypes,
19-
CredentialState,
20-
ProofEventTypes,
21-
ProofState,
16+
DidCommBasicMessageEventTypes,
17+
DidCommBasicMessageRole,
18+
DidCommCredentialEventTypes,
19+
DidCommCredentialState,
20+
DidCommProofEventTypes,
21+
DidCommProofState,
2222
} from '@credo-ts/didcomm'
2323
import { ui } from 'inquirer'
2424

@@ -41,17 +41,17 @@ export class Listener {
4141
this.on = false
4242
}
4343

44-
private printCredentialAttributes(credentialRecord: CredentialExchangeRecord) {
45-
if (credentialRecord.credentialAttributes) {
46-
const attribute = credentialRecord.credentialAttributes
44+
private printCredentialAttributes(credentialExchangeRecord: DidCommCredentialExchangeRecord) {
45+
if (credentialExchangeRecord.credentialAttributes) {
46+
const attribute = credentialExchangeRecord.credentialAttributes
4747
console.log('\n\nCredential preview:')
4848
for (const element of attribute) {
4949
console.log(purpleText(`${element.name} ${Color.Reset}${element.value}`))
5050
}
5151
}
5252
}
5353

54-
private async newCredentialPrompt(credentialRecord: CredentialExchangeRecord, aliceInquirer: AliceInquirer) {
54+
private async newCredentialPrompt(credentialRecord: DidCommCredentialExchangeRecord, aliceInquirer: AliceInquirer) {
5555
this.printCredentialAttributes(credentialRecord)
5656
this.turnListenerOn()
5757
await aliceInquirer.acceptCredentialOffer(credentialRecord)
@@ -61,44 +61,53 @@ export class Listener {
6161

6262
public credentialOfferListener(alice: Alice, aliceInquirer: AliceInquirer) {
6363
alice.agent.events.on(
64-
CredentialEventTypes.CredentialStateChanged,
65-
async ({ payload }: CredentialStateChangedEvent) => {
66-
if (payload.credentialRecord.state === CredentialState.OfferReceived) {
67-
await this.newCredentialPrompt(payload.credentialRecord, aliceInquirer)
64+
DidCommCredentialEventTypes.DidCommCredentialStateChanged,
65+
async ({ payload }: DidCommCredentialStateChangedEvent) => {
66+
if (payload.credentialExchangeRecord.state === DidCommCredentialState.OfferReceived) {
67+
await this.newCredentialPrompt(payload.credentialExchangeRecord, aliceInquirer)
6868
}
6969
}
7070
)
7171
}
7272

7373
public messageListener(agent: Agent, name: string) {
74-
agent.events.on(BasicMessageEventTypes.BasicMessageStateChanged, async (event: BasicMessageStateChangedEvent) => {
75-
if (event.payload.basicMessageRecord.role === BasicMessageRole.Receiver) {
76-
this.ui.updateBottomBar(purpleText(`\n${name} received a message: ${event.payload.message.content}\n`))
74+
agent.events.on(
75+
DidCommBasicMessageEventTypes.DidCommBasicMessageStateChanged,
76+
async (event: DidCommBasicMessageStateChangedEvent) => {
77+
if (event.payload.basicMessageRecord.role === DidCommBasicMessageRole.Receiver) {
78+
this.ui.updateBottomBar(purpleText(`\n${name} received a message: ${event.payload.message.content}\n`))
79+
}
7780
}
78-
})
81+
)
7982
}
8083

81-
private async newProofRequestPrompt(proofRecord: ProofExchangeRecord, aliceInquirer: AliceInquirer) {
84+
private async newProofRequestPrompt(proofExchangeRecord: DidCommProofExchangeRecord, aliceInquirer: AliceInquirer) {
8285
this.turnListenerOn()
83-
await aliceInquirer.acceptProofRequest(proofRecord)
86+
await aliceInquirer.acceptProofRequest(proofExchangeRecord)
8487
this.turnListenerOff()
8588
await aliceInquirer.processAnswer()
8689
}
8790

8891
public proofRequestListener(alice: Alice, aliceInquirer: AliceInquirer) {
89-
alice.agent.events.on(ProofEventTypes.ProofStateChanged, async ({ payload }: ProofStateChangedEvent) => {
90-
if (payload.proofRecord.state === ProofState.RequestReceived) {
91-
await this.newProofRequestPrompt(payload.proofRecord, aliceInquirer)
92+
alice.agent.events.on(
93+
DidCommProofEventTypes.ProofStateChanged,
94+
async ({ payload }: DidCommProofStateChangedEvent) => {
95+
if (payload.proofRecord.state === DidCommProofState.RequestReceived) {
96+
await this.newProofRequestPrompt(payload.proofRecord, aliceInquirer)
97+
}
9298
}
93-
})
99+
)
94100
}
95101

96102
public proofAcceptedListener(faber: Faber, faberInquirer: FaberInquirer) {
97-
faber.agent.events.on(ProofEventTypes.ProofStateChanged, async ({ payload }: ProofStateChangedEvent) => {
98-
if (payload.proofRecord.state === ProofState.Done) {
99-
await faberInquirer.processAnswer()
103+
faber.agent.events.on(
104+
DidCommProofEventTypes.ProofStateChanged,
105+
async ({ payload }: DidCommProofStateChangedEvent) => {
106+
if (payload.proofRecord.state === DidCommProofState.Done) {
107+
await faberInquirer.processAnswer()
108+
}
100109
}
101-
})
110+
)
102111
}
103112

104113
public async newAcceptedPrompt(title: string, faberInquirer: FaberInquirer) {

0 commit comments

Comments
 (0)