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