@onekeyfe/hd-shared 1.2.8-alpha.9 → 1.2.9
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/HardwareError.d.ts +3 -0
- package/dist/HardwareError.d.ts.map +1 -1
- package/dist/constants.d.ts +3 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +22 -3
- package/dist/index.js +18 -0
- package/package.json +2 -2
- package/src/HardwareError.test.ts +15 -0
- package/src/HardwareError.ts +22 -0
- package/src/constants.test.ts +28 -0
- package/src/constants.ts +22 -0
package/dist/HardwareError.d.ts
CHANGED
|
@@ -58,11 +58,14 @@ export declare const HardwareErrorCode: {
|
|
|
58
58
|
readonly ForbiddenKeyPath: 416;
|
|
59
59
|
readonly RepeatUnlocking: 417;
|
|
60
60
|
readonly DefectiveFirmware: 418;
|
|
61
|
+
readonly DeviceNotSupportPath: 435;
|
|
61
62
|
readonly NetworkError: 500;
|
|
62
63
|
readonly TransportNotConfigured: 600;
|
|
63
64
|
readonly TransportCallInProgress: 601;
|
|
64
65
|
readonly TransportNotFound: 602;
|
|
65
66
|
readonly TransportInvalidProtobuf: 603;
|
|
67
|
+
readonly TransportProtocolProbeFailed: 604;
|
|
68
|
+
readonly TransportProtocolMismatch: 605;
|
|
66
69
|
readonly BleScanError: 700;
|
|
67
70
|
readonly BlePermissionError: 701;
|
|
68
71
|
readonly BleLocationError: 702;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HardwareError.d.ts","sourceRoot":"","sources":["../src/HardwareError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,OAAO,CAAC,OAAO,iBAAiB,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,GAAG,CAAC;CACd;AAED,KAAK,OAAO,CAAC,C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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqdpB,CAAC;AAEX,eAAO,MAAM,wBAAwB,EAAE,+BA+J7B,CAAC;AAEX,eAAO,MAAM,UAAU,kBACN,cAAc,GAAG,MAAM,YAC5B,MAAM,WACP,GAAG,kBAMb,CAAC;AAEF,eAAO,MAAM,cAAc,YAAa,GAAG,QAe1C,CAAC;AAEF,eAAO,MAAM,oBAAoB,YAAa,MAAM,KAAG,aAOtD,CAAC;AAGF,eAAO,MAAM,gCAAgC,QAAS,MAAM,KAAG,aAQ9D,CAAC;AAEF,QAAA,MAAM,uCAAuC;oBAM3B,MAAM;oBACN,MAAM;;;mBAcvB,CAAC;AAEF,QAAA,MAAM,sCAAsC;oBAM1B,MAAM;oBACN,MAAM;;;mBAcvB,CAAC;AAEF,QAAA,MAAM,yCAAyC,cAClC,MAAM,GAAG,SAAS,YACnB,MAAM,GAAG,SAAS,iBACb,CAAC,UAAU,GAAG,KAAK,CAAC,EAAE,oBACnB;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,kBAsBF,CAAC;AAEF,QAAA,MAAM,6BAA6B,mBACjB,MAAM,qBACH,MAAM,eACZ,MAAM,kBAQpB,CAAC;AAEF,QAAA,MAAM,4BAA4B,aACtB,MAAM,aACL,MAAM,cACL,MAAM,cACN,MAAM,aACP,MAAM,kBAWlB,CAAC;AAEF,QAAA,MAAM,iCAAiC,eAAgB,MAAM,gBAAgB,aAAa,kBAItF,CAAC;AAEL,OAAO,EACL,uCAAuC,EACvC,sCAAsC,EACtC,yCAAyC,EACzC,6BAA6B,EAC7B,4BAA4B,EAC5B,iCAAiC,GAClC,CAAC"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -18,8 +18,8 @@ type WebUsbIdentityDescriptor = {
|
|
|
18
18
|
manufacturerName?: string | null;
|
|
19
19
|
};
|
|
20
20
|
export declare const isKnownTrezorWebUsbDevice: (descriptor: WebUsbIdentityDescriptor) => boolean;
|
|
21
|
-
export declare const ERROR_CODES_REQUIRE_RELEASE: readonly [903, 106, 107, 109, 112, 805, 801, 802, 812];
|
|
22
|
-
export declare const ERROR_CODES_REQUIRE_DISCONNECT: readonly [903, 106, 805];
|
|
21
|
+
export declare const ERROR_CODES_REQUIRE_RELEASE: readonly [903, 604, 605, 106, 107, 109, 112, 805, 801, 802, 812];
|
|
22
|
+
export declare const ERROR_CODES_REQUIRE_DISCONNECT: readonly [903, 604, 605, 106, 805];
|
|
23
23
|
export declare enum EOneKeyBleMessageKeys {
|
|
24
24
|
BLE_SELECT = "$onekey-ble-select",
|
|
25
25
|
BLE_SELECT_RESULT = "$onekey-ble-select-result",
|
|
@@ -78,6 +78,7 @@ export declare const canonicalizePro2BleAdvertisementName: (value: string) => st
|
|
|
78
78
|
export declare const isSameOnekeyBleName: (left?: string | null, right?: string | null) => boolean;
|
|
79
79
|
export declare const hasOnekeyCommunicationService: (serviceUuids: Array<string | null | undefined> | null | undefined) => boolean;
|
|
80
80
|
export declare const isPro2FamilyBleName: (value?: string | null) => boolean;
|
|
81
|
+
export declare const parseOnekeyBleColorCode: (manufacturerData: Uint8Array | null | undefined) => string | undefined;
|
|
81
82
|
export declare const isOnekeyBluetoothDevice: ({ id, name, localName, serviceUuids, }: BluetoothDeviceIdentity) => boolean;
|
|
82
83
|
export {};
|
|
83
84
|
//# 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;;;EAAqD,CAAC;AAE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AI,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;AAmC/C,eAAO,MAAM,6BAA6B,WAAY,MAAM,GAAG,IAAI,YAWlE,CAAC;AAEF,eAAO,MAAM,oCAAoC,UAAW,MAAM,WAejE,CAAC;AAUF,eAAO,MAAM,oCAAoC,UAAW,MAAM,WAWjE,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;AAOJ,eAAO,MAAM,mBAAmB,WAAY,MAAM,GAAG,IAAI,KAAG,OAiB3D,CAAC;AAYF,eAAO,MAAM,uBAAuB,qBAChB,UAAU,GAAG,IAAI,GAAG,SAAS,KAC9C,MAAM,GAAG,SAIX,CAAC;AAEF,eAAO,MAAM,uBAAuB,2CAKjC,uBAAuB,KAAG,OAiB5B,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -22,12 +22,12 @@ declare const isKnownTrezorWebUsbDevice: (descriptor: WebUsbIdentityDescriptor)
|
|
|
22
22
|
* Error codes that require device release after occurrence
|
|
23
23
|
* These errors indicate the device is in an invalid state and needs to be released
|
|
24
24
|
*/
|
|
25
|
-
declare const ERROR_CODES_REQUIRE_RELEASE: readonly [903, 106, 107, 109, 112, 805, 801, 802, 812];
|
|
25
|
+
declare const ERROR_CODES_REQUIRE_RELEASE: readonly [903, 604, 605, 106, 107, 109, 112, 805, 801, 802, 812];
|
|
26
26
|
/**
|
|
27
27
|
* Error codes that require device disconnect before release
|
|
28
28
|
* These errors indicate a communication failure that requires full reconnection
|
|
29
29
|
*/
|
|
30
|
-
declare const ERROR_CODES_REQUIRE_DISCONNECT: readonly [903, 106, 805];
|
|
30
|
+
declare const ERROR_CODES_REQUIRE_DISCONNECT: readonly [903, 604, 605, 106, 805];
|
|
31
31
|
declare enum EOneKeyBleMessageKeys {
|
|
32
32
|
BLE_SELECT = "$onekey-ble-select",
|
|
33
33
|
BLE_SELECT_RESULT = "$onekey-ble-select-result",
|
|
@@ -109,6 +109,11 @@ declare const hasOnekeyCommunicationService: (serviceUuids: Array<string | null
|
|
|
109
109
|
* that carry no OneKey service UUID, so a scan cannot always see it.
|
|
110
110
|
*/
|
|
111
111
|
declare const isPro2FamilyBleName: (value?: string | null) => boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Reads the serial-number color letter from the raw 0xFF advertisement payload
|
|
114
|
+
* (the bytes after the AD type). Returns undefined when no valid letter is present.
|
|
115
|
+
*/
|
|
116
|
+
declare const parseOnekeyBleColorCode: (manufacturerData: Uint8Array | null | undefined) => string | undefined;
|
|
112
117
|
declare const isOnekeyBluetoothDevice: ({ id, name, localName, serviceUuids, }: BluetoothDeviceIdentity) => boolean;
|
|
113
118
|
|
|
114
119
|
type Deferred<T, I = any, D = any> = {
|
|
@@ -314,6 +319,10 @@ declare const HardwareErrorCode: {
|
|
|
314
319
|
* Defective firmware detected
|
|
315
320
|
*/
|
|
316
321
|
readonly DefectiveFirmware: 418;
|
|
322
|
+
/**
|
|
323
|
+
* Device cannot derive this path, whatever the safety checks say
|
|
324
|
+
*/
|
|
325
|
+
readonly DeviceNotSupportPath: 435;
|
|
317
326
|
/**
|
|
318
327
|
* Netword request error
|
|
319
328
|
*/
|
|
@@ -334,6 +343,16 @@ declare const HardwareErrorCode: {
|
|
|
334
343
|
* Transport invalid protobuf
|
|
335
344
|
*/
|
|
336
345
|
readonly TransportInvalidProtobuf: 603;
|
|
346
|
+
/**
|
|
347
|
+
* No supported device protocol answered the active probe.
|
|
348
|
+
* @params: { expectedProtocol?: 'V1' | 'V2'; attempts?: number }
|
|
349
|
+
*/
|
|
350
|
+
readonly TransportProtocolProbeFailed: 604;
|
|
351
|
+
/**
|
|
352
|
+
* The actively detected device protocol differs from the required protocol.
|
|
353
|
+
* @params: { expectedProtocol: 'V1' | 'V2'; detectedProtocol?: 'V1' | 'V2' }
|
|
354
|
+
*/
|
|
355
|
+
readonly TransportProtocolMismatch: 605;
|
|
337
356
|
/**
|
|
338
357
|
* Bluetooth error code
|
|
339
358
|
*/
|
|
@@ -584,4 +603,4 @@ declare enum EDeviceType {
|
|
|
584
603
|
Neo = "neo"
|
|
585
604
|
}
|
|
586
605
|
|
|
587
|
-
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, canonicalizePro2BleAdvertisementName, createDefectiveFirmwareError, createDeferred, createDeprecatedHardwareError, createDeviceNotSupportMethodError, createKnownBleUuidAliases, createNeedUpgradeFirmwareHardwareError, createNewFirmwareForceUpdateHardwareError, createNewFirmwareUnReleaseHardwareError, hasOnekeyCommunicationService, inferProtocolHintFromUsbId, isHeaderChunk, isKnownTrezorWebUsbDevice, isOnekeyBluetoothDevice, isOnekeyDevice, isPro2FamilyBleName, isPro2FindMyAdvertisementName, isSameOnekeyBleName, matchesKnownBleUuid, normalizeBleUuid, normalizePro2FindMyAdvertisementName, resolveOneKeyUsbDevicePath, serializeError, wait };
|
|
606
|
+
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, canonicalizePro2BleAdvertisementName, createDefectiveFirmwareError, createDeferred, createDeprecatedHardwareError, createDeviceNotSupportMethodError, createKnownBleUuidAliases, createNeedUpgradeFirmwareHardwareError, createNewFirmwareForceUpdateHardwareError, createNewFirmwareUnReleaseHardwareError, hasOnekeyCommunicationService, inferProtocolHintFromUsbId, isHeaderChunk, isKnownTrezorWebUsbDevice, isOnekeyBluetoothDevice, isOnekeyDevice, isPro2FamilyBleName, isPro2FindMyAdvertisementName, isSameOnekeyBleName, matchesKnownBleUuid, normalizeBleUuid, normalizePro2FindMyAdvertisementName, parseOnekeyBleColorCode, resolveOneKeyUsbDevicePath, serializeError, wait };
|
package/dist/index.js
CHANGED
|
@@ -107,11 +107,14 @@ const HardwareErrorCode = {
|
|
|
107
107
|
ForbiddenKeyPath: 416,
|
|
108
108
|
RepeatUnlocking: 417,
|
|
109
109
|
DefectiveFirmware: 418,
|
|
110
|
+
DeviceNotSupportPath: 435,
|
|
110
111
|
NetworkError: 500,
|
|
111
112
|
TransportNotConfigured: 600,
|
|
112
113
|
TransportCallInProgress: 601,
|
|
113
114
|
TransportNotFound: 602,
|
|
114
115
|
TransportInvalidProtobuf: 603,
|
|
116
|
+
TransportProtocolProbeFailed: 604,
|
|
117
|
+
TransportProtocolMismatch: 605,
|
|
115
118
|
BleScanError: 700,
|
|
116
119
|
BlePermissionError: 701,
|
|
117
120
|
BleLocationError: 702,
|
|
@@ -217,11 +220,14 @@ const HardwareErrorCodeMessage = {
|
|
|
217
220
|
[HardwareErrorCode.ForbiddenKeyPath]: 'Forbidden key path',
|
|
218
221
|
[HardwareErrorCode.RepeatUnlocking]: 'Repeat unlocking',
|
|
219
222
|
[HardwareErrorCode.DefectiveFirmware]: 'Device firmware is defective, please update immediately',
|
|
223
|
+
[HardwareErrorCode.DeviceNotSupportPath]: 'Device not support this path',
|
|
220
224
|
[HardwareErrorCode.NetworkError]: 'Network request error',
|
|
221
225
|
[HardwareErrorCode.TransportNotConfigured]: 'Transport not configured',
|
|
222
226
|
[HardwareErrorCode.TransportCallInProgress]: 'Transport call in progress',
|
|
223
227
|
[HardwareErrorCode.TransportNotFound]: 'Transport not found',
|
|
224
228
|
[HardwareErrorCode.TransportInvalidProtobuf]: 'Transport invalid protobuf',
|
|
229
|
+
[HardwareErrorCode.TransportProtocolProbeFailed]: 'Failed to detect the device communication protocol. Reconnect the device and try again.',
|
|
230
|
+
[HardwareErrorCode.TransportProtocolMismatch]: 'The device communication protocol does not match the expected protocol.',
|
|
225
231
|
[HardwareErrorCode.BleScanError]: 'BLE scan error',
|
|
226
232
|
[HardwareErrorCode.BlePermissionError]: 'Bluetooth required to be turned on',
|
|
227
233
|
[HardwareErrorCode.BleLocationError]: 'Bluetooth or location permissions for the application are not available',
|
|
@@ -415,6 +421,8 @@ const isKnownTrezorWebUsbDevice = (descriptor) => {
|
|
|
415
421
|
};
|
|
416
422
|
const ERROR_CODES_REQUIRE_RELEASE = [
|
|
417
423
|
HardwareErrorCode.WebUsbDeviceAccessError,
|
|
424
|
+
HardwareErrorCode.TransportProtocolProbeFailed,
|
|
425
|
+
HardwareErrorCode.TransportProtocolMismatch,
|
|
418
426
|
HardwareErrorCode.DeviceInitializeFailed,
|
|
419
427
|
HardwareErrorCode.DeviceInterruptedFromOutside,
|
|
420
428
|
HardwareErrorCode.DeviceInterruptedFromUser,
|
|
@@ -426,6 +434,8 @@ const ERROR_CODES_REQUIRE_RELEASE = [
|
|
|
426
434
|
];
|
|
427
435
|
const ERROR_CODES_REQUIRE_DISCONNECT = [
|
|
428
436
|
HardwareErrorCode.WebUsbDeviceAccessError,
|
|
437
|
+
HardwareErrorCode.TransportProtocolProbeFailed,
|
|
438
|
+
HardwareErrorCode.TransportProtocolMismatch,
|
|
429
439
|
HardwareErrorCode.DeviceInitializeFailed,
|
|
430
440
|
HardwareErrorCode.ResponseUnexpectTypeError,
|
|
431
441
|
];
|
|
@@ -644,6 +654,13 @@ const isPro2FamilyBleName = (value) => {
|
|
|
644
654
|
NEO_COMPACT_NAME_PATTERN.test(compact) ||
|
|
645
655
|
isPro2FindMyAdvertisementName(value));
|
|
646
656
|
};
|
|
657
|
+
const ONEKEY_BLE_COLOR_PAYLOAD_LENGTH = 5;
|
|
658
|
+
const parseOnekeyBleColorCode = (manufacturerData) => {
|
|
659
|
+
if ((manufacturerData === null || manufacturerData === void 0 ? void 0 : manufacturerData.length) !== ONEKEY_BLE_COLOR_PAYLOAD_LENGTH)
|
|
660
|
+
return undefined;
|
|
661
|
+
const code = manufacturerData[0];
|
|
662
|
+
return code >= 0x41 && code <= 0x5a ? String.fromCharCode(code) : undefined;
|
|
663
|
+
};
|
|
647
664
|
const isOnekeyBluetoothDevice = ({ id, name, localName, serviceUuids, }) => {
|
|
648
665
|
const advertisedServiceUuids = serviceUuids !== null && serviceUuids !== void 0 ? serviceUuids : [];
|
|
649
666
|
if (hasOnekeyCommunicationService(advertisedServiceUuids)) {
|
|
@@ -768,6 +785,7 @@ exports.isSameOnekeyBleName = isSameOnekeyBleName;
|
|
|
768
785
|
exports.matchesKnownBleUuid = matchesKnownBleUuid;
|
|
769
786
|
exports.normalizeBleUuid = normalizeBleUuid;
|
|
770
787
|
exports.normalizePro2FindMyAdvertisementName = normalizePro2FindMyAdvertisementName;
|
|
788
|
+
exports.parseOnekeyBleColorCode = parseOnekeyBleColorCode;
|
|
771
789
|
exports.resolveOneKeyUsbDevicePath = resolveOneKeyUsbDevicePath;
|
|
772
790
|
exports.serializeError = serializeError;
|
|
773
791
|
exports.wait = wait;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-shared",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.9",
|
|
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": "36cc567ae08ffb9190b44efc6430d4199343be9e"
|
|
30
30
|
}
|
|
@@ -4,8 +4,23 @@ import {
|
|
|
4
4
|
TypedError,
|
|
5
5
|
serializeError,
|
|
6
6
|
} from './HardwareError';
|
|
7
|
+
import { ERROR_CODES_REQUIRE_DISCONNECT, ERROR_CODES_REQUIRE_RELEASE } from './constants';
|
|
7
8
|
|
|
8
9
|
describe('HardwareErrorCode compatibility', () => {
|
|
10
|
+
test.each([
|
|
11
|
+
['TransportProtocolProbeFailed', 604, { expectedProtocol: 'V1' }],
|
|
12
|
+
['TransportProtocolMismatch', 605, { expectedProtocol: 'V2', detectedProtocol: 'V1' }],
|
|
13
|
+
] as const)('serializes the dedicated %s transport error', (name, code, params) => {
|
|
14
|
+
expect(HardwareErrorCode[name]).toBe(code);
|
|
15
|
+
const message = HardwareErrorCodeMessage[HardwareErrorCode[name]];
|
|
16
|
+
expect(message).toBeTruthy();
|
|
17
|
+
expect(ERROR_CODES_REQUIRE_RELEASE).toContain(code);
|
|
18
|
+
expect(ERROR_CODES_REQUIRE_DISCONNECT).toContain(code);
|
|
19
|
+
expect(
|
|
20
|
+
JSON.parse(JSON.stringify(serializeError({ error: TypedError(code, undefined, params) })))
|
|
21
|
+
).toEqual({ code, error: message, params });
|
|
22
|
+
});
|
|
23
|
+
|
|
9
24
|
test('preserves published Protocol V2 values while leaving code 829 unused', () => {
|
|
10
25
|
expect(HardwareErrorCode).not.toHaveProperty('KaspaPrevTxIdMismatch');
|
|
11
26
|
expect(HardwareErrorCode.DeviceLocked).toBe(830);
|
package/src/HardwareError.ts
CHANGED
|
@@ -294,6 +294,11 @@ export const HardwareErrorCode = {
|
|
|
294
294
|
*/
|
|
295
295
|
DefectiveFirmware: 418,
|
|
296
296
|
|
|
297
|
+
/**
|
|
298
|
+
* Device cannot derive this path, whatever the safety checks say
|
|
299
|
+
*/
|
|
300
|
+
DeviceNotSupportPath: 435,
|
|
301
|
+
|
|
297
302
|
/**
|
|
298
303
|
* Netword request error
|
|
299
304
|
*/
|
|
@@ -319,6 +324,18 @@ export const HardwareErrorCode = {
|
|
|
319
324
|
*/
|
|
320
325
|
TransportInvalidProtobuf: 603,
|
|
321
326
|
|
|
327
|
+
/**
|
|
328
|
+
* No supported device protocol answered the active probe.
|
|
329
|
+
* @params: { expectedProtocol?: 'V1' | 'V2'; attempts?: number }
|
|
330
|
+
*/
|
|
331
|
+
TransportProtocolProbeFailed: 604,
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* The actively detected device protocol differs from the required protocol.
|
|
335
|
+
* @params: { expectedProtocol: 'V1' | 'V2'; detectedProtocol?: 'V1' | 'V2' }
|
|
336
|
+
*/
|
|
337
|
+
TransportProtocolMismatch: 605,
|
|
338
|
+
|
|
322
339
|
/**
|
|
323
340
|
* Bluetooth error code
|
|
324
341
|
*/
|
|
@@ -592,6 +609,7 @@ export const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping = {
|
|
|
592
609
|
[HardwareErrorCode.ForbiddenKeyPath]: 'Forbidden key path',
|
|
593
610
|
[HardwareErrorCode.RepeatUnlocking]: 'Repeat unlocking',
|
|
594
611
|
[HardwareErrorCode.DefectiveFirmware]: 'Device firmware is defective, please update immediately',
|
|
612
|
+
[HardwareErrorCode.DeviceNotSupportPath]: 'Device not support this path',
|
|
595
613
|
|
|
596
614
|
/**
|
|
597
615
|
* Network Errors
|
|
@@ -605,6 +623,10 @@ export const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping = {
|
|
|
605
623
|
[HardwareErrorCode.TransportCallInProgress]: 'Transport call in progress',
|
|
606
624
|
[HardwareErrorCode.TransportNotFound]: 'Transport not found',
|
|
607
625
|
[HardwareErrorCode.TransportInvalidProtobuf]: 'Transport invalid protobuf',
|
|
626
|
+
[HardwareErrorCode.TransportProtocolProbeFailed]:
|
|
627
|
+
'Failed to detect the device communication protocol. Reconnect the device and try again.',
|
|
628
|
+
[HardwareErrorCode.TransportProtocolMismatch]:
|
|
629
|
+
'The device communication protocol does not match the expected protocol.',
|
|
608
630
|
|
|
609
631
|
/**
|
|
610
632
|
* Bluetooth Error
|
package/src/constants.test.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
isSameOnekeyBleName,
|
|
11
11
|
matchesKnownBleUuid,
|
|
12
12
|
normalizePro2FindMyAdvertisementName,
|
|
13
|
+
parseOnekeyBleColorCode,
|
|
13
14
|
resolveOneKeyUsbDevicePath,
|
|
14
15
|
} from './constants';
|
|
15
16
|
|
|
@@ -251,3 +252,30 @@ describe('hardware device identity filters', () => {
|
|
|
251
252
|
).toBe(false);
|
|
252
253
|
});
|
|
253
254
|
});
|
|
255
|
+
|
|
256
|
+
describe('Pro2 / Neo BLE advertisement color', () => {
|
|
257
|
+
it('reads the serial-number color letter from the 5-byte payload', () => {
|
|
258
|
+
expect(parseOnekeyBleColorCode(Uint8Array.from([0x41, 0, 0, 0, 0]))).toBe('A');
|
|
259
|
+
expect(parseOnekeyBleColorCode(Uint8Array.from([0x46, 0x12, 0x34, 0x56, 0x78]))).toBe('F');
|
|
260
|
+
expect(parseOnekeyBleColorCode(Buffer.from([0x5a, 0, 0, 0, 0]))).toBe('Z');
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('treats a missing serial number or a non-letter byte as unknown', () => {
|
|
264
|
+
expect(parseOnekeyBleColorCode(Uint8Array.from([0x00, 0, 0, 0, 0]))).toBeUndefined();
|
|
265
|
+
expect(parseOnekeyBleColorCode(Uint8Array.from([0x61, 0, 0, 0, 0]))).toBeUndefined();
|
|
266
|
+
expect(parseOnekeyBleColorCode(Uint8Array.from([0x31, 0, 0, 0, 0]))).toBeUndefined();
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it('does not read a color from other manufacturer data layouts', () => {
|
|
270
|
+
// Pro2 / Neo BLE firmware before the color: a 4-byte zero nonce.
|
|
271
|
+
expect(parseOnekeyBleColorCode(Uint8Array.from([0, 0, 0, 0]))).toBeUndefined();
|
|
272
|
+
// Classic: company ID 0x00FE followed by the MAC.
|
|
273
|
+
expect(
|
|
274
|
+
parseOnekeyBleColorCode(Uint8Array.from([0xfe, 0x00, 0x41, 1, 2, 3, 4, 5]))
|
|
275
|
+
).toBeUndefined();
|
|
276
|
+
expect(parseOnekeyBleColorCode(Uint8Array.from([0x41, 0, 0, 0, 0, 0]))).toBeUndefined();
|
|
277
|
+
expect(parseOnekeyBleColorCode(new Uint8Array())).toBeUndefined();
|
|
278
|
+
expect(parseOnekeyBleColorCode(null)).toBeUndefined();
|
|
279
|
+
expect(parseOnekeyBleColorCode(undefined)).toBeUndefined();
|
|
280
|
+
});
|
|
281
|
+
});
|
package/src/constants.ts
CHANGED
|
@@ -44,6 +44,8 @@ export const isKnownTrezorWebUsbDevice = (descriptor: WebUsbIdentityDescriptor):
|
|
|
44
44
|
*/
|
|
45
45
|
export const ERROR_CODES_REQUIRE_RELEASE = [
|
|
46
46
|
HardwareErrorCode.WebUsbDeviceAccessError,
|
|
47
|
+
HardwareErrorCode.TransportProtocolProbeFailed,
|
|
48
|
+
HardwareErrorCode.TransportProtocolMismatch,
|
|
47
49
|
HardwareErrorCode.DeviceInitializeFailed,
|
|
48
50
|
HardwareErrorCode.DeviceInterruptedFromOutside,
|
|
49
51
|
HardwareErrorCode.DeviceInterruptedFromUser,
|
|
@@ -60,6 +62,8 @@ export const ERROR_CODES_REQUIRE_RELEASE = [
|
|
|
60
62
|
*/
|
|
61
63
|
export const ERROR_CODES_REQUIRE_DISCONNECT = [
|
|
62
64
|
HardwareErrorCode.WebUsbDeviceAccessError,
|
|
65
|
+
HardwareErrorCode.TransportProtocolProbeFailed,
|
|
66
|
+
HardwareErrorCode.TransportProtocolMismatch,
|
|
63
67
|
HardwareErrorCode.DeviceInitializeFailed,
|
|
64
68
|
HardwareErrorCode.ResponseUnexpectTypeError,
|
|
65
69
|
] as const;
|
|
@@ -370,6 +374,24 @@ export const isPro2FamilyBleName = (value?: string | null): boolean => {
|
|
|
370
374
|
);
|
|
371
375
|
};
|
|
372
376
|
|
|
377
|
+
// Pro2 / Neo manufacturer-specific data has no Bluetooth SIG company ID: byte 0 is
|
|
378
|
+
// serial_number[10] (the color letter, 0x00 before the SN is known) and bytes 1-4
|
|
379
|
+
// are a nonce. Older Pro2 / Neo firmware sends 4 zero bytes and Classic sends a
|
|
380
|
+
// company ID plus MAC, so any other length is not a color.
|
|
381
|
+
const ONEKEY_BLE_COLOR_PAYLOAD_LENGTH = 5;
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Reads the serial-number color letter from the raw 0xFF advertisement payload
|
|
385
|
+
* (the bytes after the AD type). Returns undefined when no valid letter is present.
|
|
386
|
+
*/
|
|
387
|
+
export const parseOnekeyBleColorCode = (
|
|
388
|
+
manufacturerData: Uint8Array | null | undefined
|
|
389
|
+
): string | undefined => {
|
|
390
|
+
if (manufacturerData?.length !== ONEKEY_BLE_COLOR_PAYLOAD_LENGTH) return undefined;
|
|
391
|
+
const code = manufacturerData[0];
|
|
392
|
+
return code >= 0x41 && code <= 0x5a ? String.fromCharCode(code) : undefined;
|
|
393
|
+
};
|
|
394
|
+
|
|
373
395
|
export const isOnekeyBluetoothDevice = ({
|
|
374
396
|
id,
|
|
375
397
|
name,
|