Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
}
): 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()
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()
}
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
}
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()