From 42fc388f980d0f64facc94eddcf4afa0b6344fcd Mon Sep 17 00:00:00 2001 From: Orie Steele Date: Fri, 23 Feb 2024 17:09:40 -0600 Subject: [PATCH] add party example --- examples/hpke.direct.diag | 2 +- examples/hpke.direct.party-id.diag | 1 + examples/hpke.wrap.diag | 2 +- test/hpke.test.ts | 47 ++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 examples/hpke.direct.party-id.diag diff --git a/examples/hpke.direct.diag b/examples/hpke.direct.diag index 88b862e..cdd442a 100644 --- a/examples/hpke.direct.diag +++ b/examples/hpke.direct.diag @@ -1 +1 @@ -16([h'a1011823', {4: "meriadoc.brandybuck@buckland.example", -1: {1: 5, -1: h'04ea598ce9d7ff813ef17aa8594083684ca09902778cecd53ed0135d1645e68aa91b70f8523aa970b569df7345bc6914fe031b4ab7dc5f4c87126b6465c7cbe1b7'}}, h'3fd73a830be4df98a6b56c47282a18cbbe321355d73670b559222588f9205695851060f5c4818e886002737443e691e119c6938529e9d5c6038ab2ba7a13e8d7378a44b18f62efb0618515a7126e084e']) +16([h'a1011823', {4: "meriadoc.brandybuck@buckland.example", -1: {1: 5, -1: h'0417572553a7126604ae71d8525c01dcd4f57dd1e5d281336bb135e17535a671bf1f982987487cd46db3d63fdb5a264012fff093587e9373f3be127b8c9ece0b8d'}}, h'c15660b575d32293b3c56f52ec8b63dbf504f214a8d22e4b6cbaa855b9050ead2d25b945de7ae75a8f630ffb0b389164d104dcd5c5e2483d59539e8cf3d15841148d53d04b63bbba0884c8ee43821657']) diff --git a/examples/hpke.direct.party-id.diag b/examples/hpke.direct.party-id.diag new file mode 100644 index 0000000..15d0798 --- /dev/null +++ b/examples/hpke.direct.party-id.diag @@ -0,0 +1 @@ +16([h'a301182334536469643a6578616d706c653a70617274792d7537536469643a6578616d706c653a70617274792d76', {4: "meriadoc.brandybuck@buckland.example", -1: {1: 5, -1: h'04b989def15e98895974d21a9b3bad8a5dc3c8f9b4779a2277a785ae7d7be49fced90fea333c205e6c32c314e609b414bf2e749246def7a842ad8009e0ba87f986'}}, h'017a7f680480b5b5a7e008a7b01d8aaf292f2ea96920ace94fa9a6b08232c9fca2db9f59e97db561b68c5724697dbfbf3ddc7579ba316a18b65d5b42304eed411b4cb4cc50491ad109ffab391981a045']) diff --git a/examples/hpke.wrap.diag b/examples/hpke.wrap.diag index 0834323..00c0444 100644 --- a/examples/hpke.wrap.diag +++ b/examples/hpke.wrap.diag @@ -1 +1 @@ -96([h'a10101', {5: 64(h'02aeece48a6acb8283626684aadafec3')}, h'3b12f74131624c529bb81d830d4e6f20d6cdf4e63483cd008c66f6335db308e00705bd45e3f0b47b9c01c3a0150fd09354a5eb18906569cb49044f913a345707bfe555e8c5bd74ba3c2687c49793c349', [[h'a1011823', {4: "meriadoc.brandybuck@buckland.example", -1: {1: 5, -1: h'047dfb4519b37232544da9652c8b30499ed9b3c6aa7a1c64c6e20615518d2c499d79d1e441af2d085dc51d411fb68bf8c4cdefbb56c052c0e01b3535e819978fa9'}}, h'e36a3c29cbe95ec0b638330c16de6d3a76d6256152e2d4a825b30f83da362829']]]) +96([h'a10101', {5: 64(h'25fd0a15840c40c22bbea60842e939ca')}, h'dbf700c25ab0d34d23c9575d210ec8295d22214e35e504aa512919adecc972b42d458d8d5a78bbeb61cc85f597c86b8280b623e994aa463f9c2458e015f06789d2fd94e99afd3f81c332d784ebd31ba8', [[h'a1011823', {4: "meriadoc.brandybuck@buckland.example", -1: {1: 5, -1: h'04501ef446ac3d71870dccf25015ad796be3f5a798a5af12f558f7838c8c5d2da9bef5ae3a48691414ace3c932d18b4657f2daeeb4e25414e8a3d41e9517658fc5'}}, h'438c0d767ad7fb56540b6b5ee3b78158a0e5bc7a4a48668ae62b9ecc7e58f22f']]]) diff --git a/test/hpke.test.ts b/test/hpke.test.ts index ea7b71a..3eac062 100644 --- a/test/hpke.test.ts +++ b/test/hpke.test.ts @@ -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([ + [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([]) + 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": "meriadoc.brandybuck@buckland.example", + "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": "meriadoc.brandybuck@buckland.example", + "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)) }) \ No newline at end of file