@onekeyfe/hd-shared 1.2.0-alpha.3 → 1.2.0-alpha.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -115,6 +115,9 @@ export declare const HardwareErrorCode: {
115
115
  readonly DeviceSettingsLanguageNotSupport: 826;
116
116
  readonly TooManyInputs: 827;
117
117
  readonly PinMismatch: 828;
118
+ readonly KaspaPrevTxIdMismatch: 829;
119
+ readonly DeviceLocked: 830;
120
+ readonly WalletSessionInvalid: 831;
118
121
  readonly LowlevelTrasnportConnectError: 900;
119
122
  readonly WebDeviceNotFoundOrNeedsPermission: 901;
120
123
  readonly WebDevicePromptAccessError: 902;
@@ -1 +1 @@
1
- {"version":3,"file":"HardwareError.d.ts","sourceRoot":"","sources":["../src/HardwareError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,OAAO,CAAC,OAAO,iBAAiB,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,GAAG,CAAC;CACd;AAED,KAAK,OAAO,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAE5C,KAAK,+BAA+B,GAAG;KAAG,CAAC,IAAI,OAAO,CAAC,OAAO,iBAAiB,CAAC,GAAG,MAAM;CAAE,CAAC;AAE5F,KAAK,cAAc,GAAG,OAAO,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAsCxD,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAS,EAAE,cAAc,CAAkC;IAE3D,OAAO,SAAM;IAEb,MAAM,EAAE,GAAG,CAAM;gBAEL,aAAa,EAAE,cAAc,GAAG,MAAM;CAmBnD;AAED,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,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 {
@@ -39,4 +45,5 @@ export declare const ONEKEY_WRITE_CHARACTERISTIC_UUID = "00000002-0000-1000-8000
39
45
  export declare const ONEKEY_NOTIFY_CHARACTERISTIC_UUID = "00000003-0000-1000-8000-00805f9b34fb";
40
46
  export declare const isHeaderChunk: (chunk: Buffer | Uint8Array) => boolean;
41
47
  export declare const isOnekeyDevice: (name: string | null, id?: string) => boolean;
48
+ export {};
42
49
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants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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",
@@ -70,53 +84,201 @@ declare class HardwareError extends Error {
70
84
  constructor(hardwareError: IHardwareError | string);
71
85
  }
72
86
  declare const HardwareErrorCode: {
87
+ /**
88
+ * This error can be thrown when unexpected error occurred and in most cases it is related to implementation bug.
89
+ * Original message is available in message property.
90
+ */
73
91
  readonly UnknownError: 0;
92
+ /**
93
+ * Firmware version mismatch
94
+ */
74
95
  readonly DeviceFwException: 101;
96
+ /**
97
+ * Device unexpected mode
98
+ */
75
99
  readonly DeviceUnexpectedMode: 102;
100
+ /**
101
+ * Device list is not initialized
102
+ */
76
103
  readonly DeviceListNotInitialized: 103;
104
+ /**
105
+ * Please select the connected device
106
+ */
77
107
  readonly SelectDevice: 104;
108
+ /**
109
+ * Device not found
110
+ */
78
111
  readonly DeviceNotFound: 105;
112
+ /**
113
+ * Device is not initialized
114
+ */
79
115
  readonly DeviceInitializeFailed: 106;
116
+ /**
117
+ * Device interrupted from another operation
118
+ */
80
119
  readonly DeviceInterruptedFromOutside: 107;
120
+ /**
121
+ * Device should be in bootloader mode
122
+ */
81
123
  readonly RequiredButInBootloaderMode: 108;
124
+ /**
125
+ * Device interrupted from user
126
+ */
82
127
  readonly DeviceInterruptedFromUser: 109;
128
+ /**
129
+ * Check device id is same
130
+ */
83
131
  readonly DeviceCheckDeviceIdError: 110;
132
+ /**
133
+ * Do not support passphrase
134
+ * @params: { require: string }
135
+ */
84
136
  readonly DeviceNotSupportPassphrase: 111;
85
137
  readonly DeviceCheckPassphraseStateError: 112;
138
+ /**
139
+ * use passphrase, but passphrase is not opened
140
+ */
86
141
  readonly DeviceNotOpenedPassphrase: 113;
142
+ /**
143
+ * not use passphrase, but passphrase is opened
144
+ */
87
145
  readonly DeviceOpenedPassphrase: 114;
146
+ /**
147
+ * Detect hardware that is in bootloader mode and return an error.
148
+ */
88
149
  readonly DeviceDetectInBootloaderMode: 115;
150
+ /**
151
+ * Device not allow in bootloader mode
152
+ */
89
153
  readonly NotAllowInBootloaderMode: 116;
154
+ /**
155
+ * Device is busy
156
+ */
90
157
  readonly DeviceBusy: 117;
158
+ /**
159
+ * Device check unlock type not match error
160
+ */
91
161
  readonly DeviceCheckUnlockTypeError: 118;
162
+ /**
163
+ * Not initialized
164
+ */
92
165
  readonly NotInitialized: 200;
166
+ /**
167
+ * Iframe not initialized
168
+ */
93
169
  readonly IFrameNotInitialized: 300;
170
+ /**
171
+ * iframe repeat initialization
172
+ */
94
173
  readonly IFrameAleradyInitialized: 301;
174
+ /**
175
+ * iframe load failure
176
+ */
95
177
  readonly IFrameLoadFail: 302;
178
+ /**
179
+ * init iframe time out
180
+ */
96
181
  readonly IframeTimeout: 303;
182
+ /**
183
+ * iframe blocked
184
+ */
97
185
  readonly IframeBlocked: 304;
186
+ /**
187
+ * iframe host not trust
188
+ */
98
189
  readonly IframeDistrust: 305;
190
+ /**
191
+ * Runtime errors during method execution
192
+ */
99
193
  readonly CallMethodError: 400;
194
+ /**
195
+ * Method does not responding
196
+ */
100
197
  readonly CallMethodNotResponse: 404;
198
+ /**
199
+ * Call method invalid parameter
200
+ */
101
201
  readonly CallMethodInvalidParameter: 405;
202
+ /**
203
+ * firmware update download failed
204
+ */
102
205
  readonly FirmwareUpdateDownloadFailed: 406;
206
+ /**
207
+ * Call method not supported, need update firmware
208
+ * @params: { current: string, require: string }
209
+ */
103
210
  readonly CallMethodNeedUpgradeFirmware: 407;
211
+ /**
212
+ * Call method not supported, is deprecated
213
+ * @params: { current: string, deprecated: string }
214
+ */
104
215
  readonly CallMethodDeprecated: 408;
216
+ /**
217
+ * Only one device can be connected during firmware upgrade
218
+ */
105
219
  readonly FirmwareUpdateLimitOneDevice: 409;
220
+ /**
221
+ * You need to manually enter boot
222
+ */
106
223
  readonly FirmwareUpdateManuallyEnterBoot: 410;
224
+ /**
225
+ * Manual entry fails. You must manually enter the boot
226
+ */
107
227
  readonly FirmwareUpdateAutoEnterBootFailure: 411;
228
+ /**
229
+ * The new firmware has not been released yet
230
+ */
108
231
  readonly NewFirmwareUnRelease: 412;
232
+ /**
233
+ * use OneKey desktop client to update the firmware
234
+ * because need copy resource file to Touch
235
+ */
109
236
  readonly UseDesktopToUpdateFirmware: 413;
237
+ /**
238
+ * Mandatory firmware update
239
+ * @params:{ connectId: string? , deviceId: string? }
240
+ */
110
241
  readonly NewFirmwareForceUpdate: 414;
242
+ /**
243
+ * Device not support this method
244
+ */
111
245
  readonly DeviceNotSupportMethod: 415;
246
+ /**
247
+ * Forbidden key path
248
+ */
112
249
  readonly ForbiddenKeyPath: 416;
250
+ /**
251
+ * Repeat unlocking
252
+ * all network get address by loop need repeat unlocking
253
+ */
113
254
  readonly RepeatUnlocking: 417;
255
+ /**
256
+ * Defective firmware detected
257
+ */
114
258
  readonly DefectiveFirmware: 418;
259
+ /**
260
+ * Netword request error
261
+ */
115
262
  readonly NetworkError: 500;
263
+ /**
264
+ * Transport not configured
265
+ */
116
266
  readonly TransportNotConfigured: 600;
267
+ /**
268
+ * Transport call in progress
269
+ */
117
270
  readonly TransportCallInProgress: 601;
271
+ /**
272
+ * Transport not found
273
+ */
118
274
  readonly TransportNotFound: 602;
275
+ /**
276
+ * Transport invalid protobuf
277
+ */
119
278
  readonly TransportInvalidProtobuf: 603;
279
+ /**
280
+ * Bluetooth error code
281
+ */
120
282
  readonly BleScanError: 700;
121
283
  readonly BlePermissionError: 701;
122
284
  readonly BleLocationError: 702;
@@ -140,37 +302,143 @@ declare const HardwareErrorCode: {
140
302
  readonly BleDeviceDisconnected: 720;
141
303
  readonly BlePoweredOff: 721;
142
304
  readonly BleUnsupported: 722;
305
+ /**
306
+ * Hardware runtiome errors
307
+ */
143
308
  readonly RuntimeError: 800;
309
+ /**
310
+ * invalid pin
311
+ */
144
312
  readonly PinInvalid: 801;
313
+ /**
314
+ * pin cancelled by user
315
+ */
145
316
  readonly PinCancelled: 802;
317
+ /**
318
+ * Action cancelled by user
319
+ */
146
320
  readonly ActionCancelled: 803;
321
+ /**
322
+ * Firmware installation failed
323
+ */
147
324
  readonly FirmwareError: 804;
325
+ /**
326
+ * transport response unexpect error
327
+ */
148
328
  readonly ResponseUnexpectTypeError: 805;
329
+ /**
330
+ * bridge network error
331
+ */
149
332
  readonly BridgeNetworkError: 806;
333
+ /**
334
+ * Bridge network timeout
335
+ */
150
336
  readonly BridgeTimeoutError: 807;
337
+ /**
338
+ * Bridge not installed
339
+ */
151
340
  readonly BridgeNotInstalled: 808;
341
+ /**
342
+ * ensure connect timeout
343
+ */
152
344
  readonly PollingTimeout: 809;
345
+ /**
346
+ * ensure connect stop polling
347
+ */
153
348
  readonly PollingStop: 810;
349
+ /**
350
+ * Device does not open blid sign
351
+ */
154
352
  readonly BlindSignDisabled: 811;
155
353
  readonly UnexpectPassphrase: 812;
354
+ /**
355
+ * NFT file already exists
356
+ */
156
357
  readonly FileAlreadyExists: 813;
358
+ /**
359
+ * check file length error
360
+ */
157
361
  readonly CheckDownloadFileError: 814;
362
+ /**
363
+ * not in signing mode
364
+ */
158
365
  readonly NotInSigningMode: 815;
366
+ /**
367
+ * not in signing mode
368
+ */
159
369
  readonly DataOverload: 816;
370
+ /**
371
+ * device disconnected during action
372
+ */
160
373
  readonly BridgeDeviceDisconnected: 817;
374
+ /**
375
+ * BTC PSBT too many utxos
376
+ * @params:{ count: number }
377
+ */
161
378
  readonly BTCPsbtTooManyUtxos: 818;
379
+ /**
380
+ * EMMC file write firmware error
381
+ */
162
382
  readonly EmmcFileWriteFirmwareError: 819;
383
+ /**
384
+ * Firmware verification failed (e.g., bootloader file verify failed)
385
+ */
163
386
  readonly FirmwareVerificationFailed: 820;
387
+ /**
388
+ * Web bridge coonect needs permission
389
+ */
164
390
  readonly BridgeNeedsPermission: 821;
165
391
  readonly CallQueueActionCancelled: 822;
392
+ /**
393
+ * Firmware downgrade not allowed
394
+ */
166
395
  readonly FirmwareDowngradeNotAllowed: 823;
396
+ /**
397
+ * Cosmos invalid JSON message, Only support Amino msgs.
398
+ */
167
399
  readonly CosmosInvalidJsonMessage: 824;
400
+ /**
401
+ * No setting provided
402
+ */
168
403
  readonly DeviceSettingsNotProvided: 825;
404
+ /**
405
+ * Language not supported
406
+ */
169
407
  readonly DeviceSettingsLanguageNotSupport: 826;
408
+ /**
409
+ * Too many inputs
410
+ * @params: { count?: string }
411
+ */
170
412
  readonly TooManyInputs: 827;
413
+ /**
414
+ * The two PIN entries did not match while setting/changing PIN on device
415
+ */
171
416
  readonly PinMismatch: 828;
417
+ /**
418
+ * Device refused to sign: refTxs don't match the spent input's outpoint
419
+ */
420
+ readonly KaspaPrevTxIdMismatch: 829;
421
+ /**
422
+ * Protocol V2 device must be unlocked before the requested operation.
423
+ * @params: { failureCode?: string; subcode?: number; firmwareMessage?: string }
424
+ */
425
+ readonly DeviceLocked: 830;
426
+ /**
427
+ * The cached wallet session is invalid or has expired.
428
+ * @params: { failureCode?: string; subcode?: number; firmwareMessage?: string }
429
+ */
430
+ readonly WalletSessionInvalid: 831;
431
+ /**
432
+ * Lowlevel transport connect error
433
+ */
172
434
  readonly LowlevelTrasnportConnectError: 900;
435
+ /**
436
+ * Web USB or Web Bluetooth device not found or needs permission
437
+ */
173
438
  readonly WebDeviceNotFoundOrNeedsPermission: 901;
439
+ /**
440
+ * Web USB or Web Bluetooth device prompt access error
441
+ */
174
442
  readonly WebDevicePromptAccessError: 902;
175
443
  };
176
444
  declare const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping;
@@ -245,4 +513,4 @@ declare enum EDeviceType {
245
513
  Pro2 = "pro2"
246
514
  }
247
515
 
248
- export { CreateErrorByMessage, CreateHardwareErrorByBridgeError, Deferred, EDeviceType, EFirmwareType, EOneKeyBleMessageKeys, HardwareError$1 as ERRORS, ERROR_CODES_REQUIRE_DISCONNECT, ERROR_CODES_REQUIRE_RELEASE, HARDWARE_CONNECT_PROTOCOL, HardwareConnectProtocol, HardwareError, HardwareErrorCode, HardwareErrorCodeMessage, IHardwareError, ONEKEY_NOTIFY_CHARACTERISTIC_UUID, ONEKEY_SERVICE_UUID, ONEKEY_WEBUSB_FILTER, ONEKEY_WRITE_CHARACTERISTIC_UUID, TypedError, createDefectiveFirmwareError, createDeferred, createDeprecatedHardwareError, createDeviceNotSupportMethodError, createNeedUpgradeFirmwareHardwareError, createNewFirmwareForceUpdateHardwareError, createNewFirmwareUnReleaseHardwareError, isHeaderChunk, isOnekeyDevice, serializeError, wait };
516
+ 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 };
package/dist/index.js CHANGED
@@ -164,6 +164,9 @@ const HardwareErrorCode = {
164
164
  DeviceSettingsLanguageNotSupport: 826,
165
165
  TooManyInputs: 827,
166
166
  PinMismatch: 828,
167
+ KaspaPrevTxIdMismatch: 829,
168
+ DeviceLocked: 830,
169
+ WalletSessionInvalid: 831,
167
170
  LowlevelTrasnportConnectError: 900,
168
171
  WebDeviceNotFoundOrNeedsPermission: 901,
169
172
  WebDevicePromptAccessError: 902,
@@ -268,6 +271,9 @@ const HardwareErrorCodeMessage = {
268
271
  [HardwareErrorCode.DeviceSettingsLanguageNotSupport]: 'Language not supported',
269
272
  [HardwareErrorCode.TooManyInputs]: 'Too many inputs',
270
273
  [HardwareErrorCode.PinMismatch]: 'PIN mismatch',
274
+ [HardwareErrorCode.DeviceLocked]: 'Device locked',
275
+ [HardwareErrorCode.KaspaPrevTxIdMismatch]: 'Kaspa previous transaction id mismatch',
276
+ [HardwareErrorCode.WalletSessionInvalid]: 'Wallet session is invalid or expired',
271
277
  [HardwareErrorCode.LowlevelTrasnportConnectError]: 'Lowlevel transport connect error',
272
278
  [HardwareErrorCode.WebDeviceNotFoundOrNeedsPermission]: 'Web-USB or Web-Bluetooth device not found or needs permission',
273
279
  [HardwareErrorCode.WebDevicePromptAccessError]: 'Web-USB or Web-Bluetooth device prompt access error',
@@ -391,6 +397,15 @@ const ONEKEY_WEBUSB_FILTER = [
391
397
  { vendorId: 0x1209, productId: 0x4f4b },
392
398
  { vendorId: 0x1209, productId: 0x4f4c },
393
399
  ];
400
+ const TREZOR_WEBUSB_MANUFACTURER_NAMES = new Set(['trezor', 'trezor company', 'satoshilabs']);
401
+ const isKnownTrezorWebUsbDevice = (descriptor) => {
402
+ var _a;
403
+ const isSharedWebUsbId = ONEKEY_WEBUSB_FILTER.some(filter => descriptor.vendorId === filter.vendorId && descriptor.productId === filter.productId);
404
+ if (!isSharedWebUsbId)
405
+ return false;
406
+ const manufacturerName = (_a = descriptor.manufacturerName) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase();
407
+ return manufacturerName != null && TREZOR_WEBUSB_MANUFACTURER_NAMES.has(manufacturerName);
408
+ };
394
409
  const ERROR_CODES_REQUIRE_RELEASE = [
395
410
  HardwareErrorCode.DeviceInitializeFailed,
396
411
  HardwareErrorCode.DeviceInterruptedFromOutside,
@@ -446,16 +461,40 @@ const isHeaderChunk = (chunk) => {
446
461
  }
447
462
  return false;
448
463
  };
464
+ const isKnownNonOneKeyDeviceName = (normalizedName) => normalizedName.startsWith('trezor') ||
465
+ normalizedName.startsWith('ledger') ||
466
+ normalizedName.startsWith('nano ') ||
467
+ normalizedName.startsWith('stax') ||
468
+ normalizedName.startsWith('flex');
469
+ const ONEKEY_EXACT_SHORT_NAMES = new Set(['s8']);
470
+ const isOneKeyShortName = (normalizedName) => {
471
+ if (ONEKEY_EXACT_SHORT_NAMES.has(normalizedName))
472
+ return true;
473
+ if (normalizedName.length !== 5)
474
+ return false;
475
+ const firstChar = normalizedName[0];
476
+ return (firstChar === 'k' || firstChar === 't') && /^\d{4}$/.test(normalizedName.slice(1));
477
+ };
449
478
  const isOnekeyDevice = (name, id) => {
450
- var _a;
451
- if ((_a = id === null || id === void 0 ? void 0 : id.startsWith) === null || _a === void 0 ? void 0 : _a.call(id, 'MI')) {
479
+ var _a, _b;
480
+ const normalizedName = (_a = name === null || name === void 0 ? void 0 : name.trim().toLowerCase()) !== null && _a !== void 0 ? _a : '';
481
+ if (isKnownNonOneKeyDeviceName(normalizedName)) {
482
+ return false;
483
+ }
484
+ if ((_b = id === null || id === void 0 ? void 0 : id.startsWith) === null || _b === void 0 ? void 0 : _b.call(id, 'MI')) {
452
485
  return true;
453
486
  }
454
- const re = /(BixinKey\d{10})|(K\d{4})|(T\d{4})|(Touch\s\w{4})|(Pro\s\w{4})|(Pro\s*2)/i;
455
- if (name && re.exec(name)) {
487
+ if (!name) {
488
+ return false;
489
+ }
490
+ if (normalizedName.startsWith('onekey') || normalizedName.startsWith('bixinkey'))
491
+ return true;
492
+ if (normalizedName.startsWith('touch ') ||
493
+ normalizedName.startsWith('pro ') ||
494
+ normalizedName.startsWith('pro2 ')) {
456
495
  return true;
457
496
  }
458
- return false;
497
+ return isOneKeyShortName(normalizedName);
459
498
  };
460
499
 
461
500
  /******************************************************************************
@@ -553,6 +592,7 @@ exports.createNeedUpgradeFirmwareHardwareError = createNeedUpgradeFirmwareHardwa
553
592
  exports.createNewFirmwareForceUpdateHardwareError = createNewFirmwareForceUpdateHardwareError;
554
593
  exports.createNewFirmwareUnReleaseHardwareError = createNewFirmwareUnReleaseHardwareError;
555
594
  exports.isHeaderChunk = isHeaderChunk;
595
+ exports.isKnownTrezorWebUsbDevice = isKnownTrezorWebUsbDevice;
556
596
  exports.isOnekeyDevice = isOnekeyDevice;
557
597
  exports.serializeError = serializeError;
558
598
  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.3",
3
+ "version": "1.2.0-alpha.30",
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": "54a4a40baee7e376b9a810dade60007d2c9b00c9"
29
+ "gitHead": "07405d2e3dcdd0ba351ae98b7cf4f61690ef2913"
29
30
  }
@@ -0,0 +1,9 @@
1
+ import { HardwareErrorCode } from './HardwareError';
2
+
3
+ describe('HardwareErrorCode compatibility', () => {
4
+ test('preserves published values when adding Protocol V2 errors', () => {
5
+ expect(HardwareErrorCode.KaspaPrevTxIdMismatch).toBe(829);
6
+ expect(HardwareErrorCode.DeviceLocked).toBe(830);
7
+ expect(HardwareErrorCode.WalletSessionInvalid).toBe(831);
8
+ });
9
+ });
@@ -484,6 +484,23 @@ export const HardwareErrorCode = {
484
484
  */
485
485
  PinMismatch: 828,
486
486
 
487
+ /**
488
+ * Device refused to sign: refTxs don't match the spent input's outpoint
489
+ */
490
+ KaspaPrevTxIdMismatch: 829,
491
+
492
+ /**
493
+ * Protocol V2 device must be unlocked before the requested operation.
494
+ * @params: { failureCode?: string; subcode?: number; firmwareMessage?: string }
495
+ */
496
+ DeviceLocked: 830,
497
+
498
+ /**
499
+ * The cached wallet session is invalid or has expired.
500
+ * @params: { failureCode?: string; subcode?: number; firmwareMessage?: string }
501
+ */
502
+ WalletSessionInvalid: 831,
503
+
487
504
  /**
488
505
  * Lowlevel transport connect error
489
506
  */
@@ -635,6 +652,9 @@ export const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping = {
635
652
  [HardwareErrorCode.DeviceSettingsLanguageNotSupport]: 'Language not supported',
636
653
  [HardwareErrorCode.TooManyInputs]: 'Too many inputs',
637
654
  [HardwareErrorCode.PinMismatch]: 'PIN mismatch',
655
+ [HardwareErrorCode.DeviceLocked]: 'Device locked',
656
+ [HardwareErrorCode.KaspaPrevTxIdMismatch]: 'Kaspa previous transaction id mismatch',
657
+ [HardwareErrorCode.WalletSessionInvalid]: 'Wallet session is invalid or expired',
638
658
 
639
659
  /**
640
660
  * Lowlevel transport
@@ -0,0 +1,60 @@
1
+ import { isKnownTrezorWebUsbDevice, isOnekeyDevice } from './constants';
2
+
3
+ describe('hardware device identity filters', () => {
4
+ it('accepts known OneKey BLE names', () => {
5
+ expect(isOnekeyDevice('Touch A1B2')).toBe(true);
6
+ expect(isOnekeyDevice('Pro A1B2')).toBe(true);
7
+ expect(isOnekeyDevice('K1234')).toBe(true);
8
+ expect(isOnekeyDevice('S8')).toBe(true);
9
+ });
10
+
11
+ it('rejects known Trezor and Ledger BLE names from OneKey discovery', () => {
12
+ expect(isOnekeyDevice('Trezor Safe 7')).toBe(false);
13
+ expect(isOnekeyDevice('Ledger Nano X')).toBe(false);
14
+ });
15
+
16
+ it('only filters WebUSB descriptors that are explicitly identified as Trezor', () => {
17
+ expect(
18
+ isKnownTrezorWebUsbDevice({
19
+ vendorId: 0x1209,
20
+ productId: 0x53c1,
21
+ manufacturerName: 'Trezor Company',
22
+ })
23
+ ).toBe(true);
24
+ expect(
25
+ isKnownTrezorWebUsbDevice({
26
+ vendorId: 0x1209,
27
+ productId: 0x53c1,
28
+ manufacturerName: 'Trezor',
29
+ })
30
+ ).toBe(true);
31
+ expect(
32
+ isKnownTrezorWebUsbDevice({
33
+ vendorId: 0x1209,
34
+ productId: 0x53c1,
35
+ manufacturerName: 'SatoshiLabs',
36
+ })
37
+ ).toBe(true);
38
+
39
+ expect(
40
+ isKnownTrezorWebUsbDevice({
41
+ vendorId: 0x1209,
42
+ productId: 0x53c1,
43
+ manufacturerName: 'OneKey',
44
+ })
45
+ ).toBe(false);
46
+ expect(
47
+ isKnownTrezorWebUsbDevice({
48
+ vendorId: 0x1209,
49
+ productId: 0x53c1,
50
+ })
51
+ ).toBe(false);
52
+ expect(
53
+ isKnownTrezorWebUsbDevice({
54
+ vendorId: 0x1209,
55
+ productId: 0x53c1,
56
+ productName: 'Trezor Safe 7',
57
+ })
58
+ ).toBe(false);
59
+ });
60
+ });
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
@@ -97,16 +115,42 @@ export const isHeaderChunk = (chunk: Buffer | Uint8Array): boolean => {
97
115
  return false;
98
116
  };
99
117
 
118
+ const isKnownNonOneKeyDeviceName = (normalizedName: string): boolean =>
119
+ normalizedName.startsWith('trezor') ||
120
+ normalizedName.startsWith('ledger') ||
121
+ normalizedName.startsWith('nano ') ||
122
+ normalizedName.startsWith('stax') ||
123
+ normalizedName.startsWith('flex');
124
+
125
+ const ONEKEY_EXACT_SHORT_NAMES = new Set(['s8']);
126
+
127
+ const isOneKeyShortName = (normalizedName: string): boolean => {
128
+ if (ONEKEY_EXACT_SHORT_NAMES.has(normalizedName)) return true;
129
+ if (normalizedName.length !== 5) return false;
130
+ const firstChar = normalizedName[0];
131
+ return (firstChar === 'k' || firstChar === 't') && /^\d{4}$/.test(normalizedName.slice(1));
132
+ };
133
+
100
134
  export const isOnekeyDevice = (name: string | null, id?: string): boolean => {
135
+ const normalizedName = name?.trim().toLowerCase() ?? '';
136
+ if (isKnownNonOneKeyDeviceName(normalizedName)) {
137
+ return false;
138
+ }
139
+
101
140
  if (id?.startsWith?.('MI')) {
102
141
  return true;
103
142
  }
104
143
 
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)) {
144
+ if (!name) {
145
+ return false;
146
+ }
147
+ if (normalizedName.startsWith('onekey') || normalizedName.startsWith('bixinkey')) return true;
148
+ if (
149
+ normalizedName.startsWith('touch ') ||
150
+ normalizedName.startsWith('pro ') ||
151
+ normalizedName.startsWith('pro2 ')
152
+ ) {
109
153
  return true;
110
154
  }
111
- return false;
155
+ return isOneKeyShortName(normalizedName);
112
156
  };