@aztec/cli-wallet 0.0.1-commit.1142ef1 → 0.0.1-commit.11bf3dd6e

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 (57) hide show
  1. package/dest/cmds/authorize_action.d.ts +2 -2
  2. package/dest/cmds/authorize_action.d.ts.map +1 -1
  3. package/dest/cmds/authorize_action.js +4 -2
  4. package/dest/cmds/check_tx.d.ts +1 -1
  5. package/dest/cmds/check_tx.d.ts.map +1 -1
  6. package/dest/cmds/check_tx.js +45 -14
  7. package/dest/cmds/create_account.d.ts +4 -3
  8. package/dest/cmds/create_account.d.ts.map +1 -1
  9. package/dest/cmds/create_account.js +42 -25
  10. package/dest/cmds/create_authwit.d.ts +2 -2
  11. package/dest/cmds/create_authwit.d.ts.map +1 -1
  12. package/dest/cmds/deploy.d.ts +4 -3
  13. package/dest/cmds/deploy.d.ts.map +1 -1
  14. package/dest/cmds/deploy.js +56 -29
  15. package/dest/cmds/deploy_account.d.ts +4 -3
  16. package/dest/cmds/deploy_account.d.ts.map +1 -1
  17. package/dest/cmds/deploy_account.js +37 -20
  18. package/dest/cmds/get_fee_juice_balance.d.ts +5 -0
  19. package/dest/cmds/get_fee_juice_balance.d.ts.map +1 -0
  20. package/dest/cmds/get_fee_juice_balance.js +27 -0
  21. package/dest/cmds/index.d.ts +1 -1
  22. package/dest/cmds/index.d.ts.map +1 -1
  23. package/dest/cmds/index.js +30 -14
  24. package/dest/cmds/send.d.ts +5 -4
  25. package/dest/cmds/send.d.ts.map +1 -1
  26. package/dest/cmds/send.js +32 -16
  27. package/dest/cmds/simulate.d.ts +1 -1
  28. package/dest/cmds/simulate.d.ts.map +1 -1
  29. package/dest/cmds/simulate.js +3 -3
  30. package/dest/storage/wallet_db.d.ts +6 -1
  31. package/dest/storage/wallet_db.d.ts.map +1 -1
  32. package/dest/storage/wallet_db.js +60 -31
  33. package/dest/utils/options/fees.d.ts +3 -2
  34. package/dest/utils/options/fees.d.ts.map +1 -1
  35. package/dest/utils/options/fees.js +32 -9
  36. package/dest/utils/options/options.d.ts +2 -2
  37. package/dest/utils/options/options.d.ts.map +1 -1
  38. package/dest/utils/profiling.d.ts +1 -1
  39. package/dest/utils/profiling.d.ts.map +1 -1
  40. package/dest/utils/profiling.js +9 -1
  41. package/dest/utils/wallet.d.ts +12 -5
  42. package/dest/utils/wallet.d.ts.map +1 -1
  43. package/dest/utils/wallet.js +87 -47
  44. package/package.json +15 -15
  45. package/src/cmds/authorize_action.ts +1 -1
  46. package/src/cmds/check_tx.ts +50 -19
  47. package/src/cmds/create_account.ts +44 -24
  48. package/src/cmds/deploy.ts +55 -27
  49. package/src/cmds/deploy_account.ts +38 -19
  50. package/src/cmds/get_fee_juice_balance.ts +37 -0
  51. package/src/cmds/index.ts +57 -4
  52. package/src/cmds/send.ts +32 -12
  53. package/src/cmds/simulate.ts +4 -7
  54. package/src/storage/wallet_db.ts +63 -36
  55. package/src/utils/options/fees.ts +39 -9
  56. package/src/utils/profiling.ts +15 -1
  57. package/src/utils/wallet.ts +99 -63
@@ -1,8 +1,9 @@
1
1
  import { EcdsaRAccountContract, EcdsaRSSHAccountContract } from '@aztec/accounts/ecdsa';
2
2
  import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
3
- import { StubAccountContractArtifact, createStubAccount } from '@aztec/accounts/stub';
3
+ import { StubEcdsaAccountContractArtifact, createStubEcdsaAccount } from '@aztec/accounts/stub/ecdsa';
4
+ import { StubSchnorrAccountContractArtifact, createStubSchnorrAccount } from '@aztec/accounts/stub/schnorr';
4
5
  import { getIdentities } from '@aztec/accounts/utils';
5
- import { type Account, type AccountContract, SignerlessAccount } from '@aztec/aztec.js/account';
6
+ import { type Account, type AccountContract, NO_FROM } from '@aztec/aztec.js/account';
6
7
  import {
7
8
  type InteractionFeeOptions,
8
9
  getContractInstanceFromInstantiationParams,
@@ -10,19 +11,21 @@ import {
10
11
  } from '@aztec/aztec.js/contracts';
11
12
  import type { AztecNode } from '@aztec/aztec.js/node';
12
13
  import { AccountManager, type Aliased, type SimulateOptions } from '@aztec/aztec.js/wallet';
14
+ import { TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
13
15
  import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
16
+ import { DefaultEntrypoint } from '@aztec/entrypoints/default';
14
17
  import { Fr } from '@aztec/foundation/curves/bn254';
15
18
  import type { LogFn } from '@aztec/foundation/log';
19
+ import type { NotesFilter } from '@aztec/pxe/client/lazy';
16
20
  import type { PXEConfig } from '@aztec/pxe/config';
17
21
  import type { PXE } from '@aztec/pxe/server';
18
22
  import { createPXE, getPXEConfig } from '@aztec/pxe/server';
19
23
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
20
24
  import { deriveSigningKey } from '@aztec/stdlib/keys';
21
25
  import { NoteDao } from '@aztec/stdlib/note';
22
- import type { NotesFilter } from '@aztec/stdlib/note';
23
- import type { TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
26
+ import type { SimulationOverrides, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx';
24
27
  import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
25
- import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
28
+ import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk/base-wallet';
26
29
 
27
30
  import type { WalletDB } from '../storage/wallet_db.js';
28
31
  import type { AccountType } from './constants.js';
@@ -55,7 +58,12 @@ export class CLIWallet extends BaseWallet {
55
58
 
56
59
  override async getAccounts(): Promise<Aliased<AztecAddress>[]> {
57
60
  const accounts = (await this.db?.listAliases('accounts')) ?? [];
58
- return Promise.resolve(accounts.map(({ key, value }) => ({ alias: value, item: AztecAddress.fromString(key) })));
61
+ return Promise.resolve(
62
+ accounts.map(({ key, value }) => {
63
+ const alias = key.includes(':') ? key.slice(key.indexOf(':') + 1) : key;
64
+ return { alias, item: AztecAddress.fromString(value) };
65
+ }),
66
+ );
59
67
  }
60
68
 
61
69
  private async createCancellationTxExecutionRequest(
@@ -64,17 +72,24 @@ export class CLIWallet extends BaseWallet {
64
72
  increasedFee: InteractionFeeOptions,
65
73
  ) {
66
74
  const executionPayload = ExecutionPayload.empty();
67
- const feeOptions = await this.completeFeeOptions(from, executionPayload.feePayer, increasedFee.gasSettings);
75
+ const feeOptions = await this.completeFeeOptions({
76
+ from,
77
+ feePayer: executionPayload.feePayer,
78
+ gasSettings: increasedFee.gasSettings,
79
+ });
68
80
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
69
81
  const fromAccount = await this.getAccountFromAddress(from);
82
+ const chainInfo = await this.getChainInfo();
70
83
  const executionOptions: DefaultAccountEntrypointOptions = {
71
84
  txNonce,
72
85
  cancellable: this.cancellableTransactions,
73
- feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
86
+ // If from is an address, feeOptions include the way the account contract should handle the fee payment
87
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
74
88
  };
75
89
  return await fromAccount.createTxExecutionRequest(
76
90
  feeExecutionPayload ?? executionPayload,
77
91
  feeOptions.gasSettings,
92
+ chainInfo,
78
93
  executionOptions,
79
94
  );
80
95
  }
@@ -85,15 +100,12 @@ export class CLIWallet extends BaseWallet {
85
100
  increasedFee: InteractionFeeOptions,
86
101
  ): Promise<TxProvingResult> {
87
102
  const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
88
- return await this.pxe.proveTx(cancellationTxRequest);
103
+ return await this.pxe.proveTx(cancellationTxRequest, this.scopesFrom(from));
89
104
  }
90
105
 
91
106
  override async getAccountFromAddress(address: AztecAddress) {
92
107
  let account: Account | undefined;
93
- if (address.equals(AztecAddress.ZERO)) {
94
- const chainInfo = await this.getChainInfo();
95
- account = new SignerlessAccount(chainInfo);
96
- } else if (this.accountCache.has(address.toString())) {
108
+ if (this.accountCache.has(address.toString())) {
97
109
  return this.accountCache.get(address.toString())!;
98
110
  } else {
99
111
  const accountManager = await this.createOrRetrieveAccount(address);
@@ -176,76 +188,94 @@ export class CLIWallet extends BaseWallet {
176
188
  return account;
177
189
  }
178
190
 
191
+ /**
192
+ * Creates a stub account that impersonates the given address, allowing kernelless simulations
193
+ * to bypass the account's authorization mechanisms via contract overrides.
194
+ * @param address - The address of the account to impersonate
195
+ * @returns The stub account, contract instance, and artifact for simulation
196
+ */
179
197
  private async getFakeAccountDataFor(address: AztecAddress) {
180
- const chainInfo = await this.getChainInfo();
181
198
  const originalAccount = await this.getAccountFromAddress(address);
182
199
  const originalAddress = originalAccount.getCompleteAddress();
183
- const { contractInstance } = await this.pxe.getContractMetadata(originalAddress.address);
200
+ const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
184
201
  if (!contractInstance) {
185
202
  throw new Error(`No contract instance found for address: ${originalAddress.address}`);
186
203
  }
187
- const stubAccount = createStubAccount(originalAddress, chainInfo);
188
- const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
189
- salt: Fr.random(),
190
- });
191
- return {
192
- account: stubAccount,
193
- instance,
194
- artifact: StubAccountContractArtifact,
195
- };
204
+ const { type } = await this.db!.retrieveAccount(address);
205
+ const isSchnorr = type === 'schnorr';
206
+ const artifact = isSchnorr ? StubSchnorrAccountContractArtifact : StubEcdsaAccountContractArtifact;
207
+ const stubAccount = isSchnorr ? createStubSchnorrAccount(originalAddress) : createStubEcdsaAccount(originalAddress);
208
+ const instance = await getContractInstanceFromInstantiationParams(artifact, { salt: Fr.random() });
209
+ return { account: stubAccount, instance, artifact };
196
210
  }
197
211
 
198
- override async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
199
- let simulationResults;
200
- const feeOptions = opts.fee?.estimateGas
201
- ? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings)
202
- : await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
212
+ override async simulateTx(
213
+ executionPayload: ExecutionPayload,
214
+ opts: SimulateOptions,
215
+ ): Promise<TxSimulationResultWithAppOffset> {
216
+ const simulationResults = await super.simulateTx(executionPayload, opts);
217
+
218
+ if (opts.fee?.estimateGas) {
219
+ const feeOptions = await this.completeFeeOptions({
220
+ from: opts.from,
221
+ feePayer: executionPayload.feePayer,
222
+ gasSettings: opts.fee?.gasSettings,
223
+ });
224
+ const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
225
+ printGasEstimates(feeOptions, limits, this.userLog);
226
+ }
227
+ return simulationResults;
228
+ }
229
+
230
+ /**
231
+ * Uses a stub account for kernelless simulation, bypassing real account authorization.
232
+ * Uses DefaultEntrypoint directly for NO_FROM transactions.
233
+ */
234
+ protected override async simulateViaEntrypoint(
235
+ executionPayload: ExecutionPayload,
236
+ opts: SimulateViaEntrypointOptions,
237
+ ): Promise<TxSimulationResultWithAppOffset> {
238
+ const { from, feeOptions, additionalScopes } = opts;
239
+ const scopes = this.scopesFrom(from, additionalScopes);
203
240
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
204
- const executionOptions: DefaultAccountEntrypointOptions = {
205
- txNonce: Fr.random(),
206
- cancellable: this.cancellableTransactions,
207
- feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
208
- };
209
241
  const finalExecutionPayload = feeExecutionPayload
210
242
  ? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
211
243
  : executionPayload;
244
+ const chainInfo = await this.getChainInfo();
212
245
 
213
- // Kernelless simulations using the multicall entrypoints are not currently supported,
214
- // since we only override proper account contracts.
215
- // TODO: allow disabling kernels even when no overrides are necessary
216
- if (opts.from.equals(AztecAddress.ZERO)) {
217
- const fromAccount = await this.getAccountFromAddress(opts.from);
218
- const txRequest = await fromAccount.createTxExecutionRequest(
219
- finalExecutionPayload,
220
- feeOptions.gasSettings,
221
- executionOptions,
222
- );
223
- simulationResults = await this.pxe.simulateTx(
224
- txRequest,
225
- true /* simulatePublic */,
226
- opts?.skipTxValidation,
227
- opts?.skipFeeEnforcement ?? true,
228
- );
246
+ let overrides: SimulationOverrides | undefined;
247
+ let txRequest: TxExecutionRequest;
248
+ if (from === NO_FROM) {
249
+ const entrypoint = new DefaultEntrypoint();
250
+ txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
229
251
  } else {
230
- const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(opts.from);
231
- const txRequest = await fromAccount.createTxExecutionRequest(
252
+ const { account, instance, artifact } = await this.getFakeAccountDataFor(from);
253
+ overrides = {
254
+ contracts: { [from.toString()]: { instance, artifact } },
255
+ };
256
+ const executionOptions: DefaultAccountEntrypointOptions = {
257
+ txNonce: Fr.random(),
258
+ cancellable: this.cancellableTransactions,
259
+ // If from is an address, feeOptions include the way the account contract should handle the fee payment
260
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
261
+ };
262
+ txRequest = await account.createTxExecutionRequest(
232
263
  finalExecutionPayload,
233
264
  feeOptions.gasSettings,
265
+ chainInfo,
234
266
  executionOptions,
235
267
  );
236
- const contractOverrides = {
237
- [opts.from.toString()]: { instance, artifact },
238
- };
239
- simulationResults = await this.pxe.simulateTx(txRequest, true /* simulatePublic */, true, true, {
240
- contracts: contractOverrides,
241
- });
242
268
  }
243
269
 
244
- if (opts.fee?.estimateGas) {
245
- const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
246
- printGasEstimates(feeOptions, limits, this.userLog);
247
- }
248
- return simulationResults;
270
+ const result = await this.pxe.simulateTx(txRequest, {
271
+ simulatePublic: true,
272
+ skipFeeEnforcement: true,
273
+ skipTxValidation: true,
274
+ overrides,
275
+ scopes,
276
+ });
277
+ const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
278
+ return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
249
279
  }
250
280
 
251
281
  // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
@@ -259,4 +289,10 @@ export class CLIWallet extends BaseWallet {
259
289
  getNotes(filter: NotesFilter): Promise<NoteDao[]> {
260
290
  return this.pxe.debug.getNotes(filter);
261
291
  }
292
+
293
+ // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
294
+ // this is just a CLI wallet.
295
+ getContractArtifact(id: Fr) {
296
+ return this.pxe.getContractArtifact(id);
297
+ }
262
298
  }