Skip to content
This repository was archived by the owner on Jun 17, 2021. It is now read-only.

Commit ada304d

Browse files
committed
Restore its original behavior to keccak
1 parent f719cf6 commit ada304d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/hash.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
const createKeccakHash = require('keccak')
22
const createHash = require('create-hash')
3+
const ethjsUtil = require('ethjs-util')
34
import rlp = require('rlp')
45
import { toBuffer, setLength } from './bytes'
56

67
/**
78
* Creates Keccak hash of the input
8-
* @param a The input data (Buffer|Array|String|Number)
9+
* @param a The input data (Buffer|Array|String|Number) If the string is a 0x-prefixed hex value
10+
* it's interpreted as hexadecimal, otherwise as utf8.
911
* @param bits The Keccak width
1012
*/
1113
export const keccak = function(a: any, bits: number = 256): Buffer {
12-
a = toBuffer(a)
14+
if (typeof a === 'string' && !ethjsUtil.isHexString(a)) {
15+
a = Buffer.from(a, 'utf8')
16+
} else {
17+
a = toBuffer(a)
18+
}
19+
1320
if (!bits) bits = 256
1421

1522
return createKeccakHash(`keccak${bits}`)

0 commit comments

Comments
 (0)