Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): store mediator id in connection record #503

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,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(7)
expect.assertions(8)
const { connectionRecord: connectionRecord } = await connectionService.createInvitation({ routing: myRouting })

expect(connectionRecord.type).toBe('ConnectionRecord')
Expand All @@ -64,6 +70,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(connectionRecord.getTags()).toEqual(
expect.objectContaining({
verkey: connectionRecord.verkey,
Expand Down Expand Up @@ -144,7 +151,7 @@ describe('ConnectionService', () => {

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

const recipientKey = 'key-1'
const invitation = new ConnectionInvitationMessage({
Expand All @@ -164,6 +171,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 @@ -27,6 +27,7 @@ export interface ConnectionRecordProps {
threadId?: string
tags?: CustomConnectionTags
multiUseInvitation: boolean
mediatorId?: string
}

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

export class ConnectionRecord
Expand All @@ -63,6 +65,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 @@ -87,6 +90,7 @@ export class ConnectionRecord
this.invitation = props.invitation
this.threadId = props.threadId
this.multiUseInvitation = props.multiUseInvitation
this.mediatorId = props.mediatorId
}
}

Expand All @@ -101,6 +105,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 @@ -578,7 +578,7 @@ export class ConnectionService {
multiUseInvitation: boolean
tags?: CustomConnectionTags
}): 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 @@ -622,6 +622,7 @@ export class ConnectionService {
theirLabel: options.theirLabel,
autoAcceptConnection: options.autoAcceptConnection,
multiUseInvitation: options.multiUseInvitation,
mediatorId,
})

await this.connectionRepository.save(connectionRecord)
Expand Down Expand Up @@ -660,6 +661,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