diff options
author | Dan Finlay <dan@danfinlay.com> | 2016-06-17 02:46:35 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2016-06-17 02:46:35 +0800 |
commit | 408addb1b2a795515149dbde8131fa40cba721f4 (patch) | |
tree | 73421e7b49a1aca972a22f53b39cfb9cd7a6a18e /app/scripts/lib | |
parent | 6b0a99a09ac9efce4cf54d84e9362ac3b6b35a3d (diff) | |
download | tangerine-wallet-browser-408addb1b2a795515149dbde8131fa40cba721f4.tar tangerine-wallet-browser-408addb1b2a795515149dbde8131fa40cba721f4.tar.gz tangerine-wallet-browser-408addb1b2a795515149dbde8131fa40cba721f4.tar.bz2 tangerine-wallet-browser-408addb1b2a795515149dbde8131fa40cba721f4.tar.lz tangerine-wallet-browser-408addb1b2a795515149dbde8131fa40cba721f4.tar.xz tangerine-wallet-browser-408addb1b2a795515149dbde8131fa40cba721f4.tar.zst tangerine-wallet-browser-408addb1b2a795515149dbde8131fa40cba721f4.zip |
Fixed signing of hashes
Signing now always takes a 64 digit hex string, and returns a message signature which appropriately pads r, s, and v with zeroes.
Need to verify with Denis that this is the behavior he requires.
Diffstat (limited to 'app/scripts/lib')
-rw-r--r-- | app/scripts/lib/id-management.js | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/app/scripts/lib/id-management.js b/app/scripts/lib/id-management.js index 0edd2e336..30a3141f1 100644 --- a/app/scripts/lib/id-management.js +++ b/app/scripts/lib/id-management.js @@ -39,16 +39,14 @@ function IdManagement(opts) { return rawTx } - this.signMsg = function(address, message){ + this.signMsg = function (address, message) { // sign message - var privKeyHex = this.exportPrivateKey(address) - var privKey = ethUtil.toBuffer(privKeyHex) - var msgHash = ethUtil.sha3(message) - var msgBuffer = new Buffer(message.replace('0x',''), 'hex') - var msgSig = ethUtil.ecsign(msgBuffer, privKey) - var rawMsgSig = ethUtil.bufferToHex(concatSig(msgSig.v, msgSig.r, msgSig.s)) - return rawMsgSig - } + var privKeyHex = this.exportPrivateKey(address); + var privKey = ethUtil.toBuffer(privKeyHex); + var msgSig = ethUtil.ecsign(new Buffer(message.replace('0x',''), 'hex'), privKey); + var rawMsgSig = ethUtil.bufferToHex(concatSig(msgSig.v, msgSig.r, msgSig.s)); + return rawMsgSig; + }; this.getSeed = function(){ return this.keyStore.getSeed(this.derivedKey) @@ -71,9 +69,8 @@ function pad_with_zeroes(number, length){ function concatSig(v, r, s) { r = pad_with_zeroes(ethUtil.fromSigned(r), 64) s = pad_with_zeroes(ethUtil.fromSigned(s), 64) - v = ethUtil.bufferToInt(v) - r = ethUtil.toUnsigned(r).toString('hex') - s = ethUtil.toUnsigned(s).toString('hex') + r = ethUtil.stripHexPrefix(r.toString('hex')) + s = ethUtil.stripHexPrefix(s.toString('hex')) v = ethUtil.stripHexPrefix(ethUtil.intToHex(v)) - return ethUtil.addHexPrefix(r.concat(s, v).toString("hex")) + return ethUtil.addHexPrefix(r.concat(s, v)) } |