@onekeyfe/hd-core 1.2.0-alpha.151 → 1.2.0-alpha.152
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 +11 -2
- package/__tests__/device-utils.test.ts +4 -0
- package/__tests__/protocol-v2.test.ts +7 -7
- package/__tests__/search-devices.test.ts +4 -3
- 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 +12 -57
- 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 +6 -97
- package/src/device/Device.ts +3 -1
- package/src/device/DeviceStateMapper.ts +2 -2
- package/src/deviceProfile/buildDeviceFeatures.ts +7 -2
- package/src/utils/deviceFeaturesCompat.ts +9 -4
|
@@ -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('Pro 2 1234');
|
|
92
92
|
expect(device.getCurrentLabel()).toBeNull();
|
|
93
|
-
expect((device as any).getCurrentDisplayName()).toBe('
|
|
93
|
+
expect((device as any).getCurrentDisplayName()).toBe('Pro 2 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: 'Pro 2 1234',
|
|
140
140
|
});
|
|
141
141
|
expect(patch.versions).toMatchObject({
|
|
142
142
|
firmware: '5.0.0',
|
|
@@ -178,7 +178,16 @@ describe('DeviceStateMapper', () => {
|
|
|
178
178
|
coprocessor: { bt_adv_name: 'Pro2 22D8 - Fin' },
|
|
179
179
|
});
|
|
180
180
|
|
|
181
|
-
expect(patch.identity?.bleName).toBe('
|
|
181
|
+
expect(patch.identity?.bleName).toBe('Pro 2 22D8');
|
|
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');
|
|
182
191
|
});
|
|
183
192
|
|
|
184
193
|
test('maps the hardware model independently from Protocol V2', () => {
|
|
@@ -131,6 +131,10 @@ 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);
|
|
134
138
|
});
|
|
135
139
|
|
|
136
140
|
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: 'Pro 2 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('Pro 2 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: 'Pro 2 6136',
|
|
2810
|
+
name: 'Pro 2 6136',
|
|
2811
|
+
label: 'Pro 2 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: 'Pro 2 6136',
|
|
2827
|
+
name: 'Pro 2 6136',
|
|
2828
2828
|
label: 'My Pro 2',
|
|
2829
2829
|
});
|
|
2830
2830
|
});
|
|
@@ -151,9 +151,10 @@ 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, '
|
|
154
|
+
['Pro2 A1B2 - Find My', undefined, 'Pro 2 A1B2'],
|
|
155
|
+
['Pro2 5E9D - Finde My', undefined, 'Pro 2 5E9D'],
|
|
156
|
+
['Pro2 22D8FindMy', undefined, 'Pro 2 22D8'],
|
|
157
|
+
['Pro 2 A1B2 - Find My', undefined, 'Pro 2 A1B2'],
|
|
157
158
|
[undefined, 'OneKey Pro 2 A1B2 - Find My', 'OneKey Pro 2 A1B2'],
|
|
158
159
|
])(
|
|
159
160
|
'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,M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AAc,CAAC,CAAgB;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,EASd,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,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WAAW,CAAC,EAAE,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":"AAmBA,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,QAuLH,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -419,7 +419,8 @@ const resolveDeviceBleName = (features) => {
|
|
|
419
419
|
if (!features)
|
|
420
420
|
return null;
|
|
421
421
|
const compatible = asCompatibleFeatures(features);
|
|
422
|
-
|
|
422
|
+
const bleName = (_a = firstNonEmptyString(compatible.bleName, compatible.onekey_ble_name, compatible.ble_name)) !== null && _a !== void 0 ? _a : null;
|
|
423
|
+
return bleName ? hdShared.canonicalizePro2BleAdvertisementName(bleName) : null;
|
|
423
424
|
};
|
|
424
425
|
const resolveDeviceFirmwareVersion = (features) => {
|
|
425
426
|
var _a;
|
|
@@ -44531,7 +44532,7 @@ const mapProtocolV2DeviceInfoToState = (info, mode = 'unknown') => {
|
|
|
44531
44532
|
vendor: 'onekey.so',
|
|
44532
44533
|
serialNo: (_b = info.hw) === null || _b === void 0 ? void 0 : _b.serial_no,
|
|
44533
44534
|
bleName: ((_c = info.coprocessor) === null || _c === void 0 ? void 0 : _c.bt_adv_name)
|
|
44534
|
-
? hdShared.
|
|
44535
|
+
? hdShared.canonicalizePro2BleAdvertisementName(info.coprocessor.bt_adv_name)
|
|
44535
44536
|
: undefined,
|
|
44536
44537
|
deviceId: loader ? null : undefined,
|
|
44537
44538
|
}),
|
|
@@ -45412,7 +45413,8 @@ class Device extends events.exports {
|
|
|
45412
45413
|
}
|
|
45413
45414
|
getCurrentBleName() {
|
|
45414
45415
|
var _a, _b;
|
|
45415
|
-
|
|
45416
|
+
const bleName = (_b = (_a = this.state) === null || _a === void 0 ? void 0 : _a.identity.bleName) !== null && _b !== void 0 ? _b : null;
|
|
45417
|
+
return bleName ? hdShared.canonicalizePro2BleAdvertisementName(bleName) : null;
|
|
45416
45418
|
}
|
|
45417
45419
|
getCurrentLabel() {
|
|
45418
45420
|
var _a, _b;
|
|
@@ -46923,7 +46925,7 @@ class SearchDevices extends BaseMethod {
|
|
|
46923
46925
|
if (!seenIds.has(lowerId)) {
|
|
46924
46926
|
seenIds.add(lowerId);
|
|
46925
46927
|
const rawBleName = (_e = (_d = device.name) !== null && _d !== void 0 ? _d : device.localName) !== null && _e !== void 0 ? _e : '';
|
|
46926
|
-
const bleName = hdShared.
|
|
46928
|
+
const bleName = hdShared.canonicalizePro2BleAdvertisementName(rawBleName);
|
|
46927
46929
|
devices.push(Object.assign(Object.assign({}, device), { connectId: device.id, serialNo: null, uuid: '', deviceId: null, name: bleName || device.name, deviceType: getDeviceTypeByBleName(bleName) }));
|
|
46928
46930
|
}
|
|
46929
46931
|
}
|
|
@@ -65216,7 +65218,6 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
65216
65218
|
if ((_g = method.payload) === null || _g === void 0 ? void 0 : _g.onlyConnectBleDevice) {
|
|
65217
65219
|
preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
|
|
65218
65220
|
Log.debug('Call API - only connect ble device: ', device === null || device === void 0 ? void 0 : device.mainId);
|
|
65219
|
-
requestQueue.releaseTask(method.responseID);
|
|
65220
65221
|
return createResponseMessage(method.responseID, true, null);
|
|
65221
65222
|
}
|
|
65222
65223
|
Log.debug('Call API - setDevice: ', device.mainId);
|
|
@@ -65592,31 +65593,7 @@ function isMissingDetectedProtocolV2Error(method, error) {
|
|
|
65592
65593
|
typeof typedError.message === 'string' &&
|
|
65593
65594
|
typedError.message.includes('Device protocol has not been detected'));
|
|
65594
65595
|
}
|
|
65595
|
-
|
|
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) {
|
|
65596
|
+
function connectDeviceForBle(method, device, retryCount = 0) {
|
|
65620
65597
|
var _a;
|
|
65621
65598
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65622
65599
|
try {
|
|
@@ -65631,31 +65608,9 @@ function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
|
|
|
65631
65608
|
!device.commands ||
|
|
65632
65609
|
device.commands.disposed;
|
|
65633
65610
|
if (shouldAcquire) {
|
|
65634
|
-
|
|
65635
|
-
|
|
65636
|
-
|
|
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
|
-
}
|
|
65611
|
+
yield device.acquire(method.payload.connectProtocol, {
|
|
65612
|
+
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
65613
|
+
});
|
|
65659
65614
|
}
|
|
65660
65615
|
if ((_a = method.payload) === null || _a === void 0 ? void 0 : _a.onlyConnectBleDevice) {
|
|
65661
65616
|
if (shouldAcquire) {
|
|
@@ -65686,7 +65641,7 @@ function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
|
|
|
65686
65641
|
const nextRetry = retryCount + 1;
|
|
65687
65642
|
Log.debug(`Bluetooth connection will retry, retry count: ${nextRetry}`);
|
|
65688
65643
|
yield wait(3000);
|
|
65689
|
-
yield connectDeviceForBle(method, device,
|
|
65644
|
+
yield connectDeviceForBle(method, device, nextRetry);
|
|
65690
65645
|
}
|
|
65691
65646
|
else {
|
|
65692
65647
|
throw err;
|
|
@@ -65771,7 +65726,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
65771
65726
|
if (tryCount === 1) {
|
|
65772
65727
|
device.beginConnectionAttempt();
|
|
65773
65728
|
}
|
|
65774
|
-
yield connectDeviceForBle(method, device
|
|
65729
|
+
yield connectDeviceForBle(method, device);
|
|
65775
65730
|
}
|
|
65776
65731
|
resolve(device);
|
|
65777
65732
|
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,EAEL,aAAa,EAEd,MAAM,qBAAqB,CAAC;AAG7B,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,IAO9E,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.152",
|
|
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.152",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.152",
|
|
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": "cbd3c7de0d95f910c98165467da53035f16e9d40"
|
|
50
50
|
}
|
package/src/api/SearchDevices.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { canonicalizePro2BleAdvertisementName } 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 = canonicalizePro2BleAdvertisementName(rawBleName);
|
|
44
44
|
devices.push({
|
|
45
45
|
...device,
|
|
46
46
|
connectId: device.id,
|
package/src/core/index.ts
CHANGED
|
@@ -415,10 +415,6 @@ 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);
|
|
422
418
|
return createResponseMessage(method.responseID, true, null);
|
|
423
419
|
}
|
|
424
420
|
|
|
@@ -958,60 +954,7 @@ export function isMissingDetectedProtocolV2Error(method: BaseMethod, error: unkn
|
|
|
958
954
|
* If the Bluetooth connection times out, retry up to 6 times
|
|
959
955
|
* @param retryCount - Current retry count (default 0)
|
|
960
956
|
*/
|
|
961
|
-
|
|
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
|
-
) {
|
|
957
|
+
async function connectDeviceForBle(method: BaseMethod, device: Device, retryCount = 0) {
|
|
1015
958
|
try {
|
|
1016
959
|
if (device.wasInterruptedByUser()) {
|
|
1017
960
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceInterruptedFromUser);
|
|
@@ -1025,43 +968,9 @@ async function connectDeviceForBle(
|
|
|
1025
968
|
!device.commands ||
|
|
1026
969
|
device.commands.disposed;
|
|
1027
970
|
if (shouldAcquire) {
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
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
|
-
}
|
|
971
|
+
await device.acquire(method.payload.connectProtocol, {
|
|
972
|
+
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
973
|
+
});
|
|
1065
974
|
}
|
|
1066
975
|
if (method.payload?.onlyConnectBleDevice) {
|
|
1067
976
|
if (shouldAcquire) {
|
|
@@ -1101,7 +1010,7 @@ async function connectDeviceForBle(
|
|
|
1101
1010
|
const nextRetry = retryCount + 1;
|
|
1102
1011
|
Log.debug(`Bluetooth connection will retry, retry count: ${nextRetry}`);
|
|
1103
1012
|
await wait(3000);
|
|
1104
|
-
await connectDeviceForBle(method, device,
|
|
1013
|
+
await connectDeviceForBle(method, device, nextRetry);
|
|
1105
1014
|
} else {
|
|
1106
1015
|
throw err;
|
|
1107
1016
|
}
|
|
@@ -1211,7 +1120,7 @@ const ensureConnected = async (
|
|
|
1211
1120
|
if (tryCount === 1) {
|
|
1212
1121
|
device.beginConnectionAttempt();
|
|
1213
1122
|
}
|
|
1214
|
-
await connectDeviceForBle(method, device
|
|
1123
|
+
await connectDeviceForBle(method, device);
|
|
1215
1124
|
}
|
|
1216
1125
|
resolve(device);
|
|
1217
1126
|
return;
|
package/src/device/Device.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
ERROR_CODES_REQUIRE_RELEASE,
|
|
10
10
|
HardwareError,
|
|
11
11
|
HardwareErrorCode,
|
|
12
|
+
canonicalizePro2BleAdvertisementName,
|
|
12
13
|
createDeferred,
|
|
13
14
|
createDeviceNotSupportMethodError,
|
|
14
15
|
} from '@onekeyfe/hd-shared';
|
|
@@ -672,7 +673,8 @@ export class Device extends EventEmitter {
|
|
|
672
673
|
}
|
|
673
674
|
|
|
674
675
|
getCurrentBleName() {
|
|
675
|
-
|
|
676
|
+
const bleName = this.state?.identity.bleName ?? null;
|
|
677
|
+
return bleName ? canonicalizePro2BleAdvertisementName(bleName) : null;
|
|
676
678
|
}
|
|
677
679
|
|
|
678
680
|
getCurrentLabel() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EFirmwareType,
|
|
1
|
+
import { EFirmwareType, canonicalizePro2BleAdvertisementName } 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
|
+
? canonicalizePro2BleAdvertisementName(info.coprocessor.bt_adv_name)
|
|
252
252
|
: undefined,
|
|
253
253
|
deviceId: loader ? null : undefined,
|
|
254
254
|
}),
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
EDeviceType,
|
|
3
|
+
EFirmwareType,
|
|
4
|
+
canonicalizePro2BleAdvertisementName,
|
|
5
|
+
} from '@onekeyfe/hd-shared';
|
|
2
6
|
|
|
3
7
|
import {
|
|
4
8
|
resolveDeviceBleFirmwareVersion,
|
|
@@ -245,7 +249,8 @@ export const buildProtocolV2FeaturesPayload = ({
|
|
|
245
249
|
const deviceId = status?.device_id ?? cached?.deviceId ?? null;
|
|
246
250
|
const serialNo = firstValue(incomingSerialNo, cached?.serialNo) ?? '';
|
|
247
251
|
const label = cached?.label ?? null;
|
|
248
|
-
const
|
|
252
|
+
const rawBleName = firstValue(info?.coprocessor?.bt_adv_name, cached?.bleName);
|
|
253
|
+
const bleName = rawBleName ? canonicalizePro2BleAdvertisementName(rawBleName) : rawBleName;
|
|
249
254
|
const initialized = firstValue(status?.init_states, cached?.initialized) ?? null;
|
|
250
255
|
// passphrase_enabled from a locked Pro2 is not authoritative. Only DeviceStatus
|
|
251
256
|
// after PIN unlock can determine the final passphrase setting.
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
EDeviceType,
|
|
3
|
+
EFirmwareType,
|
|
4
|
+
canonicalizePro2BleAdvertisementName,
|
|
5
|
+
} from '@onekeyfe/hd-shared';
|
|
2
6
|
import { Enum_Capability } from '@onekeyfe/hd-transport';
|
|
3
7
|
|
|
4
8
|
import type { PROTO } from '../constants';
|
|
@@ -125,9 +129,10 @@ export const resolveDeviceFirmwareType = (features?: DeviceFeaturesInput): EFirm
|
|
|
125
129
|
export const resolveDeviceBleName = (features?: DeviceFeaturesInput): string | null => {
|
|
126
130
|
if (!features) return null;
|
|
127
131
|
const compatible = asCompatibleFeatures(features);
|
|
128
|
-
|
|
129
|
-
firstNonEmptyString(compatible.bleName, compatible.onekey_ble_name, compatible.ble_name) ??
|
|
130
|
-
|
|
132
|
+
const bleName =
|
|
133
|
+
firstNonEmptyString(compatible.bleName, compatible.onekey_ble_name, compatible.ble_name) ??
|
|
134
|
+
null;
|
|
135
|
+
return bleName ? canonicalizePro2BleAdvertisementName(bleName) : null;
|
|
131
136
|
};
|
|
132
137
|
|
|
133
138
|
export const resolveDeviceFirmwareVersion = (features?: DeviceFeaturesInput): string | null => {
|