@aztec-labs/cli-wallet 6.0.0-nightly.20260829

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 (110) hide show
  1. package/README.md +32 -0
  2. package/dest/bin/index.d.ts +3 -0
  3. package/dest/bin/index.d.ts.map +1 -0
  4. package/dest/bin/index.js +96 -0
  5. package/dest/cmds/authorize_action.d.ts +5 -0
  6. package/dest/cmds/authorize_action.d.ts.map +1 -0
  7. package/dest/cmds/authorize_action.js +23 -0
  8. package/dest/cmds/bridge_fee_juice.d.ts +6 -0
  9. package/dest/cmds/bridge_fee_juice.d.ts.map +1 -0
  10. package/dest/cmds/bridge_fee_juice.js +54 -0
  11. package/dest/cmds/check_tx.d.ts +6 -0
  12. package/dest/cmds/check_tx.d.ts.map +1 -0
  13. package/dest/cmds/check_tx.js +181 -0
  14. package/dest/cmds/create_account.d.ts +17 -0
  15. package/dest/cmds/create_account.d.ts.map +1 -0
  16. package/dest/cmds/create_account.js +146 -0
  17. package/dest/cmds/create_authwit.d.ts +5 -0
  18. package/dest/cmds/create_authwit.d.ts.map +1 -0
  19. package/dest/cmds/create_authwit.js +16 -0
  20. package/dest/cmds/deploy.d.ts +10 -0
  21. package/dest/cmds/deploy.d.ts.map +1 -0
  22. package/dest/cmds/deploy.js +129 -0
  23. package/dest/cmds/deploy_account.d.ts +8 -0
  24. package/dest/cmds/deploy_account.d.ts.map +1 -0
  25. package/dest/cmds/deploy_account.js +111 -0
  26. package/dest/cmds/get_fee_juice_balance.d.ts +5 -0
  27. package/dest/cmds/get_fee_juice_balance.d.ts.map +1 -0
  28. package/dest/cmds/get_fee_juice_balance.js +27 -0
  29. package/dest/cmds/import_test_accounts.d.ts +5 -0
  30. package/dest/cmds/import_test_accounts.d.ts.map +1 -0
  31. package/dest/cmds/import_test_accounts.js +40 -0
  32. package/dest/cmds/index.d.ts +6 -0
  33. package/dest/cmds/index.d.ts.map +1 -0
  34. package/dest/cmds/index.js +208 -0
  35. package/dest/cmds/profile.d.ts +8 -0
  36. package/dest/cmds/profile.d.ts.map +1 -0
  37. package/dest/cmds/profile.js +28 -0
  38. package/dest/cmds/register_contract.d.ts +8 -0
  39. package/dest/cmds/register_contract.d.ts.map +1 -0
  40. package/dest/cmds/register_contract.js +27 -0
  41. package/dest/cmds/register_sender.d.ts +5 -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 +73 -0
  47. package/dest/cmds/simulate.d.ts +8 -0
  48. package/dest/cmds/simulate.d.ts.map +1 -0
  49. package/dest/cmds/simulate.js +33 -0
  50. package/dest/storage/wallet_db.d.ts +61 -0
  51. package/dest/storage/wallet_db.d.ts.map +1 -0
  52. package/dest/storage/wallet_db.js +231 -0
  53. package/dest/utils/authorizations.d.ts +6 -0
  54. package/dest/utils/authorizations.d.ts.map +1 -0
  55. package/dest/utils/authorizations.js +28 -0
  56. package/dest/utils/cli_wallet_and_node_wrapper.d.ts +12 -0
  57. package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -0
  58. package/dest/utils/cli_wallet_and_node_wrapper.js +25 -0
  59. package/dest/utils/constants.d.ts +4 -0
  60. package/dest/utils/constants.d.ts.map +1 -0
  61. package/dest/utils/constants.js +8 -0
  62. package/dest/utils/ecdsa.d.ts +2 -0
  63. package/dest/utils/ecdsa.d.ts.map +1 -0
  64. package/dest/utils/ecdsa.js +13 -0
  65. package/dest/utils/options/fees.d.ts +36 -0
  66. package/dest/utils/options/fees.d.ts.map +1 -0
  67. package/dest/utils/options/fees.js +250 -0
  68. package/dest/utils/options/index.d.ts +3 -0
  69. package/dest/utils/options/index.d.ts.map +1 -0
  70. package/dest/utils/options/index.js +2 -0
  71. package/dest/utils/options/options.d.ts +24 -0
  72. package/dest/utils/options/options.d.ts.map +1 -0
  73. package/dest/utils/options/options.js +134 -0
  74. package/dest/utils/profiling.d.ts +5 -0
  75. package/dest/utils/profiling.d.ts.map +1 -0
  76. package/dest/utils/profiling.js +68 -0
  77. package/dest/utils/wallet.d.ts +64 -0
  78. package/dest/utils/wallet.d.ts.map +1 -0
  79. package/dest/utils/wallet.js +285 -0
  80. package/dest/utils/well_known_contracts.d.ts +8 -0
  81. package/dest/utils/well_known_contracts.d.ts.map +1 -0
  82. package/dest/utils/well_known_contracts.js +38 -0
  83. package/package.json +108 -0
  84. package/src/bin/index.ts +141 -0
  85. package/src/cmds/authorize_action.ts +47 -0
  86. package/src/cmds/bridge_fee_juice.ts +92 -0
  87. package/src/cmds/check_tx.ts +220 -0
  88. package/src/cmds/create_account.ts +176 -0
  89. package/src/cmds/create_authwit.ts +39 -0
  90. package/src/cmds/deploy.ts +157 -0
  91. package/src/cmds/deploy_account.ts +140 -0
  92. package/src/cmds/get_fee_juice_balance.ts +37 -0
  93. package/src/cmds/import_test_accounts.ts +54 -0
  94. package/src/cmds/index.ts +732 -0
  95. package/src/cmds/profile.ts +47 -0
  96. package/src/cmds/register_contract.ts +43 -0
  97. package/src/cmds/register_sender.ts +8 -0
  98. package/src/cmds/send.ts +96 -0
  99. package/src/cmds/simulate.ts +55 -0
  100. package/src/storage/wallet_db.ts +264 -0
  101. package/src/utils/authorizations.ts +50 -0
  102. package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
  103. package/src/utils/constants.ts +10 -0
  104. package/src/utils/ecdsa.ts +15 -0
  105. package/src/utils/options/fees.ts +325 -0
  106. package/src/utils/options/index.ts +2 -0
  107. package/src/utils/options/options.ts +196 -0
  108. package/src/utils/profiling.ts +171 -0
  109. package/src/utils/wallet.ts +377 -0
  110. package/src/utils/well_known_contracts.ts +46 -0
@@ -0,0 +1,64 @@
1
+ import { type Account } from '@aztec-labs/aztec.js/account';
2
+ import { type InteractionFeeOptions } from '@aztec-labs/aztec.js/contracts';
3
+ import type { AztecNode } from '@aztec-labs/aztec.js/node';
4
+ import { AccountManager, type Aliased } from '@aztec-labs/aztec.js/wallet';
5
+ import { TxSimulationResultWithAppOffset } from '@aztec-labs/aztec.js/wallet';
6
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
7
+ import { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
8
+ import type { LogFn } from '@aztec-labs/foundation/log';
9
+ import type { NotesFilter } from '@aztec-labs/pxe/client/lazy';
10
+ import type { PXEConfig } from '@aztec-labs/pxe/config';
11
+ import type { PXE } from '@aztec-labs/pxe/server';
12
+ import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
13
+ import type { Gas, GasUsed } from '@aztec-labs/stdlib/gas';
14
+ import { NoteDao } from '@aztec-labs/stdlib/note';
15
+ import type { TxProvingResult } from '@aztec-labs/stdlib/tx';
16
+ import { ExecutionPayload } from '@aztec-labs/stdlib/tx';
17
+ import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec-labs/wallet-sdk/base-wallet';
18
+ import type { WalletDB } from '../storage/wallet_db.js';
19
+ import type { AccountType } from './constants.js';
20
+ export declare class CLIWallet extends BaseWallet {
21
+ private userLog;
22
+ private db?;
23
+ private accountCache;
24
+ private stubClassIds;
25
+ constructor(pxe: PXE, node: AztecNode, userLog: LogFn, db?: WalletDB | undefined);
26
+ static create(node: AztecNode, log: LogFn, db?: WalletDB, overridePXEConfig?: Partial<PXEConfig>): Promise<CLIWallet>;
27
+ private registerAuthRegistry;
28
+ private initStubClasses;
29
+ getAccounts(): Promise<Aliased<AztecAddress>[]>;
30
+ /**
31
+ * Derives suggested total and teardown gas limits from simulated gas usage, padded and clamped to the
32
+ * network's per-tx admission limits.
33
+ * @param gasUsed - The gas consumed during simulation (from a `simulate({ includeMetadata: true })` result).
34
+ */
35
+ estimateGasLimits(gasUsed: GasUsed): Promise<{
36
+ gasLimits: Gas;
37
+ teardownGasLimits: Gas;
38
+ }>;
39
+ private createCancellationTxExecutionRequest;
40
+ proveCancellationTx(from: AztecAddress, txNonce: Fr, increasedFee: InteractionFeeOptions): Promise<TxProvingResult>;
41
+ getAccountFromAddress(address: AztecAddress): Promise<Account>;
42
+ /**
43
+ * Creates an account from freshly supplied keys. SSH accounts sign with a key held in the agent (resolved from
44
+ * `publicKey`), every other type is rooted on `signingKey`, with `secretKey` as its privacy secret.
45
+ */
46
+ createAccount(type: AccountType, signingKey: GrumpkinScalar | undefined, secretKey: Fr | undefined, salt?: Fr, publicKey?: string): Promise<AccountManager>;
47
+ /**
48
+ * Retrieves a previously stored account by address, loading its keys, type and salt from the wallet database.
49
+ */
50
+ retrieveAccount(address: AztecAddress): Promise<AccountManager>;
51
+ private buildAccount;
52
+ private resolveSshPublicSigningKey;
53
+ private materializeAccount;
54
+ private getFakeAccountDataFor;
55
+ /**
56
+ * Uses a stub account for kernelless simulation, bypassing real account authorization.
57
+ * Uses DefaultEntrypoint directly for NO_FROM transactions.
58
+ */
59
+ protected simulateViaEntrypoint(executionPayload: ExecutionPayload, opts: SimulateViaEntrypointOptions): Promise<TxSimulationResultWithAppOffset>;
60
+ getContracts(): Promise<AztecAddress[]>;
61
+ getNotes(filter: NotesFilter): Promise<NoteDao[]>;
62
+ getContractArtifact(id: Fr): Promise<import("@aztec-labs/stdlib/abi").ContractArtifact | undefined>;
63
+ }
64
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2FsbGV0LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMvd2FsbGV0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUtBLE9BQU8sRUFBRSxLQUFLLE9BQU8sRUFBaUMsTUFBTSw4QkFBOEIsQ0FBQztBQUMzRixPQUFPLEVBRUwsS0FBSyxxQkFBcUIsRUFFM0IsTUFBTSxnQ0FBZ0MsQ0FBQztBQUN4QyxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQUMzRCxPQUFPL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
+ import { StubEcdsaAccountContractArtifact, createStubEcdsaAccount } from '@aztec-labs/accounts/ecdsa/stub';
3
+ import { SchnorrAccountContract, SchnorrInitializerlessAccountContract } from '@aztec-labs/accounts/schnorr';
4
+ import { StubSchnorrAccountContractArtifact, createStubSchnorrAccount } from '@aztec-labs/accounts/schnorr/stub';
5
+ import { getIdentities } from '@aztec-labs/accounts/utils';
6
+ import { NO_FROM } from '@aztec-labs/aztec.js/account';
7
+ import { ContractFunctionInteraction, getContractClassFromArtifact } from '@aztec-labs/aztec.js/contracts';
8
+ import { AccountManager } from '@aztec-labs/aztec.js/wallet';
9
+ import { TxSimulationResultWithAppOffset } from '@aztec-labs/aztec.js/wallet';
10
+ import { DefaultEntrypoint } from '@aztec-labs/entrypoints/default';
11
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
12
+ import { createPXE, getPXEConfig } from '@aztec-labs/pxe/server';
13
+ import { getStandardAuthRegistry } from '@aztec-labs/standard-contracts/auth-registry';
14
+ import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
15
+ import { ExecutionPayload, mergeExecutionPayloads } from '@aztec-labs/stdlib/tx';
16
+ import { BaseWallet, getGasLimits } from '@aztec-labs/wallet-sdk/base-wallet';
17
+ import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
18
+ /** Padding the CLI wallet applies to simulated gas usage when deriving declared gas limits. */ const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
19
+ export class CLIWallet extends BaseWallet {
20
+ userLog;
21
+ db;
22
+ accountCache;
23
+ // Stub class ids, populated on wallet startup
24
+ // to avoid redundant work per simulation
25
+ stubClassIds;
26
+ constructor(pxe, node, userLog, db){
27
+ super(pxe, node), this.userLog = userLog, this.db = db, this.accountCache = new Map(), this.stubClassIds = 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
+ const wallet = new CLIWallet(pxe, node, log, db);
34
+ await wallet.initStubClasses();
35
+ await wallet.registerAuthRegistry();
36
+ return wallet;
37
+ }
38
+ async registerAuthRegistry() {
39
+ const { instance, artifact } = await getStandardAuthRegistry();
40
+ await this.pxe.registerContractClass(artifact);
41
+ await this.pxe.registerContract(instance);
42
+ }
43
+ /**
44
+ * Hashes and registers the stub class for every supported account type with PXE, populating
45
+ * stubClassIds. Called on wallet initialization.
46
+ */ async initStubClasses() {
47
+ const { id: schnorrClassId } = await getContractClassFromArtifact(StubSchnorrAccountContractArtifact);
48
+ await this.pxe.registerContractClass(StubSchnorrAccountContractArtifact);
49
+ // ecdsa stubs share the same class id
50
+ const { id: ecdsaClassId } = await getContractClassFromArtifact(StubEcdsaAccountContractArtifact);
51
+ await this.pxe.registerContractClass(StubEcdsaAccountContractArtifact);
52
+ this.stubClassIds.set('schnorr', schnorrClassId);
53
+ this.stubClassIds.set('schnorr_initializerless', schnorrClassId);
54
+ this.stubClassIds.set('ecdsasecp256k1', ecdsaClassId);
55
+ this.stubClassIds.set('ecdsasecp256r1', ecdsaClassId);
56
+ this.stubClassIds.set('ecdsasecp256r1ssh', ecdsaClassId);
57
+ }
58
+ async getAccounts() {
59
+ const accounts = await this.db?.listAliases('accounts') ?? [];
60
+ return Promise.resolve(accounts.map(({ key, value })=>{
61
+ const alias = key.includes(':') ? key.slice(key.indexOf(':') + 1) : key;
62
+ return {
63
+ alias,
64
+ item: AztecAddress.fromStringUnsafe(value)
65
+ };
66
+ }));
67
+ }
68
+ /**
69
+ * Derives suggested total and teardown gas limits from simulated gas usage, padded and clamped to the
70
+ * network's per-tx admission limits.
71
+ * @param gasUsed - The gas consumed during simulation (from a `simulate({ includeMetadata: true })` result).
72
+ */ async estimateGasLimits(gasUsed) {
73
+ const maxTxGasLimits = await this.getMaxTxGasLimits();
74
+ return getGasLimits(gasUsed, maxTxGasLimits, DEFAULT_ESTIMATED_GAS_PADDING);
75
+ }
76
+ async createCancellationTxExecutionRequest(from, txNonce, increasedFee) {
77
+ const executionPayload = ExecutionPayload.empty();
78
+ const feeOptions = await this.completeFeeOptions({
79
+ from,
80
+ feePayer: executionPayload.feePayer,
81
+ gasSettings: increasedFee.gasSettings
82
+ });
83
+ const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
84
+ const fromAccount = await this.getAccountFromAddress(from);
85
+ const chainInfo = await this.getChainInfo();
86
+ const executionOptions = {
87
+ txNonce,
88
+ cancellable: this.cancellableTransactions,
89
+ // If from is an address, feeOptions include the way the account contract should handle the fee payment
90
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
91
+ };
92
+ return await fromAccount.createTxExecutionRequest(feeExecutionPayload ?? executionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
93
+ }
94
+ async proveCancellationTx(from, txNonce, increasedFee) {
95
+ const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
96
+ return await this.pxe.proveTx(cancellationTxRequest, {
97
+ scopes: this.scopesFrom(from, [], undefined),
98
+ senderForTags: from
99
+ });
100
+ }
101
+ async getAccountFromAddress(address) {
102
+ let account;
103
+ if (this.accountCache.has(address.toString())) {
104
+ return this.accountCache.get(address.toString());
105
+ } else {
106
+ const accountManager = await this.retrieveAccount(address);
107
+ account = await accountManager.getAccount();
108
+ }
109
+ if (!account) {
110
+ throw new Error(`Account not found in wallet for address: ${address}`);
111
+ }
112
+ return account;
113
+ }
114
+ /**
115
+ * Creates an account from freshly supplied keys. SSH accounts sign with a key held in the agent (resolved from
116
+ * `publicKey`), every other type is rooted on `signingKey`, with `secretKey` as its privacy secret.
117
+ */ async createAccount(type, signingKey, secretKey, salt = Fr.ZERO, publicKey) {
118
+ const publicSigningKey = type === 'ecdsasecp256r1ssh' ? await this.resolveSshPublicSigningKey(publicKey) : undefined;
119
+ return this.buildAccount(type, salt, signingKey, secretKey, publicSigningKey);
120
+ }
121
+ /**
122
+ * Retrieves a previously stored account by address, loading its keys, type and salt from the wallet database.
123
+ */ async retrieveAccount(address) {
124
+ if (!this.db) {
125
+ throw new Error('Cannot retrieve an account without a wallet database');
126
+ }
127
+ const { type, signingKey, secretKey, salt } = await this.db.retrieveAccount(address);
128
+ if (type !== 'ecdsasecp256r1ssh' && !signingKey) {
129
+ throw new Error(`Account ${address} has no stored signing key: it was created with an older version of aztec-wallet and is ` + `incompatible with this one. Create a new account to continue.`);
130
+ }
131
+ const publicSigningKey = type === 'ecdsasecp256r1ssh' ? await this.db.retrieveAccountMetadata(address, 'publicSigningKey') : undefined;
132
+ return this.buildAccount(type, salt, signingKey, secretKey, publicSigningKey);
133
+ }
134
+ async buildAccount(type, salt, signingKey, secretKey, publicSigningKey) {
135
+ switch(type){
136
+ case 'schnorr':
137
+ case 'schnorr_initializerless':
138
+ case 'ecdsasecp256r1':
139
+ case 'ecdsasecp256k1':
140
+ {
141
+ if (!signingKey || !secretKey) {
142
+ throw new Error('Cannot build account without signing key and secret key');
143
+ }
144
+ const contract = type === 'schnorr' ? new SchnorrAccountContract(signingKey) : type === 'schnorr_initializerless' ? new SchnorrInitializerlessAccountContract(signingKey) : type === 'ecdsasecp256r1' ? new EcdsaRAccountContract(signingKey.toBuffer()) : new EcdsaKAccountContract(signingKey.toBuffer());
145
+ return await this.materializeAccount(secretKey, salt, contract);
146
+ }
147
+ case 'ecdsasecp256r1ssh':
148
+ {
149
+ if (!secretKey || !publicSigningKey) {
150
+ throw new Error('Cannot build SSH account without secret key and public signing key');
151
+ }
152
+ return await this.materializeAccount(secretKey, salt, new EcdsaRSSHAccountContract(publicSigningKey));
153
+ }
154
+ default:
155
+ {
156
+ throw new Error(`Unsupported account type: ${type}`);
157
+ }
158
+ }
159
+ }
160
+ async resolveSshPublicSigningKey(publicKey) {
161
+ if (!publicKey) {
162
+ throw new Error('Public key must be provided for ECDSA SSH account');
163
+ }
164
+ const identities = await getIdentities();
165
+ const foundIdentity = identities.find((identity)=>identity.type === 'ecdsa-sha2-nistp256' && identity.publicKey === publicKey);
166
+ if (!foundIdentity) {
167
+ throw new Error(`Identity for public key ${publicKey} not found in the SSH agent`);
168
+ }
169
+ return extractECDSAPublicKeyFromBase64String(foundIdentity.publicKey);
170
+ }
171
+ async materializeAccount(secret, salt, contract) {
172
+ const accountManager = await AccountManager.create(this, secret, contract, {
173
+ salt
174
+ });
175
+ const instance = accountManager.getInstance();
176
+ const artifact = await contract.getContractArtifact();
177
+ await this.registerContract(instance, artifact, secret);
178
+ this.accountCache.set(accountManager.address.toString(), await accountManager.getAccount());
179
+ // Initializerless accounts have no deployment tx; their address commits to the signing public key
180
+ // (via the contract's immutablesHash, resolved by AccountManager.create) and the constructor's
181
+ // storage writes are materialized locally via a simulated "store" call here.
182
+ if (contract instanceof SchnorrInitializerlessAccountContract) {
183
+ const constructorAbi = artifact.functions.find((f)=>f.name === 'constructor');
184
+ if (!constructorAbi) {
185
+ throw new Error('Could not create SchnorrInitializerlessAccount: constructor ABI not found');
186
+ }
187
+ const { x, y } = await contract.getSigningPublicKey();
188
+ const storeCall = new ContractFunctionInteraction(this, instance.address, constructorAbi, [
189
+ x,
190
+ y
191
+ ]);
192
+ await storeCall.simulate({
193
+ from: instance.address
194
+ });
195
+ }
196
+ return accountManager;
197
+ }
198
+ /**
199
+ * Creates a stub account that impersonates the given address, allowing kernelless simulations
200
+ * to bypass the account's authorization mechanisms via contract overrides.
201
+ * @param address - The address of the account to impersonate
202
+ * @returns The stub account, contract instance, and artifact for simulation
203
+ */ async getFakeAccountDataFor(address) {
204
+ const originalAccount = await this.getAccountFromAddress(address);
205
+ const originalAddress = originalAccount.getCompleteAddress();
206
+ const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
207
+ if (!contractInstance) {
208
+ throw new Error(`No contract instance found for address: ${originalAddress.address}`);
209
+ }
210
+ const { type } = await this.db.retrieveAccount(address);
211
+ const stubAccount = type === 'schnorr' || type === 'schnorr_initializerless' ? createStubSchnorrAccount(originalAddress) : createStubEcdsaAccount(originalAddress);
212
+ const stubClassId = this.stubClassIds.get(type);
213
+ if (!stubClassId) {
214
+ throw new Error(`Stub class for account type '${type}' was not registered at wallet init. This is a bug — initStubClasses should cover every supported AccountType.`);
215
+ }
216
+ const instance = {
217
+ ...contractInstance,
218
+ currentContractClassId: stubClassId
219
+ };
220
+ return {
221
+ account: stubAccount,
222
+ instance
223
+ };
224
+ }
225
+ /**
226
+ * Uses a stub account for kernelless simulation, bypassing real account authorization.
227
+ * Uses DefaultEntrypoint directly for NO_FROM transactions.
228
+ */ async simulateViaEntrypoint(executionPayload, opts) {
229
+ const { from, feeOptions, additionalScopes, sendMessagesAs } = opts;
230
+ const scopes = this.scopesFrom(from, additionalScopes ?? [], sendMessagesAs);
231
+ const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
232
+ const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
233
+ feeExecutionPayload,
234
+ executionPayload
235
+ ]) : executionPayload;
236
+ const chainInfo = await this.getChainInfo();
237
+ let overrides;
238
+ let txRequest;
239
+ if (from === NO_FROM) {
240
+ const entrypoint = new DefaultEntrypoint();
241
+ txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
242
+ } else {
243
+ const { account, instance } = await this.getFakeAccountDataFor(from);
244
+ overrides = {
245
+ contracts: {
246
+ [from.toString()]: {
247
+ instance
248
+ }
249
+ }
250
+ };
251
+ const executionOptions = {
252
+ txNonce: Fr.random(),
253
+ cancellable: this.cancellableTransactions,
254
+ // If from is an address, feeOptions include the way the account contract should handle the fee payment
255
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
256
+ };
257
+ txRequest = await account.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
258
+ }
259
+ const result = await this.pxe.simulateTx(txRequest, {
260
+ simulatePublic: true,
261
+ skipFeeEnforcement: true,
262
+ skipTxValidation: true,
263
+ overrides,
264
+ scopes,
265
+ senderForTags: this.senderForTagsFrom(from, sendMessagesAs)
266
+ });
267
+ const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
268
+ return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
269
+ }
270
+ // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
271
+ // this is just a CLI wallet.
272
+ getContracts() {
273
+ return this.pxe.getContracts();
274
+ }
275
+ // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
276
+ // this is just a CLI wallet.
277
+ getNotes(filter) {
278
+ return this.pxe.debug.getNotes(filter);
279
+ }
280
+ // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
281
+ // this is just a CLI wallet.
282
+ getContractArtifact(id) {
283
+ return this.pxe.getContractArtifact(id);
284
+ }
285
+ }
@@ -0,0 +1,8 @@
1
+ import type { LogFn } from '@aztec-labs/foundation/log';
2
+ import type { WalletDB } from '../storage/wallet_db.js';
3
+ /**
4
+ * Aliases the well-known contracts missing from the wallet's database. Contracts that already have an alias are
5
+ * skipped, so a user's own alias survives and older databases pick up new entries.
6
+ */
7
+ export declare function registerWellKnownContractAliases(db: WalletDB, log: LogFn): Promise<void>;
8
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2VsbF9rbm93bl9jb250cmFjdHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy93ZWxsX2tub3duX2NvbnRyYWN0cy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEtBQUssRUFBRSxLQUFLLEVBQUUsTUFBTSw0QkFBNEIsQ0FBQztBQUl4RCxPQUFPLEtBQUssRUFBRSxRQUFRLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUV4RDs7O0dBR0c7QUFDSCx3QkFBc0IsZ0NBQWdDLENBQUMsRUFBRSxFQUFFLFFBQVEsRUFBRSxHQUFHLEVBQUUsS0FBSyxpQkFTOUUifQ==
@@ -0,0 +1 @@
1
+ {"version":3,"file":"well_known_contracts.d.ts","sourceRoot":"","sources":["../../src/utils/well_known_contracts.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAIxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAExD;;;GAGG;AACH,wBAAsB,gCAAgC,CAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,iBAS9E"}
@@ -0,0 +1,38 @@
1
+ import { ProtocolContractAddress } from '@aztec-labs/aztec.js/protocol';
2
+ import { getSponsoredFPCAddress } from '@aztec-labs/cli/cli-utils';
3
+ import { StandardContractAddress } from '@aztec-labs/standard-contracts/data';
4
+ /**
5
+ * Aliases the well-known contracts missing from the wallet's database. Contracts that already have an alias are
6
+ * skipped, so a user's own alias survives and older databases pick up new entries.
7
+ */ export async function registerWellKnownContractAliases(db, log) {
8
+ for (const { name, getAddress } of wellKnownContracts){
9
+ if (await hasAlias(db, `contracts:${name}`)) {
10
+ continue;
11
+ }
12
+ const address = (await getAddress()).toString();
13
+ await db.storeAlias('contracts', name, Buffer.from(address), log);
14
+ await db.storeAlias('artifacts', address, Buffer.from(name), log);
15
+ }
16
+ }
17
+ const wellKnownContracts = [
18
+ ...Object.entries({
19
+ ...ProtocolContractAddress,
20
+ ...StandardContractAddress
21
+ }).map(([name, address])=>({
22
+ name,
23
+ getAddress: ()=>address
24
+ })),
25
+ // SponsoredFPC has no generated address record: it is instantiated with a zero salt, so its address is computed
26
+ // from the current artifact.
27
+ {
28
+ name: 'SponsoredFPC',
29
+ getAddress: getSponsoredFPCAddress
30
+ }
31
+ ];
32
+ async function hasAlias(db, alias) {
33
+ try {
34
+ return !!await db.retrieveAlias(alias);
35
+ } catch {
36
+ return false;
37
+ }
38
+ }
package/package.json ADDED
@@ -0,0 +1,108 @@
1
+ {
2
+ "name": "@aztec-labs/cli-wallet",
3
+ "version": "6.0.0-nightly.20260829",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./dest/cmds/index.js",
7
+ "./cli": "./dest/bin/index.js"
8
+ },
9
+ "typedocOptions": {
10
+ "entryPoints": [
11
+ "./src/cmds/index.ts"
12
+ ],
13
+ "name": "Aztec CLI wallet",
14
+ "tsconfig": "./tsconfig.json"
15
+ },
16
+ "bin": {
17
+ "aztec-wallet": "./dest/bin/index.js"
18
+ },
19
+ "scripts": {
20
+ "start": "node --no-warnings ./dest/bin",
21
+ "start:debug": "node --inspect=0.0.0.0:9221 --no-warnings ./dest/bin",
22
+ "dev": "LOG_LEVEL=\"debug; info: json-rpc, simulator\" node ./dest/bin",
23
+ "build": "yarn clean && ../scripts/tsc.sh",
24
+ "build:dev": "../scripts/tsc.sh --watch",
25
+ "clean": "rm -rf ./dest .tsbuildinfo",
26
+ "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
27
+ },
28
+ "inherits": [
29
+ "../package.common.json"
30
+ ],
31
+ "jest": {
32
+ "preset": "ts-jest/presets/default-esm",
33
+ "moduleNameMapper": {
34
+ "^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
35
+ },
36
+ "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
37
+ "rootDir": "./src",
38
+ "extensionsToTreatAsEsm": [
39
+ ".ts"
40
+ ],
41
+ "transform": {
42
+ "^.+\\.tsx?$": [
43
+ "@swc/jest",
44
+ {
45
+ "jsc": {
46
+ "parser": {
47
+ "syntax": "typescript",
48
+ "decorators": true
49
+ },
50
+ "transform": {
51
+ "decoratorVersion": "2022-03"
52
+ }
53
+ }
54
+ }
55
+ ]
56
+ },
57
+ "reporters": [
58
+ "default"
59
+ ],
60
+ "testTimeout": 120000,
61
+ "setupFiles": [
62
+ "../../foundation/src/jest/setup.mjs"
63
+ ],
64
+ "testEnvironment": "../../foundation/src/jest/env.mjs",
65
+ "setupFilesAfterEnv": [
66
+ "../../foundation/src/jest/setupAfterEnv.mjs"
67
+ ]
68
+ },
69
+ "dependencies": {
70
+ "@aztec-labs/accounts": "6.0.0-nightly.20260829",
71
+ "@aztec-labs/aztec.js": "6.0.0-nightly.20260829",
72
+ "@aztec-labs/cli": "6.0.0-nightly.20260829",
73
+ "@aztec-labs/entrypoints": "6.0.0-nightly.20260829",
74
+ "@aztec-labs/ethereum": "6.0.0-nightly.20260829",
75
+ "@aztec-labs/foundation": "6.0.0-nightly.20260829",
76
+ "@aztec-labs/kv-store": "6.0.0-nightly.20260829",
77
+ "@aztec-labs/pxe": "6.0.0-nightly.20260829",
78
+ "@aztec-labs/standard-contracts": "6.0.0-nightly.20260829",
79
+ "@aztec-labs/stdlib": "6.0.0-nightly.20260829",
80
+ "@aztec-labs/wallet-sdk": "6.0.0-nightly.20260829",
81
+ "@aztec/bb.js": "6.0.0-nightly.20260826",
82
+ "commander": "^12.1.0",
83
+ "inquirer": "^10.1.8",
84
+ "source-map-support": "^0.5.21",
85
+ "tslib": "^2.4.0"
86
+ },
87
+ "devDependencies": {
88
+ "@jest/globals": "^30.0.0",
89
+ "@types/jest": "^30.0.0",
90
+ "@types/node": "^22.15.17",
91
+ "@types/source-map-support": "^0.5.10",
92
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
93
+ "jest": "^30.0.0",
94
+ "jest-mock-extended": "^4.0.0",
95
+ "ts-jest": "^29.4.0",
96
+ "ts-node": "^10.9.1",
97
+ "typescript": "^5.3.3"
98
+ },
99
+ "files": [
100
+ "dest",
101
+ "src",
102
+ "!*.test.*"
103
+ ],
104
+ "types": "./dest/index.d.ts",
105
+ "engines": {
106
+ "node": ">=20.10"
107
+ }
108
+ }
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env node
2
+ import { BackendType, Barretenberg } from '@aztec/bb.js';
3
+
4
+ import { computeSecretHash } from '@aztec-labs/aztec.js/crypto';
5
+ import { Fr } from '@aztec-labs/aztec.js/fields';
6
+ import { createAztecNodeClient } from '@aztec-labs/aztec.js/node';
7
+ import { LOCALHOST } from '@aztec-labs/cli/cli-utils';
8
+ import { type LogFn, createConsoleLogger, createLogger } from '@aztec-labs/foundation/log';
9
+ import { openStoreAt } from '@aztec-labs/kv-store/lmdb-v2';
10
+ import type { PXEConfig } from '@aztec-labs/pxe/config';
11
+ import { getPackageVersion } from '@aztec-labs/stdlib/update-checker';
12
+ import { Argument, Command, Option } from 'commander';
13
+ import { homedir } from 'os';
14
+ import { join } from 'path';
15
+
16
+ import { injectCommands } from '../cmds/index.js';
17
+ import { Aliases, WalletDB } from '../storage/wallet_db.js';
18
+ import { CliWalletAndNodeWrapper } from '../utils/cli_wallet_and_node_wrapper.js';
19
+ import { createAliasOption } from '../utils/options/index.js';
20
+ import { CLIWallet } from '../utils/wallet.js';
21
+ import { registerWellKnownContractAliases } from '../utils/well_known_contracts.js';
22
+
23
+ const userLog = createConsoleLogger();
24
+ const debugLogger = createLogger('wallet');
25
+
26
+ const { WALLET_DATA_DIRECTORY = join(homedir(), '.aztec/wallet') } = process.env;
27
+
28
+ // TODO: This function is only used in 1 place so we could just inline this
29
+ function injectInternalCommands(program: Command, log: LogFn, db: WalletDB) {
30
+ program
31
+ .command('alias')
32
+ .description('Aliases information for easy reference.')
33
+ .addArgument(new Argument('<type>', 'Type of alias to create').choices(Aliases))
34
+ .argument('<key>', 'Key to alias.')
35
+ .argument('<value>', 'Value to assign to the alias.')
36
+ .action(async (type, key, value) => {
37
+ value = db.tryRetrieveAlias(value) || value;
38
+ await db.storeAlias(type, key, value, log);
39
+ });
40
+
41
+ program
42
+ .command('get-alias')
43
+ .description('Shows stored aliases')
44
+ .addArgument(new Argument('[alias]', 'Alias to retrieve'))
45
+ .action(async alias => {
46
+ if (alias?.includes(':')) {
47
+ const value = await db.retrieveAlias(alias);
48
+ log(value);
49
+ } else {
50
+ const aliases = await db.listAliases(alias);
51
+ for (const { key, value } of aliases) {
52
+ log(`${key} -> ${value}`);
53
+ }
54
+ }
55
+ });
56
+
57
+ program
58
+ .command('create-secret')
59
+ .description('Creates an aliased secret to use in other commands')
60
+ .addOption(createAliasOption('Key to alias the secret with', false).makeOptionMandatory(true))
61
+ .action(async (_options, command) => {
62
+ const options = command.optsWithGlobals();
63
+ const { alias } = options;
64
+ const value = Fr.random();
65
+ const hash = await computeSecretHash(value);
66
+
67
+ await db.storeAlias('secrets', alias, Buffer.from(value.toString()), log);
68
+ await db.storeAlias('secrets', `${alias}:hash`, Buffer.from(hash.toString()), log);
69
+ });
70
+
71
+ return program;
72
+ }
73
+
74
+ /** CLI wallet main entrypoint */
75
+ async function main() {
76
+ const walletVersion = getPackageVersion();
77
+
78
+ const db = WalletDB.getInstance();
79
+ const walletAndNodeWrapper = new CliWalletAndNodeWrapper();
80
+
81
+ const program = new Command('wallet');
82
+ program
83
+ .description('Aztec wallet')
84
+ .version(walletVersion)
85
+ .option('-d, --data-dir <string>', 'Storage directory for wallet data', WALLET_DATA_DIRECTORY)
86
+ .addOption(
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'),
91
+ )
92
+ .addOption(
93
+ new Option('-n, --node-url <string>', 'URL of the Aztec node to connect to')
94
+ .env('AZTEC_NODE_URL')
95
+ .default(`http://${LOCALHOST}:8080`),
96
+ )
97
+ .hook('preSubcommand', async command => {
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();
104
+
105
+ const proverEnabled = prover !== 'none';
106
+
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
+ }
115
+
116
+ const overridePXEConfig: Partial<PXEConfig> = {
117
+ proverEnabled,
118
+ dataDirectory: join(dataDir, 'pxe'),
119
+ };
120
+
121
+ const node = createAztecNodeClient(nodeUrl);
122
+ const wallet = await CLIWallet.create(node, userLog, db, overridePXEConfig);
123
+
124
+ walletAndNodeWrapper.setNodeAndWallet(node, wallet);
125
+
126
+ await db.init(await openStoreAt(dataDir));
127
+ await registerWellKnownContractAliases(db, userLog);
128
+ });
129
+
130
+ injectCommands(program, userLog, debugLogger, walletAndNodeWrapper, db);
131
+ injectInternalCommands(program, userLog, db);
132
+ await program.parseAsync(process.argv);
133
+
134
+ await Barretenberg.destroySingleton();
135
+ }
136
+
137
+ main().catch(err => {
138
+ debugLogger.error(`Error in command execution`);
139
+ debugLogger.error(err + '\n' + err.stack);
140
+ process.exit(1);
141
+ });