npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ml-kem.netcore.browser

v0.1.0

Published

Pure JavaScript browser companion package for ML-KEM.NetCore (ML-KEM-768).

Downloads

94

Readme

ML-KEM.NetCore.Browser

License: MIT npm nuget

ML-KEM.NetCore.Browser is a pure JavaScript companion package to ML-KEM.NetCore, focused on ML-KEM-768 compatibility in browser and Node.js runtimes.

The package includes high-level KEM APIs (generateKeyPair, encapsulate, decapsulate) and lower-level modules for polynomial math, packing, NTT, and CPA-PKE internals.


Table of contents


Requirements

  • Runtime: modern browser or Node.js with ES modules.
  • No native addons required.
  • Project package type: "module".

Installation

npm

npm install ml-kem.netcore.browser

NuGet

dotnet add package ML-KEM.NetCore.Browser

Browser script bundle

Build the one-file bundle:

npm run build:bundle

Then include it in your page:

<script src="./dist/ML-KEM.NetCore.Browser.js"></script>
<script>
  const { generateKeyPair, encapsulate, decapsulate } = window.MLKEMNetCoreBrowser;
</script>

Quick start

ESM usage

import { generateKeyPair, encapsulate, decapsulate } from 'ml-kem.netcore.browser';

const { publicKey, secretKey } = await generateKeyPair();
const { ciphertext, sharedSecret: senderSecret } = await encapsulate(publicKey);
const { sharedSecret: receiverSecret } = await decapsulate(secretKey, ciphertext);

console.log(senderSecret.length, receiverSecret.length); // 32, 32

Browser global usage

<script src="./dist/ML-KEM.NetCore.Browser.js"></script>
<script>
  (async () => {
    const { generateKeyPair, encapsulate, decapsulate } = window.MLKEMNetCoreBrowser;

    const { publicKey, secretKey } = await generateKeyPair();
    const { ciphertext, sharedSecret: senderSecret } = await encapsulate(publicKey);
    const { sharedSecret: receiverSecret } = await decapsulate(secretKey, ciphertext);

    console.log(senderSecret, receiverSecret);
  })();
</script>

API reference

All binary values are Uint8Array.

generateKeyPair(seed64?)

async function generateKeyPair(seed64?: Uint8Array): Promise<{
  publicKey: Uint8Array;
  secretKey: Uint8Array;
}>;
  • Without seed64, key generation uses the configured random source.
  • With seed64, deterministic derivation is used (intended for vectors/tests).

encapsulate(publicKey, seed32?)

async function encapsulate(publicKey: Uint8Array, seed32?: Uint8Array): Promise<{
  ciphertext: Uint8Array;
  sharedSecret: Uint8Array;
}>;
  • publicKey must be a Uint8Array with ML-KEM-768 public key length.
  • Optional seed32 enables deterministic encapsulation for vector scenarios.

decapsulate(secretKey, ciphertext)

async function decapsulate(secretKey: Uint8Array, ciphertext: Uint8Array): Promise<{
  sharedSecret: Uint8Array;
}>;
  • Both arguments must be Uint8Array values.
  • Returns the receiver shared secret.

setRandomBytesProvider(provider)

function setRandomBytesProvider(provider: (length: number) => Uint8Array): void;
  • Overrides random byte generation used internally.
  • Useful for deterministic testing harnesses and controlled environments.

MLKEM_768 parameter sizes

const MLKEM_768 = {
  publicKeyBytes: 1184,
  secretKeyBytes: 2400,
  ciphertextBytes: 1088,
  sharedSecretBytes: 32,
  // ...other structural parameters
};

Import from:

import { MLKEM_768 } from 'ml-kem.netcore.browser';
// or: import { MLKEM_768 } from 'ml-kem.netcore.browser/params';

Deterministic/vector workflows

This package supports deterministic pathways used for fixture generation and cross-language verification:

  • generateKeyPair(seed64) for deterministic key derivation.
  • encapsulate(publicKey, seed32) for deterministic encapsulation.

Reference fixture:

  • test/vectors/mlkem768-fixture.json

Validation and testing

Run the test suite:

npm test

Dry-run publish contents:

npm run pack:check

Tests include:

  • ML-KEM round-trip behavior
  • CPA-PKE layer checks
  • Cross-language deterministic vector validation

Development

Build browser bundle

npm run build:bundle

Main implementation modules

  • High-level API:
    • src/index.js
    • src/mlkem.js
  • Core primitives:
    • src/params.js
    • src/random.js
    • src/sha3.js
    • src/shake.js
    • src/keccak-f1600.js
    • src/sponge.js
    • src/utils.js
    • src/modq.js
    • src/poly.js
    • src/polyvec.js
    • src/ntt.js
    • src/packing.js
    • src/cpapke.js
  • Vendored core:
    • src/vendor/mlkem/*

Interoperability notes

  • This package is intended to maintain byte-level interoperability with ML-KEM.NetCore for ML-KEM-768 workflows.
  • Keep parameter set and serialized sizes aligned between communicating peers.
  • Prefer deterministic methods only for test vectors and reproducibility.

Security notes

  • Treat secret material (secretKey, sharedSecret) as sensitive and keep lifetimes short.
  • Clear transient buffers in application code when possible.
  • Validate all external key/ciphertext lengths before calling KEM operations.
  • For high-assurance use, perform an independent cryptographic and implementation review.

License

MIT. See LICENSE.