@ledgerhq/react-native-hw-transport-ble 6.29.0 → 6.29.1-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 +9 -0
- package/lib/BleTransport.d.ts.map +1 -1
- package/lib/BleTransport.js +12 -18
- package/lib/BleTransport.js.map +1 -1
- package/lib/BleTransport.test.js +5 -5
- package/lib/BleTransport.test.js.map +1 -1
- package/lib/awaitsBleOn.js +1 -1
- package/lib/awaitsBleOn.js.map +1 -1
- package/lib/monitorCharacteristic.d.ts.map +1 -1
- package/lib/monitorCharacteristic.js +1 -1
- package/lib/monitorCharacteristic.js.map +1 -1
- package/lib/remapErrors.d.ts.map +1 -1
- package/lib/remapErrors.js +2 -6
- package/lib/remapErrors.js.map +1 -1
- package/lib-es/BleTransport.d.ts.map +1 -1
- package/lib-es/BleTransport.js +14 -20
- package/lib-es/BleTransport.js.map +1 -1
- package/lib-es/BleTransport.test.js +5 -5
- package/lib-es/BleTransport.test.js.map +1 -1
- package/lib-es/awaitsBleOn.js +1 -1
- package/lib-es/awaitsBleOn.js.map +1 -1
- package/lib-es/monitorCharacteristic.d.ts.map +1 -1
- package/lib-es/monitorCharacteristic.js +1 -1
- package/lib-es/monitorCharacteristic.js.map +1 -1
- package/lib-es/remapErrors.d.ts.map +1 -1
- package/lib-es/remapErrors.js +2 -6
- package/lib-es/remapErrors.js.map +1 -1
- package/package.json +5 -5
- package/src/BleTransport.test.ts +11 -18
- package/src/BleTransport.ts +38 -97
- package/src/awaitsBleOn.ts +2 -2
- package/src/monitorCharacteristic.ts +4 -12
- package/src/remapErrors.ts +3 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BleTransport.test.js","sourceRoot":"","sources":["../src/BleTransport.test.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,YAAY,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;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AAC;QAEH,EAAE,CAAC,gEAAgE,EAAE,IAAI,CAAC,EAAE;YAC1E,+EAA+E;YAC/E,mFAAmF;YACnF,kFAAkF;YAClF,kCAAkC;YAClC,SAAe,OAAO;;oBACpB,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;oBACpD,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBACzC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAC;oBACrD,YAAY,CAAC,mBAAmB,GAAG,GAAG,CAAC;oBAEvC,SAAS,CAAC,EAAE,CAAC,YAAY,EAAE,GAAG,EAAE;wBAC9B,IAAI,EAAE,CAAC,CAAC,qDAAqD;oBAC/D,CAAC,CAAC,CAAC;oBACH,MAAM,SAAS,CAAC,KAAK,EAAE,CAAC;oBAExB,iDAAiD;oBACjD,MAAM,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBAC1D,CAAC;aAAA;YAED,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/lib-es/awaitsBleOn.js
CHANGED
|
@@ -4,7 +4,7 @@ import timer from "./timer";
|
|
|
4
4
|
export const awaitsBleOn = (bleManager, ms = 3000) => new Promise((resolve, reject) => {
|
|
5
5
|
let done = false;
|
|
6
6
|
let lastState = "Unknown";
|
|
7
|
-
const stateSub = bleManager.onStateChange(
|
|
7
|
+
const stateSub = bleManager.onStateChange(state => {
|
|
8
8
|
lastState = state;
|
|
9
9
|
log("ble-verbose", `ble state -> ${state}`);
|
|
10
10
|
if (state === "PoweredOn") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"awaitsBleOn.js","sourceRoot":"","sources":["../src/await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SACX;IACH,CAAC,EAAE,IAAI,CAAC,CAAC;IACT,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACvC,IAAI,IAAI;YAAE,OAAO;QACjB,QAAQ,CAAC,MAAM,EAAE,CAAC;QAClB,MAAM,CACJ,IAAI,iBAAiB,CAAC,EAAE,EAAE;YACxB,KAAK,EAAE,SAAS;SACjB,CAAC,CACH,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monitorCharacteristic.d.ts","sourceRoot":"","sources":["../src/monitorCharacteristic.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,eAAO,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"monitorCharacteristic.d.ts","sourceRoot":"","sources":["../src/monitorCharacteristic.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,eAAO,MAAM,qBAAqB,mBAAoB,cAAc,KAAG,WAAW,MAAM,CAwBpF,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Observable } from "rxjs";
|
|
2
2
|
import { TransportError } from "@ledgerhq/errors";
|
|
3
3
|
import { log } from "@ledgerhq/logs";
|
|
4
|
-
export const monitorCharacteristic = (characteristic) => new Observable(
|
|
4
|
+
export const monitorCharacteristic = (characteristic) => new Observable(o => {
|
|
5
5
|
log("ble-verbose", "start monitor " + characteristic.uuid);
|
|
6
6
|
const subscription = characteristic.monitor((error, c) => {
|
|
7
7
|
if (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monitorCharacteristic.js","sourceRoot":"","sources":["../src/monitorCharacteristic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,MAAM,CAAC,MAAM,qBAAqB,GAAG,
|
|
1
|
+
{"version":3,"file":"monitorCharacteristic.js","sourceRoot":"","sources":["../src/monitorCharacteristic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,cAA8B,EAAsB,EAAE,CAC1F,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE;IACjB,GAAG,CAAC,aAAa,EAAE,gBAAgB,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IAC3D,MAAM,YAAY,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;QACvD,IAAI,KAAK,EAAE;YACT,GAAG,CAAC,aAAa,EAAE,gBAAgB,GAAG,cAAc,CAAC,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC,CAAC;YAC1E,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;SAChB;aAAM,IAAI,CAAC,CAAC,EAAE;YACb,CAAC,CAAC,KAAK,CACL,IAAI,cAAc,CAAC,mCAAmC,EAAE,2BAA2B,CAAC,CACrF,CAAC;SACH;aAAM;YACL,IAAI;gBACF,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;gBAC7C,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACf;YAAC,OAAO,KAAK,EAAE;gBACd,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;aAChB;SACF;IACH,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,EAAE;QACV,GAAG,CAAC,aAAa,EAAE,cAAc,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;QACzD,YAAY,CAAC,MAAM,EAAE,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remapErrors.d.ts","sourceRoot":"","sources":["../src/remapErrors.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EAChB,oBAAoB,EAGrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAmB,QAAQ,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAE/E,KAAK,eAAe,GAAG,KAAK,GAAG,QAAQ,GAAG,IAAI,GAAG,SAAS,CAAC;AAC3D,eAAO,MAAM,UAAU,UAAW,eAAe,KAAG,
|
|
1
|
+
{"version":3,"file":"remapErrors.d.ts","sourceRoot":"","sources":["../src/remapErrors.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EAChB,oBAAoB,EAGrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAmB,QAAQ,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAE/E,KAAK,eAAe,GAAG,KAAK,GAAG,QAAQ,GAAG,IAAI,GAAG,SAAS,CAAC;AAC3D,eAAO,MAAM,UAAU,UAAW,eAAe,KAAG,eAqBnD,CAAC;AAEF,eAAO,MAAM,YAAY,MAAO,KAAK,GAAG,IAAI,GAAG,SAAS,KAAG,KAE1D,CAAC;AAEF,eAAO,MAAM,qBAAqB,wCACL,CAAC;AAE9B,eAAO,MAAM,0BAA0B,yCAQrC,CAAC;AAEH,eAAO,MAAM,6BAA6B,aAAc,QAAQ,KAAG,gBAOlE,CAAC"}
|
package/lib-es/remapErrors.js
CHANGED
|
@@ -14,8 +14,7 @@ export const remapError = (error) => {
|
|
|
14
14
|
return new PairingFailed();
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
if (error.message.includes("was disconnected") ||
|
|
18
|
-
error.message.includes("not found")) {
|
|
17
|
+
if (error.message.includes("was disconnected") || error.message.includes("not found")) {
|
|
19
18
|
return new DisconnectedDevice();
|
|
20
19
|
}
|
|
21
20
|
return error;
|
|
@@ -26,10 +25,7 @@ export const rethrowError = (e) => {
|
|
|
26
25
|
export const decoratePromiseErrors = (promise) => promise.catch(rethrowError);
|
|
27
26
|
export const bleErrorToHwTransportError = new Map([
|
|
28
27
|
[BleErrorCode.ScanStartFailed, HwTransportErrorType.BluetoothScanStartFailed],
|
|
29
|
-
[
|
|
30
|
-
BleErrorCode.LocationServicesDisabled,
|
|
31
|
-
HwTransportErrorType.LocationServicesDisabled,
|
|
32
|
-
],
|
|
28
|
+
[BleErrorCode.LocationServicesDisabled, HwTransportErrorType.LocationServicesDisabled],
|
|
33
29
|
[
|
|
34
30
|
// BluetoothUnauthorized actually represents a location service unauthorized error
|
|
35
31
|
BleErrorCode.BluetoothUnauthorized,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remapErrors.js","sourceRoot":"","sources":["../src/remapErrors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAG/E,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAsB,EAAmB,EAAE;IACpE,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAE3C,IAAI,KAAK,YAAY,QAAQ,EAAE;QAC7B,IACE,KAAK,CAAC,YAAY,KAAK,eAAe,CAAC,aAAa;YACpD,KAAK,CAAC,MAAM,KAAK,kCAAkC,EACnD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AAU,CAAC,CAAC,CAAC,CAAC;AACtB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAI,OAAmB,EAAc,EAAE,CAC1E,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;AAE9B,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,GAAG,CAAC;IAChD,CAAC,YAAY,CAAC,eAAe,EAAE,oBAAoB,CAAC,wBAAwB,CAAC;IAC7E,CAAC,YAAY,CAAC,wBAAwB,EAAE,oBAAoB,CAAC,wBAAwB,CAAC;IACtF;QACE,kFAAkF;QAClF,YAAY,CAAC,qBAAqB;QAClC,oBAAoB,CAAC,4BAA4B;KAClD;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,QAAkB,EAAoB,EAAE;IACpF,MAAM,OAAO,GAAG,GAAG,QAAQ,CAAC,OAAO,aAAa,QAAQ,CAAC,SAAS,EAAE,CAAC;IAErE,MAAM,WAAW,GAAG,0BAA0B,CAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IACvE,MAAM,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC;IAEvE,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC7C,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/react-native-hw-transport-ble",
|
|
3
|
-
"version": "6.29.0",
|
|
3
|
+
"version": "6.29.1-nightly.0",
|
|
4
4
|
"description": "Ledger Hardware Wallet Bluetooth BLE transport for React Native",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"react-native-ble-plx": "2.0.3",
|
|
30
30
|
"rxjs": "6",
|
|
31
31
|
"uuid": "^3.4.0",
|
|
32
|
-
"@ledgerhq/devices": "^8.0.
|
|
33
|
-
"@ledgerhq/errors": "^6.12.
|
|
34
|
-
"@ledgerhq/hw-transport": "^6.28.
|
|
32
|
+
"@ledgerhq/devices": "^8.0.4-nightly.0",
|
|
33
|
+
"@ledgerhq/errors": "^6.12.7-nightly.0",
|
|
34
|
+
"@ledgerhq/hw-transport": "^6.28.5-nightly.0",
|
|
35
35
|
"@ledgerhq/logs": "^6.10.1"
|
|
36
36
|
},
|
|
37
37
|
"gitHead": "dd0dea64b58e5a9125c8a422dcffd29e5ef6abec",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"build": "tsc && tsc -m ES6 --outDir lib-es",
|
|
51
51
|
"prewatch": "pnpm build",
|
|
52
52
|
"watch": "tsc --watch",
|
|
53
|
-
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx",
|
|
53
|
+
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
|
|
54
54
|
"lint:fix": "pnpm lint --fix",
|
|
55
55
|
"test": "jest --runInBand"
|
|
56
56
|
}
|
package/src/BleTransport.test.ts
CHANGED
|
@@ -42,7 +42,7 @@ jest.mock("react-native-ble-plx", () => {
|
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
return {
|
|
45
|
-
onStateChange:
|
|
45
|
+
onStateChange: callback => {
|
|
46
46
|
setTimeout(() => callback("PoweredOn"), 500);
|
|
47
47
|
return new Subscription();
|
|
48
48
|
},
|
|
@@ -77,12 +77,12 @@ jest.mock("react-native-ble-plx", () => {
|
|
|
77
77
|
return dynamicProps.isConnected;
|
|
78
78
|
},
|
|
79
79
|
|
|
80
|
-
onDisconnected:
|
|
80
|
+
onDisconnected: callback => {
|
|
81
81
|
callbacks["onDisconnected"] = () => callback(null); // Disconnect without an error
|
|
82
82
|
return new Subscription();
|
|
83
83
|
},
|
|
84
84
|
discoverAllServicesAndCharacteristics: () => {},
|
|
85
|
-
characteristicsForService:
|
|
85
|
+
characteristicsForService: uuid => {
|
|
86
86
|
if (uuid === "13d63400-2c97-6004-0000-4c6564676572") {
|
|
87
87
|
return [
|
|
88
88
|
{
|
|
@@ -96,11 +96,10 @@ jest.mock("react-native-ble-plx", () => {
|
|
|
96
96
|
isReadable: false,
|
|
97
97
|
deviceID: "20EDD96F-7430-6E33-AB22-DD8AAB857CD4",
|
|
98
98
|
isNotifying: false,
|
|
99
|
-
value:
|
|
100
|
-
"BQAAACMzIAAECTEuMC4wLXJjOQTuAAALBDUuMTUEMC4zNQEAAQCQAA==",
|
|
99
|
+
value: "BQAAACMzIAAECTEuMC4wLXJjOQTuAAALBDUuMTUEMC4zNQEAAQCQAA==",
|
|
101
100
|
id: 105553399124864,
|
|
102
101
|
uuid: "13d63400-2c97-6004-0001-4c6564676572",
|
|
103
|
-
monitor:
|
|
102
|
+
monitor: cb => {
|
|
104
103
|
callbacks["onDeviceResponse"] = cb;
|
|
105
104
|
return new Subscription();
|
|
106
105
|
},
|
|
@@ -134,7 +133,7 @@ jest.mock("react-native-ble-plx", () => {
|
|
|
134
133
|
uuid: "13d63400-2c97-6004-0003-4c6564676572",
|
|
135
134
|
serviceUUID: "13d63400-2c97-6004-0000-4c6564676572",
|
|
136
135
|
serviceID: 105553179758272,
|
|
137
|
-
writeWithoutResponse: async
|
|
136
|
+
writeWithoutResponse: async raw => {
|
|
138
137
|
if (!dynamicProps.isConnected)
|
|
139
138
|
throw new BleError(22, "Device is not connected");
|
|
140
139
|
|
|
@@ -150,7 +149,7 @@ jest.mock("react-native-ble-plx", () => {
|
|
|
150
149
|
case "0500000005b010000000":
|
|
151
150
|
value = Buffer.from(
|
|
152
151
|
"05000000130105424f4c4f5309312e302e302d7263399000",
|
|
153
|
-
"hex"
|
|
152
|
+
"hex",
|
|
154
153
|
);
|
|
155
154
|
break;
|
|
156
155
|
// just used for a non resolving apdu
|
|
@@ -252,24 +251,18 @@ describe("BleTransport connectivity test coverage", () => {
|
|
|
252
251
|
const transport = await BleTransport.open(deviceId);
|
|
253
252
|
expect(transport.isConnected).toBe(true);
|
|
254
253
|
|
|
255
|
-
const response = await transport.exchange(
|
|
256
|
-
|
|
257
|
-
);
|
|
258
|
-
expect(response.toString("hex")).toBe(
|
|
259
|
-
"0105424f4c4f5309312e302e302d7263399000"
|
|
260
|
-
);
|
|
254
|
+
const response = await transport.exchange(Buffer.from("b010000000", "hex"));
|
|
255
|
+
expect(response.toString("hex")).toBe("0105424f4c4f5309312e302e302d7263399000");
|
|
261
256
|
});
|
|
262
257
|
|
|
263
258
|
it("should throw on exchanges if disconnected", async () => {
|
|
264
259
|
const transport = await BleTransport.open(deviceId);
|
|
265
260
|
expect(transport.isConnected).toBe(true);
|
|
266
261
|
await BleTransport.disconnect(deviceId);
|
|
267
|
-
await expect(
|
|
268
|
-
transport.exchange(Buffer.from("b010000000", "hex"))
|
|
269
|
-
).rejects.toThrow(); // More specific errors some day.
|
|
262
|
+
await expect(transport.exchange(Buffer.from("b010000000", "hex"))).rejects.toThrow(); // More specific errors some day.
|
|
270
263
|
});
|
|
271
264
|
|
|
272
|
-
it("should disconnect if close is called, even if pending response",
|
|
265
|
+
it("should disconnect if close is called, even if pending response", done => {
|
|
273
266
|
// This is actually a very important test, if we have an ongoing apdu response,
|
|
274
267
|
// as in, the device never replied, but we expressed the intention of disconnecting
|
|
275
268
|
// we will give it a few seconds and then disconnect regardless. Otherwise we fall
|
package/src/BleTransport.ts
CHANGED
|
@@ -33,14 +33,7 @@ import {
|
|
|
33
33
|
import type { DeviceModel } from "@ledgerhq/devices";
|
|
34
34
|
import { log } from "@ledgerhq/logs";
|
|
35
35
|
import { Observable, defer, merge, from, of, throwError, Observer } from "rxjs";
|
|
36
|
-
import {
|
|
37
|
-
share,
|
|
38
|
-
ignoreElements,
|
|
39
|
-
first,
|
|
40
|
-
map,
|
|
41
|
-
tap,
|
|
42
|
-
catchError,
|
|
43
|
-
} from "rxjs/operators";
|
|
36
|
+
import { share, ignoreElements, first, map, tap, catchError } from "rxjs/operators";
|
|
44
37
|
import {
|
|
45
38
|
CantOpenDevice,
|
|
46
39
|
TransportError,
|
|
@@ -51,11 +44,7 @@ import {
|
|
|
51
44
|
} from "@ledgerhq/errors";
|
|
52
45
|
import { monitorCharacteristic } from "./monitorCharacteristic";
|
|
53
46
|
import { awaitsBleOn } from "./awaitsBleOn";
|
|
54
|
-
import {
|
|
55
|
-
decoratePromiseErrors,
|
|
56
|
-
remapError,
|
|
57
|
-
mapBleErrorToHwTransportError,
|
|
58
|
-
} from "./remapErrors";
|
|
47
|
+
import { decoratePromiseErrors, remapError, mapBleErrorToHwTransportError } from "./remapErrors";
|
|
59
48
|
import { ReconnectionConfig } from "./types";
|
|
60
49
|
|
|
61
50
|
/**
|
|
@@ -67,9 +56,7 @@ let reconnectionConfig: ReconnectionConfig | null | undefined = {
|
|
|
67
56
|
delayAfterFirstPairing: 4000,
|
|
68
57
|
};
|
|
69
58
|
|
|
70
|
-
export const setReconnectionConfig = (
|
|
71
|
-
config: ReconnectionConfig | null | undefined
|
|
72
|
-
): void => {
|
|
59
|
+
export const setReconnectionConfig = (config: ReconnectionConfig | null | undefined): void => {
|
|
73
60
|
reconnectionConfig = config;
|
|
74
61
|
};
|
|
75
62
|
|
|
@@ -85,8 +72,7 @@ const retrieveInfos = (device: Device | null) => {
|
|
|
85
72
|
return infos;
|
|
86
73
|
};
|
|
87
74
|
|
|
88
|
-
const delay = (ms: number | undefined) =>
|
|
89
|
-
new Promise((success) => setTimeout(success, ms));
|
|
75
|
+
const delay = (ms: number | undefined) => new Promise(success => setTimeout(success, ms));
|
|
90
76
|
|
|
91
77
|
/**
|
|
92
78
|
* A cache of Bluetooth transport instances associated with device IDs.
|
|
@@ -153,11 +139,9 @@ async function open(deviceOrId: Device | string, needsReconnect: boolean) {
|
|
|
153
139
|
// which have discovered services, connected to system doesn't mean
|
|
154
140
|
// connected to our app, we check that below.
|
|
155
141
|
const connectedDevices = await bleManagerInstance().connectedDevices(
|
|
156
|
-
getBluetoothServiceUuids()
|
|
157
|
-
);
|
|
158
|
-
const connectedDevicesFiltered = connectedDevices.filter(
|
|
159
|
-
(d) => d.id === deviceOrId
|
|
142
|
+
getBluetoothServiceUuids(),
|
|
160
143
|
);
|
|
144
|
+
const connectedDevicesFiltered = connectedDevices.filter(d => d.id === deviceOrId);
|
|
161
145
|
log(TAG, `found ${connectedDevicesFiltered.length} connected devices`);
|
|
162
146
|
[device] = connectedDevicesFiltered;
|
|
163
147
|
}
|
|
@@ -167,10 +151,7 @@ async function open(deviceOrId: Device | string, needsReconnect: boolean) {
|
|
|
167
151
|
log(TAG, `connectToDevice(${deviceOrId})`);
|
|
168
152
|
// Nb ConnectionOptions dropped since it's not used internally by ble-plx.
|
|
169
153
|
try {
|
|
170
|
-
device = await bleManagerInstance().connectToDevice(
|
|
171
|
-
deviceOrId,
|
|
172
|
-
connectOptions
|
|
173
|
-
);
|
|
154
|
+
device = await bleManagerInstance().connectToDevice(deviceOrId, connectOptions);
|
|
174
155
|
} catch (e: any) {
|
|
175
156
|
log(TAG, `error code ${e.errorCode}`);
|
|
176
157
|
if (e.errorCode === BleErrorCode.DeviceMTUChangeFailed) {
|
|
@@ -201,10 +182,7 @@ async function open(deviceOrId: Device | string, needsReconnect: boolean) {
|
|
|
201
182
|
log("ble-verbose", `device.mtu=${device.mtu}, reconnecting`);
|
|
202
183
|
connectOptions = {};
|
|
203
184
|
await device.connect();
|
|
204
|
-
} else if (
|
|
205
|
-
e.iosErrorCode === 14 ||
|
|
206
|
-
e.reason === "Peer removed pairing information"
|
|
207
|
-
) {
|
|
185
|
+
} else if (e.iosErrorCode === 14 || e.reason === "Peer removed pairing information") {
|
|
208
186
|
log("ble-verbose", "iOS broken pairing");
|
|
209
187
|
log("ble-verbose", JSON.stringify(device));
|
|
210
188
|
log("ble-verbose", JSON.stringify(bluetoothInfoCache[device.id]));
|
|
@@ -265,65 +243,48 @@ async function open(deviceOrId: Device | string, needsReconnect: boolean) {
|
|
|
265
243
|
}
|
|
266
244
|
|
|
267
245
|
if (!writeC) {
|
|
268
|
-
throw new TransportError(
|
|
269
|
-
"write characteristic not found",
|
|
270
|
-
"BLECharacteristicNotFound"
|
|
271
|
-
);
|
|
246
|
+
throw new TransportError("write characteristic not found", "BLECharacteristicNotFound");
|
|
272
247
|
}
|
|
273
248
|
|
|
274
249
|
if (!notifyC) {
|
|
275
|
-
throw new TransportError(
|
|
276
|
-
"notify characteristic not found",
|
|
277
|
-
"BLECharacteristicNotFound"
|
|
278
|
-
);
|
|
250
|
+
throw new TransportError("notify characteristic not found", "BLECharacteristicNotFound");
|
|
279
251
|
}
|
|
280
252
|
|
|
281
253
|
if (!writeC.isWritableWithResponse) {
|
|
282
254
|
throw new TransportError(
|
|
283
255
|
"write characteristic not writableWithResponse",
|
|
284
|
-
"BLECharacteristicInvalid"
|
|
256
|
+
"BLECharacteristicInvalid",
|
|
285
257
|
);
|
|
286
258
|
}
|
|
287
259
|
|
|
288
260
|
if (!notifyC.isNotifiable) {
|
|
289
|
-
throw new TransportError(
|
|
290
|
-
"notify characteristic not notifiable",
|
|
291
|
-
"BLECharacteristicInvalid"
|
|
292
|
-
);
|
|
261
|
+
throw new TransportError("notify characteristic not notifiable", "BLECharacteristicInvalid");
|
|
293
262
|
}
|
|
294
263
|
|
|
295
264
|
if (writeCmdC) {
|
|
296
265
|
if (!writeCmdC.isWritableWithoutResponse) {
|
|
297
266
|
throw new TransportError(
|
|
298
267
|
"write cmd characteristic not writableWithoutResponse",
|
|
299
|
-
"BLECharacteristicInvalid"
|
|
268
|
+
"BLECharacteristicInvalid",
|
|
300
269
|
);
|
|
301
270
|
}
|
|
302
271
|
}
|
|
303
272
|
|
|
304
273
|
log(TAG, `device.mtu=${device.mtu}`);
|
|
305
274
|
const notifyObservable = monitorCharacteristic(notifyC).pipe(
|
|
306
|
-
catchError(
|
|
275
|
+
catchError(e => {
|
|
307
276
|
// LL-9033 fw 2.0.2 introduced this case, we silence the inner unhandled error.
|
|
308
277
|
const msg = String(e);
|
|
309
|
-
return msg.includes("notify change failed")
|
|
310
|
-
? of(new PairingFailed(msg))
|
|
311
|
-
: throwError(e);
|
|
278
|
+
return msg.includes("notify change failed") ? of(new PairingFailed(msg)) : throwError(e);
|
|
312
279
|
}),
|
|
313
|
-
tap(
|
|
280
|
+
tap(value => {
|
|
314
281
|
if (value instanceof PairingFailed) return;
|
|
315
282
|
log("ble-frame", "<= " + value.toString("hex"));
|
|
316
283
|
}),
|
|
317
|
-
share()
|
|
284
|
+
share(),
|
|
318
285
|
);
|
|
319
286
|
const notif = notifyObservable.subscribe();
|
|
320
|
-
const transport = new BleTransport(
|
|
321
|
-
device,
|
|
322
|
-
writeC,
|
|
323
|
-
writeCmdC,
|
|
324
|
-
notifyObservable,
|
|
325
|
-
deviceModel
|
|
326
|
-
);
|
|
287
|
+
const transport = new BleTransport(device, writeC, writeCmdC, notifyObservable, deviceModel);
|
|
327
288
|
|
|
328
289
|
// Keeping it as a comment for now but if no new bluetooth issues occur, we will be able to remove it
|
|
329
290
|
// await transport.requestConnectionPriority("High");
|
|
@@ -345,7 +306,7 @@ async function open(deviceOrId: Device | string, needsReconnect: boolean) {
|
|
|
345
306
|
transportsCache[transport.id] = transport;
|
|
346
307
|
const beforeMTUTime = Date.now();
|
|
347
308
|
|
|
348
|
-
disconnectedSub = device.onDisconnected(
|
|
309
|
+
disconnectedSub = device.onDisconnected(e => {
|
|
349
310
|
if (!transport.notYetDisconnected) return;
|
|
350
311
|
onDisconnect(e);
|
|
351
312
|
});
|
|
@@ -391,8 +352,7 @@ export default class BleTransport extends Transport {
|
|
|
391
352
|
/**
|
|
392
353
|
*
|
|
393
354
|
*/
|
|
394
|
-
static isSupported = (): Promise<boolean> =>
|
|
395
|
-
Promise.resolve(typeof BleManager === "function");
|
|
355
|
+
static isSupported = (): Promise<boolean> => Promise.resolve(typeof BleManager === "function");
|
|
396
356
|
|
|
397
357
|
/**
|
|
398
358
|
*
|
|
@@ -424,7 +384,7 @@ export default class BleTransport extends Transport {
|
|
|
424
384
|
observer: Observer<{
|
|
425
385
|
type: string;
|
|
426
386
|
available: boolean;
|
|
427
|
-
}
|
|
387
|
+
}>,
|
|
428
388
|
): TransportSubscription {
|
|
429
389
|
const emitFromState = (type: string) => {
|
|
430
390
|
observer.next({
|
|
@@ -445,26 +405,20 @@ export default class BleTransport extends Transport {
|
|
|
445
405
|
* @param observer Device is partial in order to avoid the live-common/this dep
|
|
446
406
|
* @returns TransportSubscription
|
|
447
407
|
*/
|
|
448
|
-
static listen(
|
|
449
|
-
observer: TransportObserver<any, HwTransportError>
|
|
450
|
-
): TransportSubscription {
|
|
408
|
+
static listen(observer: TransportObserver<any, HwTransportError>): TransportSubscription {
|
|
451
409
|
log(TAG, "listening for devices");
|
|
452
410
|
|
|
453
411
|
let unsubscribed: boolean;
|
|
454
412
|
|
|
455
|
-
const stateSub = bleManagerInstance().onStateChange(async
|
|
413
|
+
const stateSub = bleManagerInstance().onStateChange(async state => {
|
|
456
414
|
if (state === "PoweredOn") {
|
|
457
415
|
stateSub.remove();
|
|
458
|
-
const devices = await bleManagerInstance().connectedDevices(
|
|
459
|
-
getBluetoothServiceUuids()
|
|
460
|
-
);
|
|
416
|
+
const devices = await bleManagerInstance().connectedDevices(getBluetoothServiceUuids());
|
|
461
417
|
if (unsubscribed) return;
|
|
462
418
|
if (devices.length) {
|
|
463
419
|
log(TAG, "disconnecting from devices");
|
|
464
420
|
|
|
465
|
-
await Promise.all(
|
|
466
|
-
devices.map((d) => BleTransport.disconnect(d.id).catch(() => {}))
|
|
467
|
-
);
|
|
421
|
+
await Promise.all(devices.map(d => BleTransport.disconnect(d.id).catch(() => {})));
|
|
468
422
|
}
|
|
469
423
|
|
|
470
424
|
if (unsubscribed) return;
|
|
@@ -488,7 +442,7 @@ export default class BleTransport extends Transport {
|
|
|
488
442
|
deviceModel,
|
|
489
443
|
});
|
|
490
444
|
}
|
|
491
|
-
}
|
|
445
|
+
},
|
|
492
446
|
);
|
|
493
447
|
}
|
|
494
448
|
}, true);
|
|
@@ -540,7 +494,7 @@ export default class BleTransport extends Transport {
|
|
|
540
494
|
writeCharacteristic: Characteristic,
|
|
541
495
|
writeCmdCharacteristic: Characteristic | undefined,
|
|
542
496
|
notifyObservable: Observable<any>,
|
|
543
|
-
deviceModel: DeviceModel
|
|
497
|
+
deviceModel: DeviceModel,
|
|
544
498
|
) {
|
|
545
499
|
super();
|
|
546
500
|
this.id = device.id;
|
|
@@ -568,7 +522,7 @@ export default class BleTransport extends Transport {
|
|
|
568
522
|
|
|
569
523
|
const data = await merge(
|
|
570
524
|
this.notifyObservable.pipe(receiveAPDU),
|
|
571
|
-
sendAPDU(this.write, apdu, this.mtuSize)
|
|
525
|
+
sendAPDU(this.write, apdu, this.mtuSize),
|
|
572
526
|
).toPromise();
|
|
573
527
|
|
|
574
528
|
const msgOut = data.toString("hex");
|
|
@@ -600,15 +554,13 @@ export default class BleTransport extends Transport {
|
|
|
600
554
|
try {
|
|
601
555
|
mtu = await merge(
|
|
602
556
|
this.notifyObservable.pipe(
|
|
603
|
-
tap(
|
|
557
|
+
tap(maybeError => {
|
|
604
558
|
if (maybeError instanceof Error) throw maybeError;
|
|
605
559
|
}),
|
|
606
|
-
first(
|
|
607
|
-
map(
|
|
560
|
+
first(buffer => buffer.readUInt8(0) === 0x08),
|
|
561
|
+
map(buffer => buffer.readUInt8(5)),
|
|
608
562
|
),
|
|
609
|
-
defer(() => from(this.write(Buffer.from([0x08, 0, 0, 0, 0])))).pipe(
|
|
610
|
-
ignoreElements()
|
|
611
|
-
)
|
|
563
|
+
defer(() => from(this.write(Buffer.from([0x08, 0, 0, 0, 0])))).pipe(ignoreElements()),
|
|
612
564
|
).toPromise();
|
|
613
565
|
} catch (e: any) {
|
|
614
566
|
log("ble-error", "inferMTU got " + JSON.stringify(e));
|
|
@@ -636,12 +588,10 @@ export default class BleTransport extends Transport {
|
|
|
636
588
|
* @returns {Promise<Device>} Connected device.
|
|
637
589
|
*/
|
|
638
590
|
async requestConnectionPriority(
|
|
639
|
-
connectionPriority: "Balanced" | "High" | "LowPower"
|
|
591
|
+
connectionPriority: "Balanced" | "High" | "LowPower",
|
|
640
592
|
): Promise<Device> {
|
|
641
593
|
return await decoratePromiseErrors(
|
|
642
|
-
this.device.requestConnectionPriority(
|
|
643
|
-
ConnectionPriority[connectionPriority]
|
|
644
|
-
)
|
|
594
|
+
this.device.requestConnectionPriority(ConnectionPriority[connectionPriority]),
|
|
645
595
|
);
|
|
646
596
|
}
|
|
647
597
|
|
|
@@ -655,19 +605,13 @@ export default class BleTransport extends Transport {
|
|
|
655
605
|
log("ble-frame", "=> " + buffer.toString("hex"));
|
|
656
606
|
if (!this.writeCmdCharacteristic) {
|
|
657
607
|
try {
|
|
658
|
-
await this.writeCharacteristic.writeWithResponse(
|
|
659
|
-
buffer.toString("base64"),
|
|
660
|
-
txid
|
|
661
|
-
);
|
|
608
|
+
await this.writeCharacteristic.writeWithResponse(buffer.toString("base64"), txid);
|
|
662
609
|
} catch (e: any) {
|
|
663
610
|
throw new DisconnectedDeviceDuringOperation(e.message);
|
|
664
611
|
}
|
|
665
612
|
} else {
|
|
666
613
|
try {
|
|
667
|
-
await this.writeCmdCharacteristic.writeWithoutResponse(
|
|
668
|
-
buffer.toString("base64"),
|
|
669
|
-
txid
|
|
670
|
-
);
|
|
614
|
+
await this.writeCmdCharacteristic.writeWithoutResponse(buffer.toString("base64"), txid);
|
|
671
615
|
} catch (e: any) {
|
|
672
616
|
throw new DisconnectedDeviceDuringOperation(e.message);
|
|
673
617
|
}
|
|
@@ -684,7 +628,7 @@ export default class BleTransport extends Transport {
|
|
|
684
628
|
*/
|
|
685
629
|
async close(): Promise<void> {
|
|
686
630
|
let resolve: (value: void | PromiseLike<void>) => void;
|
|
687
|
-
const disconnectPromise = new Promise<void>(
|
|
631
|
+
const disconnectPromise = new Promise<void>(innerResolve => {
|
|
688
632
|
resolve = innerResolve;
|
|
689
633
|
});
|
|
690
634
|
|
|
@@ -705,10 +649,7 @@ export default class BleTransport extends Transport {
|
|
|
705
649
|
|
|
706
650
|
// The closure will occur no later than 5s, triggered either by disconnection
|
|
707
651
|
// or the actual response of the apdu.
|
|
708
|
-
await Promise.race([
|
|
709
|
-
this.exchangeBusyPromise || Promise.resolve(),
|
|
710
|
-
disconnectPromise,
|
|
711
|
-
]);
|
|
652
|
+
await Promise.race([this.exchangeBusyPromise || Promise.resolve(), disconnectPromise]);
|
|
712
653
|
|
|
713
654
|
return;
|
|
714
655
|
}
|
package/src/awaitsBleOn.ts
CHANGED
|
@@ -6,7 +6,7 @@ export const awaitsBleOn = (bleManager: BleManager, ms = 3000): Promise<void> =>
|
|
|
6
6
|
new Promise((resolve, reject) => {
|
|
7
7
|
let done = false;
|
|
8
8
|
let lastState = "Unknown";
|
|
9
|
-
const stateSub = bleManager.onStateChange(
|
|
9
|
+
const stateSub = bleManager.onStateChange(state => {
|
|
10
10
|
lastState = state;
|
|
11
11
|
log("ble-verbose", `ble state -> ${state}`);
|
|
12
12
|
|
|
@@ -24,7 +24,7 @@ export const awaitsBleOn = (bleManager: BleManager, ms = 3000): Promise<void> =>
|
|
|
24
24
|
reject(
|
|
25
25
|
new BluetoothRequired("", {
|
|
26
26
|
state: lastState,
|
|
27
|
-
})
|
|
27
|
+
}),
|
|
28
28
|
);
|
|
29
29
|
}, ms);
|
|
30
30
|
});
|
|
@@ -2,24 +2,16 @@ import { Observable } from "rxjs";
|
|
|
2
2
|
import { TransportError } from "@ledgerhq/errors";
|
|
3
3
|
import type { Characteristic } from "./types";
|
|
4
4
|
import { log } from "@ledgerhq/logs";
|
|
5
|
-
export const monitorCharacteristic = (
|
|
6
|
-
|
|
7
|
-
): Observable<Buffer> =>
|
|
8
|
-
new Observable((o) => {
|
|
5
|
+
export const monitorCharacteristic = (characteristic: Characteristic): Observable<Buffer> =>
|
|
6
|
+
new Observable(o => {
|
|
9
7
|
log("ble-verbose", "start monitor " + characteristic.uuid);
|
|
10
8
|
const subscription = characteristic.monitor((error, c) => {
|
|
11
9
|
if (error) {
|
|
12
|
-
log(
|
|
13
|
-
"ble-verbose",
|
|
14
|
-
"error monitor " + characteristic.uuid + ": " + error
|
|
15
|
-
);
|
|
10
|
+
log("ble-verbose", "error monitor " + characteristic.uuid + ": " + error);
|
|
16
11
|
o.error(error);
|
|
17
12
|
} else if (!c) {
|
|
18
13
|
o.error(
|
|
19
|
-
new TransportError(
|
|
20
|
-
"characteristic monitor null value",
|
|
21
|
-
"CharacteristicMonitorNull"
|
|
22
|
-
)
|
|
14
|
+
new TransportError("characteristic monitor null value", "CharacteristicMonitorNull"),
|
|
23
15
|
);
|
|
24
16
|
} else {
|
|
25
17
|
try {
|
package/src/remapErrors.ts
CHANGED
|
@@ -24,10 +24,7 @@ export const remapError = (error: IOBleErrorRemap): IOBleErrorRemap => {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
if (
|
|
28
|
-
error.message.includes("was disconnected") ||
|
|
29
|
-
error.message.includes("not found")
|
|
30
|
-
) {
|
|
27
|
+
if (error.message.includes("was disconnected") || error.message.includes("not found")) {
|
|
31
28
|
return new DisconnectedDevice();
|
|
32
29
|
}
|
|
33
30
|
|
|
@@ -43,10 +40,7 @@ export const decoratePromiseErrors = <A>(promise: Promise<A>): Promise<A> =>
|
|
|
43
40
|
|
|
44
41
|
export const bleErrorToHwTransportError = new Map([
|
|
45
42
|
[BleErrorCode.ScanStartFailed, HwTransportErrorType.BluetoothScanStartFailed],
|
|
46
|
-
[
|
|
47
|
-
BleErrorCode.LocationServicesDisabled,
|
|
48
|
-
HwTransportErrorType.LocationServicesDisabled,
|
|
49
|
-
],
|
|
43
|
+
[BleErrorCode.LocationServicesDisabled, HwTransportErrorType.LocationServicesDisabled],
|
|
50
44
|
[
|
|
51
45
|
// BluetoothUnauthorized actually represents a location service unauthorized error
|
|
52
46
|
BleErrorCode.BluetoothUnauthorized,
|
|
@@ -54,9 +48,7 @@ export const bleErrorToHwTransportError = new Map([
|
|
|
54
48
|
],
|
|
55
49
|
]);
|
|
56
50
|
|
|
57
|
-
export const mapBleErrorToHwTransportError = (
|
|
58
|
-
bleError: BleError
|
|
59
|
-
): HwTransportError => {
|
|
51
|
+
export const mapBleErrorToHwTransportError = (bleError: BleError): HwTransportError => {
|
|
60
52
|
const message = `${bleError.message}. Origin: ${bleError.errorCode}`;
|
|
61
53
|
|
|
62
54
|
const inferedType = bleErrorToHwTransportError.get(bleError.errorCode);
|