How to use the @shapeshiftoss/hdwallet-core.Events.CONNECT 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-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
    });
  }
github shapeshift / hdwallet / packages / hdwallet-ledger-u2f / src / adapter.ts View on Github external
if (device.vendorId !== VENDOR_ID) { continue }

      // remove last connected ledger from keyring since we don't have unique identifier
      if (!device.deviceID) {
        device.deviceID = 'u2f-ledger'
        await this.keyring.remove(device.deviceID)
      }

      if (this.keyring.wallets[device.deviceID]) { continue }

      const ledgerTransport = await TransportU2F.open()

      const wallet = createLedger(new LedgerU2FTransport(device, ledgerTransport, this.keyring))

      this.keyring.add(wallet, device.deviceID)
      this.keyring.emit(["Ledger", device.deviceID, Events.CONNECT], device.deviceID)
    }

    return Object.keys(this.keyring.wallets).length
  }
github shapeshift / hdwallet / packages / hdwallet-ledger-webusb / src / adapter.ts View on Github external
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
    }
  }
github shapeshift / hdwallet / packages / hdwallet-keepkey-chromeusb / src / adapter.ts View on Github external
    .then(() => this.keyring.emit([device.productName, device.serialNumber, Events.CONNECT], device.serialNumber))
    .catch(console.error)
github shapeshift / hdwallet / packages / hdwallet-trezor-connect / src / adapter.ts View on Github external
private async handleConnectTrezor (event: any): Promise {
    const { payload: { path, features: { device_id } } } = event
    try {
      await this.addDevice(device_id, path)
      this.connectCacheFeatures(event)
      this.keyring.emit(['Trezor', device_id, Events.CONNECT], device_id)
    } catch (e) {
      console.error(e)
    }
  }
github shapeshift / hdwallet / packages / hdwallet-metamask / src / adapter.ts View on Github external
public async pairDevice (): Promise {
    const metamask = window && window['ethereum']

    if (!metamask) return null

    metamask.on('accountsChanged', (accts) => {
      console.log('accounts changed to: ', accts)
    })

    const wallet = new MetaMaskHDWallet(metamask)
    await wallet.initialize()
    const deviceId = await wallet.getDeviceID()
    this.keyring.add(wallet, deviceId)
    this.keyring.emit(["MetaMask", deviceId, Events.CONNECT], deviceId)
    return wallet
  }
github shapeshift / hdwallet / packages / hdwallet-portis / src / adapter.ts View on Github external
private async pairPortisDevice(): Promise {
    this.portis = new Portis(this.portisAppId, 'mainnet')
    const wallet = new PortisHDWallet(this.portis)
    await wallet.initialize()
    const deviceId = await wallet.getDeviceID()
    this.keyring.add(wallet, deviceId)
    this.currentDeviceId = deviceId
    this.keyring.emit(["Portis", deviceId, Events.CONNECT], deviceId)

    const watchForInactivity =  () => {
      let time
      const resetTimer = () => {
          clearTimeout(time)
          time = setTimeout(() => {
            window.onload = null
            document.onmousemove = null
            document.onkeypress = null  
            clearTimeout(time)
            this.portis.logout()
          }, INACTIVITY_LOGOUT_TIME)
      }
      window.onload = resetTimer
      document.onmousemove = resetTimer
      document.onkeypress = resetTimer
github shapeshift / hdwallet / examples / sandbox / index.ts View on Github external
if (isKeepKey(wallet)) {
        console.log("try connect debuglink")
        await wallet.transport.tryConnectDebugLink()
      }
      await wallet.initialize()
    }
    window['wallet'] = wallet
  })
  wallet = keyring.get()
  window['wallet'] = wallet
  if (wallet) {
    let deviceID = wallet.getDeviceID()
    $keyring.val(deviceID).change()
  }

  keyring.on(['*', '*', Events.CONNECT], async (deviceId) => {
    await deviceConnected(deviceId)
  })

  keyring.on(['*', '*', Events.DISCONNECT], async (deviceId) => {
    $keyring.find(`option[value="${deviceId}"]`).remove()
  })
})()
github shapeshift / hdwallet / packages / hdwallet-keepkey-nodehid / src / adapter.ts View on Github external
.then(() => () =>
        this.keyring.emit([device.product, deviceID, Events.CONNECT], deviceID)
      )
github shapeshift / hdwallet / packages / hdwallet-keepkey-webusb / src / adapter.ts View on Github external
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}}])
    }
  }