{"id":16199787,"url":"https://github.com/or13/draft-jose-hpke-test-vectors","last_synced_at":"2025-04-07T17:46:10.613Z","repository":{"id":218601001,"uuid":"746866331","full_name":"OR13/draft-jose-hpke-test-vectors","owner":"OR13","description":null,"archived":false,"fork":false,"pushed_at":"2024-02-12T14:46:31.000Z","size":149,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-13T19:49:32.662Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OR13.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-01-22T20:34:41.000Z","updated_at":"2024-02-16T23:33:26.000Z","dependencies_parsed_at":"2024-01-28T17:50:29.543Z","dependency_job_id":null,"html_url":"https://github.com/OR13/draft-jose-hpke-test-vectors","commit_stats":null,"previous_names":["or13/draft-jose-hpke-test-vectors"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OR13%2Fdraft-jose-hpke-test-vectors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OR13%2Fdraft-jose-hpke-test-vectors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OR13%2Fdraft-jose-hpke-test-vectors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OR13%2Fdraft-jose-hpke-test-vectors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OR13","download_url":"https://codeload.github.com/OR13/draft-jose-hpke-test-vectors/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247703385,"owners_count":20982282,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T09:28:12.748Z","updated_at":"2025-04-07T17:46:10.586Z","avatar_url":"https://github.com/OR13.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JOSE HPKE Test Vectors\n\n[![CI](https://github.com/OR13/draft-jose-hpke-test-vectors/actions/workflows/ci.yml/badge.svg)](https://github.com/OR13/draft-jose-hpke-test-vectors/actions/workflows/ci.yml)\n![Branches](./badges/coverage-branches.svg)\n![Functions](./badges/coverage-functions.svg)\n![Lines](./badges/coverage-lines.svg)\n![Statements](./badges/coverage-statements.svg)\n![Jest coverage](./badges/coverage-jest%20coverage.svg)\n\n\n🚧 Experimental 🔥\n\n--\u003e [draft-rha-jose-hpke-encrypt](https://datatracker.ietf.org/doc/draft-rha-jose-hpke-encrypt/)\n\n## Compact\n\n```ts\n\nimport * as hpke from '../src'\n\nit('encrypt / decrypt', async () =\u003e {\n  const privateKeyJwk = await hpke.keys.generate('HPKE-Base-P256-SHA256-AES128GCM')\n  // {\n  //   kid: 'urn:ietf:params:oauth:jwk-thumbprint:sha-256:om1gRRYAiZ3CRMlvnSizjYzaX-t94m96A5DWzM78lm0',\n  //   alg: 'HPKE-Base-P256-SHA256-AES128GCM',\n  //   kty: 'EC',\n  //   crv: 'P-256',\n  //   x: 'UQoMdtvzzboEH-Jj41mfnw7FT6HdJhemsP7R5SJRDcM',\n  //   y: 'I4TQnPtVyFwKz_G8DLcAPvx1QwHCIjlWw6_WOB6tLDo',\n  //   d: 'lhDRw6qmjx1cX-1X2P3oljMPTlvS-wsosdGejGbxMss'\n  // }\n  const publicKeyJwk = await hpke.keys.publicFromPrivate(privateKeyJwk)\n  // {\n  //   kid: 'urn:ietf:params:oauth:jwk-thumbprint:sha-256:zLL3uvca9qDXqK1UysySHW720kcKVcEqOf7KBIVZg6Q',\n  //   alg: 'HPKE-Base-P256-SHA256-AES128GCM',\n  //   kty: 'EC',\n  //   crv: 'P-256',\n  //   x: 'W-70J8fA-XcYE3PiSIy_wNz-TQ_-j_QrOGLAo30YuN0',\n  //   y: 'v6DySTYHurdTKwNa-AN7LwHSh-jN9x4a3uO1r38b1EI'\n  // }\n  const message = `It’s a 💀 dangerous business 💀, Frodo, going out your door.`\n  const plaintext = new TextEncoder().encode(message);\n  const ciphertext = await hpke.compact.encrypt(plaintext, publicKeyJwk)\n  // eyJhbGciOiJIUEtFLUJhc2UtUDI1Ni1TSEEyNTYtQUVTMTI4R0NNIn0.BKYjy3VbemjsKyEPg6_LJpKHcSsu4igA5O2zaejWI16RbM9_uA3xjBskT3KfzJ5IPdBa5m68o93TYfY1QBeQ0EA.._4eoNOUDKEpiInbI5Bix-KIOMXIpP6vKDlGZ9f8lrN6db4Nvqis1vxvnNmgQEOTPLS81DPlHVV184q6RHGmWzn6gILTFCOu-zYKesdazqIf3tA.\n  const recovered = await hpke.compact.decrypt(ciphertext, privateKeyJwk)\n  expect(new TextDecoder().decode(recovered)).toBe(message);\n```\n\n## JSON\n\n```ts\n\nimport * as hpke from '../src'\n\nit('encrypt / decrypt', async () =\u003e {\n  // recipient 1\n  const privateKey1 = await hpke.keys.generate('HPKE-Base-P256-SHA256-AES128GCM')\n  const publicKey1 = await hpke.keys.publicFromPrivate(privateKey1)\n\n  // recipient 2\n  const privateKey2 = await hpke.keys.generate('HPKE-Base-P256-SHA256-AES128GCM')\n  privateKey2.alg = 'ECDH-ES+A128KW' // overwrite algorithm\n  const publicKey2 = await hpke.keys.publicFromPrivate(privateKey2)\n\n  const resolvePrivateKey = (kid: string): any =\u003e {\n    if (kid === publicKey1.kid){\n      return privateKey1\n    }\n    if (kid === publicKey2.kid){\n      return privateKey2\n    }\n    throw new Error('Unknown kid')\n  }\n\n  // recipients as a JWKS\n  const recipientPublicKeys = {\n    \"keys\" : [\n      publicKey1,\n      publicKey2\n    ]\n  }\n  \n  const ciphertext = await hpke.json.encrypt({\n    protectedHeader: { enc: 'A128GCM' },\n    plaintext: new TextEncoder().encode(`It’s a 💀 dangerous business 💀, Frodo, going out your door.`),\n    additionalAuthenticatedData: new TextEncoder().encode('💀 aad'),\n    recipients: recipientPublicKeys\n  });\n  // {\n  //   \"protected\": \"eyJlbmMiOiJBMTI4R0NNIn0\",\n  //   \"ciphertext\": \"t7XOvW1SZgf-3fz7ZNSDiEEUKRdI9MdblC-8wLysN49ov0erROQDieZ-EFn0QnDFZw5RcGPMLWvO8ZkHfOsgzSld\",\n  //   \"iv\": \"Sl0fLuINvzicEgzQ\",\n  //   \"aad\": \"8J-SgCBhYWQ\",\n  //   \"tag\": \"xy3xYOfBM5ObzNXdeppkyw\",\n  //   \"recipients\": [\n  //     {\n  //       \"encrypted_key\": \"tURMb3-zPMhHoHZUGlnVUyQhscrpQenjrRKorM2DoDo\",\n  //       \"header\": {\n  //         \"kid\": \"urn:ietf:params:oauth:jwk-thumbprint:sha-256:RLaSa8XtodlM3fLoS7IGBL21lgXOP-nVg7obhAf8AVs\",\n  //         \"alg\": \"HPKE-Base-P256-SHA256-AES128GCM\",\n  //         \"encapsulated_key\": \"BESPDLvUeBwkSsQhrZpY4lS-fFE_3LcQCh8TuUsphvrSd1oapl6SNg-Hs0poV8rn-KCbyWGuY6IAABpRlNUiH3g\"\n  //       }\n  //     },\n  //     {\n  //       \"encrypted_key\": \"zuVnoUXttYnMW9FtxXPkSD_rF__Udixs\",\n  //       \"header\": {\n  //         \"kid\": \"urn:ietf:params:oauth:jwk-thumbprint:sha-256:2M7TcrbAuR5riiLzxwWN_NR6Js8fMFtu-tVLakgqoAo\",\n  //         \"alg\": \"ECDH-ES+A128KW\",\n  //         \"epk\": {\n  //           \"kty\": \"EC\",\n  //           \"crv\": \"P-256\",\n  //           \"x\": \"H5jZ_QhKH8XfqvKT6lqWO0yGSMLA8VukIDmdHzQnca4\",\n  //           \"y\": \"BmWr4pxMoQI_BJaachjhP_YfMKXNmStHiQGkKFDXdaE\"\n  //         }\n  //       }\n  //     }\n  //   ]\n  // }\n  for (const recipient of recipientPublicKeys.keys){\n    const privateKey = resolvePrivateKey(recipient.kid)\n    // simulate having only one of the recipient private keys\n    const recipientPrivateKeys =  { \"keys\": [ privateKey ] }\n    const decryption = await hpke.json.decrypt({ jwe: ciphertext, privateKeys: recipientPrivateKeys})\n    expect(new TextDecoder().decode(decryption.plaintext)).toBe(`It’s a 💀 dangerous business 💀, Frodo, going out your door.`);\n    expect(new TextDecoder().decode(decryption.aad)).toBe('💀 aad');\n  }\n})\n```\n\n## Develop\n\n```bash\nnvm use 18\n# Now using node v18.17.0 (npm v9.6.7)\nnpm i\nnpm t\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2For13%2Fdraft-jose-hpke-test-vectors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2For13%2Fdraft-jose-hpke-test-vectors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2For13%2Fdraft-jose-hpke-test-vectors/lists"}