UNPKG

1.98 kBMarkdownView Raw
1Trezor-link
2====
3
4Library for low-level communication with TREZOR.
5
6Intended as a "building block" for other packages - it is used in trezor.js and chrome extension.
7
8*You probably don't want to use this package directly.* For communication with Trezor with a more high-level API, use [trezor.js](https://www.npmjs.com/package/trezor.js).
9
10How to use
11-----
12
13Use like this:
14
15```javascript
16var Link = require('trezor-link-node');
17var LowlevelTransport = Link.Lowlevel;
18var NodeHidPlugin = Link.NodeHid;
19
20var link = new LowlevelTransport(new NodeHidPlugin());
21
22// for simple config load; you can also load by file API from a disk without node-fetch
23var fetch = require('node-fetch');
24
25var config = fetch('https://wallet.mytrezor.com/data/config_signed.bin').then(function (response) {
26 if (response.ok) {
27 return response.text();
28 } else {
29 throw new Error(`Fetch error ${response.status}`);
30 }
31});
32
33return link.init().then(function () {
34 return config.then(function (configData) {
35 return link.configure(configData);
36 });
37}).then(function () {
38 return link.enumerate();
39}).then(function (devices) {
40 return link.acquire(devices[0].path);
41}).then(function (session) {
42 return link.call(session, 'GetFeatures', {}).then(function (features) {
43 console.log(features);
44 return link.release(session);
45 });
46}).catch(function (error) {
47 console.error(error);
48});
49
50```
51
52Notes
53---
54Source is annotated with Flow types, so it's more obvious what is going on from source code.
55
56Flow
57----
58If 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.
59
60
61License
62----
63LGPLv3
64
65* (C) 2015 Karel Bilek (SatoshiLabs) <kb@karelbilek.com>
66* (C) 2014 Mike Tsao <mike@sowbug.com>
67* (C) 2014 Liz Fong-Jones <lizf@google.com>
68* (C) 2015 William Wolf <throughnothing@gmail.com>
69