How to use @ledgerhq/hw-transport-webusb - 10 common examples

To help you get started, we’ve selected a few @ledgerhq/hw-transport-webusb 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 burst-apps-team / phoenix / web / angular-wallet / src / app / ledger / ledger.service.ts View on Github external
public async getPublicKey(accountIndex: number): Promise {
    if (this.appService.isDesktop()) {
      const publicKeyHex: string = this.appService.sendIpcMessageSync('ledger-get-public-key', accountIndex);
      if (publicKeyHex.startsWith('Error: ')) {
        throw new Error(publicKeyHex);
      }
      return publicKeyHex;
    } else {
      const transport = await TransportWebUSB.create();
      // todo: move this to a shared fn
      const publicKey: Buffer = await transport.exchange(Buffer.from('800400' + this.byteToHex(accountIndex) + '00', 'hex'));
      return publicKey.toString('hex').substr(0, 64);
    }
  }
github forbole / big_dipper / imports / ui / ledger / ledger.js View on Github external
async connect(timeout = INTERACTION_TIMEOUT) {
        // assume well connection if connected once
        if (this.cosmosApp) return

        const transport = await TransportWebUSB.create(timeout)
        const cosmosLedgerApp = new CosmosApp(transport)

        this.cosmosApp = cosmosLedgerApp

        await this.isSendingData()
        await this.isReady()
    }
    async getCosmosAppVersion() {
github MyEtherWallet / MyEtherWallet / src / wallets / hardware / ledger / index.js View on Github external
const isWebUsbSupported = async () => {
  const isSupported = await webUsbTransport.isSupported();
  return (
    isSupported && platform.os.family !== 'Windows' && platform.name !== 'Opera' // take it out later once the windows issue is fixed
  );
};
github Mrtenz / FindETH / src / components / SelectWallet / WalletItem / LedgerWalletItem / LedgerWalletItem.tsx View on Github external
useEffect(() => {
    // TODO: Temporary workaround for Ledger USB issues on Windows
    if (!navigator.platform.includes('Win')) {
      TransportWebUSB.isSupported()
        .then(setWebUSBSupported)
        .catch(() => setWebUSBSupported(false));
    }
  }, []);
github LedgerHQ / ledger-live-common / tools / src / live-common-setup.js View on Github external
open: (id: string): ?Promise<*> => {
    if (id.startsWith("webble")) {
      const existingDevice = webbleDevices[id];
      return existingDevice
        ? TransportWebBLE.open(existingDevice)
        : TransportWebBLE.create();
    }
    return null;
  },

  disconnect: id =>
    id.startsWith("webble")
      ? Promise.resolve() // nothing to do
      : null,

  discovery: Observable.create(TransportWebUSB.listen).pipe(
    map(bleDevice => {
      const id = "webble|" + bleDevice.id;
      webbleDevices[id] = bleDevice;
      return {
        type: "add",
        id,
        name: bleDevice.name
      };
    })
  )
});

// provide a basic mecanism to stop polling when you leave the tab
// & immediately poll when you come back.
const addExtraPollingHooks = (schedulePoll, cancelPoll) => {
  function onWindowBlur() {
github LedgerHQ / ledger-live-common / tools / src / live-common-setup.js View on Github external
open: (id: string): ?Promise<*> => {
    if (id.startsWith("webusb")) {
      const existingDevice = webusbDevices[id];
      return existingDevice
        ? TransportWebUSB.open(existingDevice)
        : TransportWebUSB.create();
    }
    return null;
  },

  disconnect: id =>
    id.startsWith("webusb")
      ? Promise.resolve() // nothing to do
      : null,

  discovery: Observable.create(TransportWebUSB.listen).pipe(
    map(usbDevice => {
      const id = "webusb|" + usbDevice.vendorId + "_" + usbDevice.productId;
      webusbDevices[id] = usbDevice;
      return {
        type: "add",
        id,
        name: usbDevice.productName
      };
    })
  )
});

const webbleDevices = {};

registerTransportModule({
  id: "webble",
github theQRL / qrl-wallet / imports / startup / client / functions.js View on Github external
export async function createTransport() {
  var transport = null;
  transport = await TransportWebUSB.create();
  console.log('USING WEBUSB');
  var qrl = await new Qrl(transport);
  return qrl
}
github vacuumlabs / adalite / app / frontend / wallet / cardano-ledger-crypto-provider.js View on Github external
const CardanoLedgerCryptoProvider = async (ADALITE_CONFIG, walletState) => {
  let transport
  try {
    transport = await LedgerTransportU2F.create()
  } catch (u2fError) {
    try {
      transport = await LedgerTransportWebusb.create()
    } catch (webUsbError) {
      debugLog(webUsbError)
      throw u2fError
    }
  }
  transport.setExchangeTimeout(ADALITE_CONFIG.ADALITE_LOGOUT_AFTER * 1000)
  const ledger = new Ledger(transport)
  const state = Object.assign(walletState, {
    derivationScheme: derivationSchemes.v2,
    rootHdPassphrase: null,
    derivedAddresses: {},
  })

  const isHwWallet = () => true
  const getHwWalletName = () => 'Ledger'
github LedgerHQ / ledger-live-common / tools / src / demos / derivations / index.js View on Github external
execInQueue(async () => {
      const { derivationMode, currency, index: account } = this.props;
      try {
        const p = transportGlobalP || TransportWebUSB.create();
        transportGlobalP = p;
        const transport = await p;
        const { address, path } = await getAddress(transport, {
          currency,
          path: runDerivationScheme(
            getDerivationScheme({ currency, derivationMode }),
            currency,
            { account }
          ),
          derivationMode,
          verify
        });
        this.setState({ address, path });
      } catch (error) {
        this.setState({ error });
      }
github burst-apps-team / phoenix / web / angular-wallet / src / app / ledger / ledger.service.ts View on Github external
public async sign(accountIndex: number, message: string): Promise {
    if (this.appService.isDesktop()) {
      const signature: string = this.appService.sendIpcMessageSync('ledger-sign', {accountIndex, message});
      if (signature.startsWith('Error: ')) {
        throw new Error(signature);
      }
      return signature;
    } else {
      const transport = await TransportWebUSB.create();
      let offset = 0;
      while (offset !== message.length) {
        let chunk: string;
        if (message.length - offset > 510) {
          chunk = message.substr(offset, 510);
        } else {
          chunk = message.substr(offset);
        }
        let apdu = '8002';
        const final = (offset + chunk.length) === message.length;
        apdu += final ? '80' : '00';
        apdu += this.byteToHex(accountIndex);
        apdu += this.byteToHex(chunk.length / 2);
        apdu += chunk;
        offset += chunk.length;
        const result: Buffer = await transport.exchange(Buffer.from(apdu, 'hex'));