@aztec/aztec.js 0.0.1-commit.b655e406 → 0.0.1-commit.c31f2472

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 (246) hide show
  1. package/dest/account/account.d.ts +26 -42
  2. package/dest/account/account.d.ts.map +1 -1
  3. package/dest/account/account.js +19 -47
  4. package/dest/account/account_contract.d.ts +9 -10
  5. package/dest/account/account_contract.d.ts.map +1 -1
  6. package/dest/account/account_with_secret_key.d.ts +20 -9
  7. package/dest/account/account_with_secret_key.d.ts.map +1 -1
  8. package/dest/account/account_with_secret_key.js +21 -4
  9. package/dest/account/index.d.ts +4 -3
  10. package/dest/account/index.d.ts.map +1 -1
  11. package/dest/account/index.js +2 -0
  12. package/dest/account/signerless_account.d.ts +7 -9
  13. package/dest/account/signerless_account.d.ts.map +1 -1
  14. package/dest/account/signerless_account.js +8 -11
  15. package/dest/api/abi.d.ts +1 -1
  16. package/dest/api/account.d.ts +3 -4
  17. package/dest/api/account.d.ts.map +1 -1
  18. package/dest/api/account.js +2 -3
  19. package/dest/api/addresses.d.ts +1 -1
  20. package/dest/api/authorization.d.ts +2 -2
  21. package/dest/api/authorization.d.ts.map +1 -1
  22. package/dest/api/authorization.js +1 -1
  23. package/dest/api/block.d.ts +1 -1
  24. package/dest/api/contract.d.ts +17 -11
  25. package/dest/api/contract.d.ts.map +1 -1
  26. package/dest/api/contract.js +15 -9
  27. package/dest/api/crypto.d.ts +1 -1
  28. package/dest/api/deployment.d.ts +1 -1
  29. package/dest/api/eth_address.d.ts +1 -1
  30. package/dest/api/ethereum.d.ts +1 -1
  31. package/dest/api/events.d.ts +1 -1
  32. package/dest/api/fee.d.ts +1 -1
  33. package/dest/api/fee_testing.d.ts +1 -1
  34. package/dest/api/fields.d.ts +3 -2
  35. package/dest/api/fields.d.ts.map +1 -1
  36. package/dest/api/fields.js +2 -1
  37. package/dest/api/keys.d.ts +1 -1
  38. package/dest/api/log.d.ts +1 -1
  39. package/dest/api/messaging.d.ts +1 -1
  40. package/dest/api/node.d.ts +8 -4
  41. package/dest/api/node.d.ts.map +1 -1
  42. package/dest/api/node.js +7 -3
  43. package/dest/api/note.d.ts +2 -2
  44. package/dest/api/note.d.ts.map +1 -1
  45. package/dest/api/note.js +1 -1
  46. package/dest/api/protocol.d.ts +7 -1
  47. package/dest/api/protocol.d.ts.map +1 -1
  48. package/dest/api/protocol.js +6 -0
  49. package/dest/api/trees.d.ts +1 -1
  50. package/dest/api/tx.d.ts +2 -2
  51. package/dest/api/tx.d.ts.map +1 -1
  52. package/dest/api/tx.js +1 -1
  53. package/dest/api/utils.d.ts +1 -1
  54. package/dest/api/wallet.d.ts +2 -3
  55. package/dest/api/wallet.d.ts.map +1 -1
  56. package/dest/api/wallet.js +1 -2
  57. package/dest/authorization/call_authorization_request.d.ts +2 -2
  58. package/dest/authorization/call_authorization_request.d.ts.map +1 -1
  59. package/dest/contract/base_contract_interaction.d.ts +8 -11
  60. package/dest/contract/base_contract_interaction.d.ts.map +1 -1
  61. package/dest/contract/base_contract_interaction.js +5 -17
  62. package/dest/contract/batch_call.d.ts +8 -9
  63. package/dest/contract/batch_call.d.ts.map +1 -1
  64. package/dest/contract/batch_call.js +54 -34
  65. package/dest/contract/checker.d.ts +1 -1
  66. package/dest/contract/contract.d.ts +2 -2
  67. package/dest/contract/contract.d.ts.map +1 -1
  68. package/dest/contract/contract.js +4 -5
  69. package/dest/contract/contract_base.d.ts +6 -10
  70. package/dest/contract/contract_base.d.ts.map +1 -1
  71. package/dest/contract/contract_base.js +5 -12
  72. package/dest/contract/contract_function_interaction.d.ts +3 -3
  73. package/dest/contract/contract_function_interaction.d.ts.map +1 -1
  74. package/dest/contract/contract_function_interaction.js +9 -6
  75. package/dest/contract/deploy_method.d.ts +71 -23
  76. package/dest/contract/deploy_method.d.ts.map +1 -1
  77. package/dest/contract/deploy_method.js +49 -29
  78. package/dest/contract/get_gas_limits.d.ts +1 -1
  79. package/dest/contract/interaction_options.d.ts +44 -7
  80. package/dest/contract/interaction_options.d.ts.map +1 -1
  81. package/dest/contract/interaction_options.js +12 -11
  82. package/dest/contract/protocol_contracts/auth-registry.d.ts +36 -0
  83. package/dest/contract/protocol_contracts/auth-registry.d.ts.map +1 -0
  84. package/dest/contract/protocol_contracts/auth-registry.js +963 -0
  85. package/dest/contract/protocol_contracts/contract-class-registry.d.ts +35 -0
  86. package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -0
  87. package/dest/contract/protocol_contracts/contract-class-registry.js +784 -0
  88. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +31 -0
  89. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -0
  90. package/dest/contract/protocol_contracts/contract-instance-registry.js +866 -0
  91. package/dest/contract/protocol_contracts/fee-juice.d.ts +30 -0
  92. package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -0
  93. package/dest/contract/protocol_contracts/fee-juice.js +827 -0
  94. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts +34 -0
  95. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts.map +1 -0
  96. package/dest/contract/protocol_contracts/multi-call-entrypoint.js +563 -0
  97. package/dest/contract/protocol_contracts/public-checks.d.ts +26 -0
  98. package/dest/contract/protocol_contracts/public-checks.d.ts.map +1 -0
  99. package/dest/contract/protocol_contracts/public-checks.js +579 -0
  100. package/dest/contract/wait_for_proven.d.ts +2 -2
  101. package/dest/contract/wait_for_proven.d.ts.map +1 -1
  102. package/dest/contract/wait_for_proven.js +1 -1
  103. package/dest/contract/wait_opts.d.ts +16 -0
  104. package/dest/contract/wait_opts.d.ts.map +1 -0
  105. package/dest/contract/wait_opts.js +5 -0
  106. package/dest/deployment/broadcast_function.d.ts +1 -1
  107. package/dest/deployment/broadcast_function.js +4 -4
  108. package/dest/deployment/contract_deployer.d.ts +1 -1
  109. package/dest/deployment/contract_deployer.d.ts.map +1 -1
  110. package/dest/deployment/contract_deployer.js +1 -1
  111. package/dest/deployment/publish_class.d.ts +1 -1
  112. package/dest/deployment/publish_class.js +3 -3
  113. package/dest/deployment/publish_instance.d.ts +2 -2
  114. package/dest/deployment/publish_instance.d.ts.map +1 -1
  115. package/dest/deployment/publish_instance.js +3 -3
  116. package/dest/ethereum/portal_manager.d.ts +7 -6
  117. package/dest/ethereum/portal_manager.d.ts.map +1 -1
  118. package/dest/ethereum/portal_manager.js +48 -22
  119. package/dest/fee/fee_juice_payment_method_with_claim.d.ts +2 -2
  120. package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -1
  121. package/dest/fee/fee_juice_payment_method_with_claim.js +3 -3
  122. package/dest/fee/fee_payment_method.d.ts +2 -2
  123. package/dest/fee/fee_payment_method.d.ts.map +1 -1
  124. package/dest/fee/private_fee_payment_method.d.ts +2 -2
  125. package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
  126. package/dest/fee/private_fee_payment_method.js +4 -4
  127. package/dest/fee/public_fee_payment_method.d.ts +2 -2
  128. package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
  129. package/dest/fee/public_fee_payment_method.js +4 -4
  130. package/dest/fee/sponsored_fee_payment.d.ts +2 -2
  131. package/dest/fee/sponsored_fee_payment.d.ts.map +1 -1
  132. package/dest/fee/sponsored_fee_payment.js +2 -2
  133. package/dest/scripts/generate_protocol_contract_types.d.ts +2 -0
  134. package/dest/scripts/generate_protocol_contract_types.d.ts.map +1 -0
  135. package/dest/scripts/generate_protocol_contract_types.js +120 -0
  136. package/dest/utils/abi_types.d.ts +2 -2
  137. package/dest/utils/abi_types.d.ts.map +1 -1
  138. package/dest/utils/authwit.d.ts +14 -12
  139. package/dest/utils/authwit.d.ts.map +1 -1
  140. package/dest/utils/authwit.js +27 -20
  141. package/dest/utils/cross_chain.d.ts +2 -2
  142. package/dest/utils/cross_chain.d.ts.map +1 -1
  143. package/dest/utils/fee_juice.d.ts +2 -2
  144. package/dest/utils/fee_juice.js +2 -2
  145. package/dest/utils/field_compressed_string.d.ts +1 -1
  146. package/dest/utils/field_compressed_string.d.ts.map +1 -1
  147. package/dest/utils/field_compressed_string.js +1 -1
  148. package/dest/utils/node.d.ts +13 -2
  149. package/dest/utils/node.d.ts.map +1 -1
  150. package/dest/utils/node.js +46 -0
  151. package/dest/utils/pub_key.d.ts +2 -2
  152. package/dest/utils/pub_key.d.ts.map +1 -1
  153. package/dest/utils/pub_key.js +1 -1
  154. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts +6 -9
  155. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts.map +1 -1
  156. package/dest/wallet/account_entrypoint_meta_payment_method.js +29 -44
  157. package/dest/wallet/account_manager.d.ts +3 -9
  158. package/dest/wallet/account_manager.d.ts.map +1 -1
  159. package/dest/wallet/account_manager.js +6 -12
  160. package/dest/wallet/deploy_account_method.d.ts +37 -9
  161. package/dest/wallet/deploy_account_method.d.ts.map +1 -1
  162. package/dest/wallet/deploy_account_method.js +9 -7
  163. package/dest/wallet/index.d.ts +1 -2
  164. package/dest/wallet/index.d.ts.map +1 -1
  165. package/dest/wallet/index.js +0 -1
  166. package/dest/wallet/wallet.d.ts +323 -1504
  167. package/dest/wallet/wallet.d.ts.map +1 -1
  168. package/dest/wallet/wallet.js +85 -115
  169. package/package.json +16 -13
  170. package/src/account/account.ts +35 -60
  171. package/src/account/account_contract.ts +7 -8
  172. package/src/account/account_with_secret_key.ts +34 -9
  173. package/src/account/index.ts +3 -2
  174. package/src/account/signerless_account.ts +15 -15
  175. package/src/api/account.ts +10 -3
  176. package/src/api/authorization.ts +1 -0
  177. package/src/api/contract.ts +24 -8
  178. package/src/api/fields.ts +2 -1
  179. package/src/api/node.ts +7 -3
  180. package/src/api/note.ts +1 -1
  181. package/src/api/protocol.ts +7 -0
  182. package/src/api/tx.ts +4 -0
  183. package/src/api/wallet.ts +10 -9
  184. package/src/authorization/call_authorization_request.ts +1 -1
  185. package/src/contract/base_contract_interaction.ts +27 -16
  186. package/src/contract/batch_call.ts +67 -48
  187. package/src/contract/contract.ts +7 -5
  188. package/src/contract/contract_base.ts +5 -15
  189. package/src/contract/contract_function_interaction.ts +10 -11
  190. package/src/contract/deploy_method.ts +134 -40
  191. package/src/contract/interaction_options.ts +52 -13
  192. package/src/contract/protocol_contracts/auth-registry.ts +545 -0
  193. package/src/contract/protocol_contracts/contract-class-registry.ts +433 -0
  194. package/src/contract/protocol_contracts/contract-instance-registry.ts +495 -0
  195. package/src/contract/protocol_contracts/fee-juice.ts +457 -0
  196. package/src/contract/protocol_contracts/multi-call-entrypoint.ts +329 -0
  197. package/src/contract/protocol_contracts/public-checks.ts +315 -0
  198. package/src/contract/wait_for_proven.ts +1 -1
  199. package/src/contract/wait_opts.ts +21 -0
  200. package/src/deployment/broadcast_function.ts +4 -4
  201. package/src/deployment/contract_deployer.ts +3 -2
  202. package/src/deployment/publish_class.ts +3 -3
  203. package/src/deployment/publish_instance.ts +3 -6
  204. package/src/ethereum/portal_manager.ts +65 -34
  205. package/src/fee/fee_juice_payment_method_with_claim.ts +4 -2
  206. package/src/fee/fee_payment_method.ts +1 -1
  207. package/src/fee/private_fee_payment_method.ts +5 -3
  208. package/src/fee/public_fee_payment_method.ts +5 -3
  209. package/src/fee/sponsored_fee_payment.ts +3 -1
  210. package/src/scripts/generate_protocol_contract_types.ts +150 -0
  211. package/src/utils/abi_types.ts +1 -1
  212. package/src/utils/authwit.ts +40 -22
  213. package/src/utils/cross_chain.ts +1 -1
  214. package/src/utils/fee_juice.ts +2 -2
  215. package/src/utils/field_compressed_string.ts +1 -1
  216. package/src/utils/node.ts +62 -0
  217. package/src/utils/pub_key.ts +2 -2
  218. package/src/wallet/account_entrypoint_meta_payment_method.ts +29 -60
  219. package/src/wallet/account_manager.ts +7 -15
  220. package/src/wallet/deploy_account_method.ts +41 -16
  221. package/src/wallet/index.ts +0 -1
  222. package/src/wallet/wallet.ts +207 -152
  223. package/dest/account/interface.d.ts +0 -19
  224. package/dest/account/interface.d.ts.map +0 -1
  225. package/dest/account/interface.js +0 -5
  226. package/dest/contract/deploy_sent_tx.d.ts +0 -43
  227. package/dest/contract/deploy_sent_tx.d.ts.map +0 -1
  228. package/dest/contract/deploy_sent_tx.js +0 -40
  229. package/dest/contract/protocol_contracts.d.ts +0 -9
  230. package/dest/contract/protocol_contracts.d.ts.map +0 -1
  231. package/dest/contract/protocol_contracts.js +0 -26
  232. package/dest/contract/sent_tx.d.ts +0 -51
  233. package/dest/contract/sent_tx.d.ts.map +0 -1
  234. package/dest/contract/sent_tx.js +0 -90
  235. package/dest/contract/unsafe_contract.d.ts +0 -15
  236. package/dest/contract/unsafe_contract.d.ts.map +0 -1
  237. package/dest/contract/unsafe_contract.js +0 -6
  238. package/dest/wallet/base_wallet.d.ts +0 -91
  239. package/dest/wallet/base_wallet.d.ts.map +0 -1
  240. package/dest/wallet/base_wallet.js +0 -238
  241. package/src/account/interface.ts +0 -25
  242. package/src/contract/deploy_sent_tx.ts +0 -68
  243. package/src/contract/protocol_contracts.ts +0 -35
  244. package/src/contract/sent_tx.ts +0 -130
  245. package/src/contract/unsafe_contract.ts +0 -19
  246. package/src/wallet/base_wallet.ts +0 -350
@@ -1,35 +0,0 @@
1
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
2
-
3
- import type { Wallet } from '../wallet/wallet.js';
4
- import { UnsafeContract } from './unsafe_contract.js';
5
-
6
- /** Returns a Contract wrapper for the contract class registry. */
7
- export async function getClassRegistryContract(wallet: Wallet) {
8
- const { contractInstance } = await wallet.getContractMetadata(ProtocolContractAddress.ContractClassRegistry);
9
- if (!contractInstance) {
10
- throw new Error("ContractClassRegistry is not registered in this wallet's instance");
11
- }
12
- const { artifact } = await wallet.getContractClassMetadata(contractInstance.currentContractClassId, true);
13
-
14
- return new UnsafeContract(contractInstance!, artifact!, wallet);
15
- }
16
-
17
- /** Returns a Contract wrapper for the contract instance registry. */
18
- export async function getInstanceRegistryContract(wallet: Wallet) {
19
- const { contractInstance } = await wallet.getContractMetadata(ProtocolContractAddress.ContractInstanceRegistry);
20
- if (!contractInstance) {
21
- throw new Error("ContractInstanceRegistry is not registered in this wallet's instance");
22
- }
23
- const { artifact } = await wallet.getContractClassMetadata(contractInstance.currentContractClassId, true);
24
- return new UnsafeContract(contractInstance!, artifact!, wallet);
25
- }
26
-
27
- /** Returns a Contract wrapper for the fee juice contract */
28
- export async function getFeeJuice(wallet: Wallet) {
29
- const { contractInstance } = await wallet.getContractMetadata(ProtocolContractAddress.FeeJuice);
30
- if (!contractInstance) {
31
- throw new Error("FeeJuice is not registered in this wallet's instance");
32
- }
33
- const { artifact } = await wallet.getContractClassMetadata(contractInstance.currentContractClassId, true);
34
- return new UnsafeContract(contractInstance!, artifact!, wallet);
35
- }
@@ -1,130 +0,0 @@
1
- import { promiseWithResolvers } from '@aztec/foundation/promise';
2
- import { retryUntil } from '@aztec/foundation/retry';
3
- import type { FieldsOf } from '@aztec/foundation/types';
4
- import type { AztecNode } from '@aztec/stdlib/interfaces/client';
5
- import { TxHash, type TxReceipt, TxStatus } from '@aztec/stdlib/tx';
6
-
7
- import type { Wallet } from '../wallet/wallet.js';
8
-
9
- /** Options related to waiting for a tx. */
10
- export type WaitOpts = {
11
- /** The amount of time to ignore TxStatus.DROPPED receipts (in seconds) due to the presumption that it is being propagated by the p2p network. Defaults to 5. */
12
- ignoreDroppedReceiptsFor?: number;
13
- /** The maximum time (in seconds) to wait for the transaction to be mined. Defaults to 60. */
14
- timeout?: number;
15
- /** The time interval (in seconds) between retries to fetch the transaction receipt. Defaults to 1. */
16
- interval?: number;
17
- /** Whether to accept a revert as a status code for the tx when waiting for it. If false, will throw if the tx reverts. */
18
- dontThrowOnRevert?: boolean;
19
- };
20
-
21
- export const DefaultWaitOpts: WaitOpts = {
22
- ignoreDroppedReceiptsFor: 5,
23
- timeout: 60,
24
- interval: 1,
25
- };
26
-
27
- /**
28
- * The SentTx class represents a sent transaction through the PXE (or directly to a node) providing methods to fetch
29
- * its hash, receipt, and mining status.
30
- */
31
- export class SentTx {
32
- protected sendTxPromise: Promise<void>;
33
- protected sendTxError?: Error;
34
- protected txHash?: TxHash;
35
-
36
- constructor(
37
- protected walletOrNode: Wallet | AztecNode,
38
- sendTx: () => Promise<TxHash>,
39
- ) {
40
- const { promise, resolve } = promiseWithResolvers<void>();
41
- this.sendTxPromise = promise;
42
- sendTx()
43
- .then(txHash => {
44
- this.txHash = txHash;
45
- resolve();
46
- })
47
- .catch(err => {
48
- this.sendTxError = err;
49
- // Calling resolve instead of reject here because we want to throw the error when getTxHash is called.
50
- resolve();
51
- });
52
- }
53
-
54
- /**
55
- * Retrieves the transaction hash of the SentTx instance.
56
- * The function internally awaits for the 'txHashPromise' to resolve, and then returns the resolved transaction hash.
57
- *
58
- * @returns A promise that resolves to the transaction hash of the SentTx instance.
59
- * TODO(#7717): Don't throw here.
60
- */
61
- public async getTxHash(): Promise<TxHash> {
62
- // Make sure sendTx has been resolved, which can be triggered when it returns a txHash or when it throws an error.
63
- await this.sendTxPromise;
64
-
65
- // If sendTx threw an error, throw it.
66
- if (this.sendTxError) {
67
- throw this.sendTxError;
68
- }
69
-
70
- // sendTx returned a txHash if it's been resolved and no error was set.
71
- return Promise.resolve(this.txHash!);
72
- }
73
-
74
- /**
75
- * Retrieve the transaction receipt associated with the current SentTx instance.
76
- * The function fetches the transaction hash using 'getTxHash' and then queries
77
- * the PXE to get the corresponding transaction receipt.
78
- *
79
- * @returns A promise that resolves to a TxReceipt object representing the fetched transaction receipt.
80
- */
81
- public async getReceipt(): Promise<TxReceipt> {
82
- const txHash = await this.getTxHash();
83
- return await this.walletOrNode.getTxReceipt(txHash);
84
- }
85
-
86
- /**
87
- * Awaits for a tx to be mined and returns the receipt. Throws if tx is not mined.
88
- * @param opts - Options for configuring the waiting for the tx to be mined.
89
- * @returns The transaction receipt.
90
- */
91
- public async wait(opts?: WaitOpts): Promise<FieldsOf<TxReceipt>> {
92
- const receipt = await this.waitForReceipt(opts);
93
- if (receipt.status !== TxStatus.SUCCESS && !opts?.dontThrowOnRevert) {
94
- throw new Error(
95
- `Transaction ${(await this.getTxHash()).toString()} was ${receipt.status}. Reason: ${receipt.error ?? 'unknown'}`,
96
- );
97
- }
98
- return receipt;
99
- }
100
-
101
- protected async waitForReceipt(opts?: WaitOpts): Promise<TxReceipt> {
102
- const txHash = await this.getTxHash();
103
- const startTime = Date.now();
104
- const ignoreDroppedReceiptsFor = opts?.ignoreDroppedReceiptsFor ?? DefaultWaitOpts.ignoreDroppedReceiptsFor;
105
-
106
- return await retryUntil(
107
- async () => {
108
- const txReceipt = await this.walletOrNode.getTxReceipt(txHash);
109
- // If receipt is not yet available, try again
110
- if (txReceipt.status === TxStatus.PENDING) {
111
- return undefined;
112
- }
113
- // If the tx was "dropped", either return it or ignore based on timing.
114
- // We can ignore it at first because the transaction may have been sent to node 1, and now we're asking node 2 for the receipt.
115
- // If we don't allow a short grace period, we could incorrectly return a TxReceipt with status DROPPED.
116
- if (txReceipt.status === TxStatus.DROPPED) {
117
- const elapsedSeconds = (Date.now() - startTime) / 1000;
118
- if (!ignoreDroppedReceiptsFor || elapsedSeconds > ignoreDroppedReceiptsFor) {
119
- return txReceipt;
120
- }
121
- return undefined;
122
- }
123
- return txReceipt;
124
- },
125
- 'isMined',
126
- opts?.timeout ?? DefaultWaitOpts.timeout,
127
- opts?.interval ?? DefaultWaitOpts.interval,
128
- );
129
- }
130
- }
@@ -1,19 +0,0 @@
1
- import type { ContractArtifact } from '@aztec/stdlib/abi';
2
- import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
3
-
4
- import type { Wallet } from '../wallet/wallet.js';
5
- import { ContractBase } from './contract_base.js';
6
-
7
- /** Unsafe constructor for ContractBase that bypasses the check that the instance is registered in the wallet. */
8
- export class UnsafeContract extends ContractBase {
9
- constructor(
10
- /** The deployed contract instance definition. */
11
- instance: ContractInstanceWithAddress,
12
- /** The Application Binary Interface for the contract. */
13
- artifact: ContractArtifact,
14
- /** The wallet used for interacting with this contract. */
15
- wallet: Wallet,
16
- ) {
17
- super(instance, artifact, wallet);
18
- }
19
- }
@@ -1,350 +0,0 @@
1
- import {
2
- GAS_ESTIMATION_DA_GAS_LIMIT,
3
- GAS_ESTIMATION_L2_GAS_LIMIT,
4
- GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT,
5
- GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT,
6
- } from '@aztec/constants';
7
- import { AccountFeePaymentMethodOptions, type DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
8
- import type { ChainInfo } from '@aztec/entrypoints/interfaces';
9
- import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/entrypoints/payload';
10
- import { Fr } from '@aztec/foundation/fields';
11
- import { createLogger } from '@aztec/foundation/log';
12
- import type { ContractArtifact, EventMetadataDefinition } from '@aztec/stdlib/abi';
13
- import type { AuthWitness } from '@aztec/stdlib/auth-witness';
14
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
15
- import {
16
- type ContractClassMetadata,
17
- type ContractInstanceWithAddress,
18
- type ContractInstantiationData,
19
- type ContractMetadata,
20
- computePartialAddress,
21
- getContractClassFromArtifact,
22
- getContractInstanceFromInstantiationParams,
23
- } from '@aztec/stdlib/contract';
24
- import { SimulationError } from '@aztec/stdlib/errors';
25
- import { Gas, GasSettings } from '@aztec/stdlib/gas';
26
- import type { AztecNode } from '@aztec/stdlib/interfaces/client';
27
- import type {
28
- TxExecutionRequest,
29
- TxHash,
30
- TxProfileResult,
31
- TxReceipt,
32
- TxSimulationResult,
33
- UtilitySimulationResult,
34
- } from '@aztec/stdlib/tx';
35
-
36
- import { inspect } from 'util';
37
-
38
- import type { Account } from '../account/account.js';
39
- import type { FeePaymentMethod } from '../fee/fee_payment_method.js';
40
- import type { CallIntent, IntentInnerHash } from '../utils/authwit.js';
41
- import type {
42
- Aliased,
43
- BatchResults,
44
- BatchableMethods,
45
- BatchedMethod,
46
- ContractInstanceAndArtifact,
47
- ProfileOptions,
48
- SendOptions,
49
- SimulateOptions,
50
- UserFeeOptions,
51
- Wallet,
52
- } from './wallet.js';
53
-
54
- /**
55
- * Options to configure fee payment for a transaction
56
- */
57
- export type FeeOptions = {
58
- /**
59
- * A wallet-provided fallback fee payment method that is used only if the transaction that is being constructed
60
- * doesn't already include one
61
- */
62
- walletFeePaymentMethod?: FeePaymentMethod;
63
- /** Configuration options for the account to properly handle the selected fee payment method */
64
- accountFeePaymentMethodOptions: AccountFeePaymentMethodOptions;
65
- /** The gas settings to use for the transaction */
66
- gasSettings: GasSettings;
67
- };
68
-
69
- /**
70
- * A base class for Wallet implementations
71
- */
72
- export abstract class BaseWallet implements Wallet {
73
- protected log = createLogger('aztecjs:base_wallet');
74
-
75
- protected baseFeePadding = 0.5;
76
- protected cancellableTransactions = false;
77
-
78
- // Protected because we want to force wallets to instantiate their own PXE.
79
- protected constructor(
80
- // TODO: We cannot type here pxe because we cannot import that package as that would result in a circular
81
- // dependency. This will eventually get resolved by the introduction of @aztec/wallet-sdk package.
82
- protected readonly pxe: any,
83
- protected readonly aztecNode: AztecNode,
84
- ) {}
85
-
86
- protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
87
-
88
- abstract getAccounts(): Promise<Aliased<AztecAddress>[]>;
89
-
90
- /**
91
- * Returns the list of aliased contacts associated with the wallet.
92
- * This base implementation directly returns PXE's senders, but note that in general contacts are a superset of senders.
93
- * - Senders: Addresses we check during synching in case they sent us notes,
94
- * - Contacts: more general concept akin to a phone's contact list.
95
- * @returns The aliased collection of AztecAddresses that form this wallet's address book
96
- */
97
- async getAddressBook(): Promise<Aliased<AztecAddress>[]> {
98
- const senders: AztecAddress[] = await this.pxe.getSenders();
99
- return senders.map(sender => ({ item: sender, alias: '' }));
100
- }
101
-
102
- async getChainInfo(): Promise<ChainInfo> {
103
- const { l1ChainId, rollupVersion } = await this.aztecNode.getNodeInfo();
104
- return { chainId: new Fr(l1ChainId), version: new Fr(rollupVersion) };
105
- }
106
-
107
- protected async createTxExecutionRequestFromPayloadAndFee(
108
- executionPayload: ExecutionPayload,
109
- from: AztecAddress,
110
- feeOptions: FeeOptions,
111
- ): Promise<TxExecutionRequest> {
112
- const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
113
- const executionOptions: DefaultAccountEntrypointOptions = {
114
- txNonce: Fr.random(),
115
- cancellable: this.cancellableTransactions,
116
- feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
117
- };
118
- const finalExecutionPayload = feeExecutionPayload
119
- ? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
120
- : executionPayload;
121
- const fromAccount = await this.getAccountFromAddress(from);
122
- return fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, executionOptions);
123
- }
124
-
125
- public async createAuthWit(
126
- from: AztecAddress,
127
- messageHashOrIntent: Fr | Buffer | IntentInnerHash | CallIntent,
128
- ): Promise<AuthWitness> {
129
- const account = await this.getAccountFromAddress(from);
130
- return account.createAuthWit(messageHashOrIntent);
131
- }
132
-
133
- public async batch<const T extends readonly BatchedMethod<keyof BatchableMethods>[]>(
134
- methods: T,
135
- ): Promise<BatchResults<T>> {
136
- const results: any[] = [];
137
- for (const method of methods) {
138
- const { name, args } = method;
139
- // Type safety is guaranteed by the BatchedMethod type, which ensures that:
140
- // 1. `name` is a valid batchable method name
141
- // 2. `args` matches the parameter types of that specific method
142
- // 3. The return type is correctly mapped in BatchResults<T>
143
- // We use dynamic dispatch here for simplicity, but the types are enforced at the call site.
144
-
145
- const fn = this[name] as (...args: any[]) => Promise<any>;
146
- const result = await fn.apply(this, args);
147
- // Wrap result with method name for discriminated union deserialization
148
- results.push({ name, result });
149
- }
150
- return results as BatchResults<T>;
151
- }
152
-
153
- /**
154
- * Returns default values for the transaction fee options
155
- * if they were omitted by the user.
156
- * @param from - The address where the transaction is being sent from
157
- * @param userFeeOptions - User-provided fee options, which might be incomplete
158
- * @returns - Populated fee options that can be used to create a transaction execution request
159
- */
160
- protected async getDefaultFeeOptions(from: AztecAddress, userFeeOptions?: UserFeeOptions): Promise<FeeOptions> {
161
- const maxFeesPerGas =
162
- userFeeOptions?.gasSettings?.maxFeesPerGas ??
163
- (await this.aztecNode.getCurrentBaseFees()).mul(1 + this.baseFeePadding);
164
- let accountFeePaymentMethodOptions;
165
- // The transaction does not include a fee payment method, so we set the flag
166
- // for the account to use its fee juice balance
167
- if (!userFeeOptions?.embeddedPaymentMethodFeePayer) {
168
- accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE;
169
- } else {
170
- // The transaction includes fee payment method, so we check if we are the fee payer for it
171
- // (this can only happen if the embedded payment method is FeeJuiceWithClaim)
172
- accountFeePaymentMethodOptions = from.equals(userFeeOptions.embeddedPaymentMethodFeePayer)
173
- ? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM
174
- : AccountFeePaymentMethodOptions.EXTERNAL;
175
- }
176
- const gasSettings: GasSettings = GasSettings.default({ ...userFeeOptions?.gasSettings, maxFeesPerGas });
177
- this.log.debug(`Using L2 gas settings`, gasSettings);
178
- return {
179
- gasSettings,
180
- walletFeePaymentMethod: undefined,
181
- accountFeePaymentMethodOptions,
182
- };
183
- }
184
-
185
- /**
186
- * Returns unreasonably high gas limits in order to execute a simulation
187
- * with the goal of estimating its gas cost. It will otherwise try to respect
188
- * the user-specified fee options, filling the gaps with default values as needed.
189
- * @param from - The address where the transaction is being sent from
190
- * @param userFeeOptions - User-provided fee options to use as a basis for the fully populated `FeeOptions` type.
191
- */
192
- protected async getFeeOptionsForGasEstimation(from: AztecAddress, userFeeOptions?: UserFeeOptions) {
193
- const defaultFeeOptions = await this.getDefaultFeeOptions(from, userFeeOptions);
194
- const {
195
- gasSettings: { maxFeesPerGas, maxPriorityFeesPerGas },
196
- } = defaultFeeOptions;
197
- // Use unrealistically high gas limits for estimation to avoid running out of gas.
198
- // They will be tuned down after the simulation.
199
- const gasSettingsForEstimation = new GasSettings(
200
- new Gas(GAS_ESTIMATION_DA_GAS_LIMIT, GAS_ESTIMATION_L2_GAS_LIMIT),
201
- new Gas(GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT),
202
- maxFeesPerGas,
203
- maxPriorityFeesPerGas,
204
- );
205
- return {
206
- ...defaultFeeOptions,
207
- gasSettings: gasSettingsForEstimation,
208
- };
209
- }
210
-
211
- registerSender(address: AztecAddress, _alias: string = ''): Promise<AztecAddress> {
212
- return this.pxe.registerSender(address);
213
- }
214
-
215
- async registerContract(
216
- instanceData: AztecAddress | ContractInstanceWithAddress | ContractInstantiationData | ContractInstanceAndArtifact,
217
- artifact?: ContractArtifact,
218
- secretKey?: Fr,
219
- ): Promise<ContractInstanceWithAddress> {
220
- /** Determines if the provided instance data is already a contract instance with an address. */
221
- function isInstanceWithAddress(instanceData: any): instanceData is ContractInstanceWithAddress {
222
- return (instanceData as ContractInstanceWithAddress).address !== undefined;
223
- }
224
- /** Determines if the provided instance data is contract instantiation data */
225
- function isContractInstantiationData(instanceData: any): instanceData is ContractInstantiationData {
226
- return (instanceData as ContractInstantiationData).salt !== undefined;
227
- }
228
- /** Determines if the provided instance data is already a contract */
229
- function isContractInstanceAndArtifact(instanceData: any): instanceData is ContractInstanceAndArtifact {
230
- return (
231
- (instanceData as ContractInstanceAndArtifact).instance !== undefined &&
232
- (instanceData as ContractInstanceAndArtifact).artifact !== undefined
233
- );
234
- }
235
- let instance: ContractInstanceWithAddress;
236
- if (isContractInstanceAndArtifact(instanceData)) {
237
- instance = instanceData.instance;
238
- await this.pxe.registerContract(instanceData);
239
- } else if (isInstanceWithAddress(instanceData)) {
240
- instance = instanceData;
241
- await this.pxe.registerContract({ artifact, instance });
242
- } else if (isContractInstantiationData(instanceData)) {
243
- if (!artifact) {
244
- throw new Error(`Contract artifact must be provided when registering a contract using instantiation data`);
245
- }
246
- instance = await getContractInstanceFromInstantiationParams(artifact, instanceData);
247
- await this.pxe.registerContract({ artifact, instance });
248
- } else {
249
- if (!artifact) {
250
- throw new Error(`Contract artifact must be provided when registering a contract using an address`);
251
- }
252
- const { contractInstance: maybeContractInstance } = await this.pxe.getContractMetadata(instanceData);
253
- if (!maybeContractInstance) {
254
- throw new Error(`Contract instance at ${instanceData.toString()} has not been registered in the wallet's PXE`);
255
- }
256
- instance = maybeContractInstance;
257
- const thisContractClass = await getContractClassFromArtifact(artifact);
258
- if (!thisContractClass.id.equals(instance.currentContractClassId)) {
259
- // wallet holds an outdated version of this contract
260
- await this.pxe.updateContract(instance.address, artifact);
261
- instance.currentContractClassId = thisContractClass.id;
262
- }
263
- }
264
- if (secretKey) {
265
- await this.pxe.registerAccount(secretKey, await computePartialAddress(instance));
266
- }
267
- return instance;
268
- }
269
-
270
- async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
271
- const feeOptions = opts.fee?.estimateGas
272
- ? await this.getFeeOptionsForGasEstimation(opts.from, opts.fee)
273
- : await this.getDefaultFeeOptions(opts.from, opts.fee);
274
- const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
275
- return this.pxe.simulateTx(
276
- txRequest,
277
- true /* simulatePublic */,
278
- opts?.skipTxValidation,
279
- opts?.skipFeeEnforcement ?? true,
280
- );
281
- }
282
-
283
- async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
284
- const fee = await this.getDefaultFeeOptions(opts.from, opts.fee);
285
- const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, fee);
286
- return this.pxe.profileTx(txRequest, opts.profileMode, opts.skipProofGeneration ?? true);
287
- }
288
-
289
- async sendTx(executionPayload: ExecutionPayload, opts: SendOptions): Promise<TxHash> {
290
- const fee = await this.getDefaultFeeOptions(opts.from, opts.fee);
291
- const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, fee);
292
- const provenTx = await this.pxe.proveTx(txRequest);
293
- const tx = await provenTx.toTx();
294
- const txHash = tx.getTxHash();
295
- if (await this.aztecNode.getTxEffect(txHash)) {
296
- throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
297
- }
298
- this.log.debug(`Sending transaction ${txHash}`);
299
- await this.aztecNode.sendTx(tx).catch(err => {
300
- throw this.contextualizeError(err, inspect(tx));
301
- });
302
- this.log.info(`Sent transaction ${txHash}`);
303
- return txHash;
304
- }
305
-
306
- protected contextualizeError(err: Error, ...context: string[]): Error {
307
- let contextStr = '';
308
- if (context.length > 0) {
309
- contextStr = `\nContext:\n${context.join('\n')}`;
310
- }
311
- if (err instanceof SimulationError) {
312
- err.setAztecContext(contextStr);
313
- } else {
314
- this.log.error(err.name, err);
315
- this.log.debug(contextStr);
316
- }
317
- return err;
318
- }
319
-
320
- simulateUtility(
321
- functionName: string,
322
- args: any[],
323
- to: AztecAddress,
324
- authwits?: AuthWitness[],
325
- from?: AztecAddress,
326
- ): Promise<UtilitySimulationResult> {
327
- return this.pxe.simulateUtility(functionName, args, to, authwits, from);
328
- }
329
-
330
- getContractClassMetadata(id: Fr, includeArtifact: boolean = false): Promise<ContractClassMetadata> {
331
- return this.pxe.getContractClassMetadata(id, includeArtifact);
332
- }
333
- getContractMetadata(address: AztecAddress): Promise<ContractMetadata> {
334
- return this.pxe.getContractMetadata(address);
335
- }
336
-
337
- getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
338
- return this.aztecNode.getTxReceipt(txHash);
339
- }
340
-
341
- getPrivateEvents<T>(
342
- contractAddress: AztecAddress,
343
- event: EventMetadataDefinition,
344
- from: number,
345
- limit: number,
346
- recipients: AztecAddress[] = [],
347
- ): Promise<T[]> {
348
- return this.pxe.getPrivateEvents(contractAddress, event, from, limit, recipients);
349
- }
350
- }