@onekeyfe/hd-shared 1.2.0-alpha.146 → 1.2.0-alpha.147
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 +0 -12
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +1 -14
- package/dist/index.js +2 -31
- package/package.json +2 -2
- package/src/constants.test.ts +0 -31
- package/src/constants.ts +3 -40
package/dist/constants.d.ts
CHANGED
|
@@ -8,10 +8,6 @@ export declare const ONEKEY_WEBUSB_FILTER: {
|
|
|
8
8
|
vendorId: number;
|
|
9
9
|
productId: number;
|
|
10
10
|
}[];
|
|
11
|
-
export declare const ONEKEY_PROTOCOL_V2_USB_IDS: readonly [{
|
|
12
|
-
readonly vendorId: 4617;
|
|
13
|
-
readonly productId: 20300;
|
|
14
|
-
}];
|
|
15
11
|
type WebUsbIdentityDescriptor = {
|
|
16
12
|
vendorId?: number;
|
|
17
13
|
productId?: number;
|
|
@@ -51,14 +47,6 @@ export declare const ONEKEY_WRITE_CHARACTERISTIC_UUID = "00000002-0000-1000-8000
|
|
|
51
47
|
export declare const ONEKEY_NOTIFY_CHARACTERISTIC_UUID = "00000003-0000-1000-8000-00805f9b34fb";
|
|
52
48
|
export declare const isHeaderChunk: (chunk: Buffer | Uint8Array) => boolean;
|
|
53
49
|
export declare const isOnekeyDevice: (name: string | null, id?: string) => boolean;
|
|
54
|
-
export declare const inferProtocolHintFromUsbId: (vendorId?: number | null, productId?: number | null) => "V2" | undefined;
|
|
55
|
-
type UsbDevicePathInput = {
|
|
56
|
-
serialNumber?: string | null;
|
|
57
|
-
vendorId?: number;
|
|
58
|
-
productId?: number;
|
|
59
|
-
productName?: string | null;
|
|
60
|
-
};
|
|
61
|
-
export declare const resolveOneKeyUsbDevicePath: (device: UsbDevicePathInput) => string | undefined;
|
|
62
50
|
type BluetoothDeviceIdentity = {
|
|
63
51
|
id?: string;
|
|
64
52
|
name?: string | null;
|
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;
|
|
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;AAEF,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;IAC3C,mBAAmB,gCAAgC;IACnD,qBAAqB,kCAAkC;IACvD,sBAAsB,mCAAmC;IACzD,qBAAqB,kCAAkC;IACvD,wBAAwB,qCAAqC;CAC9D;AAED,eAAO,MAAM,mBAAmB,yCAAyC,CAAC;AAC1E,eAAO,MAAM,gCAAgC,yCAAyC,CAAC;AACvF,eAAO,MAAM,iCAAiC,yCAAyC,CAAC;AAIxF,eAAO,MAAM,aAAa,UAAW,MAAM,GAAG,UAAU,KAAG,OAa1D,CAAC;AAkBF,eAAO,MAAM,cAAc,SAAU,MAAM,GAAG,IAAI,OAAO,MAAM,KAAG,OAuBjE,CAAC;AAEF,KAAK,uBAAuB,GAAG;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,YAAY,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;CACxD,CAAC;AAIF,eAAO,MAAM,gBAAgB,UAAW,MAAM,GAAG,IAAI,WACP,CAAC;AAE/C,eAAO,MAAM,yBAAyB,SAAU,MAAM,KAAG,YAAY,MAAM,CAc1E,CAAC;AAEF,eAAO,MAAM,mBAAmB,eAClB,MAAM,GAAG,IAAI,GAAG,SAAS,WAC5B,YAAY,MAAM,CAAC,YACgB,CAAC;AAkC/C,eAAO,MAAM,6BAA6B,WAAY,MAAM,GAAG,IAAI,YAWlE,CAAC;AAEF,eAAO,MAAM,oCAAoC,UAAW,MAAM,WAejE,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
|
@@ -7,11 +7,6 @@ declare const ONEKEY_WEBUSB_FILTER: {
|
|
|
7
7
|
vendorId: number;
|
|
8
8
|
productId: number;
|
|
9
9
|
}[];
|
|
10
|
-
/** USB IDs whose first probe should be Protocol V2. Shared Pro/Touch PIDs stay unhinted. */
|
|
11
|
-
declare const ONEKEY_PROTOCOL_V2_USB_IDS: readonly [{
|
|
12
|
-
readonly vendorId: 4617;
|
|
13
|
-
readonly productId: 20300;
|
|
14
|
-
}];
|
|
15
10
|
type WebUsbIdentityDescriptor = {
|
|
16
11
|
vendorId?: number;
|
|
17
12
|
productId?: number;
|
|
@@ -59,14 +54,6 @@ declare const ONEKEY_WRITE_CHARACTERISTIC_UUID = "00000002-0000-1000-8000-00805f
|
|
|
59
54
|
declare const ONEKEY_NOTIFY_CHARACTERISTIC_UUID = "00000003-0000-1000-8000-00805f9b34fb";
|
|
60
55
|
declare const isHeaderChunk: (chunk: Buffer | Uint8Array) => boolean;
|
|
61
56
|
declare const isOnekeyDevice: (name: string | null, id?: string) => boolean;
|
|
62
|
-
declare const inferProtocolHintFromUsbId: (vendorId?: number | null, productId?: number | null) => "V2" | undefined;
|
|
63
|
-
type UsbDevicePathInput = {
|
|
64
|
-
serialNumber?: string | null;
|
|
65
|
-
vendorId?: number;
|
|
66
|
-
productId?: number;
|
|
67
|
-
productName?: string | null;
|
|
68
|
-
};
|
|
69
|
-
declare const resolveOneKeyUsbDevicePath: (device: UsbDevicePathInput) => string | undefined;
|
|
70
57
|
type BluetoothDeviceIdentity = {
|
|
71
58
|
id?: string;
|
|
72
59
|
name?: string | null;
|
|
@@ -544,4 +531,4 @@ declare enum EDeviceType {
|
|
|
544
531
|
Neo = "neo"
|
|
545
532
|
}
|
|
546
533
|
|
|
547
|
-
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,
|
|
534
|
+
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_SERVICE_UUID, ONEKEY_WEBUSB_FILTER, ONEKEY_WRITE_CHARACTERISTIC_UUID, TypedError, createDefectiveFirmwareError, createDeferred, createDeprecatedHardwareError, createDeviceNotSupportMethodError, createKnownBleUuidAliases, createNeedUpgradeFirmwareHardwareError, createNewFirmwareForceUpdateHardwareError, createNewFirmwareUnReleaseHardwareError, hasOnekeyCommunicationService, isHeaderChunk, isKnownTrezorWebUsbDevice, isOnekeyBluetoothDevice, isOnekeyDevice, isPro2FindMyAdvertisementName, matchesKnownBleUuid, normalizeBleUuid, normalizePro2FindMyAdvertisementName, serializeError, wait };
|
package/dist/index.js
CHANGED
|
@@ -399,7 +399,6 @@ const ONEKEY_WEBUSB_FILTER = [
|
|
|
399
399
|
{ vendorId: 0x1209, productId: 0x4f4b },
|
|
400
400
|
{ vendorId: 0x1209, productId: 0x4f4c },
|
|
401
401
|
];
|
|
402
|
-
const ONEKEY_PROTOCOL_V2_USB_IDS = [{ vendorId: 0x1209, productId: 0x4f4c }];
|
|
403
402
|
const TREZOR_WEBUSB_MANUFACTURER_NAMES = new Set(['trezor', 'trezor company', 'satoshilabs']);
|
|
404
403
|
const isKnownTrezorWebUsbDevice = (descriptor) => {
|
|
405
404
|
var _a;
|
|
@@ -496,36 +495,12 @@ const isOnekeyDevice = (name, id) => {
|
|
|
496
495
|
return true;
|
|
497
496
|
if (normalizedName.startsWith('touch ') ||
|
|
498
497
|
normalizedName.startsWith('pro ') ||
|
|
499
|
-
normalizedName.startsWith('pro2') ||
|
|
500
|
-
normalizedName.startsWith('neo')) {
|
|
501
|
-
return true;
|
|
502
|
-
}
|
|
503
|
-
const compactName = compactBleName(normalizedName);
|
|
504
|
-
if (PRO2_COMPACT_NAME_PATTERN.test(compactName) || NEO_COMPACT_NAME_PATTERN.test(compactName)) {
|
|
498
|
+
normalizedName.startsWith('pro2 ') ||
|
|
499
|
+
normalizedName.startsWith('neo ')) {
|
|
505
500
|
return true;
|
|
506
501
|
}
|
|
507
502
|
return isOneKeyShortName(normalizedName);
|
|
508
503
|
};
|
|
509
|
-
const inferProtocolHintFromUsbId = (vendorId, productId) => ONEKEY_PROTOCOL_V2_USB_IDS.some(id => id.vendorId === vendorId && id.productId === productId)
|
|
510
|
-
? 'V2'
|
|
511
|
-
: undefined;
|
|
512
|
-
const resolveOneKeyUsbDevicePath = (device) => {
|
|
513
|
-
var _a, _b, _c, _d;
|
|
514
|
-
const serial = (_a = device.serialNumber) === null || _a === void 0 ? void 0 : _a.trim();
|
|
515
|
-
if (serial)
|
|
516
|
-
return serial;
|
|
517
|
-
if (device.vendorId == null && device.productId == null && !device.productName) {
|
|
518
|
-
return undefined;
|
|
519
|
-
}
|
|
520
|
-
const vendorId = ((_b = device.vendorId) !== null && _b !== void 0 ? _b : 0).toString(16).padStart(4, '0');
|
|
521
|
-
const productId = ((_c = device.productId) !== null && _c !== void 0 ? _c : 0).toString(16).padStart(4, '0');
|
|
522
|
-
const product = ((_d = device.productName) !== null && _d !== void 0 ? _d : 'onekey')
|
|
523
|
-
.trim()
|
|
524
|
-
.toLowerCase()
|
|
525
|
-
.replace(/\s+/g, '-')
|
|
526
|
-
.replace(/[^a-z0-9-]/g, '');
|
|
527
|
-
return `usb-${vendorId}-${productId}-${product || 'onekey'}`;
|
|
528
|
-
};
|
|
529
504
|
const BLUETOOTH_BASE_UUID_SUFFIX = '00001000800000805f9b34fb';
|
|
530
505
|
const normalizeBleUuid = (uuid) => (uuid !== null && uuid !== void 0 ? uuid : '').replace(/-/g, '').toLowerCase();
|
|
531
506
|
const createKnownBleUuidAliases = (uuid) => {
|
|
@@ -545,7 +520,6 @@ const matchesKnownBleUuid = (actualUuid, aliases) => aliases.has(normalizeBleUui
|
|
|
545
520
|
const ONEKEY_COMMUNICATION_SERVICE_ALIASES = createKnownBleUuidAliases(ONEKEY_SERVICE_UUID);
|
|
546
521
|
const FIDO_SERVICE_ALIASES = createKnownBleUuidAliases('0000fffd-0000-1000-8000-00805f9b34fb');
|
|
547
522
|
const PRO2_COMPACT_NAME_PATTERN = /^(?:onekey)?pro2[a-f0-9]{4}$/i;
|
|
548
|
-
const NEO_COMPACT_NAME_PATTERN = /^(?:onekey)?neo[a-f0-9]{4}$/i;
|
|
549
523
|
const FIND_MY_COMPACT_SUFFIXES = [
|
|
550
524
|
'findemy',
|
|
551
525
|
'findem',
|
|
@@ -695,7 +669,6 @@ exports.HardwareError = HardwareError;
|
|
|
695
669
|
exports.HardwareErrorCode = HardwareErrorCode;
|
|
696
670
|
exports.HardwareErrorCodeMessage = HardwareErrorCodeMessage;
|
|
697
671
|
exports.ONEKEY_NOTIFY_CHARACTERISTIC_UUID = ONEKEY_NOTIFY_CHARACTERISTIC_UUID;
|
|
698
|
-
exports.ONEKEY_PROTOCOL_V2_USB_IDS = ONEKEY_PROTOCOL_V2_USB_IDS;
|
|
699
672
|
exports.ONEKEY_SERVICE_UUID = ONEKEY_SERVICE_UUID;
|
|
700
673
|
exports.ONEKEY_WEBUSB_FILTER = ONEKEY_WEBUSB_FILTER;
|
|
701
674
|
exports.ONEKEY_WRITE_CHARACTERISTIC_UUID = ONEKEY_WRITE_CHARACTERISTIC_UUID;
|
|
@@ -709,7 +682,6 @@ exports.createNeedUpgradeFirmwareHardwareError = createNeedUpgradeFirmwareHardwa
|
|
|
709
682
|
exports.createNewFirmwareForceUpdateHardwareError = createNewFirmwareForceUpdateHardwareError;
|
|
710
683
|
exports.createNewFirmwareUnReleaseHardwareError = createNewFirmwareUnReleaseHardwareError;
|
|
711
684
|
exports.hasOnekeyCommunicationService = hasOnekeyCommunicationService;
|
|
712
|
-
exports.inferProtocolHintFromUsbId = inferProtocolHintFromUsbId;
|
|
713
685
|
exports.isHeaderChunk = isHeaderChunk;
|
|
714
686
|
exports.isKnownTrezorWebUsbDevice = isKnownTrezorWebUsbDevice;
|
|
715
687
|
exports.isOnekeyBluetoothDevice = isOnekeyBluetoothDevice;
|
|
@@ -718,6 +690,5 @@ exports.isPro2FindMyAdvertisementName = isPro2FindMyAdvertisementName;
|
|
|
718
690
|
exports.matchesKnownBleUuid = matchesKnownBleUuid;
|
|
719
691
|
exports.normalizeBleUuid = normalizeBleUuid;
|
|
720
692
|
exports.normalizePro2FindMyAdvertisementName = normalizePro2FindMyAdvertisementName;
|
|
721
|
-
exports.resolveOneKeyUsbDevicePath = resolveOneKeyUsbDevicePath;
|
|
722
693
|
exports.serializeError = serializeError;
|
|
723
694
|
exports.wait = wait;
|
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.147",
|
|
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": "a34e98865e6be227cf3e00d486146e6592761db0"
|
|
30
30
|
}
|
package/src/constants.test.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createKnownBleUuidAliases,
|
|
3
3
|
hasOnekeyCommunicationService,
|
|
4
|
-
inferProtocolHintFromUsbId,
|
|
5
4
|
isKnownTrezorWebUsbDevice,
|
|
6
5
|
isOnekeyBluetoothDevice,
|
|
7
6
|
isOnekeyDevice,
|
|
8
7
|
isPro2FindMyAdvertisementName,
|
|
9
8
|
matchesKnownBleUuid,
|
|
10
9
|
normalizePro2FindMyAdvertisementName,
|
|
11
|
-
resolveOneKeyUsbDevicePath,
|
|
12
10
|
} from './constants';
|
|
13
11
|
|
|
14
12
|
describe('hardware device identity filters', () => {
|
|
@@ -16,9 +14,6 @@ describe('hardware device identity filters', () => {
|
|
|
16
14
|
expect(isOnekeyDevice('Touch A1B2')).toBe(true);
|
|
17
15
|
expect(isOnekeyDevice('Pro A1B2')).toBe(true);
|
|
18
16
|
expect(isOnekeyDevice('Neo A1B2')).toBe(true);
|
|
19
|
-
expect(isOnekeyDevice('Pro2A1B2')).toBe(true);
|
|
20
|
-
expect(isOnekeyDevice('OneKeyPro2A1B2')).toBe(true);
|
|
21
|
-
expect(isOnekeyDevice('Neo22D8')).toBe(true);
|
|
22
17
|
expect(isOnekeyDevice('K1234')).toBe(true);
|
|
23
18
|
expect(isOnekeyDevice('S8')).toBe(true);
|
|
24
19
|
});
|
|
@@ -141,32 +136,6 @@ describe('hardware device identity filters', () => {
|
|
|
141
136
|
expect(hasOnekeyCommunicationService(['abcd0001-1234-5678-9012-abcdefabcdef'])).toBe(false);
|
|
142
137
|
});
|
|
143
138
|
|
|
144
|
-
it('hints Protocol V2 from the current Pro2/Neo USB ID only', () => {
|
|
145
|
-
expect(inferProtocolHintFromUsbId(0x1209, 0x4f4c)).toBe('V2');
|
|
146
|
-
expect(inferProtocolHintFromUsbId(0x1209, 0x53c1)).toBeUndefined();
|
|
147
|
-
expect(inferProtocolHintFromUsbId(0x1209, 0x4f4a)).toBeUndefined();
|
|
148
|
-
expect(inferProtocolHintFromUsbId(0x1209, 0x4f4b)).toBeUndefined();
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('uses the USB serial when present and synthesizes a path when firmware omits it', () => {
|
|
152
|
-
expect(
|
|
153
|
-
resolveOneKeyUsbDevicePath({
|
|
154
|
-
vendorId: 0x1209,
|
|
155
|
-
productId: 0x4f4c,
|
|
156
|
-
productName: 'OneKey Pro 2',
|
|
157
|
-
serialNumber: 'PRO2-SERIAL',
|
|
158
|
-
})
|
|
159
|
-
).toBe('PRO2-SERIAL');
|
|
160
|
-
expect(
|
|
161
|
-
resolveOneKeyUsbDevicePath({
|
|
162
|
-
vendorId: 0x1209,
|
|
163
|
-
productId: 0x4f4c,
|
|
164
|
-
productName: 'OneKey Neo',
|
|
165
|
-
serialNumber: '',
|
|
166
|
-
})
|
|
167
|
-
).toBe('usb-1209-4f4c-onekey-neo');
|
|
168
|
-
});
|
|
169
|
-
|
|
170
139
|
it('only filters WebUSB descriptors that are explicitly identified as Trezor', () => {
|
|
171
140
|
expect(
|
|
172
141
|
isKnownTrezorWebUsbDevice({
|
package/src/constants.ts
CHANGED
|
@@ -13,13 +13,10 @@ export const ONEKEY_WEBUSB_FILTER = [
|
|
|
13
13
|
{ vendorId: 0x1209, productId: 0x53c1 }, // Classic/Classic1s/Mini/Pro/Touch firmware and legacy Pro2; keep for existing devices
|
|
14
14
|
{ vendorId: 0x1209, productId: 0x4f4a }, // Pro bootloader, Touch bootloader, Pro2
|
|
15
15
|
{ vendorId: 0x1209, productId: 0x4f4b }, // Pro/Touch firmware (Trezor not implemented), Pro2
|
|
16
|
-
{ vendorId: 0x1209, productId: 0x4f4c }, // Pro2
|
|
16
|
+
{ vendorId: 0x1209, productId: 0x4f4c }, // Pro board and Pro2 with the new firmware PID
|
|
17
17
|
// { vendorId: 0x1209, productId: 0x4f50 }, // Touch Board
|
|
18
18
|
];
|
|
19
19
|
|
|
20
|
-
/** USB IDs whose first probe should be Protocol V2. Shared Pro/Touch PIDs stay unhinted. */
|
|
21
|
-
export const ONEKEY_PROTOCOL_V2_USB_IDS = [{ vendorId: 0x1209, productId: 0x4f4c }] as const;
|
|
22
|
-
|
|
23
20
|
type WebUsbIdentityDescriptor = {
|
|
24
21
|
vendorId?: number;
|
|
25
22
|
productId?: number;
|
|
@@ -155,47 +152,14 @@ export const isOnekeyDevice = (name: string | null, id?: string): boolean => {
|
|
|
155
152
|
if (
|
|
156
153
|
normalizedName.startsWith('touch ') ||
|
|
157
154
|
normalizedName.startsWith('pro ') ||
|
|
158
|
-
normalizedName.startsWith('pro2') ||
|
|
159
|
-
normalizedName.startsWith('neo')
|
|
155
|
+
normalizedName.startsWith('pro2 ') ||
|
|
156
|
+
normalizedName.startsWith('neo ')
|
|
160
157
|
) {
|
|
161
158
|
return true;
|
|
162
159
|
}
|
|
163
|
-
const compactName = compactBleName(normalizedName);
|
|
164
|
-
if (PRO2_COMPACT_NAME_PATTERN.test(compactName) || NEO_COMPACT_NAME_PATTERN.test(compactName)) {
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
160
|
return isOneKeyShortName(normalizedName);
|
|
168
161
|
};
|
|
169
162
|
|
|
170
|
-
export const inferProtocolHintFromUsbId = (vendorId?: number | null, productId?: number | null) =>
|
|
171
|
-
ONEKEY_PROTOCOL_V2_USB_IDS.some(id => id.vendorId === vendorId && id.productId === productId)
|
|
172
|
-
? ('V2' as const)
|
|
173
|
-
: undefined;
|
|
174
|
-
|
|
175
|
-
type UsbDevicePathInput = {
|
|
176
|
-
serialNumber?: string | null;
|
|
177
|
-
vendorId?: number;
|
|
178
|
-
productId?: number;
|
|
179
|
-
productName?: string | null;
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
export const resolveOneKeyUsbDevicePath = (device: UsbDevicePathInput): string | undefined => {
|
|
183
|
-
const serial = device.serialNumber?.trim();
|
|
184
|
-
if (serial) return serial;
|
|
185
|
-
if (device.vendorId == null && device.productId == null && !device.productName) {
|
|
186
|
-
return undefined;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const vendorId = (device.vendorId ?? 0).toString(16).padStart(4, '0');
|
|
190
|
-
const productId = (device.productId ?? 0).toString(16).padStart(4, '0');
|
|
191
|
-
const product = (device.productName ?? 'onekey')
|
|
192
|
-
.trim()
|
|
193
|
-
.toLowerCase()
|
|
194
|
-
.replace(/\s+/g, '-')
|
|
195
|
-
.replace(/[^a-z0-9-]/g, '');
|
|
196
|
-
return `usb-${vendorId}-${productId}-${product || 'onekey'}`;
|
|
197
|
-
};
|
|
198
|
-
|
|
199
163
|
type BluetoothDeviceIdentity = {
|
|
200
164
|
id?: string;
|
|
201
165
|
name?: string | null;
|
|
@@ -232,7 +196,6 @@ export const matchesKnownBleUuid = (
|
|
|
232
196
|
const ONEKEY_COMMUNICATION_SERVICE_ALIASES = createKnownBleUuidAliases(ONEKEY_SERVICE_UUID);
|
|
233
197
|
const FIDO_SERVICE_ALIASES = createKnownBleUuidAliases('0000fffd-0000-1000-8000-00805f9b34fb');
|
|
234
198
|
const PRO2_COMPACT_NAME_PATTERN = /^(?:onekey)?pro2[a-f0-9]{4}$/i;
|
|
235
|
-
const NEO_COMPACT_NAME_PATTERN = /^(?:onekey)?neo[a-f0-9]{4}$/i;
|
|
236
199
|
const FIND_MY_COMPACT_SUFFIXES = [
|
|
237
200
|
'findemy',
|
|
238
201
|
'findem',
|