@aztec/cli-wallet 0.0.0-test.1 → 0.0.1-commit.017a351

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 (115) hide show
  1. package/README.md +30 -0
  2. package/dest/bin/index.d.ts +2 -1
  3. package/dest/bin/index.js +58 -26
  4. package/dest/cmds/authorize_action.d.ts +4 -3
  5. package/dest/cmds/authorize_action.d.ts.map +1 -1
  6. package/dest/cmds/authorize_action.js +11 -5
  7. package/dest/cmds/bridge_fee_juice.d.ts +4 -4
  8. package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
  9. package/dest/cmds/bridge_fee_juice.js +10 -8
  10. package/dest/cmds/check_tx.d.ts +5 -3
  11. package/dest/cmds/check_tx.d.ts.map +1 -1
  12. package/dest/cmds/check_tx.js +174 -6
  13. package/dest/cmds/create_account.d.ts +10 -7
  14. package/dest/cmds/create_account.d.ts.map +1 -1
  15. package/dest/cmds/create_account.js +74 -38
  16. package/dest/cmds/create_authwit.d.ts +4 -3
  17. package/dest/cmds/create_authwit.d.ts.map +1 -1
  18. package/dest/cmds/create_authwit.js +6 -6
  19. package/dest/cmds/deploy.d.ts +8 -4
  20. package/dest/cmds/deploy.d.ts.map +1 -1
  21. package/dest/cmds/deploy.js +108 -59
  22. package/dest/cmds/deploy_account.d.ts +7 -8
  23. package/dest/cmds/deploy_account.d.ts.map +1 -1
  24. package/dest/cmds/deploy_account.js +70 -36
  25. package/dest/cmds/get_fee_juice_balance.d.ts +5 -0
  26. package/dest/cmds/get_fee_juice_balance.d.ts.map +1 -0
  27. package/dest/cmds/get_fee_juice_balance.js +27 -0
  28. package/dest/cmds/import_test_accounts.d.ts +3 -3
  29. package/dest/cmds/import_test_accounts.d.ts.map +1 -1
  30. package/dest/cmds/import_test_accounts.js +6 -9
  31. package/dest/cmds/index.d.ts +3 -3
  32. package/dest/cmds/index.d.ts.map +1 -1
  33. package/dest/cmds/index.js +99 -115
  34. package/dest/cmds/profile.d.ts +8 -0
  35. package/dest/cmds/profile.d.ts.map +1 -0
  36. package/dest/cmds/profile.js +28 -0
  37. package/dest/cmds/register_contract.d.ts +7 -3
  38. package/dest/cmds/register_contract.d.ts.map +1 -1
  39. package/dest/cmds/register_contract.js +20 -7
  40. package/dest/cmds/register_sender.d.ts +4 -3
  41. package/dest/cmds/register_sender.d.ts.map +1 -1
  42. package/dest/cmds/send.d.ts +9 -9
  43. package/dest/cmds/send.d.ts.map +1 -1
  44. package/dest/cmds/send.js +54 -27
  45. package/dest/cmds/simulate.d.ts +7 -3
  46. package/dest/cmds/simulate.d.ts.map +1 -1
  47. package/dest/cmds/simulate.js +26 -20
  48. package/dest/storage/wallet_db.d.ts +12 -19
  49. package/dest/storage/wallet_db.d.ts.map +1 -1
  50. package/dest/storage/wallet_db.js +63 -55
  51. package/dest/utils/authorizations.d.ts +6 -0
  52. package/dest/utils/authorizations.d.ts.map +1 -0
  53. package/dest/utils/authorizations.js +28 -0
  54. package/dest/utils/cli_wallet_and_node_wrapper.d.ts +12 -0
  55. package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -0
  56. package/dest/utils/cli_wallet_and_node_wrapper.js +25 -0
  57. package/dest/utils/constants.d.ts +4 -0
  58. package/dest/utils/constants.d.ts.map +1 -0
  59. package/dest/utils/constants.js +7 -0
  60. package/dest/utils/ecdsa.d.ts +1 -3
  61. package/dest/utils/ecdsa.d.ts.map +1 -1
  62. package/dest/utils/options/fees.d.ts +23 -28
  63. package/dest/utils/options/fees.d.ts.map +1 -1
  64. package/dest/utils/options/fees.js +112 -148
  65. package/dest/utils/options/index.d.ts +1 -1
  66. package/dest/utils/options/options.d.ts +9 -5
  67. package/dest/utils/options/options.d.ts.map +1 -1
  68. package/dest/utils/options/options.js +26 -14
  69. package/dest/utils/profiling.d.ts +5 -0
  70. package/dest/utils/profiling.d.ts.map +1 -0
  71. package/dest/utils/profiling.js +68 -0
  72. package/dest/utils/wallet.d.ts +44 -0
  73. package/dest/utils/wallet.d.ts.map +1 -0
  74. package/dest/utils/wallet.js +263 -0
  75. package/package.json +31 -23
  76. package/src/bin/index.ts +63 -33
  77. package/src/cmds/authorize_action.ts +16 -5
  78. package/src/cmds/bridge_fee_juice.ts +16 -12
  79. package/src/cmds/check_tx.ts +212 -5
  80. package/src/cmds/create_account.ts +89 -45
  81. package/src/cmds/create_authwit.ts +9 -5
  82. package/src/cmds/deploy.ts +115 -71
  83. package/src/cmds/deploy_account.ts +84 -36
  84. package/src/cmds/get_fee_juice_balance.ts +37 -0
  85. package/src/cmds/import_test_accounts.ts +7 -11
  86. package/src/cmds/index.ts +312 -222
  87. package/src/cmds/profile.ts +48 -0
  88. package/src/cmds/register_contract.ts +28 -5
  89. package/src/cmds/register_sender.ts +3 -2
  90. package/src/cmds/send.ts +59 -25
  91. package/src/cmds/simulate.ts +37 -24
  92. package/src/storage/wallet_db.ts +67 -68
  93. package/src/utils/authorizations.ts +51 -0
  94. package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
  95. package/src/utils/constants.ts +4 -0
  96. package/src/utils/options/fees.ts +169 -210
  97. package/src/utils/options/options.ts +41 -19
  98. package/src/utils/profiling.ts +172 -0
  99. package/src/utils/wallet.ts +330 -0
  100. package/dest/cmds/add_authwit.d.ts +0 -4
  101. package/dest/cmds/add_authwit.d.ts.map +0 -1
  102. package/dest/cmds/add_authwit.js +0 -4
  103. package/dest/cmds/cancel_tx.d.ts +0 -11
  104. package/dest/cmds/cancel_tx.d.ts.map +0 -1
  105. package/dest/cmds/cancel_tx.js +0 -38
  106. package/dest/utils/accounts.d.ts +0 -11
  107. package/dest/utils/accounts.d.ts.map +0 -1
  108. package/dest/utils/accounts.js +0 -87
  109. package/dest/utils/pxe_wrapper.d.ts +0 -10
  110. package/dest/utils/pxe_wrapper.d.ts.map +0 -1
  111. package/dest/utils/pxe_wrapper.js +0 -21
  112. package/src/cmds/add_authwit.ts +0 -13
  113. package/src/cmds/cancel_tx.ts +0 -62
  114. package/src/utils/accounts.ts +0 -102
  115. package/src/utils/pxe_wrapper.ts +0 -26
@@ -1,11 +1,11 @@
1
- import { type AccountWalletWithSecretKey, type AztecAddress, Fr } from '@aztec/aztec.js';
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { AuthWitness } from '@aztec/aztec.js/authorization';
3
+ import { type AztecNode } from '@aztec/aztec.js/node';
2
4
  import type { LogFn } from '@aztec/foundation/log';
3
- import { GasSettings } from '@aztec/stdlib/gas';
4
- import { type IFeeOpts } from '../utils/options/fees.js';
5
- export declare function send(wallet: AccountWalletWithSecretKey, functionName: string, functionArgsIn: any[], contractArtifactPath: string, contractAddress: AztecAddress, wait: boolean, cancellable: boolean, feeOpts: IFeeOpts, log: LogFn): Promise<{
6
- txHash: import("@aztec/aztec.js").TxHash;
7
- nonce: Fr;
8
- cancellable: boolean;
9
- gasSettings: GasSettings;
5
+ import { TxStatus } from '@aztec/stdlib/tx';
6
+ import { CLIFeeArgs } from '../utils/options/fees.js';
7
+ import type { CLIWallet } from '../utils/wallet.js';
8
+ export declare function send(wallet: CLIWallet, node: AztecNode, from: AztecAddress, functionName: string, functionArgsIn: any[], contractArtifactPath: string, contractAddress: AztecAddress, wait: boolean, cancellable: boolean, feeOpts: CLIFeeArgs, authWitnesses: AuthWitness[], waitForStatus: TxStatus, verbose: boolean, log: LogFn): Promise<{
9
+ txHash: import("@aztec/stdlib/tx").TxHash;
10
10
  } | undefined>;
11
- //# sourceMappingURL=send.d.ts.map
11
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VuZC5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NtZHMvc2VuZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQUM5RCxPQUFPLEVBQUUsV0FBVyxFQUFFLE1BQU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M,0BAA0B,CAAC;AAE5E,wBAAsB,IAAI,CACxB,MAAM,EAAE,0BAA0B,EAClC,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,GAAG,EAAE,EACrB,oBAAoB,EAAE,MAAM,EAC5B,eAAe,EAAE,YAAY,EAC7B,IAAI,EAAE,OAAO,EACb,WAAW,EAAE,OAAO,EACpB,OAAO,EAAE,QAAQ,EACjB,GAAG,EAAE,KAAK;;;;;eA6CX"}
1
+ {"version":3,"file":"send.d.ts","sourceRoot":"","sources":["../../src/cmds/send.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE5D,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,sBAAsB,CAAC;AAEjE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5C,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,wBAAsB,IAAI,CACxB,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,YAAY,EAClB,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,GAAG,EAAE,EACrB,oBAAoB,EAAE,MAAM,EAC5B,eAAe,EAAE,YAAY,EAC7B,IAAI,EAAE,OAAO,EACb,WAAW,EAAE,OAAO,EACpB,OAAO,EAAE,UAAU,EACnB,aAAa,EAAE,WAAW,EAAE,EAC5B,aAAa,EAAE,QAAQ,EACvB,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,KAAK;;eAoEX"}
package/dest/cmds/send.js CHANGED
@@ -1,49 +1,76 @@
1
- import { Contract, Fr } from '@aztec/aztec.js';
1
+ import { Contract, NO_WAIT } from '@aztec/aztec.js/contracts';
2
+ import { waitForTx } from '@aztec/aztec.js/node';
2
3
  import { prepTx } from '@aztec/cli/utils';
3
- import { GasSettings } from '@aztec/stdlib/gas';
4
- import { printGasEstimates } from '../utils/options/fees.js';
5
- export async function send(wallet, functionName, functionArgsIn, contractArtifactPath, contractAddress, wait, cancellable, feeOpts, log) {
4
+ import { TxStatus } from '@aztec/stdlib/tx';
5
+ import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
6
+ import { printProfileResult } from '../utils/profiling.js';
7
+ export async function send(wallet, node, from, functionName, functionArgsIn, contractArtifactPath, contractAddress, wait, cancellable, feeOpts, authWitnesses, waitForStatus, verbose, log) {
6
8
  const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
7
- const contract = await Contract.at(contractAddress, contractArtifact, wallet);
9
+ const contract = Contract.at(contractAddress, contractArtifact, wallet);
8
10
  const call = contract.methods[functionName](...functionArgs);
9
- const gasLimits = await call.estimateGas({
10
- ...await feeOpts.toSendOpts(wallet)
11
+ const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, from);
12
+ const sendOptions = {
13
+ fee: {
14
+ paymentMethod,
15
+ gasSettings
16
+ },
17
+ from,
18
+ authWitnesses
19
+ };
20
+ const localStart = performance.now();
21
+ const sim = await call.simulate({
22
+ ...sendOptions,
23
+ fee: {
24
+ ...sendOptions.fee,
25
+ estimateGas: true
26
+ }
11
27
  });
12
- printGasEstimates(feeOpts, gasLimits, log);
28
+ // estimateGas: true guarantees these fields are present
29
+ const estimatedGas = sim.estimatedGas;
30
+ const stats = sim.stats;
13
31
  if (feeOpts.estimateOnly) {
14
32
  return;
15
33
  }
16
- const nonce = Fr.random();
17
- const tx = call.send({
18
- ...await feeOpts.toSendOpts(wallet),
19
- nonce,
20
- cancellable
34
+ if (verbose) {
35
+ printProfileResult(stats, log);
36
+ }
37
+ const { txHash } = await call.send({
38
+ ...sendOptions,
39
+ fee: {
40
+ ...sendOptions.fee,
41
+ gasSettings: estimatedGas
42
+ },
43
+ wait: NO_WAIT
21
44
  });
22
- const txHash = await tx.getTxHash();
45
+ const localTimeMs = performance.now() - localStart;
23
46
  log(`\nTransaction hash: ${txHash.toString()}`);
24
47
  if (wait) {
25
48
  try {
26
- await tx.wait();
27
- log('Transaction has been mined');
28
- const receipt = await tx.getReceipt();
49
+ const nodeStart = performance.now();
50
+ const receipt = await waitForTx(node, txHash, {
51
+ timeout: DEFAULT_TX_TIMEOUT_S,
52
+ waitForStatus
53
+ });
54
+ const nodeTimeMs = performance.now() - nodeStart;
55
+ const statusLabel = waitForStatus === TxStatus.PROPOSED ? 'proposed' : 'checkpointed';
56
+ log(`Transaction has been ${statusLabel}`);
29
57
  log(` Tx fee: ${receipt.transactionFee}`);
30
58
  log(` Status: ${receipt.status}`);
31
59
  log(` Block number: ${receipt.blockNumber}`);
32
60
  log(` Block hash: ${receipt.blockHash?.toString()}`);
61
+ log(` Local processing time: ${(localTimeMs / 1000).toFixed(1)}s`);
62
+ log(` Node inclusion time: ${(nodeTimeMs / 1000).toFixed(1)}s`);
63
+ return {
64
+ txHash
65
+ };
33
66
  } catch (err) {
34
67
  log(`Transaction failed\n ${err.message}`);
68
+ throw err;
35
69
  }
36
70
  } else {
37
71
  log('Transaction pending. Check status with check-tx');
72
+ return {
73
+ txHash
74
+ };
38
75
  }
39
- const gasSettings = GasSettings.from({
40
- ...feeOpts.gasSettings,
41
- ...gasLimits
42
- });
43
- return {
44
- txHash,
45
- nonce,
46
- cancellable,
47
- gasSettings
48
- };
49
76
  }
@@ -1,4 +1,8 @@
1
- import { type AccountWalletWithSecretKey, type AztecAddress } from '@aztec/aztec.js';
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { AuthWitness } from '@aztec/aztec.js/authorization';
3
+ import type { AztecNode } from '@aztec/aztec.js/node';
2
4
  import type { LogFn } from '@aztec/foundation/log';
3
- export declare function simulate(wallet: AccountWalletWithSecretKey, functionName: string, functionArgsIn: any[], contractArtifactPath: string, contractAddress: AztecAddress, profile: boolean, log: LogFn): Promise<void>;
4
- //# sourceMappingURL=simulate.d.ts.map
5
+ import type { CLIFeeArgs } from '../utils/options/fees.js';
6
+ import type { CLIWallet } from '../utils/wallet.js';
7
+ export declare function simulate(wallet: CLIWallet, node: AztecNode, from: AztecAddress, functionName: string, functionArgsIn: any[], contractArtifactPath: string, contractAddress: AztecAddress, feeOpts: CLIFeeArgs, authWitnesses: AuthWitness[], verbose: boolean, log: LogFn): Promise<void>;
8
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2ltdWxhdGUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jbWRzL3NpbXVsYXRlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBQzlELE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUU1RCxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUV0RCxPQUFPLEtBQUssRUFBRSxLQUFLLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUtuRCxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUUzRCxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUVwRCx3QkFBc0IsUUFBUSxDQUM1QixNQUFNLEVBQUUsU0FBUyxFQUNqQixJQUFJLEVBQUUsU0FBUyxFQUNmLElBQUksRUFBRSxZQUFZLEVBQ2xCLFlBQVksRUFBRSxNQUFNLEVBQ3BCLGNBQWMsRUFBRSxHQUFHLEVBQUUsRUFDckIsb0JBQW9CLEVBQUUsTUFBTSxFQUM1QixlQUFlLEVBQUUsWUFBWSxFQUM3QixPQUFPLEVBQUUsVUFBVSxFQUNuQixhQUFhLEVBQUUsV0FBVyxFQUFFLEVBQzVCLE9BQU8sRUFBRSxPQUFPLEVBQ2hCLEdBQUcsRUFBRSxLQUFLLGlCQTZCWCJ9
@@ -1 +1 @@
1
- {"version":3,"file":"simulate.d.ts","sourceRoot":"","sources":["../../src/cmds/simulate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,0BAA0B,EAAE,KAAK,YAAY,EAAgC,MAAM,iBAAiB,CAAC;AAEnH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAkBnD,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,0BAA0B,EAClC,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,GAAG,EAAE,EACrB,oBAAoB,EAAE,MAAM,EAC5B,eAAe,EAAE,YAAY,EAC7B,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,KAAK,iBAcX"}
1
+ {"version":3,"file":"simulate.d.ts","sourceRoot":"","sources":["../../src/cmds/simulate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAKnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,YAAY,EAClB,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,GAAG,EAAE,EACrB,oBAAoB,EAAE,MAAM,EAC5B,eAAe,EAAE,YAAY,EAC7B,OAAO,EAAE,UAAU,EACnB,aAAa,EAAE,WAAW,EAAE,EAC5B,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,KAAK,iBA6BX"}
@@ -1,26 +1,32 @@
1
- import { Contract } from '@aztec/aztec.js';
1
+ import { Contract } from '@aztec/aztec.js/contracts';
2
2
  import { prepTx } from '@aztec/cli/utils';
3
3
  import { format } from 'util';
4
- function printProfileResult(result, log) {
5
- log(format('\nSimulation result:'));
6
- log(format('Return value:', JSON.stringify(result.returnValues, null, 2)));
7
- log(format('\nGate count per circuit:'));
8
- let acc = 0;
9
- result.gateCounts.forEach((r)=>{
10
- acc += r.gateCount;
11
- log(format(' ', r.circuitName.padEnd(50), 'Gates:', r.gateCount.toLocaleString(), '\tAcc:', acc.toLocaleString()));
12
- });
13
- log(format('\nTotal gates:', acc.toLocaleString()));
14
- }
15
- export async function simulate(wallet, functionName, functionArgsIn, contractArtifactPath, contractAddress, profile, log) {
4
+ import { printAuthorizations } from '../utils/authorizations.js';
5
+ import { printProfileResult } from '../utils/profiling.js';
6
+ export async function simulate(wallet, node, from, functionName, functionArgsIn, contractArtifactPath, contractAddress, feeOpts, authWitnesses, verbose, log) {
16
7
  const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
17
- const contract = await Contract.at(contractAddress, contractArtifact, wallet);
8
+ const contract = Contract.at(contractAddress, contractArtifact, wallet);
18
9
  const call = contract.methods[functionName](...functionArgs);
19
- if (profile) {
20
- const result = await call.simulateWithProfile();
21
- printProfileResult(result, log);
22
- } else {
23
- const result = await call.simulate();
24
- log(format('\nSimulation result: ', result, '\n'));
10
+ const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, from);
11
+ const simulationResult = await call.simulate({
12
+ fee: {
13
+ paymentMethod,
14
+ gasSettings
15
+ },
16
+ from,
17
+ authWitnesses,
18
+ includeMetadata: true
19
+ });
20
+ if (verbose) {
21
+ await printAuthorizations(simulationResult.offchainEffects, async (address)=>{
22
+ const metadata = await wallet.getContractMetadata(address);
23
+ if (!metadata.instance) {
24
+ return undefined;
25
+ }
26
+ const artifact = await wallet.getContractArtifact(metadata.instance.currentContractClassId);
27
+ return artifact;
28
+ }, log);
29
+ printProfileResult(simulationResult.stats, log);
25
30
  }
31
+ log(format('\nSimulation result: ', simulationResult.result, '\n'));
26
32
  }
@@ -1,13 +1,10 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
2
  import type { LogFn } from '@aztec/foundation/log';
5
3
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
6
4
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
7
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
8
- import { GasSettings } from '@aztec/stdlib/gas';
9
6
  import type { TxHash } from '@aztec/stdlib/tx';
10
- import type { AccountType } from '../utils/accounts.js';
7
+ import type { AccountType } from '../utils/constants.js';
11
8
  export declare const Aliases: readonly ["accounts", "contracts", "artifacts", "secrets", "transactions", "authwits"];
12
9
  export type AliasType = (typeof Aliases)[number];
13
10
  export declare class WalletDB {
@@ -23,7 +20,12 @@ export declare class WalletDB {
23
20
  secret: string;
24
21
  leafIndex: bigint;
25
22
  }>;
26
- storeAccount(address: AztecAddress, { type, secretKey, salt, alias, publicKey, }: {
23
+ peekBridgedFeeJuice(recipient: AztecAddress, log: LogFn): Promise<{
24
+ amount: bigint;
25
+ secret: string;
26
+ leafIndex: bigint;
27
+ }>;
28
+ storeAccount(address: AztecAddress, { type, secretKey, salt, alias, publicKey }: {
27
29
  type: AccountType;
28
30
  secretKey: Fr;
29
31
  salt: Fr;
@@ -33,18 +35,9 @@ export declare class WalletDB {
33
35
  storeSender(address: AztecAddress, alias: string, log: LogFn): Promise<void>;
34
36
  storeContract(address: AztecAddress, artifactPath: string, log: LogFn, alias?: string): Promise<void>;
35
37
  storeAuthwitness(authWit: AuthWitness, log: LogFn, alias?: string): Promise<void>;
36
- storeTx({ txHash, nonce, cancellable, gasSettings, }: {
38
+ storeTx({ txHash }: {
37
39
  txHash: TxHash;
38
- nonce: Fr;
39
- cancellable: boolean;
40
- gasSettings: GasSettings;
41
40
  }, log: LogFn, alias?: string): Promise<void>;
42
- retrieveTxData(txHash: TxHash): Promise<{
43
- txHash: TxHash;
44
- nonce: Fr;
45
- cancellable: boolean;
46
- gasSettings: GasSettings;
47
- }>;
48
41
  tryRetrieveAlias(arg: string): string;
49
42
  retrieveAliasFromCache(arg: string): string;
50
43
  retrieveAlias(arg: string): Promise<string>;
@@ -53,13 +46,13 @@ export declare class WalletDB {
53
46
  value: string;
54
47
  }[]>;
55
48
  storeAccountMetadata(aliasOrAddress: AztecAddress | string, metadataKey: string, metadata: Buffer): Promise<void>;
56
- retrieveAccountMetadata(aliasOrAddress: AztecAddress | string, metadataKey: string): Promise<Buffer>;
49
+ retrieveAccountMetadata(aliasOrAddress: AztecAddress | string, metadataKey: string): Promise<Buffer<ArrayBufferLike>>;
57
50
  retrieveAccount(address: AztecAddress | string): Promise<{
58
51
  address: string | AztecAddress;
59
52
  secretKey: Fr;
60
53
  salt: Fr;
61
- type: "schnorr" | "ecdsasecp256r1ssh" | "ecdsasecp256k1";
54
+ type: "ecdsasecp256k1" | "ecdsasecp256r1" | "ecdsasecp256r1ssh" | "schnorr";
62
55
  }>;
63
56
  storeAlias(type: AliasType, key: string, value: Buffer, log: LogFn): Promise<void>;
64
57
  }
65
- //# sourceMappingURL=wallet_db.d.ts.map
58
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2FsbGV0X2RiLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3RvcmFnZS93YWxsZXRfZGIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEVBQUUsRUFB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gBAAgB,CAAC,GAAG,EAAE,MAAM,UAM3B;IAEM,sBAAsB,CAAC,GAAG,EAAE,MAAM,UAYxC;IAEK,aAAa,CAAC,GAAG,EAAE,MAAM,mBAW9B;IAEK,WAAW,CAAC,IAAI,CAAC,EAAE,SAAS;;;SAWjC;IAEK,oBAAoB,CAAC,cAAc,EAAE,YAAY,GAAG,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,iBAGtG;IAEK,uBAAuB,CAAC,cAAc,EAAE,YAAY,GAAG,MAAM,EAAE,WAAW,EAAE,MAAM,oCAOvF;IAEK,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM;;;;;OASnD;IAEK,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,iBAMvE;CACF"}
@@ -1,5 +1,4 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import { GasSettings } from '@aztec/stdlib/gas';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
2
  import { extractECDSAPublicKeyFromBase64String } from '../utils/ecdsa.js';
4
3
  export const Aliases = [
5
4
  'accounts',
@@ -10,10 +9,10 @@ export const Aliases = [
10
9
  'authwits'
11
10
  ];
12
11
  export class WalletDB {
12
+ #store;
13
13
  #accounts;
14
14
  #aliases;
15
15
  #bridgedFeeJuice;
16
- #transactions;
17
16
  static instance;
18
17
  aliasCache = new Map();
19
18
  static getInstance() {
@@ -23,10 +22,10 @@ export class WalletDB {
23
22
  return WalletDB.instance;
24
23
  }
25
24
  async init(store) {
25
+ this.#store = store;
26
26
  this.#accounts = store.openMap('accounts');
27
27
  this.#aliases = store.openMap('aliases');
28
28
  this.#bridgedFeeJuice = store.openMap('bridgedFeeJuice');
29
- this.#transactions = store.openMap('transactions');
30
29
  await this.refreshAliasCache();
31
30
  }
32
31
  async refreshAliasCache() {
@@ -36,13 +35,15 @@ export class WalletDB {
36
35
  ]));
37
36
  }
38
37
  async pushBridgedFeeJuice(recipient, secret, amount, leafIndex, log) {
39
- let stackPointer = (await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:stackPointer`))?.readInt8() || 0;
40
- stackPointer++;
41
- await this.#bridgedFeeJuice.set(`${recipient.toString()}:${stackPointer}`, Buffer.from(`${amount.toString()}:${secret.toString()}:${leafIndex.toString()}`));
42
- await this.#bridgedFeeJuice.set(`${recipient.toString()}:stackPointer`, Buffer.from([
43
- stackPointer
44
- ]));
45
- log(`Pushed ${amount} fee juice for recipient ${recipient.toString()}. Stack pointer ${stackPointer}`);
38
+ await this.#store.transactionAsync(async ()=>{
39
+ let stackPointer = (await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:stackPointer`))?.readInt8() || 0;
40
+ stackPointer++;
41
+ await this.#bridgedFeeJuice.set(`${recipient.toString()}:${stackPointer}`, Buffer.from(`${amount.toString()}:${secret.toString()}:${leafIndex.toString()}`));
42
+ await this.#bridgedFeeJuice.set(`${recipient.toString()}:stackPointer`, Buffer.from([
43
+ stackPointer
44
+ ]));
45
+ log(`Pushed ${amount} fee juice for recipient ${recipient.toString()}. Stack pointer ${stackPointer}`);
46
+ });
46
47
  }
47
48
  async popBridgedFeeJuice(recipient, log) {
48
49
  let stackPointer = (await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:stackPointer`))?.readInt8() || 0;
@@ -61,18 +62,37 @@ export class WalletDB {
61
62
  leafIndex: BigInt(leafIndexStr)
62
63
  };
63
64
  }
64
- async storeAccount(address, { type, secretKey, salt, alias, publicKey }, log) {
65
- if (alias) {
66
- await this.#aliases.set(`accounts:${alias}`, Buffer.from(address.toString()));
65
+ async peekBridgedFeeJuice(recipient, log) {
66
+ const stackPointer = (await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:stackPointer`))?.readInt8() || 0;
67
+ const result = await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:${stackPointer}`);
68
+ if (!result) {
69
+ throw new Error(`No stored fee juice available for recipient ${recipient.toString()}. Please provide claim amount and secret. Stack pointer ${stackPointer}`);
67
70
  }
68
- await this.#accounts.set(`${address.toString()}:type`, Buffer.from(type));
69
- await this.#accounts.set(`${address.toString()}:sk`, secretKey.toBuffer());
70
- await this.#accounts.set(`${address.toString()}:salt`, salt.toBuffer());
71
+ const [amountStr, secretStr, leafIndexStr] = result.toString().split(':');
72
+ log(`Peeked ${amountStr} fee juice for recipient ${recipient.toString()}. Stack pointer ${stackPointer}`);
73
+ return {
74
+ amount: BigInt(amountStr),
75
+ secret: secretStr,
76
+ leafIndex: BigInt(leafIndexStr)
77
+ };
78
+ }
79
+ async storeAccount(address, { type, secretKey, salt, alias, publicKey }, log) {
80
+ let publicSigningKey;
71
81
  if (type === 'ecdsasecp256r1ssh' && publicKey) {
72
- const publicSigningKey = extractECDSAPublicKeyFromBase64String(publicKey);
73
- await this.storeAccountMetadata(address, 'publicSigningKey', publicSigningKey);
82
+ publicSigningKey = extractECDSAPublicKeyFromBase64String(publicKey);
74
83
  }
75
- await this.#aliases.set('accounts:last', Buffer.from(address.toString()));
84
+ await this.#store.transactionAsync(async ()=>{
85
+ if (alias) {
86
+ await this.#aliases.set(`accounts:${alias}`, Buffer.from(address.toString()));
87
+ }
88
+ await this.#accounts.set(`${address.toString()}:type`, Buffer.from(type));
89
+ await this.#accounts.set(`${address.toString()}:sk`, secretKey.toBuffer());
90
+ await this.#accounts.set(`${address.toString()}:salt`, salt.toBuffer());
91
+ if (publicSigningKey) {
92
+ await this.#accounts.set(`${address.toString()}:publicSigningKey`, publicSigningKey);
93
+ }
94
+ await this.#aliases.set('accounts:last', Buffer.from(address.toString()));
95
+ });
76
96
  log(`Account stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
77
97
  await this.refreshAliasCache();
78
98
  }
@@ -82,54 +102,42 @@ export class WalletDB {
82
102
  await this.refreshAliasCache();
83
103
  }
84
104
  async storeContract(address, artifactPath, log, alias) {
85
- if (alias) {
86
- await this.#aliases.set(`contracts:${alias}`, Buffer.from(address.toString()));
87
- await this.#aliases.set(`artifacts:${alias}`, Buffer.from(artifactPath));
88
- }
89
- await this.#aliases.set(`contracts:last`, Buffer.from(address.toString()));
90
- await this.#aliases.set(`artifacts:last`, Buffer.from(artifactPath));
91
- await this.#aliases.set(`artifacts:${address.toString()}`, Buffer.from(artifactPath));
105
+ await this.#store.transactionAsync(async ()=>{
106
+ if (alias) {
107
+ await this.#aliases.set(`contracts:${alias}`, Buffer.from(address.toString()));
108
+ await this.#aliases.set(`artifacts:${alias}`, Buffer.from(artifactPath));
109
+ }
110
+ await this.#aliases.set(`contracts:last`, Buffer.from(address.toString()));
111
+ await this.#aliases.set(`artifacts:last`, Buffer.from(artifactPath));
112
+ await this.#aliases.set(`artifacts:${address.toString()}`, Buffer.from(artifactPath));
113
+ });
92
114
  log(`Contract stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
93
115
  await this.refreshAliasCache();
94
116
  }
95
117
  async storeAuthwitness(authWit, log, alias) {
96
- if (alias) {
97
- await this.#aliases.set(`authwits:${alias}`, Buffer.from(authWit.toString()));
98
- }
99
- await this.#aliases.set(`authwits:last`, Buffer.from(authWit.toString()));
118
+ await this.#store.transactionAsync(async ()=>{
119
+ if (alias) {
120
+ await this.#aliases.set(`authwits:${alias}`, Buffer.from(authWit.toString()));
121
+ }
122
+ await this.#aliases.set(`authwits:last`, Buffer.from(authWit.toString()));
123
+ });
100
124
  log(`Authorization witness stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
101
125
  await this.refreshAliasCache();
102
126
  }
103
- async storeTx({ txHash, nonce, cancellable, gasSettings }, log, alias) {
104
- if (alias) {
105
- await this.#aliases.set(`transactions:${alias}`, Buffer.from(txHash.toString()));
106
- }
107
- await this.#transactions.set(`${txHash.toString()}:nonce`, nonce.toBuffer());
108
- await this.#transactions.set(`${txHash.toString()}:cancellable`, Buffer.from(cancellable ? 'true' : 'false'));
109
- await this.#transactions.set(`${txHash.toString()}:gasSettings`, gasSettings.toBuffer());
110
- await this.#aliases.set(`transactions:last`, Buffer.from(txHash.toString()));
127
+ async storeTx({ txHash }, log, alias) {
128
+ await this.#store.transactionAsync(async ()=>{
129
+ if (alias) {
130
+ await this.#aliases.set(`transactions:${alias}`, Buffer.from(txHash.toString()));
131
+ }
132
+ await this.#aliases.set(`transactions:last`, Buffer.from(txHash.toString()));
133
+ });
111
134
  log(`Transaction hash stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
112
135
  await this.refreshAliasCache();
113
136
  }
114
- async retrieveTxData(txHash) {
115
- const nonceBuffer = await this.#transactions.getAsync(`${txHash.toString()}:nonce`);
116
- if (!nonceBuffer) {
117
- throw new Error(`Could not find ${txHash.toString()}:nonce. Transaction with hash "${txHash.toString()}" does not exist on this wallet.`);
118
- }
119
- const nonce = Fr.fromBuffer(nonceBuffer);
120
- const cancellable = (await this.#transactions.getAsync(`${txHash.toString()}:cancellable`)).toString() === 'true';
121
- const gasBuffer = await this.#transactions.getAsync(`${txHash.toString()}:gasSettings`);
122
- return {
123
- txHash,
124
- nonce,
125
- cancellable,
126
- gasSettings: GasSettings.fromBuffer(gasBuffer)
127
- };
128
- }
129
137
  tryRetrieveAlias(arg) {
130
138
  try {
131
139
  return this.retrieveAliasFromCache(arg);
132
- } catch (e) {
140
+ } catch {
133
141
  return arg;
134
142
  }
135
143
  }
@@ -0,0 +1,6 @@
1
+ import type { ContractArtifact } from '@aztec/aztec.js/abi';
2
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
3
+ import type { LogFn } from '@aztec/foundation/log';
4
+ import type { OffchainEffect } from '@aztec/stdlib/tx';
5
+ export declare function printAuthorizations(offchainEffects: OffchainEffect[], artifactRetriever: (address: AztecAddress) => Promise<ContractArtifact | undefined>, log: LogFn): Promise<void>;
6
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXV0aG9yaXphdGlvbnMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy9hdXRob3JpemF0aW9ucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBQzVELE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBRTlELE9BQU8sS0FBSyxFQUFFLEtBQUssRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBRW5ELE9BQU8sS0FBSyxFQUFFLGNBQWMsRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBSXZELHdCQUFzQixtQkFBbUIsQ0FDdkMsZUFBZSxFQUFFLGNBQWMsRUFBRSxFQUNqQyxpQkFBaUIsRUFBRSxDQUFDLE9BQU8sRUFBRSxZQUFZLEtBQUssT0FBTyxDQUFDLGdCQUFnQixHQUFHLFNBQVMsQ0FBQyxFQUNuRixHQUFHLEVBQUUsS0FBSyxpQkFzQ1gifQ==
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorizations.d.ts","sourceRoot":"","sources":["../../src/utils/authorizations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIvD,wBAAsB,mBAAmB,CACvC,eAAe,EAAE,cAAc,EAAE,EACjC,iBAAiB,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,EACnF,GAAG,EAAE,KAAK,iBAsCX"}
@@ -0,0 +1,28 @@
1
+ import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization';
2
+ import { decodeFromAbi, getFunctionArtifact } from '@aztec/stdlib/abi';
3
+ import { format } from 'util';
4
+ export async function printAuthorizations(offchainEffects, artifactRetriever, log) {
5
+ log(format('\nAuthorizations requested by the tx:\n'));
6
+ const callAuthorizationSelector = await CallAuthorizationRequest.getSelector();
7
+ const callAuthorizationEffects = offchainEffects.filter((effect)=>effect.data[0].equals(callAuthorizationSelector.toField()));
8
+ for (const callAuthorizationEffect of callAuthorizationEffects){
9
+ const callAuthorizationRequest = await CallAuthorizationRequest.fromFields(callAuthorizationEffect.data);
10
+ const artifact = await artifactRetriever(callAuthorizationEffect.contractAddress);
11
+ if (!artifact) {
12
+ log(format(' -', `Call authorization. Inner hash: ${callAuthorizationRequest.innerHash.toString()}\n`));
13
+ log(format(' ', `Contract: unknown@${callAuthorizationEffect.contractAddress}`));
14
+ log(format(' ', `${callAuthorizationRequest.functionSelector.toString()}(\n${callAuthorizationRequest.args.map((arg)=>` ${arg.toString()}`).join(',\n')}\n )`));
15
+ } else {
16
+ const functionAbi = await getFunctionArtifact(artifact, callAuthorizationRequest.functionSelector);
17
+ const callData = decodeFromAbi(functionAbi.parameters.map((param)=>param.type), callAuthorizationRequest.args);
18
+ const parameters = functionAbi.parameters.map((param, i)=>({
19
+ name: param.name,
20
+ value: callData[i]
21
+ }));
22
+ log(format(' -', `Call authorization. Inner hash: ${callAuthorizationRequest.innerHash.toString()}`));
23
+ log(format(' ', `Contract: ${artifact.name}@${callAuthorizationEffect.contractAddress}`));
24
+ log(format(' ', /* eslint-disable-next-line @typescript-eslint/no-base-to-string */ `${functionAbi.name}(\n${parameters.map((p)=>` ${p.name}: ${p.value}`).join(',\n')}\n )`));
25
+ }
26
+ log(`\n`);
27
+ }
28
+ }
@@ -0,0 +1,12 @@
1
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
2
+ import { CLIWallet } from './wallet.js';
3
+ export declare const DEFAULT_TX_TIMEOUT_S = 180;
4
+ export declare class CliWalletAndNodeWrapper {
5
+ private _wallet;
6
+ private _node;
7
+ constructor();
8
+ get wallet(): CLIWallet;
9
+ get node(): AztecNode;
10
+ setNodeAndWallet(node: AztecNode, wallet: CLIWallet): void;
11
+ }
12
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xpX3dhbGxldF9hbmRfbm9kZV93cmFwcGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMvY2xpX3dhbGxldF9hbmRfbm9kZV93cmFwcGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBRWpFLE9BQU8sRUFBRSxTQUFTLEVBQUUsTUFBTSxhQUFhLENBQUM7QUFFeEMsZUFBTyxNQUFNLG9CQUFvQixNQUFNLENBQUM7QUFNeEMscUJBQWEsdUJBQXVCO0lBQ2xDLE9BQU8sQ0FBQyxPQUFPLENBQXdCO0lBQ3ZDLE9BQU8sQ0FBQyxLQUFLLENBQXdCO0lBRXJDLGNBQWdCO0lBRWhCLElBQUksTUFBTSxjQUtUO0lBRUQsSUFBSSxJQUFJLElBQUksU0FBUyxDQUtwQjtJQUVELGdCQUFnQixDQUFDLElBQUksRUFBRSxTQUFTLEVBQUUsTUFBTSxFQUFFLFNBQVMsUUFHbEQ7Q0FDRiJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli_wallet_and_node_wrapper.d.ts","sourceRoot":"","sources":["../../src/utils/cli_wallet_and_node_wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAEjE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAMxC,qBAAa,uBAAuB;IAClC,OAAO,CAAC,OAAO,CAAwB;IACvC,OAAO,CAAC,KAAK,CAAwB;IAErC,cAAgB;IAEhB,IAAI,MAAM,cAKT;IAED,IAAI,IAAI,IAAI,SAAS,CAKpB;IAED,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,QAGlD;CACF"}
@@ -0,0 +1,25 @@
1
+ export const DEFAULT_TX_TIMEOUT_S = 180;
2
+ /*
3
+ * Wrapper class for CLIWallet and AztecNode, avoids initialization issues due to closures when providing CLIWallet
4
+ * and AztecNode to injected commander.js commands
5
+ */ export class CliWalletAndNodeWrapper {
6
+ _wallet;
7
+ _node;
8
+ constructor(){}
9
+ get wallet() {
10
+ if (!this._wallet) {
11
+ throw new Error('Wallet not initialized while it should have been initialized in preSubcommand');
12
+ }
13
+ return this._wallet;
14
+ }
15
+ get node() {
16
+ if (!this._node) {
17
+ throw new Error('Node not initialized while it should have been initialized in preSubcommand');
18
+ }
19
+ return this._node;
20
+ }
21
+ setNodeAndWallet(node, wallet) {
22
+ this._node = node;
23
+ this._wallet = wallet;
24
+ }
25
+ }
@@ -0,0 +1,4 @@
1
+ export declare const MIN_FEE_PADDING = 0.5;
2
+ export declare const AccountTypes: readonly ["schnorr", "ecdsasecp256r1", "ecdsasecp256r1ssh", "ecdsasecp256k1"];
3
+ export type AccountType = (typeof AccountTypes)[number];
4
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3RhbnRzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMvY29uc3RhbnRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGVBQU8sTUFBTSxlQUFlLE1BQU0sQ0FBQztBQUVuQyxlQUFPLE1BQU0sWUFBWSwrRUFBZ0YsQ0FBQztBQUMxRyxNQUFNLE1BQU0sV0FBVyxHQUFHLENBQUMsT0FBTyxZQUFZLENBQUMsQ0FBQyxNQUFNLENBQUMsQ0FBQyJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,MAAM,CAAC;AAEnC,eAAO,MAAM,YAAY,+EAAgF,CAAC;AAC1G,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ export const MIN_FEE_PADDING = 0.5;
2
+ export const AccountTypes = [
3
+ 'schnorr',
4
+ 'ecdsasecp256r1',
5
+ 'ecdsasecp256r1ssh',
6
+ 'ecdsasecp256k1'
7
+ ];
@@ -1,4 +1,2 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
1
  export declare function extractECDSAPublicKeyFromBase64String(base64PublicKey: string): Buffer;
4
- //# sourceMappingURL=ecdsa.d.ts.map
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZWNkc2EuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy9lY2RzYS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSx3QkFBZ0IscUNBQXFDLENBQUMsZUFBZSxFQUFFLE1BQU0sR0FBRyxNQUFNLENBY3JGIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["../../src/utils/ecdsa.ts"],"names":[],"mappings":";;AAAA,wBAAgB,qCAAqC,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAcrF"}
1
+ {"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["../../src/utils/ecdsa.ts"],"names":[],"mappings":"AAAA,wBAAgB,qCAAqC,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAcrF"}