Skip to content

Commit

Permalink
feat(did-comm): add JWS DID comm pack / unpack
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceanis committed Jun 17, 2021
1 parent ed63135 commit 19661ed
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 111 deletions.
2 changes: 1 addition & 1 deletion __tests__/localAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,6 @@ describe('Local integration tests', () => {
documentationExamples(testContext)
keyManager(testContext)
didManager(testContext)
didComm(testContext)
messageHandler(testContext)
didComm(testContext)
})
2 changes: 1 addition & 1 deletion __tests__/localMemoryStoreAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,6 @@ describe('Local in-memory integration tests', () => {
documentationExamples(testContext)
keyManager(testContext)
didManager(testContext)
didComm(testContext)
messageHandler(testContext)
didComm(testContext)
})
2 changes: 1 addition & 1 deletion __tests__/restAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,6 @@ describe('REST integration tests', () => {
documentationExamples(testContext)
keyManager(testContext)
didManager(testContext)
didComm(testContext)
messageHandler(testContext)
didComm(testContext)
})
35 changes: 25 additions & 10 deletions __tests__/shared/didcomm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TAgent, IDIDManager, IKeyManager, IIdentifier, IResolver } from '../../packages/core/src'
import { IDIDComm, IDIDCommMessageMediaType } from '../../packages/did-comm/src'
import { IDIDComm } from '../../packages/did-comm/src'

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

Expand All @@ -19,15 +19,13 @@ export default (testContext: {

sender = await agent.didManagerImport({
did: 'did:key:z6MkgbqNU4uF9NKSz5BqJQ4XKVHuQZYcUZP8pXGsJC8nTHwo',
controllerKeyId: '1fe9b397c196ab33549041b29cf93be29b9f2bdd27322f05844112fad97ff92a',
keys: [
{
type: 'Ed25519',
kid: '1fe9b397c196ab33549041b29cf93be29b9f2bdd27322f05844112fad97ff92a',
kid: 'didcomm-senderKey-1',
publicKeyHex: '1fe9b397c196ab33549041b29cf93be29b9f2bdd27322f05844112fad97ff92a',
privateKeyHex:
'b57103882f7c66512dc96777cbafbeb2d48eca1e7a867f5a17a84e9a6740f7dc1fe9b397c196ab33549041b29cf93be29b9f2bdd27322f05844112fad97ff92a',
meta: { algorithms: ['Ed25519', 'EdDSA'] },
kms: 'local',
},
],
Expand All @@ -38,15 +36,13 @@ export default (testContext: {

receiver = await agent.didManagerImport({
did: 'did:key:z6MkrPhffVLBZpxH7xvKNyD4sRVZeZsNTWJkLdHdgWbfgNu3',
controllerKeyId: 'b162e405b6485eff8a57932429b192ec4de13c06813e9028a7cdadf0e2703636',
keys: [
{
type: 'Ed25519',
kid: 'b162e405b6485eff8a57932429b192ec4de13c06813e9028a7cdadf0e2703636',
kid: 'didcomm-receiverKey-1',
publicKeyHex: 'b162e405b6485eff8a57932429b192ec4de13c06813e9028a7cdadf0e2703636',
privateKeyHex:
'19ed9b6949cfd0f9a57e30f0927839a985fa699491886ebcdda6a954d869732ab162e405b6485eff8a57932429b192ec4de13c06813e9028a7cdadf0e2703636',
meta: { algorithms: ['Ed25519', 'EdDSA'] },
kms: 'local',
},
],
Expand All @@ -58,7 +54,7 @@ export default (testContext: {
})
afterAll(testContext.tearDown)

it('should pack a plaintext message', async () => {
it('should pack and unpack a plaintext message', async () => {
expect.assertions(1)
const message = {
type: 'test',
Expand All @@ -80,7 +76,26 @@ export default (testContext: {
})
})

it('should pack an anonymous encrypted message', async () => {
it('should pack and unpack a JWS message', async () => {
const message = {
type: 'test',
to: receiver.did,
from: sender.did,
id: 'test',
body: { hello: 'world' },
}
const packedMessage = await agent.packDIDCommMessage({
packing: 'jws',
message,
})
const unpackedMessage = await agent.unpackDIDCommMessage(packedMessage)
expect(unpackedMessage).toEqual({
message,
metaData: { packing: 'jws' },
})
})

it('should pack and unpack an anoncrypted message', async () => {
expect.assertions(2)
const message = {
type: 'test',
Expand All @@ -97,7 +112,7 @@ export default (testContext: {
expect(unpackedMessage.metaData).toEqual({ packing: 'anoncrypt' })
})

it('should pack an authcrypted message', async () => {
it('should pack and unpack an authcrypted message', async () => {
expect.assertions(2)
const message = {
type: 'test',
Expand Down
Loading

0 comments on commit 19661ed

Please sign in to comment.