1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
This commit is contained in:
brunobar79 2018-08-11 19:27:24 -04:00
parent 12b41b8fc2
commit 068bf43615
2 changed files with 14 additions and 24 deletions

View File

@ -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
}

View File

@ -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)
@ -181,8 +178,6 @@ class LedgerKeyring extends EventEmitter {
return new Promise((resolve, reject) => {
this.unlock()
.then(_ => {
console.log('[LEDGER]: sending message ', 'ledger-sign-transaction')
this.sendMessage({
action: 'ledger-sign-transaction',
params: {
@ -196,12 +191,11 @@ 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')}`)
@ -209,9 +203,6 @@ class LedgerKeyring extends EventEmitter {
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: {
@ -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