@@ -86,6 +86,11 @@ function ripemd160(msg: Uint8Array): Uint8Array;
86
86
function blake2b(msg : Uint8Array , outputLength = 64 ): Uint8Array ;
87
87
```
88
88
89
+ - SHA2 (SHA256, SHA512)
90
+ - keccak-256 variant of SHA3
91
+ - RIPEMD160
92
+ - BLAKE2b
93
+
89
94
``` js
90
95
const { sha256 } = require (" ethereum-cryptography/sha256" );
91
96
const { keccak256 , keccak224 , keccak384 , keccak512 } = require (" ethereum-cryptography/keccak" );
@@ -153,6 +158,7 @@ console.log(getRandomBytesSync(32));
153
158
function getPublicKey(privateKey : Uint8Array , isCompressed ? : false ): Uint8Array ;
154
159
function getSharedSecret(privateKeyA : Uint8Array , publicKeyB : Uint8Array ): Uint8Array ;
155
160
function sign(msgHash : Uint8Array , privateKey : Uint8Array , opts ? : Options ): Promise <Uint8Array >;
161
+ function signSync(msgHash : Uint8Array , privateKey : Uint8Array , opts ? : Options ): Uint8Array ;
156
162
function verify(signature : Uint8Array , msgHash : Uint8Array , publicKey : Uint8Array ): boolean
157
163
function recoverPublicKey(msgHash : Uint8Array , signature : Uint8Array , recovery : number ): Uint8Array | undefined ;
158
164
function utils.randomPrivateKey(): Uint8Array ;
@@ -228,9 +234,10 @@ Its only difference is that it has to be be used with a named import.
228
234
229
235
``` js
230
236
const { HDKey } = require (" ethereum-cryptography/hdkey" );
237
+ const { hexToBytes } = require (" ethereum-cryptography/utils" );
231
238
232
239
const seed = " fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542" ;
233
- const hdkey = HDKey .fromMasterSeed (Uint8Array . from (seed, " hex " ));
240
+ const hdkey = HDKey .fromMasterSeed (hexToBytes (seed));
234
241
const childkey = hdkey .derive (" m/0/2147483647'/1" );
235
242
236
243
console .log (childkey .privateExtendedKey );
@@ -275,6 +282,11 @@ The word lists are exported as a `wordlist` variable in each of these submodules
275
282
276
283
## AES Encryption
277
284
285
+ ``` ts
286
+ function encrypt(msg : Uint8Array , key : Uint8Array , iv : Uint8Array , mode = " aes-128-ctr" , pkcs7PaddingEnabled = true ): Uint8Array ;
287
+ function decrypt(cypherText : Uint8Array , key : Uint8Array , iv : Uint8Array , mode = " aes-128-ctr" , pkcs7PaddingEnabled = true ): Uint8Array
288
+ ```
289
+
278
290
The ` aes ` submodule contains encryption and decryption functions implementing
279
291
the [Advanced Encryption Standard ](https :// en.wikipedia.org/wiki/Advanced_Encryption_Standard)
280
292
algorithm .
@@ -341,23 +353,17 @@ Note that implementing this can mean catching all errors that can be thrown
341
353
when calling on of this module ' s functions, and just throwing a new generic
342
354
exception.
343
355
344
- ### Function types
345
-
346
- ``` ts
347
- function encrypt(msg : Uint8Array , key : Uint8Array , iv : Uint8Array , mode = " aes-128-ctr" , pkcs7PaddingEnabled = true ): Uint8Array ;
348
- function decrypt(cypherText : Uint8Array , key : Uint8Array , iv : Uint8Array , mode = " aes-128-ctr" , pkcs7PaddingEnabled = true ): Uint8Array
349
- ```
350
-
351
356
### Example usage
352
357
353
358
` ` ` js
354
359
const { encrypt } = require("ethereum-cryptography/aes");
360
+ const { hexToBytes, utf8ToBytes } = require("ethereum-cryptography/utils");
355
361
356
362
console.log(
357
363
encrypt(
358
- Uint8Array.from ("message", "ascii "),
359
- Uint8Array.from ("2b7e151628aed2a6abf7158809cf4f3c", "hex "),
360
- Uint8Array.from ("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", "hex ")
364
+ utf8ToBytes ("message"),
365
+ hexToBytes ("2b7e151628aed2a6abf7158809cf4f3c"),
366
+ hexToBytes ("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff")
361
367
)
362
368
);
363
369
` ` `
0 commit comments