@onekeyfe/hd-shared 1.2.0-alpha.7 → 1.2.0-alpha.71

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.
@@ -115,6 +115,9 @@ export declare const HardwareErrorCode: {
115
115
  readonly DeviceSettingsLanguageNotSupport: 826;
116
116
  readonly TooManyInputs: 827;
117
117
  readonly PinMismatch: 828;
118
+ readonly DeviceLocked: 830;
119
+ readonly WalletSessionInvalid: 831;
120
+ readonly NftStorageLimitReached: 832;
118
121
  readonly LowlevelTrasnportConnectError: 900;
119
122
  readonly WebDeviceNotFoundOrNeedsPermission: 901;
120
123
  readonly WebDevicePromptAccessError: 902;
@@ -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,CAAC;AAE5C,KAAK,+BAA+B,GAAG;KAAG,CAAC,IAAI,OAAO,CAAC,OAAO,iBAAiB,CAAC,GAAG,MAAM;CAAE,CAAC;AAE5F,KAAK,cAAc,GAAG,OAAO,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAsCxD,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAS,EAAE,cAAc,CAAkC;IAE3D,OAAO,SAAM;IAEb,MAAM,EAAE,GAAG,CAAM;gBAEL,aAAa,EAAE,cAAc,GAAG,MAAM;CAmBnD;AAED,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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b,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"}
@@ -8,6 +8,12 @@ export declare const ONEKEY_WEBUSB_FILTER: {
8
8
  vendorId: number;
9
9
  productId: number;
10
10
  }[];
11
+ type WebUsbIdentityDescriptor = {
12
+ vendorId?: number;
13
+ productId?: number;
14
+ manufacturerName?: string | null;
15
+ };
16
+ export declare const isKnownTrezorWebUsbDevice: (descriptor: WebUsbIdentityDescriptor) => boolean;
11
17
  export declare const ERROR_CODES_REQUIRE_RELEASE: readonly [106, 107, 109, 112, 805, 801, 802, 812];
12
18
  export declare const ERROR_CODES_REQUIRE_DISCONNECT: readonly [106, 805];
13
19
  export declare enum EOneKeyBleMessageKeys {
@@ -32,6 +38,7 @@ export declare enum EOneKeyBleMessageKeys {
32
38
  NOBLE_BLE_SUBSCRIBE = "$onekey-noble-ble-subscribe",
33
39
  NOBLE_BLE_UNSUBSCRIBE = "$onekey-noble-ble-unsubscribe",
34
40
  NOBLE_BLE_NOTIFICATION = "$onekey-noble-ble-notification",
41
+ NOBLE_BLE_MTU_CHANGED = "$onekey-noble-ble-mtu-changed",
35
42
  NOBLE_BLE_CANCEL_PAIRING = "$onekey-noble-ble-cancel-pairing"
36
43
  }
37
44
  export declare const ONEKEY_SERVICE_UUID = "00000001-0000-1000-8000-00805f9b34fb";
@@ -39,4 +46,17 @@ export declare const ONEKEY_WRITE_CHARACTERISTIC_UUID = "00000002-0000-1000-8000
39
46
  export declare const ONEKEY_NOTIFY_CHARACTERISTIC_UUID = "00000003-0000-1000-8000-00805f9b34fb";
40
47
  export declare const isHeaderChunk: (chunk: Buffer | Uint8Array) => boolean;
41
48
  export declare const isOnekeyDevice: (name: string | null, id?: string) => boolean;
49
+ type BluetoothDeviceIdentity = {
50
+ id?: string;
51
+ name?: string | null;
52
+ localName?: string | null;
53
+ serviceUuids?: Array<string | null | undefined> | null;
54
+ };
55
+ export declare const normalizeBleUuid: (uuid?: string | null) => string;
56
+ export declare const createKnownBleUuidAliases: (uuid: string) => ReadonlySet<string>;
57
+ export declare const matchesKnownBleUuid: (actualUuid: string | null | undefined, aliases: ReadonlySet<string>) => boolean;
58
+ export declare const isPro2FindMyAdvertisementName: (value?: string | null) => boolean;
59
+ export declare const hasOnekeyCommunicationService: (serviceUuids: Array<string | null | undefined> | null | undefined) => boolean;
60
+ export declare const isOnekeyBluetoothDevice: ({ id, name, localName, serviceUuids, }: BluetoothDeviceIdentity) => boolean;
61
+ export {};
42
62
  //# 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;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,2B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eAAO,MAAM,mBAAmB,eAClB,MAAM,GAAG,IAAI,GAAG,SAAS,WAC5B,YAAY,MAAM,CAAC,YACgB,CAAC;AAK/C,eAAO,MAAM,6BAA6B,WAAY,MAAM,GAAG,IAAI,YAGlE,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"}
@@ -6,6 +6,7 @@ export declare enum EDeviceType {
6
6
  Mini = "mini",
7
7
  Touch = "touch",
8
8
  Pro = "pro",
9
- Pro2 = "pro2"
9
+ Pro2 = "pro2",
10
+ Neo = "neo"
10
11
  }
11
12
  //# sourceMappingURL=deviceType.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deviceType.d.ts","sourceRoot":"","sources":["../src/deviceType.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACrB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,WAAW,gBAAgB;IAC3B,IAAI,SAAS;IACb,KAAK,UAAU;IACf,GAAG,QAAQ;IACX,IAAI,SAAS;CACd"}
1
+ {"version":3,"file":"deviceType.d.ts","sourceRoot":"","sources":["../src/deviceType.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACrB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,WAAW,gBAAgB;IAC3B,IAAI,SAAS;IACb,KAAK,UAAU;IACf,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,GAAG,QAAQ;CACZ"}
package/dist/index.d.ts CHANGED
@@ -7,7 +7,21 @@ declare const ONEKEY_WEBUSB_FILTER: {
7
7
  vendorId: number;
8
8
  productId: number;
9
9
  }[];
10
+ type WebUsbIdentityDescriptor = {
11
+ vendorId?: number;
12
+ productId?: number;
13
+ manufacturerName?: string | null;
14
+ };
15
+ declare const isKnownTrezorWebUsbDevice: (descriptor: WebUsbIdentityDescriptor) => boolean;
16
+ /**
17
+ * Error codes that require device release after occurrence
18
+ * These errors indicate the device is in an invalid state and needs to be released
19
+ */
10
20
  declare const ERROR_CODES_REQUIRE_RELEASE: readonly [106, 107, 109, 112, 805, 801, 802, 812];
21
+ /**
22
+ * Error codes that require device disconnect before release
23
+ * These errors indicate a communication failure that requires full reconnection
24
+ */
11
25
  declare const ERROR_CODES_REQUIRE_DISCONNECT: readonly [106, 805];
12
26
  declare enum EOneKeyBleMessageKeys {
13
27
  BLE_SELECT = "$onekey-ble-select",
@@ -31,6 +45,7 @@ declare enum EOneKeyBleMessageKeys {
31
45
  NOBLE_BLE_SUBSCRIBE = "$onekey-noble-ble-subscribe",
32
46
  NOBLE_BLE_UNSUBSCRIBE = "$onekey-noble-ble-unsubscribe",
33
47
  NOBLE_BLE_NOTIFICATION = "$onekey-noble-ble-notification",
48
+ NOBLE_BLE_MTU_CHANGED = "$onekey-noble-ble-mtu-changed",
34
49
  NOBLE_BLE_CANCEL_PAIRING = "$onekey-noble-ble-cancel-pairing"
35
50
  }
36
51
  declare const ONEKEY_SERVICE_UUID = "00000001-0000-1000-8000-00805f9b34fb";
@@ -38,6 +53,18 @@ declare const ONEKEY_WRITE_CHARACTERISTIC_UUID = "00000002-0000-1000-8000-00805f
38
53
  declare const ONEKEY_NOTIFY_CHARACTERISTIC_UUID = "00000003-0000-1000-8000-00805f9b34fb";
39
54
  declare const isHeaderChunk: (chunk: Buffer | Uint8Array) => boolean;
40
55
  declare const isOnekeyDevice: (name: string | null, id?: string) => boolean;
56
+ type BluetoothDeviceIdentity = {
57
+ id?: string;
58
+ name?: string | null;
59
+ localName?: string | null;
60
+ serviceUuids?: Array<string | null | undefined> | null;
61
+ };
62
+ declare const normalizeBleUuid: (uuid?: string | null) => string;
63
+ declare const createKnownBleUuidAliases: (uuid: string) => ReadonlySet<string>;
64
+ declare const matchesKnownBleUuid: (actualUuid: string | null | undefined, aliases: ReadonlySet<string>) => boolean;
65
+ declare const isPro2FindMyAdvertisementName: (value?: string | null) => boolean;
66
+ declare const hasOnekeyCommunicationService: (serviceUuids: Array<string | null | undefined> | null | undefined) => boolean;
67
+ declare const isOnekeyBluetoothDevice: ({ id, name, localName, serviceUuids, }: BluetoothDeviceIdentity) => boolean;
41
68
 
42
69
  type Deferred<T, I = any, D = any> = {
43
70
  id?: I;
@@ -70,53 +97,201 @@ declare class HardwareError extends Error {
70
97
  constructor(hardwareError: IHardwareError | string);
71
98
  }
72
99
  declare const HardwareErrorCode: {
100
+ /**
101
+ * This error can be thrown when unexpected error occurred and in most cases it is related to implementation bug.
102
+ * Original message is available in message property.
103
+ */
73
104
  readonly UnknownError: 0;
105
+ /**
106
+ * Firmware version mismatch
107
+ */
74
108
  readonly DeviceFwException: 101;
109
+ /**
110
+ * Device unexpected mode
111
+ */
75
112
  readonly DeviceUnexpectedMode: 102;
113
+ /**
114
+ * Device list is not initialized
115
+ */
76
116
  readonly DeviceListNotInitialized: 103;
117
+ /**
118
+ * Please select the connected device
119
+ */
77
120
  readonly SelectDevice: 104;
121
+ /**
122
+ * Device not found
123
+ */
78
124
  readonly DeviceNotFound: 105;
125
+ /**
126
+ * Device is not initialized
127
+ */
79
128
  readonly DeviceInitializeFailed: 106;
129
+ /**
130
+ * Device interrupted from another operation
131
+ */
80
132
  readonly DeviceInterruptedFromOutside: 107;
133
+ /**
134
+ * Device should be in bootloader mode
135
+ */
81
136
  readonly RequiredButInBootloaderMode: 108;
137
+ /**
138
+ * Device interrupted from user
139
+ */
82
140
  readonly DeviceInterruptedFromUser: 109;
141
+ /**
142
+ * Check device id is same
143
+ */
83
144
  readonly DeviceCheckDeviceIdError: 110;
145
+ /**
146
+ * Do not support passphrase
147
+ * @params: { require: string }
148
+ */
84
149
  readonly DeviceNotSupportPassphrase: 111;
85
150
  readonly DeviceCheckPassphraseStateError: 112;
151
+ /**
152
+ * use passphrase, but passphrase is not opened
153
+ */
86
154
  readonly DeviceNotOpenedPassphrase: 113;
155
+ /**
156
+ * not use passphrase, but passphrase is opened
157
+ */
87
158
  readonly DeviceOpenedPassphrase: 114;
159
+ /**
160
+ * Detect hardware that is in bootloader mode and return an error.
161
+ */
88
162
  readonly DeviceDetectInBootloaderMode: 115;
163
+ /**
164
+ * Device not allow in bootloader mode
165
+ */
89
166
  readonly NotAllowInBootloaderMode: 116;
167
+ /**
168
+ * Device is busy
169
+ */
90
170
  readonly DeviceBusy: 117;
171
+ /**
172
+ * Device check unlock type not match error
173
+ */
91
174
  readonly DeviceCheckUnlockTypeError: 118;
175
+ /**
176
+ * Not initialized
177
+ */
92
178
  readonly NotInitialized: 200;
179
+ /**
180
+ * Iframe not initialized
181
+ */
93
182
  readonly IFrameNotInitialized: 300;
183
+ /**
184
+ * iframe repeat initialization
185
+ */
94
186
  readonly IFrameAleradyInitialized: 301;
187
+ /**
188
+ * iframe load failure
189
+ */
95
190
  readonly IFrameLoadFail: 302;
191
+ /**
192
+ * init iframe time out
193
+ */
96
194
  readonly IframeTimeout: 303;
195
+ /**
196
+ * iframe blocked
197
+ */
97
198
  readonly IframeBlocked: 304;
199
+ /**
200
+ * iframe host not trust
201
+ */
98
202
  readonly IframeDistrust: 305;
203
+ /**
204
+ * Runtime errors during method execution
205
+ */
99
206
  readonly CallMethodError: 400;
207
+ /**
208
+ * Method does not responding
209
+ */
100
210
  readonly CallMethodNotResponse: 404;
211
+ /**
212
+ * Call method invalid parameter
213
+ */
101
214
  readonly CallMethodInvalidParameter: 405;
215
+ /**
216
+ * firmware update download failed
217
+ */
102
218
  readonly FirmwareUpdateDownloadFailed: 406;
219
+ /**
220
+ * Call method not supported, need update firmware
221
+ * @params: { current: string, require: string }
222
+ */
103
223
  readonly CallMethodNeedUpgradeFirmware: 407;
224
+ /**
225
+ * Call method not supported, is deprecated
226
+ * @params: { current: string, deprecated: string }
227
+ */
104
228
  readonly CallMethodDeprecated: 408;
229
+ /**
230
+ * Only one device can be connected during firmware upgrade
231
+ */
105
232
  readonly FirmwareUpdateLimitOneDevice: 409;
233
+ /**
234
+ * You need to manually enter boot
235
+ */
106
236
  readonly FirmwareUpdateManuallyEnterBoot: 410;
237
+ /**
238
+ * Manual entry fails. You must manually enter the boot
239
+ */
107
240
  readonly FirmwareUpdateAutoEnterBootFailure: 411;
241
+ /**
242
+ * The new firmware has not been released yet
243
+ */
108
244
  readonly NewFirmwareUnRelease: 412;
245
+ /**
246
+ * use OneKey desktop client to update the firmware
247
+ * because need copy resource file to Touch
248
+ */
109
249
  readonly UseDesktopToUpdateFirmware: 413;
250
+ /**
251
+ * Mandatory firmware update
252
+ * @params:{ connectId: string? , deviceId: string? }
253
+ */
110
254
  readonly NewFirmwareForceUpdate: 414;
255
+ /**
256
+ * Device not support this method
257
+ */
111
258
  readonly DeviceNotSupportMethod: 415;
259
+ /**
260
+ * Forbidden key path
261
+ */
112
262
  readonly ForbiddenKeyPath: 416;
263
+ /**
264
+ * Repeat unlocking
265
+ * all network get address by loop need repeat unlocking
266
+ */
113
267
  readonly RepeatUnlocking: 417;
268
+ /**
269
+ * Defective firmware detected
270
+ */
114
271
  readonly DefectiveFirmware: 418;
272
+ /**
273
+ * Netword request error
274
+ */
115
275
  readonly NetworkError: 500;
276
+ /**
277
+ * Transport not configured
278
+ */
116
279
  readonly TransportNotConfigured: 600;
280
+ /**
281
+ * Transport call in progress
282
+ */
117
283
  readonly TransportCallInProgress: 601;
284
+ /**
285
+ * Transport not found
286
+ */
118
287
  readonly TransportNotFound: 602;
288
+ /**
289
+ * Transport invalid protobuf
290
+ */
119
291
  readonly TransportInvalidProtobuf: 603;
292
+ /**
293
+ * Bluetooth error code
294
+ */
120
295
  readonly BleScanError: 700;
121
296
  readonly BlePermissionError: 701;
122
297
  readonly BleLocationError: 702;
@@ -140,37 +315,144 @@ declare const HardwareErrorCode: {
140
315
  readonly BleDeviceDisconnected: 720;
141
316
  readonly BlePoweredOff: 721;
142
317
  readonly BleUnsupported: 722;
318
+ /**
319
+ * Hardware runtiome errors
320
+ */
143
321
  readonly RuntimeError: 800;
322
+ /**
323
+ * invalid pin
324
+ */
144
325
  readonly PinInvalid: 801;
326
+ /**
327
+ * pin cancelled by user
328
+ */
145
329
  readonly PinCancelled: 802;
330
+ /**
331
+ * Action cancelled by user
332
+ */
146
333
  readonly ActionCancelled: 803;
334
+ /**
335
+ * Firmware installation failed
336
+ */
147
337
  readonly FirmwareError: 804;
338
+ /**
339
+ * transport response unexpect error
340
+ */
148
341
  readonly ResponseUnexpectTypeError: 805;
342
+ /**
343
+ * bridge network error
344
+ */
149
345
  readonly BridgeNetworkError: 806;
346
+ /**
347
+ * Bridge network timeout
348
+ */
150
349
  readonly BridgeTimeoutError: 807;
350
+ /**
351
+ * Bridge not installed
352
+ */
151
353
  readonly BridgeNotInstalled: 808;
354
+ /**
355
+ * ensure connect timeout
356
+ */
152
357
  readonly PollingTimeout: 809;
358
+ /**
359
+ * ensure connect stop polling
360
+ */
153
361
  readonly PollingStop: 810;
362
+ /**
363
+ * Device does not open blid sign
364
+ */
154
365
  readonly BlindSignDisabled: 811;
155
366
  readonly UnexpectPassphrase: 812;
367
+ /**
368
+ * NFT file already exists
369
+ */
156
370
  readonly FileAlreadyExists: 813;
371
+ /**
372
+ * check file length error
373
+ */
157
374
  readonly CheckDownloadFileError: 814;
375
+ /**
376
+ * not in signing mode
377
+ */
158
378
  readonly NotInSigningMode: 815;
379
+ /**
380
+ * not in signing mode
381
+ */
159
382
  readonly DataOverload: 816;
383
+ /**
384
+ * device disconnected during action
385
+ */
160
386
  readonly BridgeDeviceDisconnected: 817;
387
+ /**
388
+ * BTC PSBT too many utxos
389
+ * @params:{ count: number }
390
+ */
161
391
  readonly BTCPsbtTooManyUtxos: 818;
392
+ /**
393
+ * EMMC file write firmware error
394
+ */
162
395
  readonly EmmcFileWriteFirmwareError: 819;
396
+ /**
397
+ * Firmware verification failed (e.g., bootloader file verify failed)
398
+ */
163
399
  readonly FirmwareVerificationFailed: 820;
400
+ /**
401
+ * Web bridge coonect needs permission
402
+ */
164
403
  readonly BridgeNeedsPermission: 821;
165
404
  readonly CallQueueActionCancelled: 822;
405
+ /**
406
+ * Firmware downgrade not allowed
407
+ */
166
408
  readonly FirmwareDowngradeNotAllowed: 823;
409
+ /**
410
+ * Cosmos invalid JSON message, Only support Amino msgs.
411
+ */
167
412
  readonly CosmosInvalidJsonMessage: 824;
413
+ /**
414
+ * No setting provided
415
+ */
168
416
  readonly DeviceSettingsNotProvided: 825;
417
+ /**
418
+ * Language not supported
419
+ */
169
420
  readonly DeviceSettingsLanguageNotSupport: 826;
421
+ /**
422
+ * Too many inputs
423
+ * @params: { count?: string }
424
+ */
170
425
  readonly TooManyInputs: 827;
426
+ /**
427
+ * The two PIN entries did not match while setting/changing PIN on device
428
+ */
171
429
  readonly PinMismatch: 828;
430
+ /**
431
+ * Protocol V2 device must be unlocked before the requested operation.
432
+ * @params: { failureCode?: string; subcode?: number; firmwareMessage?: string }
433
+ */
434
+ readonly DeviceLocked: 830;
435
+ /**
436
+ * The cached wallet session is invalid or has expired.
437
+ * @params: { failureCode?: string; subcode?: number; firmwareMessage?: string }
438
+ */
439
+ readonly WalletSessionInvalid: 831;
440
+ /**
441
+ * Pro2 NFT storage has reached its item limit.
442
+ * @params: { count: number; limit: number }
443
+ */
444
+ readonly NftStorageLimitReached: 832;
445
+ /**
446
+ * Lowlevel transport connect error
447
+ */
172
448
  readonly LowlevelTrasnportConnectError: 900;
449
+ /**
450
+ * Web USB or Web Bluetooth device not found or needs permission
451
+ */
173
452
  readonly WebDeviceNotFoundOrNeedsPermission: 901;
453
+ /**
454
+ * Web USB or Web Bluetooth device prompt access error
455
+ */
174
456
  readonly WebDevicePromptAccessError: 902;
175
457
  };
176
458
  declare const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping;
@@ -242,7 +524,8 @@ declare enum EDeviceType {
242
524
  Mini = "mini",
243
525
  Touch = "touch",
244
526
  Pro = "pro",
245
- Pro2 = "pro2"
527
+ Pro2 = "pro2",
528
+ Neo = "neo"
246
529
  }
247
530
 
248
- 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, createNeedUpgradeFirmwareHardwareError, createNewFirmwareForceUpdateHardwareError, createNewFirmwareUnReleaseHardwareError, isHeaderChunk, isOnekeyDevice, serializeError, wait };
531
+ 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, serializeError, wait };
package/dist/index.js CHANGED
@@ -164,6 +164,9 @@ const HardwareErrorCode = {
164
164
  DeviceSettingsLanguageNotSupport: 826,
165
165
  TooManyInputs: 827,
166
166
  PinMismatch: 828,
167
+ DeviceLocked: 830,
168
+ WalletSessionInvalid: 831,
169
+ NftStorageLimitReached: 832,
167
170
  LowlevelTrasnportConnectError: 900,
168
171
  WebDeviceNotFoundOrNeedsPermission: 901,
169
172
  WebDevicePromptAccessError: 902,
@@ -268,6 +271,9 @@ const HardwareErrorCodeMessage = {
268
271
  [HardwareErrorCode.DeviceSettingsLanguageNotSupport]: 'Language not supported',
269
272
  [HardwareErrorCode.TooManyInputs]: 'Too many inputs',
270
273
  [HardwareErrorCode.PinMismatch]: 'PIN mismatch',
274
+ [HardwareErrorCode.DeviceLocked]: 'Device locked',
275
+ [HardwareErrorCode.WalletSessionInvalid]: 'Wallet session is invalid or expired',
276
+ [HardwareErrorCode.NftStorageLimitReached]: 'NFT storage limit reached. Remove an NFT from the device and try again.',
271
277
  [HardwareErrorCode.LowlevelTrasnportConnectError]: 'Lowlevel transport connect error',
272
278
  [HardwareErrorCode.WebDeviceNotFoundOrNeedsPermission]: 'Web-USB or Web-Bluetooth device not found or needs permission',
273
279
  [HardwareErrorCode.WebDevicePromptAccessError]: 'Web-USB or Web-Bluetooth device prompt access error',
@@ -391,6 +397,15 @@ const ONEKEY_WEBUSB_FILTER = [
391
397
  { vendorId: 0x1209, productId: 0x4f4b },
392
398
  { vendorId: 0x1209, productId: 0x4f4c },
393
399
  ];
400
+ const TREZOR_WEBUSB_MANUFACTURER_NAMES = new Set(['trezor', 'trezor company', 'satoshilabs']);
401
+ const isKnownTrezorWebUsbDevice = (descriptor) => {
402
+ var _a;
403
+ const isSharedWebUsbId = ONEKEY_WEBUSB_FILTER.some(filter => descriptor.vendorId === filter.vendorId && descriptor.productId === filter.productId);
404
+ if (!isSharedWebUsbId)
405
+ return false;
406
+ const manufacturerName = (_a = descriptor.manufacturerName) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase();
407
+ return manufacturerName != null && TREZOR_WEBUSB_MANUFACTURER_NAMES.has(manufacturerName);
408
+ };
394
409
  const ERROR_CODES_REQUIRE_RELEASE = [
395
410
  HardwareErrorCode.DeviceInitializeFailed,
396
411
  HardwareErrorCode.DeviceInterruptedFromOutside,
@@ -428,6 +443,7 @@ exports.EOneKeyBleMessageKeys = void 0;
428
443
  EOneKeyBleMessageKeys["NOBLE_BLE_SUBSCRIBE"] = "$onekey-noble-ble-subscribe";
429
444
  EOneKeyBleMessageKeys["NOBLE_BLE_UNSUBSCRIBE"] = "$onekey-noble-ble-unsubscribe";
430
445
  EOneKeyBleMessageKeys["NOBLE_BLE_NOTIFICATION"] = "$onekey-noble-ble-notification";
446
+ EOneKeyBleMessageKeys["NOBLE_BLE_MTU_CHANGED"] = "$onekey-noble-ble-mtu-changed";
431
447
  EOneKeyBleMessageKeys["NOBLE_BLE_CANCEL_PAIRING"] = "$onekey-noble-ble-cancel-pairing";
432
448
  })(exports.EOneKeyBleMessageKeys || (exports.EOneKeyBleMessageKeys = {}));
433
449
  const ONEKEY_SERVICE_UUID = '00000001-0000-1000-8000-00805f9b34fb';
@@ -446,16 +462,78 @@ const isHeaderChunk = (chunk) => {
446
462
  }
447
463
  return false;
448
464
  };
465
+ const isKnownNonOneKeyDeviceName = (normalizedName) => normalizedName.startsWith('trezor') ||
466
+ normalizedName.startsWith('ledger') ||
467
+ normalizedName.startsWith('nano ') ||
468
+ normalizedName.startsWith('stax') ||
469
+ normalizedName.startsWith('flex');
470
+ const ONEKEY_EXACT_SHORT_NAMES = new Set(['s8']);
471
+ const isOneKeyShortName = (normalizedName) => {
472
+ if (ONEKEY_EXACT_SHORT_NAMES.has(normalizedName))
473
+ return true;
474
+ if (normalizedName.length !== 5)
475
+ return false;
476
+ const firstChar = normalizedName[0];
477
+ return (firstChar === 'k' || firstChar === 't') && /^\d{4}$/.test(normalizedName.slice(1));
478
+ };
449
479
  const isOnekeyDevice = (name, id) => {
450
- var _a;
451
- if ((_a = id === null || id === void 0 ? void 0 : id.startsWith) === null || _a === void 0 ? void 0 : _a.call(id, 'MI')) {
480
+ var _a, _b;
481
+ const normalizedName = (_a = name === null || name === void 0 ? void 0 : name.trim().toLowerCase()) !== null && _a !== void 0 ? _a : '';
482
+ if (isKnownNonOneKeyDeviceName(normalizedName)) {
483
+ return false;
484
+ }
485
+ if ((_b = id === null || id === void 0 ? void 0 : id.startsWith) === null || _b === void 0 ? void 0 : _b.call(id, 'MI')) {
452
486
  return true;
453
487
  }
454
- const re = /(BixinKey\d{10})|(K\d{4})|(T\d{4})|(Touch\s\w{4})|(Pro\s\w{4})|(Pro\s*2)/i;
455
- if (name && re.exec(name)) {
488
+ if (!name) {
489
+ return false;
490
+ }
491
+ if (normalizedName.startsWith('onekey') || normalizedName.startsWith('bixinkey'))
492
+ return true;
493
+ if (normalizedName.startsWith('touch ') ||
494
+ normalizedName.startsWith('pro ') ||
495
+ normalizedName.startsWith('pro2 ') ||
496
+ normalizedName.startsWith('neo ')) {
456
497
  return true;
457
498
  }
458
- return false;
499
+ return isOneKeyShortName(normalizedName);
500
+ };
501
+ const BLUETOOTH_BASE_UUID_SUFFIX = '00001000800000805f9b34fb';
502
+ const normalizeBleUuid = (uuid) => (uuid !== null && uuid !== void 0 ? uuid : '').replace(/-/g, '').toLowerCase();
503
+ const createKnownBleUuidAliases = (uuid) => {
504
+ const normalized = normalizeBleUuid(uuid);
505
+ const aliases = new Set([normalized]);
506
+ if (normalized.length !== 32 || !normalized.endsWith(BLUETOOTH_BASE_UUID_SUFFIX)) {
507
+ return aliases;
508
+ }
509
+ const assignedNumber = normalized.slice(0, 8);
510
+ aliases.add(assignedNumber);
511
+ if (assignedNumber.startsWith('0000')) {
512
+ aliases.add(assignedNumber.slice(4));
513
+ }
514
+ return aliases;
515
+ };
516
+ const matchesKnownBleUuid = (actualUuid, aliases) => aliases.has(normalizeBleUuid(actualUuid));
517
+ const ONEKEY_COMMUNICATION_SERVICE_ALIASES = createKnownBleUuidAliases(ONEKEY_SERVICE_UUID);
518
+ const FIDO_SERVICE_ALIASES = createKnownBleUuidAliases('0000fffd-0000-1000-8000-00805f9b34fb');
519
+ const isPro2FindMyAdvertisementName = (value) => {
520
+ var _a;
521
+ const normalizedName = (_a = value === null || value === void 0 ? void 0 : value.trim().toLowerCase()) !== null && _a !== void 0 ? _a : '';
522
+ return /\bpro\s*2\b/.test(normalizedName) && /\bfinde?\s+my\b/.test(normalizedName);
523
+ };
524
+ const hasOnekeyCommunicationService = (serviceUuids) => (serviceUuids !== null && serviceUuids !== void 0 ? serviceUuids : []).some(uuid => matchesKnownBleUuid(uuid, ONEKEY_COMMUNICATION_SERVICE_ALIASES));
525
+ const isOnekeyBluetoothDevice = ({ id, name, localName, serviceUuids, }) => {
526
+ const advertisedServiceUuids = serviceUuids !== null && serviceUuids !== void 0 ? serviceUuids : [];
527
+ if (hasOnekeyCommunicationService(advertisedServiceUuids)) {
528
+ return true;
529
+ }
530
+ if (isPro2FindMyAdvertisementName(name) || isPro2FindMyAdvertisementName(localName)) {
531
+ return false;
532
+ }
533
+ if (advertisedServiceUuids.some(uuid => matchesKnownBleUuid(uuid, FIDO_SERVICE_ALIASES))) {
534
+ return false;
535
+ }
536
+ return isOnekeyDevice(name !== null && name !== void 0 ? name : null, id) || isOnekeyDevice(localName !== null && localName !== void 0 ? localName : null, id);
459
537
  };
460
538
 
461
539
  /******************************************************************************
@@ -529,6 +607,7 @@ exports.EDeviceType = void 0;
529
607
  EDeviceType["Touch"] = "touch";
530
608
  EDeviceType["Pro"] = "pro";
531
609
  EDeviceType["Pro2"] = "pro2";
610
+ EDeviceType["Neo"] = "neo";
532
611
  })(exports.EDeviceType || (exports.EDeviceType = {}));
533
612
 
534
613
  exports.CreateErrorByMessage = CreateErrorByMessage;
@@ -549,10 +628,17 @@ exports.createDefectiveFirmwareError = createDefectiveFirmwareError;
549
628
  exports.createDeferred = createDeferred;
550
629
  exports.createDeprecatedHardwareError = createDeprecatedHardwareError;
551
630
  exports.createDeviceNotSupportMethodError = createDeviceNotSupportMethodError;
631
+ exports.createKnownBleUuidAliases = createKnownBleUuidAliases;
552
632
  exports.createNeedUpgradeFirmwareHardwareError = createNeedUpgradeFirmwareHardwareError;
553
633
  exports.createNewFirmwareForceUpdateHardwareError = createNewFirmwareForceUpdateHardwareError;
554
634
  exports.createNewFirmwareUnReleaseHardwareError = createNewFirmwareUnReleaseHardwareError;
635
+ exports.hasOnekeyCommunicationService = hasOnekeyCommunicationService;
555
636
  exports.isHeaderChunk = isHeaderChunk;
637
+ exports.isKnownTrezorWebUsbDevice = isKnownTrezorWebUsbDevice;
638
+ exports.isOnekeyBluetoothDevice = isOnekeyBluetoothDevice;
556
639
  exports.isOnekeyDevice = isOnekeyDevice;
640
+ exports.isPro2FindMyAdvertisementName = isPro2FindMyAdvertisementName;
641
+ exports.matchesKnownBleUuid = matchesKnownBleUuid;
642
+ exports.normalizeBleUuid = normalizeBleUuid;
557
643
  exports.serializeError = serializeError;
558
644
  exports.wait = wait;
package/jest.config.js ADDED
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ preset: '../../jest.config.js',
3
+ testEnvironment: 'node',
4
+ modulePathIgnorePatterns: ['node_modules', '<rootDir>/dist'],
5
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-shared",
3
- "version": "1.2.0-alpha.7",
3
+ "version": "1.2.0-alpha.71",
4
4
  "description": "Hardware SDK's shared tool library",
5
5
  "keywords": [
6
6
  "Hardware-SDK",
@@ -22,8 +22,9 @@
22
22
  "scripts": {
23
23
  "dev": "rimraf dist && rollup -c ../../build/rollup.config.js -w",
24
24
  "build": "rimraf dist && rollup -c ../../build/rollup.config.js",
25
+ "test": "jest",
25
26
  "lint": "eslint .",
26
27
  "lint:fix": "eslint . --fix"
27
28
  },
28
- "gitHead": "001372047f518aaeed5fcbe87b990b8b619a9a65"
29
+ "gitHead": "c58f39f2e5c54a98faa8844cd8b6b0453a17d80c"
29
30
  }
@@ -0,0 +1,9 @@
1
+ import { HardwareErrorCode } from './HardwareError';
2
+
3
+ describe('HardwareErrorCode compatibility', () => {
4
+ test('preserves published Protocol V2 values while leaving code 829 unused', () => {
5
+ expect(HardwareErrorCode).not.toHaveProperty('KaspaPrevTxIdMismatch');
6
+ expect(HardwareErrorCode.DeviceLocked).toBe(830);
7
+ expect(HardwareErrorCode.WalletSessionInvalid).toBe(831);
8
+ });
9
+ });
@@ -484,6 +484,24 @@ export const HardwareErrorCode = {
484
484
  */
485
485
  PinMismatch: 828,
486
486
 
487
+ /**
488
+ * Protocol V2 device must be unlocked before the requested operation.
489
+ * @params: { failureCode?: string; subcode?: number; firmwareMessage?: string }
490
+ */
491
+ DeviceLocked: 830,
492
+
493
+ /**
494
+ * The cached wallet session is invalid or has expired.
495
+ * @params: { failureCode?: string; subcode?: number; firmwareMessage?: string }
496
+ */
497
+ WalletSessionInvalid: 831,
498
+
499
+ /**
500
+ * Pro2 NFT storage has reached its item limit.
501
+ * @params: { count: number; limit: number }
502
+ */
503
+ NftStorageLimitReached: 832,
504
+
487
505
  /**
488
506
  * Lowlevel transport connect error
489
507
  */
@@ -635,6 +653,10 @@ export const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping = {
635
653
  [HardwareErrorCode.DeviceSettingsLanguageNotSupport]: 'Language not supported',
636
654
  [HardwareErrorCode.TooManyInputs]: 'Too many inputs',
637
655
  [HardwareErrorCode.PinMismatch]: 'PIN mismatch',
656
+ [HardwareErrorCode.DeviceLocked]: 'Device locked',
657
+ [HardwareErrorCode.WalletSessionInvalid]: 'Wallet session is invalid or expired',
658
+ [HardwareErrorCode.NftStorageLimitReached]:
659
+ 'NFT storage limit reached. Remove an NFT from the device and try again.',
638
660
 
639
661
  /**
640
662
  * Lowlevel transport
@@ -0,0 +1,153 @@
1
+ import {
2
+ createKnownBleUuidAliases,
3
+ hasOnekeyCommunicationService,
4
+ isKnownTrezorWebUsbDevice,
5
+ isOnekeyBluetoothDevice,
6
+ isOnekeyDevice,
7
+ matchesKnownBleUuid,
8
+ } from './constants';
9
+
10
+ describe('hardware device identity filters', () => {
11
+ it('accepts known OneKey BLE names', () => {
12
+ expect(isOnekeyDevice('Touch A1B2')).toBe(true);
13
+ expect(isOnekeyDevice('Pro A1B2')).toBe(true);
14
+ expect(isOnekeyDevice('Neo A1B2')).toBe(true);
15
+ expect(isOnekeyDevice('K1234')).toBe(true);
16
+ expect(isOnekeyDevice('S8')).toBe(true);
17
+ });
18
+
19
+ it('rejects known Trezor and Ledger BLE names from OneKey discovery', () => {
20
+ expect(isOnekeyDevice('Trezor Safe 7')).toBe(false);
21
+ expect(isOnekeyDevice('Ledger Nano X')).toBe(false);
22
+ });
23
+
24
+ it('does not identify an FFFD-only advertisement as OneKey', () => {
25
+ expect(isOnekeyBluetoothDevice({ name: 'Find My', serviceUuids: ['fffd'] })).toBe(false);
26
+ expect(
27
+ isOnekeyBluetoothDevice({ serviceUuids: ['0000fffd-0000-1000-8000-00805f9b34fb'] })
28
+ ).toBe(false);
29
+ });
30
+
31
+ it('identifies Pro2 communication advertisements independently of their display name', () => {
32
+ expect(
33
+ isOnekeyBluetoothDevice({
34
+ name: 'Pro2 A1B2',
35
+ serviceUuids: ['0001', 'fffd'],
36
+ })
37
+ ).toBe(true);
38
+ expect(
39
+ isOnekeyBluetoothDevice({
40
+ localName: 'Pro2 A1B2 - Find My',
41
+ serviceUuids: ['0001', 'fffd'],
42
+ })
43
+ ).toBe(true);
44
+ expect(
45
+ isOnekeyBluetoothDevice({
46
+ name: 'Pro2 5E9D - Finde My',
47
+ serviceUuids: ['0001', 'fffd'],
48
+ })
49
+ ).toBe(true);
50
+ });
51
+
52
+ it('rejects Pro2 Find My entries when the communication service is absent', () => {
53
+ expect(
54
+ isOnekeyBluetoothDevice({
55
+ name: 'Pro2 A1B2 - Find My',
56
+ })
57
+ ).toBe(false);
58
+ expect(
59
+ isOnekeyBluetoothDevice({
60
+ localName: 'OneKey Pro 2 A1B2 - Find My',
61
+ serviceUuids: [],
62
+ })
63
+ ).toBe(false);
64
+ expect(
65
+ isOnekeyBluetoothDevice({
66
+ name: 'Pro2 5E9D - Finde My',
67
+ serviceUuids: ['fffd'],
68
+ })
69
+ ).toBe(false);
70
+ });
71
+
72
+ it('keeps OneKey discovery on the communication service', () => {
73
+ expect(
74
+ isOnekeyBluetoothDevice({
75
+ name: 'OneKey Pro 2',
76
+ serviceUuids: ['00000001-0000-1000-8000-00805f9b34fb'],
77
+ })
78
+ ).toBe(true);
79
+ });
80
+
81
+ it('only aliases standard Bluetooth Base UUID representations', () => {
82
+ const aliases = createKnownBleUuidAliases('00000001-0000-1000-8000-00805f9b34fb');
83
+
84
+ expect(matchesKnownBleUuid('0001', aliases)).toBe(true);
85
+ expect(matchesKnownBleUuid('00000001', aliases)).toBe(true);
86
+ expect(matchesKnownBleUuid('abcd0001-1234-5678-9012-abcdefabcdef', aliases)).toBe(false);
87
+ });
88
+
89
+ it('does not treat vendor-specific UUID fragments as communication or FIDO services', () => {
90
+ expect(
91
+ isOnekeyBluetoothDevice({
92
+ name: 'OneKey Pro 2',
93
+ serviceUuids: ['abcdfffd-1234-5678-9012-abcdefabcdef'],
94
+ })
95
+ ).toBe(true);
96
+ expect(
97
+ isOnekeyBluetoothDevice({
98
+ serviceUuids: ['abcd0001-1234-5678-9012-abcdefabcdef'],
99
+ })
100
+ ).toBe(false);
101
+ });
102
+
103
+ it('requires an explicitly advertised communication service for strict discovery', () => {
104
+ expect(hasOnekeyCommunicationService([])).toBe(false);
105
+ expect(hasOnekeyCommunicationService(['0001'])).toBe(true);
106
+ expect(hasOnekeyCommunicationService(['abcd0001-1234-5678-9012-abcdefabcdef'])).toBe(false);
107
+ });
108
+
109
+ it('only filters WebUSB descriptors that are explicitly identified as Trezor', () => {
110
+ expect(
111
+ isKnownTrezorWebUsbDevice({
112
+ vendorId: 0x1209,
113
+ productId: 0x53c1,
114
+ manufacturerName: 'Trezor Company',
115
+ })
116
+ ).toBe(true);
117
+ expect(
118
+ isKnownTrezorWebUsbDevice({
119
+ vendorId: 0x1209,
120
+ productId: 0x53c1,
121
+ manufacturerName: 'Trezor',
122
+ })
123
+ ).toBe(true);
124
+ expect(
125
+ isKnownTrezorWebUsbDevice({
126
+ vendorId: 0x1209,
127
+ productId: 0x53c1,
128
+ manufacturerName: 'SatoshiLabs',
129
+ })
130
+ ).toBe(true);
131
+
132
+ expect(
133
+ isKnownTrezorWebUsbDevice({
134
+ vendorId: 0x1209,
135
+ productId: 0x53c1,
136
+ manufacturerName: 'OneKey',
137
+ })
138
+ ).toBe(false);
139
+ expect(
140
+ isKnownTrezorWebUsbDevice({
141
+ vendorId: 0x1209,
142
+ productId: 0x53c1,
143
+ })
144
+ ).toBe(false);
145
+ expect(
146
+ isKnownTrezorWebUsbDevice({
147
+ vendorId: 0x1209,
148
+ productId: 0x53c1,
149
+ productName: 'Trezor Safe 7',
150
+ })
151
+ ).toBe(false);
152
+ });
153
+ });
package/src/constants.ts CHANGED
@@ -10,13 +10,31 @@ export type HardwareConnectProtocol =
10
10
 
11
11
  export const ONEKEY_WEBUSB_FILTER = [
12
12
  { vendorId: 0x1209, productId: 0x53c0 }, // Classic Boot、Classic1s Boot、Mini Boot
13
- { vendorId: 0x1209, productId: 0x53c1 }, // Classic Firmware、Classic1s Firmware、Mini Firmware、Pro Firmware、Touch Firmware、Pro2(旧固件,勿删:存量设备仍以此 PID 枚举)
14
- { vendorId: 0x1209, productId: 0x4f4a }, // Pro Boot、Touch Boot、Pro2
15
- { vendorId: 0x1209, productId: 0x4f4b }, // Pro Firmware、Touch Firmware(Not implemented Trezor)、Pro2
16
- { vendorId: 0x1209, productId: 0x4f4c }, // Pro Board、Pro2(新固件 PID
13
+ { vendorId: 0x1209, productId: 0x53c1 }, // Classic/Classic1s/Mini/Pro/Touch firmware and legacy Pro2; keep for existing devices
14
+ { vendorId: 0x1209, productId: 0x4f4a }, // Pro bootloader, Touch bootloader, Pro2
15
+ { vendorId: 0x1209, productId: 0x4f4b }, // Pro/Touch firmware (Trezor not implemented), 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
+ type WebUsbIdentityDescriptor = {
21
+ vendorId?: number;
22
+ productId?: number;
23
+ manufacturerName?: string | null;
24
+ };
25
+
26
+ const TREZOR_WEBUSB_MANUFACTURER_NAMES = new Set(['trezor', 'trezor company', 'satoshilabs']);
27
+
28
+ export const isKnownTrezorWebUsbDevice = (descriptor: WebUsbIdentityDescriptor): boolean => {
29
+ const isSharedWebUsbId = ONEKEY_WEBUSB_FILTER.some(
30
+ filter => descriptor.vendorId === filter.vendorId && descriptor.productId === filter.productId
31
+ );
32
+ if (!isSharedWebUsbId) return false;
33
+
34
+ const manufacturerName = descriptor.manufacturerName?.trim().toLowerCase();
35
+ return manufacturerName != null && TREZOR_WEBUSB_MANUFACTURER_NAMES.has(manufacturerName);
36
+ };
37
+
20
38
  /**
21
39
  * Error codes that require device release after occurrence
22
40
  * These errors indicate the device is in an invalid state and needs to be released
@@ -73,6 +91,7 @@ export enum EOneKeyBleMessageKeys {
73
91
  NOBLE_BLE_SUBSCRIBE = '$onekey-noble-ble-subscribe',
74
92
  NOBLE_BLE_UNSUBSCRIBE = '$onekey-noble-ble-unsubscribe',
75
93
  NOBLE_BLE_NOTIFICATION = '$onekey-noble-ble-notification',
94
+ NOBLE_BLE_MTU_CHANGED = '$onekey-noble-ble-mtu-changed',
76
95
  NOBLE_BLE_CANCEL_PAIRING = '$onekey-noble-ble-cancel-pairing',
77
96
  }
78
97
 
@@ -97,16 +116,115 @@ export const isHeaderChunk = (chunk: Buffer | Uint8Array): boolean => {
97
116
  return false;
98
117
  };
99
118
 
119
+ const isKnownNonOneKeyDeviceName = (normalizedName: string): boolean =>
120
+ normalizedName.startsWith('trezor') ||
121
+ normalizedName.startsWith('ledger') ||
122
+ normalizedName.startsWith('nano ') ||
123
+ normalizedName.startsWith('stax') ||
124
+ normalizedName.startsWith('flex');
125
+
126
+ const ONEKEY_EXACT_SHORT_NAMES = new Set(['s8']);
127
+
128
+ const isOneKeyShortName = (normalizedName: string): boolean => {
129
+ if (ONEKEY_EXACT_SHORT_NAMES.has(normalizedName)) return true;
130
+ if (normalizedName.length !== 5) return false;
131
+ const firstChar = normalizedName[0];
132
+ return (firstChar === 'k' || firstChar === 't') && /^\d{4}$/.test(normalizedName.slice(1));
133
+ };
134
+
100
135
  export const isOnekeyDevice = (name: string | null, id?: string): boolean => {
136
+ const normalizedName = name?.trim().toLowerCase() ?? '';
137
+ if (isKnownNonOneKeyDeviceName(normalizedName)) {
138
+ return false;
139
+ }
140
+
101
141
  if (id?.startsWith?.('MI')) {
102
142
  return true;
103
143
  }
104
144
 
105
- // 过滤 BixinKeyxxx 和 Kxxxx 和 Txxxx 和 Pro2
106
- // i 忽略大小写模式
107
- const re = /(BixinKey\d{10})|(K\d{4})|(T\d{4})|(Touch\s\w{4})|(Pro\s\w{4})|(Pro\s*2)/i;
108
- if (name && re.exec(name)) {
145
+ if (!name) {
146
+ return false;
147
+ }
148
+ if (normalizedName.startsWith('onekey') || normalizedName.startsWith('bixinkey')) return true;
149
+ if (
150
+ normalizedName.startsWith('touch ') ||
151
+ normalizedName.startsWith('pro ') ||
152
+ normalizedName.startsWith('pro2 ') ||
153
+ normalizedName.startsWith('neo ')
154
+ ) {
109
155
  return true;
110
156
  }
111
- return false;
157
+ return isOneKeyShortName(normalizedName);
158
+ };
159
+
160
+ type BluetoothDeviceIdentity = {
161
+ id?: string;
162
+ name?: string | null;
163
+ localName?: string | null;
164
+ serviceUuids?: Array<string | null | undefined> | null;
165
+ };
166
+
167
+ const BLUETOOTH_BASE_UUID_SUFFIX = '00001000800000805f9b34fb';
168
+
169
+ export const normalizeBleUuid = (uuid?: string | null) =>
170
+ (uuid ?? '').replace(/-/g, '').toLowerCase();
171
+
172
+ export const createKnownBleUuidAliases = (uuid: string): ReadonlySet<string> => {
173
+ const normalized = normalizeBleUuid(uuid);
174
+ const aliases = new Set([normalized]);
175
+
176
+ if (normalized.length !== 32 || !normalized.endsWith(BLUETOOTH_BASE_UUID_SUFFIX)) {
177
+ return aliases;
178
+ }
179
+
180
+ const assignedNumber = normalized.slice(0, 8);
181
+ aliases.add(assignedNumber);
182
+ if (assignedNumber.startsWith('0000')) {
183
+ aliases.add(assignedNumber.slice(4));
184
+ }
185
+ return aliases;
186
+ };
187
+
188
+ export const matchesKnownBleUuid = (
189
+ actualUuid: string | null | undefined,
190
+ aliases: ReadonlySet<string>
191
+ ) => aliases.has(normalizeBleUuid(actualUuid));
192
+
193
+ const ONEKEY_COMMUNICATION_SERVICE_ALIASES = createKnownBleUuidAliases(ONEKEY_SERVICE_UUID);
194
+ const FIDO_SERVICE_ALIASES = createKnownBleUuidAliases('0000fffd-0000-1000-8000-00805f9b34fb');
195
+
196
+ export const isPro2FindMyAdvertisementName = (value?: string | null) => {
197
+ const normalizedName = value?.trim().toLowerCase() ?? '';
198
+ return /\bpro\s*2\b/.test(normalizedName) && /\bfinde?\s+my\b/.test(normalizedName);
199
+ };
200
+
201
+ export const hasOnekeyCommunicationService = (
202
+ serviceUuids: Array<string | null | undefined> | null | undefined
203
+ ) =>
204
+ (serviceUuids ?? []).some(uuid =>
205
+ matchesKnownBleUuid(uuid, ONEKEY_COMMUNICATION_SERVICE_ALIASES)
206
+ );
207
+
208
+ export const isOnekeyBluetoothDevice = ({
209
+ id,
210
+ name,
211
+ localName,
212
+ serviceUuids,
213
+ }: BluetoothDeviceIdentity): boolean => {
214
+ const advertisedServiceUuids = serviceUuids ?? [];
215
+ if (hasOnekeyCommunicationService(advertisedServiceUuids)) {
216
+ return true;
217
+ }
218
+
219
+ // Android can return a connected Find My peripheral without its advertised
220
+ // services. Do not let the Pro2-looking name fall through to name discovery.
221
+ if (isPro2FindMyAdvertisementName(name) || isPro2FindMyAdvertisementName(localName)) {
222
+ return false;
223
+ }
224
+
225
+ if (advertisedServiceUuids.some(uuid => matchesKnownBleUuid(uuid, FIDO_SERVICE_ALIASES))) {
226
+ return false;
227
+ }
228
+
229
+ return isOnekeyDevice(name ?? null, id) || isOnekeyDevice(localName ?? null, id);
112
230
  };
package/src/deviceType.ts CHANGED
@@ -7,4 +7,5 @@ export enum EDeviceType {
7
7
  Touch = 'touch',
8
8
  Pro = 'pro',
9
9
  Pro2 = 'pro2',
10
+ Neo = 'neo',
10
11
  }