@aztec/cli-wallet 0.0.1-commit.b33fc05d0 → 0.0.1-commit.b3d3157a
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/bin/index.js +1 -1
- 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 +41 -15
- 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 +24 -21
- package/dest/cmds/deploy.d.ts +5 -4
- package/dest/cmds/deploy.d.ts.map +1 -1
- package/dest/cmds/deploy.js +40 -34
- package/dest/cmds/deploy_account.d.ts +4 -3
- package/dest/cmds/deploy_account.d.ts.map +1 -1
- package/dest/cmds/deploy_account.js +19 -16
- 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/index.d.ts +1 -1
- package/dest/cmds/index.d.ts.map +1 -1
- package/dest/cmds/index.js +31 -15
- package/dest/cmds/send.d.ts +4 -3
- package/dest/cmds/send.d.ts.map +1 -1
- package/dest/cmds/send.js +23 -22
- package/dest/storage/wallet_db.d.ts +6 -1
- package/dest/storage/wallet_db.d.ts.map +1 -1
- package/dest/storage/wallet_db.js +14 -0
- package/dest/utils/options/fees.d.ts +3 -2
- package/dest/utils/options/fees.d.ts.map +1 -1
- package/dest/utils/options/fees.js +30 -9
- package/dest/utils/wallet.d.ts +11 -7
- package/dest/utils/wallet.d.ts.map +1 -1
- package/dest/utils/wallet.js +104 -49
- package/package.json +16 -15
- package/src/bin/index.ts +1 -1
- package/src/cmds/check_tx.ts +46 -14
- package/src/cmds/create_account.ts +25 -16
- package/src/cmds/deploy.ts +37 -32
- package/src/cmds/deploy_account.ts +19 -11
- package/src/cmds/get_fee_juice_balance.ts +37 -0
- package/src/cmds/index.ts +59 -5
- package/src/cmds/send.ts +20 -15
- package/src/storage/wallet_db.ts +14 -0
- package/src/utils/options/fees.ts +33 -9
- package/src/utils/wallet.ts +112 -72
package/src/utils/wallet.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { EcdsaRAccountContract, EcdsaRSSHAccountContract } from '@aztec/accounts/ecdsa';
|
|
2
2
|
import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
|
|
3
|
-
import {
|
|
3
|
+
import { StubEcdsaAccountContractArtifact, createStubEcdsaAccount } from '@aztec/accounts/stub/ecdsa';
|
|
4
|
+
import { StubSchnorrAccountContractArtifact, createStubSchnorrAccount } from '@aztec/accounts/stub/schnorr';
|
|
4
5
|
import { getIdentities } from '@aztec/accounts/utils';
|
|
5
|
-
import { type Account, type AccountContract,
|
|
6
|
-
import {
|
|
7
|
-
type InteractionFeeOptions,
|
|
8
|
-
getContractInstanceFromInstantiationParams,
|
|
9
|
-
getGasLimits,
|
|
10
|
-
} from '@aztec/aztec.js/contracts';
|
|
6
|
+
import { type Account, type AccountContract, NO_FROM } from '@aztec/aztec.js/account';
|
|
7
|
+
import { type InteractionFeeOptions, getContractClassFromArtifact, getGasLimits } from '@aztec/aztec.js/contracts';
|
|
11
8
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
12
9
|
import { AccountManager, type Aliased, type SimulateOptions } from '@aztec/aztec.js/wallet';
|
|
10
|
+
import { TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
13
11
|
import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
12
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
14
13
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
15
14
|
import type { LogFn } from '@aztec/foundation/log';
|
|
16
|
-
import type {
|
|
15
|
+
import type { NotesFilter } from '@aztec/pxe/client/lazy';
|
|
17
16
|
import type { PXEConfig } from '@aztec/pxe/config';
|
|
18
17
|
import type { PXE } from '@aztec/pxe/server';
|
|
19
18
|
import { createPXE, getPXEConfig } from '@aztec/pxe/server';
|
|
19
|
+
import { getStandardAuthRegistry } from '@aztec/standard-contracts/auth-registry';
|
|
20
20
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
21
21
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
22
22
|
import { NoteDao } from '@aztec/stdlib/note';
|
|
23
|
-
import type {
|
|
23
|
+
import type { SimulationOverrides, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx';
|
|
24
24
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
25
|
-
import { BaseWallet, type
|
|
25
|
+
import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
26
26
|
|
|
27
27
|
import type { WalletDB } from '../storage/wallet_db.js';
|
|
28
28
|
import type { AccountType } from './constants.js';
|
|
@@ -31,6 +31,9 @@ import { printGasEstimates } from './options/fees.js';
|
|
|
31
31
|
|
|
32
32
|
export class CLIWallet extends BaseWallet {
|
|
33
33
|
private accountCache = new Map<string, Account>();
|
|
34
|
+
// Stub class ids, populated on wallet startup
|
|
35
|
+
// to avoid redundant work per simulation
|
|
36
|
+
private stubClassIds = new Map<AccountType, Fr>();
|
|
34
37
|
|
|
35
38
|
constructor(
|
|
36
39
|
pxe: PXE,
|
|
@@ -50,12 +53,43 @@ export class CLIWallet extends BaseWallet {
|
|
|
50
53
|
): Promise<CLIWallet> {
|
|
51
54
|
const pxeConfig = Object.assign(getPXEConfig(), overridePXEConfig);
|
|
52
55
|
const pxe = await createPXE(node, pxeConfig);
|
|
53
|
-
|
|
56
|
+
const wallet = new CLIWallet(pxe, node, log, db);
|
|
57
|
+
await wallet.initStubClasses();
|
|
58
|
+
await wallet.registerAuthRegistry();
|
|
59
|
+
return wallet;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private async registerAuthRegistry(): Promise<void> {
|
|
63
|
+
const { instance, artifact } = await getStandardAuthRegistry();
|
|
64
|
+
await this.pxe.registerContract({ instance, artifact });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Hashes and registers the stub class for every supported account type with PXE, populating
|
|
69
|
+
* stubClassIds. Called on wallet initialization.
|
|
70
|
+
*/
|
|
71
|
+
private async initStubClasses(): Promise<void> {
|
|
72
|
+
const { id: schnorrClassId } = await getContractClassFromArtifact(StubSchnorrAccountContractArtifact);
|
|
73
|
+
await this.pxe.registerContractClass(StubSchnorrAccountContractArtifact);
|
|
74
|
+
|
|
75
|
+
// ecdsa stubs share the same class id
|
|
76
|
+
const { id: ecdsaClassId } = await getContractClassFromArtifact(StubEcdsaAccountContractArtifact);
|
|
77
|
+
await this.pxe.registerContractClass(StubEcdsaAccountContractArtifact);
|
|
78
|
+
|
|
79
|
+
this.stubClassIds.set('schnorr', schnorrClassId);
|
|
80
|
+
this.stubClassIds.set('ecdsasecp256k1', ecdsaClassId);
|
|
81
|
+
this.stubClassIds.set('ecdsasecp256r1', ecdsaClassId);
|
|
82
|
+
this.stubClassIds.set('ecdsasecp256r1ssh', ecdsaClassId);
|
|
54
83
|
}
|
|
55
84
|
|
|
56
85
|
override async getAccounts(): Promise<Aliased<AztecAddress>[]> {
|
|
57
86
|
const accounts = (await this.db?.listAliases('accounts')) ?? [];
|
|
58
|
-
return Promise.resolve(
|
|
87
|
+
return Promise.resolve(
|
|
88
|
+
accounts.map(({ key, value }) => {
|
|
89
|
+
const alias = key.includes(':') ? key.slice(key.indexOf(':') + 1) : key;
|
|
90
|
+
return { alias, item: AztecAddress.fromString(value) };
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
59
93
|
}
|
|
60
94
|
|
|
61
95
|
private async createCancellationTxExecutionRequest(
|
|
@@ -64,14 +98,19 @@ export class CLIWallet extends BaseWallet {
|
|
|
64
98
|
increasedFee: InteractionFeeOptions,
|
|
65
99
|
) {
|
|
66
100
|
const executionPayload = ExecutionPayload.empty();
|
|
67
|
-
const feeOptions = await this.completeFeeOptions(
|
|
101
|
+
const feeOptions = await this.completeFeeOptions({
|
|
102
|
+
from,
|
|
103
|
+
feePayer: executionPayload.feePayer,
|
|
104
|
+
gasSettings: increasedFee.gasSettings,
|
|
105
|
+
});
|
|
68
106
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
69
107
|
const fromAccount = await this.getAccountFromAddress(from);
|
|
70
108
|
const chainInfo = await this.getChainInfo();
|
|
71
109
|
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
72
110
|
txNonce,
|
|
73
111
|
cancellable: this.cancellableTransactions,
|
|
74
|
-
|
|
112
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
113
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
75
114
|
};
|
|
76
115
|
return await fromAccount.createTxExecutionRequest(
|
|
77
116
|
feeExecutionPayload ?? executionPayload,
|
|
@@ -87,14 +126,12 @@ export class CLIWallet extends BaseWallet {
|
|
|
87
126
|
increasedFee: InteractionFeeOptions,
|
|
88
127
|
): Promise<TxProvingResult> {
|
|
89
128
|
const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
|
|
90
|
-
return await this.pxe.proveTx(cancellationTxRequest, this.scopesFrom(from));
|
|
129
|
+
return await this.pxe.proveTx(cancellationTxRequest, { scopes: this.scopesFrom(from), senderForTags: from });
|
|
91
130
|
}
|
|
92
131
|
|
|
93
132
|
override async getAccountFromAddress(address: AztecAddress) {
|
|
94
133
|
let account: Account | undefined;
|
|
95
|
-
if (address.
|
|
96
|
-
account = new SignerlessAccount();
|
|
97
|
-
} else if (this.accountCache.has(address.toString())) {
|
|
134
|
+
if (this.accountCache.has(address.toString())) {
|
|
98
135
|
return this.accountCache.get(address.toString())!;
|
|
99
136
|
} else {
|
|
100
137
|
const accountManager = await this.createOrRetrieveAccount(address);
|
|
@@ -108,7 +145,7 @@ export class CLIWallet extends BaseWallet {
|
|
|
108
145
|
}
|
|
109
146
|
|
|
110
147
|
private async createAccount(secret: Fr, salt: Fr, contract: AccountContract): Promise<AccountManager> {
|
|
111
|
-
const accountManager = await AccountManager.create(this, secret, contract, salt);
|
|
148
|
+
const accountManager = await AccountManager.create(this, secret, contract, { salt });
|
|
112
149
|
|
|
113
150
|
const instance = accountManager.getInstance();
|
|
114
151
|
const artifact = await contract.getContractArtifact();
|
|
@@ -185,33 +222,36 @@ export class CLIWallet extends BaseWallet {
|
|
|
185
222
|
*/
|
|
186
223
|
private async getFakeAccountDataFor(address: AztecAddress) {
|
|
187
224
|
const originalAccount = await this.getAccountFromAddress(address);
|
|
188
|
-
|
|
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();
|
|
225
|
+
const originalAddress = originalAccount.getCompleteAddress();
|
|
195
226
|
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
196
227
|
if (!contractInstance) {
|
|
197
228
|
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
198
229
|
}
|
|
199
|
-
const
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
230
|
+
const { type } = await this.db!.retrieveAccount(address);
|
|
231
|
+
const stubAccount =
|
|
232
|
+
type === 'schnorr' ? createStubSchnorrAccount(originalAddress) : createStubEcdsaAccount(originalAddress);
|
|
233
|
+
const stubClassId = this.stubClassIds.get(type);
|
|
234
|
+
if (!stubClassId) {
|
|
235
|
+
throw new Error(
|
|
236
|
+
`Stub class for account type '${type}' was not registered at wallet init. This is a bug — initStubClasses should cover every supported AccountType.`,
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
const instance = { ...contractInstance, currentContractClassId: stubClassId };
|
|
240
|
+
return { account: stubAccount, instance };
|
|
208
241
|
}
|
|
209
242
|
|
|
210
|
-
override async simulateTx(
|
|
243
|
+
override async simulateTx(
|
|
244
|
+
executionPayload: ExecutionPayload,
|
|
245
|
+
opts: SimulateOptions,
|
|
246
|
+
): Promise<TxSimulationResultWithAppOffset> {
|
|
211
247
|
const simulationResults = await super.simulateTx(executionPayload, opts);
|
|
212
248
|
|
|
213
249
|
if (opts.fee?.estimateGas) {
|
|
214
|
-
const feeOptions = await this.completeFeeOptions(
|
|
250
|
+
const feeOptions = await this.completeFeeOptions({
|
|
251
|
+
from: opts.from,
|
|
252
|
+
feePayer: executionPayload.feePayer,
|
|
253
|
+
gasSettings: opts.fee?.gasSettings,
|
|
254
|
+
});
|
|
215
255
|
const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
|
|
216
256
|
printGasEstimates(feeOptions, limits, this.userLog);
|
|
217
257
|
}
|
|
@@ -220,54 +260,54 @@ export class CLIWallet extends BaseWallet {
|
|
|
220
260
|
|
|
221
261
|
/**
|
|
222
262
|
* Uses a stub account for kernelless simulation, bypassing real account authorization.
|
|
223
|
-
*
|
|
263
|
+
* Uses DefaultEntrypoint directly for NO_FROM transactions.
|
|
224
264
|
*/
|
|
225
265
|
protected override async simulateViaEntrypoint(
|
|
226
266
|
executionPayload: ExecutionPayload,
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
skipFeeEnforcement?: boolean,
|
|
232
|
-
): Promise<TxSimulationResult> {
|
|
233
|
-
if (from.equals(AztecAddress.ZERO)) {
|
|
234
|
-
return super.simulateViaEntrypoint(
|
|
235
|
-
executionPayload,
|
|
236
|
-
from,
|
|
237
|
-
feeOptions,
|
|
238
|
-
scopes,
|
|
239
|
-
skipTxValidation,
|
|
240
|
-
skipFeeEnforcement,
|
|
241
|
-
);
|
|
242
|
-
}
|
|
243
|
-
|
|
267
|
+
opts: SimulateViaEntrypointOptions,
|
|
268
|
+
): Promise<TxSimulationResultWithAppOffset> {
|
|
269
|
+
const { from, feeOptions, additionalScopes, sendMessagesAs } = opts;
|
|
270
|
+
const scopes = this.scopesFrom(from, additionalScopes);
|
|
244
271
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
245
|
-
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
246
|
-
txNonce: Fr.random(),
|
|
247
|
-
cancellable: this.cancellableTransactions,
|
|
248
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
249
|
-
};
|
|
250
272
|
const finalExecutionPayload = feeExecutionPayload
|
|
251
273
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
252
274
|
: executionPayload;
|
|
253
|
-
|
|
254
|
-
const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(from);
|
|
255
275
|
const chainInfo = await this.getChainInfo();
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
276
|
+
|
|
277
|
+
let overrides: SimulationOverrides | undefined;
|
|
278
|
+
let txRequest: TxExecutionRequest;
|
|
279
|
+
if (from === NO_FROM) {
|
|
280
|
+
const entrypoint = new DefaultEntrypoint();
|
|
281
|
+
txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
282
|
+
} else {
|
|
283
|
+
const { account, instance } = await this.getFakeAccountDataFor(from);
|
|
284
|
+
overrides = {
|
|
285
|
+
contracts: { [from.toString()]: { instance } },
|
|
286
|
+
};
|
|
287
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
288
|
+
txNonce: Fr.random(),
|
|
289
|
+
cancellable: this.cancellableTransactions,
|
|
290
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
291
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
292
|
+
};
|
|
293
|
+
txRequest = await account.createTxExecutionRequest(
|
|
294
|
+
finalExecutionPayload,
|
|
295
|
+
feeOptions.gasSettings,
|
|
296
|
+
chainInfo,
|
|
297
|
+
executionOptions,
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
263
302
|
simulatePublic: true,
|
|
264
303
|
skipFeeEnforcement: true,
|
|
265
304
|
skipTxValidation: true,
|
|
266
|
-
overrides
|
|
267
|
-
contracts: { [from.toString()]: { instance, artifact } },
|
|
268
|
-
},
|
|
305
|
+
overrides,
|
|
269
306
|
scopes,
|
|
307
|
+
senderForTags: this.senderForTagsFrom(from, sendMessagesAs),
|
|
270
308
|
});
|
|
309
|
+
const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
|
|
310
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
271
311
|
}
|
|
272
312
|
|
|
273
313
|
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|