@aztec/cli-wallet 0.0.0-test.1 → 0.0.1-commit.b655e406

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.
Files changed (105) hide show
  1. package/README.md +30 -0
  2. package/dest/bin/index.js +48 -26
  3. package/dest/cmds/authorize_action.d.ts +3 -2
  4. package/dest/cmds/authorize_action.d.ts.map +1 -1
  5. package/dest/cmds/authorize_action.js +8 -4
  6. package/dest/cmds/bridge_fee_juice.d.ts +2 -2
  7. package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
  8. package/dest/cmds/bridge_fee_juice.js +8 -7
  9. package/dest/cmds/check_tx.d.ts +4 -2
  10. package/dest/cmds/check_tx.d.ts.map +1 -1
  11. package/dest/cmds/check_tx.js +145 -6
  12. package/dest/cmds/create_account.d.ts +6 -5
  13. package/dest/cmds/create_account.d.ts.map +1 -1
  14. package/dest/cmds/create_account.js +46 -27
  15. package/dest/cmds/create_authwit.d.ts +3 -2
  16. package/dest/cmds/create_authwit.d.ts.map +1 -1
  17. package/dest/cmds/create_authwit.js +5 -5
  18. package/dest/cmds/deploy.d.ts +6 -3
  19. package/dest/cmds/deploy.d.ts.map +1 -1
  20. package/dest/cmds/deploy.js +71 -54
  21. package/dest/cmds/deploy_account.d.ts +5 -7
  22. package/dest/cmds/deploy_account.d.ts.map +1 -1
  23. package/dest/cmds/deploy_account.js +46 -29
  24. package/dest/cmds/import_test_accounts.d.ts +2 -2
  25. package/dest/cmds/import_test_accounts.d.ts.map +1 -1
  26. package/dest/cmds/import_test_accounts.js +6 -9
  27. package/dest/cmds/index.d.ts +2 -2
  28. package/dest/cmds/index.d.ts.map +1 -1
  29. package/dest/cmds/index.js +83 -115
  30. package/dest/cmds/profile.d.ts +8 -0
  31. package/dest/cmds/profile.d.ts.map +1 -0
  32. package/dest/cmds/profile.js +28 -0
  33. package/dest/cmds/register_contract.d.ts +6 -2
  34. package/dest/cmds/register_contract.d.ts.map +1 -1
  35. package/dest/cmds/register_contract.js +20 -7
  36. package/dest/cmds/register_sender.d.ts +3 -2
  37. package/dest/cmds/register_sender.d.ts.map +1 -1
  38. package/dest/cmds/send.d.ts +7 -8
  39. package/dest/cmds/send.d.ts.map +1 -1
  40. package/dest/cmds/send.js +31 -20
  41. package/dest/cmds/simulate.d.ts +6 -2
  42. package/dest/cmds/simulate.d.ts.map +1 -1
  43. package/dest/cmds/simulate.js +25 -19
  44. package/dest/storage/wallet_db.d.ts +4 -16
  45. package/dest/storage/wallet_db.d.ts.map +1 -1
  46. package/dest/storage/wallet_db.js +2 -23
  47. package/dest/utils/authorizations.d.ts +6 -0
  48. package/dest/utils/authorizations.d.ts.map +1 -0
  49. package/dest/utils/authorizations.js +28 -0
  50. package/dest/utils/cli_wallet_and_node_wrapper.d.ts +12 -0
  51. package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -0
  52. package/dest/utils/cli_wallet_and_node_wrapper.js +25 -0
  53. package/dest/utils/ecdsa.d.ts +0 -2
  54. package/dest/utils/ecdsa.d.ts.map +1 -1
  55. package/dest/utils/options/fees.d.ts +20 -27
  56. package/dest/utils/options/fees.d.ts.map +1 -1
  57. package/dest/utils/options/fees.js +85 -144
  58. package/dest/utils/options/options.d.ts +8 -4
  59. package/dest/utils/options/options.d.ts.map +1 -1
  60. package/dest/utils/options/options.js +26 -14
  61. package/dest/utils/profiling.d.ts +5 -0
  62. package/dest/utils/profiling.d.ts.map +1 -0
  63. package/dest/utils/profiling.js +60 -0
  64. package/dest/utils/wallet.d.ts +35 -0
  65. package/dest/utils/wallet.d.ts.map +1 -0
  66. package/dest/utils/wallet.js +193 -0
  67. package/package.json +24 -20
  68. package/src/bin/index.ts +56 -32
  69. package/src/cmds/authorize_action.ts +15 -4
  70. package/src/cmds/bridge_fee_juice.ts +14 -11
  71. package/src/cmds/check_tx.ts +182 -5
  72. package/src/cmds/create_account.ts +55 -32
  73. package/src/cmds/create_authwit.ts +8 -4
  74. package/src/cmds/deploy.ts +79 -62
  75. package/src/cmds/deploy_account.ts +57 -28
  76. package/src/cmds/import_test_accounts.ts +7 -11
  77. package/src/cmds/index.ts +256 -220
  78. package/src/cmds/profile.ts +48 -0
  79. package/src/cmds/register_contract.ts +28 -5
  80. package/src/cmds/register_sender.ts +3 -2
  81. package/src/cmds/send.ts +31 -17
  82. package/src/cmds/simulate.ts +39 -23
  83. package/src/storage/wallet_db.ts +3 -31
  84. package/src/utils/authorizations.ts +51 -0
  85. package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
  86. package/src/utils/options/fees.ts +134 -206
  87. package/src/utils/options/options.ts +41 -19
  88. package/src/utils/profiling.ts +158 -0
  89. package/src/utils/wallet.ts +264 -0
  90. package/dest/cmds/add_authwit.d.ts +0 -4
  91. package/dest/cmds/add_authwit.d.ts.map +0 -1
  92. package/dest/cmds/add_authwit.js +0 -4
  93. package/dest/cmds/cancel_tx.d.ts +0 -11
  94. package/dest/cmds/cancel_tx.d.ts.map +0 -1
  95. package/dest/cmds/cancel_tx.js +0 -38
  96. package/dest/utils/accounts.d.ts +0 -11
  97. package/dest/utils/accounts.d.ts.map +0 -1
  98. package/dest/utils/accounts.js +0 -87
  99. package/dest/utils/pxe_wrapper.d.ts +0 -10
  100. package/dest/utils/pxe_wrapper.d.ts.map +0 -1
  101. package/dest/utils/pxe_wrapper.js +0 -21
  102. package/src/cmds/add_authwit.ts +0 -13
  103. package/src/cmds/cancel_tx.ts +0 -62
  104. package/src/utils/accounts.ts +0 -102
  105. package/src/utils/pxe_wrapper.ts +0 -26
@@ -0,0 +1,158 @@
1
+ import type { LogFn } from '@aztec/foundation/log';
2
+ import type { PrivateExecutionStep } from '@aztec/stdlib/kernel';
3
+ import type { ProvingStats, ProvingTimings, SimulationStats, SimulationTimings } from '@aztec/stdlib/tx';
4
+
5
+ import { format } from 'util';
6
+
7
+ const FN_NAME_PADDING = 60;
8
+ const COLUMN_MIN_WIDTH = 13;
9
+ const COLUMN_MAX_WIDTH = 15;
10
+
11
+ const ORACLE_NAME_PADDING = 50;
12
+
13
+ export function printProfileResult(
14
+ stats: ProvingStats | SimulationStats,
15
+ log: LogFn,
16
+ printOracles: boolean = false,
17
+ executionSteps?: PrivateExecutionStep[],
18
+ ) {
19
+ log(format('\nPer circuit breakdown:\n'));
20
+ log(
21
+ format(
22
+ ' ',
23
+ 'Function name'.padEnd(FN_NAME_PADDING),
24
+ 'Time'.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH),
25
+ executionSteps ? 'Gates'.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH) : '',
26
+ executionSteps ? 'Subtotal'.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH) : '',
27
+ ),
28
+ );
29
+ log(
30
+ format(
31
+ ''.padEnd(
32
+ FN_NAME_PADDING +
33
+ COLUMN_MAX_WIDTH +
34
+ COLUMN_MAX_WIDTH +
35
+ (executionSteps ? COLUMN_MAX_WIDTH + COLUMN_MAX_WIDTH : 0),
36
+ '-',
37
+ ),
38
+ ),
39
+ );
40
+ let acc = 0;
41
+ let biggest: PrivateExecutionStep | undefined = executionSteps?.[0];
42
+
43
+ const timings = stats.timings;
44
+ timings.perFunction.forEach((fn, i) => {
45
+ const currentExecutionStep = executionSteps?.[i];
46
+ if (currentExecutionStep && biggest && currentExecutionStep.gateCount! > biggest.gateCount!) {
47
+ biggest = currentExecutionStep;
48
+ }
49
+ acc += currentExecutionStep ? currentExecutionStep.gateCount! : 0;
50
+
51
+ log(
52
+ format(
53
+ ' - ',
54
+ fn.functionName.padEnd(FN_NAME_PADDING),
55
+ `${fn.time.toFixed(2)}ms`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH),
56
+ currentExecutionStep
57
+ ? currentExecutionStep.gateCount!.toLocaleString().padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH)
58
+ : '',
59
+ currentExecutionStep ? acc.toLocaleString().padStart(COLUMN_MAX_WIDTH) : '',
60
+ ),
61
+ );
62
+ if (printOracles && fn.oracles) {
63
+ log('');
64
+ for (const [oracleName, { times }] of Object.entries(fn.oracles)) {
65
+ const calls = times.length;
66
+ const min = Math.min(...times);
67
+ const max = Math.max(...times);
68
+ const total = times.reduce((acc, time) => acc + time, 0);
69
+ const avg = total / calls;
70
+ log(
71
+ format(
72
+ ' ',
73
+ oracleName.padEnd(ORACLE_NAME_PADDING),
74
+ `${calls} calls`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH),
75
+ `${total.toFixed(2)}ms`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH),
76
+ `min: ${min.toFixed(2)}ms`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH),
77
+ `avg: ${avg.toFixed(2)}ms`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH),
78
+ `max: ${max.toFixed(2)}ms`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH),
79
+ ),
80
+ );
81
+ }
82
+ }
83
+ log('');
84
+ });
85
+
86
+ if (biggest) {
87
+ log(
88
+ format(
89
+ '\nTotal gates:',
90
+ acc.toLocaleString(),
91
+ `(Biggest circuit: ${biggest.functionName} -> ${biggest.gateCount!.toLocaleString()})`,
92
+ ),
93
+ );
94
+ }
95
+
96
+ if (stats.nodeRPCCalls) {
97
+ log(format('\nRPC calls:\n'));
98
+ for (const [method, { times }] of Object.entries(stats.nodeRPCCalls)) {
99
+ const calls = times.length;
100
+ const total = times.reduce((acc, time) => acc + time, 0);
101
+ const avg = total / calls;
102
+ const min = Math.min(...times);
103
+ const max = Math.max(...times);
104
+ log(
105
+ format(
106
+ method.padEnd(ORACLE_NAME_PADDING),
107
+ `${calls} calls`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH),
108
+ `${total.toFixed(2)}ms`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH),
109
+ `min: ${min.toFixed(2)}ms`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH),
110
+ `avg: ${avg.toFixed(2)}ms`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH),
111
+ `max: ${max.toFixed(2)}ms`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH),
112
+ ),
113
+ );
114
+ }
115
+ }
116
+
117
+ log(format('\nSync time:'.padEnd(25), `${timings.sync?.toFixed(2)}ms`.padStart(16)));
118
+ log(
119
+ format(
120
+ 'Private simulation time:'.padEnd(25),
121
+ `${timings.perFunction.reduce((acc, { time }) => acc + time, 0).toFixed(2)}ms`.padStart(COLUMN_MAX_WIDTH),
122
+ ),
123
+ );
124
+ if ((timings as ProvingTimings).proving) {
125
+ log(
126
+ format(
127
+ 'Proving time:'.padEnd(25),
128
+ `${(timings as ProvingTimings).proving?.toFixed(2)}ms`.padStart(COLUMN_MAX_WIDTH),
129
+ ),
130
+ );
131
+ }
132
+ if ((timings as SimulationTimings).publicSimulation) {
133
+ log(
134
+ format(
135
+ 'Public simulation time:'.padEnd(25),
136
+ `${(timings as SimulationTimings).publicSimulation?.toFixed(2)}ms`.padStart(COLUMN_MAX_WIDTH),
137
+ ),
138
+ );
139
+ }
140
+
141
+ if ((timings as SimulationTimings).validation) {
142
+ log(
143
+ format(
144
+ 'Validation time:'.padEnd(25),
145
+ `${(timings as SimulationTimings).validation?.toFixed(2)}ms`.padStart(COLUMN_MAX_WIDTH),
146
+ ),
147
+ );
148
+ }
149
+
150
+ log(
151
+ format(
152
+ 'Total time:'.padEnd(25),
153
+ `${timings.total.toFixed(2)}ms`.padStart(COLUMN_MAX_WIDTH),
154
+ `(${timings.unaccounted.toFixed(2)}ms unaccounted)`,
155
+ ),
156
+ );
157
+ log('\n');
158
+ }
@@ -0,0 +1,264 @@
1
+ import { EcdsaRAccountContract, EcdsaRSSHAccountContract } from '@aztec/accounts/ecdsa';
2
+ import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
3
+ import { StubAccountContractArtifact, createStubAccount } from '@aztec/accounts/stub';
4
+ import { getIdentities } from '@aztec/accounts/utils';
5
+ import { type Account, type AccountContract, SignerlessAccount } from '@aztec/aztec.js/account';
6
+ import {
7
+ type InteractionFeeOptions,
8
+ getContractInstanceFromInstantiationParams,
9
+ getGasLimits,
10
+ } from '@aztec/aztec.js/contracts';
11
+ import type { AztecNode } from '@aztec/aztec.js/node';
12
+ import { UniqueNote } from '@aztec/aztec.js/note';
13
+ import { AccountManager, type Aliased, BaseWallet, type SimulateOptions } from '@aztec/aztec.js/wallet';
14
+ import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
15
+ import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/entrypoints/payload';
16
+ import { Fr } from '@aztec/foundation/fields';
17
+ import type { LogFn } from '@aztec/foundation/log';
18
+ import type { PXEConfig } from '@aztec/pxe/config';
19
+ import type { PXE } from '@aztec/pxe/server';
20
+ import { createPXE, getPXEConfig } from '@aztec/pxe/server';
21
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
22
+ import { deriveSigningKey } from '@aztec/stdlib/keys';
23
+ import type { NotesFilter } from '@aztec/stdlib/note';
24
+ import type { TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
25
+
26
+ import type { WalletDB } from '../storage/wallet_db.js';
27
+ import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
28
+ import { printGasEstimates } from './options/fees.js';
29
+
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
+ export class CLIWallet extends BaseWallet {
36
+ private accountCache = new Map<string, Account>();
37
+
38
+ constructor(
39
+ pxe: PXE,
40
+ node: AztecNode,
41
+ private userLog: LogFn,
42
+ private db?: WalletDB,
43
+ ) {
44
+ super(pxe, node);
45
+ this.cancellableTransactions = true;
46
+ }
47
+
48
+ static async create(
49
+ node: AztecNode,
50
+ log: LogFn,
51
+ db?: WalletDB,
52
+ overridePXEConfig?: Partial<PXEConfig>,
53
+ ): Promise<CLIWallet> {
54
+ const pxeConfig = Object.assign(getPXEConfig(), overridePXEConfig);
55
+ const pxe = await createPXE(node, pxeConfig);
56
+ return new CLIWallet(pxe, node, log, db);
57
+ }
58
+
59
+ override async getAccounts(): Promise<Aliased<AztecAddress>[]> {
60
+ const accounts = (await this.db?.listAliases('accounts')) ?? [];
61
+ return Promise.resolve(accounts.map(({ key, value }) => ({ alias: value, item: AztecAddress.fromString(key) })));
62
+ }
63
+
64
+ private async createCancellationTxExecutionRequest(
65
+ from: AztecAddress,
66
+ txNonce: Fr,
67
+ increasedFee: InteractionFeeOptions,
68
+ ) {
69
+ const feeOptions = await this.getDefaultFeeOptions(from, increasedFee);
70
+ const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
71
+ const fromAccount = await this.getAccountFromAddress(from);
72
+ const executionOptions: DefaultAccountEntrypointOptions = {
73
+ txNonce,
74
+ cancellable: this.cancellableTransactions,
75
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
76
+ };
77
+ return await fromAccount.createTxExecutionRequest(
78
+ feeExecutionPayload ?? ExecutionPayload.empty(),
79
+ feeOptions.gasSettings,
80
+ executionOptions,
81
+ );
82
+ }
83
+
84
+ async proveCancellationTx(
85
+ from: AztecAddress,
86
+ txNonce: Fr,
87
+ increasedFee: InteractionFeeOptions,
88
+ ): Promise<TxProvingResult> {
89
+ const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
90
+ return await this.pxe.proveTx(cancellationTxRequest);
91
+ }
92
+
93
+ override async getAccountFromAddress(address: AztecAddress) {
94
+ let account: Account | undefined;
95
+ if (address.equals(AztecAddress.ZERO)) {
96
+ const chainInfo = await this.getChainInfo();
97
+ account = new SignerlessAccount(chainInfo);
98
+ } else if (this.accountCache.has(address.toString())) {
99
+ return this.accountCache.get(address.toString())!;
100
+ } else {
101
+ const accountManager = await this.createOrRetrieveAccount(address);
102
+ account = await accountManager.getAccount();
103
+ }
104
+
105
+ if (!account) {
106
+ throw new Error(`Account not found in wallet for address: ${address}`);
107
+ }
108
+ return account;
109
+ }
110
+
111
+ private async createAccount(secret: Fr, salt: Fr, contract: AccountContract): Promise<AccountManager> {
112
+ const accountManager = await AccountManager.create(this, secret, contract, salt);
113
+
114
+ const instance = accountManager.getInstance();
115
+ const artifact = await contract.getContractArtifact();
116
+
117
+ await this.registerContract(instance, artifact, secret);
118
+ this.accountCache.set(accountManager.address.toString(), await accountManager.getAccount());
119
+ return accountManager;
120
+ }
121
+
122
+ async createOrRetrieveAccount(
123
+ address?: AztecAddress,
124
+ secretKey?: Fr,
125
+ type: AccountType = 'schnorr',
126
+ salt?: Fr,
127
+ publicKey?: string,
128
+ ): Promise<AccountManager> {
129
+ let account;
130
+
131
+ salt ??= Fr.ZERO;
132
+
133
+ if (this.db && address) {
134
+ ({ type, secretKey, salt } = await this.db.retrieveAccount(address));
135
+ }
136
+
137
+ if (!secretKey) {
138
+ throw new Error('Cannot retrieve/create wallet without secret key');
139
+ }
140
+
141
+ switch (type) {
142
+ case 'schnorr': {
143
+ account = await this.createAccount(secretKey, salt, new SchnorrAccountContract(deriveSigningKey(secretKey)));
144
+ break;
145
+ }
146
+ case 'ecdsasecp256r1': {
147
+ account = await this.createAccount(
148
+ secretKey,
149
+ salt,
150
+ new EcdsaRAccountContract(deriveSigningKey(secretKey).toBuffer()),
151
+ );
152
+ break;
153
+ }
154
+ case 'ecdsasecp256r1ssh': {
155
+ let publicSigningKey;
156
+ if (this.db && address) {
157
+ publicSigningKey = await this.db.retrieveAccountMetadata(address, 'publicSigningKey');
158
+ } else if (publicKey) {
159
+ const identities = await getIdentities();
160
+ const foundIdentity = identities.find(
161
+ identity => identity.type === 'ecdsa-sha2-nistp256' && identity.publicKey === publicKey,
162
+ );
163
+ if (!foundIdentity) {
164
+ throw new Error(`Identity for public key ${publicKey} not found in the SSH agent`);
165
+ }
166
+ publicSigningKey = extractECDSAPublicKeyFromBase64String(foundIdentity.publicKey);
167
+ } else {
168
+ throw new Error('Public key must be provided for ECDSA SSH account');
169
+ }
170
+ account = await this.createAccount(secretKey, salt, new EcdsaRSSHAccountContract(publicSigningKey));
171
+ break;
172
+ }
173
+ default: {
174
+ throw new Error(`Unsupported account type: ${type}`);
175
+ }
176
+ }
177
+
178
+ return account;
179
+ }
180
+
181
+ private async getFakeAccountDataFor(address: AztecAddress) {
182
+ const chainInfo = await this.getChainInfo();
183
+ const originalAccount = await this.getAccountFromAddress(address);
184
+ const originalAddress = originalAccount.getCompleteAddress();
185
+ const { contractInstance } = await this.pxe.getContractMetadata(originalAddress.address);
186
+ if (!contractInstance) {
187
+ throw new Error(`No contract instance found for address: ${originalAddress.address}`);
188
+ }
189
+ const stubAccount = createStubAccount(originalAddress, chainInfo);
190
+ const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
191
+ salt: Fr.random(),
192
+ });
193
+ return {
194
+ account: stubAccount,
195
+ instance,
196
+ artifact: StubAccountContractArtifact,
197
+ };
198
+ }
199
+
200
+ override async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
201
+ let simulationResults;
202
+ const feeOptions = opts.fee?.estimateGas
203
+ ? await this.getFeeOptionsForGasEstimation(opts.from, opts.fee)
204
+ : await this.getDefaultFeeOptions(opts.from, opts.fee);
205
+ const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
206
+ const executionOptions: DefaultAccountEntrypointOptions = {
207
+ txNonce: Fr.random(),
208
+ cancellable: this.cancellableTransactions,
209
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
210
+ };
211
+ const finalExecutionPayload = feeExecutionPayload
212
+ ? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
213
+ : executionPayload;
214
+
215
+ // Kernelless simulations using the multicall entrypoints are not currently supported,
216
+ // since we only override proper account contracts.
217
+ // TODO: allow disabling kernels even when no overrides are necessary
218
+ if (opts.from.equals(AztecAddress.ZERO)) {
219
+ const fromAccount = await this.getAccountFromAddress(opts.from);
220
+ const txRequest = await fromAccount.createTxExecutionRequest(
221
+ finalExecutionPayload,
222
+ feeOptions.gasSettings,
223
+ executionOptions,
224
+ );
225
+ simulationResults = await this.pxe.simulateTx(
226
+ txRequest,
227
+ true /* simulatePublic */,
228
+ opts?.skipTxValidation,
229
+ opts?.skipFeeEnforcement ?? true,
230
+ );
231
+ } else {
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;
251
+ }
252
+
253
+ // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
254
+ // this is just a CLI wallet.
255
+ getContracts(): Promise<AztecAddress[]> {
256
+ return this.pxe.getContracts();
257
+ }
258
+
259
+ // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
260
+ // this is just a CLI wallet.
261
+ getNotes(filter: NotesFilter): Promise<UniqueNote[]> {
262
+ return this.pxe.getNotes(filter);
263
+ }
264
+ }
@@ -1,4 +0,0 @@
1
- import type { AccountWalletWithSecretKey, AuthWitness, AztecAddress } from '@aztec/aztec.js';
2
- import type { LogFn } from '@aztec/foundation/log';
3
- export declare function addAuthwit(wallet: AccountWalletWithSecretKey, authwit: AuthWitness, authorizer: AztecAddress, log: LogFn): Promise<void>;
4
- //# sourceMappingURL=add_authwit.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"add_authwit.d.ts","sourceRoot":"","sources":["../../src/cmds/add_authwit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,wBAAsB,UAAU,CAC9B,MAAM,EAAE,0BAA0B,EAClC,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,YAAY,EACxB,GAAG,EAAE,KAAK,iBAKX"}
@@ -1,4 +0,0 @@
1
- export async function addAuthwit(wallet, authwit, authorizer, log) {
2
- await wallet.addAuthWitness(authwit);
3
- log(`Added authorization witness from ${authorizer}`);
4
- }
@@ -1,11 +0,0 @@
1
- import { type AccountWalletWithSecretKey, type FeePaymentMethod, type TxHash } from '@aztec/aztec.js';
2
- import { Fr } from '@aztec/foundation/fields';
3
- import type { LogFn } from '@aztec/foundation/log';
4
- import { GasFees, GasSettings } from '@aztec/stdlib/gas';
5
- export declare function cancelTx(wallet: AccountWalletWithSecretKey, { txHash, gasSettings: prevTxGasSettings, nonce, cancellable, }: {
6
- txHash: TxHash;
7
- gasSettings: GasSettings;
8
- nonce: Fr;
9
- cancellable: boolean;
10
- }, paymentMethod: FeePaymentMethod, increasedFees: GasFees, maxFeesPerGas: GasFees | undefined, log: LogFn): Promise<void>;
11
- //# sourceMappingURL=cancel_tx.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cancel_tx.d.ts","sourceRoot":"","sources":["../../src/cmds/cancel_tx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,0BAA0B,EAAE,KAAK,gBAAgB,EAAU,KAAK,MAAM,EAAY,MAAM,iBAAiB,CAAC;AAExH,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEzD,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,0BAA0B,EAClC,EACE,MAAM,EACN,WAAW,EAAE,iBAAiB,EAC9B,KAAK,EACL,WAAW,GACZ,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,EAAE,CAAC;IAAC,WAAW,EAAE,OAAO,CAAA;CAAE,EAChF,aAAa,EAAE,gBAAgB,EAC/B,aAAa,EAAE,OAAO,EACtB,aAAa,EAAE,OAAO,GAAG,SAAS,EAClC,GAAG,EAAE,KAAK,iBA4CX"}
@@ -1,38 +0,0 @@
1
- import { SentTx, TxStatus } from '@aztec/aztec.js';
2
- import { GasFees, GasSettings } from '@aztec/stdlib/gas';
3
- export async function cancelTx(wallet, { txHash, gasSettings: prevTxGasSettings, nonce, cancellable }, paymentMethod, increasedFees, maxFeesPerGas, log) {
4
- const receipt = await wallet.getTxReceipt(txHash);
5
- if (receipt.status !== TxStatus.PENDING || !cancellable) {
6
- log(`Transaction is in status ${receipt.status} and cannot be cancelled`);
7
- return;
8
- }
9
- const maxPriorityFeesPerGas = new GasFees(prevTxGasSettings.maxPriorityFeesPerGas.feePerDaGas.add(increasedFees.feePerDaGas), prevTxGasSettings.maxPriorityFeesPerGas.feePerL2Gas.add(increasedFees.feePerL2Gas));
10
- const fee = {
11
- paymentMethod,
12
- gasSettings: GasSettings.from({
13
- ...prevTxGasSettings,
14
- maxPriorityFeesPerGas,
15
- maxFeesPerGas: maxFeesPerGas ?? prevTxGasSettings.maxFeesPerGas
16
- })
17
- };
18
- const txRequest = await wallet.createTxExecutionRequest({
19
- calls: [],
20
- fee,
21
- nonce,
22
- cancellable: true
23
- });
24
- const txSimulationResult = await wallet.simulateTx(txRequest, true);
25
- const txProvingResult = await wallet.proveTx(txRequest, txSimulationResult.privateExecutionResult);
26
- const sentTx = new SentTx(wallet, wallet.sendTx(txProvingResult.toTx()));
27
- try {
28
- await sentTx.wait();
29
- log('Transaction has been cancelled');
30
- const cancelReceipt = await sentTx.getReceipt();
31
- log(` Tx fee: ${cancelReceipt.transactionFee}`);
32
- log(` Status: ${cancelReceipt.status}`);
33
- log(` Block number: ${cancelReceipt.blockNumber}`);
34
- log(` Block hash: ${cancelReceipt.blockHash?.toString()}`);
35
- } catch (err) {
36
- log(`Could not cancel transaction\n ${err.message}`);
37
- }
38
- }
@@ -1,11 +0,0 @@
1
- import type { AccountManager, AccountWalletWithSecretKey } from '@aztec/aztec.js';
2
- import { Fr } from '@aztec/foundation/fields';
3
- import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
- import type { PXE } from '@aztec/stdlib/interfaces/client';
5
- import type { WalletDB } from '../storage/wallet_db.js';
6
- export declare const AccountTypes: readonly ["schnorr", "ecdsasecp256r1ssh", "ecdsasecp256k1"];
7
- export type AccountType = (typeof AccountTypes)[number];
8
- export declare function createOrRetrieveAccount(pxe: PXE, address?: AztecAddress, db?: WalletDB, secretKey?: Fr, type?: AccountType, salt?: Fr, publicKey?: string | undefined): Promise<AccountManager>;
9
- export declare function addScopeToWallet(wallet: AccountWalletWithSecretKey, scope: AztecAddress, db?: WalletDB): Promise<void>;
10
- export declare function getWalletWithScopes(account: AccountManager, db?: WalletDB): Promise<AccountWalletWithSecretKey>;
11
- //# sourceMappingURL=accounts.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../src/utils/accounts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAC;AAG3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAGxD,eAAO,MAAM,YAAY,6DAA8D,CAAC;AACxF,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAExD,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,GAAG,EACR,OAAO,CAAC,EAAE,YAAY,EACtB,EAAE,CAAC,EAAE,QAAQ,EACb,SAAS,CAAC,EAAE,EAAE,EACd,IAAI,GAAE,WAAuB,EAC7B,IAAI,CAAC,EAAE,EAAE,EACT,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,GAC7B,OAAO,CAAC,cAAc,CAAC,CAkDzB;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,0BAA0B,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,CAAC,EAAE,QAAQ,iBAU5G;AAED,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,CAAC,EAAE,QAAQ,uCAgB/E"}
@@ -1,87 +0,0 @@
1
- import { getIdentities } from '@aztec/accounts/utils';
2
- import { Fr } from '@aztec/foundation/fields';
3
- import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
- import { deriveSigningKey } from '@aztec/stdlib/keys';
5
- import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
6
- export const AccountTypes = [
7
- 'schnorr',
8
- 'ecdsasecp256r1ssh',
9
- 'ecdsasecp256k1'
10
- ];
11
- export async function createOrRetrieveAccount(pxe, address, db, secretKey, type = 'schnorr', salt, publicKey) {
12
- let account;
13
- salt ??= Fr.ZERO;
14
- if (db && address) {
15
- ({ type, secretKey, salt } = await db.retrieveAccount(address));
16
- }
17
- if (!salt) {
18
- throw new Error('Cannot retrieve/create wallet without salt');
19
- }
20
- if (!secretKey) {
21
- throw new Error('Cannot retrieve/create wallet without secret key');
22
- }
23
- switch(type){
24
- case 'schnorr':
25
- {
26
- const { getSchnorrAccount } = await import('@aztec/accounts/schnorr');
27
- account = getSchnorrAccount(pxe, secretKey, deriveSigningKey(secretKey), salt);
28
- break;
29
- }
30
- case 'ecdsasecp256r1ssh':
31
- {
32
- let publicSigningKey;
33
- if (db && address) {
34
- publicSigningKey = await db.retrieveAccountMetadata(address, 'publicSigningKey');
35
- } else if (publicKey) {
36
- const identities = await getIdentities();
37
- const foundIdentity = identities.find((identity)=>identity.type === 'ecdsa-sha2-nistp256' && identity.publicKey === publicKey);
38
- if (!foundIdentity) {
39
- throw new Error(`Identity for public key ${publicKey} not found in the SSH agent`);
40
- }
41
- publicSigningKey = extractECDSAPublicKeyFromBase64String(foundIdentity.publicKey);
42
- } else {
43
- throw new Error('Public key must be provided for ECDSA SSH account');
44
- }
45
- const { getEcdsaRSSHAccount } = await import('@aztec/accounts/ecdsa');
46
- account = getEcdsaRSSHAccount(pxe, secretKey, publicSigningKey, salt);
47
- break;
48
- }
49
- default:
50
- {
51
- throw new Error(`Unsupported account type: ${type}`);
52
- }
53
- }
54
- return account;
55
- }
56
- export async function addScopeToWallet(wallet, scope, db) {
57
- const address = wallet.getAddress().toString();
58
- const currentScopes = wallet.getScopes() ?? [];
59
- const deduplicatedScopes = Array.from(new Set([
60
- address,
61
- ...currentScopes,
62
- scope
63
- ].map((scope)=>scope.toString())).values());
64
- if (db) {
65
- await db.storeAccountMetadata(wallet.getAddress(), 'scopes', Buffer.from(deduplicatedScopes.join(',')));
66
- }
67
- wallet.setScopes(deduplicatedScopes.map((scope)=>AztecAddress.fromString(scope)));
68
- }
69
- export async function getWalletWithScopes(account, db) {
70
- const wallet = await account.getWallet();
71
- if (db) {
72
- const address = wallet.getAddress().toString();
73
- let storedScopes = [];
74
- try {
75
- storedScopes = (await db.retrieveAccountMetadata(wallet.getAddress(), 'scopes') ?? '').toString().split(',');
76
- // eslint-disable-next-line no-empty
77
- } catch {}
78
- const currentScopes = wallet.getScopes()?.map((scopes)=>scopes.toString()) ?? [];
79
- const deduplicatedScopes = Array.from(new Set([
80
- address,
81
- ...currentScopes,
82
- ...storedScopes
83
- ]).values()).map((scope)=>AztecAddress.fromString(scope));
84
- wallet.setScopes(deduplicatedScopes);
85
- }
86
- return wallet;
87
- }
@@ -1,10 +0,0 @@
1
- import { type PXEServiceConfig } from '@aztec/pxe/server';
2
- import { type AztecNode, type PXE } from '@aztec/stdlib/interfaces/client';
3
- export declare class PXEWrapper {
4
- private static pxe;
5
- private static node;
6
- getPXE(): PXE | undefined;
7
- getNode(): AztecNode | undefined;
8
- init(nodeUrl: string, dataDir: string, overridePXEServiceConfig?: Partial<PXEServiceConfig>): Promise<void>;
9
- }
10
- //# sourceMappingURL=pxe_wrapper.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pxe_wrapper.d.ts","sourceRoot":"","sources":["../../src/utils/pxe_wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAyC,MAAM,mBAAmB,CAAC;AACjG,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,GAAG,EAAyB,MAAM,iCAAiC,CAAC;AAMlG,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAC,GAAG,CAAkB;IACpC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAwB;IAE3C,MAAM,IAAI,GAAG,GAAG,SAAS;IAIzB,OAAO,IAAI,SAAS,GAAG,SAAS;IAI1B,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,wBAAwB,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC;CAMlG"}
@@ -1,21 +0,0 @@
1
- import { createPXEService, getPXEServiceConfig } from '@aztec/pxe/server';
2
- import { createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
3
- /*
4
- * Wrapper class for PXE service, avoids initialization issues due to
5
- * closures when providing PXE service to injected commander.js commands
6
- */ export class PXEWrapper {
7
- static pxe;
8
- static node;
9
- getPXE() {
10
- return PXEWrapper.pxe;
11
- }
12
- getNode() {
13
- return PXEWrapper.node;
14
- }
15
- async init(nodeUrl, dataDir, overridePXEServiceConfig) {
16
- PXEWrapper.node = createAztecNodeClient(nodeUrl);
17
- const pxeConfig = Object.assign(getPXEServiceConfig(), overridePXEServiceConfig);
18
- pxeConfig.dataDirectory = dataDir;
19
- PXEWrapper.pxe = await createPXEService(PXEWrapper.node, pxeConfig);
20
- }
21
- }
@@ -1,13 +0,0 @@
1
- import type { AccountWalletWithSecretKey, AuthWitness, AztecAddress } from '@aztec/aztec.js';
2
- import type { LogFn } from '@aztec/foundation/log';
3
-
4
- export async function addAuthwit(
5
- wallet: AccountWalletWithSecretKey,
6
- authwit: AuthWitness,
7
- authorizer: AztecAddress,
8
- log: LogFn,
9
- ) {
10
- await wallet.addAuthWitness(authwit);
11
-
12
- log(`Added authorization witness from ${authorizer}`);
13
- }