@onekeyfe/hd-shared 1.2.0-alpha.12 → 1.2.0-alpha.121

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