-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for did-comm over simple HTTP-based transports (#610)
fixes #552 fixes #469 * feat: add sending didcomm messages * feat: add transport logic * fix(did-comm): message handler * docs: add more inline documentation for did-comm * fix: use http transport by default with didcomm * test(did-comm): integration test for sending data * test(did-comm): check didcomm events * style: refactoring and code reformatting Co-authored-by: Oliver Terbu <> Co-authored-by: Mircea Nistor <[email protected]> Co-authored-by: Simonas Karuzas <[email protected]>
- Loading branch information
1 parent
eebe32c
commit 78836a4
Showing
12 changed files
with
434 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import { | ||
TAgent, | ||
IDIDManager, | ||
IKeyManager, | ||
IIdentifier, | ||
IResolver, | ||
IEventListener, | ||
IAgentOptions, | ||
} from '../../packages/core/src' | ||
import { IDIDComm } from '../../packages/did-comm/src' | ||
|
||
type ConfiguredAgent = TAgent<IDIDManager & IKeyManager & IResolver & IDIDComm> | ||
|
||
const DIDCommEventSniffer: IEventListener = { | ||
eventTypes: ['DIDCommV2Message-sent', 'DIDCommV2Message-received'], | ||
onEvent: jest.fn(), | ||
} | ||
|
||
export default (testContext: { | ||
getAgent: () => ConfiguredAgent | ||
setup: (options?: IAgentOptions) => Promise<boolean> | ||
tearDown: () => Promise<boolean> | ||
}) => { | ||
describe('DID comm remote', () => { | ||
let agent: ConfiguredAgent | ||
let sender: IIdentifier | ||
let receiver: IIdentifier | ||
|
||
beforeAll(async () => { | ||
await testContext.setup({ plugins: [DIDCommEventSniffer] }) | ||
agent = testContext.getAgent() | ||
|
||
sender = await agent.didManagerImport({ | ||
did: 'did:fake:z6MkgbqNU4uF9NKSz5BqJQ4XKVHuQZYcUZP8pXGsJC8nTHwo', | ||
keys: [ | ||
{ | ||
type: 'Ed25519', | ||
kid: 'didcomm-senderKey-1', | ||
publicKeyHex: '1fe9b397c196ab33549041b29cf93be29b9f2bdd27322f05844112fad97ff92a', | ||
privateKeyHex: | ||
'b57103882f7c66512dc96777cbafbeb2d48eca1e7a867f5a17a84e9a6740f7dc1fe9b397c196ab33549041b29cf93be29b9f2bdd27322f05844112fad97ff92a', | ||
kms: 'local', | ||
}, | ||
], | ||
services: [ | ||
{ | ||
id: 'msg1', | ||
type: 'DIDCommMessaging', | ||
serviceEndpoint: 'http://localhost:3002/messaging', | ||
}, | ||
], | ||
provider: 'did:fake', | ||
alias: 'sender', | ||
}) | ||
|
||
receiver = await agent.didManagerImport({ | ||
did: 'did:fake:z6MkrPhffVLBZpxH7xvKNyD4sRVZeZsNTWJkLdHdgWbfgNu3', | ||
keys: [ | ||
{ | ||
type: 'Ed25519', | ||
kid: 'didcomm-receiverKey-1', | ||
publicKeyHex: 'b162e405b6485eff8a57932429b192ec4de13c06813e9028a7cdadf0e2703636', | ||
privateKeyHex: | ||
'19ed9b6949cfd0f9a57e30f0927839a985fa699491886ebcdda6a954d869732ab162e405b6485eff8a57932429b192ec4de13c06813e9028a7cdadf0e2703636', | ||
kms: 'local', | ||
}, | ||
], | ||
services: [ | ||
{ | ||
id: 'msg2', | ||
type: 'DIDCommMessaging', | ||
serviceEndpoint: 'http://localhost:3002/messaging', | ||
}, | ||
], | ||
provider: 'did:fake', | ||
alias: 'receiver', | ||
}) | ||
return true | ||
}) | ||
afterAll(testContext.tearDown) | ||
|
||
it('should send a message', async () => { | ||
expect.assertions(3) | ||
|
||
const message = { | ||
type: 'test', | ||
to: receiver.did, | ||
from: sender.did, | ||
id: 'test', | ||
body: { hello: 'world' }, | ||
} | ||
const packedMessage = await agent.packDIDCommMessage({ | ||
packing: 'authcrypt', | ||
message, | ||
}) | ||
const result = await agent.sendDIDCommMessage({ | ||
messageId: '123', | ||
packedMessage, | ||
recipientDidUrl: receiver.did, | ||
}) | ||
|
||
expect(result).toBeTruthy() | ||
expect(DIDCommEventSniffer.onEvent).toHaveBeenCalledWith( | ||
{ data: '123', type: 'DIDCommV2Message-sent' }, | ||
expect.anything(), | ||
) | ||
// in our case, it is the same agent that is receiving the messages | ||
expect(DIDCommEventSniffer.onEvent).toHaveBeenCalledWith( | ||
{ | ||
data: { | ||
message: { | ||
body: { hello: 'world' }, | ||
from: 'did:fake:z6MkgbqNU4uF9NKSz5BqJQ4XKVHuQZYcUZP8pXGsJC8nTHwo', | ||
id: 'test', | ||
to: 'did:fake:z6MkrPhffVLBZpxH7xvKNyD4sRVZeZsNTWJkLdHdgWbfgNu3', | ||
type: 'test', | ||
}, | ||
metaData: { packing: 'authcrypt' }, | ||
}, | ||
type: 'DIDCommV2Message-received', | ||
}, | ||
expect.anything(), | ||
) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.