diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-06-08 18:19:02 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-06-08 18:19:02 +0800 |
commit | a328f0c8053173fd8e1f75b808228c3edb617bcc (patch) | |
tree | 42eeb9f4fbff9bd999c61915e688ed496488f180 | |
parent | 8311203f73bf6eff8bcac8d1fb72f9cf8b65c45b (diff) | |
download | dexon-sol-tools-a328f0c8053173fd8e1f75b808228c3edb617bcc.tar dexon-sol-tools-a328f0c8053173fd8e1f75b808228c3edb617bcc.tar.gz dexon-sol-tools-a328f0c8053173fd8e1f75b808228c3edb617bcc.tar.bz2 dexon-sol-tools-a328f0c8053173fd8e1f75b808228c3edb617bcc.tar.lz dexon-sol-tools-a328f0c8053173fd8e1f75b808228c3edb617bcc.tar.xz dexon-sol-tools-a328f0c8053173fd8e1f75b808228c3edb617bcc.tar.zst dexon-sol-tools-a328f0c8053173fd8e1f75b808228c3edb617bcc.zip |
Move isValidSignature back from utils
-rw-r--r-- | src/0x.js.ts | 14 | ||||
-rw-r--r-- | src/utils/utils.ts | 15 |
2 files changed, 13 insertions, 16 deletions
diff --git a/src/0x.js.ts b/src/0x.js.ts index f275d9fbd..8f1178b2a 100644 --- a/src/0x.js.ts +++ b/src/0x.js.ts @@ -40,7 +40,19 @@ export class ZeroEx { assert.doesConformToSchema('signature', signature, ecSignatureSchema); assert.isETHAddressHex('signerAddressHex', signerAddressHex); - return utils.isValidSignature(dataHex, signature, signerAddressHex); + const dataBuff = ethUtil.toBuffer(dataHex); + const msgHashBuff = ethUtil.hashPersonalMessage(dataBuff); + try { + const pubKey = ethUtil.ecrecover( + msgHashBuff, + signature.v, + ethUtil.toBuffer(signature.r), + ethUtil.toBuffer(signature.s)); + const retrievedAddress = ethUtil.bufferToHex(ethUtil.pubToAddress(pubKey)); + return retrievedAddress === signerAddressHex; + } catch (err) { + return false; + } } /** * Generates pseudo-random 256 bit salt. diff --git a/src/utils/utils.ts b/src/utils/utils.ts index ea3d8c7e1..ded2d31fd 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -51,21 +51,6 @@ export const utils = { const hashHex = ethUtil.bufferToHex(hashBuff); return hashHex; }, - isValidSignature(dataHex: string, signature: ECSignature, signerAddressHex: string): boolean { - const dataBuff = ethUtil.toBuffer(dataHex); - const msgHashBuff = ethUtil.hashPersonalMessage(dataBuff); - try { - const pubKey = ethUtil.ecrecover( - msgHashBuff, - signature.v, - ethUtil.toBuffer(signature.r), - ethUtil.toBuffer(signature.s)); - const retrievedAddress = ethUtil.bufferToHex(ethUtil.pubToAddress(pubKey)); - return retrievedAddress === signerAddressHex; - } catch (err) { - return false; - } - }, getCurrentUnixTimestamp(): BigNumber.BigNumber { return new BigNumber(Date.now() / 1000); }, |