{"_id":"@noble/curves@2.4.0","bugs":{"url":"https://github.com/paulmillr/noble-curves/issues"},"dist":{"shasum":"367c869bfd790c3a2248152562f255b5f8898b74","tarball":"http://registry-npm.ywwl.com/@noble/curves/download/@noble/curves-2.4.0.tgz","integrity":"sha512-P4/62zrgfH33CneE3Dn4WhJVA22YUU0eR51wKIan4NVRvwsA0YnPTwWGpNbpuacSujmSFLvyzpyuR30+fbq2Ew==","fileCount":72,"unpackedSize":1590210,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@noble%2fcurves@2.4.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQC2ZQZDA+Hj07qenHW3BdNvK7cBxuaxH+S5RuMLQa+zNQIhAOfm9vDtM9ZeSzYqx1TUl6tnuO7qd6B3ANkCseO+Rt0M"}],"size":413451,"noattachment":false,"key":"/@noble/curves/-/@noble/curves-2.4.0.tgz"},"main":"index.js","name":"@noble/curves","type":"module","types":"index.d.ts","author":{"url":"https://paulmillr.com","name":"Paul Miller"},"module":"index.js","engines":{"node":">= 20.19.0"},"exports":{".":"./index.js","./misc.js":"./misc.js","./nist.js":"./nist.js","./bn254.js":"./bn254.js","./ed448.js":"./ed448.js","./utils.js":"./utils.js","./ed25519.js":"./ed25519.js","./bls12-381.js":"./bls12-381.js","./secp256k1.js":"./secp256k1.js","./webcrypto.js":"./webcrypto.js","./abstract/bls.js":"./abstract/bls.js","./abstract/der.js":"./abstract/der.js","./abstract/fft.js":"./abstract/fft.js","./abstract/oprf.js":"./abstract/oprf.js","./abstract/curve.js":"./abstract/curve.js","./abstract/frost.js":"./abstract/frost.js","./abstract/tower.js":"./abstract/tower.js","./abstract/edwards.js":"./abstract/edwards.js","./abstract/modular.js":"./abstract/modular.js","./abstract/poseidon.js":"./abstract/poseidon.js","./abstract/montgomery.js":"./abstract/montgomery.js","./abstract/weierstrass.js":"./abstract/weierstrass.js","./abstract/hash-to-curve.js":"./abstract/hash-to-curve.js"},"funding":"https://paulmillr.com/funding/","gitHead":"656c4364dffa44c64aa0c49914b8000b278b67a9","license":"MIT","scripts":{"test":"node --no-warnings test/index.ts","build":"tsc","check":"jsbt-check","format":"prettier --write 'src/**/*.{js,ts}' 'test/*.{js,ts}'","test:bun":"bun test/index.ts","benchmark":"node benchmark/main.ts","test:deno":"deno --allow-env --allow-read test/index.ts","test:slow":"node test/slow-curves.test.ts","build:clean":"rm {.,abstract}/*.{js,d.ts} 2> /dev/null","benchmark:ct":"node benchmark/ct.ts"},"version":"2.4.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:3c7a6933-7d25-414c-b383-038f56db5dda"},"approver":{"name":"paulmillr","email":"paul@paulmillr.com"}},"homepage":"https://paulmillr.com/noble/","keywords":["cryptography","secp256k1","ed25519","p256","p384","p521","secp256r1","ed448","x25519","ed25519","bls12-381","bn254","alt_bn128","bls","noble","ecc","ecdsa","eddsa","oprf","schnorr","fft"],"repository":{"url":"git+https://github.com/paulmillr/noble-curves.git","type":"git"},"_npmVersion":"12.0.2","description":"Audited & minimal JS implementation of elliptic curve cryptography","directories":{},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"sideEffects":false,"_nodeVersion":"24.19.0","dependencies":{"@noble/hashes":"2.4.0"},"devDependencies":{"bismar":"0.1.8","prettier":"3.9.6","fast-check":"4.2.0","typescript":"6.0.3","@types/node":"26.2.0","@paulmillr/jsbt":"0.7.1"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/curves_2.4.0_1787840886929_0.25592427145736796"},"_hasShrinkwrap":false,"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```js\n// import * from '@noble/curves'; // Error: use sub-imports, to ensure small app size\nimport { secp256k1 } from '@noble/curves/secp256k1.js';\nconst { secretKey, publicKey } = secp256k1.keygen();\nconst msg = new TextEncoder().encode('hello noble');\nconst sig = secp256k1.sign(msg, secretKey);\nconst isValid = secp256k1.verify(sig, msg, publicKey);\n```\n\n- [ECDSA, EdDSA, Schnorr signatures](#ecdsa-eddsa-schnorr-signatures)\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- [hash-to-curve: hashing to curve points](#hash-to-curve-hashing-to-curve-points)\n- [OPRFs](#oprfs) | [FROST threshold signatures](#frost-threshold-signatures)\n- [poseidon: Poseidon hash](#poseidon-poseidon-hash) | [fft: Fast Fourier Transform](#fft-fast-fourier-transform) | [utils](#utils-byte-shuffling-conversion)\n- Internals: [Point math](#elliptic-curve-point-math) | [modular](#modular-modular-arithmetics--finite-fields) | [custom curves](#weierstrass-custom-weierstrass-curve--ecdsa)\n- [Specs](#specs)\n- [Security](#security) | [Speed](#speed) | [Upgrading](#upgrading) | [Contributing & testing](#contributing--testing) | [License](#license)\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\nMessages are always hashed first: see [prehashed signing](#prehashed-signing).\nECDSA uses deterministic k, EdDSA follows RFC 8032, Schnorr (secp256k1-only) follows BIP 340: see [Specs](#specs).\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#### 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\nBy default (`prehash: true`), sign() and verify() apply the curve's built-in hash to the message first:\nsha256 for secp256k1, sha512 for p521. `prehash: false` allows using a custom hash\n(e.g. secp256k1 + keccak_256). In noble-curves v1, `prehash: false` was the default.\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 is only supported with ECDSA. It is a simple math operation:\nthere are no guarantees the signing was actually done. A forged (r, s, h) recovers into\na random public key, but it's not feasible 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\nBy default, ECDSA signatures are deterministic (RFC 6979). Purely deterministic signatures are\nvulnerable to fault attacks, so newer schemes, such as BIP340 schnorr, incorporate randomness\ninto sig generation - a.k.a. hedging. `extraEntropy` enables hedged mode. For more info, check out\n[Deterministic signatures are not your friends](https://paulmillr.com/posts/deterministic-signatures/).\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* `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 / FIPS 186-5 verification and adds SBS-based\n  non-repudiation, which is useful for contract signing, e-voting and blockchains.\n\nBoth modes have SUF-CMA (strong unforgeability under chosen message attacks);\nmost other libraries have neither SUF-CMA nor SBS.\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 { x25519 } from '@noble/curves/ed25519.js';\nconst alice = x25519.keygen();\nconst bob = x25519.keygen();\nconst sharedKey = x25519.getSharedSecret(alice.secretKey, bob.publicKey);\n// Same API: secp256k1, p256, p384, p521, x448\n\n// converting ed25519 keys to x25519\nimport { ed25519 } from '@noble/curves/ed25519.js';\nconst alice2 = ed25519.keygen();\nconst bob2 = ed25519.keygen();\nconst aliceSecX = ed25519.utils.toMontgomerySecret(alice2.secretKey);\nconst bobPubX = ed25519.utils.toMontgomery(bob2.publicKey);\nconst sharedKey2 = 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```js\nimport { ed25519, x25519 } from '@noble/curves/webcrypto.js';\n\n// signatures: p256, p384, p521, ed25519, ed448\nconst keys = await ed25519.keygen();\nconst msg = new TextEncoder().encode('hello noble');\nconst sig = await ed25519.sign(msg, keys.secretKey);\nconst isValid = await ed25519.verify(sig, msg, keys.publicKey);\n\n// ECDH: p256, p384, p521, x25519, x448\nconst alice = await x25519.keygen();\nconst bob = await x25519.keygen();\nconst shared = await x25519.getSharedSecret(alice.secretKey, bob.publicKey);\n\n// key conversion between noble (raw) and webcrypto (pkcs8 / spki) formats\nimport { p256 as p256n } from '@noble/curves/nist.js';\nimport { p256 } from '@noble/curves/webcrypto.js';\nconst nobleKeys = p256n.keygen();\nconst secretKeyPkcs8 = await p256.utils.convertSecretKey(nobleKeys.secretKey, 'raw', 'pkcs8');\nconst publicKeySpki = await p256.utils.convertPublicKey(nobleKeys.publicKey, 'raw', 'spki');\n```\n\nA thin wrapper over built-in WebCrypto, mirroring the noble API. Methods are always async;\nruntime support varies - check with `await curve.isSupported()`.\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();\nconst msg = new TextEncoder().encode('hello noble');\nconst msgp = blsl.hash(msg); // hash to point, default DST\nconst msgpd = blsl.hash(msg, 'BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_'); // custom DST (Ethereum)\nconst signature = blsl.sign(msgp, secretKey);\nconst isValid = blsl.verify(signature, msgp, publicKey);\n\n// G1 sigs, G2 pubkeys: identical API\nconst blss = bls12_381.shortSignatures;\n\n// Aggregation\nconst aggregatedKey = blsl.aggregatePublicKeys([\n  blsl.getPublicKey(bls12_381.utils.randomSecretKey()),\n  blsl.getPublicKey(bls12_381.utils.randomSecretKey()),\n]);\n// const aggregatedSig = blsl.aggregateSignatures(sigs)\n\n// Pairings: bls12_381.pairing(PointG1, PointG2)\n// Fields: bls12_381.fields.Fp, Fp2, Fp12, Fr\n```\n\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 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):\ncheck out [the implementation of bn254 EVM precompiles](https://github.com/paulmillr/noble-curves/blob/3ed792f8ad9932765b84d1064afea8663a255457/test/bn254.test.js#L697).\nbn254 points don't implement toBytes, [because there is no serialization standard](https://github.com/privacy-scaling-explorations/halo2curves/issues/109):\nimplementations diverge on endianness, flags and G2 imaginary-part order.\nInitialize points from bigints instead.\n\n### hash-to-curve: hashing to curve points\n\n```ts\nimport { secp256k1_hasher } from '@noble/curves/secp256k1.js';\n\nconst msg = Uint8Array.from([0xca, 0xfe, 0x01, 0x23]);\nconst point = secp256k1_hasher.hashToCurve(msg);\nconst pointDst = secp256k1_hasher.hashToCurve(msg, { DST: 'hello noble' });\nconst pointNu = secp256k1_hasher.encodeToCurve(msg);\nconst scalar = secp256k1_hasher.hashToScalar(msg);\n\n// Same API: p256_hasher, p384_hasher, p521_hasher (nist.js),\n// ed25519_hasher, ristretto255_hasher (ed25519.js), ed448_hasher, decaf448_hasher (ed448.js),\n// bls12_381.G1, bls12_381.G2.\n// ristretto255 & decaf448 also provide deriveToCurve.\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`_hasher` namespaces are separate from curves for tree-shaking:\nusers 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```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 (above) or with DKG (distributed key generation).\nDKG has three rounds: participants commit to key generation, exchange private shares,\nthen derive final participant keys - see `DKG.round1` / `round2` / `round3` usage in\n[the tests](./test/rfc9591-frost.test.ts).\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\nNTT / FFT (Fast Fourier Transform) over finite fields.\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 { secp256k1 } from '@noble/curves/secp256k1.js';\nconst { Point } = secp256k1;\nconst { BASE, ZERO, Fp, Fn } = Point;\nconst p = BASE.multiply(2n);\n\n// Math\nconst p1 = p.add(p);\nconst p2 = p.double();\nconst p3 = p.subtract(p);\nconst p4 = p.negate();\nconst p5 = p.multiply(451n);\n\n// MSM (multi-scalar multiplication)\nimport { pippenger } from '@noble/curves/abstract/curve.js';\nconst pa = [BASE, BASE.multiply(2n), BASE.multiply(4n), BASE.multiply(8n)];\nconst p6 = pippenger(Point, pa, [3n, 5n, 7n, 11n]); // == BASE.multiply(129n)\n\n// Cofactor\nconst pcl = p.clearCofactor();\nconst isTorsionFree = p.isTorsionFree();\n\n// Conversions\nconst bytes = p.toBytes();\nconst p_ = Point.fromBytes(bytes);\nconst { x, y } = p.toAffine();\nconst p__ = Point.fromAffine({ x, y });\n```\n\nEvery curve exposes its Point class: secp256k1, schnorr, p256, p384, p521, ed25519, ed448,\nristretto255, decaf448, bls12_381.G1 / G2, bn254.G1, jubjub, babyjubjub.\nWeierstrass points use projective (homogeneous) coordinates `new Point(X, Y, Z)`,\nedwards points use extended coordinates `new Point(X, Y, Z, T)`; both with x=X/Z, y=Y/Z.\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 & ECDSA\n\n```js\nimport { weierstrass, ecdsa } from '@noble/curves/abstract/weierstrass.js';\nimport { sha256 } from '@noble/hashes/sha2.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);\nconst p192 = ecdsa(p192_Point, sha256);\n\nconst keys = p192.keygen();\nconst msg = new TextEncoder().encode('custom curve');\nconst sig = p192.sign(msg, keys.secretKey);\nconst isValid = p192.verify(sig, msg, keys.publicKey);\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, and returns a Point class.\n`ecdsa` combines a Point class with a hash function into a signature scheme.\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### Specs\n\n- ECDSA: deterministic k from [RFC 6979](https://www.rfc-editor.org/rfc/rfc6979),\n  hedged signatures from [cfrg-det-sigs-with-noise draft](https://datatracker.ietf.org/doc/draft-irtf-cfrg-det-sigs-with-noise/)\n- EdDSA: [RFC 8032](https://www.rfc-editor.org/rfc/rfc8032),\n  [FIPS 186-5](https://csrc.nist.gov/publications/detail/fips/186/5/final);\n  consensus-friendly verification: [ZIP215](https://zips.z.cash/zip-0215)\n- Schnorr signatures: [BIP 340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki)\n- X25519, X448 ECDH: [RFC 7748](https://www.rfc-editor.org/rfc/rfc7748)\n- ristretto255, decaf448: [RFC 9496](https://www.rfc-editor.org/rfc/rfc9496)\n- hash-to-curve: [RFC 9380](https://www.rfc-editor.org/rfc/rfc9380)\n- OPRFs: [RFC 9497](https://www.rfc-editor.org/rfc/rfc9497)\n- FROST: [RFC 9591](https://www.rfc-editor.org/rfc/rfc9591)\n- bn254: [EIP-196](https://eips.ethereum.org/EIPS/eip-196), [EIP-197](https://eips.ethereum.org/EIPS/eip-197)\n- Poseidon: [site](https://www.poseidon-hash.info)\n\n## Security\n\nThe library has been audited:\n\n- at version 2.3.0, in Aug 2026, by [Trail of Bits](https://www.trailofbits.com), in collaboration with OpenAI\n  - It was done during \"Patch the Planet\" initiative\n  - Scope: everything\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  - 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  - 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  - 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\nWe've started regular AI-assisted self-audits in Apr 2026.\n\nIt is tested against property-based, cross-library and Wycheproof vectors,\nand is being fuzzed in github ci.\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 benchmark\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# algorithm=getPublicKey\ned25519                    7,299 ops/sec · 137 μs/op\nsecp256k1                  4,872 ops/sec · 205 μs/op · -1.5x\np256                       4,724 ops/sec · 212 μs/op · -1.5x\nbls12_381 (long, G2 sig)   3,466 ops/sec · 288 μs/op · -2.1x\ned448                      3,224 ops/sec · 310 μs/op · -2.3x\np384                       2,185 ops/sec · 458 μs/op · -3.3x\np521                       1,221 ops/sec · 819 μs/op · -6x\nbls12_381 (short, G1 sig)  1,070 ops/sec · 934 μs/op · -6.8x\n\n# algorithm=sign\nsecp256k1                  4,217 ops/sec · 237 μs/op\np256                       4,116 ops/sec · 243 μs/op · ≈\ned25519                    3,536 ops/sec · 283 μs/op · -1.2x\np384                       1,992 ops/sec · 502 μs/op · -2.1x\ned448                      1,577 ops/sec · 634 μs/op · -2.7x\np521                       1,131 ops/sec · 884 μs/op · -3.7x\nbls12_381 (short, G1 sig)  417 ops/sec · 2.39 ms/op · -10x\nbls12_381 (long, G2 sig)   112 ops/sec · 8.88 ms/op · -37x\n\n# algorithm=verify\ned25519                    1,504 ops/sec · 665 μs/op\nsecp256k1                  1,352 ops/sec · 739 μs/op · -1.1x\np256                       917 ops/sec · 1.09 ms/op · -1.6x\ned448                      546 ops/sec · 1.83 ms/op · -2.8x\np384                       381 ops/sec · 2.62 ms/op · -3.9x\np521                       187 ops/sec · 5.34 ms/op · -8x\nbls12_381 (short, G1 sig)  100 ops/sec · 9.98 ms/op · -15x\nbls12_381 (long, G2 sig)   77 ops/sec · 12.9 ms/op · -19x\n\n# algorithm=getSharedSecret\ned25519                    1,695 ops/sec · 590 μs/op\nsecp256k1                  763 ops/sec · 1.31 ms/op · -2.2x\np256                       737 ops/sec · 1.36 ms/op · -2.3x\ned448                      599 ops/sec · 1.67 ms/op · -2.8x\np384                       326 ops/sec · 3.06 ms/op · -5.2x\np521                       176 ops/sec · 5.68 ms/op · -9.6x\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### v1 to 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\n**Upgrade path:** upgrade to curves v1.9.x first. Fix the deprecation warnings, then switch to v2.\n\nModules:\n\n- The package is now ESM-only. ESM can finally be loaded from common.js on node v20.19+\n- `.js` extension is now required: `@noble/curves/ed25519` => `@noble/curves/ed25519.js`.\n  This enables native browser usage, without transpilers\n- `p256`, `p384`, `p521` were moved into `nist`; `jubjub` was moved into `misc`\n- `pasta` and `bn254_weierstrass` (NOT pairing-based bn254) curves were removed\n\nNew features:\n\n- webcrypto: friendly noble-like wrapper over built-in WebCrypto\n- oprf: RFC 9497 OPRFs (oblivious pseudorandom functions)\n  for p256, p384, p521, ristretto255 and decaf448\n- weierstrass, edwards: new `isValidSecretKey`, `isValidPublicKey` methods\n- misc: Brainpool curves brainpoolP256r1, brainpoolP384r1, brainpoolP512r1\n- Massively improved, more descriptive error messages\n\nBreaking changes:\n\n- Most methods now only accept Uint8Array; string hex inputs are prohibited.\n  This simplifies reasoning, improves security and reduces malleability.\n  `Point.fromHex` is now string-only: use `Point.fromBytes` for Uint8Array\n- ECDSA (secp256k1, p256, p384...) sign & verify:\n    - **Prehashed messages**: methods now expect the unhashed message\n      instead of messageHash. Old behavior: `{prehash: false}`\n    - **lowS signatures** by default. secp256k1 is unaffected: it has used\n      lowS since the beginning. Old behavior: `{lowS: false}`\n    - **Uint8Array signatures** (format: 'compact') by default\n    - verify: **der format must be explicitly specified** in `{format: 'der'}`.\n      This reduces malleability\n    - verify: **Signature instances are prohibited**: call `signature.toBytes()` first\n- BLS signatures (bls12-381, bn254):\n    - getPublicKey, sign, verify, signShortSignature etc were moved into two new namespaces:\n      `longSignatures` (G1 pubkeys, G2 sigs) and `shortSignatures` (G1 sigs, G2 pubkeys)\n    - verifyBatch now expects array of inputs `{message: ..., publicKey: ...}[]`\n- Custom curves:\n    - Curve creation was massively simplified and split into point creation &\n      sig generator creation: `weierstrass() + ecdsa()` / `edwards() + eddsa()`.\n      weierstrass / edwards expect simplified curve params (Fp became p);\n      ecdsa / eddsa expect Point class and hash\n    - pippenger: removed unnecessary Fn argument\n    - Field#fromBytes() now validates elements to be in 0..order-1 range\n\nRenamings (curves v1.9 highlights old names as deprecated):\n\n- Points\n    - ExtendedPoint, ProjectivePoint => Point\n    - Point coordinates px/ex, py/ey, pz/ez, et => X, Y, Z, T\n    - toRawBytes, fromRawBytes => toBytes, fromBytes\n    - Point.normalizeZ, Point.msm => separate methods in `abstract/curve.js` submodule\n    - Point.fromPrivateKey(key) => `Point.BASE.multiply(Point.Fn.fromBytes(key))`\n    - `CURVE` property with all kinds of random stuff => Point.CURVE(),\n      which only provides curve parameters\n    - RistrettoPoint => ristretto255.Point, DecafPoint => decaf448.Point\n- ECDSA Signatures\n    - toCompactRawBytes, toDERRawBytes => toBytes('compact'), toBytes('der')\n    - toCompactHex, toDERHex => toHex('compact'), toHex('der')\n    - fromCompact, fromDER => fromBytes(bytes, format), fromHex(hex, format)\n- utils\n    - randomPrivateKey => randomSecretKey\n    - normPrivateKeyToScalar => Point.Fn.fromBytes\n    - utils.precompute, Point#_setWindowSize => Point#precompute\n    - edwardsToMontgomery, edwardsToMontgomeryPriv => utils.toMontgomery, utils.toMontgomerySecret\n- Curve-specific hash-to-curve methods => `*curve*_hasher`.\n  Example: `secp256k1.hashToCurve` => `secp256k1_hasher.hashToCurve()`\n- Massive type renamings and improvements\n\nRemoved features: Point#multiplyAndAddUnsafe, Point#hasEvenY, Field.MASK\n\n## Contributing & testing\n\n`npm install && npm run build && npm test` will build the code and run tests.\n\nThere are **additional** suites: slow large-scalar / large-curve tests `npm run test:slow`,\nand the constant-timeness harness `npm run benchmark:ct`.\n\nSee [paulmillr.com/noble](https://paulmillr.com/noble/) for useful resources, articles,\ndocumentation and demos related to the library.\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":1787840887012,"_cnpm_publish_time":1787840887012,"dist-tags":{"latest":"2.4.0"}}