@onekeyfe/hd-shared 1.2.8 → 1.2.10-alpha.1

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.
@@ -63,6 +63,8 @@ export declare const HardwareErrorCode: {
63
63
  readonly TransportCallInProgress: 601;
64
64
  readonly TransportNotFound: 602;
65
65
  readonly TransportInvalidProtobuf: 603;
66
+ readonly TransportProtocolProbeFailed: 604;
67
+ readonly TransportProtocolMismatch: 605;
66
68
  readonly BleScanError: 700;
67
69
  readonly BlePermissionError: 701;
68
70
  readonly BleLocationError: 702;
@@ -123,11 +125,10 @@ export declare const HardwareErrorCode: {
123
125
  readonly LowlevelTrasnportConnectError: 900;
124
126
  readonly WebDeviceNotFoundOrNeedsPermission: 901;
125
127
  readonly WebDevicePromptAccessError: 902;
128
+ readonly WebUsbDeviceAccessError: 903;
126
129
  };
127
130
  export declare const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping;
128
131
  export declare const TypedError: (hardwareError: ErrorCodeUnion | string, message?: string, params?: any) => HardwareError;
129
- export declare const isBleStaleBondHardwareError: (error: unknown) => boolean;
130
- export declare const isBleStaleBondErrorText: (text: string) => boolean;
131
132
  export declare const serializeError: (payload: any) => any;
132
133
  export declare const CreateErrorByMessage: (message: string) => HardwareError;
133
134
  export declare const CreateHardwareErrorByBridgeError: (raw: string) => HardwareError;
@@ -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,CAAC,SAAS,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,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;;;;;;;;;;;;;;;;CAgdpB,CAAC;AAEX,eAAO,MAAM,wBAAwB,EAAE,+BA8J7B,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"}
@@ -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 [106, 107, 109, 112, 805, 801, 802, 812];
22
- export declare const ERROR_CODES_REQUIRE_DISCONNECT: readonly [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
@@ -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,CA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AAM,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 [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 [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> = {
@@ -334,6 +339,16 @@ declare const HardwareErrorCode: {
334
339
  * Transport invalid protobuf
335
340
  */
336
341
  readonly TransportInvalidProtobuf: 603;
342
+ /**
343
+ * No supported device protocol answered the active probe.
344
+ * @params: { expectedProtocol?: 'V1' | 'V2'; attempts?: number }
345
+ */
346
+ readonly TransportProtocolProbeFailed: 604;
347
+ /**
348
+ * The actively detected device protocol differs from the required protocol.
349
+ * @params: { expectedProtocol: 'V1' | 'V2'; detectedProtocol?: 'V1' | 'V2' }
350
+ */
351
+ readonly TransportProtocolMismatch: 605;
337
352
  /**
338
353
  * Bluetooth error code
339
354
  */
@@ -449,7 +464,7 @@ declare const HardwareErrorCode: {
449
464
  */
450
465
  readonly FirmwareVerificationFailed: 820;
451
466
  /**
452
- * Web bridge coonect needs permission
467
+ * USB access needs OS permission (bridge/libusb or WebUSB).
453
468
  */
454
469
  readonly BridgeNeedsPermission: 821;
455
470
  readonly CallQueueActionCancelled: 822;
@@ -505,11 +520,14 @@ declare const HardwareErrorCode: {
505
520
  * Web USB or Web Bluetooth device prompt access error
506
521
  */
507
522
  readonly WebDevicePromptAccessError: 902;
523
+ /**
524
+ * WebUSB device is present, but its interface or endpoint is unavailable
525
+ * @params: { operation: 'open' | 'claimInterface' | 'transferIn' | 'transferOut'; nativeErrorName?: string; nativeErrorMessage?: string }
526
+ */
527
+ readonly WebUsbDeviceAccessError: 903;
508
528
  };
509
529
  declare const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping;
510
530
  declare const TypedError: (hardwareError: ErrorCodeUnion | string, message?: string, params?: any) => HardwareError;
511
- declare const isBleStaleBondHardwareError: (error: unknown) => boolean;
512
- declare const isBleStaleBondErrorText: (text: string) => boolean;
513
531
  declare const serializeError: (payload: any) => any;
514
532
  declare const CreateErrorByMessage: (message: string) => HardwareError;
515
533
  declare const CreateHardwareErrorByBridgeError: (raw: string) => HardwareError;
@@ -545,8 +563,6 @@ declare const HardwareError$1_HardwareError: typeof HardwareError;
545
563
  declare const HardwareError$1_HardwareErrorCode: typeof HardwareErrorCode;
546
564
  declare const HardwareError$1_HardwareErrorCodeMessage: typeof HardwareErrorCodeMessage;
547
565
  declare const HardwareError$1_TypedError: typeof TypedError;
548
- declare const HardwareError$1_isBleStaleBondHardwareError: typeof isBleStaleBondHardwareError;
549
- declare const HardwareError$1_isBleStaleBondErrorText: typeof isBleStaleBondErrorText;
550
566
  declare const HardwareError$1_serializeError: typeof serializeError;
551
567
  declare const HardwareError$1_CreateErrorByMessage: typeof CreateErrorByMessage;
552
568
  declare const HardwareError$1_CreateHardwareErrorByBridgeError: typeof CreateHardwareErrorByBridgeError;
@@ -563,8 +579,6 @@ declare namespace HardwareError$1 {
563
579
  HardwareError$1_HardwareErrorCode as HardwareErrorCode,
564
580
  HardwareError$1_HardwareErrorCodeMessage as HardwareErrorCodeMessage,
565
581
  HardwareError$1_TypedError as TypedError,
566
- HardwareError$1_isBleStaleBondHardwareError as isBleStaleBondHardwareError,
567
- HardwareError$1_isBleStaleBondErrorText as isBleStaleBondErrorText,
568
582
  HardwareError$1_serializeError as serializeError,
569
583
  HardwareError$1_CreateErrorByMessage as CreateErrorByMessage,
570
584
  HardwareError$1_CreateHardwareErrorByBridgeError as CreateHardwareErrorByBridgeError,
@@ -585,4 +599,4 @@ declare enum EDeviceType {
585
599
  Neo = "neo"
586
600
  }
587
601
 
588
- 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, isBleStaleBondErrorText, isBleStaleBondHardwareError, isHeaderChunk, isKnownTrezorWebUsbDevice, isOnekeyBluetoothDevice, isOnekeyDevice, isPro2FamilyBleName, isPro2FindMyAdvertisementName, isSameOnekeyBleName, matchesKnownBleUuid, normalizeBleUuid, normalizePro2FindMyAdvertisementName, resolveOneKeyUsbDevicePath, serializeError, wait };
602
+ 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
@@ -112,6 +112,8 @@ const HardwareErrorCode = {
112
112
  TransportCallInProgress: 601,
113
113
  TransportNotFound: 602,
114
114
  TransportInvalidProtobuf: 603,
115
+ TransportProtocolProbeFailed: 604,
116
+ TransportProtocolMismatch: 605,
115
117
  BleScanError: 700,
116
118
  BlePermissionError: 701,
117
119
  BleLocationError: 702,
@@ -172,6 +174,7 @@ const HardwareErrorCode = {
172
174
  LowlevelTrasnportConnectError: 900,
173
175
  WebDeviceNotFoundOrNeedsPermission: 901,
174
176
  WebDevicePromptAccessError: 902,
177
+ WebUsbDeviceAccessError: 903,
175
178
  };
176
179
  const HardwareErrorCodeMessage = {
177
180
  [HardwareErrorCode.UnknownError]: 'Unknown error occurred. Check message property.',
@@ -221,9 +224,11 @@ const HardwareErrorCodeMessage = {
221
224
  [HardwareErrorCode.TransportCallInProgress]: 'Transport call in progress',
222
225
  [HardwareErrorCode.TransportNotFound]: 'Transport not found',
223
226
  [HardwareErrorCode.TransportInvalidProtobuf]: 'Transport invalid protobuf',
227
+ [HardwareErrorCode.TransportProtocolProbeFailed]: 'Failed to detect the device communication protocol. Reconnect the device and try again.',
228
+ [HardwareErrorCode.TransportProtocolMismatch]: 'The device communication protocol does not match the expected protocol.',
224
229
  [HardwareErrorCode.BleScanError]: 'BLE scan error',
225
230
  [HardwareErrorCode.BlePermissionError]: 'Bluetooth required to be turned on',
226
- [HardwareErrorCode.BleLocationError]: 'Location permissions for the application are not available',
231
+ [HardwareErrorCode.BleLocationError]: 'Bluetooth or location permissions for the application are not available',
227
232
  [HardwareErrorCode.BleRequiredUUID]: 'uuid is required',
228
233
  [HardwareErrorCode.BleConnectedError]: 'connected error is always runtime error',
229
234
  [HardwareErrorCode.BleDeviceNotBonded]: 'device is not bonded',
@@ -281,6 +286,7 @@ const HardwareErrorCodeMessage = {
281
286
  [HardwareErrorCode.LowlevelTrasnportConnectError]: 'Lowlevel transport connect error',
282
287
  [HardwareErrorCode.WebDeviceNotFoundOrNeedsPermission]: 'Web-USB or Web-Bluetooth device not found or needs permission',
283
288
  [HardwareErrorCode.WebDevicePromptAccessError]: 'Web-USB or Web-Bluetooth device prompt access error',
289
+ [HardwareErrorCode.WebUsbDeviceAccessError]: 'WebUSB device access failed',
284
290
  };
285
291
  const TypedError = (hardwareError, message, params) => {
286
292
  if (typeof hardwareError === 'string') {
@@ -288,20 +294,6 @@ const TypedError = (hardwareError, message, params) => {
288
294
  }
289
295
  return new HardwareError({ errorCode: hardwareError, message: message !== null && message !== void 0 ? message : '', params });
290
296
  };
291
- const isBleStaleBondHardwareError = (error) => {
292
- const code = error === null || error === void 0 ? void 0 : error.errorCode;
293
- return (code === HardwareErrorCode.BleDeviceBondError ||
294
- code === HardwareErrorCode.BlePeerRemovedPairingInformation ||
295
- code === HardwareErrorCode.BleBondInvalid);
296
- };
297
- const isBleStaleBondErrorText = (text) => {
298
- const value = text.toLowerCase();
299
- return (value.includes('encryption is insufficient') ||
300
- value.includes('insufficient encryption') ||
301
- value.includes('peer removed pairing information') ||
302
- value.includes('cberrordomain:14') ||
303
- value.includes('gatt_insuf_authentication'));
304
- };
305
297
  const serializeError = (payload) => {
306
298
  if (payload && payload.error instanceof HardwareError) {
307
299
  return {
@@ -393,8 +385,6 @@ var HardwareError$1 = /*#__PURE__*/Object.freeze({
393
385
  HardwareErrorCode: HardwareErrorCode,
394
386
  HardwareErrorCodeMessage: HardwareErrorCodeMessage,
395
387
  TypedError: TypedError,
396
- isBleStaleBondHardwareError: isBleStaleBondHardwareError,
397
- isBleStaleBondErrorText: isBleStaleBondErrorText,
398
388
  serializeError: serializeError,
399
389
  CreateErrorByMessage: CreateErrorByMessage,
400
390
  CreateHardwareErrorByBridgeError: CreateHardwareErrorByBridgeError,
@@ -428,6 +418,9 @@ const isKnownTrezorWebUsbDevice = (descriptor) => {
428
418
  return manufacturerName != null && TREZOR_WEBUSB_MANUFACTURER_NAMES.has(manufacturerName);
429
419
  };
430
420
  const ERROR_CODES_REQUIRE_RELEASE = [
421
+ HardwareErrorCode.WebUsbDeviceAccessError,
422
+ HardwareErrorCode.TransportProtocolProbeFailed,
423
+ HardwareErrorCode.TransportProtocolMismatch,
431
424
  HardwareErrorCode.DeviceInitializeFailed,
432
425
  HardwareErrorCode.DeviceInterruptedFromOutside,
433
426
  HardwareErrorCode.DeviceInterruptedFromUser,
@@ -438,6 +431,9 @@ const ERROR_CODES_REQUIRE_RELEASE = [
438
431
  HardwareErrorCode.UnexpectPassphrase,
439
432
  ];
440
433
  const ERROR_CODES_REQUIRE_DISCONNECT = [
434
+ HardwareErrorCode.WebUsbDeviceAccessError,
435
+ HardwareErrorCode.TransportProtocolProbeFailed,
436
+ HardwareErrorCode.TransportProtocolMismatch,
441
437
  HardwareErrorCode.DeviceInitializeFailed,
442
438
  HardwareErrorCode.ResponseUnexpectTypeError,
443
439
  ];
@@ -656,6 +652,13 @@ const isPro2FamilyBleName = (value) => {
656
652
  NEO_COMPACT_NAME_PATTERN.test(compact) ||
657
653
  isPro2FindMyAdvertisementName(value));
658
654
  };
655
+ const ONEKEY_BLE_COLOR_PAYLOAD_LENGTH = 5;
656
+ const parseOnekeyBleColorCode = (manufacturerData) => {
657
+ if ((manufacturerData === null || manufacturerData === void 0 ? void 0 : manufacturerData.length) !== ONEKEY_BLE_COLOR_PAYLOAD_LENGTH)
658
+ return undefined;
659
+ const code = manufacturerData[0];
660
+ return code >= 0x41 && code <= 0x5a ? String.fromCharCode(code) : undefined;
661
+ };
659
662
  const isOnekeyBluetoothDevice = ({ id, name, localName, serviceUuids, }) => {
660
663
  const advertisedServiceUuids = serviceUuids !== null && serviceUuids !== void 0 ? serviceUuids : [];
661
664
  if (hasOnekeyCommunicationService(advertisedServiceUuids)) {
@@ -770,8 +773,6 @@ exports.createNewFirmwareForceUpdateHardwareError = createNewFirmwareForceUpdate
770
773
  exports.createNewFirmwareUnReleaseHardwareError = createNewFirmwareUnReleaseHardwareError;
771
774
  exports.hasOnekeyCommunicationService = hasOnekeyCommunicationService;
772
775
  exports.inferProtocolHintFromUsbId = inferProtocolHintFromUsbId;
773
- exports.isBleStaleBondErrorText = isBleStaleBondErrorText;
774
- exports.isBleStaleBondHardwareError = isBleStaleBondHardwareError;
775
776
  exports.isHeaderChunk = isHeaderChunk;
776
777
  exports.isKnownTrezorWebUsbDevice = isKnownTrezorWebUsbDevice;
777
778
  exports.isOnekeyBluetoothDevice = isOnekeyBluetoothDevice;
@@ -782,6 +783,7 @@ exports.isSameOnekeyBleName = isSameOnekeyBleName;
782
783
  exports.matchesKnownBleUuid = matchesKnownBleUuid;
783
784
  exports.normalizeBleUuid = normalizeBleUuid;
784
785
  exports.normalizePro2FindMyAdvertisementName = normalizePro2FindMyAdvertisementName;
786
+ exports.parseOnekeyBleColorCode = parseOnekeyBleColorCode;
785
787
  exports.resolveOneKeyUsbDevicePath = resolveOneKeyUsbDevicePath;
786
788
  exports.serializeError = serializeError;
787
789
  exports.wait = wait;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-shared",
3
- "version": "1.2.8",
3
+ "version": "1.2.10-alpha.1",
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": "9f016278a7f395bf66b8502815dc63191e162fd3"
29
+ "gitHead": "df785eba29f144fac2cfdcbd808426e0a2c259b2"
30
30
  }
@@ -2,11 +2,25 @@ import {
2
2
  HardwareErrorCode,
3
3
  HardwareErrorCodeMessage,
4
4
  TypedError,
5
- isBleStaleBondErrorText,
6
5
  serializeError,
7
6
  } from './HardwareError';
7
+ import { ERROR_CODES_REQUIRE_DISCONNECT, ERROR_CODES_REQUIRE_RELEASE } from './constants';
8
8
 
9
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
+
10
24
  test('preserves published Protocol V2 values while leaving code 829 unused', () => {
11
25
  expect(HardwareErrorCode).not.toHaveProperty('KaspaPrevTxIdMismatch');
12
26
  expect(HardwareErrorCode.DeviceLocked).toBe(830);
@@ -50,14 +64,4 @@ describe('HardwareErrorCode compatibility', () => {
50
64
  'pairing information is no longer valid'
51
65
  );
52
66
  });
53
-
54
- test('recognizes the macOS CoreBluetooth stale-pairing error without matching generic failures', () => {
55
- expect(
56
- isBleStaleBondErrorText(
57
- 'CBErrorDomain:14 Peer removed pairing information on the device side'
58
- )
59
- ).toBe(true);
60
- expect(isBleStaleBondErrorText('CBATTErrorDomain:14 localized native message')).toBe(false);
61
- expect(isBleStaleBondErrorText('connection failed')).toBe(false);
62
- });
63
67
  });
@@ -319,6 +319,18 @@ export const HardwareErrorCode = {
319
319
  */
320
320
  TransportInvalidProtobuf: 603,
321
321
 
322
+ /**
323
+ * No supported device protocol answered the active probe.
324
+ * @params: { expectedProtocol?: 'V1' | 'V2'; attempts?: number }
325
+ */
326
+ TransportProtocolProbeFailed: 604,
327
+
328
+ /**
329
+ * The actively detected device protocol differs from the required protocol.
330
+ * @params: { expectedProtocol: 'V1' | 'V2'; detectedProtocol?: 'V1' | 'V2' }
331
+ */
332
+ TransportProtocolMismatch: 605,
333
+
322
334
  /**
323
335
  * Bluetooth error code
324
336
  */
@@ -456,7 +468,7 @@ export const HardwareErrorCode = {
456
468
  FirmwareVerificationFailed: 820,
457
469
 
458
470
  /**
459
- * Web bridge coonect needs permission
471
+ * USB access needs OS permission (bridge/libusb or WebUSB).
460
472
  */
461
473
  BridgeNeedsPermission: 821,
462
474
 
@@ -522,6 +534,12 @@ export const HardwareErrorCode = {
522
534
  * Web USB or Web Bluetooth device prompt access error
523
535
  */
524
536
  WebDevicePromptAccessError: 902,
537
+
538
+ /**
539
+ * WebUSB device is present, but its interface or endpoint is unavailable
540
+ * @params: { operation: 'open' | 'claimInterface' | 'transferIn' | 'transferOut'; nativeErrorName?: string; nativeErrorMessage?: string }
541
+ */
542
+ WebUsbDeviceAccessError: 903,
525
543
  } as const;
526
544
 
527
545
  export const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping = {
@@ -599,6 +617,10 @@ export const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping = {
599
617
  [HardwareErrorCode.TransportCallInProgress]: 'Transport call in progress',
600
618
  [HardwareErrorCode.TransportNotFound]: 'Transport not found',
601
619
  [HardwareErrorCode.TransportInvalidProtobuf]: 'Transport invalid protobuf',
620
+ [HardwareErrorCode.TransportProtocolProbeFailed]:
621
+ 'Failed to detect the device communication protocol. Reconnect the device and try again.',
622
+ [HardwareErrorCode.TransportProtocolMismatch]:
623
+ 'The device communication protocol does not match the expected protocol.',
602
624
 
603
625
  /**
604
626
  * Bluetooth Error
@@ -606,7 +628,7 @@ export const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping = {
606
628
  [HardwareErrorCode.BleScanError]: 'BLE scan error',
607
629
  [HardwareErrorCode.BlePermissionError]: 'Bluetooth required to be turned on',
608
630
  [HardwareErrorCode.BleLocationError]:
609
- 'Location permissions for the application are not available',
631
+ 'Bluetooth or location permissions for the application are not available',
610
632
  [HardwareErrorCode.BleRequiredUUID]: 'uuid is required',
611
633
  [HardwareErrorCode.BleConnectedError]: 'connected error is always runtime error',
612
634
  [HardwareErrorCode.BleDeviceNotBonded]: 'device is not bonded',
@@ -677,6 +699,7 @@ export const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping = {
677
699
  'Web-USB or Web-Bluetooth device not found or needs permission',
678
700
  [HardwareErrorCode.WebDevicePromptAccessError]:
679
701
  'Web-USB or Web-Bluetooth device prompt access error',
702
+ [HardwareErrorCode.WebUsbDeviceAccessError]: 'WebUSB device access failed',
680
703
  } as const;
681
704
 
682
705
  export const TypedError = (
@@ -690,26 +713,6 @@ export const TypedError = (
690
713
  return new HardwareError({ errorCode: hardwareError, message: message ?? '', params });
691
714
  };
692
715
 
693
- export const isBleStaleBondHardwareError = (error: unknown): boolean => {
694
- const code = (error as { errorCode?: unknown })?.errorCode;
695
- return (
696
- code === HardwareErrorCode.BleDeviceBondError ||
697
- code === HardwareErrorCode.BlePeerRemovedPairingInformation ||
698
- code === HardwareErrorCode.BleBondInvalid
699
- );
700
- };
701
-
702
- export const isBleStaleBondErrorText = (text: string): boolean => {
703
- const value = text.toLowerCase();
704
- return (
705
- value.includes('encryption is insufficient') ||
706
- value.includes('insufficient encryption') ||
707
- value.includes('peer removed pairing information') ||
708
- value.includes('cberrordomain:14') ||
709
- value.includes('gatt_insuf_authentication')
710
- );
711
- };
712
-
713
716
  export const serializeError = (payload: any) => {
714
717
  if (payload && payload.error instanceof HardwareError) {
715
718
  return {
@@ -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
@@ -43,6 +43,9 @@ export const isKnownTrezorWebUsbDevice = (descriptor: WebUsbIdentityDescriptor):
43
43
  * These errors indicate the device is in an invalid state and needs to be released
44
44
  */
45
45
  export const ERROR_CODES_REQUIRE_RELEASE = [
46
+ HardwareErrorCode.WebUsbDeviceAccessError,
47
+ HardwareErrorCode.TransportProtocolProbeFailed,
48
+ HardwareErrorCode.TransportProtocolMismatch,
46
49
  HardwareErrorCode.DeviceInitializeFailed,
47
50
  HardwareErrorCode.DeviceInterruptedFromOutside,
48
51
  HardwareErrorCode.DeviceInterruptedFromUser,
@@ -58,6 +61,9 @@ export const ERROR_CODES_REQUIRE_RELEASE = [
58
61
  * These errors indicate a communication failure that requires full reconnection
59
62
  */
60
63
  export const ERROR_CODES_REQUIRE_DISCONNECT = [
64
+ HardwareErrorCode.WebUsbDeviceAccessError,
65
+ HardwareErrorCode.TransportProtocolProbeFailed,
66
+ HardwareErrorCode.TransportProtocolMismatch,
61
67
  HardwareErrorCode.DeviceInitializeFailed,
62
68
  HardwareErrorCode.ResponseUnexpectTypeError,
63
69
  ] as const;
@@ -368,6 +374,24 @@ export const isPro2FamilyBleName = (value?: string | null): boolean => {
368
374
  );
369
375
  };
370
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
+
371
395
  export const isOnekeyBluetoothDevice = ({
372
396
  id,
373
397
  name,