@onekeyfe/hd-core 1.2.8-alpha.9 → 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 (154) hide show
  1. package/README.md +27 -0
  2. package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +13 -4
  3. package/__tests__/DeviceCommands.test.ts +25 -0
  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 +21 -0
  9. package/__tests__/device-connector-protocol.test.ts +5 -2
  10. package/__tests__/device-lifecycle-events.test.ts +127 -10
  11. package/__tests__/firmware-update/firmware-artifact-source.test.ts +11 -0
  12. package/__tests__/logBlockEvent.test.ts +331 -9
  13. package/__tests__/logger.test.ts +18 -0
  14. package/__tests__/monero-get-address.test.ts +147 -0
  15. package/__tests__/monero-key-image-sync.test.ts +272 -0
  16. package/__tests__/monero-sign-transaction.test.ts +436 -0
  17. package/__tests__/protocol-v2-key-export-confirmation.test.ts +75 -0
  18. package/__tests__/protocol-v2-resources.test.ts +14 -0
  19. package/__tests__/protocol-v2.test.ts +845 -3
  20. package/__tests__/protocolV2FileWrite.test.ts +454 -7
  21. package/__tests__/search-devices.test.ts +36 -0
  22. package/__tests__/sol-sign-offchain-message.test.ts +8 -0
  23. package/__tests__/usb-identity-probe.test.ts +358 -0
  24. package/__tests__/zcash-protobuf.test.ts +152 -0
  25. package/__tests__/zcash-sign-pczt.test.ts +525 -0
  26. package/dist/api/BaseMethod.d.ts.map +1 -1
  27. package/dist/api/FileWrite.d.ts.map +1 -1
  28. package/dist/api/FirmwareUpdateV4.d.ts +5 -0
  29. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  30. package/dist/api/SearchDevices.d.ts +21 -1
  31. package/dist/api/SearchDevices.d.ts.map +1 -1
  32. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts +3 -0
  33. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  34. package/dist/api/btc/BTCDeriveContextHash.d.ts +16 -0
  35. package/dist/api/btc/BTCDeriveContextHash.d.ts.map +1 -0
  36. package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -1
  37. package/dist/api/helpers/pathUtils.d.ts +1 -0
  38. package/dist/api/helpers/pathUtils.d.ts.map +1 -1
  39. package/dist/api/helpers/protocolV2FileWrite.d.ts +5 -1
  40. package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
  41. package/dist/api/index.d.ts +8 -0
  42. package/dist/api/index.d.ts.map +1 -1
  43. package/dist/api/monero/MoneroGetAddress.d.ts +11 -0
  44. package/dist/api/monero/MoneroGetAddress.d.ts.map +1 -0
  45. package/dist/api/monero/MoneroGetWatchKey.d.ts +11 -0
  46. package/dist/api/monero/MoneroGetWatchKey.d.ts.map +1 -0
  47. package/dist/api/monero/MoneroKeyImageSync.d.ts +20 -0
  48. package/dist/api/monero/MoneroKeyImageSync.d.ts.map +1 -0
  49. package/dist/api/monero/MoneroSignTransaction.d.ts +17 -0
  50. package/dist/api/monero/MoneroSignTransaction.d.ts.map +1 -0
  51. package/dist/api/monero/helpers.d.ts +5 -0
  52. package/dist/api/monero/helpers.d.ts.map +1 -0
  53. package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -1
  54. package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
  55. package/dist/api/zcash/ZcashGetAddress.d.ts +12 -0
  56. package/dist/api/zcash/ZcashGetAddress.d.ts.map +1 -0
  57. package/dist/api/zcash/ZcashGetFullViewingKey.d.ts +12 -0
  58. package/dist/api/zcash/ZcashGetFullViewingKey.d.ts.map +1 -0
  59. package/dist/api/zcash/ZcashSignPczt.d.ts +16 -0
  60. package/dist/api/zcash/ZcashSignPczt.d.ts.map +1 -0
  61. package/dist/api/zcash/helpers.d.ts +2 -0
  62. package/dist/api/zcash/helpers.d.ts.map +1 -0
  63. package/dist/core/index.d.ts +3 -1
  64. package/dist/core/index.d.ts.map +1 -1
  65. package/dist/device/Device.d.ts +1 -0
  66. package/dist/device/Device.d.ts.map +1 -1
  67. package/dist/device/DeviceCommands.d.ts +4 -4
  68. package/dist/device/DeviceCommands.d.ts.map +1 -1
  69. package/dist/events/logBlockEvent.d.ts +10 -0
  70. package/dist/events/logBlockEvent.d.ts.map +1 -1
  71. package/dist/events/ui-request.d.ts +2 -0
  72. package/dist/events/ui-request.d.ts.map +1 -1
  73. package/dist/index.d.ts +202 -7
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +5849 -4205
  76. package/dist/inject.d.ts.map +1 -1
  77. package/dist/protocols/protocol-v2/resources.d.ts +1 -0
  78. package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
  79. package/dist/protocols/protocol-v2/uiInteraction.d.ts +1 -0
  80. package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
  81. package/dist/types/api/allNetworkGetAddress.d.ts +4 -1
  82. package/dist/types/api/allNetworkGetAddress.d.ts.map +1 -1
  83. package/dist/types/api/btcDeriveContextHash.d.ts +10 -0
  84. package/dist/types/api/btcDeriveContextHash.d.ts.map +1 -0
  85. package/dist/types/api/export.d.ts +8 -0
  86. package/dist/types/api/export.d.ts.map +1 -1
  87. package/dist/types/api/index.d.ts +16 -0
  88. package/dist/types/api/index.d.ts.map +1 -1
  89. package/dist/types/api/moneroGetAddress.d.ts +15 -0
  90. package/dist/types/api/moneroGetAddress.d.ts.map +1 -0
  91. package/dist/types/api/moneroGetWatchKey.d.ts +15 -0
  92. package/dist/types/api/moneroGetWatchKey.d.ts.map +1 -0
  93. package/dist/types/api/moneroKeyImageSync.d.ts +24 -0
  94. package/dist/types/api/moneroKeyImageSync.d.ts.map +1 -0
  95. package/dist/types/api/moneroSignTransaction.d.ts +32 -0
  96. package/dist/types/api/moneroSignTransaction.d.ts.map +1 -0
  97. package/dist/types/api/zcashGetAddress.d.ts +20 -0
  98. package/dist/types/api/zcashGetAddress.d.ts.map +1 -0
  99. package/dist/types/api/zcashGetFullViewingKey.d.ts +13 -0
  100. package/dist/types/api/zcashGetFullViewingKey.d.ts.map +1 -0
  101. package/dist/types/api/zcashSignPczt.d.ts +9 -0
  102. package/dist/types/api/zcashSignPczt.d.ts.map +1 -0
  103. package/dist/types/device.d.ts +10 -0
  104. package/dist/types/device.d.ts.map +1 -1
  105. package/dist/utils/logger.d.ts.map +1 -1
  106. package/dist/utils/patch.d.ts +1 -1
  107. package/dist/utils/patch.d.ts.map +1 -1
  108. package/package.json +4 -4
  109. package/src/api/BaseMethod.ts +2 -0
  110. package/src/api/FileWrite.ts +7 -1
  111. package/src/api/FirmwareUpdateV4.ts +358 -74
  112. package/src/api/SearchDevices.ts +172 -7
  113. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +55 -15
  114. package/src/api/btc/BTCDeriveContextHash.ts +90 -0
  115. package/src/api/firmware/FirmwareArtifactSource.ts +12 -3
  116. package/src/api/helpers/pathUtils.ts +23 -0
  117. package/src/api/helpers/protocolV2FileWrite.ts +382 -111
  118. package/src/api/index.ts +9 -0
  119. package/src/api/monero/MoneroGetAddress.ts +71 -0
  120. package/src/api/monero/MoneroGetWatchKey.ts +75 -0
  121. package/src/api/monero/MoneroKeyImageSync.ts +170 -0
  122. package/src/api/monero/MoneroSignTransaction.ts +319 -0
  123. package/src/api/monero/helpers.ts +28 -0
  124. package/src/api/protocol-v2/DeviceUploadNft.ts +6 -1
  125. package/src/api/protocol-v2/DeviceUploadWallpaper.ts +15 -1
  126. package/src/api/zcash/ZcashGetAddress.ts +108 -0
  127. package/src/api/zcash/ZcashGetFullViewingKey.ts +78 -0
  128. package/src/api/zcash/ZcashSignPczt.ts +152 -0
  129. package/src/api/zcash/helpers.ts +16 -0
  130. package/src/core/index.ts +49 -17
  131. package/src/data/messages/messages-protocol-v2.json +152 -0
  132. package/src/data/messages/messages.json +51 -0
  133. package/src/device/Device.ts +21 -3
  134. package/src/device/DeviceCommands.ts +17 -0
  135. package/src/device/DeviceConnector.ts +4 -4
  136. package/src/events/logBlockEvent.ts +58 -3
  137. package/src/events/ui-request.ts +2 -0
  138. package/src/index.ts +1 -0
  139. package/src/inject.ts +17 -0
  140. package/src/protocols/protocol-v2/resources.ts +6 -1
  141. package/src/protocols/protocol-v2/uiInteraction.ts +1 -1
  142. package/src/types/api/allNetworkGetAddress.ts +8 -1
  143. package/src/types/api/btcDeriveContextHash.ts +15 -0
  144. package/src/types/api/export.ts +17 -0
  145. package/src/types/api/index.ts +24 -0
  146. package/src/types/api/moneroGetAddress.ts +27 -0
  147. package/src/types/api/moneroGetWatchKey.ts +28 -0
  148. package/src/types/api/moneroKeyImageSync.ts +45 -0
  149. package/src/types/api/moneroSignTransaction.ts +54 -0
  150. package/src/types/api/zcashGetAddress.ts +32 -0
  151. package/src/types/api/zcashGetFullViewingKey.ts +24 -0
  152. package/src/types/api/zcashSignPczt.ts +18 -0
  153. package/src/types/device.ts +18 -0
  154. 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
@@ -452,6 +455,7 @@ export class Device extends EventEmitter {
452
455
  ) {
453
456
  const attempt = this.connectionAttempt;
454
457
  this.throwIfInterruptedByUser();
458
+ this.releasedBleConnection = false;
455
459
  const env = DataManager.getSettings('env');
456
460
  const mainIdKey = DataManager.isBleConnect(env) ? 'id' : 'session';
457
461
  const previousProtocol = this.originalDescriptor.protocolType;
@@ -562,6 +566,7 @@ export class Device extends EventEmitter {
562
566
  (this.isUsedHere() && !this.keepSession && this.mainId) ||
563
567
  (this.mainId && DataManager.isBleConnect(env))
564
568
  ) {
569
+ this.releasedBleConnection = false;
565
570
  // wait for callback tasks to complete before releasing device
566
571
  if (this.pendingCallbackPromise) {
567
572
  try {
@@ -585,12 +590,24 @@ export class Device extends EventEmitter {
585
590
  }
586
591
  }
587
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);
588
598
  // BLE releases even when keepSession is set, so forward the intent.
589
- await this.deviceConnector?.release(this.mainId, false, this.keepSession);
590
- 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;
591
605
  } catch (err) {
592
606
  Log.error('[Device] release error: ', err);
593
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);
594
611
  this.needReloadDevice = true;
595
612
  }
596
613
  }
@@ -1369,6 +1386,7 @@ export class Device extends EventEmitter {
1369
1386
 
1370
1387
  markTransportDisconnected() {
1371
1388
  this.deviceAcquired = false;
1389
+ this.releasedBleConnection = false;
1372
1390
  this.invalidateProtocolV2RuntimeState();
1373
1391
  }
1374
1392
 
@@ -1631,7 +1649,7 @@ export class Device extends EventEmitter {
1631
1649
  await commands?.cancelDevice?.().catch(cancelError => {
1632
1650
  Log.debug('Protocol V2 fallback cancel error', cancelError);
1633
1651
  });
1634
- } else if (!acquired) {
1652
+ } else if (!acquired && !this.releasedBleConnection) {
1635
1653
  // Abort setup without acquiring a session just to send Cancel.
1636
1654
  if (mainId && deviceConnector?.disconnect) {
1637
1655
  // The connector drops the link silently, so without this line a
@@ -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)) {
@@ -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;
@@ -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>;
@@ -1,5 +1,6 @@
1
1
  export type { BTCAddress, BTCGetAddressParams } from './btcGetAddress';
2
2
  export type { BTCPublicKey, BTCGetPublicKeyParams } from './btcGetPublicKey';
3
+ export type { BTCDeriveContextHashParams } from './btcDeriveContextHash';
3
4
  export type { BTCSignMessageParams } from './btcSignMessage';
4
5
  export type { BTCVerifyMessageParams } from './btcVerifyMessage';
5
6
  export type {
@@ -226,3 +227,19 @@ export type { BenfenAddress, BenfenGetAddressParams } from './benfenGetAddress';
226
227
  export type { BenfenPublicKey, BenfenGetPublicKeyParams } from './benfenGetPublicKey';
227
228
  export type { BenfenSignMessageParams } from './benfenSignMessage';
228
229
  export type { BenfenSignedTx, BenfenSignTransactionParams } from './benfenSignTransaction';
230
+ export type { ZcashAddress, ZcashGetAddressParams } from './zcashGetAddress';
231
+ export type { ZcashFullViewingKey, ZcashGetFullViewingKeyParams } from './zcashGetFullViewingKey';
232
+ export type { ZcashSignedPczt, ZcashSignPcztParams } from './zcashSignPczt';
233
+
234
+ export type { MoneroAddress, MoneroGetAddressParams } from './moneroGetAddress';
235
+ export type { MoneroGetWatchKeyParams, MoneroWatchKey } from './moneroGetWatchKey';
236
+ export type {
237
+ MoneroEncryptedKeyImage,
238
+ MoneroKeyImageSyncParams,
239
+ MoneroKeyImageSyncResult,
240
+ MoneroKeyImageTransfer,
241
+ } from './moneroKeyImageSync';
242
+ export type {
243
+ MoneroSignTransactionParams,
244
+ MoneroSignTransactionResult,
245
+ } from './moneroSignTransaction';
@@ -73,6 +73,7 @@ import type { evmSignTypedData } from './evmSignTypedData';
73
73
  import type { evmVerifyMessage } from './evmVerifyMessage';
74
74
  import type { btcGetAddress } from './btcGetAddress';
75
75
  import type { btcGetPublicKey } from './btcGetPublicKey';
76
+ import type { btcDeriveContextHash } from './btcDeriveContextHash';
76
77
  import type { btcSignMessage } from './btcSignMessage';
77
78
  import type { btcSignPsbt } from './btcSignPsbt';
78
79
  import type { btcSignTransaction } from './btcSignTransaction';
@@ -153,6 +154,13 @@ import type { benfenSignTransaction } from './benfenSignTransaction';
153
154
  import type { benfenSignMessage } from './benfenSignMessage';
154
155
  import type { neoGetAddress } from './neoGetAddress';
155
156
  import type { neoSignTransaction } from './neoSignTransaction';
157
+ import type { zcashGetAddress } from './zcashGetAddress';
158
+ import type { zcashGetFullViewingKey } from './zcashGetFullViewingKey';
159
+ import type { zcashSignPczt } from './zcashSignPczt';
160
+ import type { moneroGetAddress } from './moneroGetAddress';
161
+ import type { moneroGetWatchKey } from './moneroGetWatchKey';
162
+ import type { moneroKeyImageSync } from './moneroKeyImageSync';
163
+ import type { moneroSignTransaction } from './moneroSignTransaction';
156
164
  import type { ConnectSettings } from '../settings';
157
165
  import type { HardwareConnectProtocol } from '@onekeyfe/hd-shared';
158
166
 
@@ -286,6 +294,7 @@ export type CoreApi = {
286
294
  */
287
295
  btcGetAddress: typeof btcGetAddress;
288
296
  btcGetPublicKey: typeof btcGetPublicKey;
297
+ btcDeriveContextHash: typeof btcDeriveContextHash;
289
298
  btcSignMessage: typeof btcSignMessage;
290
299
  btcSignPsbt: typeof btcSignPsbt;
291
300
  btcSignTransaction: typeof btcSignTransaction;
@@ -470,4 +479,19 @@ export type CoreApi = {
470
479
  */
471
480
  neoGetAddress: typeof neoGetAddress;
472
481
  neoSignTransaction: typeof neoSignTransaction;
482
+
483
+ /**
484
+ * Zcash
485
+ */
486
+ zcashGetAddress: typeof zcashGetAddress;
487
+ zcashGetFullViewingKey: typeof zcashGetFullViewingKey;
488
+ zcashSignPczt: typeof zcashSignPczt;
489
+
490
+ /**
491
+ * Monero
492
+ */
493
+ moneroGetAddress: typeof moneroGetAddress;
494
+ moneroGetWatchKey: typeof moneroGetWatchKey;
495
+ moneroKeyImageSync: typeof moneroKeyImageSync;
496
+ moneroSignTransaction: typeof moneroSignTransaction;
473
497
  };
@@ -0,0 +1,27 @@
1
+ import type { CommonParams, Response } from '../params';
2
+
3
+ export type MoneroAddress = {
4
+ path: string;
5
+ // Primary address of the account, base58
6
+ address: string;
7
+ };
8
+
9
+ export type MoneroGetAddressParams = {
10
+ // Account path, m/44'/128'/account'
11
+ path: string | number[];
12
+ showOnOneKey?: boolean;
13
+ // 0 mainnet, 1 testnet, 2 stagenet
14
+ networkType?: number;
15
+ };
16
+
17
+ export declare function moneroGetAddress(
18
+ connectId: string,
19
+ deviceId: string,
20
+ params: CommonParams & MoneroGetAddressParams
21
+ ): Response<MoneroAddress>;
22
+
23
+ export declare function moneroGetAddress(
24
+ connectId: string,
25
+ deviceId: string,
26
+ params: CommonParams & { bundle?: MoneroGetAddressParams[] }
27
+ ): Response<Array<MoneroAddress>>;