TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ecies/js-post-quantum/llms.txt
Use this file to discover all available pages before exploring further.
@ecies/post-quantum library exposes a Config class that controls every tunable aspect of the encryption pipeline — which ML-KEM variant to use for key encapsulation, which AEAD cipher to use for payload encryption, and (for AES-256-GCM) how long the random nonce should be. Sensible defaults are provided out of the box through the exported DEFAULT_CONFIG singleton so that most applications need zero configuration to get started.
Type definitions
The three exported types and their defaults are:DEFAULT_CONFIG is a module-level singleton created once at import time. It is ready to use immediately and reflects the NIST-recommended defaults.
Asymmetric algorithm
TheasymmetricAlgorithm field selects which ML-KEM variant handles key encapsulation. All three variants are standardised in NIST FIPS 203 and resist quantum attacks, but they differ in ciphertext size and security level.
| Variant | PKE Ciphertext Size | Security Level | Notes |
|---|---|---|---|
ml-kem-512 | 768 bytes | Level 1 (≈ AES-128) | Fastest, smallest overhead |
ml-kem-768 | 1088 bytes | Level 3 (≈ AES-192) | NIST recommended default |
ml-kem-1024 | 1568 bytes | Level 5 (≈ AES-256) | Highest security margin |
Config instance and set asymmetricAlgorithm before calling encrypt or decrypt:
config.asymmetricModule getter returns the correct @noble/post-quantum module (ml_kem512, ml_kem768, or ml_kem1024) for the selected variant, so key generation automatically produces the right key sizes.
Symmetric cipher
ThesymmetricAlgorithm field selects the AEAD cipher used to encrypt the actual payload. Both options provide authenticated encryption — confidentiality plus integrity.
AES-256-GCM ("aes-256-gcm", default) is the standard choice for environments with hardware AES acceleration (AES-NI). Most modern desktop and server CPUs support AES-NI, making this the fastest option in those contexts. The symmetricNonceLength field applies only to this cipher.
XChaCha20-Poly1305 ("xchacha20") is a constant-time stream cipher that does not rely on hardware acceleration. It is the better choice for low-end, embedded, or mobile devices that lack AES-NI, and for applications where timing-side-channel resistance is a priority. Its nonce is always 24 bytes and is not configurable.
To switch to XChaCha20-Poly1305:
Nonce length (AES-256-GCM only)
When using AES-256-GCM, you can choose between a 12-byte and a 16-byte random nonce:symmetricNonceLength is ignored when symmetricAlgorithm is "xchacha20". XChaCha20-Poly1305 always uses a 24-byte nonce, which is large enough that random nonce collision is effectively impossible.Using DEFAULT_CONFIG safely
DEFAULT_CONFIG is a shared singleton. Mutating it directly changes the configuration for every subsequent encrypt and decrypt call in the same process — including those made by other modules that imported the same singleton.
Config() instance: