@ledgerhq/react-native-hw-transport-ble 6.31.0 → 6.32.0-nightly.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 +26 -0
- package/LICENSE.txt +21 -0
- 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 +6 -4
- package/src/BleTransport.test.ts +116 -15
- package/src/BleTransport.ts +278 -100
- package/src/remapErrors.ts +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @ledgerhq/react-native-hw-transport-ble
|
|
2
2
|
|
|
3
|
+
## 6.32.0-nightly.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#5171](https://github.com/LedgerHQ/ledger-live/pull/5171) [`52a373273d`](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
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Updated dependencies [[`52a373273d`](https://github.com/LedgerHQ/ledger-live/commit/52a373273dee3b2cb5a3e8d2d4b05f90616d71a2), [`52a373273d`](https://github.com/LedgerHQ/ledger-live/commit/52a373273dee3b2cb5a3e8d2d4b05f90616d71a2)]:
|
|
25
|
+
- @ledgerhq/hw-transport@6.30.1-nightly.0
|
|
26
|
+
- @ledgerhq/errors@6.16.1-nightly.0
|
|
27
|
+
- @ledgerhq/devices@8.2.0-nightly.0
|
|
28
|
+
|
|
3
29
|
## 6.31.0
|
|
4
30
|
|
|
5
31
|
### Minor Changes
|
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-present Ledger https://www.ledger.com/
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
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,OAA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