aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/scripts/controllers/transactions/index.js4
-rw-r--r--app/scripts/eth-ledger-keyring-listener.js34
2 files changed, 14 insertions, 24 deletions
diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js
index 8e2288aed..7ac6ec2e6 100644
--- a/app/scripts/controllers/transactions/index.js
+++ b/app/scripts/controllers/transactions/index.js
@@ -289,10 +289,10 @@ class TransactionController extends EventEmitter {
// sign tx
const fromAddress = txParams.from
const ethTx = new Transaction(txParams)
- await this.signEthTx(ethTx, fromAddress)
+ const signedTx = await this.signEthTx(ethTx, fromAddress)
// set state to signed
this.txStateManager.setTxStatusSigned(txMeta.id)
- const rawTx = ethUtil.bufferToHex(ethTx.serialize())
+ const rawTx = ethUtil.bufferToHex(signedTx.serialize())
return rawTx
}
diff --git a/app/scripts/eth-ledger-keyring-listener.js b/app/scripts/eth-ledger-keyring-listener.js
index 92c85f600..0043058e6 100644
--- a/app/scripts/eth-ledger-keyring-listener.js
+++ b/app/scripts/eth-ledger-keyring-listener.js
@@ -9,7 +9,7 @@ const Transaction = require('ethereumjs-tx')
// HD path differs from eth-hd-keyring - MEW, Parity, Geth and Official Ledger clients use same unusual derivation for Ledger
const hdPathString = `44'/60'/0'`
const type = 'Ledger Hardware'
-const ORIGIN = 'https://localhost:3000'
+const ORIGIN = 'https://localhost:3000'
const pathBase = 'm'
const MAX_INDEX = 1000
@@ -27,21 +27,18 @@ class LedgerKeyring extends EventEmitter {
this.deserialize(opts)
}
- setupIframe(){
+ setupIframe () {
this.iframe = document.createElement('iframe')
this.iframe.src = ORIGIN
console.log('Injecting ledger iframe')
document.head.appendChild(this.iframe)
-
- console.log('[LEDGER]: LEDGER FROM-IFRAME LISTENER READY')
-
}
- sendMessage(msg, cb) {
+ sendMessage (msg, cb) {
console.log('[LEDGER]: SENDING MESSAGE TO IFRAME', msg)
this.iframe.contentWindow.postMessage({...msg, target: 'LEDGER-IFRAME'}, '*')
window.addEventListener('message', ({ origin, data }) => {
- if(origin !== ORIGIN) return false
+ if (origin !== ORIGIN) return false
if (data && data.action && data.action === `${msg.action}-reply`) {
console.log('[LEDGER]: GOT MESAGE FROM IFRAME', data)
cb(data)
@@ -79,7 +76,7 @@ class LedgerKeyring extends EventEmitter {
hdPath: this.hdPath,
},
},
- ({action, success, payload}) => {
+ ({action, success, payload}) => {
if (success) {
this.hdk.publicKey = new Buffer(payload.publicKey, 'hex')
this.hdk.chainCode = new Buffer(payload.chainCode, 'hex')
@@ -177,12 +174,10 @@ class LedgerKeyring extends EventEmitter {
// tx is an instance of the ethereumjs-transaction class.
async signTransaction (address, tx) {
-
+
return new Promise((resolve, reject) => {
this.unlock()
.then(_ => {
- console.log('[LEDGER]: sending message ', 'ledger-sign-transaction')
-
this.sendMessage({
action: 'ledger-sign-transaction',
params: {
@@ -196,26 +191,22 @@ class LedgerKeyring extends EventEmitter {
gasLimit: this._normalize(tx.gasLimit),
gasPrice: this._normalize(tx.gasPrice),
},
- path: this._pathFromAddress(address)
+ path: this._pathFromAddress(address),
},
},
({action, success, payload}) => {
if (success) {
- console.log('[LEDGER]: got tx signed!', payload.txData)
const signedTx = new Transaction(payload.txData)
// Validate that the signature matches the right address
const addressSignedWith = ethUtil.toChecksumAddress(`0x${signedTx.from.toString('hex')}`)
const correctAddress = ethUtil.toChecksumAddress(address)
if (addressSignedWith !== correctAddress) {
reject('signature doesnt match the right address')
- }
- console.log('[LEDGER]: all good!', signedTx.toJSON())
- console.log('[LEDGER]: signedTX', `0x${signedTx.serialize().toString('hex')}`)
-
+ }
resolve(signedTx)
} else {
reject(payload)
- }
+ }
})
})
})
@@ -230,7 +221,6 @@ class LedgerKeyring extends EventEmitter {
return new Promise((resolve, reject) => {
this.unlock()
.then(_ => {
- console.log('[LEDGER]: sending message ', 'ledger-sign-personal-message')
this.sendMessage({
action: 'ledger-sign-personal-message',
params: {
@@ -243,7 +233,7 @@ class LedgerKeyring extends EventEmitter {
resolve(payload)
} else {
reject(payload)
- }
+ }
})
})
})
@@ -315,8 +305,8 @@ class LedgerKeyring extends EventEmitter {
return str
}
- _fixNonce(nonce){
- if(nonce === '0x'){
+ _fixNonce (nonce) {
+ if (nonce === '0x') {
return `${nonce}0`
}
return nonce