|
| 1 | +# noble-curves |
| 2 | + |
| 3 | +Minimal, zero-dependency JS implementation of elliptic curve cryptography. |
| 4 | + |
| 5 | +Implements Short Weierstrass curves with ECDSA signature scheme. |
| 6 | + |
| 7 | +To keep the package minimal, no curve definitions are provided out-of-box. |
| 8 | +Main reason for that is the fact hashing library is usually required for full functionality. Use separate package that defines popular curves: `micro-curve-definitions` for P192, P224, P256, P384, P521, secp256k1, stark curve, bn254, pasta (pallas/vesta) - it depends on `@noble/hashes`. |
| 9 | + |
| 10 | +Future plans: |
| 11 | + |
| 12 | +- Edwards, Twisted Edwards & Montgomery curves |
| 13 | +- hash-to-curve standard |
| 14 | +- pairings |
| 15 | + |
| 16 | +### This library belongs to _noble_ crypto |
| 17 | + |
| 18 | +> **noble-crypto** — high-security, easily auditable set of contained cryptographic libraries and tools. |
| 19 | +
|
| 20 | +- No dependencies, small files |
| 21 | +- Easily auditable TypeScript/JS code |
| 22 | +- Supported in all major browsers and stable node.js versions |
| 23 | +- All releases are signed with PGP keys |
| 24 | +- Check out [homepage](https://paulmillr.com/noble/) & all libraries: |
| 25 | + [secp256k1](https://github.com/paulmillr/noble-secp256k1), |
| 26 | + [ed25519](https://github.com/paulmillr/noble-ed25519), |
| 27 | + [bls12-381](https://github.com/paulmillr/noble-bls12-381), |
| 28 | + [hashes](https://github.com/paulmillr/noble-hashes), |
| 29 | + [curves](https://github.com/paulmillr/noble-curves) |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +Use NPM in node.js / browser, or include single file from |
| 34 | +[GitHub's releases page](https://github.com/paulmillr/noble-curves/releases): |
| 35 | + |
| 36 | +## Usage |
| 37 | + |
| 38 | +```sh |
| 39 | +npm install @noble/curves |
| 40 | +``` |
| 41 | + |
| 42 | +```ts |
| 43 | +// Short Weierstrass curve |
| 44 | +import shortw from '@noble/curves/shortw'; |
| 45 | +import { sha256 } from '@noble/hashes/sha256'; |
| 46 | +import { hmac } from '@noble/hashes/hmac'; |
| 47 | +import { concatBytes, randomBytes } from '@noble/hashes/utils'; |
| 48 | + |
| 49 | +export const secp256k1 = shortw({ |
| 50 | + a: 0n, |
| 51 | + b: 7n, |
| 52 | + // Field over which we'll do calculations |
| 53 | + P: 2n ** 256n - 2n ** 32n - 2n ** 9n - 2n ** 8n - 2n ** 7n - 2n ** 6n - 2n ** 4n - 1n, |
| 54 | + // Curve order, total count of valid points in the field |
| 55 | + n: 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n, |
| 56 | + // Base point (x, y) aka generator point |
| 57 | + Gx: 55066263022277343669578718895168534326250603453777594175500187360389116729240n, |
| 58 | + Gy: 32670510020758816978083085130507043184471273380659243275938904335757337482424n, |
| 59 | + hash: sha256, |
| 60 | + hmac: (k: Uint8Array, ...msgs: Uint8Array[]) => hmac(sha256, key, concatBytes(...msgs)), |
| 61 | + randomBytes: randomBytes |
| 62 | +}); |
| 63 | + |
| 64 | +// secp256k1.getPublicKey(priv) |
| 65 | +// secp256k1.sign(msg, priv) |
| 66 | +// secp256k1.verify(sig, msg, pub) |
| 67 | +``` |
| 68 | + |
| 69 | +## License |
| 70 | + |
| 71 | +MIT (c) Paul Miller [(https://paulmillr.com)](https://paulmillr.com), see LICENSE file. |
0 commit comments