@onekeyfe/hd-shared 1.2.0-alpha.14 → 1.2.0-alpha.140

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.
@@ -86,6 +86,7 @@ export declare const HardwareErrorCode: {
86
86
  readonly BleDeviceDisconnected: 720;
87
87
  readonly BlePoweredOff: 721;
88
88
  readonly BleUnsupported: 722;
89
+ readonly BleUnavailableWhileUsbConnected: 723;
89
90
  readonly RuntimeError: 800;
90
91
  readonly PinInvalid: 801;
91
92
  readonly PinCancelled: 802;
@@ -115,7 +116,9 @@ export declare const HardwareErrorCode: {
115
116
  readonly DeviceSettingsLanguageNotSupport: 826;
116
117
  readonly TooManyInputs: 827;
117
118
  readonly PinMismatch: 828;
118
- readonly DeviceLocked: 829;
119
+ readonly DeviceLocked: 830;
120
+ readonly WalletSessionInvalid: 831;
121
+ readonly NftStorageLimitReached: 832;
119
122
  readonly LowlevelTrasnportConnectError: 900;
120
123
  readonly WebDeviceNotFoundOrNeedsPermission: 901;
121
124
  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,qBA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AM,KAAG,aAQ9D,CAAC;AAEF,QAAA,MAAM,uCAAuC;oBAM3B,MAAM;oBACN,MAAM;;;mBAcvB,CAAC;AAEF,QAAA,MAAM,sCAAsC;oBAM1B,MAAM;oBACN,MAAM;;;mBAcvB,CAAC;AAEF,QAAA,MAAM,yCAAyC,cAClC,MAAM,GAAG,SAAS,YACnB,MAAM,GAAG,SAAS,iBACb,CAAC,UAAU,GAAG,KAAK,CAAC,EAAE,oBACnB;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,kBAsBF,CAAC;AAEF,QAAA,MAAM,6BAA6B,mBACjB,MAAM,qBACH,MAAM,eACZ,MAAM,kBAQpB,CAAC;AAEF,QAAA,MAAM,4BAA4B,aACtB,MAAM,aACL,MAAM,cACL,MAAM,cACN,MAAM,aACP,MAAM,kBAWlB,CAAC;AAEF,QAAA,MAAM,iCAAiC,eAAgB,MAAM,gBAAgB,aAAa,kBAItF,CAAC;AAEL,OAAO,EACL,uCAAuC,EACvC,sCAAsC,EACtC,yCAAyC,EACzC,6BAA6B,EAC7B,4BAA4B,EAC5B,iCAAiC,GAClC,CAAC"}
@@ -33,11 +33,13 @@ export declare enum EOneKeyBleMessageKeys {
33
33
  NOBLE_BLE_STOP_SCAN = "$onekey-noble-ble-stop-scan",
34
34
  NOBLE_BLE_GET_DEVICE = "$onekey-noble-ble-get-device",
35
35
  NOBLE_BLE_CONNECT = "$onekey-noble-ble-connect",
36
+ NOBLE_BLE_RELEASE = "$onekey-noble-ble-release",
36
37
  NOBLE_BLE_DISCONNECT = "$onekey-noble-ble-disconnect",
37
38
  NOBLE_BLE_WRITE = "$onekey-noble-ble-write",
38
39
  NOBLE_BLE_SUBSCRIBE = "$onekey-noble-ble-subscribe",
39
40
  NOBLE_BLE_UNSUBSCRIBE = "$onekey-noble-ble-unsubscribe",
40
41
  NOBLE_BLE_NOTIFICATION = "$onekey-noble-ble-notification",
42
+ NOBLE_BLE_MTU_CHANGED = "$onekey-noble-ble-mtu-changed",
41
43
  NOBLE_BLE_CANCEL_PAIRING = "$onekey-noble-ble-cancel-pairing"
42
44
  }
43
45
  export declare const ONEKEY_SERVICE_UUID = "00000001-0000-1000-8000-00805f9b34fb";
@@ -45,5 +47,18 @@ export declare const ONEKEY_WRITE_CHARACTERISTIC_UUID = "00000002-0000-1000-8000
45
47
  export declare const ONEKEY_NOTIFY_CHARACTERISTIC_UUID = "00000003-0000-1000-8000-00805f9b34fb";
46
48
  export declare const isHeaderChunk: (chunk: Buffer | Uint8Array) => boolean;
47
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 normalizePro2FindMyAdvertisementName: (value: string) => string;
61
+ export declare const hasOnekeyCommunicationService: (serviceUuids: Array<string | null | undefined> | null | undefined) => boolean;
62
+ export declare const isOnekeyBluetoothDevice: ({ id, name, localName, serviceUuids, }: BluetoothDeviceIdentity) => boolean;
48
63
  export {};
49
64
  //# 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;AAEF,KAAK,wBAAwB,GAAG;IAC9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AAM,KAAG,OAuBjE,CAAC;AAEF,KAAK,uBAAuB,GAAG;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,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;AAkC/C,eAAO,MAAM,6BAA6B,WAAY,MAAM,GAAG,IAAI,YAWlE,CAAC;AAEF,eAAO,MAAM,oCAAoC,UAAW,MAAM,WAejE,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
@@ -13,7 +13,15 @@ type WebUsbIdentityDescriptor = {
13
13
  manufacturerName?: string | null;
14
14
  };
15
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
+ */
16
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
+ */
17
25
  declare const ERROR_CODES_REQUIRE_DISCONNECT: readonly [106, 805];
18
26
  declare enum EOneKeyBleMessageKeys {
19
27
  BLE_SELECT = "$onekey-ble-select",
@@ -32,11 +40,13 @@ declare enum EOneKeyBleMessageKeys {
32
40
  NOBLE_BLE_STOP_SCAN = "$onekey-noble-ble-stop-scan",
33
41
  NOBLE_BLE_GET_DEVICE = "$onekey-noble-ble-get-device",
34
42
  NOBLE_BLE_CONNECT = "$onekey-noble-ble-connect",
43
+ NOBLE_BLE_RELEASE = "$onekey-noble-ble-release",
35
44
  NOBLE_BLE_DISCONNECT = "$onekey-noble-ble-disconnect",
36
45
  NOBLE_BLE_WRITE = "$onekey-noble-ble-write",
37
46
  NOBLE_BLE_SUBSCRIBE = "$onekey-noble-ble-subscribe",
38
47
  NOBLE_BLE_UNSUBSCRIBE = "$onekey-noble-ble-unsubscribe",
39
48
  NOBLE_BLE_NOTIFICATION = "$onekey-noble-ble-notification",
49
+ NOBLE_BLE_MTU_CHANGED = "$onekey-noble-ble-mtu-changed",
40
50
  NOBLE_BLE_CANCEL_PAIRING = "$onekey-noble-ble-cancel-pairing"
41
51
  }
42
52
  declare const ONEKEY_SERVICE_UUID = "00000001-0000-1000-8000-00805f9b34fb";
@@ -44,6 +54,19 @@ declare const ONEKEY_WRITE_CHARACTERISTIC_UUID = "00000002-0000-1000-8000-00805f
44
54
  declare const ONEKEY_NOTIFY_CHARACTERISTIC_UUID = "00000003-0000-1000-8000-00805f9b34fb";
45
55
  declare const isHeaderChunk: (chunk: Buffer | Uint8Array) => boolean;
46
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 normalizePro2FindMyAdvertisementName: (value: string) => string;
68
+ declare const hasOnekeyCommunicationService: (serviceUuids: Array<string | null | undefined> | null | undefined) => boolean;
69
+ declare const isOnekeyBluetoothDevice: ({ id, name, localName, serviceUuids, }: BluetoothDeviceIdentity) => boolean;
47
70
 
48
71
  type Deferred<T, I = any, D = any> = {
49
72
  id?: I;
@@ -76,53 +99,201 @@ declare class HardwareError extends Error {
76
99
  constructor(hardwareError: IHardwareError | string);
77
100
  }
78
101
  declare const HardwareErrorCode: {
102
+ /**
103
+ * This error can be thrown when unexpected error occurred and in most cases it is related to implementation bug.
104
+ * Original message is available in message property.
105
+ */
79
106
  readonly UnknownError: 0;
107
+ /**
108
+ * Firmware version mismatch
109
+ */
80
110
  readonly DeviceFwException: 101;
111
+ /**
112
+ * Device unexpected mode
113
+ */
81
114
  readonly DeviceUnexpectedMode: 102;
115
+ /**
116
+ * Device list is not initialized
117
+ */
82
118
  readonly DeviceListNotInitialized: 103;
119
+ /**
120
+ * Please select the connected device
121
+ */
83
122
  readonly SelectDevice: 104;
123
+ /**
124
+ * Device not found
125
+ */
84
126
  readonly DeviceNotFound: 105;
127
+ /**
128
+ * Device is not initialized
129
+ */
85
130
  readonly DeviceInitializeFailed: 106;
131
+ /**
132
+ * Device interrupted from another operation
133
+ */
86
134
  readonly DeviceInterruptedFromOutside: 107;
135
+ /**
136
+ * Device should be in bootloader mode
137
+ */
87
138
  readonly RequiredButInBootloaderMode: 108;
139
+ /**
140
+ * Device interrupted from user
141
+ */
88
142
  readonly DeviceInterruptedFromUser: 109;
143
+ /**
144
+ * Check device id is same
145
+ */
89
146
  readonly DeviceCheckDeviceIdError: 110;
147
+ /**
148
+ * Do not support passphrase
149
+ * @params: { require: string }
150
+ */
90
151
  readonly DeviceNotSupportPassphrase: 111;
91
152
  readonly DeviceCheckPassphraseStateError: 112;
153
+ /**
154
+ * use passphrase, but passphrase is not opened
155
+ */
92
156
  readonly DeviceNotOpenedPassphrase: 113;
157
+ /**
158
+ * not use passphrase, but passphrase is opened
159
+ */
93
160
  readonly DeviceOpenedPassphrase: 114;
161
+ /**
162
+ * Detect hardware that is in bootloader mode and return an error.
163
+ */
94
164
  readonly DeviceDetectInBootloaderMode: 115;
165
+ /**
166
+ * Device not allow in bootloader mode
167
+ */
95
168
  readonly NotAllowInBootloaderMode: 116;
169
+ /**
170
+ * Device is busy
171
+ */
96
172
  readonly DeviceBusy: 117;
173
+ /**
174
+ * Device check unlock type not match error
175
+ */
97
176
  readonly DeviceCheckUnlockTypeError: 118;
177
+ /**
178
+ * Not initialized
179
+ */
98
180
  readonly NotInitialized: 200;
181
+ /**
182
+ * Iframe not initialized
183
+ */
99
184
  readonly IFrameNotInitialized: 300;
185
+ /**
186
+ * iframe repeat initialization
187
+ */
100
188
  readonly IFrameAleradyInitialized: 301;
189
+ /**
190
+ * iframe load failure
191
+ */
101
192
  readonly IFrameLoadFail: 302;
193
+ /**
194
+ * init iframe time out
195
+ */
102
196
  readonly IframeTimeout: 303;
197
+ /**
198
+ * iframe blocked
199
+ */
103
200
  readonly IframeBlocked: 304;
201
+ /**
202
+ * iframe host not trust
203
+ */
104
204
  readonly IframeDistrust: 305;
205
+ /**
206
+ * Runtime errors during method execution
207
+ */
105
208
  readonly CallMethodError: 400;
209
+ /**
210
+ * Method does not responding
211
+ */
106
212
  readonly CallMethodNotResponse: 404;
213
+ /**
214
+ * Call method invalid parameter
215
+ */
107
216
  readonly CallMethodInvalidParameter: 405;
217
+ /**
218
+ * firmware update download failed
219
+ */
108
220
  readonly FirmwareUpdateDownloadFailed: 406;
221
+ /**
222
+ * Call method not supported, need update firmware
223
+ * @params: { current: string, require: string }
224
+ */
109
225
  readonly CallMethodNeedUpgradeFirmware: 407;
226
+ /**
227
+ * Call method not supported, is deprecated
228
+ * @params: { current: string, deprecated: string }
229
+ */
110
230
  readonly CallMethodDeprecated: 408;
231
+ /**
232
+ * Only one device can be connected during firmware upgrade
233
+ */
111
234
  readonly FirmwareUpdateLimitOneDevice: 409;
235
+ /**
236
+ * You need to manually enter boot
237
+ */
112
238
  readonly FirmwareUpdateManuallyEnterBoot: 410;
239
+ /**
240
+ * Manual entry fails. You must manually enter the boot
241
+ */
113
242
  readonly FirmwareUpdateAutoEnterBootFailure: 411;
243
+ /**
244
+ * The new firmware has not been released yet
245
+ */
114
246
  readonly NewFirmwareUnRelease: 412;
247
+ /**
248
+ * use OneKey desktop client to update the firmware
249
+ * because need copy resource file to Touch
250
+ */
115
251
  readonly UseDesktopToUpdateFirmware: 413;
252
+ /**
253
+ * Mandatory firmware update
254
+ * @params:{ connectId: string? , deviceId: string? }
255
+ */
116
256
  readonly NewFirmwareForceUpdate: 414;
257
+ /**
258
+ * Device not support this method
259
+ */
117
260
  readonly DeviceNotSupportMethod: 415;
261
+ /**
262
+ * Forbidden key path
263
+ */
118
264
  readonly ForbiddenKeyPath: 416;
265
+ /**
266
+ * Repeat unlocking
267
+ * all network get address by loop need repeat unlocking
268
+ */
119
269
  readonly RepeatUnlocking: 417;
270
+ /**
271
+ * Defective firmware detected
272
+ */
120
273
  readonly DefectiveFirmware: 418;
274
+ /**
275
+ * Netword request error
276
+ */
121
277
  readonly NetworkError: 500;
278
+ /**
279
+ * Transport not configured
280
+ */
122
281
  readonly TransportNotConfigured: 600;
282
+ /**
283
+ * Transport call in progress
284
+ */
123
285
  readonly TransportCallInProgress: 601;
286
+ /**
287
+ * Transport not found
288
+ */
124
289
  readonly TransportNotFound: 602;
290
+ /**
291
+ * Transport invalid protobuf
292
+ */
125
293
  readonly TransportInvalidProtobuf: 603;
294
+ /**
295
+ * Bluetooth error code
296
+ */
126
297
  readonly BleScanError: 700;
127
298
  readonly BlePermissionError: 701;
128
299
  readonly BleLocationError: 702;
@@ -146,38 +317,145 @@ declare const HardwareErrorCode: {
146
317
  readonly BleDeviceDisconnected: 720;
147
318
  readonly BlePoweredOff: 721;
148
319
  readonly BleUnsupported: 722;
320
+ readonly BleUnavailableWhileUsbConnected: 723;
321
+ /**
322
+ * Hardware runtiome errors
323
+ */
149
324
  readonly RuntimeError: 800;
325
+ /**
326
+ * invalid pin
327
+ */
150
328
  readonly PinInvalid: 801;
329
+ /**
330
+ * pin cancelled by user
331
+ */
151
332
  readonly PinCancelled: 802;
333
+ /**
334
+ * Action cancelled by user
335
+ */
152
336
  readonly ActionCancelled: 803;
337
+ /**
338
+ * Firmware installation failed
339
+ */
153
340
  readonly FirmwareError: 804;
341
+ /**
342
+ * transport response unexpect error
343
+ */
154
344
  readonly ResponseUnexpectTypeError: 805;
345
+ /**
346
+ * bridge network error
347
+ */
155
348
  readonly BridgeNetworkError: 806;
349
+ /**
350
+ * Bridge network timeout
351
+ */
156
352
  readonly BridgeTimeoutError: 807;
353
+ /**
354
+ * Bridge not installed
355
+ */
157
356
  readonly BridgeNotInstalled: 808;
357
+ /**
358
+ * ensure connect timeout
359
+ */
158
360
  readonly PollingTimeout: 809;
361
+ /**
362
+ * ensure connect stop polling
363
+ */
159
364
  readonly PollingStop: 810;
365
+ /**
366
+ * Device does not open blid sign
367
+ */
160
368
  readonly BlindSignDisabled: 811;
161
369
  readonly UnexpectPassphrase: 812;
370
+ /**
371
+ * NFT file already exists
372
+ */
162
373
  readonly FileAlreadyExists: 813;
374
+ /**
375
+ * check file length error
376
+ */
163
377
  readonly CheckDownloadFileError: 814;
378
+ /**
379
+ * not in signing mode
380
+ */
164
381
  readonly NotInSigningMode: 815;
382
+ /**
383
+ * not in signing mode
384
+ */
165
385
  readonly DataOverload: 816;
386
+ /**
387
+ * device disconnected during action
388
+ */
166
389
  readonly BridgeDeviceDisconnected: 817;
390
+ /**
391
+ * BTC PSBT too many utxos
392
+ * @params:{ count: number }
393
+ */
167
394
  readonly BTCPsbtTooManyUtxos: 818;
395
+ /**
396
+ * EMMC file write firmware error
397
+ */
168
398
  readonly EmmcFileWriteFirmwareError: 819;
399
+ /**
400
+ * Firmware verification failed (e.g., bootloader file verify failed)
401
+ */
169
402
  readonly FirmwareVerificationFailed: 820;
403
+ /**
404
+ * Web bridge coonect needs permission
405
+ */
170
406
  readonly BridgeNeedsPermission: 821;
171
407
  readonly CallQueueActionCancelled: 822;
408
+ /**
409
+ * Firmware downgrade not allowed
410
+ */
172
411
  readonly FirmwareDowngradeNotAllowed: 823;
412
+ /**
413
+ * Cosmos invalid JSON message, Only support Amino msgs.
414
+ */
173
415
  readonly CosmosInvalidJsonMessage: 824;
416
+ /**
417
+ * No setting provided
418
+ */
174
419
  readonly DeviceSettingsNotProvided: 825;
420
+ /**
421
+ * Language not supported
422
+ */
175
423
  readonly DeviceSettingsLanguageNotSupport: 826;
424
+ /**
425
+ * Too many inputs
426
+ * @params: { count?: string }
427
+ */
176
428
  readonly TooManyInputs: 827;
429
+ /**
430
+ * The two PIN entries did not match while setting/changing PIN on device
431
+ */
177
432
  readonly PinMismatch: 828;
178
- readonly DeviceLocked: 829;
433
+ /**
434
+ * Protocol V2 device must be unlocked before the requested operation.
435
+ * @params: { failureCode?: string; subcode?: number; firmwareMessage?: string }
436
+ */
437
+ readonly DeviceLocked: 830;
438
+ /**
439
+ * The cached wallet session is invalid or has expired.
440
+ * @params: { failureCode?: string; subcode?: number; firmwareMessage?: string }
441
+ */
442
+ readonly WalletSessionInvalid: 831;
443
+ /**
444
+ * Pro2 NFT storage has reached its item limit.
445
+ * @params: { count: number; limit: number }
446
+ */
447
+ readonly NftStorageLimitReached: 832;
448
+ /**
449
+ * Lowlevel transport connect error
450
+ */
179
451
  readonly LowlevelTrasnportConnectError: 900;
452
+ /**
453
+ * Web USB or Web Bluetooth device not found or needs permission
454
+ */
180
455
  readonly WebDeviceNotFoundOrNeedsPermission: 901;
456
+ /**
457
+ * Web USB or Web Bluetooth device prompt access error
458
+ */
181
459
  readonly WebDevicePromptAccessError: 902;
182
460
  };
183
461
  declare const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping;
@@ -249,7 +527,8 @@ declare enum EDeviceType {
249
527
  Mini = "mini",
250
528
  Touch = "touch",
251
529
  Pro = "pro",
252
- Pro2 = "pro2"
530
+ Pro2 = "pro2",
531
+ Neo = "neo"
253
532
  }
254
533
 
255
- 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, isKnownTrezorWebUsbDevice, isOnekeyDevice, serializeError, wait };
534
+ 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, normalizePro2FindMyAdvertisementName, serializeError, wait };
package/dist/index.js CHANGED
@@ -135,6 +135,7 @@ const HardwareErrorCode = {
135
135
  BleDeviceDisconnected: 720,
136
136
  BlePoweredOff: 721,
137
137
  BleUnsupported: 722,
138
+ BleUnavailableWhileUsbConnected: 723,
138
139
  RuntimeError: 800,
139
140
  PinInvalid: 801,
140
141
  PinCancelled: 802,
@@ -164,7 +165,9 @@ const HardwareErrorCode = {
164
165
  DeviceSettingsLanguageNotSupport: 826,
165
166
  TooManyInputs: 827,
166
167
  PinMismatch: 828,
167
- DeviceLocked: 829,
168
+ DeviceLocked: 830,
169
+ WalletSessionInvalid: 831,
170
+ NftStorageLimitReached: 832,
168
171
  LowlevelTrasnportConnectError: 900,
169
172
  WebDeviceNotFoundOrNeedsPermission: 901,
170
173
  WebDevicePromptAccessError: 902,
@@ -240,6 +243,7 @@ const HardwareErrorCodeMessage = {
240
243
  [HardwareErrorCode.BleDeviceDisconnected]: 'Device disconnected',
241
244
  [HardwareErrorCode.BlePoweredOff]: 'Bluetooth is turned off',
242
245
  [HardwareErrorCode.BleUnsupported]: 'Bluetooth is not supported on this device',
246
+ [HardwareErrorCode.BleUnavailableWhileUsbConnected]: 'Bluetooth is unavailable while USB is connected. Unplug USB and try again.',
243
247
  [HardwareErrorCode.RuntimeError]: 'Runtime error',
244
248
  [HardwareErrorCode.PinInvalid]: 'Pin invalid',
245
249
  [HardwareErrorCode.PinCancelled]: 'Pin cancelled',
@@ -270,6 +274,8 @@ const HardwareErrorCodeMessage = {
270
274
  [HardwareErrorCode.TooManyInputs]: 'Too many inputs',
271
275
  [HardwareErrorCode.PinMismatch]: 'PIN mismatch',
272
276
  [HardwareErrorCode.DeviceLocked]: 'Device locked',
277
+ [HardwareErrorCode.WalletSessionInvalid]: 'Wallet session is invalid or expired',
278
+ [HardwareErrorCode.NftStorageLimitReached]: 'NFT storage limit reached. Remove an NFT from the device and try again.',
273
279
  [HardwareErrorCode.LowlevelTrasnportConnectError]: 'Lowlevel transport connect error',
274
280
  [HardwareErrorCode.WebDeviceNotFoundOrNeedsPermission]: 'Web-USB or Web-Bluetooth device not found or needs permission',
275
281
  [HardwareErrorCode.WebDevicePromptAccessError]: 'Web-USB or Web-Bluetooth device prompt access error',
@@ -434,11 +440,13 @@ exports.EOneKeyBleMessageKeys = void 0;
434
440
  EOneKeyBleMessageKeys["NOBLE_BLE_STOP_SCAN"] = "$onekey-noble-ble-stop-scan";
435
441
  EOneKeyBleMessageKeys["NOBLE_BLE_GET_DEVICE"] = "$onekey-noble-ble-get-device";
436
442
  EOneKeyBleMessageKeys["NOBLE_BLE_CONNECT"] = "$onekey-noble-ble-connect";
443
+ EOneKeyBleMessageKeys["NOBLE_BLE_RELEASE"] = "$onekey-noble-ble-release";
437
444
  EOneKeyBleMessageKeys["NOBLE_BLE_DISCONNECT"] = "$onekey-noble-ble-disconnect";
438
445
  EOneKeyBleMessageKeys["NOBLE_BLE_WRITE"] = "$onekey-noble-ble-write";
439
446
  EOneKeyBleMessageKeys["NOBLE_BLE_SUBSCRIBE"] = "$onekey-noble-ble-subscribe";
440
447
  EOneKeyBleMessageKeys["NOBLE_BLE_UNSUBSCRIBE"] = "$onekey-noble-ble-unsubscribe";
441
448
  EOneKeyBleMessageKeys["NOBLE_BLE_NOTIFICATION"] = "$onekey-noble-ble-notification";
449
+ EOneKeyBleMessageKeys["NOBLE_BLE_MTU_CHANGED"] = "$onekey-noble-ble-mtu-changed";
442
450
  EOneKeyBleMessageKeys["NOBLE_BLE_CANCEL_PAIRING"] = "$onekey-noble-ble-cancel-pairing";
443
451
  })(exports.EOneKeyBleMessageKeys || (exports.EOneKeyBleMessageKeys = {}));
444
452
  const ONEKEY_SERVICE_UUID = '00000001-0000-1000-8000-00805f9b34fb';
@@ -487,11 +495,95 @@ const isOnekeyDevice = (name, id) => {
487
495
  return true;
488
496
  if (normalizedName.startsWith('touch ') ||
489
497
  normalizedName.startsWith('pro ') ||
490
- normalizedName.startsWith('pro2 ')) {
498
+ normalizedName.startsWith('pro2 ') ||
499
+ normalizedName.startsWith('neo ')) {
491
500
  return true;
492
501
  }
493
502
  return isOneKeyShortName(normalizedName);
494
503
  };
504
+ const BLUETOOTH_BASE_UUID_SUFFIX = '00001000800000805f9b34fb';
505
+ const normalizeBleUuid = (uuid) => (uuid !== null && uuid !== void 0 ? uuid : '').replace(/-/g, '').toLowerCase();
506
+ const createKnownBleUuidAliases = (uuid) => {
507
+ const normalized = normalizeBleUuid(uuid);
508
+ const aliases = new Set([normalized]);
509
+ if (normalized.length !== 32 || !normalized.endsWith(BLUETOOTH_BASE_UUID_SUFFIX)) {
510
+ return aliases;
511
+ }
512
+ const assignedNumber = normalized.slice(0, 8);
513
+ aliases.add(assignedNumber);
514
+ if (assignedNumber.startsWith('0000')) {
515
+ aliases.add(assignedNumber.slice(4));
516
+ }
517
+ return aliases;
518
+ };
519
+ const matchesKnownBleUuid = (actualUuid, aliases) => aliases.has(normalizeBleUuid(actualUuid));
520
+ const ONEKEY_COMMUNICATION_SERVICE_ALIASES = createKnownBleUuidAliases(ONEKEY_SERVICE_UUID);
521
+ const FIDO_SERVICE_ALIASES = createKnownBleUuidAliases('0000fffd-0000-1000-8000-00805f9b34fb');
522
+ const PRO2_COMPACT_NAME_PATTERN = /^(?:onekey)?pro2[a-f0-9]{4}$/i;
523
+ const FIND_MY_COMPACT_SUFFIXES = [
524
+ 'findemy',
525
+ 'findem',
526
+ 'finde',
527
+ 'findmy',
528
+ 'findm',
529
+ 'find',
530
+ 'fin',
531
+ ];
532
+ const COMPLETE_FIND_MY_COMPACT_SUFFIXES = ['findemy', 'findmy'];
533
+ const compactBleName = (value) => Array.from(value)
534
+ .filter(character => character !== '-' && character.trim() !== '')
535
+ .join('')
536
+ .toLowerCase();
537
+ const getFindMyCompactSuffix = (compactName) => FIND_MY_COMPACT_SUFFIXES.find(candidate => compactName.endsWith(candidate));
538
+ const getPro2FindMyBaseLength = (value) => {
539
+ const compactName = compactBleName(value);
540
+ const suffix = getFindMyCompactSuffix(compactName);
541
+ if (!suffix)
542
+ return undefined;
543
+ const compactBaseName = compactName.slice(0, -suffix.length);
544
+ return PRO2_COMPACT_NAME_PATTERN.test(compactBaseName) ? compactBaseName.length : undefined;
545
+ };
546
+ const isPro2FindMyAdvertisementName = (value) => {
547
+ if (!value)
548
+ return false;
549
+ if (getPro2FindMyBaseLength(value) !== undefined)
550
+ return true;
551
+ const compactName = compactBleName(value);
552
+ const suffix = COMPLETE_FIND_MY_COMPACT_SUFFIXES.find(candidate => compactName.endsWith(candidate));
553
+ if (!suffix)
554
+ return false;
555
+ return compactName.slice(0, -suffix.length).includes('pro2');
556
+ };
557
+ const normalizePro2FindMyAdvertisementName = (value) => {
558
+ const baseLength = getPro2FindMyBaseLength(value);
559
+ if (baseLength === undefined)
560
+ return value;
561
+ let compactLength = 0;
562
+ for (let index = 0; index < value.length; index += 1) {
563
+ const character = value[index];
564
+ if (character !== '-' && character.trim() !== '') {
565
+ compactLength += 1;
566
+ if (compactLength === baseLength) {
567
+ return value.slice(0, index + 1).trimEnd();
568
+ }
569
+ }
570
+ }
571
+ return value;
572
+ };
573
+ const hasOnekeyCommunicationService = (serviceUuids) => (serviceUuids !== null && serviceUuids !== void 0 ? serviceUuids : []).some(uuid => matchesKnownBleUuid(uuid, ONEKEY_COMMUNICATION_SERVICE_ALIASES));
574
+ const isOnekeyBluetoothDevice = ({ id, name, localName, serviceUuids, }) => {
575
+ const advertisedServiceUuids = serviceUuids !== null && serviceUuids !== void 0 ? serviceUuids : [];
576
+ if (hasOnekeyCommunicationService(advertisedServiceUuids)) {
577
+ return true;
578
+ }
579
+ if (isPro2FindMyAdvertisementName(name) || isPro2FindMyAdvertisementName(localName)) {
580
+ return false;
581
+ }
582
+ if (advertisedServiceUuids.some(uuid => matchesKnownBleUuid(uuid, FIDO_SERVICE_ALIASES))) {
583
+ return false;
584
+ }
585
+ return isOnekeyDevice(name !== null && name !== void 0 ? name : null, id) || isOnekeyDevice(localName !== null && localName !== void 0 ? localName : null, id);
586
+ };
495
587
 
496
588
  /******************************************************************************
497
589
  Copyright (c) Microsoft Corporation.
@@ -564,6 +656,7 @@ exports.EDeviceType = void 0;
564
656
  EDeviceType["Touch"] = "touch";
565
657
  EDeviceType["Pro"] = "pro";
566
658
  EDeviceType["Pro2"] = "pro2";
659
+ EDeviceType["Neo"] = "neo";
567
660
  })(exports.EDeviceType || (exports.EDeviceType = {}));
568
661
 
569
662
  exports.CreateErrorByMessage = CreateErrorByMessage;
@@ -584,11 +677,18 @@ exports.createDefectiveFirmwareError = createDefectiveFirmwareError;
584
677
  exports.createDeferred = createDeferred;
585
678
  exports.createDeprecatedHardwareError = createDeprecatedHardwareError;
586
679
  exports.createDeviceNotSupportMethodError = createDeviceNotSupportMethodError;
680
+ exports.createKnownBleUuidAliases = createKnownBleUuidAliases;
587
681
  exports.createNeedUpgradeFirmwareHardwareError = createNeedUpgradeFirmwareHardwareError;
588
682
  exports.createNewFirmwareForceUpdateHardwareError = createNewFirmwareForceUpdateHardwareError;
589
683
  exports.createNewFirmwareUnReleaseHardwareError = createNewFirmwareUnReleaseHardwareError;
684
+ exports.hasOnekeyCommunicationService = hasOnekeyCommunicationService;
590
685
  exports.isHeaderChunk = isHeaderChunk;
591
686
  exports.isKnownTrezorWebUsbDevice = isKnownTrezorWebUsbDevice;
687
+ exports.isOnekeyBluetoothDevice = isOnekeyBluetoothDevice;
592
688
  exports.isOnekeyDevice = isOnekeyDevice;
689
+ exports.isPro2FindMyAdvertisementName = isPro2FindMyAdvertisementName;
690
+ exports.matchesKnownBleUuid = matchesKnownBleUuid;
691
+ exports.normalizeBleUuid = normalizeBleUuid;
692
+ exports.normalizePro2FindMyAdvertisementName = normalizePro2FindMyAdvertisementName;
593
693
  exports.serializeError = serializeError;
594
694
  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.14",
3
+ "version": "1.2.0-alpha.140",
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": "c1edaed6435fb6049c7516c64b298ee62519e797"
29
+ "gitHead": "15e3f0dc6c543c83a96e63b5d19aad70cdd6efb1"
29
30
  }
@@ -0,0 +1,36 @@
1
+ import {
2
+ HardwareErrorCode,
3
+ HardwareErrorCodeMessage,
4
+ TypedError,
5
+ serializeError,
6
+ } from './HardwareError';
7
+
8
+ describe('HardwareErrorCode compatibility', () => {
9
+ test('preserves published Protocol V2 values while leaving code 829 unused', () => {
10
+ expect(HardwareErrorCode).not.toHaveProperty('KaspaPrevTxIdMismatch');
11
+ expect(HardwareErrorCode.DeviceLocked).toBe(830);
12
+ expect(HardwareErrorCode.WalletSessionInvalid).toBe(831);
13
+ });
14
+
15
+ test('reserves the BLE and USB conflict code for app error mapping', () => {
16
+ expect(HardwareErrorCode.BleUnavailableWhileUsbConnected).toBe(723);
17
+ expect(HardwareErrorCodeMessage[HardwareErrorCode.BleUnavailableWhileUsbConnected]).toBe(
18
+ 'Bluetooth is unavailable while USB is connected. Unplug USB and try again.'
19
+ );
20
+ expect(
21
+ serializeError({
22
+ error: TypedError(HardwareErrorCode.BleUnavailableWhileUsbConnected, undefined, {
23
+ failureCode: 'Failure_ProcessError',
24
+ firmwareMessage: 'link disabled',
25
+ }),
26
+ })
27
+ ).toEqual({
28
+ code: 723,
29
+ error: 'Bluetooth is unavailable while USB is connected. Unplug USB and try again.',
30
+ params: {
31
+ failureCode: 'Failure_ProcessError',
32
+ firmwareMessage: 'link disabled',
33
+ },
34
+ });
35
+ });
36
+ });
@@ -345,6 +345,7 @@ export const HardwareErrorCode = {
345
345
  BleDeviceDisconnected: 720,
346
346
  BlePoweredOff: 721,
347
347
  BleUnsupported: 722,
348
+ BleUnavailableWhileUsbConnected: 723,
348
349
 
349
350
  /**
350
351
  * Hardware runtiome errors
@@ -488,7 +489,19 @@ export const HardwareErrorCode = {
488
489
  * Protocol V2 device must be unlocked before the requested operation.
489
490
  * @params: { failureCode?: string; subcode?: number; firmwareMessage?: string }
490
491
  */
491
- DeviceLocked: 829,
492
+ DeviceLocked: 830,
493
+
494
+ /**
495
+ * The cached wallet session is invalid or has expired.
496
+ * @params: { failureCode?: string; subcode?: number; firmwareMessage?: string }
497
+ */
498
+ WalletSessionInvalid: 831,
499
+
500
+ /**
501
+ * Pro2 NFT storage has reached its item limit.
502
+ * @params: { count: number; limit: number }
503
+ */
504
+ NftStorageLimitReached: 832,
492
505
 
493
506
  /**
494
507
  * Lowlevel transport connect error
@@ -607,6 +620,8 @@ export const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping = {
607
620
  [HardwareErrorCode.BleDeviceDisconnected]: 'Device disconnected',
608
621
  [HardwareErrorCode.BlePoweredOff]: 'Bluetooth is turned off',
609
622
  [HardwareErrorCode.BleUnsupported]: 'Bluetooth is not supported on this device',
623
+ [HardwareErrorCode.BleUnavailableWhileUsbConnected]:
624
+ 'Bluetooth is unavailable while USB is connected. Unplug USB and try again.',
610
625
 
611
626
  /**
612
627
  * Runtime Error
@@ -642,6 +657,9 @@ export const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping = {
642
657
  [HardwareErrorCode.TooManyInputs]: 'Too many inputs',
643
658
  [HardwareErrorCode.PinMismatch]: 'PIN mismatch',
644
659
  [HardwareErrorCode.DeviceLocked]: 'Device locked',
660
+ [HardwareErrorCode.WalletSessionInvalid]: 'Wallet session is invalid or expired',
661
+ [HardwareErrorCode.NftStorageLimitReached]:
662
+ 'NFT storage limit reached. Remove an NFT from the device and try again.',
645
663
 
646
664
  /**
647
665
  * Lowlevel transport
@@ -1,9 +1,19 @@
1
- import { isKnownTrezorWebUsbDevice, isOnekeyDevice } from './constants';
1
+ import {
2
+ createKnownBleUuidAliases,
3
+ hasOnekeyCommunicationService,
4
+ isKnownTrezorWebUsbDevice,
5
+ isOnekeyBluetoothDevice,
6
+ isOnekeyDevice,
7
+ isPro2FindMyAdvertisementName,
8
+ matchesKnownBleUuid,
9
+ normalizePro2FindMyAdvertisementName,
10
+ } from './constants';
2
11
 
3
12
  describe('hardware device identity filters', () => {
4
13
  it('accepts known OneKey BLE names', () => {
5
14
  expect(isOnekeyDevice('Touch A1B2')).toBe(true);
6
15
  expect(isOnekeyDevice('Pro A1B2')).toBe(true);
16
+ expect(isOnekeyDevice('Neo A1B2')).toBe(true);
7
17
  expect(isOnekeyDevice('K1234')).toBe(true);
8
18
  expect(isOnekeyDevice('S8')).toBe(true);
9
19
  });
@@ -13,6 +23,119 @@ describe('hardware device identity filters', () => {
13
23
  expect(isOnekeyDevice('Ledger Nano X')).toBe(false);
14
24
  });
15
25
 
26
+ it('does not identify an FFFD-only advertisement as OneKey', () => {
27
+ expect(isOnekeyBluetoothDevice({ name: 'Find My', serviceUuids: ['fffd'] })).toBe(false);
28
+ expect(
29
+ isOnekeyBluetoothDevice({ serviceUuids: ['0000fffd-0000-1000-8000-00805f9b34fb'] })
30
+ ).toBe(false);
31
+ });
32
+
33
+ it('identifies Pro2 communication advertisements independently of their display name', () => {
34
+ expect(
35
+ isOnekeyBluetoothDevice({
36
+ name: 'Pro2 A1B2',
37
+ serviceUuids: ['0001', 'fffd'],
38
+ })
39
+ ).toBe(true);
40
+ expect(
41
+ isOnekeyBluetoothDevice({
42
+ localName: 'Pro2 A1B2 - Find My',
43
+ serviceUuids: ['0001', 'fffd'],
44
+ })
45
+ ).toBe(true);
46
+ expect(
47
+ isOnekeyBluetoothDevice({
48
+ name: 'Pro2 5E9D - Finde My',
49
+ serviceUuids: ['0001', 'fffd'],
50
+ })
51
+ ).toBe(true);
52
+ });
53
+
54
+ it('rejects Pro2 Find My entries when the communication service is absent', () => {
55
+ expect(
56
+ isOnekeyBluetoothDevice({
57
+ name: 'Pro2 A1B2 - Find My',
58
+ })
59
+ ).toBe(false);
60
+ expect(
61
+ isOnekeyBluetoothDevice({
62
+ localName: 'OneKey Pro 2 A1B2 - Find My',
63
+ serviceUuids: [],
64
+ })
65
+ ).toBe(false);
66
+ expect(
67
+ isOnekeyBluetoothDevice({
68
+ name: 'Pro2 5E9D - Finde My',
69
+ serviceUuids: ['fffd'],
70
+ })
71
+ ).toBe(false);
72
+ expect(isOnekeyBluetoothDevice({ name: 'Pro2 - Find My' })).toBe(false);
73
+ expect(isOnekeyBluetoothDevice({ name: 'Pro2 G12Z - Find My' })).toBe(false);
74
+ });
75
+
76
+ it('uses a broad Find My guard without broadening public name normalization', () => {
77
+ expect(isPro2FindMyAdvertisementName('Pro2 Griffin - Find My')).toBe(true);
78
+ expect(isPro2FindMyAdvertisementName('Pro2 Griffin')).toBe(false);
79
+ expect(isPro2FindMyAdvertisementName('Pro2 22D8 - Find My')).toBe(true);
80
+ expect(normalizePro2FindMyAdvertisementName('Pro2 Griffin - Find My')).toBe(
81
+ 'Pro2 Griffin - Find My'
82
+ );
83
+ expect(normalizePro2FindMyAdvertisementName('Pro2 22D8 - Find My')).toBe('Pro2 22D8');
84
+ });
85
+
86
+ it.each([
87
+ ['Pro2 A1B2 - Find My', 'Pro2 A1B2'],
88
+ ['Pro2 5E9D - Finde My', 'Pro2 5E9D'],
89
+ [' OneKey Pro 2 A1B2 Find My ', ' OneKey Pro 2 A1B2'],
90
+ ['OneKey Pro-2 22D8--Find-My', 'OneKey Pro-2 22D8'],
91
+ ['Pro2 22D8FindMy', 'Pro2 22D8'],
92
+ ['Pro2 22D8 - Fin', 'Pro2 22D8'],
93
+ ['Pro2 22D8FindM', 'Pro2 22D8'],
94
+ [`Pro2 22D8${'\t'.repeat(10_000)}Find My`, 'Pro2 22D8'],
95
+ ['Pro2 A1B2', 'Pro2 A1B2'],
96
+ ['Pro2 Griffin', 'Pro2 Griffin'],
97
+ ['Find My', 'Find My'],
98
+ ])('normalizes the public Pro2 advertisement name %s', (name, expected) => {
99
+ expect(normalizePro2FindMyAdvertisementName(name)).toBe(expected);
100
+ });
101
+
102
+ it('keeps OneKey discovery on the communication service', () => {
103
+ expect(
104
+ isOnekeyBluetoothDevice({
105
+ name: 'OneKey Pro 2',
106
+ serviceUuids: ['00000001-0000-1000-8000-00805f9b34fb'],
107
+ })
108
+ ).toBe(true);
109
+ });
110
+
111
+ it('only aliases standard Bluetooth Base UUID representations', () => {
112
+ const aliases = createKnownBleUuidAliases('00000001-0000-1000-8000-00805f9b34fb');
113
+
114
+ expect(matchesKnownBleUuid('0001', aliases)).toBe(true);
115
+ expect(matchesKnownBleUuid('00000001', aliases)).toBe(true);
116
+ expect(matchesKnownBleUuid('abcd0001-1234-5678-9012-abcdefabcdef', aliases)).toBe(false);
117
+ });
118
+
119
+ it('does not treat vendor-specific UUID fragments as communication or FIDO services', () => {
120
+ expect(
121
+ isOnekeyBluetoothDevice({
122
+ name: 'OneKey Pro 2',
123
+ serviceUuids: ['abcdfffd-1234-5678-9012-abcdefabcdef'],
124
+ })
125
+ ).toBe(true);
126
+ expect(
127
+ isOnekeyBluetoothDevice({
128
+ serviceUuids: ['abcd0001-1234-5678-9012-abcdefabcdef'],
129
+ })
130
+ ).toBe(false);
131
+ });
132
+
133
+ it('requires an explicitly advertised communication service for strict discovery', () => {
134
+ expect(hasOnekeyCommunicationService([])).toBe(false);
135
+ expect(hasOnekeyCommunicationService(['0001'])).toBe(true);
136
+ expect(hasOnekeyCommunicationService(['abcd0001-1234-5678-9012-abcdefabcdef'])).toBe(false);
137
+ });
138
+
16
139
  it('only filters WebUSB descriptors that are explicitly identified as Trezor', () => {
17
140
  expect(
18
141
  isKnownTrezorWebUsbDevice({
package/src/constants.ts CHANGED
@@ -10,10 +10,10 @@ 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
 
@@ -86,11 +86,15 @@ export enum EOneKeyBleMessageKeys {
86
86
  NOBLE_BLE_STOP_SCAN = '$onekey-noble-ble-stop-scan',
87
87
  NOBLE_BLE_GET_DEVICE = '$onekey-noble-ble-get-device',
88
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',
89
92
  NOBLE_BLE_DISCONNECT = '$onekey-noble-ble-disconnect',
90
93
  NOBLE_BLE_WRITE = '$onekey-noble-ble-write',
91
94
  NOBLE_BLE_SUBSCRIBE = '$onekey-noble-ble-subscribe',
92
95
  NOBLE_BLE_UNSUBSCRIBE = '$onekey-noble-ble-unsubscribe',
93
96
  NOBLE_BLE_NOTIFICATION = '$onekey-noble-ble-notification',
97
+ NOBLE_BLE_MTU_CHANGED = '$onekey-noble-ble-mtu-changed',
94
98
  NOBLE_BLE_CANCEL_PAIRING = '$onekey-noble-ble-cancel-pairing',
95
99
  }
96
100
 
@@ -148,9 +152,136 @@ export const isOnekeyDevice = (name: string | null, id?: string): boolean => {
148
152
  if (
149
153
  normalizedName.startsWith('touch ') ||
150
154
  normalizedName.startsWith('pro ') ||
151
- normalizedName.startsWith('pro2 ')
155
+ normalizedName.startsWith('pro2 ') ||
156
+ normalizedName.startsWith('neo ')
152
157
  ) {
153
158
  return true;
154
159
  }
155
160
  return isOneKeyShortName(normalizedName);
156
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
+ const PRO2_COMPACT_NAME_PATTERN = /^(?:onekey)?pro2[a-f0-9]{4}$/i;
199
+ const FIND_MY_COMPACT_SUFFIXES = [
200
+ 'findemy',
201
+ 'findem',
202
+ 'finde',
203
+ 'findmy',
204
+ 'findm',
205
+ 'find',
206
+ 'fin',
207
+ ] as const;
208
+ const COMPLETE_FIND_MY_COMPACT_SUFFIXES = ['findemy', 'findmy'] as const;
209
+
210
+ const compactBleName = (value: string) =>
211
+ Array.from(value)
212
+ .filter(character => character !== '-' && character.trim() !== '')
213
+ .join('')
214
+ .toLowerCase();
215
+
216
+ const getFindMyCompactSuffix = (compactName: string) =>
217
+ FIND_MY_COMPACT_SUFFIXES.find(candidate => compactName.endsWith(candidate));
218
+
219
+ const getPro2FindMyBaseLength = (value: string) => {
220
+ const compactName = compactBleName(value);
221
+ const suffix = getFindMyCompactSuffix(compactName);
222
+ if (!suffix) return undefined;
223
+
224
+ const compactBaseName = compactName.slice(0, -suffix.length);
225
+ return PRO2_COMPACT_NAME_PATTERN.test(compactBaseName) ? compactBaseName.length : undefined;
226
+ };
227
+
228
+ export const isPro2FindMyAdvertisementName = (value?: string | null) => {
229
+ if (!value) return false;
230
+ if (getPro2FindMyBaseLength(value) !== undefined) return true;
231
+
232
+ const compactName = compactBleName(value);
233
+ const suffix = COMPLETE_FIND_MY_COMPACT_SUFFIXES.find(candidate =>
234
+ compactName.endsWith(candidate)
235
+ );
236
+ if (!suffix) return false;
237
+
238
+ return compactName.slice(0, -suffix.length).includes('pro2');
239
+ };
240
+
241
+ export const normalizePro2FindMyAdvertisementName = (value: string) => {
242
+ const baseLength = getPro2FindMyBaseLength(value);
243
+ if (baseLength === undefined) return value;
244
+
245
+ let compactLength = 0;
246
+ for (let index = 0; index < value.length; index += 1) {
247
+ const character = value[index];
248
+ if (character !== '-' && character.trim() !== '') {
249
+ compactLength += 1;
250
+ if (compactLength === baseLength) {
251
+ return value.slice(0, index + 1).trimEnd();
252
+ }
253
+ }
254
+ }
255
+ return value;
256
+ };
257
+
258
+ export const hasOnekeyCommunicationService = (
259
+ serviceUuids: Array<string | null | undefined> | null | undefined
260
+ ) =>
261
+ (serviceUuids ?? []).some(uuid =>
262
+ matchesKnownBleUuid(uuid, ONEKEY_COMMUNICATION_SERVICE_ALIASES)
263
+ );
264
+
265
+ export const isOnekeyBluetoothDevice = ({
266
+ id,
267
+ name,
268
+ localName,
269
+ serviceUuids,
270
+ }: BluetoothDeviceIdentity): boolean => {
271
+ const advertisedServiceUuids = serviceUuids ?? [];
272
+ if (hasOnekeyCommunicationService(advertisedServiceUuids)) {
273
+ return true;
274
+ }
275
+
276
+ // Android can return a connected Find My peripheral without its advertised
277
+ // services. Do not let the Pro2-looking name fall through to name discovery.
278
+ if (isPro2FindMyAdvertisementName(name) || isPro2FindMyAdvertisementName(localName)) {
279
+ return false;
280
+ }
281
+
282
+ if (advertisedServiceUuids.some(uuid => matchesKnownBleUuid(uuid, FIDO_SERVICE_ALIASES))) {
283
+ return false;
284
+ }
285
+
286
+ return isOnekeyDevice(name ?? null, id) || isOnekeyDevice(localName ?? null, id);
287
+ };
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
  }