1 | Trezor-link
|
2 | ====
|
3 |
|
4 | Library for low-level communication with TREZOR.
|
5 |
|
6 | Intended 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 |
|
10 | How to use
|
11 | -----
|
12 |
|
13 | Use like this:
|
14 |
|
15 | ```javascript
|
16 | var Link = require('trezor-link-node');
|
17 | var LowlevelTransport = Link.Lowlevel;
|
18 | var NodeHidPlugin = Link.NodeHid;
|
19 |
|
20 | var link = new LowlevelTransport(new NodeHidPlugin());
|
21 |
|
22 | // for simple config load; you can also load by file API from a disk without node-fetch
|
23 | var fetch = require('node-fetch');
|
24 |
|
25 | var 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 |
|
33 | return 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 |
|
52 | Notes
|
53 | ---
|
54 | Source is annotated with Flow types, so it's more obvious what is going on from source code.
|
55 |
|
56 | Flow
|
57 | ----
|
58 | 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.
|
59 |
|
60 |
|
61 | License
|
62 | ----
|
63 | LGPLv3
|
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 |
|