@@ -3,7 +3,6 @@ import type { Routing } from './services/ConnectionService'
33import type { AgentContext } from '../../agent'
44import type { InboundMessageContext } from '../../agent/models/InboundMessageContext'
55import type { ParsedMessageType } from '../../utils/messageType'
6- import type { ResolvedDidCommService } from '../didcomm'
76import type { OutOfBandRecord } from '../oob/repository'
87
98import { InjectionSymbols } from '../../constants'
@@ -19,6 +18,7 @@ import { TypedArrayEncoder, isDid, Buffer } from '../../utils'
1918import { JsonEncoder } from '../../utils/JsonEncoder'
2019import { JsonTransformer } from '../../utils/JsonTransformer'
2120import { base64ToBase64URL } from '../../utils/base64'
21+ import { DidCommDocumentService , type ResolvedDidCommService } from '../didcomm'
2222import {
2323 DidDocument ,
2424 DidKey ,
@@ -29,8 +29,8 @@ import {
2929 getAlternativeDidsForPeerDid ,
3030} from '../dids'
3131import { getKeyFromVerificationMethod } from '../dids/domain/key-type'
32- import { tryParseDid } from '../dids/domain/parse'
33- import { didKeyToInstanceOfKey } from '../dids/helpers'
32+ import { parseDid , tryParseDid } from '../dids/domain/parse'
33+ import { didKeyToInstanceOfKey , didKeyToVerkey } from '../dids/helpers'
3434import { DidRepository } from '../dids/repository'
3535import { OutOfBandRole } from '../oob/domain/OutOfBandRole'
3636import { OutOfBandState } from '../oob/domain/OutOfBandState'
@@ -295,17 +295,26 @@ export class DidExchangeProtocol {
295295 )
296296 } else {
297297 // We assume any other case is a resolvable did (e.g. did:peer:2 or did:peer:4)
298+ const didcommDocumentService = agentContext . dependencyManager . resolve ( DidCommDocumentService )
299+
300+ const invitationRecipientKeys = outOfBandRecord . outOfBandInvitation
301+ . getInlineServices ( )
302+ . map ( ( s ) => s . recipientKeys )
303+ . reduce ( ( acc , curr ) => acc . concat ( curr ) , [ ] )
304+
305+ // Consider also pure-DID services, used when DID Exchange is started with an implicit invitation or a public DID
306+ for ( const did of outOfBandRecord . outOfBandInvitation . getDidServices ( ) ) {
307+ invitationRecipientKeys . push (
308+ ...( await didcommDocumentService . resolveServicesFromDid ( agentContext , parseDid ( did ) . did ) ) . flatMap ( ( service ) =>
309+ service . recipientKeys . map ( ( key ) => key . publicKeyBase58 )
310+ )
311+ )
312+ }
313+
298314 message . didRotate = await this . createSignedAttachment (
299315 agentContext ,
300316 didDocument . id ,
301- Array . from (
302- new Set (
303- services
304- . map ( ( s ) => s . recipientKeys )
305- . reduce ( ( acc , curr ) => acc . concat ( curr ) , [ ] )
306- . map ( ( key ) => key . publicKeyBase58 )
307- )
308- )
317+ Array . from ( new Set ( invitationRecipientKeys . map ( didKeyToVerkey ) ) )
309318 )
310319 }
311320
0 commit comments