How to use the @keepkey/device-protocol/lib/messages_pb.MessageType.MESSAGETYPE_FAILURE 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 / bitcoin.ts View on Github external
tx.setLockTime(msg.locktime || 0)

    let responseType: number
    let response: any
    const { message_enum, proto } = await transport.call(MessageType.MESSAGETYPE_SIGNTX, tx, LONG_TIMEOUT, /*omitLock=*/true) as Event // 5 Minute timeout
    responseType = message_enum
    response = proto

    // Prepare structure for signatures
    const signatures: string[] = new Array(msg.inputs.length).fill(null)
    let serializedTx: string = ''

    try {
      // Begin callback loop
      while (true) {
        if (responseType === MessageType.MESSAGETYPE_FAILURE) {
          const errorResponse = response as Failure
          throw new Error(`Signing failed: ${errorResponse.getMessage()}`)
        }

        if (responseType !== MessageType.MESSAGETYPE_TXREQUEST) {
          throw new Error(`Unexpected message type: ${responseType}`)
        }

        let txRequest = response as TxRequest

        // If there's some part of signed transaction, add it
        if (txRequest.hasSerialized() && txRequest.getSerialized().hasSerializedTx()) {
          serializedTx += toHexString(txRequest.getSerialized().getSerializedTx_asU8())
        }

        if (txRequest.hasSerialized() && txRequest.getSerialized().hasSignatureIndex()) {
github shapeshift / hdwallet / packages / hdwallet-keepkey / src / ethereum.ts View on Github external
let response: EthereumTxRequest
    let nextResponse = await transport.call(MessageType.MESSAGETYPE_ETHEREUMSIGNTX, est, LONG_TIMEOUT, /*omitLock=*/true)
    if (nextResponse.message_enum === MessageType.MESSAGETYPE_FAILURE) {
      throw nextResponse
    }
    response = nextResponse.proto as EthereumTxRequest

    try {
      while (response.hasDataLength()) {
        const dataLength = response.getDataLength()
        dataChunk = dataRemaining.slice(0, dataLength)
        dataRemaining = dataRemaining.slice(dataLength, dataRemaining.length)

        nextResponse = await transport.call(MessageType.MESSAGETYPE_ETHEREUMSIGNTX, est, LONG_TIMEOUT, /*omitLock=*/true)
        if (nextResponse.message_enum === MessageType.MESSAGETYPE_FAILURE) {
          throw nextResponse
        }
        response = nextResponse.proto as EthereumTxRequest
      }
    } catch(error) {
      console.error({ error })
      throw new Error('Failed to sign ETH transaction')
    }

    const r = '0x' + toHexString(response.getSignatureR_asU8())
    const s = '0x' + toHexString(response.getSignatureS_asU8())
    const v = '0x' + response.getSignatureV().toString(16)

    const utx = {
      to: msg.to,
      value: msg.value,
github shapeshift / hdwallet / packages / hdwallet-keepkey / src / ethereum.ts View on Github external
if (msg.data) {
      dataRemaining = arrayify(msg.data)
      est.setDataLength(dataRemaining.length)
      dataChunk = dataRemaining.slice(0, 1024)
      dataRemaining = dataRemaining.slice(dataChunk.length)
      est.setDataInitialChunk(dataChunk)
    }

    if (msg.chainId !== undefined) {
      est.setChainId(msg.chainId)
    }

    let response: EthereumTxRequest
    let nextResponse = await transport.call(MessageType.MESSAGETYPE_ETHEREUMSIGNTX, est, LONG_TIMEOUT, /*omitLock=*/true)
    if (nextResponse.message_enum === MessageType.MESSAGETYPE_FAILURE) {
      throw nextResponse
    }
    response = nextResponse.proto as EthereumTxRequest

    try {
      while (response.hasDataLength()) {
        const dataLength = response.getDataLength()
        dataChunk = dataRemaining.slice(0, dataLength)
        dataRemaining = dataRemaining.slice(dataLength, dataRemaining.length)

        nextResponse = await transport.call(MessageType.MESSAGETYPE_ETHEREUMSIGNTX, est, LONG_TIMEOUT, /*omitLock=*/true)
        if (nextResponse.message_enum === MessageType.MESSAGETYPE_FAILURE) {
          throw nextResponse
        }
        response = nextResponse.proto as EthereumTxRequest
      }

@keepkey/device-protocol

The proto buffer files from the KeepKey device, packed for consumption by the client.

ISC
Latest version published 3 months ago

Package Health Score

63 / 100
Full package analysis

Similar packages