-
Notifications
You must be signed in to change notification settings - Fork 200
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: Discover Features V2 over DIDComm V2 #1576
base: feat/didcomm-v2
Are you sure you want to change the base?
Changes from all commits
c447c32
76e8a5c
0a4d4f2
7acfdac
af61ae7
49ad374
ef0b934
7d75254
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,17 +1,20 @@ | ||||||
import type { AgentBaseMessage } from './AgentBaseMessage' | ||||||
import type { AgentContext } from './context' | ||||||
import type { DidCommV1Message } from '../didcomm/versions/v1' | ||||||
import type { ConnectionRecord, Routing } from '../modules/connections' | ||||||
import type { ResolvedDidCommService } from '../modules/didcomm' | ||||||
import type { OutOfBandRecord } from '../modules/oob' | ||||||
import type { BaseRecordAny } from '../storage/BaseRecord' | ||||||
|
||||||
import { Key } from '../crypto' | ||||||
import { ServiceDecorator } from '../decorators/service/ServiceDecorator' | ||||||
import { DidCommMessageVersion, DidCommV1Message, DidCommV2Message } from '../didcomm' | ||||||
import { AriesFrameworkError } from '../error' | ||||||
import { OutOfBandService, OutOfBandRole, OutOfBandRepository } from '../modules/oob' | ||||||
import { OutOfBandRole } from '../modules/oob/domain' | ||||||
import { OutOfBandService } from '../modules/oob/protocols' | ||||||
import { OutOfBandRepository } from '../modules/oob/repository' | ||||||
import { OutOfBandRecordMetadataKeys } from '../modules/oob/repository/outOfBandRecordMetadataTypes' | ||||||
import { RoutingService } from '../modules/routing' | ||||||
import { DidCommMessageRepository, DidCommMessageRole } from '../storage' | ||||||
import { RoutingService } from '../modules/routing/services' | ||||||
import { DidCommMessageRepository, DidCommMessageRole } from '../storage/didcomm' | ||||||
import { uuid } from '../utils/uuid' | ||||||
|
||||||
import { OutboundMessageContext } from './models' | ||||||
|
@@ -37,9 +40,9 @@ export async function getOutboundMessageContext( | |||||
}: { | ||||||
connectionRecord?: ConnectionRecord | ||||||
associatedRecord?: BaseRecordAny | ||||||
message: DidCommV1Message | ||||||
lastReceivedMessage?: DidCommV1Message | ||||||
lastSentMessage?: DidCommV1Message | ||||||
message: AgentBaseMessage | ||||||
lastReceivedMessage?: AgentBaseMessage | ||||||
lastSentMessage?: AgentBaseMessage | ||||||
} | ||||||
) { | ||||||
// TODO: even if using a connection record, we should check if there's an oob record associated and this | ||||||
|
@@ -48,6 +51,27 @@ export async function getOutboundMessageContext( | |||||
agentContext.config.logger.debug( | ||||||
`Creating outbound message context for message ${message.id} with connection ${connectionRecord.id}` | ||||||
) | ||||||
|
||||||
// Check that message DIDComm version matches connection | ||||||
if ( | ||||||
(connectionRecord.isDidCommV1Connection && message.didCommVersion !== DidCommMessageVersion.V1) || | ||||||
(connectionRecord.isDidCommV2Connection && message.didCommVersion !== DidCommMessageVersion.V2) | ||||||
) { | ||||||
throw new AriesFrameworkError( | ||||||
`Message DIDComm version ${message.didCommVersion} does not match connection ${connectionRecord.id}` | ||||||
) | ||||||
} | ||||||
Comment on lines
+55
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. I think we may have to tweak this at some point as the services in a did document dictate which didcomm versions are supported. We only have did:peer connections now, but if we want to make it future proof already, we could also handle this later on, after we've resolved the services for a connection. Thoughts? |
||||||
|
||||||
// Attach 'from' and 'to' fields according to connection record (unless they are previously defined) | ||||||
if (message instanceof DidCommV2Message) { | ||||||
message.from = message.from ?? connectionRecord.did | ||||||
const recipients = message.to ?? (connectionRecord.theirDid ? [connectionRecord.theirDid] : undefined) | ||||||
if (!recipients) { | ||||||
throw new AriesFrameworkError('Cannot find recipient did for message') | ||||||
} | ||||||
message.to = recipients | ||||||
} | ||||||
Comment on lines
+65
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can there be any danger in having different from/to than the connectionRecord? What would be the use case? I think if you want custom from/to you should probably not pass a connection record to the |
||||||
|
||||||
return new OutboundMessageContext(message, { | ||||||
agentContext, | ||||||
associatedRecord, | ||||||
|
@@ -67,6 +91,14 @@ export async function getOutboundMessageContext( | |||||
) | ||||||
} | ||||||
|
||||||
if ( | ||||||
!(message instanceof DidCommV1Message) || | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can invert all these statements?
Suggested change
|
||||||
(lastReceivedMessage !== undefined && !(lastReceivedMessage instanceof DidCommV1Message)) || | ||||||
(lastSentMessage !== undefined && !(lastSentMessage instanceof DidCommV1Message)) | ||||||
) { | ||||||
throw new AriesFrameworkError('No connection record associated with DIDComm V2 messages exchange') | ||||||
} | ||||||
|
||||||
// Connectionless | ||||||
return getConnectionlessOutboundMessageContext(agentContext, { | ||||||
message, | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
import type { DidCommMessageVersion } from './types' | ||
import type { DidCommV1Message } from './versions/v1' | ||
import type { DidCommV2Message } from './versions/v2' | ||
import type { ParsedMessageType } from '../utils/messageType' | ||
import type { Constructor } from '../utils/mixins' | ||
|
||
export * from './versions/v1' | ||
export * from './versions/v2' | ||
export * from './transformers' | ||
export * from './types' | ||
export * from './helpers' | ||
export * from './JweEnvelope' | ||
|
||
export type ConstructableDidCommMessage = Constructor<DidCommV1Message | DidCommV2Message> & { type: ParsedMessageType } | ||
export type ConstructableDidCommMessage = Constructor<DidCommV1Message | DidCommV2Message> & { | ||
type: ParsedMessageType | ||
didCommVersion: DidCommMessageVersion | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make this future proof and have an if / else if / else throw error?