@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.
- package/README.md +32 -0
- package/dest/bin/index.d.ts +3 -0
- package/dest/bin/index.d.ts.map +1 -0
- package/dest/bin/index.js +96 -0
- package/dest/cmds/authorize_action.d.ts +5 -0
- package/dest/cmds/authorize_action.d.ts.map +1 -0
- package/dest/cmds/authorize_action.js +23 -0
- package/dest/cmds/bridge_fee_juice.d.ts +6 -0
- package/dest/cmds/bridge_fee_juice.d.ts.map +1 -0
- package/dest/cmds/bridge_fee_juice.js +54 -0
- package/dest/cmds/check_tx.d.ts +6 -0
- package/dest/cmds/check_tx.d.ts.map +1 -0
- package/dest/cmds/check_tx.js +181 -0
- package/dest/cmds/create_account.d.ts +17 -0
- package/dest/cmds/create_account.d.ts.map +1 -0
- package/dest/cmds/create_account.js +146 -0
- package/dest/cmds/create_authwit.d.ts +5 -0
- package/dest/cmds/create_authwit.d.ts.map +1 -0
- package/dest/cmds/create_authwit.js +16 -0
- package/dest/cmds/deploy.d.ts +10 -0
- package/dest/cmds/deploy.d.ts.map +1 -0
- package/dest/cmds/deploy.js +129 -0
- package/dest/cmds/deploy_account.d.ts +8 -0
- package/dest/cmds/deploy_account.d.ts.map +1 -0
- package/dest/cmds/deploy_account.js +111 -0
- package/dest/cmds/get_fee_juice_balance.d.ts +5 -0
- package/dest/cmds/get_fee_juice_balance.d.ts.map +1 -0
- package/dest/cmds/get_fee_juice_balance.js +27 -0
- package/dest/cmds/import_test_accounts.d.ts +5 -0
- package/dest/cmds/import_test_accounts.d.ts.map +1 -0
- package/dest/cmds/import_test_accounts.js +40 -0
- package/dest/cmds/index.d.ts +6 -0
- package/dest/cmds/index.d.ts.map +1 -0
- package/dest/cmds/index.js +208 -0
- package/dest/cmds/profile.d.ts +8 -0
- package/dest/cmds/profile.d.ts.map +1 -0
- package/dest/cmds/profile.js +28 -0
- package/dest/cmds/register_contract.d.ts +8 -0
- package/dest/cmds/register_contract.d.ts.map +1 -0
- package/dest/cmds/register_contract.js +27 -0
- package/dest/cmds/register_sender.d.ts +5 -0
- package/dest/cmds/register_sender.d.ts.map +1 -0
- package/dest/cmds/register_sender.js +4 -0
- package/dest/cmds/send.d.ts +11 -0
- package/dest/cmds/send.d.ts.map +1 -0
- package/dest/cmds/send.js +73 -0
- package/dest/cmds/simulate.d.ts +8 -0
- package/dest/cmds/simulate.d.ts.map +1 -0
- package/dest/cmds/simulate.js +33 -0
- package/dest/storage/wallet_db.d.ts +61 -0
- package/dest/storage/wallet_db.d.ts.map +1 -0
- package/dest/storage/wallet_db.js +231 -0
- package/dest/utils/authorizations.d.ts +6 -0
- package/dest/utils/authorizations.d.ts.map +1 -0
- package/dest/utils/authorizations.js +28 -0
- package/dest/utils/cli_wallet_and_node_wrapper.d.ts +12 -0
- package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -0
- package/dest/utils/cli_wallet_and_node_wrapper.js +25 -0
- package/dest/utils/constants.d.ts +4 -0
- package/dest/utils/constants.d.ts.map +1 -0
- package/dest/utils/constants.js +8 -0
- package/dest/utils/ecdsa.d.ts +2 -0
- package/dest/utils/ecdsa.d.ts.map +1 -0
- package/dest/utils/ecdsa.js +13 -0
- package/dest/utils/options/fees.d.ts +36 -0
- package/dest/utils/options/fees.d.ts.map +1 -0
- package/dest/utils/options/fees.js +250 -0
- package/dest/utils/options/index.d.ts +3 -0
- package/dest/utils/options/index.d.ts.map +1 -0
- package/dest/utils/options/index.js +2 -0
- package/dest/utils/options/options.d.ts +24 -0
- package/dest/utils/options/options.d.ts.map +1 -0
- package/dest/utils/options/options.js +134 -0
- package/dest/utils/profiling.d.ts +5 -0
- package/dest/utils/profiling.d.ts.map +1 -0
- package/dest/utils/profiling.js +68 -0
- package/dest/utils/wallet.d.ts +64 -0
- package/dest/utils/wallet.d.ts.map +1 -0
- package/dest/utils/wallet.js +285 -0
- package/dest/utils/well_known_contracts.d.ts +8 -0
- package/dest/utils/well_known_contracts.d.ts.map +1 -0
- package/dest/utils/well_known_contracts.js +38 -0
- package/package.json +108 -0
- package/src/bin/index.ts +141 -0
- package/src/cmds/authorize_action.ts +47 -0
- package/src/cmds/bridge_fee_juice.ts +92 -0
- package/src/cmds/check_tx.ts +220 -0
- package/src/cmds/create_account.ts +176 -0
- package/src/cmds/create_authwit.ts +39 -0
- package/src/cmds/deploy.ts +157 -0
- package/src/cmds/deploy_account.ts +140 -0
- package/src/cmds/get_fee_juice_balance.ts +37 -0
- package/src/cmds/import_test_accounts.ts +54 -0
- package/src/cmds/index.ts +732 -0
- package/src/cmds/profile.ts +47 -0
- package/src/cmds/register_contract.ts +43 -0
- package/src/cmds/register_sender.ts +8 -0
- package/src/cmds/send.ts +96 -0
- package/src/cmds/simulate.ts +55 -0
- package/src/storage/wallet_db.ts +264 -0
- package/src/utils/authorizations.ts +50 -0
- package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
- package/src/utils/constants.ts +10 -0
- package/src/utils/ecdsa.ts +15 -0
- package/src/utils/options/fees.ts +325 -0
- package/src/utils/options/index.ts +2 -0
- package/src/utils/options/options.ts +196 -0
- package/src/utils/profiling.ts +171 -0
- package/src/utils/wallet.ts +377 -0
- package/src/utils/well_known_contracts.ts +46 -0
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { EcdsaKAccountContract, EcdsaRAccountContract, EcdsaRSSHAccountContract } from '@aztec-labs/accounts/ecdsa';
|
|
2
|
+
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 { type Account, type AccountContract, NO_FROM } from '@aztec-labs/aztec.js/account';
|
|
7
|
+
import {
|
|
8
|
+
ContractFunctionInteraction,
|
|
9
|
+
type InteractionFeeOptions,
|
|
10
|
+
getContractClassFromArtifact,
|
|
11
|
+
} from '@aztec-labs/aztec.js/contracts';
|
|
12
|
+
import type { AztecNode } from '@aztec-labs/aztec.js/node';
|
|
13
|
+
import { AccountManager, type Aliased } from '@aztec-labs/aztec.js/wallet';
|
|
14
|
+
import { TxSimulationResultWithAppOffset } from '@aztec-labs/aztec.js/wallet';
|
|
15
|
+
import type { DefaultAccountEntrypointOptions } from '@aztec-labs/entrypoints/account';
|
|
16
|
+
import { DefaultEntrypoint } from '@aztec-labs/entrypoints/default';
|
|
17
|
+
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
18
|
+
import { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
|
|
19
|
+
import type { LogFn } from '@aztec-labs/foundation/log';
|
|
20
|
+
import type { NotesFilter } from '@aztec-labs/pxe/client/lazy';
|
|
21
|
+
import type { PXEConfig } from '@aztec-labs/pxe/config';
|
|
22
|
+
import type { PXE } from '@aztec-labs/pxe/server';
|
|
23
|
+
import { createPXE, getPXEConfig } from '@aztec-labs/pxe/server';
|
|
24
|
+
import { getStandardAuthRegistry } from '@aztec-labs/standard-contracts/auth-registry';
|
|
25
|
+
import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
|
|
26
|
+
import type { Gas, GasUsed } from '@aztec-labs/stdlib/gas';
|
|
27
|
+
import { NoteDao } from '@aztec-labs/stdlib/note';
|
|
28
|
+
import type { SimulationOverrides, TxExecutionRequest, TxProvingResult } from '@aztec-labs/stdlib/tx';
|
|
29
|
+
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec-labs/stdlib/tx';
|
|
30
|
+
import { BaseWallet, type SimulateViaEntrypointOptions, getGasLimits } from '@aztec-labs/wallet-sdk/base-wallet';
|
|
31
|
+
|
|
32
|
+
import type { WalletDB } from '../storage/wallet_db.js';
|
|
33
|
+
import type { AccountType } from './constants.js';
|
|
34
|
+
import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
|
|
35
|
+
|
|
36
|
+
/** Padding the CLI wallet applies to simulated gas usage when deriving declared gas limits. */
|
|
37
|
+
const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
|
|
38
|
+
|
|
39
|
+
export class CLIWallet extends BaseWallet {
|
|
40
|
+
private accountCache = new Map<string, Account>();
|
|
41
|
+
// Stub class ids, populated on wallet startup
|
|
42
|
+
// to avoid redundant work per simulation
|
|
43
|
+
private stubClassIds = new Map<AccountType, Fr>();
|
|
44
|
+
|
|
45
|
+
constructor(
|
|
46
|
+
pxe: PXE,
|
|
47
|
+
node: AztecNode,
|
|
48
|
+
private userLog: LogFn,
|
|
49
|
+
private db?: WalletDB,
|
|
50
|
+
) {
|
|
51
|
+
super(pxe, node);
|
|
52
|
+
this.cancellableTransactions = true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static async create(
|
|
56
|
+
node: AztecNode,
|
|
57
|
+
log: LogFn,
|
|
58
|
+
db?: WalletDB,
|
|
59
|
+
overridePXEConfig?: Partial<PXEConfig>,
|
|
60
|
+
): Promise<CLIWallet> {
|
|
61
|
+
const pxeConfig = Object.assign(getPXEConfig(), overridePXEConfig);
|
|
62
|
+
const pxe = await createPXE(node, pxeConfig);
|
|
63
|
+
const wallet = new CLIWallet(pxe, node, log, db);
|
|
64
|
+
await wallet.initStubClasses();
|
|
65
|
+
await wallet.registerAuthRegistry();
|
|
66
|
+
return wallet;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private async registerAuthRegistry(): Promise<void> {
|
|
70
|
+
const { instance, artifact } = await getStandardAuthRegistry();
|
|
71
|
+
await this.pxe.registerContractClass(artifact);
|
|
72
|
+
await this.pxe.registerContract(instance);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Hashes and registers the stub class for every supported account type with PXE, populating
|
|
77
|
+
* stubClassIds. Called on wallet initialization.
|
|
78
|
+
*/
|
|
79
|
+
private async initStubClasses(): Promise<void> {
|
|
80
|
+
const { id: schnorrClassId } = await getContractClassFromArtifact(StubSchnorrAccountContractArtifact);
|
|
81
|
+
await this.pxe.registerContractClass(StubSchnorrAccountContractArtifact);
|
|
82
|
+
|
|
83
|
+
// ecdsa stubs share the same class id
|
|
84
|
+
const { id: ecdsaClassId } = await getContractClassFromArtifact(StubEcdsaAccountContractArtifact);
|
|
85
|
+
await this.pxe.registerContractClass(StubEcdsaAccountContractArtifact);
|
|
86
|
+
|
|
87
|
+
this.stubClassIds.set('schnorr', schnorrClassId);
|
|
88
|
+
this.stubClassIds.set('schnorr_initializerless', schnorrClassId);
|
|
89
|
+
this.stubClassIds.set('ecdsasecp256k1', ecdsaClassId);
|
|
90
|
+
this.stubClassIds.set('ecdsasecp256r1', ecdsaClassId);
|
|
91
|
+
this.stubClassIds.set('ecdsasecp256r1ssh', ecdsaClassId);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
override async getAccounts(): Promise<Aliased<AztecAddress>[]> {
|
|
95
|
+
const accounts = (await this.db?.listAliases('accounts')) ?? [];
|
|
96
|
+
return Promise.resolve(
|
|
97
|
+
accounts.map(({ key, value }) => {
|
|
98
|
+
const alias = key.includes(':') ? key.slice(key.indexOf(':') + 1) : key;
|
|
99
|
+
return { alias, item: AztecAddress.fromStringUnsafe(value) };
|
|
100
|
+
}),
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Derives suggested total and teardown gas limits from simulated gas usage, padded and clamped to the
|
|
106
|
+
* network's per-tx admission limits.
|
|
107
|
+
* @param gasUsed - The gas consumed during simulation (from a `simulate({ includeMetadata: true })` result).
|
|
108
|
+
*/
|
|
109
|
+
async estimateGasLimits(gasUsed: GasUsed): Promise<{ gasLimits: Gas; teardownGasLimits: Gas }> {
|
|
110
|
+
const maxTxGasLimits = await this.getMaxTxGasLimits();
|
|
111
|
+
return getGasLimits(gasUsed, maxTxGasLimits, DEFAULT_ESTIMATED_GAS_PADDING);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private async createCancellationTxExecutionRequest(
|
|
115
|
+
from: AztecAddress,
|
|
116
|
+
txNonce: Fr,
|
|
117
|
+
increasedFee: InteractionFeeOptions,
|
|
118
|
+
) {
|
|
119
|
+
const executionPayload = ExecutionPayload.empty();
|
|
120
|
+
const feeOptions = await this.completeFeeOptions({
|
|
121
|
+
from,
|
|
122
|
+
feePayer: executionPayload.feePayer,
|
|
123
|
+
gasSettings: increasedFee.gasSettings,
|
|
124
|
+
});
|
|
125
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
126
|
+
const fromAccount = await this.getAccountFromAddress(from);
|
|
127
|
+
const chainInfo = await this.getChainInfo();
|
|
128
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
129
|
+
txNonce,
|
|
130
|
+
cancellable: this.cancellableTransactions,
|
|
131
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
132
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
133
|
+
};
|
|
134
|
+
return await fromAccount.createTxExecutionRequest(
|
|
135
|
+
feeExecutionPayload ?? executionPayload,
|
|
136
|
+
feeOptions.gasSettings,
|
|
137
|
+
chainInfo,
|
|
138
|
+
executionOptions,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async proveCancellationTx(
|
|
143
|
+
from: AztecAddress,
|
|
144
|
+
txNonce: Fr,
|
|
145
|
+
increasedFee: InteractionFeeOptions,
|
|
146
|
+
): Promise<TxProvingResult> {
|
|
147
|
+
const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
|
|
148
|
+
return await this.pxe.proveTx(cancellationTxRequest, {
|
|
149
|
+
scopes: this.scopesFrom(from, [], undefined),
|
|
150
|
+
senderForTags: from,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
override async getAccountFromAddress(address: AztecAddress) {
|
|
155
|
+
let account: Account | undefined;
|
|
156
|
+
if (this.accountCache.has(address.toString())) {
|
|
157
|
+
return this.accountCache.get(address.toString())!;
|
|
158
|
+
} else {
|
|
159
|
+
const accountManager = await this.retrieveAccount(address);
|
|
160
|
+
account = await accountManager.getAccount();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (!account) {
|
|
164
|
+
throw new Error(`Account not found in wallet for address: ${address}`);
|
|
165
|
+
}
|
|
166
|
+
return account;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Creates an account from freshly supplied keys. SSH accounts sign with a key held in the agent (resolved from
|
|
171
|
+
* `publicKey`), every other type is rooted on `signingKey`, with `secretKey` as its privacy secret.
|
|
172
|
+
*/
|
|
173
|
+
async createAccount(
|
|
174
|
+
type: AccountType,
|
|
175
|
+
signingKey: GrumpkinScalar | undefined,
|
|
176
|
+
secretKey: Fr | undefined,
|
|
177
|
+
salt: Fr = Fr.ZERO,
|
|
178
|
+
publicKey?: string,
|
|
179
|
+
): Promise<AccountManager> {
|
|
180
|
+
const publicSigningKey =
|
|
181
|
+
type === 'ecdsasecp256r1ssh' ? await this.resolveSshPublicSigningKey(publicKey) : undefined;
|
|
182
|
+
return this.buildAccount(type, salt, signingKey, secretKey, publicSigningKey);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Retrieves a previously stored account by address, loading its keys, type and salt from the wallet database.
|
|
187
|
+
*/
|
|
188
|
+
async retrieveAccount(address: AztecAddress): Promise<AccountManager> {
|
|
189
|
+
if (!this.db) {
|
|
190
|
+
throw new Error('Cannot retrieve an account without a wallet database');
|
|
191
|
+
}
|
|
192
|
+
const { type, signingKey, secretKey, salt } = await this.db.retrieveAccount(address);
|
|
193
|
+
if (type !== 'ecdsasecp256r1ssh' && !signingKey) {
|
|
194
|
+
throw new Error(
|
|
195
|
+
`Account ${address} has no stored signing key: it was created with an older version of aztec-wallet and is ` +
|
|
196
|
+
`incompatible with this one. Create a new account to continue.`,
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
const publicSigningKey =
|
|
200
|
+
type === 'ecdsasecp256r1ssh' ? await this.db.retrieveAccountMetadata(address, 'publicSigningKey') : undefined;
|
|
201
|
+
return this.buildAccount(type, salt, signingKey, secretKey, publicSigningKey);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private async buildAccount(
|
|
205
|
+
type: AccountType,
|
|
206
|
+
salt: Fr,
|
|
207
|
+
signingKey: GrumpkinScalar | undefined,
|
|
208
|
+
secretKey: Fr | undefined,
|
|
209
|
+
publicSigningKey: Buffer | undefined,
|
|
210
|
+
): Promise<AccountManager> {
|
|
211
|
+
switch (type) {
|
|
212
|
+
case 'schnorr':
|
|
213
|
+
case 'schnorr_initializerless':
|
|
214
|
+
case 'ecdsasecp256r1':
|
|
215
|
+
case 'ecdsasecp256k1': {
|
|
216
|
+
if (!signingKey || !secretKey) {
|
|
217
|
+
throw new Error('Cannot build account without signing key and secret key');
|
|
218
|
+
}
|
|
219
|
+
const contract =
|
|
220
|
+
type === 'schnorr'
|
|
221
|
+
? new SchnorrAccountContract(signingKey)
|
|
222
|
+
: type === 'schnorr_initializerless'
|
|
223
|
+
? new SchnorrInitializerlessAccountContract(signingKey)
|
|
224
|
+
: type === 'ecdsasecp256r1'
|
|
225
|
+
? new EcdsaRAccountContract(signingKey.toBuffer())
|
|
226
|
+
: new EcdsaKAccountContract(signingKey.toBuffer());
|
|
227
|
+
return await this.materializeAccount(secretKey, salt, contract);
|
|
228
|
+
}
|
|
229
|
+
case 'ecdsasecp256r1ssh': {
|
|
230
|
+
if (!secretKey || !publicSigningKey) {
|
|
231
|
+
throw new Error('Cannot build SSH account without secret key and public signing key');
|
|
232
|
+
}
|
|
233
|
+
return await this.materializeAccount(secretKey, salt, new EcdsaRSSHAccountContract(publicSigningKey));
|
|
234
|
+
}
|
|
235
|
+
default: {
|
|
236
|
+
throw new Error(`Unsupported account type: ${type}`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
private async resolveSshPublicSigningKey(publicKey: string | undefined): Promise<Buffer> {
|
|
242
|
+
if (!publicKey) {
|
|
243
|
+
throw new Error('Public key must be provided for ECDSA SSH account');
|
|
244
|
+
}
|
|
245
|
+
const identities = await getIdentities();
|
|
246
|
+
const foundIdentity = identities.find(
|
|
247
|
+
identity => identity.type === 'ecdsa-sha2-nistp256' && identity.publicKey === publicKey,
|
|
248
|
+
);
|
|
249
|
+
if (!foundIdentity) {
|
|
250
|
+
throw new Error(`Identity for public key ${publicKey} not found in the SSH agent`);
|
|
251
|
+
}
|
|
252
|
+
return extractECDSAPublicKeyFromBase64String(foundIdentity.publicKey);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private async materializeAccount(secret: Fr, salt: Fr, contract: AccountContract): Promise<AccountManager> {
|
|
256
|
+
const accountManager = await AccountManager.create(this, secret, contract, { salt });
|
|
257
|
+
|
|
258
|
+
const instance = accountManager.getInstance();
|
|
259
|
+
const artifact = await contract.getContractArtifact();
|
|
260
|
+
|
|
261
|
+
await this.registerContract(instance, artifact, secret);
|
|
262
|
+
this.accountCache.set(accountManager.address.toString(), await accountManager.getAccount());
|
|
263
|
+
|
|
264
|
+
// Initializerless accounts have no deployment tx; their address commits to the signing public key
|
|
265
|
+
// (via the contract's immutablesHash, resolved by AccountManager.create) and the constructor's
|
|
266
|
+
// storage writes are materialized locally via a simulated "store" call here.
|
|
267
|
+
if (contract instanceof SchnorrInitializerlessAccountContract) {
|
|
268
|
+
const constructorAbi = artifact.functions.find(f => f.name === 'constructor');
|
|
269
|
+
if (!constructorAbi) {
|
|
270
|
+
throw new Error('Could not create SchnorrInitializerlessAccount: constructor ABI not found');
|
|
271
|
+
}
|
|
272
|
+
const { x, y } = await contract.getSigningPublicKey();
|
|
273
|
+
const storeCall = new ContractFunctionInteraction(this, instance.address, constructorAbi, [x, y]);
|
|
274
|
+
await storeCall.simulate({ from: instance.address });
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return accountManager;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Creates a stub account that impersonates the given address, allowing kernelless simulations
|
|
282
|
+
* to bypass the account's authorization mechanisms via contract overrides.
|
|
283
|
+
* @param address - The address of the account to impersonate
|
|
284
|
+
* @returns The stub account, contract instance, and artifact for simulation
|
|
285
|
+
*/
|
|
286
|
+
private async getFakeAccountDataFor(address: AztecAddress) {
|
|
287
|
+
const originalAccount = await this.getAccountFromAddress(address);
|
|
288
|
+
const originalAddress = originalAccount.getCompleteAddress();
|
|
289
|
+
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
290
|
+
if (!contractInstance) {
|
|
291
|
+
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
292
|
+
}
|
|
293
|
+
const { type } = await this.db!.retrieveAccount(address);
|
|
294
|
+
const stubAccount =
|
|
295
|
+
type === 'schnorr' || type === 'schnorr_initializerless'
|
|
296
|
+
? createStubSchnorrAccount(originalAddress)
|
|
297
|
+
: createStubEcdsaAccount(originalAddress);
|
|
298
|
+
const stubClassId = this.stubClassIds.get(type);
|
|
299
|
+
if (!stubClassId) {
|
|
300
|
+
throw new Error(
|
|
301
|
+
`Stub class for account type '${type}' was not registered at wallet init. This is a bug — initStubClasses should cover every supported AccountType.`,
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
const instance = { ...contractInstance, currentContractClassId: stubClassId };
|
|
305
|
+
return { account: stubAccount, instance };
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Uses a stub account for kernelless simulation, bypassing real account authorization.
|
|
310
|
+
* Uses DefaultEntrypoint directly for NO_FROM transactions.
|
|
311
|
+
*/
|
|
312
|
+
protected override async simulateViaEntrypoint(
|
|
313
|
+
executionPayload: ExecutionPayload,
|
|
314
|
+
opts: SimulateViaEntrypointOptions,
|
|
315
|
+
): Promise<TxSimulationResultWithAppOffset> {
|
|
316
|
+
const { from, feeOptions, additionalScopes, sendMessagesAs } = opts;
|
|
317
|
+
const scopes = this.scopesFrom(from, additionalScopes ?? [], sendMessagesAs);
|
|
318
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
319
|
+
const finalExecutionPayload = feeExecutionPayload
|
|
320
|
+
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
321
|
+
: executionPayload;
|
|
322
|
+
const chainInfo = await this.getChainInfo();
|
|
323
|
+
|
|
324
|
+
let overrides: SimulationOverrides | undefined;
|
|
325
|
+
let txRequest: TxExecutionRequest;
|
|
326
|
+
if (from === NO_FROM) {
|
|
327
|
+
const entrypoint = new DefaultEntrypoint();
|
|
328
|
+
txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
329
|
+
} else {
|
|
330
|
+
const { account, instance } = await this.getFakeAccountDataFor(from);
|
|
331
|
+
overrides = {
|
|
332
|
+
contracts: { [from.toString()]: { instance } },
|
|
333
|
+
};
|
|
334
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
335
|
+
txNonce: Fr.random(),
|
|
336
|
+
cancellable: this.cancellableTransactions,
|
|
337
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
338
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
339
|
+
};
|
|
340
|
+
txRequest = await account.createTxExecutionRequest(
|
|
341
|
+
finalExecutionPayload,
|
|
342
|
+
feeOptions.gasSettings,
|
|
343
|
+
chainInfo,
|
|
344
|
+
executionOptions,
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
349
|
+
simulatePublic: true,
|
|
350
|
+
skipFeeEnforcement: true,
|
|
351
|
+
skipTxValidation: true,
|
|
352
|
+
overrides,
|
|
353
|
+
scopes,
|
|
354
|
+
senderForTags: this.senderForTagsFrom(from, sendMessagesAs),
|
|
355
|
+
});
|
|
356
|
+
const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
|
|
357
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
361
|
+
// this is just a CLI wallet.
|
|
362
|
+
getContracts(): Promise<AztecAddress[]> {
|
|
363
|
+
return this.pxe.getContracts();
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
367
|
+
// this is just a CLI wallet.
|
|
368
|
+
getNotes(filter: NotesFilter): Promise<NoteDao[]> {
|
|
369
|
+
return this.pxe.debug.getNotes(filter);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
373
|
+
// this is just a CLI wallet.
|
|
374
|
+
getContractArtifact(id: Fr) {
|
|
375
|
+
return this.pxe.getContractArtifact(id);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ProtocolContractAddress } from '@aztec-labs/aztec.js/protocol';
|
|
2
|
+
import { getSponsoredFPCAddress } from '@aztec-labs/cli/cli-utils';
|
|
3
|
+
import type { LogFn } from '@aztec-labs/foundation/log';
|
|
4
|
+
import { StandardContractAddress } from '@aztec-labs/standard-contracts/data';
|
|
5
|
+
import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
|
|
6
|
+
|
|
7
|
+
import type { WalletDB } from '../storage/wallet_db.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Aliases the well-known contracts missing from the wallet's database. Contracts that already have an alias are
|
|
11
|
+
* skipped, so a user's own alias survives and older databases pick up new entries.
|
|
12
|
+
*/
|
|
13
|
+
export async function registerWellKnownContractAliases(db: WalletDB, log: LogFn) {
|
|
14
|
+
for (const { name, getAddress } of wellKnownContracts) {
|
|
15
|
+
if (await hasAlias(db, `contracts:${name}`)) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const address = (await getAddress()).toString();
|
|
19
|
+
await db.storeAlias('contracts', name, Buffer.from(address), log);
|
|
20
|
+
await db.storeAlias('artifacts', address, Buffer.from(name), log);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** A contract that commands can refer to by name, without the user having to know its address. */
|
|
25
|
+
type WellKnownContract = {
|
|
26
|
+
name: string;
|
|
27
|
+
getAddress: () => AztecAddress | Promise<AztecAddress>;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const wellKnownContracts: WellKnownContract[] = [
|
|
31
|
+
...Object.entries({ ...ProtocolContractAddress, ...StandardContractAddress }).map(([name, address]) => ({
|
|
32
|
+
name,
|
|
33
|
+
getAddress: () => address,
|
|
34
|
+
})),
|
|
35
|
+
// SponsoredFPC has no generated address record: it is instantiated with a zero salt, so its address is computed
|
|
36
|
+
// from the current artifact.
|
|
37
|
+
{ name: 'SponsoredFPC', getAddress: getSponsoredFPCAddress },
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
async function hasAlias(db: WalletDB, alias: string) {
|
|
41
|
+
try {
|
|
42
|
+
return !!(await db.retrieveAlias(alias));
|
|
43
|
+
} catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|