@aztec/cli-wallet 0.0.1-commit.a072138 → 0.0.1-commit.a4600f49

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/bin/index.js +1 -1
  2. package/dest/cmds/authorize_action.d.ts +2 -2
  3. package/dest/cmds/authorize_action.d.ts.map +1 -1
  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 +50 -21
  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 +36 -26
  10. package/dest/cmds/deploy.d.ts +5 -4
  11. package/dest/cmds/deploy.d.ts.map +1 -1
  12. package/dest/cmds/deploy.js +44 -38
  13. package/dest/cmds/deploy_account.d.ts +4 -3
  14. package/dest/cmds/deploy_account.d.ts.map +1 -1
  15. package/dest/cmds/deploy_account.js +28 -20
  16. package/dest/cmds/get_fee_juice_balance.d.ts +5 -0
  17. package/dest/cmds/get_fee_juice_balance.d.ts.map +1 -0
  18. package/dest/cmds/get_fee_juice_balance.js +27 -0
  19. package/dest/cmds/import_test_accounts.d.ts +1 -1
  20. package/dest/cmds/import_test_accounts.d.ts.map +1 -1
  21. package/dest/cmds/import_test_accounts.js +1 -1
  22. package/dest/cmds/index.d.ts +1 -1
  23. package/dest/cmds/index.d.ts.map +1 -1
  24. package/dest/cmds/index.js +31 -15
  25. package/dest/cmds/send.d.ts +4 -3
  26. package/dest/cmds/send.d.ts.map +1 -1
  27. package/dest/cmds/send.js +28 -27
  28. package/dest/cmds/simulate.d.ts +1 -1
  29. package/dest/cmds/simulate.d.ts.map +1 -1
  30. package/dest/cmds/simulate.js +2 -1
  31. package/dest/storage/wallet_db.d.ts +7 -2
  32. package/dest/storage/wallet_db.d.ts.map +1 -1
  33. package/dest/storage/wallet_db.js +14 -0
  34. package/dest/utils/constants.d.ts +2 -2
  35. package/dest/utils/constants.d.ts.map +1 -1
  36. package/dest/utils/constants.js +1 -0
  37. package/dest/utils/options/fees.d.ts +3 -2
  38. package/dest/utils/options/fees.d.ts.map +1 -1
  39. package/dest/utils/options/fees.js +36 -10
  40. package/dest/utils/wallet.d.ts +24 -6
  41. package/dest/utils/wallet.d.ts.map +1 -1
  42. package/dest/utils/wallet.js +135 -60
  43. package/package.json +16 -15
  44. package/src/bin/index.ts +1 -1
  45. package/src/cmds/check_tx.ts +57 -24
  46. package/src/cmds/create_account.ts +36 -20
  47. package/src/cmds/deploy.ts +41 -33
  48. package/src/cmds/deploy_account.ts +27 -14
  49. package/src/cmds/get_fee_juice_balance.ts +37 -0
  50. package/src/cmds/import_test_accounts.ts +5 -1
  51. package/src/cmds/index.ts +60 -6
  52. package/src/cmds/send.ts +25 -17
  53. package/src/cmds/simulate.ts +3 -2
  54. package/src/storage/wallet_db.ts +14 -0
  55. package/src/utils/constants.ts +7 -1
  56. package/src/utils/options/fees.ts +42 -10
  57. package/src/utils/wallet.ts +148 -76
@@ -1,36 +1,46 @@
1
1
  import { EcdsaRAccountContract, EcdsaRSSHAccountContract } from '@aztec/accounts/ecdsa';
2
- import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
3
- import { StubAccountContractArtifact, createStubAccount } from '@aztec/accounts/stub';
2
+ import { StubEcdsaAccountContractArtifact, createStubEcdsaAccount } from '@aztec/accounts/ecdsa/stub';
3
+ import { SchnorrAccountContract, SchnorrInitializerlessAccountContract } from '@aztec/accounts/schnorr';
4
+ import { StubSchnorrAccountContractArtifact, createStubSchnorrAccount } from '@aztec/accounts/schnorr/stub';
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 {
8
+ ContractFunctionInteraction,
7
9
  type InteractionFeeOptions,
8
- getContractInstanceFromInstantiationParams,
9
- getGasLimits,
10
+ getContractClassFromArtifact,
10
11
  } from '@aztec/aztec.js/contracts';
11
12
  import type { AztecNode } from '@aztec/aztec.js/node';
12
- import { AccountManager, type Aliased, type SimulateOptions } from '@aztec/aztec.js/wallet';
13
+ import { AccountManager, type Aliased } 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';
23
+ import { getStandardAuthRegistry } from '@aztec/standard-contracts/auth-registry';
19
24
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
25
+ import type { Gas, GasUsed } from '@aztec/stdlib/gas';
20
26
  import { deriveSigningKey } from '@aztec/stdlib/keys';
21
27
  import { NoteDao } from '@aztec/stdlib/note';
22
- import type { NotesFilter } from '@aztec/stdlib/note';
23
- import type { TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
28
+ import type { SimulationOverrides, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx';
24
29
  import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
25
- import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
30
+ import { BaseWallet, type SimulateViaEntrypointOptions, getGasLimits } from '@aztec/wallet-sdk/base-wallet';
26
31
 
27
32
  import type { WalletDB } from '../storage/wallet_db.js';
28
33
  import type { AccountType } from './constants.js';
29
34
  import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
30
- import { printGasEstimates } from './options/fees.js';
35
+
36
+ /** Padding the CLI wallet applies to simulated gas usage when deriving declared gas limits. */
37
+ const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
31
38
 
32
39
  export class CLIWallet extends BaseWallet {
33
40
  private accountCache = new Map<string, Account>();
41
+ // Stub class ids, populated on wallet startup
42
+ // to avoid redundant work per simulation
43
+ private stubClassIds = new Map<AccountType, Fr>();
34
44
 
35
45
  constructor(
36
46
  pxe: PXE,
@@ -50,12 +60,55 @@ export class CLIWallet extends BaseWallet {
50
60
  ): Promise<CLIWallet> {
51
61
  const pxeConfig = Object.assign(getPXEConfig(), overridePXEConfig);
52
62
  const pxe = await createPXE(node, pxeConfig);
53
- return new CLIWallet(pxe, node, log, db);
63
+ const wallet = new CLIWallet(pxe, node, log, db);
64
+ await wallet.initStubClasses();
65
+ await wallet.registerAuthRegistry();
66
+ return wallet;
67
+ }
68
+
69
+ private async registerAuthRegistry(): Promise<void> {
70
+ const { instance, artifact } = await getStandardAuthRegistry();
71
+ await this.pxe.registerContractClass(artifact);
72
+ await this.pxe.registerContract(instance);
73
+ }
74
+
75
+ /**
76
+ * Hashes and registers the stub class for every supported account type with PXE, populating
77
+ * stubClassIds. Called on wallet initialization.
78
+ */
79
+ private async initStubClasses(): Promise<void> {
80
+ const { id: schnorrClassId } = await getContractClassFromArtifact(StubSchnorrAccountContractArtifact);
81
+ await this.pxe.registerContractClass(StubSchnorrAccountContractArtifact);
82
+
83
+ // ecdsa stubs share the same class id
84
+ const { id: ecdsaClassId } = await getContractClassFromArtifact(StubEcdsaAccountContractArtifact);
85
+ await this.pxe.registerContractClass(StubEcdsaAccountContractArtifact);
86
+
87
+ this.stubClassIds.set('schnorr', schnorrClassId);
88
+ this.stubClassIds.set('schnorr_initializerless', schnorrClassId);
89
+ this.stubClassIds.set('ecdsasecp256k1', ecdsaClassId);
90
+ this.stubClassIds.set('ecdsasecp256r1', ecdsaClassId);
91
+ this.stubClassIds.set('ecdsasecp256r1ssh', ecdsaClassId);
54
92
  }
55
93
 
56
94
  override async getAccounts(): Promise<Aliased<AztecAddress>[]> {
57
95
  const accounts = (await this.db?.listAliases('accounts')) ?? [];
58
- return Promise.resolve(accounts.map(({ key, value }) => ({ alias: value, item: AztecAddress.fromString(key) })));
96
+ return Promise.resolve(
97
+ accounts.map(({ key, value }) => {
98
+ const alias = key.includes(':') ? key.slice(key.indexOf(':') + 1) : key;
99
+ return { alias, item: AztecAddress.fromStringUnsafe(value) };
100
+ }),
101
+ );
102
+ }
103
+
104
+ /**
105
+ * Derives suggested total and teardown gas limits from simulated gas usage, padded and clamped to the
106
+ * network's per-tx admission limits.
107
+ * @param gasUsed - The gas consumed during simulation (from a `simulate({ includeMetadata: true })` result).
108
+ */
109
+ async estimateGasLimits(gasUsed: GasUsed): Promise<{ gasLimits: Gas; teardownGasLimits: Gas }> {
110
+ const maxTxGasLimits = await this.getMaxTxGasLimits();
111
+ return getGasLimits(gasUsed, maxTxGasLimits, DEFAULT_ESTIMATED_GAS_PADDING);
59
112
  }
60
113
 
61
114
  private async createCancellationTxExecutionRequest(
@@ -64,14 +117,19 @@ export class CLIWallet extends BaseWallet {
64
117
  increasedFee: InteractionFeeOptions,
65
118
  ) {
66
119
  const executionPayload = ExecutionPayload.empty();
67
- const feeOptions = await this.completeFeeOptions(from, executionPayload.feePayer, increasedFee.gasSettings);
120
+ const feeOptions = await this.completeFeeOptions({
121
+ from,
122
+ feePayer: executionPayload.feePayer,
123
+ gasSettings: increasedFee.gasSettings,
124
+ });
68
125
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
69
126
  const fromAccount = await this.getAccountFromAddress(from);
70
127
  const chainInfo = await this.getChainInfo();
71
128
  const executionOptions: DefaultAccountEntrypointOptions = {
72
129
  txNonce,
73
130
  cancellable: this.cancellableTransactions,
74
- feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
131
+ // If from is an address, feeOptions include the way the account contract should handle the fee payment
132
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
75
133
  };
76
134
  return await fromAccount.createTxExecutionRequest(
77
135
  feeExecutionPayload ?? executionPayload,
@@ -87,14 +145,12 @@ export class CLIWallet extends BaseWallet {
87
145
  increasedFee: InteractionFeeOptions,
88
146
  ): Promise<TxProvingResult> {
89
147
  const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
90
- return await this.pxe.proveTx(cancellationTxRequest);
148
+ return await this.pxe.proveTx(cancellationTxRequest, { scopes: this.scopesFrom(from), senderForTags: from });
91
149
  }
92
150
 
93
151
  override async getAccountFromAddress(address: AztecAddress) {
94
152
  let account: Account | undefined;
95
- if (address.equals(AztecAddress.ZERO)) {
96
- account = new SignerlessAccount();
97
- } else if (this.accountCache.has(address.toString())) {
153
+ if (this.accountCache.has(address.toString())) {
98
154
  return this.accountCache.get(address.toString())!;
99
155
  } else {
100
156
  const accountManager = await this.createOrRetrieveAccount(address);
@@ -108,13 +164,27 @@ export class CLIWallet extends BaseWallet {
108
164
  }
109
165
 
110
166
  private async createAccount(secret: Fr, salt: Fr, contract: AccountContract): Promise<AccountManager> {
111
- const accountManager = await AccountManager.create(this, secret, contract, salt);
167
+ const accountManager = await AccountManager.create(this, secret, contract, { salt });
112
168
 
113
169
  const instance = accountManager.getInstance();
114
170
  const artifact = await contract.getContractArtifact();
115
171
 
116
172
  await this.registerContract(instance, artifact, secret);
117
173
  this.accountCache.set(accountManager.address.toString(), await accountManager.getAccount());
174
+
175
+ // Initializerless accounts have no deployment tx; their address commits to the signing public key
176
+ // (via the contract's immutablesHash, resolved by AccountManager.create) and the constructor's
177
+ // storage writes are materialized locally via a simulated "store" call here.
178
+ if (contract instanceof SchnorrInitializerlessAccountContract) {
179
+ const constructorAbi = artifact.functions.find(f => f.name === 'constructor');
180
+ if (!constructorAbi) {
181
+ throw new Error('Could not create SchnorrInitializerlessAccount: constructor ABI not found');
182
+ }
183
+ const { x, y } = await contract.getSigningPublicKey();
184
+ const storeCall = new ContractFunctionInteraction(this, instance.address, constructorAbi, [x, y]);
185
+ await storeCall.simulate({ from: instance.address });
186
+ }
187
+
118
188
  return accountManager;
119
189
  }
120
190
 
@@ -142,6 +212,14 @@ export class CLIWallet extends BaseWallet {
142
212
  account = await this.createAccount(secretKey, salt, new SchnorrAccountContract(deriveSigningKey(secretKey)));
143
213
  break;
144
214
  }
215
+ case 'schnorr_initializerless': {
216
+ account = await this.createAccount(
217
+ secretKey,
218
+ salt,
219
+ new SchnorrInitializerlessAccountContract(deriveSigningKey(secretKey)),
220
+ );
221
+ break;
222
+ }
145
223
  case 'ecdsasecp256r1': {
146
224
  account = await this.createAccount(
147
225
  secretKey,
@@ -185,82 +263,76 @@ export class CLIWallet extends BaseWallet {
185
263
  */
186
264
  private async getFakeAccountDataFor(address: AztecAddress) {
187
265
  const originalAccount = await this.getAccountFromAddress(address);
188
- // Account contracts can only be overridden if they have an associated address
189
- // Overwriting SignerlessAccount is not supported, and does not really make sense
190
- // since it has no authorization mechanism.
191
- if (originalAccount instanceof SignerlessAccount) {
192
- throw new Error(`Cannot create fake account data for SignerlessAccount at address: ${address}`);
193
- }
194
- const originalAddress = (originalAccount as Account).getCompleteAddress();
266
+ const originalAddress = originalAccount.getCompleteAddress();
195
267
  const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
196
268
  if (!contractInstance) {
197
269
  throw new Error(`No contract instance found for address: ${originalAddress.address}`);
198
270
  }
199
- const stubAccount = createStubAccount(originalAddress);
200
- const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
201
- salt: Fr.random(),
202
- });
203
- return {
204
- account: stubAccount,
205
- instance,
206
- artifact: StubAccountContractArtifact,
207
- };
271
+ const { type } = await this.db!.retrieveAccount(address);
272
+ const stubAccount =
273
+ type === 'schnorr' || type === 'schnorr_initializerless'
274
+ ? createStubSchnorrAccount(originalAddress)
275
+ : createStubEcdsaAccount(originalAddress);
276
+ const stubClassId = this.stubClassIds.get(type);
277
+ if (!stubClassId) {
278
+ throw new Error(
279
+ `Stub class for account type '${type}' was not registered at wallet init. This is a bug — initStubClasses should cover every supported AccountType.`,
280
+ );
281
+ }
282
+ const instance = { ...contractInstance, currentContractClassId: stubClassId };
283
+ return { account: stubAccount, instance };
208
284
  }
209
285
 
210
- override async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
211
- let simulationResults;
212
- const feeOptions = opts.fee?.estimateGas
213
- ? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings)
214
- : await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
286
+ /**
287
+ * Uses a stub account for kernelless simulation, bypassing real account authorization.
288
+ * Uses DefaultEntrypoint directly for NO_FROM transactions.
289
+ */
290
+ protected override async simulateViaEntrypoint(
291
+ executionPayload: ExecutionPayload,
292
+ opts: SimulateViaEntrypointOptions,
293
+ ): Promise<TxSimulationResultWithAppOffset> {
294
+ const { from, feeOptions, additionalScopes, sendMessagesAs } = opts;
295
+ const scopes = this.scopesFrom(from, additionalScopes);
215
296
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
216
- const chainInfo = await this.getChainInfo();
217
- const executionOptions: DefaultAccountEntrypointOptions = {
218
- txNonce: Fr.random(),
219
- cancellable: this.cancellableTransactions,
220
- feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
221
- };
222
297
  const finalExecutionPayload = feeExecutionPayload
223
298
  ? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
224
299
  : executionPayload;
300
+ const chainInfo = await this.getChainInfo();
225
301
 
226
- // Kernelless simulations using the multicall entrypoints are not currently supported,
227
- // since we only override proper account contracts.
228
- // TODO: allow disabling kernels even when no overrides are necessary
229
- if (opts.from.equals(AztecAddress.ZERO)) {
230
- const fromAccount = await this.getAccountFromAddress(opts.from);
231
- const txRequest = await fromAccount.createTxExecutionRequest(
232
- finalExecutionPayload,
233
- feeOptions.gasSettings,
234
- chainInfo,
235
- executionOptions,
236
- );
237
- simulationResults = await this.pxe.simulateTx(
238
- txRequest,
239
- true /* simulatePublic */,
240
- opts?.skipTxValidation,
241
- opts?.skipFeeEnforcement ?? true,
242
- );
302
+ let overrides: SimulationOverrides | undefined;
303
+ let txRequest: TxExecutionRequest;
304
+ if (from === NO_FROM) {
305
+ const entrypoint = new DefaultEntrypoint();
306
+ txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
243
307
  } else {
244
- const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(opts.from);
245
- const txRequest = await fromAccount.createTxExecutionRequest(
308
+ const { account, instance } = await this.getFakeAccountDataFor(from);
309
+ overrides = {
310
+ contracts: { [from.toString()]: { instance } },
311
+ };
312
+ const executionOptions: DefaultAccountEntrypointOptions = {
313
+ txNonce: Fr.random(),
314
+ cancellable: this.cancellableTransactions,
315
+ // If from is an address, feeOptions include the way the account contract should handle the fee payment
316
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
317
+ };
318
+ txRequest = await account.createTxExecutionRequest(
246
319
  finalExecutionPayload,
247
320
  feeOptions.gasSettings,
248
321
  chainInfo,
249
322
  executionOptions,
250
323
  );
251
- const contractOverrides = {
252
- [opts.from.toString()]: { instance, artifact },
253
- };
254
- simulationResults = await this.pxe.simulateTx(txRequest, true /* simulatePublic */, true, true, {
255
- contracts: contractOverrides,
256
- });
257
324
  }
258
325
 
259
- if (opts.fee?.estimateGas) {
260
- const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
261
- printGasEstimates(feeOptions, limits, this.userLog);
262
- }
263
- return simulationResults;
326
+ const result = await this.pxe.simulateTx(txRequest, {
327
+ simulatePublic: true,
328
+ skipFeeEnforcement: true,
329
+ skipTxValidation: true,
330
+ overrides,
331
+ scopes,
332
+ senderForTags: this.senderForTagsFrom(from, sendMessagesAs),
333
+ });
334
+ const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
335
+ return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
264
336
  }
265
337
 
266
338
  // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because