{"name":"noble-secp256k1","version":"0.2.2","description":"Noble secp256k1. High-security, easily auditable, 0-dep, 1-file pubkey & ECDSA.","main":"index.js","scripts":{"compile":"tsc -d","test":"jest"},"jest":{"testRegex":"/.*?\\.test.ts","transform":{"^.+\\.ts$":"ts-jest"}},"author":{"name":"Paul Miller","url":"https://paulmillr.com"},"homepage":"https://github.com/paulmillr/noble-secp256k1","repository":{"type":"git","url":"git+https://github.com/paulmillr/noble-secp256k1.git"},"license":"MIT","devDependencies":{"@types/jest":"^24.0.21","@types/node":"^12.12.5","fast-check":"^1.18.1","jest":"^24.9.0","ts-jest":"^24.1.0","typescript":"^3.6.4"},"keywords":["secp256k1","secp","elliptic","elliptic curve","curve","signature","ecc","ecdsa","cryptography","security","noble"],"gitHead":"0c0805b5621f8f67cd3a364bcbe8b5db10e5a414","bugs":{"url":"https://github.com/paulmillr/noble-secp256k1/issues"},"_id":"noble-secp256k1@0.2.2","_nodeVersion":"12.12.0","_npmVersion":"6.13.0","dist":{"integrity":"sha512-Fe2ZL+Y6WVuxy9AtxDDjnSbyQYK/yfAwO5VrJ+MxLCvKpj6STGW0qtMcZH61zCHnBIE0Xv3b+M5dFkGYmykr2A==","shasum":"dc3b5c81ca21a94cd0bdf3d5525f95d005610f2a","tarball":"http://registry-npm.ywwl.com/noble-secp256k1/download/noble-secp256k1-0.2.2.tgz","fileCount":5,"unpackedSize":22408,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdyFyACRA9TVsSAnZWagAA8TEQAIPtMuouzcr44LJVS2Kd\nlPwfY/o6aKql6IOiyXupICw0KYbCtVY6Q3hIVgABa4j9ObY0P4IaxHPmCvJu\nm3lTadG8erA6n5pmnjJr1Q+vnNCfy4LYjqCb7Zb1txWxRmUJu7FIiL684dnF\ncydpN6X+mmG2iMIINE0OQjPcbY6gb7NFWcOZBM0/0IC17bD2r5sW6XJCXmFB\nxGqZVW93W3yYQurYotF6hXyzFc6/9nRoVHfltCeAC+5isF/gaRdEMpSnSlGw\nNroYdvLDQGHoFngvnafUQhe8GBuGgzRrtfG2edaYhIEdsm3VySful4Tmv2pl\nR3iIyoW+pKI81MW2PCvRIFWnIwel9tvI3iRB8g3NPA7lWq0x38rySOESzpsY\naLlEdz9Yo5PohKnLRc5OoF8mSHed84fjCKhq54WLQ0Z3eNWBweQszlaiPHWd\nFZLCce/g4RvVvED/XEOPLQ0FkO3cwRXDaMWpp3r7Rqx1G4LEgXHIzjh6WBLu\ntmXotINVoJq2bjFjveK5GztOk8rTEN/YECdnhHpOFKZWFeCnXu2lk++X9AyC\nyic+Xp0aHcObbJzhthB0r2oLZEvyGDLWREUIRqtSozA0sammdSjT/oajecA3\nZezwUajBEtVBfSjqj9ypp5Biva7Jl6tWbgkhXg5aAyXAY0ljgQpinljp7j3V\ngbuq\r\n=mFiO\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD8/qy0tdidEvbdsaVsXm6mVXL0/JvIW+Oaqhq6SLactgIhAKqTMhESTMlM4P6dGWB088yeTrVGTmxw+MeAxeSZNWxc"}],"size":7193,"noattachment":false,"key":"/noble-secp256k1/-/noble-secp256k1-0.2.2.tgz"},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"_npmUser":{"name":"paulmillr","email":"paul@paulmillr.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/noble-secp256k1_0.2.2_1573411967572_0.8187794386614129"},"_hasShrinkwrap":false,"deprecated":"Switch to \"@noble/secp256k1\" for security updates","readme":"# noble-secp256k1 ![Node CI](https://github.com/paulmillr/noble-secp256k1/workflows/Node%20CI/badge.svg) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)\n\n[Fastest](#speed) JS implementation of [secp256k1](https://www.secg.org/sec2-v2.pdf),\nan elliptic curve that could be used for asymmetric encryption,\nECDH key agreement protocol and signature schemes. Supports deterministic **ECDSA** from RFC6979 and **Schnorr** signatures from BIP0340.\n\n[**Audited**](#security) with crowdfunding by an independent security firm. Tested against thousands of test vectors from a different library. Check out [the online demo](https://paulmillr.com/ecc) and blog post: [Learning fast elliptic-curve cryptography in JS](https://paulmillr.com/posts/noble-secp256k1-fast-ecc/)\n\n### This library belongs to *noble* crypto\n\n> **noble-crypto** — high-security, easily auditable set of contained cryptographic libraries and tools.\n\n- No dependencies, one small file\n- Easily auditable TypeScript/JS code\n- Supported in all major browsers and stable node.js versions\n- All releases are signed with PGP keys\n- Check out all libraries:\n  [secp256k1](https://github.com/paulmillr/noble-secp256k1),\n  [ed25519](https://github.com/paulmillr/noble-ed25519),\n  [bls12-381](https://github.com/paulmillr/noble-bls12-381),\n  [hashes](https://github.com/paulmillr/noble-hashes)\n\n## Usage\n\nUse NPM in node.js / browser, or include single file from\n[GitHub's releases page](https://github.com/paulmillr/noble-secp256k1/releases):\n\n> npm install noble-secp256k1\n\n```js\nimport * as secp from \"noble-secp256k1\";\n// if you're using single file, use global variable nobleSecp256k1 instead\n\n(async () => {\n  // You pass either a hex string, or Uint8Array\n  const privateKey = \"6b911fd37cdf5c81d4c0adb1ab7fa822ed253ab0ad9aa18d77257c88b29b718e\";\n  const messageHash = \"a33321f98e4ff1c283c76998f14f57447545d339b3db534c6d886decb4209f28\";\n  const publicKey = secp.getPublicKey(privateKey);\n  const signature = await secp.sign(messageHash, privateKey);\n  const isSigned = secp.verify(signature, messageHash, publicKey);\n\n  // Supports Schnorr signatures\n  const rpub = secp.schnorr.getPublicKey(privateKey);\n  const rsignature = await secp.schnorr.sign(messageHash, privateKey);\n  const risSigned = await secp.schnorr.verify(rsignature, messageHash, rpub);\n})();\n```\n\nDeno:\n\n```typescript\nimport * as secp from \"https://deno.land/x/secp256k1/mod.ts\";\nconst publicKey = secp.getPublicKey(\"6b911fd37cdf5c81d4c0adb1ab7fa822ed253ab0ad9aa18d77257c88b29b718e\");\n```\n\n## API\n\n- [`getPublicKey(privateKey)`](#getpublickeyprivatekey)\n- [`getSharedSecret(privateKeyA, publicKeyB)`](#getsharedsecretprivatekeya-publickeyb)\n- [`sign(hash, privateKey)`](#signhash-privatekey)\n- [`verify(signature, hash, publicKey)`](#verifysignature-hash-publickey)\n- [`recoverPublicKey(hash, signature, recovery)`](#recoverpublickeyhash-signature-recovery)\n- [`schnorr.getPublicKey(privateKey)`](#schnorrgetpublickeyprivatekey)\n- [`schnorr.sign(hash, privateKey)`](#schnorrsignhash-privatekey)\n- [`schnorr.verify(signature, hash, publicKey)`](#schnorrverifysignature-hash-publickey)\n- [Helpers](#helpers)\n\n##### `getPublicKey(privateKey)`\n```typescript\nfunction getPublicKey(privateKey: Uint8Array, isCompressed?: false): Uint8Array;\nfunction getPublicKey(privateKey: string, isCompressed?: false): string;\nfunction getPublicKey(privateKey: bigint): Uint8Array;\n```\n`privateKey` will be used to generate public key.\n  Public key is generated by doing scalar multiplication of a base Point(x, y) by a fixed\n  integer. The result is another `Point(x, y)` which we will by default encode to hex Uint8Array.\n`isCompressed` (default is `false`) determines whether the output should contain `y` coordinate of the point.\n\nTo get Point instance, use `Point.fromPrivateKey(privateKey)`.\n\n##### `getSharedSecret(privateKeyA, publicKeyB)`\n```typescript\nfunction getSharedSecret(privateKeyA: Uint8Array, publicKeyB: Uint8Array): Uint8Array;\nfunction getSharedSecret(privateKeyA: string, publicKeyB: string): string;\nfunction getSharedSecret(privateKeyA: bigint, publicKeyB: Point): Uint8Array;\n```\n\nComputes ECDH (Elliptic Curve Diffie-Hellman) shared secret between a private key and a different public key.\n\nTo get Point instance, use `Point.fromHex(publicKeyB).multiply(privateKeyA)`.\n\nTo speed-up the function massively by precomputing EC multiplications,\nuse `getSharedSecret(privateKeyA, secp.utils.precompute(8, publicKeyB))`\n\n\n##### `sign(hash, privateKey)`\n```typescript\nfunction sign(msgHash: Uint8Array, privateKey: Uint8Array, opts?: Options): Promise<Uint8Array>;\nfunction sign(msgHash: string, privateKey: string, opts?: Options): Promise<string>;\nfunction sign(msgHash: Uint8Array, privateKey: Uint8Array, opts?: Options): Promise<[Uint8Array | string, number]>;\n```\n\nGenerates deterministic ECDSA signature as per RFC6979.\n\n- `msgHash: Uint8Array | string` - message hash which would be signed\n- `privateKey: Uint8Array | string | bigint` - private key which will sign the hash\n- `options?: Options` - *optional* object related to signature value and format\n- `options?.recovered: boolean = false` - whether the recovered bit should be included in the result. In this case, the result would be an array of two items.\n- `options?.canonical: boolean = false` - whether a signature `s` should be no more than 1/2 prime order\n- `options?.der: boolean = true` - whether the returned signature should be in DER format. If `false`, it would be in Compact format (32-byte r + 32-byte s)\n\nThe function is asynchronous because we're utilizing built-in HMAC API to not rely on dependencies.\n\n`signSync` counterpart could also be used, you need to set `utils.hmacSha256Sync` to a function with signature `key: Uint8Array, ...messages: Uint8Array[]) => Uint8Array`. Example with `noble-hashes` package:\n\n```ts\nconst { hmac } = require('noble-hashes/lib/hmac');\nconst { sha256 } = require('noble-hashes/lib/sha256');\nsecp256k1.utils.hmacSha256Sync = (key: Uint8Array, ...msgs: Uint8Array[]) => {\n  const h = hmac.create(sha256, key);\n  msgs.forEach(msg => h.update(msg));\n  return h.digest();\n};\n\n// Can be used now\nsecp256k1.signSync(msgHash, privateKey)\n```\n\n##### `verify(signature, hash, publicKey)`\n```typescript\nfunction verify(signature: Uint8Array, msgHash: Uint8Array, publicKey: Uint8Array): boolean\nfunction verify(signature: string, msgHash: string, publicKey: string): boolean\n```\n- `signature: Uint8Array | string | { r: bigint, s: bigint }` - object returned by the `sign` function\n- `msgHash: Uint8Array | string` - message hash that needs to be verified\n- `publicKey: Uint8Array | string | Point` - e.g. that was generated from `privateKey` by `getPublicKey`\n- Returns `boolean`: `true` if `signature == hash`; otherwise `false`\n\n##### `recoverPublicKey(hash, signature, recovery)`\n```typescript\nexport declare function recoverPublicKey(msgHash: string, signature: string, recovery: number): string | undefined;\nexport declare function recoverPublicKey(msgHash: Uint8Array, signature: Uint8Array, recovery: number): Uint8Array | undefined;\n```\n- `msgHash: Uint8Array | string` - message hash which would be signed\n- `signature: Uint8Array | string | { r: bigint, s: bigint }` - object returned by the `sign` function\n- `recovery: number` - recovery bit returned by `sign` with `recovered` option\n  Public key is generated by doing scalar multiplication of a base Point(x, y) by a fixed\n  integer. The result is another `Point(x, y)` which we will by default encode to hex Uint8Array.\n  If signature is invalid - function will return `undefined` as result.\n\nTo get Point instance, use `Point.fromSignature(hash, signature, recovery)`.\n\n##### `schnorr.getPublicKey(privateKey)`\n```typescript\nfunction schnorrGetPublicKey(privateKey: Uint8Array): Uint8Array;\nfunction schnorrGetPublicKey(privateKey: string): string;\n```\n\nReturns 32-byte public key. *Warning:* it is incompatible with non-schnorr pubkey.\n\nSpecifically, its *y* coordinate may be flipped. See BIP0340 for clarification.\n\n##### `schnorr.sign(hash, privateKey)`\n```typescript\nfunction schnorrSign(msgHash: Uint8Array, privateKey: Uint8Array, auxilaryRandom?: Uint8Array): Promise<Uint8Array>;\nfunction schnorrSign(msgHash: string, privateKey: string, auxilaryRandom?: string): Promise<string>;\n```\n\nGenerates Schnorr signature as per BIP0340. Asynchronous, so use `await`.\n\n- `msgHash: Uint8Array | string` - message hash which would be signed\n- `privateKey: Uint8Array | string | bigint` - private key which will sign the hash\n- `auxilaryRandom?: Uint8Array` — optional 32 random bytes. By default, the method gathers cryptogarphically secure random.\n- Returns Schnorr signature in Hex format.\n\n##### `schnorr.verify(signature, hash, publicKey)`\n```typescript\nfunction schnorrVerify(signature: Uint8Array | string, msgHash: Uint8Array | string, publicKey: Uint8Array | string): boolean\n```\n- `signature: Uint8Array | string | { r: bigint, s: bigint }` - object returned by the `sign` function\n- `msgHash: Uint8Array | string` - message hash that needs to be verified\n- `publicKey: Uint8Array | string | Point` - e.g. that was generated from `privateKey` by `getPublicKey`\n- Returns `boolean`: `true` if `signature == hash`; otherwise `false`\n\n#### Point methods\n\n##### Helpers\n\n###### `utils.randomPrivateKey(): Uint8Array`\n\nReturns `Uint8Array` of 32 cryptographically secure random bytes that can be used as private key. The signature is:\n\n```ts\n(key: Uint8Array, ...msgs: Uint8Array[]): Uint8Array;\n```\n\n###### `utils.hmacSha256Sync`\n\nThe function is not defined by default, but could be used to implement `signSync` method (see above).\n\n###### `utils.precompute(W = 8, point = BASE_POINT): Point`\n\nReturns cached point which you can use to pass to `getSharedSecret` or to `#multiply` by it.\n\nThis is done by default, no need to run it unless you want to\ndisable precomputation or change window size.\n\nWe're doing scalar multiplication (used in getPublicKey etc) with\nprecomputed BASE_POINT values.\n\nThis slows down first getPublicKey() by milliseconds (see Speed section),\nbut allows to speed-up subsequent getPublicKey() calls up to 20x.\n\nYou may want to precompute values for your own point.\n\n```typescript\nsecp256k1.CURVE.P // Field, 2 ** 256 - 2 ** 32 - 977\nsecp256k1.CURVE.n // Order, 2 ** 256 - 432420386565659656852420866394968145599\nsecp256k1.Point.BASE // new secp256k1.Point(Gx, Gy) where\n// Gx = 55066263022277343669578718895168534326250603453777594175500187360389116729240n\n// Gy = 32670510020758816978083085130507043184471273380659243275938904335757337482424n;\n\n// Elliptic curve point in Affine (x, y) coordinates.\nsecp256k1.Point {\n  constructor(x: bigint, y: bigint);\n  // Supports compressed and non-compressed hex\n  static fromHex(hex: Uint8Array | string);\n  static fromPrivateKey(privateKey: Uint8Array | string | number | bigint);\n  static fromSignature(\n    msgHash: Hex,\n    signature: Signature,\n    recovery: number | bigint\n  ): Point | undefined {\n  toRawBytes(isCompressed = false): Uint8Array;\n  toHex(isCompressed = false): string;\n  equals(other: Point): boolean;\n  negate(): Point;\n  add(other: Point): Point;\n  subtract(other: Point): Point;\n  // Constant-time scalar multiplication.\n  multiply(scalar: bigint | Uint8Array): Point;\n}\nsecp256k1.Signature {\n  constructor(r: bigint, s: bigint);\n  // DER encoded ECDSA signature\n  static fromDER(hex: Uint8Array | string);\n  // R, S 32-byte each\n  static fromCompact(hex: Uint8Array | string);\n  toDERRawBytes(): Uint8Array;\n  toDERHex(): string;\n  toCompactRawBytes(): Uint8Array;\n  toCompactHex(): string;\n}\n```\n\n## Security\n\nNoble is production-ready.\n\n1. The library has been audited by an independent security firm cure53: [PDF](https://cure53.de/pentest-report_noble-lib.pdf). The audit has been [crowdfunded](https://gitcoin.co/grants/2451/audit-of-noble-secp256k1-cryptographic-library) by community with help of [Umbra.cash](https://umbra.cash).\n2. The library has also been fuzzed by [Guido Vranken's cryptofuzz](https://github.com/guidovranken/cryptofuzz). You can run the fuzzer by yourself to check it.\n\nWe're using built-in JS `BigInt`, which is \"unsuitable for use in cryptography\" as [per official spec](https://github.com/tc39/proposal-bigint#cryptography). This means that the lib is potentially vulnerable to [timing attacks](https://en.wikipedia.org/wiki/Timing_attack). But, *JIT-compiler* and *Garbage Collector* make \"constant time\" extremely hard to achieve in a scripting language. Which means *any other JS library doesn't use constant-time bigints*. Including bn.js or anything else. Even statically typed Rust, a language without GC, [makes it harder to achieve constant-time](https://www.chosenplaintext.ca/open-source/rust-timing-shield/security) for some cases. If your goal is absolute security, don't use any JS lib — including bindings to native ones. Use low-level libraries & languages. Nonetheless we've hardened implementation of koblitz curve multiplication to be algorithmically constant time.\n\nWe however consider infrastructure attacks like rogue NPM modules very important; that's why it's crucial to minimize the amount of 3rd-party dependencies & native bindings. If your app uses 500 dependencies, any dep could get hacked and you'll be downloading rootkits with every `npm install`. Our goal is to minimize this attack vector.\n\n## Speed\n\nBenchmarks measured with Apple M1.\n\n    getPublicKey(utils.randomPrivateKey()) x 6,121 ops/sec @ 163μs/op\n    sign x 4,468 ops/sec @ 223μs/op\n    verify x 923 ops/sec @ 1ms/op\n    recoverPublicKey x 491 ops/sec @ 2ms/op\n    getSharedSecret aka ecdh x 534 ops/sec @ 1ms/op\n    getSharedSecret (precomputed) x 7,105 ops/sec @ 140μs/op\n    Point.fromHex (decompression) x 12,171 ops/sec @ 82μs/op\n    schnorr.sign x 409 ops/sec @ 2ms/op\n    schnorr.verify x 504 ops/sec @ 1ms/op\n\nCompare to other libraries (`openssl` uses native bindings, not JS):\n\n    elliptic#getPublicKey x 1,940 ops/sec\n    sjcl#getPublicKey x 211 ops/sec\n\n    elliptic#sign x 1,808 ops/sec\n    sjcl#sign x 199 ops/sec\n    openssl#sign x 4,243 ops/sec\n    ecdsa#sign x 116 ops/sec\n    bip-schnorr#sign x 60 ops/sec\n\n    elliptic#verify x 812 ops/sec\n    sjcl#verify x 166 ops/sec\n    openssl#verify x 4,452 ops/sec\n    ecdsa#verify x 80 ops/sec\n    bip-schnorr#verify x 56 ops/sec\n\n    elliptic#ecdh x 971 ops/sec\n\n\n## Contributing\n\nCheck out a blog post about this library: [Learning fast elliptic-curve cryptography in JS](https://paulmillr.com/posts/noble-secp256k1-fast-ecc/).\n\n1. Clone the repository.\n2. `npm install` to install build dependencies like TypeScript\n3. `npm run compile` to compile TypeScript code\n4. `npm run test` to run jest on `test/index.ts`\n\nSpecial thanks to [Roman Koblov](https://github.com/romankoblov), who have helped to improve scalar multiplication speed.\n\n## License\n\nMIT (c) Paul Miller [(https://paulmillr.com)](https://paulmillr.com), see LICENSE file.\n","publish_time":1573411967677,"_cnpm_publish_time":1573411967677,"dist-tags":{"latest":"1.2.14"}}