From 98196846f6013ef3012e2c4864daf196f5c0ace0 Mon Sep 17 00:00:00 2001 From: junaidtaj Date: Fri, 19 Jul 2019 12:54:17 +0200 Subject: [PATCH 1/2] fixed #46, toMinHex will complain if non hex is passed --- src/util/util.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/util/util.ts b/src/util/util.ts index f681f23..07d94c8 100644 --- a/src/util/util.ts +++ b/src/util/util.ts @@ -168,13 +168,20 @@ export function getAddress(pk: string) { export function toMinHex(key: string | Buffer | number) { if (typeof key === 'number') key = toHex(key) + if (typeof key === 'string') { + key = key.trim() + + if(key.length<3 || key[0]!='0' || key[1]!='x') + throw new Error("Only Hex format is supported. Given value "+ key +" is not valid Hex ") + for (let i = 2; i < key.length; i++) { if (key[i] !== '0') return '0x' + key.substr(i) } } else if (Buffer.isBuffer(key)) { + console.log("s") const hex = key.toString('hex') for (let i = 0; i < hex.length; i++) { if (hex[i] !== '0') From 2bc93f0d05e5a78519a1f6e3045e7fafefc4c38e Mon Sep 17 00:00:00 2001 From: junaidtaj Date: Fri, 19 Jul 2019 15:20:41 +0200 Subject: [PATCH 2/2] reverting check --- src/util/util.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util/util.ts b/src/util/util.ts index 07d94c8..53fa6bb 100644 --- a/src/util/util.ts +++ b/src/util/util.ts @@ -181,7 +181,6 @@ export function toMinHex(key: string | Buffer | number) { } } else if (Buffer.isBuffer(key)) { - console.log("s") const hex = key.toString('hex') for (let i = 0; i < hex.length; i++) { if (hex[i] !== '0')