diff options
author | kumavis <kumavis@users.noreply.github.com> | 2017-01-22 02:06:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-22 02:06:50 +0800 |
commit | 74dc20bdf179cbd8b25f6fae007553784466e3ff (patch) | |
tree | 4b28d3230bf38c68b68e40efcb5b1bf810eacf3e /app/scripts/keyrings/simple.js | |
parent | bc1615f032186e88aebfa9dac38039dcff263162 (diff) | |
parent | 247f7aad5e358fae33616fd310e695e06673dd19 (diff) | |
download | tangerine-wallet-browser-74dc20bdf179cbd8b25f6fae007553784466e3ff.tar tangerine-wallet-browser-74dc20bdf179cbd8b25f6fae007553784466e3ff.tar.gz tangerine-wallet-browser-74dc20bdf179cbd8b25f6fae007553784466e3ff.tar.bz2 tangerine-wallet-browser-74dc20bdf179cbd8b25f6fae007553784466e3ff.tar.lz tangerine-wallet-browser-74dc20bdf179cbd8b25f6fae007553784466e3ff.tar.xz tangerine-wallet-browser-74dc20bdf179cbd8b25f6fae007553784466e3ff.tar.zst tangerine-wallet-browser-74dc20bdf179cbd8b25f6fae007553784466e3ff.zip |
Merge branch 'dev' into obs-store2
Diffstat (limited to 'app/scripts/keyrings/simple.js')
-rw-r--r-- | app/scripts/keyrings/simple.js | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/app/scripts/keyrings/simple.js b/app/scripts/keyrings/simple.js index 9717f1c45..46687fcaf 100644 --- a/app/scripts/keyrings/simple.js +++ b/app/scripts/keyrings/simple.js @@ -20,13 +20,19 @@ class SimpleKeyring extends EventEmitter { } deserialize (privateKeys = []) { - this.wallets = privateKeys.map((privateKey) => { - const stripped = ethUtil.stripHexPrefix(privateKey) - const buffer = new Buffer(stripped, 'hex') - const wallet = Wallet.fromPrivateKey(buffer) - return wallet + return new Promise((resolve, reject) => { + try { + this.wallets = privateKeys.map((privateKey) => { + const stripped = ethUtil.stripHexPrefix(privateKey) + const buffer = new Buffer(stripped, 'hex') + const wallet = Wallet.fromPrivateKey(buffer) + return wallet + }) + } catch (e) { + reject(e) + } + resolve() }) - return Promise.resolve() } addAccounts (n = 1) { @@ -35,12 +41,12 @@ class SimpleKeyring extends EventEmitter { newWallets.push(Wallet.generate()) } this.wallets = this.wallets.concat(newWallets) - const hexWallets = newWallets.map(w => w.getAddress().toString('hex')) + const hexWallets = newWallets.map(w => ethUtil.bufferToHex(w.getAddress())) return Promise.resolve(hexWallets) } getAccounts () { - return Promise.resolve(this.wallets.map(w => w.getAddress().toString('hex'))) + return Promise.resolve(this.wallets.map(w => ethUtil.bufferToHex(w.getAddress()))) } // tx is an instance of the ethereumjs-transaction class. @@ -54,7 +60,7 @@ class SimpleKeyring extends EventEmitter { // For eth_sign, we need to sign transactions: signMessage (withAccount, data) { const wallet = this._getWalletForAccount(withAccount) - const message = ethUtil.removeHexPrefix(data) + const message = ethUtil.stripHexPrefix(data) var privKey = wallet.getPrivateKey() var msgSig = ethUtil.ecsign(new Buffer(message, 'hex'), privKey) var rawMsgSig = ethUtil.bufferToHex(sigUtil.concatSig(msgSig.v, msgSig.r, msgSig.s)) @@ -70,7 +76,9 @@ class SimpleKeyring extends EventEmitter { /* PRIVATE METHODS */ _getWalletForAccount (account) { - return this.wallets.find(w => w.getAddress().toString('hex') === account) + let wallet = this.wallets.find(w => ethUtil.bufferToHex(w.getAddress()) === account) + if (!wallet) throw new Error('Simple Keyring - Unable to find matching address.') + return wallet } } |