Skip to content

Commit

Permalink
org
Browse files Browse the repository at this point in the history
  • Loading branch information
OR13 committed Feb 25, 2024
1 parent 8296a31 commit 573ed33
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 22 deletions.
24 changes: 2 additions & 22 deletions test/hpke.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as transmute from '../src'
import * as cose from '../src'
import fs from 'fs'

const {
Expand All @@ -12,7 +12,7 @@ const {
COSE_Encrypt,
COSE_Encrypt0,
Direct
} = transmute
} = cose

const message = "💀 My lungs taste the air of Time Blown past falling sands ⌛"
const plaintext = new TextEncoder().encode(message)
Expand Down Expand Up @@ -75,23 +75,3 @@ it('direct', async () => {
expect(new TextDecoder().decode(decrypted)).toBe(message)
fs.writeFileSync('./examples/hpke.direct.diag', await cbor.diagnose(ciphertext))
})

it('direct with party info', async () => {
const ciphertext = await encrypt.direct({
protectedHeader: ProtectedHeader([
[Protected.Alg, Direct['HPKE-Base-P256-SHA256-AES128GCM']],
[Protected.PartyUIdentity, Buffer.from(new TextEncoder().encode('did:example:party-u'))],
[Protected.PartyVIdentity, Buffer.from(new TextEncoder().encode('did:example:party-v'))]
]),
plaintext,
recipients: encryptionKeys
})
const decoded = cbor.decodeFirstSync(ciphertext);
expect(decoded.tag).toBe(COSE_Encrypt0)
const decrypted = await decrypt.direct({
ciphertext,
recipients: decryptionKeys
})
expect(new TextDecoder().decode(decrypted)).toBe(message)
fs.writeFileSync('./examples/hpke.direct.party-id.diag', await cbor.diagnose(ciphertext))
})
59 changes: 59 additions & 0 deletions test/kdf.context.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import * as cose from '../src'
import fs from 'fs'

const {
cbor,
encrypt,
decrypt,
ProtectedHeader,
UnprotectedHeader,
Protected,
Aead,
COSE_Encrypt,
COSE_Encrypt0,
Direct
} = cose

const message = "💀 My lungs taste the air of Time Blown past falling sands ⌛"
const plaintext = new TextEncoder().encode(message)
const encryptionKeys = {
keys: [{
"kid": "[email protected]",
"alg": "HPKE-Base-P256-SHA256-AES128GCM",
"kty": "EC",
"crv": "P-256",
"x": "Ze2loSV3wrroKUN_4zhwGhCqo3Xhu1td4QjeQ5wIVR0",
"y": "HlLtdXARY_f55A3fnzQbPcm6hgr34Mp8p-nuzQCE0Zw",
}]
}
const decryptionKeys = {
keys: [{
"kid": "[email protected]",
"alg": "HPKE-Base-P256-SHA256-AES128GCM",
"kty": "EC",
"crv": "P-256",
"x": "Ze2loSV3wrroKUN_4zhwGhCqo3Xhu1td4QjeQ5wIVR0",
"y": "HlLtdXARY_f55A3fnzQbPcm6hgr34Mp8p-nuzQCE0Zw",
"d": "r_kHyZ-a06rmxM3yESK84r1otSg-aQcVStkRhA-iCM8"
}]
}

it('direct with party info', async () => {
const ciphertext = await encrypt.direct({
protectedHeader: ProtectedHeader([
[Protected.Alg, Direct['HPKE-Base-P256-SHA256-AES128GCM']],
[Protected.PartyUIdentity, Buffer.from(new TextEncoder().encode('did:example:party-u'))],
[Protected.PartyVIdentity, Buffer.from(new TextEncoder().encode('did:example:party-v'))]
]),
plaintext,
recipients: encryptionKeys
})
const decoded = cbor.decodeFirstSync(ciphertext);
expect(decoded.tag).toBe(COSE_Encrypt0)
const decrypted = await decrypt.direct({
ciphertext,
recipients: decryptionKeys
})
expect(new TextDecoder().decode(decrypted)).toBe(message)
fs.writeFileSync('./examples/hpke.direct.party-id.diag', await cbor.diagnose(ciphertext))
})

0 comments on commit 573ed33

Please sign in to comment.