Skip to content

Commit ec3db95

Browse files
committed
README
1 parent e02e0fb commit ec3db95

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

README.md

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ Fastest 5KB JS implementation of secp256k1 signatures & ECDH.
88
signatures compliant with [BIP340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki)
99
- 🤝 Elliptic Curve Diffie-Hellman [ECDH](https://en.wikipedia.org/wiki/Elliptic-curve_Diffie–Hellman)
1010
- 🔒 Supports [hedged signatures](https://paulmillr.com/posts/deterministic-signatures/) guarding against fault attacks
11-
- 🪶 4.94KB (gzipped, elliptic.js is 10x larger, tiny-secp256k1 is 25x larger)
11+
- 🪶 4.94KB (gzipped) - 10-25x smaller than similar libraries
1212

13-
The module is a sister project of [noble-curves](https://github.com/paulmillr/noble-curves),
14-
focusing on smaller attack surface & better auditability.
15-
Curves are drop-in replacement and have more features:
16-
MSM, DER encoding, endomorphism, prehashing, custom point precomputes, hash-to-curve, oprf.
17-
To upgrade from earlier version, see [Upgrading](#upgrading).
13+
The module is a sister project of [noble-curves](https://github.com/paulmillr/noble-curves).
14+
Use noble-secp256k1 if you need smaller attack surface & better auditability.
15+
Switch to noble-curves (drop-in) if you need features like MSM, DER encoding, custom point precomputes.
1816

19-
898-byte version of the library is available for learning purposes in `test/misc/1kb.min.js`,
17+
898-byte version of the library is available for learning purposes in [`test/misc/1kb.min.js`](https://github.com/paulmillr/noble-secp256k1/blob/c38e57d17a2ecfdb9b8a80890a8e1a2cc140aa04/test/misc/1kb.min.js),
2018
it was created for the article [Learning fast elliptic-curve cryptography](https://paulmillr.com/posts/noble-secp256k1-fast-ecc/).
2119

2220
### This library belongs to _noble_ cryptography
@@ -25,14 +23,16 @@ it was created for the article [Learning fast elliptic-curve cryptography](https
2523
2624
- Zero or minimal dependencies
2725
- Highly readable TypeScript / JS code
28-
- PGP-signed releases and transparent NPM builds with provenance
29-
- Check out [homepage](https://paulmillr.com/noble/) & all libraries:
26+
- PGP-signed releases and transparent NPM builds
27+
- All libraries:
3028
[ciphers](https://github.com/paulmillr/noble-ciphers),
3129
[curves](https://github.com/paulmillr/noble-curves),
3230
[hashes](https://github.com/paulmillr/noble-hashes),
3331
[post-quantum](https://github.com/paulmillr/noble-post-quantum),
3432
5kb [secp256k1](https://github.com/paulmillr/noble-secp256k1) /
3533
[ed25519](https://github.com/paulmillr/noble-ed25519)
34+
- [Check out the homepage](https://paulmillr.com/noble/)
35+
for reading resources, documentation, and apps built with noble
3636

3737
## Usage
3838

@@ -50,10 +50,16 @@ import * as secp from '@noble/secp256k1';
5050
const msg = new TextEncoder().encode('hello noble');
5151
const sig = await secp.signAsync(msg, secretKey);
5252
const isValid = await secp.verifyAsync(sig, msg, publicKey);
53+
})();
54+
55+
// ECDH, key recovery
56+
(async () => {
57+
const alice = secp.keygen();
58+
const bob = secp.keygen();
59+
const shared = secp.getSharedSecret(alice.secretKey, bob.publicKey);
5360

54-
const bobsKeys = secp.keygen();
55-
const shared = secp.getSharedSecret(secretKey, bobsKeys.publicKey); // Diffie-Hellman
56-
const sigr = await secp.signAsync(msg, secretKey, { format: 'recovered' });
61+
// recovery
62+
const sigr = await secp.signAsync(msg, alice.secretKey, { format: 'recovered' });
5763
const publicKey2 = secp.recoverPublicKey(sigr, msg);
5864
})();
5965

@@ -81,6 +87,9 @@ secp.hashes.sha256 = sha256;
8187

8288
### React Native: polyfill getRandomValues and sha256
8389

90+
React Native does not provide secure getRandomValues by default.
91+
This can't be securely polyfilled from our end, so one will need a RN-specific compile-time dep.
92+
8493
```ts
8594
import 'react-native-get-random-values';
8695
import { hmac } from '@noble/hashes/hmac.js';
@@ -295,31 +304,27 @@ Use low-level libraries & languages.
295304

296305
### Supply chain security
297306

298-
- **Commits** are signed with PGP keys, to prevent forgery. Make sure to verify commit signatures
299-
- **Releases** are transparent and built on GitHub CI.
300-
Check out [attested checksums of single-file builds](https://github.com/paulmillr/noble-secp256k1/attestations)
301-
and [provenance logs](https://github.com/paulmillr/noble-secp256k1/actions/workflows/release.yml)
302-
- **Rare releasing** is followed to ensure less re-audit need for end-users
303-
- **Dependencies** are minimized and locked-down: any dependency could get hacked and users will be downloading malware with every install.
304-
- We make sure to use as few dependencies as possible
305-
- Automatic dep updates are prevented by locking-down version ranges; diffs are checked with `npm-diff`
306-
- **Dev Dependencies** are disabled for end-users; they are only used to develop / build the source code
307+
- **Commits** are signed with PGP keys to prevent forgery. Be sure to verify the commit signatures
308+
- **Releases** are made transparently through token-less GitHub CI and Trusted Publishing. Be sure to verify the [provenance logs](https://docs.npmjs.com/generating-provenance-statements) for authenticity.
309+
- **Rare releasing** is practiced to minimize the need for re-audits by end-users.
310+
- **Dependencies** are minimized and strictly pinned to reduce supply-chain risk.
311+
- We use as few dependencies as possible.
312+
- Version ranges are locked, and changes are checked with npm-diff.
313+
- **Dev dependencies** are excluded from end-user installs; they’re only used for development and build steps.
307314

308315
For this package, there are 0 dependencies; and a few dev dependencies:
309316

310317
- [noble-hashes](https://github.com/paulmillr/noble-hashes) provides cryptographic hashing functionality
311-
- micro-bmark, micro-should and jsbt are used for benchmarking / testing / build tooling and developed by the same author
312-
- prettier, fast-check and typescript are used for code quality / test generation / ts compilation. It's hard to audit their source code thoroughly and fully because of their size
318+
- jsbt is used for benchmarking / testing / build tooling and developed by the same author
319+
- prettier, fast-check and typescript are used for code quality / test generation / ts compilation
313320

314321
### Randomness
315322

316-
We're deferring to built-in
317-
[crypto.getRandomValues](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues)
318-
which is considered cryptographically secure (CSPRNG).
323+
We rely on the built-in
324+
[`crypto.getRandomValues`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues),
325+
which is considered a cryptographically secure PRNG.
319326

320-
In the past, browsers had bugs that made it weak: it may happen again.
321-
Implementing a userspace CSPRNG to get resilient to the weakness
322-
is even worse: there is no reliable userspace source of quality entropy.
327+
Browsers have had weaknesses in the past - and could again - but implementing a userspace CSPRNG is even worse, as there’s no reliable userspace source of high-quality entropy.
323328

324329
### Quantum computers
325330

@@ -373,8 +378,8 @@ v3 brings the package closer to noble-curves v2.
373378

374379
```js
375380
// before
376-
// etc.hmacSha256Sync = (key, ...messages) => hmac(sha256, key, etc.concatBytes(...messages));
377-
// etc.hmacSha256Async = (key, ...messages) => Promise.resolve(etc.hmacSha256Sync(key, ...messages));
381+
etc.hmacSha256Sync = (key, ...messages) => hmac(sha256, key, etc.concatBytes(...messages));
382+
etc.hmacSha256Async = (key, ...messages) => Promise.resolve(etc.hmacSha256Sync(key, ...messages));
378383
// after
379384
hashes.hmacSha256 = (key, msg) => hmac(sha256, key, msg);
380385
hashes.sha256 = sha256;

0 commit comments

Comments
 (0)