How to use trezor-connect - 10 common examples

To help you get started, we’ve selected a few trezor-connect 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-trezor-connect / src / adapter.ts View on Github external
TrezorConnect.off(DEVICE_EVENT, connectHandler)

    for (const connectEvent of connectEvents)
      this.handleConnectTrezor(connectEvent)

    TrezorConnect.on(DEVICE_EVENT, (event: any) => {
      if (event.type === 'device-connect') {
        this.handleConnectTrezor(event)
      } else if (event.type === 'device-changed') {
        this.handleChangeTrezor(event)
      } else if (event.type === 'device-disconnect') {
        this.handleDisconnectTrezor(event)
      }
    })

    TrezorConnect.on(TRANSPORT_EVENT, (event) => {
      // Log TrezorConnect's event raw:
      try {
        let device_id = event.payload && event.payload.features
            ? event.payload.features.device_id
            : ''
        this.keyring.emit(['Trezor', device_id, event.type], event)
      } catch(e) {
        console.error('Could not emit Trezor transport event', event, e)
      }
    })

    TrezorConnect.on(UI.ADDRESS_VALIDATION, (event) => {
      console.log('Confirm on Trezor', event)
    })

    return true
github shapeshift / hdwallet / packages / hdwallet-trezor-connect / src / adapter.ts View on Github external
}
    })

    TrezorConnect.on(TRANSPORT_EVENT, (event) => {
      // Log TrezorConnect's event raw:
      try {
        let device_id = event.payload && event.payload.features
            ? event.payload.features.device_id
            : ''
        this.keyring.emit(['Trezor', device_id, event.type], event)
      } catch(e) {
        console.error('Could not emit Trezor transport event', event, e)
      }
    })

    TrezorConnect.on(UI.ADDRESS_VALIDATION, (event) => {
      console.log('Confirm on Trezor', event)
    })

    return true
  }
github AugurProject / augur / packages / augur-ui / src / modules / auth / components / trezor-connect / trezor-connect.tsx View on Github external
indexes.forEach((index: number) => {
        const derivationPath = DerivationPath.buildString(
          DerivationPath.increment(components, index)
        );
        paths.push(derivationPath);
      });
    });

    const addresses: Array = [];

    const bundle = paths.map((path: string) => ({
      path,
      showOnTrezor: false,
    }));

    const response = await TrezorConnect.ethereumGetAddress({
      bundle,
    }).catch((err: any) => {
      console.log("Error:", err);
      return { success: false };
    });

    if (response.success) {
      // parse up the bundle results
      response.payload.every((item: { address: string, path: Array, serializedPath: string }) => {
        return addresses.push({
          address: item.address,
          derivationPath: item.path,
          serializedPath: item.serializedPath,
        });
      });
github AugurProject / augur-ui / src / modules / auth / components / trezor-connect / trezor-connect.jsx View on Github external
indexes.forEach(index => {
        const derivationPath = DerivationPath.buildString(
          DerivationPath.increment(components, index)
        );
        paths.push(derivationPath);
      });
    });

    const addresses = [];

    const bundle = paths.map(path => ({
      path,
      showOnTrezor: false
    }));

    const response = await TrezorConnect.ethereumGetAddress({
      bundle
    }).catch(err => {
      console.log("Error:", err);
      return { success: false };
    });

    if (response.success) {
      // parse up the bundle results
      response.payload.every(item =>
        addresses.push({
          address: item.address,
          derivationPath: item.path,
          serializedPath: item.serializedPath
        })
      );
      if (addresses && addresses.length > 0) {
github shapeshift / hdwallet / packages / hdwallet-trezor-connect / src / adapter.ts View on Github external
private async connectInit (args: TrezorConnectArgs): Promise {
    // Collect connect events that happen during init, but don't handle them
    // until after init has resolved. This awkward sequence is needed because we
    // need TrezorConnect to be fully operational before we're able to process
    // the events.
    let connectEvents = []
    let connectHandler = (event: any) => {
      if (event.type === 'device-connect') {
        connectEvents.push(event)
      }
    }
    TrezorConnect.on(DEVICE_EVENT, connectHandler)

    // TODO: using this in electron will needs some more scaffolding:
    // https://github.com/szymonlesisz/trezor-connect-electron-boilerplate/blob/master/src/electron.js
    await TrezorConnect.init({
      ...args,
      popup: POPUP,
      lazyLoad: false
    })

    TrezorConnect.off(DEVICE_EVENT, connectHandler)

    for (const connectEvent of connectEvents)
      this.handleConnectTrezor(connectEvent)

    TrezorConnect.on(DEVICE_EVENT, (event: any) => {
      if (event.type === 'device-connect') {
github shapeshift / hdwallet / packages / hdwallet-trezor-connect / src / adapter.ts View on Github external
TrezorConnect.on(DEVICE_EVENT, connectHandler)

    // TODO: using this in electron will needs some more scaffolding:
    // https://github.com/szymonlesisz/trezor-connect-electron-boilerplate/blob/master/src/electron.js
    await TrezorConnect.init({
      ...args,
      popup: POPUP,
      lazyLoad: false
    })

    TrezorConnect.off(DEVICE_EVENT, connectHandler)

    for (const connectEvent of connectEvents)
      this.handleConnectTrezor(connectEvent)

    TrezorConnect.on(DEVICE_EVENT, (event: any) => {
      if (event.type === 'device-connect') {
        this.handleConnectTrezor(event)
      } else if (event.type === 'device-changed') {
        this.handleChangeTrezor(event)
      } else if (event.type === 'device-disconnect') {
        this.handleDisconnectTrezor(event)
      }
    })

    TrezorConnect.on(TRANSPORT_EVENT, (event) => {
      // Log TrezorConnect's event raw:
      try {
        let device_id = event.payload && event.payload.features
            ? event.payload.features.device_id
            : ''
        this.keyring.emit(['Trezor', device_id, event.type], event)
github shapeshift / hdwallet / packages / hdwallet-trezor-connect / src / adapter.ts View on Github external
let connectHandler = (event: any) => {
      if (event.type === 'device-connect') {
        connectEvents.push(event)
      }
    }
    TrezorConnect.on(DEVICE_EVENT, connectHandler)

    // TODO: using this in electron will needs some more scaffolding:
    // https://github.com/szymonlesisz/trezor-connect-electron-boilerplate/blob/master/src/electron.js
    await TrezorConnect.init({
      ...args,
      popup: POPUP,
      lazyLoad: false
    })

    TrezorConnect.off(DEVICE_EVENT, connectHandler)

    for (const connectEvent of connectEvents)
      this.handleConnectTrezor(connectEvent)

    TrezorConnect.on(DEVICE_EVENT, (event: any) => {
      if (event.type === 'device-connect') {
        this.handleConnectTrezor(event)
      } else if (event.type === 'device-changed') {
        this.handleChangeTrezor(event)
      } else if (event.type === 'device-disconnect') {
        this.handleDisconnectTrezor(event)
      }
    })

    TrezorConnect.on(TRANSPORT_EVENT, (event) => {
      // Log TrezorConnect's event raw:
github shapeshift / hdwallet / packages / hdwallet-trezor-connect / src / adapter.ts View on Github external
private async connectInit (args: TrezorConnectArgs): Promise {
    // Collect connect events that happen during init, but don't handle them
    // until after init has resolved. This awkward sequence is needed because we
    // need TrezorConnect to be fully operational before we're able to process
    // the events.
    let connectEvents = []
    let connectHandler = (event: any) => {
      if (event.type === 'device-connect') {
        connectEvents.push(event)
      }
    }
    TrezorConnect.on(DEVICE_EVENT, connectHandler)

    // TODO: using this in electron will needs some more scaffolding:
    // https://github.com/szymonlesisz/trezor-connect-electron-boilerplate/blob/master/src/electron.js
    await TrezorConnect.init({
      ...args,
      popup: POPUP,
      lazyLoad: false
    })

    TrezorConnect.off(DEVICE_EVENT, connectHandler)

    for (const connectEvent of connectEvents)
      this.handleConnectTrezor(connectEvent)

    TrezorConnect.on(DEVICE_EVENT, (event: any) => {
      if (event.type === 'device-connect') {
        this.handleConnectTrezor(event)
      } else if (event.type === 'device-changed') {
        this.handleChangeTrezor(event)
      } else if (event.type === 'device-disconnect') {
github MyCryptoHQ / MyCrypto / common / v2 / services / WalletService / deterministic / trezor.ts View on Github external
import { Transaction as EthTx, TxData } from 'ethereumjs-tx';
import mapValues from 'lodash/mapValues';

import { translateRaw } from 'v2/translations';
import TrezorConnect from 'trezor-connect';
import { getTransactionFields } from 'v2/services/EthService';
import { stripHexPrefixAndLower, padLeftEven } from 'v2/services/EthService/utils';
import { HardwareWallet, ChainCodeResponse } from './hardware';

// read more: https://github.com/trezor/connect/blob/develop/docs/index.md#trezor-connect-manifest
TrezorConnect.manifest({
  email: 'support@mycrypto.com',
  appUrl: 'https://mycrypto.com/'
});

export class TrezorWallet extends HardwareWallet {
  public static getChainCode(dpath: string): Promise {
    return new Promise(resolve => {
      TrezorConnect.getPublicKey({
        path: dpath
      }).then((res: any) => {
        if (res.success) {
          resolve({
            publicKey: res.payload.publicKey,
            chainCode: res.payload.chainCode
          });
        } else {
github Mrtenz / FindETH / packages / web / src / wallets / Trezor.ts View on Github external
public async initialize(): Promise {
    TrezorConnect.manifest({
      email: 'maarten@zuidhoorn.com',
      appUrl: 'https://findeth.io'
    });

    this.cache = {};

    // Fetch a random address to ensure the connection works
    await this.getAddress(DEFAULT_ETH, 50);
  }