{"name":"@noble/curves","version":"1.9.7","keywords":["elliptic","curve","cryptography","secp256k1","ed25519","p256","p384","p521","secp256r1","ed448","x25519","ed25519","bls12-381","bn254","alt_bn128","bls","noble","ecc","ecdsa","eddsa","weierstrass","montgomery","edwards","schnorr","fft"],"author":{"url":"https://paulmillr.com","name":"Paul Miller"},"license":"MIT","_id":"@noble/curves@1.9.7","maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"homepage":"https://paulmillr.com/noble/","bugs":{"url":"https://github.com/paulmillr/noble-curves/issues"},"dist":{"shasum":"79d04b4758a43e4bca2cbdc62e7771352fa6b951","tarball":"http://registry-npm.ywwl.com/@noble/curves/download/@noble/curves-1.9.7.tgz","fileCount":239,"integrity":"sha512-gbKGcRUYIjA3/zCCNaWDciTMFI0dCkvou3TL8Zmy5Nc7sJ47a0jtOeZoTaMxkuqRo9cRhjOdZJXegxYE5FN/xw==","signatures":[{"sig":"MEUCIEpRdYGl7ChAEWbxHQWJcP6RL7UkU6XU9LK328zQNxYtAiEA8rKl27SvfY0MtFzcZxDpPjV4pqk2NAetkNNxSX0jAm8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@noble%2fcurves@1.9.7","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":2059987,"size":362302,"noattachment":false,"key":"/@noble/curves/-/@noble/curves-1.9.7.tgz"},"main":"index.js","types":"./index.d.ts","engines":{"node":"^14.21.3 || >=16"},"exports":{".":{"import":"./esm/index.js","require":"./index.js"},"./misc":{"import":"./esm/misc.js","require":"./misc.js"},"./nist":{"import":"./esm/nist.js","require":"./nist.js"},"./p256":{"import":"./esm/p256.js","require":"./p256.js"},"./p384":{"import":"./esm/p384.js","require":"./p384.js"},"./p521":{"import":"./esm/p521.js","require":"./p521.js"},"./bn254":{"import":"./esm/bn254.js","require":"./bn254.js"},"./ed448":{"import":"./esm/ed448.js","require":"./ed448.js"},"./index":{"import":"./esm/index.js","require":"./index.js"},"./pasta":{"import":"./esm/pasta.js","require":"./pasta.js"},"./utils":{"import":"./esm/utils.js","require":"./utils.js"},"./jubjub":{"import":"./esm/jubjub.js","require":"./jubjub.js"},"./ed25519":{"import":"./esm/ed25519.js","require":"./ed25519.js"},"./misc.js":{"import":"./esm/misc.js","require":"./misc.js"},"./nist.js":{"import":"./esm/nist.js","require":"./nist.js"},"./p256.js":{"import":"./esm/p256.js","require":"./p256.js"},"./p384.js":{"import":"./esm/p384.js","require":"./p384.js"},"./p521.js":{"import":"./esm/p521.js","require":"./p521.js"},"./bn254.js":{"import":"./esm/bn254.js","require":"./bn254.js"},"./ed448.js":{"import":"./esm/ed448.js","require":"./ed448.js"},"./index.js":{"import":"./esm/index.js","require":"./index.js"},"./pasta.js":{"import":"./esm/pasta.js","require":"./pasta.js"},"./utils.js":{"import":"./esm/utils.js","require":"./utils.js"},"./bls12-381":{"import":"./esm/bls12-381.js","require":"./bls12-381.js"},"./jubjub.js":{"import":"./esm/jubjub.js","require":"./jubjub.js"},"./secp256k1":{"import":"./esm/secp256k1.js","require":"./secp256k1.js"},"./ed25519.js":{"import":"./esm/ed25519.js","require":"./ed25519.js"},"./abstract/bls":{"import":"./esm/abstract/bls.js","require":"./abstract/bls.js"},"./abstract/fft":{"import":"./esm/abstract/fft.js","require":"./abstract/fft.js"},"./bls12-381.js":{"import":"./esm/bls12-381.js","require":"./bls12-381.js"},"./secp256k1.js":{"import":"./esm/secp256k1.js","require":"./secp256k1.js"},"./_shortw_utils":{"import":"./esm/_shortw_utils.js","require":"./_shortw_utils.js"},"./abstract/curve":{"import":"./esm/abstract/curve.js","require":"./abstract/curve.js"},"./abstract/tower":{"import":"./esm/abstract/tower.js","require":"./abstract/tower.js"},"./abstract/utils":{"import":"./esm/abstract/utils.js","require":"./abstract/utils.js"},"./abstract/bls.js":{"import":"./esm/abstract/bls.js","require":"./abstract/bls.js"},"./abstract/fft.js":{"import":"./esm/abstract/fft.js","require":"./abstract/fft.js"},"./_shortw_utils.js":{"import":"./esm/_shortw_utils.js","require":"./_shortw_utils.js"},"./abstract/edwards":{"import":"./esm/abstract/edwards.js","require":"./abstract/edwards.js"},"./abstract/modular":{"import":"./esm/abstract/modular.js","require":"./abstract/modular.js"},"./abstract/curve.js":{"import":"./esm/abstract/curve.js","require":"./abstract/curve.js"},"./abstract/poseidon":{"import":"./esm/abstract/poseidon.js","require":"./abstract/poseidon.js"},"./abstract/tower.js":{"import":"./esm/abstract/tower.js","require":"./abstract/tower.js"},"./abstract/utils.js":{"import":"./esm/abstract/utils.js","require":"./abstract/utils.js"},"./abstract/edwards.js":{"import":"./esm/abstract/edwards.js","require":"./abstract/edwards.js"},"./abstract/modular.js":{"import":"./esm/abstract/modular.js","require":"./abstract/modular.js"},"./abstract/montgomery":{"import":"./esm/abstract/montgomery.js","require":"./abstract/montgomery.js"},"./abstract/poseidon.js":{"import":"./esm/abstract/poseidon.js","require":"./abstract/poseidon.js"},"./abstract/weierstrass":{"import":"./esm/abstract/weierstrass.js","require":"./abstract/weierstrass.js"},"./abstract/hash-to-curve":{"import":"./esm/abstract/hash-to-curve.js","require":"./abstract/hash-to-curve.js"},"./abstract/montgomery.js":{"import":"./esm/abstract/montgomery.js","require":"./abstract/montgomery.js"},"./abstract/weierstrass.js":{"import":"./esm/abstract/weierstrass.js","require":"./abstract/weierstrass.js"},"./abstract/hash-to-curve.js":{"import":"./esm/abstract/hash-to-curve.js","require":"./abstract/hash-to-curve.js"}},"funding":"https://paulmillr.com/funding/","gitHead":"a0ac59846ee76c52f7c18886f4963e1211345d48","scripts":{"lint":"prettier --check 'src/**/*.{js,ts}' 'test/*.js'","test":"node --disable-warning=ExperimentalWarning test/index.js","bench":"npm run bench:install; cd test/benchmark; node secp256k1.js; node curves.js; node utils.js; node bls.js","build":"tsc && tsc -p tsconfig.cjs.json","format":"prettier --write 'src/**/*.{js,ts}' 'test/*.js'","test:bun":"bun test/index.js","test:deno":"deno --allow-env --allow-read test/index.js","build:clean":"rm {.,esm,abstract,esm/abstract}/*.{js,d.ts,d.ts.map,js.map} 2> /dev/null","bench:install":"cd test/benchmark; npm install; npm install ../.. --install-links","build:release":"npx jsbt esbuild test/build","test:coverage":"npm install --no-save c8@10.1.2 && npx c8 npm test"},"_npmUser":{"name":"paulmillr","email":"paul@paulmillr.com"},"repository":{"url":"git+https://github.com/paulmillr/noble-curves.git","type":"git"},"_npmVersion":"10.9.2","description":"Audited & minimal JS implementation of elliptic curve cryptography","directories":{},"sideEffects":false,"_nodeVersion":"22.15.0","dependencies":{"@noble/hashes":"1.8.0"},"_hasShrinkwrap":false,"devDependencies":{"prettier":"3.5.3","fast-check":"4.1.1","typescript":"5.8.3","@types/node":"22.15.21","micro-bmark":"0.4.2","micro-should":"0.5.3","@paulmillr/jsbt":"0.4.0"},"_npmOperationalInternal":{"tmp":"tmp/curves_1.9.7_1755268716611_0.3142673820827304","host":"s3://npm-registry-packages-npm-production"},"readme":"# noble-curves\n\nAudited & minimal JS implementation of elliptic curve cryptography.\n\n- 🔒 [**Audited**](#security) by independent security firms\n- 🪶 Minimal: 15KB (gzipped) secp256k1, unused code is excluded from your builds\n- 🏎 Fast: hand-optimized for caveats of JS engines\n- 🔍 Reliable: cross-library / wycheproof tests ensure correctness\n- ➰ Weierstrass, Edwards curves; ECDSA, EdDSA, Schnorr, BLS signatures\n- ✍️ ECDH, hash-to-curve, OPRF, FROST, Poseidon hash, FFT\n- 🔖 Non-repudiation (SUF-CMA, SBS) & consensus-friendliness (ZIP215) in ed25519, ed448\n- 🥈 Wrapper with identical API over native WebCrypto\n\nCurves have 5kb sister projects\n[secp256k1](https://github.com/paulmillr/noble-secp256k1) & [ed25519](https://github.com/paulmillr/noble-ed25519).\nThey have smaller attack surface, but less features.\n\n### This library belongs to _noble_ cryptography\n\n> **noble cryptography** — high-security, easily auditable set of contained cryptographic libraries and tools.\n\n- Zero or minimal dependencies\n- Highly readable TypeScript / JS code\n- PGP-signed releases and transparent NPM builds\n- All libraries:\n  [ciphers](https://github.com/paulmillr/noble-ciphers),\n  [curves](https://github.com/paulmillr/noble-curves),\n  [hashes](https://github.com/paulmillr/noble-hashes),\n  [post-quantum](https://github.com/paulmillr/noble-post-quantum),\n  5kb [secp256k1](https://github.com/paulmillr/noble-secp256k1) /\n  [ed25519](https://github.com/paulmillr/noble-ed25519)\n- WASM version: [awasm-noble](https://github.com/paulmillr/awasm-noble)\n- [Check out the homepage](https://paulmillr.com/noble/)\n  for reading resources, documentation, and apps built with noble\n\n## Usage\n\n> `npm install @noble/curves`\n\n> `deno add jsr:@noble/curves`\n\nWe support all major platforms and runtimes.\nFor React Native, you may need a [polyfill for getRandomValues](https://github.com/LinusU/react-native-get-random-values).\nA standalone file [noble-curves.js](https://github.com/paulmillr/noble-curves/releases) is also available.\n\n```ts\n// import * from '@noble/curves'; // Error: use sub-imports, to ensure small app size\nimport { secp256k1, schnorr } from '@noble/curves/secp256k1.js';\nimport { ed25519, ed25519ph, ed25519ctx, x25519, ristretto255 } from '@noble/curves/ed25519.js';\nimport { ed448, ed448ph, x448, decaf448 } from '@noble/curves/ed448.js';\nimport { p256, p384, p521 } from '@noble/curves/nist.js';\nimport { bls12_381 } from '@noble/curves/bls12-381.js';\nimport { bn254 } from '@noble/curves/bn254.js';\nimport { jubjub, babyjubjub, brainpoolP256r1, brainpoolP384r1, brainpoolP512r1 } from '@noble/curves/misc.js';\n\n// hash-to-curve\nimport { secp256k1_hasher } from '@noble/curves/secp256k1.js';\nimport { p256_hasher, p384_hasher, p521_hasher } from '@noble/curves/nist.js';\nimport { ristretto255_hasher } from '@noble/curves/ed25519.js';\nimport { decaf448_hasher } from '@noble/curves/ed448.js';\n\n// OPRFs\nimport { p256_oprf, p384_oprf, p521_oprf } from '@noble/curves/nist.js';\nimport { ristretto255_oprf } from '@noble/curves/ed25519.js';\nimport { decaf448_oprf } from '@noble/curves/ed448.js';\n\n// utils\nimport { bytesToHex, hexToBytes, concatBytes } from '@noble/curves/utils.js';\nimport { Field } from '@noble/curves/abstract/modular.js';\nimport { weierstrass, ecdsa } from '@noble/curves/abstract/weierstrass.js';\nimport { edwards, eddsa } from '@noble/curves/abstract/edwards.js';\nimport { poseidon, poseidonSponge } from '@noble/curves/abstract/poseidon.js';\nimport { FFT, poly } from '@noble/curves/abstract/fft.js';\n```\n\n- Examples\n  - [ECDSA, EdDSA, Schnorr signatures](#ecdsa-eddsa-schnorr-signatures)\n    - [secp256k1, p256, p384, p521, ed25519, ed448, brainpool](#secp256k1-p256-p384-p521-ed25519-ed448-brainpool)\n    - [ristretto255, decaf448](#ristretto255-decaf448)\n    - [Prehashed signing](#prehashed-signing)\n    - [Recovering public keys from signatures](#recovering-public-keys-from-signatures)\n    - [Hedged ECDSA with noise](#hedged-ecdsa-with-noise)\n    - [Consensus-friendliness vs e-voting](#consensus-friendliness-vs-e-voting)\n  - [ECDH: Diffie-Hellman shared secrets](#ecdh-diffie-hellman-shared-secrets)\n  - [webcrypto: Friendly wrapper](#webcrypto-friendly-wrapper)\n  - [BLS signatures, bls12-381, bn254 aka alt\\_bn128](#bls-signatures-bls12-381-bn254-aka-alt_bn128)\n  - [Hashing to curve points](#hash-to-curve-hashing-to-curve-points)\n  - [OPRFs](#oprfs)\n  - [FROST threshold signatures](#frost-threshold-signatures)\n  - [Poseidon hash](#poseidon-poseidon-hash)\n  - [Fast Fourier Transform](#fft-fast-fourier-transform)\n  - [utils](#utils-byte-shuffling-conversion)\n- [Internals](#internals)\n  - [Elliptic curve Point math](#elliptic-curve-point-math)\n  - [modular: Modular arithmetics \\& finite fields](#modular-modular-arithmetics--finite-fields)\n  - [weierstrass: Custom Weierstrass curve](#weierstrass-custom-weierstrass-curve)\n  - [edwards: Custom Edwards curve](#edwards-custom-edwards-curve)\n  - [Custom ECDSA instance](#custom-ecdsa-instance)\n- [Security](#security)\n- [Speed](#speed)\n- [Contributing & testing](#contributing--testing)\n- [Upgrading](#upgrading)\n\n### ECDSA, EdDSA, Schnorr signatures\n\n#### secp256k1, p256, p384, p521, ed25519, ed448, brainpool\n\n```js\nimport { secp256k1, schnorr } from '@noble/curves/secp256k1.js';\nimport { p256, p384, p521 } from '@noble/curves/nist.js';\nimport { ed25519 } from '@noble/curves/ed25519.js';\nimport { ed448 } from '@noble/curves/ed448.js';\nimport { brainpoolP256r1, brainpoolP384r1, brainpoolP512r1 } from '@noble/curves/misc.js';\nfor (const curve of [\n  secp256k1, schnorr,\n  p256, p384, p521,\n  ed25519, ed448,\n  brainpoolP256r1, brainpoolP384r1, brainpoolP512r1\n]) {\n  const { secretKey, publicKey } = curve.keygen();\n  const msg = new TextEncoder().encode('hello noble');\n  const sig = curve.sign(msg, secretKey);\n  const isValid = curve.verify(sig, msg, publicKey);\n  console.log(curve, secretKey, publicKey, sig, isValid);\n}\n\n// Specific private key\nimport { hexToBytes } from '@noble/curves/utils.js';\nconst secret2 = hexToBytes('46c930bc7bb4db7f55da20798697421b98c4175a52c630294d75a84b9c126236');\nconst pub2 = secp256k1.getPublicKey(secret2);\n```\n\nECDSA signatures use deterministic k, conforming to [RFC 6979](https://www.rfc-editor.org/rfc/rfc6979).\nEdDSA conforms to [RFC 8032](https://www.rfc-editor.org/rfc/rfc8032).\nSchnorr (secp256k1-only) conforms to [BIP 340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki).\n\nMessages are always hashed first.\n\n#### ristretto255, decaf448\n\n```ts\nimport { ristretto255, ristretto255_hasher, ristretto255_oprf } from '@noble/curves/ed25519.js';\nimport { decaf448, decaf448_hasher, decaf448_oprf } from '@noble/curves/ed448.js';\n\nconsole.log(ristretto255.Point, decaf448.Point);\n```\n\nCheck out [RFC 9496](https://www.rfc-editor.org/rfc/rfc9496) more info on ristretto255 & decaf448.\nCheck out separate documentation for [Point](#elliptic-curve-point-math), [hasher](#hash-to-curve-hashing-to-curve-points) and [oprf](#oprfs).\n\n#### Prehashed signing\n\n```js\nimport { secp256k1 } from '@noble/curves/secp256k1.js';\nimport { keccak_256 } from '@noble/hashes/sha3.js';\nconst { secretKey } = secp256k1.keygen();\nconst msg = new TextEncoder().encode('hello noble');\n// prehash: true (default) - hash using secp256k1.hash (sha256)\nconst sig = secp256k1.sign(msg, secretKey);\n// prehash: false - hash using custom hash\nconst sigKeccak = secp256k1.sign(keccak_256(msg), secretKey, { prehash: false });\n```\n\nDefault sign() and verify() behavior (`prehash: true`) applies built-in hash function to message first.\nFor secp256k1 that's sha256, for p521 that's sha512.\n\nProviding `prehash: false` allows user to specify their own hash function (e.g. use secp256k1 + keccak_256).\n\n> [!NOTE]\n> Previously, in noble-curves v1, `prehash: false` was the default.\n> Some other libraries (like libsecp256k1) have no prehashing.\n\n#### Recovering public keys from signatures\n\n```js\nimport { secp256k1 } from '@noble/curves/secp256k1.js';\nconst { secretKey, publicKey } = secp256k1.keygen();\nconst msg = new TextEncoder().encode('hello noble');\nconst sigRec = secp256k1.sign(msg, secretKey, { format: 'recovered' });\nconst publicKey_ = secp256k1.recoverPublicKey(sigRec, msg); // == publicKey\n\n// recovered sig is compact sig with an extra byte\nconst sigNoRec = secp256k1.sign(msg, secretKey, { format: 'compact' });\n// sigNoRec == sigRec.slice(1)\n\n// Signature instance\nconst sigInstance = secp256k1.Signature.fromBytes(sigRec, 'recovered');\n```\n\nPublic key recovery - only supported with ECDSA.\n\n> [!NOTE]\n> Key recovery is a simple math operation.\n> There are no guarantees the signing was actually done.\n> It's possible to forge signature and msg hash (r, s, h), which would\n> recover into a random public key, but it's not feasible\n> to find m which would lead to this specific forged h.\n\n#### Hedged ECDSA with noise\n\n```js\nimport { secp256k1 } from '@noble/curves/secp256k1.js';\nconst { secretKey } = secp256k1.keygen();\nconst msg = new TextEncoder().encode('hello noble');\n// extraEntropy: false - default, hedging disabled\nconst sigNoisy = secp256k1.sign(msg, secretKey);\n// extraEntropy: true - fetch 32 random bytes from CSPRNG\nconst sigNoisyA = secp256k1.sign(msg, secretKey, { extraEntropy: true });\n// extraEntropy: bytes - specific extra entropy\nconst ent = Uint8Array.from([0xca, 0xfe, 0x01, 0x23]);\nconst sigNoisy2 = secp256k1.sign(msg, secretKey, { extraEntropy: ent });\n```\n\nECDSA `sign()` allows providing `extraEntropy`, which switches sig generation to hedged mode.\n\nBy default, ECDSA signatures are generated deterministically,\nfollowing [RFC 6979](https://www.rfc-editor.org/rfc/rfc6979).\nHowever, purely deterministic signatures are vulnerable to fault attacks.\nNewer signature schemes, such as BIP340 schnorr, switched to hedged signatures because of this.\nHedging is basically incorporating some randomness into sig generation process.\n\nFor more info, check out\n[Deterministic signatures are not your friends](https://paulmillr.com/posts/deterministic-signatures/),\n[RFC 6979](https://www.rfc-editor.org/rfc/rfc6979) section 3.6,\nand [cfrg-det-sigs-with-noise draft](https://datatracker.ietf.org/doc/draft-irtf-cfrg-det-sigs-with-noise/).\n\n#### Consensus-friendliness vs e-voting\n\n```js\nimport { ed25519 } from '@noble/curves/ed25519.js';\nconst { secretKey, publicKey } = ed25519.keygen();\nconst msg = new TextEncoder().encode('hello noble');\nconst sig = ed25519.sign(msg, secretKey);\n// zip215: true\nconst isValid = ed25519.verify(sig, msg, publicKey);\n// SBS / e-voting / RFC8032 / FIPS 186-5\nconst isValidRfc = ed25519.verify(sig, msg, publicKey, { zip215: false });\n```\n\n> [!NOTE]\n> Most other libraries don't have SUF-CMA & SBS - less optimal choice for their security.\n\nIn ed25519, there is an ability to choose between consensus-friendliness vs e-voting mode.\n\n* `zip215: true` (default) uses the more permissive, [consensus-friendly](https://hdevalence.ca/blog/2020-10-04-its-25519am) verification rules defined in [ZIP215](https://zips.z.cash/zip-0215).\n* `zip215: false` enforces strict [RFC 8032](https://www.rfc-editor.org/rfc/rfc8032) / [FIPS 186-5](https://csrc.nist.gov/publications/detail/fips/186/5/final) verification and adds SBS-based non-repudiation, which is useful for:\n    * **Contract signing:** prevents a signer from later claiming they signed a different document\n    * **E-voting:** stops voters from choosing keys that let them repudiate their vote\n    * **Blockchains:** avoids signatures valid for multiple transactions (e.g., amount X also validating amount Y)\n\nBoth modes have SUF-CMA (strong unforgeability under chosen message attacks).\nSee [Taming the many EdDSAs](https://eprint.iacr.org/2020/1244) for more info.\n\n### ECDH: Diffie-Hellman shared secrets\n\n```js\nimport { secp256k1 } from '@noble/curves/secp256k1.js';\nimport { x25519 } from '@noble/curves/ed25519.js';\nimport { x448 } from '@noble/curves/ed448.js';\nimport { p256, p384, p521 } from '@noble/curves/nist.js';\n\nfor (const curve of [secp256k1, x25519, x448, p256, p384, p521]) {\n  const alice = curve.keygen();\n  const bob = curve.keygen();\n  const sharedKey = curve.getSharedSecret(alice.secretKey, bob.publicKey);\n  console.log('alice', alice, 'bob', bob, 'shared', sharedKey);\n}\n\n// x25519 & x448 specific methods\nimport { ed25519 } from '@noble/curves/ed25519.js';\nconst alice = ed25519.keygen();\nconst bob = ed25519.keygen();\nconst aliceSecX = ed25519.utils.toMontgomerySecret(alice.secretKey);\nconst bobPubX = ed25519.utils.toMontgomery(bob.publicKey);\nconst sharedKey = x25519.getSharedSecret(aliceSecX, bobPubX);\n```\n\nWe provide ECDH over all Weierstrass curves, and over 2 Montgomery curves\nX25519 (Curve25519) & X448 (Curve448), conforming to [RFC 7748](https://www.rfc-editor.org/rfc/rfc7748).\n\nIn Weierstrass curves, shared secrets:\n\n- Include y-parity bytes: use `key.slice(1)` to strip it\n- Are not hashed: use hashing or KDF on top, like `sha256(shared)` or `hkdf(shared)`\n\n#### webcrypto: Friendly wrapper\n\n> [!NOTE]\n> Webcrypto methods are always async.\n\n##### webcrypto signatures\n\n```js\nimport { ed25519, ed448, p256, p384, p521 } from '@noble/curves/webcrypto.js';\n\n(async () => {\n  for (let [name, curve] of Object.entries({ p256, p384, p521, ed25519, ed448 })) {\n    console.log('curve', name);\n    if (!await curve.isSupported()) {\n      console.log('is not supported, skipping');\n      continue;\n    }\n    const keys = await curve.keygen();\n    const msg = new TextEncoder().encode('hello noble');\n    const sig = await curve.sign(msg, keys.secretKey);\n    const isValid = await curve.verify(sig, msg, keys.publicKey);\n    console.log({\n      keys, msg, sig, isValid\n    });\n  }\n})();\n```\n\n##### webcrypto ecdh\n\n```js\nimport { p256, p384, p521, x25519, x448 } from '@noble/curves/webcrypto.js';\n\n(async () => {\n  for (let [name, curve] of Object.entries({ p256, p384, p521, x25519, x448 })) {\n    console.log('curve', name);\n    if (!await curve.isSupported()) {\n      console.log('is not supported, skipping');\n      continue;\n    }\n    const alice = await curve.keygen();\n    const bob = await curve.keygen();\n    const shared = await curve.getSharedSecret(alice.secretKey, bob.publicKey);\n    const shared2 = await curve.getSharedSecret(bob.secretKey, alice.publicKey);\n    console.log({shared});\n  }\n})();\n```\n\n##### Key conversion from noble to webcrypto and back\n\n```js\nimport { p256 as p256n } from '@noble/curves/nist.js';\nimport { p256 } from '@noble/curves/webcrypto.js';\n(async () => {\n  const nobleKeys = p256n.keygen();\n  // convert noble keys to webcrypto\n  const webKeys = {\n    secretKey: await p256.utils.convertSecretKey(nobleKeys.secretKey, 'raw', 'pkcs8'),\n    publicKey: await p256.utils.convertPublicKey(nobleKeys.publicKey, 'raw', 'spki')\n  };\n  // convert webcrypto keys to noble\n  const nobleKeys2 = {\n    secretKey: await p256.utils.convertSecretKey(webKeys.secretKey, 'pkcs8', 'raw'),\n    publicKey: await p256.utils.convertPublicKey(webKeys.publicKey, 'spki', 'raw')\n  };\n})();\n```\n\nCheck out [micro-key-producer](https://github.com/paulmillr/micro-key-producer) for\npure JS key conversion utils.\n\n### BLS signatures, bls12-381, bn254 aka alt_bn128\n\n```ts\nimport { bls12_381 } from '@noble/curves/bls12-381.js';\n\n// G1 pubkeys, G2 sigs\nconst blsl = bls12_381.longSignatures;\nconst { secretKey, publicKey } = blsl.keygen();\n// const publicKey = blsl.getPublicKey(secretKey);\nconst msg = new TextEncoder().encode('hello noble');\n// default DST\nconst msgp = blsl.hash(msg);\n// custom DST (Ethereum)\nconst msgpd = blsl.hash(msg, 'BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_');\nconst signature = blsl.sign(msgp, secretKey);\nconst isValid = blsl.verify(signature, msgp, publicKey);\nconsole.log('long', { publicKey, signature, isValid });\n\n// G1 sigs, G2 pubkeys\nconst blss = bls12_381.shortSignatures;\nconst publicKey2 = blss.getPublicKey(secretKey);\nconst msgp2 = blss.hash(msg, 'BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_');\nconst signature2 = blss.sign(msgp2, secretKey);\nconst isValid2 = blss.verify(signature2, msgp2, publicKey2);\nconsole.log({ publicKey2, signature2, isValid2 });\n\n// Aggregation\nconst aggregatedKey = bls12_381.longSignatures.aggregatePublicKeys([\n  blsl.getPublicKey(bls12_381.utils.randomSecretKey()),\n  blsl.getPublicKey(bls12_381.utils.randomSecretKey()),\n]);\n// const aggregatedSig = bls.aggregateSignatures(sigs)\n\n// Pairings, with and without final exponentiation\n// bls.pairing(PointG1, PointG2);\n// bls.pairing(PointG1, PointG2, false);\n// bls.fields.Fp12.finalExponentiate(bls.fields.Fp12.mul(PointG1, PointG2));\n\n// Others\n// bls.G1.Point.BASE, bls.G2.Point.BASE;\n// bls.fields.Fp, bls.fields.Fp2, bls.fields.Fp12, bls.fields.Fr;\n```\n\nSee [abstract/bls](#bls-barreto-lynn-scott-curves).\nFor example usage, check out [the implementation of BLS EVM precompiles](https://github.com/ethereumjs/ethereumjs-monorepo/blob/361f4edbc239e795a411ac2da7e5567298b9e7e5/packages/evm/src/precompiles/bls12_381/noble.ts).\n\nThe BN254 API mirrors [BLS](#bls12-381). The curve was previously called alt_bn128.\nThe implementation is compatible with [EIP-196](https://eips.ethereum.org/EIPS/eip-196) and\n[EIP-197](https://eips.ethereum.org/EIPS/eip-197).\n\nFor BN254 usage, check out [the implementation of bn254 EVM precompiles](https://github.com/paulmillr/noble-curves/blob/3ed792f8ad9932765b84d1064afea8663a255457/test/bn254.test.js#L697).\nWe don't implement Point methods toBytes. To work around this limitation, has to initialize points on their own from BigInts. Reason it's not implemented is because [there is no standard](https://github.com/privacy-scaling-explorations/halo2curves/issues/109).\nPoints of divergence:\n\n- Endianness: LE vs BE (byte-swapped)\n- Flags as first hex bits (similar to BLS) vs no-flags\n- Imaginary part last in G2 vs first (c0, c1 vs c1, c0)\n\n### hash-to-curve: hashing to curve points\n\n```ts\nimport { bls12_381 } from '@noble/curves/bls12-381.js';\nimport { ed25519_hasher, ristretto255_hasher } from '@noble/curves/ed25519.js';\nimport { decaf448_hasher, ed448_hasher } from '@noble/curves/ed448.js';\nimport { p256_hasher, p384_hasher, p521_hasher } from '@noble/curves/nist.js';\nimport { secp256k1_hasher } from '@noble/curves/secp256k1.js';\n\nconst h = {\n  secp256k1_hasher,\n  p256_hasher, p384_hasher, p521_hasher,\n  ed25519_hasher,\n  ed448_hasher,\n  ristretto255_hasher,\n  decaf448_hasher,\n  bls_G1: bls12_381.G1,\n  bls_G2: bls12_381.G2\n};\n\nconst msg = Uint8Array.from([0xca, 0xfe, 0x01, 0x23]);\nconsole.log('msg', msg);\nfor (let [name, c] of Object.entries(h)) {\n  const hashToCurve = c.hashToCurve(msg).toHex();\n  const hashToCurve_customDST = c.hashToCurve(msg, { DST: 'hello noble' }).toHex();\n  const encodeToCurve = 'encodeToCurve' in c ? c.encodeToCurve(msg).toHex() : undefined;\n  // ristretto255, decaf448 only\n  const deriveToCurve = 'deriveToCurve' in c ?\n    c.deriveToCurve!(new Uint8Array(c.Point.Fp.BYTES * 2)).toHex() : undefined;\n  const hashToScalar = c.hashToScalar(msg);\n  console.log({\n    name, hashToCurve, hashToCurve_customDST, encodeToCurve, deriveToCurve, hashToScalar\n  });\n}\n\n// abstract methods\nimport { expand_message_xmd, expand_message_xof, hash_to_field } from '@noble/curves/abstract/hash-to-curve.js';\n```\n\nThe module allows to hash arbitrary strings to elliptic curve points. Implements [RFC 9380](https://www.rfc-editor.org/rfc/rfc9380).\n\n> [!NOTE]\n> Why is `p256_hasher` separate from `p256`?\n> The methods reside in separate _hasher namespace for tree-shaking:\n> this way users who don't need hash-to-curve, won't have it in their builds.\n\n### OPRFs\n\n```js\nimport { p256_oprf, p384_oprf, p521_oprf } from '@noble/curves/nist.js';\nimport { ristretto255_oprf } from '@noble/curves/ed25519.js';\nimport { decaf448_oprf } from '@noble/curves/ed448.js';\n```\n\nWe provide OPRFs (oblivious pseudorandom functions),\nconforming to [RFC 9497](https://www.rfc-editor.org/rfc/rfc9497).\n\nOPRF allows to interactively create an `Output = PRF(Input, serverSecretKey)`:\n\n- Server cannot calculate Output by itself: it doesn't know Input\n- Client cannot calculate Output by itself: it doesn't know server secretKey\n- An attacker interception the communication can't restore Input/Output/serverSecretKey and can't\n  link Input to some value.\n\n### FROST threshold signatures\n\nFROST implements [RFC 9591](https://www.rfc-editor.org/rfc/rfc9591) threshold Schnorr signing.\nIt is similar to multisig from the application point of view: any `min` of `max` participants\ncan jointly produce one Schnorr signature under a shared public key.\nSupported ciphersuites are `p256_FROST`, `ed25519_FROST`, `ed448_FROST`, `ristretto255_FROST`,\n`secp256k1_FROST`, and `schnorr_FROST` (Taproot-compatible secp256k1).\nSigning has two rounds: selected signers commit first, then produce signature shares.\n\n> [!WARNING]\n> The FROST code is new and has not been audited yet.\n> It passes the imported `frost-rs` vectors/examples and local regression tests.\n\n```js\nimport { p256_FROST } from '@noble/curves/nist.js';\n\nconst signers = { min: 2, max: 3 };\nconst alice = p256_FROST.Identifier.derive('alice@example.com');\nconst bob = p256_FROST.Identifier.derive('bob@example.com');\nconst carol = p256_FROST.Identifier.derive('carol@example.com');\n// trusted dealer\nconst deal = p256_FROST.trustedDealer(signers, [alice, bob, carol]);\nfor (const id of [alice, bob, carol]) p256_FROST.validateSecret(deal.secretShares[id], deal.public);\n\nconst msg = new TextEncoder().encode('hello threshold');\n// round 1: selected signers commit\nconst aliceRound1 = p256_FROST.commit(deal.secretShares[alice]);\nconst bobRound1 = p256_FROST.commit(deal.secretShares[bob]);\nconst commitmentList = [aliceRound1.commitments, bobRound1.commitments];\n// round 2: signers produce signature shares\nconst sigShares = {\n  [alice]: p256_FROST.signShare(\n    deal.secretShares[alice],\n    deal.public,\n    aliceRound1.nonces,\n    commitmentList,\n    msg\n  ),\n  [bob]: p256_FROST.signShare(\n    deal.secretShares[bob],\n    deal.public,\n    bobRound1.nonces,\n    commitmentList,\n    msg\n  ),\n};\nconst sig = p256_FROST.aggregate(deal.public, commitmentList, msg, sigShares);\nconst isValid = p256_FROST.verify(sig, msg, deal.public.commitments[0]);\n```\n\nKey generation can be done with a trusted dealer or with DKG.\nDKG has three rounds: participants commit to key generation, exchange private shares, then derive final participant keys.\n\n```js\nimport { p256_FROST } from '@noble/curves/nist.js';\n\nconst signers = { min: 2, max: 3 };\nconst alice = p256_FROST.DKG.round1(p256_FROST.Identifier.fromNumber(1), signers);\nconst bob = p256_FROST.DKG.round1(p256_FROST.Identifier.fromNumber(2), signers);\nconst carol = p256_FROST.DKG.round1(p256_FROST.Identifier.fromNumber(3), signers);\n\n// round 1: participants commit to key generation\nconst aliceRound2 = p256_FROST.DKG.round2(alice.secret, [bob.public, carol.public]);\nconst bobRound2 = p256_FROST.DKG.round2(bob.secret, [alice.public, carol.public]);\nconst carolRound2 = p256_FROST.DKG.round2(carol.secret, [alice.public, bob.public]);\n\n// round 2: private shares for each recipient\nconst aliceKey = p256_FROST.DKG.round3(alice.secret, [bob.public, carol.public], [\n  bobRound2[p256_FROST.Identifier.fromNumber(1)],\n  carolRound2[p256_FROST.Identifier.fromNumber(1)],\n]);\n// round 3: final participant key package\n```\n\nDKG helpers are intended for interoperable testing and practical key generation.\nThe library implements the cryptographic steps, not the surrounding application protocol:\ncallers still need authenticated communication, coordination, retries, session handling, and policy.\n\n### poseidon: Poseidon hash\n\nImplements [Poseidon](https://www.poseidon-hash.info) ZK-friendly hash:\npermutation and sponge.\n\nThere are many poseidon variants with different constants.\nWe don't provide them: you should construct them manually.\nCheck out [scure-starknet](https://github.com/paulmillr/scure-starknet) package for a proper example.\n\n```ts\nimport { bn254 } from '@noble/curves/bn254.js';\nimport { grainGenConstants, poseidon, poseidonSponge } from '@noble/curves/abstract/poseidon.js';\n\nconst rate = 2;\nconst capacity = 1;\nconst Fp = bn254.fields.Fr;\nconst { mds, roundConstants } = grainGenConstants({\n  Fp,\n  t: rate + capacity,\n  roundsFull: 8,\n  roundsPartial: 31,\n});\nconst opts = {\n  Fp,\n  rate,\n  capacity,\n  sboxPower: 17,\n  mds,\n  roundConstants,\n  roundsFull: 8,\n  roundsPartial: 31,\n};\nconst permutation = poseidon({ ...opts, t: rate + capacity });\nconst sponge = poseidonSponge(opts); // use carefully, not specced\n```\n\n### fft: Fast Fourier Transform\n\n```ts\nimport * as fft from '@noble/curves/abstract/fft.js';\nimport { bls12_381 } from '@noble/curves/bls12-381.js';\nconst Fr = bls12_381.fields.Fr;\nconst roots = fft.rootsOfUnity(Fr, 7n);\nconst fftFr = fft.FFT(roots, Fr);\n```\n\nExperimental implementation of NTT / FFT (Fast Fourier Transform) over finite fields.\nAPI may change at any time. The code has not been audited. Feature requests are welcome.\n\n### utils: byte shuffling, conversion\n\n```ts\nimport { bytesToHex, concatBytes, equalBytes, hexToBytes } from '@noble/curves/utils.js';\n\nbytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23]));\nhexToBytes('cafe0123');\nconcatBytes(Uint8Array.from([0xca, 0xfe]), Uint8Array.from([0x01, 0x23]));\nequalBytes(Uint8Array.of(0xca), Uint8Array.of(0xca));\n```\n\n### Internals\n\n#### Elliptic curve Point math\n\n```js\nimport { pippenger } from '@noble/curves/abstract/curve.js';\nimport { secp256k1, schnorr } from '@noble/curves/secp256k1.js';\nimport { p256, p384, p521 } from '@noble/curves/nist.js';\nimport { ed25519, ristretto255 } from '@noble/curves/ed25519.js';\nimport { ed448, decaf448 } from '@noble/curves/ed448.js';\nimport { bls12_381 } from '@noble/curves/bls12-381.js';\nimport { bn254 } from '@noble/curves/bn254.js';\nimport { jubjub, babyjubjub } from '@noble/curves/misc.js';\n\nconst curves = [\n  secp256k1, schnorr, p256, p384, p521, ed25519, ed448,\n  ristretto255, decaf448,\n  bls12_381.G1, bls12_381.G2, bn254.G1,\n  jubjub, babyjubjub\n];\nfor (const curve of curves) {\n  const { Point } = curve;\n  const { BASE, ZERO, Fp, Fn } = Point;\n  const info = Point.CURVE?.();\n  const p = BASE.multiply(2n);\n\n  // Initialization\n  if (info?.type === 'weierstrass') {\n    // projective (homogeneous) coordinates: (X, Y, Z) ∋ (x=X/Z, y=Y/Z)\n    const p_ = new Point(BASE.X, BASE.Y, BASE.Z);\n  } else if (info?.type === 'edwards') {\n    // extended coordinates: (X, Y, Z, T) ∋ (x=X/Z, y=Y/Z)\n    const p_ = new Point(BASE.X, BASE.Y, BASE.Z, BASE.T);\n  }\n\n  // Math\n  const p1 = p.add(p);\n  const p2 = p.double();\n  const p3 = p.subtract(p);\n  const p4 = p.negate();\n  const p5 = p.multiply(451n);\n\n  // MSM (multi-scalar multiplication)\n  const pa = [BASE, BASE.multiply(2n), BASE.multiply(4n), BASE.multiply(8n)];\n  const p6 = pippenger(Point, pa, [3n, 5n, 7n, 11n]);\n  const _true3 = p6.equals(BASE.multiply(129n)); // 129*G\n\n  const pcl = p.clearCofactor();\n  const isTorsionFree = p.isTorsionFree();\n\n  const r1 = p.toBytes();\n  const r1_ = Point.fromBytes(r1);\n  const r2 = p.toAffine();\n  const { x, y } = r2;\n  const r2_ = Point.fromAffine(r2);\n}\n```\n\n#### modular: Modular arithmetics & finite fields\n\n```js\nimport { mod, invert, Field } from '@noble/curves/abstract/modular.js';\n\n// Finite Field utils\nconst fp = Field(2n ** 255n - 19n); // Finite field over 2^255-19\nfp.mul(591n, 932n); // multiplication\nfp.pow(481n, 11024858120n); // exponentiation\nfp.div(5n, 17n); // division: 5/17 mod 2^255-19 == 5 * invert(17)\nfp.inv(5n); // modular inverse\nfp.sqrt(4n); // square root\n\n// Non-Field generic utils are also available\nmod(21n, 10n); // 21 mod 10 == 1n; fixed version of 21 % 10\ninvert(17n, 10n); // invert(17) mod 10; modular multiplicative inverse\n```\n\nAll arithmetics is done with JS bigints over finite fields,\nwhich is defined from `modular` sub-module.\n\nField operations are not constant-time: see [security](#security).\nThe fact is mostly irrelevant, but the important method to keep in mind is `pow`,\nwhich may leak exponent bits, when used naïvely.\n\n#### weierstrass: Custom Weierstrass curve\n\n```js\nimport { weierstrass } from '@noble/curves/abstract/weierstrass.js';\n// NIST secp192r1 aka p192. https://www.secg.org/sec2-v2.pdf\nconst p192_CURVE = {\n  p: 0xfffffffffffffffffffffffffffffffeffffffffffffffffn,\n  n: 0xffffffffffffffffffffffff99def836146bc9b1b4d22831n,\n  h: 1n,\n  a: 0xfffffffffffffffffffffffffffffffefffffffffffffffcn,\n  b: 0x64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1n,\n  Gx: 0x188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012n,\n  Gy: 0x07192b95ffc8da78631011ed6b24cdd573f977a11e794811n,\n};\nconst p192_Point = weierstrass(p192_CURVE);\n```\n\nShort Weierstrass curve's formula is `y² = x³ + ax + b`. `weierstrass`\nexpects arguments `a`, `b`, field characteristic `p`, curve order `n`,\ncofactor `h` and coordinates `Gx`, `Gy` of generator point.\n\n#### edwards: Custom Edwards curve\n\n```js\nimport { edwards } from '@noble/curves/abstract/edwards.js';\nconst ed25519_CURVE = {\n  p: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedn,\n  n: 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3edn,\n  h: 8n,\n  a: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecn,\n  d: 0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3n,\n  Gx: 0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,\n  Gy: 0x6666666666666666666666666666666666666666666666666666666666666658n,\n};\nconst ed25519_Point = edwards(ed25519_CURVE);\n```\n\nTwisted Edwards curve's formula is `ax² + y² = 1 + dx²y²`.\nYou must specify `a`, `d`, field characteristic `p`, curve order `n` (sometimes named as `L`),\ncofactor `h` and coordinates `Gx`, `Gy` of generator point.\n\n#### Custom ECDSA instance\n\n```js\nimport { weierstrass, ecdsa } from '@noble/curves/abstract/weierstrass.js';\nimport { sha224, sha256 } from '@noble/hashes/sha2.js';\nconst p192_CURVE = {\n  p: 0xfffffffffffffffffffffffffffffffeffffffffffffffffn,\n  n: 0xffffffffffffffffffffffff99def836146bc9b1b4d22831n,\n  h: 1n,\n  a: 0xfffffffffffffffffffffffffffffffefffffffffffffffcn,\n  b: 0x64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1n,\n  Gx: 0x188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012n,\n  Gy: 0x07192b95ffc8da78631011ed6b24cdd573f977a11e794811n,\n};\nconst p192_Point = weierstrass(p192_CURVE);\nconst p192_sha256 = ecdsa(p192_Point, sha256);\n// or\nconst p192_sha224 = ecdsa(p192_Point, sha224);\n\nconst keys = p192_sha256.keygen();\nconst msg = new TextEncoder().encode('custom curve');\nconst sig = p192_sha256.sign(msg, keys.secretKey);\nconst isValid = p192_sha256.verify(sig, msg, keys.publicKey);\n```\n\n## Security\n\nThe library has been audited:\n\n- at version 2.2.0, in Apr 2026, by ourselves (self-audited)\n  - Scope: everything\n  - [Changes since audit](https://github.com/paulmillr/noble-curves/compare/2.2.0..main)\n- at version 1.6.0, in Sep 2024, independently, by [Cure53](https://cure53.de)\n  - PDFs: [website](https://cure53.de/audit-report_noble-crypto-libs.pdf), [in-repo](./audit/2024-09-cure53-audit-nbl4.pdf)\n  - [Changes since audit](https://github.com/paulmillr/noble-curves/compare/1.6.0..main)\n  - Scope: ed25519, ed448, their add-ons, bls12-381, bn254,\n    hash-to-curve, low-level primitives bls, tower, edwards, montgomery.\n  - The audit has been funded by [OpenSats](https://opensats.org)\n- at version 1.2.0, in Sep 2023, independently, by [Kudelski Security](https://kudelskisecurity.com)\n  - PDFs: [in-repo](./audit/2023-09-kudelski-audit-starknet.pdf)\n  - [Changes since audit](https://github.com/paulmillr/noble-curves/compare/1.2.0..main)\n  - Scope: [scure-starknet](https://github.com/paulmillr/scure-starknet) and its related\n    abstract modules of noble-curves: `curve`, `modular`, `poseidon`, `weierstrass`\n  - The audit has been funded by [Starkware](https://starkware.co)\n- at version 0.7.3, in Feb 2023, independently, by [Trail of Bits](https://www.trailofbits.com)\n  - PDFs: [website](https://github.com/trailofbits/publications/blob/master/reviews/2023-01-ryanshea-noblecurveslibrary-securityreview.pdf),\n    [in-repo](./audit/2023-01-trailofbits-audit-curves.pdf)\n  - [Changes since audit](https://github.com/paulmillr/noble-curves/compare/0.7.3..main)\n  - Scope: abstract modules `curve`, `hash-to-curve`, `modular`, `poseidon`, `utils`, `weierstrass` and\n    top-level modules `_shortw_utils` and `secp256k1`\n  - The audit has been funded by [Ryan Shea](https://www.shea.io)\n\nIt is tested against property-based, cross-library and Wycheproof vectors,\nand is being fuzzed in [the separate repo](https://github.com/paulmillr/integration-tests).\n\nIf you see anything unusual: investigate and report.\n\n### Constant-timeness\n\nWe're targetting algorithmic constant time. _JIT-compiler_ and _Garbage Collector_ make \"constant time\"\nextremely hard to achieve [timing attack](https://en.wikipedia.org/wiki/Timing_attack) resistance\nin a scripting language. Which means _any other JS library can't have\nconstant-timeness_. Even statically typed Rust, a language without GC,\n[makes it harder to achieve constant-time](https://www.chosenplaintext.ca/open-source/rust-timing-shield/security)\nfor some cases. If your goal is absolute security, don't use any JS lib — including bindings to native ones.\nUse low-level libraries & languages.\n\nWithin those limits, secret-scalar multiplication provides specific, measurable properties:\n\n- **Fixed operation sequence:** `multiply()` uses signed fixed-window tables with\n  data-oblivious table scans — the number and order of point operations\n  is independent of the scalar value.\n- **Scalar blinding:** secret scalars are additionally masked as `s + r·n` with a random\n  128-bit `r` before multiplication. This applies to all multiplications on cofactor-1\n  curves (p256, p384, p521, secp256k1), and to base-point multiplications everywhere.\n- **Statistical validation:** a dudect-style Welch t-test harness (`benchmark/ct.ts`)\n  compares timing across adversarial scalar classes (sparse vs dense, low vs high bits,\n  near-order, bit patterns). Base-point multiplication shows no distinguishable timing on any\n  curve, and random-point multiplication shows none on the Weierstrass curves\n  (max |t| ≤ 2.8 at 1000 samples; threshold 4.5).\n\nKnown limitation: on cofactored Edwards curves (ed25519, ed448), multiplying a **non-base**\npoint by a secret scalar is not blinded. The same harness detects this reliably. EdDSA signing is\nunaffected (it only multiplies the blinded base point), and X25519/X448 use a separate\nMontgomery-ladder implementation (also unaffected). It matters for protocols that multiply arbitrary\nEdwards/Ristretto points by long-lived secret scalars; prefer scalars that are\nfull-width by construction there. Note that detectability in an isolated harness does not\nimply practical exploitability: we attempted scalar extraction in a realistic\ncross-tenant / in-browser setting and were unable to recover Edwards scalars\neven with 100,000 timing samples.\n\n### Memory dumping\n\nUse low-level languages instead of JS / WASM if your goal is absolute security.\n\nThe library mostly uses Uint8Arrays and bigints.\n\n- Uint8Arrays have `.fill(0)` which instructs to fill content with zeroes\n  but there are no guarantees in JS\n- bigints are immutable and don't have a method to zeroize their content:\n  a user needs to wait until the next garbage collection cycle\n- hex strings are also immutable: there is no way to zeroize them\n- `await fn()` will write all internal variables to memory. With\n  async functions there are no guarantees when the code\n  chunk would be executed. Which means attacker can have\n  plenty of time to read data from memory.\n\nThis means some secrets could stay in memory longer than anticipated.\nHowever, if an attacker can read application memory, it's doomed anyway:\nthere is no way to guarantee anything about zeroizing sensitive data without\ncomplex tests-suite which will dump process memory and verify that there is\nno sensitive data left. For JS it means testing all browsers (including mobile).\nAnd, of course, it will be useless without using the same\ntest-suite in the actual application that consumes the library.\n\n### Supply chain security\n\n- **Commits** are signed with PGP keys to prevent forgery. Be sure to verify the commit signatures\n- **Releases** are made transparently through token-less GitHub CI and Trusted Publishing. Be sure to verify the [provenance logs](https://docs.npmjs.com/generating-provenance-statements) for authenticity.\n- **Rare releasing** is practiced to minimize the need for re-audits by end-users.\n- **Dependencies** are minimized and strictly pinned to reduce supply-chain risk.\n  - We use as few dependencies as possible.\n  - Version ranges are locked, and changes are checked with npm-diff.\n- **Dev dependencies** are excluded from end-user installs; they’re only used for development and build steps.\n\nFor this package, there is 1 dependency; and a few dev dependencies:\n\n- [noble-hashes](https://github.com/paulmillr/noble-hashes) provides cryptographic hashing functionality\n- jsbt is used for benchmarking / testing / build tooling and developed by the same author\n- prettier, fast-check and typescript are used for code quality / test generation / ts compilation\n\n### Randomness\n\nWe rely on the built-in\n[`crypto.getRandomValues`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues),\nwhich is considered a cryptographically secure PRNG.\n\nBrowsers have had weaknesses in the past - and could again - but implementing a userspace CSPRNG is even worse, as there’s no reliable userspace source of high-quality entropy.\n\n### Quantum computers\n\nCryptographically relevant quantum computer, if built, will allow to\nbreak elliptic curve cryptography (both ECDSA / EdDSA & ECDH) using Shor's algorithm.\n\nConsider switching to newer / hybrid algorithms, such as SPHINCS+. They are available in\n[noble-post-quantum](https://github.com/paulmillr/noble-post-quantum).\n\nNIST prohibits classical cryptography (RSA, DSA, ECDSA, ECDH) [after 2035](https://nvlpubs.nist.gov/nistpubs/ir/2024/NIST.IR.8547.ipd.pdf). Australian ASD prohibits it [after 2030](https://www.cyber.gov.au/resources-business-and-government/essential-cyber-security/ism/cyber-security-guidelines/guidelines-cryptography).\n\n## Speed\n\n```sh\nnpm run bench\n```\n\nnoble-curves spends 10+ ms to generate 20MB+ of base point precomputes.\nThis is done **one-time** per curve.\n\nThe generation is deferred until any method (pubkey, sign, verify) is called.\nUser can force precompute generation by manually calling `Point.BASE.precompute(windowSize, false)`.\nCheck out the source code.\n\nBenchmark results on Apple M4:\n\n```\n# secp256k1\ninit 11ms\ngetPublicKey x 4,909 ops/sec @ 203μs/op\nsign x 4,319 ops/sec @ 231μs/op\nverify x 1,391 ops/sec @ 718μs/op\nrecoverPublicKey x 1,377 ops/sec @ 725μs/op\ngetSharedSecret x 793 ops/sec @ 1ms/op\nschnorr.sign x 895 ops/sec @ 1ms/op\nschnorr.verify x 1,418 ops/sec @ 704μs/op\n\n# ed25519\ninit 9ms\ngetPublicKey x 7,161 ops/sec @ 139μs/op\nsign x 3,541 ops/sec @ 282μs/op\nverify x 1,483 ops/sec @ 674μs/op\n\n# ed448\ninit 19ms\ngetPublicKey x 3,125 ops/sec @ 319μs/op\nsign x 1,549 ops/sec @ 645μs/op\nverify x 518 ops/sec @ 1ms/op ± 6.59% (1ms..15ms)\n\n# p256\ninit 9ms\ngetPublicKey x 4,799 ops/sec @ 208μs/op\nsign x 4,262 ops/sec @ 234μs/op\nverify x 943 ops/sec @ 1ms/op\n\n# p384\ninit 20ms\ngetPublicKey x 2,208 ops/sec @ 452μs/op\nsign x 1,949 ops/sec @ 512μs/op\nverify x 371 ops/sec @ 2ms/op\n\n# p521\ninit 37ms\ngetPublicKey x 1,215 ops/sec @ 822μs/op\nsign x 1,116 ops/sec @ 895μs/op\nverify x 186 ops/sec @ 5ms/op\n\n# ristretto255\nadd x 719,424 ops/sec @ 1μs/op\nmultiply x 7,214 ops/sec @ 138μs/op\nencode x 21,337 ops/sec @ 46μs/op\ndecode x 20,682 ops/sec @ 48μs/op\n\n# decaf448\nadd x 467,945 ops/sec @ 2μs/op\nmultiply x 682 ops/sec @ 1ms/op\nencode x 8,279 ops/sec @ 120μs/op\ndecode x 8,044 ops/sec @ 124μs/op\n\n# ECDH\nx25519 x 1,631 ops/sec @ 612μs/op\nx448 x 584 ops/sec @ 1ms/op\nsecp256k1 x 791 ops/sec @ 1ms/op\np256 x 757 ops/sec @ 1ms/op\np384 x 329 ops/sec @ 3ms/op\np521 x 175 ops/sec @ 5ms/op\n\n# hash-to-curve\nhashToScalar x 212,404 ops/sec @ 4μs/op\nhash_to_field x 239,578 ops/sec @ 4μs/op\nhashToCurve secp256k1 x 5,101 ops/sec @ 196μs/op\nhashToCurve p256 x 7,651 ops/sec @ 130μs/op\nhashToCurve p384 x 3,275 ops/sec @ 305μs/op\nhashToCurve p521 x 1,642 ops/sec @ 608μs/op\nhashToCurve ed25519 x 6,679 ops/sec @ 149μs/op\nhashToCurve ed448 x 2,911 ops/sec @ 343μs/op\nhash_to_ristretto255 x 9,284 ops/sec @ 107μs/op\nhash_to_decaf448 x 3,764 ops/sec @ 265μs/op\n\n# modular over secp256k1 P field\ninvert a x 868,809 ops/sec @ 1μs/op\ninvert b x 662,251 ops/sec @ 1μs/op\nsqrt p = 3 mod 4 x 24,440 ops/sec @ 40μs/op\nsqrt tonneli-shanks x 803 ops/sec @ 1ms/op\n\n# bls12-381\ninit 90ms\ngetPublicKey x 2,315 ops/sec @ 431μs/op\nsign x 222 ops/sec @ 4ms/op\nverify x 113 ops/sec @ 8ms/op\npairing x 160 ops/sec @ 6ms/op\npairing10 x 42 ops/sec @ 23ms/op ± 7.14% (22ms..36ms)\nMSM 4096 scalars x points 564ms\naggregatePublicKeys/8 x 1,862 ops/sec @ 536μs/op\naggregatePublicKeys/32 x 1,589 ops/sec @ 629μs/op\naggregatePublicKeys/128 x 988 ops/sec @ 1ms/op\naggregatePublicKeys/512 x 396 ops/sec @ 2ms/op\naggregatePublicKeys/2048 x 115 ops/sec @ 8ms/op\naggregateSignatures/8 x 87 ops/sec @ 11ms/op\naggregateSignatures/32 x 23 ops/sec @ 43ms/op\naggregateSignatures/128 x 5 ops/sec @ 170ms/op\naggregateSignatures/512 x 1 ops/sec @ 680ms/op\naggregateSignatures/2048 x 0 ops/sec @ 2737ms/op\n```\n\n## Upgrading\n\nSupported node.js versions:\n\n- v2 (2025-08): v20.19+ (ESM-only)\n- v1 (2023-04): v14.21+ (ESM & CJS)\n\n### Changelog of curves v1 to curves v2\n\nv2 massively simplifies internals, improves security, reduces bundle size and lays path for the future.\nWe tried to keep v2 as much backwards-compatible as possible.\n\nTo simplify upgrading, upgrade first to curves 1.9.x. It would show deprecations in vscode-like text editor.\nFix them first.\n\n- The package is now ESM-only. ESM can finally be loaded from common.js on node v20.19+\n- `.js` extension must be used for all modules\n    - Old: `@noble/curves/ed25519`\n    - New: `@noble/curves/ed25519.js`\n    - This simplifies working in browsers natively without transpilers\n\nNew features:\n\n- webcrypto: create friendly noble-like wrapper over built-in WebCrypto\n- oprf: implement RFC 9497 OPRFs (oblivious pseudorandom functions)\n    - We support p256, p384, p521, ristretto255 and decaf448\n- weierstrass, edwards: add `isValidSecretKey`, `isValidPublicKey`\n- misc: add Brainpool curves: brainpoolP256r1, brainpoolP384r1, brainpoolP512r1\n\nChanges:\n\n- Most methods now expect Uint8Array, string hex inputs are prohibited\n    - The change simplifies reasoning, improves security and reduces malleability\n    - `Point.fromHex` now expects string-only hex inputs, use `Point.fromBytes` for Uint8Array\n- Many methods were renamed, upgrade to curves v1.9 first to highlight deprecated old names\n- Breaking changes of ECDSA (secp256k1, p256, p384...):\n    - To bring back old behavior, pass `{ prehash: false, lowS: false }` to sign / verify\n    - sign, verify: Switch to **prehashed messages**. Instead of\n      messageHash, the methods now expect unhashed message.\n      To bring back old behavior, use option `{prehash: false}`\n    - sign, verify: Switch to **lowS signatures** by default.\n      This change doesn't affect secp256k1, which has been using lowS since beginning.\n      To bring back old behavior, use option `{lowS: false}`\n    - sign, verify: Switch to **Uint8Array signatures** (format: 'compact') by default.\n    - verify: **der format must be explicitly specified** in `{format: 'der'}`.\n      This reduces malleability\n    - verify: **prohibit Signature-instance** signature. User must now always do\n      `signature.toBytes()`\n- Breaking changes of BLS signatures (bls12-381, bn254):\n    - Move getPublicKey, sign, verify, signShortSignature etc into two new namespaces:\n      bls.longSignatures (G1 pubkeys, G2 sigs) and bls.shortSignatures (G1 sigs, G2 pubkeys).\n    - verifyBatch now expects array of inputs `{message: ..., publicKey: ...}[]`\n- Curve changes:\n    - Massively simplify curve creation, split it into point creation & sig generator creation\n    - New methods are `weierstrass() + ecdsa()` / `edwards() + eddsa()`\n    - weierstrass / edwards expect simplified curve params (Fp became p)\n    - ecdsa / eddsa expect Point class and hash\n    - Remove unnecessary Fn argument in `pippenger`\n- modular changes:\n    - Field#fromBytes() now validates elements to be in 0..order-1 range\n- Massively improve error messages, make them more descriptive\n\nRenamings:\n\n- Module changes\n    - `p256`, `p384`, `p521` modules have been moved into `nist`\n    - `jubjub` module has been moved into `misc`\n- Point changes\n    - ExtendedPoint, ProjectivePoint => Point\n    - Point coordinates (projective / extended) from px/ex, py/ey, pz/ez, et => X, Y, Z, T\n    - Point.normalizeZ, Point.msm => separate methods in `abstract/curve.js` submodule\n    - Point.fromPrivateKey() got removed, use `Point.BASE.multiply()` and `Point.Fn.fromBytes(secretKey)`\n    - toRawBytes, fromRawBytes => toBytes, fromBytes\n    - RistrettoPoint => ristretto255.Point, DecafPoiont => decaf448.Point\n- Signature (ECDSA) changes\n    - toCompactRawBytes, toDERRawBytes => toBytes('compact'), toBytes('der')\n    - toCompactHex, toDERHex => toHex('compact'), toHex('der')\n    - fromCompact, fromDER => fromBytes(format), fromHex(format)\n- utils changes\n    - randomPrivateKey => randomSecretKey\n    - utils.precompute, Point#_setWindowSize => Point#precompute\n    - edwardsToMontgomery => utils.toMontgomery\n    - edwardsToMontgomeryPriv => utils.toMontgomerySecret\n- Rename all curve-specific hash-to-curve methods to `*curve*_hasher`.\n  Example: `secp256k1.hashToCurve` => `secp256k1_hasher.hashToCurve()`\n- Massive type renamings and improvements\n\nRemoved features:\n\n- Point#multiplyAndAddUnsafe, Point#hasEvenY\n- `CURVE` property with all kinds of random stuff. Point.CURVE() now replaces it, but only provides\n  curve parameters\n- Remove `pasta`, `bn254_weierstrass` (NOT pairing-based bn254) curves\n- utils.normPrivateKeyToScalar - use `Point.Fn.fromBytes`\n- Field.MASK\n\n### secp256k1 v1, ed25519 v1, bls12-381 v1 to curves v1\n\nPreviously, the library was split into single-feature packages\n[noble-secp256k1](https://github.com/paulmillr/noble-secp256k1),\n[noble-ed25519](https://github.com/paulmillr/noble-ed25519) and\n[noble-bls12-381](https://github.com/paulmillr/noble-bls12-381).\n\nCurves continue their original work. The single-feature packages changed their\ndirection towards providing minimal 5kb implementations of cryptography,\nwhich means they have less features. Separate bls package had been deprecated.\n\nsecp256k1:\n\n- `getPublicKey`: defaults to compressed sigs (use second argument to adjust)\n- `sign`: renamed options `canonical` => `lowS`; `der` => `format: 'der'`\n- `verify`: renamed option `strict` => `lowS`\n- `getSharedSecret`: defaults to compressed sigs (use third argument to adjust)\n- `recoverPublicKey(msg, sig, rec)` was changed to `sig.recoverPublicKey(msg)`\n- `Point` (2d xy) has been changed to `ProjectivePoint` (3d xyz)\n\ned25519:\n\n- `Signature` was removed in favor of raw bytes\n- `getSharedSecret` was moved to `x25519` module\n\nbls12-381:\n\n- Renamed PointG1 -> G1.Point, PointG2 -> G2.Point\n- Renamed PointG2.fromSignature -> Signature.decode, PointG2.toSignature -> Signature.encode\n\n## Contributing & testing\n\n- `npm install && npm run build && npm test` will build the code and run tests.\n- `npm run lint` / `npm run format` will run linter / fix linter issues.\n- `npm run bench` will run benchmarks\n- `npm run bundle` will build single file\n\nSee [paulmillr.com/noble](https://paulmillr.com/noble/)\nfor useful resources, articles, documentation and demos\nrelated to the library.\n\nMuSig2 signature scheme and BIP324 ElligatorSwift mapping for secp256k1\nare available [in a separate package](https://github.com/paulmillr/scure-btc-signer).\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2022 Paul Miller [(https://paulmillr.com)](https://paulmillr.com)\n\nSee LICENSE file.\n","publish_time":1755268716878,"_cnpm_publish_time":1755268716878,"dist-tags":{"latest":"2.4.0"}}