@ledgerhq/react-native-hw-transport-ble 6.31.0-nightly.3 → 6.32.0-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 +1 -1
- package/CHANGELOG.md +36 -23
- package/lib/BleTransport.d.ts +67 -16
- package/lib/BleTransport.d.ts.map +1 -1
- package/lib/BleTransport.js +187 -79
- package/lib/BleTransport.js.map +1 -1
- package/lib/BleTransport.test.js +103 -15
- package/lib/BleTransport.test.js.map +1 -1
- package/lib/remapErrors.d.ts +1 -2
- package/lib/remapErrors.d.ts.map +1 -1
- package/lib/remapErrors.js.map +1 -1
- package/lib-es/BleTransport.d.ts +67 -16
- package/lib-es/BleTransport.d.ts.map +1 -1
- package/lib-es/BleTransport.js +191 -83
- package/lib-es/BleTransport.js.map +1 -1
- package/lib-es/BleTransport.test.js +104 -16
- package/lib-es/BleTransport.test.js.map +1 -1
- package/lib-es/remapErrors.d.ts +1 -2
- package/lib-es/remapErrors.d.ts.map +1 -1
- package/lib-es/remapErrors.js.map +1 -1
- package/package.json +10 -8
- package/src/BleTransport.test.ts +116 -15
- package/src/BleTransport.ts +278 -100
- package/src/remapErrors.ts +2 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
> @ledgerhq/react-native-hw-transport-ble@6.31.0
|
|
2
|
+
> @ledgerhq/react-native-hw-transport-ble@6.31.0 build /home/runner/work/ledger-live/ledger-live/libs/ledgerjs/packages/react-native-hw-transport-ble
|
|
3
3
|
> tsc && tsc -m ES6 --outDir lib-es
|
|
4
4
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
# @ledgerhq/react-native-hw-transport-ble
|
|
2
2
|
|
|
3
|
-
## 6.
|
|
3
|
+
## 6.32.0-next.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#5171](https://github.com/LedgerHQ/ledger-live/pull/5171) [`52a3732`](https://github.com/LedgerHQ/ledger-live/commit/52a373273dee3b2cb5a3e8d2d4b05f90616d71a2) Thanks [@alexandremgo](https://github.com/alexandremgo)! - Feat: new abort timeout on opening transport and APDU exchange
|
|
8
|
+
|
|
9
|
+
On `@ledgerhq/hw-transport`
|
|
10
|
+
|
|
11
|
+
- `exchange` adding an optional `abortTimeoutMs` arg to its definition
|
|
12
|
+
- `send` taking an optional `abortTimeoutMs` and passing it to `exchange`
|
|
13
|
+
- Some documentation and tracing
|
|
14
|
+
|
|
15
|
+
On `@ledgerhq/react-native-hw-transport-ble`
|
|
16
|
+
|
|
17
|
+
- `open`: enabling optional timeout when opening a transport instance
|
|
18
|
+
- `exchange`: enabling optional timeout on APDU exchange, calling `cancelPendingOperations` on timeout
|
|
19
|
+
- `cancelPendingOperations`: using a `currentTransactionIds` array of transactions id for each `write`, we can try to abort completely pending writes
|
|
20
|
+
- More documentation + tracing + simple unit tests
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
|
6
23
|
|
|
7
|
-
- Updated dependencies [[`
|
|
8
|
-
- @ledgerhq/
|
|
9
|
-
- @ledgerhq/
|
|
10
|
-
- @ledgerhq/
|
|
24
|
+
- Updated dependencies [[`52a3732`](https://github.com/LedgerHQ/ledger-live/commit/52a373273dee3b2cb5a3e8d2d4b05f90616d71a2), [`4d1aade`](https://github.com/LedgerHQ/ledger-live/commit/4d1aade53cd33f8e7548ce340f54fbb834bdcdcb), [`52a3732`](https://github.com/LedgerHQ/ledger-live/commit/52a373273dee3b2cb5a3e8d2d4b05f90616d71a2)]:
|
|
25
|
+
- @ledgerhq/hw-transport@6.30.1-next.0
|
|
26
|
+
- @ledgerhq/errors@6.16.1-next.0
|
|
27
|
+
- @ledgerhq/devices@8.2.0-next.0
|
|
11
28
|
|
|
12
|
-
## 6.31.0
|
|
29
|
+
## 6.31.0
|
|
13
30
|
|
|
14
31
|
### Minor Changes
|
|
15
32
|
|
|
@@ -17,29 +34,25 @@
|
|
|
17
34
|
|
|
18
35
|
### Patch Changes
|
|
19
36
|
|
|
20
|
-
- Updated dependencies [[`5964e30bed`](https://github.com/LedgerHQ/ledger-live/commit/5964e30bed11d64a3b7401c6ab51ffc1ad4c427c)]:
|
|
21
|
-
- @ledgerhq/
|
|
22
|
-
- @ledgerhq/
|
|
23
|
-
- @ledgerhq/
|
|
24
|
-
- @ledgerhq/logs@6.12.0
|
|
25
|
-
|
|
26
|
-
## 6.30.1-nightly.1
|
|
37
|
+
- Updated dependencies [[`771c9d3c1d`](https://github.com/LedgerHQ/ledger-live/commit/771c9d3c1d138ddd68da2e4f9738e2c41ecaf81b), [`c5981ae341`](https://github.com/LedgerHQ/ledger-live/commit/c5981ae3411abc4c8594adf2efcb52aacddac143), [`e63205b850`](https://github.com/LedgerHQ/ledger-live/commit/e63205b85071538ed2431157a12818d7a8f0ffa9), [`5964e30bed`](https://github.com/LedgerHQ/ledger-live/commit/5964e30bed11d64a3b7401c6ab51ffc1ad4c427c)]:
|
|
38
|
+
- @ledgerhq/errors@6.16.0
|
|
39
|
+
- @ledgerhq/hw-transport@6.30.0
|
|
40
|
+
- @ledgerhq/devices@8.1.0
|
|
41
|
+
- @ledgerhq/logs@6.12.0
|
|
27
42
|
|
|
28
|
-
|
|
43
|
+
## 6.31.0-next.0
|
|
29
44
|
|
|
30
|
-
|
|
31
|
-
- @ledgerhq/errors@6.16.0-nightly.1
|
|
32
|
-
- @ledgerhq/devices@8.0.9-nightly.1
|
|
33
|
-
- @ledgerhq/hw-transport@6.29.1-nightly.1
|
|
45
|
+
### Minor Changes
|
|
34
46
|
|
|
35
|
-
|
|
47
|
+
- [#5430](https://github.com/LedgerHQ/ledger-live/pull/5430) [`5964e30bed`](https://github.com/LedgerHQ/ledger-live/commit/5964e30bed11d64a3b7401c6ab51ffc1ad4c427c) Thanks [@hedi-edelbloute](https://github.com/hedi-edelbloute)! - Update documentation v14 ledgerjs
|
|
36
48
|
|
|
37
49
|
### Patch Changes
|
|
38
50
|
|
|
39
|
-
- Updated dependencies [[`e63205b850`](https://github.com/LedgerHQ/ledger-live/commit/e63205b85071538ed2431157a12818d7a8f0ffa9)]:
|
|
40
|
-
- @ledgerhq/errors@6.
|
|
41
|
-
- @ledgerhq/
|
|
42
|
-
- @ledgerhq/
|
|
51
|
+
- Updated dependencies [[`771c9d3c1d`](https://github.com/LedgerHQ/ledger-live/commit/771c9d3c1d138ddd68da2e4f9738e2c41ecaf81b), [`c5981ae341`](https://github.com/LedgerHQ/ledger-live/commit/c5981ae3411abc4c8594adf2efcb52aacddac143), [`e63205b850`](https://github.com/LedgerHQ/ledger-live/commit/e63205b85071538ed2431157a12818d7a8f0ffa9), [`5964e30bed`](https://github.com/LedgerHQ/ledger-live/commit/5964e30bed11d64a3b7401c6ab51ffc1ad4c427c)]:
|
|
52
|
+
- @ledgerhq/errors@6.16.0-next.0
|
|
53
|
+
- @ledgerhq/hw-transport@6.30.0-next.0
|
|
54
|
+
- @ledgerhq/devices@8.1.0-next.0
|
|
55
|
+
- @ledgerhq/logs@6.12.0-next.0
|
|
43
56
|
|
|
44
57
|
## 6.30.0
|
|
45
58
|
|
package/lib/BleTransport.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Subscription as TransportSubscription, Observer as TransportObserv
|
|
|
4
4
|
import { DeviceId, Device, Characteristic } from "react-native-ble-plx";
|
|
5
5
|
import type { DeviceModel } from "@ledgerhq/devices";
|
|
6
6
|
import { TraceContext } from "@ledgerhq/logs";
|
|
7
|
-
import { Observable, Observer } from "rxjs";
|
|
7
|
+
import { Observable, Observer, SchedulerLike } from "rxjs";
|
|
8
8
|
import { HwTransportError } from "@ledgerhq/errors";
|
|
9
9
|
import { ReconnectionConfig } from "./types";
|
|
10
10
|
export declare const setReconnectionConfig: (config: ReconnectionConfig | null | undefined) => void;
|
|
@@ -49,37 +49,82 @@ export default class BleTransport extends Transport {
|
|
|
49
49
|
* Opens a BLE transport
|
|
50
50
|
*
|
|
51
51
|
* @param {Device | string} deviceOrId
|
|
52
|
-
* @param timeoutMs
|
|
52
|
+
* @param timeoutMs Applied when trying to connect to a device
|
|
53
53
|
* @param context An optional context object for log/tracing strategy
|
|
54
|
+
* @param injectedDependencies Contains optional injected dependencies used by the transport implementation
|
|
55
|
+
* - rxjsScheduler: dependency injected RxJS scheduler to control time. Default AsyncScheduler.
|
|
54
56
|
*/
|
|
55
|
-
static open(deviceOrId: Device | string, timeoutMs?: number, context?: TraceContext
|
|
57
|
+
static open(deviceOrId: Device | string, timeoutMs?: number, context?: TraceContext, { rxjsScheduler }?: {
|
|
58
|
+
rxjsScheduler?: SchedulerLike;
|
|
59
|
+
}): Promise<BleTransport>;
|
|
56
60
|
/**
|
|
57
61
|
* Exposes method from the ble-plx library to disconnect a device
|
|
58
62
|
*
|
|
59
63
|
* Disconnects from {@link Device} if it's connected or cancels pending connection.
|
|
64
|
+
* A "disconnect" event will normally be emitted by the ble-plx lib once the device is disconnected.
|
|
65
|
+
* Errors are logged but silenced.
|
|
60
66
|
*/
|
|
61
|
-
static
|
|
67
|
+
static disconnectDevice: (id: DeviceId, context?: TraceContext) => Promise<void>;
|
|
62
68
|
device: Device;
|
|
63
69
|
deviceModel: DeviceModel;
|
|
64
70
|
disconnectTimeout: null | ReturnType<typeof setTimeout>;
|
|
65
71
|
id: string;
|
|
66
72
|
isConnected: boolean;
|
|
67
73
|
mtuSize: number;
|
|
68
|
-
notifyObservable: Observable<
|
|
74
|
+
notifyObservable: Observable<Buffer | Error>;
|
|
69
75
|
notYetDisconnected: boolean;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
76
|
+
writableWithResponseCharacteristic: Characteristic;
|
|
77
|
+
writableWithoutResponseCharacteristic: Characteristic | undefined;
|
|
78
|
+
rxjsScheduler?: SchedulerLike;
|
|
79
|
+
currentTransactionIds: Array<string>;
|
|
80
|
+
/**
|
|
81
|
+
* The static `open` function is used to handle BleTransport instantiation
|
|
82
|
+
*
|
|
83
|
+
* @param device
|
|
84
|
+
* @param writableWithResponseCharacteristic A BLE characteristic that we can write on,
|
|
85
|
+
* and that will be acknowledged in response from the device when it receives the written value.
|
|
86
|
+
* @param writableWithoutResponseCharacteristic A BLE characteristic that we can write on,
|
|
87
|
+
* and that will not be acknowledged in response from the device
|
|
88
|
+
* @param notifyObservable A multicast observable that emits messages received from the device
|
|
89
|
+
* @param deviceModel
|
|
90
|
+
* @param params Contains optional options and injected dependencies used by the transport implementation
|
|
91
|
+
* - abortTimeoutMs: stop the exchange after a given timeout. Another timeout exists
|
|
92
|
+
* to detect unresponsive device (see `unresponsiveTimeout`). This timeout aborts the exchange.
|
|
93
|
+
* - rxjsScheduler: dependency injected RxJS scheduler to control time. Default: AsyncScheduler.
|
|
94
|
+
*/
|
|
95
|
+
constructor(device: Device, writableWithResponseCharacteristic: Characteristic, writableWithoutResponseCharacteristic: Characteristic | undefined, notifyObservable: Observable<Buffer | Error>, deviceModel: DeviceModel, { context, rxjsScheduler }?: {
|
|
73
96
|
context?: TraceContext;
|
|
97
|
+
rxjsScheduler?: SchedulerLike;
|
|
74
98
|
});
|
|
75
99
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
100
|
+
* A message exchange (APDU request <-> response) with the device that can be aborted
|
|
101
|
+
*
|
|
102
|
+
* The message will be BLE-encoded/framed before being sent, and the response will be BLE-decoded.
|
|
103
|
+
*
|
|
104
|
+
* @param message A buffer (u8 array) of a none BLE-encoded message (an APDU for ex) to be sent to the device
|
|
105
|
+
* as a request
|
|
106
|
+
* @param options Contains optional options for the exchange function
|
|
107
|
+
* - abortTimeoutMs: stop the exchange after a given timeout. Another timeout exists
|
|
108
|
+
* to detect unresponsive device (see `unresponsiveTimeout`). This timeout aborts the exchange.
|
|
109
|
+
* @returns A promise that resolves with the response data from the device.
|
|
110
|
+
*/
|
|
111
|
+
exchange: (message: Buffer, { abortTimeoutMs }?: {
|
|
112
|
+
abortTimeoutMs?: number | undefined;
|
|
113
|
+
}) => Promise<Buffer>;
|
|
114
|
+
/**
|
|
115
|
+
* Tries to cancel all operations that have a recorded transaction and are pending
|
|
116
|
+
*
|
|
117
|
+
* Cancelling transaction which doesn't exist is ignored.
|
|
78
118
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
119
|
+
* Note: cancelling `writableWithoutResponseCharacteristic.write...` will throw a `BleError` with code `OperationCancelled`
|
|
120
|
+
* but this error should be ignored. (In `exchange` our observable is unsubscribed before `cancelPendingOperations`
|
|
121
|
+
* is called so the error is ignored)
|
|
122
|
+
*/
|
|
123
|
+
private cancelPendingOperations;
|
|
124
|
+
/**
|
|
125
|
+
* Sets the collection of current transaction ids to an empty array
|
|
81
126
|
*/
|
|
82
|
-
|
|
127
|
+
private clearCurrentTransactionIds;
|
|
83
128
|
/**
|
|
84
129
|
* Negotiate with the device the maximum transfer unit for the ble frames
|
|
85
130
|
* @returns Promise<number>
|
|
@@ -95,10 +140,16 @@ export default class BleTransport extends Transport {
|
|
|
95
140
|
/**
|
|
96
141
|
* Do not call this directly unless you know what you're doing. Communication
|
|
97
142
|
* with a Ledger device should be through the {@link exchange} method.
|
|
98
|
-
*
|
|
99
|
-
*
|
|
143
|
+
*
|
|
144
|
+
* For each call a transaction id is added to the current stack of transaction ids.
|
|
145
|
+
* With this transaction id, a pending BLE communication operations can be cancelled.
|
|
146
|
+
* Note: each frame/packet of a longer BLE-encoded message to be sent should have their unique transaction id.
|
|
147
|
+
*
|
|
148
|
+
* @param buffer BLE-encoded packet to send to the device
|
|
149
|
+
* @param frameId Frame id to make `write` aware of a bigger message that this frame/packet is part of.
|
|
150
|
+
* Helps creating related a collection of transaction ids
|
|
100
151
|
*/
|
|
101
|
-
write: (buffer: Buffer
|
|
152
|
+
write: (buffer: Buffer) => Promise<void>;
|
|
102
153
|
/**
|
|
103
154
|
* We intentionally do not immediately close a transport connection.
|
|
104
155
|
* Instead, we queue the disconnect and wait for a future connection to dismiss the event.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BleTransport.d.ts","sourceRoot":"","sources":["../src/BleTransport.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"BleTransport.d.ts","sourceRoot":"","sources":["../src/BleTransport.ts"],"names":[],"mappings":";AACA,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,EACV,YAAY,IAAI,qBAAqB,EACrC,QAAQ,IAAI,iBAAiB,EAC9B,MAAM,wBAAwB,CAAC;AAWhC,OAAO,EAKL,QAAQ,EACR,MAAM,EACN,cAAc,EAGf,MAAM,sBAAsB,CAAC;AAO9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAsB,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EACL,UAAU,EAMV,QAAQ,EAGR,aAAa,EACd,MAAM,MAAM,CAAC;AAWd,OAAO,EAML,gBAAgB,EAEjB,MAAM,kBAAkB,CAAC;AAS1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAa7C,eAAO,MAAM,qBAAqB,WAAY,kBAAkB,GAAG,IAAI,GAAG,SAAS,KAAG,IAErF,CAAC;AAwWF;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,SAAS;IACjD,MAAM,CAAC,mBAAmB,SAAQ;IAClC;;OAEG;IACH,MAAM,CAAC,WAAW,QAAO,QAAQ,OAAO,CAAC,CAAsD;IAE/F;;OAEG;IACH,MAAM,CAAC,IAAI,QAAO,QAAQ,IAAI,EAAE,CAAC,CAE/B;IAEF;;;;OAIG;IACH,MAAM,CAAC,WAAW,aAAc,MAAM,KAAG,IAAI,CAM3C;IAEF;;;;;OAKG;IACH,MAAM,CAAC,YAAY,CACjB,QAAQ,EAAE,QAAQ,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,OAAO,CAAC;KACpB,CAAC,GACD,qBAAqB;IAexB;;;;OAIG;IACH,MAAM,CAAC,MAAM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