@onekeyfe/hd-core 1.2.8 → 1.2.10-alpha.1

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 (151) hide show
  1. package/README.md +27 -0
  2. package/__tests__/DeviceCommands.test.ts +66 -13
  3. package/__tests__/allNetworkGetAddress-privacy-networks.test.ts +78 -0
  4. package/__tests__/btc-derive-context-hash.test.ts +200 -0
  5. package/__tests__/core-dispose.test.ts +114 -1
  6. package/__tests__/core-error-output.test.ts +55 -3
  7. package/__tests__/device-connector-protocol.test.ts +5 -2
  8. package/__tests__/device-lifecycle-events.test.ts +191 -27
  9. package/__tests__/device-pool-state.test.ts +50 -0
  10. package/__tests__/firmware-update/firmware-artifact-source.test.ts +11 -0
  11. package/__tests__/logBlockEvent.test.ts +331 -9
  12. package/__tests__/logger.test.ts +18 -0
  13. package/__tests__/monero-get-address.test.ts +147 -0
  14. package/__tests__/monero-key-image-sync.test.ts +272 -0
  15. package/__tests__/monero-sign-transaction.test.ts +436 -0
  16. package/__tests__/protocol-v2-bootloader-mode.test.ts +43 -2
  17. package/__tests__/protocol-v2-resources.test.ts +14 -0
  18. package/__tests__/protocol-v2.test.ts +841 -46
  19. package/__tests__/protocolV2FileWrite.test.ts +454 -7
  20. package/__tests__/refresh-device-state.test.ts +19 -17
  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 +141 -0
  25. package/__tests__/zcash-sign-pczt.test.ts +446 -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/GetDeviceState.d.ts.map +1 -1
  31. package/dist/api/SearchDevices.d.ts +21 -1
  32. package/dist/api/SearchDevices.d.ts.map +1 -1
  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 +7 -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/DeviceReboot.d.ts.map +1 -1
  54. package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -1
  55. package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
  56. package/dist/api/zcash/ZcashGetAddress.d.ts +12 -0
  57. package/dist/api/zcash/ZcashGetAddress.d.ts.map +1 -0
  58. package/dist/api/zcash/ZcashSignPczt.d.ts +16 -0
  59. package/dist/api/zcash/ZcashSignPczt.d.ts.map +1 -0
  60. package/dist/core/index.d.ts +3 -2
  61. package/dist/core/index.d.ts.map +1 -1
  62. package/dist/device/Device.d.ts +3 -0
  63. package/dist/device/Device.d.ts.map +1 -1
  64. package/dist/device/DeviceCommands.d.ts +4 -4
  65. package/dist/device/DeviceCommands.d.ts.map +1 -1
  66. package/dist/device/DevicePool.d.ts.map +1 -1
  67. package/dist/events/logBlockEvent.d.ts +10 -0
  68. package/dist/events/logBlockEvent.d.ts.map +1 -1
  69. package/dist/events/ui-request.d.ts +2 -0
  70. package/dist/events/ui-request.d.ts.map +1 -1
  71. package/dist/index.d.ts +196 -7
  72. package/dist/index.d.ts.map +1 -1
  73. package/dist/index.js +4363 -2792
  74. package/dist/inject.d.ts.map +1 -1
  75. package/dist/protocols/protocol-v2/resources.d.ts +1 -0
  76. package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
  77. package/dist/types/api/allNetworkGetAddress.d.ts +5 -1
  78. package/dist/types/api/allNetworkGetAddress.d.ts.map +1 -1
  79. package/dist/types/api/btcDeriveContextHash.d.ts +10 -0
  80. package/dist/types/api/btcDeriveContextHash.d.ts.map +1 -0
  81. package/dist/types/api/export.d.ts +7 -0
  82. package/dist/types/api/export.d.ts.map +1 -1
  83. package/dist/types/api/index.d.ts +14 -0
  84. package/dist/types/api/index.d.ts.map +1 -1
  85. package/dist/types/api/moneroGetAddress.d.ts +15 -0
  86. package/dist/types/api/moneroGetAddress.d.ts.map +1 -0
  87. package/dist/types/api/moneroGetWatchKey.d.ts +15 -0
  88. package/dist/types/api/moneroGetWatchKey.d.ts.map +1 -0
  89. package/dist/types/api/moneroKeyImageSync.d.ts +24 -0
  90. package/dist/types/api/moneroKeyImageSync.d.ts.map +1 -0
  91. package/dist/types/api/moneroSignTransaction.d.ts +32 -0
  92. package/dist/types/api/moneroSignTransaction.d.ts.map +1 -0
  93. package/dist/types/api/zcashGetAddress.d.ts +22 -0
  94. package/dist/types/api/zcashGetAddress.d.ts.map +1 -0
  95. package/dist/types/api/zcashSignPczt.d.ts +9 -0
  96. package/dist/types/api/zcashSignPczt.d.ts.map +1 -0
  97. package/dist/types/device.d.ts +10 -0
  98. package/dist/types/device.d.ts.map +1 -1
  99. package/dist/types/params.d.ts +1 -0
  100. package/dist/types/params.d.ts.map +1 -1
  101. package/dist/utils/logger.d.ts.map +1 -1
  102. package/dist/utils/patch.d.ts +1 -1
  103. package/dist/utils/patch.d.ts.map +1 -1
  104. package/package.json +4 -4
  105. package/src/api/BaseMethod.ts +2 -0
  106. package/src/api/FileWrite.ts +7 -1
  107. package/src/api/FirmwareUpdateV4.ts +366 -99
  108. package/src/api/GetDeviceState.ts +2 -5
  109. package/src/api/SearchDevices.ts +172 -7
  110. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +38 -1
  111. package/src/api/btc/BTCDeriveContextHash.ts +90 -0
  112. package/src/api/firmware/FirmwareArtifactSource.ts +12 -3
  113. package/src/api/helpers/pathUtils.ts +23 -0
  114. package/src/api/helpers/protocolV2FileWrite.ts +382 -111
  115. package/src/api/index.ts +8 -0
  116. package/src/api/monero/MoneroGetAddress.ts +71 -0
  117. package/src/api/monero/MoneroGetWatchKey.ts +69 -0
  118. package/src/api/monero/MoneroKeyImageSync.ts +164 -0
  119. package/src/api/monero/MoneroSignTransaction.ts +319 -0
  120. package/src/api/monero/helpers.ts +28 -0
  121. package/src/api/protocol-v2/DeviceReboot.ts +2 -0
  122. package/src/api/protocol-v2/DeviceUploadNft.ts +6 -1
  123. package/src/api/protocol-v2/DeviceUploadWallpaper.ts +15 -1
  124. package/src/api/zcash/ZcashGetAddress.ts +119 -0
  125. package/src/api/zcash/ZcashSignPczt.ts +152 -0
  126. package/src/core/index.ts +52 -24
  127. package/src/data/messages/messages-protocol-v2.json +138 -1
  128. package/src/data/messages/messages.json +51 -0
  129. package/src/device/Device.ts +32 -4
  130. package/src/device/DeviceCommands.ts +15 -1
  131. package/src/device/DeviceConnector.ts +4 -4
  132. package/src/device/DevicePool.ts +12 -2
  133. package/src/events/core.ts +2 -2
  134. package/src/events/logBlockEvent.ts +57 -3
  135. package/src/events/ui-request.ts +2 -0
  136. package/src/index.ts +1 -0
  137. package/src/inject.ts +15 -0
  138. package/src/protocols/protocol-v2/resources.ts +6 -1
  139. package/src/types/api/allNetworkGetAddress.ts +9 -1
  140. package/src/types/api/btcDeriveContextHash.ts +15 -0
  141. package/src/types/api/export.ts +16 -0
  142. package/src/types/api/index.ts +22 -0
  143. package/src/types/api/moneroGetAddress.ts +27 -0
  144. package/src/types/api/moneroGetWatchKey.ts +28 -0
  145. package/src/types/api/moneroKeyImageSync.ts +45 -0
  146. package/src/types/api/moneroSignTransaction.ts +54 -0
  147. package/src/types/api/zcashGetAddress.ts +35 -0
  148. package/src/types/api/zcashSignPczt.ts +18 -0
  149. package/src/types/device.ts +18 -0
  150. package/src/types/params.ts +1 -1
  151. package/src/utils/logger.ts +4 -0
@@ -0,0 +1,54 @@
1
+ import type { MoneroTransactionData, MoneroTransactionSourceEntry } from '@onekeyfe/hd-transport';
2
+ import type { CommonParams, Response } from '../params';
3
+
4
+ export type MoneroSignTransactionParams = {
5
+ // Account path, m/44'/128'/account'
6
+ path: string | number[];
7
+ // 0 mainnet, 1 testnet, 2 stagenet
8
+ networkType?: number;
9
+ // Init data in protobuf field names; outputs include the change, in final order
10
+ tsxData: MoneroTransactionData;
11
+ // One source entry per input, in original order, each with its full ring
12
+ inputs: MoneroTransactionSourceEntry[];
13
+ };
14
+
15
+ // Raw device output, hex unless noted. The host assembles the transaction.
16
+ export type MoneroSignTransactionResult = {
17
+ // Original input index of each sorted input
18
+ origIndices: number[];
19
+ // Serialized tx.vin entries, sorted by key image (descending)
20
+ vinis: string[];
21
+ // Pseudo-output commitments from SignInputAck, sorted order
22
+ pseudoOuts: string[];
23
+ // Sealed CLSAG signatures, sorted order; openingKey unseals them
24
+ signatures: string[];
25
+ // Serialized tx.vout entries, output order
26
+ txOuts: string[];
27
+ // Output key and commitment (64 bytes each), output order
28
+ outPks: string[];
29
+ // Encrypted 8-byte amounts, output order
30
+ ecdhInfos: string[];
31
+ // Aggregated Bulletproof+ without V
32
+ rsig: string;
33
+ extra: string;
34
+ txPrefixHash: string;
35
+ fullMessageHash: string;
36
+ rv: {
37
+ // Decimal piconero
38
+ txnFee: string;
39
+ message: string;
40
+ rvType: number;
41
+ };
42
+ openingKey: string;
43
+ // Tx private keys sealed by the device for later proofs (MoneroGetTxKeyRequest), with the
44
+ // salts that rederive the sealing key; wallet2 keeps them as salt1, salt2, enc_keys
45
+ salt: string;
46
+ randMult: string;
47
+ txEncKeys: string;
48
+ };
49
+
50
+ export declare function moneroSignTransaction(
51
+ connectId: string,
52
+ deviceId: string,
53
+ params: CommonParams & MoneroSignTransactionParams
54
+ ): Response<MoneroSignTransactionResult>;
@@ -0,0 +1,35 @@
1
+ import type { ZcashAddressScope, ZcashAddressType } from '@onekeyfe/hd-transport';
2
+ import type { CommonParams, Response } from '../params';
3
+
4
+ export type ZcashAddress = {
5
+ path: string;
6
+ // ZIP-316 unified address or transparent P2PKH address
7
+ address: string;
8
+ // ZIP-316 unified full viewing key, present when includeUfvk was requested
9
+ ufvk?: string;
10
+ // ZIP-32 seed fingerprint (hex), present when includeSeedFingerprint was requested
11
+ seedFingerprint?: string;
12
+ };
13
+
14
+ export type ZcashGetAddressParams = {
15
+ // ZIP-32 account path, m/32'/133'/account'
16
+ path: string | number[];
17
+ showOnOneKey?: boolean;
18
+ diversifierIndex?: number;
19
+ addressType?: ZcashAddressType;
20
+ scope?: ZcashAddressScope;
21
+ includeUfvk?: boolean;
22
+ includeSeedFingerprint?: boolean;
23
+ };
24
+
25
+ export declare function zcashGetAddress(
26
+ connectId: string,
27
+ deviceId: string,
28
+ params: CommonParams & ZcashGetAddressParams
29
+ ): Response<ZcashAddress>;
30
+
31
+ export declare function zcashGetAddress(
32
+ connectId: string,
33
+ deviceId: string,
34
+ params: CommonParams & { bundle?: ZcashGetAddressParams[] }
35
+ ): Response<Array<ZcashAddress>>;
@@ -0,0 +1,18 @@
1
+ import type { CommonParams, Response } from '../params';
2
+
3
+ export type ZcashSignPcztParams = {
4
+ // Unproved PCZT (v2, tx v6) as hex; the device signs it and returns a
5
+ // redacted copy with signatures filled in.
6
+ pczt: string;
7
+ };
8
+
9
+ export type ZcashSignedPczt = {
10
+ // Signed, redacted PCZT as hex
11
+ pczt: string;
12
+ };
13
+
14
+ export declare function zcashSignPczt(
15
+ connectId: string,
16
+ deviceId: string,
17
+ params: CommonParams & ZcashSignPcztParams
18
+ ): Response<ZcashSignedPczt>;
@@ -83,6 +83,24 @@ export type SearchDevice = {
83
83
  deviceType: IDeviceType;
84
84
  name: string;
85
85
  commType: OneKeyDeviceCommType;
86
+ /**
87
+ * React Native and Electron BLE discovery only. Serial-number color letter ('A'-'Z')
88
+ * advertised by Pro2 / Neo, possibly remembered from an earlier advertisement in this
89
+ * process. Absent when unknown; the letter's meaning depends on deviceType.
90
+ */
91
+ bleColorCode?: string;
92
+ };
93
+
94
+ /** Identity confirmed over USB. The descriptor path is only a transport address. */
95
+ export type UsbDeviceIdentity = {
96
+ path: string;
97
+ serialNo: string | null;
98
+ deviceId: string | null;
99
+ deviceType: IDeviceType;
100
+ connectProtocol: HardwareConnectProtocol;
101
+ commType: 'webusb' | 'bridge';
102
+ /** Mode confirmed by the device response; absent when discovery cannot establish it. */
103
+ mode?: DeviceStateMode;
86
104
  };
87
105
 
88
106
  // export type UnknownDevice = {
@@ -83,7 +83,7 @@ export type Params<T> = CommonParams & T & { bundle?: undefined };
83
83
 
84
84
  export interface Unsuccessful {
85
85
  success: false;
86
- payload: { error: string; code?: string | number };
86
+ payload: { error: string; code?: string | number; params?: Record<string, unknown> };
87
87
  }
88
88
 
89
89
  export interface Success<T> {
@@ -78,6 +78,10 @@ class Log {
78
78
  const _logs: { [k: string]: Log } = {};
79
79
 
80
80
  export const initLog = (prefix: string, enabled?: boolean) => {
81
+ // Loggers that share a prefix must share one instance; otherwise enableLog only reaches the
82
+ // last one registered and the others never print.
83
+ const existing = _logs[prefix];
84
+ if (existing) return existing;
81
85
  const instance = new Log(prefix, !!enabled);
82
86
  _logs[prefix] = instance;
83
87
  return instance;