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 | Packages
|
11 | ----
|
12 | We have three different npm packages for different usecases, unfortunately.
|
13 |
|
14 | * `require('trezor-link')` for browser
|
15 | * `require('trezor-link-node')` for node.js (and electron apps)
|
16 | * `require('trezor-link-browser-extension')` for browser extensions
|
17 |
|
18 | How to use
|
19 | -----
|
20 |
|
21 | Use like this (in node):
|
22 |
|
23 | ```javascript
|
24 | var link = require('trezor-link-node');
|
25 | var LowlevelTransport = link.Lowlevel;
|
26 | var NodeHidPlugin = link.NodeHid;
|
27 |
|
28 | var link = new LowlevelTransport(new NodeHidPlugin());
|
29 |
|
30 | // for simple config load; you can also load by file API from a disk without node-fetch
|
31 | var fetch = require('node-fetch');
|
32 |
|
33 | var config = fetch('https://wallet.mytrezor.com/data/config_signed.bin').then(function (response) {
|
34 | if (response.ok) {
|
35 | return response.text();
|
36 | } else {
|
37 | throw new Error(`Fetch error ${response.status}`);
|
38 | }
|
39 | });
|
40 |
|
41 | return link.init().then(function () {
|
42 | return config.then(function (configData) {
|
43 | return link.configure(configData);
|
44 | });
|
45 | }).then(function () {
|
46 | return link.enumerate();
|
47 | }).then(function (devices) {
|
48 | return link.acquire(devices[0].path);
|
49 | }).then(function (session) {
|
50 | return link.call(session, 'GetFeatures', {}).then(function (features) {
|
51 | console.log(features);
|
52 | return link.release(session);
|
53 | });
|
54 | }).catch(function (error) {
|
55 | console.error(error);
|
56 | });
|
57 |
|
58 | ```
|
59 |
|
60 | Notes
|
61 | ---
|
62 | Source is annotated with Flow types, so it's more obvious what is going on from source code.
|
63 |
|
64 | Flow
|
65 | ----
|
66 | 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.
|
67 |
|
68 | License
|
69 | ----
|
70 | LGPLv3
|
71 |
|
72 | * (C) 2015 Karel Bilek (SatoshiLabs) <kb@karelbilek.com>
|
73 | * (C) 2014 Mike Tsao <mike@sowbug.com>
|
74 | * (C) 2014 Liz Fong-Jones <lizf@google.com>
|
75 | * (C) 2015 William Wolf <throughnothing@gmail.com>
|
76 |
|