Skip to content

Commit

Permalink
feat(Eth Legacy): sign from legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
plondon committed May 4, 2018
1 parent d96160a commit da34353
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default ({ coreSagas }) => {
const password = yield call(promptForSecondPassword)
payment = yield payment.amount(effectiveBalance)
payment = yield payment.build()
payment = yield payment.sign(password)
payment = yield payment.signLegacy(password)
yield payment.publish()
yield put(actions.modals.closeAllModals())
yield put(actions.router.push('/eth/transactions'))
Expand Down
15 changes: 14 additions & 1 deletion packages/blockchain-wallet-v4/src/redux/payment/eth/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default ({ api }) => {
case 'ACCOUNT':
return S.kvStore.ethereum.getAccountIndex(appState, prop('address', from)).getOrFail('Could not find ether account index')
case 'LEGACY':
return 0
return 1
}
}
// ///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -113,6 +113,19 @@ export default ({ api }) => {
}
},

* signLegacy (password) {
try {
const appState = yield select(identity)
const seedHexT = S.wallet.getSeedHex(appState, password)
const seedHex = yield call(() => taskToPromise(seedHexT))
const signLegacy = data => taskToPromise(eth.signLegacy(network, seedHex, data))
const signed = yield call(signLegacy, p.raw)
return makePayment(merge(p, { signed }))
} catch (e) {
throw new Error('missing_seed_hex')
}
},

* publish () {
const signed = prop('signed', p)
if (isNil(signed)) throw new Error('missing_signed_tx')
Expand Down
32 changes: 15 additions & 17 deletions packages/blockchain-wallet-v4/src/signer/eth.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,20 @@ export const sign = curry((network = 1, mnemonic, data) => {
return Task.of(rawTx)
})

// TODO
export const signLegacy = curry((network = 1, mnemonic, data) => {
throw new Error('Not implemented exception')
// const { index, to, amount, nonce, gasPrice, gasLimit } = data
// const privateKey = eth.getPrivateKey(mnemonic, index).getWallet().getPrivateKey()
// const txParams = {
// to,
// nonce: toHex(nonce),
// gasPrice: toHex(gasPrice),
// gasLimit: toHex(gasLimit),
// value: toHex(amount),
// chainId: network || 1
// }
export const signLegacy = curry((network = 1, seedHex, data) => {
const { index, to, amount, nonce, gasPrice, gasLimit } = data
const privateKey = eth.getLegacyPrivateKey(seedHex, index)
const txParams = {
to,
nonce: toHex(nonce),
gasPrice: toHex(gasPrice),
gasLimit: toHex(gasLimit),
value: toHex(amount),
chainId: network || 1
}

// const tx = new EthereumTx(txParams)
// tx.signLegacy(privateKey)
// const rawTx = '0x' + tx.serialize().toString('hex')
// return Task.of(rawTx)
const tx = new EthereumTx(txParams)
tx.sign(privateKey)
const rawTx = '0x' + tx.serialize().toString('hex')
return Task.of(rawTx)
})

0 comments on commit da34353

Please sign in to comment.