Git Product home page Git Product logo

trezor-link's Introduction

trezor-link

Build Status gitter

Library for low-level communication with TREZOR.

Intended as a "building block" for other packages - it is used in trezor.js and chrome extension.

You probably don't want to use this package directly. For communication with Trezor with a more high-level API, use trezor.js.

Packages

We have three different npm packages for different usecases, unfortunately.

  • require('trezor-link') for browser
  • require('trezor-link-node') for node.js (and electron apps)
  • require('trezor-link-browser-extension') for browser extensions

How to use

Use like this (in node):

var Link = require('trezor-link-node');
var LowlevelTransport = Link.Lowlevel;
var NodeHidPlugin = Link.NodeHid;

var link = new LowlevelTransport(new NodeHidPlugin());

// for simple config load; you can also load by file API from a disk without node-fetch
var fetch = require('node-fetch');

var config = fetch('https://wallet.mytrezor.com/data/config_signed.bin').then(function (response) {
  if (response.ok) {
    return response.text();
  } else {
    throw new Error(`Fetch error ${response.status}`);
  }
});

return link.init().then(function () { 
  return config.then(function (configData) {
    return link.configure(configData);
  });
}).then(function () {
  return link.enumerate();
}).then(function (devices) {
  return link.acquire(devices[0].path);
}).then(function (session) {
  return link.call(session, 'GetFeatures', {}).then(function (features) {
    console.log(features);
    return link.release(session);
  });
}).catch(function (error) {
  console.error(error);
});

Notes

Source is annotated with Flow types, so it's more obvious what is going on from source code.

Flow

If you want to use flow for typechecking, just include the file as normally, it will automatically use the included flow file. However, you need to add flowtype/*.js to your [libs] (or copy it yourself from flow-typed repository), and probably libs from flowconfig.

License

LGPLv3

trezor-link's People

Contributors

karelbilek avatar prusnak avatar

Watchers

James Cloos avatar Dušan Klinec avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.