How to use the @shapeshiftoss/hdwallet-core.WebUSBNotAvailable 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 / adapter.ts View on Github external
public async initialize (
    devices?: USBDevice[],
    tryDebugLink: boolean = false,
    autoConnect: boolean = true
  ): 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
      }
github shapeshift / hdwallet / packages / hdwallet-ledger-webusb / src / transport.ts View on Github external
export async function openTransport(device: USBDevice): Promise {
  if (!(window && window.navigator.usb))
    throw new WebUSBNotAvailable()

  try {
    return await TransportWebUSB.open(device)
  } catch (err) {
    if (err.name === 'TransportInterfaceNotAvailable') {
      throw new ConflictingApp('Ledger')
    }

    throw new WebUSBCouldNotInitialize('Ledger', err.message)
  }
}
github shapeshift / hdwallet / packages / hdwallet-ledger-webusb / src / transport.ts View on Github external
export async function getTransport(): Promise {
  if (!(window && window.navigator.usb))
    throw new WebUSBNotAvailable()

  try {
    return await TransportWebUSB.request()
  } catch (err) {
    if (err.name === 'TransportInterfaceNotAvailable') {
      throw new ConflictingApp('Ledger')
    }

    throw new WebUSBCouldNotPair('Ledger', err.message)
  }
}
github shapeshift / hdwallet / packages / hdwallet-ledger-webusb / src / transport.ts View on Github external
export async function getFirstLedgerDevice(): Promise {
  if (!(window && window.navigator.usb))
    throw new WebUSBNotAvailable()

  const existingDevices = await TransportWebUSB.list()

  return existingDevices.length > 0 ? existingDevices[0] : null
}
github shapeshift / hdwallet / packages / hdwallet-keepkey-webusb / src / adapter.ts View on Github external
public async pairDevice (serialNumber: string = undefined, tryDebugLink: boolean = false): Promise {
    if (!(window && window.navigator.usb)) {
      throw new WebUSBNotAvailable()
    }

    let device
    try {
      device = await window.navigator.usb.requestDevice({ filters: [
        { vendorId: VENDOR_ID, productId: WEBUSB_PRODUCT_ID, serialNumber },
        { vendorId: VENDOR_ID, productId: HID_PRODUCT_ID, serialNumber }
      ] })
    } catch (e) {
      throw new WebUSBCouldNotPair('KeepKey', e.message)
    }

    await this.initialize([device], tryDebugLink, /*autoConnect=*/true)

    return this.keyring.get(device.serialNumber)
  }