$ npm install @xrplf/mpt-crypto
Cryptographic primitives for Confidential MPT (XLS-0096) on the XRP Ledger, exposed as a small hex-in / hex-out TypeScript API over a vendored WebAssembly build of the reference C crypto library.
This package ships as a dependency of xrpl, but it is lazily loaded: the
xrpl/confidential builders reach it through a
dynamic import, so bundlers code-split its ~2 MB WASM into a separate chunk and
apps that never assemble a Confidential MPT transaction never load it. You
typically interact with those builders rather than calling this package directly.
Confidential MPT replaces a public MPT balance with EC-ElGamal ciphertexts on-ledger and uses zero-knowledge proofs so validators can verify transfers (no overdraft, amounts conserved) without seeing the amounts. This package exposes the building blocks:
encryptAmount, decryptAmount (EC-ElGamal over secp256k1).getPedersenCommitment, generateBlindingFactor.getConvertContextHash, getConvertBackContextHash,
getSendContextHash, getClawbackContextHash. Each binds a proof to a
specific transaction (account, issuance, sequence, …).getConvertProof, getConvertBackProof,
getConfidentialSendProof, getClawbackProof.PUBKEY_SIZE, ELGAMAL_TOTAL_SIZE, the
per-transaction proof sizes, …) and the bytesToHex / hexToBytes helpers.0x prefix (matching the rest of xrpl.js).bigint, to losslessly carry the full uint64_t
range.ripple-keypairs
(deriveKeypair(generateSeed({ algorithm: 'ecdsa-secp256k1' }))).import {
encryptAmount,
decryptAmount,
generateBlindingFactor,
} from '@xrplf/mpt-crypto'
const blinding = await generateBlindingFactor()
const ciphertext = await encryptAmount(1000n, publicKey, blinding)
// `rangeHigh` bounds the discrete-log search; decryption recovers any amount in
// [0, rangeHigh]. Pass the tightest correct bound you know (e.g. the issuance's
// outstanding confidential amount) — cost scales with it.
const amount = await decryptAmount(ciphertext, privateKey, 10_000n) // 1000n
wasm/mpt_crypto.{js,mjs,wasm} is an Emscripten build of the reference
mpt-crypto C library (XRPLF/mpt-crypto),
the same library rippled links. A single .wasm is wrapped by three glues built
from it — mpt_crypto.js (CommonJS, for Node / require), mpt_crypto.mjs (ES
module, for Node / import), and mpt_crypto.web.mjs (ES module with no node:
imports, for bundlers / browsers) — so the module loads in every environment.
The exact mpt-crypto release these are built from is pinned in
MPT_CRYPTO_VERSION. The npm release pipeline downloads
that release's WASM bundle and vendors it into wasm/ before publishing (via
scripts/fetch-wasm.sh), so the published package
always carries the exact WASM for the pinned tag — never fetched at the
consumer's install time.
The pinned version must stay in lockstep with the mpt-crypto version that
rippled pins — a mismatch produces valid-looking transactions that rippled
rejects with tecBAD_PROOF. To update:
rippled pins in its conanfile.py (e.g. mpt-crypto/1.0.2).MPT_CRYPTO_VERSION.npm run fetch:wasm to vendor the matching WASM locally (the release
pipeline does the same automatically).fetch-wasm.sh verifies the bundle's SHA256SUMS manifest when the release
ships one; integrity of the published npm package is further covered by the npm
package hash.
© 2010 - cnpmjs.org x YWFE | Home | YWFE