UNPKG

2.46 kBMarkdownView Raw
1# trezor-link
2
3[![Build Status](https://travis-ci.org/trezor/trezor-link.svg?branch=master)](https://travis-ci.org/trezor/trezor-link) [![gitter](https://badges.gitter.im/trezor/community.svg)](https://gitter.im/trezor/community)
4
5Library for low-level communication with TREZOR.
6
7Intended as a "building block" for other packages - it is used in trezor.js and chrome extension.
8
9*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).
10
11## Packages
12
13We have three different npm packages for different usecases, unfortunately.
14
15* `require('trezor-link')` for browser
16* `require('trezor-link-node')` for node.js (and electron apps)
17* `require('trezor-link-browser-extension')` for browser extensions
18
19## How to use
20
21Use like this (in node):
22
23```javascript
24var Link = require('trezor-link-node');
25var LowlevelTransport = Link.Lowlevel;
26var NodeHidPlugin = Link.NodeHid;
27
28var link = new LowlevelTransport(new NodeHidPlugin());
29
30// for simple config load; you can also load by file API from a disk without node-fetch
31var fetch = require('node-fetch');
32
33var 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
41return 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
62Source is annotated with Flow types, so it's more obvious what is going on from source code.
63
64## Flow
65
66If 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
70LGPLv3
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