Skip to content

Commit cd424b8

Browse files
committed
Replace sha3 with keccak
sha3 wasn't faster than the pure js implementation, keccak is.
1 parent 1217000 commit cd424b8

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

packages/ethereum-cryptography-native/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
},
4444
"optionalDependencies": {
4545
"blake2": "^2.0.1",
46+
"keccak": "^2.0.0",
4647
"scrypt": "^6.0.3",
47-
"secp256k1": "^3.7.1",
48-
"sha3": "^1.2.3"
48+
"secp256k1": "^3.7.1"
4949
},
5050
"dependencies": {
5151
"@types/secp256k1": "^3.5.0"
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
const SHA3 = require("sha3");
1+
const createKeccakHash = require("keccak");
22

33
export function keccak224(msg: Buffer): Buffer {
4-
const sha3 = new SHA3.SHA3Hash(224);
5-
sha3.update(msg);
6-
return Buffer.from(sha3.digest(), "binary");
4+
const hash = createKeccakHash("keccak224");
5+
hash.update(msg);
6+
return Buffer.from(hash.digest(), "binary");
77
}
88

99
export function keccak256(msg: Buffer): Buffer {
10-
const sha3 = new SHA3.SHA3Hash(256);
11-
sha3.update(msg);
12-
return Buffer.from(sha3.digest(), "binary");
10+
const hash = createKeccakHash("keccak256");
11+
hash.update(msg);
12+
return Buffer.from(hash.digest(), "binary");
1313
}
1414

1515
export function keccak384(msg: Buffer): Buffer {
16-
const sha3 = new SHA3.SHA3Hash(384);
17-
sha3.update(msg);
18-
return Buffer.from(sha3.digest(), "binary");
16+
const hash = createKeccakHash("keccak384");
17+
hash.update(msg);
18+
return Buffer.from(hash.digest(), "binary");
1919
}
2020

2121
export function keccak512(msg: Buffer): Buffer {
22-
const sha3 = new SHA3.SHA3Hash(512);
23-
sha3.update(msg);
24-
return Buffer.from(sha3.digest(), "binary");
22+
const hash = createKeccakHash("keccak512");
23+
hash.update(msg);
24+
return Buffer.from(hash.digest(), "binary");
2525
}

0 commit comments

Comments
 (0)