@aztec/cli-wallet 0.0.1-commit.9b94fc1 → 0.0.1-commit.9ee6fcc6
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/dest/cmds/authorize_action.d.ts +2 -2
- package/dest/cmds/authorize_action.d.ts.map +1 -1
- package/dest/cmds/authorize_action.js +4 -2
- package/dest/cmds/bridge_fee_juice.d.ts +2 -2
- package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
- package/dest/cmds/bridge_fee_juice.js +3 -2
- package/dest/cmds/check_tx.d.ts +1 -1
- package/dest/cmds/check_tx.d.ts.map +1 -1
- package/dest/cmds/check_tx.js +44 -14
- package/dest/cmds/create_account.d.ts +4 -3
- package/dest/cmds/create_account.d.ts.map +1 -1
- package/dest/cmds/create_account.js +32 -18
- package/dest/cmds/create_authwit.d.ts +2 -2
- package/dest/cmds/create_authwit.d.ts.map +1 -1
- package/dest/cmds/deploy.d.ts +1 -1
- package/dest/cmds/deploy.d.ts.map +1 -1
- package/dest/cmds/deploy.js +50 -24
- package/dest/cmds/deploy_account.d.ts +1 -1
- package/dest/cmds/deploy_account.d.ts.map +1 -1
- package/dest/cmds/deploy_account.js +31 -17
- package/dest/cmds/index.js +2 -2
- package/dest/cmds/send.d.ts +2 -2
- package/dest/cmds/send.d.ts.map +1 -1
- package/dest/cmds/send.js +32 -17
- package/dest/cmds/simulate.d.ts +1 -1
- package/dest/cmds/simulate.d.ts.map +1 -1
- package/dest/cmds/simulate.js +3 -3
- package/dest/storage/wallet_db.d.ts +3 -3
- package/dest/storage/wallet_db.d.ts.map +1 -1
- package/dest/storage/wallet_db.js +47 -32
- package/dest/utils/constants.d.ts +4 -0
- package/dest/utils/constants.d.ts.map +1 -0
- package/dest/utils/constants.js +7 -0
- package/dest/utils/options/fees.d.ts +1 -1
- package/dest/utils/options/fees.d.ts.map +1 -1
- package/dest/utils/options/fees.js +5 -3
- package/dest/utils/options/options.d.ts +2 -2
- package/dest/utils/options/options.d.ts.map +1 -1
- package/dest/utils/options/options.js +1 -1
- package/dest/utils/profiling.d.ts +1 -1
- package/dest/utils/profiling.d.ts.map +1 -1
- package/dest/utils/profiling.js +9 -1
- package/dest/utils/wallet.d.ts +11 -7
- package/dest/utils/wallet.d.ts.map +1 -1
- package/dest/utils/wallet.js +63 -44
- package/package.json +17 -17
- package/src/cmds/authorize_action.ts +1 -1
- package/src/cmds/bridge_fee_juice.ts +3 -2
- package/src/cmds/check_tx.ts +48 -18
- package/src/cmds/create_account.ts +32 -20
- package/src/cmds/deploy.ts +45 -23
- package/src/cmds/deploy_account.ts +29 -18
- package/src/cmds/index.ts +3 -3
- package/src/cmds/send.ts +26 -11
- package/src/cmds/simulate.ts +4 -7
- package/src/storage/wallet_db.ts +51 -38
- package/src/utils/constants.ts +4 -0
- package/src/utils/options/fees.ts +9 -3
- package/src/utils/options/options.ts +1 -1
- package/src/utils/profiling.ts +15 -1
- package/src/utils/wallet.ts +76 -57
package/src/utils/wallet.ts
CHANGED
|
@@ -11,28 +11,24 @@ import {
|
|
|
11
11
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
12
12
|
import { AccountManager, type Aliased, type SimulateOptions } from '@aztec/aztec.js/wallet';
|
|
13
13
|
import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
14
|
-
import { Fr } from '@aztec/foundation/
|
|
14
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
15
15
|
import type { LogFn } from '@aztec/foundation/log';
|
|
16
|
+
import type { NotesFilter } from '@aztec/pxe/client/lazy';
|
|
16
17
|
import type { PXEConfig } from '@aztec/pxe/config';
|
|
17
18
|
import type { PXE } from '@aztec/pxe/server';
|
|
18
19
|
import { createPXE, getPXEConfig } from '@aztec/pxe/server';
|
|
19
20
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
20
21
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
21
22
|
import { NoteDao } from '@aztec/stdlib/note';
|
|
22
|
-
import type {
|
|
23
|
-
import type { TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
23
|
+
import type { SimulationOverrides, TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
24
24
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
25
|
-
import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
|
|
25
|
+
import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
26
26
|
|
|
27
27
|
import type { WalletDB } from '../storage/wallet_db.js';
|
|
28
|
+
import type { AccountType } from './constants.js';
|
|
28
29
|
import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
|
|
29
30
|
import { printGasEstimates } from './options/fees.js';
|
|
30
31
|
|
|
31
|
-
export const AccountTypes = ['schnorr', 'ecdsasecp256r1', 'ecdsasecp256r1ssh', 'ecdsasecp256k1'] as const;
|
|
32
|
-
export type AccountType = (typeof AccountTypes)[number];
|
|
33
|
-
|
|
34
|
-
export const BASE_FEE_PADDING = 0.5;
|
|
35
|
-
|
|
36
32
|
export class CLIWallet extends BaseWallet {
|
|
37
33
|
private accountCache = new Map<string, Account>();
|
|
38
34
|
|
|
@@ -71,6 +67,7 @@ export class CLIWallet extends BaseWallet {
|
|
|
71
67
|
const feeOptions = await this.completeFeeOptions(from, executionPayload.feePayer, increasedFee.gasSettings);
|
|
72
68
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
73
69
|
const fromAccount = await this.getAccountFromAddress(from);
|
|
70
|
+
const chainInfo = await this.getChainInfo();
|
|
74
71
|
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
75
72
|
txNonce,
|
|
76
73
|
cancellable: this.cancellableTransactions,
|
|
@@ -79,6 +76,7 @@ export class CLIWallet extends BaseWallet {
|
|
|
79
76
|
return await fromAccount.createTxExecutionRequest(
|
|
80
77
|
feeExecutionPayload ?? executionPayload,
|
|
81
78
|
feeOptions.gasSettings,
|
|
79
|
+
chainInfo,
|
|
82
80
|
executionOptions,
|
|
83
81
|
);
|
|
84
82
|
}
|
|
@@ -89,14 +87,13 @@ export class CLIWallet extends BaseWallet {
|
|
|
89
87
|
increasedFee: InteractionFeeOptions,
|
|
90
88
|
): Promise<TxProvingResult> {
|
|
91
89
|
const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
|
|
92
|
-
return await this.pxe.proveTx(cancellationTxRequest);
|
|
90
|
+
return await this.pxe.proveTx(cancellationTxRequest, this.scopesFrom(from));
|
|
93
91
|
}
|
|
94
92
|
|
|
95
93
|
override async getAccountFromAddress(address: AztecAddress) {
|
|
96
94
|
let account: Account | undefined;
|
|
97
95
|
if (address.equals(AztecAddress.ZERO)) {
|
|
98
|
-
|
|
99
|
-
account = new SignerlessAccount(chainInfo);
|
|
96
|
+
account = new SignerlessAccount();
|
|
100
97
|
} else if (this.accountCache.has(address.toString())) {
|
|
101
98
|
return this.accountCache.get(address.toString())!;
|
|
102
99
|
} else {
|
|
@@ -180,15 +177,26 @@ export class CLIWallet extends BaseWallet {
|
|
|
180
177
|
return account;
|
|
181
178
|
}
|
|
182
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Creates a stub account that impersonates the given address, allowing kernelless simulations
|
|
182
|
+
* to bypass the account's authorization mechanisms via contract overrides.
|
|
183
|
+
* @param address - The address of the account to impersonate
|
|
184
|
+
* @returns The stub account, contract instance, and artifact for simulation
|
|
185
|
+
*/
|
|
183
186
|
private async getFakeAccountDataFor(address: AztecAddress) {
|
|
184
|
-
const chainInfo = await this.getChainInfo();
|
|
185
187
|
const originalAccount = await this.getAccountFromAddress(address);
|
|
186
|
-
|
|
187
|
-
|
|
188
|
+
// Account contracts can only be overridden if they have an associated address
|
|
189
|
+
// Overwriting SignerlessAccount is not supported, and does not really make sense
|
|
190
|
+
// since it has no authorization mechanism.
|
|
191
|
+
if (originalAccount instanceof SignerlessAccount) {
|
|
192
|
+
throw new Error(`Cannot create fake account data for SignerlessAccount at address: ${address}`);
|
|
193
|
+
}
|
|
194
|
+
const originalAddress = (originalAccount as Account).getCompleteAddress();
|
|
195
|
+
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
188
196
|
if (!contractInstance) {
|
|
189
197
|
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
190
198
|
}
|
|
191
|
-
const stubAccount = createStubAccount(originalAddress
|
|
199
|
+
const stubAccount = createStubAccount(originalAddress);
|
|
192
200
|
const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
|
|
193
201
|
salt: Fr.random(),
|
|
194
202
|
});
|
|
@@ -200,10 +208,37 @@ export class CLIWallet extends BaseWallet {
|
|
|
200
208
|
}
|
|
201
209
|
|
|
202
210
|
override async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
211
|
+
const simulationResults = await super.simulateTx(executionPayload, opts);
|
|
212
|
+
|
|
213
|
+
if (opts.fee?.estimateGas) {
|
|
214
|
+
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
215
|
+
const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
|
|
216
|
+
printGasEstimates(feeOptions, limits, this.userLog);
|
|
217
|
+
}
|
|
218
|
+
return simulationResults;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Uses a stub account for kernelless simulation, bypassing real account authorization.
|
|
223
|
+
* Falls through to the standard entrypoint path for SignerlessAccount (ZERO address).
|
|
224
|
+
*/
|
|
225
|
+
protected override async simulateViaEntrypoint(
|
|
226
|
+
executionPayload: ExecutionPayload,
|
|
227
|
+
opts: SimulateViaEntrypointOptions,
|
|
228
|
+
): Promise<TxSimulationResult> {
|
|
229
|
+
const { from, feeOptions, scopes } = opts;
|
|
230
|
+
let overrides: SimulationOverrides | undefined;
|
|
231
|
+
let fromAccount: Account;
|
|
232
|
+
if (!from.equals(AztecAddress.ZERO)) {
|
|
233
|
+
const { account, instance, artifact } = await this.getFakeAccountDataFor(from);
|
|
234
|
+
fromAccount = account;
|
|
235
|
+
overrides = {
|
|
236
|
+
contracts: { [from.toString()]: { instance, artifact } },
|
|
237
|
+
};
|
|
238
|
+
} else {
|
|
239
|
+
fromAccount = await this.getAccountFromAddress(from);
|
|
240
|
+
}
|
|
241
|
+
|
|
207
242
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
208
243
|
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
209
244
|
txNonce: Fr.random(),
|
|
@@ -214,42 +249,20 @@ export class CLIWallet extends BaseWallet {
|
|
|
214
249
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
215
250
|
: executionPayload;
|
|
216
251
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
opts?.skipFeeEnforcement ?? true,
|
|
232
|
-
);
|
|
233
|
-
} else {
|
|
234
|
-
const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(opts.from);
|
|
235
|
-
const txRequest = await fromAccount.createTxExecutionRequest(
|
|
236
|
-
finalExecutionPayload,
|
|
237
|
-
feeOptions.gasSettings,
|
|
238
|
-
executionOptions,
|
|
239
|
-
);
|
|
240
|
-
const contractOverrides = {
|
|
241
|
-
[opts.from.toString()]: { instance, artifact },
|
|
242
|
-
};
|
|
243
|
-
simulationResults = await this.pxe.simulateTx(txRequest, true /* simulatePublic */, true, true, {
|
|
244
|
-
contracts: contractOverrides,
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if (opts.fee?.estimateGas) {
|
|
249
|
-
const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
|
|
250
|
-
printGasEstimates(feeOptions, limits, this.userLog);
|
|
251
|
-
}
|
|
252
|
-
return simulationResults;
|
|
252
|
+
const chainInfo = await this.getChainInfo();
|
|
253
|
+
const txRequest = await fromAccount.createTxExecutionRequest(
|
|
254
|
+
finalExecutionPayload,
|
|
255
|
+
feeOptions.gasSettings,
|
|
256
|
+
chainInfo,
|
|
257
|
+
executionOptions,
|
|
258
|
+
);
|
|
259
|
+
return this.pxe.simulateTx(txRequest, {
|
|
260
|
+
simulatePublic: true,
|
|
261
|
+
skipFeeEnforcement: true,
|
|
262
|
+
skipTxValidation: true,
|
|
263
|
+
overrides,
|
|
264
|
+
scopes,
|
|
265
|
+
});
|
|
253
266
|
}
|
|
254
267
|
|
|
255
268
|
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
@@ -261,6 +274,12 @@ export class CLIWallet extends BaseWallet {
|
|
|
261
274
|
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
262
275
|
// this is just a CLI wallet.
|
|
263
276
|
getNotes(filter: NotesFilter): Promise<NoteDao[]> {
|
|
264
|
-
return this.pxe.getNotes(filter);
|
|
277
|
+
return this.pxe.debug.getNotes(filter);
|
|
278
|
+
}
|
|
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: Fr) {
|
|
283
|
+
return this.pxe.getContractArtifact(id);
|
|
265
284
|
}
|
|
266
285
|
}
|