Skip to content

Commit ffb3a12

Browse files
committed
readme
1 parent 4d7b22f commit ffb3a12

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

README.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,41 +56,46 @@ import * as secp from '@noble/secp256k1';
5656
})();
5757
```
5858

59-
Additional polyfills for some environments:
59+
### Enabling synchronous methods
60+
61+
Only async methods are available by default, to keep the library dependency-free.
62+
To enable sync methods:
6063

6164
```ts
62-
// 1. Enable synchronous methods.
63-
// Only async methods are available by default, to keep the library dependency-free.
6465
import { hmac } from '@noble/hashes/hmac';
6566
import { sha256 } from '@noble/hashes/sha256';
6667
secp.etc.hmacSha256Sync = (k, ...m) => hmac(sha256, k, secp.etc.concatBytes(...m));
67-
// Sync methods can be used now:
68-
// secp.sign(msgHash, privKey);
68+
```
6969

70-
// 2. node.js 18 and older, requires polyfilling globalThis.crypto
71-
import { webcrypto } from 'node:crypto';
72-
// @ts-ignore
73-
if (!globalThis.crypto) globalThis.crypto = webcrypto;
70+
### React Native: polyfill getRandomValues and sha512
7471

75-
// 3. React Native needs crypto.getRandomValues polyfill and sha512
72+
```ts
7673
import 'react-native-get-random-values';
7774
import { hmac } from '@noble/hashes/hmac';
7875
import { sha256 } from '@noble/hashes/sha256';
7976
secp.etc.hmacSha256Sync = (k, ...m) => hmac(sha256, k, secp.etc.concatBytes(...m));
8077
secp.etc.hmacSha256Async = (k, ...m) => Promise.resolve(secp.etc.hmacSha256Sync(k, ...m));
8178
```
8279

83-
## API
84-
85-
There are 3 main methods: `getPublicKey(privateKey)`,
86-
`sign(messageHash, privateKey)` and
87-
`verify(signature, messageHash, publicKey)`.
88-
We accept Hex type everywhere:
80+
### nodejs v18 and older: polyfill webcrypto
8981

9082
```ts
91-
type Hex = Uint8Array | string;
83+
import { webcrypto } from 'node:crypto';
84+
// @ts-ignore
85+
if (!globalThis.crypto) globalThis.crypto = webcrypto;
9286
```
9387

88+
## API
89+
90+
There are 3 main methods:
91+
92+
* `getPublicKey(privateKey)`
93+
* `sign(messageHash, privateKey)` and `signAsync(messageHash, privateKey)`
94+
* `verify(signature, messageHash, publicKey)`
95+
96+
Functions generally accept Uint8Array.
97+
There are optional utilities which convert hex strings, utf8 strings or bigints to u8a.
98+
9499
### getPublicKey
95100

96101
```ts

0 commit comments

Comments
 (0)