@aztec/cli-wallet 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f
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/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/check_tx.d.ts +1 -1
- package/dest/cmds/check_tx.d.ts.map +1 -1
- package/dest/cmds/check_tx.js +45 -14
- package/dest/cmds/create_account.d.ts +6 -4
- package/dest/cmds/create_account.d.ts.map +1 -1
- package/dest/cmds/create_account.js +42 -25
- 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 +5 -4
- package/dest/cmds/deploy.d.ts.map +1 -1
- package/dest/cmds/deploy.js +64 -32
- 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 +37 -20
- 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 +5 -4
- package/dest/cmds/send.d.ts.map +1 -1
- package/dest/cmds/send.js +32 -16
- 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 +7 -2
- package/dest/storage/wallet_db.d.ts.map +1 -1
- package/dest/storage/wallet_db.js +60 -31
- 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 +3 -2
- package/dest/utils/options/fees.d.ts.map +1 -1
- package/dest/utils/options/fees.js +33 -10
- 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 +16 -8
- package/dest/utils/wallet.d.ts.map +1 -1
- package/dest/utils/wallet.js +129 -61
- package/package.json +17 -16
- package/src/bin/index.ts +1 -1
- package/src/cmds/authorize_action.ts +1 -1
- package/src/cmds/check_tx.ts +50 -19
- package/src/cmds/create_account.ts +46 -25
- package/src/cmds/deploy.ts +63 -36
- package/src/cmds/deploy_account.ts +38 -19
- package/src/cmds/get_fee_juice_balance.ts +37 -0
- package/src/cmds/index.ts +61 -7
- package/src/cmds/send.ts +32 -12
- package/src/cmds/simulate.ts +4 -7
- package/src/storage/wallet_db.ts +64 -37
- package/src/utils/constants.ts +4 -0
- package/src/utils/options/fees.ts +40 -10
- package/src/utils/options/options.ts +1 -1
- package/src/utils/profiling.ts +15 -1
- package/src/utils/wallet.ts +139 -75
package/src/storage/wallet_db.ts
CHANGED
|
@@ -5,13 +5,14 @@ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
|
5
5
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
6
|
import type { TxHash } from '@aztec/stdlib/tx';
|
|
7
7
|
|
|
8
|
+
import type { AccountType } from '../utils/constants.js';
|
|
8
9
|
import { extractECDSAPublicKeyFromBase64String } from '../utils/ecdsa.js';
|
|
9
|
-
import type { AccountType } from '../utils/wallet.js';
|
|
10
10
|
|
|
11
11
|
export const Aliases = ['accounts', 'contracts', 'artifacts', 'secrets', 'transactions', 'authwits'] as const;
|
|
12
12
|
export type AliasType = (typeof Aliases)[number];
|
|
13
13
|
|
|
14
14
|
export class WalletDB {
|
|
15
|
+
#store!: AztecAsyncKVStore;
|
|
15
16
|
#accounts!: AztecAsyncMap<string, Buffer>;
|
|
16
17
|
#aliases!: AztecAsyncMap<string, Buffer>;
|
|
17
18
|
#bridgedFeeJuice!: AztecAsyncMap<string, Buffer>;
|
|
@@ -29,6 +30,7 @@ export class WalletDB {
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
async init(store: AztecAsyncKVStore) {
|
|
33
|
+
this.#store = store;
|
|
32
34
|
this.#accounts = store.openMap('accounts');
|
|
33
35
|
this.#aliases = store.openMap('aliases');
|
|
34
36
|
this.#bridgedFeeJuice = store.openMap('bridgedFeeJuice');
|
|
@@ -41,14 +43,17 @@ export class WalletDB {
|
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
async pushBridgedFeeJuice(recipient: AztecAddress, secret: Fr, amount: bigint, leafIndex: bigint, log: LogFn) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
await this.#store.transactionAsync(async () => {
|
|
47
|
+
let stackPointer =
|
|
48
|
+
(await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:stackPointer`))?.readInt8() || 0;
|
|
49
|
+
stackPointer++;
|
|
50
|
+
await this.#bridgedFeeJuice.set(
|
|
51
|
+
`${recipient.toString()}:${stackPointer}`,
|
|
52
|
+
Buffer.from(`${amount.toString()}:${secret.toString()}:${leafIndex.toString()}`),
|
|
53
|
+
);
|
|
54
|
+
await this.#bridgedFeeJuice.set(`${recipient.toString()}:stackPointer`, Buffer.from([stackPointer]));
|
|
55
|
+
log(`Pushed ${amount} fee juice for recipient ${recipient.toString()}. Stack pointer ${stackPointer}`);
|
|
56
|
+
});
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
async popBridgedFeeJuice(recipient: AztecAddress, log: LogFn) {
|
|
@@ -65,6 +70,20 @@ export class WalletDB {
|
|
|
65
70
|
return { amount: BigInt(amountStr), secret: secretStr, leafIndex: BigInt(leafIndexStr) };
|
|
66
71
|
}
|
|
67
72
|
|
|
73
|
+
async peekBridgedFeeJuice(recipient: AztecAddress, log: LogFn) {
|
|
74
|
+
const stackPointer =
|
|
75
|
+
(await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:stackPointer`))?.readInt8() || 0;
|
|
76
|
+
const result = await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:${stackPointer}`);
|
|
77
|
+
if (!result) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
`No stored fee juice available for recipient ${recipient.toString()}. Please provide claim amount and secret. Stack pointer ${stackPointer}`,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
const [amountStr, secretStr, leafIndexStr] = result.toString().split(':');
|
|
83
|
+
log(`Peeked ${amountStr} fee juice for recipient ${recipient.toString()}. Stack pointer ${stackPointer}`);
|
|
84
|
+
return { amount: BigInt(amountStr), secret: secretStr, leafIndex: BigInt(leafIndexStr) };
|
|
85
|
+
}
|
|
86
|
+
|
|
68
87
|
async storeAccount(
|
|
69
88
|
address: AztecAddress,
|
|
70
89
|
{
|
|
@@ -76,19 +95,24 @@ export class WalletDB {
|
|
|
76
95
|
}: { type: AccountType; secretKey: Fr; salt: Fr; alias: string | undefined; publicKey: string | undefined },
|
|
77
96
|
log: LogFn,
|
|
78
97
|
) {
|
|
79
|
-
|
|
80
|
-
await this.#aliases.set(`accounts:${alias}`, Buffer.from(address.toString()));
|
|
81
|
-
}
|
|
82
|
-
await this.#accounts.set(`${address.toString()}:type`, Buffer.from(type));
|
|
83
|
-
await this.#accounts.set(`${address.toString()}:sk`, secretKey.toBuffer());
|
|
84
|
-
await this.#accounts.set(`${address.toString()}:salt`, salt.toBuffer());
|
|
98
|
+
let publicSigningKey: Buffer | undefined;
|
|
85
99
|
if (type === 'ecdsasecp256r1ssh' && publicKey) {
|
|
86
|
-
|
|
87
|
-
await this.storeAccountMetadata(address, 'publicSigningKey', publicSigningKey);
|
|
100
|
+
publicSigningKey = extractECDSAPublicKeyFromBase64String(publicKey);
|
|
88
101
|
}
|
|
89
|
-
await this.#aliases.set('accounts:last', Buffer.from(address.toString()));
|
|
90
|
-
log(`Account stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
91
102
|
|
|
103
|
+
await this.#store.transactionAsync(async () => {
|
|
104
|
+
if (alias) {
|
|
105
|
+
await this.#aliases.set(`accounts:${alias}`, Buffer.from(address.toString()));
|
|
106
|
+
}
|
|
107
|
+
await this.#accounts.set(`${address.toString()}:type`, Buffer.from(type));
|
|
108
|
+
await this.#accounts.set(`${address.toString()}:sk`, secretKey.toBuffer());
|
|
109
|
+
await this.#accounts.set(`${address.toString()}:salt`, salt.toBuffer());
|
|
110
|
+
if (publicSigningKey) {
|
|
111
|
+
await this.#accounts.set(`${address.toString()}:publicSigningKey`, publicSigningKey);
|
|
112
|
+
}
|
|
113
|
+
await this.#aliases.set('accounts:last', Buffer.from(address.toString()));
|
|
114
|
+
});
|
|
115
|
+
log(`Account stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
92
116
|
await this.refreshAliasCache();
|
|
93
117
|
}
|
|
94
118
|
|
|
@@ -100,35 +124,38 @@ export class WalletDB {
|
|
|
100
124
|
}
|
|
101
125
|
|
|
102
126
|
async storeContract(address: AztecAddress, artifactPath: string, log: LogFn, alias?: string) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
127
|
+
await this.#store.transactionAsync(async () => {
|
|
128
|
+
if (alias) {
|
|
129
|
+
await this.#aliases.set(`contracts:${alias}`, Buffer.from(address.toString()));
|
|
130
|
+
await this.#aliases.set(`artifacts:${alias}`, Buffer.from(artifactPath));
|
|
131
|
+
}
|
|
132
|
+
await this.#aliases.set(`contracts:last`, Buffer.from(address.toString()));
|
|
133
|
+
await this.#aliases.set(`artifacts:last`, Buffer.from(artifactPath));
|
|
134
|
+
await this.#aliases.set(`artifacts:${address.toString()}`, Buffer.from(artifactPath));
|
|
135
|
+
});
|
|
110
136
|
log(`Contract stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
111
|
-
|
|
112
137
|
await this.refreshAliasCache();
|
|
113
138
|
}
|
|
114
139
|
|
|
115
140
|
async storeAuthwitness(authWit: AuthWitness, log: LogFn, alias?: string) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
141
|
+
await this.#store.transactionAsync(async () => {
|
|
142
|
+
if (alias) {
|
|
143
|
+
await this.#aliases.set(`authwits:${alias}`, Buffer.from(authWit.toString()));
|
|
144
|
+
}
|
|
145
|
+
await this.#aliases.set(`authwits:last`, Buffer.from(authWit.toString()));
|
|
146
|
+
});
|
|
120
147
|
log(`Authorization witness stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
121
|
-
|
|
122
148
|
await this.refreshAliasCache();
|
|
123
149
|
}
|
|
124
150
|
|
|
125
151
|
async storeTx({ txHash }: { txHash: TxHash }, log: LogFn, alias?: string) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
152
|
+
await this.#store.transactionAsync(async () => {
|
|
153
|
+
if (alias) {
|
|
154
|
+
await this.#aliases.set(`transactions:${alias}`, Buffer.from(txHash.toString()));
|
|
155
|
+
}
|
|
156
|
+
await this.#aliases.set(`transactions:last`, Buffer.from(txHash.toString()));
|
|
157
|
+
});
|
|
130
158
|
log(`Transaction hash stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
131
|
-
|
|
132
159
|
await this.refreshAliasCache();
|
|
133
160
|
}
|
|
134
161
|
|
|
@@ -5,13 +5,13 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
5
5
|
import type { LogFn } from '@aztec/foundation/log';
|
|
6
6
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
7
7
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
|
-
import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
8
|
+
import { Gas, GasFees, GasSettings, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
9
9
|
import type { FeeOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
10
10
|
|
|
11
11
|
import { Option } from 'commander';
|
|
12
12
|
|
|
13
13
|
import type { WalletDB } from '../../storage/wallet_db.js';
|
|
14
|
-
import {
|
|
14
|
+
import { MIN_FEE_PADDING } from '../constants.js';
|
|
15
15
|
import { aliasedAddressParser } from './options.js';
|
|
16
16
|
|
|
17
17
|
export type RawCliFeeArgs = {
|
|
@@ -115,6 +115,7 @@ export function parsePaymentMethod(
|
|
|
115
115
|
payment: string,
|
|
116
116
|
log: LogFn,
|
|
117
117
|
db?: WalletDB,
|
|
118
|
+
estimateOnly?: boolean,
|
|
118
119
|
): (wallet: Wallet, from: AztecAddress, gasSettings: GasSettings) => Promise<FeePaymentMethod | undefined> {
|
|
119
120
|
const parsed = payment.split(',').reduce(
|
|
120
121
|
(acc, item) => {
|
|
@@ -149,7 +150,7 @@ export function parsePaymentMethod(
|
|
|
149
150
|
amount: claimAmount,
|
|
150
151
|
secret: claimSecret,
|
|
151
152
|
leafIndex: messageLeafIndex,
|
|
152
|
-
} = await db.popBridgedFeeJuice(from, log));
|
|
153
|
+
} = estimateOnly ? await db.peekBridgedFeeJuice(from, log) : await db.popBridgedFeeJuice(from, log));
|
|
153
154
|
} else {
|
|
154
155
|
({ claimAmount, claimSecret, messageLeafIndex } = parsed);
|
|
155
156
|
}
|
|
@@ -157,10 +158,10 @@ export function parsePaymentMethod(
|
|
|
157
158
|
const { FeeJuicePaymentMethodWithClaim } = await import('@aztec/aztec.js/fee');
|
|
158
159
|
return new FeeJuicePaymentMethodWithClaim(from, {
|
|
159
160
|
claimAmount: (typeof claimAmount === 'string'
|
|
160
|
-
? Fr.
|
|
161
|
+
? Fr.fromString(claimAmount)
|
|
161
162
|
: new Fr(claimAmount)
|
|
162
163
|
).toBigInt(),
|
|
163
|
-
claimSecret: Fr.
|
|
164
|
+
claimSecret: typeof claimSecret === 'string' ? Fr.fromString(claimSecret) : claimSecret,
|
|
164
165
|
messageLeafIndex: BigInt(messageLeafIndex),
|
|
165
166
|
});
|
|
166
167
|
} else {
|
|
@@ -171,6 +172,9 @@ export function parsePaymentMethod(
|
|
|
171
172
|
case 'fpc-public': {
|
|
172
173
|
const fpc = getFpc();
|
|
173
174
|
const asset = getAsset();
|
|
175
|
+
log(
|
|
176
|
+
`WARNING: fpc-public is deprecated and will not work on mainnet alpha. Use fee_juice or fpc-sponsored instead.`,
|
|
177
|
+
);
|
|
174
178
|
log(`Using public fee payment with asset ${asset} via paymaster ${fpc}`);
|
|
175
179
|
const { PublicFeePaymentMethod } = await import('@aztec/aztec.js/fee');
|
|
176
180
|
return new PublicFeePaymentMethod(fpc, from, wallet, gasSettings);
|
|
@@ -178,6 +182,9 @@ export function parsePaymentMethod(
|
|
|
178
182
|
case 'fpc-private': {
|
|
179
183
|
const fpc = getFpc();
|
|
180
184
|
const asset = getAsset();
|
|
185
|
+
log(
|
|
186
|
+
`WARNING: fpc-private is deprecated and will not work on mainnet alpha. Use fee_juice or fpc-sponsored instead.`,
|
|
187
|
+
);
|
|
181
188
|
log(`Using private fee payment with asset ${asset} via paymaster ${fpc}`);
|
|
182
189
|
const { PrivateFeePaymentMethod } = await import('@aztec/aztec.js/fee');
|
|
183
190
|
return new PrivateFeePaymentMethod(fpc, from, wallet, gasSettings);
|
|
@@ -250,8 +257,9 @@ export class CLIFeeArgs {
|
|
|
250
257
|
) {}
|
|
251
258
|
|
|
252
259
|
async toUserFeeOptions(node: AztecNode, wallet: Wallet, from: AztecAddress): Promise<ParsedFeeOptions> {
|
|
253
|
-
const
|
|
254
|
-
const
|
|
260
|
+
const minFees = await this.getMinFees(node);
|
|
261
|
+
const maxFeesPerGas = minFees.mul(1 + MIN_FEE_PADDING);
|
|
262
|
+
const gasSettings = GasSettings.fallback({ ...this.gasSettings, maxFeesPerGas });
|
|
255
263
|
const paymentMethod = await this.paymentMethod(wallet, from, gasSettings);
|
|
256
264
|
return {
|
|
257
265
|
paymentMethod,
|
|
@@ -259,10 +267,32 @@ export class CLIFeeArgs {
|
|
|
259
267
|
};
|
|
260
268
|
}
|
|
261
269
|
|
|
270
|
+
/**
|
|
271
|
+
* Returns the worst-case min fee across predicted future slots.
|
|
272
|
+
* Falls back to getCurrentMinFees if the node doesn't support getPredictedMinFees.
|
|
273
|
+
*/
|
|
274
|
+
private async getMinFees(node: AztecNode): Promise<GasFees> {
|
|
275
|
+
try {
|
|
276
|
+
const predicted = await node.getPredictedMinFees(ManaUsageEstimate.Limit);
|
|
277
|
+
if (predicted.length === 0) {
|
|
278
|
+
return node.getCurrentMinFees();
|
|
279
|
+
}
|
|
280
|
+
return predicted.reduce((worst, fees) => (fees.feePerL2Gas > worst.feePerL2Gas ? fees : worst));
|
|
281
|
+
} catch (err: any) {
|
|
282
|
+
// Fallback for old nodes that don't support getPredictedMinFees.
|
|
283
|
+
// Only fall back on method-not-found errors (JSON-RPC code -32601); rethrow others.
|
|
284
|
+
if (err?.cause?.code === -32601 || err?.message?.includes('Method not found')) {
|
|
285
|
+
return node.getCurrentMinFees();
|
|
286
|
+
}
|
|
287
|
+
throw err;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
262
291
|
static parse(args: RawCliFeeArgs, log: LogFn, db?: WalletDB): CLIFeeArgs {
|
|
292
|
+
const estimateOnly = !!args.estimateGasOnly;
|
|
263
293
|
return new CLIFeeArgs(
|
|
264
|
-
|
|
265
|
-
parsePaymentMethod(args.payment ?? 'method=fee_juice', log, db),
|
|
294
|
+
estimateOnly,
|
|
295
|
+
parsePaymentMethod(args.payment ?? 'method=fee_juice', log, db, estimateOnly),
|
|
266
296
|
parseGasSettings(args),
|
|
267
297
|
);
|
|
268
298
|
}
|
|
@@ -288,7 +318,7 @@ function formatGasEstimate(estimate: Pick<GasSettings, 'gasLimits' | 'teardownGa
|
|
|
288
318
|
}
|
|
289
319
|
|
|
290
320
|
function getEstimatedCost(estimate: Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>, maxFeesPerGas: GasFees) {
|
|
291
|
-
return GasSettings.
|
|
321
|
+
return GasSettings.fallback({ ...estimate, maxFeesPerGas })
|
|
292
322
|
.getFeeLimit()
|
|
293
323
|
.toBigInt();
|
|
294
324
|
}
|
|
@@ -7,7 +7,7 @@ import { Option } from 'commander';
|
|
|
7
7
|
import { readdir, stat } from 'fs/promises';
|
|
8
8
|
|
|
9
9
|
import type { AliasType, WalletDB } from '../../storage/wallet_db.js';
|
|
10
|
-
import { AccountTypes } from '../
|
|
10
|
+
import { AccountTypes } from '../constants.js';
|
|
11
11
|
|
|
12
12
|
const TARGET_DIR = 'target';
|
|
13
13
|
|
package/src/utils/profiling.ts
CHANGED
|
@@ -95,7 +95,7 @@ export function printProfileResult(
|
|
|
95
95
|
|
|
96
96
|
if (stats.nodeRPCCalls) {
|
|
97
97
|
log(format('\nRPC calls:\n'));
|
|
98
|
-
for (const [method, { times }] of Object.entries(stats.nodeRPCCalls)) {
|
|
98
|
+
for (const [method, { times }] of Object.entries(stats.nodeRPCCalls.perMethod)) {
|
|
99
99
|
const calls = times.length;
|
|
100
100
|
const total = times.reduce((acc, time) => acc + time, 0);
|
|
101
101
|
const avg = total / calls;
|
|
@@ -112,6 +112,20 @@ export function printProfileResult(
|
|
|
112
112
|
),
|
|
113
113
|
);
|
|
114
114
|
}
|
|
115
|
+
|
|
116
|
+
const { roundTrips } = stats.nodeRPCCalls;
|
|
117
|
+
log(format('\nRound trips (actual blocking waits):\n'));
|
|
118
|
+
log(format('Round trips:'.padEnd(25), `${roundTrips.roundTrips}`.padStart(COLUMN_MAX_WIDTH)));
|
|
119
|
+
log(
|
|
120
|
+
format(
|
|
121
|
+
'Total blocking time:'.padEnd(25),
|
|
122
|
+
`${roundTrips.totalBlockingTime.toFixed(2)}ms`.padStart(COLUMN_MAX_WIDTH),
|
|
123
|
+
),
|
|
124
|
+
);
|
|
125
|
+
if (roundTrips.roundTrips > 0) {
|
|
126
|
+
const avgRoundTrip = roundTrips.totalBlockingTime / roundTrips.roundTrips;
|
|
127
|
+
log(format('Avg round trip:'.padEnd(25), `${avgRoundTrip.toFixed(2)}ms`.padStart(COLUMN_MAX_WIDTH)));
|
|
128
|
+
}
|
|
115
129
|
}
|
|
116
130
|
|
|
117
131
|
log(format('\nSync time:'.padEnd(25), `${timings.sync?.toFixed(2)}ms`.padStart(16)));
|
package/src/utils/wallet.ts
CHANGED
|
@@ -1,40 +1,39 @@
|
|
|
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';
|
|
15
|
+
import type { NotesFilter } from '@aztec/pxe/client/lazy';
|
|
16
16
|
import type { PXEConfig } from '@aztec/pxe/config';
|
|
17
17
|
import type { PXE } from '@aztec/pxe/server';
|
|
18
18
|
import { createPXE, getPXEConfig } from '@aztec/pxe/server';
|
|
19
|
+
import { getStandardAuthRegistry } from '@aztec/standard-contracts/auth-registry';
|
|
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, TxExecutionRequest, TxProvingResult } 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>();
|
|
34
|
+
// Stub class ids, populated on wallet startup
|
|
35
|
+
// to avoid redundant work per simulation
|
|
36
|
+
private stubClassIds = new Map<AccountType, Fr>();
|
|
38
37
|
|
|
39
38
|
constructor(
|
|
40
39
|
pxe: PXE,
|
|
@@ -54,12 +53,43 @@ export class CLIWallet extends BaseWallet {
|
|
|
54
53
|
): Promise<CLIWallet> {
|
|
55
54
|
const pxeConfig = Object.assign(getPXEConfig(), overridePXEConfig);
|
|
56
55
|
const pxe = await createPXE(node, pxeConfig);
|
|
57
|
-
|
|
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);
|
|
58
83
|
}
|
|
59
84
|
|
|
60
85
|
override async getAccounts(): Promise<Aliased<AztecAddress>[]> {
|
|
61
86
|
const accounts = (await this.db?.listAliases('accounts')) ?? [];
|
|
62
|
-
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
|
+
);
|
|
63
93
|
}
|
|
64
94
|
|
|
65
95
|
private async createCancellationTxExecutionRequest(
|
|
@@ -68,17 +98,24 @@ export class CLIWallet extends BaseWallet {
|
|
|
68
98
|
increasedFee: InteractionFeeOptions,
|
|
69
99
|
) {
|
|
70
100
|
const executionPayload = ExecutionPayload.empty();
|
|
71
|
-
const feeOptions = await this.completeFeeOptions(
|
|
101
|
+
const feeOptions = await this.completeFeeOptions({
|
|
102
|
+
from,
|
|
103
|
+
feePayer: executionPayload.feePayer,
|
|
104
|
+
gasSettings: increasedFee.gasSettings,
|
|
105
|
+
});
|
|
72
106
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
73
107
|
const fromAccount = await this.getAccountFromAddress(from);
|
|
108
|
+
const chainInfo = await this.getChainInfo();
|
|
74
109
|
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
75
110
|
txNonce,
|
|
76
111
|
cancellable: this.cancellableTransactions,
|
|
77
|
-
|
|
112
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
113
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
78
114
|
};
|
|
79
115
|
return await fromAccount.createTxExecutionRequest(
|
|
80
116
|
feeExecutionPayload ?? executionPayload,
|
|
81
117
|
feeOptions.gasSettings,
|
|
118
|
+
chainInfo,
|
|
82
119
|
executionOptions,
|
|
83
120
|
);
|
|
84
121
|
}
|
|
@@ -89,15 +126,12 @@ export class CLIWallet extends BaseWallet {
|
|
|
89
126
|
increasedFee: InteractionFeeOptions,
|
|
90
127
|
): Promise<TxProvingResult> {
|
|
91
128
|
const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
|
|
92
|
-
return await this.pxe.proveTx(cancellationTxRequest);
|
|
129
|
+
return await this.pxe.proveTx(cancellationTxRequest, { scopes: this.scopesFrom(from), senderForTags: from });
|
|
93
130
|
}
|
|
94
131
|
|
|
95
132
|
override async getAccountFromAddress(address: AztecAddress) {
|
|
96
133
|
let account: Account | undefined;
|
|
97
|
-
if (address.
|
|
98
|
-
const chainInfo = await this.getChainInfo();
|
|
99
|
-
account = new SignerlessAccount(chainInfo);
|
|
100
|
-
} else if (this.accountCache.has(address.toString())) {
|
|
134
|
+
if (this.accountCache.has(address.toString())) {
|
|
101
135
|
return this.accountCache.get(address.toString())!;
|
|
102
136
|
} else {
|
|
103
137
|
const accountManager = await this.createOrRetrieveAccount(address);
|
|
@@ -111,7 +145,7 @@ export class CLIWallet extends BaseWallet {
|
|
|
111
145
|
}
|
|
112
146
|
|
|
113
147
|
private async createAccount(secret: Fr, salt: Fr, contract: AccountContract): Promise<AccountManager> {
|
|
114
|
-
const accountManager = await AccountManager.create(this, secret, contract, salt);
|
|
148
|
+
const accountManager = await AccountManager.create(this, secret, contract, { salt });
|
|
115
149
|
|
|
116
150
|
const instance = accountManager.getInstance();
|
|
117
151
|
const artifact = await contract.getContractArtifact();
|
|
@@ -180,76 +214,100 @@ export class CLIWallet extends BaseWallet {
|
|
|
180
214
|
return account;
|
|
181
215
|
}
|
|
182
216
|
|
|
217
|
+
/**
|
|
218
|
+
* Creates a stub account that impersonates the given address, allowing kernelless simulations
|
|
219
|
+
* to bypass the account's authorization mechanisms via contract overrides.
|
|
220
|
+
* @param address - The address of the account to impersonate
|
|
221
|
+
* @returns The stub account, contract instance, and artifact for simulation
|
|
222
|
+
*/
|
|
183
223
|
private async getFakeAccountDataFor(address: AztecAddress) {
|
|
184
|
-
const chainInfo = await this.getChainInfo();
|
|
185
224
|
const originalAccount = await this.getAccountFromAddress(address);
|
|
186
225
|
const originalAddress = originalAccount.getCompleteAddress();
|
|
187
|
-
const
|
|
226
|
+
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
188
227
|
if (!contractInstance) {
|
|
189
228
|
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
190
229
|
}
|
|
191
|
-
const
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
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 };
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
override async simulateTx(
|
|
244
|
+
executionPayload: ExecutionPayload,
|
|
245
|
+
opts: SimulateOptions,
|
|
246
|
+
): Promise<TxSimulationResultWithAppOffset> {
|
|
247
|
+
const simulationResults = await super.simulateTx(executionPayload, opts);
|
|
248
|
+
|
|
249
|
+
if (opts.fee?.estimateGas) {
|
|
250
|
+
const feeOptions = await this.completeFeeOptions({
|
|
251
|
+
from: opts.from,
|
|
252
|
+
feePayer: executionPayload.feePayer,
|
|
253
|
+
gasSettings: opts.fee?.gasSettings,
|
|
254
|
+
});
|
|
255
|
+
const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
|
|
256
|
+
printGasEstimates(feeOptions, limits, this.userLog);
|
|
257
|
+
}
|
|
258
|
+
return simulationResults;
|
|
200
259
|
}
|
|
201
260
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
261
|
+
/**
|
|
262
|
+
* Uses a stub account for kernelless simulation, bypassing real account authorization.
|
|
263
|
+
* Uses DefaultEntrypoint directly for NO_FROM transactions.
|
|
264
|
+
*/
|
|
265
|
+
protected override async simulateViaEntrypoint(
|
|
266
|
+
executionPayload: ExecutionPayload,
|
|
267
|
+
opts: SimulateViaEntrypointOptions,
|
|
268
|
+
): Promise<TxSimulationResultWithAppOffset> {
|
|
269
|
+
const { from, feeOptions, additionalScopes, sendMessagesAs } = opts;
|
|
270
|
+
const scopes = this.scopesFrom(from, additionalScopes);
|
|
207
271
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
208
|
-
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
209
|
-
txNonce: Fr.random(),
|
|
210
|
-
cancellable: this.cancellableTransactions,
|
|
211
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
212
|
-
};
|
|
213
272
|
const finalExecutionPayload = feeExecutionPayload
|
|
214
273
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
215
274
|
: executionPayload;
|
|
275
|
+
const chainInfo = await this.getChainInfo();
|
|
216
276
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const txRequest = await fromAccount.createTxExecutionRequest(
|
|
223
|
-
finalExecutionPayload,
|
|
224
|
-
feeOptions.gasSettings,
|
|
225
|
-
executionOptions,
|
|
226
|
-
);
|
|
227
|
-
simulationResults = await this.pxe.simulateTx(
|
|
228
|
-
txRequest,
|
|
229
|
-
true /* simulatePublic */,
|
|
230
|
-
opts?.skipTxValidation,
|
|
231
|
-
opts?.skipFeeEnforcement ?? true,
|
|
232
|
-
);
|
|
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);
|
|
233
282
|
} else {
|
|
234
|
-
const { account
|
|
235
|
-
|
|
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(
|
|
236
294
|
finalExecutionPayload,
|
|
237
295
|
feeOptions.gasSettings,
|
|
296
|
+
chainInfo,
|
|
238
297
|
executionOptions,
|
|
239
298
|
);
|
|
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
299
|
}
|
|
247
300
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
301
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
302
|
+
simulatePublic: true,
|
|
303
|
+
skipFeeEnforcement: true,
|
|
304
|
+
skipTxValidation: true,
|
|
305
|
+
overrides,
|
|
306
|
+
scopes,
|
|
307
|
+
senderForTags: this.senderForTagsFrom(from, sendMessagesAs),
|
|
308
|
+
});
|
|
309
|
+
const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
|
|
310
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
253
311
|
}
|
|
254
312
|
|
|
255
313
|
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
@@ -263,4 +321,10 @@ export class CLIWallet extends BaseWallet {
|
|
|
263
321
|
getNotes(filter: NotesFilter): Promise<NoteDao[]> {
|
|
264
322
|
return this.pxe.debug.getNotes(filter);
|
|
265
323
|
}
|
|
324
|
+
|
|
325
|
+
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
326
|
+
// this is just a CLI wallet.
|
|
327
|
+
getContractArtifact(id: Fr) {
|
|
328
|
+
return this.pxe.getContractArtifact(id);
|
|
329
|
+
}
|
|
266
330
|
}
|