-
Notifications
You must be signed in to change notification settings - Fork 1
Home
██ ▐█████ ██ ▐█▌ ▄█▌ ███▌ ▀███████▀▄██▌ ▐█▌ ███▌ ██▌ ▓▓
▐█▌ ▐█▌ ▓█ ▐█▌ ▓██ ▐█▌██ ▐█▌ ███ ██▌ ▐█▌██ ▓██ ██
██▌ ░███ ▐█▌ ██ ▀▀ ██ ▐█▌ ██ ▐██▌ █▓ ▓█ ▐█▌ ▐███▌ █▓
██ ██ ▐█▌ █▓ ▐██ ▐█▌ █▓ ██ ▐██▄▄ ▐█▌ ▐█▌ ██ ▐█▌██ ▐█▌
▐█▌ ▐█▌ ██ ▐█▌ ██ ██ ██ ▐█▌ ██▀▀████▌ ██ ██ ██ ▐█▌▐█▌
▐▒▌ ▐▒▌ ▐▒▌ ██ ▒█ ██▀▀▀██▌ ▐▒▌ ▒█ █▓░ ▒█▀▀▀██▌ ▒█ ██▐█
█▓ ▄▄▓█ █▓ ▄▄▓█ ▓▓ ▐▓▌ ▐▓▌ ▐█▌ ▐▒▌ █▓ ▐▓▌ ▐▓█ ▐▓▌ ▐▒▌▐▓▌ ▐███
▓██▀▀ ▓██▀▀ ▓█▓█ ▐█▌ ▐█▌ ▐▓▌ ▓█ ▐█▌ ▐█▓ ▐█▌ ▐▓▌▐█▌ ██▓
▓█ ▀▀ ▐█▌▌▌
Note
A zero-dependency WebAssembly cryptography library. Two ciphers, opposite philosophies, same security properties.
bun add leviathan-crypto
# or
npm install leviathan-cryptoNo bundler is required. See CDN usage.
Seal, SealStream,
OpenStream, and SealStreamPool
are the primary API for authenticated encryption in leviathan-crypto.
They are cipher-agnostic: you pass a CipherSuite object
at construction and the implementation handles key derivation, nonce
management, and authentication for you.
The classes form a natural progression:
- Seal handles data that fits in memory (>~66k).
- SealStream and OpenStream handle data that arrives in chunks or is too large to buffer.
- SealStreamPool parallelizes the chunked approach across Web Workers.
All four produce and consume the same wire format, so a Seal blob can be opened by OpenStream and vice versa.
| I want to... | |
|---|---|
| Encrypt data |
Seal with SerpentCipher or XChaCha20Cipher
|
| Encrypt a stream or large file |
SealStream to encrypt, OpenStream to decrypt |
| Encrypt in parallel |
SealStreamPool distributes chunks across Web Workers |
| Add post-quantum security |
KyberSuite wraps MlKem512, MlKem768, or MlKem1024 with any cipher suite |
| Hash data |
SHA256, SHA384, SHA512, SHA3_256, SHA3_512, SHAKE256 ... |
| Authenticate a message |
HMAC_SHA256, HMAC_SHA384, or HMAC_SHA512
|
| Derive keys |
HKDF_SHA256 or HKDF_SHA512
|
| Generate random bytes |
Fortuna for forward-secret generation, randomBytes for one-off use |
| Compare secrets safely |
constantTimeEqual uses a WASM SIMD path to prevent timing attacks |
| Work with bytes |
hexToBytes, bytesToHex, wipe, xor, concat ... |
For raw primitives, low-level cipher access, and ASM internals see the full API reference.
Tip
New to crypto? We have a lot of technical jargon. Checkout the lexicon if you need a glossary of cryptographic terminology.
We maintain demo applications for the library at https://github.com/xero/leviathan-demos
web [ demo · source · readme ]
A self-contained browser encryption tool in a single HTML file. Encrypt text or files with Serpent-256-CBC and Argon2id key derivation, then share the armored output. No server, no install, no network connection after initial load. The code is written to be read. The Encrypt-then-MAC construction, HMAC input, and Argon2id parameters are all intentional examples worth studying.
chat [ demo · source · readme ]
End-to-end encrypted chat over X25519 key exchange and XChaCha20-Poly1305 message encryption. The relay server is a dumb WebSocket pipe that never sees plaintext. Messages carry sequence numbers so the protocol detects and rejects replayed messages. The demo deconstructs the protocol step by step with visual feedback for injection and replay attacks.
Command-line file encryption tool supporting both Serpent-256 and
XChaCha20-Poly1305 via --cipher. A single keyfile works with both ciphers.
The header byte determines decryption automatically. Chunks distribute across a
worker pool sized to hardwareConcurrency. Each worker owns an isolated WASM
instance with no shared memory. The tool can export it's own interactive
competitions for a variety of shells.
bun add -g lvthn # or npm i -g lvthn
lvthn keygen --armor -o my.key
cat secret.txt | lvthn encrypt -k my.key --armor > secret.enckyber [ demo · source · readme ]
Post-quantum cryptography demo simulating a complete ML-KEM key encapsulation ceremony between two browser-side clients. A live wire at the top of the page logs every value that crosses the channel; importantly, the shared secret never appears in the wire. After the ceremony completes, both sides independently derive a symmetric key using HKDF-SHA256 and exchange messages encrypted with XChaCha20-Poly1305. Each wire frame is expandable, revealing the raw nonce, ciphertext, Poly1305 tag, and AAD.
- Serpent-256 TypeScript | WASM
-
Serpent,SerpentCtr,SerpentCbc
-
- ChaCha20 TypeScript | WASM
-
ChaCha20,Poly1305,ChaCha20Poly1305,XChaCha20Poly1305
-
- ML-KEM TypeScript
-
MlKem512,MlKem768,MlKem1024
-
- SHA-2 TypeScript | WASM
-
SHA256,SHA512,SHA384,HMAC_SHA256,HMAC_SHA512,HMAC_SHA384,HKDF_SHA256,HKDF_SHA512
-
- SHA-3 TypeScript | WASM
-
SHA3_224,SHA3_256,SHA3_384,SHA3_512,SHAKE128,SHAKE256
-
- Fortuna CSPRNG
-
Utils
-
randomBytes,constantTimeEqual,wipe, encoding helpers
-
-
TypeScript interfaces
-
Hash,KeyedHash,Blockcipher,Streamcipher,AEAD
-