How to use @shapeshiftoss/hdwallet-core - 10 common examples

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-ledger-webusb / src / adapter.ts View on Github external
private async handleDisconnectWebUSBLedger(e: USBConnectionEvent): Promise {
    if (e.device.vendorId !== VENDOR_ID) return

    await timeout(APP_NAVIGATION_DELAY) // timeout gives time to detect if it is an app navigation based disconnec/connect event

    if (this.connectTimestamp !== 0) return

    try {
      await this.keyring.remove(e.device.serialNumber)
    } catch(e) {
      console.error(e)
    } finally {
      this.keyring.emit([e.device.manufacturerName, e.device.productName, Events.DISCONNECT], e.device.serialNumber)
    }
  }
github shapeshift / hdwallet / packages / hdwallet-ledger-webusb / src / transport.ts View on Github external
public async call(coin: string, method: string, ...args: any[]): Promise {
    let response

    try {
      this.emit(`ledger.${coin}.${method}.call`, makeEvent({
        message_type: method,
        from_wallet: false,
        message: {}
      }))

      if (coin) {
        response = await new (translateCoin(coin))(this.transport)[method](...args)
      } else {
        // @ts-ignore
        response = await (translateMethod(method))(this.transport, ...args)
      }
    } catch (e) {
      console.error(e)
      return {
        success: false,
        payload: { error: e.toString() },
github shapeshift / hdwallet / integration / src / ethereum / ethereum.ts View on Github external
test('ethSignMessage()', async () => {
      if (!wallet) return
      if (isLedger(wallet)) return // FIXME: Expected failure
      let res = await wallet.ethSignMessage({
        addressNList: bip32ToAddressNList("m/44'/60'/0'/0/0"),
        message: 'Hello World'
      })
      expect(res.address).toEqual('0x3f2329C9ADFbcCd9A84f52c906E936A42dA18CB8')
      expect(res.signature).toEqual('0x29f7212ecc1c76cea81174af267b67506f754ea8c73f144afa900a0d85b24b21319621aeb062903e856352f38305710190869c3ce5a1425d65ef4fa558d0fc251b')
    }, TIMEOUT)
github shapeshift / hdwallet / integration / src / bitcoin / bitcoin.ts View on Github external
test('btcSignMessage()', async () => {
      if (!wallet) return
      let res = await wallet.btcSignMessage({
        addressNList: bip32ToAddressNList("m/44'/0'/0'/0/0"),
        coin: 'Bitcoin',
        scriptType: BTCInputScriptType.SpendAddress,
        message: "Hello World"
      })

      // not implemented on portis
      if(isPortis(wallet)) {
        expect(res).toEqual(undefined)
        return
      }

      expect(res).toEqual({
        address: "1FH6ehAd5ZFXCM1cLGzHxK1s4dGdq1JusM",
        signature: "20a037c911044cd6c851b6508317d8892067b0b62074b2cf1c0df9abd4aa053a3c243ffdc37f64d7af2c857128eafc81947c380995596615e5dcc313a15f512cdd",
      })
    }, TIMEOUT)
github shapeshift / hdwallet / packages / hdwallet-portis / src / portis.ts View on Github external
this.portisCallInProgress = new Promise( async (resolve, reject) => {
      try {
          await this.portisCallInProgress
      } catch (e) {
          console.error(e)
      }
      for (let i = 0; i < msg.length; i++) {
        const { addressNList, coin } = msg[i];
        const bitcoinSlip44 = 0x80000000 + slip44ByCoin('Bitcoin')
        // TODO we really shouldnt be every using the "bitcoin" string parameter but is here for now to make it work with their btc address on their portis wallet.
        const portisResult = await this.portis.getExtendedPublicKey(addressNListToBIP32(addressNList), addressNList[1] === bitcoinSlip44 ? 'Bitcoin' : '')
        const { result, error } = portisResult
        if(error)
          reject(error)
        publicKeys.push({ xpub: result })
      }
      resolve(publicKeys)
    })
    return this.portisCallInProgress
github shapeshift / hdwallet / packages / hdwallet-keepkey / src / ethereum.ts View on Github external
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
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 / ethereum.ts View on Github external
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)
github shapeshift / hdwallet / packages / hdwallet-keepkey / src / ethereum.ts View on Github external
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))
github shapeshift / hdwallet / packages / hdwallet-react / src / context / HDWalletProvider.tsx View on Github external
};
    });

    // Initialize each of the adapters
    await Promise.all(
      adapters.map(async ({ name, adapter, config }) => {
        console.debug(`[HDWallet] - ✅ Initializing ${name} adapter`, config);
        try {
          return await adapter.initialize(/* undefined, false, false*/);
        } catch (err) {
          console.error(err.message);
        }
      })
    );

    this.keyring.on(["*", "*", Events.CONNECT], this.handleDeviceConnect);
    this.keyring.on(["*", "*", Events.DISCONNECT], this.handleDeviceDisconnect);

    // This will fail out of sync if device is connected/disconnected
    const pairedDevices = this.keyring.wallets;
    this.adapters = adapters;

    this.setState({
      pairedDevices
    });
  }