@onekeyfe/hd-core 1.2.8 → 1.2.9

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.
Files changed (167) hide show
  1. package/README.md +27 -0
  2. package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +13 -4
  3. package/__tests__/DeviceCommands.test.ts +91 -13
  4. package/__tests__/allNetworkGetAddress-privacy-networks.test.ts +77 -0
  5. package/__tests__/allNetworkGetAddress-skippable.test.ts +49 -0
  6. package/__tests__/btc-derive-context-hash.test.ts +200 -0
  7. package/__tests__/core-dispose.test.ts +114 -1
  8. package/__tests__/core-error-output.test.ts +55 -3
  9. package/__tests__/device-connector-protocol.test.ts +5 -2
  10. package/__tests__/device-lifecycle-events.test.ts +191 -27
  11. package/__tests__/device-pool-state.test.ts +50 -0
  12. package/__tests__/firmware-update/firmware-artifact-source.test.ts +11 -0
  13. package/__tests__/logBlockEvent.test.ts +331 -9
  14. package/__tests__/logger.test.ts +18 -0
  15. package/__tests__/monero-get-address.test.ts +147 -0
  16. package/__tests__/monero-key-image-sync.test.ts +272 -0
  17. package/__tests__/monero-sign-transaction.test.ts +436 -0
  18. package/__tests__/protocol-v2-bootloader-mode.test.ts +43 -2
  19. package/__tests__/protocol-v2-key-export-confirmation.test.ts +75 -0
  20. package/__tests__/protocol-v2-resources.test.ts +14 -0
  21. package/__tests__/protocol-v2.test.ts +841 -46
  22. package/__tests__/protocolV2FileWrite.test.ts +454 -7
  23. package/__tests__/refresh-device-state.test.ts +19 -17
  24. package/__tests__/search-devices.test.ts +36 -0
  25. package/__tests__/sol-sign-offchain-message.test.ts +8 -0
  26. package/__tests__/usb-identity-probe.test.ts +358 -0
  27. package/__tests__/zcash-protobuf.test.ts +152 -0
  28. package/__tests__/zcash-sign-pczt.test.ts +525 -0
  29. package/dist/api/BaseMethod.d.ts.map +1 -1
  30. package/dist/api/FileWrite.d.ts.map +1 -1
  31. package/dist/api/FirmwareUpdateV4.d.ts +5 -0
  32. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  33. package/dist/api/GetDeviceState.d.ts.map +1 -1
  34. package/dist/api/SearchDevices.d.ts +21 -1
  35. package/dist/api/SearchDevices.d.ts.map +1 -1
  36. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts +3 -0
  37. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  38. package/dist/api/btc/BTCDeriveContextHash.d.ts +16 -0
  39. package/dist/api/btc/BTCDeriveContextHash.d.ts.map +1 -0
  40. package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -1
  41. package/dist/api/helpers/pathUtils.d.ts +1 -0
  42. package/dist/api/helpers/pathUtils.d.ts.map +1 -1
  43. package/dist/api/helpers/protocolV2FileWrite.d.ts +5 -1
  44. package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
  45. package/dist/api/index.d.ts +8 -0
  46. package/dist/api/index.d.ts.map +1 -1
  47. package/dist/api/monero/MoneroGetAddress.d.ts +11 -0
  48. package/dist/api/monero/MoneroGetAddress.d.ts.map +1 -0
  49. package/dist/api/monero/MoneroGetWatchKey.d.ts +11 -0
  50. package/dist/api/monero/MoneroGetWatchKey.d.ts.map +1 -0
  51. package/dist/api/monero/MoneroKeyImageSync.d.ts +20 -0
  52. package/dist/api/monero/MoneroKeyImageSync.d.ts.map +1 -0
  53. package/dist/api/monero/MoneroSignTransaction.d.ts +17 -0
  54. package/dist/api/monero/MoneroSignTransaction.d.ts.map +1 -0
  55. package/dist/api/monero/helpers.d.ts +5 -0
  56. package/dist/api/monero/helpers.d.ts.map +1 -0
  57. package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -1
  58. package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -1
  59. package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
  60. package/dist/api/zcash/ZcashGetAddress.d.ts +12 -0
  61. package/dist/api/zcash/ZcashGetAddress.d.ts.map +1 -0
  62. package/dist/api/zcash/ZcashGetFullViewingKey.d.ts +12 -0
  63. package/dist/api/zcash/ZcashGetFullViewingKey.d.ts.map +1 -0
  64. package/dist/api/zcash/ZcashSignPczt.d.ts +16 -0
  65. package/dist/api/zcash/ZcashSignPczt.d.ts.map +1 -0
  66. package/dist/api/zcash/helpers.d.ts +2 -0
  67. package/dist/api/zcash/helpers.d.ts.map +1 -0
  68. package/dist/core/index.d.ts +3 -2
  69. package/dist/core/index.d.ts.map +1 -1
  70. package/dist/device/Device.d.ts +3 -0
  71. package/dist/device/Device.d.ts.map +1 -1
  72. package/dist/device/DeviceCommands.d.ts +4 -4
  73. package/dist/device/DeviceCommands.d.ts.map +1 -1
  74. package/dist/device/DevicePool.d.ts.map +1 -1
  75. package/dist/events/logBlockEvent.d.ts +10 -0
  76. package/dist/events/logBlockEvent.d.ts.map +1 -1
  77. package/dist/events/ui-request.d.ts +2 -0
  78. package/dist/events/ui-request.d.ts.map +1 -1
  79. package/dist/index.d.ts +206 -7
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +4456 -2801
  82. package/dist/inject.d.ts.map +1 -1
  83. package/dist/protocols/protocol-v2/resources.d.ts +1 -0
  84. package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
  85. package/dist/protocols/protocol-v2/uiInteraction.d.ts +1 -0
  86. package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
  87. package/dist/types/api/allNetworkGetAddress.d.ts +4 -1
  88. package/dist/types/api/allNetworkGetAddress.d.ts.map +1 -1
  89. package/dist/types/api/btcDeriveContextHash.d.ts +10 -0
  90. package/dist/types/api/btcDeriveContextHash.d.ts.map +1 -0
  91. package/dist/types/api/export.d.ts +8 -0
  92. package/dist/types/api/export.d.ts.map +1 -1
  93. package/dist/types/api/index.d.ts +16 -0
  94. package/dist/types/api/index.d.ts.map +1 -1
  95. package/dist/types/api/moneroGetAddress.d.ts +15 -0
  96. package/dist/types/api/moneroGetAddress.d.ts.map +1 -0
  97. package/dist/types/api/moneroGetWatchKey.d.ts +15 -0
  98. package/dist/types/api/moneroGetWatchKey.d.ts.map +1 -0
  99. package/dist/types/api/moneroKeyImageSync.d.ts +24 -0
  100. package/dist/types/api/moneroKeyImageSync.d.ts.map +1 -0
  101. package/dist/types/api/moneroSignTransaction.d.ts +32 -0
  102. package/dist/types/api/moneroSignTransaction.d.ts.map +1 -0
  103. package/dist/types/api/zcashGetAddress.d.ts +20 -0
  104. package/dist/types/api/zcashGetAddress.d.ts.map +1 -0
  105. package/dist/types/api/zcashGetFullViewingKey.d.ts +13 -0
  106. package/dist/types/api/zcashGetFullViewingKey.d.ts.map +1 -0
  107. package/dist/types/api/zcashSignPczt.d.ts +9 -0
  108. package/dist/types/api/zcashSignPczt.d.ts.map +1 -0
  109. package/dist/types/device.d.ts +10 -0
  110. package/dist/types/device.d.ts.map +1 -1
  111. package/dist/types/params.d.ts +1 -0
  112. package/dist/types/params.d.ts.map +1 -1
  113. package/dist/utils/logger.d.ts.map +1 -1
  114. package/dist/utils/patch.d.ts +1 -1
  115. package/dist/utils/patch.d.ts.map +1 -1
  116. package/package.json +4 -4
  117. package/src/api/BaseMethod.ts +2 -0
  118. package/src/api/FileWrite.ts +7 -1
  119. package/src/api/FirmwareUpdateV4.ts +366 -99
  120. package/src/api/GetDeviceState.ts +2 -5
  121. package/src/api/SearchDevices.ts +172 -7
  122. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +55 -15
  123. package/src/api/btc/BTCDeriveContextHash.ts +90 -0
  124. package/src/api/firmware/FirmwareArtifactSource.ts +12 -3
  125. package/src/api/helpers/pathUtils.ts +23 -0
  126. package/src/api/helpers/protocolV2FileWrite.ts +382 -111
  127. package/src/api/index.ts +9 -0
  128. package/src/api/monero/MoneroGetAddress.ts +71 -0
  129. package/src/api/monero/MoneroGetWatchKey.ts +75 -0
  130. package/src/api/monero/MoneroKeyImageSync.ts +170 -0
  131. package/src/api/monero/MoneroSignTransaction.ts +319 -0
  132. package/src/api/monero/helpers.ts +28 -0
  133. package/src/api/protocol-v2/DeviceReboot.ts +2 -0
  134. package/src/api/protocol-v2/DeviceUploadNft.ts +6 -1
  135. package/src/api/protocol-v2/DeviceUploadWallpaper.ts +15 -1
  136. package/src/api/zcash/ZcashGetAddress.ts +108 -0
  137. package/src/api/zcash/ZcashGetFullViewingKey.ts +78 -0
  138. package/src/api/zcash/ZcashSignPczt.ts +152 -0
  139. package/src/api/zcash/helpers.ts +16 -0
  140. package/src/core/index.ts +52 -24
  141. package/src/data/messages/messages-protocol-v2.json +152 -0
  142. package/src/data/messages/messages.json +51 -0
  143. package/src/device/Device.ts +32 -4
  144. package/src/device/DeviceCommands.ts +32 -1
  145. package/src/device/DeviceConnector.ts +4 -4
  146. package/src/device/DevicePool.ts +12 -2
  147. package/src/events/core.ts +2 -2
  148. package/src/events/logBlockEvent.ts +58 -3
  149. package/src/events/ui-request.ts +2 -0
  150. package/src/index.ts +1 -0
  151. package/src/inject.ts +17 -0
  152. package/src/protocols/protocol-v2/resources.ts +6 -1
  153. package/src/protocols/protocol-v2/uiInteraction.ts +1 -1
  154. package/src/types/api/allNetworkGetAddress.ts +8 -1
  155. package/src/types/api/btcDeriveContextHash.ts +15 -0
  156. package/src/types/api/export.ts +17 -0
  157. package/src/types/api/index.ts +24 -0
  158. package/src/types/api/moneroGetAddress.ts +27 -0
  159. package/src/types/api/moneroGetWatchKey.ts +28 -0
  160. package/src/types/api/moneroKeyImageSync.ts +45 -0
  161. package/src/types/api/moneroSignTransaction.ts +54 -0
  162. package/src/types/api/zcashGetAddress.ts +32 -0
  163. package/src/types/api/zcashGetFullViewingKey.ts +24 -0
  164. package/src/types/api/zcashSignPczt.ts +18 -0
  165. package/src/types/device.ts +18 -0
  166. package/src/types/params.ts +1 -1
  167. package/src/utils/logger.ts +4 -0
@@ -11034,6 +11034,149 @@
11034
11034
  }
11035
11035
  }
11036
11036
  },
11037
+ "ZcashAddressType": {
11038
+ "values": {
11039
+ "UNIFIED_ORCHARD_P2PKH": 0,
11040
+ "TRANSPARENT_P2PKH": 1,
11041
+ "UNIFIED_ORCHARD": 2
11042
+ }
11043
+ },
11044
+ "ZcashAddressScope": {
11045
+ "values": {
11046
+ "EXTERNAL": 0,
11047
+ "INTERNAL": 1
11048
+ }
11049
+ },
11050
+ "ZcashGetAddress": {
11051
+ "fields": {
11052
+ "address_n": {
11053
+ "rule": "repeated",
11054
+ "type": "uint32",
11055
+ "id": 1,
11056
+ "options": {
11057
+ "packed": false
11058
+ }
11059
+ },
11060
+ "show_display": {
11061
+ "type": "bool",
11062
+ "id": 2
11063
+ },
11064
+ "include_seed_fingerprint": {
11065
+ "type": "bool",
11066
+ "id": 3
11067
+ },
11068
+ "diversifier_index": {
11069
+ "type": "uint32",
11070
+ "id": 5,
11071
+ "options": {
11072
+ "default": 0
11073
+ }
11074
+ },
11075
+ "address_type": {
11076
+ "type": "ZcashAddressType",
11077
+ "id": 6,
11078
+ "options": {
11079
+ "default": "UNIFIED_ORCHARD_P2PKH"
11080
+ }
11081
+ },
11082
+ "scope": {
11083
+ "type": "ZcashAddressScope",
11084
+ "id": 7,
11085
+ "options": {
11086
+ "default": "EXTERNAL"
11087
+ }
11088
+ }
11089
+ }
11090
+ },
11091
+ "ZcashAddress": {
11092
+ "fields": {
11093
+ "address": {
11094
+ "rule": "required",
11095
+ "type": "string",
11096
+ "id": 1
11097
+ },
11098
+ "seed_fingerprint": {
11099
+ "type": "bytes",
11100
+ "id": 3
11101
+ }
11102
+ }
11103
+ },
11104
+ "ZcashGetFullViewingKey": {
11105
+ "fields": {
11106
+ "address_n": {
11107
+ "rule": "repeated",
11108
+ "type": "uint32",
11109
+ "id": 1,
11110
+ "options": {
11111
+ "packed": false
11112
+ }
11113
+ }
11114
+ }
11115
+ },
11116
+ "ZcashFullViewingKey": {
11117
+ "fields": {
11118
+ "ufvk": {
11119
+ "rule": "required",
11120
+ "type": "string",
11121
+ "id": 1
11122
+ }
11123
+ }
11124
+ },
11125
+ "ZcashSignPczt": {
11126
+ "fields": {
11127
+ "pczt_length": {
11128
+ "rule": "required",
11129
+ "type": "uint32",
11130
+ "id": 1
11131
+ },
11132
+ "pczt_initial_chunk": {
11133
+ "rule": "required",
11134
+ "type": "bytes",
11135
+ "id": 2
11136
+ }
11137
+ }
11138
+ },
11139
+ "ZcashPcztChunkRequest": {
11140
+ "fields": {
11141
+ "chunk_length": {
11142
+ "rule": "required",
11143
+ "type": "uint32",
11144
+ "id": 1
11145
+ }
11146
+ }
11147
+ },
11148
+ "ZcashPcztChunkAck": {
11149
+ "fields": {
11150
+ "data_chunk": {
11151
+ "rule": "required",
11152
+ "type": "bytes",
11153
+ "id": 1
11154
+ }
11155
+ }
11156
+ },
11157
+ "ZcashSignedPczt": {
11158
+ "fields": {
11159
+ "pczt_length": {
11160
+ "rule": "required",
11161
+ "type": "uint32",
11162
+ "id": 1
11163
+ },
11164
+ "pczt_initial_chunk": {
11165
+ "rule": "required",
11166
+ "type": "bytes",
11167
+ "id": 2
11168
+ }
11169
+ }
11170
+ },
11171
+ "ZcashSignedPcztChunkRequest": {
11172
+ "fields": {
11173
+ "chunk_length": {
11174
+ "rule": "required",
11175
+ "type": "uint32",
11176
+ "id": 1
11177
+ }
11178
+ }
11179
+ },
11037
11180
  "wire_in": {
11038
11181
  "type": "bool",
11039
11182
  "id": 50002,
@@ -11459,6 +11602,15 @@
11459
11602
  "MessageType_NeoAddress": 12302,
11460
11603
  "MessageType_NeoSignTx": 12303,
11461
11604
  "MessageType_NeoSignedTx": 12304,
11605
+ "MessageType_ZcashGetAddress": 12400,
11606
+ "MessageType_ZcashAddress": 12401,
11607
+ "MessageType_ZcashSignPczt": 12402,
11608
+ "MessageType_ZcashSignedPczt": 12403,
11609
+ "MessageType_ZcashPcztChunkRequest": 12404,
11610
+ "MessageType_ZcashPcztChunkAck": 12405,
11611
+ "MessageType_ZcashSignedPcztChunkRequest": 12406,
11612
+ "MessageType_ZcashGetFullViewingKey": 12407,
11613
+ "MessageType_ZcashFullViewingKey": 12408,
11462
11614
  "MessageType_DeviceFactoryInfoSet": 60000,
11463
11615
  "MessageType_DeviceFactoryInfoGet": 60001,
11464
11616
  "MessageType_DeviceFactoryInfo": 60002,
@@ -12485,6 +12485,8 @@
12485
12485
  "(has_bitcoin_only_values)": true
12486
12486
  },
12487
12487
  "values": {
12488
+ "MessageType_BabylonDeriveContextHash": 10054,
12489
+ "MessageType_BabylonDerivedContextHash": 10055,
12488
12490
  "MessageType_Initialize": 0,
12489
12491
  "MessageType_Ping": 1,
12490
12492
  "MessageType_Success": 2,
@@ -12949,6 +12951,55 @@
12949
12951
  "MessageType_UpgradeFileHeader": 10050
12950
12952
  }
12951
12953
  },
12954
+ "CanonicalBitcoinNetwork": {
12955
+ "values": {
12956
+ "BITCOIN_MAINNET": 0,
12957
+ "BITCOIN_TESTNET": 1,
12958
+ "BITCOIN_SIGNET": 2,
12959
+ "BITCOIN_REGTEST": 3
12960
+ }
12961
+ },
12962
+ "BabylonDeriveContextHash": {
12963
+ "fields": {
12964
+ "address_n": {
12965
+ "rule": "repeated",
12966
+ "type": "uint32",
12967
+ "id": 1,
12968
+ "options": {
12969
+ "packed": false
12970
+ }
12971
+ },
12972
+ "script_type": {
12973
+ "rule": "required",
12974
+ "type": "InputScriptType",
12975
+ "id": 2
12976
+ },
12977
+ "app_name": {
12978
+ "rule": "required",
12979
+ "type": "bytes",
12980
+ "id": 3
12981
+ },
12982
+ "context": {
12983
+ "rule": "required",
12984
+ "type": "bytes",
12985
+ "id": 4
12986
+ },
12987
+ "network": {
12988
+ "rule": "required",
12989
+ "type": "CanonicalBitcoinNetwork",
12990
+ "id": 5
12991
+ }
12992
+ }
12993
+ },
12994
+ "BabylonDerivedContextHash": {
12995
+ "fields": {
12996
+ "secret": {
12997
+ "rule": "required",
12998
+ "type": "bytes",
12999
+ "id": 1
13000
+ }
13001
+ }
13002
+ },
12952
13003
  "google": {
12953
13004
  "nested": {
12954
13005
  "protobuf": {
@@ -236,6 +236,9 @@ export class Device extends EventEmitter {
236
236
  */
237
237
  private deviceAcquired = false;
238
238
 
239
+ /** A completed BLE release left the physical link available for the next call. */
240
+ private releasedBleConnection = false;
241
+
239
242
  /**
240
243
  * Connection-attempt generation. interruptionFromUser() pins the current
241
244
  * attempt so a late acquire cannot finish, while the next public connect
@@ -248,6 +251,9 @@ export class Device extends EventEmitter {
248
251
  /** Canonical device-state cache; legacy Features is a compatibility projection. */
249
252
  private stateStore = new DeviceStateStore();
250
253
 
254
+ /** Retain the old public identity only for disconnect notifications after wipe. */
255
+ private deviceBeforeWipe: DeviceTyped | null = null;
256
+
251
257
  /** Force the next initialization to reload DeviceInfo after reconnect or reboot. */
252
258
  private protocolV2StateNeedsReload = false;
253
259
 
@@ -351,6 +357,8 @@ export class Device extends EventEmitter {
351
357
  toMessageObject(): DeviceTyped | null {
352
358
  if (this.isUnacquired() || !this.features) return null;
353
359
 
360
+ this.deviceBeforeWipe = null;
361
+
354
362
  const env = DataManager.getSettings('env');
355
363
  const deviceType = this.getCurrentDeviceType();
356
364
 
@@ -395,6 +403,10 @@ export class Device extends EventEmitter {
395
403
  };
396
404
  }
397
405
 
406
+ toDisconnectMessageObject(): DeviceTyped | null {
407
+ return this.toMessageObject() ?? this.deviceBeforeWipe;
408
+ }
409
+
398
410
  /**
399
411
  * Device connect
400
412
  * @returns {Promise<boolean>}
@@ -443,6 +455,7 @@ export class Device extends EventEmitter {
443
455
  ) {
444
456
  const attempt = this.connectionAttempt;
445
457
  this.throwIfInterruptedByUser();
458
+ this.releasedBleConnection = false;
446
459
  const env = DataManager.getSettings('env');
447
460
  const mainIdKey = DataManager.isBleConnect(env) ? 'id' : 'session';
448
461
  const previousProtocol = this.originalDescriptor.protocolType;
@@ -553,6 +566,7 @@ export class Device extends EventEmitter {
553
566
  (this.isUsedHere() && !this.keepSession && this.mainId) ||
554
567
  (this.mainId && DataManager.isBleConnect(env))
555
568
  ) {
569
+ this.releasedBleConnection = false;
556
570
  // wait for callback tasks to complete before releasing device
557
571
  if (this.pendingCallbackPromise) {
558
572
  try {
@@ -576,12 +590,24 @@ export class Device extends EventEmitter {
576
590
  }
577
591
  }
578
592
  try {
593
+ const deviceType = this.getCurrentDeviceType();
594
+ const keepBleConnection =
595
+ (env === 'react-native' || env === 'desktop-web-ble') &&
596
+ this.isProtocolV2() &&
597
+ (deviceType === EDeviceType.Pro2 || deviceType === EDeviceType.Neo);
579
598
  // BLE releases even when keepSession is set, so forward the intent.
580
- await this.deviceConnector?.release(this.mainId, false, this.keepSession);
581
- this.updateDescriptor({ session: null } as DeviceDescriptor);
599
+ await this.deviceConnector?.release(
600
+ this.mainId,
601
+ false,
602
+ this.keepSession || keepBleConnection
603
+ );
604
+ this.releasedBleConnection = keepBleConnection;
582
605
  } catch (err) {
583
606
  Log.error('[Device] release error: ', err);
584
607
  } finally {
608
+ // Core no longer owns a logical transport session after release starts,
609
+ // even if native cleanup must be retried by the transport.
610
+ this.updateDescriptor({ session: null } as DeviceDescriptor);
585
611
  this.needReloadDevice = true;
586
612
  }
587
613
  }
@@ -1360,10 +1386,12 @@ export class Device extends EventEmitter {
1360
1386
 
1361
1387
  markTransportDisconnected() {
1362
1388
  this.deviceAcquired = false;
1389
+ this.releasedBleConnection = false;
1363
1390
  this.invalidateProtocolV2RuntimeState();
1364
1391
  }
1365
1392
 
1366
1393
  invalidateAfterWipe() {
1394
+ this.deviceBeforeWipe = this.toMessageObject() ?? this.deviceBeforeWipe;
1367
1395
  const deviceId = this.getCurrentDeviceId();
1368
1396
  if (deviceId) {
1369
1397
  deviceWalletSessionStore.deleteDevice(deviceId);
@@ -1621,7 +1649,7 @@ export class Device extends EventEmitter {
1621
1649
  await commands?.cancelDevice?.().catch(cancelError => {
1622
1650
  Log.debug('Protocol V2 fallback cancel error', cancelError);
1623
1651
  });
1624
- } else if (!acquired) {
1652
+ } else if (!acquired && !this.releasedBleConnection) {
1625
1653
  // Abort setup without acquiring a session just to send Cancel.
1626
1654
  if (mainId && deviceConnector?.disconnect) {
1627
1655
  // The connector drops the link silently, so without this line a
@@ -1801,7 +1829,7 @@ export class Device extends EventEmitter {
1801
1829
  // both allow and require cases might generate single unexpected mode
1802
1830
  if (!this.isUnacquired()) {
1803
1831
  // allow cases
1804
- if (this.isBootloader() && !this.isProtocolV2() && !allow.includes(UI_REQUEST.BOOTLOADER)) {
1832
+ if ((this.isBootloader() || this.isRomloader()) && !allow.includes(UI_REQUEST.BOOTLOADER)) {
1805
1833
  return UI_REQUEST.BOOTLOADER;
1806
1834
  }
1807
1835
  if (!this.isInitialized() && !allow.includes(UI_REQUEST.NOT_INITIALIZE)) {
@@ -66,6 +66,15 @@ const DEVICE_CONTROL_CALLS = new Set([
66
66
  'DeviceMiscUsbMscControl',
67
67
  ]);
68
68
 
69
+ // Paths the firmware can never derive, whatever the safety checks say. Lowercase: matched
70
+ // case-insensitively, as firmware wording varies.
71
+ const UNSUPPORTED_PATH_FAILURES = [
72
+ // Ed25519 derives hardened levels only (Touch, Pro), e.g. Monero's Cake path m/44'/128'/x'/0/0.
73
+ 'non-hardened paths unsupported on ed25519',
74
+ // Classic 1S refuses paths off a chain's fixed pattern.
75
+ 'invalid path',
76
+ ];
77
+
69
78
  // Older Protocol V2 firmware may omit the cancellation subcode, so retain a
70
79
  // narrow message fallback for compatibility.
71
80
  const isProtocolV2ActionCancelledMessage = (message: string) =>
@@ -534,6 +543,14 @@ export class DeviceCommands {
534
543
  count: detailMatch?.[1],
535
544
  });
536
545
  }
546
+ const lowerMessage = message?.toLowerCase() ?? '';
547
+ // Strict safety checks refuse a path outside the chain's standard ones.
548
+ if (lowerMessage.includes('forbidden key path')) {
549
+ error = ERRORS.TypedError(HardwareErrorCode.ForbiddenKeyPath, message);
550
+ }
551
+ if (UNSUPPORTED_PATH_FAILURES.some(text => lowerMessage.includes(text))) {
552
+ error = ERRORS.TypedError(HardwareErrorCode.DeviceNotSupportPath, message);
553
+ }
537
554
  }
538
555
 
539
556
  if (isProtocolV2LinkDisabledFailure(code, message)) {
@@ -549,6 +566,16 @@ export class DeviceCommands {
549
566
  this.device.isProtocolV2() &&
550
567
  DEVICE_CONTROL_CALLS.has(callType) &&
551
568
  subcode === DeviceErrorCode.DeviceError_Busy;
569
+ const isProtocolV2PinCancelledBusyFailure =
570
+ this.device.isProtocolV2() &&
571
+ !DEVICE_SESSION_CALLS.has(callType) &&
572
+ subcode === DeviceSessionErrorCode.DeviceSessionError_UserCancelled &&
573
+ /^pin cancelled$/i.test(normalizedMessage);
574
+ const isProtocolV2FirmwareUpdateBusyFailure =
575
+ this.device.isProtocolV2() &&
576
+ /^requested command not allowed while a firmware update is in progress$/i.test(
577
+ normalizedMessage
578
+ );
552
579
  const isLegacyProtocolV2LockedFailure =
553
580
  this.device.isProtocolV2() && /^device (?:is )?locked$/i.test(normalizedMessage);
554
581
  if (
@@ -606,7 +633,11 @@ export class DeviceCommands {
606
633
  subcode,
607
634
  firmwareMessage: message,
608
635
  });
609
- } else if (isProtocolV2DeviceBusyFailure) {
636
+ } else if (
637
+ isProtocolV2DeviceBusyFailure ||
638
+ isProtocolV2PinCancelledBusyFailure ||
639
+ isProtocolV2FirmwareUpdateBusyFailure
640
+ ) {
610
641
  error = ERRORS.TypedError(HardwareErrorCode.DeviceBusy, message, {
611
642
  failureCode: code,
612
643
  subcode,
@@ -133,10 +133,10 @@ export default class DeviceConnector {
133
133
  : undefined;
134
134
  const detectedProtocol = acquiredProtocol ?? transport.getProtocolType(path);
135
135
  if (detectedProtocol !== expectedProtocol) {
136
- throw ERRORS.TypedError(
137
- HardwareErrorCode.RuntimeError,
138
- `Device protocol mismatch: expected ${expectedProtocol}, detected ${detectedProtocol}`
139
- );
136
+ throw ERRORS.TypedError(HardwareErrorCode.TransportProtocolMismatch, undefined, {
137
+ expectedProtocol,
138
+ detectedProtocol,
139
+ });
140
140
  }
141
141
  }
142
142
  return res;
@@ -114,7 +114,11 @@ export class DevicePool extends EventEmitter {
114
114
  const exist = canPathIdentifyDevice(cachedPath)
115
115
  ? descriptorList.find(d => d.path === cachedPath)
116
116
  : undefined;
117
- if (exist && !initOptions?.forceProtocolDetection) {
117
+ if (
118
+ exist &&
119
+ !initOptions?.forceProtocolDetection &&
120
+ !(device.needReloadDevice && device.isUnacquired())
121
+ ) {
118
122
  // Log.debug('find existed Device: ', connectId);
119
123
  device.updateDescriptor(exist, true);
120
124
  await this._refreshRuntimeState(device, initOptions);
@@ -170,7 +174,13 @@ export class DevicePool extends EventEmitter {
170
174
  const forceProtocolDetection = initOptions?.forceProtocolDetection === true;
171
175
  const isNewDevice = !cachedDevice;
172
176
  const device = cachedDevice ?? Device.fromDescriptor(descriptor);
173
- if (isNewDevice || forceProtocolDetection) {
177
+ if (
178
+ isNewDevice ||
179
+ forceProtocolDetection ||
180
+ (device.needReloadDevice && device.isUnacquired())
181
+ ) {
182
+ // Wipe invalidates state while the same USB path can remain discoverable.
183
+ if (cachedDevice) device.updateDescriptor(descriptor, true);
174
184
  device.deviceConnector = this.connector;
175
185
  // Search/discovery acquires outside Device.run(). Start a new attempt so
176
186
  // a previous user cancel does not hide this device from later searches.
@@ -54,9 +54,9 @@ export const parseMessage = (messageData: any): CoreMessage => {
54
54
  };
55
55
 
56
56
  export const createErrorMessage = (error: Error & { code?: string | number }): Unsuccessful => {
57
- let payload = { error: error.message, code: error.code };
57
+ let payload: Unsuccessful['payload'] = { error: error.message, code: error.code };
58
58
  if (error instanceof HardwareError) {
59
- payload = { error: error.message, code: error.errorCode };
59
+ payload = { error: error.message, code: error.errorCode, params: error.params };
60
60
  }
61
61
  return {
62
62
  success: false,
@@ -8,14 +8,23 @@ export const LogBlockEvent: Set<string> = new Set([
8
8
  UI_RESPONSE.RECEIVE_PASSPHRASE,
9
9
  ]);
10
10
 
11
- // These resource/file APIs did not exist in 1.1.32. Skip the payload so
12
- // the log layer does not copy huge Base64 or binary data.
11
+ // Drop sensitive wallet payloads and large resource data before logger caches
12
+ // or log events can retain them, regardless of whether debug output is enabled.
13
13
  const LogPayloadBlockMethod: Set<string> = new Set([
14
+ 'btcDeriveContextHash',
15
+ 'btcSignMessage',
14
16
  'deviceUploadNft',
15
17
  'deviceUploadWallpaper',
16
18
  'uploadPortfolio',
17
19
  'fileWrite',
18
20
  'fileRead',
21
+ 'zcashGetAddress',
22
+ 'zcashGetFullViewingKey',
23
+ 'zcashSignPczt',
24
+ 'moneroGetAddress',
25
+ 'moneroGetWatchKey',
26
+ 'moneroKeyImageSync',
27
+ 'moneroSignTransaction',
19
28
  ]);
20
29
 
21
30
  export function getLogBlockLabel(message: unknown): string | undefined {
@@ -39,11 +48,57 @@ export function getLogBlockLabel(message: unknown): string | undefined {
39
48
  return undefined;
40
49
  }
41
50
 
51
+ // All-network results of these networks carry what their own address methods
52
+ // keep out of logs (viewing keys, private addresses).
53
+ const LogPayloadBlockNetwork: Set<string> = new Set(['zcash', 'xmr']);
54
+
55
+ type AllNetworkLogItem = { network?: string; success?: boolean; payload?: object | string } | null;
56
+
57
+ // A call response lists the results in `payload`; a loop callback carries one
58
+ // result, or all of them when finished, in `payload.data`.
59
+ type AllNetworkLogMessage = {
60
+ payload?: AllNetworkLogItem[] | { data?: AllNetworkLogItem | AllNetworkLogItem[] };
61
+ };
62
+
63
+ function redactAllNetworkItem(item: AllNetworkLogItem): AllNetworkLogItem {
64
+ if (!item || item.success === false || item.payload === undefined) return item;
65
+ return item.network && LogPayloadBlockNetwork.has(item.network)
66
+ ? { ...item, payload: '[REDACTED]' }
67
+ : item;
68
+ }
69
+
70
+ function redactAllNetworkItems(items: AllNetworkLogItem[]) {
71
+ const redacted = items.map(redactAllNetworkItem);
72
+ return redacted.some((item, index) => item !== items[index]) ? redacted : items;
73
+ }
74
+
75
+ // Returns `message` itself when nothing needs redacting.
76
+ function redactAllNetworkResults(message: AllNetworkLogMessage): AllNetworkLogMessage {
77
+ const { payload } = message;
78
+ if (Array.isArray(payload)) {
79
+ const items = redactAllNetworkItems(payload);
80
+ return items === payload ? message : { ...message, payload: items };
81
+ }
82
+ const data = payload?.data;
83
+ if (!data) return message;
84
+ const redacted = Array.isArray(data) ? redactAllNetworkItems(data) : redactAllNetworkItem(data);
85
+ return redacted === data ? message : { ...message, payload: { ...payload, data: redacted } };
86
+ }
87
+
42
88
  export function getSafeLogPayload(value: unknown, blockLabel?: string): unknown {
43
89
  if (blockLabel) {
44
90
  return { method: blockLabel, payload: '[REDACTED]' };
45
91
  }
46
- return value;
92
+ if (!value || typeof value !== 'object') return value;
93
+ return redactAllNetworkResults(value as AllNetworkLogMessage);
94
+ }
95
+
96
+ // A queued task holds its method's raw payload; redact it like the call.
97
+ export function getSafeLogTask<T extends { id?: number; method?: { payload?: unknown } }>(
98
+ task: T | undefined
99
+ ): T | { id?: number; method: string; payload: string } | undefined {
100
+ const blockLabel = getLogBlockLabel(task?.method?.payload);
101
+ return blockLabel ? { id: task?.id, method: blockLabel, payload: '[REDACTED]' } : task;
47
102
  }
48
103
 
49
104
  export function formatLogMethodLabel(label: string, methodName?: string): string {
@@ -211,6 +211,7 @@ export interface DeviceProgress {
211
211
  totalBytes?: number;
212
212
  rateBytesPerSecond?: number;
213
213
  elapsedMs?: number;
214
+ retryCount?: number;
214
215
  };
215
216
  }
216
217
 
@@ -218,6 +219,7 @@ export interface PreviousAddressResult {
218
219
  type: typeof UI_REQUEST.PREVIOUS_ADDRESS_RESULT;
219
220
  payload: {
220
221
  device: Device;
222
+ method: string;
221
223
  data: {
222
224
  address?: string;
223
225
  path?: string;
package/src/index.ts CHANGED
@@ -21,6 +21,7 @@ export { executeCallback, cleanupCallback };
21
21
  export { preloadSessionCache } from './device/Device';
22
22
  export { projectFeatures as projectDeviceStateFeatures } from './device/DeviceStateProjector';
23
23
  export { getMethodSupportedProtocols } from './api/utils';
24
+ export { probeUsbDeviceIdentitiesWithTransport } from './api/SearchDevices';
24
25
  export {
25
26
  getFirmwareUpdateHostBindingGeneration,
26
27
  registerFirmwareUpdateHostBinding,
package/src/inject.ts CHANGED
@@ -309,6 +309,8 @@ export const createCoreApi = (
309
309
  call({ ...params, connectId, deviceId, method: 'btcGetAddress' }),
310
310
  btcGetPublicKey: (connectId, deviceId, params) =>
311
311
  call({ ...params, connectId, deviceId, method: 'btcGetPublicKey' }),
312
+ btcDeriveContextHash: (connectId, deviceId, params) =>
313
+ call({ ...params, connectId, deviceId, method: 'btcDeriveContextHash' }),
312
314
  btcSignMessage: (connectId, deviceId, params) =>
313
315
  call({ ...params, connectId, deviceId, method: 'btcSignMessage' }),
314
316
  btcSignPsbt: (connectId, deviceId, params) =>
@@ -502,4 +504,19 @@ export const createCoreApi = (
502
504
  call({ ...params, connectId, deviceId, method: 'neoGetAddress' }),
503
505
  neoSignTransaction: (connectId, deviceId, params) =>
504
506
  call({ ...params, connectId, deviceId, method: 'neoSignTransaction' }),
507
+ zcashGetAddress: (connectId, deviceId, params) =>
508
+ call({ ...params, connectId, deviceId, method: 'zcashGetAddress' }),
509
+ zcashGetFullViewingKey: (connectId, deviceId, params) =>
510
+ call({ ...params, connectId, deviceId, method: 'zcashGetFullViewingKey' }),
511
+ zcashSignPczt: (connectId, deviceId, params) =>
512
+ call({ ...params, connectId, deviceId, method: 'zcashSignPczt' }),
513
+
514
+ moneroGetAddress: (connectId, deviceId, params) =>
515
+ call({ ...params, connectId, deviceId, method: 'moneroGetAddress' }),
516
+ moneroGetWatchKey: (connectId, deviceId, params) =>
517
+ call({ ...params, connectId, deviceId, method: 'moneroGetWatchKey' }),
518
+ moneroKeyImageSync: (connectId, deviceId, params) =>
519
+ call({ ...params, connectId, deviceId, method: 'moneroKeyImageSync' }),
520
+ moneroSignTransaction: (connectId, deviceId, params) =>
521
+ call({ ...params, connectId, deviceId, method: 'moneroSignTransaction' }),
505
522
  });
@@ -7,6 +7,8 @@ export const PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH =
7
7
  export const PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_STAGING_PATH = `${PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH}.staging`;
8
8
  export const PROTOCOL_V2_ROM_PARAMS_PACKAGE_PATH = 'vol0:/loaders/rom/params.okpkg';
9
9
  export const PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_SIZE = 0x5f90;
10
+ // Installed-package comparison only needs the prefix through the header hash.
11
+ export const PROTOCOL_V2_RESOURCE_PACKAGE_COMPARE_SIZE = 0x280;
10
12
 
11
13
  const PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_VERSION = 1;
12
14
  const PROTOCOL_V2_RESOURCE_PACKAGE_FLEXIBLE_OFFSET = 0x6c;
@@ -123,7 +125,7 @@ export function parseProtocolV2ResourcePackageHeader(
123
125
  bytes: Uint8Array,
124
126
  packageSize: number
125
127
  ): ProtocolV2ResourcePackageHeader {
126
- if (bytes.byteLength < PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_SIZE) {
128
+ if (bytes.byteLength < PROTOCOL_V2_RESOURCE_PACKAGE_COMPARE_SIZE) {
127
129
  throw new Error('Pro2 RESOURCE package is shorter than its header');
128
130
  }
129
131
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
@@ -169,5 +171,8 @@ export function parseProtocolV2ResourcePackage(
169
171
  binary: ArrayBuffer | Uint8Array
170
172
  ): ProtocolV2ResourcePackageHeader {
171
173
  const bytes = binary instanceof Uint8Array ? binary : new Uint8Array(binary);
174
+ if (bytes.byteLength < PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_SIZE) {
175
+ throw new Error('Pro2 RESOURCE package is shorter than its header');
176
+ }
172
177
  return parseProtocolV2ResourcePackageHeader(bytes, bytes.byteLength);
173
178
  }
@@ -71,7 +71,7 @@ const getDisplayState = (value: unknown) => {
71
71
  return { seen, enabled };
72
72
  };
73
73
 
74
- const createMethodInteraction = (
74
+ export const createMethodInteraction = (
75
75
  reason: 'address-confirmation' | 'public-key-confirmation' | 'signing-confirmation',
76
76
  operation: string
77
77
  ): ProtocolV2InteractionDescriptor => ({
@@ -34,7 +34,9 @@ export type INetwork =
34
34
  | 'nostr'
35
35
  | 'benfen'
36
36
  | 'neo'
37
- | 'stellar';
37
+ | 'stellar'
38
+ | 'xmr'
39
+ | 'zcash';
38
40
 
39
41
  export type CommonResponseParams = {
40
42
  path: string;
@@ -66,6 +68,11 @@ type AllNetworkAddressPayload =
66
68
  // Nostr public key (bech32)
67
69
  npub?: string;
68
70
  }
71
+ | {
72
+ // Zcash
73
+ address: string;
74
+ seedFingerprint?: string;
75
+ }
69
76
  | {
70
77
  // Cardano
71
78
  addressParameters: CardanoAddressParameters;
@@ -0,0 +1,15 @@
1
+ import type { BabylonDerivedContextHash } from '@onekeyfe/hd-transport';
2
+ import type { CommonParams, Response } from '../params';
3
+
4
+ export type BTCDeriveContextHashParams = {
5
+ path: string | number[];
6
+ appName: string;
7
+ context: string;
8
+ network: 'bitcoin-mainnet' | 'bitcoin-testnet' | 'bitcoin-signet' | 'bitcoin-regtest';
9
+ };
10
+
11
+ export declare function btcDeriveContextHash(
12
+ connectId: string,
13
+ deviceId: string,
14
+ params: CommonParams & BTCDeriveContextHashParams
15
+ ): Response<BabylonDerivedContextHash>;