@aztec/cli-wallet 0.0.1-commit.b655e406 → 0.0.1-commit.c0b82b2
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/README.md +2 -2
- package/dest/bin/index.d.ts +2 -1
- package/dest/bin/index.js +20 -10
- 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 +5 -3
- 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.js +10 -7
- package/dest/cmds/create_account.d.ts +4 -3
- package/dest/cmds/create_account.d.ts.map +1 -1
- package/dest/cmds/create_account.js +25 -19
- package/dest/cmds/create_authwit.d.ts +1 -1
- package/dest/cmds/create_authwit.js +1 -1
- package/dest/cmds/deploy.d.ts +1 -1
- package/dest/cmds/deploy.d.ts.map +1 -1
- package/dest/cmds/deploy.js +46 -23
- package/dest/cmds/deploy_account.d.ts +1 -1
- package/dest/cmds/deploy_account.d.ts.map +1 -1
- package/dest/cmds/deploy_account.js +24 -18
- package/dest/cmds/import_test_accounts.d.ts +1 -1
- package/dest/cmds/index.d.ts +1 -1
- package/dest/cmds/index.js +3 -3
- package/dest/cmds/profile.d.ts +1 -1
- package/dest/cmds/profile.js +1 -1
- package/dest/cmds/register_contract.d.ts +1 -1
- package/dest/cmds/register_sender.d.ts +1 -1
- package/dest/cmds/send.d.ts +2 -2
- package/dest/cmds/send.d.ts.map +1 -1
- package/dest/cmds/send.js +29 -17
- package/dest/cmds/simulate.d.ts +1 -1
- package/dest/cmds/simulate.d.ts.map +1 -1
- package/dest/cmds/simulate.js +4 -4
- package/dest/storage/wallet_db.d.ts +5 -5
- package/dest/storage/wallet_db.d.ts.map +1 -1
- package/dest/storage/wallet_db.js +47 -32
- package/dest/utils/authorizations.d.ts +1 -1
- package/dest/utils/cli_wallet_and_node_wrapper.d.ts +1 -1
- package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -1
- 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/ecdsa.d.ts +1 -1
- 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 +3 -3
- package/dest/utils/options/index.d.ts +1 -1
- package/dest/utils/options/options.d.ts +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 +15 -10
- package/dest/utils/wallet.d.ts.map +1 -1
- package/dest/utils/wallet.js +61 -46
- package/package.json +17 -14
- package/src/bin/index.ts +18 -12
- package/src/cmds/authorize_action.ts +2 -2
- package/src/cmds/bridge_fee_juice.ts +3 -2
- package/src/cmds/check_tx.ts +10 -12
- package/src/cmds/create_account.ts +26 -19
- package/src/cmds/create_authwit.ts +1 -1
- package/src/cmds/deploy.ts +41 -22
- package/src/cmds/deploy_account.ts +23 -17
- package/src/cmds/index.ts +4 -4
- package/src/cmds/profile.ts +1 -1
- package/src/cmds/send.ts +23 -11
- package/src/cmds/simulate.ts +4 -7
- package/src/storage/wallet_db.ts +51 -38
- package/src/utils/cli_wallet_and_node_wrapper.ts +1 -1
- package/src/utils/constants.ts +4 -0
- package/src/utils/options/fees.ts +5 -4
- package/src/utils/options/options.ts +1 -1
- package/src/utils/profiling.ts +15 -1
- package/src/utils/wallet.ts +87 -61
package/src/cmds/index.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
parseFieldFromHexString,
|
|
11
11
|
parsePublicKey,
|
|
12
12
|
} from '@aztec/cli/utils';
|
|
13
|
-
import { randomBytes } from '@aztec/foundation/crypto';
|
|
13
|
+
import { randomBytes } from '@aztec/foundation/crypto/random';
|
|
14
14
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
15
15
|
|
|
16
16
|
import { type Command, Option } from 'commander';
|
|
@@ -18,6 +18,7 @@ import inquirer from 'inquirer';
|
|
|
18
18
|
|
|
19
19
|
import type { WalletDB } from '../storage/wallet_db.js';
|
|
20
20
|
import type { CliWalletAndNodeWrapper } from '../utils/cli_wallet_and_node_wrapper.js';
|
|
21
|
+
import type { AccountType } from '../utils/constants.js';
|
|
21
22
|
import {
|
|
22
23
|
ARTIFACT_DESCRIPTION,
|
|
23
24
|
CLIFeeArgs,
|
|
@@ -38,7 +39,6 @@ import {
|
|
|
38
39
|
createVerboseOption,
|
|
39
40
|
integerArgParser,
|
|
40
41
|
} from '../utils/options/index.js';
|
|
41
|
-
import type { AccountType } from '../utils/wallet.js';
|
|
42
42
|
|
|
43
43
|
// TODO: This function is only used in 1 place so we could just inline this
|
|
44
44
|
export function injectCommands(
|
|
@@ -63,7 +63,7 @@ export function injectCommands(
|
|
|
63
63
|
const createAccountCommand = program
|
|
64
64
|
.command('create-account')
|
|
65
65
|
.description(
|
|
66
|
-
'Creates an aztec account that can be used for sending transactions. Registers the account on the PXE and deploys an account contract. Uses a Schnorr
|
|
66
|
+
'Creates an aztec account that can be used for sending transactions. Registers the account on the PXE and deploys an account contract. Uses a Schnorr account which uses an immutable key for authentication.',
|
|
67
67
|
)
|
|
68
68
|
.summary('Creates an aztec account that can be used for sending transactions.')
|
|
69
69
|
.addOption(createAccountOption('Alias or address of the account performing the deployment', !db, db))
|
|
@@ -346,7 +346,7 @@ export function injectCommands(
|
|
|
346
346
|
log,
|
|
347
347
|
);
|
|
348
348
|
if (db && sentTx) {
|
|
349
|
-
const txAlias = alias ? alias : `${functionName}-${randomBytes(16).toString()}`;
|
|
349
|
+
const txAlias = alias ? alias : `${functionName}-${randomBytes(16).toString('hex')}`;
|
|
350
350
|
await db.storeTx(sentTx, log, txAlias);
|
|
351
351
|
}
|
|
352
352
|
});
|
package/src/cmds/profile.ts
CHANGED
|
@@ -28,7 +28,7 @@ export async function profile(
|
|
|
28
28
|
) {
|
|
29
29
|
const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
|
|
30
30
|
|
|
31
|
-
const contract =
|
|
31
|
+
const contract = Contract.at(contractAddress, contractArtifact, wallet);
|
|
32
32
|
const call = contract.methods[functionName](...functionArgs);
|
|
33
33
|
|
|
34
34
|
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, from);
|
package/src/cmds/send.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
2
|
import { AuthWitness } from '@aztec/aztec.js/authorization';
|
|
3
|
-
import { Contract, type SendInteractionOptions } from '@aztec/aztec.js/contracts';
|
|
3
|
+
import { Contract, NO_WAIT, type SendInteractionOptions } from '@aztec/aztec.js/contracts';
|
|
4
4
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
5
5
|
import { prepTx } from '@aztec/cli/utils';
|
|
6
6
|
import type { LogFn } from '@aztec/foundation/log';
|
|
@@ -27,7 +27,7 @@ export async function send(
|
|
|
27
27
|
) {
|
|
28
28
|
const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
|
|
29
29
|
|
|
30
|
-
const contract =
|
|
30
|
+
const contract = Contract.at(contractAddress, contractArtifact, wallet);
|
|
31
31
|
const call = contract.methods[functionName](...functionArgs);
|
|
32
32
|
|
|
33
33
|
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, from);
|
|
@@ -46,31 +46,43 @@ export async function send(
|
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
const tx = call.send({ ...sendOptions, fee: { ...sendOptions.fee, gasSettings: estimatedGas } });
|
|
50
49
|
if (verbose) {
|
|
51
50
|
printProfileResult(stats!, log);
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
const txHash = await tx.getTxHash();
|
|
55
|
-
log(`\nTransaction hash: ${txHash.toString()}`);
|
|
56
53
|
if (wait) {
|
|
57
54
|
try {
|
|
58
|
-
await
|
|
55
|
+
const receipt = await call.send({
|
|
56
|
+
...sendOptions,
|
|
57
|
+
fee: { ...sendOptions.fee, gasSettings: estimatedGas },
|
|
58
|
+
wait: { timeout: DEFAULT_TX_TIMEOUT_S },
|
|
59
|
+
});
|
|
59
60
|
|
|
61
|
+
const txHash = receipt.txHash;
|
|
62
|
+
log(`\nTransaction hash: ${txHash.toString()}`);
|
|
60
63
|
log('Transaction has been mined');
|
|
61
|
-
|
|
62
|
-
const receipt = await tx.getReceipt();
|
|
63
64
|
log(` Tx fee: ${receipt.transactionFee}`);
|
|
64
65
|
log(` Status: ${receipt.status}`);
|
|
65
66
|
log(` Block number: ${receipt.blockNumber}`);
|
|
66
67
|
log(` Block hash: ${receipt.blockHash?.toString()}`);
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
txHash,
|
|
71
|
+
};
|
|
67
72
|
} catch (err: any) {
|
|
68
73
|
log(`Transaction failed\n ${err.message}`);
|
|
74
|
+
throw err;
|
|
69
75
|
}
|
|
70
76
|
} else {
|
|
77
|
+
const txHash = await call.send({
|
|
78
|
+
...sendOptions,
|
|
79
|
+
fee: { ...sendOptions.fee, gasSettings: estimatedGas },
|
|
80
|
+
wait: NO_WAIT,
|
|
81
|
+
});
|
|
82
|
+
log(`\nTransaction hash: ${txHash.toString()}`);
|
|
71
83
|
log('Transaction pending. Check status with check-tx');
|
|
84
|
+
return {
|
|
85
|
+
txHash,
|
|
86
|
+
};
|
|
72
87
|
}
|
|
73
|
-
return {
|
|
74
|
-
txHash,
|
|
75
|
-
};
|
|
76
88
|
}
|
package/src/cmds/simulate.ts
CHANGED
|
@@ -27,7 +27,7 @@ export async function simulate(
|
|
|
27
27
|
) {
|
|
28
28
|
const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
|
|
29
29
|
|
|
30
|
-
const contract =
|
|
30
|
+
const contract = Contract.at(contractAddress, contractArtifact, wallet);
|
|
31
31
|
const call = contract.methods[functionName](...functionArgs);
|
|
32
32
|
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, from);
|
|
33
33
|
const simulationResult = await call.simulate({
|
|
@@ -41,14 +41,11 @@ export async function simulate(
|
|
|
41
41
|
simulationResult.offchainEffects!,
|
|
42
42
|
async (address: AztecAddress) => {
|
|
43
43
|
const metadata = await wallet.getContractMetadata(address);
|
|
44
|
-
if (!metadata.
|
|
44
|
+
if (!metadata.instance) {
|
|
45
45
|
return undefined;
|
|
46
46
|
}
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
true,
|
|
50
|
-
);
|
|
51
|
-
return classMetadata.artifact;
|
|
47
|
+
const artifact = await wallet.getContractArtifact(metadata.instance.currentContractClassId);
|
|
48
|
+
return artifact;
|
|
52
49
|
},
|
|
53
50
|
log,
|
|
54
51
|
);
|
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) {
|
|
@@ -76,19 +81,24 @@ export class WalletDB {
|
|
|
76
81
|
}: { type: AccountType; secretKey: Fr; salt: Fr; alias: string | undefined; publicKey: string | undefined },
|
|
77
82
|
log: LogFn,
|
|
78
83
|
) {
|
|
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());
|
|
84
|
+
let publicSigningKey: Buffer | undefined;
|
|
85
85
|
if (type === 'ecdsasecp256r1ssh' && publicKey) {
|
|
86
|
-
|
|
87
|
-
await this.storeAccountMetadata(address, 'publicSigningKey', publicSigningKey);
|
|
86
|
+
publicSigningKey = extractECDSAPublicKeyFromBase64String(publicKey);
|
|
88
87
|
}
|
|
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
88
|
|
|
89
|
+
await this.#store.transactionAsync(async () => {
|
|
90
|
+
if (alias) {
|
|
91
|
+
await this.#aliases.set(`accounts:${alias}`, Buffer.from(address.toString()));
|
|
92
|
+
}
|
|
93
|
+
await this.#accounts.set(`${address.toString()}:type`, Buffer.from(type));
|
|
94
|
+
await this.#accounts.set(`${address.toString()}:sk`, secretKey.toBuffer());
|
|
95
|
+
await this.#accounts.set(`${address.toString()}:salt`, salt.toBuffer());
|
|
96
|
+
if (publicSigningKey) {
|
|
97
|
+
await this.#accounts.set(`${address.toString()}:publicSigningKey`, publicSigningKey);
|
|
98
|
+
}
|
|
99
|
+
await this.#aliases.set('accounts:last', Buffer.from(address.toString()));
|
|
100
|
+
});
|
|
101
|
+
log(`Account stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
92
102
|
await this.refreshAliasCache();
|
|
93
103
|
}
|
|
94
104
|
|
|
@@ -100,35 +110,38 @@ export class WalletDB {
|
|
|
100
110
|
}
|
|
101
111
|
|
|
102
112
|
async storeContract(address: AztecAddress, artifactPath: string, log: LogFn, alias?: string) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
113
|
+
await this.#store.transactionAsync(async () => {
|
|
114
|
+
if (alias) {
|
|
115
|
+
await this.#aliases.set(`contracts:${alias}`, Buffer.from(address.toString()));
|
|
116
|
+
await this.#aliases.set(`artifacts:${alias}`, Buffer.from(artifactPath));
|
|
117
|
+
}
|
|
118
|
+
await this.#aliases.set(`contracts:last`, Buffer.from(address.toString()));
|
|
119
|
+
await this.#aliases.set(`artifacts:last`, Buffer.from(artifactPath));
|
|
120
|
+
await this.#aliases.set(`artifacts:${address.toString()}`, Buffer.from(artifactPath));
|
|
121
|
+
});
|
|
110
122
|
log(`Contract stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
111
|
-
|
|
112
123
|
await this.refreshAliasCache();
|
|
113
124
|
}
|
|
114
125
|
|
|
115
126
|
async storeAuthwitness(authWit: AuthWitness, log: LogFn, alias?: string) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
127
|
+
await this.#store.transactionAsync(async () => {
|
|
128
|
+
if (alias) {
|
|
129
|
+
await this.#aliases.set(`authwits:${alias}`, Buffer.from(authWit.toString()));
|
|
130
|
+
}
|
|
131
|
+
await this.#aliases.set(`authwits:last`, Buffer.from(authWit.toString()));
|
|
132
|
+
});
|
|
120
133
|
log(`Authorization witness stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
121
|
-
|
|
122
134
|
await this.refreshAliasCache();
|
|
123
135
|
}
|
|
124
136
|
|
|
125
137
|
async storeTx({ txHash }: { txHash: TxHash }, log: LogFn, alias?: string) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
138
|
+
await this.#store.transactionAsync(async () => {
|
|
139
|
+
if (alias) {
|
|
140
|
+
await this.#aliases.set(`transactions:${alias}`, Buffer.from(txHash.toString()));
|
|
141
|
+
}
|
|
142
|
+
await this.#aliases.set(`transactions:last`, Buffer.from(txHash.toString()));
|
|
143
|
+
});
|
|
130
144
|
log(`Transaction hash stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
131
|
-
|
|
132
145
|
await this.refreshAliasCache();
|
|
133
146
|
}
|
|
134
147
|
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
2
2
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
3
|
-
import type {
|
|
4
|
-
import { Fr } from '@aztec/foundation/
|
|
3
|
+
import type { Wallet } from '@aztec/aztec.js/wallet';
|
|
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';
|
|
8
8
|
import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
9
|
+
import type { FeeOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
9
10
|
|
|
10
11
|
import { Option } from 'commander';
|
|
11
12
|
|
|
12
13
|
import type { WalletDB } from '../../storage/wallet_db.js';
|
|
13
|
-
import {
|
|
14
|
+
import { MIN_FEE_PADDING } from '../constants.js';
|
|
14
15
|
import { aliasedAddressParser } from './options.js';
|
|
15
16
|
|
|
16
17
|
export type RawCliFeeArgs = {
|
|
@@ -249,7 +250,7 @@ export class CLIFeeArgs {
|
|
|
249
250
|
) {}
|
|
250
251
|
|
|
251
252
|
async toUserFeeOptions(node: AztecNode, wallet: Wallet, from: AztecAddress): Promise<ParsedFeeOptions> {
|
|
252
|
-
const maxFeesPerGas = (await node.
|
|
253
|
+
const maxFeesPerGas = (await node.getCurrentMinFees()).mul(1 + MIN_FEE_PADDING);
|
|
253
254
|
const gasSettings = GasSettings.default({ ...this.gasSettings, maxFeesPerGas });
|
|
254
255
|
const paymentMethod = await this.paymentMethod(wallet, from, gasSettings);
|
|
255
256
|
return {
|
|
@@ -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
|
@@ -9,29 +9,26 @@ import {
|
|
|
9
9
|
getGasLimits,
|
|
10
10
|
} from '@aztec/aztec.js/contracts';
|
|
11
11
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
12
|
-
import {
|
|
13
|
-
import { AccountManager, type Aliased, BaseWallet, type SimulateOptions } from '@aztec/aztec.js/wallet';
|
|
12
|
+
import { AccountManager, type Aliased, type SimulateOptions } from '@aztec/aztec.js/wallet';
|
|
14
13
|
import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
15
|
-
import {
|
|
16
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
14
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
17
15
|
import type { LogFn } from '@aztec/foundation/log';
|
|
16
|
+
import type { AccessScopes, NotesFilter } from '@aztec/pxe/client/lazy';
|
|
18
17
|
import type { PXEConfig } from '@aztec/pxe/config';
|
|
19
18
|
import type { PXE } from '@aztec/pxe/server';
|
|
20
19
|
import { createPXE, getPXEConfig } from '@aztec/pxe/server';
|
|
21
20
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
22
21
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
23
|
-
import
|
|
22
|
+
import { NoteDao } from '@aztec/stdlib/note';
|
|
24
23
|
import type { TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
24
|
+
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
25
|
+
import { BaseWallet, type FeeOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
25
26
|
|
|
26
27
|
import type { WalletDB } from '../storage/wallet_db.js';
|
|
28
|
+
import type { AccountType } from './constants.js';
|
|
27
29
|
import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
|
|
28
30
|
import { printGasEstimates } from './options/fees.js';
|
|
29
31
|
|
|
30
|
-
export const AccountTypes = ['schnorr', 'ecdsasecp256r1', 'ecdsasecp256r1ssh', 'ecdsasecp256k1'] as const;
|
|
31
|
-
export type AccountType = (typeof AccountTypes)[number];
|
|
32
|
-
|
|
33
|
-
export const BASE_FEE_PADDING = 0.5;
|
|
34
|
-
|
|
35
32
|
export class CLIWallet extends BaseWallet {
|
|
36
33
|
private accountCache = new Map<string, Account>();
|
|
37
34
|
|
|
@@ -66,17 +63,20 @@ export class CLIWallet extends BaseWallet {
|
|
|
66
63
|
txNonce: Fr,
|
|
67
64
|
increasedFee: InteractionFeeOptions,
|
|
68
65
|
) {
|
|
69
|
-
const
|
|
66
|
+
const executionPayload = ExecutionPayload.empty();
|
|
67
|
+
const feeOptions = await this.completeFeeOptions(from, executionPayload.feePayer, increasedFee.gasSettings);
|
|
70
68
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
71
69
|
const fromAccount = await this.getAccountFromAddress(from);
|
|
70
|
+
const chainInfo = await this.getChainInfo();
|
|
72
71
|
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
73
72
|
txNonce,
|
|
74
73
|
cancellable: this.cancellableTransactions,
|
|
75
74
|
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
76
75
|
};
|
|
77
76
|
return await fromAccount.createTxExecutionRequest(
|
|
78
|
-
feeExecutionPayload ??
|
|
77
|
+
feeExecutionPayload ?? executionPayload,
|
|
79
78
|
feeOptions.gasSettings,
|
|
79
|
+
chainInfo,
|
|
80
80
|
executionOptions,
|
|
81
81
|
);
|
|
82
82
|
}
|
|
@@ -87,14 +87,13 @@ export class CLIWallet extends BaseWallet {
|
|
|
87
87
|
increasedFee: InteractionFeeOptions,
|
|
88
88
|
): Promise<TxProvingResult> {
|
|
89
89
|
const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
|
|
90
|
-
return await this.pxe.proveTx(cancellationTxRequest);
|
|
90
|
+
return await this.pxe.proveTx(cancellationTxRequest, this.scopesFrom(from));
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
override async getAccountFromAddress(address: AztecAddress) {
|
|
94
94
|
let account: Account | undefined;
|
|
95
95
|
if (address.equals(AztecAddress.ZERO)) {
|
|
96
|
-
|
|
97
|
-
account = new SignerlessAccount(chainInfo);
|
|
96
|
+
account = new SignerlessAccount();
|
|
98
97
|
} else if (this.accountCache.has(address.toString())) {
|
|
99
98
|
return this.accountCache.get(address.toString())!;
|
|
100
99
|
} else {
|
|
@@ -178,15 +177,26 @@ export class CLIWallet extends BaseWallet {
|
|
|
178
177
|
return account;
|
|
179
178
|
}
|
|
180
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Creates a stub account that impersonates the given address, allowing kernelless simulations
|
|
182
|
+
* to bypass the account's authorization mechanisms via contract overrides.
|
|
183
|
+
* @param address - The address of the account to impersonate
|
|
184
|
+
* @returns The stub account, contract instance, and artifact for simulation
|
|
185
|
+
*/
|
|
181
186
|
private async getFakeAccountDataFor(address: AztecAddress) {
|
|
182
|
-
const chainInfo = await this.getChainInfo();
|
|
183
187
|
const originalAccount = await this.getAccountFromAddress(address);
|
|
184
|
-
|
|
185
|
-
|
|
188
|
+
// Account contracts can only be overridden if they have an associated address
|
|
189
|
+
// Overwriting SignerlessAccount is not supported, and does not really make sense
|
|
190
|
+
// since it has no authorization mechanism.
|
|
191
|
+
if (originalAccount instanceof SignerlessAccount) {
|
|
192
|
+
throw new Error(`Cannot create fake account data for SignerlessAccount at address: ${address}`);
|
|
193
|
+
}
|
|
194
|
+
const originalAddress = (originalAccount as Account).getCompleteAddress();
|
|
195
|
+
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
186
196
|
if (!contractInstance) {
|
|
187
197
|
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
188
198
|
}
|
|
189
|
-
const stubAccount = createStubAccount(originalAddress
|
|
199
|
+
const stubAccount = createStubAccount(originalAddress);
|
|
190
200
|
const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
|
|
191
201
|
salt: Fr.random(),
|
|
192
202
|
});
|
|
@@ -198,10 +208,39 @@ export class CLIWallet extends BaseWallet {
|
|
|
198
208
|
}
|
|
199
209
|
|
|
200
210
|
override async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
211
|
+
const simulationResults = await super.simulateTx(executionPayload, opts);
|
|
212
|
+
|
|
213
|
+
if (opts.fee?.estimateGas) {
|
|
214
|
+
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
215
|
+
const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
|
|
216
|
+
printGasEstimates(feeOptions, limits, this.userLog);
|
|
217
|
+
}
|
|
218
|
+
return simulationResults;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Uses a stub account for kernelless simulation, bypassing real account authorization.
|
|
223
|
+
* Falls through to the standard entrypoint path for SignerlessAccount (ZERO address).
|
|
224
|
+
*/
|
|
225
|
+
protected override async simulateViaEntrypoint(
|
|
226
|
+
executionPayload: ExecutionPayload,
|
|
227
|
+
from: AztecAddress,
|
|
228
|
+
feeOptions: FeeOptions,
|
|
229
|
+
scopes: AccessScopes,
|
|
230
|
+
skipTxValidation?: boolean,
|
|
231
|
+
skipFeeEnforcement?: boolean,
|
|
232
|
+
): Promise<TxSimulationResult> {
|
|
233
|
+
if (from.equals(AztecAddress.ZERO)) {
|
|
234
|
+
return super.simulateViaEntrypoint(
|
|
235
|
+
executionPayload,
|
|
236
|
+
from,
|
|
237
|
+
feeOptions,
|
|
238
|
+
scopes,
|
|
239
|
+
skipTxValidation,
|
|
240
|
+
skipFeeEnforcement,
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
205
244
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
206
245
|
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
207
246
|
txNonce: Fr.random(),
|
|
@@ -212,42 +251,23 @@ export class CLIWallet extends BaseWallet {
|
|
|
212
251
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
213
252
|
: executionPayload;
|
|
214
253
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(opts.from);
|
|
233
|
-
const txRequest = await fromAccount.createTxExecutionRequest(
|
|
234
|
-
finalExecutionPayload,
|
|
235
|
-
feeOptions.gasSettings,
|
|
236
|
-
executionOptions,
|
|
237
|
-
);
|
|
238
|
-
const contractOverrides = {
|
|
239
|
-
[opts.from.toString()]: { instance, artifact },
|
|
240
|
-
};
|
|
241
|
-
simulationResults = await this.pxe.simulateTx(txRequest, true /* simulatePublic */, true, true, {
|
|
242
|
-
contracts: contractOverrides,
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (opts.fee?.estimateGas) {
|
|
247
|
-
const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
|
|
248
|
-
printGasEstimates(feeOptions, limits, this.userLog);
|
|
249
|
-
}
|
|
250
|
-
return simulationResults;
|
|
254
|
+
const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(from);
|
|
255
|
+
const chainInfo = await this.getChainInfo();
|
|
256
|
+
const txRequest = await fromAccount.createTxExecutionRequest(
|
|
257
|
+
finalExecutionPayload,
|
|
258
|
+
feeOptions.gasSettings,
|
|
259
|
+
chainInfo,
|
|
260
|
+
executionOptions,
|
|
261
|
+
);
|
|
262
|
+
return this.pxe.simulateTx(txRequest, {
|
|
263
|
+
simulatePublic: true,
|
|
264
|
+
skipFeeEnforcement: true,
|
|
265
|
+
skipTxValidation: true,
|
|
266
|
+
overrides: {
|
|
267
|
+
contracts: { [from.toString()]: { instance, artifact } },
|
|
268
|
+
},
|
|
269
|
+
scopes,
|
|
270
|
+
});
|
|
251
271
|
}
|
|
252
272
|
|
|
253
273
|
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
@@ -258,7 +278,13 @@ export class CLIWallet extends BaseWallet {
|
|
|
258
278
|
|
|
259
279
|
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
260
280
|
// this is just a CLI wallet.
|
|
261
|
-
getNotes(filter: NotesFilter): Promise<
|
|
262
|
-
return this.pxe.getNotes(filter);
|
|
281
|
+
getNotes(filter: NotesFilter): Promise<NoteDao[]> {
|
|
282
|
+
return this.pxe.debug.getNotes(filter);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
286
|
+
// this is just a CLI wallet.
|
|
287
|
+
getContractArtifact(id: Fr) {
|
|
288
|
+
return this.pxe.getContractArtifact(id);
|
|
263
289
|
}
|
|
264
290
|
}
|