This commit is contained in:
Paul Miller 2023-07-18 07:11:24 +00:00
parent ff92bafb6f
commit aee10c8141
No known key found for this signature in database
GPG Key ID: 697079DA6878B89B

@ -43,8 +43,26 @@ If you don't like NPM, a standalone [noble-curves.js](https://github.com/paulmil
The package consists of two parts:
implementations (using [noble-hashes](https://github.com/paulmillr/noble-hashes)), and zero-dep abstract api.
Generic example for all curves, secp256k1:
```ts
// import * from '@noble/curves'; // Error
// Use sub-imports for tree-shaking, to ensure small size of your apps
// Each curve has similar methods
import { secp256k1 } from '@noble/curves/secp256k1'; // ESM and Common.js
// import { secp256k1 } from 'npm:@noble/curves@1.2.0/secp256k1'; // Deno
const priv = secp256k1.utils.randomPrivateKey();
const pub = secp256k1.getPublicKey(priv);
const msg = new Uint8Array(32).fill(1);
const sig = secp256k1.sign(msg, priv);
const isValid = secp256k1.verify(sig, msg, pub) === true;
// hex strings are also supported besides Uint8Arrays:
const privHex = '46c930bc7bb4db7f55da20798697421b98c4175a52c630294d75a84b9c126236';
const pub2 = secp256k1.getPublicKey(privHex);
```
- [Usage](#usage)
- [Generic example for all curves, secp256k1](#generic-example-for-all-curves-secp256k1)
- [Everything](#everything)
- [ECDSA public key recovery & ECDH](#ecdsa-public-key-recovery--ecdh)
- [Schnorr signatures over secp256k1 BIP340](#schnorr-signatures-over-secp256k1-bip340)
@ -69,25 +87,6 @@ implementations (using [noble-hashes](https://github.com/paulmillr/noble-hashes)
- [Resources](#resources)
- [License](#license)
#### Generic example for all curves, secp256k1
```ts
// import * from '@noble/curves'; // Error
// Use sub-imports for tree-shaking, to ensure small size of your apps
// Each curve has similar methods
import { secp256k1 } from '@noble/curves/secp256k1'; // ESM and Common.js
// import { secp256k1 } from 'npm:@noble/curves@1.2.0/secp256k1'; // Deno
const priv = secp256k1.utils.randomPrivateKey();
const pub = secp256k1.getPublicKey(priv);
const msg = new Uint8Array(32).fill(1);
const sig = secp256k1.sign(msg, priv);
const isValid = secp256k1.verify(sig, msg, pub) === true;
// hex strings are also supported besides Uint8Arrays:
const privHex = '46c930bc7bb4db7f55da20798697421b98c4175a52c630294d75a84b9c126236';
const pub2 = secp256k1.getPublicKey(privHex);
```
#### Everything
```typescript