How to use the @keepkey/device-protocol/lib/exchange_pb.SignedExchangeResponse.deserializeBinary function in @keepkey/device-protocol

To help you get started, we’ve selected a few @keepkey/device-protocol examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shapeshift / hdwallet / packages / hdwallet-keepkey / src / ethereum.ts View on Github external
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)
    }

    if (msg.to) {
      est.setTo(arrayify(msg.to))
github shapeshift / hdwallet / packages / hdwallet-keepkey / src / bitcoin.ts View on Github external
outputs.forEach((o, k) => {
    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(