@aztec/cli-wallet 0.0.0-test.0 → 0.0.1-commit.001888fc

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 (111) 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 +148 -6
  13. package/dest/cmds/create_account.d.ts +9 -7
  14. package/dest/cmds/create_account.d.ts.map +1 -1
  15. package/dest/cmds/create_account.js +68 -35
  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 +7 -4
  20. package/dest/cmds/deploy.d.ts.map +1 -1
  21. package/dest/cmds/deploy.js +101 -58
  22. package/dest/cmds/deploy_account.d.ts +6 -8
  23. package/dest/cmds/deploy_account.d.ts.map +1 -1
  24. package/dest/cmds/deploy_account.js +67 -36
  25. package/dest/cmds/import_test_accounts.d.ts +3 -3
  26. package/dest/cmds/import_test_accounts.d.ts.map +1 -1
  27. package/dest/cmds/import_test_accounts.js +6 -9
  28. package/dest/cmds/index.d.ts +3 -3
  29. package/dest/cmds/index.d.ts.map +1 -1
  30. package/dest/cmds/index.js +83 -115
  31. package/dest/cmds/profile.d.ts +8 -0
  32. package/dest/cmds/profile.d.ts.map +1 -0
  33. package/dest/cmds/profile.js +28 -0
  34. package/dest/cmds/register_contract.d.ts +7 -3
  35. package/dest/cmds/register_contract.d.ts.map +1 -1
  36. package/dest/cmds/register_contract.js +20 -7
  37. package/dest/cmds/register_sender.d.ts +4 -3
  38. package/dest/cmds/register_sender.d.ts.map +1 -1
  39. package/dest/cmds/send.d.ts +8 -9
  40. package/dest/cmds/send.d.ts.map +1 -1
  41. package/dest/cmds/send.js +54 -28
  42. package/dest/cmds/simulate.d.ts +7 -3
  43. package/dest/cmds/simulate.d.ts.map +1 -1
  44. package/dest/cmds/simulate.js +26 -20
  45. package/dest/storage/wallet_db.d.ts +7 -19
  46. package/dest/storage/wallet_db.d.ts.map +1 -1
  47. package/dest/storage/wallet_db.js +49 -55
  48. package/dest/utils/authorizations.d.ts +6 -0
  49. package/dest/utils/authorizations.d.ts.map +1 -0
  50. package/dest/utils/authorizations.js +28 -0
  51. package/dest/utils/cli_wallet_and_node_wrapper.d.ts +12 -0
  52. package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -0
  53. package/dest/utils/cli_wallet_and_node_wrapper.js +25 -0
  54. package/dest/utils/constants.d.ts +4 -0
  55. package/dest/utils/constants.d.ts.map +1 -0
  56. package/dest/utils/constants.js +7 -0
  57. package/dest/utils/ecdsa.d.ts +1 -3
  58. package/dest/utils/ecdsa.d.ts.map +1 -1
  59. package/dest/utils/options/fees.d.ts +22 -28
  60. package/dest/utils/options/fees.d.ts.map +1 -1
  61. package/dest/utils/options/fees.js +88 -145
  62. package/dest/utils/options/index.d.ts +1 -1
  63. package/dest/utils/options/options.d.ts +9 -5
  64. package/dest/utils/options/options.d.ts.map +1 -1
  65. package/dest/utils/options/options.js +26 -14
  66. package/dest/utils/profiling.d.ts +5 -0
  67. package/dest/utils/profiling.d.ts.map +1 -0
  68. package/dest/utils/profiling.js +68 -0
  69. package/dest/utils/wallet.d.ts +40 -0
  70. package/dest/utils/wallet.d.ts.map +1 -0
  71. package/dest/utils/wallet.js +208 -0
  72. package/package.json +29 -22
  73. package/src/bin/index.ts +63 -33
  74. package/src/cmds/authorize_action.ts +16 -5
  75. package/src/cmds/bridge_fee_juice.ts +16 -12
  76. package/src/cmds/check_tx.ts +180 -5
  77. package/src/cmds/create_account.ts +76 -41
  78. package/src/cmds/create_authwit.ts +9 -5
  79. package/src/cmds/deploy.ts +106 -67
  80. package/src/cmds/deploy_account.ts +76 -36
  81. package/src/cmds/import_test_accounts.ts +7 -11
  82. package/src/cmds/index.ts +257 -221
  83. package/src/cmds/profile.ts +48 -0
  84. package/src/cmds/register_contract.ts +28 -5
  85. package/src/cmds/register_sender.ts +3 -2
  86. package/src/cmds/send.ts +54 -25
  87. package/src/cmds/simulate.ts +37 -24
  88. package/src/storage/wallet_db.ts +53 -68
  89. package/src/utils/authorizations.ts +51 -0
  90. package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
  91. package/src/utils/constants.ts +4 -0
  92. package/src/utils/options/fees.ts +142 -207
  93. package/src/utils/options/options.ts +41 -19
  94. package/src/utils/profiling.ts +172 -0
  95. package/src/utils/wallet.ts +290 -0
  96. package/dest/cmds/add_authwit.d.ts +0 -4
  97. package/dest/cmds/add_authwit.d.ts.map +0 -1
  98. package/dest/cmds/add_authwit.js +0 -4
  99. package/dest/cmds/cancel_tx.d.ts +0 -11
  100. package/dest/cmds/cancel_tx.d.ts.map +0 -1
  101. package/dest/cmds/cancel_tx.js +0 -38
  102. package/dest/utils/accounts.d.ts +0 -11
  103. package/dest/utils/accounts.d.ts.map +0 -1
  104. package/dest/utils/accounts.js +0 -87
  105. package/dest/utils/pxe_wrapper.d.ts +0 -10
  106. package/dest/utils/pxe_wrapper.d.ts.map +0 -1
  107. package/dest/utils/pxe_wrapper.js +0 -21
  108. package/src/cmds/add_authwit.ts +0 -13
  109. package/src/cmds/cancel_tx.ts +0 -62
  110. package/src/utils/accounts.ts +0 -102
  111. package/src/utils/pxe_wrapper.ts +0 -26
@@ -1,22 +1,36 @@
1
- import type { AccountManager, DeployAccountOptions } from '@aztec/aztec.js';
1
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { NO_WAIT } from '@aztec/aztec.js/contracts';
3
+ import type { AztecNode } from '@aztec/aztec.js/node';
4
+ import type { DeployAccountOptions } from '@aztec/aztec.js/wallet';
2
5
  import { prettyPrintJSON } from '@aztec/cli/cli-utils';
3
6
  import type { LogFn, Logger } from '@aztec/foundation/log';
7
+ import type { TxHash, TxReceipt } from '@aztec/stdlib/tx';
4
8
 
5
- import { type IFeeOpts, printGasEstimates } from '../utils/options/fees.js';
9
+ import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
10
+ import type { CLIFeeArgs } from '../utils/options/fees.js';
11
+ import { printProfileResult } from '../utils/profiling.js';
12
+ import type { CLIWallet } from '../utils/wallet.js';
6
13
 
7
14
  export async function deployAccount(
8
- account: AccountManager,
15
+ wallet: CLIWallet,
16
+ aztecNode: AztecNode,
17
+ address: AztecAddress,
9
18
  wait: boolean,
10
- feeOpts: IFeeOpts,
19
+ deployer: AztecAddress | undefined,
20
+ registerClass: boolean,
21
+ publicDeploy: boolean,
22
+ skipInitialization: boolean,
23
+ feeOpts: CLIFeeArgs,
11
24
  json: boolean,
25
+ verbose: boolean,
12
26
  debugLogger: Logger,
13
27
  log: LogFn,
14
28
  ) {
15
29
  const out: Record<string, any> = {};
16
- const { address, partialAddress, publicKeys } = await account.getCompleteAddress();
17
- const { initializationHash, deployer, salt } = account.getInstance();
18
- const wallet = await account.getWallet();
19
- const secretKey = wallet.getSecretKey();
30
+
31
+ const account = await wallet.createOrRetrieveAccount(address);
32
+ const { partialAddress, publicKeys } = await account.getCompleteAddress();
33
+ const { initializationHash, salt } = account.getInstance();
20
34
 
21
35
  if (json) {
22
36
  out.address = address;
@@ -28,65 +42,91 @@ export async function deployAccount(
28
42
  log(`\nNew account:\n`);
29
43
  log(`Address: ${address.toString()}`);
30
44
  log(`Public key: ${publicKeys.toString()}`);
31
- if (secretKey) {
32
- log(`Secret key: ${secretKey.toString()}`);
33
- }
34
45
  log(`Partial address: ${partialAddress.toString()}`);
35
46
  log(`Salt: ${salt.toString()}`);
36
47
  log(`Init hash: ${initializationHash.toString()}`);
37
- log(`Deployer: ${deployer.toString()}`);
38
48
  }
39
49
 
40
- let tx;
41
- let txReceipt;
50
+ let txHash: TxHash | undefined;
51
+ let txReceipt: TxReceipt | undefined;
52
+ const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(aztecNode, wallet, address);
42
53
 
43
- const deployOpts: DeployAccountOptions = {
44
- ...(await feeOpts.toDeployAccountOpts(wallet)),
45
- skipInitialization: false,
54
+ const delegatedDeployment = deployer && !account.address.equals(deployer);
55
+ const from = delegatedDeployment ? deployer : AztecAddress.ZERO;
56
+
57
+ const deployAccountOpts: DeployAccountOptions = {
58
+ skipClassPublication: !registerClass,
59
+ skipInstancePublication: !publicDeploy,
60
+ skipInitialization,
61
+ from,
62
+ fee: { paymentMethod, gasSettings },
46
63
  };
64
+
65
+ const deployMethod = await account.getDeployMethod();
66
+ const sim = await deployMethod.simulate({
67
+ ...deployAccountOpts,
68
+ fee: { ...deployAccountOpts.fee, estimateGas: true },
69
+ });
70
+ // estimateGas: true guarantees these fields are present
71
+ const estimatedGas = sim.estimatedGas!;
72
+ const stats = sim.stats!;
73
+
47
74
  if (feeOpts.estimateOnly) {
48
- const gas = await (await account.getDeployMethod(deployOpts.deployWallet)).estimateGas(deployOpts);
49
75
  if (json) {
50
76
  out.fee = {
51
77
  gasLimits: {
52
- da: gas.gasLimits.daGas,
53
- l2: gas.gasLimits.l2Gas,
78
+ da: estimatedGas.gasLimits.daGas,
79
+ l2: estimatedGas.gasLimits.l2Gas,
54
80
  },
55
81
  teardownGasLimits: {
56
- da: gas.teardownGasLimits.daGas,
57
- l2: gas.teardownGasLimits,
82
+ da: estimatedGas.teardownGasLimits.daGas,
83
+ l2: estimatedGas.teardownGasLimits,
58
84
  },
59
85
  };
60
- } else {
61
- printGasEstimates(feeOpts, gas, log);
62
86
  }
63
87
  } else {
64
- tx = account.deploy(deployOpts);
65
- const txHash = await tx.getTxHash();
66
- debugLogger.debug(`Account contract tx sent with hash ${txHash}`);
67
- out.txHash = txHash;
88
+ if (verbose) {
89
+ printProfileResult(stats, log);
90
+ }
91
+
92
+ if (!json) {
93
+ log(`\nWaiting for account contract deployment...`);
94
+ }
95
+ const sendOpts = {
96
+ ...deployAccountOpts,
97
+ fee: deployAccountOpts.fee
98
+ ? {
99
+ ...deployAccountOpts.fee,
100
+ gasSettings: estimatedGas,
101
+ }
102
+ : undefined,
103
+ };
68
104
  if (wait) {
69
- if (!json) {
70
- log(`\nWaiting for account contract deployment...`);
71
- }
72
- txReceipt = await tx.wait();
105
+ const { receipt } = await deployMethod.send({
106
+ ...sendOpts,
107
+ wait: { timeout: DEFAULT_TX_TIMEOUT_S, returnReceipt: true },
108
+ });
109
+ txReceipt = receipt;
110
+ txHash = receipt.txHash;
73
111
  out.txReceipt = {
74
112
  status: txReceipt.status,
75
113
  transactionFee: txReceipt.transactionFee,
76
114
  };
115
+ } else {
116
+ ({ txHash } = await deployMethod.send({ ...sendOpts, wait: NO_WAIT }));
77
117
  }
118
+ debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
119
+ out.txHash = txHash;
78
120
  }
79
121
 
80
122
  if (json) {
81
123
  log(prettyPrintJSON(out));
82
124
  } else {
83
- if (tx) {
84
- log(`Deploy tx hash: ${await tx.getTxHash()}`);
125
+ if (txHash) {
126
+ log(`Deploy tx hash: ${txHash.toString()}`);
85
127
  }
86
128
  if (txReceipt) {
87
129
  log(`Deploy tx fee: ${txReceipt.transactionFee}`);
88
130
  }
89
131
  }
90
-
91
- return { address, secretKey, salt };
92
132
  }
@@ -1,25 +1,21 @@
1
- import { getSchnorrAccount } from '@aztec/accounts/schnorr';
2
- import { getInitialTestAccounts } from '@aztec/accounts/testing';
3
- import { Fr, type PXE } from '@aztec/aztec.js';
1
+ import { getInitialTestAccountsData } from '@aztec/accounts/testing';
2
+ import { Fr } from '@aztec/aztec.js/fields';
4
3
  import { prettyPrintJSON } from '@aztec/cli/cli-utils';
5
4
  import type { LogFn } from '@aztec/foundation/log';
6
5
 
7
6
  import type { WalletDB } from '../storage/wallet_db.js';
7
+ import type { CLIWallet } from '../utils/wallet.js';
8
8
 
9
- export async function importTestAccounts(client: PXE, db: WalletDB, json: boolean, log: LogFn) {
10
- const testAccounts = await getInitialTestAccounts();
11
- const accounts = await Promise.all(
12
- testAccounts.map(({ secret, signingKey, salt }) => getSchnorrAccount(client, secret, signingKey, salt)),
13
- );
9
+ export async function importTestAccounts(wallet: CLIWallet, db: WalletDB, json: boolean, log: LogFn) {
10
+ const testAccounts = await getInitialTestAccountsData();
14
11
 
15
12
  const out: Record<string, any> = {};
16
13
  await Promise.all(
17
- accounts.map(async (account, i) => {
14
+ testAccounts.map(async (account, i) => {
18
15
  const alias = `test${i}`;
19
16
  const secret = testAccounts[i].secret;
20
17
  const salt = new Fr(account.salt);
21
- const address = account.getAddress();
22
- await account.register();
18
+ const address = account.address;
23
19
  await db.storeAccount(address, { type: 'schnorr', secretKey: secret, salt, alias, publicKey: undefined }, log);
24
20
 
25
21
  if (json) {