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

Commit 9d91f70

Browse files
committed
Make toBuffer fail on non 0x-prefixed strings
1 parent 764d380 commit 9d91f70

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/bytes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ export const toBuffer = function(v: any): Buffer {
7575
if (ethjsUtil.isHexString(v)) {
7676
v = Buffer.from(ethjsUtil.padToEven(ethjsUtil.stripHexPrefix(v)), 'hex')
7777
} else {
78-
v = Buffer.from(v)
78+
throw new Error(
79+
'Cannot convert string to buffer. toBuffer only supports 0x-prefixed hex strings.',
80+
)
7981
}
8082
} else if (typeof v === 'number') {
8183
v = ethjsUtil.intToBuffer(v)

0 commit comments

Comments
 (0)