1
1
# ethereum-cryptography
2
2
3
- [ ![ npm version] [ 1 ]] [ 2 ]
4
- [ ![ Travis CI] [ 3 ]] [ 4 ]
5
- [ ![ license] [ 5 ]] [ 6 ]
6
- [ ![ Types] [ 7 ]] [ 8 ]
3
+ [ ![ npm version] [ 1 ]] [ 2 ] [ ![ Travis CI] [ 3 ]] [ 4 ] [ ![ license] [ 5 ]] [ 6 ] [ ![ Types] [ 7 ]] [ 8 ]
7
4
8
- This npm package contains all the cryptographic primitives normally used when
9
- developing Javascript/TypeScript applications and tools for Ethereum.
10
-
11
- Pure Javascript implementations of all the primitives are included, so it can
12
- be used out of the box for web applications and libraries.
5
+ This package contains all pure-js cryptographic primitives normally used when
6
+ developing Javascript / TypeScript applications and tools for Ethereum.
13
7
14
8
The cryptographic primitives included are:
15
9
16
- * Hashes: SHA256, keccak-256, RIPEMD160, BLAKE2b
17
- * KDFs: PBKDF2, Scrypt
18
- * CSPRNG (Cryptographically strong pseudorandom number generator)
19
- * secp256k1 curve
20
- * BIP32 HD Keygen
21
- * BIP39 Mnemonic phrases
22
- * AES Encryption
10
+ * [ Hashes: SHA256, keccak-256, RIPEMD160, BLAKE2b] ( #hashes-sha256-keccak-256-ripemd160-blake2b )
11
+ * [ KDFs: PBKDF2, Scrypt] ( #kdfs-pbkdf2-scrypt )
12
+ * [ CSPRNG (Cryptographically strong pseudorandom number generator)] ( #csprng-cryptographically-strong-pseudorandom-number-generator )
13
+ * [ secp256k1 curve] ( #secp256k1-curve )
14
+ * [ BIP32 HD Keygen] ( #bip32-hd-keygen )
15
+ * [ BIP39 Mnemonic phrases] ( #bip39-mnemonic-phrases )
16
+ * [ AES Encryption] ( #aes-encryption )
17
+
18
+ ** October 2021 update:** We're releasing ** experimental** version 0.2 of the package.
19
+ The module has been completely rewritten:
20
+
21
+ - ~ 6x smaller: 4,000 lines of code incl. all deps instead of 22,438; 185KB of unpacked code instead of 755KB
22
+ - 3 dependencies (pending an audit) instead of 38
23
+ - Same functionality, all old APIs are the same to simplify the upgrade path
24
+ - ** Breaking:** we target runtimes with [ bigint] ( https://caniuse.com/bigint ) support,
25
+ which is Chrome 67+, Edge 79+, Firefox 68+, Safari 14+, node.js 10+. If you need to support
26
+ older runtimes, use
` [email protected] `
27
+ - ** Breaking:** we return ` Uint8Array ` from all methods that worked with ` Buffer ` before.
28
+ ` Buffer ` has never been supported in browsers, while ` Uint8Array ` s are supported natively in both
29
+ browsers and node.js. See [ Upgrading] ( #upgrading )
30
+ - 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
23
31
24
32
## Usage
25
33
@@ -34,7 +42,7 @@ yarn add ethereum-cryptography
34
42
```
35
43
36
44
See [ browser usage] ( #browser-usage ) for information on using the package with major Javascript bundlers. It is
37
- tested with ` webpack ` , ` Rollup ` , ` Parcel ` , and ` Browserify ` .
45
+ tested with ** Webpack, Rollup, Parcel and Browserify** .
38
46
39
47
This package has no single entry-point, but submodule for each cryptographic
40
48
primitive. Read each primitive's section of this document to learn how to use
@@ -413,7 +421,33 @@ to implement the following EIPs:
413
421
Feel free to open an issue if you want this decision to be reconsidered , or if
414
422
you found another primitive that is missing.
415
423
416
- ## Security audit
424
+ ## Upgrading
425
+
426
+ Version 0.2 changes from 0.1:
427
+
428
+ - **Breaking : ** we target runtimes with [bigint ](https : // caniuse.com/bigint) support,
429
+ which is Chrome 67 +, Edge 79+, Firefox 68+, Safari 14+, node.js 10+. If you need to support
430
+ older runtimes ,
use ` [email protected] `
431
+ - **Breaking : ** we return ` Uint8Array ` from all methods that worked with ` Buffer ` before .
432
+ ` Buffer ` has never been supported in browsers , while ` Uint8Array ` s are supported natively in both
433
+ browsers and node.js:
434
+
435
+ ` ` `
436
+ const { sha256 } = require("ethereum-cryptography/sha256");
437
+
438
+ // Old usage
439
+ const hasho = sha256(Buffer.from("string", "utf8")).toString("hex");
440
+
441
+ // New usage
442
+ const { toHex } = require("ethereum-cryptography/utils");
443
+ const hashn = toHex(sha256("string"));
444
+
445
+ // If you have ` Buffer ` module and want to preserve it:
446
+ const hashb = Buffer.from(sha256("string"));
447
+ const hashbo = hashb.toString("hex");
448
+ ` ` `
449
+
450
+ ## Security
417
451
418
452
This library is in the process of getting a security audit .
419
453
0 commit comments