From 65dad9490ba71da18d172436c79d0b3a420ebf15 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Sun, 12 Jun 2022 13:47:20 +0400 Subject: [PATCH 1/3] Expose _createKeccak256. Upgrade deps. --- package.json | 8 ++++---- src/keccak.ts | 11 ++++++----- src/utils.ts | 9 +++++---- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 46536be..36877c4 100644 --- a/package.json +++ b/package.json @@ -24,10 +24,10 @@ "*.d.ts" ], "dependencies": { - "@noble/hashes": "1.0.0", - "@noble/secp256k1": "1.5.5", - "@scure/bip32": "1.0.1", - "@scure/bip39": "1.0.0" + "@noble/hashes": "1.1.1", + "@noble/secp256k1": "1.6.0", + "@scure/bip32": "1.1.0", + "@scure/bip39": "1.1.0" }, "browser": { "crypto": false diff --git a/src/keccak.ts b/src/keccak.ts index 1d67b78..5999869 100644 --- a/src/keccak.ts +++ b/src/keccak.ts @@ -1,7 +1,8 @@ -import * as sha3 from "@noble/hashes/sha3"; +import { keccak_224, keccak_256, keccak_384, keccak_512 } from "@noble/hashes/sha3"; import { wrapHash } from "./utils"; -export const keccak224 = wrapHash(sha3.keccak_224); -export const keccak256 = wrapHash(sha3.keccak_256); -export const keccak384 = wrapHash(sha3.keccak_384); -export const keccak512 = wrapHash(sha3.keccak_512); +export const keccak224 = wrapHash(keccak_224); +export const keccak256 = wrapHash(keccak_256); +export const createKeccak256 = keccak_256.create; +export const keccak384 = wrapHash(keccak_384); +export const keccak512 = wrapHash(keccak_512); diff --git a/src/utils.ts b/src/utils.ts index 0583236..e5328b4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,8 +1,9 @@ // buf.toString('hex') -> toHex(buf) -import { assertBytes } from "@noble/hashes/utils"; +import assert from "@noble/hashes/_assert"; +const assertBool = assert.bool; +const assertBytes = assert.bytes; +export { assertBool, assertBytes }; export { - assertBool, - assertBytes, bytesToHex, bytesToHex as toHex, concatBytes, @@ -35,7 +36,7 @@ export function equalsBytes(a: Uint8Array, b: Uint8Array): boolean { // Internal utils export function wrapHash(hash: (msg: Uint8Array) => Uint8Array) { return (msg: Uint8Array) => { - assertBytes(msg); + assert.bytes(msg); return hash(msg); }; } From df8537b0b7f6c2eeb29b608bca26575b0bc265ff Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Sun, 12 Jun 2022 19:37:20 +0400 Subject: [PATCH 2/3] Fix keccak --- src/keccak.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/keccak.ts b/src/keccak.ts index 5999869..38434d2 100644 --- a/src/keccak.ts +++ b/src/keccak.ts @@ -1,8 +1,18 @@ -import { keccak_224, keccak_256, keccak_384, keccak_512 } from "@noble/hashes/sha3"; +import { Keccak, keccak_224, keccak_256, keccak_384, keccak_512 } from "@noble/hashes/sha3"; +import { Hash } from "@noble/hashes/utils"; import { wrapHash } from "./utils"; +// Expose create only for keccak256 +interface K256 { + (data: Uint8Array): Uint8Array; + create(): Hash; +} + export const keccak224 = wrapHash(keccak_224); -export const keccak256 = wrapHash(keccak_256); -export const createKeccak256 = keccak_256.create; +export const keccak256: K256 = (() => { + const k: any = wrapHash(keccak_256); + k.create = keccak_256.create; + return k; +})(); export const keccak384 = wrapHash(keccak_384); export const keccak512 = wrapHash(keccak_512); From f5bddae37c63c16235b68634e5b3c45c3ad43c16 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Sun, 12 Jun 2022 19:39:31 +0400 Subject: [PATCH 3/3] Lint. Remove esModuleInterop --- src/keccak.ts | 8 +++++++- tsconfig.json | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/keccak.ts b/src/keccak.ts index 38434d2..991a70d 100644 --- a/src/keccak.ts +++ b/src/keccak.ts @@ -1,4 +1,10 @@ -import { Keccak, keccak_224, keccak_256, keccak_384, keccak_512 } from "@noble/hashes/sha3"; +import { + Keccak, + keccak_224, + keccak_256, + keccak_384, + keccak_512 +} from "@noble/hashes/sha3"; import { Hash } from "@noble/hashes/utils"; import { wrapHash } from "./utils"; diff --git a/tsconfig.json b/tsconfig.json index f549af3..7fae157 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,6 @@ "target": "es2020", "module": "commonjs", "strict": true, - "esModuleInterop": true, "downlevelIteration": true, "rootDirs": [ "./src",