Skip to content

Commit

Permalink
feat(core): store mediator id in connection record (#503)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra authored Oct 31, 2021
1 parent e50b821 commit da51f2e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,18 @@ describe('ConnectionService', () => {
eventEmitter = new EventEmitter(config)
connectionRepository = new ConnectionRepositoryMock()
connectionService = new ConnectionService(wallet, config, connectionRepository, eventEmitter)
myRouting = { did: 'fakeDid', verkey: 'fakeVerkey', endpoints: config.endpoints ?? [], routingKeys: [] }
myRouting = {
did: 'fakeDid',
verkey: 'fakeVerkey',
endpoints: config.endpoints ?? [],
routingKeys: [],
mediatorId: 'fakeMediatorId',
}
})

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

expect(connectionRecord.type).toBe('ConnectionRecord')
Expand All @@ -67,6 +73,7 @@ describe('ConnectionService', () => {
expect(connectionRecord.autoAcceptConnection).toBeUndefined()
expect(connectionRecord.id).toEqual(expect.any(String))
expect(connectionRecord.verkey).toEqual(expect.any(String))
expect(connectionRecord.mediatorId).toEqual('fakeMediatorId')
expect(message.imageUrl).toBe(connectionImageUrl)
expect(connectionRecord.getTags()).toEqual(
expect.objectContaining({
Expand Down Expand Up @@ -148,7 +155,7 @@ describe('ConnectionService', () => {

describe('processInvitation', () => {
it('returns a connection record containing the information from the connection invitation', async () => {
expect.assertions(11)
expect.assertions(12)

const recipientKey = 'key-1'
const invitation = new ConnectionInvitationMessage({
Expand All @@ -169,6 +176,7 @@ describe('ConnectionService', () => {
expect(connection.autoAcceptConnection).toBeUndefined()
expect(connection.id).toEqual(expect.any(String))
expect(connection.verkey).toEqual(expect.any(String))
expect(connection.mediatorId).toEqual('fakeMediatorId')
expect(connection.getTags()).toEqual(
expect.objectContaining({
verkey: connection.verkey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface ConnectionRecordProps {
tags?: CustomConnectionTags
imageUrl?: string
multiUseInvitation: boolean
mediatorId?: string
}

export type CustomConnectionTags = TagsBase
Expand All @@ -38,6 +39,7 @@ export type DefaultConnectionTags = {
threadId?: string
verkey?: string
theirKey?: string
mediatorId?: string
}

export class ConnectionRecord
Expand Down Expand Up @@ -65,6 +67,7 @@ export class ConnectionRecord
public multiUseInvitation!: boolean

public threadId?: string
public mediatorId?: string

public static readonly type = 'ConnectionRecord'
public readonly type = ConnectionRecord.type
Expand All @@ -90,6 +93,7 @@ export class ConnectionRecord
this.threadId = props.threadId
this.imageUrl = props.imageUrl
this.multiUseInvitation = props.multiUseInvitation
this.mediatorId = props.mediatorId
}
}

Expand All @@ -104,6 +108,7 @@ export class ConnectionRecord
threadId: this.threadId,
verkey: this.verkey,
theirKey: this.theirKey || undefined,
mediatorId: this.mediatorId,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ export class ConnectionService {
tags?: CustomConnectionTags
imageUrl?: string
}): Promise<ConnectionRecord> {
const { endpoints, did, verkey, routingKeys } = options.routing
const { endpoints, did, verkey, routingKeys, mediatorId } = options.routing

const publicKey = new Ed25119Sig2018({
id: `${did}#1`,
Expand Down Expand Up @@ -628,6 +628,7 @@ export class ConnectionService {
autoAcceptConnection: options.autoAcceptConnection,
imageUrl: options.imageUrl,
multiUseInvitation: options.multiUseInvitation,
mediatorId,
})

await this.connectionRepository.save(connectionRecord)
Expand Down Expand Up @@ -666,6 +667,7 @@ export interface Routing {
verkey: string
did: string
routingKeys: string[]
mediatorId?: string
}

export interface ConnectionProtocolMsgReturnType<MessageType extends AgentMessage> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AgentMessage } from '../../../agent/AgentMessage'
import type { InboundMessageContext } from '../../../agent/models/InboundMessageContext'
import type { ConnectionRecord } from '../../connections'
import type { Routing } from '../../connections/services/ConnectionService'
import type { MediationStateChangedEvent, KeylistUpdatedEvent } from '../RoutingEvents'
import type { MediationGrantMessage, MediationDenyMessage, KeylistUpdateResponseMessage } from '../messages'

Expand Down Expand Up @@ -154,7 +155,7 @@ export class MediationRecipientService {
return keylistUpdateMessage
}

public async getRouting(mediationRecord?: MediationRecord) {
public async getRouting(mediationRecord?: MediationRecord): Promise<Routing> {
let endpoints = this.config.endpoints
let routingKeys: string[] = []

Expand All @@ -168,7 +169,7 @@ export class MediationRecipientService {
} else {
// TODO: check that recipient keys are in wallet
}
return { mediationRecord, endpoints, routingKeys, did, verkey }
return { endpoints, routingKeys, did, verkey, mediatorId: mediationRecord?.id }
}

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

0 comments on commit da51f2e

Please sign in to comment.