aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <somniac@me.com>2016-06-21 06:08:27 +0800
committerGitHub <noreply@github.com>2016-06-21 06:08:27 +0800
commit61459a6b51948a0c6e4ac904a242eabb54b55be0 (patch)
treeb6f168a27484b40784d991cf55b43875e8ed4374 /app
parent7ecc028c5db7d53d00a15c607e1bec711dae7213 (diff)
parent451be3b10e4550d80cf11c73f38e879d13a15e3d (diff)
downloadtangerine-wallet-browser-61459a6b51948a0c6e4ac904a242eabb54b55be0.tar
tangerine-wallet-browser-61459a6b51948a0c6e4ac904a242eabb54b55be0.tar.gz
tangerine-wallet-browser-61459a6b51948a0c6e4ac904a242eabb54b55be0.tar.bz2
tangerine-wallet-browser-61459a6b51948a0c6e4ac904a242eabb54b55be0.tar.lz
tangerine-wallet-browser-61459a6b51948a0c6e4ac904a242eabb54b55be0.tar.xz
tangerine-wallet-browser-61459a6b51948a0c6e4ac904a242eabb54b55be0.tar.zst
tangerine-wallet-browser-61459a6b51948a0c6e4ac904a242eabb54b55be0.zip
Merge pull request #294 from MetaMask/SignFullDataNotHash
Sign full data not hash
Diffstat (limited to 'app')
-rw-r--r--app/scripts/lib/id-management.js76
-rw-r--r--app/scripts/lib/idStore.js77
2 files changed, 77 insertions, 76 deletions
diff --git a/app/scripts/lib/id-management.js b/app/scripts/lib/id-management.js
new file mode 100644
index 000000000..30a3141f1
--- /dev/null
+++ b/app/scripts/lib/id-management.js
@@ -0,0 +1,76 @@
+const ethUtil = require('ethereumjs-util')
+
+module.exports = IdManagement
+
+function IdManagement(opts) {
+ if (!opts) opts = {}
+
+ this.keyStore = opts.keyStore
+ this.derivedKey = opts.derivedKey
+ this.hdPathString = "m/44'/60'/0'/0"
+
+ this.getAddresses = function(){
+ return keyStore.getAddresses(this.hdPathString).map(function(address){ return '0x'+address })
+ }
+
+ this.signTx = function(txParams){
+ // normalize values
+ txParams.to = ethUtil.addHexPrefix(txParams.to)
+ txParams.from = ethUtil.addHexPrefix(txParams.from)
+ txParams.value = ethUtil.addHexPrefix(txParams.value)
+ txParams.data = ethUtil.addHexPrefix(txParams.data)
+ txParams.gasLimit = ethUtil.addHexPrefix(txParams.gasLimit || txParams.gas)
+ txParams.nonce = ethUtil.addHexPrefix(txParams.nonce)
+ var tx = new Transaction(txParams)
+
+ // sign tx
+ var privKeyHex = this.exportPrivateKey(txParams.from)
+ var privKey = ethUtil.toBuffer(privKeyHex)
+ tx.sign(privKey)
+
+ // Add the tx hash to the persisted meta-tx object
+ var txHash = ethUtil.bufferToHex(tx.hash())
+ var metaTx = configManager.getTx(txParams.metamaskId)
+ metaTx.hash = txHash
+ configManager.updateTx(metaTx)
+
+ // return raw serialized tx
+ var rawTx = ethUtil.bufferToHex(tx.serialize())
+ return rawTx
+ }
+
+ this.signMsg = function (address, message) {
+ // sign message
+ 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)
+ }
+
+ this.exportPrivateKey = function(address) {
+ var privKeyHex = ethUtil.addHexPrefix(this.keyStore.exportPrivateKey(address, this.derivedKey, this.hdPathString))
+ return privKeyHex
+ }
+}
+
+function pad_with_zeroes(number, length){
+ var my_string = '' + number;
+ while (my_string.length < length) {
+ my_string = '0' + my_string;
+ }
+ return my_string;
+}
+
+function concatSig(v, r, s) {
+ r = pad_with_zeroes(ethUtil.fromSigned(r), 64)
+ s = pad_with_zeroes(ethUtil.fromSigned(s), 64)
+ 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))
+}
diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js
index d569174dc..8c736eac9 100644
--- a/app/scripts/lib/idStore.js
+++ b/app/scripts/lib/idStore.js
@@ -13,6 +13,7 @@ const autoFaucet = require('./auto-faucet')
const configManager = require('./config-manager-singleton')
const messageManager = require('./message-manager')
const DEFAULT_RPC = 'https://testrpc.metamask.io/'
+const IdManagement = require('./id-management')
module.exports = IdentityStore
@@ -478,82 +479,6 @@ IdentityStore.prototype._autoFaucet = function() {
autoFaucet(addresses[0])
}
-function IdManagement(opts) {
- if (!opts) opts = {}
-
- this.keyStore = opts.keyStore
- this.derivedKey = opts.derivedKey
- this.hdPathString = "m/44'/60'/0'/0"
-
- this.getAddresses = function(){
- return keyStore.getAddresses(this.hdPathString).map(function(address){ return '0x'+address })
- }
-
- this.signTx = function(txParams){
- // normalize values
- txParams.to = ethUtil.addHexPrefix(txParams.to)
- txParams.from = ethUtil.addHexPrefix(txParams.from)
- txParams.value = ethUtil.addHexPrefix(txParams.value)
- txParams.data = ethUtil.addHexPrefix(txParams.data)
- txParams.gasLimit = ethUtil.addHexPrefix(txParams.gasLimit || txParams.gas)
- txParams.nonce = ethUtil.addHexPrefix(txParams.nonce)
- var tx = new Transaction(txParams)
-
- // sign tx
- var privKeyHex = this.exportPrivateKey(txParams.from)
- var privKey = ethUtil.toBuffer(privKeyHex)
- tx.sign(privKey)
-
- // Add the tx hash to the persisted meta-tx object
- var txHash = ethUtil.bufferToHex(tx.hash())
- var metaTx = configManager.getTx(txParams.metamaskId)
- metaTx.hash = txHash
- configManager.updateTx(metaTx)
-
- // return raw serialized tx
- var rawTx = ethUtil.bufferToHex(tx.serialize())
- return rawTx
- }
-
- this.signMsg = function(address, message){
- // sign message
- var privKeyHex = this.exportPrivateKey(address)
- var privKey = ethUtil.toBuffer(privKeyHex)
- var msgHash = ethUtil.sha3(message)
- var msgSig = ethUtil.ecsign(msgHash, privKey)
- var rawMsgSig = ethUtil.bufferToHex(concatSig(msgSig.v, msgSig.r, msgSig.s))
- return rawMsgSig
- }
-
- this.getSeed = function(){
- return this.keyStore.getSeed(this.derivedKey)
- }
-
- this.exportPrivateKey = function(address) {
- var privKeyHex = ethUtil.addHexPrefix(this.keyStore.exportPrivateKey(address, this.derivedKey, this.hdPathString))
- return privKeyHex
- }
-}
-
-
// util
function noop(){}
-
-function pad_with_zeroes(number, length){
- var my_string = '' + number;
- while (my_string.length < length) {
- my_string = '0' + my_string;
- }
- return my_string;
-}
-
-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')
- v = ethUtil.stripHexPrefix(ethUtil.intToHex(v))
- return ethUtil.addHexPrefix(r.concat(s, v).toString("hex"))
-}