@onekeyfe/hd-shared 1.2.0-alpha.162 → 1.2.0-alpha.164
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/constants.d.ts +1 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +6 -10
- package/dist/index.js +15 -20
- package/package.json +2 -2
- package/src/constants.test.ts +0 -39
- package/src/constants.ts +24 -30
package/dist/constants.d.ts
CHANGED
|
@@ -74,9 +74,8 @@ export declare const createKnownBleUuidAliases: (uuid: string) => ReadonlySet<st
|
|
|
74
74
|
export declare const matchesKnownBleUuid: (actualUuid: string | null | undefined, aliases: ReadonlySet<string>) => boolean;
|
|
75
75
|
export declare const isPro2FindMyAdvertisementName: (value?: string | null) => boolean;
|
|
76
76
|
export declare const normalizePro2FindMyAdvertisementName: (value: string) => string;
|
|
77
|
-
export declare const canonicalizePro2BleAdvertisementName: (value: string) => string;
|
|
78
|
-
export declare const isSameOnekeyBleName: (left?: string | null, right?: string | null) => boolean;
|
|
79
77
|
export declare const hasOnekeyCommunicationService: (serviceUuids: Array<string | null | undefined> | null | undefined) => boolean;
|
|
78
|
+
export declare const isPro2FamilyBleName: (value?: string | null) => boolean;
|
|
80
79
|
export declare const isOnekeyBluetoothDevice: ({ id, name, localName, serviceUuids, }: BluetoothDeviceIdentity) => boolean;
|
|
81
80
|
export {};
|
|
82
81
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";AAEA,eAAO,MAAM,yBAAyB;;;CAG5B,CAAC;AAEX,MAAM,MAAM,uBAAuB,GACjC,CAAC,OAAO,yBAAyB,CAAC,CAAC,MAAM,OAAO,yBAAyB,CAAC,CAAC;AAE7E,eAAO,MAAM,oBAAoB;;;GAOhC,CAAC;AAGF,eAAO,MAAM,0BAA0B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D,CAAC;AAEF,eAAO,MAAM,uBAAuB,2CAKjC,uBAAuB,KAAG,OAiB5B,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -92,17 +92,13 @@ declare const createKnownBleUuidAliases: (uuid: string) => ReadonlySet<string>;
|
|
|
92
92
|
declare const matchesKnownBleUuid: (actualUuid: string | null | undefined, aliases: ReadonlySet<string>) => boolean;
|
|
93
93
|
declare const isPro2FindMyAdvertisementName: (value?: string | null) => boolean;
|
|
94
94
|
declare const normalizePro2FindMyAdvertisementName: (value: string) => string;
|
|
95
|
+
declare const hasOnekeyCommunicationService: (serviceUuids: Array<string | null | undefined> | null | undefined) => boolean;
|
|
95
96
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* Match the compact Pro2 form first. A leading "Pro 2" regex would also eat the
|
|
101
|
-
* first digit of a OneKey Pro suffix such as "Pro 22D8" or "Pro 2D8F".
|
|
97
|
+
* Protocol V2 family (Pro2 / Neo) by advertised BLE name. Callers use it to
|
|
98
|
+
* pick a connection strategy: this family also advertises under Find My names
|
|
99
|
+
* that carry no OneKey service UUID, so a scan cannot always see it.
|
|
102
100
|
*/
|
|
103
|
-
declare const
|
|
104
|
-
declare const isSameOnekeyBleName: (left?: string | null, right?: string | null) => boolean;
|
|
105
|
-
declare const hasOnekeyCommunicationService: (serviceUuids: Array<string | null | undefined> | null | undefined) => boolean;
|
|
101
|
+
declare const isPro2FamilyBleName: (value?: string | null) => boolean;
|
|
106
102
|
declare const isOnekeyBluetoothDevice: ({ id, name, localName, serviceUuids, }: BluetoothDeviceIdentity) => boolean;
|
|
107
103
|
|
|
108
104
|
type Deferred<T, I = any, D = any> = {
|
|
@@ -568,4 +564,4 @@ declare enum EDeviceType {
|
|
|
568
564
|
Neo = "neo"
|
|
569
565
|
}
|
|
570
566
|
|
|
571
|
-
export { CreateErrorByMessage, CreateHardwareErrorByBridgeError, Deferred, EBleDisconnectReason, EDeviceType, EFirmwareType, EOneKeyBleMessageKeys, HardwareError$1 as ERRORS, ERROR_CODES_REQUIRE_DISCONNECT, ERROR_CODES_REQUIRE_RELEASE, HARDWARE_CONNECT_PROTOCOL, HardwareConnectProtocol, HardwareError, HardwareErrorCode, HardwareErrorCodeMessage, IHardwareError, ONEKEY_NOTIFY_CHARACTERISTIC_UUID, ONEKEY_PROTOCOL_V2_USB_IDS, ONEKEY_SERVICE_UUID, ONEKEY_WEBUSB_FILTER, ONEKEY_WRITE_CHARACTERISTIC_UUID, TypedError,
|
|
567
|
+
export { CreateErrorByMessage, CreateHardwareErrorByBridgeError, Deferred, EBleDisconnectReason, EDeviceType, EFirmwareType, EOneKeyBleMessageKeys, HardwareError$1 as ERRORS, ERROR_CODES_REQUIRE_DISCONNECT, ERROR_CODES_REQUIRE_RELEASE, HARDWARE_CONNECT_PROTOCOL, HardwareConnectProtocol, HardwareError, HardwareErrorCode, HardwareErrorCodeMessage, IHardwareError, ONEKEY_NOTIFY_CHARACTERISTIC_UUID, ONEKEY_PROTOCOL_V2_USB_IDS, ONEKEY_SERVICE_UUID, ONEKEY_WEBUSB_FILTER, ONEKEY_WRITE_CHARACTERISTIC_UUID, TypedError, createDefectiveFirmwareError, createDeferred, createDeprecatedHardwareError, createDeviceNotSupportMethodError, createKnownBleUuidAliases, createNeedUpgradeFirmwareHardwareError, createNewFirmwareForceUpdateHardwareError, createNewFirmwareUnReleaseHardwareError, hasOnekeyCommunicationService, inferProtocolHintFromUsbId, isHeaderChunk, isKnownTrezorWebUsbDevice, isOnekeyBluetoothDevice, isOnekeyDevice, isPro2FamilyBleName, isPro2FindMyAdvertisementName, matchesKnownBleUuid, normalizeBleUuid, normalizePro2FindMyAdvertisementName, resolveOneKeyUsbDevicePath, serializeError, wait };
|
package/dist/index.js
CHANGED
|
@@ -601,27 +601,23 @@ const normalizePro2FindMyAdvertisementName = (value) => {
|
|
|
601
601
|
}
|
|
602
602
|
return value;
|
|
603
603
|
};
|
|
604
|
-
const
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
const
|
|
610
|
-
if (!
|
|
611
|
-
return withoutFindMy;
|
|
612
|
-
const rest = withoutFindMy.slice(match[0].length);
|
|
613
|
-
const prefix = match[1] ? 'OneKey Pro 2' : 'Pro 2';
|
|
614
|
-
return rest ? `${prefix} ${rest}` : prefix;
|
|
615
|
-
};
|
|
616
|
-
const isSameOnekeyBleName = (left, right) => {
|
|
617
|
-
if (!left || !right)
|
|
604
|
+
const hasOnekeyCommunicationService = (serviceUuids) => (serviceUuids !== null && serviceUuids !== void 0 ? serviceUuids : []).some(uuid => matchesKnownBleUuid(uuid, ONEKEY_COMMUNICATION_SERVICE_ALIASES));
|
|
605
|
+
const isPro2FamilyBleName = (value) => {
|
|
606
|
+
if (!value) {
|
|
607
|
+
return false;
|
|
608
|
+
}
|
|
609
|
+
const normalized = value.trim().toLowerCase();
|
|
610
|
+
if (!normalized) {
|
|
618
611
|
return false;
|
|
619
|
-
|
|
612
|
+
}
|
|
613
|
+
if (normalized.startsWith('pro2') || normalized.startsWith('neo')) {
|
|
620
614
|
return true;
|
|
621
|
-
|
|
622
|
-
|
|
615
|
+
}
|
|
616
|
+
const compact = compactBleName(normalized);
|
|
617
|
+
return (PRO2_COMPACT_NAME_PATTERN.test(compact) ||
|
|
618
|
+
NEO_COMPACT_NAME_PATTERN.test(compact) ||
|
|
619
|
+
isPro2FindMyAdvertisementName(value));
|
|
623
620
|
};
|
|
624
|
-
const hasOnekeyCommunicationService = (serviceUuids) => (serviceUuids !== null && serviceUuids !== void 0 ? serviceUuids : []).some(uuid => matchesKnownBleUuid(uuid, ONEKEY_COMMUNICATION_SERVICE_ALIASES));
|
|
625
621
|
const isOnekeyBluetoothDevice = ({ id, name, localName, serviceUuids, }) => {
|
|
626
622
|
const advertisedServiceUuids = serviceUuids !== null && serviceUuids !== void 0 ? serviceUuids : [];
|
|
627
623
|
if (hasOnekeyCommunicationService(advertisedServiceUuids)) {
|
|
@@ -725,7 +721,6 @@ exports.ONEKEY_SERVICE_UUID = ONEKEY_SERVICE_UUID;
|
|
|
725
721
|
exports.ONEKEY_WEBUSB_FILTER = ONEKEY_WEBUSB_FILTER;
|
|
726
722
|
exports.ONEKEY_WRITE_CHARACTERISTIC_UUID = ONEKEY_WRITE_CHARACTERISTIC_UUID;
|
|
727
723
|
exports.TypedError = TypedError;
|
|
728
|
-
exports.canonicalizePro2BleAdvertisementName = canonicalizePro2BleAdvertisementName;
|
|
729
724
|
exports.createDefectiveFirmwareError = createDefectiveFirmwareError;
|
|
730
725
|
exports.createDeferred = createDeferred;
|
|
731
726
|
exports.createDeprecatedHardwareError = createDeprecatedHardwareError;
|
|
@@ -740,8 +735,8 @@ exports.isHeaderChunk = isHeaderChunk;
|
|
|
740
735
|
exports.isKnownTrezorWebUsbDevice = isKnownTrezorWebUsbDevice;
|
|
741
736
|
exports.isOnekeyBluetoothDevice = isOnekeyBluetoothDevice;
|
|
742
737
|
exports.isOnekeyDevice = isOnekeyDevice;
|
|
738
|
+
exports.isPro2FamilyBleName = isPro2FamilyBleName;
|
|
743
739
|
exports.isPro2FindMyAdvertisementName = isPro2FindMyAdvertisementName;
|
|
744
|
-
exports.isSameOnekeyBleName = isSameOnekeyBleName;
|
|
745
740
|
exports.matchesKnownBleUuid = matchesKnownBleUuid;
|
|
746
741
|
exports.normalizeBleUuid = normalizeBleUuid;
|
|
747
742
|
exports.normalizePro2FindMyAdvertisementName = normalizePro2FindMyAdvertisementName;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-shared",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.164",
|
|
4
4
|
"description": "Hardware SDK's shared tool library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Hardware-SDK",
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"lint": "eslint .",
|
|
27
27
|
"lint:fix": "eslint . --fix"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "8a6f829b0ea1544d2c5f7a1fd0cc0f08d6df7dcd"
|
|
30
30
|
}
|
package/src/constants.test.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
canonicalizePro2BleAdvertisementName,
|
|
3
2
|
createKnownBleUuidAliases,
|
|
4
3
|
hasOnekeyCommunicationService,
|
|
5
4
|
inferProtocolHintFromUsbId,
|
|
@@ -7,7 +6,6 @@ import {
|
|
|
7
6
|
isOnekeyBluetoothDevice,
|
|
8
7
|
isOnekeyDevice,
|
|
9
8
|
isPro2FindMyAdvertisementName,
|
|
10
|
-
isSameOnekeyBleName,
|
|
11
9
|
matchesKnownBleUuid,
|
|
12
10
|
normalizePro2FindMyAdvertisementName,
|
|
13
11
|
resolveOneKeyUsbDevicePath,
|
|
@@ -19,9 +17,7 @@ describe('hardware device identity filters', () => {
|
|
|
19
17
|
expect(isOnekeyDevice('Pro A1B2')).toBe(true);
|
|
20
18
|
expect(isOnekeyDevice('Neo A1B2')).toBe(true);
|
|
21
19
|
expect(isOnekeyDevice('Pro2A1B2')).toBe(true);
|
|
22
|
-
expect(isOnekeyDevice('Pro 2 A1B2')).toBe(true);
|
|
23
20
|
expect(isOnekeyDevice('OneKeyPro2A1B2')).toBe(true);
|
|
24
|
-
expect(isOnekeyDevice('OneKey Pro 2 A1B2')).toBe(true);
|
|
25
21
|
expect(isOnekeyDevice('Neo22D8')).toBe(true);
|
|
26
22
|
expect(isOnekeyDevice('K1234')).toBe(true);
|
|
27
23
|
expect(isOnekeyDevice('S8')).toBe(true);
|
|
@@ -46,12 +42,6 @@ describe('hardware device identity filters', () => {
|
|
|
46
42
|
serviceUuids: ['0001', 'fffd'],
|
|
47
43
|
})
|
|
48
44
|
).toBe(true);
|
|
49
|
-
expect(
|
|
50
|
-
isOnekeyBluetoothDevice({
|
|
51
|
-
name: 'Pro 2 A1B2',
|
|
52
|
-
serviceUuids: ['0001', 'fffd'],
|
|
53
|
-
})
|
|
54
|
-
).toBe(true);
|
|
55
45
|
expect(
|
|
56
46
|
isOnekeyBluetoothDevice({
|
|
57
47
|
localName: 'Pro2 A1B2 - Find My',
|
|
@@ -114,35 +104,6 @@ describe('hardware device identity filters', () => {
|
|
|
114
104
|
expect(normalizePro2FindMyAdvertisementName(name)).toBe(expected);
|
|
115
105
|
});
|
|
116
106
|
|
|
117
|
-
it.each([
|
|
118
|
-
['Pro2 A1B2', 'Pro 2 A1B2'],
|
|
119
|
-
['Pro2A1B2', 'Pro 2 A1B2'],
|
|
120
|
-
['Pro 2 A1B2', 'Pro 2 A1B2'],
|
|
121
|
-
['Pro 2 0088', 'Pro 2 0088'],
|
|
122
|
-
['Pro2 22D8 - Find My', 'Pro 2 22D8'],
|
|
123
|
-
['Pro 2 A1B2 - Find My', 'Pro 2 A1B2'],
|
|
124
|
-
['OneKeyPro2A1B2', 'OneKey Pro 2 A1B2'],
|
|
125
|
-
['OneKey Pro 2 A1B2', 'OneKey Pro 2 A1B2'],
|
|
126
|
-
['OneKey Pro 2', 'OneKey Pro 2'],
|
|
127
|
-
['Pro A1B2', 'Pro A1B2'],
|
|
128
|
-
['Pro 22D8', 'Pro 22D8'],
|
|
129
|
-
['Pro 2D8F', 'Pro 2D8F'],
|
|
130
|
-
['OneKey Pro 22D8', 'OneKey Pro 22D8'],
|
|
131
|
-
['Neo 22D8', 'Neo 22D8'],
|
|
132
|
-
])('canonicalizes the public Pro2 advertisement name %s', (name, expected) => {
|
|
133
|
-
expect(canonicalizePro2BleAdvertisementName(name)).toBe(expected);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('treats compact and spaced Pro2 BLE names as the same device', () => {
|
|
137
|
-
expect(isSameOnekeyBleName('Pro2 6136', 'Pro 2 6136')).toBe(true);
|
|
138
|
-
expect(isSameOnekeyBleName('Pro2 6136 - Find My', 'Pro 2 6136')).toBe(true);
|
|
139
|
-
expect(isSameOnekeyBleName('Pro 2 6136', 'Pro 2 0088')).toBe(false);
|
|
140
|
-
expect(isSameOnekeyBleName('Pro A1B2', 'Pro 2 A1B2')).toBe(false);
|
|
141
|
-
expect(isSameOnekeyBleName('Pro 22D8', 'Pro 22D8')).toBe(true);
|
|
142
|
-
expect(isSameOnekeyBleName('Pro 22D8', 'Pro2 22D8')).toBe(false);
|
|
143
|
-
expect(isSameOnekeyBleName('Pro 22D8', 'Pro 2 22D8')).toBe(false);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
107
|
it('keeps OneKey discovery on the communication service', () => {
|
|
147
108
|
expect(
|
|
148
109
|
isOnekeyBluetoothDevice({
|
package/src/constants.ts
CHANGED
|
@@ -307,36 +307,6 @@ export const normalizePro2FindMyAdvertisementName = (value: string) => {
|
|
|
307
307
|
return value;
|
|
308
308
|
};
|
|
309
309
|
|
|
310
|
-
/**
|
|
311
|
-
* Current Pro2 advertisements use "Pro 2 XXXX". Older firmware used "Pro2 XXXX".
|
|
312
|
-
* Discovery and DeviceInfo both go through this helper so the public BLE name
|
|
313
|
-
* stays on the spaced form without changing OneKey Pro / Neo names.
|
|
314
|
-
*
|
|
315
|
-
* Match the compact Pro2 form first. A leading "Pro 2" regex would also eat the
|
|
316
|
-
* first digit of a OneKey Pro suffix such as "Pro 22D8" or "Pro 2D8F".
|
|
317
|
-
*/
|
|
318
|
-
export const canonicalizePro2BleAdvertisementName = (value: string) => {
|
|
319
|
-
const withoutFindMy = normalizePro2FindMyAdvertisementName(value);
|
|
320
|
-
const compact = compactBleName(withoutFindMy);
|
|
321
|
-
if (!PRO2_COMPACT_NAME_PATTERN.test(compact)) return withoutFindMy;
|
|
322
|
-
|
|
323
|
-
const match = withoutFindMy.match(/^(onekey\s*)?pro\s*2\s*/i);
|
|
324
|
-
if (!match) return withoutFindMy;
|
|
325
|
-
|
|
326
|
-
const rest = withoutFindMy.slice(match[0].length);
|
|
327
|
-
const prefix = match[1] ? 'OneKey Pro 2' : 'Pro 2';
|
|
328
|
-
return rest ? `${prefix} ${rest}` : prefix;
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
export const isSameOnekeyBleName = (left?: string | null, right?: string | null) => {
|
|
332
|
-
if (!left || !right) return false;
|
|
333
|
-
if (left === right) return true;
|
|
334
|
-
return (
|
|
335
|
-
compactBleName(canonicalizePro2BleAdvertisementName(left)) ===
|
|
336
|
-
compactBleName(canonicalizePro2BleAdvertisementName(right))
|
|
337
|
-
);
|
|
338
|
-
};
|
|
339
|
-
|
|
340
310
|
export const hasOnekeyCommunicationService = (
|
|
341
311
|
serviceUuids: Array<string | null | undefined> | null | undefined
|
|
342
312
|
) =>
|
|
@@ -344,6 +314,30 @@ export const hasOnekeyCommunicationService = (
|
|
|
344
314
|
matchesKnownBleUuid(uuid, ONEKEY_COMMUNICATION_SERVICE_ALIASES)
|
|
345
315
|
);
|
|
346
316
|
|
|
317
|
+
/**
|
|
318
|
+
* Protocol V2 family (Pro2 / Neo) by advertised BLE name. Callers use it to
|
|
319
|
+
* pick a connection strategy: this family also advertises under Find My names
|
|
320
|
+
* that carry no OneKey service UUID, so a scan cannot always see it.
|
|
321
|
+
*/
|
|
322
|
+
export const isPro2FamilyBleName = (value?: string | null): boolean => {
|
|
323
|
+
if (!value) {
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
const normalized = value.trim().toLowerCase();
|
|
327
|
+
if (!normalized) {
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
if (normalized.startsWith('pro2') || normalized.startsWith('neo')) {
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
const compact = compactBleName(normalized);
|
|
334
|
+
return (
|
|
335
|
+
PRO2_COMPACT_NAME_PATTERN.test(compact) ||
|
|
336
|
+
NEO_COMPACT_NAME_PATTERN.test(compact) ||
|
|
337
|
+
isPro2FindMyAdvertisementName(value)
|
|
338
|
+
);
|
|
339
|
+
};
|
|
340
|
+
|
|
347
341
|
export const isOnekeyBluetoothDevice = ({
|
|
348
342
|
id,
|
|
349
343
|
name,
|