forked from tornado-packages/noble-curves
readme
This commit is contained in:
parent
ff92bafb6f
commit
aee10c8141
39
README.md
39
README.md
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user