@aztec/cli-wallet 0.0.1-fake-ceab37513c → 0.0.2-commit.217f559981

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 (106) hide show
  1. package/README.md +30 -0
  2. package/dest/bin/index.d.ts +2 -1
  3. package/dest/bin/index.js +39 -23
  4. package/dest/cmds/authorize_action.d.ts +4 -3
  5. package/dest/cmds/authorize_action.d.ts.map +1 -1
  6. package/dest/cmds/authorize_action.js +8 -7
  7. package/dest/cmds/bridge_fee_juice.d.ts +4 -4
  8. package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
  9. package/dest/cmds/bridge_fee_juice.js +9 -7
  10. package/dest/cmds/check_tx.d.ts +5 -3
  11. package/dest/cmds/check_tx.d.ts.map +1 -1
  12. package/dest/cmds/check_tx.js +148 -6
  13. package/dest/cmds/create_account.d.ts +8 -6
  14. package/dest/cmds/create_account.d.ts.map +1 -1
  15. package/dest/cmds/create_account.js +56 -62
  16. package/dest/cmds/create_authwit.d.ts +4 -3
  17. package/dest/cmds/create_authwit.d.ts.map +1 -1
  18. package/dest/cmds/create_authwit.js +6 -6
  19. package/dest/cmds/deploy.d.ts +7 -4
  20. package/dest/cmds/deploy.d.ts.map +1 -1
  21. package/dest/cmds/deploy.js +84 -50
  22. package/dest/cmds/deploy_account.d.ts +6 -8
  23. package/dest/cmds/deploy_account.d.ts.map +1 -1
  24. package/dest/cmds/deploy_account.js +56 -65
  25. package/dest/cmds/import_test_accounts.d.ts +3 -3
  26. package/dest/cmds/import_test_accounts.d.ts.map +1 -1
  27. package/dest/cmds/import_test_accounts.js +6 -9
  28. package/dest/cmds/index.d.ts +3 -3
  29. package/dest/cmds/index.d.ts.map +1 -1
  30. package/dest/cmds/index.js +73 -112
  31. package/dest/cmds/profile.d.ts +7 -4
  32. package/dest/cmds/profile.d.ts.map +1 -1
  33. package/dest/cmds/profile.js +9 -4
  34. package/dest/cmds/register_contract.d.ts +7 -3
  35. package/dest/cmds/register_contract.d.ts.map +1 -1
  36. package/dest/cmds/register_contract.js +5 -6
  37. package/dest/cmds/register_sender.d.ts +4 -3
  38. package/dest/cmds/register_sender.d.ts.map +1 -1
  39. package/dest/cmds/send.d.ts +8 -9
  40. package/dest/cmds/send.d.ts.map +1 -1
  41. package/dest/cmds/send.js +46 -31
  42. package/dest/cmds/simulate.d.ts +7 -4
  43. package/dest/cmds/simulate.d.ts.map +1 -1
  44. package/dest/cmds/simulate.js +12 -7
  45. package/dest/storage/wallet_db.d.ts +6 -16
  46. package/dest/storage/wallet_db.d.ts.map +1 -1
  47. package/dest/storage/wallet_db.js +48 -54
  48. package/dest/utils/authorizations.d.ts +3 -2
  49. package/dest/utils/authorizations.d.ts.map +1 -1
  50. package/dest/utils/authorizations.js +1 -1
  51. package/dest/utils/cli_wallet_and_node_wrapper.d.ts +12 -0
  52. package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -0
  53. package/dest/utils/cli_wallet_and_node_wrapper.js +25 -0
  54. package/dest/utils/constants.d.ts +4 -0
  55. package/dest/utils/constants.d.ts.map +1 -0
  56. package/dest/utils/constants.js +7 -0
  57. package/dest/utils/ecdsa.d.ts +1 -1
  58. package/dest/utils/options/fees.d.ts +22 -28
  59. package/dest/utils/options/fees.d.ts.map +1 -1
  60. package/dest/utils/options/fees.js +66 -133
  61. package/dest/utils/options/index.d.ts +1 -1
  62. package/dest/utils/options/options.d.ts +3 -2
  63. package/dest/utils/options/options.d.ts.map +1 -1
  64. package/dest/utils/options/options.js +1 -1
  65. package/dest/utils/profiling.d.ts +1 -1
  66. package/dest/utils/profiling.d.ts.map +1 -1
  67. package/dest/utils/profiling.js +9 -1
  68. package/dest/utils/wallet.d.ts +40 -0
  69. package/dest/utils/wallet.d.ts.map +1 -0
  70. package/dest/utils/wallet.js +208 -0
  71. package/package.json +17 -14
  72. package/src/bin/index.ts +39 -31
  73. package/src/cmds/authorize_action.ts +14 -6
  74. package/src/cmds/bridge_fee_juice.ts +15 -11
  75. package/src/cmds/check_tx.ts +180 -5
  76. package/src/cmds/create_account.ts +63 -66
  77. package/src/cmds/create_authwit.ts +9 -5
  78. package/src/cmds/deploy.ts +82 -61
  79. package/src/cmds/deploy_account.ts +62 -64
  80. package/src/cmds/import_test_accounts.ts +7 -11
  81. package/src/cmds/index.ts +120 -206
  82. package/src/cmds/profile.ts +14 -6
  83. package/src/cmds/register_contract.ts +9 -11
  84. package/src/cmds/register_sender.ts +3 -2
  85. package/src/cmds/send.ts +42 -40
  86. package/src/cmds/simulate.ts +17 -12
  87. package/src/storage/wallet_db.ts +52 -67
  88. package/src/utils/authorizations.ts +3 -1
  89. package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
  90. package/src/utils/constants.ts +4 -0
  91. package/src/utils/options/fees.ts +88 -178
  92. package/src/utils/options/options.ts +3 -2
  93. package/src/utils/profiling.ts +15 -1
  94. package/src/utils/wallet.ts +290 -0
  95. package/dest/cmds/cancel_tx.d.ts +0 -11
  96. package/dest/cmds/cancel_tx.d.ts.map +0 -1
  97. package/dest/cmds/cancel_tx.js +0 -43
  98. package/dest/utils/accounts.d.ts +0 -9
  99. package/dest/utils/accounts.d.ts.map +0 -1
  100. package/dest/utils/accounts.js +0 -61
  101. package/dest/utils/pxe_wrapper.d.ts +0 -12
  102. package/dest/utils/pxe_wrapper.d.ts.map +0 -1
  103. package/dest/utils/pxe_wrapper.js +0 -26
  104. package/src/cmds/cancel_tx.ts +0 -66
  105. package/src/utils/accounts.ts +0 -77
  106. package/src/utils/pxe_wrapper.ts +0 -32
@@ -0,0 +1,290 @@
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 { AccountManager, type Aliased, type SimulateOptions } from '@aztec/aztec.js/wallet';
13
+ import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
14
+ import { Fr } from '@aztec/foundation/curves/bn254';
15
+ import type { LogFn } from '@aztec/foundation/log';
16
+ import type { AccessScopes, NotesFilter } from '@aztec/pxe/client/lazy';
17
+ import type { PXEConfig } from '@aztec/pxe/config';
18
+ import type { PXE } from '@aztec/pxe/server';
19
+ import { createPXE, getPXEConfig } from '@aztec/pxe/server';
20
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
21
+ import { deriveSigningKey } from '@aztec/stdlib/keys';
22
+ import { NoteDao } from '@aztec/stdlib/note';
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';
26
+
27
+ import type { WalletDB } from '../storage/wallet_db.js';
28
+ import type { AccountType } from './constants.js';
29
+ import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
30
+ import { printGasEstimates } from './options/fees.js';
31
+
32
+ export class CLIWallet extends BaseWallet {
33
+ private accountCache = new Map<string, Account>();
34
+
35
+ constructor(
36
+ pxe: PXE,
37
+ node: AztecNode,
38
+ private userLog: LogFn,
39
+ private db?: WalletDB,
40
+ ) {
41
+ super(pxe, node);
42
+ this.cancellableTransactions = true;
43
+ }
44
+
45
+ static async create(
46
+ node: AztecNode,
47
+ log: LogFn,
48
+ db?: WalletDB,
49
+ overridePXEConfig?: Partial<PXEConfig>,
50
+ ): Promise<CLIWallet> {
51
+ const pxeConfig = Object.assign(getPXEConfig(), overridePXEConfig);
52
+ const pxe = await createPXE(node, pxeConfig);
53
+ return new CLIWallet(pxe, node, log, db);
54
+ }
55
+
56
+ override async getAccounts(): Promise<Aliased<AztecAddress>[]> {
57
+ const accounts = (await this.db?.listAliases('accounts')) ?? [];
58
+ return Promise.resolve(accounts.map(({ key, value }) => ({ alias: value, item: AztecAddress.fromString(key) })));
59
+ }
60
+
61
+ private async createCancellationTxExecutionRequest(
62
+ from: AztecAddress,
63
+ txNonce: Fr,
64
+ increasedFee: InteractionFeeOptions,
65
+ ) {
66
+ const executionPayload = ExecutionPayload.empty();
67
+ const feeOptions = await this.completeFeeOptions(from, executionPayload.feePayer, increasedFee.gasSettings);
68
+ const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
69
+ const fromAccount = await this.getAccountFromAddress(from);
70
+ const chainInfo = await this.getChainInfo();
71
+ const executionOptions: DefaultAccountEntrypointOptions = {
72
+ txNonce,
73
+ cancellable: this.cancellableTransactions,
74
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
75
+ };
76
+ return await fromAccount.createTxExecutionRequest(
77
+ feeExecutionPayload ?? executionPayload,
78
+ feeOptions.gasSettings,
79
+ chainInfo,
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, this.scopesFrom(from));
91
+ }
92
+
93
+ override async getAccountFromAddress(address: AztecAddress) {
94
+ let account: Account | undefined;
95
+ if (address.equals(AztecAddress.ZERO)) {
96
+ account = new SignerlessAccount();
97
+ } else if (this.accountCache.has(address.toString())) {
98
+ return this.accountCache.get(address.toString())!;
99
+ } else {
100
+ const accountManager = await this.createOrRetrieveAccount(address);
101
+ account = await accountManager.getAccount();
102
+ }
103
+
104
+ if (!account) {
105
+ throw new Error(`Account not found in wallet for address: ${address}`);
106
+ }
107
+ return account;
108
+ }
109
+
110
+ private async createAccount(secret: Fr, salt: Fr, contract: AccountContract): Promise<AccountManager> {
111
+ const accountManager = await AccountManager.create(this, secret, contract, salt);
112
+
113
+ const instance = accountManager.getInstance();
114
+ const artifact = await contract.getContractArtifact();
115
+
116
+ await this.registerContract(instance, artifact, secret);
117
+ this.accountCache.set(accountManager.address.toString(), await accountManager.getAccount());
118
+ return accountManager;
119
+ }
120
+
121
+ async createOrRetrieveAccount(
122
+ address?: AztecAddress,
123
+ secretKey?: Fr,
124
+ type: AccountType = 'schnorr',
125
+ salt?: Fr,
126
+ publicKey?: string,
127
+ ): Promise<AccountManager> {
128
+ let account;
129
+
130
+ salt ??= Fr.ZERO;
131
+
132
+ if (this.db && address) {
133
+ ({ type, secretKey, salt } = await this.db.retrieveAccount(address));
134
+ }
135
+
136
+ if (!secretKey) {
137
+ throw new Error('Cannot retrieve/create wallet without secret key');
138
+ }
139
+
140
+ switch (type) {
141
+ case 'schnorr': {
142
+ account = await this.createAccount(secretKey, salt, new SchnorrAccountContract(deriveSigningKey(secretKey)));
143
+ break;
144
+ }
145
+ case 'ecdsasecp256r1': {
146
+ account = await this.createAccount(
147
+ secretKey,
148
+ salt,
149
+ new EcdsaRAccountContract(deriveSigningKey(secretKey).toBuffer()),
150
+ );
151
+ break;
152
+ }
153
+ case 'ecdsasecp256r1ssh': {
154
+ let publicSigningKey;
155
+ if (this.db && address) {
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');
168
+ }
169
+ account = await this.createAccount(secretKey, salt, new EcdsaRSSHAccountContract(publicSigningKey));
170
+ break;
171
+ }
172
+ default: {
173
+ throw new Error(`Unsupported account type: ${type}`);
174
+ }
175
+ }
176
+
177
+ return account;
178
+ }
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
+ */
186
+ private async getFakeAccountDataFor(address: AztecAddress) {
187
+ const originalAccount = await this.getAccountFromAddress(address);
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);
196
+ if (!contractInstance) {
197
+ throw new Error(`No contract instance found for address: ${originalAddress.address}`);
198
+ }
199
+ const stubAccount = createStubAccount(originalAddress);
200
+ const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
201
+ salt: Fr.random(),
202
+ });
203
+ return {
204
+ account: stubAccount,
205
+ instance,
206
+ artifact: StubAccountContractArtifact,
207
+ };
208
+ }
209
+
210
+ override async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
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
+
244
+ const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
245
+ const executionOptions: DefaultAccountEntrypointOptions = {
246
+ txNonce: Fr.random(),
247
+ cancellable: this.cancellableTransactions,
248
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
249
+ };
250
+ const finalExecutionPayload = feeExecutionPayload
251
+ ? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
252
+ : executionPayload;
253
+
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
+ });
271
+ }
272
+
273
+ // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
274
+ // this is just a CLI wallet.
275
+ getContracts(): Promise<AztecAddress[]> {
276
+ return this.pxe.getContracts();
277
+ }
278
+
279
+ // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
280
+ // this is just a CLI wallet.
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);
289
+ }
290
+ }
@@ -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, txNonce, cancellable, }: {
6
- txHash: TxHash;
7
- gasSettings: GasSettings;
8
- txNonce: 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;AAGxH,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;AAIzD,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,0BAA0B,EAClC,EACE,MAAM,EACN,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EACP,WAAW,GACZ,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;IAAC,WAAW,EAAE,OAAO,CAAA;CAAE,EAClF,aAAa,EAAE,gBAAgB,EAC/B,aAAa,EAAE,OAAO,EACtB,aAAa,EAAE,OAAO,GAAG,SAAS,EAClC,GAAG,EAAE,KAAK,iBA6CX"}
@@ -1,43 +0,0 @@
1
- import { SentTx, TxStatus } from '@aztec/aztec.js';
2
- import { ExecutionPayload } from '@aztec/entrypoints/payload';
3
- import { GasFees, GasSettings } from '@aztec/stdlib/gas';
4
- import { DEFAULT_TX_TIMEOUT_S } from '../utils/pxe_wrapper.js';
5
- export async function cancelTx(wallet, { txHash, gasSettings: prevTxGasSettings, txNonce, cancellable }, paymentMethod, increasedFees, maxFeesPerGas, log) {
6
- const receipt = await wallet.getTxReceipt(txHash);
7
- if (receipt.status !== TxStatus.PENDING || !cancellable) {
8
- log(`Transaction is in status ${receipt.status} and cannot be cancelled`);
9
- return;
10
- }
11
- const maxPriorityFeesPerGas = new GasFees(prevTxGasSettings.maxPriorityFeesPerGas.feePerDaGas + increasedFees.feePerDaGas, prevTxGasSettings.maxPriorityFeesPerGas.feePerL2Gas + increasedFees.feePerL2Gas);
12
- const fee = {
13
- paymentMethod,
14
- gasSettings: GasSettings.from({
15
- ...prevTxGasSettings,
16
- maxPriorityFeesPerGas,
17
- maxFeesPerGas: maxFeesPerGas ?? prevTxGasSettings.maxFeesPerGas
18
- })
19
- };
20
- const txRequest = await wallet.createTxExecutionRequest(ExecutionPayload.empty(), fee, {
21
- txNonce,
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, async ()=>{
27
- const tx = await txProvingResult.toTx();
28
- return wallet.sendTx(tx);
29
- });
30
- try {
31
- await sentTx.wait({
32
- timeout: DEFAULT_TX_TIMEOUT_S
33
- });
34
- log('Transaction has been cancelled');
35
- const cancelReceipt = await sentTx.getReceipt();
36
- log(` Tx fee: ${cancelReceipt.transactionFee}`);
37
- log(` Status: ${cancelReceipt.status}`);
38
- log(` Block number: ${cancelReceipt.blockNumber}`);
39
- log(` Block hash: ${cancelReceipt.blockHash?.toString()}`);
40
- } catch (err) {
41
- log(`Could not cancel transaction\n ${err.message}`);
42
- }
43
- }
@@ -1,9 +0,0 @@
1
- import type { AccountManager } 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", "ecdsasecp256r1", "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): Promise<AccountManager>;
9
- //# 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,MAAM,iBAAiB,CAAC;AACtD,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,+EAAgF,CAAC;AAC1G,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,GACjB,OAAO,CAAC,cAAc,CAAC,CAuDzB"}
@@ -1,61 +0,0 @@
1
- import { getIdentities } from '@aztec/accounts/utils';
2
- import { Fr } from '@aztec/foundation/fields';
3
- import { deriveSigningKey } from '@aztec/stdlib/keys';
4
- import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
5
- export const AccountTypes = [
6
- 'schnorr',
7
- 'ecdsasecp256r1',
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 'ecdsasecp256r1':
31
- {
32
- const { getEcdsaRAccount } = await import('@aztec/accounts/ecdsa');
33
- account = getEcdsaRAccount(pxe, secretKey, deriveSigningKey(secretKey).toBuffer(), salt);
34
- break;
35
- }
36
- case 'ecdsasecp256r1ssh':
37
- {
38
- let publicSigningKey;
39
- if (db && address) {
40
- publicSigningKey = await db.retrieveAccountMetadata(address, 'publicSigningKey');
41
- } else if (publicKey) {
42
- const identities = await getIdentities();
43
- const foundIdentity = identities.find((identity)=>identity.type === 'ecdsa-sha2-nistp256' && identity.publicKey === publicKey);
44
- if (!foundIdentity) {
45
- throw new Error(`Identity for public key ${publicKey} not found in the SSH agent`);
46
- }
47
- publicSigningKey = extractECDSAPublicKeyFromBase64String(foundIdentity.publicKey);
48
- } else {
49
- throw new Error('Public key must be provided for ECDSA SSH account');
50
- }
51
- const { getEcdsaRSSHAccount } = await import('@aztec/accounts/ecdsa');
52
- account = getEcdsaRSSHAccount(pxe, secretKey, publicSigningKey, salt);
53
- break;
54
- }
55
- default:
56
- {
57
- throw new Error(`Unsupported account type: ${type}`);
58
- }
59
- }
60
- return account;
61
- }
@@ -1,12 +0,0 @@
1
- import { type PXEServiceConfig } from '@aztec/pxe/server';
2
- import { type AztecNode, type PXE } from '@aztec/stdlib/interfaces/client';
3
- export declare const DEFAULT_TX_TIMEOUT_S = 180;
4
- export declare class PXEWrapper {
5
- private static pxeConfig;
6
- private static pxe;
7
- private static node;
8
- getPXE(): Promise<PXE>;
9
- getNode(): AztecNode | undefined;
10
- prepare(nodeUrl: string, dataDir: string, overridePXEServiceConfig?: Partial<PXEServiceConfig>): void;
11
- }
12
- //# 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;AAElG,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAMxC,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAC,SAAS,CAA+B;IACvD,OAAO,CAAC,MAAM,CAAC,GAAG,CAAkB;IACpC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAwB;IAErC,MAAM;IAOZ,OAAO,IAAI,SAAS,GAAG,SAAS;IAIhC,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,wBAAwB,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC;CAM/F"}
@@ -1,26 +0,0 @@
1
- import { createPXEService, getPXEServiceConfig } from '@aztec/pxe/server';
2
- import { createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
3
- export const DEFAULT_TX_TIMEOUT_S = 180;
4
- /*
5
- * Wrapper class for PXE service, avoids initialization issues due to
6
- * closures when providing PXE service to injected commander.js commands
7
- */ export class PXEWrapper {
8
- static pxeConfig;
9
- static pxe;
10
- static node;
11
- async getPXE() {
12
- if (!PXEWrapper.pxe) {
13
- PXEWrapper.pxe = await createPXEService(PXEWrapper.node, PXEWrapper.pxeConfig);
14
- }
15
- return PXEWrapper.pxe;
16
- }
17
- getNode() {
18
- return PXEWrapper.node;
19
- }
20
- prepare(nodeUrl, dataDir, overridePXEServiceConfig) {
21
- PXEWrapper.node = createAztecNodeClient(nodeUrl);
22
- const pxeConfig = Object.assign(getPXEServiceConfig(), overridePXEServiceConfig);
23
- pxeConfig.dataDirectory = dataDir;
24
- PXEWrapper.pxeConfig = pxeConfig;
25
- }
26
- }
@@ -1,66 +0,0 @@
1
- import { type AccountWalletWithSecretKey, type FeePaymentMethod, SentTx, type TxHash, TxStatus } from '@aztec/aztec.js';
2
- import type { FeeOptions } from '@aztec/entrypoints/interfaces';
3
- import { ExecutionPayload } from '@aztec/entrypoints/payload';
4
- import { Fr } from '@aztec/foundation/fields';
5
- import type { LogFn } from '@aztec/foundation/log';
6
- import { GasFees, GasSettings } from '@aztec/stdlib/gas';
7
-
8
- import { DEFAULT_TX_TIMEOUT_S } from '../utils/pxe_wrapper.js';
9
-
10
- export async function cancelTx(
11
- wallet: AccountWalletWithSecretKey,
12
- {
13
- txHash,
14
- gasSettings: prevTxGasSettings,
15
- txNonce,
16
- cancellable,
17
- }: { txHash: TxHash; gasSettings: GasSettings; txNonce: Fr; cancellable: boolean },
18
- paymentMethod: FeePaymentMethod,
19
- increasedFees: GasFees,
20
- maxFeesPerGas: GasFees | undefined,
21
- log: LogFn,
22
- ) {
23
- const receipt = await wallet.getTxReceipt(txHash);
24
- if (receipt.status !== TxStatus.PENDING || !cancellable) {
25
- log(`Transaction is in status ${receipt.status} and cannot be cancelled`);
26
- return;
27
- }
28
-
29
- const maxPriorityFeesPerGas = new GasFees(
30
- prevTxGasSettings.maxPriorityFeesPerGas.feePerDaGas + increasedFees.feePerDaGas,
31
- prevTxGasSettings.maxPriorityFeesPerGas.feePerL2Gas + increasedFees.feePerL2Gas,
32
- );
33
-
34
- const fee: FeeOptions = {
35
- paymentMethod,
36
- gasSettings: GasSettings.from({
37
- ...prevTxGasSettings,
38
- maxPriorityFeesPerGas,
39
- maxFeesPerGas: maxFeesPerGas ?? prevTxGasSettings.maxFeesPerGas,
40
- }),
41
- };
42
-
43
- const txRequest = await wallet.createTxExecutionRequest(ExecutionPayload.empty(), fee, {
44
- txNonce,
45
- cancellable: true,
46
- });
47
- const txSimulationResult = await wallet.simulateTx(txRequest, true);
48
- const txProvingResult = await wallet.proveTx(txRequest, txSimulationResult.privateExecutionResult);
49
- const sentTx = new SentTx(wallet, async () => {
50
- const tx = await txProvingResult.toTx();
51
- return wallet.sendTx(tx);
52
- });
53
- try {
54
- await sentTx.wait({ timeout: DEFAULT_TX_TIMEOUT_S });
55
-
56
- log('Transaction has been cancelled');
57
-
58
- const cancelReceipt = await sentTx.getReceipt();
59
- log(` Tx fee: ${cancelReceipt.transactionFee}`);
60
- log(` Status: ${cancelReceipt.status}`);
61
- log(` Block number: ${cancelReceipt.blockNumber}`);
62
- log(` Block hash: ${cancelReceipt.blockHash?.toString()}`);
63
- } catch (err: any) {
64
- log(`Could not cancel transaction\n ${err.message}`);
65
- }
66
- }
@@ -1,77 +0,0 @@
1
- import { getIdentities } from '@aztec/accounts/utils';
2
- import type { AccountManager } from '@aztec/aztec.js';
3
- import { Fr } from '@aztec/foundation/fields';
4
- import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
- import type { PXE } from '@aztec/stdlib/interfaces/client';
6
- import { deriveSigningKey } from '@aztec/stdlib/keys';
7
-
8
- import type { WalletDB } from '../storage/wallet_db.js';
9
- import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
10
-
11
- export const AccountTypes = ['schnorr', 'ecdsasecp256r1', 'ecdsasecp256r1ssh', 'ecdsasecp256k1'] as const;
12
- export type AccountType = (typeof AccountTypes)[number];
13
-
14
- export async function createOrRetrieveAccount(
15
- pxe: PXE,
16
- address?: AztecAddress,
17
- db?: WalletDB,
18
- secretKey?: Fr,
19
- type: AccountType = 'schnorr',
20
- salt?: Fr,
21
- publicKey?: string,
22
- ): Promise<AccountManager> {
23
- let account;
24
-
25
- salt ??= Fr.ZERO;
26
-
27
- if (db && address) {
28
- ({ type, secretKey, salt } = await db.retrieveAccount(address));
29
- }
30
-
31
- if (!salt) {
32
- throw new Error('Cannot retrieve/create wallet without salt');
33
- }
34
-
35
- if (!secretKey) {
36
- throw new Error('Cannot retrieve/create wallet without secret key');
37
- }
38
-
39
- switch (type) {
40
- case 'schnorr': {
41
- const { getSchnorrAccount } = await import('@aztec/accounts/schnorr');
42
- account = getSchnorrAccount(pxe, secretKey, deriveSigningKey(secretKey), salt);
43
- break;
44
- }
45
- case 'ecdsasecp256r1': {
46
- const { getEcdsaRAccount } = await import('@aztec/accounts/ecdsa');
47
- account = getEcdsaRAccount(pxe, secretKey, deriveSigningKey(secretKey).toBuffer(), salt);
48
- break;
49
- }
50
- case 'ecdsasecp256r1ssh': {
51
- let publicSigningKey;
52
- if (db && address) {
53
- publicSigningKey = await db.retrieveAccountMetadata(address, 'publicSigningKey');
54
- } else if (publicKey) {
55
- const identities = await getIdentities();
56
- const foundIdentity = identities.find(
57
- identity => identity.type === 'ecdsa-sha2-nistp256' && identity.publicKey === publicKey,
58
- );
59
- if (!foundIdentity) {
60
- throw new Error(`Identity for public key ${publicKey} not found in the SSH agent`);
61
- }
62
- publicSigningKey = extractECDSAPublicKeyFromBase64String(foundIdentity.publicKey);
63
- } else {
64
- throw new Error('Public key must be provided for ECDSA SSH account');
65
- }
66
-
67
- const { getEcdsaRSSHAccount } = await import('@aztec/accounts/ecdsa');
68
- account = getEcdsaRSSHAccount(pxe, secretKey, publicSigningKey, salt);
69
- break;
70
- }
71
- default: {
72
- throw new Error(`Unsupported account type: ${type}`);
73
- }
74
- }
75
-
76
- return account;
77
- }
@@ -1,32 +0,0 @@
1
- import { type PXEServiceConfig, createPXEService, getPXEServiceConfig } from '@aztec/pxe/server';
2
- import { type AztecNode, type PXE, createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
3
-
4
- export const DEFAULT_TX_TIMEOUT_S = 180;
5
-
6
- /*
7
- * Wrapper class for PXE service, avoids initialization issues due to
8
- * closures when providing PXE service to injected commander.js commands
9
- */
10
- export class PXEWrapper {
11
- private static pxeConfig: PXEServiceConfig | undefined;
12
- private static pxe: PXE | undefined;
13
- private static node: AztecNode | undefined;
14
-
15
- async getPXE() {
16
- if (!PXEWrapper.pxe) {
17
- PXEWrapper.pxe = await createPXEService(PXEWrapper.node!, PXEWrapper.pxeConfig!);
18
- }
19
- return PXEWrapper.pxe;
20
- }
21
-
22
- getNode(): AztecNode | undefined {
23
- return PXEWrapper.node;
24
- }
25
-
26
- prepare(nodeUrl: string, dataDir: string, overridePXEServiceConfig?: Partial<PXEServiceConfig>) {
27
- PXEWrapper.node = createAztecNodeClient(nodeUrl);
28
- const pxeConfig = Object.assign(getPXEServiceConfig(), overridePXEServiceConfig);
29
- pxeConfig.dataDirectory = dataDir;
30
- PXEWrapper.pxeConfig = pxeConfig;
31
- }
32
- }