How to use the @shapeshiftoss/hdwallet-core.BTCInputScriptType.SpendAddress function in @shapeshiftoss/hdwallet-core

To help you get started, we’ve selected a few @shapeshiftoss/hdwallet-core 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
// 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)
      newOutput.setAddressType(OutputAddressType.CHANGE)
    } else {
      newOutput.setScriptType(OutputScriptType.PAYTOADDRESS)
      newOutput.setAddress(output.address)
      newOutput.setAddressType(OutputAddressType.SPEND)
    }
    unsignedTx.addOutputs(newOutput, k)
  })
github shapeshift / hdwallet / packages / hdwallet-keepkey / src / ethereum.ts View on Github external
}

    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))
    }

    let dataChunk = null
    let dataRemaining = undefined

    if (msg.data) {
github shapeshift / hdwallet / integration / src / bitcoin / bitcoin.ts View on Github external
test('btcGetAccountPaths()', async () => {
      await each([
        ['Bitcoin',     0, undefined],
        ['Bitcoin',     1, BTCInputScriptType.SpendAddress],
        ['Bitcoin',     3, BTCInputScriptType.SpendP2SHWitness],
        ['Bitcoin',     2, BTCInputScriptType.SpendWitness],
        ['Litecoin',    1, BTCInputScriptType.SpendAddress],
        ['Litecoin',    1, BTCInputScriptType.SpendP2SHWitness],
        ['Dash',        0, BTCInputScriptType.SpendAddress],
        ['Dogecoin',    0, BTCInputScriptType.SpendAddress],
        ['BitcoinCash', 0, BTCInputScriptType.SpendAddress],
        ['BitcoinGold', 0, BTCInputScriptType.SpendAddress],
      ], async (args) => {
        let coin = args[0] as Coin
        let accountIdx = args[1] as number
        let scriptType = args[2] as BTCInputScriptType
        if (!wallet) return
        if (!await wallet.btcSupportsCoin(coin))
          return
        expect(await info.btcSupportsCoin(coin)).toBeTruthy()
github shapeshift / hdwallet / integration / src / bitcoin / bitcoin.ts View on Github external
test('btcGetAccountPaths()', async () => {
      await each([
        ['Bitcoin',     0, undefined],
        ['Bitcoin',     1, BTCInputScriptType.SpendAddress],
        ['Bitcoin',     3, BTCInputScriptType.SpendP2SHWitness],
        ['Bitcoin',     2, BTCInputScriptType.SpendWitness],
        ['Litecoin',    1, BTCInputScriptType.SpendAddress],
        ['Litecoin',    1, BTCInputScriptType.SpendP2SHWitness],
        ['Dash',        0, BTCInputScriptType.SpendAddress],
        ['Dogecoin',    0, BTCInputScriptType.SpendAddress],
        ['BitcoinCash', 0, BTCInputScriptType.SpendAddress],
        ['BitcoinGold', 0, BTCInputScriptType.SpendAddress],
      ], async (args) => {
        let coin = args[0] as Coin
        let accountIdx = args[1] as number
        let scriptType = args[2] as BTCInputScriptType
        if (!wallet) return
        if (!await wallet.btcSupportsCoin(coin))
          return
        expect(await info.btcSupportsCoin(coin)).toBeTruthy()
        if (!await wallet.btcSupportsScriptType(coin, scriptType))
          return
        expect(await info.btcSupportsScriptType(coin, scriptType)).toBeTruthy()
        let paths = wallet.btcGetAccountPaths({ coin: coin, accountIdx: accountIdx, scriptType: scriptType })
        expect(paths.length > 0).toBeTruthy()
        if (scriptType !== undefined)
          expect(paths.filter(path => { return path.scriptType !== scriptType })).toHaveLength(0)
github shapeshift / hdwallet / integration / src / bitcoin / bitcoin.ts View on Github external
test('btcGetAddress()', async () => {
      if (!wallet || isPortis(wallet)) return
      await each([
        ['Show', 'Bitcoin',  "m/44'/0'/0'/0/0", BTCInputScriptType.SpendAddress,     '1FH6ehAd5ZFXCM1cLGzHxK1s4dGdq1JusM'],
        ['Show', 'Bitcoin',  "m/49'/0'/0'/0/0", BTCInputScriptType.SpendP2SHWitness, '3AnYTd2FGxJLNKL1AzxfW3FJMntp9D2KKX'],
        ['Tell', 'Bitcoin',  "m/49'/0'/0'/0/0", BTCInputScriptType.SpendP2SHWitness, '3AnYTd2FGxJLNKL1AzxfW3FJMntp9D2KKX'],
        ['Tell', 'Litecoin', "m/49'/2'/0'/0/0", BTCInputScriptType.SpendP2SHWitness, 'MFoQRU1KQq365Sy3cXhix3ygycEU4YWB1V'],
        ['Tell', 'Dash',     "m/44'/5'/0'/0/0", BTCInputScriptType.SpendAddress,     'XxKhGNv6ECbqVswm9KYcLPQnyWgZ86jJ6Q'],
      ], async (args) => {
        let mode = args[0] as string
        let coin = args[1] as Coin
        let path = args[2] as string
        let scriptType = args[3] as BTCInputScriptType
        let expected = args[4] as string

        if (!await wallet.btcSupportsCoin(coin)) return
        expect(await info.btcSupportsCoin(coin)).toBeTruthy()
        if (!await wallet.btcSupportsScriptType(coin, scriptType)) return
        expect(await info.btcSupportsScriptType(coin, scriptType)).toBeTruthy()
        let res = await wallet.btcGetAddress({
github shapeshift / hdwallet / packages / hdwallet-keepkey / src / bitcoin.ts View on Github external
function legacyAccount (coin: Coin, slip44: number, accountIdx: number): BTCAccountPath {
  return {
    coin,
    scriptType: BTCInputScriptType.SpendAddress,
    addressNList: [ 0x80000000 + 44, 0x80000000 + slip44, 0x80000000 + accountIdx ]
  }
}
github shapeshift / hdwallet / packages / hdwallet-ledger / src / bitcoin.ts View on Github external
export async function btcSupportsScriptType (coin: Coin, scriptType: BTCInputScriptType): Promise {
  const supported = {
    Bitcoin: [
      BTCInputScriptType.SpendAddress,
      BTCInputScriptType.SpendWitness,
      BTCInputScriptType.SpendP2SHWitness
    ],
    BitcoinCash: [
      BTCInputScriptType.SpendAddress
    ]
  }

  return !!supported[coin] && supported[coin].includes(scriptType)
}
github shapeshift / hdwallet / packages / hdwallet-portis / src / bitcoin.ts View on Github external
export function verifyScriptTypePurpose(scriptType: BTCInputScriptType, purpose: number): boolean {
  return (
      (purpose === 0x80000000 + 44 && scriptType === BTCInputScriptType.SpendAddress ) ||
      (purpose === 0x80000000 + 49 && scriptType === BTCInputScriptType.SpendP2SHWitness ) ||
      (purpose === 0x80000000 + 84 && scriptType === BTCInputScriptType.SpendWitness )
  )
}
github shapeshift / hdwallet / integration / src / wallets / trezor.ts View on Github external
isKnown: true,
      accountIdx: 0,
      addressIdx: 0,
      wholeAccount: false,
      isChange: false,
      isPrefork: false,
    })

    expect(wallet.info.describePath({
      path: bip32ToAddressNList("m/44'/0'/7'/1/5"),
      coin: 'Bitcoin',
      scriptType: BTCInputScriptType.SpendAddress
    })).toEqual({
      verbose: "Bitcoin Account #7, Change Address #5 (Legacy)",
      coin: 'Bitcoin',
      scriptType: BTCInputScriptType.SpendAddress,
      isKnown: true,
      accountIdx: 7,
      addressIdx: 5,
      wholeAccount: false,
      isChange: true,
      isPrefork: false,
    })

    expect(wallet.info.describePath({
      path: bip32ToAddressNList("m/44'/0'/7'/1/5"),
      coin: 'BitcoinCash',
      scriptType: BTCInputScriptType.SpendAddress
    })).toEqual({
      verbose: "m/44'/0'/7'/1/5",
      coin: 'BitcoinCash',
      scriptType: BTCInputScriptType.SpendAddress,
github shapeshift / hdwallet / packages / hdwallet-ledger / src / bitcoin.ts View on Github external
export async function btcSupportsScriptType (coin: Coin, scriptType: BTCInputScriptType): Promise {
  const supported = {
    Bitcoin: [
      BTCInputScriptType.SpendAddress,
      BTCInputScriptType.SpendWitness,
      BTCInputScriptType.SpendP2SHWitness
    ],
    BitcoinCash: [
      BTCInputScriptType.SpendAddress
    ]
  }

  return !!supported[coin] && supported[coin].includes(scriptType)
}