@aztec/cli-wallet 0.0.1-commit.5476d83 → 0.0.1-commit.5914bae
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.d.ts +1 -0
- package/dest/bin/index.js +1 -0
- 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 +45 -14
- package/dest/cmds/create_account.d.ts +7 -5
- package/dest/cmds/create_account.d.ts.map +1 -1
- package/dest/cmds/create_account.js +43 -26
- 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 +4 -3
- package/dest/cmds/deploy.d.ts.map +1 -1
- package/dest/cmds/deploy.js +56 -29
- 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 +8 -3
- package/dest/storage/wallet_db.d.ts.map +1 -1
- package/dest/storage/wallet_db.js +61 -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 +2 -2
- package/dest/utils/options/fees.d.ts.map +1 -1
- package/dest/utils/options/fees.js +13 -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 +14 -9
- package/dest/utils/wallet.d.ts.map +1 -1
- package/dest/utils/wallet.js +89 -56
- package/package.json +17 -17
- package/src/bin/index.ts +1 -0
- package/src/cmds/authorize_action.ts +1 -1
- package/src/cmds/bridge_fee_juice.ts +3 -2
- package/src/cmds/check_tx.ts +50 -19
- package/src/cmds/create_account.ts +47 -26
- package/src/cmds/deploy.ts +55 -27
- package/src/cmds/deploy_account.ts +38 -19
- package/src/cmds/get_fee_juice_balance.ts +37 -0
- package/src/cmds/index.ts +59 -6
- package/src/cmds/send.ts +32 -12
- package/src/cmds/simulate.ts +4 -7
- package/src/storage/wallet_db.ts +65 -38
- package/src/utils/constants.ts +4 -0
- package/src/utils/options/fees.ts +18 -10
- package/src/utils/options/options.ts +1 -1
- package/src/utils/profiling.ts +15 -1
- package/src/utils/wallet.ts +102 -70
package/src/storage/wallet_db.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { LogFn } from '@aztec/foundation/log';
|
|
3
3
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
4
4
|
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
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
2
2
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
3
3
|
import type { Wallet } from '@aztec/aztec.js/wallet';
|
|
4
|
-
import { Fr } from '@aztec/foundation/
|
|
4
|
+
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';
|
|
@@ -11,7 +11,7 @@ import type { FeeOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
|
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,8 @@ export class CLIFeeArgs {
|
|
|
250
257
|
) {}
|
|
251
258
|
|
|
252
259
|
async toUserFeeOptions(node: AztecNode, wallet: Wallet, from: AztecAddress): Promise<ParsedFeeOptions> {
|
|
253
|
-
const maxFeesPerGas = (await node.
|
|
254
|
-
const gasSettings = GasSettings.
|
|
260
|
+
const maxFeesPerGas = (await node.getCurrentMinFees()).mul(1 + MIN_FEE_PADDING);
|
|
261
|
+
const gasSettings = GasSettings.fallback({ ...this.gasSettings, maxFeesPerGas });
|
|
255
262
|
const paymentMethod = await this.paymentMethod(wallet, from, gasSettings);
|
|
256
263
|
return {
|
|
257
264
|
paymentMethod,
|
|
@@ -260,9 +267,10 @@ export class CLIFeeArgs {
|
|
|
260
267
|
}
|
|
261
268
|
|
|
262
269
|
static parse(args: RawCliFeeArgs, log: LogFn, db?: WalletDB): CLIFeeArgs {
|
|
270
|
+
const estimateOnly = !!args.estimateGasOnly;
|
|
263
271
|
return new CLIFeeArgs(
|
|
264
|
-
|
|
265
|
-
parsePaymentMethod(args.payment ?? 'method=fee_juice', log, db),
|
|
272
|
+
estimateOnly,
|
|
273
|
+
parsePaymentMethod(args.payment ?? 'method=fee_juice', log, db, estimateOnly),
|
|
266
274
|
parseGasSettings(args),
|
|
267
275
|
);
|
|
268
276
|
}
|
|
@@ -288,7 +296,7 @@ function formatGasEstimate(estimate: Pick<GasSettings, 'gasLimits' | 'teardownGa
|
|
|
288
296
|
}
|
|
289
297
|
|
|
290
298
|
function getEstimatedCost(estimate: Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>, maxFeesPerGas: GasFees) {
|
|
291
|
-
return GasSettings.
|
|
299
|
+
return GasSettings.fallback({ ...estimate, maxFeesPerGas })
|
|
292
300
|
.getFeeLimit()
|
|
293
301
|
.toBigInt();
|
|
294
302
|
}
|
|
@@ -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,8 +1,9 @@
|
|
|
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 { type Account, type AccountContract, NO_FROM } from '@aztec/aztec.js/account';
|
|
6
7
|
import {
|
|
7
8
|
type InteractionFeeOptions,
|
|
8
9
|
getContractInstanceFromInstantiationParams,
|
|
@@ -10,29 +11,27 @@ import {
|
|
|
10
11
|
} from '@aztec/aztec.js/contracts';
|
|
11
12
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
12
13
|
import { AccountManager, type Aliased, type SimulateOptions } from '@aztec/aztec.js/wallet';
|
|
14
|
+
import { TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
13
15
|
import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
14
|
-
import {
|
|
16
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
17
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
15
18
|
import type { LogFn } from '@aztec/foundation/log';
|
|
19
|
+
import type { NotesFilter } from '@aztec/pxe/client/lazy';
|
|
16
20
|
import type { PXEConfig } from '@aztec/pxe/config';
|
|
17
21
|
import type { PXE } from '@aztec/pxe/server';
|
|
18
22
|
import { createPXE, getPXEConfig } from '@aztec/pxe/server';
|
|
19
23
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
20
24
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
21
25
|
import { NoteDao } from '@aztec/stdlib/note';
|
|
22
|
-
import type {
|
|
23
|
-
import type { TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
26
|
+
import type { SimulationOverrides, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx';
|
|
24
27
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
25
|
-
import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
|
|
28
|
+
import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
26
29
|
|
|
27
30
|
import type { WalletDB } from '../storage/wallet_db.js';
|
|
31
|
+
import type { AccountType } from './constants.js';
|
|
28
32
|
import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
|
|
29
33
|
import { printGasEstimates } from './options/fees.js';
|
|
30
34
|
|
|
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
35
|
export class CLIWallet extends BaseWallet {
|
|
37
36
|
private accountCache = new Map<string, Account>();
|
|
38
37
|
|
|
@@ -59,7 +58,12 @@ export class CLIWallet extends BaseWallet {
|
|
|
59
58
|
|
|
60
59
|
override async getAccounts(): Promise<Aliased<AztecAddress>[]> {
|
|
61
60
|
const accounts = (await this.db?.listAliases('accounts')) ?? [];
|
|
62
|
-
return Promise.resolve(
|
|
61
|
+
return Promise.resolve(
|
|
62
|
+
accounts.map(({ key, value }) => {
|
|
63
|
+
const alias = key.includes(':') ? key.slice(key.indexOf(':') + 1) : key;
|
|
64
|
+
return { alias, item: AztecAddress.fromString(value) };
|
|
65
|
+
}),
|
|
66
|
+
);
|
|
63
67
|
}
|
|
64
68
|
|
|
65
69
|
private async createCancellationTxExecutionRequest(
|
|
@@ -68,17 +72,24 @@ export class CLIWallet extends BaseWallet {
|
|
|
68
72
|
increasedFee: InteractionFeeOptions,
|
|
69
73
|
) {
|
|
70
74
|
const executionPayload = ExecutionPayload.empty();
|
|
71
|
-
const feeOptions = await this.completeFeeOptions(
|
|
75
|
+
const feeOptions = await this.completeFeeOptions({
|
|
76
|
+
from,
|
|
77
|
+
feePayer: executionPayload.feePayer,
|
|
78
|
+
gasSettings: increasedFee.gasSettings,
|
|
79
|
+
});
|
|
72
80
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
73
81
|
const fromAccount = await this.getAccountFromAddress(from);
|
|
82
|
+
const chainInfo = await this.getChainInfo();
|
|
74
83
|
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
75
84
|
txNonce,
|
|
76
85
|
cancellable: this.cancellableTransactions,
|
|
77
|
-
|
|
86
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
87
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
78
88
|
};
|
|
79
89
|
return await fromAccount.createTxExecutionRequest(
|
|
80
90
|
feeExecutionPayload ?? executionPayload,
|
|
81
91
|
feeOptions.gasSettings,
|
|
92
|
+
chainInfo,
|
|
82
93
|
executionOptions,
|
|
83
94
|
);
|
|
84
95
|
}
|
|
@@ -89,15 +100,12 @@ export class CLIWallet extends BaseWallet {
|
|
|
89
100
|
increasedFee: InteractionFeeOptions,
|
|
90
101
|
): Promise<TxProvingResult> {
|
|
91
102
|
const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
|
|
92
|
-
return await this.pxe.proveTx(cancellationTxRequest);
|
|
103
|
+
return await this.pxe.proveTx(cancellationTxRequest, this.scopesFrom(from));
|
|
93
104
|
}
|
|
94
105
|
|
|
95
106
|
override async getAccountFromAddress(address: AztecAddress) {
|
|
96
107
|
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())) {
|
|
108
|
+
if (this.accountCache.has(address.toString())) {
|
|
101
109
|
return this.accountCache.get(address.toString())!;
|
|
102
110
|
} else {
|
|
103
111
|
const accountManager = await this.createOrRetrieveAccount(address);
|
|
@@ -180,76 +188,94 @@ export class CLIWallet extends BaseWallet {
|
|
|
180
188
|
return account;
|
|
181
189
|
}
|
|
182
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Creates a stub account that impersonates the given address, allowing kernelless simulations
|
|
193
|
+
* to bypass the account's authorization mechanisms via contract overrides.
|
|
194
|
+
* @param address - The address of the account to impersonate
|
|
195
|
+
* @returns The stub account, contract instance, and artifact for simulation
|
|
196
|
+
*/
|
|
183
197
|
private async getFakeAccountDataFor(address: AztecAddress) {
|
|
184
|
-
const chainInfo = await this.getChainInfo();
|
|
185
198
|
const originalAccount = await this.getAccountFromAddress(address);
|
|
186
199
|
const originalAddress = originalAccount.getCompleteAddress();
|
|
187
|
-
const
|
|
200
|
+
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
188
201
|
if (!contractInstance) {
|
|
189
202
|
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
190
203
|
}
|
|
191
|
-
const
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
204
|
+
const { type } = await this.db!.retrieveAccount(address);
|
|
205
|
+
const isSchnorr = type === 'schnorr';
|
|
206
|
+
const artifact = isSchnorr ? StubSchnorrAccountContractArtifact : StubEcdsaAccountContractArtifact;
|
|
207
|
+
const stubAccount = isSchnorr ? createStubSchnorrAccount(originalAddress) : createStubEcdsaAccount(originalAddress);
|
|
208
|
+
const instance = await getContractInstanceFromInstantiationParams(artifact, { salt: Fr.random() });
|
|
209
|
+
return { account: stubAccount, instance, artifact };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
override async simulateTx(
|
|
213
|
+
executionPayload: ExecutionPayload,
|
|
214
|
+
opts: SimulateOptions,
|
|
215
|
+
): Promise<TxSimulationResultWithAppOffset> {
|
|
216
|
+
const simulationResults = await super.simulateTx(executionPayload, opts);
|
|
217
|
+
|
|
218
|
+
if (opts.fee?.estimateGas) {
|
|
219
|
+
const feeOptions = await this.completeFeeOptions({
|
|
220
|
+
from: opts.from,
|
|
221
|
+
feePayer: executionPayload.feePayer,
|
|
222
|
+
gasSettings: opts.fee?.gasSettings,
|
|
223
|
+
});
|
|
224
|
+
const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
|
|
225
|
+
printGasEstimates(feeOptions, limits, this.userLog);
|
|
226
|
+
}
|
|
227
|
+
return simulationResults;
|
|
200
228
|
}
|
|
201
229
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
230
|
+
/**
|
|
231
|
+
* Uses a stub account for kernelless simulation, bypassing real account authorization.
|
|
232
|
+
* Uses DefaultEntrypoint directly for NO_FROM transactions.
|
|
233
|
+
*/
|
|
234
|
+
protected override async simulateViaEntrypoint(
|
|
235
|
+
executionPayload: ExecutionPayload,
|
|
236
|
+
opts: SimulateViaEntrypointOptions,
|
|
237
|
+
): Promise<TxSimulationResultWithAppOffset> {
|
|
238
|
+
const { from, feeOptions, additionalScopes } = opts;
|
|
239
|
+
const scopes = this.scopesFrom(from, additionalScopes);
|
|
207
240
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
208
|
-
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
209
|
-
txNonce: Fr.random(),
|
|
210
|
-
cancellable: this.cancellableTransactions,
|
|
211
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
212
|
-
};
|
|
213
241
|
const finalExecutionPayload = feeExecutionPayload
|
|
214
242
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
215
243
|
: executionPayload;
|
|
244
|
+
const chainInfo = await this.getChainInfo();
|
|
216
245
|
|
|
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
|
-
);
|
|
246
|
+
let overrides: SimulationOverrides | undefined;
|
|
247
|
+
let txRequest: TxExecutionRequest;
|
|
248
|
+
if (from === NO_FROM) {
|
|
249
|
+
const entrypoint = new DefaultEntrypoint();
|
|
250
|
+
txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
233
251
|
} else {
|
|
234
|
-
const { account
|
|
235
|
-
|
|
252
|
+
const { account, instance, artifact } = await this.getFakeAccountDataFor(from);
|
|
253
|
+
overrides = {
|
|
254
|
+
contracts: { [from.toString()]: { instance, artifact } },
|
|
255
|
+
};
|
|
256
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
257
|
+
txNonce: Fr.random(),
|
|
258
|
+
cancellable: this.cancellableTransactions,
|
|
259
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
260
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
261
|
+
};
|
|
262
|
+
txRequest = await account.createTxExecutionRequest(
|
|
236
263
|
finalExecutionPayload,
|
|
237
264
|
feeOptions.gasSettings,
|
|
265
|
+
chainInfo,
|
|
238
266
|
executionOptions,
|
|
239
267
|
);
|
|
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
268
|
}
|
|
247
269
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
270
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
271
|
+
simulatePublic: true,
|
|
272
|
+
skipFeeEnforcement: true,
|
|
273
|
+
skipTxValidation: true,
|
|
274
|
+
overrides,
|
|
275
|
+
scopes,
|
|
276
|
+
});
|
|
277
|
+
const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
|
|
278
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
253
279
|
}
|
|
254
280
|
|
|
255
281
|
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
@@ -261,6 +287,12 @@ export class CLIWallet extends BaseWallet {
|
|
|
261
287
|
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
262
288
|
// this is just a CLI wallet.
|
|
263
289
|
getNotes(filter: NotesFilter): Promise<NoteDao[]> {
|
|
264
|
-
return this.pxe.getNotes(filter);
|
|
290
|
+
return this.pxe.debug.getNotes(filter);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
294
|
+
// this is just a CLI wallet.
|
|
295
|
+
getContractArtifact(id: Fr) {
|
|
296
|
+
return this.pxe.getContractArtifact(id);
|
|
265
297
|
}
|
|
266
298
|
}
|