@aztec/cli-wallet 0.0.0-test.0 → 0.0.1-commit.023c3e5

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 +147 -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 +61 -36
  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 +98 -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 +60 -37
  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 +51 -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 +86 -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 +35 -0
  70. package/dest/utils/wallet.d.ts.map +1 -0
  71. package/dest/utils/wallet.js +204 -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 +72 -42
  78. package/src/cmds/create_authwit.ts +9 -5
  79. package/src/cmds/deploy.ts +103 -67
  80. package/src/cmds/deploy_account.ts +72 -37
  81. package/src/cmds/import_test_accounts.ts +7 -11
  82. package/src/cmds/index.ts +256 -220
  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 +51 -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 +136 -207
  93. package/src/utils/options/options.ts +41 -19
  94. package/src/utils/profiling.ts +172 -0
  95. package/src/utils/wallet.ts +283 -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,86 @@ 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 { estimatedGas, stats } = await deployMethod.simulate({
67
+ ...deployAccountOpts,
68
+ fee: { ...deployAccountOpts.fee, estimateGas: true },
69
+ });
70
+
47
71
  if (feeOpts.estimateOnly) {
48
- const gas = await (await account.getDeployMethod(deployOpts.deployWallet)).estimateGas(deployOpts);
49
72
  if (json) {
50
73
  out.fee = {
51
74
  gasLimits: {
52
- da: gas.gasLimits.daGas,
53
- l2: gas.gasLimits.l2Gas,
75
+ da: estimatedGas.gasLimits.daGas,
76
+ l2: estimatedGas.gasLimits.l2Gas,
54
77
  },
55
78
  teardownGasLimits: {
56
- da: gas.teardownGasLimits.daGas,
57
- l2: gas.teardownGasLimits,
79
+ da: estimatedGas.teardownGasLimits.daGas,
80
+ l2: estimatedGas.teardownGasLimits,
58
81
  },
59
82
  };
60
- } else {
61
- printGasEstimates(feeOpts, gas, log);
62
83
  }
63
84
  } 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;
68
- if (wait) {
69
- if (!json) {
70
- log(`\nWaiting for account contract deployment...`);
71
- }
72
- txReceipt = await tx.wait();
85
+ if (verbose) {
86
+ printProfileResult(stats, log);
87
+ }
88
+
89
+ if (!json) {
90
+ log(`\nWaiting for account contract deployment...`);
91
+ }
92
+ const result = await deployMethod.send({
93
+ ...deployAccountOpts,
94
+ fee: deployAccountOpts.fee
95
+ ? {
96
+ ...deployAccountOpts.fee,
97
+ gasSettings: estimatedGas,
98
+ }
99
+ : undefined,
100
+ wait: wait ? { timeout: DEFAULT_TX_TIMEOUT_S, returnReceipt: true } : NO_WAIT,
101
+ });
102
+ const isReceipt = (data: TxReceipt | TxHash): data is TxReceipt => 'txHash' in data;
103
+ if (isReceipt(result)) {
104
+ txReceipt = result;
105
+ txHash = result.txHash;
73
106
  out.txReceipt = {
74
107
  status: txReceipt.status,
75
108
  transactionFee: txReceipt.transactionFee,
76
109
  };
110
+ } else {
111
+ txHash = result;
77
112
  }
113
+ debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
114
+ out.txHash = txHash;
78
115
  }
79
116
 
80
117
  if (json) {
81
118
  log(prettyPrintJSON(out));
82
119
  } else {
83
- if (tx) {
84
- log(`Deploy tx hash: ${await tx.getTxHash()}`);
120
+ if (txHash) {
121
+ log(`Deploy tx hash: ${txHash.toString()}`);
85
122
  }
86
123
  if (txReceipt) {
87
124
  log(`Deploy tx fee: ${txReceipt.transactionFee}`);
88
125
  }
89
126
  }
90
-
91
- return { address, secretKey, salt };
92
127
  }
@@ -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) {