Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async handleConnectWebUSBLedger(e: USBConnectionEvent): Promise {
if (e.device.vendorId !== VENDOR_ID) return
this.connectTimestamp = e.timeStamp
try {
await this.initialize(e.device)
this.keyring.emit([e.device.manufacturerName, e.device.productName, Events.CONNECT], e.device.serialNumber)
} catch(error) {
this.keyring.emit([e.device.manufacturerName, e.device.productName, Events.FAILURE], [e.device.serialNumber, {message: { code: error.type, ...error}}])
} finally {
await timeout(APP_NAVIGATION_DELAY) // Allow connection to happen as fast as possible, but still give time to detect for app navigation before resetting timestamp
this.connectTimestamp = 0
}
}
private async handleConnectWebUSBKeepKey (e: USBConnectionEvent): Promise {
try {
await this.initialize([e.device])
this.keyring.emit([e.device.productName, e.device.serialNumber, Events.CONNECT], e.device.serialNumber)
} catch(error) {
this.keyring.emit([e.device.productName, e.device.serialNumber, Events.FAILURE], [e.device.serialNumber, {message: { code: error.type, ...error}}])
}
}
export async function btcGetAddress (wallet: BTCWallet, transport: KeepKeyTransport, msg: BTCGetAddress): Promise {
await ensureCoinSupport(wallet, msg.coin)
const addr = new GetAddress()
addr.setAddressNList(msg.addressNList)
addr.setCoinName(msg.coin)
addr.setShowDisplay(msg.showDisplay || false)
addr.setScriptType(translateInputScriptType(msg.scriptType || BTCInputScriptType.SpendAddress))
const response = await transport.call(MessageType.MESSAGETYPE_GETADDRESS, addr, LONG_TIMEOUT) as Event
if(response.message_type === Events.FAILURE) throw response
if(response.message_type === Events.CANCEL) throw response
const btcAddress = response.proto as Address
return btcAddress.getAddress()
}
export async function ethGetAddress (transport: KeepKeyTransport, msg: ETHGetAddress): Promise {
const getAddr = new EthereumGetAddress()
getAddr.setAddressNList(msg.addressNList)
getAddr.setShowDisplay(msg.showDisplay !== false)
const response = await transport.call(MessageType.MESSAGETYPE_ETHEREUMGETADDRESS, getAddr, LONG_TIMEOUT)
const ethAddress = response.proto as EthereumAddress
if(response.message_type === Events.FAILURE) throw response
let address = null
if (ethAddress.hasAddressStr())
address = ethAddress.getAddressStr()
else if (ethAddress.hasAddress())
address = '0x' + toHexString(ethAddress.getAddress_asU8())
else
throw new Error('Unable to obtain ETH address from device.')
return address
}
public async getFeatures(cached: boolean = false): Promise {
if (cached && this.featuresCache)
return this.featuresCache
const features = new Messages.GetFeatures();
const event = await this.transport.call(
Messages.MessageType.MESSAGETYPE_GETFEATURES,
features
) as Event
if(event.message_type === Events.FAILURE) throw event
this.cacheFeatures(event.message)
return event.message as Messages.Features.AsObject
}