@onekeyfe/hd-transport-react-native 1.1.27-alpha.35 → 1.1.27-alpha.36
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/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -13
- package/package.json +5 -5
- package/src/index.ts +47 -13
package/dist/index.d.ts
CHANGED
|
@@ -72,6 +72,8 @@ declare class ReactNativeBleTransport {
|
|
|
72
72
|
cancel(): void;
|
|
73
73
|
private getCachedTransport;
|
|
74
74
|
private createProtocolMismatchError;
|
|
75
|
+
private createProtocolDetectionError;
|
|
76
|
+
private clearProbeProtocol;
|
|
75
77
|
private detectProtocol;
|
|
76
78
|
private resetProbeStateAfterProtocolProbe;
|
|
77
79
|
private probeProtocolV1;
|
|
@@ -85,7 +87,7 @@ declare class ReactNativeBleTransport {
|
|
|
85
87
|
private readProtocolV2Frame;
|
|
86
88
|
private writeProtocolV2Frame;
|
|
87
89
|
private callProtocolV2;
|
|
88
|
-
getProtocolType(path: string): ProtocolType;
|
|
90
|
+
getProtocolType(path: string): ProtocolType | undefined;
|
|
89
91
|
}
|
|
90
92
|
|
|
91
93
|
export { IOneKeyDevice, ProtocolV2BleTuning, configureProtocolV2BleTuning, ReactNativeBleTransport as default, getProtocolV2BleTuning, resetProtocolV2BleTuning };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAIL,UAAU,IAAI,aAAa,EAE5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAEhB,KAAK,oBAAoB,EAGzB,KAAK,YAAY,EAGjB,KAAK,oBAAoB,EAE1B,MAAM,wBAAwB,CAAC;AAkBhC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc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KAAK,EAAE,eAAe;;;;IAmRpC,sBAAsB,CACpB,cAAc,EAAE,cAAc,EAC9B,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,EACpB,mBAAmB,EAAE,MAAM,GAC1B,YAAY;IAwGT,OAAO,CAAC,IAAI,EAAE,MAAM;IAwDpB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAIjE,IAAI,CACR,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,oBAAoB;YAoDlB,cAAc;IA6H5B,IAAI;IAIE,UAAU,CAAC,OAAO,EAAE,MAAM;IAiFhC,MAAM;IAQN,OAAO,CAAC,kBAAkB;IAQ1B,OAAO,CAAC,2BAA2B;IAOnC,OAAO,CAAC,4BAA4B;IAOpC,OAAO,CAAC,kBAAkB;YAMZ,cAAc;YAqDd,iCAAiC;YAmDjC,eAAe;YAgBf,eAAe;IAwB7B,OAAO,CAAC,4BAA4B;IA0BpC,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,yBAAyB;IAQjC,OAAO,CAAC,qBAAqB;IAK7B,OAAO,CAAC,sBAAsB;YAIhB,mBAAmB;YAiBnB,oBAAoB;YAoDpB,cAAc;IAsG5B,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
|
package/dist/index.js
CHANGED
|
@@ -749,7 +749,12 @@ class ReactNativeBleTransport {
|
|
|
749
749
|
}
|
|
750
750
|
try {
|
|
751
751
|
const data = buffer.Buffer.from(c.value, 'base64');
|
|
752
|
-
|
|
752
|
+
const protocol = this.deviceProtocol.get(uuid);
|
|
753
|
+
if (!protocol) {
|
|
754
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('monitor data ignored before protocol detection: ', uuid);
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
if (protocol === 'V2') {
|
|
753
758
|
this.handleProtocolV2Notification(uuid, new Uint8Array(data));
|
|
754
759
|
return;
|
|
755
760
|
}
|
|
@@ -843,6 +848,9 @@ class ReactNativeBleTransport {
|
|
|
843
848
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportCallInProgress);
|
|
844
849
|
}
|
|
845
850
|
const protocol = this.getProtocolType(uuid);
|
|
851
|
+
if (!protocol) {
|
|
852
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol has not been detected for ${uuid}`);
|
|
853
|
+
}
|
|
846
854
|
if (name === 'ResourceUpdate' || name === 'ResourceAck') {
|
|
847
855
|
Log === null || Log === void 0 ? void 0 : Log.debug('transport-react-native', 'call-', ' name: ', name, ' data: ', {
|
|
848
856
|
file_name: data === null || data === void 0 ? void 0 : data.file_name,
|
|
@@ -1057,6 +1065,14 @@ class ReactNativeBleTransport {
|
|
|
1057
1065
|
createProtocolMismatchError(expected) {
|
|
1058
1066
|
return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`);
|
|
1059
1067
|
}
|
|
1068
|
+
createProtocolDetectionError() {
|
|
1069
|
+
return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, 'Unable to detect BLE protocol: device did not respond to Protocol V1 Initialize or Protocol V2 Ping');
|
|
1070
|
+
}
|
|
1071
|
+
clearProbeProtocol(uuid, protocol) {
|
|
1072
|
+
if (this.deviceProtocol.get(uuid) === protocol) {
|
|
1073
|
+
this.deviceProtocol.delete(uuid);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1060
1076
|
detectProtocol(uuid, expectedProtocol, protocolHint) {
|
|
1061
1077
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1062
1078
|
if (expectedProtocol === 'V1') {
|
|
@@ -1085,17 +1101,20 @@ class ReactNativeBleTransport {
|
|
|
1085
1101
|
Log === null || Log === void 0 ? void 0 : Log.debug(`[ReactNativeBleTransport] detectProtocol: uuid=${uuid} -> V2 (cached)`);
|
|
1086
1102
|
return 'V2';
|
|
1087
1103
|
}
|
|
1088
|
-
let protocol = 'V1';
|
|
1089
1104
|
const protocolV1Detected = yield this.probeProtocolV1(uuid);
|
|
1090
|
-
if (
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1105
|
+
if (protocolV1Detected) {
|
|
1106
|
+
this.deviceProtocol.set(uuid, 'V1');
|
|
1107
|
+
Log === null || Log === void 0 ? void 0 : Log.debug(`[ReactNativeBleTransport] detectProtocol: uuid=${uuid} -> V1`);
|
|
1108
|
+
return 'V1';
|
|
1109
|
+
}
|
|
1110
|
+
yield this.resetProbeStateAfterProtocolProbe(uuid, 'V1');
|
|
1111
|
+
if (yield this.probeProtocolV2(uuid)) {
|
|
1112
|
+
this.deviceProtocol.set(uuid, 'V2');
|
|
1113
|
+
Log === null || Log === void 0 ? void 0 : Log.debug(`[ReactNativeBleTransport] detectProtocol: uuid=${uuid} -> V2`);
|
|
1114
|
+
return 'V2';
|
|
1095
1115
|
}
|
|
1096
|
-
this.deviceProtocol.
|
|
1097
|
-
|
|
1098
|
-
return protocol;
|
|
1116
|
+
this.deviceProtocol.delete(uuid);
|
|
1117
|
+
throw this.createProtocolDetectionError();
|
|
1099
1118
|
});
|
|
1100
1119
|
}
|
|
1101
1120
|
resetProbeStateAfterProtocolProbe(uuid, protocol) {
|
|
@@ -1153,6 +1172,7 @@ class ReactNativeBleTransport {
|
|
|
1153
1172
|
return true;
|
|
1154
1173
|
}
|
|
1155
1174
|
catch (error) {
|
|
1175
|
+
this.clearProbeProtocol(uuid, 'V1');
|
|
1156
1176
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Protocol V1 Initialize probe failed:', error);
|
|
1157
1177
|
return false;
|
|
1158
1178
|
}
|
|
@@ -1166,7 +1186,7 @@ class ReactNativeBleTransport {
|
|
|
1166
1186
|
}
|
|
1167
1187
|
this.deviceProtocol.set(uuid, 'V2');
|
|
1168
1188
|
(_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
|
|
1169
|
-
|
|
1189
|
+
const detected = yield transport.probeProtocolV2({
|
|
1170
1190
|
call: (name, data, options) => this.callProtocolV2(uuid, name, data, options),
|
|
1171
1191
|
timeoutMs: PROTOCOL_V2_PROBE_TIMEOUT_MS,
|
|
1172
1192
|
logger: Log,
|
|
@@ -1177,6 +1197,10 @@ class ReactNativeBleTransport {
|
|
|
1177
1197
|
this.resetProtocolV2Frames(uuid);
|
|
1178
1198
|
},
|
|
1179
1199
|
});
|
|
1200
|
+
if (!detected) {
|
|
1201
|
+
this.clearProbeProtocol(uuid, 'V2');
|
|
1202
|
+
}
|
|
1203
|
+
return detected;
|
|
1180
1204
|
});
|
|
1181
1205
|
}
|
|
1182
1206
|
handleProtocolV2Notification(uuid, data) {
|
|
@@ -1380,8 +1404,7 @@ class ReactNativeBleTransport {
|
|
|
1380
1404
|
});
|
|
1381
1405
|
}
|
|
1382
1406
|
getProtocolType(path) {
|
|
1383
|
-
|
|
1384
|
-
return (_a = this.deviceProtocol.get(path)) !== null && _a !== void 0 ? _a : 'V1';
|
|
1407
|
+
return this.deviceProtocol.get(path);
|
|
1385
1408
|
}
|
|
1386
1409
|
}
|
|
1387
1410
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-react-native",
|
|
3
|
-
"version": "1.1.27-alpha.
|
|
3
|
+
"version": "1.1.27-alpha.36",
|
|
4
4
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
"lint:fix": "eslint . --fix"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@onekeyfe/hd-core": "1.1.27-alpha.
|
|
23
|
-
"@onekeyfe/hd-shared": "1.1.27-alpha.
|
|
24
|
-
"@onekeyfe/hd-transport": "1.1.27-alpha.
|
|
22
|
+
"@onekeyfe/hd-core": "1.1.27-alpha.36",
|
|
23
|
+
"@onekeyfe/hd-shared": "1.1.27-alpha.36",
|
|
24
|
+
"@onekeyfe/hd-transport": "1.1.27-alpha.36",
|
|
25
25
|
"@onekeyfe/react-native-ble-utils": "^0.1.4",
|
|
26
26
|
"react-native-ble-plx": "3.5.1"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "1aaff42d7dd10933009ba7e0c0b7324e91d8e993"
|
|
29
29
|
}
|
package/src/index.ts
CHANGED
|
@@ -739,7 +739,12 @@ export default class ReactNativeBleTransport {
|
|
|
739
739
|
|
|
740
740
|
try {
|
|
741
741
|
const data = Buffer.from(c.value as string, 'base64');
|
|
742
|
-
|
|
742
|
+
const protocol = this.deviceProtocol.get(uuid);
|
|
743
|
+
if (!protocol) {
|
|
744
|
+
Log?.debug('monitor data ignored before protocol detection: ', uuid);
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
if (protocol === 'V2') {
|
|
743
748
|
this.handleProtocolV2Notification(uuid, new Uint8Array(data));
|
|
744
749
|
return;
|
|
745
750
|
}
|
|
@@ -856,6 +861,12 @@ export default class ReactNativeBleTransport {
|
|
|
856
861
|
}
|
|
857
862
|
|
|
858
863
|
const protocol = this.getProtocolType(uuid);
|
|
864
|
+
if (!protocol) {
|
|
865
|
+
throw ERRORS.TypedError(
|
|
866
|
+
HardwareErrorCode.RuntimeError,
|
|
867
|
+
`Device protocol has not been detected for ${uuid}`
|
|
868
|
+
);
|
|
869
|
+
}
|
|
859
870
|
// Upload resources on low-end phones may OOM
|
|
860
871
|
if (name === 'ResourceUpdate' || name === 'ResourceAck') {
|
|
861
872
|
Log?.debug('transport-react-native', 'call-', ' name: ', name, ' data: ', {
|
|
@@ -1117,6 +1128,19 @@ export default class ReactNativeBleTransport {
|
|
|
1117
1128
|
);
|
|
1118
1129
|
}
|
|
1119
1130
|
|
|
1131
|
+
private createProtocolDetectionError() {
|
|
1132
|
+
return ERRORS.TypedError(
|
|
1133
|
+
HardwareErrorCode.BleTimeoutError,
|
|
1134
|
+
'Unable to detect BLE protocol: device did not respond to Protocol V1 Initialize or Protocol V2 Ping'
|
|
1135
|
+
);
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
private clearProbeProtocol(uuid: string, protocol: ProtocolType) {
|
|
1139
|
+
if (this.deviceProtocol.get(uuid) === protocol) {
|
|
1140
|
+
this.deviceProtocol.delete(uuid);
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1120
1144
|
private async detectProtocol(
|
|
1121
1145
|
uuid: string,
|
|
1122
1146
|
expectedProtocol?: ProtocolType,
|
|
@@ -1152,17 +1176,22 @@ export default class ReactNativeBleTransport {
|
|
|
1152
1176
|
return 'V2';
|
|
1153
1177
|
}
|
|
1154
1178
|
|
|
1155
|
-
let protocol: ProtocolType = 'V1';
|
|
1156
1179
|
const protocolV1Detected = await this.probeProtocolV1(uuid);
|
|
1157
|
-
if (
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
}
|
|
1180
|
+
if (protocolV1Detected) {
|
|
1181
|
+
this.deviceProtocol.set(uuid, 'V1');
|
|
1182
|
+
Log?.debug(`[ReactNativeBleTransport] detectProtocol: uuid=${uuid} -> V1`);
|
|
1183
|
+
return 'V1';
|
|
1162
1184
|
}
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1185
|
+
|
|
1186
|
+
await this.resetProbeStateAfterProtocolProbe(uuid, 'V1');
|
|
1187
|
+
if (await this.probeProtocolV2(uuid)) {
|
|
1188
|
+
this.deviceProtocol.set(uuid, 'V2');
|
|
1189
|
+
Log?.debug(`[ReactNativeBleTransport] detectProtocol: uuid=${uuid} -> V2`);
|
|
1190
|
+
return 'V2';
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
this.deviceProtocol.delete(uuid);
|
|
1194
|
+
throw this.createProtocolDetectionError();
|
|
1166
1195
|
}
|
|
1167
1196
|
|
|
1168
1197
|
private async resetProbeStateAfterProtocolProbe(uuid: string, protocol: ProtocolType) {
|
|
@@ -1226,6 +1255,7 @@ export default class ReactNativeBleTransport {
|
|
|
1226
1255
|
await this.callProtocolV1(uuid, 'Initialize', {}, { timeoutMs: PROTOCOL_PROBE_TIMEOUT_MS });
|
|
1227
1256
|
return true;
|
|
1228
1257
|
} catch (error) {
|
|
1258
|
+
this.clearProbeProtocol(uuid, 'V1');
|
|
1229
1259
|
Log?.debug('[ReactNativeBleTransport] Protocol V1 Initialize probe failed:', error);
|
|
1230
1260
|
return false;
|
|
1231
1261
|
}
|
|
@@ -1238,7 +1268,7 @@ export default class ReactNativeBleTransport {
|
|
|
1238
1268
|
|
|
1239
1269
|
this.deviceProtocol.set(uuid, 'V2');
|
|
1240
1270
|
this.protocolV2Assemblers.get(uuid)?.reset();
|
|
1241
|
-
|
|
1271
|
+
const detected = await probeProtocolV2Helper({
|
|
1242
1272
|
call: (name: string, data: Record<string, unknown>, options?: TransportCallOptions) =>
|
|
1243
1273
|
this.callProtocolV2(uuid, name, data, options),
|
|
1244
1274
|
timeoutMs: PROTOCOL_V2_PROBE_TIMEOUT_MS,
|
|
@@ -1249,6 +1279,10 @@ export default class ReactNativeBleTransport {
|
|
|
1249
1279
|
this.resetProtocolV2Frames(uuid);
|
|
1250
1280
|
},
|
|
1251
1281
|
});
|
|
1282
|
+
if (!detected) {
|
|
1283
|
+
this.clearProbeProtocol(uuid, 'V2');
|
|
1284
|
+
}
|
|
1285
|
+
return detected;
|
|
1252
1286
|
}
|
|
1253
1287
|
|
|
1254
1288
|
private handleProtocolV2Notification(uuid: string, data: Uint8Array) {
|
|
@@ -1484,7 +1518,7 @@ export default class ReactNativeBleTransport {
|
|
|
1484
1518
|
}
|
|
1485
1519
|
}
|
|
1486
1520
|
|
|
1487
|
-
getProtocolType(path: string): ProtocolType {
|
|
1488
|
-
return this.deviceProtocol.get(path)
|
|
1521
|
+
getProtocolType(path: string): ProtocolType | undefined {
|
|
1522
|
+
return this.deviceProtocol.get(path);
|
|
1489
1523
|
}
|
|
1490
1524
|
}
|