UNPKG

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