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