@onekeyfe/hd-core 1.2.0-alpha.152 → 1.2.0-alpha.154
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/__tests__/device-state-events.test.ts +2 -2
- package/__tests__/device-state-mapper.test.ts +2 -11
- package/__tests__/device-utils.test.ts +0 -4
- package/__tests__/protocol-v2.test.ts +7 -7
- package/__tests__/search-devices.test.ts +3 -4
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/index.js +57 -12
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/SearchDevices.ts +2 -2
- package/src/core/index.ts +97 -6
- package/src/device/Device.ts +1 -3
- package/src/device/DeviceStateMapper.ts +2 -2
- package/src/deviceProfile/buildDeviceFeatures.ts +2 -7
- package/src/utils/deviceFeaturesCompat.ts +4 -9
|
@@ -88,9 +88,9 @@ describe('Device state events', () => {
|
|
|
88
88
|
expect(device.getCurrentDeviceType()).toBe(EDeviceType.Pro2);
|
|
89
89
|
expect(device.getCurrentDeviceId()).toBe('wallet-id');
|
|
90
90
|
expect(device.getCurrentSerialNo()).toBe('SERIAL-PRO2');
|
|
91
|
-
expect(device.getCurrentBleName()).toBe('
|
|
91
|
+
expect(device.getCurrentBleName()).toBe('Pro2 1234');
|
|
92
92
|
expect(device.getCurrentLabel()).toBeNull();
|
|
93
|
-
expect((device as any).getCurrentDisplayName()).toBe('
|
|
93
|
+
expect((device as any).getCurrentDisplayName()).toBe('Pro2 1234');
|
|
94
94
|
expect(device.getCurrentPassphraseProtection()).toBe(false);
|
|
95
95
|
expect(device.getCurrentFirmwareVersionString()).toBe('5.1.2');
|
|
96
96
|
expect(device.getCurrentBLEFirmwareVersionString()).toBe('0.0.0');
|
|
@@ -136,7 +136,7 @@ describe('DeviceStateMapper', () => {
|
|
|
136
136
|
expect(patch.identity).toMatchObject({
|
|
137
137
|
deviceType: EDeviceType.Pro2,
|
|
138
138
|
serialNo: 'SERIAL-1',
|
|
139
|
-
bleName: '
|
|
139
|
+
bleName: 'Pro2 1234',
|
|
140
140
|
});
|
|
141
141
|
expect(patch.versions).toMatchObject({
|
|
142
142
|
firmware: '5.0.0',
|
|
@@ -178,16 +178,7 @@ describe('DeviceStateMapper', () => {
|
|
|
178
178
|
coprocessor: { bt_adv_name: 'Pro2 22D8 - Fin' },
|
|
179
179
|
});
|
|
180
180
|
|
|
181
|
-
expect(patch.identity?.bleName).toBe('
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
test('canonicalizes a spaced Pro2 advertisement name from DeviceInfo', () => {
|
|
185
|
-
const patch = mapProtocolV2DeviceInfoToState({
|
|
186
|
-
hw: { Device_type: DeviceType.PRO2, serial_no: 'SERIAL-1' },
|
|
187
|
-
coprocessor: { bt_adv_name: 'Pro 2 0088 - Find My' },
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
expect(patch.identity?.bleName).toBe('Pro 2 0088');
|
|
181
|
+
expect(patch.identity?.bleName).toBe('Pro2 22D8');
|
|
191
182
|
});
|
|
192
183
|
|
|
193
184
|
test('maps the hardware model independently from Protocol V2', () => {
|
|
@@ -131,10 +131,6 @@ describe('device feature selectors', () => {
|
|
|
131
131
|
expect(getDeviceTypeByBleName('Pro2 A1B2')).toBe(EDeviceType.Pro2);
|
|
132
132
|
expect(getDeviceTypeByBleName('Pro2A1B2')).toBe(EDeviceType.Pro2);
|
|
133
133
|
expect(getDeviceTypeByBleName('OneKeyPro2A1B2')).toBe(EDeviceType.Pro2);
|
|
134
|
-
expect(getDeviceTypeByBleName('Pro 2 A1B2')).toBe(EDeviceType.Pro2);
|
|
135
|
-
expect(getDeviceTypeByBleName('Pro 2 0088')).toBe(EDeviceType.Pro2);
|
|
136
|
-
expect(getDeviceTypeByBleName('OneKey Pro 2 A1B2')).toBe(EDeviceType.Pro2);
|
|
137
|
-
expect(getDeviceTypeByBleName('Pro A1B2')).toBe(EDeviceType.Pro);
|
|
138
134
|
});
|
|
139
135
|
|
|
140
136
|
test.each([EDeviceType.Pro2, EDeviceType.Neo])(
|
|
@@ -744,7 +744,7 @@ describe('Protocol V2 feature adapter', () => {
|
|
|
744
744
|
expect(features).toMatchObject({
|
|
745
745
|
deviceId: 'P2-DYNAMIC',
|
|
746
746
|
serialNo: 'P2-STATIC',
|
|
747
|
-
bleName: '
|
|
747
|
+
bleName: 'Pro2 STATIC',
|
|
748
748
|
initialized: true,
|
|
749
749
|
unlocked: true,
|
|
750
750
|
passphraseProtection: true,
|
|
@@ -865,7 +865,7 @@ describe('Protocol V2 feature adapter', () => {
|
|
|
865
865
|
expect(features.boardVersion).toBe('0.1.0');
|
|
866
866
|
expect(features.verify?.boardBuildId).toBe('rom-build');
|
|
867
867
|
expect(features.verify?.boardHash).toBe('0102ff');
|
|
868
|
-
expect(features.bleName).toBe('
|
|
868
|
+
expect(features.bleName).toBe('Pro2 BLE');
|
|
869
869
|
expect(features.bleVersion).toBe('4.5.6');
|
|
870
870
|
expect(features.verify?.bleHash).toBe('0c0d');
|
|
871
871
|
expect(features.se01Version).toBe('7.8.9');
|
|
@@ -2806,9 +2806,9 @@ describe('Protocol V2 feature adapter', () => {
|
|
|
2806
2806
|
|
|
2807
2807
|
expect(device.toMessageObject()).toMatchObject({
|
|
2808
2808
|
serialNo: 'PR9999999999',
|
|
2809
|
-
bleName: '
|
|
2810
|
-
name: '
|
|
2811
|
-
label: '
|
|
2809
|
+
bleName: 'Pro2 6136',
|
|
2810
|
+
name: 'Pro2 6136',
|
|
2811
|
+
label: 'Pro2 6136',
|
|
2812
2812
|
});
|
|
2813
2813
|
expect(device.features?.label).toBeNull();
|
|
2814
2814
|
});
|
|
@@ -2823,8 +2823,8 @@ describe('Protocol V2 feature adapter', () => {
|
|
|
2823
2823
|
|
|
2824
2824
|
expect(device.getCurrentDisplayName()).toBe('My Pro 2');
|
|
2825
2825
|
expect(device.toMessageObject()).toMatchObject({
|
|
2826
|
-
bleName: '
|
|
2827
|
-
name: '
|
|
2826
|
+
bleName: 'Pro2 6136',
|
|
2827
|
+
name: 'Pro2 6136',
|
|
2828
2828
|
label: 'My Pro 2',
|
|
2829
2829
|
});
|
|
2830
2830
|
});
|
|
@@ -151,10 +151,9 @@ describe('SearchDevices', () => {
|
|
|
151
151
|
);
|
|
152
152
|
|
|
153
153
|
test.each([
|
|
154
|
-
['Pro2 A1B2 - Find My', undefined, '
|
|
155
|
-
['Pro2 5E9D - Finde My', undefined, '
|
|
156
|
-
['Pro2 22D8FindMy', undefined, '
|
|
157
|
-
['Pro 2 A1B2 - Find My', undefined, 'Pro 2 A1B2'],
|
|
154
|
+
['Pro2 A1B2 - Find My', undefined, 'Pro2 A1B2'],
|
|
155
|
+
['Pro2 5E9D - Finde My', undefined, 'Pro2 5E9D'],
|
|
156
|
+
['Pro2 22D8FindMy', undefined, 'Pro2 22D8'],
|
|
158
157
|
[undefined, 'OneKey Pro 2 A1B2 - Find My', 'OneKey Pro 2 A1B2'],
|
|
159
158
|
])(
|
|
160
159
|
'BLE discovery normalizes the Find My display name from name=%s localName=%s',
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAoClC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAsB1C,OAAO,eAAe,MAAM,2BAA2B,CAAC;AAYxD,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,UAAU,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAmD,MAAM,WAAW,CAAC;AAI9F,OAAO,KAAK,EACV,6BAA6B,EAG9B,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAWpD,MAAM,MAAM,WAAW,GAAG,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;IAGvC,OAAO,CAAC,sBAAsB,CAAoC;IAElE,OAAO,CAAC,iBAAiB,CAAoB;;IAS7C,OAAO,CAAC,cAAc;IA6BhB,aAAa,CAAC,OAAO,EAAE,WAAW;IAuExC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAOV,gBAAgB;CAiC/B;AAED,eAAO,MAAM,QAAQ,YAIpB,CAAC;AAEF,eAAO,MAAM,aAAa,uBAYzB,CAAC;AAMF,eAAO,MAAM,IAAI,aACL,eAAe,aACd,GAAG,WACL,6BAA6B,8BAiBvC,CAAC;AAEF,eAAO,MAAM,eAAe;SAKrB,eAAe,CAAC,KAAK,CAAC;eAChB,GAAG;;UASf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Device.d.ts","sourceRoot":"","sources":["../../src/device/Device.ts"],"names":[],"mappings":";AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAmB,MAAM,wBAAwB,CAAC;AACjG,OAAO,EAEL,aAAa,
|
|
1
|
+
{"version":3,"file":"Device.d.ts","sourceRoot":"","sources":["../../src/device/Device.ts"],"names":[],"mappings":";AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAmB,MAAM,wBAAwB,CAAC;AACjG,OAAO,EAEL,aAAa,EAQd,MAAM,qBAAqB,CAAC;AAU7B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAalD,OAAO,EACL,KAAK,mBAAmB,EAExB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAE5B,KAAK,MAAM,IAAI,WAAW,EAC1B,iBAAiB,EACjB,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC7B,MAAM,UAAU,CAAC;AACl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E,OAAO,CAAA;KAAE;IAmG3D,0BAA0B,CAC9B,eAAe,CAAC,EAAE,MAAM,EACxB,kBAAkB,CAAC,EAAE,OAAO,EAC5B,mBAAmB,CAAC,EAAE,OAAO,EAC7B,aAAa,CAAC,EAAE,OAAO;CAyD1B;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildDeviceFeatures.d.ts","sourceRoot":"","sources":["../../src/deviceProfile/buildDeviceFeatures.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buildDeviceFeatures.d.ts","sourceRoot":"","sources":["../../src/deviceProfile/buildDeviceFeatures.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAEV,YAAY,EACZ,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,KAAK,EAAsB,QAAQ,EAAE,MAAM,UAAU,CAAC;AA6C7D,eAAO,MAAM,8BAA8B,uBACrB,cAAc,aACvB,QAAQ,KAClB,QA+HF,CAAC;AASF,eAAO,MAAM,8BAA8B;;;;;MAUvC,QAsLH,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -419,8 +419,7 @@ const resolveDeviceBleName = (features) => {
|
|
|
419
419
|
if (!features)
|
|
420
420
|
return null;
|
|
421
421
|
const compatible = asCompatibleFeatures(features);
|
|
422
|
-
|
|
423
|
-
return bleName ? hdShared.canonicalizePro2BleAdvertisementName(bleName) : null;
|
|
422
|
+
return ((_a = firstNonEmptyString(compatible.bleName, compatible.onekey_ble_name, compatible.ble_name)) !== null && _a !== void 0 ? _a : null);
|
|
424
423
|
};
|
|
425
424
|
const resolveDeviceFirmwareVersion = (features) => {
|
|
426
425
|
var _a;
|
|
@@ -44532,7 +44531,7 @@ const mapProtocolV2DeviceInfoToState = (info, mode = 'unknown') => {
|
|
|
44532
44531
|
vendor: 'onekey.so',
|
|
44533
44532
|
serialNo: (_b = info.hw) === null || _b === void 0 ? void 0 : _b.serial_no,
|
|
44534
44533
|
bleName: ((_c = info.coprocessor) === null || _c === void 0 ? void 0 : _c.bt_adv_name)
|
|
44535
|
-
? hdShared.
|
|
44534
|
+
? hdShared.normalizePro2FindMyAdvertisementName(info.coprocessor.bt_adv_name)
|
|
44536
44535
|
: undefined,
|
|
44537
44536
|
deviceId: loader ? null : undefined,
|
|
44538
44537
|
}),
|
|
@@ -45413,8 +45412,7 @@ class Device extends events.exports {
|
|
|
45413
45412
|
}
|
|
45414
45413
|
getCurrentBleName() {
|
|
45415
45414
|
var _a, _b;
|
|
45416
|
-
|
|
45417
|
-
return bleName ? hdShared.canonicalizePro2BleAdvertisementName(bleName) : null;
|
|
45415
|
+
return (_b = (_a = this.state) === null || _a === void 0 ? void 0 : _a.identity.bleName) !== null && _b !== void 0 ? _b : null;
|
|
45418
45416
|
}
|
|
45419
45417
|
getCurrentLabel() {
|
|
45420
45418
|
var _a, _b;
|
|
@@ -46925,7 +46923,7 @@ class SearchDevices extends BaseMethod {
|
|
|
46925
46923
|
if (!seenIds.has(lowerId)) {
|
|
46926
46924
|
seenIds.add(lowerId);
|
|
46927
46925
|
const rawBleName = (_e = (_d = device.name) !== null && _d !== void 0 ? _d : device.localName) !== null && _e !== void 0 ? _e : '';
|
|
46928
|
-
const bleName = hdShared.
|
|
46926
|
+
const bleName = hdShared.normalizePro2FindMyAdvertisementName(rawBleName);
|
|
46929
46927
|
devices.push(Object.assign(Object.assign({}, device), { connectId: device.id, serialNo: null, uuid: '', deviceId: null, name: bleName || device.name, deviceType: getDeviceTypeByBleName(bleName) }));
|
|
46930
46928
|
}
|
|
46931
46929
|
}
|
|
@@ -65218,6 +65216,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
65218
65216
|
if ((_g = method.payload) === null || _g === void 0 ? void 0 : _g.onlyConnectBleDevice) {
|
|
65219
65217
|
preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
|
|
65220
65218
|
Log.debug('Call API - only connect ble device: ', device === null || device === void 0 ? void 0 : device.mainId);
|
|
65219
|
+
requestQueue.releaseTask(method.responseID);
|
|
65221
65220
|
return createResponseMessage(method.responseID, true, null);
|
|
65222
65221
|
}
|
|
65223
65222
|
Log.debug('Call API - setDevice: ', device.mainId);
|
|
@@ -65593,7 +65592,31 @@ function isMissingDetectedProtocolV2Error(method, error) {
|
|
|
65593
65592
|
typeof typedError.message === 'string' &&
|
|
65594
65593
|
typedError.message.includes('Device protocol has not been detected'));
|
|
65595
65594
|
}
|
|
65596
|
-
|
|
65595
|
+
const BLE_ACQUIRE_DEADLINE_MS = 60 * 1000;
|
|
65596
|
+
function raceBleAcquire(acquirePromise, abortSignal) {
|
|
65597
|
+
return new Promise((resolve, reject) => {
|
|
65598
|
+
let settled = false;
|
|
65599
|
+
const settle = (fn) => {
|
|
65600
|
+
if (settled)
|
|
65601
|
+
return;
|
|
65602
|
+
settled = true;
|
|
65603
|
+
clearTimeout(deadline);
|
|
65604
|
+
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener('abort', onAbort);
|
|
65605
|
+
fn();
|
|
65606
|
+
};
|
|
65607
|
+
const onAbort = () => settle(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled)));
|
|
65608
|
+
const deadline = setTimeout(() => settle(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, `BLE acquire exceeded ${BLE_ACQUIRE_DEADLINE_MS}ms deadline`))), BLE_ACQUIRE_DEADLINE_MS);
|
|
65609
|
+
acquirePromise.then(value => settle(() => resolve(value)), error => settle(() => reject(error)));
|
|
65610
|
+
if (abortSignal) {
|
|
65611
|
+
if (abortSignal.aborted) {
|
|
65612
|
+
onAbort();
|
|
65613
|
+
return;
|
|
65614
|
+
}
|
|
65615
|
+
abortSignal.addEventListener('abort', onAbort);
|
|
65616
|
+
}
|
|
65617
|
+
});
|
|
65618
|
+
}
|
|
65619
|
+
function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
|
|
65597
65620
|
var _a;
|
|
65598
65621
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65599
65622
|
try {
|
|
@@ -65608,9 +65631,31 @@ function connectDeviceForBle(method, device, retryCount = 0) {
|
|
|
65608
65631
|
!device.commands ||
|
|
65609
65632
|
device.commands.disposed;
|
|
65610
65633
|
if (shouldAcquire) {
|
|
65611
|
-
|
|
65612
|
-
|
|
65613
|
-
|
|
65634
|
+
const useAcquireGuards = DataManager.getSettings('env') === 'desktop-web-ble';
|
|
65635
|
+
if (useAcquireGuards && (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
|
|
65636
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
|
|
65637
|
+
}
|
|
65638
|
+
if (!useAcquireGuards) {
|
|
65639
|
+
yield device.acquire(method.payload.connectProtocol, {
|
|
65640
|
+
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
65641
|
+
});
|
|
65642
|
+
}
|
|
65643
|
+
else {
|
|
65644
|
+
try {
|
|
65645
|
+
yield raceBleAcquire(device.acquire(method.payload.connectProtocol, {
|
|
65646
|
+
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
65647
|
+
}), abortSignal);
|
|
65648
|
+
}
|
|
65649
|
+
catch (err) {
|
|
65650
|
+
if (err.errorCode === hdShared.HardwareErrorCode.BleTimeoutError &&
|
|
65651
|
+
device.mainId &&
|
|
65652
|
+
device.deviceConnector) {
|
|
65653
|
+
yield device.deviceConnector.disconnect(device.mainId).catch(() => undefined);
|
|
65654
|
+
device.markTransportDisconnected();
|
|
65655
|
+
}
|
|
65656
|
+
throw err;
|
|
65657
|
+
}
|
|
65658
|
+
}
|
|
65614
65659
|
}
|
|
65615
65660
|
if ((_a = method.payload) === null || _a === void 0 ? void 0 : _a.onlyConnectBleDevice) {
|
|
65616
65661
|
if (shouldAcquire) {
|
|
@@ -65641,7 +65686,7 @@ function connectDeviceForBle(method, device, retryCount = 0) {
|
|
|
65641
65686
|
const nextRetry = retryCount + 1;
|
|
65642
65687
|
Log.debug(`Bluetooth connection will retry, retry count: ${nextRetry}`);
|
|
65643
65688
|
yield wait(3000);
|
|
65644
|
-
yield connectDeviceForBle(method, device, nextRetry);
|
|
65689
|
+
yield connectDeviceForBle(method, device, abortSignal, nextRetry);
|
|
65645
65690
|
}
|
|
65646
65691
|
else {
|
|
65647
65692
|
throw err;
|
|
@@ -65726,7 +65771,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
65726
65771
|
if (tryCount === 1) {
|
|
65727
65772
|
device.beginConnectionAttempt();
|
|
65728
65773
|
}
|
|
65729
|
-
yield connectDeviceForBle(method, device);
|
|
65774
|
+
yield connectDeviceForBle(method, device, abortSignal);
|
|
65730
65775
|
}
|
|
65731
65776
|
resolve(device);
|
|
65732
65777
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deviceFeaturesCompat.d.ts","sourceRoot":"","sources":["../../src/utils/deviceFeaturesCompat.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"deviceFeaturesCompat.d.ts","sourceRoot":"","sources":["../../src/utils/deviceFeaturesCompat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGjE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEtD,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;AAoB5D,eAAO,MAAM,qBAAqB,cAAe,mBAAmB,KAAG,MAWtE,CAAC;AAEF,eAAO,MAAM,2BAA2B,cAAe,mBAAmB,KAAG,OAI5E,CAAC;AAEF,eAAO,MAAM,iBAAiB,cAAe,mBAAmB,KAAG,WAqDlE,CAAC;AAEF,eAAO,MAAM,yBAAyB,cAAe,mBAAmB,KAAG,aAsB1E,CAAC;AAEF,eAAO,MAAM,oBAAoB,cAAe,mBAAmB,KAAG,MAAM,GAAG,IAM9E,CAAC;AAEF,eAAO,MAAM,4BAA4B,cAAe,mBAAmB,KAAG,MAAM,GAAG,IAgBtF,CAAC;AAEF,eAAO,MAAM,8BAA8B,cAAe,mBAAmB,KAAG,MAAM,GAAG,IAiBxF,CAAC;AAEF,eAAO,MAAM,yBAAyB,cAAe,mBAAmB,KAAG,MAAM,GAAG,IAUnF,CAAC;AAEF,eAAO,MAAM,+BAA+B,cAAe,mBAAmB,KAAG,MAAM,GAAG,IASzF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.154",
|
|
4
4
|
"description": "Core processes and APIs for communicating with OneKey hardware devices.",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
29
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.154",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.154",
|
|
30
30
|
"axios": "1.15.2",
|
|
31
31
|
"bignumber.js": "^9.0.2",
|
|
32
32
|
"buffer": "^6.0.3",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@types/w3c-web-usb": "^1.0.10",
|
|
47
47
|
"@types/web-bluetooth": "^0.0.21"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "0b81bf264b2b33e00550b1008264c02e0a049b68"
|
|
50
50
|
}
|
package/src/api/SearchDevices.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { normalizePro2FindMyAdvertisementName } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
3
|
import { BaseMethod } from './BaseMethod';
|
|
4
4
|
import TransportManager from '../data-manager/TransportManager';
|
|
@@ -40,7 +40,7 @@ export default class SearchDevices extends BaseMethod {
|
|
|
40
40
|
seenIds.add(lowerId);
|
|
41
41
|
const rawBleName =
|
|
42
42
|
device.name ?? (device as unknown as { localName?: string }).localName ?? '';
|
|
43
|
-
const bleName =
|
|
43
|
+
const bleName = normalizePro2FindMyAdvertisementName(rawBleName);
|
|
44
44
|
devices.push({
|
|
45
45
|
...device,
|
|
46
46
|
connectId: device.id,
|
package/src/core/index.ts
CHANGED
|
@@ -415,6 +415,10 @@ const onCallDevice = async (
|
|
|
415
415
|
if (method.payload?.onlyConnectBleDevice) {
|
|
416
416
|
preWarmCallbackTask?.resolve();
|
|
417
417
|
Log.debug('Call API - only connect ble device: ', device?.mainId);
|
|
418
|
+
// This early return bypasses the normal-path releaseTask at the end of the
|
|
419
|
+
// call; without it the task leaks and haunts every later queue snapshot
|
|
420
|
+
// and cancel sweep (field log: a completed task lingered for 6 minutes).
|
|
421
|
+
requestQueue.releaseTask(method.responseID);
|
|
418
422
|
return createResponseMessage(method.responseID, true, null);
|
|
419
423
|
}
|
|
420
424
|
|
|
@@ -954,7 +958,60 @@ export function isMissingDetectedProtocolV2Error(method: BaseMethod, error: unkn
|
|
|
954
958
|
* If the Bluetooth connection times out, retry up to 6 times
|
|
955
959
|
* @param retryCount - Current retry count (default 0)
|
|
956
960
|
*/
|
|
957
|
-
|
|
961
|
+
// device.acquire awaits a transport reply with no deadline of its own; a
|
|
962
|
+
// transport that never settles (field case: Electron main lost an IPC reply,
|
|
963
|
+
// "reply was never sent" after 5 minutes) hangs the call forever and cancel()
|
|
964
|
+
// only takes effect at poll checkpoints. Race acquire against a deadline and
|
|
965
|
+
// the caller's abort signal so the hang is bounded and cancel is immediate.
|
|
966
|
+
const BLE_ACQUIRE_DEADLINE_MS = 60 * 1000;
|
|
967
|
+
|
|
968
|
+
function raceBleAcquire<T>(acquirePromise: Promise<T>, abortSignal?: AbortSignal): Promise<T> {
|
|
969
|
+
return new Promise<T>((resolve, reject) => {
|
|
970
|
+
let settled = false;
|
|
971
|
+
const settle = (fn: () => void) => {
|
|
972
|
+
if (settled) return;
|
|
973
|
+
settled = true;
|
|
974
|
+
clearTimeout(deadline);
|
|
975
|
+
abortSignal?.removeEventListener('abort', onAbort);
|
|
976
|
+
fn();
|
|
977
|
+
};
|
|
978
|
+
const onAbort = () =>
|
|
979
|
+
settle(() => reject(ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled)));
|
|
980
|
+
const deadline = setTimeout(
|
|
981
|
+
() =>
|
|
982
|
+
settle(() =>
|
|
983
|
+
reject(
|
|
984
|
+
ERRORS.TypedError(
|
|
985
|
+
HardwareErrorCode.BleTimeoutError,
|
|
986
|
+
`BLE acquire exceeded ${BLE_ACQUIRE_DEADLINE_MS}ms deadline`
|
|
987
|
+
)
|
|
988
|
+
)
|
|
989
|
+
),
|
|
990
|
+
BLE_ACQUIRE_DEADLINE_MS
|
|
991
|
+
);
|
|
992
|
+
// Attach before any early return so a late settlement of acquirePromise
|
|
993
|
+
// is always consumed — an abort or deadline must never leave the acquire
|
|
994
|
+
// rejection unhandled.
|
|
995
|
+
acquirePromise.then(
|
|
996
|
+
value => settle(() => resolve(value)),
|
|
997
|
+
error => settle(() => reject(error))
|
|
998
|
+
);
|
|
999
|
+
if (abortSignal) {
|
|
1000
|
+
if (abortSignal.aborted) {
|
|
1001
|
+
onAbort();
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
abortSignal.addEventListener('abort', onAbort);
|
|
1005
|
+
}
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
async function connectDeviceForBle(
|
|
1010
|
+
method: BaseMethod,
|
|
1011
|
+
device: Device,
|
|
1012
|
+
abortSignal?: AbortSignal,
|
|
1013
|
+
retryCount = 0
|
|
1014
|
+
) {
|
|
958
1015
|
try {
|
|
959
1016
|
if (device.wasInterruptedByUser()) {
|
|
960
1017
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceInterruptedFromUser);
|
|
@@ -968,9 +1025,43 @@ async function connectDeviceForBle(method: BaseMethod, device: Device, retryCoun
|
|
|
968
1025
|
!device.commands ||
|
|
969
1026
|
device.commands.disposed;
|
|
970
1027
|
if (shouldAcquire) {
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
1028
|
+
// The deadline/abort guards are scoped to the desktop electron
|
|
1029
|
+
// transport: its IPC acquire is the only path with a proven
|
|
1030
|
+
// never-settling failure mode, while react-native/lowlevel acquire may
|
|
1031
|
+
// legitimately block on a user-driven system bonding prompt for longer
|
|
1032
|
+
// than any sane deadline. Other envs keep the plain acquire unchanged.
|
|
1033
|
+
const useAcquireGuards = DataManager.getSettings('env') === 'desktop-web-ble';
|
|
1034
|
+
// A cancel landing during the retry backoff must not start a new acquire.
|
|
1035
|
+
if (useAcquireGuards && abortSignal?.aborted) {
|
|
1036
|
+
throw ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled);
|
|
1037
|
+
}
|
|
1038
|
+
if (!useAcquireGuards) {
|
|
1039
|
+
await device.acquire(method.payload.connectProtocol, {
|
|
1040
|
+
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
1041
|
+
});
|
|
1042
|
+
} else {
|
|
1043
|
+
try {
|
|
1044
|
+
await raceBleAcquire(
|
|
1045
|
+
device.acquire(method.payload.connectProtocol, {
|
|
1046
|
+
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
1047
|
+
}),
|
|
1048
|
+
abortSignal
|
|
1049
|
+
);
|
|
1050
|
+
} catch (err) {
|
|
1051
|
+
// A deadline hit means the transport is wedged mid-acquire; drop the
|
|
1052
|
+
// link before the retry so it cold-connects instead of stacking a
|
|
1053
|
+
// second connect onto the half-open one.
|
|
1054
|
+
if (
|
|
1055
|
+
err.errorCode === HardwareErrorCode.BleTimeoutError &&
|
|
1056
|
+
device.mainId &&
|
|
1057
|
+
device.deviceConnector
|
|
1058
|
+
) {
|
|
1059
|
+
await device.deviceConnector.disconnect(device.mainId).catch(() => undefined);
|
|
1060
|
+
device.markTransportDisconnected();
|
|
1061
|
+
}
|
|
1062
|
+
throw err;
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
974
1065
|
}
|
|
975
1066
|
if (method.payload?.onlyConnectBleDevice) {
|
|
976
1067
|
if (shouldAcquire) {
|
|
@@ -1010,7 +1101,7 @@ async function connectDeviceForBle(method: BaseMethod, device: Device, retryCoun
|
|
|
1010
1101
|
const nextRetry = retryCount + 1;
|
|
1011
1102
|
Log.debug(`Bluetooth connection will retry, retry count: ${nextRetry}`);
|
|
1012
1103
|
await wait(3000);
|
|
1013
|
-
await connectDeviceForBle(method, device, nextRetry);
|
|
1104
|
+
await connectDeviceForBle(method, device, abortSignal, nextRetry);
|
|
1014
1105
|
} else {
|
|
1015
1106
|
throw err;
|
|
1016
1107
|
}
|
|
@@ -1120,7 +1211,7 @@ const ensureConnected = async (
|
|
|
1120
1211
|
if (tryCount === 1) {
|
|
1121
1212
|
device.beginConnectionAttempt();
|
|
1122
1213
|
}
|
|
1123
|
-
await connectDeviceForBle(method, device);
|
|
1214
|
+
await connectDeviceForBle(method, device, abortSignal);
|
|
1124
1215
|
}
|
|
1125
1216
|
resolve(device);
|
|
1126
1217
|
return;
|
package/src/device/Device.ts
CHANGED
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
ERROR_CODES_REQUIRE_RELEASE,
|
|
10
10
|
HardwareError,
|
|
11
11
|
HardwareErrorCode,
|
|
12
|
-
canonicalizePro2BleAdvertisementName,
|
|
13
12
|
createDeferred,
|
|
14
13
|
createDeviceNotSupportMethodError,
|
|
15
14
|
} from '@onekeyfe/hd-shared';
|
|
@@ -673,8 +672,7 @@ export class Device extends EventEmitter {
|
|
|
673
672
|
}
|
|
674
673
|
|
|
675
674
|
getCurrentBleName() {
|
|
676
|
-
|
|
677
|
-
return bleName ? canonicalizePro2BleAdvertisementName(bleName) : null;
|
|
675
|
+
return this.state?.identity.bleName ?? null;
|
|
678
676
|
}
|
|
679
677
|
|
|
680
678
|
getCurrentLabel() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EFirmwareType,
|
|
1
|
+
import { EFirmwareType, normalizePro2FindMyAdvertisementName } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
3
|
import { buildProtocolV1FeaturesPayload } from '../deviceProfile/buildDeviceFeatures';
|
|
4
4
|
import { resolveProtocolV2DeviceIdentity } from '../deviceProfile/protocolV2DeviceIdentity';
|
|
@@ -248,7 +248,7 @@ export const mapProtocolV2DeviceInfoToState = (
|
|
|
248
248
|
vendor: 'onekey.so',
|
|
249
249
|
serialNo: info.hw?.serial_no,
|
|
250
250
|
bleName: info.coprocessor?.bt_adv_name
|
|
251
|
-
?
|
|
251
|
+
? normalizePro2FindMyAdvertisementName(info.coprocessor.bt_adv_name)
|
|
252
252
|
: undefined,
|
|
253
253
|
deviceId: loader ? null : undefined,
|
|
254
254
|
}),
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EDeviceType,
|
|
3
|
-
EFirmwareType,
|
|
4
|
-
canonicalizePro2BleAdvertisementName,
|
|
5
|
-
} from '@onekeyfe/hd-shared';
|
|
1
|
+
import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
|
|
6
2
|
|
|
7
3
|
import {
|
|
8
4
|
resolveDeviceBleFirmwareVersion,
|
|
@@ -249,8 +245,7 @@ export const buildProtocolV2FeaturesPayload = ({
|
|
|
249
245
|
const deviceId = status?.device_id ?? cached?.deviceId ?? null;
|
|
250
246
|
const serialNo = firstValue(incomingSerialNo, cached?.serialNo) ?? '';
|
|
251
247
|
const label = cached?.label ?? null;
|
|
252
|
-
const
|
|
253
|
-
const bleName = rawBleName ? canonicalizePro2BleAdvertisementName(rawBleName) : rawBleName;
|
|
248
|
+
const bleName = firstValue(info?.coprocessor?.bt_adv_name, cached?.bleName);
|
|
254
249
|
const initialized = firstValue(status?.init_states, cached?.initialized) ?? null;
|
|
255
250
|
// passphrase_enabled from a locked Pro2 is not authoritative. Only DeviceStatus
|
|
256
251
|
// after PIN unlock can determine the final passphrase setting.
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EDeviceType,
|
|
3
|
-
EFirmwareType,
|
|
4
|
-
canonicalizePro2BleAdvertisementName,
|
|
5
|
-
} from '@onekeyfe/hd-shared';
|
|
1
|
+
import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
|
|
6
2
|
import { Enum_Capability } from '@onekeyfe/hd-transport';
|
|
7
3
|
|
|
8
4
|
import type { PROTO } from '../constants';
|
|
@@ -129,10 +125,9 @@ export const resolveDeviceFirmwareType = (features?: DeviceFeaturesInput): EFirm
|
|
|
129
125
|
export const resolveDeviceBleName = (features?: DeviceFeaturesInput): string | null => {
|
|
130
126
|
if (!features) return null;
|
|
131
127
|
const compatible = asCompatibleFeatures(features);
|
|
132
|
-
|
|
133
|
-
firstNonEmptyString(compatible.bleName, compatible.onekey_ble_name, compatible.ble_name) ??
|
|
134
|
-
|
|
135
|
-
return bleName ? canonicalizePro2BleAdvertisementName(bleName) : null;
|
|
128
|
+
return (
|
|
129
|
+
firstNonEmptyString(compatible.bleName, compatible.onekey_ble_name, compatible.ble_name) ?? null
|
|
130
|
+
);
|
|
136
131
|
};
|
|
137
132
|
|
|
138
133
|
export const resolveDeviceFirmwareVersion = (features?: DeviceFeaturesInput): string | null => {
|