@aztec/cli-wallet 0.75.0-commit.c03ba01a2a4122e43e90d5133ba017e54b90e9d2

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 (48) hide show
  1. package/README.md +2 -0
  2. package/dest/bin/index.js +75 -0
  3. package/dest/cmds/add_authwit.js +4 -0
  4. package/dest/cmds/add_note.js +14 -0
  5. package/dest/cmds/authorize_action.js +17 -0
  6. package/dest/cmds/bridge_fee_juice.js +52 -0
  7. package/dest/cmds/cancel_tx.js +38 -0
  8. package/dest/cmds/check_tx.js +11 -0
  9. package/dest/cmds/create_account.js +98 -0
  10. package/dest/cmds/create_authwit.js +16 -0
  11. package/dest/cmds/deploy.js +83 -0
  12. package/dest/cmds/deploy_account.js +84 -0
  13. package/dest/cmds/index.js +227 -0
  14. package/dest/cmds/register_contract.js +14 -0
  15. package/dest/cmds/register_sender.js +4 -0
  16. package/dest/cmds/send.js +49 -0
  17. package/dest/cmds/simulate.js +26 -0
  18. package/dest/storage/wallet_db.js +180 -0
  19. package/dest/utils/accounts.js +87 -0
  20. package/dest/utils/ecdsa.js +13 -0
  21. package/dest/utils/options/fees.js +189 -0
  22. package/dest/utils/options/index.js +2 -0
  23. package/dest/utils/options/options.js +122 -0
  24. package/dest/utils/pxe_wrapper.js +21 -0
  25. package/package.json +103 -0
  26. package/src/bin/index.ts +121 -0
  27. package/src/cmds/add_authwit.ts +13 -0
  28. package/src/cmds/add_note.ts +30 -0
  29. package/src/cmds/authorize_action.ts +36 -0
  30. package/src/cmds/bridge_fee_juice.ts +88 -0
  31. package/src/cmds/cancel_tx.ts +61 -0
  32. package/src/cmds/check_tx.ts +12 -0
  33. package/src/cmds/create_account.ts +120 -0
  34. package/src/cmds/create_authwit.ts +35 -0
  35. package/src/cmds/deploy.ts +113 -0
  36. package/src/cmds/deploy_account.ts +92 -0
  37. package/src/cmds/index.ts +674 -0
  38. package/src/cmds/register_contract.ts +20 -0
  39. package/src/cmds/register_sender.ts +7 -0
  40. package/src/cmds/send.ts +62 -0
  41. package/src/cmds/simulate.ts +42 -0
  42. package/src/storage/wallet_db.ts +205 -0
  43. package/src/utils/accounts.ts +102 -0
  44. package/src/utils/ecdsa.ts +15 -0
  45. package/src/utils/options/fees.ts +234 -0
  46. package/src/utils/options/index.ts +2 -0
  47. package/src/utils/options/options.ts +175 -0
  48. package/src/utils/pxe_wrapper.ts +26 -0
@@ -0,0 +1,674 @@
1
+ import { getIdentities } from '@aztec/accounts/utils';
2
+ import { createCompatibleClient } from '@aztec/aztec.js/rpc';
3
+ import { TxHash } from '@aztec/aztec.js/tx_hash';
4
+ import { createAztecNodeClient } from '@aztec/circuit-types';
5
+ import { GasFees } from '@aztec/circuits.js';
6
+ import { PublicKeys } from '@aztec/circuits.js/types';
7
+ import {
8
+ ETHEREUM_HOST,
9
+ PRIVATE_KEY,
10
+ addOptions,
11
+ createSecretKeyOption,
12
+ l1ChainIdOption,
13
+ logJson,
14
+ parseBigint,
15
+ parseFieldFromHexString,
16
+ parsePublicKey,
17
+ pxeOption,
18
+ } from '@aztec/cli/utils';
19
+ import { type LogFn, type Logger } from '@aztec/foundation/log';
20
+
21
+ import { type Command, Option } from 'commander';
22
+ import inquirer from 'inquirer';
23
+
24
+ import { type WalletDB } from '../storage/wallet_db.js';
25
+ import { type AccountType, addScopeToWallet, createOrRetrieveAccount, getWalletWithScopes } from '../utils/accounts.js';
26
+ import { FeeOpts } from '../utils/options/fees.js';
27
+ import {
28
+ ARTIFACT_DESCRIPTION,
29
+ aliasedAddressParser,
30
+ aliasedAuthWitParser,
31
+ aliasedSecretKeyParser,
32
+ aliasedTxHashParser,
33
+ artifactPathFromPromiseOrAlias,
34
+ artifactPathParser,
35
+ createAccountOption,
36
+ createAliasOption,
37
+ createArgsOption,
38
+ createArtifactOption,
39
+ createContractAddressOption,
40
+ createProfileOption,
41
+ createTypeOption,
42
+ integerArgParser,
43
+ parseGasFees,
44
+ parsePaymentMethod,
45
+ } from '../utils/options/index.js';
46
+ import { type PXEWrapper } from '../utils/pxe_wrapper.js';
47
+
48
+ export function injectCommands(
49
+ program: Command,
50
+ log: LogFn,
51
+ debugLogger: Logger,
52
+ db?: WalletDB,
53
+ pxeWrapper?: PXEWrapper,
54
+ ) {
55
+ const createAccountCommand = program
56
+ .command('create-account')
57
+ .description(
58
+ 'Creates an aztec account that can be used for sending transactions. Registers the account on the PXE and deploys an account contract. Uses a Schnorr single-key account which uses the same key for encryption and authentication (not secure for production usage).',
59
+ )
60
+ .summary('Creates an aztec account that can be used for sending transactions.')
61
+ .option(
62
+ '--skip-initialization',
63
+ 'Skip initializing the account contract. Useful for publicly deploying an existing account.',
64
+ )
65
+ .option('--public-deploy', 'Publicly deploys the account and registers the class if needed.')
66
+ .option(
67
+ '-p, --public-key <string>',
68
+ 'Public key that identifies a private signing key stored outside of the wallet. Used for ECDSA SSH accounts over the secp256r1 curve.',
69
+ )
70
+ .addOption(pxeOption)
71
+ .addOption(
72
+ createSecretKeyOption('Secret key for account. Uses random by default.', false, sk =>
73
+ aliasedSecretKeyParser(sk, db),
74
+ ).conflicts('public-key'),
75
+ )
76
+ .addOption(createAliasOption('Alias for the account. Used for easy reference in subsequent commands.', !db))
77
+ .addOption(createTypeOption(true))
78
+ .option(
79
+ '--register-only',
80
+ 'Just register the account on the PXE. Do not deploy or initialize the account contract.',
81
+ )
82
+ .option('--json', 'Emit output as json')
83
+ // `options.wait` is default true. Passing `--no-wait` will set it to false.
84
+ // https://github.com/tj/commander.js#other-option-types-negatable-boolean-and-booleanvalue
85
+ .option('--no-wait', 'Skip waiting for the contract to be deployed. Print the hash of deployment transaction');
86
+
87
+ addOptions(createAccountCommand, FeeOpts.getOptions()).action(async (_options, command) => {
88
+ const { createAccount } = await import('./create_account.js');
89
+ const options = command.optsWithGlobals();
90
+ const { type, secretKey, wait, registerOnly, skipInitialization, publicDeploy, rpcUrl, alias, json } = options;
91
+ let { publicKey } = options;
92
+ if ((type as AccountType) === 'ecdsasecp256r1ssh' && !publicKey) {
93
+ const identities = await getIdentities();
94
+ const answers = await inquirer.prompt([
95
+ {
96
+ type: 'list',
97
+ name: 'identity',
98
+ message: 'What public key to use?',
99
+ choices: identities.map(key => `${key.type} ${key.publicKey} ${key.comment}`),
100
+ // Any required until https://github.com/SBoudrias/Inquirer.js/issues/1495 is fixed
101
+ } as any,
102
+ ]);
103
+ publicKey = answers.identity.split(' ')[1];
104
+ }
105
+ const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger));
106
+ const accountCreationResult = await createAccount(
107
+ client,
108
+ type,
109
+ secretKey,
110
+ publicKey,
111
+ alias,
112
+ registerOnly,
113
+ skipInitialization,
114
+ publicDeploy,
115
+ wait,
116
+ await FeeOpts.fromCli(options, client, log, db),
117
+ json,
118
+ debugLogger,
119
+ log,
120
+ );
121
+ if (db) {
122
+ const { address, alias, secretKey, salt } = accountCreationResult;
123
+ await db.storeAccount(address, { type, secretKey, salt, alias, publicKey }, log);
124
+ }
125
+ });
126
+
127
+ const deployAccountCommand = program
128
+ .command('deploy-account')
129
+ .description('Deploys an already registered aztec account that can be used for sending transactions.')
130
+ .addOption(createAccountOption('Alias or address of the account to deploy', !db, db))
131
+ .addOption(pxeOption)
132
+ .option('--json', 'Emit output as json')
133
+ // `options.wait` is default true. Passing `--no-wait` will set it to false.
134
+ // https://github.com/tj/commander.js#other-option-types-negatable-boolean-and-booleanvalue
135
+ .option('--no-wait', 'Skip waiting for the contract to be deployed. Print the hash of deployment transaction');
136
+
137
+ addOptions(deployAccountCommand, FeeOpts.getOptions()).action(async (_options, command) => {
138
+ const { deployAccount } = await import('./deploy_account.js');
139
+ const options = command.optsWithGlobals();
140
+ const { rpcUrl, wait, from: parsedFromAddress, json } = options;
141
+
142
+ const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger));
143
+ const account = await createOrRetrieveAccount(client, parsedFromAddress, db);
144
+
145
+ await deployAccount(account, wait, await FeeOpts.fromCli(options, client, log, db), json, debugLogger, log);
146
+ });
147
+
148
+ const deployCommand = program
149
+ .command('deploy')
150
+ .description('Deploys a compiled Aztec.nr contract to Aztec.')
151
+ .argument('[artifact]', ARTIFACT_DESCRIPTION, artifactPathParser)
152
+ .option('--init <string>', 'The contract initializer function to call', 'constructor')
153
+ .option('--no-init', 'Leave the contract uninitialized')
154
+ .option(
155
+ '-k, --public-key <string>',
156
+ 'Optional encryption public key for this address. Set this value only if this contract is expected to receive private notes, which will be encrypted using this public key.',
157
+ parsePublicKey,
158
+ )
159
+ .option(
160
+ '-s, --salt <hex string>',
161
+ 'Optional deployment salt as a hex string for generating the deployment address.',
162
+ parseFieldFromHexString,
163
+ )
164
+ .option('--universal', 'Do not mix the sender address into the deployment.')
165
+ .addOption(pxeOption)
166
+ .addOption(createArgsOption(true, db))
167
+ .addOption(
168
+ createSecretKeyOption("The sender's secret key", !db, sk => aliasedSecretKeyParser(sk, db)).conflicts('account'),
169
+ )
170
+ .addOption(createAccountOption('Alias or address of the account to deploy from', !db, db))
171
+ .addOption(createAliasOption('Alias for the contract. Used for easy reference subsequent commands.', !db))
172
+ .option('--json', 'Emit output as json')
173
+ // `options.wait` is default true. Passing `--no-wait` will set it to false.
174
+ // https://github.com/tj/commander.js#other-option-types-negatable-boolean-and-booleanvalue
175
+ .option('--no-wait', 'Skip waiting for the contract to be deployed. Print the hash of deployment transaction')
176
+ .option('--no-class-registration', "Don't register this contract class")
177
+ .option('--no-public-deployment', "Don't emit this contract's public bytecode");
178
+
179
+ addOptions(deployCommand, FeeOpts.getOptions()).action(async (artifactPathPromise, _options, command) => {
180
+ const { deploy } = await import('./deploy.js');
181
+ const options = command.optsWithGlobals();
182
+ const {
183
+ json,
184
+ publicKey,
185
+ args,
186
+ salt,
187
+ wait,
188
+ secretKey,
189
+ classRegistration,
190
+ init,
191
+ publicDeployment,
192
+ universal,
193
+ rpcUrl,
194
+ from: parsedFromAddress,
195
+ alias,
196
+ } = options;
197
+ const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger));
198
+ const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey);
199
+ const wallet = await getWalletWithScopes(account, db);
200
+ const artifactPath = await artifactPathPromise;
201
+
202
+ debugLogger.info(`Using wallet with address ${wallet.getCompleteAddress().address.toString()}`);
203
+
204
+ const address = await deploy(
205
+ client,
206
+ wallet,
207
+ artifactPath,
208
+ json,
209
+ publicKey ? PublicKeys.fromString(publicKey) : undefined,
210
+ args,
211
+ salt,
212
+ typeof init === 'string' ? init : undefined,
213
+ !publicDeployment,
214
+ !classRegistration,
215
+ typeof init === 'string' ? false : init,
216
+ universal,
217
+ wait,
218
+ await FeeOpts.fromCli(options, client, log, db),
219
+ debugLogger,
220
+ log,
221
+ logJson(log),
222
+ );
223
+ if (db && address) {
224
+ await db.storeContract(address, artifactPath, log, alias);
225
+ }
226
+ });
227
+
228
+ const sendCommand = program
229
+ .command('send')
230
+ .description('Calls a function on an Aztec contract.')
231
+ .argument('<functionName>', 'Name of function to execute')
232
+ .addOption(pxeOption)
233
+ .addOption(createArgsOption(false, db))
234
+ .addOption(createArtifactOption(db))
235
+ .addOption(createContractAddressOption(db))
236
+ .addOption(
237
+ createAliasOption('Alias for the transaction hash. Used for easy reference in subsequent commands.', !db),
238
+ )
239
+ .addOption(
240
+ createSecretKeyOption("The sender's secret key", !db, sk => aliasedSecretKeyParser(sk, db)).conflicts('account'),
241
+ )
242
+ .addOption(createAccountOption('Alias or address of the account to send the transaction from', !db, db))
243
+ .option('--no-wait', 'Print transaction hash without waiting for it to be mined')
244
+ .option('--no-cancel', 'Do not allow the transaction to be cancelled. This makes for cheaper transactions.');
245
+
246
+ addOptions(sendCommand, FeeOpts.getOptions()).action(async (functionName, _options, command) => {
247
+ const { send } = await import('./send.js');
248
+ const options = command.optsWithGlobals();
249
+ const {
250
+ args,
251
+ contractArtifact: artifactPathPromise,
252
+ contractAddress,
253
+ from: parsedFromAddress,
254
+ wait,
255
+ rpcUrl,
256
+ secretKey,
257
+ alias,
258
+ cancel,
259
+ } = options;
260
+ const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger));
261
+ const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey);
262
+ const wallet = await getWalletWithScopes(account, db);
263
+ const artifactPath = await artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db);
264
+
265
+ debugLogger.info(`Using wallet with address ${wallet.getCompleteAddress().address.toString()}`);
266
+
267
+ const sentTx = await send(
268
+ wallet,
269
+ functionName,
270
+ args,
271
+ artifactPath,
272
+ contractAddress,
273
+ wait,
274
+ cancel,
275
+ await FeeOpts.fromCli(options, client, log, db),
276
+ log,
277
+ );
278
+ if (db && sentTx) {
279
+ const txAlias = alias ? alias : `${functionName}-${sentTx.nonce.toString().slice(-4)}`;
280
+ await db.storeTx(sentTx, log, txAlias);
281
+ }
282
+ });
283
+
284
+ program
285
+ .command('simulate')
286
+ .description('Simulates the execution of a function on an Aztec contract.')
287
+ .argument('<functionName>', 'Name of function to simulate')
288
+ .addOption(pxeOption)
289
+ .addOption(createArgsOption(false, db))
290
+ .addOption(createContractAddressOption(db))
291
+ .addOption(createArtifactOption(db))
292
+ .addOption(
293
+ createSecretKeyOption("The sender's secret key", !db, sk => aliasedSecretKeyParser(sk, db)).conflicts('account'),
294
+ )
295
+ .addOption(createAccountOption('Alias or address of the account to simulate from', !db, db))
296
+ .addOption(createProfileOption())
297
+ .action(async (functionName, _options, command) => {
298
+ const { simulate } = await import('./simulate.js');
299
+ const options = command.optsWithGlobals();
300
+ const {
301
+ args,
302
+ contractArtifact: artifactPathPromise,
303
+ contractAddress,
304
+ from: parsedFromAddress,
305
+ rpcUrl,
306
+ secretKey,
307
+ profile,
308
+ } = options;
309
+
310
+ const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger));
311
+ const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey);
312
+ const wallet = await getWalletWithScopes(account, db);
313
+ const artifactPath = await artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db);
314
+ await simulate(wallet, functionName, args, artifactPath, contractAddress, profile, log);
315
+ });
316
+
317
+ program
318
+ .command('bridge-fee-juice')
319
+ .description('Mints L1 Fee Juice and pushes them to L2.')
320
+ .argument('<amount>', 'The amount of Fee Juice to mint and bridge.', parseBigint)
321
+ .argument('<recipient>', 'Aztec address of the recipient.', address =>
322
+ aliasedAddressParser('accounts', address, db),
323
+ )
324
+ .requiredOption(
325
+ '--l1-rpc-url <string>',
326
+ 'Url of the ethereum host. Chain identifiers localhost and testnet can be used',
327
+ ETHEREUM_HOST,
328
+ )
329
+ .option(
330
+ '-m, --mnemonic <string>',
331
+ 'The mnemonic to use for deriving the Ethereum address that will mint and bridge',
332
+ 'test test test test test test test test test test test junk',
333
+ )
334
+ .option('--mint', 'Mint the tokens on L1', false)
335
+ .option('--l1-private-key <string>', 'The private key to the eth account bridging', PRIVATE_KEY)
336
+ .addOption(pxeOption)
337
+ .addOption(l1ChainIdOption)
338
+ .option('--json', 'Output the claim in JSON format')
339
+ // `options.wait` is default true. Passing `--no-wait` will set it to false.
340
+ // https://github.com/tj/commander.js#other-option-types-negatable-boolean-and-booleanvalue
341
+ .option('--no-wait', 'Wait for the brigded funds to be available in L2, polling every 60 seconds')
342
+ .addOption(
343
+ new Option('--interval <number>', 'The polling interval in seconds for the bridged funds')
344
+ .default('60')
345
+ .conflicts('wait'),
346
+ )
347
+ .action(async (amount, recipient, options) => {
348
+ const { bridgeL1FeeJuice } = await import('./bridge_fee_juice.js');
349
+ const { rpcUrl, l1RpcUrl, l1ChainId, l1PrivateKey, mnemonic, mint, json, wait, interval: intervalS } = options;
350
+ const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger));
351
+
352
+ const [secret, messageLeafIndex] = await bridgeL1FeeJuice(
353
+ amount,
354
+ recipient,
355
+ client,
356
+ l1RpcUrl,
357
+ l1ChainId,
358
+ l1PrivateKey,
359
+ mnemonic,
360
+ mint,
361
+ json,
362
+ wait,
363
+ intervalS * 1000,
364
+ log,
365
+ debugLogger,
366
+ );
367
+ if (db) {
368
+ await db.pushBridgedFeeJuice(recipient, secret, amount, messageLeafIndex, log);
369
+ }
370
+ });
371
+
372
+ program
373
+ .command('add-note')
374
+ .description('Adds a note to the database in the PXE.')
375
+ .argument('[name]', 'The Note name')
376
+ .argument(
377
+ '[storageFieldName]',
378
+ 'The name of the variable in the storage field that contains the note. WARNING: Maps are not supported',
379
+ )
380
+ .requiredOption('-a, --address <string>', 'The Aztec address of the note owner.', address =>
381
+ aliasedAddressParser('accounts', address, db),
382
+ )
383
+ .addOption(createSecretKeyOption("The sender's secret key", !db, sk => aliasedSecretKeyParser(sk, db)))
384
+ .requiredOption('-t, --transaction-hash <string>', 'The hash of the tx containing the note.', txHash =>
385
+ aliasedTxHashParser(txHash, db),
386
+ )
387
+ .addOption(createContractAddressOption(db))
388
+ .addOption(createArtifactOption(db))
389
+ .addOption(
390
+ new Option('-b, --body [noteFields...]', 'The members of a Note')
391
+ .argParser((arg, prev: string[]) => {
392
+ const next = db?.tryRetrieveAlias(arg) || arg;
393
+ prev.push(next);
394
+ return prev;
395
+ })
396
+ .default([]),
397
+ )
398
+ .addOption(pxeOption)
399
+ .action(async (noteName, storageFieldName, _options, command) => {
400
+ const { addNote } = await import('./add_note.js');
401
+ const options = command.optsWithGlobals();
402
+ const {
403
+ contractArtifact: artifactPathPromise,
404
+ contractAddress,
405
+ address,
406
+ secretKey,
407
+ rpcUrl,
408
+ body,
409
+ transactionHash,
410
+ } = options;
411
+ const artifactPath = await artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db);
412
+ const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger));
413
+ const account = await createOrRetrieveAccount(client, address, db, undefined, secretKey);
414
+ const wallet = await getWalletWithScopes(account, db);
415
+
416
+ await addNote(
417
+ wallet,
418
+ address,
419
+ contractAddress,
420
+ noteName,
421
+ storageFieldName,
422
+ artifactPath,
423
+ transactionHash,
424
+ body,
425
+ log,
426
+ );
427
+ });
428
+
429
+ program
430
+ .command('create-authwit')
431
+ .description(
432
+ 'Creates an authorization witness that can be privately sent to a caller so they can perform an action on behalf of the provided account',
433
+ )
434
+ .argument('<functionName>', 'Name of function to authorize')
435
+ .argument('<caller>', 'Account to be authorized to perform the action', address =>
436
+ aliasedAddressParser('accounts', address, db),
437
+ )
438
+ .addOption(pxeOption)
439
+ .addOption(createArgsOption(false, db))
440
+ .addOption(createContractAddressOption(db))
441
+ .addOption(createArtifactOption(db))
442
+ .addOption(
443
+ createSecretKeyOption("The sender's secret key", !db, sk => aliasedSecretKeyParser(sk, db)).conflicts('account'),
444
+ )
445
+ .addOption(createAccountOption('Alias or address of the account to simulate from', !db, db))
446
+ .addOption(
447
+ createAliasOption('Alias for the authorization witness. Used for easy reference in subsequent commands.', !db),
448
+ )
449
+ .action(async (functionName, caller, _options, command) => {
450
+ const { createAuthwit } = await import('./create_authwit.js');
451
+ const options = command.optsWithGlobals();
452
+ const {
453
+ args,
454
+ contractArtifact: artifactPathPromise,
455
+ contractAddress,
456
+ from: parsedFromAddress,
457
+ rpcUrl,
458
+ secretKey,
459
+ alias,
460
+ } = options;
461
+
462
+ const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger));
463
+ const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey);
464
+ const wallet = await getWalletWithScopes(account, db);
465
+ const artifactPath = await artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db);
466
+ const witness = await createAuthwit(wallet, functionName, caller, args, artifactPath, contractAddress, log);
467
+
468
+ if (db) {
469
+ await db.storeAuthwitness(witness, log, alias);
470
+ }
471
+ });
472
+
473
+ program
474
+ .command('authorize-action')
475
+ .description(
476
+ 'Authorizes a public call on the caller, so they can perform an action on behalf of the provided account',
477
+ )
478
+ .argument('<functionName>', 'Name of function to authorize')
479
+ .argument('<caller>', 'Account to be authorized to perform the action', address =>
480
+ aliasedAddressParser('accounts', address, db),
481
+ )
482
+ .addOption(pxeOption)
483
+ .addOption(createArgsOption(false, db))
484
+ .addOption(createContractAddressOption(db))
485
+ .addOption(createArtifactOption(db))
486
+ .addOption(
487
+ createSecretKeyOption("The sender's secret key", !db, sk => aliasedSecretKeyParser(sk, db)).conflicts('account'),
488
+ )
489
+ .addOption(createAccountOption('Alias or address of the account to simulate from', !db, db))
490
+ .action(async (functionName, caller, _options, command) => {
491
+ const { authorizeAction } = await import('./authorize_action.js');
492
+ const options = command.optsWithGlobals();
493
+ const {
494
+ args,
495
+ contractArtifact: artifactPathPromise,
496
+ contractAddress,
497
+ from: parsedFromAddress,
498
+ rpcUrl,
499
+ secretKey,
500
+ } = options;
501
+
502
+ const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger));
503
+ const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey);
504
+ const wallet = await getWalletWithScopes(account, db);
505
+ const artifactPath = await artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db);
506
+ await authorizeAction(wallet, functionName, caller, args, artifactPath, contractAddress, log);
507
+ });
508
+
509
+ program
510
+ .command('add-authwit')
511
+ .description(
512
+ 'Adds an authorization witness to the provided account, granting PXE access to the notes of the authorizer so that it can be verified',
513
+ )
514
+ .argument('<authwit>', 'Authorization witness to add to the account', witness => aliasedAuthWitParser(witness, db))
515
+ .argument('<authorizer>', 'Account that provides the authorization to perform the action', address =>
516
+ aliasedAddressParser('accounts', address, db),
517
+ )
518
+ .addOption(pxeOption)
519
+ .addOption(
520
+ createSecretKeyOption("The sender's secret key", !db, sk => aliasedSecretKeyParser(sk, db)).conflicts('account'),
521
+ )
522
+ .addOption(createAccountOption('Alias or address of the account to simulate from', !db, db))
523
+ .addOption(
524
+ createAliasOption('Alias for the authorization witness. Used for easy reference in subsequent commands.', !db),
525
+ )
526
+ .action(async (authwit, authorizer, _options, command) => {
527
+ const { addAuthwit } = await import('./add_authwit.js');
528
+ const options = command.optsWithGlobals();
529
+ const { from: parsedFromAddress, rpcUrl, secretKey } = options;
530
+
531
+ const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger));
532
+ const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey);
533
+ const wallet = await getWalletWithScopes(account, db);
534
+ await addAuthwit(wallet, authwit, authorizer, log);
535
+ await addScopeToWallet(wallet, authorizer, db);
536
+ });
537
+
538
+ program
539
+ .command('get-tx')
540
+ .description('Gets the status of the recent txs, or a detailed view if a specific transaction hash is provided')
541
+ .argument('[txHash]', 'A transaction hash to get the receipt for.', txHash => aliasedTxHashParser(txHash, db))
542
+ .addOption(pxeOption)
543
+ .option('-p, --page <number>', 'The page number to display', value => integerArgParser(value, '--page', 1), 1)
544
+ .option(
545
+ '-s, --page-size <number>',
546
+ 'The number of transactions to display per page',
547
+ value => integerArgParser(value, '--page-size', 1),
548
+ 10,
549
+ )
550
+ .action(async (txHash, options) => {
551
+ const { checkTx } = await import('./check_tx.js');
552
+ const { rpcUrl, pageSize } = options;
553
+ let { page } = options;
554
+ const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger));
555
+
556
+ if (txHash) {
557
+ await checkTx(client, txHash, false, log);
558
+ } else if (db) {
559
+ const aliases = db.listAliases('transactions');
560
+ const totalPages = Math.ceil(aliases.length / pageSize);
561
+ page = Math.min(page - 1, totalPages - 1);
562
+ const dataRows = await Promise.all(
563
+ aliases.slice(page * pageSize, pageSize * (1 + page)).map(async ({ key, value }) => ({
564
+ alias: key,
565
+ txHash: value,
566
+ cancellable: db.retrieveTxData(TxHash.fromString(value)).cancellable,
567
+ status: await checkTx(client, TxHash.fromString(value), true, log),
568
+ })),
569
+ );
570
+ log(`Recent transactions:`);
571
+ log('');
572
+ log(`${'Alias'.padEnd(32, ' ')} | ${'TxHash'.padEnd(64, ' ')} | ${'Cancellable'.padEnd(12, ' ')} | Status`);
573
+ log(''.padEnd(32 + 64 + 12 + 20, '-'));
574
+ for (const { alias, txHash, status, cancellable } of dataRows) {
575
+ log(`${alias.padEnd(32, ' ')} | ${txHash} | ${cancellable.toString()?.padEnd(12, ' ')} | ${status}`);
576
+ log(''.padEnd(32 + 64 + 12 + 20, '-'));
577
+ }
578
+ log(`Displaying ${Math.min(pageSize, aliases.length)} rows, page ${page + 1}/${totalPages}`);
579
+ } else {
580
+ log('Recent transactions are not available, please provide a specific transaction hash');
581
+ }
582
+ });
583
+
584
+ program
585
+ .command('cancel-tx')
586
+ .description('Cancels a pending tx by reusing its nonce with a higher fee and an empty payload')
587
+ .argument('<txHash>', 'A transaction hash to cancel.', txHash => aliasedTxHashParser(txHash, db))
588
+ .addOption(pxeOption)
589
+ .addOption(
590
+ createSecretKeyOption("The sender's secret key", !db, sk => aliasedSecretKeyParser(sk, db)).conflicts('account'),
591
+ )
592
+ .addOption(createAccountOption('Alias or address of the account to simulate from', !db, db))
593
+ .addOption(FeeOpts.paymentMethodOption().default('method=none'))
594
+ .option(
595
+ '-i --increased-fees <da=1,l2=1>',
596
+ 'The amounts by which the fees are increased',
597
+ value => parseGasFees(value),
598
+ new GasFees(1, 1),
599
+ )
600
+ .option('--max-fees-per-gas <da=100,l2=100>', 'Maximum fees per gas unit for DA and L2 computation.', value =>
601
+ parseGasFees(value),
602
+ )
603
+ .action(async (txHash, options) => {
604
+ const { cancelTx } = await import('./cancel_tx.js');
605
+ const { from: parsedFromAddress, rpcUrl, secretKey, payment, increasedFees, maxFeesPerGas } = options;
606
+ const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger));
607
+ const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey);
608
+ const wallet = await getWalletWithScopes(account, db);
609
+
610
+ const txData = db?.retrieveTxData(txHash);
611
+ if (!txData) {
612
+ throw new Error('Transaction data not found in the database, cannot reuse nonce');
613
+ }
614
+
615
+ const paymentMethod = await parsePaymentMethod(payment, log, db)(wallet);
616
+
617
+ await cancelTx(wallet, txData, paymentMethod, increasedFees, maxFeesPerGas, log);
618
+ });
619
+
620
+ program
621
+ .command('register-sender')
622
+ .description(
623
+ "Registers a sender's address in the wallet, so the note synching process will look for notes sent by them",
624
+ )
625
+ .argument('[address]', 'The address of the sender to register', address =>
626
+ aliasedAddressParser('accounts', address, db),
627
+ )
628
+ .addOption(pxeOption)
629
+ .addOption(createAccountOption('Alias or address of the account to simulate from', !db, db))
630
+ .addOption(createAliasOption('Alias for the sender. Used for easy reference in subsequent commands.', !db))
631
+ .action(async (address, options) => {
632
+ const { registerSender } = await import('./register_sender.js');
633
+ const { from: parsedFromAddress, rpcUrl, secretKey, alias } = options;
634
+ const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger));
635
+ const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey);
636
+ const wallet = await getWalletWithScopes(account, db);
637
+
638
+ await registerSender(wallet, address, log);
639
+
640
+ if (db && alias) {
641
+ await db.storeSender(address, alias, log);
642
+ }
643
+ });
644
+
645
+ program
646
+ .command('register-contract')
647
+ .description("Registers a contract in this wallet's PXE")
648
+ .argument('[address]', 'The address of the contract to register', address =>
649
+ aliasedAddressParser('accounts', address, db),
650
+ )
651
+ .argument('[artifact]', ARTIFACT_DESCRIPTION, artifactPathParser)
652
+ .addOption(createArgsOption(true, db))
653
+ .addOption(pxeOption)
654
+ .addOption(createAccountOption('Alias or address of the account to simulate from', !db, db))
655
+ .addOption(createAliasOption('Alias for the contact. Used for easy reference in subsequent commands.', !db))
656
+ .action(async (address, artifactPathPromise, _options, command) => {
657
+ const { registerContract } = await import('./register_contract.js');
658
+ const { from: parsedFromAddress, rpcUrl, nodeUrl, secretKey, alias } = command.optsWithGlobals();
659
+ const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger));
660
+ const node = pxeWrapper?.getNode() ?? createAztecNodeClient(nodeUrl);
661
+ const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey);
662
+ const wallet = await getWalletWithScopes(account, db);
663
+
664
+ const artifactPath = await artifactPathPromise;
665
+
666
+ const instance = await registerContract(wallet, node, address, artifactPath, log);
667
+
668
+ if (db && alias) {
669
+ await db.storeContract(instance.address, artifactPath, log, alias);
670
+ }
671
+ });
672
+
673
+ return program;
674
+ }
@@ -0,0 +1,20 @@
1
+ import { type AccountWalletWithSecretKey, type AztecAddress, type AztecNode } from '@aztec/aztec.js';
2
+ import { getContractArtifact } from '@aztec/cli/cli-utils';
3
+ import { type LogFn } from '@aztec/foundation/log';
4
+
5
+ export async function registerContract(
6
+ wallet: AccountWalletWithSecretKey,
7
+ node: AztecNode,
8
+ address: AztecAddress,
9
+ artifactPath: string,
10
+ log: LogFn,
11
+ ) {
12
+ const contractArtifact = await getContractArtifact(artifactPath, log);
13
+ const contractInstance = await node.getContract(address);
14
+ if (!contractInstance) {
15
+ throw new Error(`Contract not found at address: ${address}`);
16
+ }
17
+ await wallet.registerContract({ instance: contractInstance, artifact: contractArtifact });
18
+ log(`Contract registered: at ${contractInstance.address}`);
19
+ return contractInstance;
20
+ }