Skip to content

Commit

Permalink
Expose keccak256.create. Upgrade deps with ESM support. (#41)
Browse files Browse the repository at this point in the history
* Expose _createKeccak256. Upgrade deps.

* Fix keccak

* Lint. Remove esModuleInterop
  • Loading branch information
paulmillr authored Jun 13, 2022
1 parent 35043d1 commit 29818dc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 22 additions & 5 deletions src/keccak.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
import * as sha3 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";

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);
// Expose create only for keccak256
interface K256 {
(data: Uint8Array): Uint8Array;
create(): Hash<Keccak>;
}

export const keccak224 = wrapHash(keccak_224);
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);
9 changes: 5 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);
};
}
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"target": "es2020",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"downlevelIteration": true,
"rootDirs": [
"./src",
Expand Down

0 comments on commit 29818dc

Please sign in to comment.