Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return transport.lockDuring(async () => {
const est: EthereumSignTx = new EthereumSignTx()
est.setAddressNList(msg.addressNList)
est.setNonce(arrayify(msg.nonce))
est.setGasPrice(arrayify(msg.gasPrice))
est.setGasLimit(arrayify(msg.gasLimit))
if (msg.value.match('^0x0*$') === null) {
est.setValue(arrayify(msg.value))
}
if (msg.toAddressNList) {
est.setAddressType(OutputAddressType.SPEND)
est.setToAddressNList(msg.toAddressNList)
} else if (msg.exchangeType) {
est.setAddressType(OutputAddressType.EXCHANGE)
const signedHex = base64toHEX(msg.exchangeType.signedExchangeResponse)
const signedExchangeOut = SignedExchangeResponse.deserializeBinary(arrayify(signedHex))
const exchangeType = new ExchangeType()
exchangeType.setSignedExchangeResponse(signedExchangeOut)
exchangeType.setWithdrawalCoinName(msg.exchangeType.withdrawalCoinName) // KeepKey firmware will complain if this doesn't match signed exchange response
exchangeType.setWithdrawalAddressNList(msg.exchangeType.withdrawalAddressNList)
exchangeType.setWithdrawalScriptType(translateInputScriptType(
msg.exchangeType.withdrawalScriptType || BTCInputScriptType.SpendAddress))
exchangeType.setReturnAddressNList(msg.exchangeType.returnAddressNList)
exchangeType.setReturnScriptType(translateInputScriptType(
msg.exchangeType.returnScriptType || BTCInputScriptType.SpendAddress))
est.setExchangeType(exchangeType)
} else {
est.setAddressType(OutputAddressType.SPEND)
}
val += depAmt[jj] * Math.pow(2,(8 * (depAmt.length - jj - 1)))
// TODO validate is uint64
}
const outExchangeType = new ExchangeType()
outExchangeType.setSignedExchangeResponse(signedExchange)
outExchangeType.setWithdrawalCoinName(output.exchangeType.withdrawalCoinName)
outExchangeType.setWithdrawalAddressNList(output.exchangeType.withdrawalAddressNList)
outExchangeType.setWithdrawalScriptType(translateInputScriptType(
output.exchangeType.withdrawalScriptType || BTCInputScriptType.SpendAddress))
outExchangeType.setReturnAddressNList(output.exchangeType.returnAddressNList)
outExchangeType.setReturnScriptType(translateInputScriptType(
output.exchangeType.returnScriptType || BTCInputScriptType.SpendAddress))
newOutput.setAmount(val)
newOutput.setAddress(signedExchange.toObject().responsev2.depositAddress.address)
newOutput.setScriptType(OutputScriptType.PAYTOADDRESS)
newOutput.setAddressType(OutputAddressType.EXCHANGE)
newOutput.setExchangeType(outExchangeType)
} else if (output.isChange) {
newOutput.setScriptType(translateOutputScriptType(output.scriptType))
newOutput.setAddressNList(output.addressNList)
newOutput.setAddressType(OutputAddressType.CHANGE)
} else {
newOutput.setScriptType(OutputScriptType.PAYTOADDRESS)
newOutput.setAddress(output.address)
newOutput.setAddressType(OutputAddressType.SPEND)
}
unsignedTx.addOutputs(newOutput, k)
})