@ledgerhq/hw-transport 6.28.4 → 6.28.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/CHANGELOG.md +8 -0
- package/lib/Transport.d.ts +1 -1
- package/lib/Transport.d.ts.map +1 -1
- package/lib/Transport.js +6 -10
- package/lib/Transport.js.map +1 -1
- package/lib-es/Transport.d.ts +1 -1
- package/lib-es/Transport.d.ts.map +1 -1
- package/lib-es/Transport.js +7 -11
- package/lib-es/Transport.js.map +1 -1
- package/package.json +4 -4
- package/src/Transport.ts +21 -62
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @ledgerhq/hw-transport
|
|
2
2
|
|
|
3
|
+
## 6.28.5-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`9adc1862dd`](https://github.com/LedgerHQ/ledger-live/commit/9adc1862dda605a722d19f3b6895bd324834c914)]:
|
|
8
|
+
- @ledgerhq/errors@6.12.7-next.0
|
|
9
|
+
- @ledgerhq/devices@8.0.4-next.0
|
|
10
|
+
|
|
3
11
|
## 6.28.4
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/lib/Transport.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import EventEmitter from "events";
|
|
4
4
|
import type { DeviceModel } from "@ledgerhq/devices";
|
|
5
5
|
import { TransportError, StatusCodes, getAltStatusMessage, TransportStatusError } from "@ledgerhq/errors";
|
|
6
|
-
export { TransportError, TransportStatusError, StatusCodes, getAltStatusMessage
|
|
6
|
+
export { TransportError, TransportStatusError, StatusCodes, getAltStatusMessage };
|
|
7
7
|
/**
|
|
8
8
|
*/
|
|
9
9
|
export type Subscription = {
|
package/lib/Transport.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transport.d.ts","sourceRoot":"","sources":["../src/Transport.ts"],"names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,MAAM,CAAC,0BAA0B,SAA4B;CAC9D"}
|
package/lib/Transport.js
CHANGED
|
@@ -44,13 +44,9 @@ class Transport {
|
|
|
44
44
|
if (data.length >= 256) {
|
|
45
45
|
throw new errors_1.TransportError("data.length exceed 256 bytes limit. Got: " + data.length, "DataLengthTooBig");
|
|
46
46
|
}
|
|
47
|
-
const response = yield this.exchange(Buffer.concat([
|
|
48
|
-
Buffer.from([cla, ins, p1, p2]),
|
|
49
|
-
Buffer.from([data.length]),
|
|
50
|
-
data,
|
|
51
|
-
]));
|
|
47
|
+
const response = yield this.exchange(Buffer.concat([Buffer.from([cla, ins, p1, p2]), Buffer.from([data.length]), data]));
|
|
52
48
|
const sw = response.readUInt16BE(response.length - 2);
|
|
53
|
-
if (!statusList.some(
|
|
49
|
+
if (!statusList.some(s => s === sw)) {
|
|
54
50
|
throw new errors_1.TransportStatusError(sw);
|
|
55
51
|
}
|
|
56
52
|
return response;
|
|
@@ -60,7 +56,7 @@ class Transport {
|
|
|
60
56
|
throw new errors_1.TransportRaceCondition("An action was already pending on the Ledger device. Please deny or reconnect.");
|
|
61
57
|
}
|
|
62
58
|
let resolveBusy;
|
|
63
|
-
const busyPromise = new Promise(
|
|
59
|
+
const busyPromise = new Promise(r => {
|
|
64
60
|
resolveBusy = r;
|
|
65
61
|
});
|
|
66
62
|
this.exchangeBusyPromise = busyPromise;
|
|
@@ -120,7 +116,7 @@ class Transport {
|
|
|
120
116
|
observer.next(r);
|
|
121
117
|
}
|
|
122
118
|
});
|
|
123
|
-
main().then(() => !unsubscribed && observer.complete(),
|
|
119
|
+
main().then(() => !unsubscribed && observer.complete(), e => !unsubscribed && observer.error(e));
|
|
124
120
|
return { unsubscribe };
|
|
125
121
|
}
|
|
126
122
|
/**
|
|
@@ -185,7 +181,7 @@ class Transport {
|
|
|
185
181
|
return new Promise((resolve, reject) => {
|
|
186
182
|
let found = false;
|
|
187
183
|
const sub = this.listen({
|
|
188
|
-
next:
|
|
184
|
+
next: e => {
|
|
189
185
|
found = true;
|
|
190
186
|
if (sub)
|
|
191
187
|
sub.unsubscribe();
|
|
@@ -193,7 +189,7 @@ class Transport {
|
|
|
193
189
|
clearTimeout(listenTimeoutId);
|
|
194
190
|
this.open(e.descriptor, openTimeout).then(resolve, reject);
|
|
195
191
|
},
|
|
196
|
-
error:
|
|
192
|
+
error: e => {
|
|
197
193
|
if (listenTimeoutId)
|
|
198
194
|
clearTimeout(listenTimeoutId);
|
|
199
195
|
reject(e);
|
package/lib/Transport.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transport.js","sourceRoot":"","sources":["../src/Transport.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAAkC;AAElC,6CAM0B;
|
|
1
|
+
{"version":3,"file":"Transport.js","sourceRoot":"","sources":["../src/Transport.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAAkC;AAElC,6CAM0B;AACjB,+FALP,uBAAc,OAKO;AAAwB,4FAJ7C,oBAAW,OAI6C;AAAE,oGAH1D,4BAAmB,OAG0D;AAAtD,qGAFvB,6BAAoB,OAEuB;AAoC7C;;;;GAIG;AACH,MAAqB,SAAS;IAA9B;QACE,oBAAe,GAAG,KAAK,CAAC;QACxB,wBAAmB,GAAG,KAAK,CAAC;QAC5B,gBAAW,GAAmC,IAAI,CAAC;QA6GnD,YAAO,GAAG,IAAI,gBAAY,EAAE,CAAC;QA+C7B;;;;;;;;;WASG;QACH,SAAI,GAAG,CACL,GAAW,EACX,GAAW,EACX,EAAU,EACV,EAAU,EACV,OAAe,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAC9B,aAA4B,CAAC,oBAAW,CAAC,EAAE,CAAC,EAC3B,EAAE;YACnB,IAAI,IAAI,CAAC,MAAM,IAAI,GAAG,EAAE;gBACtB,MAAM,IAAI,uBAAc,CACtB,2CAA2C,GAAG,IAAI,CAAC,MAAM,EACzD,kBAAkB,CACnB,CAAC;aACH;YAED,MAAM,QAA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WAAW,EAAE,GAAG,IAAI,CAAC;YAE7B,IAAI,WAAW,EAAE;gBACf,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,uBAAc,CAAC,8BAA8B,GAAG,WAAW,GAAG,GAAG,EAAE,iBAAiB,CAAC,CAC1F,CAAC;aACH;YAED,IAAI;gBACF,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;gBAC9B,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;gBACjC,OAAO,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;aACjC;oBAAS;gBACR,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;aACzB;QACH,CAAC,CAAA,CAAC;IACJ,CAAC;;AA3SH,4BA+SC;AAFQ,oCAA0B,GAAG,kCAAkC,CAAC;AAChE,oCAA0B,GAAG,wBAAwB,CAAC"}
|
package/lib-es/Transport.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import EventEmitter from "events";
|
|
4
4
|
import type { DeviceModel } from "@ledgerhq/devices";
|
|
5
5
|
import { TransportError, StatusCodes, getAltStatusMessage, TransportStatusError } from "@ledgerhq/errors";
|
|
6
|
-
export { TransportError, TransportStatusError, StatusCodes, getAltStatusMessage
|
|
6
|
+
export { TransportError, TransportStatusError, StatusCodes, getAltStatusMessage };
|
|
7
7
|
/**
|
|
8
8
|
*/
|
|
9
9
|
export type Subscription = {
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
1
|
+
{"version":3,"file":"Transport.d.ts","sourceRoot":"","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,CAAC,mBAAmB,EAAE,MAAM,GAAG,IAAI;IAIjE;;;;;;;;;OASG;IACH,IAAI,QACG,MAAM,OACN,MAAM,MACP,MAAM,MACN,MAAM,SACJ,MAAM,eACA,MAAM,MAAM,CAAC,KACxB,QAAQ,MAAM,CAAC,CAkBhB;IAEF;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,CAAC,WAAW,SAAO,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IA+B7E,mBAAmB,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACtD,kBAAkB,MAAa,MAAM,QAAQ,MAAM,GAAG,IAAI,CAAC,KAAG,QAAQ,MAAM,GAAG,IAAI,CAAC,CA+BlF;IAEF,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,MAAM,CAAC,0BAA0B,SAAsC;IACvE,MAAM,CAAC,0BAA0B,SAA4B;CAC9D"}
|
package/lib-es/Transport.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import EventEmitter from "events";
|
|
11
11
|
import { TransportRaceCondition, TransportError, StatusCodes, getAltStatusMessage, TransportStatusError, } from "@ledgerhq/errors";
|
|
12
|
-
export { TransportError, TransportStatusError, StatusCodes, getAltStatusMessage
|
|
12
|
+
export { TransportError, TransportStatusError, StatusCodes, getAltStatusMessage };
|
|
13
13
|
/**
|
|
14
14
|
* The Transport class defines a generic interface for communicating with a Ledger hardware wallet.
|
|
15
15
|
* There are different kind of transports based on the technology (channels like U2F, HID, Bluetooth, Webusb) and environment (Node, Web,...).
|
|
@@ -35,13 +35,9 @@ export default class Transport {
|
|
|
35
35
|
if (data.length >= 256) {
|
|
36
36
|
throw new TransportError("data.length exceed 256 bytes limit. Got: " + data.length, "DataLengthTooBig");
|
|
37
37
|
}
|
|
38
|
-
const response = yield this.exchange(Buffer.concat([
|
|
39
|
-
Buffer.from([cla, ins, p1, p2]),
|
|
40
|
-
Buffer.from([data.length]),
|
|
41
|
-
data,
|
|
42
|
-
]));
|
|
38
|
+
const response = yield this.exchange(Buffer.concat([Buffer.from([cla, ins, p1, p2]), Buffer.from([data.length]), data]));
|
|
43
39
|
const sw = response.readUInt16BE(response.length - 2);
|
|
44
|
-
if (!statusList.some(
|
|
40
|
+
if (!statusList.some(s => s === sw)) {
|
|
45
41
|
throw new TransportStatusError(sw);
|
|
46
42
|
}
|
|
47
43
|
return response;
|
|
@@ -51,7 +47,7 @@ export default class Transport {
|
|
|
51
47
|
throw new TransportRaceCondition("An action was already pending on the Ledger device. Please deny or reconnect.");
|
|
52
48
|
}
|
|
53
49
|
let resolveBusy;
|
|
54
|
-
const busyPromise = new Promise(
|
|
50
|
+
const busyPromise = new Promise(r => {
|
|
55
51
|
resolveBusy = r;
|
|
56
52
|
});
|
|
57
53
|
this.exchangeBusyPromise = busyPromise;
|
|
@@ -111,7 +107,7 @@ export default class Transport {
|
|
|
111
107
|
observer.next(r);
|
|
112
108
|
}
|
|
113
109
|
});
|
|
114
|
-
main().then(() => !unsubscribed && observer.complete(),
|
|
110
|
+
main().then(() => !unsubscribed && observer.complete(), e => !unsubscribed && observer.error(e));
|
|
115
111
|
return { unsubscribe };
|
|
116
112
|
}
|
|
117
113
|
/**
|
|
@@ -176,7 +172,7 @@ export default class Transport {
|
|
|
176
172
|
return new Promise((resolve, reject) => {
|
|
177
173
|
let found = false;
|
|
178
174
|
const sub = this.listen({
|
|
179
|
-
next:
|
|
175
|
+
next: e => {
|
|
180
176
|
found = true;
|
|
181
177
|
if (sub)
|
|
182
178
|
sub.unsubscribe();
|
|
@@ -184,7 +180,7 @@ export default class Transport {
|
|
|
184
180
|
clearTimeout(listenTimeoutId);
|
|
185
181
|
this.open(e.descriptor, openTimeout).then(resolve, reject);
|
|
186
182
|
},
|
|
187
|
-
error:
|
|
183
|
+
error: e => {
|
|
188
184
|
if (listenTimeoutId)
|
|
189
185
|
clearTimeout(listenTimeoutId);
|
|
190
186
|
reject(e);
|
package/lib-es/Transport.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,cAAc,EAAE,oBAAoB,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC;AAoClF;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS;IAA9B;QACE,oBAAe,GAAG,KAAK,CAAC;QACxB,wBAAmB,GAAG,KAAK,CAAC;QAC5B,gBAAW,GAAmC,IAAI,CAAC;QA6GnD,YAAO,GAAG,IA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CAAC,IAAyB,EAAE,OAAsB,EAAE,WAAmB;QAC1F,KAAK,MAAM,UAAU,IAAI,OAAO,EAAE;YAChC,IAAI,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,oBAAoB,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;SAC/F;IACH,CAAC;IAID,oBAAoB,CAClB,UAAkB,EAClB,CAA6B,EAC7B,GAAQ,EACR,WAAmB;QAEnB,OAAO,CAAO,GAAG,IAAI,EAAE,EAAE;YACvB,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;YAE7B,IAAI,WAAW,EAAE;gBACf,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,cAAc,CAAC,8BAA8B,GAAG,WAAW,GAAG,GAAG,EAAE,iBAAiB,CAAC,CAC1F,CAAC;aACH;YAED,IAAI;gBACF,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;gBAC9B,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;gBACjC,OAAO,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;aACjC;oBAAS;gBACR,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;aACzB;QACH,CAAC,CAAA,CAAC;IACJ,CAAC;;AAEM,oCAA0B,GAAG,kCAAkC,CAAC;AAChE,oCAA0B,GAAG,wBAAwB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/hw-transport",
|
|
3
|
-
"version": "6.28.
|
|
3
|
+
"version": "6.28.5-next.0",
|
|
4
4
|
"description": "Ledger Hardware Wallet common interface of the communication layer",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"license": "Apache-2.0",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"events": "^3.3.0",
|
|
29
|
-
"@ledgerhq/devices": "^8.0.
|
|
30
|
-
"@ledgerhq/errors": "^6.12.
|
|
29
|
+
"@ledgerhq/devices": "^8.0.4-next.0",
|
|
30
|
+
"@ledgerhq/errors": "^6.12.7-next.0"
|
|
31
31
|
},
|
|
32
32
|
"gitHead": "dd0dea64b58e5a9125c8a422dcffd29e5ef6abec",
|
|
33
33
|
"devDependencies": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"prewatch": "pnpm build",
|
|
47
47
|
"watch": "tsc --watch",
|
|
48
48
|
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
|
|
49
|
-
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx",
|
|
49
|
+
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
|
|
50
50
|
"lint:fix": "pnpm lint --fix",
|
|
51
51
|
"test": "jest"
|
|
52
52
|
}
|
package/src/Transport.ts
CHANGED
|
@@ -7,12 +7,7 @@ import {
|
|
|
7
7
|
getAltStatusMessage,
|
|
8
8
|
TransportStatusError,
|
|
9
9
|
} from "@ledgerhq/errors";
|
|
10
|
-
export {
|
|
11
|
-
TransportError,
|
|
12
|
-
TransportStatusError,
|
|
13
|
-
StatusCodes,
|
|
14
|
-
getAltStatusMessage,
|
|
15
|
-
};
|
|
10
|
+
export { TransportError, TransportStatusError, StatusCodes, getAltStatusMessage };
|
|
16
11
|
|
|
17
12
|
/**
|
|
18
13
|
*/
|
|
@@ -93,9 +88,7 @@ export default class Transport {
|
|
|
93
88
|
complete: () => {}
|
|
94
89
|
})
|
|
95
90
|
*/
|
|
96
|
-
static readonly listen: (
|
|
97
|
-
observer: Observer<DescriptorEvent<any>>
|
|
98
|
-
) => Subscription;
|
|
91
|
+
static readonly listen: (observer: Observer<DescriptorEvent<any>>) => Subscription;
|
|
99
92
|
|
|
100
93
|
/**
|
|
101
94
|
* Attempt to create a Transport instance with a specific descriptor.
|
|
@@ -105,10 +98,7 @@ export default class Transport {
|
|
|
105
98
|
* @example
|
|
106
99
|
TransportFoo.open(descriptor).then(transport => ...)
|
|
107
100
|
*/
|
|
108
|
-
static readonly open: (
|
|
109
|
-
descriptor?: any,
|
|
110
|
-
timeout?: number
|
|
111
|
-
) => Promise<Transport>;
|
|
101
|
+
static readonly open: (descriptor?: any, timeout?: number) => Promise<Transport>;
|
|
112
102
|
|
|
113
103
|
/**
|
|
114
104
|
* Send data to the device using a low level API.
|
|
@@ -148,7 +138,7 @@ export default class Transport {
|
|
|
148
138
|
|
|
149
139
|
main().then(
|
|
150
140
|
() => !unsubscribed && observer.complete(),
|
|
151
|
-
|
|
141
|
+
e => !unsubscribed && observer.error(e),
|
|
152
142
|
);
|
|
153
143
|
|
|
154
144
|
return { unsubscribe };
|
|
@@ -199,7 +189,7 @@ export default class Transport {
|
|
|
199
189
|
*/
|
|
200
190
|
setDebugMode() {
|
|
201
191
|
console.warn(
|
|
202
|
-
"setDebugMode is deprecated. use @ledgerhq/logs instead. No logs are emitted in this anymore."
|
|
192
|
+
"setDebugMode is deprecated. use @ledgerhq/logs instead. No logs are emitted in this anymore.",
|
|
203
193
|
);
|
|
204
194
|
}
|
|
205
195
|
|
|
@@ -233,25 +223,21 @@ export default class Transport {
|
|
|
233
223
|
p1: number,
|
|
234
224
|
p2: number,
|
|
235
225
|
data: Buffer = Buffer.alloc(0),
|
|
236
|
-
statusList: Array<number> = [StatusCodes.OK]
|
|
226
|
+
statusList: Array<number> = [StatusCodes.OK],
|
|
237
227
|
): Promise<Buffer> => {
|
|
238
228
|
if (data.length >= 256) {
|
|
239
229
|
throw new TransportError(
|
|
240
230
|
"data.length exceed 256 bytes limit. Got: " + data.length,
|
|
241
|
-
"DataLengthTooBig"
|
|
231
|
+
"DataLengthTooBig",
|
|
242
232
|
);
|
|
243
233
|
}
|
|
244
234
|
|
|
245
235
|
const response = await this.exchange(
|
|
246
|
-
Buffer.concat([
|
|
247
|
-
Buffer.from([cla, ins, p1, p2]),
|
|
248
|
-
Buffer.from([data.length]),
|
|
249
|
-
data,
|
|
250
|
-
])
|
|
236
|
+
Buffer.concat([Buffer.from([cla, ins, p1, p2]), Buffer.from([data.length]), data]),
|
|
251
237
|
);
|
|
252
238
|
const sw = response.readUInt16BE(response.length - 2);
|
|
253
239
|
|
|
254
|
-
if (!statusList.some(
|
|
240
|
+
if (!statusList.some(s => s === sw)) {
|
|
255
241
|
throw new TransportStatusError(sw);
|
|
256
242
|
}
|
|
257
243
|
|
|
@@ -265,20 +251,17 @@ export default class Transport {
|
|
|
265
251
|
* @example
|
|
266
252
|
TransportFoo.create().then(transport => ...)
|
|
267
253
|
*/
|
|
268
|
-
static create(
|
|
269
|
-
openTimeout = 3000,
|
|
270
|
-
listenTimeout?: number
|
|
271
|
-
): Promise<Transport> {
|
|
254
|
+
static create(openTimeout = 3000, listenTimeout?: number): Promise<Transport> {
|
|
272
255
|
return new Promise((resolve, reject) => {
|
|
273
256
|
let found = false;
|
|
274
257
|
const sub = this.listen({
|
|
275
|
-
next:
|
|
258
|
+
next: e => {
|
|
276
259
|
found = true;
|
|
277
260
|
if (sub) sub.unsubscribe();
|
|
278
261
|
if (listenTimeoutId) clearTimeout(listenTimeoutId);
|
|
279
262
|
this.open(e.descriptor, openTimeout).then(resolve, reject);
|
|
280
263
|
},
|
|
281
|
-
error:
|
|
264
|
+
error: e => {
|
|
282
265
|
if (listenTimeoutId) clearTimeout(listenTimeoutId);
|
|
283
266
|
reject(e);
|
|
284
267
|
},
|
|
@@ -286,41 +269,29 @@ export default class Transport {
|
|
|
286
269
|
if (listenTimeoutId) clearTimeout(listenTimeoutId);
|
|
287
270
|
|
|
288
271
|
if (!found) {
|
|
289
|
-
reject(
|
|
290
|
-
new TransportError(
|
|
291
|
-
this.ErrorMessage_NoDeviceFound,
|
|
292
|
-
"NoDeviceFound"
|
|
293
|
-
)
|
|
294
|
-
);
|
|
272
|
+
reject(new TransportError(this.ErrorMessage_NoDeviceFound, "NoDeviceFound"));
|
|
295
273
|
}
|
|
296
274
|
},
|
|
297
275
|
});
|
|
298
276
|
const listenTimeoutId = listenTimeout
|
|
299
277
|
? setTimeout(() => {
|
|
300
278
|
sub.unsubscribe();
|
|
301
|
-
reject(
|
|
302
|
-
new TransportError(
|
|
303
|
-
this.ErrorMessage_ListenTimeout,
|
|
304
|
-
"ListenTimeout"
|
|
305
|
-
)
|
|
306
|
-
);
|
|
279
|
+
reject(new TransportError(this.ErrorMessage_ListenTimeout, "ListenTimeout"));
|
|
307
280
|
}, listenTimeout)
|
|
308
281
|
: null;
|
|
309
282
|
});
|
|
310
283
|
}
|
|
311
284
|
|
|
312
285
|
exchangeBusyPromise: Promise<void> | null | undefined;
|
|
313
|
-
exchangeAtomicImpl = async (
|
|
314
|
-
f: () => Promise<Buffer | void>
|
|
315
|
-
): Promise<Buffer | void> => {
|
|
286
|
+
exchangeAtomicImpl = async (f: () => Promise<Buffer | void>): Promise<Buffer | void> => {
|
|
316
287
|
if (this.exchangeBusyPromise) {
|
|
317
288
|
throw new TransportRaceCondition(
|
|
318
|
-
"An action was already pending on the Ledger device. Please deny or reconnect."
|
|
289
|
+
"An action was already pending on the Ledger device. Please deny or reconnect.",
|
|
319
290
|
);
|
|
320
291
|
}
|
|
321
292
|
|
|
322
293
|
let resolveBusy;
|
|
323
|
-
const busyPromise: Promise<void> = new Promise(
|
|
294
|
+
const busyPromise: Promise<void> = new Promise(r => {
|
|
324
295
|
resolveBusy = r;
|
|
325
296
|
});
|
|
326
297
|
this.exchangeBusyPromise = busyPromise;
|
|
@@ -345,18 +316,9 @@ export default class Transport {
|
|
|
345
316
|
}
|
|
346
317
|
};
|
|
347
318
|
|
|
348
|
-
decorateAppAPIMethods(
|
|
349
|
-
self: Record<string, any>,
|
|
350
|
-
methods: Array<string>,
|
|
351
|
-
scrambleKey: string
|
|
352
|
-
) {
|
|
319
|
+
decorateAppAPIMethods(self: Record<string, any>, methods: Array<string>, scrambleKey: string) {
|
|
353
320
|
for (const methodName of methods) {
|
|
354
|
-
self[methodName] = this.decorateAppAPIMethod(
|
|
355
|
-
methodName,
|
|
356
|
-
self[methodName],
|
|
357
|
-
self,
|
|
358
|
-
scrambleKey
|
|
359
|
-
);
|
|
321
|
+
self[methodName] = this.decorateAppAPIMethod(methodName, self[methodName], self, scrambleKey);
|
|
360
322
|
}
|
|
361
323
|
}
|
|
362
324
|
|
|
@@ -366,17 +328,14 @@ export default class Transport {
|
|
|
366
328
|
methodName: string,
|
|
367
329
|
f: (...args: A) => Promise<R>,
|
|
368
330
|
ctx: any,
|
|
369
|
-
scrambleKey: string
|
|
331
|
+
scrambleKey: string,
|
|
370
332
|
): (...args: A) => Promise<R> {
|
|
371
333
|
return async (...args) => {
|
|
372
334
|
const { _appAPIlock } = this;
|
|
373
335
|
|
|
374
336
|
if (_appAPIlock) {
|
|
375
337
|
return Promise.reject(
|
|
376
|
-
new TransportError(
|
|
377
|
-
"Ledger Device is busy (lock " + _appAPIlock + ")",
|
|
378
|
-
"TransportLocked"
|
|
379
|
-
)
|
|
338
|
+
new TransportError("Ledger Device is busy (lock " + _appAPIlock + ")", "TransportLocked"),
|
|
380
339
|
);
|
|
381
340
|
}
|
|
382
341
|
|