Skip to content

Commit da51f2e

Browse files
authored
feat(core): store mediator id in connection record (#503)
Signed-off-by: Timo Glastra <timo@animo.id>
1 parent e50b821 commit da51f2e

4 files changed

Lines changed: 22 additions & 6 deletions

File tree

packages/core/src/modules/connections/__tests__/ConnectionService.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,18 @@ describe('ConnectionService', () => {
5353
eventEmitter = new EventEmitter(config)
5454
connectionRepository = new ConnectionRepositoryMock()
5555
connectionService = new ConnectionService(wallet, config, connectionRepository, eventEmitter)
56-
myRouting = { did: 'fakeDid', verkey: 'fakeVerkey', endpoints: config.endpoints ?? [], routingKeys: [] }
56+
myRouting = {
57+
did: 'fakeDid',
58+
verkey: 'fakeVerkey',
59+
endpoints: config.endpoints ?? [],
60+
routingKeys: [],
61+
mediatorId: 'fakeMediatorId',
62+
}
5763
})
5864

5965
describe('createInvitation', () => {
6066
it('returns a connection record with values set', async () => {
61-
expect.assertions(8)
67+
expect.assertions(9)
6268
const { connectionRecord, message } = await connectionService.createInvitation({ routing: myRouting })
6369

6470
expect(connectionRecord.type).toBe('ConnectionRecord')
@@ -67,6 +73,7 @@ describe('ConnectionService', () => {
6773
expect(connectionRecord.autoAcceptConnection).toBeUndefined()
6874
expect(connectionRecord.id).toEqual(expect.any(String))
6975
expect(connectionRecord.verkey).toEqual(expect.any(String))
76+
expect(connectionRecord.mediatorId).toEqual('fakeMediatorId')
7077
expect(message.imageUrl).toBe(connectionImageUrl)
7178
expect(connectionRecord.getTags()).toEqual(
7279
expect.objectContaining({
@@ -148,7 +155,7 @@ describe('ConnectionService', () => {
148155

149156
describe('processInvitation', () => {
150157
it('returns a connection record containing the information from the connection invitation', async () => {
151-
expect.assertions(11)
158+
expect.assertions(12)
152159

153160
const recipientKey = 'key-1'
154161
const invitation = new ConnectionInvitationMessage({
@@ -169,6 +176,7 @@ describe('ConnectionService', () => {
169176
expect(connection.autoAcceptConnection).toBeUndefined()
170177
expect(connection.id).toEqual(expect.any(String))
171178
expect(connection.verkey).toEqual(expect.any(String))
179+
expect(connection.mediatorId).toEqual('fakeMediatorId')
172180
expect(connection.getTags()).toEqual(
173181
expect.objectContaining({
174182
verkey: connection.verkey,

packages/core/src/modules/connections/repository/ConnectionRecord.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface ConnectionRecordProps {
2828
tags?: CustomConnectionTags
2929
imageUrl?: string
3030
multiUseInvitation: boolean
31+
mediatorId?: string
3132
}
3233

3334
export type CustomConnectionTags = TagsBase
@@ -38,6 +39,7 @@ export type DefaultConnectionTags = {
3839
threadId?: string
3940
verkey?: string
4041
theirKey?: string
42+
mediatorId?: string
4143
}
4244

4345
export class ConnectionRecord
@@ -65,6 +67,7 @@ export class ConnectionRecord
6567
public multiUseInvitation!: boolean
6668

6769
public threadId?: string
70+
public mediatorId?: string
6871

6972
public static readonly type = 'ConnectionRecord'
7073
public readonly type = ConnectionRecord.type
@@ -90,6 +93,7 @@ export class ConnectionRecord
9093
this.threadId = props.threadId
9194
this.imageUrl = props.imageUrl
9295
this.multiUseInvitation = props.multiUseInvitation
96+
this.mediatorId = props.mediatorId
9397
}
9498
}
9599

@@ -104,6 +108,7 @@ export class ConnectionRecord
104108
threadId: this.threadId,
105109
verkey: this.verkey,
106110
theirKey: this.theirKey || undefined,
111+
mediatorId: this.mediatorId,
107112
}
108113
}
109114

packages/core/src/modules/connections/services/ConnectionService.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ export class ConnectionService {
583583
tags?: CustomConnectionTags
584584
imageUrl?: string
585585
}): Promise<ConnectionRecord> {
586-
const { endpoints, did, verkey, routingKeys } = options.routing
586+
const { endpoints, did, verkey, routingKeys, mediatorId } = options.routing
587587

588588
const publicKey = new Ed25119Sig2018({
589589
id: `${did}#1`,
@@ -628,6 +628,7 @@ export class ConnectionService {
628628
autoAcceptConnection: options.autoAcceptConnection,
629629
imageUrl: options.imageUrl,
630630
multiUseInvitation: options.multiUseInvitation,
631+
mediatorId,
631632
})
632633

633634
await this.connectionRepository.save(connectionRecord)
@@ -666,6 +667,7 @@ export interface Routing {
666667
verkey: string
667668
did: string
668669
routingKeys: string[]
670+
mediatorId?: string
669671
}
670672

671673
export interface ConnectionProtocolMsgReturnType<MessageType extends AgentMessage> {

packages/core/src/modules/routing/services/MediationRecipientService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { AgentMessage } from '../../../agent/AgentMessage'
22
import type { InboundMessageContext } from '../../../agent/models/InboundMessageContext'
33
import type { ConnectionRecord } from '../../connections'
4+
import type { Routing } from '../../connections/services/ConnectionService'
45
import type { MediationStateChangedEvent, KeylistUpdatedEvent } from '../RoutingEvents'
56
import type { MediationGrantMessage, MediationDenyMessage, KeylistUpdateResponseMessage } from '../messages'
67

@@ -154,7 +155,7 @@ export class MediationRecipientService {
154155
return keylistUpdateMessage
155156
}
156157

157-
public async getRouting(mediationRecord?: MediationRecord) {
158+
public async getRouting(mediationRecord?: MediationRecord): Promise<Routing> {
158159
let endpoints = this.config.endpoints
159160
let routingKeys: string[] = []
160161

@@ -168,7 +169,7 @@ export class MediationRecipientService {
168169
} else {
169170
// TODO: check that recipient keys are in wallet
170171
}
171-
return { mediationRecord, endpoints, routingKeys, did, verkey }
172+
return { endpoints, routingKeys, did, verkey, mediatorId: mediationRecord?.id }
172173
}
173174

174175
public async saveRoute(recipientKey: string, mediationRecord: MediationRecord) {

0 commit comments

Comments
 (0)