@onekeyfe/hd-shared 1.2.8-alpha.113 → 1.2.8-alpha.114

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.
@@ -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,CAAC;AAMF,eAAO,MAAM,2BAA2B,kEAY9B,CAAC;AAMX,eAAO,MAAM,8BAA8B,oCAMjC,CAAC;AAGX,oBAAY,qBAAqB;IAE/B,UAAU,uBAAuB;IACjC,iBAAiB,8BAA8B;IAC/C,aAAa,0BAA0B;IACvC,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AC,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
@@ -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> = {
@@ -594,4 +599,4 @@ declare enum EDeviceType {
594
599
  Neo = "neo"
595
600
  }
596
601
 
597
- 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 };
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
@@ -652,6 +652,13 @@ const isPro2FamilyBleName = (value) => {
652
652
  NEO_COMPACT_NAME_PATTERN.test(compact) ||
653
653
  isPro2FindMyAdvertisementName(value));
654
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
+ };
655
662
  const isOnekeyBluetoothDevice = ({ id, name, localName, serviceUuids, }) => {
656
663
  const advertisedServiceUuids = serviceUuids !== null && serviceUuids !== void 0 ? serviceUuids : [];
657
664
  if (hasOnekeyCommunicationService(advertisedServiceUuids)) {
@@ -776,6 +783,7 @@ exports.isSameOnekeyBleName = isSameOnekeyBleName;
776
783
  exports.matchesKnownBleUuid = matchesKnownBleUuid;
777
784
  exports.normalizeBleUuid = normalizeBleUuid;
778
785
  exports.normalizePro2FindMyAdvertisementName = normalizePro2FindMyAdvertisementName;
786
+ exports.parseOnekeyBleColorCode = parseOnekeyBleColorCode;
779
787
  exports.resolveOneKeyUsbDevicePath = resolveOneKeyUsbDevicePath;
780
788
  exports.serializeError = serializeError;
781
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-alpha.113",
3
+ "version": "1.2.8-alpha.114",
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": "c56caf8fdd87e3a00bdc90aca044e75693704ae3"
29
+ "gitHead": "272fd40094bac0425bd824b82b5b74c54d220bd7"
30
30
  }
@@ -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
@@ -374,6 +374,24 @@ export const isPro2FamilyBleName = (value?: string | null): boolean => {
374
374
  );
375
375
  };
376
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
+
377
395
  export const isOnekeyBluetoothDevice = ({
378
396
  id,
379
397
  name,