Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
}
if (msg.to) {
est.setTo(arrayify(msg.to))
}
const output: BTCSignTxOutput = o
const newOutput = new TxOutputType()
newOutput.setAmount(Number(output.amount))
if (output.exchangeType) {
// convert the base64 encoded signedExchangeResponse message into the correct object
const signedHex = base64toHEX(output.exchangeType.signedExchangeResponse)
const signedExchange = SignedExchangeResponse.deserializeBinary(arrayify(signedHex))
// decode the deposit amount from a little-endian Uint8Array into an unsigned uint64
let depAmt = signedExchange.getResponsev2().getDepositAmount_asU8()
let val = 0
for (let jj = depAmt.length - 1; jj >= 0; jj--) {
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)