Skip to content

Commit caf41a9

Browse files
committed
Changes as per feedback
1 parent cc47e53 commit caf41a9

File tree

8 files changed

+651
-639
lines changed

8 files changed

+651
-639
lines changed

README.md

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ The module has been completely rewritten:
2626
browsers and node.js. See [Upgrading](#upgrading)
2727
2. We target runtimes with [bigint](https://caniuse.com/bigint) support,
2828
which is Chrome 67+, Edge 79+, Firefox 68+, Safari 14+, node.js 10+. If you need to support older runtimes, use `[email protected]`
29+
3. If you've used `secp256k1`, [rename it to `secp256k1-compat`](#legacy-secp256k1-compatibility-layer)
2930
- The new module [has not been audited yet](#security), but it's in the process of getting the audit. Use it at your own risk
3031

3132
## Usage
@@ -34,10 +35,10 @@ Use NPM / Yarn in node.js / browser:
3435

3536
```bash
3637
# NPM
37-
npm install ethereum-cryptography
38+
npm install ethereum-cryptography@next
3839

3940
# Yarn
40-
yarn add ethereum-cryptography
41+
yarn add ethereum-cryptography@next
4142
```
4243

4344
See [browser usage](#browser-usage) for information on using the package with major Javascript bundlers. It is
@@ -76,6 +77,9 @@ const { createPrivateKeySync, ecdsaSign } = require("ethereum-cryptography/secp2
7677
const { HDKey } = require("ethereum-cryptography/hdkey");
7778
const { generateMnemonic } = require("ethereum-cryptography/bip39");
7879
const { wordlist } = require("ethereum-cryptography/bip39/wordlists/english");
80+
81+
// utilities
82+
const { hexToBytes, toHex, utf8ToBytes } = require("ethereum-cryptography/utils");
7983
```
8084

8185
## Hashes: SHA256, keccak-256, RIPEMD160, BLAKE2b
@@ -101,6 +105,16 @@ const { sha512 } = require("ethereum-cryptography/sha512");
101105
const { keccak256, keccak224, keccak384, keccak512 } = require("ethereum-cryptography/keccak");
102106
const { ripemd160 } = require("ethereum-cryptography/ripemd160");
103107
const { blake2b } = require("ethereum-cryptography/blake2b");
108+
109+
sha256(Uint8Array.from([1, 2, 3]))
110+
111+
// Can be used with strings
112+
const { utf8ToBytes } = require("ethereum-cryptography/utils");
113+
sha256(utf8ToBytes("abc"))
114+
115+
// If you need hex
116+
const { toHex } = require("ethereum-cryptography/utils");
117+
toHex(sha256(utf8ToBytes("abc")))
104118
```
105119

106120
## KDFs: PBKDF2, Scrypt
@@ -127,13 +141,16 @@ Encoding passwords is a frequent source of errors. Please read
127141
before using these submodules.
128142

129143
```js
130-
const { pbkdf2Sync } = require("ethereum-cryptography/pbkdf2");
131-
console.log(pbkdf2Sync("password", "salt", 131072, 32, "sha256"));
144+
const { pbkdf2 } = require("ethereum-cryptography/pbkdf2");
145+
const { utf8ToBytes } = require("ethereum-cryptography/utils");
146+
// Pass Uint8Array, or convert strings to Uint8Array
147+
console.log(await pbkdf2(utf8ToBytes("password"), utf8ToBytes("salt"), 131072, 32, "sha256"));
132148
```
133149

134150
```js
135151
const { scryptSync } = require("ethereum-cryptography/scrypt");
136-
console.log(scryptSync("password", "salt", 262144, 8, 1, 32));
152+
const { utf8ToBytes } = require("ethereum-cryptography/utils");
153+
console.log(await scrypt(utf8ToBytes("password"), utf8ToBytes("salt"), 262144, 8, 1, 32));
137154
```
138155

139156
## CSPRNG (Cryptographically strong pseudorandom number generator)
@@ -165,15 +182,15 @@ function recoverPublicKey(msgHash: Uint8Array, signature: Uint8Array, recovery:
165182
function utils.randomPrivateKey(): Uint8Array;
166183
```
167184

168-
The `curve-secp256k1` submodule provides a library for elliptic curve operations on
185+
The `secp256k1` submodule provides a library for elliptic curve operations on
169186
the curve secp256k1. For detailed documentation, follow [README of `noble-secp256k1`](https://github.com/paulmillr/noble-secp256k1), which the module uses as a backend.
170187

171188
secp256k1 private keys need to be cryptographically secure random numbers with
172189
certain caracteristics. If this is not the case, the security of secp256k1 is
173190
compromised. We strongly recommend using `utils.randomPrivateKey()` to generate them.
174191

175192
```js
176-
const secp = require("ethereum-cryptography/curve-secp256k1");
193+
const secp = require("ethereum-cryptography/secp256k1");
177194
(async () => {
178195
// You pass either a hex string, or Uint8Array
179196
const privateKey = "6b911fd37cdf5c81d4c0adb1ab7fa822ed253ab0ad9aa18d77257c88b29b718e";
@@ -376,19 +393,13 @@ console.log(
376393
Using this library with Rollup requires the following plugins:
377394

378395
* [`@rollup/plugin-commonjs`](https://www.npmjs.com/package/@rollup/plugin-commonjs)
379-
* [`@rollup/plugin-json`](https://www.npmjs.com/package/@rollup/plugin-json)
380396
* [`@rollup/plugin-node-resolve`](https://www.npmjs.com/package/@rollup/plugin-node-resolve)
381-
* [`rollup-plugin-node-builtins`](https://www.npmjs.com/package/rollup-plugin-node-builtins)
382-
* [`rollup-plugin-node-globals`](https://www.npmjs.com/package/rollup-plugin-node-globals)
383397

384398
These can be used by setting your `plugins` array like this:
385399

386400
```js
387401
plugins: [
388402
commonjs(),
389-
json(),
390-
nodeGlobals(),
391-
nodeBuiltins(),
392403
resolve({
393404
browser: true,
394405
preferBuiltins: false,
@@ -398,14 +409,15 @@ These can be used by setting your `plugins` array like this:
398409

399410
## Legacy secp256k1 compatibility layer
400411

401-
**Note:** do not use this module; it is only for users who upgrade
412+
**Note:** consider using `secp256k1` instead;
413+
This module is only for users who upgraded
402414
from ethereum-cryptography v0.1. It could be removed in the future,
403415
but we're keeping it around for now, for backwards-compatibility.
404416

405-
The API of `secp256k1` is the same as [secp256k1-node](https://github.com/cryptocoinjs/secp256k1-node):
417+
The API of `secp256k1-compat` is the same as [secp256k1-node](https://github.com/cryptocoinjs/secp256k1-node):
406418

407419
```js
408-
const { createPrivateKeySync, ecdsaSign } = require("ethereum-cryptography/secp256k1");
420+
const { createPrivateKeySync, ecdsaSign } = require("ethereum-cryptography/secp256k1-compat");
409421
const msgHash = Uint8Array.from(
410422
"82ff40c0a986c6a5cfad4ddf4c3aa6996f1a7837f9c398e17e5de5cbd5a12b28",
411423
"hex"

src/curve-secp256k1.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/hdkey.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ripemd160 } from "noble-hashes/lib/ripemd160";
44
import { sha256 } from "noble-hashes/lib/sha256";
55
import { sha512 } from "noble-hashes/lib/sha512";
66
import { bytesToHex } from "noble-hashes/lib/utils";
7-
import * as secp from "./curve-secp256k1";
7+
import * as secp from "./secp256k1";
88
import {
99
assertBytes,
1010
concatBytes,

0 commit comments

Comments
 (0)