@onekeyfe/hd-shared 1.2.0-alpha.155 → 1.2.0-alpha.157
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 +2 -4
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +8 -15
- package/dist/index.js +19 -5
- package/package.json +2 -2
- package/src/constants.test.ts +33 -0
- package/src/constants.ts +24 -15
package/dist/constants.d.ts
CHANGED
|
@@ -46,10 +46,6 @@ export declare enum EOneKeyBleMessageKeys {
|
|
|
46
46
|
NOBLE_BLE_MTU_CHANGED = "$onekey-noble-ble-mtu-changed",
|
|
47
47
|
NOBLE_BLE_CANCEL_PAIRING = "$onekey-noble-ble-cancel-pairing"
|
|
48
48
|
}
|
|
49
|
-
export declare enum EBleDisconnectReason {
|
|
50
|
-
DeviceDisconnected = "device-disconnected",
|
|
51
|
-
IdleKeepAlive = "idle-keep-alive"
|
|
52
|
-
}
|
|
53
49
|
export declare const ONEKEY_SERVICE_UUID = "00000001-0000-1000-8000-00805f9b34fb";
|
|
54
50
|
export declare const ONEKEY_WRITE_CHARACTERISTIC_UUID = "00000002-0000-1000-8000-00805f9b34fb";
|
|
55
51
|
export declare const ONEKEY_NOTIFY_CHARACTERISTIC_UUID = "00000003-0000-1000-8000-00805f9b34fb";
|
|
@@ -74,6 +70,8 @@ export declare const createKnownBleUuidAliases: (uuid: string) => ReadonlySet<st
|
|
|
74
70
|
export declare const matchesKnownBleUuid: (actualUuid: string | null | undefined, aliases: ReadonlySet<string>) => boolean;
|
|
75
71
|
export declare const isPro2FindMyAdvertisementName: (value?: string | null) => boolean;
|
|
76
72
|
export declare const normalizePro2FindMyAdvertisementName: (value: string) => string;
|
|
73
|
+
export declare const canonicalizePro2BleAdvertisementName: (value: string) => string;
|
|
74
|
+
export declare const isSameOnekeyBleName: (left?: string | null, right?: string | null) => boolean;
|
|
77
75
|
export declare const hasOnekeyCommunicationService: (serviceUuids: Array<string | null | undefined> | null | undefined) => boolean;
|
|
78
76
|
export declare const isOnekeyBluetoothDevice: ({ id, name, localName, serviceUuids, }: BluetoothDeviceIdentity) => boolean;
|
|
79
77
|
export {};
|
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;;;EAAqD,CAAC;AAE7F,KAAK,wBAAwB,GAAG;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC,CAAC;AAIF,eAAO,MAAM,yBAAyB,eAAgB,wBAAwB,KAAG,OAQhF,CAAC;AAMF,eAAO,MAAM,2BAA2B,mDAS9B,CAAC;AAMX,eAAO,MAAM,8BAA8B,qBAGjC,CAAC;AAGX,oBAAY,qBAAqB;IAE/B,UAAU,uBAAuB;IACjC,iBAAiB,8BAA8B;IAC/C,aAAa,0BAA0B;IACvC,kBAAkB,+BAA+B;IACjD,cAAc,2BAA2B;IACzC,oBAAoB,iCAAiC;IAGrD,mBAAmB,gCAAgC;IACnD,oBAAoB,iCAAiC;IAGrD,aAAa,0BAA0B;IACvC,oBAAoB,iCAAiC;IAGrD,uBAAuB,oCAAoC;IAC3D,sBAAsB,mCAAmC;IAGzD,mBAAmB,gCAAgC;IACnD,mBAAmB,gCAAgC;IACnD,oBAAoB,iCAAiC;IACrD,iBAAiB,8BAA8B;IAG/C,iBAAiB,8BAA8B;IAC/C,oBAAoB,iCAAiC;IACrD,eAAe,4BAA4B;IAC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M,6BAA6B,WAAY,MAAM,GAAG,IAAI,YAWlE,CAAC;AAEF,eAAO,MAAM,oCAAoC,UAAW,MAAM,WAejE,CAAC;AAOF,eAAO,MAAM,oCAAoC,UAAW,MAAM,WAQjE,CAAC;AAEF,eAAO,MAAM,mBAAmB,UAAW,MAAM,GAAG,IAAI,UAAU,MAAM,GAAG,IAAI,YAO9E,CAAC;AAEF,eAAO,MAAM,6BAA6B,iBAC1B,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,IAAI,GAAG,SAAS,YAIhE,CAAC;AAEJ,eAAO,MAAM,uBAAuB,2CAKjC,uBAAuB,KAAG,OAiB5B,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -54,20 +54,6 @@ declare enum EOneKeyBleMessageKeys {
|
|
|
54
54
|
NOBLE_BLE_MTU_CHANGED = "$onekey-noble-ble-mtu-changed",
|
|
55
55
|
NOBLE_BLE_CANCEL_PAIRING = "$onekey-noble-ble-cancel-pairing"
|
|
56
56
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Why a BLE link went down, carried on BLE_DEVICE_DISCONNECTED.
|
|
59
|
-
*
|
|
60
|
-
* The main process frees an idle link on its own keep-alive timer, which is an
|
|
61
|
-
* internal optimisation the device knows nothing about — consumers must not
|
|
62
|
-
* treat it as "the device is gone". Only DeviceDisconnected means the
|
|
63
|
-
* peripheral actually dropped.
|
|
64
|
-
*/
|
|
65
|
-
declare enum EBleDisconnectReason {
|
|
66
|
-
/** Unsolicited peripheral drop: powered off, out of range, cable/BLE lost. */
|
|
67
|
-
DeviceDisconnected = "device-disconnected",
|
|
68
|
-
/** Main-process keep-alive timer released an idle link; device still present. */
|
|
69
|
-
IdleKeepAlive = "idle-keep-alive"
|
|
70
|
-
}
|
|
71
57
|
declare const ONEKEY_SERVICE_UUID = "00000001-0000-1000-8000-00805f9b34fb";
|
|
72
58
|
declare const ONEKEY_WRITE_CHARACTERISTIC_UUID = "00000002-0000-1000-8000-00805f9b34fb";
|
|
73
59
|
declare const ONEKEY_NOTIFY_CHARACTERISTIC_UUID = "00000003-0000-1000-8000-00805f9b34fb";
|
|
@@ -92,6 +78,13 @@ declare const createKnownBleUuidAliases: (uuid: string) => ReadonlySet<string>;
|
|
|
92
78
|
declare const matchesKnownBleUuid: (actualUuid: string | null | undefined, aliases: ReadonlySet<string>) => boolean;
|
|
93
79
|
declare const isPro2FindMyAdvertisementName: (value?: string | null) => boolean;
|
|
94
80
|
declare const normalizePro2FindMyAdvertisementName: (value: string) => string;
|
|
81
|
+
/**
|
|
82
|
+
* Current Pro2 advertisements use "Pro 2 XXXX". Older firmware used "Pro2 XXXX".
|
|
83
|
+
* Discovery and DeviceInfo both go through this helper so the public BLE name
|
|
84
|
+
* stays on the spaced form without changing OneKey Pro / Neo names.
|
|
85
|
+
*/
|
|
86
|
+
declare const canonicalizePro2BleAdvertisementName: (value: string) => string;
|
|
87
|
+
declare const isSameOnekeyBleName: (left?: string | null, right?: string | null) => boolean;
|
|
95
88
|
declare const hasOnekeyCommunicationService: (serviceUuids: Array<string | null | undefined> | null | undefined) => boolean;
|
|
96
89
|
declare const isOnekeyBluetoothDevice: ({ id, name, localName, serviceUuids, }: BluetoothDeviceIdentity) => boolean;
|
|
97
90
|
|
|
@@ -558,4 +551,4 @@ declare enum EDeviceType {
|
|
|
558
551
|
Neo = "neo"
|
|
559
552
|
}
|
|
560
553
|
|
|
561
|
-
export { CreateErrorByMessage, CreateHardwareErrorByBridgeError, Deferred,
|
|
554
|
+
export { CreateErrorByMessage, CreateHardwareErrorByBridgeError, Deferred, 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, canonicalizePro2BleAdvertisementName, createDefectiveFirmwareError, createDeferred, createDeprecatedHardwareError, createDeviceNotSupportMethodError, createKnownBleUuidAliases, createNeedUpgradeFirmwareHardwareError, createNewFirmwareForceUpdateHardwareError, createNewFirmwareUnReleaseHardwareError, hasOnekeyCommunicationService, inferProtocolHintFromUsbId, isHeaderChunk, isKnownTrezorWebUsbDevice, isOnekeyBluetoothDevice, isOnekeyDevice, isPro2FindMyAdvertisementName, isSameOnekeyBleName, matchesKnownBleUuid, normalizeBleUuid, normalizePro2FindMyAdvertisementName, resolveOneKeyUsbDevicePath, serializeError, wait };
|
package/dist/index.js
CHANGED
|
@@ -450,11 +450,6 @@ exports.EOneKeyBleMessageKeys = void 0;
|
|
|
450
450
|
EOneKeyBleMessageKeys["NOBLE_BLE_MTU_CHANGED"] = "$onekey-noble-ble-mtu-changed";
|
|
451
451
|
EOneKeyBleMessageKeys["NOBLE_BLE_CANCEL_PAIRING"] = "$onekey-noble-ble-cancel-pairing";
|
|
452
452
|
})(exports.EOneKeyBleMessageKeys || (exports.EOneKeyBleMessageKeys = {}));
|
|
453
|
-
exports.EBleDisconnectReason = void 0;
|
|
454
|
-
(function (EBleDisconnectReason) {
|
|
455
|
-
EBleDisconnectReason["DeviceDisconnected"] = "device-disconnected";
|
|
456
|
-
EBleDisconnectReason["IdleKeepAlive"] = "idle-keep-alive";
|
|
457
|
-
})(exports.EBleDisconnectReason || (exports.EBleDisconnectReason = {}));
|
|
458
453
|
const ONEKEY_SERVICE_UUID = '00000001-0000-1000-8000-00805f9b34fb';
|
|
459
454
|
const ONEKEY_WRITE_CHARACTERISTIC_UUID = '00000002-0000-1000-8000-00805f9b34fb';
|
|
460
455
|
const ONEKEY_NOTIFY_CHARACTERISTIC_UUID = '00000003-0000-1000-8000-00805f9b34fb';
|
|
@@ -601,6 +596,23 @@ const normalizePro2FindMyAdvertisementName = (value) => {
|
|
|
601
596
|
}
|
|
602
597
|
return value;
|
|
603
598
|
};
|
|
599
|
+
const canonicalizePro2BleAdvertisementName = (value) => {
|
|
600
|
+
const withoutFindMy = normalizePro2FindMyAdvertisementName(value);
|
|
601
|
+
const match = withoutFindMy.match(/^(onekey\s*)?pro\s*2\s*/i);
|
|
602
|
+
if (!match)
|
|
603
|
+
return withoutFindMy;
|
|
604
|
+
const rest = withoutFindMy.slice(match[0].length);
|
|
605
|
+
const prefix = match[1] ? 'OneKey Pro 2' : 'Pro 2';
|
|
606
|
+
return rest ? `${prefix} ${rest}` : prefix;
|
|
607
|
+
};
|
|
608
|
+
const isSameOnekeyBleName = (left, right) => {
|
|
609
|
+
if (!left || !right)
|
|
610
|
+
return false;
|
|
611
|
+
if (left === right)
|
|
612
|
+
return true;
|
|
613
|
+
return (compactBleName(canonicalizePro2BleAdvertisementName(left)) ===
|
|
614
|
+
compactBleName(canonicalizePro2BleAdvertisementName(right)));
|
|
615
|
+
};
|
|
604
616
|
const hasOnekeyCommunicationService = (serviceUuids) => (serviceUuids !== null && serviceUuids !== void 0 ? serviceUuids : []).some(uuid => matchesKnownBleUuid(uuid, ONEKEY_COMMUNICATION_SERVICE_ALIASES));
|
|
605
617
|
const isOnekeyBluetoothDevice = ({ id, name, localName, serviceUuids, }) => {
|
|
606
618
|
const advertisedServiceUuids = serviceUuids !== null && serviceUuids !== void 0 ? serviceUuids : [];
|
|
@@ -705,6 +717,7 @@ exports.ONEKEY_SERVICE_UUID = ONEKEY_SERVICE_UUID;
|
|
|
705
717
|
exports.ONEKEY_WEBUSB_FILTER = ONEKEY_WEBUSB_FILTER;
|
|
706
718
|
exports.ONEKEY_WRITE_CHARACTERISTIC_UUID = ONEKEY_WRITE_CHARACTERISTIC_UUID;
|
|
707
719
|
exports.TypedError = TypedError;
|
|
720
|
+
exports.canonicalizePro2BleAdvertisementName = canonicalizePro2BleAdvertisementName;
|
|
708
721
|
exports.createDefectiveFirmwareError = createDefectiveFirmwareError;
|
|
709
722
|
exports.createDeferred = createDeferred;
|
|
710
723
|
exports.createDeprecatedHardwareError = createDeprecatedHardwareError;
|
|
@@ -720,6 +733,7 @@ exports.isKnownTrezorWebUsbDevice = isKnownTrezorWebUsbDevice;
|
|
|
720
733
|
exports.isOnekeyBluetoothDevice = isOnekeyBluetoothDevice;
|
|
721
734
|
exports.isOnekeyDevice = isOnekeyDevice;
|
|
722
735
|
exports.isPro2FindMyAdvertisementName = isPro2FindMyAdvertisementName;
|
|
736
|
+
exports.isSameOnekeyBleName = isSameOnekeyBleName;
|
|
723
737
|
exports.matchesKnownBleUuid = matchesKnownBleUuid;
|
|
724
738
|
exports.normalizeBleUuid = normalizeBleUuid;
|
|
725
739
|
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.157",
|
|
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": "1e9aaf5fbf64562504ebc22dc34fb22220ba0b0b"
|
|
30
30
|
}
|
package/src/constants.test.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
canonicalizePro2BleAdvertisementName,
|
|
2
3
|
createKnownBleUuidAliases,
|
|
3
4
|
hasOnekeyCommunicationService,
|
|
4
5
|
inferProtocolHintFromUsbId,
|
|
@@ -6,6 +7,7 @@ import {
|
|
|
6
7
|
isOnekeyBluetoothDevice,
|
|
7
8
|
isOnekeyDevice,
|
|
8
9
|
isPro2FindMyAdvertisementName,
|
|
10
|
+
isSameOnekeyBleName,
|
|
9
11
|
matchesKnownBleUuid,
|
|
10
12
|
normalizePro2FindMyAdvertisementName,
|
|
11
13
|
resolveOneKeyUsbDevicePath,
|
|
@@ -17,7 +19,9 @@ describe('hardware device identity filters', () => {
|
|
|
17
19
|
expect(isOnekeyDevice('Pro A1B2')).toBe(true);
|
|
18
20
|
expect(isOnekeyDevice('Neo A1B2')).toBe(true);
|
|
19
21
|
expect(isOnekeyDevice('Pro2A1B2')).toBe(true);
|
|
22
|
+
expect(isOnekeyDevice('Pro 2 A1B2')).toBe(true);
|
|
20
23
|
expect(isOnekeyDevice('OneKeyPro2A1B2')).toBe(true);
|
|
24
|
+
expect(isOnekeyDevice('OneKey Pro 2 A1B2')).toBe(true);
|
|
21
25
|
expect(isOnekeyDevice('Neo22D8')).toBe(true);
|
|
22
26
|
expect(isOnekeyDevice('K1234')).toBe(true);
|
|
23
27
|
expect(isOnekeyDevice('S8')).toBe(true);
|
|
@@ -42,6 +46,12 @@ describe('hardware device identity filters', () => {
|
|
|
42
46
|
serviceUuids: ['0001', 'fffd'],
|
|
43
47
|
})
|
|
44
48
|
).toBe(true);
|
|
49
|
+
expect(
|
|
50
|
+
isOnekeyBluetoothDevice({
|
|
51
|
+
name: 'Pro 2 A1B2',
|
|
52
|
+
serviceUuids: ['0001', 'fffd'],
|
|
53
|
+
})
|
|
54
|
+
).toBe(true);
|
|
45
55
|
expect(
|
|
46
56
|
isOnekeyBluetoothDevice({
|
|
47
57
|
localName: 'Pro2 A1B2 - Find My',
|
|
@@ -104,6 +114,29 @@ describe('hardware device identity filters', () => {
|
|
|
104
114
|
expect(normalizePro2FindMyAdvertisementName(name)).toBe(expected);
|
|
105
115
|
});
|
|
106
116
|
|
|
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
|
+
['Neo 22D8', 'Neo 22D8'],
|
|
129
|
+
])('canonicalizes the public Pro2 advertisement name %s', (name, expected) => {
|
|
130
|
+
expect(canonicalizePro2BleAdvertisementName(name)).toBe(expected);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('treats compact and spaced Pro2 BLE names as the same device', () => {
|
|
134
|
+
expect(isSameOnekeyBleName('Pro2 6136', 'Pro 2 6136')).toBe(true);
|
|
135
|
+
expect(isSameOnekeyBleName('Pro2 6136 - Find My', 'Pro 2 6136')).toBe(true);
|
|
136
|
+
expect(isSameOnekeyBleName('Pro 2 6136', 'Pro 2 0088')).toBe(false);
|
|
137
|
+
expect(isSameOnekeyBleName('Pro A1B2', 'Pro 2 A1B2')).toBe(false);
|
|
138
|
+
});
|
|
139
|
+
|
|
107
140
|
it('keeps OneKey discovery on the communication service', () => {
|
|
108
141
|
expect(
|
|
109
142
|
isOnekeyBluetoothDevice({
|
package/src/constants.ts
CHANGED
|
@@ -101,21 +101,6 @@ export enum EOneKeyBleMessageKeys {
|
|
|
101
101
|
NOBLE_BLE_CANCEL_PAIRING = '$onekey-noble-ble-cancel-pairing',
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
/**
|
|
105
|
-
* Why a BLE link went down, carried on BLE_DEVICE_DISCONNECTED.
|
|
106
|
-
*
|
|
107
|
-
* The main process frees an idle link on its own keep-alive timer, which is an
|
|
108
|
-
* internal optimisation the device knows nothing about — consumers must not
|
|
109
|
-
* treat it as "the device is gone". Only DeviceDisconnected means the
|
|
110
|
-
* peripheral actually dropped.
|
|
111
|
-
*/
|
|
112
|
-
export enum EBleDisconnectReason {
|
|
113
|
-
/** Unsolicited peripheral drop: powered off, out of range, cable/BLE lost. */
|
|
114
|
-
DeviceDisconnected = 'device-disconnected',
|
|
115
|
-
/** Main-process keep-alive timer released an idle link; device still present. */
|
|
116
|
-
IdleKeepAlive = 'idle-keep-alive',
|
|
117
|
-
}
|
|
118
|
-
|
|
119
104
|
export const ONEKEY_SERVICE_UUID = '00000001-0000-1000-8000-00805f9b34fb';
|
|
120
105
|
export const ONEKEY_WRITE_CHARACTERISTIC_UUID = '00000002-0000-1000-8000-00805f9b34fb';
|
|
121
106
|
export const ONEKEY_NOTIFY_CHARACTERISTIC_UUID = '00000003-0000-1000-8000-00805f9b34fb';
|
|
@@ -307,6 +292,30 @@ export const normalizePro2FindMyAdvertisementName = (value: string) => {
|
|
|
307
292
|
return value;
|
|
308
293
|
};
|
|
309
294
|
|
|
295
|
+
/**
|
|
296
|
+
* Current Pro2 advertisements use "Pro 2 XXXX". Older firmware used "Pro2 XXXX".
|
|
297
|
+
* Discovery and DeviceInfo both go through this helper so the public BLE name
|
|
298
|
+
* stays on the spaced form without changing OneKey Pro / Neo names.
|
|
299
|
+
*/
|
|
300
|
+
export const canonicalizePro2BleAdvertisementName = (value: string) => {
|
|
301
|
+
const withoutFindMy = normalizePro2FindMyAdvertisementName(value);
|
|
302
|
+
const match = withoutFindMy.match(/^(onekey\s*)?pro\s*2\s*/i);
|
|
303
|
+
if (!match) return withoutFindMy;
|
|
304
|
+
|
|
305
|
+
const rest = withoutFindMy.slice(match[0].length);
|
|
306
|
+
const prefix = match[1] ? 'OneKey Pro 2' : 'Pro 2';
|
|
307
|
+
return rest ? `${prefix} ${rest}` : prefix;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
export const isSameOnekeyBleName = (left?: string | null, right?: string | null) => {
|
|
311
|
+
if (!left || !right) return false;
|
|
312
|
+
if (left === right) return true;
|
|
313
|
+
return (
|
|
314
|
+
compactBleName(canonicalizePro2BleAdvertisementName(left)) ===
|
|
315
|
+
compactBleName(canonicalizePro2BleAdvertisementName(right))
|
|
316
|
+
);
|
|
317
|
+
};
|
|
318
|
+
|
|
310
319
|
export const hasOnekeyCommunicationService = (
|
|
311
320
|
serviceUuids: Array<string | null | undefined> | null | undefined
|
|
312
321
|
) =>
|