@onekeyfe/hd-shared 1.1.31 → 1.1.32-alpha.4
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 -7
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +1 -7
- package/dist/index.js +6 -37
- package/package.json +2 -2
- package/src/constants.ts +6 -44
- package/src/constants.test.ts +0 -60
package/dist/constants.d.ts
CHANGED
|
@@ -3,12 +3,6 @@ export declare const ONEKEY_WEBUSB_FILTER: {
|
|
|
3
3
|
vendorId: number;
|
|
4
4
|
productId: number;
|
|
5
5
|
}[];
|
|
6
|
-
type WebUsbIdentityDescriptor = {
|
|
7
|
-
vendorId?: number;
|
|
8
|
-
productId?: number;
|
|
9
|
-
manufacturerName?: string | null;
|
|
10
|
-
};
|
|
11
|
-
export declare const isKnownTrezorWebUsbDevice: (descriptor: WebUsbIdentityDescriptor) => boolean;
|
|
12
6
|
export declare const ERROR_CODES_REQUIRE_RELEASE: readonly [106, 107, 109, 112, 805, 801, 802, 812];
|
|
13
7
|
export declare const ERROR_CODES_REQUIRE_DISCONNECT: readonly [106, 805];
|
|
14
8
|
export declare enum EOneKeyBleMessageKeys {
|
|
@@ -40,5 +34,4 @@ export declare const ONEKEY_WRITE_CHARACTERISTIC_UUID = "00000002-0000-1000-8000
|
|
|
40
34
|
export declare const ONEKEY_NOTIFY_CHARACTERISTIC_UUID = "00000003-0000-1000-8000-00805f9b34fb";
|
|
41
35
|
export declare const isHeaderChunk: (chunk: Buffer | Uint8Array) => boolean;
|
|
42
36
|
export declare const isOnekeyDevice: (name: string | null, id?: string) => boolean;
|
|
43
|
-
export {};
|
|
44
37
|
//# 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,oBAAoB;;;GAOhC,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";AAEA,eAAO,MAAM,oBAAoB;;;GAOhC,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;IAC/C,oBAAoB,iCAAiC;IACrD,eAAe,4BAA4B;IAC3C,mBAAmB,gCAAgC;IACnD,qBAAqB,kCAAkC;IACvD,sBAAsB,mCAAmC;IACzD,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;AAEF,eAAO,MAAM,cAAc,SAAU,MAAM,GAAG,IAAI,OAAO,MAAM,KAAG,OAYjE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,12 +2,6 @@ declare const ONEKEY_WEBUSB_FILTER: {
|
|
|
2
2
|
vendorId: number;
|
|
3
3
|
productId: number;
|
|
4
4
|
}[];
|
|
5
|
-
type WebUsbIdentityDescriptor = {
|
|
6
|
-
vendorId?: number;
|
|
7
|
-
productId?: number;
|
|
8
|
-
manufacturerName?: string | null;
|
|
9
|
-
};
|
|
10
|
-
declare const isKnownTrezorWebUsbDevice: (descriptor: WebUsbIdentityDescriptor) => boolean;
|
|
11
5
|
declare const ERROR_CODES_REQUIRE_RELEASE: readonly [106, 107, 109, 112, 805, 801, 802, 812];
|
|
12
6
|
declare const ERROR_CODES_REQUIRE_DISCONNECT: readonly [106, 805];
|
|
13
7
|
declare enum EOneKeyBleMessageKeys {
|
|
@@ -245,4 +239,4 @@ declare enum EDeviceType {
|
|
|
245
239
|
Pro = "pro"
|
|
246
240
|
}
|
|
247
241
|
|
|
248
|
-
export { CreateErrorByMessage, CreateHardwareErrorByBridgeError, Deferred, EDeviceType, EFirmwareType, EOneKeyBleMessageKeys, HardwareError$1 as ERRORS, ERROR_CODES_REQUIRE_DISCONNECT, ERROR_CODES_REQUIRE_RELEASE, HardwareError, HardwareErrorCode, HardwareErrorCodeMessage, IHardwareError, ONEKEY_NOTIFY_CHARACTERISTIC_UUID, ONEKEY_SERVICE_UUID, ONEKEY_WEBUSB_FILTER, ONEKEY_WRITE_CHARACTERISTIC_UUID, TypedError, createDefectiveFirmwareError, createDeferred, createDeprecatedHardwareError, createDeviceNotSupportMethodError, createNeedUpgradeFirmwareHardwareError, createNewFirmwareForceUpdateHardwareError, createNewFirmwareUnReleaseHardwareError, isHeaderChunk,
|
|
242
|
+
export { CreateErrorByMessage, CreateHardwareErrorByBridgeError, Deferred, EDeviceType, EFirmwareType, EOneKeyBleMessageKeys, HardwareError$1 as ERRORS, ERROR_CODES_REQUIRE_DISCONNECT, ERROR_CODES_REQUIRE_RELEASE, HardwareError, HardwareErrorCode, HardwareErrorCodeMessage, IHardwareError, ONEKEY_NOTIFY_CHARACTERISTIC_UUID, ONEKEY_SERVICE_UUID, ONEKEY_WEBUSB_FILTER, ONEKEY_WRITE_CHARACTERISTIC_UUID, TypedError, createDefectiveFirmwareError, createDeferred, createDeprecatedHardwareError, createDeviceNotSupportMethodError, createNeedUpgradeFirmwareHardwareError, createNewFirmwareForceUpdateHardwareError, createNewFirmwareUnReleaseHardwareError, isHeaderChunk, isOnekeyDevice, serializeError, wait };
|
package/dist/index.js
CHANGED
|
@@ -386,15 +386,6 @@ const ONEKEY_WEBUSB_FILTER = [
|
|
|
386
386
|
{ vendorId: 0x1209, productId: 0x4f4a },
|
|
387
387
|
{ vendorId: 0x1209, productId: 0x4f4b },
|
|
388
388
|
];
|
|
389
|
-
const TREZOR_WEBUSB_MANUFACTURER_NAMES = new Set(['trezor', 'trezor company', 'satoshilabs']);
|
|
390
|
-
const isKnownTrezorWebUsbDevice = (descriptor) => {
|
|
391
|
-
var _a;
|
|
392
|
-
const isSharedWebUsbId = ONEKEY_WEBUSB_FILTER.some(filter => descriptor.vendorId === filter.vendorId && descriptor.productId === filter.productId);
|
|
393
|
-
if (!isSharedWebUsbId)
|
|
394
|
-
return false;
|
|
395
|
-
const manufacturerName = (_a = descriptor.manufacturerName) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase();
|
|
396
|
-
return manufacturerName != null && TREZOR_WEBUSB_MANUFACTURER_NAMES.has(manufacturerName);
|
|
397
|
-
};
|
|
398
389
|
const ERROR_CODES_REQUIRE_RELEASE = [
|
|
399
390
|
HardwareErrorCode.DeviceInitializeFailed,
|
|
400
391
|
HardwareErrorCode.DeviceInterruptedFromOutside,
|
|
@@ -450,37 +441,16 @@ const isHeaderChunk = (chunk) => {
|
|
|
450
441
|
}
|
|
451
442
|
return false;
|
|
452
443
|
};
|
|
453
|
-
const isKnownNonOneKeyDeviceName = (normalizedName) => normalizedName.startsWith('trezor') ||
|
|
454
|
-
normalizedName.startsWith('ledger') ||
|
|
455
|
-
normalizedName.startsWith('nano ') ||
|
|
456
|
-
normalizedName.startsWith('stax') ||
|
|
457
|
-
normalizedName.startsWith('flex');
|
|
458
|
-
const ONEKEY_EXACT_SHORT_NAMES = new Set(['s8']);
|
|
459
|
-
const isOneKeyShortName = (normalizedName) => {
|
|
460
|
-
if (ONEKEY_EXACT_SHORT_NAMES.has(normalizedName))
|
|
461
|
-
return true;
|
|
462
|
-
if (normalizedName.length !== 5)
|
|
463
|
-
return false;
|
|
464
|
-
const firstChar = normalizedName[0];
|
|
465
|
-
return (firstChar === 'k' || firstChar === 't') && /^\d{4}$/.test(normalizedName.slice(1));
|
|
466
|
-
};
|
|
467
444
|
const isOnekeyDevice = (name, id) => {
|
|
468
|
-
var _a
|
|
469
|
-
|
|
470
|
-
if (isKnownNonOneKeyDeviceName(normalizedName)) {
|
|
471
|
-
return false;
|
|
472
|
-
}
|
|
473
|
-
if ((_b = id === null || id === void 0 ? void 0 : id.startsWith) === null || _b === void 0 ? void 0 : _b.call(id, 'MI')) {
|
|
445
|
+
var _a;
|
|
446
|
+
if ((_a = id === null || id === void 0 ? void 0 : id.startsWith) === null || _a === void 0 ? void 0 : _a.call(id, 'MI')) {
|
|
474
447
|
return true;
|
|
475
448
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
}
|
|
479
|
-
if (normalizedName.startsWith('onekey') || normalizedName.startsWith('bixinkey'))
|
|
449
|
+
const re = /(BixinKey\d{10})|(K\d{4})|(T\d{4})|(Touch\s\w{4})|(Pro\s\w{4})/i;
|
|
450
|
+
if (name && re.exec(name)) {
|
|
480
451
|
return true;
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
return isOneKeyShortName(normalizedName);
|
|
452
|
+
}
|
|
453
|
+
return false;
|
|
484
454
|
};
|
|
485
455
|
|
|
486
456
|
/******************************************************************************
|
|
@@ -576,7 +546,6 @@ exports.createNeedUpgradeFirmwareHardwareError = createNeedUpgradeFirmwareHardwa
|
|
|
576
546
|
exports.createNewFirmwareForceUpdateHardwareError = createNewFirmwareForceUpdateHardwareError;
|
|
577
547
|
exports.createNewFirmwareUnReleaseHardwareError = createNewFirmwareUnReleaseHardwareError;
|
|
578
548
|
exports.isHeaderChunk = isHeaderChunk;
|
|
579
|
-
exports.isKnownTrezorWebUsbDevice = isKnownTrezorWebUsbDevice;
|
|
580
549
|
exports.isOnekeyDevice = isOnekeyDevice;
|
|
581
550
|
exports.serializeError = serializeError;
|
|
582
551
|
exports.wait = wait;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-shared",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.32-alpha.4",
|
|
4
4
|
"description": "Hardware SDK's shared tool library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Hardware-SDK",
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"lint": "eslint .",
|
|
26
26
|
"lint:fix": "eslint . --fix"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "fc3bd904e2d35e9185d34c11460b53d558644009"
|
|
29
29
|
}
|
package/src/constants.ts
CHANGED
|
@@ -9,24 +9,6 @@ export const ONEKEY_WEBUSB_FILTER = [
|
|
|
9
9
|
// { vendorId: 0x1209, productId: 0x4f50 }, // Touch Board
|
|
10
10
|
];
|
|
11
11
|
|
|
12
|
-
type WebUsbIdentityDescriptor = {
|
|
13
|
-
vendorId?: number;
|
|
14
|
-
productId?: number;
|
|
15
|
-
manufacturerName?: string | null;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const TREZOR_WEBUSB_MANUFACTURER_NAMES = new Set(['trezor', 'trezor company', 'satoshilabs']);
|
|
19
|
-
|
|
20
|
-
export const isKnownTrezorWebUsbDevice = (descriptor: WebUsbIdentityDescriptor): boolean => {
|
|
21
|
-
const isSharedWebUsbId = ONEKEY_WEBUSB_FILTER.some(
|
|
22
|
-
filter => descriptor.vendorId === filter.vendorId && descriptor.productId === filter.productId
|
|
23
|
-
);
|
|
24
|
-
if (!isSharedWebUsbId) return false;
|
|
25
|
-
|
|
26
|
-
const manufacturerName = descriptor.manufacturerName?.trim().toLowerCase();
|
|
27
|
-
return manufacturerName != null && TREZOR_WEBUSB_MANUFACTURER_NAMES.has(manufacturerName);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
12
|
/**
|
|
31
13
|
* Error codes that require device release after occurrence
|
|
32
14
|
* These errors indicate the device is in an invalid state and needs to be released
|
|
@@ -107,36 +89,16 @@ export const isHeaderChunk = (chunk: Buffer | Uint8Array): boolean => {
|
|
|
107
89
|
return false;
|
|
108
90
|
};
|
|
109
91
|
|
|
110
|
-
const isKnownNonOneKeyDeviceName = (normalizedName: string): boolean =>
|
|
111
|
-
normalizedName.startsWith('trezor') ||
|
|
112
|
-
normalizedName.startsWith('ledger') ||
|
|
113
|
-
normalizedName.startsWith('nano ') ||
|
|
114
|
-
normalizedName.startsWith('stax') ||
|
|
115
|
-
normalizedName.startsWith('flex');
|
|
116
|
-
|
|
117
|
-
const ONEKEY_EXACT_SHORT_NAMES = new Set(['s8']);
|
|
118
|
-
|
|
119
|
-
const isOneKeyShortName = (normalizedName: string): boolean => {
|
|
120
|
-
if (ONEKEY_EXACT_SHORT_NAMES.has(normalizedName)) return true;
|
|
121
|
-
if (normalizedName.length !== 5) return false;
|
|
122
|
-
const firstChar = normalizedName[0];
|
|
123
|
-
return (firstChar === 'k' || firstChar === 't') && /^\d{4}$/.test(normalizedName.slice(1));
|
|
124
|
-
};
|
|
125
|
-
|
|
126
92
|
export const isOnekeyDevice = (name: string | null, id?: string): boolean => {
|
|
127
|
-
const normalizedName = name?.trim().toLowerCase() ?? '';
|
|
128
|
-
if (isKnownNonOneKeyDeviceName(normalizedName)) {
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
93
|
if (id?.startsWith?.('MI')) {
|
|
133
94
|
return true;
|
|
134
95
|
}
|
|
135
96
|
|
|
136
|
-
|
|
137
|
-
|
|
97
|
+
// 过滤 BixinKeyxxx 和 Kxxxx 和 Txxxx
|
|
98
|
+
// i 忽略大小写模式
|
|
99
|
+
const re = /(BixinKey\d{10})|(K\d{4})|(T\d{4})|(Touch\s\w{4})|(Pro\s\w{4})/i;
|
|
100
|
+
if (name && re.exec(name)) {
|
|
101
|
+
return true;
|
|
138
102
|
}
|
|
139
|
-
|
|
140
|
-
if (normalizedName.startsWith('touch ') || normalizedName.startsWith('pro ')) return true;
|
|
141
|
-
return isOneKeyShortName(normalizedName);
|
|
103
|
+
return false;
|
|
142
104
|
};
|
package/src/constants.test.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { isKnownTrezorWebUsbDevice, isOnekeyDevice } from './constants';
|
|
2
|
-
|
|
3
|
-
describe('hardware device identity filters', () => {
|
|
4
|
-
it('accepts known OneKey BLE names', () => {
|
|
5
|
-
expect(isOnekeyDevice('Touch A1B2')).toBe(true);
|
|
6
|
-
expect(isOnekeyDevice('Pro A1B2')).toBe(true);
|
|
7
|
-
expect(isOnekeyDevice('K1234')).toBe(true);
|
|
8
|
-
expect(isOnekeyDevice('S8')).toBe(true);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('rejects known Trezor and Ledger BLE names from OneKey discovery', () => {
|
|
12
|
-
expect(isOnekeyDevice('Trezor Safe 7')).toBe(false);
|
|
13
|
-
expect(isOnekeyDevice('Ledger Nano X')).toBe(false);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('only filters WebUSB descriptors that are explicitly identified as Trezor', () => {
|
|
17
|
-
expect(
|
|
18
|
-
isKnownTrezorWebUsbDevice({
|
|
19
|
-
vendorId: 0x1209,
|
|
20
|
-
productId: 0x53c1,
|
|
21
|
-
manufacturerName: 'Trezor Company',
|
|
22
|
-
})
|
|
23
|
-
).toBe(true);
|
|
24
|
-
expect(
|
|
25
|
-
isKnownTrezorWebUsbDevice({
|
|
26
|
-
vendorId: 0x1209,
|
|
27
|
-
productId: 0x53c1,
|
|
28
|
-
manufacturerName: 'Trezor',
|
|
29
|
-
})
|
|
30
|
-
).toBe(true);
|
|
31
|
-
expect(
|
|
32
|
-
isKnownTrezorWebUsbDevice({
|
|
33
|
-
vendorId: 0x1209,
|
|
34
|
-
productId: 0x53c1,
|
|
35
|
-
manufacturerName: 'SatoshiLabs',
|
|
36
|
-
})
|
|
37
|
-
).toBe(true);
|
|
38
|
-
|
|
39
|
-
expect(
|
|
40
|
-
isKnownTrezorWebUsbDevice({
|
|
41
|
-
vendorId: 0x1209,
|
|
42
|
-
productId: 0x53c1,
|
|
43
|
-
manufacturerName: 'OneKey',
|
|
44
|
-
})
|
|
45
|
-
).toBe(false);
|
|
46
|
-
expect(
|
|
47
|
-
isKnownTrezorWebUsbDevice({
|
|
48
|
-
vendorId: 0x1209,
|
|
49
|
-
productId: 0x53c1,
|
|
50
|
-
})
|
|
51
|
-
).toBe(false);
|
|
52
|
-
expect(
|
|
53
|
-
isKnownTrezorWebUsbDevice({
|
|
54
|
-
vendorId: 0x1209,
|
|
55
|
-
productId: 0x53c1,
|
|
56
|
-
productName: 'Trezor Safe 7',
|
|
57
|
-
})
|
|
58
|
-
).toBe(false);
|
|
59
|
-
});
|
|
60
|
-
});
|