@ledgerhq/hw-transport 6.31.4-next.0 → 6.31.5-next.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/.turbo/turbo-build.log +2 -2
- package/CHANGELOG.md +16 -0
- package/lib/Transport.d.ts +1 -0
- package/lib/Transport.d.ts.map +1 -1
- package/lib/Transport.js +128 -92
- package/lib/Transport.js.map +1 -1
- package/lib-es/Transport.d.ts +1 -0
- package/lib-es/Transport.d.ts.map +1 -1
- package/lib-es/Transport.js +129 -94
- package/lib-es/Transport.js.map +1 -1
- package/package.json +6 -5
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
> @ledgerhq/hw-transport@6.31.
|
|
3
|
-
> tsc && tsc -m
|
|
2
|
+
> @ledgerhq/hw-transport@6.31.4 build /home/runner/work/ledger-live/ledger-live/libs/ledgerjs/packages/hw-transport
|
|
3
|
+
> tsc && tsc -m esnext --moduleResolution bundler --outDir lib-es
|
|
4
4
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @ledgerhq/hw-transport
|
|
2
2
|
|
|
3
|
+
## 6.31.5-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`107f35a`](https://github.com/LedgerHQ/ledger-live/commit/107f35a0650412716b088a3503b86435e6d9cf47), [`9081c26`](https://github.com/LedgerHQ/ledger-live/commit/9081c2648490f977469a33762a3c67bb2c2a0be5)]:
|
|
8
|
+
- @ledgerhq/errors@6.21.0-next.0
|
|
9
|
+
- @ledgerhq/devices@8.4.5-next.0
|
|
10
|
+
|
|
11
|
+
## 6.31.4
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`0a71c43`](https://github.com/LedgerHQ/ledger-live/commit/0a71c4344b7bb2c6640f3e5dda152ae815573330)]:
|
|
16
|
+
- @ledgerhq/errors@6.19.1
|
|
17
|
+
- @ledgerhq/devices@8.4.4
|
|
18
|
+
|
|
3
19
|
## 6.31.4-next.0
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/lib/Transport.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
3
4
|
import EventEmitter from "events";
|
|
4
5
|
import type { DeviceModel } from "@ledgerhq/devices";
|
|
5
6
|
import { TransportError, StatusCodes, getAltStatusMessage, TransportStatusError } from "@ledgerhq/errors";
|
package/lib/Transport.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transport.d.ts","sourceRoot":"","sources":["../src/Transport.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Transport.d.ts","sourceRoot":"","sources":["../src/Transport.ts"],"names":[],"mappings":";;;AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAClC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAEL,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC;AAIlF;GACG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB,CAAC;AAEF;GACG;AACH,MAAM,MAAM,MAAM,GAAG,GAAG,CAAC;AAEzB,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG,QAAQ,CAAC;AACnD;;;;;;GAMG;AACH,MAAM,WAAW,eAAe,CAAC,UAAU;IACzC,IAAI,EAAE,mBAAmB,CAAC;IAC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AAC;IAgC7E,mBAAmB,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IAEtD;;;;;;;OAOG;IACG,kBAAkB,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAgD3E,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,MAAM;IAM5F,WAAW,EAAE,MAAM,GAAG,IAAI,CAAQ;IAElC,oBAAoB,CAAC,CAAC,EAAE,CAAC,SAAS,GAAG,EAAE,EACrC,UAAU,EAAE,MAAM,EAClB,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAC7B,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,MAAM,GAClB,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC;IAoB7B;;;;;;;OAOG;IACH,eAAe,CAAC,OAAO,CAAC,EAAE,YAAY;IAItC;;;;;;OAMG;IACH,kBAAkB,CAAC,YAAY,EAAE,YAAY;IAI7C;;OAEG;IACH,eAAe,IAAI,YAAY,GAAG,SAAS;IAI3C,MAAM,CAAC,0BAA0B,SAAsC;IACvE,MAAM,CAAC,0BAA0B,SAA4B;CAC9D"}
|
package/lib/Transport.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -27,45 +18,57 @@ const DEFAULT_LOG_TYPE = "transport";
|
|
|
27
18
|
* It is an abstract class that needs to be implemented.
|
|
28
19
|
*/
|
|
29
20
|
class Transport {
|
|
21
|
+
exchangeTimeout = 30000;
|
|
22
|
+
unresponsiveTimeout = 15000;
|
|
23
|
+
deviceModel = null;
|
|
24
|
+
tracer;
|
|
30
25
|
constructor({ context, logType } = {}) {
|
|
31
|
-
this.
|
|
32
|
-
this.unresponsiveTimeout = 15000;
|
|
33
|
-
this.deviceModel = null;
|
|
34
|
-
this._events = new events_1.default();
|
|
35
|
-
/**
|
|
36
|
-
* Send data to the device using the higher level API.
|
|
37
|
-
*
|
|
38
|
-
* @param {number} cla - The instruction class for the command.
|
|
39
|
-
* @param {number} ins - The instruction code for the command.
|
|
40
|
-
* @param {number} p1 - The first parameter for the instruction.
|
|
41
|
-
* @param {number} p2 - The second parameter for the instruction.
|
|
42
|
-
* @param {Buffer} data - The data to be sent. Defaults to an empty buffer.
|
|
43
|
-
* @param {Array<number>} statusList - A list of acceptable status codes for the response. Defaults to [StatusCodes.OK].
|
|
44
|
-
* @param {Object} options - Contains optional options for the exchange function
|
|
45
|
-
* - abortTimeoutMs: stop the send after a given timeout. Another timeout exists
|
|
46
|
-
* to detect unresponsive device (see `unresponsiveTimeout`). This timeout aborts the exchange.
|
|
47
|
-
* @returns {Promise<Buffer>} A promise that resolves with the response data from the device.
|
|
48
|
-
*/
|
|
49
|
-
this.send = (cla_1, ins_1, p1_1, p2_1, ...args_1) => __awaiter(this, [cla_1, ins_1, p1_1, p2_1, ...args_1], void 0, function* (cla, ins, p1, p2, data = Buffer.alloc(0), statusList = [errors_1.StatusCodes.OK], { abortTimeoutMs } = {}) {
|
|
50
|
-
const tracer = this.tracer.withUpdatedContext({ function: "send" });
|
|
51
|
-
if (data.length >= 256) {
|
|
52
|
-
tracer.trace("data.length exceeded 256 bytes limit", { dataLength: data.length });
|
|
53
|
-
throw new errors_1.TransportError("data.length exceed 256 bytes limit. Got: " + data.length, "DataLengthTooBig");
|
|
54
|
-
}
|
|
55
|
-
tracer.trace("Starting an exchange", { abortTimeoutMs });
|
|
56
|
-
const response = yield this.exchange(
|
|
57
|
-
// The size of the data is added in 1 byte just before `data`
|
|
58
|
-
Buffer.concat([Buffer.from([cla, ins, p1, p2]), Buffer.from([data.length]), data]), { abortTimeoutMs });
|
|
59
|
-
tracer.trace("Received response from exchange");
|
|
60
|
-
const sw = response.readUInt16BE(response.length - 2);
|
|
61
|
-
if (!statusList.some(s => s === sw)) {
|
|
62
|
-
throw new errors_1.TransportStatusError(sw);
|
|
63
|
-
}
|
|
64
|
-
return response;
|
|
65
|
-
});
|
|
66
|
-
this._appAPIlock = null;
|
|
67
|
-
this.tracer = new logs_1.LocalTracer(logType !== null && logType !== void 0 ? logType : DEFAULT_LOG_TYPE, context);
|
|
26
|
+
this.tracer = new logs_1.LocalTracer(logType ?? DEFAULT_LOG_TYPE, context);
|
|
68
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Check if the transport is supported on the current platform/browser.
|
|
30
|
+
* @returns {Promise<boolean>} A promise that resolves with a boolean indicating support.
|
|
31
|
+
*/
|
|
32
|
+
static isSupported;
|
|
33
|
+
/**
|
|
34
|
+
* List all available descriptors for the transport.
|
|
35
|
+
* For a better granularity, checkout `listen()`.
|
|
36
|
+
*
|
|
37
|
+
* @returns {Promise<Array<any>>} A promise that resolves with an array of descriptors.
|
|
38
|
+
* @example
|
|
39
|
+
* TransportFoo.list().then(descriptors => ...)
|
|
40
|
+
*/
|
|
41
|
+
static list;
|
|
42
|
+
/**
|
|
43
|
+
* Listen for device events for the transport. The method takes an observer of DescriptorEvent and returns a Subscription.
|
|
44
|
+
* A DescriptorEvent is an object containing a "descriptor" and a "type" field. The "type" field can be "add" or "remove", and the "descriptor" field can be passed to the "open" method.
|
|
45
|
+
* The "listen" method will first emit all currently connected devices and then will emit events as they occur, such as when a USB device is plugged in or a Bluetooth device becomes discoverable.
|
|
46
|
+
* @param {Observer<DescriptorEvent<any>>} observer - An object with "next", "error", and "complete" functions, following the observer pattern.
|
|
47
|
+
* @returns {Subscription} A Subscription object on which you can call ".unsubscribe()" to stop listening to descriptors.
|
|
48
|
+
* @example
|
|
49
|
+
const sub = TransportFoo.listen({
|
|
50
|
+
next: e => {
|
|
51
|
+
if (e.type==="add") {
|
|
52
|
+
sub.unsubscribe();
|
|
53
|
+
const transport = await TransportFoo.open(e.descriptor);
|
|
54
|
+
...
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
error: error => {},
|
|
58
|
+
complete: () => {}
|
|
59
|
+
})
|
|
60
|
+
*/
|
|
61
|
+
static listen;
|
|
62
|
+
/**
|
|
63
|
+
* Attempt to create a Transport instance with a specific descriptor.
|
|
64
|
+
* @param {any} descriptor - The descriptor to open the transport with.
|
|
65
|
+
* @param {number} timeout - An optional timeout for the transport connection.
|
|
66
|
+
* @param {TraceContext} context Optional tracing/log context
|
|
67
|
+
* @returns {Promise<Transport>} A promise that resolves with a Transport instance.
|
|
68
|
+
* @example
|
|
69
|
+
TransportFoo.open(descriptor).then(transport => ...)
|
|
70
|
+
*/
|
|
71
|
+
static open;
|
|
69
72
|
/**
|
|
70
73
|
* Send data to the device using a low level API.
|
|
71
74
|
* It's recommended to use the "send" method for a higher level API.
|
|
@@ -90,11 +93,11 @@ class Transport {
|
|
|
90
93
|
const unsubscribe = () => {
|
|
91
94
|
unsubscribed = true;
|
|
92
95
|
};
|
|
93
|
-
const main = () =>
|
|
96
|
+
const main = async () => {
|
|
94
97
|
if (unsubscribed)
|
|
95
98
|
return;
|
|
96
99
|
for (const apdu of apdus) {
|
|
97
|
-
const r =
|
|
100
|
+
const r = await this.exchange(apdu);
|
|
98
101
|
if (unsubscribed)
|
|
99
102
|
return;
|
|
100
103
|
const status = r.readUInt16BE(r.length - 2);
|
|
@@ -103,7 +106,7 @@ class Transport {
|
|
|
103
106
|
}
|
|
104
107
|
observer.next(r);
|
|
105
108
|
}
|
|
106
|
-
}
|
|
109
|
+
};
|
|
107
110
|
main().then(() => !unsubscribed && observer.complete(), e => !unsubscribed && observer.error(e));
|
|
108
111
|
return { unsubscribe };
|
|
109
112
|
}
|
|
@@ -128,6 +131,7 @@ class Transport {
|
|
|
128
131
|
close() {
|
|
129
132
|
return Promise.resolve();
|
|
130
133
|
}
|
|
134
|
+
_events = new events_1.default();
|
|
131
135
|
/**
|
|
132
136
|
* Listen for an event on the transport instance.
|
|
133
137
|
* Transport implementations may have specific events. Common events include:
|
|
@@ -165,6 +169,37 @@ class Transport {
|
|
|
165
169
|
setExchangeUnresponsiveTimeout(unresponsiveTimeout) {
|
|
166
170
|
this.unresponsiveTimeout = unresponsiveTimeout;
|
|
167
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Send data to the device using the higher level API.
|
|
174
|
+
*
|
|
175
|
+
* @param {number} cla - The instruction class for the command.
|
|
176
|
+
* @param {number} ins - The instruction code for the command.
|
|
177
|
+
* @param {number} p1 - The first parameter for the instruction.
|
|
178
|
+
* @param {number} p2 - The second parameter for the instruction.
|
|
179
|
+
* @param {Buffer} data - The data to be sent. Defaults to an empty buffer.
|
|
180
|
+
* @param {Array<number>} statusList - A list of acceptable status codes for the response. Defaults to [StatusCodes.OK].
|
|
181
|
+
* @param {Object} options - Contains optional options for the exchange function
|
|
182
|
+
* - abortTimeoutMs: stop the send after a given timeout. Another timeout exists
|
|
183
|
+
* to detect unresponsive device (see `unresponsiveTimeout`). This timeout aborts the exchange.
|
|
184
|
+
* @returns {Promise<Buffer>} A promise that resolves with the response data from the device.
|
|
185
|
+
*/
|
|
186
|
+
send = async (cla, ins, p1, p2, data = Buffer.alloc(0), statusList = [errors_1.StatusCodes.OK], { abortTimeoutMs } = {}) => {
|
|
187
|
+
const tracer = this.tracer.withUpdatedContext({ function: "send" });
|
|
188
|
+
if (data.length >= 256) {
|
|
189
|
+
tracer.trace("data.length exceeded 256 bytes limit", { dataLength: data.length });
|
|
190
|
+
throw new errors_1.TransportError("data.length exceed 256 bytes limit. Got: " + data.length, "DataLengthTooBig");
|
|
191
|
+
}
|
|
192
|
+
tracer.trace("Starting an exchange", { abortTimeoutMs });
|
|
193
|
+
const response = await this.exchange(
|
|
194
|
+
// The size of the data is added in 1 byte just before `data`
|
|
195
|
+
Buffer.concat([Buffer.from([cla, ins, p1, p2]), Buffer.from([data.length]), data]), { abortTimeoutMs });
|
|
196
|
+
tracer.trace("Received response from exchange");
|
|
197
|
+
const sw = response.readUInt16BE(response.length - 2);
|
|
198
|
+
if (!statusList.some(s => s === sw)) {
|
|
199
|
+
throw new errors_1.TransportStatusError(sw);
|
|
200
|
+
}
|
|
201
|
+
return response;
|
|
202
|
+
};
|
|
168
203
|
/**
|
|
169
204
|
* create() allows to open the first descriptor available or
|
|
170
205
|
* throw if there is none or if timeout is reached.
|
|
@@ -205,6 +240,8 @@ class Transport {
|
|
|
205
240
|
: null;
|
|
206
241
|
});
|
|
207
242
|
}
|
|
243
|
+
// Blocks other exchange to happen concurrently
|
|
244
|
+
exchangeBusyPromise;
|
|
208
245
|
/**
|
|
209
246
|
* Wrapper to make an exchange "atomic" (blocking any other exchange)
|
|
210
247
|
*
|
|
@@ -213,55 +250,54 @@ class Transport {
|
|
|
213
250
|
* @param f The exchange job, using the transport to run
|
|
214
251
|
* @returns a Promise resolving with the output of the given job
|
|
215
252
|
*/
|
|
216
|
-
exchangeAtomicImpl(f) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
253
|
+
async exchangeAtomicImpl(f) {
|
|
254
|
+
const tracer = this.tracer.withUpdatedContext({
|
|
255
|
+
function: "exchangeAtomicImpl",
|
|
256
|
+
unresponsiveTimeout: this.unresponsiveTimeout,
|
|
257
|
+
});
|
|
258
|
+
if (this.exchangeBusyPromise) {
|
|
259
|
+
tracer.trace("Atomic exchange is already busy");
|
|
260
|
+
throw new errors_1.TransportRaceCondition("An action was already pending on the Ledger device. Please deny or reconnect.");
|
|
261
|
+
}
|
|
262
|
+
// Sets the atomic guard
|
|
263
|
+
let resolveBusy;
|
|
264
|
+
const busyPromise = new Promise(r => {
|
|
265
|
+
resolveBusy = r;
|
|
266
|
+
});
|
|
267
|
+
this.exchangeBusyPromise = busyPromise;
|
|
268
|
+
// The device unresponsiveness handler
|
|
269
|
+
let unresponsiveReached = false;
|
|
270
|
+
const timeout = setTimeout(() => {
|
|
271
|
+
tracer.trace(`Timeout reached, emitting Transport event "unresponsive"`, {
|
|
220
272
|
unresponsiveTimeout: this.unresponsiveTimeout,
|
|
221
273
|
});
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
});
|
|
231
|
-
this.exchangeBusyPromise = busyPromise;
|
|
232
|
-
// The device unresponsiveness handler
|
|
233
|
-
let unresponsiveReached = false;
|
|
234
|
-
const timeout = setTimeout(() => {
|
|
235
|
-
tracer.trace(`Timeout reached, emitting Transport event "unresponsive"`, {
|
|
236
|
-
unresponsiveTimeout: this.unresponsiveTimeout,
|
|
237
|
-
});
|
|
238
|
-
unresponsiveReached = true;
|
|
239
|
-
this.emit("unresponsive");
|
|
240
|
-
}, this.unresponsiveTimeout);
|
|
241
|
-
try {
|
|
242
|
-
const res = yield f();
|
|
243
|
-
if (unresponsiveReached) {
|
|
244
|
-
tracer.trace("Device was unresponsive, emitting responsive");
|
|
245
|
-
this.emit("responsive");
|
|
246
|
-
}
|
|
247
|
-
return res;
|
|
248
|
-
}
|
|
249
|
-
finally {
|
|
250
|
-
tracer.trace("Finalize, clearing busy guard");
|
|
251
|
-
clearTimeout(timeout);
|
|
252
|
-
if (resolveBusy)
|
|
253
|
-
resolveBusy();
|
|
254
|
-
this.exchangeBusyPromise = null;
|
|
274
|
+
unresponsiveReached = true;
|
|
275
|
+
this.emit("unresponsive");
|
|
276
|
+
}, this.unresponsiveTimeout);
|
|
277
|
+
try {
|
|
278
|
+
const res = await f();
|
|
279
|
+
if (unresponsiveReached) {
|
|
280
|
+
tracer.trace("Device was unresponsive, emitting responsive");
|
|
281
|
+
this.emit("responsive");
|
|
255
282
|
}
|
|
256
|
-
|
|
283
|
+
return res;
|
|
284
|
+
}
|
|
285
|
+
finally {
|
|
286
|
+
tracer.trace("Finalize, clearing busy guard");
|
|
287
|
+
clearTimeout(timeout);
|
|
288
|
+
if (resolveBusy)
|
|
289
|
+
resolveBusy();
|
|
290
|
+
this.exchangeBusyPromise = null;
|
|
291
|
+
}
|
|
257
292
|
}
|
|
258
293
|
decorateAppAPIMethods(self, methods, scrambleKey) {
|
|
259
294
|
for (const methodName of methods) {
|
|
260
295
|
self[methodName] = this.decorateAppAPIMethod(methodName, self[methodName], self, scrambleKey);
|
|
261
296
|
}
|
|
262
297
|
}
|
|
298
|
+
_appAPIlock = null;
|
|
263
299
|
decorateAppAPIMethod(methodName, f, ctx, scrambleKey) {
|
|
264
|
-
return (...args) =>
|
|
300
|
+
return async (...args) => {
|
|
265
301
|
const { _appAPIlock } = this;
|
|
266
302
|
if (_appAPIlock) {
|
|
267
303
|
return Promise.reject(new errors_1.TransportError("Ledger Device is busy (lock " + _appAPIlock + ")", "TransportLocked"));
|
|
@@ -269,12 +305,12 @@ class Transport {
|
|
|
269
305
|
try {
|
|
270
306
|
this._appAPIlock = methodName;
|
|
271
307
|
this.setScrambleKey(scrambleKey);
|
|
272
|
-
return
|
|
308
|
+
return await f.apply(ctx, args);
|
|
273
309
|
}
|
|
274
310
|
finally {
|
|
275
311
|
this._appAPIlock = null;
|
|
276
312
|
}
|
|
277
|
-
}
|
|
313
|
+
};
|
|
278
314
|
}
|
|
279
315
|
/**
|
|
280
316
|
* Sets the context used by the logging/tracing mechanism
|
|
@@ -303,8 +339,8 @@ class Transport {
|
|
|
303
339
|
getTraceContext() {
|
|
304
340
|
return this.tracer.getContext();
|
|
305
341
|
}
|
|
342
|
+
static ErrorMessage_ListenTimeout = "No Ledger device found (timeout)";
|
|
343
|
+
static ErrorMessage_NoDeviceFound = "No Ledger device found";
|
|
306
344
|
}
|
|
307
|
-
Transport.ErrorMessage_ListenTimeout = "No Ledger device found (timeout)";
|
|
308
|
-
Transport.ErrorMessage_NoDeviceFound = "No Ledger device found";
|
|
309
345
|
exports.default = Transport;
|
|
310
346
|
//# sourceMappingURL=Transport.js.map
|
package/lib/Transport.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transport.js","sourceRoot":"","sources":["../src/Transport.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Transport.js","sourceRoot":"","sources":["../src/Transport.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAkC;AAElC,6CAM0B;AAEjB,+FANP,uBAAc,OAMO;AAAwB,4FAL7C,oBAAW,OAK6C;AAAE,oGAJ1D,4BAAmB,OAI0D;AAAtD,qGAHvB,6BAAoB,OAGuB;AAD7C,yCAAoE;AAGpE,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAoCrC;;;;GAIG;AACH,MAAqB,SAAS;IAC5B,eAAe,GAAG,KAAK,CAAC;IACxB,mBAAmB,GAAG,KAAK,CAAC;IAC5B,WAAW,GAAmC,IAAI,CAAC;IACnD,MAAM,CAAc;IAEpB,YAAY,EAAE,OAAO,EAAE,OAAO,KAAoD,EAAE;QAClF,IAAI,CAAC,MAAM,GAAG,IAAI,kBAAW,CAAC,OAAO,IAAI,gBAAgB,EAAE,OAAO,CAAC,CAAC;IACtE,CAAC;IAED;;;OAGG;IACH,MAAM,CAAU,WAAW,CAAyB;IAEpD;;;;;;;OAOG;IACH,MAAM,CAAU,IAAI,CAA4B;IAEhD;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yYC"}
|
package/lib-es/Transport.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
3
4
|
import EventEmitter from "events";
|
|
4
5
|
import type { DeviceModel } from "@ledgerhq/devices";
|
|
5
6
|
import { TransportError, StatusCodes, getAltStatusMessage, TransportStatusError } from "@ledgerhq/errors";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transport.d.ts","sourceRoot":"","sources":["../src/Transport.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Transport.d.ts","sourceRoot":"","sources":["../src/Transport.ts"],"names":[],"mappings":";;;AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAClC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAEL,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC;AAIlF;GACG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB,CAAC;AAEF;GACG;AACH,MAAM,MAAM,MAAM,GAAG,GAAG,CAAC;AAEzB,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG,QAAQ,CAAC;AACnD;;;;;;GAMG;AACH,MAAM,WAAW,eAAe,CAAC,UAAU;IACzC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,CAAC,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,MAA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CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAgD3E,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,MAAM;IAM5F,WAAW,EAAE,MAAM,GAAG,IAAI,CAAQ;IAElC,oBAAoB,CAAC,CAAC,EAAE,CAAC,SAAS,GAAG,EAAE,EACrC,UAAU,EAAE,MAAM,EAClB,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAC7B,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,MAAM,GAClB,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC;IAoB7B;;;;;;;OAOG;IACH,eAAe,CAAC,OAAO,CAAC,EAAE,YAAY;IAItC;;;;;;OAMG;IACH,kBAAkB,CAAC,YAAY,EAAE,YAAY;IAI7C;;OAEG;IACH,eAAe,IAAI,YAAY,GAAG,SAAS;IAI3C,MAAM,CAAC,0BAA0B,SAAsC;IACvE,MAAM,CAAC,0BAA0B,SAA4B;CAC9D"}
|
package/lib-es/Transport.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import EventEmitter from "events";
|
|
11
2
|
import { TransportRaceCondition, TransportError, StatusCodes, getAltStatusMessage, TransportStatusError, } from "@ledgerhq/errors";
|
|
12
3
|
import { LocalTracer } from "@ledgerhq/logs";
|
|
@@ -17,46 +8,58 @@ const DEFAULT_LOG_TYPE = "transport";
|
|
|
17
8
|
* There are different kind of transports based on the technology (channels like U2F, HID, Bluetooth, Webusb) and environment (Node, Web,...).
|
|
18
9
|
* It is an abstract class that needs to be implemented.
|
|
19
10
|
*/
|
|
20
|
-
class Transport {
|
|
11
|
+
export default class Transport {
|
|
12
|
+
exchangeTimeout = 30000;
|
|
13
|
+
unresponsiveTimeout = 15000;
|
|
14
|
+
deviceModel = null;
|
|
15
|
+
tracer;
|
|
21
16
|
constructor({ context, logType } = {}) {
|
|
22
|
-
this.
|
|
23
|
-
this.unresponsiveTimeout = 15000;
|
|
24
|
-
this.deviceModel = null;
|
|
25
|
-
this._events = new EventEmitter();
|
|
26
|
-
/**
|
|
27
|
-
* Send data to the device using the higher level API.
|
|
28
|
-
*
|
|
29
|
-
* @param {number} cla - The instruction class for the command.
|
|
30
|
-
* @param {number} ins - The instruction code for the command.
|
|
31
|
-
* @param {number} p1 - The first parameter for the instruction.
|
|
32
|
-
* @param {number} p2 - The second parameter for the instruction.
|
|
33
|
-
* @param {Buffer} data - The data to be sent. Defaults to an empty buffer.
|
|
34
|
-
* @param {Array<number>} statusList - A list of acceptable status codes for the response. Defaults to [StatusCodes.OK].
|
|
35
|
-
* @param {Object} options - Contains optional options for the exchange function
|
|
36
|
-
* - abortTimeoutMs: stop the send after a given timeout. Another timeout exists
|
|
37
|
-
* to detect unresponsive device (see `unresponsiveTimeout`). This timeout aborts the exchange.
|
|
38
|
-
* @returns {Promise<Buffer>} A promise that resolves with the response data from the device.
|
|
39
|
-
*/
|
|
40
|
-
this.send = (cla_1, ins_1, p1_1, p2_1, ...args_1) => __awaiter(this, [cla_1, ins_1, p1_1, p2_1, ...args_1], void 0, function* (cla, ins, p1, p2, data = Buffer.alloc(0), statusList = [StatusCodes.OK], { abortTimeoutMs } = {}) {
|
|
41
|
-
const tracer = this.tracer.withUpdatedContext({ function: "send" });
|
|
42
|
-
if (data.length >= 256) {
|
|
43
|
-
tracer.trace("data.length exceeded 256 bytes limit", { dataLength: data.length });
|
|
44
|
-
throw new TransportError("data.length exceed 256 bytes limit. Got: " + data.length, "DataLengthTooBig");
|
|
45
|
-
}
|
|
46
|
-
tracer.trace("Starting an exchange", { abortTimeoutMs });
|
|
47
|
-
const response = yield this.exchange(
|
|
48
|
-
// The size of the data is added in 1 byte just before `data`
|
|
49
|
-
Buffer.concat([Buffer.from([cla, ins, p1, p2]), Buffer.from([data.length]), data]), { abortTimeoutMs });
|
|
50
|
-
tracer.trace("Received response from exchange");
|
|
51
|
-
const sw = response.readUInt16BE(response.length - 2);
|
|
52
|
-
if (!statusList.some(s => s === sw)) {
|
|
53
|
-
throw new TransportStatusError(sw);
|
|
54
|
-
}
|
|
55
|
-
return response;
|
|
56
|
-
});
|
|
57
|
-
this._appAPIlock = null;
|
|
58
|
-
this.tracer = new LocalTracer(logType !== null && logType !== void 0 ? logType : DEFAULT_LOG_TYPE, context);
|
|
17
|
+
this.tracer = new LocalTracer(logType ?? DEFAULT_LOG_TYPE, context);
|
|
59
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Check if the transport is supported on the current platform/browser.
|
|
21
|
+
* @returns {Promise<boolean>} A promise that resolves with a boolean indicating support.
|
|
22
|
+
*/
|
|
23
|
+
static isSupported;
|
|
24
|
+
/**
|
|
25
|
+
* List all available descriptors for the transport.
|
|
26
|
+
* For a better granularity, checkout `listen()`.
|
|
27
|
+
*
|
|
28
|
+
* @returns {Promise<Array<any>>} A promise that resolves with an array of descriptors.
|
|
29
|
+
* @example
|
|
30
|
+
* TransportFoo.list().then(descriptors => ...)
|
|
31
|
+
*/
|
|
32
|
+
static list;
|
|
33
|
+
/**
|
|
34
|
+
* Listen for device events for the transport. The method takes an observer of DescriptorEvent and returns a Subscription.
|
|
35
|
+
* A DescriptorEvent is an object containing a "descriptor" and a "type" field. The "type" field can be "add" or "remove", and the "descriptor" field can be passed to the "open" method.
|
|
36
|
+
* The "listen" method will first emit all currently connected devices and then will emit events as they occur, such as when a USB device is plugged in or a Bluetooth device becomes discoverable.
|
|
37
|
+
* @param {Observer<DescriptorEvent<any>>} observer - An object with "next", "error", and "complete" functions, following the observer pattern.
|
|
38
|
+
* @returns {Subscription} A Subscription object on which you can call ".unsubscribe()" to stop listening to descriptors.
|
|
39
|
+
* @example
|
|
40
|
+
const sub = TransportFoo.listen({
|
|
41
|
+
next: e => {
|
|
42
|
+
if (e.type==="add") {
|
|
43
|
+
sub.unsubscribe();
|
|
44
|
+
const transport = await TransportFoo.open(e.descriptor);
|
|
45
|
+
...
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
error: error => {},
|
|
49
|
+
complete: () => {}
|
|
50
|
+
})
|
|
51
|
+
*/
|
|
52
|
+
static listen;
|
|
53
|
+
/**
|
|
54
|
+
* Attempt to create a Transport instance with a specific descriptor.
|
|
55
|
+
* @param {any} descriptor - The descriptor to open the transport with.
|
|
56
|
+
* @param {number} timeout - An optional timeout for the transport connection.
|
|
57
|
+
* @param {TraceContext} context Optional tracing/log context
|
|
58
|
+
* @returns {Promise<Transport>} A promise that resolves with a Transport instance.
|
|
59
|
+
* @example
|
|
60
|
+
TransportFoo.open(descriptor).then(transport => ...)
|
|
61
|
+
*/
|
|
62
|
+
static open;
|
|
60
63
|
/**
|
|
61
64
|
* Send data to the device using a low level API.
|
|
62
65
|
* It's recommended to use the "send" method for a higher level API.
|
|
@@ -81,11 +84,11 @@ class Transport {
|
|
|
81
84
|
const unsubscribe = () => {
|
|
82
85
|
unsubscribed = true;
|
|
83
86
|
};
|
|
84
|
-
const main = () =>
|
|
87
|
+
const main = async () => {
|
|
85
88
|
if (unsubscribed)
|
|
86
89
|
return;
|
|
87
90
|
for (const apdu of apdus) {
|
|
88
|
-
const r =
|
|
91
|
+
const r = await this.exchange(apdu);
|
|
89
92
|
if (unsubscribed)
|
|
90
93
|
return;
|
|
91
94
|
const status = r.readUInt16BE(r.length - 2);
|
|
@@ -94,7 +97,7 @@ class Transport {
|
|
|
94
97
|
}
|
|
95
98
|
observer.next(r);
|
|
96
99
|
}
|
|
97
|
-
}
|
|
100
|
+
};
|
|
98
101
|
main().then(() => !unsubscribed && observer.complete(), e => !unsubscribed && observer.error(e));
|
|
99
102
|
return { unsubscribe };
|
|
100
103
|
}
|
|
@@ -119,6 +122,7 @@ class Transport {
|
|
|
119
122
|
close() {
|
|
120
123
|
return Promise.resolve();
|
|
121
124
|
}
|
|
125
|
+
_events = new EventEmitter();
|
|
122
126
|
/**
|
|
123
127
|
* Listen for an event on the transport instance.
|
|
124
128
|
* Transport implementations may have specific events. Common events include:
|
|
@@ -156,6 +160,37 @@ class Transport {
|
|
|
156
160
|
setExchangeUnresponsiveTimeout(unresponsiveTimeout) {
|
|
157
161
|
this.unresponsiveTimeout = unresponsiveTimeout;
|
|
158
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Send data to the device using the higher level API.
|
|
165
|
+
*
|
|
166
|
+
* @param {number} cla - The instruction class for the command.
|
|
167
|
+
* @param {number} ins - The instruction code for the command.
|
|
168
|
+
* @param {number} p1 - The first parameter for the instruction.
|
|
169
|
+
* @param {number} p2 - The second parameter for the instruction.
|
|
170
|
+
* @param {Buffer} data - The data to be sent. Defaults to an empty buffer.
|
|
171
|
+
* @param {Array<number>} statusList - A list of acceptable status codes for the response. Defaults to [StatusCodes.OK].
|
|
172
|
+
* @param {Object} options - Contains optional options for the exchange function
|
|
173
|
+
* - abortTimeoutMs: stop the send after a given timeout. Another timeout exists
|
|
174
|
+
* to detect unresponsive device (see `unresponsiveTimeout`). This timeout aborts the exchange.
|
|
175
|
+
* @returns {Promise<Buffer>} A promise that resolves with the response data from the device.
|
|
176
|
+
*/
|
|
177
|
+
send = async (cla, ins, p1, p2, data = Buffer.alloc(0), statusList = [StatusCodes.OK], { abortTimeoutMs } = {}) => {
|
|
178
|
+
const tracer = this.tracer.withUpdatedContext({ function: "send" });
|
|
179
|
+
if (data.length >= 256) {
|
|
180
|
+
tracer.trace("data.length exceeded 256 bytes limit", { dataLength: data.length });
|
|
181
|
+
throw new TransportError("data.length exceed 256 bytes limit. Got: " + data.length, "DataLengthTooBig");
|
|
182
|
+
}
|
|
183
|
+
tracer.trace("Starting an exchange", { abortTimeoutMs });
|
|
184
|
+
const response = await this.exchange(
|
|
185
|
+
// The size of the data is added in 1 byte just before `data`
|
|
186
|
+
Buffer.concat([Buffer.from([cla, ins, p1, p2]), Buffer.from([data.length]), data]), { abortTimeoutMs });
|
|
187
|
+
tracer.trace("Received response from exchange");
|
|
188
|
+
const sw = response.readUInt16BE(response.length - 2);
|
|
189
|
+
if (!statusList.some(s => s === sw)) {
|
|
190
|
+
throw new TransportStatusError(sw);
|
|
191
|
+
}
|
|
192
|
+
return response;
|
|
193
|
+
};
|
|
159
194
|
/**
|
|
160
195
|
* create() allows to open the first descriptor available or
|
|
161
196
|
* throw if there is none or if timeout is reached.
|
|
@@ -196,6 +231,8 @@ class Transport {
|
|
|
196
231
|
: null;
|
|
197
232
|
});
|
|
198
233
|
}
|
|
234
|
+
// Blocks other exchange to happen concurrently
|
|
235
|
+
exchangeBusyPromise;
|
|
199
236
|
/**
|
|
200
237
|
* Wrapper to make an exchange "atomic" (blocking any other exchange)
|
|
201
238
|
*
|
|
@@ -204,55 +241,54 @@ class Transport {
|
|
|
204
241
|
* @param f The exchange job, using the transport to run
|
|
205
242
|
* @returns a Promise resolving with the output of the given job
|
|
206
243
|
*/
|
|
207
|
-
exchangeAtomicImpl(f) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
244
|
+
async exchangeAtomicImpl(f) {
|
|
245
|
+
const tracer = this.tracer.withUpdatedContext({
|
|
246
|
+
function: "exchangeAtomicImpl",
|
|
247
|
+
unresponsiveTimeout: this.unresponsiveTimeout,
|
|
248
|
+
});
|
|
249
|
+
if (this.exchangeBusyPromise) {
|
|
250
|
+
tracer.trace("Atomic exchange is already busy");
|
|
251
|
+
throw new TransportRaceCondition("An action was already pending on the Ledger device. Please deny or reconnect.");
|
|
252
|
+
}
|
|
253
|
+
// Sets the atomic guard
|
|
254
|
+
let resolveBusy;
|
|
255
|
+
const busyPromise = new Promise(r => {
|
|
256
|
+
resolveBusy = r;
|
|
257
|
+
});
|
|
258
|
+
this.exchangeBusyPromise = busyPromise;
|
|
259
|
+
// The device unresponsiveness handler
|
|
260
|
+
let unresponsiveReached = false;
|
|
261
|
+
const timeout = setTimeout(() => {
|
|
262
|
+
tracer.trace(`Timeout reached, emitting Transport event "unresponsive"`, {
|
|
211
263
|
unresponsiveTimeout: this.unresponsiveTimeout,
|
|
212
264
|
});
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
265
|
+
unresponsiveReached = true;
|
|
266
|
+
this.emit("unresponsive");
|
|
267
|
+
}, this.unresponsiveTimeout);
|
|
268
|
+
try {
|
|
269
|
+
const res = await f();
|
|
270
|
+
if (unresponsiveReached) {
|
|
271
|
+
tracer.trace("Device was unresponsive, emitting responsive");
|
|
272
|
+
this.emit("responsive");
|
|
216
273
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
tracer.trace(`Timeout reached, emitting Transport event "unresponsive"`, {
|
|
227
|
-
unresponsiveTimeout: this.unresponsiveTimeout,
|
|
228
|
-
});
|
|
229
|
-
unresponsiveReached = true;
|
|
230
|
-
this.emit("unresponsive");
|
|
231
|
-
}, this.unresponsiveTimeout);
|
|
232
|
-
try {
|
|
233
|
-
const res = yield f();
|
|
234
|
-
if (unresponsiveReached) {
|
|
235
|
-
tracer.trace("Device was unresponsive, emitting responsive");
|
|
236
|
-
this.emit("responsive");
|
|
237
|
-
}
|
|
238
|
-
return res;
|
|
239
|
-
}
|
|
240
|
-
finally {
|
|
241
|
-
tracer.trace("Finalize, clearing busy guard");
|
|
242
|
-
clearTimeout(timeout);
|
|
243
|
-
if (resolveBusy)
|
|
244
|
-
resolveBusy();
|
|
245
|
-
this.exchangeBusyPromise = null;
|
|
246
|
-
}
|
|
247
|
-
});
|
|
274
|
+
return res;
|
|
275
|
+
}
|
|
276
|
+
finally {
|
|
277
|
+
tracer.trace("Finalize, clearing busy guard");
|
|
278
|
+
clearTimeout(timeout);
|
|
279
|
+
if (resolveBusy)
|
|
280
|
+
resolveBusy();
|
|
281
|
+
this.exchangeBusyPromise = null;
|
|
282
|
+
}
|
|
248
283
|
}
|
|
249
284
|
decorateAppAPIMethods(self, methods, scrambleKey) {
|
|
250
285
|
for (const methodName of methods) {
|
|
251
286
|
self[methodName] = this.decorateAppAPIMethod(methodName, self[methodName], self, scrambleKey);
|
|
252
287
|
}
|
|
253
288
|
}
|
|
289
|
+
_appAPIlock = null;
|
|
254
290
|
decorateAppAPIMethod(methodName, f, ctx, scrambleKey) {
|
|
255
|
-
return (...args) =>
|
|
291
|
+
return async (...args) => {
|
|
256
292
|
const { _appAPIlock } = this;
|
|
257
293
|
if (_appAPIlock) {
|
|
258
294
|
return Promise.reject(new TransportError("Ledger Device is busy (lock " + _appAPIlock + ")", "TransportLocked"));
|
|
@@ -260,12 +296,12 @@ class Transport {
|
|
|
260
296
|
try {
|
|
261
297
|
this._appAPIlock = methodName;
|
|
262
298
|
this.setScrambleKey(scrambleKey);
|
|
263
|
-
return
|
|
299
|
+
return await f.apply(ctx, args);
|
|
264
300
|
}
|
|
265
301
|
finally {
|
|
266
302
|
this._appAPIlock = null;
|
|
267
303
|
}
|
|
268
|
-
}
|
|
304
|
+
};
|
|
269
305
|
}
|
|
270
306
|
/**
|
|
271
307
|
* Sets the context used by the logging/tracing mechanism
|
|
@@ -294,8 +330,7 @@ class Transport {
|
|
|
294
330
|
getTraceContext() {
|
|
295
331
|
return this.tracer.getContext();
|
|
296
332
|
}
|
|
333
|
+
static ErrorMessage_ListenTimeout = "No Ledger device found (timeout)";
|
|
334
|
+
static ErrorMessage_NoDeviceFound = "No Ledger device found";
|
|
297
335
|
}
|
|
298
|
-
Transport.ErrorMessage_ListenTimeout = "No Ledger device found (timeout)";
|
|
299
|
-
Transport.ErrorMessage_NoDeviceFound = "No Ledger device found";
|
|
300
|
-
export default Transport;
|
|
301
336
|
//# sourceMappingURL=Transport.js.map
|
package/lib-es/Transport.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transport.js","sourceRoot":"","sources":["../src/Transport.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Transport.js","sourceRoot":"","sources":["../src/Transport.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAElC,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAyB,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC;AAElF,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAoCrC;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,eAAe,GAAG,KAAK,CAAC;IACxB,mBAAmB,GAAG,KAAK,CAAC;IAC5B,WAAW,GAAmC,IAAI,CAAC;IACnD,MAAM,CAAc;IAEpB,YAAY,EAAE,OAAO,EAAE,OAAO,KAAoD,EAAE;QAClF,IAAI,CAAC,MAAM,GAAG,IAAI,WAAW,CAAC,OAAO,IAAI,gBAAgB,EAAE,OAAO,CAAC,CAAC;IACtE,CAAC;IAED;;;OAGG;IACH,MAAM,CAAU,WAAW,CAAyB;IAEpD;;;;;;;OAOG;IACH,MAAM,CAAU,IAAI,CAA4B;IAEhD;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAU,MAAM,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": "@ledgerhq/hw-transport",
|
|
3
|
-
"version": "6.31.
|
|
3
|
+
"version": "6.31.5-next.0",
|
|
4
4
|
"description": "Ledger Hardware Wallet common interface of the communication layer",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
"license": "Apache-2.0",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"events": "^3.3.0",
|
|
29
|
-
"@ledgerhq/devices": "
|
|
30
|
-
"@ledgerhq/errors": "^6.
|
|
29
|
+
"@ledgerhq/devices": "8.4.5-next.0",
|
|
30
|
+
"@ledgerhq/errors": "^6.21.0-next.0",
|
|
31
31
|
"@ledgerhq/logs": "^6.12.0"
|
|
32
32
|
},
|
|
33
33
|
"gitHead": "dd0dea64b58e5a9125c8a422dcffd29e5ef6abec",
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/jest": "^29.5.10",
|
|
36
|
-
"@types/node": "^
|
|
36
|
+
"@types/node": "^22.10.10",
|
|
37
37
|
"documentation": "14.0.2",
|
|
38
38
|
"jest": "^29.7.0",
|
|
39
39
|
"rimraf": "^4.4.1",
|
|
@@ -43,9 +43,10 @@
|
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"clean": "rimraf lib lib-es",
|
|
46
|
-
"build": "tsc && tsc -m
|
|
46
|
+
"build": "tsc && tsc -m esnext --moduleResolution bundler --outDir lib-es",
|
|
47
47
|
"prewatch": "pnpm build",
|
|
48
48
|
"watch": "tsc --watch",
|
|
49
|
+
"watch:es": "tsc --watch -m esnext --moduleResolution bundler --outDir lib-es",
|
|
49
50
|
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
|
|
50
51
|
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
|
|
51
52
|
"lint:fix": "pnpm lint --fix",
|