{"name":"@noble/ed25519","version":"1.6.0","description":"Fastest JS implementation of ed25519. Independently audited, high-security, 0-dependency EDDSA, X25519 ECDH, ristretto255 & scalarmult","main":"lib/index.js","module":"lib/esm/index.js","types":"lib/index.d.ts","scripts":{"build":"tsc -d && tsc -p tsconfig.esm.json","build:release":"rollup -c rollup.config.js","lint":"prettier --print-width 100 --single-quote --check index.ts","test":"jest","bench":"node test/benchmark.js"},"author":{"name":"Paul Miller","url":"https://paulmillr.com"},"homepage":"https://paulmillr.com/noble/","repository":{"type":"git","url":"git+https://github.com/paulmillr/noble-ed25519.git"},"license":"MIT","browser":{"crypto":false},"devDependencies":{"@rollup/plugin-node-resolve":"^13.0.0","@types/jest":"^27","@types/node":"^16","fast-check":"^2.14.0","jest":"^27.4.5","micro-bmark":"^0.1.3","prettier":"^2.5.1","rollup":"^2.62.0","ts-jest":"^27.1.2","typescript":"4.5.4"},"keywords":["ed25519","edwards","ristretto255","decaf","curve25519","x25519","elliptic","elliptic curve","curve","elligator","signature","ecc","eddsa","RFC7748","RFC8032","ZIP215","cryptography","security"],"exports":{".":{"import":"./lib/esm/index.js","default":"./lib/index.js"},"./index.d.ts":"./lib/index.d.ts"},"jest":{"testRegex":"/test/.*.ts","transform":{"^.+\\.ts$":"ts-jest"},"useStderr":true,"bail":2},"funding":[{"type":"individual","url":"https://paulmillr.com/funding/"}],"gitHead":"edeb48a685c386b8b2d5b4be6b7dc5c432839e05","bugs":{"url":"https://github.com/paulmillr/noble-ed25519/issues"},"_id":"@noble/ed25519@1.6.0","_nodeVersion":"17.4.0","_npmVersion":"8.4.0","dist":{"integrity":"sha512-UKju89WV37IUALIMfKhKW3psO8AqmrE/GvH6QbPKjzolQ98zM7WmGUeY+xdIgSf5tqPFf75ZCYMgym6E9Jsw3Q==","shasum":"b55f7c9e532b478bf1d7c4f609e1f3a37850b583","tarball":"http://registry-npm.ywwl.com/@noble/ed25519/download/@noble/ed25519-1.6.0.tgz","fileCount":7,"unpackedSize":77957,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJiCn3dCRA9TVsSAnZWagAAJV0P/2ojuZTPgap3kLPAGnxE\ncjTBFg/x2R1wZ4JiDQZ/1VYBFUpSmSzmNJ+VaWkYnwHgsl3WtacVIKucI6+I\nBFVy6XDqGn6Cueeag+b3GOF6/Lh7cUE4e31UHXiUA/XjzhG3z8GIzhn8z/YV\ngSpvhezhll02SiDnN9IgRVSVVlIiO96VgnTZx5kXH06RMFdRsOOoM++5iZV1\nTM1iliP8oD+I6xC90FZYy5n3n57Hu6WvlZ7SRc8oFpAC2YhLN6gMFvWtube+\noHg38ciCJhWSNfA5P5aAPsTj3m1ZjTrklNhnDy92CsoBiJrJhznHBbQWFdgd\nBYYmk96qzAtXc6xtlu5VldEYpnXy9rxwbUaEGf3UNy0UyILQm9jRv0Q7iB2J\nt9HUf0nh8q4Jw0VxMj6cu8niO/ACks25rllkrDANdA70dljCCkOnhmk0DjOy\ngF7XyALAnAAh1l6h+6m1VIos0bDOqW1h53FzN9uy8ZCCjL4Oa9G3X5WRSnTg\n0qyLBS7qIsyqieTyrBqyTs2IiEBJKasIrux7z5zBWiQXvBEVUJ3zwuFsn0L8\nKVLR2S7pB3JNJEnbmQ3gXWu6hYLffl/a7NMeVqxI9LYk5kWoW1bxtsW82+pO\njHg/KCGOCIfaTjJIitpO+mt7dDK9+5BAYCE1kul5mbfmQpBur5eZJEr6WXSI\nzF0P\r\n=AiEs\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCHszeN4/GqNkcYWGwzqa0+rS0ozY6jIPvPivS9FxaAdwIgQlDf5xOmIZ8SIygCfadr4X8cfnZIuo+XcpPKqo6e1Yc="}],"size":15890,"noattachment":false,"key":"/@noble/ed25519/-/@noble/ed25519-1.6.0.tgz"},"_npmUser":{"name":"paulmillr","email":"paul@paulmillr.com"},"directories":{},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ed25519_1.6.0_1644854749283_0.3045502345031963"},"_hasShrinkwrap":false,"readme":"# noble-ed25519\n\nFastest 4KB JS implementation of ed25519 signatures.\n\n- ✍️ [EDDSA](https://en.wikipedia.org/wiki/EdDSA) signatures compliant with [RFC8032](https://tools.ietf.org/html/rfc8032),\n  FIPS 186-5\n- 🪢 Consensus-friendly, compliant with [ZIP215](https://zips.z.cash/zip-0215)\n- 🔖 SUF-CMA (strong unforgeability under chosen message attacks) and SBS (non-repudiation / exclusive ownership)\n- 📦 Pure ESM, can be imported without transpilers\n- 🪶 4KB gzipped, 350 lines of code\n\nUse larger drop-in replacement [noble-curves](https://github.com/paulmillr/noble-curves) instead,\nif you need additional features such as common.js support, ristretto255, X25519, curve25519, ed25519ph, ed25519ctx.\nTo upgrade from v1 to v2, see [Upgrading](#upgrading). [Online demo](https://paulmillr.com/noble/).\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 with provenance\n- Check out [homepage](https://paulmillr.com/noble/) & 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  4kb [secp256k1](https://github.com/paulmillr/noble-secp256k1) /\n  [ed25519](https://github.com/paulmillr/noble-ed25519)\n\n## Usage\n\n> npm install @noble/ed25519\n\nWe support all major platforms and runtimes. For node.js <= 18 and React Native, additional polyfills are needed: see below.\n\n```js\nimport * as ed from '@noble/ed25519';\n// import * as ed from \"https://deno.land/x/ed25519/mod.ts\"; // Deno\n// import * as ed from \"https://unpkg.com/@noble/ed25519\"; // Unpkg\n(async () => {\n  // keys, messages & other inputs can be Uint8Arrays or hex strings\n  // Uint8Array.from([0xde, 0xad, 0xbe, 0xef]) === 'deadbeef'\n  const privKey = ed.utils.randomPrivateKey(); // Secure random private key\n  const message = Uint8Array.from([0xab, 0xbc, 0xcd, 0xde]);\n  const pubKey = await ed.getPublicKeyAsync(privKey); // Sync methods below\n  const signature = await ed.signAsync(message, privKey);\n  const isValid = await ed.verifyAsync(signature, message, pubKey);\n})();\n```\n\nAdditional polyfills for some environments:\n\n```ts\n// 1. Enable synchronous methods.\n// Only async methods are available by default, to keep the library dependency-free.\nimport { sha512 } from '@noble/hashes/sha512';\ned.etc.sha512Sync = (...m) => sha512(ed.etc.concatBytes(...m));\n// Sync methods can be used now:\n// ed.getPublicKey(privKey); ed.sign(msg, privKey); ed.verify(signature, msg, pubKey);\n\n// 2. node.js 18 and older, requires polyfilling globalThis.crypto\nimport { webcrypto } from 'node:crypto';\n// @ts-ignore\nif (!globalThis.crypto) globalThis.crypto = webcrypto;\n\n// 3. React Native needs crypto.getRandomValues polyfill and sha512\nimport 'react-native-get-random-values';\nimport { sha512 } from '@noble/hashes/sha512';\ned.etc.sha512Sync = (...m) => sha512(ed.etc.concatBytes(...m));\ned.etc.sha512Async = (...m) => Promise.resolve(ed.etc.sha512Sync(...m));\n```\n\n## API\n\nThere are 3 main methods: `getPublicKey(privateKey)`, `sign(message, privateKey)`\nand `verify(signature, message, publicKey)`. We accept Hex type everywhere:\n\n```ts\ntype Hex = Uint8Array | string\n```\n\n### getPublicKey\n\n```typescript\nfunction getPublicKey(privateKey: Hex): Uint8Array;\nfunction getPublicKeyAsync(privateKey: Hex): Promise<Uint8Array>;\n```\n\nGenerates 32-byte public key from 32-byte private key.\n- Some libraries have 64-byte private keys. Don't worry, those are just\n  priv+pub concatenated. Slice it: `priv64b.slice(0, 32)`\n- Use `Point.fromPrivateKey(privateKey)` if you want `Point` instance instead\n- Use `Point.fromHex(publicKey)` if you want to convert hex / bytes into Point.\n  It will use decompression algorithm 5.1.3 of RFC 8032.\n- Use `utils.getExtendedPublicKey` if you need full SHA512 hash of seed\n\n### sign\n\n```ts\nfunction sign(\n  message: Hex, // message which would be signed\n  privateKey: Hex // 32-byte private key\n): Uint8Array;\nfunction signAsync(message: Hex, privateKey: Hex): Promise<Uint8Array>;\n```\n\nGenerates EdDSA signature. Always deterministic.\n\nAssumes unhashed `message`: it would be hashed by ed25519 internally.\nFor prehashed ed25519ph, switch to noble-curves.\n\n### verify\n\n```ts\nfunction verify(\n  signature: Hex, // returned by the `sign` function\n  message: Hex, // message that needs to be verified\n  publicKey: Hex // public (not private) key,\n  options = { zip215: true } // ZIP215 or RFC8032 verification type\n): boolean;\nfunction verifyAsync(signature: Hex, message: Hex, publicKey: Hex): Promise<boolean>;\n```\n\nVerifies EdDSA signature. Has SUF-CMA (strong unforgeability under chosen message attacks).\nBy default, follows ZIP215 [1] and can be used in consensus-critical apps [2].\n`zip215: false` option switches verification criteria to strict\nRFC8032 / FIPS 186-5 and provides non-repudiation with SBS (Strongly Binding Signatures) [3].\n\n[1]: https://zips.z.cash/zip-0215\n[2]: https://hdevalence.ca/blog/2020-10-04-its-25519am\n[3]: https://eprint.iacr.org/2020/1244\n\n### utils\n\nA bunch of useful **utilities** are also exposed:\n\n```typescript\nconst etc: {\n  bytesToHex: (b: Bytes) => string;\n  hexToBytes: (hex: string) => Bytes;\n  concatBytes: (...arrs: Bytes[]) => Uint8Array;\n  mod: (a: bigint, b?: bigint) => bigint;\n  invert: (num: bigint, md?: bigint) => bigint;\n  randomBytes: (len: number) => Bytes;\n  sha512Async: (...messages: Bytes[]) => Promise<Bytes>;\n  sha512Sync: Sha512FnSync;\n};\nconst utils: {\n  getExtendedPublicKeyAsync: (priv: Hex) => Promise<ExtK>;\n  getExtendedPublicKey: (priv: Hex) => ExtK;\n  precompute(p: Point, w?: number): Point;\n  randomPrivateKey: () => Bytes; // Uses CSPRNG https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues\n};\n\nclass ExtendedPoint { // Elliptic curve point in Extended (x, y, z, t) coordinates.\n  constructor(ex: bigint, ey: bigint, ez: bigint, et: bigint);\n  static readonly BASE: Point;\n  static readonly ZERO: Point;\n  static fromAffine(point: AffinePoint): ExtendedPoint;\n  static fromHex(hash: string);\n  get x(): bigint;\n  get y(): bigint;\n  // Note: It does not check whether the `other` point is valid point on curve.\n  add(other: ExtendedPoint): ExtendedPoint;\n  equals(other: ExtendedPoint): boolean;\n  isTorsionFree(): boolean; // Multiplies the point by curve order\n  multiply(scalar: bigint): ExtendedPoint;\n  subtract(other: ExtendedPoint): ExtendedPoint;\n  toAffine(): Point;\n  toRawBytes(): Uint8Array;\n  toHex(): string; // Compact representation of a Point\n}\n// Curve params\ned25519.CURVE.p // 2 ** 255 - 19\ned25519.CURVE.n // 2 ** 252 + 27742317777372353535851937790883648493\ned25519.ExtendedPoint.BASE // new ed25519.Point(Gx, Gy) where\n// Gx=15112221349535400772501151409588531511454012693041857206046113283949847762202n\n// Gy=46316835694926478169428394003475163141307993866256225615783033603165251855960n;\n```\n\n## Security\n\nThe library has not been independently audited as of v2, which is a rewrite of v1.\nv1 has been audited by [Cure53](https://cure53.de/pentest-report_ed25519.pdf) in Feb 2022.\n\nThe code is identical to [noble-curves](https://github.com/paulmillr/noble-curves), which *has* been audited.\n\nIt is tested against property-based, cross-library and Wycheproof vectors,\nand has fuzzing by [Guido Vranken's cryptofuzz](https://github.com/guidovranken/cryptofuzz).\n\n### Constant-timeness\n\n_JIT-compiler_ and _Garbage Collector_ make \"constant time\" extremely hard to\nachieve [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. Nonetheless we're targetting algorithmic constant time.\n\n### Supply chain security\n\n1. **Commits** are signed with PGP keys, to prevent forgery. Make sure to verify commit signatures.\n2. **Releases** are transparent and built on GitHub CI. Make sure to verify [provenance](https://docs.npmjs.com/generating-provenance-statements) logs\n3. **Rare releasing** is followed.\n   The less often it is done, the less code dependents would need to audit\n4. **Dependencies** are minimal:\n   - All deps are prevented from automatic updates and have locked-down version ranges. Every update is checked with `npm-diff`\n   - Updates themselves are rare, to ensure rogue updates are not catched accidentally\n5. devDependencies are only used if you want to contribute to the repo. They are disabled for end-users:\n   - [noble-hashes](https://github.com/paulmillr/noble-hashes) is used, by the same author, to provide hashing functionality tests\n   - micro-bmark and micro-should are developed by the same author and follow identical security practices\n   - fast-check (property-based testing) and typescript are used for code quality, vector generation and ts compilation.\n   The packages are big, which makes it hard to audit their source code thoroughly and fully\n\nWe consider infrastructure attacks like rogue NPM modules very important;\nthat's why it's crucial to minimize the amount of 3rd-party dependencies & native bindings.\nIf your app uses 500 dependencies, any dep could get hacked and you'll be\ndownloading malware with every install. Our goal is to minimize this attack vector.\n\nIf you see anything unusual: investigate and report.\n\n### Randomness\n\nWe're deferring to built-in\n[crypto.getRandomValues](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues)\nwhich is considered cryptographically secure (CSPRNG).\n\nIn the past, browsers had bugs that made it weak: it may happen again.\n\n## Speed\n\nBenchmarks done with Apple M2 on macOS 13 with Node.js 20.\n\n    getPublicKey(utils.randomPrivateKey()) x 9,173 ops/sec @ 109μs/op\n    sign x 4,567 ops/sec @ 218μs/op\n    verify x 994 ops/sec @ 1ms/op\n    Point.fromHex decompression x 16,164 ops/sec @ 61μs/op\n\nCompare to alternative implementations:\n\n    tweetnacl@1.0.3 getPublicKey x 1,808 ops/sec @ 552μs/op ± 1.64%\n    tweetnacl@1.0.3 sign x 651 ops/sec @ 1ms/op\n    ristretto255@0.1.2 getPublicKey x 640 ops/sec @ 1ms/op ± 1.59%\n    sodium-native#sign x 83,654 ops/sec @ 11μs/op\n\n## Contributing\n\n1. Clone the repository\n2. `npm install` to install build dependencies like TypeScript\n3. `npm run build` to compile TypeScript code\n4. `npm run test` to run tests\n\n## Upgrading\n\nnoble-ed25519 v2 features improved security and smaller attack surface.\nThe goal of v2 is to provide minimum possible JS library which is safe and fast.\n\nThat means the library was reduced 4x, to just over 300 lines. In order to\nachieve the goal, **some features were moved** to\n[noble-curves](https://github.com/paulmillr/noble-curves), which is\neven safer and faster drop-in replacement library with same API.\nSwitch to curves if you intend to keep using these features:\n\n- x25519 / curve25519 / getSharedSecret\n- ristretto255 / RistrettoPoint\n- Using `utils.precompute()` for non-base point\n- Support for environments which don't support bigint literals\n- Common.js support\n- Support for node.js 18 and older without [shim](#usage)\n\nOther changes for upgrading from @noble/ed25519 1.7 to 2.0:\n\n- Methods are now sync by default; use `getPublicKeyAsync`, `signAsync`, `verifyAsync` for async versions\n- `bigint` is no longer allowed in `getPublicKey`, `sign`, `verify`. Reason: ed25519 is LE, can lead to bugs\n- `Point` (2d xy) has been changed to `ExtendedPoint` (xyzt)\n- `Signature` was removed: just use raw bytes or hex now\n- `utils` were split into `utils` (same api as in noble-curves) and\n  `etc` (`sha512Sync` and others)\n\n## License\n\nMIT (c) 2019 Paul Miller [(https://paulmillr.com)](https://paulmillr.com), see LICENSE file.\n","publish_time":1644854749478,"_cnpm_publish_time":1644854749478,"dist-tags":{"latest":"3.2.0","legacy-v1":"1.7.5"}}