@aztec/cli-wallet 0.0.0-test.1 → 0.0.1-commit.b655e406

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 (105) hide show
  1. package/README.md +30 -0
  2. package/dest/bin/index.js +48 -26
  3. package/dest/cmds/authorize_action.d.ts +3 -2
  4. package/dest/cmds/authorize_action.d.ts.map +1 -1
  5. package/dest/cmds/authorize_action.js +8 -4
  6. package/dest/cmds/bridge_fee_juice.d.ts +2 -2
  7. package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
  8. package/dest/cmds/bridge_fee_juice.js +8 -7
  9. package/dest/cmds/check_tx.d.ts +4 -2
  10. package/dest/cmds/check_tx.d.ts.map +1 -1
  11. package/dest/cmds/check_tx.js +145 -6
  12. package/dest/cmds/create_account.d.ts +6 -5
  13. package/dest/cmds/create_account.d.ts.map +1 -1
  14. package/dest/cmds/create_account.js +46 -27
  15. package/dest/cmds/create_authwit.d.ts +3 -2
  16. package/dest/cmds/create_authwit.d.ts.map +1 -1
  17. package/dest/cmds/create_authwit.js +5 -5
  18. package/dest/cmds/deploy.d.ts +6 -3
  19. package/dest/cmds/deploy.d.ts.map +1 -1
  20. package/dest/cmds/deploy.js +71 -54
  21. package/dest/cmds/deploy_account.d.ts +5 -7
  22. package/dest/cmds/deploy_account.d.ts.map +1 -1
  23. package/dest/cmds/deploy_account.js +46 -29
  24. package/dest/cmds/import_test_accounts.d.ts +2 -2
  25. package/dest/cmds/import_test_accounts.d.ts.map +1 -1
  26. package/dest/cmds/import_test_accounts.js +6 -9
  27. package/dest/cmds/index.d.ts +2 -2
  28. package/dest/cmds/index.d.ts.map +1 -1
  29. package/dest/cmds/index.js +83 -115
  30. package/dest/cmds/profile.d.ts +8 -0
  31. package/dest/cmds/profile.d.ts.map +1 -0
  32. package/dest/cmds/profile.js +28 -0
  33. package/dest/cmds/register_contract.d.ts +6 -2
  34. package/dest/cmds/register_contract.d.ts.map +1 -1
  35. package/dest/cmds/register_contract.js +20 -7
  36. package/dest/cmds/register_sender.d.ts +3 -2
  37. package/dest/cmds/register_sender.d.ts.map +1 -1
  38. package/dest/cmds/send.d.ts +7 -8
  39. package/dest/cmds/send.d.ts.map +1 -1
  40. package/dest/cmds/send.js +31 -20
  41. package/dest/cmds/simulate.d.ts +6 -2
  42. package/dest/cmds/simulate.d.ts.map +1 -1
  43. package/dest/cmds/simulate.js +25 -19
  44. package/dest/storage/wallet_db.d.ts +4 -16
  45. package/dest/storage/wallet_db.d.ts.map +1 -1
  46. package/dest/storage/wallet_db.js +2 -23
  47. package/dest/utils/authorizations.d.ts +6 -0
  48. package/dest/utils/authorizations.d.ts.map +1 -0
  49. package/dest/utils/authorizations.js +28 -0
  50. package/dest/utils/cli_wallet_and_node_wrapper.d.ts +12 -0
  51. package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -0
  52. package/dest/utils/cli_wallet_and_node_wrapper.js +25 -0
  53. package/dest/utils/ecdsa.d.ts +0 -2
  54. package/dest/utils/ecdsa.d.ts.map +1 -1
  55. package/dest/utils/options/fees.d.ts +20 -27
  56. package/dest/utils/options/fees.d.ts.map +1 -1
  57. package/dest/utils/options/fees.js +85 -144
  58. package/dest/utils/options/options.d.ts +8 -4
  59. package/dest/utils/options/options.d.ts.map +1 -1
  60. package/dest/utils/options/options.js +26 -14
  61. package/dest/utils/profiling.d.ts +5 -0
  62. package/dest/utils/profiling.d.ts.map +1 -0
  63. package/dest/utils/profiling.js +60 -0
  64. package/dest/utils/wallet.d.ts +35 -0
  65. package/dest/utils/wallet.d.ts.map +1 -0
  66. package/dest/utils/wallet.js +193 -0
  67. package/package.json +24 -20
  68. package/src/bin/index.ts +56 -32
  69. package/src/cmds/authorize_action.ts +15 -4
  70. package/src/cmds/bridge_fee_juice.ts +14 -11
  71. package/src/cmds/check_tx.ts +182 -5
  72. package/src/cmds/create_account.ts +55 -32
  73. package/src/cmds/create_authwit.ts +8 -4
  74. package/src/cmds/deploy.ts +79 -62
  75. package/src/cmds/deploy_account.ts +57 -28
  76. package/src/cmds/import_test_accounts.ts +7 -11
  77. package/src/cmds/index.ts +256 -220
  78. package/src/cmds/profile.ts +48 -0
  79. package/src/cmds/register_contract.ts +28 -5
  80. package/src/cmds/register_sender.ts +3 -2
  81. package/src/cmds/send.ts +31 -17
  82. package/src/cmds/simulate.ts +39 -23
  83. package/src/storage/wallet_db.ts +3 -31
  84. package/src/utils/authorizations.ts +51 -0
  85. package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
  86. package/src/utils/options/fees.ts +134 -206
  87. package/src/utils/options/options.ts +41 -19
  88. package/src/utils/profiling.ts +158 -0
  89. package/src/utils/wallet.ts +264 -0
  90. package/dest/cmds/add_authwit.d.ts +0 -4
  91. package/dest/cmds/add_authwit.d.ts.map +0 -1
  92. package/dest/cmds/add_authwit.js +0 -4
  93. package/dest/cmds/cancel_tx.d.ts +0 -11
  94. package/dest/cmds/cancel_tx.d.ts.map +0 -1
  95. package/dest/cmds/cancel_tx.js +0 -38
  96. package/dest/utils/accounts.d.ts +0 -11
  97. package/dest/utils/accounts.d.ts.map +0 -1
  98. package/dest/utils/accounts.js +0 -87
  99. package/dest/utils/pxe_wrapper.d.ts +0 -10
  100. package/dest/utils/pxe_wrapper.d.ts.map +0 -1
  101. package/dest/utils/pxe_wrapper.js +0 -21
  102. package/src/cmds/add_authwit.ts +0 -13
  103. package/src/cmds/cancel_tx.ts +0 -62
  104. package/src/utils/accounts.ts +0 -102
  105. package/src/utils/pxe_wrapper.ts +0 -26
@@ -0,0 +1,193 @@
1
+ import { EcdsaRAccountContract, EcdsaRSSHAccountContract } from '@aztec/accounts/ecdsa';
2
+ import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
3
+ import { StubAccountContractArtifact, createStubAccount } from '@aztec/accounts/stub';
4
+ import { getIdentities } from '@aztec/accounts/utils';
5
+ import { SignerlessAccount } from '@aztec/aztec.js/account';
6
+ import { getContractInstanceFromInstantiationParams, getGasLimits } from '@aztec/aztec.js/contracts';
7
+ import { AccountManager, BaseWallet } from '@aztec/aztec.js/wallet';
8
+ import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/entrypoints/payload';
9
+ import { Fr } from '@aztec/foundation/fields';
10
+ import { createPXE, getPXEConfig } from '@aztec/pxe/server';
11
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
12
+ import { deriveSigningKey } from '@aztec/stdlib/keys';
13
+ import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
14
+ import { printGasEstimates } from './options/fees.js';
15
+ export const AccountTypes = [
16
+ 'schnorr',
17
+ 'ecdsasecp256r1',
18
+ 'ecdsasecp256r1ssh',
19
+ 'ecdsasecp256k1'
20
+ ];
21
+ export const BASE_FEE_PADDING = 0.5;
22
+ export class CLIWallet extends BaseWallet {
23
+ userLog;
24
+ db;
25
+ accountCache;
26
+ constructor(pxe, node, userLog, db){
27
+ super(pxe, node), this.userLog = userLog, this.db = db, this.accountCache = new Map();
28
+ this.cancellableTransactions = true;
29
+ }
30
+ static async create(node, log, db, overridePXEConfig) {
31
+ const pxeConfig = Object.assign(getPXEConfig(), overridePXEConfig);
32
+ const pxe = await createPXE(node, pxeConfig);
33
+ return new CLIWallet(pxe, node, log, db);
34
+ }
35
+ async getAccounts() {
36
+ const accounts = await this.db?.listAliases('accounts') ?? [];
37
+ return Promise.resolve(accounts.map(({ key, value })=>({
38
+ alias: value,
39
+ item: AztecAddress.fromString(key)
40
+ })));
41
+ }
42
+ async createCancellationTxExecutionRequest(from, txNonce, increasedFee) {
43
+ const feeOptions = await this.getDefaultFeeOptions(from, increasedFee);
44
+ const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
45
+ const fromAccount = await this.getAccountFromAddress(from);
46
+ const executionOptions = {
47
+ txNonce,
48
+ cancellable: this.cancellableTransactions,
49
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
50
+ };
51
+ return await fromAccount.createTxExecutionRequest(feeExecutionPayload ?? ExecutionPayload.empty(), feeOptions.gasSettings, executionOptions);
52
+ }
53
+ async proveCancellationTx(from, txNonce, increasedFee) {
54
+ const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
55
+ return await this.pxe.proveTx(cancellationTxRequest);
56
+ }
57
+ async getAccountFromAddress(address) {
58
+ let account;
59
+ if (address.equals(AztecAddress.ZERO)) {
60
+ const chainInfo = await this.getChainInfo();
61
+ account = new SignerlessAccount(chainInfo);
62
+ } else if (this.accountCache.has(address.toString())) {
63
+ return this.accountCache.get(address.toString());
64
+ } else {
65
+ const accountManager = await this.createOrRetrieveAccount(address);
66
+ account = await accountManager.getAccount();
67
+ }
68
+ if (!account) {
69
+ throw new Error(`Account not found in wallet for address: ${address}`);
70
+ }
71
+ return account;
72
+ }
73
+ async createAccount(secret, salt, contract) {
74
+ const accountManager = await AccountManager.create(this, secret, contract, salt);
75
+ const instance = accountManager.getInstance();
76
+ const artifact = await contract.getContractArtifact();
77
+ await this.registerContract(instance, artifact, secret);
78
+ this.accountCache.set(accountManager.address.toString(), await accountManager.getAccount());
79
+ return accountManager;
80
+ }
81
+ async createOrRetrieveAccount(address, secretKey, type = 'schnorr', salt, publicKey) {
82
+ let account;
83
+ salt ??= Fr.ZERO;
84
+ if (this.db && address) {
85
+ ({ type, secretKey, salt } = await this.db.retrieveAccount(address));
86
+ }
87
+ if (!secretKey) {
88
+ throw new Error('Cannot retrieve/create wallet without secret key');
89
+ }
90
+ switch(type){
91
+ case 'schnorr':
92
+ {
93
+ account = await this.createAccount(secretKey, salt, new SchnorrAccountContract(deriveSigningKey(secretKey)));
94
+ break;
95
+ }
96
+ case 'ecdsasecp256r1':
97
+ {
98
+ account = await this.createAccount(secretKey, salt, new EcdsaRAccountContract(deriveSigningKey(secretKey).toBuffer()));
99
+ break;
100
+ }
101
+ case 'ecdsasecp256r1ssh':
102
+ {
103
+ let publicSigningKey;
104
+ if (this.db && address) {
105
+ publicSigningKey = await this.db.retrieveAccountMetadata(address, 'publicSigningKey');
106
+ } else if (publicKey) {
107
+ const identities = await getIdentities();
108
+ const foundIdentity = identities.find((identity)=>identity.type === 'ecdsa-sha2-nistp256' && identity.publicKey === publicKey);
109
+ if (!foundIdentity) {
110
+ throw new Error(`Identity for public key ${publicKey} not found in the SSH agent`);
111
+ }
112
+ publicSigningKey = extractECDSAPublicKeyFromBase64String(foundIdentity.publicKey);
113
+ } else {
114
+ throw new Error('Public key must be provided for ECDSA SSH account');
115
+ }
116
+ account = await this.createAccount(secretKey, salt, new EcdsaRSSHAccountContract(publicSigningKey));
117
+ break;
118
+ }
119
+ default:
120
+ {
121
+ throw new Error(`Unsupported account type: ${type}`);
122
+ }
123
+ }
124
+ return account;
125
+ }
126
+ async getFakeAccountDataFor(address) {
127
+ const chainInfo = await this.getChainInfo();
128
+ const originalAccount = await this.getAccountFromAddress(address);
129
+ const originalAddress = originalAccount.getCompleteAddress();
130
+ const { contractInstance } = await this.pxe.getContractMetadata(originalAddress.address);
131
+ if (!contractInstance) {
132
+ throw new Error(`No contract instance found for address: ${originalAddress.address}`);
133
+ }
134
+ const stubAccount = createStubAccount(originalAddress, chainInfo);
135
+ const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
136
+ salt: Fr.random()
137
+ });
138
+ return {
139
+ account: stubAccount,
140
+ instance,
141
+ artifact: StubAccountContractArtifact
142
+ };
143
+ }
144
+ async simulateTx(executionPayload, opts) {
145
+ let simulationResults;
146
+ const feeOptions = opts.fee?.estimateGas ? await this.getFeeOptionsForGasEstimation(opts.from, opts.fee) : await this.getDefaultFeeOptions(opts.from, opts.fee);
147
+ const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
148
+ const executionOptions = {
149
+ txNonce: Fr.random(),
150
+ cancellable: this.cancellableTransactions,
151
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
152
+ };
153
+ const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
154
+ feeExecutionPayload,
155
+ executionPayload
156
+ ]) : executionPayload;
157
+ // Kernelless simulations using the multicall entrypoints are not currently supported,
158
+ // since we only override proper account contracts.
159
+ // TODO: allow disabling kernels even when no overrides are necessary
160
+ if (opts.from.equals(AztecAddress.ZERO)) {
161
+ const fromAccount = await this.getAccountFromAddress(opts.from);
162
+ const txRequest = await fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, executionOptions);
163
+ simulationResults = await this.pxe.simulateTx(txRequest, true, opts?.skipTxValidation, opts?.skipFeeEnforcement ?? true);
164
+ } else {
165
+ const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(opts.from);
166
+ const txRequest = await fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, executionOptions);
167
+ const contractOverrides = {
168
+ [opts.from.toString()]: {
169
+ instance,
170
+ artifact
171
+ }
172
+ };
173
+ simulationResults = await this.pxe.simulateTx(txRequest, true, true, true, {
174
+ contracts: contractOverrides
175
+ });
176
+ }
177
+ if (opts.fee?.estimateGas) {
178
+ const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
179
+ printGasEstimates(feeOptions, limits, this.userLog);
180
+ }
181
+ return simulationResults;
182
+ }
183
+ // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
184
+ // this is just a CLI wallet.
185
+ getContracts() {
186
+ return this.pxe.getContracts();
187
+ }
188
+ // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
189
+ // this is just a CLI wallet.
190
+ getNotes(filter) {
191
+ return this.pxe.getNotes(filter);
192
+ }
193
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/cli-wallet",
3
- "version": "0.0.0-test.1",
3
+ "version": "0.0.1-commit.b655e406",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/cmds/index.js",
@@ -23,8 +23,6 @@
23
23
  "build": "yarn clean && tsc -b",
24
24
  "build:dev": "tsc -b --watch",
25
25
  "clean": "rm -rf ./dest .tsbuildinfo",
26
- "formatting": "run -T prettier --check ./src && run -T eslint ./src",
27
- "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
28
26
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
29
27
  },
30
28
  "inherits": [
@@ -62,33 +60,39 @@
62
60
  "testTimeout": 120000,
63
61
  "setupFiles": [
64
62
  "../../foundation/src/jest/setup.mjs"
63
+ ],
64
+ "testEnvironment": "../../foundation/src/jest/env.mjs",
65
+ "setupFilesAfterEnv": [
66
+ "../../foundation/src/jest/setupAfterEnv.mjs"
65
67
  ]
66
68
  },
67
69
  "dependencies": {
68
- "@aztec/accounts": "0.0.0-test.1",
69
- "@aztec/aztec.js": "0.0.0-test.1",
70
- "@aztec/cli": "0.0.0-test.1",
71
- "@aztec/ethereum": "0.0.0-test.1",
72
- "@aztec/foundation": "0.0.0-test.1",
73
- "@aztec/kv-store": "0.0.0-test.1",
74
- "@aztec/noir-contracts.js": "0.0.0-test.1",
75
- "@aztec/pxe": "0.0.0-test.1",
76
- "@aztec/stdlib": "0.0.0-test.1",
70
+ "@aztec/accounts": "0.0.1-commit.b655e406",
71
+ "@aztec/aztec.js": "0.0.1-commit.b655e406",
72
+ "@aztec/cli": "0.0.1-commit.b655e406",
73
+ "@aztec/entrypoints": "0.0.1-commit.b655e406",
74
+ "@aztec/ethereum": "0.0.1-commit.b655e406",
75
+ "@aztec/foundation": "0.0.1-commit.b655e406",
76
+ "@aztec/kv-store": "0.0.1-commit.b655e406",
77
+ "@aztec/noir-contracts.js": "0.0.1-commit.b655e406",
78
+ "@aztec/noir-noirc_abi": "0.0.1-commit.b655e406",
79
+ "@aztec/pxe": "0.0.1-commit.b655e406",
80
+ "@aztec/stdlib": "0.0.1-commit.b655e406",
77
81
  "commander": "^12.1.0",
78
82
  "inquirer": "^10.1.8",
79
83
  "source-map-support": "^0.5.21",
80
84
  "tslib": "^2.4.0"
81
85
  },
82
86
  "devDependencies": {
83
- "@jest/globals": "^29.5.0",
84
- "@types/jest": "^29.5.0",
85
- "@types/node": "^18.7.23",
87
+ "@jest/globals": "^30.0.0",
88
+ "@types/jest": "^30.0.0",
89
+ "@types/node": "^22.15.17",
86
90
  "@types/source-map-support": "^0.5.10",
87
- "jest": "^29.5.0",
88
- "jest-mock-extended": "^3.0.5",
89
- "ts-jest": "^29.1.0",
91
+ "jest": "^30.0.0",
92
+ "jest-mock-extended": "^4.0.0",
93
+ "ts-jest": "^29.4.0",
90
94
  "ts-node": "^10.9.1",
91
- "typescript": "^5.0.4"
95
+ "typescript": "^5.3.3"
92
96
  },
93
97
  "files": [
94
98
  "dest",
@@ -97,6 +101,6 @@
97
101
  ],
98
102
  "types": "./dest/index.d.ts",
99
103
  "engines": {
100
- "node": ">=18"
104
+ "node": ">=20.10"
101
105
  }
102
106
  }
package/src/bin/index.ts CHANGED
@@ -1,24 +1,31 @@
1
- import { Fr, computeSecretHash, fileURLToPath } from '@aztec/aztec.js';
1
+ import { computeSecretHash } from '@aztec/aztec.js/crypto';
2
+ import { Fr } from '@aztec/aztec.js/fields';
3
+ import { createAztecNodeClient } from '@aztec/aztec.js/node';
4
+ import { ProtocolContractAddress } from '@aztec/aztec.js/protocol';
2
5
  import { LOCALHOST } from '@aztec/cli/cli-utils';
3
6
  import { type LogFn, createConsoleLogger, createLogger } from '@aztec/foundation/log';
4
7
  import { openStoreAt } from '@aztec/kv-store/lmdb-v2';
5
- import type { PXEServiceConfig } from '@aztec/pxe/config';
8
+ import type { PXEConfig } from '@aztec/pxe/config';
9
+ import { getPackageVersion } from '@aztec/stdlib/update-checker';
6
10
 
7
11
  import { Argument, Command, Option } from 'commander';
8
- import { mkdirSync, readFileSync } from 'fs';
12
+ import { mkdirSync } from 'fs';
9
13
  import { homedir } from 'os';
10
14
  import { dirname, join, resolve } from 'path';
15
+ import { fileURLToPath } from 'url';
11
16
 
12
17
  import { injectCommands } from '../cmds/index.js';
13
18
  import { Aliases, WalletDB } from '../storage/wallet_db.js';
19
+ import { CliWalletAndNodeWrapper } from '../utils/cli_wallet_and_node_wrapper.js';
14
20
  import { createAliasOption } from '../utils/options/index.js';
15
- import { PXEWrapper } from '../utils/pxe_wrapper.js';
21
+ import { CLIWallet } from '../utils/wallet.js';
16
22
 
17
23
  const userLog = createConsoleLogger();
18
24
  const debugLogger = createLogger('wallet');
19
25
 
20
- const { WALLET_DATA_DIRECTORY = join(homedir(), '.aztec/wallet'), PXE_PROVER = 'none' } = process.env;
26
+ const { WALLET_DATA_DIRECTORY = join(homedir(), '.aztec/wallet') } = process.env;
21
27
 
28
+ // TODO: This function is only used in 1 place so we could just inline this
22
29
  function injectInternalCommands(program: Command, log: LogFn, db: WalletDB) {
23
30
  program
24
31
  .command('alias')
@@ -55,7 +62,7 @@ function injectInternalCommands(program: Command, log: LogFn, db: WalletDB) {
55
62
  const options = command.optsWithGlobals();
56
63
  const { alias } = options;
57
64
  const value = Fr.random();
58
- const hash = computeSecretHash(value);
65
+ const hash = await computeSecretHash(value);
59
66
 
60
67
  await db.storeAlias('secrets', alias, Buffer.from(value.toString()), log);
61
68
  await db.storeAlias('secrets', `${alias}:hash`, Buffer.from(hash.toString()), log);
@@ -66,23 +73,21 @@ function injectInternalCommands(program: Command, log: LogFn, db: WalletDB) {
66
73
 
67
74
  /** CLI wallet main entrypoint */
68
75
  async function main() {
69
- const packageJsonPath = resolve(dirname(fileURLToPath(import.meta.url)), '../../package.json');
70
- const walletVersion: string = JSON.parse(readFileSync(packageJsonPath).toString()).version;
76
+ const walletVersion = getPackageVersion() ?? '0.0.0';
71
77
 
72
78
  const db = WalletDB.getInstance();
73
- const pxeWrapper = new PXEWrapper();
79
+ const walletAndNodeWrapper = new CliWalletAndNodeWrapper();
74
80
 
75
81
  const program = new Command('wallet');
76
82
  program
77
83
  .description('Aztec wallet')
78
84
  .version(walletVersion)
79
85
  .option('-d, --data-dir <string>', 'Storage directory for wallet data', WALLET_DATA_DIRECTORY)
80
- .option('-p, --prover <string>', 'wasm|native|none', PXE_PROVER)
81
86
  .addOption(
82
- new Option('--remote-pxe', 'Connect to an external PXE RPC server, instead of the local one')
83
- .env('REMOTE_PXE')
84
- .default(false)
85
- .conflicts('rpc-url'),
87
+ new Option('-p, --prover <string>', 'The type of prover the wallet uses')
88
+ .choices(['wasm', 'native', 'none'])
89
+ .env('PXE_PROVER')
90
+ .default('native'),
86
91
  )
87
92
  .addOption(
88
93
  new Option('-n, --node-url <string>', 'URL of the Aztec node to connect to')
@@ -90,32 +95,51 @@ async function main() {
90
95
  .default(`http://${LOCALHOST}:8080`),
91
96
  )
92
97
  .hook('preSubcommand', async command => {
93
- const { dataDir, remotePxe, nodeUrl, prover } = command.optsWithGlobals();
98
+ const { dataDir, nodeUrl, prover } = command.optsWithGlobals();
94
99
 
95
- if (!remotePxe) {
96
- debugLogger.info('Using local PXE service');
100
+ const proverEnabled = prover !== 'none';
97
101
 
98
- const proverEnabled = prover !== 'none';
102
+ const bbBinaryPath =
103
+ prover === 'native'
104
+ ? (process.env.BB_BINARY_PATH ??
105
+ resolve(dirname(fileURLToPath(import.meta.url)), '../../../../barretenberg/cpp/build/bin/bb'))
106
+ : undefined;
107
+ const bbWorkingDirectory = dataDir + '/bb';
108
+ mkdirSync(bbWorkingDirectory, { recursive: true });
99
109
 
100
- const bbBinaryPath =
101
- prover === 'native'
102
- ? resolve(dirname(fileURLToPath(import.meta.url)), '../../../../barretenberg/cpp/build/bin/bb')
103
- : undefined;
104
- const bbWorkingDirectory = dataDir + '/bb';
105
- mkdirSync(bbWorkingDirectory, { recursive: true });
110
+ const overridePXEConfig: Partial<PXEConfig> = {
111
+ proverEnabled,
112
+ bbBinaryPath: prover === 'native' ? bbBinaryPath : undefined,
113
+ bbWorkingDirectory: prover === 'native' ? bbWorkingDirectory : undefined,
114
+ dataDirectory: join(dataDir, 'pxe'),
115
+ };
106
116
 
107
- const overridePXEConfig: Partial<PXEServiceConfig> = {
108
- proverEnabled,
109
- bbBinaryPath: prover === 'native' ? bbBinaryPath : undefined,
110
- bbWorkingDirectory: prover === 'native' ? bbWorkingDirectory : undefined,
111
- };
117
+ const node = createAztecNodeClient(nodeUrl);
118
+ const wallet = await CLIWallet.create(node, userLog, db, overridePXEConfig);
119
+
120
+ walletAndNodeWrapper.setNodeAndWallet(node, wallet);
112
121
 
113
- await pxeWrapper.init(nodeUrl, join(dataDir, 'pxe'), overridePXEConfig);
114
- }
115
122
  await db.init(await openStoreAt(dataDir));
123
+ let protocolContractsRegistered;
124
+ try {
125
+ protocolContractsRegistered = !!(await db.retrieveAlias('contracts:ContractClassRegistry'));
126
+ // eslint-disable-next-line no-empty
127
+ } catch {}
128
+ if (!protocolContractsRegistered) {
129
+ userLog('Registering protocol contract aliases...');
130
+ for (const [name, address] of Object.entries(ProtocolContractAddress)) {
131
+ await db.storeAlias('contracts', name, Buffer.from(address.toString()), userLog);
132
+ await db.storeAlias(
133
+ 'artifacts',
134
+ address.toString(),
135
+ Buffer.from(`${name.slice(0, 1).toUpperCase()}${name.slice(1)}`),
136
+ userLog,
137
+ );
138
+ }
139
+ }
116
140
  });
117
141
 
118
- injectCommands(program, userLog, debugLogger, db, pxeWrapper);
142
+ injectCommands(program, userLog, debugLogger, walletAndNodeWrapper, db);
119
143
  injectInternalCommands(program, userLog, db);
120
144
  await program.parseAsync(process.argv);
121
145
  }
@@ -1,9 +1,15 @@
1
- import { type AccountWalletWithSecretKey, type AztecAddress, Contract } from '@aztec/aztec.js';
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { SetPublicAuthwitContractInteraction } from '@aztec/aztec.js/authorization';
3
+ import { Contract } from '@aztec/aztec.js/contracts';
4
+ import type { Wallet } from '@aztec/aztec.js/wallet';
2
5
  import { prepTx } from '@aztec/cli/utils';
3
6
  import type { LogFn } from '@aztec/foundation/log';
4
7
 
8
+ import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
9
+
5
10
  export async function authorizeAction(
6
- wallet: AccountWalletWithSecretKey,
11
+ wallet: Wallet,
12
+ from: AztecAddress,
7
13
  functionName: string,
8
14
  caller: AztecAddress,
9
15
  functionArgsIn: any[],
@@ -27,8 +33,13 @@ export async function authorizeAction(
27
33
  const contract = await Contract.at(contractAddress, contractArtifact, wallet);
28
34
  const action = contract.methods[functionName](...functionArgs);
29
35
 
30
- const setAuthwitnessInteraction = await wallet.setPublicAuthWit({ caller, action }, true);
31
- const witness = await setAuthwitnessInteraction.send().wait();
36
+ const setAuthwitnessInteraction = await SetPublicAuthwitContractInteraction.create(
37
+ wallet,
38
+ from,
39
+ { caller, action },
40
+ true,
41
+ );
42
+ const witness = await setAuthwitnessInteraction.send().wait({ timeout: DEFAULT_TX_TIMEOUT_S });
32
43
 
33
44
  log(`Authorized action ${functionName} on contract ${contractAddress} for caller ${caller}`);
34
45
 
@@ -1,14 +1,17 @@
1
- import { L1FeeJuicePortalManager, type PXE } from '@aztec/aztec.js';
1
+ import { L1FeeJuicePortalManager } from '@aztec/aztec.js/ethereum';
2
+ import type { AztecNode } from '@aztec/aztec.js/node';
3
+ import { ProtocolContractAddress } from '@aztec/aztec.js/protocol';
2
4
  import { prettyPrintJSON } from '@aztec/cli/utils';
3
- import { createEthereumChain, createL1Clients } from '@aztec/ethereum';
5
+ import { createEthereumChain, createExtendedL1Client } from '@aztec/ethereum';
4
6
  import { Fr } from '@aztec/foundation/fields';
5
7
  import type { LogFn, Logger } from '@aztec/foundation/log';
6
8
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
9
+ import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
7
10
 
8
11
  export async function bridgeL1FeeJuice(
9
12
  amount: bigint,
10
13
  recipient: AztecAddress,
11
- pxe: PXE,
14
+ node: AztecNode,
12
15
  l1RpcUrls: string[],
13
16
  chainId: number,
14
17
  privateKey: string | undefined,
@@ -22,14 +25,10 @@ export async function bridgeL1FeeJuice(
22
25
  ) {
23
26
  // Prepare L1 client
24
27
  const chain = createEthereumChain(l1RpcUrls, chainId);
25
- const { publicClient, walletClient } = createL1Clients(chain.rpcUrls, privateKey ?? mnemonic, chain.chainInfo);
26
-
27
- const {
28
- protocolContractAddresses: { feeJuice: feeJuiceAddress },
29
- } = await pxe.getPXEInfo();
28
+ const client = createExtendedL1Client(chain.rpcUrls, privateKey ?? mnemonic, chain.chainInfo);
30
29
 
31
30
  // Setup portal manager
32
- const portal = await L1FeeJuicePortalManager.new(pxe, publicClient, walletClient, debugLogger);
31
+ const portal = await L1FeeJuicePortalManager.new(node, client, debugLogger);
33
32
  const { claimAmount, claimSecret, messageHash, messageLeafIndex } = await portal.bridgeTokensPublic(
34
33
  recipient,
35
34
  amount,
@@ -66,8 +65,12 @@ export async function bridgeL1FeeJuice(
66
65
  const delayedCheck = (delay: number) => {
67
66
  return new Promise((resolve, reject) => {
68
67
  setTimeout(() => {
69
- void pxe
70
- .getL1ToL2MembershipWitness(feeJuiceAddress, Fr.fromHexString(messageHash), claimSecret)
68
+ void getNonNullifiedL1ToL2MessageWitness(
69
+ node,
70
+ ProtocolContractAddress.FeeJuice,
71
+ Fr.fromHexString(messageHash),
72
+ claimSecret,
73
+ )
71
74
  .then(witness => resolve(witness))
72
75
  .catch(err => reject(err));
73
76
  }, delay);