@aztec/cli-wallet 0.0.0-test.0 → 0.0.1-commit.0208eb9

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 (111) hide show
  1. package/README.md +30 -0
  2. package/dest/bin/index.d.ts +2 -1
  3. package/dest/bin/index.js +58 -26
  4. package/dest/cmds/authorize_action.d.ts +4 -3
  5. package/dest/cmds/authorize_action.d.ts.map +1 -1
  6. package/dest/cmds/authorize_action.js +11 -5
  7. package/dest/cmds/bridge_fee_juice.d.ts +4 -4
  8. package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
  9. package/dest/cmds/bridge_fee_juice.js +10 -8
  10. package/dest/cmds/check_tx.d.ts +5 -3
  11. package/dest/cmds/check_tx.d.ts.map +1 -1
  12. package/dest/cmds/check_tx.js +147 -6
  13. package/dest/cmds/create_account.d.ts +9 -7
  14. package/dest/cmds/create_account.d.ts.map +1 -1
  15. package/dest/cmds/create_account.js +61 -36
  16. package/dest/cmds/create_authwit.d.ts +4 -3
  17. package/dest/cmds/create_authwit.d.ts.map +1 -1
  18. package/dest/cmds/create_authwit.js +6 -6
  19. package/dest/cmds/deploy.d.ts +7 -4
  20. package/dest/cmds/deploy.d.ts.map +1 -1
  21. package/dest/cmds/deploy.js +98 -58
  22. package/dest/cmds/deploy_account.d.ts +6 -8
  23. package/dest/cmds/deploy_account.d.ts.map +1 -1
  24. package/dest/cmds/deploy_account.js +60 -37
  25. package/dest/cmds/import_test_accounts.d.ts +3 -3
  26. package/dest/cmds/import_test_accounts.d.ts.map +1 -1
  27. package/dest/cmds/import_test_accounts.js +6 -9
  28. package/dest/cmds/index.d.ts +3 -3
  29. package/dest/cmds/index.d.ts.map +1 -1
  30. package/dest/cmds/index.js +83 -115
  31. package/dest/cmds/profile.d.ts +8 -0
  32. package/dest/cmds/profile.d.ts.map +1 -0
  33. package/dest/cmds/profile.js +28 -0
  34. package/dest/cmds/register_contract.d.ts +7 -3
  35. package/dest/cmds/register_contract.d.ts.map +1 -1
  36. package/dest/cmds/register_contract.js +20 -7
  37. package/dest/cmds/register_sender.d.ts +4 -3
  38. package/dest/cmds/register_sender.d.ts.map +1 -1
  39. package/dest/cmds/send.d.ts +8 -9
  40. package/dest/cmds/send.d.ts.map +1 -1
  41. package/dest/cmds/send.js +51 -28
  42. package/dest/cmds/simulate.d.ts +7 -3
  43. package/dest/cmds/simulate.d.ts.map +1 -1
  44. package/dest/cmds/simulate.js +26 -20
  45. package/dest/storage/wallet_db.d.ts +7 -19
  46. package/dest/storage/wallet_db.d.ts.map +1 -1
  47. package/dest/storage/wallet_db.js +49 -55
  48. package/dest/utils/authorizations.d.ts +6 -0
  49. package/dest/utils/authorizations.d.ts.map +1 -0
  50. package/dest/utils/authorizations.js +28 -0
  51. package/dest/utils/cli_wallet_and_node_wrapper.d.ts +12 -0
  52. package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -0
  53. package/dest/utils/cli_wallet_and_node_wrapper.js +25 -0
  54. package/dest/utils/constants.d.ts +4 -0
  55. package/dest/utils/constants.d.ts.map +1 -0
  56. package/dest/utils/constants.js +7 -0
  57. package/dest/utils/ecdsa.d.ts +1 -3
  58. package/dest/utils/ecdsa.d.ts.map +1 -1
  59. package/dest/utils/options/fees.d.ts +22 -28
  60. package/dest/utils/options/fees.d.ts.map +1 -1
  61. package/dest/utils/options/fees.js +86 -145
  62. package/dest/utils/options/index.d.ts +1 -1
  63. package/dest/utils/options/options.d.ts +9 -5
  64. package/dest/utils/options/options.d.ts.map +1 -1
  65. package/dest/utils/options/options.js +26 -14
  66. package/dest/utils/profiling.d.ts +5 -0
  67. package/dest/utils/profiling.d.ts.map +1 -0
  68. package/dest/utils/profiling.js +68 -0
  69. package/dest/utils/wallet.d.ts +35 -0
  70. package/dest/utils/wallet.d.ts.map +1 -0
  71. package/dest/utils/wallet.js +204 -0
  72. package/package.json +29 -22
  73. package/src/bin/index.ts +63 -33
  74. package/src/cmds/authorize_action.ts +16 -5
  75. package/src/cmds/bridge_fee_juice.ts +16 -12
  76. package/src/cmds/check_tx.ts +180 -5
  77. package/src/cmds/create_account.ts +72 -42
  78. package/src/cmds/create_authwit.ts +9 -5
  79. package/src/cmds/deploy.ts +103 -67
  80. package/src/cmds/deploy_account.ts +72 -37
  81. package/src/cmds/import_test_accounts.ts +7 -11
  82. package/src/cmds/index.ts +256 -220
  83. package/src/cmds/profile.ts +48 -0
  84. package/src/cmds/register_contract.ts +28 -5
  85. package/src/cmds/register_sender.ts +3 -2
  86. package/src/cmds/send.ts +51 -25
  87. package/src/cmds/simulate.ts +37 -24
  88. package/src/storage/wallet_db.ts +53 -68
  89. package/src/utils/authorizations.ts +51 -0
  90. package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
  91. package/src/utils/constants.ts +4 -0
  92. package/src/utils/options/fees.ts +136 -207
  93. package/src/utils/options/options.ts +41 -19
  94. package/src/utils/profiling.ts +172 -0
  95. package/src/utils/wallet.ts +283 -0
  96. package/dest/cmds/add_authwit.d.ts +0 -4
  97. package/dest/cmds/add_authwit.d.ts.map +0 -1
  98. package/dest/cmds/add_authwit.js +0 -4
  99. package/dest/cmds/cancel_tx.d.ts +0 -11
  100. package/dest/cmds/cancel_tx.d.ts.map +0 -1
  101. package/dest/cmds/cancel_tx.js +0 -38
  102. package/dest/utils/accounts.d.ts +0 -11
  103. package/dest/utils/accounts.d.ts.map +0 -1
  104. package/dest/utils/accounts.js +0 -87
  105. package/dest/utils/pxe_wrapper.d.ts +0 -10
  106. package/dest/utils/pxe_wrapper.d.ts.map +0 -1
  107. package/dest/utils/pxe_wrapper.js +0 -21
  108. package/src/cmds/add_authwit.ts +0 -13
  109. package/src/cmds/cancel_tx.ts +0 -62
  110. package/src/utils/accounts.ts +0 -102
  111. package/src/utils/pxe_wrapper.ts +0 -26
@@ -0,0 +1,204 @@
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 } from '@aztec/aztec.js/wallet';
8
+ import { Fr } from '@aztec/foundation/curves/bn254';
9
+ import { createPXE, getPXEConfig } from '@aztec/pxe/server';
10
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
11
+ import { deriveSigningKey } from '@aztec/stdlib/keys';
12
+ import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
13
+ import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
14
+ import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
15
+ import { printGasEstimates } from './options/fees.js';
16
+ export class CLIWallet extends BaseWallet {
17
+ userLog;
18
+ db;
19
+ accountCache;
20
+ constructor(pxe, node, userLog, db){
21
+ super(pxe, node), this.userLog = userLog, this.db = db, this.accountCache = new Map();
22
+ this.cancellableTransactions = true;
23
+ }
24
+ static async create(node, log, db, overridePXEConfig) {
25
+ const pxeConfig = Object.assign(getPXEConfig(), overridePXEConfig);
26
+ const pxe = await createPXE(node, pxeConfig);
27
+ return new CLIWallet(pxe, node, log, db);
28
+ }
29
+ async getAccounts() {
30
+ const accounts = await this.db?.listAliases('accounts') ?? [];
31
+ return Promise.resolve(accounts.map(({ key, value })=>({
32
+ alias: value,
33
+ item: AztecAddress.fromString(key)
34
+ })));
35
+ }
36
+ async createCancellationTxExecutionRequest(from, txNonce, increasedFee) {
37
+ const executionPayload = ExecutionPayload.empty();
38
+ const feeOptions = await this.completeFeeOptions(from, executionPayload.feePayer, increasedFee.gasSettings);
39
+ const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
40
+ const fromAccount = await this.getAccountFromAddress(from);
41
+ const chainInfo = await this.getChainInfo();
42
+ const executionOptions = {
43
+ txNonce,
44
+ cancellable: this.cancellableTransactions,
45
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
46
+ };
47
+ return await fromAccount.createTxExecutionRequest(feeExecutionPayload ?? executionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
48
+ }
49
+ async proveCancellationTx(from, txNonce, increasedFee) {
50
+ const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
51
+ return await this.pxe.proveTx(cancellationTxRequest);
52
+ }
53
+ async getAccountFromAddress(address) {
54
+ let account;
55
+ if (address.equals(AztecAddress.ZERO)) {
56
+ account = new SignerlessAccount();
57
+ } else if (this.accountCache.has(address.toString())) {
58
+ return this.accountCache.get(address.toString());
59
+ } else {
60
+ const accountManager = await this.createOrRetrieveAccount(address);
61
+ account = await accountManager.getAccount();
62
+ }
63
+ if (!account) {
64
+ throw new Error(`Account not found in wallet for address: ${address}`);
65
+ }
66
+ return account;
67
+ }
68
+ async createAccount(secret, salt, contract) {
69
+ const accountManager = await AccountManager.create(this, secret, contract, salt);
70
+ const instance = accountManager.getInstance();
71
+ const artifact = await contract.getContractArtifact();
72
+ await this.registerContract(instance, artifact, secret);
73
+ this.accountCache.set(accountManager.address.toString(), await accountManager.getAccount());
74
+ return accountManager;
75
+ }
76
+ async createOrRetrieveAccount(address, secretKey, type = 'schnorr', salt, publicKey) {
77
+ let account;
78
+ salt ??= Fr.ZERO;
79
+ if (this.db && address) {
80
+ ({ type, secretKey, salt } = await this.db.retrieveAccount(address));
81
+ }
82
+ if (!secretKey) {
83
+ throw new Error('Cannot retrieve/create wallet without secret key');
84
+ }
85
+ switch(type){
86
+ case 'schnorr':
87
+ {
88
+ account = await this.createAccount(secretKey, salt, new SchnorrAccountContract(deriveSigningKey(secretKey)));
89
+ break;
90
+ }
91
+ case 'ecdsasecp256r1':
92
+ {
93
+ account = await this.createAccount(secretKey, salt, new EcdsaRAccountContract(deriveSigningKey(secretKey).toBuffer()));
94
+ break;
95
+ }
96
+ case 'ecdsasecp256r1ssh':
97
+ {
98
+ let publicSigningKey;
99
+ if (this.db && address) {
100
+ publicSigningKey = await this.db.retrieveAccountMetadata(address, 'publicSigningKey');
101
+ } else if (publicKey) {
102
+ const identities = await getIdentities();
103
+ const foundIdentity = identities.find((identity)=>identity.type === 'ecdsa-sha2-nistp256' && identity.publicKey === publicKey);
104
+ if (!foundIdentity) {
105
+ throw new Error(`Identity for public key ${publicKey} not found in the SSH agent`);
106
+ }
107
+ publicSigningKey = extractECDSAPublicKeyFromBase64String(foundIdentity.publicKey);
108
+ } else {
109
+ throw new Error('Public key must be provided for ECDSA SSH account');
110
+ }
111
+ account = await this.createAccount(secretKey, salt, new EcdsaRSSHAccountContract(publicSigningKey));
112
+ break;
113
+ }
114
+ default:
115
+ {
116
+ throw new Error(`Unsupported account type: ${type}`);
117
+ }
118
+ }
119
+ return account;
120
+ }
121
+ /**
122
+ * Creates a stub account that impersonates the given address, allowing kernelless simulations
123
+ * to bypass the account's authorization mechanisms via contract overrides.
124
+ * @param address - The address of the account to impersonate
125
+ * @returns The stub account, contract instance, and artifact for simulation
126
+ */ async getFakeAccountDataFor(address) {
127
+ const originalAccount = await this.getAccountFromAddress(address);
128
+ // Account contracts can only be overridden if they have an associated address
129
+ // Overwriting SignerlessAccount is not supported, and does not really make sense
130
+ // since it has no authorization mechanism.
131
+ if (originalAccount instanceof SignerlessAccount) {
132
+ throw new Error(`Cannot create fake account data for SignerlessAccount at address: ${address}`);
133
+ }
134
+ const originalAddress = originalAccount.getCompleteAddress();
135
+ const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
136
+ if (!contractInstance) {
137
+ throw new Error(`No contract instance found for address: ${originalAddress.address}`);
138
+ }
139
+ const stubAccount = createStubAccount(originalAddress);
140
+ const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
141
+ salt: Fr.random()
142
+ });
143
+ return {
144
+ account: stubAccount,
145
+ instance,
146
+ artifact: StubAccountContractArtifact
147
+ };
148
+ }
149
+ async simulateTx(executionPayload, opts) {
150
+ let simulationResults;
151
+ const feeOptions = opts.fee?.estimateGas ? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings) : await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
152
+ const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
153
+ const chainInfo = await this.getChainInfo();
154
+ const executionOptions = {
155
+ txNonce: Fr.random(),
156
+ cancellable: this.cancellableTransactions,
157
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
158
+ };
159
+ const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
160
+ feeExecutionPayload,
161
+ executionPayload
162
+ ]) : executionPayload;
163
+ // Kernelless simulations using the multicall entrypoints are not currently supported,
164
+ // since we only override proper account contracts.
165
+ // TODO: allow disabling kernels even when no overrides are necessary
166
+ if (opts.from.equals(AztecAddress.ZERO)) {
167
+ const fromAccount = await this.getAccountFromAddress(opts.from);
168
+ const txRequest = await fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
169
+ simulationResults = await this.pxe.simulateTx(txRequest, true, opts?.skipTxValidation, opts?.skipFeeEnforcement ?? true);
170
+ } else {
171
+ const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(opts.from);
172
+ const txRequest = await fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
173
+ const contractOverrides = {
174
+ [opts.from.toString()]: {
175
+ instance,
176
+ artifact
177
+ }
178
+ };
179
+ simulationResults = await this.pxe.simulateTx(txRequest, true, true, true, {
180
+ contracts: contractOverrides
181
+ });
182
+ }
183
+ if (opts.fee?.estimateGas) {
184
+ const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
185
+ printGasEstimates(feeOptions, limits, this.userLog);
186
+ }
187
+ return simulationResults;
188
+ }
189
+ // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
190
+ // this is just a CLI wallet.
191
+ getContracts() {
192
+ return this.pxe.getContracts();
193
+ }
194
+ // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
195
+ // this is just a CLI wallet.
196
+ getNotes(filter) {
197
+ return this.pxe.debug.getNotes(filter);
198
+ }
199
+ // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
200
+ // this is just a CLI wallet.
201
+ getContractArtifact(id) {
202
+ return this.pxe.getContractArtifact(id);
203
+ }
204
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/cli-wallet",
3
- "version": "0.0.0-test.0",
3
+ "version": "0.0.1-commit.0208eb9",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/cmds/index.js",
@@ -20,11 +20,9 @@
20
20
  "start": "node --no-warnings ./dest/bin",
21
21
  "start:debug": "node --inspect=0.0.0.0:9221 --no-warnings ./dest/bin",
22
22
  "dev": "LOG_LEVEL=debug && node ./dest/bin",
23
- "build": "yarn clean && tsc -b",
24
- "build:dev": "tsc -b --watch",
23
+ "build": "yarn clean && ../scripts/tsc.sh",
24
+ "build:dev": "../scripts/tsc.sh --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,42 @@
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.0",
69
- "@aztec/aztec.js": "0.0.0-test.0",
70
- "@aztec/cli": "0.0.0-test.0",
71
- "@aztec/ethereum": "0.0.0-test.0",
72
- "@aztec/foundation": "0.0.0-test.0",
73
- "@aztec/kv-store": "0.0.0-test.0",
74
- "@aztec/noir-contracts.js": "0.0.0-test.0",
75
- "@aztec/pxe": "0.0.0-test.0",
76
- "@aztec/stdlib": "0.0.0-test.0",
70
+ "@aztec/accounts": "0.0.1-commit.0208eb9",
71
+ "@aztec/aztec.js": "0.0.1-commit.0208eb9",
72
+ "@aztec/bb.js": "0.0.1-commit.0208eb9",
73
+ "@aztec/cli": "0.0.1-commit.0208eb9",
74
+ "@aztec/entrypoints": "0.0.1-commit.0208eb9",
75
+ "@aztec/ethereum": "0.0.1-commit.0208eb9",
76
+ "@aztec/foundation": "0.0.1-commit.0208eb9",
77
+ "@aztec/kv-store": "0.0.1-commit.0208eb9",
78
+ "@aztec/noir-contracts.js": "0.0.1-commit.0208eb9",
79
+ "@aztec/noir-noirc_abi": "0.0.1-commit.0208eb9",
80
+ "@aztec/pxe": "0.0.1-commit.0208eb9",
81
+ "@aztec/stdlib": "0.0.1-commit.0208eb9",
82
+ "@aztec/wallet-sdk": "0.0.1-commit.0208eb9",
77
83
  "commander": "^12.1.0",
78
84
  "inquirer": "^10.1.8",
79
85
  "source-map-support": "^0.5.21",
80
86
  "tslib": "^2.4.0"
81
87
  },
82
88
  "devDependencies": {
83
- "@jest/globals": "^29.5.0",
84
- "@types/jest": "^29.5.0",
85
- "@types/node": "^18.7.23",
89
+ "@jest/globals": "^30.0.0",
90
+ "@types/jest": "^30.0.0",
91
+ "@types/node": "^22.15.17",
86
92
  "@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",
93
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
94
+ "jest": "^30.0.0",
95
+ "jest-mock-extended": "^4.0.0",
96
+ "ts-jest": "^29.4.0",
90
97
  "ts-node": "^10.9.1",
91
- "typescript": "^5.0.4"
98
+ "typescript": "^5.3.3"
92
99
  },
93
100
  "files": [
94
101
  "dest",
@@ -97,6 +104,6 @@
97
104
  ],
98
105
  "types": "./dest/index.d.ts",
99
106
  "engines": {
100
- "node": ">=18"
107
+ "node": ">=20.10"
101
108
  }
102
109
  }
package/src/bin/index.ts CHANGED
@@ -1,24 +1,31 @@
1
- import { Fr, computeSecretHash, fileURLToPath } from '@aztec/aztec.js';
1
+ #!/usr/bin/env node
2
+ import { computeSecretHash } from '@aztec/aztec.js/crypto';
3
+ import { Fr } from '@aztec/aztec.js/fields';
4
+ import { createAztecNodeClient } from '@aztec/aztec.js/node';
5
+ import { ProtocolContractAddress } from '@aztec/aztec.js/protocol';
6
+ import { BackendType, Barretenberg } from '@aztec/bb.js';
2
7
  import { LOCALHOST } from '@aztec/cli/cli-utils';
3
8
  import { type LogFn, createConsoleLogger, createLogger } from '@aztec/foundation/log';
4
9
  import { openStoreAt } from '@aztec/kv-store/lmdb-v2';
5
- import type { PXEServiceConfig } from '@aztec/pxe/config';
10
+ import type { PXEConfig } from '@aztec/pxe/config';
11
+ import { getPackageVersion } from '@aztec/stdlib/update-checker';
6
12
 
7
13
  import { Argument, Command, Option } from 'commander';
8
- import { mkdirSync, readFileSync } from 'fs';
9
14
  import { homedir } from 'os';
10
- import { dirname, join, resolve } from 'path';
15
+ import { join } from 'path';
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,34 +95,59 @@ 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
+ // Skip initialization if user is just requesting help
99
+ if (command.args.includes('--help') || command.args.includes('-h')) {
100
+ return;
101
+ }
102
+
103
+ const { dataDir, nodeUrl, prover } = command.optsWithGlobals();
94
104
 
95
- if (!remotePxe) {
96
- debugLogger.info('Using local PXE service');
105
+ const proverEnabled = prover !== 'none';
97
106
 
98
- const proverEnabled = prover !== 'none';
107
+ switch (prover) {
108
+ case 'native':
109
+ await Barretenberg.initSingleton({ backend: BackendType.NativeUnixSocket });
110
+ break;
111
+ case 'wasm':
112
+ await Barretenberg.initSingleton({ backend: BackendType.Wasm });
113
+ break;
114
+ }
99
115
 
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 });
116
+ const overridePXEConfig: Partial<PXEConfig> = {
117
+ proverEnabled,
118
+ dataDirectory: join(dataDir, 'pxe'),
119
+ };
106
120
 
107
- const overridePXEConfig: Partial<PXEServiceConfig> = {
108
- proverEnabled,
109
- bbBinaryPath: prover === 'native' ? bbBinaryPath : undefined,
110
- bbWorkingDirectory: prover === 'native' ? bbWorkingDirectory : undefined,
111
- };
121
+ const node = createAztecNodeClient(nodeUrl);
122
+ const wallet = await CLIWallet.create(node, userLog, db, overridePXEConfig);
123
+
124
+ walletAndNodeWrapper.setNodeAndWallet(node, wallet);
112
125
 
113
- await pxeWrapper.init(nodeUrl, join(dataDir, 'pxe'), overridePXEConfig);
114
- }
115
126
  await db.init(await openStoreAt(dataDir));
127
+ let protocolContractsRegistered;
128
+ try {
129
+ protocolContractsRegistered = !!(await db.retrieveAlias('contracts:ContractClassRegistry'));
130
+ // eslint-disable-next-line no-empty
131
+ } catch {}
132
+ if (!protocolContractsRegistered) {
133
+ userLog('Registering protocol contract aliases...');
134
+ for (const [name, address] of Object.entries(ProtocolContractAddress)) {
135
+ await db.storeAlias('contracts', name, Buffer.from(address.toString()), userLog);
136
+ await db.storeAlias(
137
+ 'artifacts',
138
+ address.toString(),
139
+ Buffer.from(`${name.slice(0, 1).toUpperCase()}${name.slice(1)}`),
140
+ userLog,
141
+ );
142
+ }
143
+ }
116
144
  });
117
145
 
118
- injectCommands(program, userLog, debugLogger, db, pxeWrapper);
146
+ injectCommands(program, userLog, debugLogger, walletAndNodeWrapper, db);
119
147
  injectInternalCommands(program, userLog, db);
120
148
  await program.parseAsync(process.argv);
149
+
150
+ await Barretenberg.destroySingleton();
121
151
  }
122
152
 
123
153
  main().catch(err => {
@@ -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[],
@@ -24,11 +30,16 @@ export async function authorizeAction(
24
30
  );
25
31
  }
26
32
 
27
- const contract = await Contract.at(contractAddress, contractArtifact, wallet);
33
+ const contract = 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,18 @@
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';
4
- import { Fr } from '@aztec/foundation/fields';
5
+ import { createEthereumChain } from '@aztec/ethereum/chain';
6
+ import { createExtendedL1Client } from '@aztec/ethereum/client';
7
+ import { Fr } from '@aztec/foundation/curves/bn254';
5
8
  import type { LogFn, Logger } from '@aztec/foundation/log';
6
9
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
10
+ import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
7
11
 
8
12
  export async function bridgeL1FeeJuice(
9
13
  amount: bigint,
10
14
  recipient: AztecAddress,
11
- pxe: PXE,
15
+ node: AztecNode,
12
16
  l1RpcUrls: string[],
13
17
  chainId: number,
14
18
  privateKey: string | undefined,
@@ -22,14 +26,10 @@ export async function bridgeL1FeeJuice(
22
26
  ) {
23
27
  // Prepare L1 client
24
28
  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();
29
+ const client = createExtendedL1Client(chain.rpcUrls, privateKey ?? mnemonic, chain.chainInfo);
30
30
 
31
31
  // Setup portal manager
32
- const portal = await L1FeeJuicePortalManager.new(pxe, publicClient, walletClient, debugLogger);
32
+ const portal = await L1FeeJuicePortalManager.new(node, client, debugLogger);
33
33
  const { claimAmount, claimSecret, messageHash, messageLeafIndex } = await portal.bridgeTokensPublic(
34
34
  recipient,
35
35
  amount,
@@ -66,8 +66,12 @@ export async function bridgeL1FeeJuice(
66
66
  const delayedCheck = (delay: number) => {
67
67
  return new Promise((resolve, reject) => {
68
68
  setTimeout(() => {
69
- void pxe
70
- .getL1ToL2MembershipWitness(feeJuiceAddress, Fr.fromHexString(messageHash), claimSecret)
69
+ void getNonNullifiedL1ToL2MessageWitness(
70
+ node,
71
+ ProtocolContractAddress.FeeJuice,
72
+ Fr.fromHexString(messageHash),
73
+ claimSecret,
74
+ )
71
75
  .then(witness => resolve(witness))
72
76
  .catch(err => reject(err));
73
77
  }, delay);