@ledgerhq/react-native-hw-transport-ble 6.15.0 → 6.25.1-alpha.3
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/.yalc/@ledgerhq/hw-transport/flow-typed/npm/@ledgerhq/devices_vx.x.x.js +60 -0
- package/.yalc/@ledgerhq/hw-transport/flow-typed/npm/events_vx.x.x.js +186 -0
- package/.yalc/@ledgerhq/hw-transport/flow-typed/npm/flow-bin_v0.x.x.js +6 -0
- package/.yalc/@ledgerhq/hw-transport/flow-typed/npm/flow-typed_vx.x.x.js +193 -0
- package/lib/BleTransport.d.ts +2 -1
- package/lib/BleTransport.d.ts.map +1 -1
- package/lib/BleTransport.js +43 -22
- package/lib/BleTransport.js.map +1 -1
- package/lib/awaitsBleOn.js +1 -1
- package/lib/awaitsBleOn.js.map +1 -1
- package/lib-es/BleTransport.d.ts +2 -1
- package/lib-es/BleTransport.d.ts.map +1 -1
- package/lib-es/BleTransport.js +43 -22
- package/lib-es/BleTransport.js.flow +483 -0
- package/lib-es/BleTransport.js.map +1 -1
- package/lib-es/awaitsBleOn.js +1 -1
- package/lib-es/awaitsBleOn.js.flow +33 -0
- package/lib-es/awaitsBleOn.js.map +1 -1
- package/lib-es/monitorCharacteristic.js.flow +41 -0
- package/lib-es/remapErrors.js.flow +20 -0
- package/lib-es/timer.js.flow +27 -0
- package/lib-es/types.js.flow +4 -0
- package/package.json +4 -4
- package/src/BleTransport.ts +36 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/react-native-hw-transport-ble",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.25.1-alpha.3+eb669e17",
|
|
4
4
|
"description": "Ledger Hardware Wallet Bluetooth BLE transport for React Native",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"types": "lib/BleTransport.d.ts",
|
|
26
26
|
"license": "Apache-2.0",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@ledgerhq/devices": "^6.
|
|
28
|
+
"@ledgerhq/devices": "^6.24.1",
|
|
29
29
|
"@ledgerhq/errors": "^6.10.0",
|
|
30
|
-
"@ledgerhq/hw-transport": "^6.
|
|
30
|
+
"@ledgerhq/hw-transport": "^6.25.1-alpha.3+eb669e17",
|
|
31
31
|
"@ledgerhq/logs": "^6.10.0",
|
|
32
32
|
"invariant": "^2.2.4",
|
|
33
33
|
"react-native-ble-plx": "2.0.3",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"build": "bash ../../script/build.sh",
|
|
40
40
|
"watch": "bash ../../script/watch.sh"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "eb669e17dd87d3ab568beab1f9a5ddb1a2536e83"
|
|
43
43
|
}
|
package/src/BleTransport.ts
CHANGED
|
@@ -26,6 +26,7 @@ import { awaitsBleOn } from "./awaitsBleOn";
|
|
|
26
26
|
import { decoratePromiseErrors, remapError } from "./remapErrors";
|
|
27
27
|
let connectOptions: Record<string, unknown> = {
|
|
28
28
|
requestMTU: 156,
|
|
29
|
+
connectionPriority: 1,
|
|
29
30
|
};
|
|
30
31
|
const transportsCache = {};
|
|
31
32
|
const bleManager = new BleManager();
|
|
@@ -147,7 +148,7 @@ async function open(deviceOrId: Device | string, needsReconnect: boolean) {
|
|
|
147
148
|
throw new TransportError("service not found", "BLEServiceNotFound");
|
|
148
149
|
}
|
|
149
150
|
|
|
150
|
-
const { deviceModel, serviceUuid, writeUuid, notifyUuid } = res;
|
|
151
|
+
const { deviceModel, serviceUuid, writeUuid, writeCmdUuid, notifyUuid } = res;
|
|
151
152
|
|
|
152
153
|
if (!characteristics) {
|
|
153
154
|
characteristics = await device.characteristicsForService(serviceUuid);
|
|
@@ -158,11 +159,14 @@ async function open(deviceOrId: Device | string, needsReconnect: boolean) {
|
|
|
158
159
|
}
|
|
159
160
|
|
|
160
161
|
let writeC;
|
|
162
|
+
let writeCmdC;
|
|
161
163
|
let notifyC;
|
|
162
164
|
|
|
163
165
|
for (const c of characteristics) {
|
|
164
166
|
if (c.uuid === writeUuid) {
|
|
165
167
|
writeC = c;
|
|
168
|
+
} else if (c.uuid === writeCmdUuid) {
|
|
169
|
+
writeCmdC = c;
|
|
166
170
|
} else if (c.uuid === notifyUuid) {
|
|
167
171
|
notifyC = c;
|
|
168
172
|
}
|
|
@@ -196,6 +200,15 @@ async function open(deviceOrId: Device | string, needsReconnect: boolean) {
|
|
|
196
200
|
);
|
|
197
201
|
}
|
|
198
202
|
|
|
203
|
+
if (writeCmdC) {
|
|
204
|
+
if (!writeCmdC.isWritableWithoutResponse) {
|
|
205
|
+
throw new TransportError(
|
|
206
|
+
"write cmd characteristic not writableWithoutResponse",
|
|
207
|
+
"BLEChracteristicInvalid"
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
199
212
|
log("ble-verbose", `device.mtu=${device.mtu}`);
|
|
200
213
|
const notifyObservable = monitorCharacteristic(notifyC).pipe(
|
|
201
214
|
tap((value) => {
|
|
@@ -207,6 +220,7 @@ async function open(deviceOrId: Device | string, needsReconnect: boolean) {
|
|
|
207
220
|
const transport = new BluetoothTransport(
|
|
208
221
|
device,
|
|
209
222
|
writeC,
|
|
223
|
+
writeCmdC,
|
|
210
224
|
notifyObservable,
|
|
211
225
|
deviceModel
|
|
212
226
|
);
|
|
@@ -373,6 +387,7 @@ export default class BluetoothTransport extends Transport {
|
|
|
373
387
|
device: Device;
|
|
374
388
|
mtuSize = 20;
|
|
375
389
|
writeCharacteristic: Characteristic;
|
|
390
|
+
writeCmdCharacteristic: Characteristic;
|
|
376
391
|
notifyObservable: Observable<Buffer>;
|
|
377
392
|
deviceModel: DeviceModel;
|
|
378
393
|
notYetDisconnected = true;
|
|
@@ -380,6 +395,7 @@ export default class BluetoothTransport extends Transport {
|
|
|
380
395
|
constructor(
|
|
381
396
|
device: Device,
|
|
382
397
|
writeCharacteristic: Characteristic,
|
|
398
|
+
writeCmdCharacteristic: Characteristic,
|
|
383
399
|
notifyObservable: Observable<Buffer>,
|
|
384
400
|
deviceModel: DeviceModel
|
|
385
401
|
) {
|
|
@@ -387,6 +403,7 @@ export default class BluetoothTransport extends Transport {
|
|
|
387
403
|
this.id = device.id;
|
|
388
404
|
this.device = device;
|
|
389
405
|
this.writeCharacteristic = writeCharacteristic;
|
|
406
|
+
this.writeCmdCharacteristic = writeCmdCharacteristic;
|
|
390
407
|
this.notifyObservable = notifyObservable;
|
|
391
408
|
this.deviceModel = deviceModel;
|
|
392
409
|
log("ble-verbose", `BleTransport(${String(this.id)}) new instance`);
|
|
@@ -470,13 +487,24 @@ export default class BluetoothTransport extends Transport {
|
|
|
470
487
|
write = async (buffer: Buffer, txid?: string | null | undefined) => {
|
|
471
488
|
log("ble-frame", "=> " + buffer.toString("hex"));
|
|
472
489
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
490
|
+
if (!this.writeCmdCharacteristic) {
|
|
491
|
+
try {
|
|
492
|
+
await this.writeCharacteristic.writeWithResponse(
|
|
493
|
+
buffer.toString("base64"),
|
|
494
|
+
txid
|
|
495
|
+
);
|
|
496
|
+
} catch (e: any) {
|
|
497
|
+
throw new DisconnectedDeviceDuringOperation(e.message);
|
|
498
|
+
}
|
|
499
|
+
} else {
|
|
500
|
+
try {
|
|
501
|
+
await this.writeCmdCharacteristic.writeWithoutResponse(
|
|
502
|
+
buffer.toString("base64"),
|
|
503
|
+
txid
|
|
504
|
+
);
|
|
505
|
+
} catch (e: any) {
|
|
506
|
+
throw new DisconnectedDeviceDuringOperation(e.message);
|
|
507
|
+
}
|
|
480
508
|
}
|
|
481
509
|
};
|
|
482
510
|
|