Skip to content

Commit 29818dc

Browse files
authored
Expose keccak256.create. Upgrade deps with ESM support. (#41)
* Expose _createKeccak256. Upgrade deps. * Fix keccak * Lint. Remove esModuleInterop
1 parent 35043d1 commit 29818dc

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

Diff for: package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
"*.d.ts"
2525
],
2626
"dependencies": {
27-
"@noble/hashes": "1.0.0",
28-
"@noble/secp256k1": "1.5.5",
29-
"@scure/bip32": "1.0.1",
30-
"@scure/bip39": "1.0.0"
27+
"@noble/hashes": "1.1.1",
28+
"@noble/secp256k1": "1.6.0",
29+
"@scure/bip32": "1.1.0",
30+
"@scure/bip39": "1.1.0"
3131
},
3232
"browser": {
3333
"crypto": false

Diff for: src/keccak.ts

+22-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1-
import * as sha3 from "@noble/hashes/sha3";
1+
import {
2+
Keccak,
3+
keccak_224,
4+
keccak_256,
5+
keccak_384,
6+
keccak_512
7+
} from "@noble/hashes/sha3";
8+
import { Hash } from "@noble/hashes/utils";
29
import { wrapHash } from "./utils";
310

4-
export const keccak224 = wrapHash(sha3.keccak_224);
5-
export const keccak256 = wrapHash(sha3.keccak_256);
6-
export const keccak384 = wrapHash(sha3.keccak_384);
7-
export const keccak512 = wrapHash(sha3.keccak_512);
11+
// Expose create only for keccak256
12+
interface K256 {
13+
(data: Uint8Array): Uint8Array;
14+
create(): Hash<Keccak>;
15+
}
16+
17+
export const keccak224 = wrapHash(keccak_224);
18+
export const keccak256: K256 = (() => {
19+
const k: any = wrapHash(keccak_256);
20+
k.create = keccak_256.create;
21+
return k;
22+
})();
23+
export const keccak384 = wrapHash(keccak_384);
24+
export const keccak512 = wrapHash(keccak_512);

Diff for: src/utils.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// buf.toString('hex') -> toHex(buf)
2-
import { assertBytes } from "@noble/hashes/utils";
2+
import assert from "@noble/hashes/_assert";
3+
const assertBool = assert.bool;
4+
const assertBytes = assert.bytes;
5+
export { assertBool, assertBytes };
36
export {
4-
assertBool,
5-
assertBytes,
67
bytesToHex,
78
bytesToHex as toHex,
89
concatBytes,
@@ -35,7 +36,7 @@ export function equalsBytes(a: Uint8Array, b: Uint8Array): boolean {
3536
// Internal utils
3637
export function wrapHash(hash: (msg: Uint8Array) => Uint8Array) {
3738
return (msg: Uint8Array) => {
38-
assertBytes(msg);
39+
assert.bytes(msg);
3940
return hash(msg);
4041
};
4142
}

Diff for: tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"target": "es2020",
44
"module": "commonjs",
55
"strict": true,
6-
"esModuleInterop": true,
76
"downlevelIteration": true,
87
"rootDirs": [
98
"./src",

0 commit comments

Comments
 (0)