{"_id":"@hpke/ml-kem","_rev":"6-64ecc13c5d4844ce3e91ffa22b4ef10c","name":"@hpke/ml-kem","dist-tags":{"latest":"0.3.1"},"versions":{"0.1.0":{"name":"@hpke/ml-kem","version":"0.1.0","keywords":["hpke","ml-kem","kyber","post-quantum","pqc","security","encryption"],"author":{"name":"Ajitomi Daisuke"},"license":"MIT","_id":"@hpke/ml-kem@0.1.0","maintainers":[{"name":"dajiaji","email":"ajitomi@gmail.com"}],"homepage":"https://github.com/dajiaji/hpke-js#readme","bugs":{"url":"https://github.com/dajiaji/hpke-js/issues"},"dist":{"shasum":"27ea0a7bca036be974c063774cce4ce75803bfce","tarball":"https://registry.npmjs.org/@hpke/ml-kem/-/ml-kem-0.1.0.tgz","fileCount":237,"integrity":"sha512-A6YZ7Bz4VclsleJy+6JpbzfVUhY/2K27gp3TAq3fBS9Ql33WM0lzGXoqIJ1xyPcJV51/j31mENiLTADV6byK2A==","signatures":[{"sig":"MEUCIFoOGrGcbYLQTtB+/jGahJGPAUs2UhS8cKEMQSjK+FYFAiEAsPSu8GGH4xQDJgRnO1grKsBMn5FRfDdTLdxUccxRReA=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":152450},"main":"./script/mod.js","types":"./esm/mod.d.ts","module":"./esm/mod.js","engines":{"node":">=16.0.0"},"exports":{".":{"import":"./esm/mod.js","require":"./script/mod.js"},"./package.json":"./package.json"},"gitHead":"9fb6a65a87cae62059e693d5090ff6b44c3e3b98","scripts":{"test":"node test_runner.js"},"_npmUser":{"name":"dajiaji","email":"ajitomi@gmail.com"},"repository":{"url":"git+https://github.com/dajiaji/hpke-js.git","type":"git"},"_npmVersion":"10.8.2","description":"A Hybrid Public Key Encryption (HPKE) module extension for ML-KEM.","directories":{},"sideEffects":false,"_nodeVersion":"20.18.0","dependencies":{"mlkem":"^2.3.0","@hpke/common":"^1.7.1"},"_hasShrinkwrap":false,"devDependencies":{"@hpke/core":"^1.7.1","picocolors":"^1.0.0","@types/node":"^20.9.0","@deno/shim-deno":"~0.18.0"},"_npmOperationalInternal":{"tmp":"tmp/ml-kem_0.1.0_1731297078449_0.44728407256077896","host":"s3://npm-registry-packages"}},"0.1.1":{"name":"@hpke/ml-kem","version":"0.1.1","keywords":["hpke","ml-kem","kyber","post-quantum","pqc","security","encryption"],"author":{"name":"Ajitomi Daisuke"},"license":"MIT","_id":"@hpke/ml-kem@0.1.1","maintainers":[{"name":"dajiaji","email":"ajitomi@gmail.com"}],"homepage":"https://github.com/dajiaji/hpke-js#readme","bugs":{"url":"https://github.com/dajiaji/hpke-js/issues"},"dist":{"shasum":"1704c1522a796878ad33bdaa8fea116b97c9ee21","tarball":"https://registry.npmjs.org/@hpke/ml-kem/-/ml-kem-0.1.1.tgz","fileCount":245,"integrity":"sha512-Q8ynsXkqQ2lQiLnF7X1rf0OVB/G0+SQ/NI85VosALgH4AkbNgRsoX7UWg9Ms1L0mE9mG9Llv5SLDqv1GV+ykkg==","signatures":[{"sig":"MEUCIAgfMKYKO/QMamUYgTqHDNaGJo+LpKxyKKzE3OcG78oiAiEA1c4cHmknmaNc1dmD60dTyGpZmi6NOTOCsW9N1dyDkEw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@hpke%2fml-kem@0.1.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":156210},"main":"./script/mod.js","types":"./esm/mod.d.ts","module":"./esm/mod.js","engines":{"node":">=16.0.0"},"exports":{".":{"import":"./esm/mod.js","require":"./script/mod.js"},"./package.json":"./package.json"},"gitHead":"427f83642b9d2ffd5a9f469d3ffcaf5b28e2376b","scripts":{"test":"node test_runner.js"},"_npmUser":{"name":"dajiaji","email":"ajitomi@gmail.com"},"repository":{"url":"git+https://github.com/dajiaji/hpke-js.git","type":"git"},"_npmVersion":"10.9.2","description":"A Hybrid Public Key Encryption (HPKE) module extension for ML-KEM.","directories":{},"sideEffects":false,"_nodeVersion":"22.17.0","dependencies":{"mlkem":"^2.3.1","@hpke/common":"^1.7.3"},"_hasShrinkwrap":false,"devDependencies":{"@hpke/core":"^1.7.3","picocolors":"^1.0.0","@types/node":"^20.9.0","@deno/shim-deno":"~0.18.0"},"_npmOperationalInternal":{"tmp":"tmp/ml-kem_0.1.1_1752368838392_0.1591230994809265","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@hpke/ml-kem","version":"0.2.0","keywords":["hpke","ml-kem","kyber","post-quantum","pqc","security","encryption"],"author":{"name":"Ajitomi Daisuke"},"license":"MIT","_id":"@hpke/ml-kem@0.2.0","maintainers":[{"name":"dajiaji","email":"ajitomi@gmail.com"}],"homepage":"https://github.com/dajiaji/hpke-js#readme","bugs":{"url":"https://github.com/dajiaji/hpke-js/issues"},"dist":{"shasum":"4c034f7f81c9a5d3d68e77561040373d97f0d886","tarball":"https://registry.npmjs.org/@hpke/ml-kem/-/ml-kem-0.2.0.tgz","fileCount":245,"integrity":"sha512-DNSMhzTjTSjR1egiVTmuwaQgQBUsz9COMA46wQhprAz1BrX8/EZG2WZbdogMX9NWN8JFmzMFFdLvd50RNTFXlg==","signatures":[{"sig":"MEUCIQDCqwundik5xG/7srZUiTxrPFwspSUSQtWAaYkTH7+jBgIgY69MPEtOIaXESm56UVOQfo9TMPmLFF3hU6D0dHvInhY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@hpke%2fml-kem@0.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":156812},"main":"./script/mod.js","types":"./esm/mod.d.ts","module":"./esm/mod.js","engines":{"node":">=16.0.0"},"exports":{".":{"import":"./esm/mod.js","require":"./script/mod.js"},"./package.json":"./package.json"},"gitHead":"90fc36f8439b489f58ae5ae69ccb5dbf2f38335b","scripts":{"test":"node test_runner.js"},"_npmUser":{"name":"dajiaji","email":"ajitomi@gmail.com"},"repository":{"url":"git+https://github.com/dajiaji/hpke-js.git","type":"git"},"_npmVersion":"10.9.3","description":"A Hybrid Public Key Encryption (HPKE) module extension for ML-KEM.","directories":{},"sideEffects":false,"_nodeVersion":"22.18.0","dependencies":{"mlkem":"^2.5.0","@hpke/common":"^1.7.3"},"_hasShrinkwrap":false,"devDependencies":{"@hpke/core":"^1.7.3","picocolors":"^1.0.0","@types/node":"^20.9.0","@deno/shim-deno":"~0.18.0"},"_npmOperationalInternal":{"tmp":"tmp/ml-kem_0.2.0_1754893576624_0.7988930690757277","host":"s3://npm-registry-packages-npm-production"}},"0.2.1":{"name":"@hpke/ml-kem","version":"0.2.1","keywords":["hpke","ml-kem","kyber","post-quantum","pqc","security","encryption"],"author":{"name":"Ajitomi Daisuke"},"license":"MIT","_id":"@hpke/ml-kem@0.2.1","maintainers":[{"name":"dajiaji","email":"ajitomi@gmail.com"}],"homepage":"https://github.com/dajiaji/hpke-js#readme","bugs":{"url":"https://github.com/dajiaji/hpke-js/issues"},"dist":{"shasum":"67d3eb5527628458f01e5b16c05075d1c1689366","tarball":"https://registry.npmjs.org/@hpke/ml-kem/-/ml-kem-0.2.1.tgz","fileCount":17,"integrity":"sha512-9Hmf2fO8W45/h2COdD8+RAaszI2dw9/Id0lwrJD7rEwFbNki7lxb1HyEnqUuHz9ipL2D3q0L6egFKZbhBwj/5A==","signatures":[{"sig":"MEUCIBUr7RBFAZ1bCYahXrMi9P4QOSTDdaziKvvO0Sa9VFLYAiEAhPUdVOnSw0ccS3cMfp2DjVWCkbC4e1L/hcWEOSdpjtY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@hpke%2fml-kem@0.2.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":61246},"main":"./script/mod.js","types":"./esm/mod.d.ts","module":"./esm/mod.js","engines":{"node":">=16.0.0"},"exports":{".":{"import":"./esm/mod.js","require":"./script/mod.js"},"./package.json":"./package.json"},"gitHead":"25bf845c64650f0491f951c0e50f7e739c52ab76","_npmUser":{"name":"dajiaji","email":"ajitomi@gmail.com"},"repository":{"url":"git+https://github.com/dajiaji/hpke-js.git","type":"git"},"_npmVersion":"10.9.3","description":"A Hybrid Public Key Encryption (HPKE) module extension for ML-KEM.","directories":{},"sideEffects":false,"_nodeVersion":"22.18.0","dependencies":{"mlkem":"^2.5.0","@hpke/common":"^1.8.1"},"_hasShrinkwrap":false,"devDependencies":{"@types/node":"^20.9.0"},"_npmOperationalInternal":{"tmp":"tmp/ml-kem_0.2.1_1755253286854_0.837097648670835","host":"s3://npm-registry-packages-npm-production"}},"0.3.0":{"name":"@hpke/ml-kem","version":"0.3.0","keywords":["hpke","ml-kem","kyber","post-quantum","pqc","security","encryption"],"author":{"name":"Ajitomi Daisuke"},"license":"MIT","_id":"@hpke/ml-kem@0.3.0","maintainers":[{"name":"dajiaji","email":"ajitomi@gmail.com"}],"homepage":"https://github.com/dajiaji/hpke-js#readme","bugs":{"url":"https://github.com/dajiaji/hpke-js/issues"},"dist":{"shasum":"d32df2c4bcee4b67d10d49a76059c477daca1bd2","tarball":"https://registry.npmjs.org/@hpke/ml-kem/-/ml-kem-0.3.0.tgz","fileCount":17,"integrity":"sha512-+K0I37CCKOvom/MDiNuUQEOIbkij55yTTbw5o/NKOfBjANt/WeYKMmSOtot6essGmt8/9FJASRSFDkjAWu0eiQ==","signatures":[{"sig":"MEUCIBVpCOApjjgjYH5piq5uUxedhJZ/XaQAv7OHpDsBprXIAiEA02R1q/CIPtzSuWserKZLm3hl2clpwUU78ShaE8HD2W4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@hpke%2fml-kem@0.3.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":62656},"main":"./script/mod.js","types":"./esm/mod.d.ts","module":"./esm/mod.js","engines":{"node":">=16.0.0"},"exports":{".":{"import":"./esm/mod.js","require":"./script/mod.js"},"./package.json":"./package.json"},"gitHead":"f9fbe3d5a6404f516df859e472c078c0d08e8057","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:08b5c416-8061-4c0d-adb9-c3217983b73c"}},"repository":{"url":"git+https://github.com/dajiaji/hpke-js.git","type":"git"},"_npmVersion":"11.9.0","description":"A Hybrid Public Key Encryption (HPKE) module extension for ML-KEM.","directories":{},"sideEffects":false,"_nodeVersion":"24.14.0","dependencies":{"mlkem":"^2.5.0","@hpke/common":"^1.10.0"},"_hasShrinkwrap":false,"devDependencies":{"picocolors":"^1.0.0","@types/node":"^20.9.0","@deno/shim-deno":"~0.18.0"},"_npmOperationalInternal":{"tmp":"tmp/ml-kem_0.3.0_1772979500643_0.6387527104484432","host":"s3://npm-registry-packages-npm-production"}},"0.3.1":{"_id":"@hpke/ml-kem@0.3.1","bugs":{"url":"https://github.com/dajiaji/hpke-js/issues"},"dist":{"shasum":"57f1f7bb546c814a32037e8ec595817332b71aaf","tarball":"https://registry.npmjs.org/@hpke/ml-kem/-/ml-kem-0.3.1.tgz","integrity":"sha512-38R6lF8CxA2PZZ0/qDTvw42Bs1qTysDnn6RlnVStj//lOu94mBnc2gcKgx41DyJyYxthxZdLYUuyqamMvHfDFw==","fileCount":17,"unpackedSize":64177,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@hpke%2fml-kem@0.3.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEMCH1SZ4qSdxXX92OvmUC7Xj2vro7bj3ZrGR97SeumwnugCIAm6xUQ/gsFjwS/xW7/FzmBH2bRBQOmy/ubz/iLLFA4r"}]},"main":"./script/mod.js","name":"@hpke/ml-kem","types":"./esm/mod.d.ts","author":{"name":"Ajitomi Daisuke"},"module":"./esm/mod.js","engines":{"node":">=16.0.0"},"exports":{".":{"import":"./esm/mod.js","require":"./script/mod.js"},"./package.json":"./package.json"},"funding":{"url":"https://github.com/sponsors/dajiaji","type":"github"},"gitHead":"895662abba5afd37e16dcc68f98abb9e3789c96e","license":"MIT","version":"0.3.1","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"08b5c416-8061-4c0d-adb9-c3217983b73c"},"approver":{"name":"dajiaji","email":"ajitomi@gmail.com"}},"homepage":"https://github.com/dajiaji/hpke-js#readme","keywords":["hpke","ml-kem","kyber","post-quantum","pqc","security","encryption"],"repository":{"url":"git+https://github.com/dajiaji/hpke-js.git","type":"git"},"_npmVersion":"11.19.1","description":"A Hybrid Public Key Encryption (HPKE) module extension for ML-KEM.","directories":{},"maintainers":[{"name":"dajiaji","email":"ajitomi@gmail.com"}],"sideEffects":false,"_nodeVersion":"24.22.2","dependencies":{"mlkem":"^2.7.0","@hpke/common":"^1.13.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ml-kem_0.3.1_1794107113787_0.08713926791661053"},"_hasShrinkwrap":false}},"time":{"created":"2024-11-11T03:51:18.316Z","modified":"2026-11-08T03:05:14.200Z","0.1.0":"2024-11-11T03:51:18.634Z","0.1.1":"2025-07-13T01:07:18.582Z","0.2.0":"2025-08-11T06:26:16.799Z","0.2.1":"2025-08-15T10:21:27.153Z","0.3.0":"2026-03-08T14:18:20.792Z","0.3.1":"2026-11-08T03:05:13.894Z"},"bugs":{"url":"https://github.com/dajiaji/hpke-js/issues"},"author":{"name":"Ajitomi Daisuke"},"license":"MIT","homepage":"https://github.com/dajiaji/hpke-js#readme","keywords":["hpke","ml-kem","kyber","post-quantum","pqc","security","encryption"],"repository":{"url":"git+https://github.com/dajiaji/hpke-js.git","type":"git"},"description":"A Hybrid Public Key Encryption (HPKE) module extension for ML-KEM.","maintainers":[{"name":"dajiaji","email":"ajitomi@gmail.com"}],"readme":"<h1 align=\"center\">@hpke/ml-kem</h1>\n\n<div align=\"center\">\n<a href=\"https://www.npmjs.com/package/@hpke/ml-kem\"><img src=\"https://img.shields.io/npm/v/@hpke/ml-kem\" alt=\"npm\"/></a>\n<a href=\"https://jsr.io/@hpke/ml-kem\"><img src=\"https://jsr.io/badges/@hpke/ml-kem\" alt=\"JSR\"/></a>\n</div>\n\n<div align=\"center\">\nA TypeScript <a href=\"https://datatracker.ietf.org/doc/html/rfc9180\">Hybrid Public Key Encryption (HPKE)</a> module extension for <a href=\"https://datatracker.ietf.org/doc/draft-connolly-cfrg-hpke-mlkem/\">ML-KEM for HPKE</a>.\n</div>\n<p></p>\n\n<div align=\"center\">\n\nDocumentation: [jsr.io](https://jsr.io/@hpke/ml-kem/doc) |\n[pages (only for the latest ver.)](https://dajiaji.github.io/hpke-js/ml-kem/docs/)\n\n</div>\n\nAn example of use:\n\n```ts\nimport { Aes256Gcm, CipherSuite, HkdfSha256 } from \"@hpke/core\";\nimport { MlKem768 } from \"@hpke/ml-kem\"; // MlKem512 and MlKem1024 are also available.\n\nasync function doHpke() {\n  const suite = new CipherSuite({\n    kem: new MlKem768(),\n    kdf: new HkdfSha256(),\n    aead: new Aes256Gcm(),\n  });\n\n  // NOTE: The following support for JWKs with the AKP key type is experimental.\n  // Please be aware that the specifications are subject to change without notice.\n  const jwkPub = {\n    kty: \"AKP\",\n    kid: \"01\",\n    alg: \"ML-KEM-768\",\n    pub:\n      \"PxuKXPWqDLFIz6x2ajCnggmjzpfLQnqegTJU4LapmuJTcLWDwnU1fOO01sYKr9oD6Zc04OmOulau74IekrjB20OUKnw3yZd9eZRv4EdN8nuc87EsqUuwZAHQkVBTC_gq38RiO9evl0JZhLjFP1GWnrwC2bQarOeVNuMoKvWt7bY2PUp727BqaeJMiSiI9nEAVbtkTbYLo7iEIEwDsHwqisoCSawp6td9XIeaeQoJuFClXvYUzHPPf3JyI7oNY1MpXACMmGqpIANJoKxQDjR-4XlaGoNpq2FRwnsTQcrOVoUu52xtPMuDMbI83osiSvmy3uQC2WBbv6hAGXZBnFerFoa9oJayjLZUzUpdt8MlmOAUkeIbjNVEl_YP4rwx14OSjjgr-_MzK3VM-WmxKqWPQ4tKVwZBKdRFYAmhcqWas7d8yEx2lEuZpTRFpSmsCmKtSQF0pHMkpdNLgaaCppwKjddfDek8IOQwJmwjsAxIafU8b9CFTtPK9FRJUrBe07Ow1so08PKX8umnwRh4BKN6Ehpq0qtQ2vR1qjol5smg1qKd72LL0pgFD1swfAU6XIg4tMM1fzN2ZTwzZvpv4QJdGWDHW6ZDJlwVeoTJFNVZ9UDGfsFYc5Sve9F4MNUInVBZBvqfdmqbk5CfW2YnzAWgshksv8InGwsi13oHzlUe2qZSLUArAAA3I8EVk2yX9UyIqlE0gqBVVMYo5pRI62oO9vNGNByAK9q5sDugryl9nouTi5yr76RnIkIaM4qHLZqIuIyfDuxGkyw2fMWLg1c9JgNqr1J25RWw8jBZtAyEj2OKzjcD7mwn2WaZDHcC7SOgzZukz2Fppmih8LtYawdmkuHCFXVP9nhL2RokjLkPAIo-ylmFLAV5ZpM6Goa24FsvrZGyi8YWSLBBp6wEargRK2rCy5APtcCYIdxLBxa1CeEi3JfG7XNC9vSftlVZcpw4R2O6LSu4z1auNvOyaZcKxUhBITskt5LJSfPHdecKyPfMU3Y_9jitxRE-xgB1waeSdspHPBE4MpVKviB76_DNBCbA4pczlHJWx3Vr-bUNghkaB_C6XVoVSwhm4pNHO0B2oemV-dCGpHLBGKwiwhaoOZIGYKMx7uGY31saFZUjnVeAzadfc8Z2WkauSqNAAZOd-tkvfhJKXyxiiyWd6VYLv0cMxpzGUtwpuTuoakmQ3OCvGkUkwZmmkmcMr3SNFmEv7tcR-IpQXVUqZECqBCJibxhfaSGoLvklCGAoroVi_HYQ4bFknvAJTZa1Bfu38RKJbvrA0ZKvRdkDrHmSu-m_MOJXfiRYHLxPc7GA0Epp9UCznhmkrjauxPIa3ndJZTkbyuvAr4actjYxMntCG-xnJmUbh1i_7nPFkSEtT_mB9mhMWLNZwtB_oeYB1sXL_clksxkJzKN__5YgT7VojZLKWoV1jPFg6bBu0YMgpLGwyOgZaudqb2IZctF6TWSn3wTFpMMzw7wayqs3cJFJo7jKCCqPvKEyaKGwIiMOLWMCcsuf8uZlWvFzJ_O5gHCV9YK-GL0_Tgu3I-ztabBYVimYZUjXIrA7W70Vesmd7hwKmqE\",\n    key_ops: [],\n  };\n  const pk = await suite.kem.importKey(\"jwk\", jwkPub, true);\n  // In addition to importing keys from external sources, you can also generate keys as follows:\n  //   const rkp = await suite.kem.generateKeyPair();\n  //   const rkp = await suite.kem.deriveKeyPair(random64bytesValue);\n\n  const sender = await suite.createSenderContext({ recipientPublicKey: pk });\n\n  const jwkPriv = {\n    kty: \"AKP\",\n    kid: \"01\",\n    alg: \"ML-KEM-768\",\n    priv:\n      \"1pz8ZPhNTzPkxU4Wa3_5KDo5SYalObI5h6EPOdLZaJtt5i40ZaVcnHigfSZb6FQLPliwgBoSTQf_ErQ41SAuoA\",\n    key_ops: [\"deriveBits\"],\n  };\n  const sk = await suite.kem.importKey(\"jwk\", jwkPriv, false);\n  const recipient = await suite.createRecipientContext({\n    recipientKey: sk,\n    enc: sender.enc,\n  });\n  const encrypted = await sender.seal(\n    new TextEncoder().encode(\"Hellow world!\"),\n  );\n  const pt = await recipient.open(encrypted);\n\n  // Hello world!\n  console.log(new TextDecoder().decode(pt));\n}\n\ntry {\n  doHpke();\n} catch (err: unknown) {\n  console.log(\"failed:\", (err as Error).message);\n}\n```\n\nAuth and AuthPSK require a KEM that supports AuthEncap/AuthDecap. ML-KEM, X-Wing\nand X25519-Kyber768 support only Base and PSK modes; requesting authentication\nwith these KEMs throws `NotSupportedError` (RFC 9180 Section 7.1.5).\n\n## Index\n\n- [Installation](#installation)\n  - [Node.js](#nodejs)\n  - [Deno](#deno)\n  - [Web Browsers](#web-browsers)\n- [Usage](#usage)\n- [Contributing](#contributing)\n\n## Installation\n\n`@hpke/ml-kem` needs to be used with\n[@hpke/core](https://github.com/dajiaji/hpke-js/blob/main/packages/core/README.md),\nwhich can be installed in the same manner as desribed below.\n\n### Node.js\n\nYou can install the package with npm, yarn or pnpm.\n\n```sh\n# Using npm:\nnpm install @hpke/ml-kem\nyarn add @hpke/ml-kem\npnpm install @hpke/ml-kem\n# Using jsr:\nnpx jsr add @hpke/ml-kem\nyarn add jsr:@hpke/ml-kem\npnpm add jsr:@hpke/ml-kem\n```\n\nThe above manner can be used with other JavaScript runtimes that support npm,\nsuch as Cloudflare Workers and Bun.\n\nThen, you can use the module from code like this:\n\n```ts\nimport { Aes256Gcm, CipherSuite, HkdfSha256 } from \"@hpke/core\";\nimport { MlKem768 } from \"@hpke/ml-kem\";\n```\n\n### Deno\n\nFor Deno, it is recommended to use the jsr.io registry.\n\n```sh\ndeno add jsr:@hpke/ml-kem\n```\n\n### Web Browsers\n\nFollowings are how to use this module with typical CDNs. Other CDNs can be used\nas well.\n\nUsing esm.sh:\n\n```html\n<!-- use a specific version -->\n<script type=\"module\">\nimport {\n  Aes256Gcm,\n  CipherSuite,\n  HkdfSha256,\n} from \"https://esm.sh/@hpke/core@<SEMVER>\";\nimport { MlKem768 } from \"https://esm.sh/@hpke/ml-kem@<SEMVER>\";\n// ...\n</script>\n\n<!-- use the latest stable version -->\n<script type=\"module\">\nimport { Aes256Gcm, CipherSuite, HkdfSha256 } from \"https://esm.sh/@hpke/core\";\nimport { MlKem768 } from \"https://esm.sh/@hpke/ml-kem\";\n// ...\n</script>\n```\n\nUsing unpkg:\n\n```html\n<!-- use a specific version -->\n<script type=\"module\">\nimport {\n  Aes256Gcm,\n  CipherSuite,\n  HkdfSha256,\n} from \"https://unpkg.com/@hpke/core@<SEMVER>/esm/mod.js\";\nimport { MlKem768 } from \"https://unpkg.com/@hpke/ml-kem@<SEMVER>/esm/mod.js\";\n// ...\n</script>\n```\n\n## Usage\n\nThis section shows some typical usage examples.\n\n### Node.js\n\n```js\nimport { Aes256Gcm, CipherSuite, HkdfSha256 } from \"@hpke/core\";\nimport { MlKem768 } from \"@hpke/ml-kem\";\n\nasync function doHpke() {\n  // setup\n  const suite = new CipherSuite({\n    kem: new MlKem768(),\n    kdf: new HkdfSha256(),\n    aead: new Aes256Gcm(),\n  });\n\n  const rkp = await suite.kem.generateKeyPair();\n\n  // Note that the `ct` (ciphertext) resulting from ML-KEM::Encaps() is set to `sender.enc`.\n  const sender = await suite.createSenderContext({\n    recipientPublicKey: rkp.publicKey,\n  });\n\n  // encrypt\n  const encrypted = await sender.seal(new TextEncoder().encode(\"Hello world!\"));\n\n  const recipient = await suite.createRecipientContext({\n    recipientKey: rkp.privateKey,\n    enc: sender.enc, // == `ct` (ciphertext) in the context of ML-KEM\n  });\n\n  // decrypt\n  const pt = await recipient.open(encrypted);\n\n  // Hello world!\n  console.log(new TextDecoder().decode(pt));\n}\n\ntry {\n  doHpke();\n} catch (err) {\n  console.log(\"failed:\", err.message);\n}\n```\n\n### Deno\n\n```ts\nimport { Aes256Gcm, CipherSuite, HkdfSha256 } from \"@hpke/core\";\nimport { MlKem768 } from \"@hpke/ml-kem\";\n\nasync function doHpke() {\n  // setup\n  const suite = new CipherSuite({\n    kem: new MlKem768(),\n    kdf: new HkdfSha256(),\n    aead: new Aes256Gcm(),\n  });\n\n  const rkp = await suite.kem.generateKeyPair();\n\n  // Note that the `ct` (ciphertext) resulting from ML-KEM::Encaps() is set to `sender.enc`.\n  const sender = await suite.createSenderContext({\n    recipientPublicKey: rkp.publicKey,\n  });\n\n  // encrypt\n  const encrypted = await sender.seal(new TextEncoder().encode(\"Hello world!\"));\n\n  const recipient = await suite.createRecipientContext({\n    recipientKey: rkp.privateKey,\n    enc: sender.enc, // == `ct` (ciphertext) in the context of ML-KEM\n  });\n\n  // decrypt\n  const pt = await recipient.open(encrypted);\n\n  // Hello world!\n  console.log(new TextDecoder().decode(pt));\n}\n\ntry {\n  doHpke();\n} catch (_err: unknown) {\n  console.log(\"failed.\");\n}\n```\n\n### Web Browsers\n\n```html\n<html>\n  <head></head>\n  <body>\n    <script type=\"module\">\n    import { Aes256Gcm, CipherSuite, HkdfSha256 } from \"https://esm.sh/@hpke/core\";\n    import { MlKem768 } from \"https://esm.sh/@hpke/ml-kem\";\n\n    globalThis.doHpke = async () => {\n      try {\n        const suite = new CipherSuite({\n          kem: new MlKem768(),\n          kdf: new HkdfSha256(),\n          aead: new Aes256Gcm(),\n        });\n\n        const rkp = await suite.kem.generateKeyPair();\n\n        // Note that the `ct` (ciphertext) resulting from ML-KEM::Encaps() is set to `sender.enc`.\n        const sender = await suite.createSenderContext({\n          recipientPublicKey: rkp.publicKey,\n        });\n        // encrypt\n        const encrypted = await sender.seal(\n          new TextEncoder().encode(\"Hello world!\"),\n        );\n\n        const recipient = await suite.createRecipientContext({\n          recipientKey: rkp.privateKey, // rkp (CryptoKeyPair) is also acceptable.\n          enc: sender.enc, // == `ct` (ciphertext) in the context of ML-KEM\n        });\n\n        // decrypt\n        const pt = await recipient.open(encrypted);\n\n        // Hello world!\n        alert(new TextDecoder().decode(pt));\n      } catch (err) {\n        alert(\"failed:\", err.message);\n      }\n    };\n    </script>\n    <button type=\"button\" onclick=\"doHpke()\">do HPKE</button>\n  </body>\n</html>\n```\n\n## Contributing\n\nWe welcome all kind of contributions, filing issues, suggesting new features or\nsending PRs.\n","readmeFilename":"README.md"}