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

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
package/dist/index.js CHANGED
@@ -1721,6 +1721,12 @@ const createCoreApi = (call) => ({
1721
1721
  benfenSignMessage: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'benfenSignMessage' })),
1722
1722
  neoGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'neoGetAddress' })),
1723
1723
  neoSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'neoSignTransaction' })),
1724
+ zcashGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'zcashGetAddress' })),
1725
+ zcashSignPczt: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'zcashSignPczt' })),
1726
+ moneroGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'moneroGetAddress' })),
1727
+ moneroGetWatchKey: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'moneroGetWatchKey' })),
1728
+ moneroKeyImageSync: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'moneroKeyImageSync' })),
1729
+ moneroSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'moneroSignTransaction' })),
1724
1730
  });
1725
1731
 
1726
1732
  const lowLevelInject = ({ call, cancel, dispose, eventEmitter, init, uiResponse, updateSettings, switchTransport, addHardwareGlobalEventListener, }) => {
@@ -2439,6 +2445,12 @@ const LogPayloadBlockMethod = new Set([
2439
2445
  'uploadPortfolio',
2440
2446
  'fileWrite',
2441
2447
  'fileRead',
2448
+ 'zcashGetAddress',
2449
+ 'zcashSignPczt',
2450
+ 'moneroGetAddress',
2451
+ 'moneroGetWatchKey',
2452
+ 'moneroKeyImageSync',
2453
+ 'moneroSignTransaction',
2442
2454
  ]);
2443
2455
  function getLogBlockLabel(message) {
2444
2456
  if (!message || typeof message !== 'object')
@@ -2453,11 +2465,41 @@ function getLogBlockLabel(message) {
2453
2465
  }
2454
2466
  return undefined;
2455
2467
  }
2468
+ const LogPayloadBlockNetwork = new Set(['zcash', 'xmr']);
2469
+ function redactAllNetworkItem(item) {
2470
+ if (!item || item.success === false || item.payload === undefined)
2471
+ return item;
2472
+ return item.network && LogPayloadBlockNetwork.has(item.network)
2473
+ ? Object.assign(Object.assign({}, item), { payload: '[REDACTED]' }) : item;
2474
+ }
2475
+ function redactAllNetworkItems(items) {
2476
+ const redacted = items.map(redactAllNetworkItem);
2477
+ return redacted.some((item, index) => item !== items[index]) ? redacted : items;
2478
+ }
2479
+ function redactAllNetworkResults(message) {
2480
+ const { payload } = message;
2481
+ if (Array.isArray(payload)) {
2482
+ const items = redactAllNetworkItems(payload);
2483
+ return items === payload ? message : Object.assign(Object.assign({}, message), { payload: items });
2484
+ }
2485
+ const data = payload === null || payload === void 0 ? void 0 : payload.data;
2486
+ if (!data)
2487
+ return message;
2488
+ const redacted = Array.isArray(data) ? redactAllNetworkItems(data) : redactAllNetworkItem(data);
2489
+ return redacted === data ? message : Object.assign(Object.assign({}, message), { payload: Object.assign(Object.assign({}, payload), { data: redacted }) });
2490
+ }
2456
2491
  function getSafeLogPayload(value, blockLabel) {
2457
2492
  if (blockLabel) {
2458
2493
  return { method: blockLabel, payload: '[REDACTED]' };
2459
2494
  }
2460
- return value;
2495
+ if (!value || typeof value !== 'object')
2496
+ return value;
2497
+ return redactAllNetworkResults(value);
2498
+ }
2499
+ function getSafeLogTask(task) {
2500
+ var _a;
2501
+ const blockLabel = getLogBlockLabel((_a = task === null || task === void 0 ? void 0 : task.method) === null || _a === void 0 ? void 0 : _a.payload);
2502
+ return blockLabel ? { id: task === null || task === void 0 ? void 0 : task.id, method: blockLabel, payload: '[REDACTED]' } : task;
2461
2503
  }
2462
2504
  function formatLogMethodLabel(label, methodName) {
2463
2505
  return methodName ? `${label} [${methodName}]` : label;
@@ -2574,6 +2616,25 @@ const validatePath = (path, length = 0, base = false) => {
2574
2616
  throw PATH_NOT_VALID;
2575
2617
  return base ? valid.splice(0, 3) : valid;
2576
2618
  };
2619
+ const isTextIndex = (part) => {
2620
+ var _a;
2621
+ const digits = (_a = /^(\d+)'?$/.exec(part)) === null || _a === void 0 ? void 0 : _a[1];
2622
+ return digits !== undefined && Number(digits) < HD_HARDENED;
2623
+ };
2624
+ const isUint32 = (n) => Number.isInteger(n) && n >= 0 && n <= 0xffffffff;
2625
+ const validateStrictPath = (path, length = 0) => {
2626
+ const addressN = validatePath(path, length);
2627
+ const isStrict = typeof path === 'string'
2628
+ ? path
2629
+ .toLowerCase()
2630
+ .split('/')
2631
+ .filter(p => p !== 'm' && p !== '')
2632
+ .every(isTextIndex)
2633
+ : path.every(isUint32);
2634
+ if (!isStrict)
2635
+ throw PATH_NOT_VALID;
2636
+ return addressN;
2637
+ };
2577
2638
 
2578
2639
  const pkg = require('../package.json');
2579
2640
  const getSDKVersion = () => pkg.version;
@@ -37942,6 +38003,61 @@ var nested = {
37942
38003
  }
37943
38004
  }
37944
38005
  },
38006
+ ZcashSignPczt: {
38007
+ fields: {
38008
+ pczt_length: {
38009
+ rule: "required",
38010
+ type: "uint32",
38011
+ id: 1
38012
+ },
38013
+ pczt_initial_chunk: {
38014
+ rule: "required",
38015
+ type: "bytes",
38016
+ id: 2
38017
+ }
38018
+ }
38019
+ },
38020
+ ZcashPcztChunkRequest: {
38021
+ fields: {
38022
+ chunk_length: {
38023
+ rule: "required",
38024
+ type: "uint32",
38025
+ id: 1
38026
+ }
38027
+ }
38028
+ },
38029
+ ZcashPcztChunkAck: {
38030
+ fields: {
38031
+ data_chunk: {
38032
+ rule: "required",
38033
+ type: "bytes",
38034
+ id: 1
38035
+ }
38036
+ }
38037
+ },
38038
+ ZcashSignedPczt: {
38039
+ fields: {
38040
+ pczt_length: {
38041
+ rule: "required",
38042
+ type: "uint32",
38043
+ id: 1
38044
+ },
38045
+ pczt_initial_chunk: {
38046
+ rule: "required",
38047
+ type: "bytes",
38048
+ id: 2
38049
+ }
38050
+ }
38051
+ },
38052
+ ZcashSignedPcztChunkRequest: {
38053
+ fields: {
38054
+ chunk_length: {
38055
+ rule: "required",
38056
+ type: "uint32",
38057
+ id: 1
38058
+ }
38059
+ }
38060
+ },
37945
38061
  wire_in: {
37946
38062
  type: "bool",
37947
38063
  id: 50002,
@@ -38367,6 +38483,11 @@ var nested = {
38367
38483
  MessageType_NeoAddress: 12302,
38368
38484
  MessageType_NeoSignTx: 12303,
38369
38485
  MessageType_NeoSignedTx: 12304,
38486
+ MessageType_ZcashSignPczt: 12402,
38487
+ MessageType_ZcashSignedPczt: 12403,
38488
+ MessageType_ZcashPcztChunkRequest: 12404,
38489
+ MessageType_ZcashPcztChunkAck: 12405,
38490
+ MessageType_ZcashSignedPcztChunkRequest: 12406,
38370
38491
  MessageType_DeviceFactoryInfoSet: 60000,
38371
38492
  MessageType_DeviceFactoryInfoGet: 60001,
38372
38493
  MessageType_DeviceFactoryInfo: 60002,
@@ -38419,7 +38540,9 @@ var nested = {
38419
38540
  MessageType_PortfolioUpdate: 61400,
38420
38541
  MessageType_NftUpdate: 61500,
38421
38542
  MessageType_OnboardingStatusGet: 61600,
38422
- MessageType_OnboardingStatus: 61601
38543
+ MessageType_OnboardingStatus: 61601,
38544
+ MessageType_ZcashGetAddress: 12400,
38545
+ MessageType_ZcashAddress: 12401
38423
38546
  },
38424
38547
  reserved: [
38425
38548
  [
@@ -40724,6 +40847,81 @@ var nested = {
40724
40847
  }
40725
40848
  }
40726
40849
  }
40850
+ },
40851
+ ZcashAddressType: {
40852
+ values: {
40853
+ UNIFIED_ORCHARD_P2PKH: 0,
40854
+ TRANSPARENT_P2PKH: 1,
40855
+ UNIFIED_ORCHARD: 2
40856
+ }
40857
+ },
40858
+ ZcashAddressScope: {
40859
+ values: {
40860
+ EXTERNAL: 0,
40861
+ INTERNAL: 1
40862
+ }
40863
+ },
40864
+ ZcashGetAddress: {
40865
+ fields: {
40866
+ address_n: {
40867
+ rule: "repeated",
40868
+ type: "uint32",
40869
+ id: 1,
40870
+ options: {
40871
+ packed: false
40872
+ }
40873
+ },
40874
+ show_display: {
40875
+ type: "bool",
40876
+ id: 2
40877
+ },
40878
+ include_seed_fingerprint: {
40879
+ type: "bool",
40880
+ id: 3
40881
+ },
40882
+ include_ufvk: {
40883
+ type: "bool",
40884
+ id: 4
40885
+ },
40886
+ diversifier_index: {
40887
+ type: "uint32",
40888
+ id: 5,
40889
+ options: {
40890
+ "default": 0
40891
+ }
40892
+ },
40893
+ address_type: {
40894
+ type: "ZcashAddressType",
40895
+ id: 6,
40896
+ options: {
40897
+ "default": "UNIFIED_ORCHARD_P2PKH"
40898
+ }
40899
+ },
40900
+ scope: {
40901
+ type: "ZcashAddressScope",
40902
+ id: 7,
40903
+ options: {
40904
+ "default": "EXTERNAL"
40905
+ }
40906
+ }
40907
+ }
40908
+ },
40909
+ ZcashAddress: {
40910
+ fields: {
40911
+ address: {
40912
+ rule: "required",
40913
+ type: "string",
40914
+ id: 1
40915
+ },
40916
+ ufvk: {
40917
+ type: "string",
40918
+ id: 2
40919
+ },
40920
+ seed_fingerprint: {
40921
+ type: "bytes",
40922
+ id: 3
40923
+ }
40924
+ }
40727
40925
  }
40728
40926
  };
40729
40927
  var MessagesProtocolV2JSON = {
@@ -43561,6 +43759,7 @@ class BaseMethod {
43561
43759
  this.postPreviousAddressMessage = (data) => {
43562
43760
  this.postMessage(createUiMessage(UI_REQUEST.PREVIOUS_ADDRESS_RESULT, {
43563
43761
  device: this.device.toMessageObject(),
43762
+ method: this.name,
43564
43763
  data,
43565
43764
  }));
43566
43765
  };
@@ -47828,7 +48027,7 @@ function parseChainId(chainId) {
47828
48027
  }
47829
48028
 
47830
48029
  const invalidParameter = (message) => hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, message);
47831
- const invalidResponse = (message) => hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodError, message);
48030
+ const invalidResponse$1 = (message) => hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodError, message);
47832
48031
  const validateParams = (values, fields) => {
47833
48032
  fields.forEach(field => {
47834
48033
  const existsProp = Object.prototype.hasOwnProperty.call(values, field.name);
@@ -47905,12 +48104,12 @@ const validateParams = (values, fields) => {
47905
48104
  function validateResult(result, nonNullableFields, options) {
47906
48105
  if (Array.isArray(result)) {
47907
48106
  if ((options === null || options === void 0 ? void 0 : options.expectedLength) !== null && result.length !== (options === null || options === void 0 ? void 0 : options.expectedLength)) {
47908
- throw invalidResponse(`Expected array length of ${options === null || options === void 0 ? void 0 : options.expectedLength}, but got ${result.length}`);
48107
+ throw invalidResponse$1(`Expected array length of ${options === null || options === void 0 ? void 0 : options.expectedLength}, but got ${result.length}`);
47909
48108
  }
47910
48109
  result.forEach((item, index) => {
47911
48110
  nonNullableFields.forEach(field => {
47912
48111
  if (item[field] == null) {
47913
- throw invalidResponse(`Field '${field}' in array item at index ${index} is null`);
48112
+ throw invalidResponse$1(`Field '${field}' in array item at index ${index} is null`);
47914
48113
  }
47915
48114
  });
47916
48115
  });
@@ -47918,12 +48117,12 @@ function validateResult(result, nonNullableFields, options) {
47918
48117
  else if (typeof result === 'object' && result !== null) {
47919
48118
  nonNullableFields.forEach(field => {
47920
48119
  if (result[field] == null) {
47921
- throw invalidResponse(`Field '${field}' in object is null`);
48120
+ throw invalidResponse$1(`Field '${field}' in object is null`);
47922
48121
  }
47923
48122
  });
47924
48123
  }
47925
48124
  else {
47926
- throw invalidResponse('Result is neither an array nor a valid object');
48125
+ throw invalidResponse$1('Result is neither an array nor a valid object');
47927
48126
  }
47928
48127
  }
47929
48128
 
@@ -56204,6 +56403,11 @@ function runMethodWithUnlockPolicy(method, device, options = {}) {
56204
56403
  }
56205
56404
 
56206
56405
  const Mainnet = 'mainnet';
56406
+ const MoneroNetworkTypes = new Map([
56407
+ [Mainnet, hdTransport.Messages.MoneroNetworkType.MAINNET],
56408
+ ['testnet', hdTransport.Messages.MoneroNetworkType.TESTNET],
56409
+ ['stagenet', hdTransport.Messages.MoneroNetworkType.STAGENET],
56410
+ ]);
56207
56411
  const networkAliases = {
56208
56412
  tbtc: { name: 'btc', coin: 'Testnet' },
56209
56413
  bch: { name: 'btc', coin: 'Bcash' },
@@ -56392,6 +56596,36 @@ const networkConfigMap = {
56392
56596
  stellar: {
56393
56597
  methodName: 'stellarGetAddress',
56394
56598
  },
56599
+ xmr: {
56600
+ methodName: 'moneroGetAddress',
56601
+ getParams: (baseParams, chainName) => {
56602
+ const { path, showOnOneKey } = baseParams;
56603
+ const networkType = MoneroNetworkTypes.get(chainName !== null && chainName !== void 0 ? chainName : Mainnet);
56604
+ if (networkType === undefined) {
56605
+ throw invalidParameter(`Unsupported Monero chainName: ${chainName}`);
56606
+ }
56607
+ return {
56608
+ path,
56609
+ networkType,
56610
+ showOnOneKey,
56611
+ };
56612
+ },
56613
+ },
56614
+ zcash: {
56615
+ methodName: 'zcashGetAddress',
56616
+ getParams: (baseParams) => {
56617
+ const { path, showOnOneKey } = baseParams;
56618
+ return {
56619
+ path,
56620
+ showOnOneKey,
56621
+ addressType: hdTransport.Messages.ZcashAddressType.UNIFIED_ORCHARD,
56622
+ scope: hdTransport.Messages.ZcashAddressScope.EXTERNAL,
56623
+ diversifierIndex: 0,
56624
+ includeUfvk: true,
56625
+ includeSeedFingerprint: true,
56626
+ };
56627
+ },
56628
+ },
56395
56629
  };
56396
56630
  class AllNetworkGetAddressBase extends BaseMethod {
56397
56631
  constructor() {
@@ -65868,6 +66102,620 @@ class NeoSignTransaction extends BaseMethod {
65868
66102
  }
65869
66103
  }
65870
66104
 
66105
+ class ZcashGetAddress extends BaseMethod {
66106
+ constructor() {
66107
+ super(...arguments);
66108
+ this.hasBundle = false;
66109
+ }
66110
+ getSupportedProtocols() {
66111
+ return ['V2'];
66112
+ }
66113
+ init() {
66114
+ var _a;
66115
+ this.checkDeviceId = true;
66116
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
66117
+ this.strictCheckDeviceSupport = true;
66118
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
66119
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
66120
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
66121
+ this.params = [];
66122
+ payload.bundle.forEach((batch) => {
66123
+ var _a, _b, _c, _d, _e, _f;
66124
+ const addressN = validateStrictPath(batch.path, 3);
66125
+ if (addressN.length !== 3 ||
66126
+ addressN[0] !== toHardened(32) ||
66127
+ addressN[1] !== toHardened(133) ||
66128
+ addressN[2] < toHardened(0)) {
66129
+ throw invalidParameter("Zcash requires a ZIP-32 account path m/32'/133'/account'");
66130
+ }
66131
+ const addressType = (_a = batch.addressType) !== null && _a !== void 0 ? _a : hdTransport.ZcashAddressType.UNIFIED_ORCHARD_P2PKH;
66132
+ const scope = (_b = batch.scope) !== null && _b !== void 0 ? _b : hdTransport.ZcashAddressScope.EXTERNAL;
66133
+ const diversifierIndex = (_c = batch.diversifierIndex) !== null && _c !== void 0 ? _c : 0;
66134
+ if (![
66135
+ hdTransport.ZcashAddressType.UNIFIED_ORCHARD_P2PKH,
66136
+ hdTransport.ZcashAddressType.TRANSPARENT_P2PKH,
66137
+ hdTransport.ZcashAddressType.UNIFIED_ORCHARD,
66138
+ ].includes(addressType) ||
66139
+ ![hdTransport.ZcashAddressScope.EXTERNAL, hdTransport.ZcashAddressScope.INTERNAL].includes(scope)) {
66140
+ throw invalidParameter('Invalid Zcash address type or scope');
66141
+ }
66142
+ const maxIndex = addressType === hdTransport.ZcashAddressType.UNIFIED_ORCHARD ? 0xffffffff : 0x7fffffff;
66143
+ if (!Number.isSafeInteger(diversifierIndex) ||
66144
+ diversifierIndex < 0 ||
66145
+ diversifierIndex > maxIndex) {
66146
+ throw invalidParameter('Invalid Zcash diversifier index');
66147
+ }
66148
+ validateParams(batch, [
66149
+ { name: 'path', required: true },
66150
+ { name: 'showOnOneKey', type: 'boolean' },
66151
+ { name: 'includeUfvk', type: 'boolean' },
66152
+ { name: 'includeSeedFingerprint', type: 'boolean' },
66153
+ ]);
66154
+ this.params.push({
66155
+ address_n: addressN,
66156
+ address_type: addressType,
66157
+ scope,
66158
+ diversifier_index: diversifierIndex,
66159
+ show_display: (_d = batch.showOnOneKey) !== null && _d !== void 0 ? _d : true,
66160
+ include_ufvk: (_e = batch.includeUfvk) !== null && _e !== void 0 ? _e : false,
66161
+ include_seed_fingerprint: (_f = batch.includeSeedFingerprint) !== null && _f !== void 0 ? _f : false,
66162
+ });
66163
+ });
66164
+ }
66165
+ getVersionRange() {
66166
+ return {
66167
+ model_pro2: {
66168
+ min: '0.0.0',
66169
+ },
66170
+ };
66171
+ }
66172
+ run() {
66173
+ return __awaiter(this, void 0, void 0, function* () {
66174
+ const responses = [];
66175
+ for (let i = 0; i < this.params.length; i++) {
66176
+ const param = this.params[i];
66177
+ const res = yield this.device.commands.typedCall('ZcashGetAddress', 'ZcashAddress', Object.assign({}, param));
66178
+ const path = serializedPath(param.address_n);
66179
+ const { address, ufvk, seed_fingerprint: seedFingerprint } = res.message;
66180
+ responses.push(Object.assign(Object.assign({ path,
66181
+ address }, (ufvk ? { ufvk } : {})), (seedFingerprint ? { seedFingerprint } : {})));
66182
+ this.postPreviousAddressMessage({ address, path });
66183
+ }
66184
+ validateResult(responses, ['address'], {
66185
+ expectedLength: this.params.length,
66186
+ });
66187
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
66188
+ });
66189
+ }
66190
+ }
66191
+
66192
+ const CHUNK_BYTE_SIZE = 1024;
66193
+ const SIGNED_PCZT_SANITY_MAX_BYTES = 16 * 1024 * 1024;
66194
+ class ZcashSignPczt extends BaseMethod {
66195
+ constructor() {
66196
+ super(...arguments);
66197
+ this.pczt = Buffer.alloc(0);
66198
+ this.uploadPczt = (typedCall, first, initialOffset) => __awaiter(this, void 0, void 0, function* () {
66199
+ let res = first;
66200
+ let offset = initialOffset;
66201
+ while (res.type === 'ZcashPcztChunkRequest') {
66202
+ const { chunk_length: chunkLength } = res.message;
66203
+ if (!Number.isSafeInteger(chunkLength) ||
66204
+ chunkLength <= 0 ||
66205
+ offset + chunkLength > this.pczt.length) {
66206
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ResponseUnexpectTypeError, `device requested ${chunkLength} bytes at offset ${offset} of ${this.pczt.length}`);
66207
+ }
66208
+ const chunk = this.pczt.subarray(offset, offset + chunkLength);
66209
+ res = yield typedCall('ZcashPcztChunkAck', ['ZcashSignedPczt', 'ZcashPcztChunkRequest'], {
66210
+ data_chunk: utils.bytesToHex(chunk),
66211
+ });
66212
+ offset += chunkLength;
66213
+ }
66214
+ if (offset !== this.pczt.length) {
66215
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ResponseUnexpectTypeError, 'device completed signing before receiving the whole pczt');
66216
+ }
66217
+ return res;
66218
+ });
66219
+ this.downloadSignedPczt = (typedCall, res) => __awaiter(this, void 0, void 0, function* () {
66220
+ var _a;
66221
+ const { pczt_length: total, pczt_initial_chunk: initial } = res.message;
66222
+ if (!Number.isSafeInteger(total) || total <= 0 || total > SIGNED_PCZT_SANITY_MAX_BYTES) {
66223
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ResponseUnexpectTypeError, `device announced invalid signed pczt length ${total}`);
66224
+ }
66225
+ const parts = [Buffer.from(initial !== null && initial !== void 0 ? initial : '', 'hex')];
66226
+ let received = parts[0].length;
66227
+ if (received > total) {
66228
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ResponseUnexpectTypeError, 'device returned more initial pczt bytes than announced');
66229
+ }
66230
+ while (received < total) {
66231
+ const chunkLength = Math.min(CHUNK_BYTE_SIZE, total - received);
66232
+ const ack = yield typedCall('ZcashSignedPcztChunkRequest', 'ZcashPcztChunkAck', {
66233
+ chunk_length: chunkLength,
66234
+ });
66235
+ const chunk = Buffer.from((_a = ack.message.data_chunk) !== null && _a !== void 0 ? _a : '', 'hex');
66236
+ if (chunk.length !== chunkLength) {
66237
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ResponseUnexpectTypeError, `device returned ${chunk.length} of ${chunkLength} requested bytes at offset ${received} of ${total}`);
66238
+ }
66239
+ parts.push(chunk);
66240
+ received += chunk.length;
66241
+ }
66242
+ return Buffer.concat(parts);
66243
+ });
66244
+ }
66245
+ getSupportedProtocols() {
66246
+ return ['V2'];
66247
+ }
66248
+ init() {
66249
+ this.checkDeviceId = true;
66250
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
66251
+ this.strictCheckDeviceSupport = true;
66252
+ validateParams(this.payload, [{ name: 'pczt', type: 'hexString', required: true }]);
66253
+ const pcztHex = stripHexPrefix(this.payload.pczt);
66254
+ if (pcztHex.length % 2 !== 0) {
66255
+ throw invalidParameter('pczt hex must have an even length');
66256
+ }
66257
+ this.pczt = Buffer.from(pcztHex, 'hex');
66258
+ if (this.pczt.length === 0) {
66259
+ throw invalidParameter('pczt is empty');
66260
+ }
66261
+ this.params = {
66262
+ pczt_length: this.pczt.length,
66263
+ pczt_initial_chunk: utils.bytesToHex(this.pczt.subarray(0, CHUNK_BYTE_SIZE)),
66264
+ };
66265
+ }
66266
+ getVersionRange() {
66267
+ return {
66268
+ model_pro2: {
66269
+ min: '0.0.0',
66270
+ },
66271
+ };
66272
+ }
66273
+ run() {
66274
+ return __awaiter(this, void 0, void 0, function* () {
66275
+ const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
66276
+ const first = yield typedCall('ZcashSignPczt', ['ZcashSignedPczt', 'ZcashPcztChunkRequest'], Object.assign({}, this.params));
66277
+ const signed = yield this.uploadPczt(typedCall, first, Math.min(CHUNK_BYTE_SIZE, this.pczt.length));
66278
+ const pczt = yield this.downloadSignedPczt(typedCall, signed);
66279
+ return { pczt: utils.bytesToHex(pczt) };
66280
+ });
66281
+ }
66282
+ }
66283
+
66284
+ const NETWORK_TYPES = [0, 1, 2];
66285
+ function validateMoneroNetworkType(networkType) {
66286
+ const value = networkType !== null && networkType !== void 0 ? networkType : 0;
66287
+ if (!NETWORK_TYPES.includes(value)) {
66288
+ throw invalidParameter('Invalid Monero network type');
66289
+ }
66290
+ return value;
66291
+ }
66292
+ function decodeMoneroAddress(hex) {
66293
+ return hex ? Buffer.from(hexToBytes(hex)).toString('utf-8') : undefined;
66294
+ }
66295
+ function getMoneroVersionRange() {
66296
+ return {
66297
+ model_touch: {
66298
+ min: '0.0.0',
66299
+ },
66300
+ };
66301
+ }
66302
+
66303
+ class MoneroGetAddress extends BaseMethod {
66304
+ constructor() {
66305
+ super(...arguments);
66306
+ this.hasBundle = false;
66307
+ }
66308
+ getSupportedProtocols() {
66309
+ return ['V1', 'V2'];
66310
+ }
66311
+ init() {
66312
+ var _a;
66313
+ this.checkDeviceId = true;
66314
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
66315
+ this.strictCheckDeviceSupport = true;
66316
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
66317
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
66318
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
66319
+ this.params = [];
66320
+ payload.bundle.forEach((batch) => {
66321
+ var _a;
66322
+ validateParams(batch, [
66323
+ { name: 'path', required: true },
66324
+ { name: 'showOnOneKey', type: 'boolean' },
66325
+ { name: 'networkType', type: 'number' },
66326
+ ]);
66327
+ this.params.push({
66328
+ address_n: validateStrictPath(batch.path, 3),
66329
+ network_type: validateMoneroNetworkType(batch.networkType),
66330
+ show_display: (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true,
66331
+ });
66332
+ });
66333
+ }
66334
+ getVersionRange() {
66335
+ return getMoneroVersionRange();
66336
+ }
66337
+ run() {
66338
+ return __awaiter(this, void 0, void 0, function* () {
66339
+ const responses = [];
66340
+ for (let i = 0; i < this.params.length; i++) {
66341
+ const param = this.params[i];
66342
+ const res = yield this.device.commands.typedCall('MoneroGetAddress', 'MoneroAddress', Object.assign({}, param));
66343
+ const path = serializedPath(param.address_n);
66344
+ const address = decodeMoneroAddress(res.message.address);
66345
+ responses.push({ path, address });
66346
+ this.postPreviousAddressMessage({ address, path });
66347
+ }
66348
+ validateResult(responses, ['address'], {
66349
+ expectedLength: this.params.length,
66350
+ });
66351
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
66352
+ });
66353
+ }
66354
+ }
66355
+
66356
+ class MoneroGetWatchKey extends BaseMethod {
66357
+ constructor() {
66358
+ super(...arguments);
66359
+ this.hasBundle = false;
66360
+ }
66361
+ getSupportedProtocols() {
66362
+ return ['V1', 'V2'];
66363
+ }
66364
+ init() {
66365
+ var _a;
66366
+ this.checkDeviceId = true;
66367
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
66368
+ this.strictCheckDeviceSupport = true;
66369
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
66370
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
66371
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
66372
+ this.params = [];
66373
+ payload.bundle.forEach((batch) => {
66374
+ validateParams(batch, [
66375
+ { name: 'path', required: true },
66376
+ { name: 'networkType', type: 'number' },
66377
+ ]);
66378
+ this.params.push({
66379
+ address_n: validateStrictPath(batch.path, 3),
66380
+ network_type: validateMoneroNetworkType(batch.networkType),
66381
+ });
66382
+ });
66383
+ }
66384
+ getVersionRange() {
66385
+ return getMoneroVersionRange();
66386
+ }
66387
+ run() {
66388
+ return __awaiter(this, void 0, void 0, function* () {
66389
+ const responses = [];
66390
+ for (let i = 0; i < this.params.length; i++) {
66391
+ const param = this.params[i];
66392
+ const res = yield this.device.commands.typedCall('MoneroGetWatchKey', 'MoneroWatchKey', Object.assign({}, param));
66393
+ responses.push({
66394
+ path: serializedPath(param.address_n),
66395
+ watchKey: res.message.watch_key,
66396
+ address: decodeMoneroAddress(res.message.address),
66397
+ });
66398
+ }
66399
+ validateResult(responses, ['watchKey', 'address'], {
66400
+ expectedLength: this.params.length,
66401
+ });
66402
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
66403
+ });
66404
+ }
66405
+ }
66406
+
66407
+ const STEP_SIZE = 10;
66408
+ const UINT32_MAX = 0xffffffff;
66409
+ const parseKey = (value, name) => {
66410
+ const hex = typeof value === 'string' ? stripHexPrefix(value) : '';
66411
+ if (!/^[0-9a-fA-F]{64}$/.test(hex)) {
66412
+ throw invalidParameter(`${name} must be a 32-byte hex string`);
66413
+ }
66414
+ return hex.toLowerCase();
66415
+ };
66416
+ const parseUint = (value, name, max = Number.MAX_SAFE_INTEGER) => {
66417
+ if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0 || value > max) {
66418
+ throw invalidParameter(`${name} must be an unsigned integer`);
66419
+ }
66420
+ return value;
66421
+ };
66422
+ const parseTransfer = (transfer, index) => {
66423
+ var _a, _b, _c;
66424
+ const name = `transfers[${index}]`;
66425
+ if (!transfer || typeof transfer !== 'object') {
66426
+ throw invalidParameter(`${name} must be an object`);
66427
+ }
66428
+ const additional = (_a = transfer.additionalTxPubKeys) !== null && _a !== void 0 ? _a : [];
66429
+ if (!Array.isArray(additional)) {
66430
+ throw invalidParameter(`${name}.additionalTxPubKeys must be an array`);
66431
+ }
66432
+ return {
66433
+ out_key: parseKey(transfer.outKey, `${name}.outKey`),
66434
+ tx_pub_key: parseKey(transfer.txPubKey, `${name}.txPubKey`),
66435
+ additional_tx_pub_keys: additional.map((key, i) => parseKey(key, `${name}.additionalTxPubKeys[${i}]`)),
66436
+ internal_output_index: parseUint(transfer.internalOutputIndex, `${name}.internalOutputIndex`),
66437
+ sub_addr_major: parseUint((_b = transfer.subAddrMajor) !== null && _b !== void 0 ? _b : 0, `${name}.subAddrMajor`, UINT32_MAX),
66438
+ sub_addr_minor: parseUint((_c = transfer.subAddrMinor) !== null && _c !== void 0 ? _c : 0, `${name}.subAddrMinor`, UINT32_MAX),
66439
+ };
66440
+ };
66441
+ const encodeUvarint = (value) => {
66442
+ const bytes = [];
66443
+ let n = value;
66444
+ while (n >= 0x80) {
66445
+ bytes.push((n % 0x80) + 0x80);
66446
+ n = Math.floor(n / 0x80);
66447
+ }
66448
+ bytes.push(n);
66449
+ return Uint8Array.from(bytes);
66450
+ };
66451
+ const computeTransfersHash = (tdis) => {
66452
+ const total = sha3.keccak_256.create();
66453
+ tdis.forEach(td => {
66454
+ const hash = sha3.keccak_256.create();
66455
+ hash.update(hexToBytes(td.out_key));
66456
+ hash.update(hexToBytes(td.tx_pub_key));
66457
+ td.additional_tx_pub_keys.forEach(key => hash.update(hexToBytes(key)));
66458
+ hash.update(encodeUvarint(td.internal_output_index));
66459
+ total.update(hash.digest());
66460
+ });
66461
+ return utils.bytesToHex(total.digest());
66462
+ };
66463
+ class MoneroKeyImageSync extends BaseMethod {
66464
+ getSupportedProtocols() {
66465
+ return ['V1', 'V2'];
66466
+ }
66467
+ init() {
66468
+ this.checkDeviceId = true;
66469
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
66470
+ this.strictCheckDeviceSupport = true;
66471
+ const payload = this.payload;
66472
+ validateParams(payload, [
66473
+ { name: 'path', required: true },
66474
+ { name: 'networkType', type: 'number' },
66475
+ { name: 'transfers', type: 'array', required: true },
66476
+ ]);
66477
+ if (!Array.isArray(payload.transfers) || payload.transfers.length === 0) {
66478
+ throw invalidParameter('transfers must be a non-empty array');
66479
+ }
66480
+ this.params = {
66481
+ address_n: validateStrictPath(payload.path, 3),
66482
+ network_type: validateMoneroNetworkType(payload.networkType),
66483
+ tdis: payload.transfers.map(parseTransfer),
66484
+ };
66485
+ }
66486
+ getVersionRange() {
66487
+ return getMoneroVersionRange();
66488
+ }
66489
+ run() {
66490
+ return __awaiter(this, void 0, void 0, function* () {
66491
+ const { address_n, network_type, tdis } = this.params;
66492
+ yield this.device.commands.typedCall('MoneroKeyImageExportInitRequest', 'MoneroKeyImageExportInitAck', {
66493
+ num: tdis.length,
66494
+ hash: computeTransfersHash(tdis),
66495
+ address_n,
66496
+ network_type,
66497
+ subs: [],
66498
+ });
66499
+ const keyImages = [];
66500
+ for (let start = 0; start < tdis.length; start += STEP_SIZE) {
66501
+ const res = yield this.device.commands.typedCall('MoneroKeyImageSyncStepRequest', 'MoneroKeyImageSyncStepAck', { tdis: tdis.slice(start, start + STEP_SIZE) });
66502
+ res.message.kis.forEach(ki => keyImages.push({ iv: ki.iv, blob: ki.blob }));
66503
+ }
66504
+ const res = yield this.device.commands.typedCall('MoneroKeyImageSyncFinalRequest', 'MoneroKeyImageSyncFinalAck', {});
66505
+ const encKey = res.message.enc_key;
66506
+ validateResult(keyImages, ['iv', 'blob'], { expectedLength: tdis.length });
66507
+ validateResult({ encKey }, ['encKey']);
66508
+ return Promise.resolve({ encKey, keyImages });
66509
+ });
66510
+ }
66511
+ }
66512
+
66513
+ const BP_PLUS_VERSION = 4;
66514
+ const OFFLOAD_RANGE_PROOF = 1;
66515
+ const KEY_IMAGE_HEX_LENGTH = 64;
66516
+ const invalidResponse = (message) => hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodError, message);
66517
+ const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
66518
+ const requireBytes = (value, name) => {
66519
+ if (typeof value !== 'string' || value.length === 0) {
66520
+ throw invalidResponse(`Device response is missing ${name}`);
66521
+ }
66522
+ return value;
66523
+ };
66524
+ const withoutNulls = (value) => {
66525
+ if (Array.isArray(value))
66526
+ return value.map(withoutNulls);
66527
+ if (!isObject(value))
66528
+ return value;
66529
+ return Object.fromEntries(Object.entries(value)
66530
+ .filter(([, item]) => item !== null && item !== undefined)
66531
+ .map(([key, item]) => [key, withoutNulls(item)]));
66532
+ };
66533
+ const validateObjects = (values, name) => {
66534
+ values.forEach((value, index) => {
66535
+ if (!isObject(value)) {
66536
+ throw invalidParameter(`${name}[${index}] must be an object`);
66537
+ }
66538
+ });
66539
+ };
66540
+ const validateTsxData = (tsxData, inputCount) => {
66541
+ if (tsxData.num_inputs !== inputCount) {
66542
+ throw invalidParameter('tsxData.num_inputs must equal the number of inputs');
66543
+ }
66544
+ const { outputs } = tsxData;
66545
+ if (!Array.isArray(outputs) || outputs.length < 2) {
66546
+ throw invalidParameter('tsxData.outputs must hold at least 2 outputs');
66547
+ }
66548
+ validateObjects(outputs, 'tsxData.outputs');
66549
+ const hardFork = tsxData.hard_fork;
66550
+ if (typeof hardFork !== 'number' || !Number.isSafeInteger(hardFork) || hardFork <= 0) {
66551
+ throw invalidParameter('tsxData.hard_fork is required');
66552
+ }
66553
+ const rsigData = tsxData.rsig_data;
66554
+ if (!isObject(rsigData) || rsigData.bp_version !== BP_PLUS_VERSION) {
66555
+ throw invalidParameter('tsxData.rsig_data.bp_version must be 4 (Bulletproof+)');
66556
+ }
66557
+ const { grouping } = rsigData;
66558
+ const validBatches = Array.isArray(grouping) &&
66559
+ grouping.every(size => Number.isSafeInteger(size) && size > 0) &&
66560
+ grouping.reduce((sum, size) => sum + size, 0) === outputs.length;
66561
+ if (!validBatches) {
66562
+ throw invalidParameter('tsxData.rsig_data.grouping must add up to the number of outputs');
66563
+ }
66564
+ };
66565
+ const parseSetInputAck = (ack, origIdx) => {
66566
+ const name = (field) => `${field} of input ${origIdx}`;
66567
+ const vini = requireBytes(ack.vini, name('vini'));
66568
+ if (vini.length < KEY_IMAGE_HEX_LENGTH) {
66569
+ throw invalidResponse(`Device returned a vini without a key image for input ${origIdx}`);
66570
+ }
66571
+ return {
66572
+ origIdx,
66573
+ keyImage: vini.slice(-KEY_IMAGE_HEX_LENGTH).toLowerCase(),
66574
+ vini,
66575
+ vini_hmac: requireBytes(ack.vini_hmac, name('vini_hmac')),
66576
+ pseudo_out: requireBytes(ack.pseudo_out, name('pseudo_out')),
66577
+ pseudo_out_hmac: requireBytes(ack.pseudo_out_hmac, name('pseudo_out_hmac')),
66578
+ pseudo_out_alpha: requireBytes(ack.pseudo_out_alpha, name('pseudo_out_alpha')),
66579
+ spend_key: requireBytes(ack.spend_key, name('spend_key')),
66580
+ };
66581
+ };
66582
+ const parseAllOutSetAck = (ack) => {
66583
+ const { rv } = ack;
66584
+ if (!rv || rv.txn_fee == null || rv.rv_type == null) {
66585
+ throw invalidResponse('Device response is missing rv');
66586
+ }
66587
+ return {
66588
+ extra: requireBytes(ack.extra, 'extra'),
66589
+ txPrefixHash: requireBytes(ack.tx_prefix_hash, 'tx_prefix_hash'),
66590
+ fullMessageHash: requireBytes(ack.full_message_hash, 'full_message_hash'),
66591
+ rv: {
66592
+ txnFee: String(rv.txn_fee),
66593
+ message: requireBytes(rv.message, 'rv.message'),
66594
+ rvType: rv.rv_type,
66595
+ },
66596
+ };
66597
+ };
66598
+ const sortByKeyImage = (inputs) => {
66599
+ const sorted = [...inputs].sort((a, b) => {
66600
+ if (a.keyImage === b.keyImage)
66601
+ return 0;
66602
+ return a.keyImage > b.keyImage ? -1 : 1;
66603
+ });
66604
+ sorted.forEach((input, index) => {
66605
+ if (index > 0 && sorted[index - 1].keyImage === input.keyImage) {
66606
+ throw invalidResponse('Two inputs have the same key image');
66607
+ }
66608
+ });
66609
+ return sorted;
66610
+ };
66611
+ class MoneroSignTransaction extends BaseMethod {
66612
+ getSupportedProtocols() {
66613
+ return ['V1', 'V2'];
66614
+ }
66615
+ init() {
66616
+ this.checkDeviceId = true;
66617
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
66618
+ this.strictCheckDeviceSupport = true;
66619
+ const payload = this.payload;
66620
+ validateParams(payload, [
66621
+ { name: 'path', required: true },
66622
+ { name: 'networkType', type: 'number' },
66623
+ { name: 'tsxData', type: 'object', required: true },
66624
+ { name: 'inputs', type: 'array', required: true },
66625
+ ]);
66626
+ if (!isObject(payload.tsxData)) {
66627
+ throw invalidParameter('tsxData must be an object');
66628
+ }
66629
+ if (!Array.isArray(payload.inputs) || payload.inputs.length === 0) {
66630
+ throw invalidParameter('inputs must be a non-empty array');
66631
+ }
66632
+ validateObjects(payload.inputs, 'inputs');
66633
+ const tsxData = withoutNulls(payload.tsxData);
66634
+ validateTsxData(tsxData, payload.inputs.length);
66635
+ this.params = {
66636
+ address_n: validateStrictPath(payload.path, 3),
66637
+ network_type: validateMoneroNetworkType(payload.networkType),
66638
+ tsx_data: tsxData,
66639
+ inputs: payload.inputs.map(input => withoutNulls(input)),
66640
+ };
66641
+ }
66642
+ getVersionRange() {
66643
+ return getMoneroVersionRange();
66644
+ }
66645
+ run() {
66646
+ var _a, _b;
66647
+ return __awaiter(this, void 0, void 0, function* () {
66648
+ const { address_n, network_type, tsx_data, inputs } = this.params;
66649
+ const { outputs } = tsx_data;
66650
+ const init = yield this.device.commands.typedCall('MoneroTransactionInitRequest', 'MoneroTransactionInitAck', { version: 0, address_n, network_type, tsx_data });
66651
+ if (((_a = init.message.rsig_data) === null || _a === void 0 ? void 0 : _a.offload_type) === OFFLOAD_RANGE_PROOF) {
66652
+ throw invalidResponse('The device asked the host to prove the range proof, which is not supported: send at most 2 outputs');
66653
+ }
66654
+ const { hmacs } = init.message;
66655
+ if (!Array.isArray(hmacs) || hmacs.length !== outputs.length) {
66656
+ throw invalidResponse('Device returned a wrong number of output HMACs');
66657
+ }
66658
+ const states = [];
66659
+ for (let i = 0; i < inputs.length; i++) {
66660
+ const res = yield this.device.commands.typedCall('MoneroTransactionSetInputRequest', 'MoneroTransactionSetInputAck', { src_entr: inputs[i] });
66661
+ states.push(parseSetInputAck(res.message, i));
66662
+ }
66663
+ const sorted = sortByKeyImage(states);
66664
+ for (const input of sorted) {
66665
+ yield this.device.commands.typedCall('MoneroTransactionInputViniRequest', 'MoneroTransactionInputViniAck', {
66666
+ src_entr: inputs[input.origIdx],
66667
+ vini: input.vini,
66668
+ vini_hmac: input.vini_hmac,
66669
+ pseudo_out: input.pseudo_out,
66670
+ pseudo_out_hmac: input.pseudo_out_hmac,
66671
+ orig_idx: input.origIdx,
66672
+ });
66673
+ }
66674
+ yield this.device.commands.typedCall('MoneroTransactionAllInputsSetRequest', 'MoneroTransactionAllInputsSetAck', {});
66675
+ const txOuts = [];
66676
+ const outPks = [];
66677
+ const ecdhInfos = [];
66678
+ const rsigs = [];
66679
+ for (let i = 0; i < outputs.length; i++) {
66680
+ const res = yield this.device.commands.typedCall('MoneroTransactionSetOutputRequest', 'MoneroTransactionSetOutputAck', { dst_entr: outputs[i], dst_entr_hmac: hmacs[i] });
66681
+ txOuts.push(requireBytes(res.message.tx_out, `tx_out of output ${i}`));
66682
+ outPks.push(requireBytes(res.message.out_pk, `out_pk of output ${i}`));
66683
+ ecdhInfos.push(requireBytes(res.message.ecdh_info, `ecdh_info of output ${i}`));
66684
+ const rsig = (_b = res.message.rsig_data) === null || _b === void 0 ? void 0 : _b.rsig;
66685
+ if (rsig)
66686
+ rsigs.push(rsig);
66687
+ }
66688
+ if (rsigs.length !== 1) {
66689
+ throw invalidResponse(`Expected one aggregated range proof, got ${rsigs.length}`);
66690
+ }
66691
+ const allOut = yield this.device.commands.typedCall('MoneroTransactionAllOutSetRequest', 'MoneroTransactionAllOutSetAck', {});
66692
+ const prefix = parseAllOutSetAck(allOut.message);
66693
+ const signatures = [];
66694
+ const pseudoOuts = [];
66695
+ for (const input of sorted) {
66696
+ const res = yield this.device.commands.typedCall('MoneroTransactionSignInputRequest', 'MoneroTransactionSignInputAck', {
66697
+ src_entr: inputs[input.origIdx],
66698
+ vini: input.vini,
66699
+ vini_hmac: input.vini_hmac,
66700
+ pseudo_out: input.pseudo_out,
66701
+ pseudo_out_hmac: input.pseudo_out_hmac,
66702
+ pseudo_out_alpha: input.pseudo_out_alpha,
66703
+ spend_key: input.spend_key,
66704
+ orig_idx: input.origIdx,
66705
+ });
66706
+ signatures.push(requireBytes(res.message.signature, `signature of input ${input.origIdx}`));
66707
+ pseudoOuts.push(requireBytes(res.message.pseudo_out, `pseudo_out of input ${input.origIdx}`));
66708
+ }
66709
+ const final = yield this.device.commands.typedCall('MoneroTransactionFinalRequest', 'MoneroTransactionFinalAck', {});
66710
+ return Object.assign(Object.assign({ origIndices: sorted.map(input => input.origIdx), vinis: sorted.map(input => input.vini), pseudoOuts,
66711
+ signatures,
66712
+ txOuts,
66713
+ outPks,
66714
+ ecdhInfos, rsig: rsigs[0] }, prefix), { openingKey: requireBytes(final.message.opening_key, 'opening_key'), salt: requireBytes(final.message.salt, 'salt'), randMult: requireBytes(final.message.rand_mult, 'rand_mult'), txEncKeys: requireBytes(final.message.tx_enc_keys, 'tx_enc_keys') });
66715
+ });
66716
+ }
66717
+ }
66718
+
65871
66719
  var ApiMethods = /*#__PURE__*/Object.freeze({
65872
66720
  __proto__: null,
65873
66721
  testInitializeDeviceDuration: TestInitializeDeviceDuration,
@@ -66011,7 +66859,13 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
66011
66859
  benfenSignMessage: BenfenSignMessage,
66012
66860
  benfenSignTransaction: BenfenSignTransaction,
66013
66861
  neoGetAddress: NeoGetAddress,
66014
- neoSignTransaction: NeoSignTransaction
66862
+ neoSignTransaction: NeoSignTransaction,
66863
+ zcashGetAddress: ZcashGetAddress,
66864
+ zcashSignPczt: ZcashSignPczt,
66865
+ moneroGetAddress: MoneroGetAddress,
66866
+ moneroGetWatchKey: MoneroGetWatchKey,
66867
+ moneroKeyImageSync: MoneroKeyImageSync,
66868
+ moneroSignTransaction: MoneroSignTransaction
66015
66869
  });
66016
66870
 
66017
66871
  const publicMethodRegistry = ApiMethods;
@@ -67421,7 +68275,7 @@ const cancel = (context, connectId) => {
67421
68275
  };
67422
68276
  for (const requestId of requestIds) {
67423
68277
  const task = requestQueue.getTask(requestId);
67424
- Log.debug('Cancel Api connect task: ', task);
68278
+ Log.debug('Cancel Api connect task: ', getSafeLogTask(task));
67425
68279
  if (task) {
67426
68280
  interruptDevice((_a = task.method) === null || _a === void 0 ? void 0 : _a.device, connectId);
67427
68281
  interruptDevice(deviceCacheMap.get(connectId), connectId);
@@ -67450,7 +68304,7 @@ const cancel = (context, connectId) => {
67450
68304
  };
67451
68305
  for (const requestId of requestQueue.getRequestTasksId()) {
67452
68306
  const task = requestQueue.getTask(requestId);
67453
- Log.debug('Cancel Api connect task: ', task);
68307
+ Log.debug('Cancel Api connect task: ', getSafeLogTask(task));
67454
68308
  if (task) {
67455
68309
  interruptDevice((_b = task.method) === null || _b === void 0 ? void 0 : _b.device);
67456
68310
  if (task.method.connectId) {
@@ -67740,7 +68594,7 @@ class Core extends events.exports {
67740
68594
  break;
67741
68595
  }
67742
68596
  case IFRAME.CALLBACK: {
67743
- Log.log('callback message: ', message);
68597
+ Log.log('callback message: ', getSafeLogPayload(message));
67744
68598
  postMessage(message);
67745
68599
  break;
67746
68600
  }
@@ -67978,6 +68832,7 @@ exports.getNftSize = getNftSize;
67978
68832
  exports.getOutputScriptType = getOutputScriptType;
67979
68833
  exports.getSDKVersion = getSDKVersion;
67980
68834
  exports.getSafeLogPayload = getSafeLogPayload;
68835
+ exports.getSafeLogTask = getSafeLogTask;
67981
68836
  exports.getScriptType = getScriptType;
67982
68837
  exports.getTimeStamp = getTimeStamp;
67983
68838
  exports.httpRequest = httpRequest;