How to use the @shapeshiftoss/hdwallet-core.FirmwareUpdateRequired 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-webusb / src / transport.ts View on Github external
public async connect(): Promise {
    await this.usbDevice.open()
    if (this.usbDevice.configuration === null)
      await this.usbDevice.selectConfiguration(1)

    try {
      await this.usbDevice.claimInterface(0)
    } catch (e) {
      console.error('Could not claim interface 0', this.usbDevice, {e})
      if (e.code === 18) // "The requested interface implements a protected class"
        throw new FirmwareUpdateRequired("KeepKey", "6.1.0")
      if (e.code === 19) // "Unable to claim interface"
        throw new ConflictingApp("KeepKey")
      throw e
    }

    // Start reading data from usbDevice
    this.listen()
  }
github shapeshift / hdwallet / packages / hdwallet-keepkey-webusb / src / adapter.ts View on Github external
): Promise {
    if (!(window && window.navigator.usb))
      throw new WebUSBNotAvailable()

    const devicesToInitialize = devices || await window.navigator.usb.getDevices()

    let errors = []
    for (let i = 0; i < devicesToInitialize.length; i++) {
      const usbDevice = devicesToInitialize[i]
      if (usbDevice.vendorId !== VENDOR_ID)
        continue

      if (usbDevice.productId !== WEBUSB_PRODUCT_ID) {
        // 🚨 Workaround for bug when an error is thrown inside for loop.
        // https://github.com/rpetrich/babel-plugin-transform-async-to-promises/issues/32
        errors.push(new FirmwareUpdateRequired("KeepKey", "6.1.0"))
        continue
      }

      if (this.keyring.wallets[usbDevice.serialNumber])
        continue

      let transport = new WebUSBKeepKeyTransport(usbDevice, this.keyring)

      if (autoConnect) {
        // Attempt to re-claim device
        if (usbDevice.opened) {
          await transport.usbDevice.close()
        }

        await transport.connect()
github shapeshift / hdwallet / packages / hdwallet-keepkey-nodewebusb / src / transport.ts View on Github external
public async connect (): Promise {
    if(this.isOpened)
      return

    await this.usbDevice.open()

    if (this.usbDevice.configuration === null)
      await this.usbDevice.selectConfiguration(1)

    try {
      await this.usbDevice.claimInterface(0)
    } catch (e) {
      if (e.code === 18) // "The requested interface implements a protected class"
        throw new FirmwareUpdateRequired("KeepKey", "6.1.0")
      if (e.code === 19) // "Unable to claim interface"
        throw new ConflictingApp("KeepKey")
      throw e
    }

    // Start reading data from usbDevice
    this.listen()
  }
github shapeshift / hdwallet / packages / hdwallet-keepkey-chromeusb / src / adapter.ts View on Github external
devices?: USBDevice[],
    autoConnect: boolean = true
  ): Promise {
    if (!(chrome && c.usb))
      throw new Error('ChromeUSB not supported in your browser!')

    const devicesToInitialize = devices || await getDevices()

    for (let i = 0; i < devicesToInitialize.length; i++) {
      const usbDevice = devicesToInitialize[i]

      if (usbDevice.vendorId !== VENDOR_ID)
        continue

      if (usbDevice.productId !== WEBUSB_PRODUCT_ID)
        throw new FirmwareUpdateRequired("KeepKey", "6.1.0")

      if (this.keyring.wallets[usbDevice.serialNumber]) {
        await this.keyring.remove(usbDevice.serialNumber)
      }

      let wallet = createHIDKeepKey(new ChromeUSBKeepKeyTransport(usbDevice, false, this.keyring))

      if (autoConnect)
        await wallet.initialize()

      this.keyring.add(wallet, usbDevice.serialNumber)
    }

    return Object.keys(this.keyring.wallets).length
  }
github shapeshift / hdwallet / packages / hdwallet-keepkey-nodewebusb / src / adapter.ts View on Github external
public async initialize (
    devices?: USBDevice[],
    tryDebugLink: boolean = false,
    autoConnect: boolean = true
  ): Promise {
    const devicesToInitialize = devices || await usb.getDevices()

    for (let i = 0; i < devicesToInitialize.length; i++) {
      const usbDevice = devicesToInitialize[i]

      if (usbDevice.vendorId !== VENDOR_ID)
        continue

      if (usbDevice.productId !== WEBUSB_PRODUCT_ID)
        throw new FirmwareUpdateRequired("KeepKey", "6.1.0")

      if (this.keyring.wallets[usbDevice.serialNumber])
        continue

      let transport = new NodeWebUSBKeepKeyTransport(usbDevice, this.keyring)

      if (autoConnect) {
        await transport.connect()
        if (tryDebugLink)
          await transport.tryConnectDebugLink()
      }

      let wallet = createKeepKey(transport)

      if (autoConnect)
        await wallet.initialize()