Skip to content

Commit

Permalink
feat(did-comm): Improve DIDComm Service compatibility (#1340)
Browse files Browse the repository at this point in the history
* fix(did-comm): support services defined as arrays, including shorthand form
* feat(did-comm): sendMessage now uses all transports and endpoints that match
* fix(did-provider-peer): add options for creating a did:peer from known private keys
* fix(did-comm): update `message.to` to an array of recipients

BREAKING CHANGE: the DIDComm Message structure has changed. The message can now specify multiple recipients in the `to` property.
  • Loading branch information
mirceanis committed Feb 22, 2024
1 parent 07c982f commit 6df704c
Show file tree
Hide file tree
Showing 28 changed files with 829 additions and 323 deletions.
2 changes: 1 addition & 1 deletion __tests__/shared/dbInitOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export default (testContext: {
packedMessage = await agent.packDIDCommMessage({
packing: 'authcrypt',
message: {
to: identifier.did,
to: [identifier.did],
from: identifier.did,
id: 'test-message-123',
type: 'w3c.vc',
Expand Down
4 changes: 2 additions & 2 deletions __tests__/shared/didCommAndDataStoreWithCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default (testContext: {

const message = {
type: 'test',
to: receiver.did,
to: [receiver.did],
from: sender.did,
id: 'test',
body: { hello: 'world' },
Expand Down Expand Up @@ -136,7 +136,7 @@ export default (testContext: {
id: v4(),
type: 'w3c.vc',
from: sender.did,
to: receiver.did,
to: [receiver.did],
body: vc,
},
})
Expand Down
26 changes: 13 additions & 13 deletions __tests__/shared/didCommPacking.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// noinspection ES6PreferShortImport

import { IDIDManager, IIdentifier, IKeyManager, IResolver, TAgent } from '../../packages/core-types/src'
import { IDIDComm } from '../../packages/did-comm/src'
import { IDIDComm, IDIDCommMessage } from '../../packages/did-comm/src'

type ConfiguredAgent = TAgent<IDIDManager & IKeyManager & IResolver & IDIDComm>

Expand Down Expand Up @@ -58,9 +58,9 @@ export default (testContext: {

it('should pack and unpack a plaintext message', async () => {
expect.assertions(2)
const message = {
const message: IDIDCommMessage = {
type: 'test',
to: receiver.did,
to: [receiver.did],
id: 'test',
body: { hello: 'world' },
}
Expand All @@ -80,9 +80,9 @@ export default (testContext: {
})

it('should pack and unpack a JWS message', async () => {
const message = {
const message: IDIDCommMessage = {
type: 'test',
to: receiver.did,
to: [receiver.did],
from: sender.did,
id: 'test',
body: { hello: 'world' },
Expand All @@ -100,9 +100,9 @@ export default (testContext: {

it('should pack and unpack an anoncrypted message', async () => {
expect.assertions(2)
const message = {
const message :IDIDCommMessage = {
type: 'test',
to: receiver.did,
to: [receiver.did],
id: 'test',
body: { hello: 'world' },
}
Expand All @@ -117,9 +117,9 @@ export default (testContext: {

it('should pack and unpack an authcrypted message', async () => {
expect.assertions(2)
const message = {
const message: IDIDCommMessage = {
type: 'test',
to: receiver.did,
to: [receiver.did],
from: sender.did,
id: 'test',
body: { hello: 'world' },
Expand All @@ -146,10 +146,10 @@ export default (testContext: {
provider: 'did:key',
})

const message = {
const message: IDIDCommMessage = {
type: 'test',
from: originator.did,
to: originator.did,
to: [originator.did],
id: 'test',
body: { hello: 'world' },
}
Expand Down Expand Up @@ -179,10 +179,10 @@ export default (testContext: {
provider: 'did:key',
})

const message = {
const message: IDIDCommMessage = {
type: 'test',
from: originator.did,
to: originator.did,
to: [originator.did],
id: 'test',
body: { hello: 'world' },
}
Expand Down
30 changes: 15 additions & 15 deletions __tests__/shared/didCommWithEthrDidFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export default (testContext: {

const message = {
type: 'test',
to: alice.did,
to: [alice.did],
from: bob.did,
id: 'test-jws-success',
body: { hello: 'world' },
Expand Down Expand Up @@ -315,7 +315,7 @@ export default (testContext: {
body: { hello: 'world' },
from: bob.did,
id: 'test-jws-success',
to: alice.did,
to: [alice.did],
type: 'test',
},
metaData: { packing: 'jws' },
Expand Down Expand Up @@ -364,7 +364,7 @@ export default (testContext: {

const message = {
type: 'test',
to: alice.did,
to: [alice.did],
from: bob.did,
id: 'test-jws-success',
body: { hello: 'world' },
Expand Down Expand Up @@ -392,7 +392,7 @@ export default (testContext: {
body: { hello: 'world' },
from: bob.did,
id: 'test-jws-success',
to: alice.did,
to: [alice.did],
type: 'test',
},
metaData: { packing: 'jws' },
Expand Down Expand Up @@ -441,7 +441,7 @@ export default (testContext: {

const message = {
type: 'test',
to: alice.did,
to: [alice.did],
from: bob.did,
id: 'test-jws-success',
body: { hello: 'world' },
Expand Down Expand Up @@ -469,7 +469,7 @@ export default (testContext: {
body: { hello: 'world' },
from: bob.did,
id: 'test-jws-success',
to: alice.did,
to: [alice.did],
type: 'test',
},
metaData: { packing: 'jws' },
Expand Down Expand Up @@ -518,7 +518,7 @@ export default (testContext: {

const message = {
type: 'test',
to: alice.did,
to: [alice.did],
from: bob.did,
id: 'test-jws-success',
body: { hello: 'world' },
Expand Down Expand Up @@ -546,7 +546,7 @@ export default (testContext: {
body: { hello: 'world' },
from: bob.did,
id: 'test-jws-success',
to: alice.did,
to: [alice.did],
type: 'test',
},
metaData: { packing: 'jws' },
Expand All @@ -562,7 +562,7 @@ export default (testContext: {

const message = {
type: 'test',
to: alice.did,
to: [alice.did],
from: bob.did,
id: 'test-anoncrypt-fail',
body: { hello: 'world' },
Expand Down Expand Up @@ -600,7 +600,7 @@ export default (testContext: {

const message = {
type: 'test',
to: alice.did,
to: [alice.did],
from: bob.did,
id: 'test-anoncrypt-success',
body: { hello: 'world' },
Expand Down Expand Up @@ -628,7 +628,7 @@ export default (testContext: {
body: { hello: 'world' },
from: 'did:ethr:ganache:0x02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5',
id: 'test-anoncrypt-success',
to: 'did:ethr:ganache:0x0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
to: ['did:ethr:ganache:0x0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'],
type: 'test',
},
metaData: { packing: 'anoncrypt' },
Expand All @@ -644,7 +644,7 @@ export default (testContext: {

const message = {
type: 'test',
to: bob.did,
to: [bob.did],
from: alice.did,
id: 'test-endpoint-fail',
body: { hello: 'world' },
Expand All @@ -667,7 +667,7 @@ export default (testContext: {

const message = {
type: 'test',
to: alice.did,
to: [alice.did],
from: bob.did,
id: 'test-authcrypt-fail',
body: { hello: 'world' },
Expand Down Expand Up @@ -705,7 +705,7 @@ export default (testContext: {

const message = {
type: 'test',
to: alice.did,
to: [alice.did],
from: bob.did,
id: 'test-authcrypt-success',
body: { hello: 'world' },
Expand Down Expand Up @@ -733,7 +733,7 @@ export default (testContext: {
body: { hello: 'world' },
from: bob.did,
id: 'test-authcrypt-success',
to: alice.did,
to: [alice.did],
type: 'test',
},
metaData: { packing: 'authcrypt' },
Expand Down
24 changes: 12 additions & 12 deletions __tests__/shared/didCommWithFakeDidFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export default (testContext: {

const message = {
type: 'test',
to: receiver.did,
to: [receiver.did],
from: sender.did,
id: 'test',
body: { hello: 'world' },
Expand Down Expand Up @@ -302,7 +302,7 @@ export default (testContext: {
body: { hello: 'world' },
from: 'did:fake:z6MkgbqNU4uF9NKSz5BqJQ4XKVHuQZYcUZP8pXGsJC8nTHwo',
id: 'test',
to: 'did:fake:z6MkrPhffVLBZpxH7xvKNyD4sRVZeZsNTWJkLdHdgWbfgNu3',
to: ['did:fake:z6MkrPhffVLBZpxH7xvKNyD4sRVZeZsNTWJkLdHdgWbfgNu3'],
type: 'test',
},
metaData: { packing: 'authcrypt' },
Expand All @@ -318,7 +318,7 @@ export default (testContext: {

const message = {
type: 'test',
to: receiverWithMediation.did,
to: [receiverWithMediation.did],
from: sender.did,
id: 'test',
body: { hello: 'world' },
Expand Down Expand Up @@ -356,7 +356,7 @@ export default (testContext: {
message: {
body: { next: receiverWithMediation.did },
id: expect.anything(),
to: mediator.did,
to: [mediator.did],
type: 'https://didcomm.org/routing/2.0/forward',
attachments: expect.anything(),
},
Expand All @@ -373,7 +373,7 @@ export default (testContext: {

const message = {
type: 'test',
to: receiverWithMediation5.did,
to: [receiverWithMediation5.did],
from: sender.did,
id: 'test',
body: { hello: 'world' },
Expand Down Expand Up @@ -411,7 +411,7 @@ export default (testContext: {
message: {
body: { next: receiverWithMediation5.did },
id: expect.anything(),
to: mediator.did,
to: [mediator.did],
type: 'https://didcomm.org/routing/2.0/forward',
attachments: expect.anything(),
},
Expand All @@ -428,7 +428,7 @@ export default (testContext: {

const message = {
type: 'test',
to: receiverWithMediation2.did,
to: [receiverWithMediation2.did],
from: sender.did,
id: 'test',
body: { hello: 'world' },
Expand Down Expand Up @@ -477,7 +477,7 @@ export default (testContext: {
message: {
body: { next: mediator.did },
id: expect.anything(),
to: mediator2.did,
to: [mediator2.did],
type: 'https://didcomm.org/routing/2.0/forward',
attachments: expect.anything(),
},
Expand All @@ -494,7 +494,7 @@ export default (testContext: {

const message = {
type: 'test',
to: receiverWithMediation3.did,
to: [receiverWithMediation3.did],
from: sender.did,
id: 'test',
body: { hello: 'world' },
Expand Down Expand Up @@ -532,7 +532,7 @@ export default (testContext: {
message: {
body: { next: receiverWithMediation3.did },
id: expect.anything(),
to: mediator.did,
to: [mediator.did],
type: 'https://didcomm.org/routing/2.0/forward',
attachments: expect.anything(),
},
Expand All @@ -549,7 +549,7 @@ export default (testContext: {

const message = {
type: 'test',
to: receiverWithMediation4.did,
to: [receiverWithMediation4.did],
from: sender.did,
id: 'test',
body: { hello: 'world' },
Expand Down Expand Up @@ -598,7 +598,7 @@ export default (testContext: {
message: {
body: { next: mediator.did },
id: expect.anything(),
to: mediator2.did,
to: [mediator2.did],
type: 'https://didcomm.org/routing/2.0/forward',
attachments: expect.anything(),
},
Expand Down
2 changes: 1 addition & 1 deletion __tests__/shared/didCommWithPeerDidFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default (testContext: {

const message = {
type: 'test',
to: receiver.did,
to: [receiver.did],
from: sender.did,
id: 'test',
body: { hello: 'world' },
Expand Down
2 changes: 0 additions & 2 deletions packages/did-comm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
"@veramo/mediation-manager": "workspace:^",
"@veramo/message-handler": "workspace:^",
"@veramo/utils": "workspace:^",
"@veramo/kv-store": "workspace:^",
"@veramo/mediation-manager": "workspace:^",
"cross-fetch": "^4.0.0",
"debug": "^4.3.3",
"did-jwt": "^8.0.0",
Expand Down
Loading

0 comments on commit 6df704c

Please sign in to comment.