diff --git a/packages/core/src/agent/MessageSender.ts b/packages/core/src/agent/MessageSender.ts index a09ed505a8..31fc4fac70 100644 --- a/packages/core/src/agent/MessageSender.ts +++ b/packages/core/src/agent/MessageSender.ts @@ -5,7 +5,6 @@ import type { TransportSession } from './TransportService' import type { AgentContext } from './context' import type { ConnectionRecord } from '../modules/connections' import type { ResolvedDidCommService } from '../modules/didcomm' -import type { DidDocument } from '../modules/dids' import type { OutOfBandRecord } from '../modules/oob/repository' import type { OutboundTransport } from '../transport/OutboundTransport' import type { EncryptedMessage, OutboundPackage } from '../types' @@ -15,6 +14,7 @@ import { ReturnRouteTypes } from '../decorators/transport/TransportDecorator' import { AriesFrameworkError, MessageSendingError } from '../error' import { Logger } from '../logger' import { DidCommDocumentService } from '../modules/didcomm' +import { DidKey, type DidDocument } from '../modules/dids' import { getKeyFromVerificationMethod } from '../modules/dids/domain/key-type' import { didKeyToInstanceOfKey, verkeyToDidKey } from '../modules/dids/helpers' import { DidResolverService } from '../modules/dids/services/DidResolverService' @@ -180,7 +180,7 @@ export class MessageSender { this.logger.debug(`Queue packed message for connection ${connection.id} (${connection.theirLabel})`) await this.messagePickupRepository.addMessage({ connectionId: connection.id, - recipientKeys: [recipientKey], + recipientDids: [verkeyToDidKey(recipientKey)], payload: encryptedMessage, }) return @@ -335,7 +335,7 @@ export class MessageSender { const encryptedMessage = await this.envelopeService.packMessage(agentContext, message, keys) await this.messagePickupRepository.addMessage({ connectionId: connection.id, - recipientKeys: keys.recipientKeys.map((item) => verkeyToDidKey(item.publicKeyBase58)), + recipientDids: keys.recipientKeys.map((item) => new DidKey(item).did), payload: encryptedMessage, }) diff --git a/packages/core/src/modules/message-pickup/MessagePickupApi.ts b/packages/core/src/modules/message-pickup/MessagePickupApi.ts index 0169897423..9878cc2684 100644 --- a/packages/core/src/modules/message-pickup/MessagePickupApi.ts +++ b/packages/core/src/modules/message-pickup/MessagePickupApi.ts @@ -7,6 +7,8 @@ import type { QueueMessageReturnType, SetLiveDeliveryModeOptions, SetLiveDeliveryModeReturnType, + DeliverMessagesReturnType, + DeliverMessagesFromQueueReturnType, } from './MessagePickupApiOptions' import type { MessagePickupSession, MessagePickupSessionRole } from './MessagePickupSession' import type { V1MessagePickupProtocol, V2MessagePickupProtocol } from './protocol' @@ -32,8 +34,9 @@ export interface MessagePickupApi { connectionId: string role?: MessagePickupSessionRole }): Promise - deliverMessages(options: DeliverMessagesOptions): Promise - deliverMessagesFromQueue(options: DeliverMessagesFromQueueOptions): Promise + deliverMessages(options: DeliverMessagesOptions): Promise + deliverMessagesFromQueue(options: DeliverMessagesFromQueueOptions): Promise + setLiveDeliveryMode(options: SetLiveDeliveryModeOptions): Promise } @injectable() @@ -85,14 +88,14 @@ export class MessagePickupApi { this.logger.debug('Queuing message...') - const { connectionId, message, recipientKeys } = options + const { connectionId, message, recipientDids } = options const connectionRecord = await this.connectionService.getById(this.agentContext, connectionId) const messagePickupRepository = this.agentContext.dependencyManager.resolve( InjectionSymbols.MessagePickupRepository ) - await messagePickupRepository.addMessage({ connectionId: connectionRecord.id, recipientKeys, payload: message }) + await messagePickupRepository.addMessage({ connectionId: connectionRecord.id, recipientDids, payload: message }) } /** @@ -153,13 +156,12 @@ export class MessagePickupApi { connectionId: string protocolVersion: MessagePickupProtocolVersionType - recipientKey?: string + recipientDid?: string batchSize?: number } @@ -43,4 +43,6 @@ export type PickupMessagesReturnType = void export type DeliverMessagesReturnType = void +export type DeliverMessagesFromQueueReturnType = void + export type SetLiveDeliveryModeReturnType = void diff --git a/packages/core/src/modules/message-pickup/protocol/MessagePickupProtocolOptions.ts b/packages/core/src/modules/message-pickup/protocol/MessagePickupProtocolOptions.ts index 41391f3286..4f4409c501 100644 --- a/packages/core/src/modules/message-pickup/protocol/MessagePickupProtocolOptions.ts +++ b/packages/core/src/modules/message-pickup/protocol/MessagePickupProtocolOptions.ts @@ -4,7 +4,7 @@ import type { QueuedMessage } from '../storage' export interface PickupMessagesProtocolOptions { connectionRecord: ConnectionRecord - recipientKey?: string + recipientDid?: string batchSize?: number } diff --git a/packages/core/src/modules/message-pickup/protocol/v1/V1MessagePickupProtocol.ts b/packages/core/src/modules/message-pickup/protocol/v1/V1MessagePickupProtocol.ts index 48f86e393c..b0994478a9 100644 --- a/packages/core/src/modules/message-pickup/protocol/v1/V1MessagePickupProtocol.ts +++ b/packages/core/src/modules/message-pickup/protocol/v1/V1MessagePickupProtocol.ts @@ -94,10 +94,7 @@ export class V1MessagePickupProtocol extends BaseMessagePickupProtocol { } } - public async setLiveDeliveryMode( - agentContext: AgentContext, - options: SetLiveDeliveryModeProtocolOptions - ): Promise> { + public async setLiveDeliveryMode(): Promise> { throw new AriesFrameworkError('Live Delivery mode not supported in Message Pickup V1 protocol') } diff --git a/packages/core/src/modules/message-pickup/protocol/v2/V2MessagePickupProtocol.ts b/packages/core/src/modules/message-pickup/protocol/v2/V2MessagePickupProtocol.ts index 96e9722c31..c0b927b039 100644 --- a/packages/core/src/modules/message-pickup/protocol/v2/V2MessagePickupProtocol.ts +++ b/packages/core/src/modules/message-pickup/protocol/v2/V2MessagePickupProtocol.ts @@ -78,7 +78,7 @@ export class V2MessagePickupProtocol extends BaseMessagePickupProtocol { agentContext: AgentContext, options: PickupMessagesProtocolOptions ): Promise> { - const { connectionRecord, recipientKey } = options + const { connectionRecord, recipientDid: recipientKey } = options connectionRecord.assertReady() const message = new V2StatusRequestMessage({ @@ -104,7 +104,7 @@ export class V2MessagePickupProtocol extends BaseMessagePickupProtocol { messages ?? (await messagePickupRepository.takeFromQueue({ connectionId: connectionRecord.id, - recipientKey, + recipientDid: recipientKey, limit: 10, // TODO: Define as config parameter })) @@ -156,7 +156,7 @@ export class V2MessagePickupProtocol extends BaseMessagePickupProtocol { recipientKey, messageCount: await messagePickupRepository.getAvailableMessageCount({ connectionId: connection.id, - recipientKey: recipientKey ? verkeyToDidKey(recipientKey) : undefined, + recipientDid: recipientKey ? verkeyToDidKey(recipientKey) : undefined, }), }) @@ -180,7 +180,7 @@ export class V2MessagePickupProtocol extends BaseMessagePickupProtocol { // Get available messages from queue, but don't delete them const messages = await messagePickupRepository.takeFromQueue({ connectionId: connection.id, - recipientKey: recipientKey ? verkeyToDidKey(recipientKey) : undefined, + recipientDid: recipientKey ? verkeyToDidKey(recipientKey) : undefined, limit: message.limit, }) diff --git a/packages/core/src/modules/message-pickup/protocol/v2/__tests__/V2MessagePickupProtocol.test.ts b/packages/core/src/modules/message-pickup/protocol/v2/__tests__/V2MessagePickupProtocol.test.ts index 7707b56db7..bf0d6b2f0a 100644 --- a/packages/core/src/modules/message-pickup/protocol/v2/__tests__/V2MessagePickupProtocol.test.ts +++ b/packages/core/src/modules/message-pickup/protocol/v2/__tests__/V2MessagePickupProtocol.test.ts @@ -233,7 +233,7 @@ describe('V2MessagePickupProtocol', () => { expect(messagePickupRepository.takeFromQueue).toHaveBeenCalledWith({ connectionId: mockConnection.id, limit: 10, - recipientKey: verkeyToDidKey('recipientKey'), + recipientDid: verkeyToDidKey('recipientKey'), }) }) }) @@ -299,7 +299,7 @@ describe('V2MessagePickupProtocol', () => { it('creates a status request message', async () => { const { message: statusRequestMessage } = await pickupProtocol.createPickupMessage(agentContext, { connectionRecord: mockConnection, - recipientKey: 'a-key', + recipientDid: 'a-key', }) expect(statusRequestMessage).toMatchObject({ diff --git a/packages/core/src/modules/message-pickup/storage/InMemoryMessagePickupRepository.ts b/packages/core/src/modules/message-pickup/storage/InMemoryMessagePickupRepository.ts index 65f5e7da46..f066899369 100644 --- a/packages/core/src/modules/message-pickup/storage/InMemoryMessagePickupRepository.ts +++ b/packages/core/src/modules/message-pickup/storage/InMemoryMessagePickupRepository.ts @@ -14,7 +14,7 @@ import { uuid } from '../../../utils/uuid' interface InMemoryQueuedMessage extends QueuedMessage { connectionId: string - recipientKeys: string[] + recipientDids: string[] state: 'pending' | 'sending' } @@ -29,25 +29,25 @@ export class InMemoryMessagePickupRepository implements MessagePickupRepository } public getAvailableMessageCount(options: GetAvailableMessageCountOptions): number | Promise { - const { connectionId, recipientKey } = options + const { connectionId, recipientDid } = options const messages = this.messages.filter( (msg) => msg.connectionId === connectionId && - (recipientKey === undefined || msg.recipientKeys.includes(recipientKey)) && + (recipientDid === undefined || msg.recipientDids.includes(recipientDid)) && msg.state === 'pending' ) return messages.length } public takeFromQueue(options: TakeFromQueueOptions): QueuedMessage[] { - const { connectionId, recipientKey, limit, deleteMessages } = options + const { connectionId, recipientDid, limit, deleteMessages } = options let messages = this.messages.filter( (msg) => msg.connectionId === connectionId && msg.state === 'pending' && - (recipientKey === undefined || msg.recipientKeys.includes(recipientKey)) + (recipientDid === undefined || msg.recipientDids.includes(recipientDid)) ) const messagesToTake = limit ?? messages.length @@ -70,14 +70,14 @@ export class InMemoryMessagePickupRepository implements MessagePickupRepository } public addMessage(options: AddMessageOptions) { - const { connectionId, recipientKeys, payload } = options + const { connectionId, recipientDids, payload } = options const id = uuid() this.messages.push({ id, connectionId, encryptedMessage: payload, - recipientKeys, + recipientDids, state: 'pending', }) diff --git a/packages/core/src/modules/message-pickup/storage/MessagePickupRepositoryOptions.ts b/packages/core/src/modules/message-pickup/storage/MessagePickupRepositoryOptions.ts index 85b26e0c91..e586d5756a 100644 --- a/packages/core/src/modules/message-pickup/storage/MessagePickupRepositoryOptions.ts +++ b/packages/core/src/modules/message-pickup/storage/MessagePickupRepositoryOptions.ts @@ -2,19 +2,19 @@ import type { EncryptedMessage } from '../../../types' export interface GetAvailableMessageCountOptions { connectionId: string - recipientKey?: string + recipientDid?: string } export interface TakeFromQueueOptions { connectionId: string - recipientKey?: string + recipientDid?: string limit?: number deleteMessages?: boolean } export interface AddMessageOptions { connectionId: string - recipientKeys: string[] + recipientDids: string[] payload: EncryptedMessage } diff --git a/packages/core/src/modules/routing/services/MediatorService.ts b/packages/core/src/modules/routing/services/MediatorService.ts index 448a0b22a6..d7cdf433f1 100644 --- a/packages/core/src/modules/routing/services/MediatorService.ts +++ b/packages/core/src/modules/routing/services/MediatorService.ts @@ -96,14 +96,14 @@ export class MediatorService { case MessageForwardingStrategy.QueueOnly: await this.messagePickupApi.queueMessage({ connectionId: mediationRecord.connectionId, - recipientKeys: [verkeyToDidKey(message.to)], + recipientDids: [verkeyToDidKey(message.to)], message: message.message, }) break case MessageForwardingStrategy.QueueAndLiveModeDelivery: { await this.messagePickupApi.queueMessage({ connectionId: mediationRecord.connectionId, - recipientKeys: [verkeyToDidKey(message.to)], + recipientDids: [verkeyToDidKey(message.to)], message: message.message, }) const session = await this.messagePickupApi.getLiveModeSession({ @@ -113,7 +113,7 @@ export class MediatorService { if (session) { await this.messagePickupApi.deliverMessagesFromQueue({ pickupSessionId: session.id, - recipientKey: verkeyToDidKey(message.to), + recipientDid: verkeyToDidKey(message.to), }) } break