@onekeyfe/hd-core 1.2.8-alpha.126 → 1.2.8-alpha.128

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 (81) hide show
  1. package/__tests__/allNetworkGetAddress-privacy-networks.test.ts +78 -0
  2. package/__tests__/logBlockEvent.test.ts +292 -0
  3. package/__tests__/monero-get-address.test.ts +147 -0
  4. package/__tests__/monero-key-image-sync.test.ts +272 -0
  5. package/__tests__/monero-sign-transaction.test.ts +436 -0
  6. package/__tests__/zcash-protobuf.test.ts +141 -0
  7. package/__tests__/zcash-sign-pczt.test.ts +446 -0
  8. package/dist/api/BaseMethod.d.ts.map +1 -1
  9. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  10. package/dist/api/helpers/pathUtils.d.ts +1 -0
  11. package/dist/api/helpers/pathUtils.d.ts.map +1 -1
  12. package/dist/api/index.d.ts +6 -0
  13. package/dist/api/index.d.ts.map +1 -1
  14. package/dist/api/monero/MoneroGetAddress.d.ts +11 -0
  15. package/dist/api/monero/MoneroGetAddress.d.ts.map +1 -0
  16. package/dist/api/monero/MoneroGetWatchKey.d.ts +11 -0
  17. package/dist/api/monero/MoneroGetWatchKey.d.ts.map +1 -0
  18. package/dist/api/monero/MoneroKeyImageSync.d.ts +20 -0
  19. package/dist/api/monero/MoneroKeyImageSync.d.ts.map +1 -0
  20. package/dist/api/monero/MoneroSignTransaction.d.ts +17 -0
  21. package/dist/api/monero/MoneroSignTransaction.d.ts.map +1 -0
  22. package/dist/api/monero/helpers.d.ts +5 -0
  23. package/dist/api/monero/helpers.d.ts.map +1 -0
  24. package/dist/api/zcash/ZcashGetAddress.d.ts +12 -0
  25. package/dist/api/zcash/ZcashGetAddress.d.ts.map +1 -0
  26. package/dist/api/zcash/ZcashSignPczt.d.ts +16 -0
  27. package/dist/api/zcash/ZcashSignPczt.d.ts.map +1 -0
  28. package/dist/core/index.d.ts.map +1 -1
  29. package/dist/events/logBlockEvent.d.ts +10 -0
  30. package/dist/events/logBlockEvent.d.ts.map +1 -1
  31. package/dist/events/ui-request.d.ts +1 -0
  32. package/dist/events/ui-request.d.ts.map +1 -1
  33. package/dist/index.d.ts +140 -4
  34. package/dist/index.js +866 -11
  35. package/dist/inject.d.ts.map +1 -1
  36. package/dist/types/api/allNetworkGetAddress.d.ts +5 -1
  37. package/dist/types/api/allNetworkGetAddress.d.ts.map +1 -1
  38. package/dist/types/api/export.d.ts +6 -0
  39. package/dist/types/api/export.d.ts.map +1 -1
  40. package/dist/types/api/index.d.ts +12 -0
  41. package/dist/types/api/index.d.ts.map +1 -1
  42. package/dist/types/api/moneroGetAddress.d.ts +15 -0
  43. package/dist/types/api/moneroGetAddress.d.ts.map +1 -0
  44. package/dist/types/api/moneroGetWatchKey.d.ts +15 -0
  45. package/dist/types/api/moneroGetWatchKey.d.ts.map +1 -0
  46. package/dist/types/api/moneroKeyImageSync.d.ts +24 -0
  47. package/dist/types/api/moneroKeyImageSync.d.ts.map +1 -0
  48. package/dist/types/api/moneroSignTransaction.d.ts +32 -0
  49. package/dist/types/api/moneroSignTransaction.d.ts.map +1 -0
  50. package/dist/types/api/zcashGetAddress.d.ts +22 -0
  51. package/dist/types/api/zcashGetAddress.d.ts.map +1 -0
  52. package/dist/types/api/zcashSignPczt.d.ts +9 -0
  53. package/dist/types/api/zcashSignPczt.d.ts.map +1 -0
  54. package/dist/utils/patch.d.ts +1 -1
  55. package/dist/utils/patch.d.ts.map +1 -1
  56. package/package.json +4 -4
  57. package/src/api/BaseMethod.ts +2 -0
  58. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +38 -1
  59. package/src/api/helpers/pathUtils.ts +23 -0
  60. package/src/api/index.ts +7 -0
  61. package/src/api/monero/MoneroGetAddress.ts +71 -0
  62. package/src/api/monero/MoneroGetWatchKey.ts +69 -0
  63. package/src/api/monero/MoneroKeyImageSync.ts +164 -0
  64. package/src/api/monero/MoneroSignTransaction.ts +319 -0
  65. package/src/api/monero/helpers.ts +28 -0
  66. package/src/api/zcash/ZcashGetAddress.ts +119 -0
  67. package/src/api/zcash/ZcashSignPczt.ts +152 -0
  68. package/src/core/index.ts +4 -3
  69. package/src/data/messages/messages-protocol-v2.json +138 -1
  70. package/src/events/logBlockEvent.ts +55 -3
  71. package/src/events/ui-request.ts +1 -0
  72. package/src/inject.ts +13 -0
  73. package/src/types/api/allNetworkGetAddress.ts +9 -1
  74. package/src/types/api/export.ts +15 -0
  75. package/src/types/api/index.ts +20 -0
  76. package/src/types/api/moneroGetAddress.ts +27 -0
  77. package/src/types/api/moneroGetWatchKey.ts +28 -0
  78. package/src/types/api/moneroKeyImageSync.ts +45 -0
  79. package/src/types/api/moneroSignTransaction.ts +54 -0
  80. package/src/types/api/zcashGetAddress.ts +35 -0
  81. package/src/types/api/zcashSignPczt.ts +18 -0
@@ -0,0 +1,152 @@
1
+ import { bytesToHex } from '@noble/hashes/utils';
2
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
3
+
4
+ import { BaseMethod } from '../BaseMethod';
5
+ import { invalidParameter, validateParams } from '../helpers/paramsValidator';
6
+ import { stripHexPrefix } from '../helpers/hexUtils';
7
+ import { UI_REQUEST } from '../../constants/ui-request';
8
+
9
+ import type { ZcashSignPczt as HardwareZcashSignPczt } from '@onekeyfe/hd-transport';
10
+ import type { TypedCall, TypedResponseMessage } from '../../device/DeviceCommands';
11
+ import type { ZcashSignedPczt } from '../../types/api/zcashSignPczt';
12
+ import type { DeviceFirmwareRange } from '../../types';
13
+
14
+ const CHUNK_BYTE_SIZE = 1024;
15
+ // Host memory sanity bound on the device-announced length, not a device limit.
16
+ const SIGNED_PCZT_SANITY_MAX_BYTES = 16 * 1024 * 1024;
17
+
18
+ export default class ZcashSignPczt extends BaseMethod<HardwareZcashSignPczt> {
19
+ pczt: Buffer = Buffer.alloc(0);
20
+
21
+ getSupportedProtocols() {
22
+ return ['V2'] as const;
23
+ }
24
+
25
+ init() {
26
+ this.checkDeviceId = true;
27
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
28
+ this.strictCheckDeviceSupport = true;
29
+
30
+ validateParams(this.payload, [{ name: 'pczt', type: 'hexString', required: true }]);
31
+
32
+ // Reject odd-length hex instead of left-padding it, which would shift every nibble.
33
+ const pcztHex = stripHexPrefix(this.payload.pczt);
34
+ if (pcztHex.length % 2 !== 0) {
35
+ throw invalidParameter('pczt hex must have an even length');
36
+ }
37
+ this.pczt = Buffer.from(pcztHex, 'hex');
38
+ if (this.pczt.length === 0) {
39
+ throw invalidParameter('pczt is empty');
40
+ }
41
+
42
+ this.params = {
43
+ pczt_length: this.pczt.length,
44
+ pczt_initial_chunk: bytesToHex(this.pczt.subarray(0, CHUNK_BYTE_SIZE)),
45
+ };
46
+ }
47
+
48
+ getVersionRange(): DeviceFirmwareRange {
49
+ return {
50
+ model_pro2: {
51
+ min: '0.0.0',
52
+ },
53
+ };
54
+ }
55
+
56
+ // Upload: the device decides every chunk length via ZcashPcztChunkRequest and
57
+ // the host must answer with exactly that many bytes.
58
+ uploadPczt = async (
59
+ typedCall: TypedCall,
60
+ first: TypedResponseMessage<'ZcashSignedPczt'> | TypedResponseMessage<'ZcashPcztChunkRequest'>,
61
+ initialOffset: number
62
+ ): Promise<TypedResponseMessage<'ZcashSignedPczt'>> => {
63
+ let res = first;
64
+ let offset = initialOffset;
65
+ while (res.type === 'ZcashPcztChunkRequest') {
66
+ const { chunk_length: chunkLength } = res.message;
67
+ if (
68
+ !Number.isSafeInteger(chunkLength) ||
69
+ chunkLength <= 0 ||
70
+ offset + chunkLength > this.pczt.length
71
+ ) {
72
+ throw ERRORS.TypedError(
73
+ HardwareErrorCode.ResponseUnexpectTypeError,
74
+ `device requested ${chunkLength} bytes at offset ${offset} of ${this.pczt.length}`
75
+ );
76
+ }
77
+
78
+ const chunk = this.pczt.subarray(offset, offset + chunkLength);
79
+ res = await typedCall('ZcashPcztChunkAck', ['ZcashSignedPczt', 'ZcashPcztChunkRequest'], {
80
+ data_chunk: bytesToHex(chunk),
81
+ });
82
+ offset += chunkLength;
83
+ }
84
+
85
+ if (offset !== this.pczt.length) {
86
+ throw ERRORS.TypedError(
87
+ HardwareErrorCode.ResponseUnexpectTypeError,
88
+ 'device completed signing before receiving the whole pczt'
89
+ );
90
+ }
91
+ return res;
92
+ };
93
+
94
+ // Download: the host decides chunk lengths via ZcashSignedPcztChunkRequest
95
+ // until the announced pczt_length has been received.
96
+ downloadSignedPczt = async (
97
+ typedCall: TypedCall,
98
+ res: TypedResponseMessage<'ZcashSignedPczt'>
99
+ ): Promise<Buffer> => {
100
+ const { pczt_length: total, pczt_initial_chunk: initial } = res.message;
101
+ if (!Number.isSafeInteger(total) || total <= 0 || total > SIGNED_PCZT_SANITY_MAX_BYTES) {
102
+ throw ERRORS.TypedError(
103
+ HardwareErrorCode.ResponseUnexpectTypeError,
104
+ `device announced invalid signed pczt length ${total}`
105
+ );
106
+ }
107
+
108
+ const parts: Buffer[] = [Buffer.from(initial ?? '', 'hex')];
109
+ let received = parts[0].length;
110
+ if (received > total) {
111
+ throw ERRORS.TypedError(
112
+ HardwareErrorCode.ResponseUnexpectTypeError,
113
+ 'device returned more initial pczt bytes than announced'
114
+ );
115
+ }
116
+
117
+ while (received < total) {
118
+ const chunkLength = Math.min(CHUNK_BYTE_SIZE, total - received);
119
+ const ack = await typedCall('ZcashSignedPcztChunkRequest', 'ZcashPcztChunkAck', {
120
+ chunk_length: chunkLength,
121
+ });
122
+ const chunk = Buffer.from(ack.message.data_chunk ?? '', 'hex');
123
+ if (chunk.length !== chunkLength) {
124
+ throw ERRORS.TypedError(
125
+ HardwareErrorCode.ResponseUnexpectTypeError,
126
+ `device returned ${chunk.length} of ${chunkLength} requested bytes at offset ${received} of ${total}`
127
+ );
128
+ }
129
+ parts.push(chunk);
130
+ received += chunk.length;
131
+ }
132
+
133
+ return Buffer.concat(parts);
134
+ };
135
+
136
+ async run(): Promise<ZcashSignedPczt> {
137
+ const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
138
+
139
+ const first = await typedCall('ZcashSignPczt', ['ZcashSignedPczt', 'ZcashPcztChunkRequest'], {
140
+ ...this.params,
141
+ });
142
+
143
+ const signed = await this.uploadPczt(
144
+ typedCall,
145
+ first,
146
+ Math.min(CHUNK_BYTE_SIZE, this.pczt.length)
147
+ );
148
+ const pczt = await this.downloadSignedPczt(typedCall, signed);
149
+
150
+ return { pczt: bytesToHex(pczt) };
151
+ }
152
+ }
package/src/core/index.ts CHANGED
@@ -61,6 +61,7 @@ import {
61
61
  formatLogMethodLabel,
62
62
  getLogBlockLabel,
63
63
  getSafeLogPayload,
64
+ getSafeLogTask,
64
65
  } from '../events';
65
66
  import TransportManager from '../data-manager/TransportManager';
66
67
  import DeviceConnector from '../device/DeviceConnector';
@@ -1451,7 +1452,7 @@ export const cancel = (context: CoreContext, connectId?: string) => {
1451
1452
  };
1452
1453
  for (const requestId of requestIds) {
1453
1454
  const task = requestQueue.getTask(requestId);
1454
- Log.debug('Cancel Api connect task: ', task);
1455
+ Log.debug('Cancel Api connect task: ', getSafeLogTask(task));
1455
1456
  if (task) {
1456
1457
  // During ensureConnected the method has a connectId but device is
1457
1458
  // assigned only after the poll succeeds. Interrupt the cached BLE
@@ -1486,7 +1487,7 @@ export const cancel = (context: CoreContext, connectId?: string) => {
1486
1487
  };
1487
1488
  for (const requestId of requestQueue.getRequestTasksId()) {
1488
1489
  const task = requestQueue.getTask(requestId);
1489
- Log.debug('Cancel Api connect task: ', task);
1490
+ Log.debug('Cancel Api connect task: ', getSafeLogTask(task));
1490
1491
  if (task) {
1491
1492
  interruptDevice(task.method?.device);
1492
1493
  if (task.method.connectId) {
@@ -1949,7 +1950,7 @@ export default class Core extends EventEmitter {
1949
1950
  break;
1950
1951
  }
1951
1952
  case IFRAME.CALLBACK: {
1952
- Log.log('callback message: ', message);
1953
+ Log.log('callback message: ', getSafeLogPayload(message));
1953
1954
  postMessage(message);
1954
1955
  break;
1955
1956
  }
@@ -11034,6 +11034,61 @@
11034
11034
  }
11035
11035
  }
11036
11036
  },
11037
+ "ZcashSignPczt": {
11038
+ "fields": {
11039
+ "pczt_length": {
11040
+ "rule": "required",
11041
+ "type": "uint32",
11042
+ "id": 1
11043
+ },
11044
+ "pczt_initial_chunk": {
11045
+ "rule": "required",
11046
+ "type": "bytes",
11047
+ "id": 2
11048
+ }
11049
+ }
11050
+ },
11051
+ "ZcashPcztChunkRequest": {
11052
+ "fields": {
11053
+ "chunk_length": {
11054
+ "rule": "required",
11055
+ "type": "uint32",
11056
+ "id": 1
11057
+ }
11058
+ }
11059
+ },
11060
+ "ZcashPcztChunkAck": {
11061
+ "fields": {
11062
+ "data_chunk": {
11063
+ "rule": "required",
11064
+ "type": "bytes",
11065
+ "id": 1
11066
+ }
11067
+ }
11068
+ },
11069
+ "ZcashSignedPczt": {
11070
+ "fields": {
11071
+ "pczt_length": {
11072
+ "rule": "required",
11073
+ "type": "uint32",
11074
+ "id": 1
11075
+ },
11076
+ "pczt_initial_chunk": {
11077
+ "rule": "required",
11078
+ "type": "bytes",
11079
+ "id": 2
11080
+ }
11081
+ }
11082
+ },
11083
+ "ZcashSignedPcztChunkRequest": {
11084
+ "fields": {
11085
+ "chunk_length": {
11086
+ "rule": "required",
11087
+ "type": "uint32",
11088
+ "id": 1
11089
+ }
11090
+ }
11091
+ },
11037
11092
  "wire_in": {
11038
11093
  "type": "bool",
11039
11094
  "id": 50002,
@@ -11459,6 +11514,11 @@
11459
11514
  "MessageType_NeoAddress": 12302,
11460
11515
  "MessageType_NeoSignTx": 12303,
11461
11516
  "MessageType_NeoSignedTx": 12304,
11517
+ "MessageType_ZcashSignPczt": 12402,
11518
+ "MessageType_ZcashSignedPczt": 12403,
11519
+ "MessageType_ZcashPcztChunkRequest": 12404,
11520
+ "MessageType_ZcashPcztChunkAck": 12405,
11521
+ "MessageType_ZcashSignedPcztChunkRequest": 12406,
11462
11522
  "MessageType_DeviceFactoryInfoSet": 60000,
11463
11523
  "MessageType_DeviceFactoryInfoGet": 60001,
11464
11524
  "MessageType_DeviceFactoryInfo": 60002,
@@ -11511,7 +11571,9 @@
11511
11571
  "MessageType_PortfolioUpdate": 61400,
11512
11572
  "MessageType_NftUpdate": 61500,
11513
11573
  "MessageType_OnboardingStatusGet": 61600,
11514
- "MessageType_OnboardingStatus": 61601
11574
+ "MessageType_OnboardingStatus": 61601,
11575
+ "MessageType_ZcashGetAddress": 12400,
11576
+ "MessageType_ZcashAddress": 12401
11515
11577
  },
11516
11578
  "reserved": [
11517
11579
  [90, 92],
@@ -13730,6 +13792,81 @@
13730
13792
  }
13731
13793
  }
13732
13794
  }
13795
+ },
13796
+ "ZcashAddressType": {
13797
+ "values": {
13798
+ "UNIFIED_ORCHARD_P2PKH": 0,
13799
+ "TRANSPARENT_P2PKH": 1,
13800
+ "UNIFIED_ORCHARD": 2
13801
+ }
13802
+ },
13803
+ "ZcashAddressScope": {
13804
+ "values": {
13805
+ "EXTERNAL": 0,
13806
+ "INTERNAL": 1
13807
+ }
13808
+ },
13809
+ "ZcashGetAddress": {
13810
+ "fields": {
13811
+ "address_n": {
13812
+ "rule": "repeated",
13813
+ "type": "uint32",
13814
+ "id": 1,
13815
+ "options": {
13816
+ "packed": false
13817
+ }
13818
+ },
13819
+ "show_display": {
13820
+ "type": "bool",
13821
+ "id": 2
13822
+ },
13823
+ "include_seed_fingerprint": {
13824
+ "type": "bool",
13825
+ "id": 3
13826
+ },
13827
+ "include_ufvk": {
13828
+ "type": "bool",
13829
+ "id": 4
13830
+ },
13831
+ "diversifier_index": {
13832
+ "type": "uint32",
13833
+ "id": 5,
13834
+ "options": {
13835
+ "default": 0
13836
+ }
13837
+ },
13838
+ "address_type": {
13839
+ "type": "ZcashAddressType",
13840
+ "id": 6,
13841
+ "options": {
13842
+ "default": "UNIFIED_ORCHARD_P2PKH"
13843
+ }
13844
+ },
13845
+ "scope": {
13846
+ "type": "ZcashAddressScope",
13847
+ "id": 7,
13848
+ "options": {
13849
+ "default": "EXTERNAL"
13850
+ }
13851
+ }
13852
+ }
13853
+ },
13854
+ "ZcashAddress": {
13855
+ "fields": {
13856
+ "address": {
13857
+ "rule": "required",
13858
+ "type": "string",
13859
+ "id": 1
13860
+ },
13861
+ "ufvk": {
13862
+ "type": "string",
13863
+ "id": 2
13864
+ },
13865
+ "seed_fingerprint": {
13866
+ "type": "bytes",
13867
+ "id": 3
13868
+ }
13869
+ }
13733
13870
  }
13734
13871
  }
13735
13872
  }
@@ -8,8 +8,8 @@ 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
14
  'btcDeriveContextHash',
15
15
  'deviceUploadNft',
@@ -17,6 +17,12 @@ const LogPayloadBlockMethod: Set<string> = new Set([
17
17
  'uploadPortfolio',
18
18
  'fileWrite',
19
19
  'fileRead',
20
+ 'zcashGetAddress',
21
+ 'zcashSignPczt',
22
+ 'moneroGetAddress',
23
+ 'moneroGetWatchKey',
24
+ 'moneroKeyImageSync',
25
+ 'moneroSignTransaction',
20
26
  ]);
21
27
 
22
28
  export function getLogBlockLabel(message: unknown): string | undefined {
@@ -40,11 +46,57 @@ export function getLogBlockLabel(message: unknown): string | undefined {
40
46
  return undefined;
41
47
  }
42
48
 
49
+ // All-network results of these networks carry what their own address methods
50
+ // keep out of logs (viewing keys, private addresses).
51
+ const LogPayloadBlockNetwork: Set<string> = new Set(['zcash', 'xmr']);
52
+
53
+ type AllNetworkLogItem = { network?: string; success?: boolean; payload?: object | string } | null;
54
+
55
+ // A call response lists the results in `payload`; a loop callback carries one
56
+ // result, or all of them when finished, in `payload.data`.
57
+ type AllNetworkLogMessage = {
58
+ payload?: AllNetworkLogItem[] | { data?: AllNetworkLogItem | AllNetworkLogItem[] };
59
+ };
60
+
61
+ function redactAllNetworkItem(item: AllNetworkLogItem): AllNetworkLogItem {
62
+ if (!item || item.success === false || item.payload === undefined) return item;
63
+ return item.network && LogPayloadBlockNetwork.has(item.network)
64
+ ? { ...item, payload: '[REDACTED]' }
65
+ : item;
66
+ }
67
+
68
+ function redactAllNetworkItems(items: AllNetworkLogItem[]) {
69
+ const redacted = items.map(redactAllNetworkItem);
70
+ return redacted.some((item, index) => item !== items[index]) ? redacted : items;
71
+ }
72
+
73
+ // Returns `message` itself when nothing needs redacting.
74
+ function redactAllNetworkResults(message: AllNetworkLogMessage): AllNetworkLogMessage {
75
+ const { payload } = message;
76
+ if (Array.isArray(payload)) {
77
+ const items = redactAllNetworkItems(payload);
78
+ return items === payload ? message : { ...message, payload: items };
79
+ }
80
+ const data = payload?.data;
81
+ if (!data) return message;
82
+ const redacted = Array.isArray(data) ? redactAllNetworkItems(data) : redactAllNetworkItem(data);
83
+ return redacted === data ? message : { ...message, payload: { ...payload, data: redacted } };
84
+ }
85
+
43
86
  export function getSafeLogPayload(value: unknown, blockLabel?: string): unknown {
44
87
  if (blockLabel) {
45
88
  return { method: blockLabel, payload: '[REDACTED]' };
46
89
  }
47
- return value;
90
+ if (!value || typeof value !== 'object') return value;
91
+ return redactAllNetworkResults(value as AllNetworkLogMessage);
92
+ }
93
+
94
+ // A queued task holds its method's raw payload; redact it like the call.
95
+ export function getSafeLogTask<T extends { id?: number; method?: { payload?: unknown } }>(
96
+ task: T | undefined
97
+ ): T | { id?: number; method: string; payload: string } | undefined {
98
+ const blockLabel = getLogBlockLabel(task?.method?.payload);
99
+ return blockLabel ? { id: task?.id, method: blockLabel, payload: '[REDACTED]' } : task;
48
100
  }
49
101
 
50
102
  export function formatLogMethodLabel(label: string, methodName?: string): string {
@@ -218,6 +218,7 @@ export interface PreviousAddressResult {
218
218
  type: typeof UI_REQUEST.PREVIOUS_ADDRESS_RESULT;
219
219
  payload: {
220
220
  device: Device;
221
+ method: string;
221
222
  data: {
222
223
  address?: string;
223
224
  path?: string;
package/src/inject.ts CHANGED
@@ -504,4 +504,17 @@ export const createCoreApi = (
504
504
  call({ ...params, connectId, deviceId, method: 'neoGetAddress' }),
505
505
  neoSignTransaction: (connectId, deviceId, params) =>
506
506
  call({ ...params, connectId, deviceId, method: 'neoSignTransaction' }),
507
+ zcashGetAddress: (connectId, deviceId, params) =>
508
+ call({ ...params, connectId, deviceId, method: 'zcashGetAddress' }),
509
+ zcashSignPczt: (connectId, deviceId, params) =>
510
+ call({ ...params, connectId, deviceId, method: 'zcashSignPczt' }),
511
+
512
+ moneroGetAddress: (connectId, deviceId, params) =>
513
+ call({ ...params, connectId, deviceId, method: 'moneroGetAddress' }),
514
+ moneroGetWatchKey: (connectId, deviceId, params) =>
515
+ call({ ...params, connectId, deviceId, method: 'moneroGetWatchKey' }),
516
+ moneroKeyImageSync: (connectId, deviceId, params) =>
517
+ call({ ...params, connectId, deviceId, method: 'moneroKeyImageSync' }),
518
+ moneroSignTransaction: (connectId, deviceId, params) =>
519
+ call({ ...params, connectId, deviceId, method: 'moneroSignTransaction' }),
507
520
  });
@@ -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,12 @@ type AllNetworkAddressPayload =
66
68
  // Nostr public key (bech32)
67
69
  npub?: string;
68
70
  }
71
+ | {
72
+ // Zcash
73
+ address: string;
74
+ ufvk?: string;
75
+ seedFingerprint?: string;
76
+ }
69
77
  | {
70
78
  // Cardano
71
79
  addressParameters: CardanoAddressParameters;
@@ -227,3 +227,18 @@ export type { BenfenAddress, BenfenGetAddressParams } from './benfenGetAddress';
227
227
  export type { BenfenPublicKey, BenfenGetPublicKeyParams } from './benfenGetPublicKey';
228
228
  export type { BenfenSignMessageParams } from './benfenSignMessage';
229
229
  export type { BenfenSignedTx, BenfenSignTransactionParams } from './benfenSignTransaction';
230
+ export type { ZcashAddress, ZcashGetAddressParams } from './zcashGetAddress';
231
+ export type { ZcashSignedPczt, ZcashSignPcztParams } from './zcashSignPczt';
232
+
233
+ export type { MoneroAddress, MoneroGetAddressParams } from './moneroGetAddress';
234
+ export type { MoneroGetWatchKeyParams, MoneroWatchKey } from './moneroGetWatchKey';
235
+ export type {
236
+ MoneroEncryptedKeyImage,
237
+ MoneroKeyImageSyncParams,
238
+ MoneroKeyImageSyncResult,
239
+ MoneroKeyImageTransfer,
240
+ } from './moneroKeyImageSync';
241
+ export type {
242
+ MoneroSignTransactionParams,
243
+ MoneroSignTransactionResult,
244
+ } from './moneroSignTransaction';
@@ -154,6 +154,12 @@ import type { benfenSignTransaction } from './benfenSignTransaction';
154
154
  import type { benfenSignMessage } from './benfenSignMessage';
155
155
  import type { neoGetAddress } from './neoGetAddress';
156
156
  import type { neoSignTransaction } from './neoSignTransaction';
157
+ import type { zcashGetAddress } from './zcashGetAddress';
158
+ import type { zcashSignPczt } from './zcashSignPczt';
159
+ import type { moneroGetAddress } from './moneroGetAddress';
160
+ import type { moneroGetWatchKey } from './moneroGetWatchKey';
161
+ import type { moneroKeyImageSync } from './moneroKeyImageSync';
162
+ import type { moneroSignTransaction } from './moneroSignTransaction';
157
163
  import type { ConnectSettings } from '../settings';
158
164
  import type { HardwareConnectProtocol } from '@onekeyfe/hd-shared';
159
165
 
@@ -472,4 +478,18 @@ export type CoreApi = {
472
478
  */
473
479
  neoGetAddress: typeof neoGetAddress;
474
480
  neoSignTransaction: typeof neoSignTransaction;
481
+
482
+ /**
483
+ * Zcash
484
+ */
485
+ zcashGetAddress: typeof zcashGetAddress;
486
+ zcashSignPczt: typeof zcashSignPczt;
487
+
488
+ /**
489
+ * Monero
490
+ */
491
+ moneroGetAddress: typeof moneroGetAddress;
492
+ moneroGetWatchKey: typeof moneroGetWatchKey;
493
+ moneroKeyImageSync: typeof moneroKeyImageSync;
494
+ moneroSignTransaction: typeof moneroSignTransaction;
475
495
  };
@@ -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>>;
@@ -0,0 +1,28 @@
1
+ import type { CommonParams, Response } from '../params';
2
+
3
+ export type MoneroWatchKey = {
4
+ path: string;
5
+ // Private view key, hex
6
+ watchKey: string;
7
+ // Primary address of the account, base58
8
+ address: string;
9
+ };
10
+
11
+ export type MoneroGetWatchKeyParams = {
12
+ // Account path, m/44'/128'/account'
13
+ path: string | number[];
14
+ // 0 mainnet, 1 testnet, 2 stagenet
15
+ networkType?: number;
16
+ };
17
+
18
+ export declare function moneroGetWatchKey(
19
+ connectId: string,
20
+ deviceId: string,
21
+ params: CommonParams & MoneroGetWatchKeyParams
22
+ ): Response<MoneroWatchKey>;
23
+
24
+ export declare function moneroGetWatchKey(
25
+ connectId: string,
26
+ deviceId: string,
27
+ params: CommonParams & { bundle?: MoneroGetWatchKeyParams[] }
28
+ ): Response<Array<MoneroWatchKey>>;
@@ -0,0 +1,45 @@
1
+ import type { CommonParams, Response } from '../params';
2
+
3
+ // One owned output, as wallet2 describes it to the device. Keys are 32-byte hex.
4
+ export type MoneroKeyImageTransfer = {
5
+ // Output public key
6
+ outKey: string;
7
+ // Transaction public key R
8
+ txPubKey: string;
9
+ // Additional tx public keys: the one for this output, or the whole list
10
+ additionalTxPubKeys?: string[];
11
+ // Index of the output within its transaction
12
+ internalOutputIndex: number;
13
+ // Receiving subaddress index; omitted means 0 (primary address)
14
+ subAddrMajor?: number;
15
+ subAddrMinor?: number;
16
+ };
17
+
18
+ // ChaCha20-Poly1305 under encKey, hex.
19
+ export type MoneroEncryptedKeyImage = {
20
+ // 12-byte nonce
21
+ iv: string;
22
+ // Ciphertext of key image || signature c || signature r, then the 16-byte tag
23
+ blob: string;
24
+ };
25
+
26
+ export type MoneroKeyImageSyncResult = {
27
+ // Key that decrypts every blob, hex
28
+ encKey: string;
29
+ // One entry per transfer, in request order
30
+ keyImages: MoneroEncryptedKeyImage[];
31
+ };
32
+
33
+ export type MoneroKeyImageSyncParams = {
34
+ // Account path, m/44'/128'/account'
35
+ path: string | number[];
36
+ // 0 mainnet, 1 testnet, 2 stagenet
37
+ networkType?: number;
38
+ transfers: MoneroKeyImageTransfer[];
39
+ };
40
+
41
+ export declare function moneroKeyImageSync(
42
+ connectId: string,
43
+ deviceId: string,
44
+ params: CommonParams & MoneroKeyImageSyncParams
45
+ ): Response<MoneroKeyImageSyncResult>;