Cryptographic envelope layer of DIDComm written in Typescript
npm install @hearro/didcommDIDComm-crypto-js when a CI/CD platform can be added to publish it.NOTE THESE APIs are currently unstable at this point to account for new non-repudiable signing changes
There's currently 4 APIs of use in this library that will handle encryption and decryption to multiple recipients. Messages encrypted with this library support repudiable authentication and anonymous encryption. There's additional APIs to support non-repudiable signing and verification of messages.
``typescript`
const didcomm = new DIDComm()
await didcomm.Ready
const alice = await didcomm.generateKeyPair()
const bob = await didcomm.generateKeyPair()
const message = 'I AM A PRIVATE MESSAGE'
const packedMsg = await didcomm.pack_auth_msg_for_recipients(message, [bob.publicKey], alice)
const unpackedMsg = await didcomm.unpackMessage(packedMsg, bob)
. To understand what non-repudiation is and when it should be used refer here.`typescript
const didcomm = new DIDComm()
await didcomm.Ready
const alice = await didcomm.generateKeyPair()
const bob = await didcomm.generateKeyPair()
const message = 'I AM A PRIVATE MESSAGE'
const packedMsg = await didcomm.pack_auth_msg_for_recipients(message, [bob.publicKey], alice, true)
const unpackedMsg = await didcomm.unpackMessage(packedMsg, bob)
`$3
For privacy reasons or to meet the principle of least information, it may be necessary to encrypt a message, but does not provide authentication guarantees.
`typescript
const didcomm = new DIDComm()
await didcomm.Ready
const bob = await didcomm.generateKeyPair()
const message = JSON.stringify({
"@type": "did:example:1234567890;spec/test",
data: "I AM A SIGNED MESSAGE"
})
const packedMsg = await didcomm.pack_anon_msg_for_recipients(message, [bob.publicKey])
const unpackedMsg = await didcomm.unpackMessage(packedMsg, bob)
`$3
In very specific use cases like the invitation protocol or incredibly short lived connection (1 round trip only) it's necessary to provide data in a plaintext format to provide a key. In these cases we will sign the data, but leave it unencrypted.
`typescript
const didcomm = new DIDComm()
await didcomm.Ready
const bob = await didcomm.generateKeyPair()
const message = "I AM A PUBLIC MESSAGE"
const packedMsg = await didcomm.pack_nonrepudiable_msg_for_anyone(message, bob)
const unpackedMsg = await didcomm.unpackMessage(packedMsg, bob)
``To perform authentication this library should be combined with resolution of a DID Document to ensure the key used by the sender is contained in a valid DID Document. This funcationality is considered out of scope for this library.