Skip to content

Commit

Permalink
add party example
Browse files Browse the repository at this point in the history
  • Loading branch information
OR13 committed Feb 23, 2024
1 parent a52bbf9 commit 42fc388
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/hpke.direct.diag
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16([h'a1011823', {4: "[email protected]", -1: {1: 5, -1: h'04ea598ce9d7ff813ef17aa8594083684ca09902778cecd53ed0135d1645e68aa91b70f8523aa970b569df7345bc6914fe031b4ab7dc5f4c87126b6465c7cbe1b7'}}, h'3fd73a830be4df98a6b56c47282a18cbbe321355d73670b559222588f9205695851060f5c4818e886002737443e691e119c6938529e9d5c6038ab2ba7a13e8d7378a44b18f62efb0618515a7126e084e'])
16([h'a1011823', {4: "[email protected]", -1: {1: 5, -1: h'0417572553a7126604ae71d8525c01dcd4f57dd1e5d281336bb135e17535a671bf1f982987487cd46db3d63fdb5a264012fff093587e9373f3be127b8c9ece0b8d'}}, h'c15660b575d32293b3c56f52ec8b63dbf504f214a8d22e4b6cbaa855b9050ead2d25b945de7ae75a8f630ffb0b389164d104dcd5c5e2483d59539e8cf3d15841148d53d04b63bbba0884c8ee43821657'])
1 change: 1 addition & 0 deletions examples/hpke.direct.party-id.diag
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16([h'a301182334536469643a6578616d706c653a70617274792d7537536469643a6578616d706c653a70617274792d76', {4: "[email protected]", -1: {1: 5, -1: h'04b989def15e98895974d21a9b3bad8a5dc3c8f9b4779a2277a785ae7d7be49fced90fea333c205e6c32c314e609b414bf2e749246def7a842ad8009e0ba87f986'}}, h'017a7f680480b5b5a7e008a7b01d8aaf292f2ea96920ace94fa9a6b08232c9fca2db9f59e97db561b68c5724697dbfbf3ddc7579ba316a18b65d5b42304eed411b4cb4cc50491ad109ffab391981a045'])
2 changes: 1 addition & 1 deletion examples/hpke.wrap.diag
Original file line number Diff line number Diff line change
@@ -1 +1 @@
96([h'a10101', {5: 64(h'02aeece48a6acb8283626684aadafec3')}, h'3b12f74131624c529bb81d830d4e6f20d6cdf4e63483cd008c66f6335db308e00705bd45e3f0b47b9c01c3a0150fd09354a5eb18906569cb49044f913a345707bfe555e8c5bd74ba3c2687c49793c349', [[h'a1011823', {4: "[email protected]", -1: {1: 5, -1: h'047dfb4519b37232544da9652c8b30499ed9b3c6aa7a1c64c6e20615518d2c499d79d1e441af2d085dc51d411fb68bf8c4cdefbb56c052c0e01b3535e819978fa9'}}, h'e36a3c29cbe95ec0b638330c16de6d3a76d6256152e2d4a825b30f83da362829']]])
96([h'a10101', {5: 64(h'25fd0a15840c40c22bbea60842e939ca')}, h'dbf700c25ab0d34d23c9575d210ec8295d22214e35e504aa512919adecc972b42d458d8d5a78bbeb61cc85f597c86b8280b623e994aa463f9c2458e015f06789d2fd94e99afd3f81c332d784ebd31ba8', [[h'a1011823', {4: "[email protected]", -1: {1: 5, -1: h'04501ef446ac3d71870dccf25015ad796be3f5a798a5af12f558f7838c8c5d2da9bef5ae3a48691414ace3c932d18b4657f2daeeb4e25414e8a3d41e9517658fc5'}}, h'438c0d767ad7fb56540b6b5ee3b78158a0e5bc7a4a48668ae62b9ecc7e58f22f']]])
47 changes: 47 additions & 0 deletions test/hpke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,51 @@ it('direct', async () => {
})
expect(new TextDecoder().decode(decrypted)).toBe("πŸ’€ My lungs taste the air of Time Blown past falling sands βŒ›")
fs.writeFileSync('./examples/hpke.direct.diag', await cbor.diagnose(ct))
})



it('direct with party info', async () => {
const protectedHeader = new Map<number, any>([
[1, 35], // alg : HPKE-Base-P256-SHA256-AES128GCM
[-21, Buffer.from(new TextEncoder().encode('did:example:party-u'))],
[-24, Buffer.from(new TextEncoder().encode('did:example:party-v'))]
])
const unprotectedHeader = new Map<number, any>([])
const plaintext = new TextEncoder().encode("πŸ’€ My lungs taste the air of Time Blown past falling sands βŒ›")
const ct = await transmute.encrypt.direct({
protectedHeader,
unprotectedHeader,
plaintext,
recipients: {
keys: [{
"kid": "[email protected]",
"alg": "HPKE-Base-P256-SHA256-AES128GCM",
"kty": "EC",
"crv": "P-256",
"x": "Ze2loSV3wrroKUN_4zhwGhCqo3Xhu1td4QjeQ5wIVR0",
"y": "HlLtdXARY_f55A3fnzQbPcm6hgr34Mp8p-nuzQCE0Zw",
// encrypt to public keys only
// "d": "r_kHyZ-a06rmxM3yESK84r1otSg-aQcVStkRhA-iCM8"
}]
}
})
const decoded = transmute.cbor.decodeFirstSync(ct);
expect(decoded.tag).toBe(16)
const decrypted = await transmute.decrypt.direct({
ciphertext: ct,
recipients: {
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"
}]
}
})
expect(new TextDecoder().decode(decrypted)).toBe("πŸ’€ My lungs taste the air of Time Blown past falling sands βŒ›")
fs.writeFileSync('./examples/hpke.direct.party-id.diag', await cbor.diagnose(ct))
})

0 comments on commit 42fc388

Please sign in to comment.