@shapeshiftoss/hdwallet-keepkey-nodehid 0.10.1 → 1.19.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{LICENSE → LICENSE.md} +0 -0
- package/dist/adapter.d.ts +27 -10
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +62 -0
- package/dist/adapter.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -520
- package/dist/index.js.map +1 -1
- package/dist/transport.d.ts +19 -24
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +85 -0
- package/dist/transport.js.map +1 -0
- package/dist/utils.d.ts +3 -2
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +6 -0
- package/dist/utils.js.map +1 -0
- package/package.json +9 -14
- package/dist/index.m.js +0 -514
- package/dist/index.m.js.map +0 -1
- package/dist/index.umd.js +0 -521
- package/dist/index.umd.js.map +0 -1
package/{LICENSE → LICENSE.md}
RENAMED
|
File without changes
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
export declare
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
1
|
+
import * as keepkey from "@shapeshiftoss/hdwallet-keepkey";
|
|
2
|
+
import { Device, TransportDelegate } from "./transport";
|
|
3
|
+
export declare const HIDKeepKeyAdapterDelegate: {
|
|
4
|
+
inspectDevice(device: Device): Promise<{
|
|
5
|
+
readonly productName: string | undefined;
|
|
6
|
+
readonly serialNumber: string;
|
|
7
|
+
}>;
|
|
8
|
+
getDevices(): Promise<Device[]>;
|
|
9
|
+
getTransportDelegate(device: Device): Promise<TransportDelegate>;
|
|
10
|
+
};
|
|
11
|
+
export declare const Adapter: keepkey.AdapterConstructor<{
|
|
12
|
+
inspectDevice(device: Device): Promise<{
|
|
13
|
+
readonly productName: string | undefined;
|
|
14
|
+
readonly serialNumber: string;
|
|
15
|
+
}>;
|
|
16
|
+
getDevices(): Promise<Device[]>;
|
|
17
|
+
getTransportDelegate(device: Device): Promise<TransportDelegate>;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const HIDKeepKeyAdapter: keepkey.AdapterConstructor<{
|
|
20
|
+
inspectDevice(device: Device): Promise<{
|
|
21
|
+
readonly productName: string | undefined;
|
|
22
|
+
readonly serialNumber: string;
|
|
23
|
+
}>;
|
|
24
|
+
getDevices(): Promise<Device[]>;
|
|
25
|
+
getTransportDelegate(device: Device): Promise<TransportDelegate>;
|
|
26
|
+
}>;
|
|
27
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,iCAAiC,CAAC;AAG3D,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGxD,eAAO,MAAM,yBAAyB;0BACR,MAAM;;;;kBAUd,QAAQ,MAAM,EAAE,CAAC;iCAKF,MAAM;CAG1C,CAAC;AAEF,eAAO,MAAM,OAAO;0BApBU,MAAM;;;;kBAUd,QAAQ,MAAM,EAAE,CAAC;iCAKF,MAAM;EAKmC,CAAC;AAC/E,eAAO,MAAM,iBAAiB;0BArBA,MAAM;;;;kBAUd,QAAQ,MAAM,EAAE,CAAC;iCAKF,MAAM;EAMH,CAAC"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.HIDKeepKeyAdapter = exports.Adapter = exports.HIDKeepKeyAdapterDelegate = void 0;
|
|
32
|
+
const keepkey = __importStar(require("@shapeshiftoss/hdwallet-keepkey"));
|
|
33
|
+
const hid = __importStar(require("node-hid"));
|
|
34
|
+
const transport_1 = require("./transport");
|
|
35
|
+
const utils_1 = require("./utils");
|
|
36
|
+
exports.HIDKeepKeyAdapterDelegate = {
|
|
37
|
+
inspectDevice(device) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
return {
|
|
40
|
+
get productName() {
|
|
41
|
+
return device.product;
|
|
42
|
+
},
|
|
43
|
+
get serialNumber() {
|
|
44
|
+
return device.serialNumber;
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
getDevices() {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
return hid.devices().filter((d) => d.path !== undefined && d.serialNumber !== undefined).filter((d) => d.vendorId === utils_1.VENDOR_ID && d.productId === utils_1.PRODUCT_ID);
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
getTransportDelegate(device) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
return new transport_1.TransportDelegate(device);
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
exports.Adapter = keepkey.Adapter.fromDelegate(exports.HIDKeepKeyAdapterDelegate);
|
|
61
|
+
exports.HIDKeepKeyAdapter = exports.Adapter;
|
|
62
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAA2D;AAC3D,8CAAgC;AAEhC,2CAAwD;AACxD,mCAAgD;AAEnC,QAAA,yBAAyB,GAAG;IACjC,aAAa,CAAC,MAAc;;YAChC,OAAO;gBACL,IAAI,WAAW;oBACb,OAAO,MAAM,CAAC,OAAO,CAAC;gBACxB,CAAC;gBACD,IAAI,YAAY;oBACd,OAAO,MAAM,CAAC,YAAY,CAAC;gBAC7B,CAAC;aACF,CAAC;QACJ,CAAC;KAAA;IACK,UAAU;;YACd,OAAQ,GAAG,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,CAAC,YAAY,KAAK,SAAS,CAAc,CAAC,MAAM,CAC3G,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,iBAAS,IAAI,CAAC,CAAC,SAAS,KAAK,kBAAU,CAC9D,CAAC;QACJ,CAAC;KAAA;IACK,oBAAoB,CAAC,MAAc;;YACvC,OAAO,IAAI,6BAAiB,CAAC,MAAM,CAAC,CAAC;QACvC,CAAC;KAAA;CACF,CAAC;AAEW,QAAA,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,iCAAyB,CAAC,CAAC;AAClE,QAAA,iBAAiB,GAAG,eAAO,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from "./adapter";
|
|
2
|
+
export * from "./transport";
|
|
3
|
+
export * from "./utils";
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,521 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var _Pact =
|
|
12
|
-
/*#__PURE__*/
|
|
13
|
-
function () {
|
|
14
|
-
function _Pact() {}
|
|
15
|
-
|
|
16
|
-
_Pact.prototype.then = function (onFulfilled, onRejected) {
|
|
17
|
-
var result = new _Pact();
|
|
18
|
-
var state = this.s;
|
|
19
|
-
|
|
20
|
-
if (state) {
|
|
21
|
-
var callback = state & 1 ? onFulfilled : onRejected;
|
|
22
|
-
|
|
23
|
-
if (callback) {
|
|
24
|
-
try {
|
|
25
|
-
_settle(result, 1, callback(this.v));
|
|
26
|
-
} catch (e) {
|
|
27
|
-
_settle(result, 2, e);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return result;
|
|
31
|
-
} else {
|
|
32
|
-
return this;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
this.o = function (_this) {
|
|
37
|
-
try {
|
|
38
|
-
var value = _this.v;
|
|
39
|
-
|
|
40
|
-
if (_this.s & 1) {
|
|
41
|
-
_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
|
|
42
|
-
} else if (onRejected) {
|
|
43
|
-
_settle(result, 1, onRejected(value));
|
|
44
|
-
} else {
|
|
45
|
-
_settle(result, 2, value);
|
|
46
|
-
}
|
|
47
|
-
} catch (e) {
|
|
48
|
-
_settle(result, 2, e);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
return result;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
return _Pact;
|
|
56
|
-
}(); // Settles a pact synchronously
|
|
57
|
-
|
|
58
|
-
function _settle(pact, state, value) {
|
|
59
|
-
if (!pact.s) {
|
|
60
|
-
if (value instanceof _Pact) {
|
|
61
|
-
if (value.s) {
|
|
62
|
-
if (state & 1) {
|
|
63
|
-
state = value.s;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
value = value.v;
|
|
67
|
-
} else {
|
|
68
|
-
value.o = _settle.bind(null, pact, state);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (value && value.then) {
|
|
74
|
-
value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2));
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
pact.s = state;
|
|
79
|
-
pact.v = value;
|
|
80
|
-
var observer = pact.o;
|
|
81
|
-
|
|
82
|
-
if (observer) {
|
|
83
|
-
observer(pact);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
function _isSettledPact(thenable) {
|
|
88
|
-
return thenable instanceof _Pact && thenable.s & 1;
|
|
89
|
-
} // Converts argument to a function that always returns a Promise
|
|
90
|
-
|
|
91
|
-
function _forTo(array, body, check) {
|
|
92
|
-
var i = -1,
|
|
93
|
-
pact,
|
|
94
|
-
reject;
|
|
95
|
-
|
|
96
|
-
function _cycle(result) {
|
|
97
|
-
try {
|
|
98
|
-
while (++i < array.length && (!check || !check())) {
|
|
99
|
-
result = body(i);
|
|
100
|
-
|
|
101
|
-
if (result && result.then) {
|
|
102
|
-
if (_isSettledPact(result)) {
|
|
103
|
-
result = result.v;
|
|
104
|
-
} else {
|
|
105
|
-
result.then(_cycle, reject || (reject = _settle.bind(null, pact = new _Pact(), 2)));
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (pact) {
|
|
112
|
-
_settle(pact, 1, result);
|
|
113
|
-
} else {
|
|
114
|
-
pact = result;
|
|
115
|
-
}
|
|
116
|
-
} catch (e) {
|
|
117
|
-
_settle(pact || (pact = new _Pact()), 2, e);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
_cycle();
|
|
122
|
-
|
|
123
|
-
return pact;
|
|
124
|
-
} // Asynchronously iterate through an object's properties (including properties inherited from the prototype)
|
|
125
|
-
var _iteratorSymbol =
|
|
126
|
-
/*#__PURE__*/
|
|
127
|
-
typeof Symbol !== "undefined" ? Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator")) : "@@iterator"; // Asynchronously iterate through an object's values
|
|
128
|
-
var _asyncIteratorSymbol =
|
|
129
|
-
/*#__PURE__*/
|
|
130
|
-
typeof Symbol !== "undefined" ? Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator")) : "@@asyncIterator"; // Asynchronously iterate on a value using it's async iterator if present, or its synchronous iterator if missing
|
|
131
|
-
|
|
132
|
-
function _for(test, update, body) {
|
|
133
|
-
var stage;
|
|
134
|
-
|
|
135
|
-
for (;;) {
|
|
136
|
-
var shouldContinue = test();
|
|
137
|
-
|
|
138
|
-
if (_isSettledPact(shouldContinue)) {
|
|
139
|
-
shouldContinue = shouldContinue.v;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (!shouldContinue) {
|
|
143
|
-
return result;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (shouldContinue.then) {
|
|
147
|
-
stage = 0;
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
var result = body();
|
|
152
|
-
|
|
153
|
-
if (result && result.then) {
|
|
154
|
-
if (_isSettledPact(result)) {
|
|
155
|
-
result = result.s;
|
|
156
|
-
} else {
|
|
157
|
-
stage = 1;
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (update) {
|
|
163
|
-
var updateValue = update();
|
|
164
|
-
|
|
165
|
-
if (updateValue && updateValue.then && !_isSettledPact(updateValue)) {
|
|
166
|
-
stage = 2;
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
var pact = new _Pact();
|
|
173
|
-
|
|
174
|
-
var reject = _settle.bind(null, pact, 2);
|
|
175
|
-
|
|
176
|
-
(stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
|
|
177
|
-
return pact;
|
|
178
|
-
|
|
179
|
-
function _resumeAfterBody(value) {
|
|
180
|
-
result = value;
|
|
181
|
-
|
|
182
|
-
do {
|
|
183
|
-
if (update) {
|
|
184
|
-
updateValue = update();
|
|
185
|
-
|
|
186
|
-
if (updateValue && updateValue.then && !_isSettledPact(updateValue)) {
|
|
187
|
-
updateValue.then(_resumeAfterUpdate).then(void 0, reject);
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
shouldContinue = test();
|
|
193
|
-
|
|
194
|
-
if (!shouldContinue || _isSettledPact(shouldContinue) && !shouldContinue.v) {
|
|
195
|
-
_settle(pact, 1, result);
|
|
196
|
-
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (shouldContinue.then) {
|
|
201
|
-
shouldContinue.then(_resumeAfterTest).then(void 0, reject);
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
result = body();
|
|
206
|
-
|
|
207
|
-
if (_isSettledPact(result)) {
|
|
208
|
-
result = result.v;
|
|
209
|
-
}
|
|
210
|
-
} while (!result || !result.then);
|
|
211
|
-
|
|
212
|
-
result.then(_resumeAfterBody).then(void 0, reject);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function _resumeAfterTest(shouldContinue) {
|
|
216
|
-
if (shouldContinue) {
|
|
217
|
-
result = body();
|
|
218
|
-
|
|
219
|
-
if (result && result.then) {
|
|
220
|
-
result.then(_resumeAfterBody).then(void 0, reject);
|
|
221
|
-
} else {
|
|
222
|
-
_resumeAfterBody(result);
|
|
223
|
-
}
|
|
224
|
-
} else {
|
|
225
|
-
_settle(pact, 1, result);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function _resumeAfterUpdate() {
|
|
230
|
-
if (shouldContinue = test()) {
|
|
231
|
-
if (shouldContinue.then) {
|
|
232
|
-
shouldContinue.then(_resumeAfterTest).then(void 0, reject);
|
|
233
|
-
} else {
|
|
234
|
-
_resumeAfterTest(shouldContinue);
|
|
235
|
-
}
|
|
236
|
-
} else {
|
|
237
|
-
_settle(pact, 1, result);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
} // Asynchronously implement a do ... while loop
|
|
241
|
-
|
|
242
|
-
function _catch(body, recover) {
|
|
243
|
-
try {
|
|
244
|
-
var result = body();
|
|
245
|
-
} catch (e) {
|
|
246
|
-
return recover(e);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
if (result && result.then) {
|
|
250
|
-
return result.then(void 0, recover);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
return result;
|
|
254
|
-
} // Asynchronously await a promise and pass the result to a finally continuation
|
|
255
|
-
|
|
256
|
-
var VENDOR_ID = 0x2b24;
|
|
257
|
-
var PRODUCT_ID = 0x0001;
|
|
258
|
-
|
|
259
|
-
var ByteBuffer_default = ByteBuffer__default;
|
|
260
|
-
var concat = ByteBuffer_default.concat;
|
|
261
|
-
var wrap = ByteBuffer_default.wrap;
|
|
262
|
-
function requestPair() {
|
|
263
|
-
return new HID.HID(VENDOR_ID, PRODUCT_ID);
|
|
264
|
-
}
|
|
265
|
-
var HIDKeepKeyTransport = /*@__PURE__*/(function (KeepKeyTransport) {
|
|
266
|
-
function HIDKeepKeyTransport(hidDevice, keyring, hidRef) {
|
|
267
|
-
KeepKeyTransport.call(this, keyring);
|
|
268
|
-
this.bufferQueue = [];
|
|
269
|
-
this.hidDevice = hidDevice;
|
|
270
|
-
this.hidRef = hidRef || new HID.HID(hidDevice.path);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
if ( KeepKeyTransport ) HIDKeepKeyTransport.__proto__ = KeepKeyTransport;
|
|
274
|
-
HIDKeepKeyTransport.prototype = Object.create( KeepKeyTransport && KeepKeyTransport.prototype );
|
|
275
|
-
HIDKeepKeyTransport.prototype.constructor = HIDKeepKeyTransport;
|
|
276
|
-
|
|
277
|
-
var prototypeAccessors = { isOpened: { configurable: true } };
|
|
278
|
-
|
|
279
|
-
HIDKeepKeyTransport.prototype.getDeviceID = function getDeviceID () {
|
|
280
|
-
return this.hidDevice.serialNumber;
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
HIDKeepKeyTransport.prototype.getVendor = function getVendor () {
|
|
284
|
-
return 'keepkey.com';
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
HIDKeepKeyTransport.prototype.getFirmwareHash = function getFirmwareHash (firmware) {
|
|
288
|
-
try {
|
|
289
|
-
var hash = crypto.createHash('sha256');
|
|
290
|
-
hash.update(firmware);
|
|
291
|
-
return hash.digest();
|
|
292
|
-
} catch (e) {
|
|
293
|
-
return Promise.reject(e);
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
prototypeAccessors.isOpened.get = function () {
|
|
298
|
-
return this.hidDevice.interface > -1;
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
HIDKeepKeyTransport.prototype.connect = function connect () {
|
|
302
|
-
try {
|
|
303
|
-
var _this = this;
|
|
304
|
-
|
|
305
|
-
if (_this.isOpened) { return; }
|
|
306
|
-
|
|
307
|
-
_this.hidRef.readSync(); // Start reading data from usbDevice
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
_this.listen();
|
|
311
|
-
} catch (e) {
|
|
312
|
-
return Promise.reject(e);
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
HIDKeepKeyTransport.prototype.disconnect = function disconnect () {
|
|
317
|
-
try {
|
|
318
|
-
var _this2 = this;
|
|
319
|
-
|
|
320
|
-
var _temp = _catch(function () {
|
|
321
|
-
// If the device is disconnected, this will fail and throw, which is fine.
|
|
322
|
-
return Promise.resolve(_this2.hidRef.close()).then(function () {});
|
|
323
|
-
}, function (e) {
|
|
324
|
-
console.log('Disconnect Error (Ignored):', e);
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
return _temp && _temp.then ? _temp.then(function () {}) : void 0;
|
|
328
|
-
} catch (e) {
|
|
329
|
-
return Promise.reject(e);
|
|
330
|
-
}
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
HIDKeepKeyTransport.prototype.getEntropy = function getEntropy (length) {
|
|
334
|
-
if ( length === void 0 ) length = 64;
|
|
335
|
-
|
|
336
|
-
return crypto.randomBytes(length);
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
HIDKeepKeyTransport.prototype.write = function write (buff) {
|
|
340
|
-
try {
|
|
341
|
-
var _this3 = this;
|
|
342
|
-
|
|
343
|
-
var i = 0;
|
|
344
|
-
|
|
345
|
-
var _temp2 = _for(function () {
|
|
346
|
-
return i < buff.limit;
|
|
347
|
-
}, function () {
|
|
348
|
-
return !!(i += hdwalletKeepkey.SEGMENT_SIZE);
|
|
349
|
-
}, function () {
|
|
350
|
-
var segment = buff.toArrayBuffer().slice(i, i + hdwalletKeepkey.SEGMENT_SIZE);
|
|
351
|
-
var padding = new Array(hdwalletKeepkey.SEGMENT_SIZE - segment.byteLength + 1).join('\0');
|
|
352
|
-
var fragments = [];
|
|
353
|
-
fragments.push([63]);
|
|
354
|
-
fragments.push(segment);
|
|
355
|
-
fragments.push(padding);
|
|
356
|
-
var fragmentBuffer = concat(fragments);
|
|
357
|
-
return Promise.resolve(_this3.writeChunk(fragmentBuffer)).then(function () {});
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
// break frame into segments
|
|
361
|
-
return _temp2 && _temp2.then ? _temp2.then(function () {}) : void 0;
|
|
362
|
-
} catch (e) {
|
|
363
|
-
return Promise.reject(e);
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
|
|
367
|
-
HIDKeepKeyTransport.prototype.readChunk = function readChunk (debugLink) {
|
|
368
|
-
try {
|
|
369
|
-
var _this4 = this;
|
|
370
|
-
|
|
371
|
-
return Promise.resolve(_this4.hidRef.readSync()).then(function (result) {
|
|
372
|
-
return Promise.resolve(wrap(result));
|
|
373
|
-
});
|
|
374
|
-
} catch (e) {
|
|
375
|
-
return Promise.reject(e);
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
HIDKeepKeyTransport.prototype.read = function read (debugLink) {
|
|
380
|
-
try {
|
|
381
|
-
var _this5 = this;
|
|
382
|
-
|
|
383
|
-
return Promise.resolve(_this5.readChunk(debugLink)).then(function (first) {
|
|
384
|
-
// Check that buffer starts with: "?##" [ 0x3f, 0x23, 0x23 ]
|
|
385
|
-
// "?" = USB marker, "##" = KeepKey magic bytes
|
|
386
|
-
// Message ID is bytes 4-5. Message length starts at byte 6.
|
|
387
|
-
var valid = (first.readUint32(0) & 0xffffff00) === 0x3f232300;
|
|
388
|
-
var msgLength = first.readUint32(5);
|
|
389
|
-
return function () {
|
|
390
|
-
if (valid && msgLength >= 0) {
|
|
391
|
-
function _temp4() {
|
|
392
|
-
return wrap(buffer);
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
// FIXME: why doesn't ByteBuffer.concat() work?
|
|
396
|
-
var buffer = new Uint8Array(9 + 2 + msgLength);
|
|
397
|
-
|
|
398
|
-
for (var k = 0; k < first.limit; k++) {
|
|
399
|
-
buffer[k] = first.readUint8(k);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
var offset = first.limit;
|
|
403
|
-
|
|
404
|
-
var _temp3 = _for(function () {
|
|
405
|
-
return offset < buffer.length;
|
|
406
|
-
}, void 0, function () {
|
|
407
|
-
return Promise.resolve(_this5.readChunk(debugLink)).then(function (next) {
|
|
408
|
-
// Drop USB "?" reportId in the first byte
|
|
409
|
-
for (var k = 1; k < next.limit && offset < buffer.length; k++) {
|
|
410
|
-
buffer[offset] = next.readUint8(k);
|
|
411
|
-
offset++;
|
|
412
|
-
}
|
|
413
|
-
});
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
|
|
417
|
-
}
|
|
418
|
-
}();
|
|
419
|
-
});
|
|
420
|
-
} catch (e) {
|
|
421
|
-
return Promise.reject(e);
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
|
|
425
|
-
HIDKeepKeyTransport.prototype.writeChunk = function writeChunk (buffer) {
|
|
426
|
-
try {
|
|
427
|
-
var _this6 = this;
|
|
428
|
-
|
|
429
|
-
var arr = new Array(buffer.limit).fill(undefined);
|
|
430
|
-
|
|
431
|
-
for (var i = buffer.offset; i < buffer.limit; i++) {
|
|
432
|
-
arr[i] = buffer.readByte(i);
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
return _this6.hidRef.write(arr);
|
|
436
|
-
} catch (e) {
|
|
437
|
-
return Promise.reject(e);
|
|
438
|
-
}
|
|
439
|
-
};
|
|
440
|
-
|
|
441
|
-
HIDKeepKeyTransport.prototype.enqueueBuffer = function enqueueBuffer (data) {
|
|
442
|
-
if (data.length) { this.bufferQueue.push(wrap(data)); }
|
|
443
|
-
};
|
|
444
|
-
|
|
445
|
-
Object.defineProperties( HIDKeepKeyTransport.prototype, prototypeAccessors );
|
|
446
|
-
|
|
447
|
-
return HIDKeepKeyTransport;
|
|
448
|
-
}(hdwalletKeepkey.KeepKeyTransport));
|
|
449
|
-
|
|
450
|
-
var HIDKeepKeyAdapter = function HIDKeepKeyAdapter(keyring) {
|
|
451
|
-
this.keyring = keyring;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
452
11
|
};
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
HIDKeepKeyAdapter.prototype.initialize = function initialize (devices, autoConnect) {
|
|
459
|
-
if ( autoConnect === void 0 ) autoConnect = true;
|
|
460
|
-
|
|
461
|
-
try {
|
|
462
|
-
var _this = this;
|
|
463
|
-
|
|
464
|
-
function _temp6() {
|
|
465
|
-
return Object.keys(_this.keyring.wallets).length;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
var devicesToInitialize = devices || HID.devices().filter(function (d) { return d.vendorId === VENDOR_ID && d.productId === PRODUCT_ID; });
|
|
469
|
-
|
|
470
|
-
var _temp5 = _forTo(devicesToInitialize, function (i) {
|
|
471
|
-
function _temp4() {
|
|
472
|
-
function _temp2() {
|
|
473
|
-
_this.keyring.add(wallet, hidDevice.serialNumber);
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
var wallet = hdwalletKeepkey.create(new HIDKeepKeyTransport(hidDevice, _this.keyring));
|
|
477
|
-
|
|
478
|
-
var _temp = function () {
|
|
479
|
-
if (autoConnect) { return Promise.resolve(wallet.initialize()).then(function () {}); }
|
|
480
|
-
}();
|
|
481
|
-
|
|
482
|
-
return _temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp);
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
var hidDevice = devicesToInitialize[i];
|
|
486
|
-
|
|
487
|
-
var _temp3 = function () {
|
|
488
|
-
if (_this.keyring.wallets[hidDevice.serialNumber]) {
|
|
489
|
-
return Promise.resolve(_this.keyring.remove(hidDevice.serialNumber)).then(function () {});
|
|
490
|
-
}
|
|
491
|
-
}();
|
|
492
|
-
|
|
493
|
-
return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
return _temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5);
|
|
497
|
-
} catch (e) {
|
|
498
|
-
return Promise.reject(e);
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
|
|
502
|
-
HIDKeepKeyAdapter.prototype.handleConnectKeepKey = function handleConnectKeepKey (device) {
|
|
503
|
-
var this$1 = this;
|
|
504
|
-
|
|
505
|
-
var deviceID = device.serialNumber;
|
|
506
|
-
var devices = HID.devices().filter(function (d) { return d.serialNumber === device.serialNumber; });
|
|
507
|
-
this.initialize(devices).then(function () { return function () { return this$1.keyring.emit([device.product, deviceID, hdwalletCore.Events.CONNECT], deviceID); }; }).catch(console.error);
|
|
508
|
-
};
|
|
509
|
-
|
|
510
|
-
HIDKeepKeyAdapter.prototype.handleDisconnectKeepKey = function handleDisconnectKeepKey (device) {
|
|
511
|
-
var this$1 = this;
|
|
512
|
-
|
|
513
|
-
this.keyring.remove(device.serialNumber).then(function () { return this$1.keyring.emit([device.product, device.serialNumber, hdwalletCore.Events.DISCONNECT], device.serialNumber); }).catch(function () { return this$1.keyring.emit([device.product, device.serialNumber, hdwalletCore.Events.DISCONNECT], device.serialNumber); });
|
|
514
|
-
};
|
|
515
|
-
|
|
516
|
-
exports.HIDKeepKeyAdapter = HIDKeepKeyAdapter;
|
|
517
|
-
exports.requestPair = requestPair;
|
|
518
|
-
exports.HIDKeepKeyTransport = HIDKeepKeyTransport;
|
|
519
|
-
exports.VENDOR_ID = VENDOR_ID;
|
|
520
|
-
exports.PRODUCT_ID = PRODUCT_ID;
|
|
521
|
-
//# sourceMappingURL=index.js.map
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./adapter"), exports);
|
|
14
|
+
__exportStar(require("./transport"), exports);
|
|
15
|
+
__exportStar(require("./utils"), exports);
|
|
16
|
+
//# sourceMappingURL=index.js.map
|