@aztec/cli-wallet 0.0.0-test.0

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