@aztec-labs/aztec.js 6.0.0-nightly.20260829

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 (275) hide show
  1. package/README.md +44 -0
  2. package/dest/account/account.d.ts +44 -0
  3. package/dest/account/account.d.ts.map +1 -0
  4. package/dest/account/account.js +31 -0
  5. package/dest/account/account_contract.d.ts +49 -0
  6. package/dest/account/account_contract.d.ts.map +1 -0
  7. package/dest/account/account_contract.js +20 -0
  8. package/dest/account/index.d.ts +11 -0
  9. package/dest/account/index.d.ts.map +1 -0
  10. package/dest/account/index.js +6 -0
  11. package/dest/api/abi.d.ts +4 -0
  12. package/dest/api/abi.d.ts.map +1 -0
  13. package/dest/api/abi.js +1 -0
  14. package/dest/api/account.d.ts +5 -0
  15. package/dest/api/account.d.ts.map +1 -0
  16. package/dest/api/account.js +3 -0
  17. package/dest/api/addresses.d.ts +4 -0
  18. package/dest/api/addresses.d.ts.map +1 -0
  19. package/dest/api/addresses.js +3 -0
  20. package/dest/api/authorization.d.ts +5 -0
  21. package/dest/api/authorization.d.ts.map +1 -0
  22. package/dest/api/authorization.js +4 -0
  23. package/dest/api/block.d.ts +3 -0
  24. package/dest/api/block.d.ts.map +1 -0
  25. package/dest/api/block.js +2 -0
  26. package/dest/api/contract.d.ts +48 -0
  27. package/dest/api/contract.d.ts.map +1 -0
  28. package/dest/api/contract.js +46 -0
  29. package/dest/api/crypto.d.ts +2 -0
  30. package/dest/api/crypto.d.ts.map +1 -0
  31. package/dest/api/crypto.js +1 -0
  32. package/dest/api/deployment.d.ts +4 -0
  33. package/dest/api/deployment.d.ts.map +1 -0
  34. package/dest/api/deployment.js +3 -0
  35. package/dest/api/eth_address.d.ts +2 -0
  36. package/dest/api/eth_address.d.ts.map +1 -0
  37. package/dest/api/eth_address.js +1 -0
  38. package/dest/api/ethereum.d.ts +2 -0
  39. package/dest/api/ethereum.d.ts.map +1 -0
  40. package/dest/api/ethereum.js +1 -0
  41. package/dest/api/event_cursor.d.ts +44 -0
  42. package/dest/api/event_cursor.d.ts.map +1 -0
  43. package/dest/api/event_cursor.js +42 -0
  44. package/dest/api/events.d.ts +36 -0
  45. package/dest/api/events.d.ts.map +1 -0
  46. package/dest/api/events.js +59 -0
  47. package/dest/api/fee.d.ts +6 -0
  48. package/dest/api/fee.d.ts.map +1 -0
  49. package/dest/api/fee.js +4 -0
  50. package/dest/api/fee_testing.d.ts +2 -0
  51. package/dest/api/fee_testing.d.ts.map +1 -0
  52. package/dest/api/fee_testing.js +1 -0
  53. package/dest/api/fields.d.ts +4 -0
  54. package/dest/api/fields.d.ts.map +1 -0
  55. package/dest/api/fields.js +3 -0
  56. package/dest/api/keys.d.ts +4 -0
  57. package/dest/api/keys.d.ts.map +1 -0
  58. package/dest/api/keys.js +3 -0
  59. package/dest/api/log.d.ts +3 -0
  60. package/dest/api/log.d.ts.map +1 -0
  61. package/dest/api/log.js +2 -0
  62. package/dest/api/messaging.d.ts +3 -0
  63. package/dest/api/messaging.d.ts.map +1 -0
  64. package/dest/api/messaging.js +2 -0
  65. package/dest/api/node.d.ts +25 -0
  66. package/dest/api/node.d.ts.map +1 -0
  67. package/dest/api/node.js +22 -0
  68. package/dest/api/note.d.ts +2 -0
  69. package/dest/api/note.d.ts.map +1 -0
  70. package/dest/api/note.js +1 -0
  71. package/dest/api/protocol.d.ts +6 -0
  72. package/dest/api/protocol.d.ts.map +1 -0
  73. package/dest/api/protocol.js +5 -0
  74. package/dest/api/trees.d.ts +3 -0
  75. package/dest/api/trees.d.ts.map +1 -0
  76. package/dest/api/trees.js +2 -0
  77. package/dest/api/tx.d.ts +3 -0
  78. package/dest/api/tx.d.ts.map +1 -0
  79. package/dest/api/tx.js +1 -0
  80. package/dest/api/utils.d.ts +13 -0
  81. package/dest/api/utils.d.ts.map +1 -0
  82. package/dest/api/utils.js +12 -0
  83. package/dest/api/wallet.d.ts +8 -0
  84. package/dest/api/wallet.d.ts.map +1 -0
  85. package/dest/api/wallet.js +7 -0
  86. package/dest/authorization/call_authorization_request.d.ts +46 -0
  87. package/dest/authorization/call_authorization_request.d.ts.map +1 -0
  88. package/dest/authorization/call_authorization_request.js +72 -0
  89. package/dest/contract/base_contract_interaction.d.ts +32 -0
  90. package/dest/contract/base_contract_interaction.d.ts.map +1 -0
  91. package/dest/contract/base_contract_interaction.js +24 -0
  92. package/dest/contract/batch_call.d.ts +27 -0
  93. package/dest/contract/batch_call.d.ts.map +1 -0
  94. package/dest/contract/batch_call.js +152 -0
  95. package/dest/contract/checker.d.ts +11 -0
  96. package/dest/contract/checker.d.ts.map +1 -0
  97. package/dest/contract/checker.js +107 -0
  98. package/dest/contract/contract.d.ts +33 -0
  99. package/dest/contract/contract.d.ts.map +1 -0
  100. package/dest/contract/contract.js +36 -0
  101. package/dest/contract/contract_base.d.ts +51 -0
  102. package/dest/contract/contract_base.d.ts.map +1 -0
  103. package/dest/contract/contract_base.js +38 -0
  104. package/dest/contract/contract_function_interaction.d.ts +67 -0
  105. package/dest/contract/contract_function_interaction.d.ts.map +1 -0
  106. package/dest/contract/contract_function_interaction.js +218 -0
  107. package/dest/contract/deploy_method.d.ts +433 -0
  108. package/dest/contract/deploy_method.d.ts.map +1 -0
  109. package/dest/contract/deploy_method.js +471 -0
  110. package/dest/contract/fastforward_contract_update.d.ts +25 -0
  111. package/dest/contract/fastforward_contract_update.d.ts.map +1 -0
  112. package/dest/contract/fastforward_contract_update.js +57 -0
  113. package/dest/contract/interaction_options.d.ts +213 -0
  114. package/dest/contract/interaction_options.d.ts.map +1 -0
  115. package/dest/contract/interaction_options.js +87 -0
  116. package/dest/contract/protocol_contracts/contract-class-registry.d.ts +18 -0
  117. package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -0
  118. package/dest/contract/protocol_contracts/contract-class-registry.js +137 -0
  119. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +25 -0
  120. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -0
  121. package/dest/contract/protocol_contracts/contract-instance-registry.js +366 -0
  122. package/dest/contract/protocol_contracts/fee-juice.d.ts +24 -0
  123. package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -0
  124. package/dest/contract/protocol_contracts/fee-juice.js +383 -0
  125. package/dest/contract/wait_for_proven.d.ts +18 -0
  126. package/dest/contract/wait_for_proven.d.ts.map +1 -0
  127. package/dest/contract/wait_for_proven.js +17 -0
  128. package/dest/contract/wait_opts.d.ts +21 -0
  129. package/dest/contract/wait_opts.d.ts.map +1 -0
  130. package/dest/contract/wait_opts.js +5 -0
  131. package/dest/deployment/contract_deployer.d.ts +28 -0
  132. package/dest/deployment/contract_deployer.d.ts.map +1 -0
  133. package/dest/deployment/contract_deployer.js +35 -0
  134. package/dest/deployment/publish_class.d.ts +6 -0
  135. package/dest/deployment/publish_class.d.ts.map +1 -0
  136. package/dest/deployment/publish_class.js +17 -0
  137. package/dest/deployment/publish_instance.d.ts +10 -0
  138. package/dest/deployment/publish_instance.d.ts.map +1 -0
  139. package/dest/deployment/publish_instance.js +11 -0
  140. package/dest/ethereum/portal_manager.d.ts +146 -0
  141. package/dest/ethereum/portal_manager.d.ts.map +1 -0
  142. package/dest/ethereum/portal_manager.js +415 -0
  143. package/dest/fee/fee_juice_payment_method_with_claim.d.ts +23 -0
  144. package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -0
  145. package/dest/fee/fee_juice_payment_method_with_claim.js +46 -0
  146. package/dest/fee/fee_payment_method.d.ts +26 -0
  147. package/dest/fee/fee_payment_method.d.ts.map +1 -0
  148. package/dest/fee/fee_payment_method.js +3 -0
  149. package/dest/fee/private_fee_payment_method.d.ts +69 -0
  150. package/dest/fee/private_fee_payment_method.d.ts.map +1 -0
  151. package/dest/fee/private_fee_payment_method.js +122 -0
  152. package/dest/fee/public_fee_payment_method.d.ts +59 -0
  153. package/dest/fee/public_fee_payment_method.d.ts.map +1 -0
  154. package/dest/fee/public_fee_payment_method.js +116 -0
  155. package/dest/fee/sponsored_fee_payment.d.ts +17 -0
  156. package/dest/fee/sponsored_fee_payment.d.ts.map +1 -0
  157. package/dest/fee/sponsored_fee_payment.js +33 -0
  158. package/dest/scripts/generate_protocol_contract_types.d.ts +2 -0
  159. package/dest/scripts/generate_protocol_contract_types.d.ts.map +1 -0
  160. package/dest/scripts/generate_protocol_contract_types.js +128 -0
  161. package/dest/test/fixtures.d.ts +13 -0
  162. package/dest/test/fixtures.d.ts.map +1 -0
  163. package/dest/test/fixtures.js +185 -0
  164. package/dest/utils/abi_types.d.ts +32 -0
  165. package/dest/utils/abi_types.d.ts.map +1 -0
  166. package/dest/utils/abi_types.js +1 -0
  167. package/dest/utils/authwit.d.ts +119 -0
  168. package/dest/utils/authwit.d.ts.map +1 -0
  169. package/dest/utils/authwit.js +266 -0
  170. package/dest/utils/cross_chain.d.ts +28 -0
  171. package/dest/utils/cross_chain.d.ts.map +1 -0
  172. package/dest/utils/cross_chain.js +26 -0
  173. package/dest/utils/fee_juice.d.ts +8 -0
  174. package/dest/utils/fee_juice.d.ts.map +1 -0
  175. package/dest/utils/fee_juice.js +10 -0
  176. package/dest/utils/field_compressed_string.d.ts +17 -0
  177. package/dest/utils/field_compressed_string.d.ts.map +1 -0
  178. package/dest/utils/field_compressed_string.js +15 -0
  179. package/dest/utils/node.d.ts +24 -0
  180. package/dest/utils/node.d.ts.map +1 -0
  181. package/dest/utils/node.js +80 -0
  182. package/dest/utils/pub_key.d.ts +9 -0
  183. package/dest/utils/pub_key.d.ts.map +1 -0
  184. package/dest/utils/pub_key.js +8 -0
  185. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts +33 -0
  186. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts.map +1 -0
  187. package/dest/wallet/account_entrypoint_meta_payment_method.js +63 -0
  188. package/dest/wallet/account_manager.d.ts +73 -0
  189. package/dest/wallet/account_manager.d.ts.map +1 -0
  190. package/dest/wallet/account_manager.js +102 -0
  191. package/dest/wallet/capabilities.d.ts +456 -0
  192. package/dest/wallet/capabilities.d.ts.map +1 -0
  193. package/dest/wallet/capabilities.js +3 -0
  194. package/dest/wallet/deploy_account_method.d.ts +97 -0
  195. package/dest/wallet/deploy_account_method.d.ts.map +1 -0
  196. package/dest/wallet/deploy_account_method.js +127 -0
  197. package/dest/wallet/index.d.ts +5 -0
  198. package/dest/wallet/index.d.ts.map +1 -0
  199. package/dest/wallet/index.js +4 -0
  200. package/dest/wallet/tx_simulation_result_with_app_offset.d.ts +40 -0
  201. package/dest/wallet/tx_simulation_result_with_app_offset.d.ts.map +1 -0
  202. package/dest/wallet/tx_simulation_result_with_app_offset.js +65 -0
  203. package/dest/wallet/wallet.d.ts +1451 -0
  204. package/dest/wallet/wallet.d.ts.map +1 -0
  205. package/dest/wallet/wallet.js +430 -0
  206. package/package.json +138 -0
  207. package/src/account/account.ts +72 -0
  208. package/src/account/account_contract.ts +80 -0
  209. package/src/account/index.ts +12 -0
  210. package/src/api/README.md +7 -0
  211. package/src/api/abi.ts +42 -0
  212. package/src/api/account.ts +12 -0
  213. package/src/api/addresses.ts +3 -0
  214. package/src/api/authorization.ts +15 -0
  215. package/src/api/block.ts +2 -0
  216. package/src/api/contract.ts +86 -0
  217. package/src/api/crypto.ts +1 -0
  218. package/src/api/deployment.ts +3 -0
  219. package/src/api/eth_address.ts +1 -0
  220. package/src/api/ethereum.ts +10 -0
  221. package/src/api/event_cursor.ts +60 -0
  222. package/src/api/events.ts +79 -0
  223. package/src/api/fee.ts +5 -0
  224. package/src/api/fee_testing.ts +1 -0
  225. package/src/api/fields.ts +3 -0
  226. package/src/api/keys.ts +8 -0
  227. package/src/api/log.ts +2 -0
  228. package/src/api/messaging.ts +2 -0
  229. package/src/api/node.ts +30 -0
  230. package/src/api/note.ts +1 -0
  231. package/src/api/protocol.ts +6 -0
  232. package/src/api/trees.ts +2 -0
  233. package/src/api/tx.ts +20 -0
  234. package/src/api/utils.ts +14 -0
  235. package/src/api/wallet.ts +83 -0
  236. package/src/authorization/call_authorization_request.ts +93 -0
  237. package/src/contract/base_contract_interaction.ts +62 -0
  238. package/src/contract/batch_call.ts +188 -0
  239. package/src/contract/checker.ts +122 -0
  240. package/src/contract/contract.ts +52 -0
  241. package/src/contract/contract_base.ts +73 -0
  242. package/src/contract/contract_function_interaction.ts +297 -0
  243. package/src/contract/deploy_method.ts +877 -0
  244. package/src/contract/fastforward_contract_update.ts +71 -0
  245. package/src/contract/interaction_options.ts +301 -0
  246. package/src/contract/protocol_contracts/contract-class-registry.ts +104 -0
  247. package/src/contract/protocol_contracts/contract-instance-registry.ts +241 -0
  248. package/src/contract/protocol_contracts/fee-juice.ts +257 -0
  249. package/src/contract/wait_for_proven.ts +43 -0
  250. package/src/contract/wait_opts.ts +26 -0
  251. package/src/deployment/contract_deployer.ts +40 -0
  252. package/src/deployment/publish_class.ts +34 -0
  253. package/src/deployment/publish_instance.ts +24 -0
  254. package/src/ethereum/portal_manager.ts +539 -0
  255. package/src/fee/fee_juice_payment_method_with_claim.ts +63 -0
  256. package/src/fee/fee_payment_method.ts +26 -0
  257. package/src/fee/private_fee_payment_method.ts +145 -0
  258. package/src/fee/public_fee_payment_method.ts +145 -0
  259. package/src/fee/sponsored_fee_payment.ts +45 -0
  260. package/src/scripts/generate_protocol_contract_types.ts +160 -0
  261. package/src/test/fixtures.ts +126 -0
  262. package/src/utils/abi_types.ts +32 -0
  263. package/src/utils/authwit.ts +327 -0
  264. package/src/utils/cross_chain.ts +55 -0
  265. package/src/utils/fee_juice.ts +14 -0
  266. package/src/utils/field_compressed_string.ts +27 -0
  267. package/src/utils/node.ts +110 -0
  268. package/src/utils/pub_key.ts +12 -0
  269. package/src/wallet/account_entrypoint_meta_payment_method.ts +76 -0
  270. package/src/wallet/account_manager.ts +164 -0
  271. package/src/wallet/capabilities.ts +505 -0
  272. package/src/wallet/deploy_account_method.ts +234 -0
  273. package/src/wallet/index.ts +4 -0
  274. package/src/wallet/tx_simulation_result_with_app_offset.ts +100 -0
  275. package/src/wallet/wallet.ts +668 -0
@@ -0,0 +1,26 @@
1
+ import { retryUntil } from '@aztec-labs/foundation/retry';
2
+ /**
3
+ * Waits for the L1 to L2 message to be ready to be consumed.
4
+ * @param node - Aztec node instance used to obtain the information about the message
5
+ * @param l1ToL2MessageHash - Hash of the L1 to L2 message
6
+ * @param opts - Options
7
+ */ export function waitForL1ToL2MessageReady(node, l1ToL2MessageHash, opts) {
8
+ return retryUntil(()=>isL1ToL2MessageReady(node, l1ToL2MessageHash, opts.chainTip), `L1 to L2 message ${l1ToL2MessageHash.toString()} ready`, opts.timeoutSeconds, 1);
9
+ }
10
+ /**
11
+ * Returns whether the L1 to L2 message is ready to be consumed.
12
+ * @param node - Aztec node instance used to obtain the information about the message
13
+ * @param l1ToL2MessageHash - Hash of the L1 to L2 message
14
+ * @param chainTip - Chain tip to evaluate readiness against. Defaults to `'latest'`. Pass the tip the consuming PXE
15
+ * syncs to (e.g. `'proven'`) so readiness is checked at the block the transaction simulation will anchor to.
16
+ * @returns True if the message is ready to be consumed, false otherwise
17
+ */ export async function isL1ToL2MessageReady(node, l1ToL2MessageHash, chainTip = 'latest') {
18
+ const messageIndex = await node.getL1ToL2MessageIndex(l1ToL2MessageHash);
19
+ if (messageIndex === undefined) {
20
+ return false;
21
+ }
22
+ // Blocks consume L1-to-L2 messages in Inbox order into consecutive leaves of the message tree, so the message is
23
+ // available at a tip exactly when that tip's tree has grown past the message's leaf index.
24
+ const block = await node.getBlockData(chainTip);
25
+ return block !== undefined && messageIndex < BigInt(block.header.state.l1ToL2MessageTree.nextAvailableLeafIndex);
26
+ }
@@ -0,0 +1,8 @@
1
+ import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
2
+ import type { AztecNode } from '@aztec-labs/stdlib/interfaces/client';
3
+ /**
4
+ * Returns the owner's fee juice balance.
5
+ * Note: This is used only e2e_local_network_example test. TODO: Consider nuking.
6
+ */
7
+ export declare function getFeeJuiceBalance(owner: AztecAddress, node: AztecNode): Promise<bigint>;
8
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmVlX2p1aWNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMvZmVlX2p1aWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLGtDQUFrQyxDQUFDO0FBRXJFLE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLHNDQUFzQyxDQUFDO0FBRXRFOzs7R0FHRztBQUNILHdCQUFzQixrQkFBa0IsQ0FBQyxLQUFLLEVBQUUsWUFBWSxFQUFFLElBQUksRUFBRSxTQUFTLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUc5RiJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fee_juice.d.ts","sourceRoot":"","sources":["../../src/utils/fee_juice.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAErE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAEtE;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAG9F"}
@@ -0,0 +1,10 @@
1
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
2
+ import { ProtocolContractAddress } from '@aztec-labs/protocol-contracts';
3
+ import { deriveStorageSlotInMap } from '@aztec-labs/stdlib/hash';
4
+ /**
5
+ * Returns the owner's fee juice balance.
6
+ * Note: This is used only e2e_local_network_example test. TODO: Consider nuking.
7
+ */ export async function getFeeJuiceBalance(owner, node) {
8
+ const slot = await deriveStorageSlotInMap(new Fr(1), owner);
9
+ return (await node.getPublicStorageAt('latest', ProtocolContractAddress.FeeJuice, slot)).toBigInt();
10
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The representation of a FieldCompressedString in aztec.nr
3
+ */
4
+ interface NoirFieldCompressedString {
5
+ /**
6
+ * The field value of the string
7
+ */
8
+ value: bigint;
9
+ }
10
+ /**
11
+ * This turns
12
+ * @param field - The field that contains the string
13
+ * @returns - the string that is decoded from the field
14
+ */
15
+ export declare const readFieldCompressedString: (field: NoirFieldCompressedString) => string;
16
+ export {};
17
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmllbGRfY29tcHJlc3NlZF9zdHJpbmcuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy9maWVsZF9jb21wcmVzc2VkX3N0cmluZy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQTs7R0FFRztBQUNILFVBQVUseUJBQXlCO0lBQ2pDOztPQUVHO0lBQ0gsS0FBSyxFQUFFLE1BQU0sQ0FBQztDQUNmO0FBQ0Q7Ozs7R0FJRztBQUNILGVBQU8sTUFBTSx5QkFBeUIsOENBVXJDLENBQUMifQ==
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field_compressed_string.d.ts","sourceRoot":"","sources":["../../src/utils/field_compressed_string.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,UAAU,yBAAyB;IACjC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AACD;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,8CAUrC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
2
+ /**
3
+ * This turns
4
+ * @param field - The field that contains the string
5
+ * @returns - the string that is decoded from the field
6
+ */ export const readFieldCompressedString = (field)=>{
7
+ const vals = Array.from(new Fr(field.value).toBuffer());
8
+ let str = '';
9
+ for(let i = 0; i < vals.length; i++){
10
+ if (vals[i] != 0) {
11
+ str += String.fromCharCode(Number(vals[i]));
12
+ }
13
+ }
14
+ return str;
15
+ };
@@ -0,0 +1,24 @@
1
+ import type { Logger } from '@aztec-labs/foundation/log';
2
+ import type { AztecNode } from '@aztec-labs/stdlib/interfaces/client';
3
+ import type { TxHash, TxReceipt } from '@aztec-labs/stdlib/tx';
4
+ import { type WaitOpts } from '../contract/wait_opts.js';
5
+ /**
6
+ * Waits for an Aztec node to become reachable, polling {@link AztecNode.getNodeInfo} until it succeeds.
7
+ * @param node - The Aztec node to contact.
8
+ * @param logger - Optional logger for polling progress.
9
+ * @param opts - Optional timeout and interval (in seconds). `timeout` defaults to {@link DefaultWaitOpts.timeout};
10
+ * pass `timeout: 0` to wait indefinitely.
11
+ * @throws TimeoutError if the node stays unreachable past the timeout.
12
+ */
13
+ export declare const waitForNode: (node: AztecNode, logger?: Logger | undefined, opts?: Pick<WaitOpts, "interval" | "timeout"> | undefined) => Promise<void>;
14
+ /**
15
+ * Waits for a transaction to be mined and returns its receipt.
16
+ * @param node - The Aztec node to query for transaction status
17
+ * @param txHash - The hash of the transaction to wait for
18
+ * @param opts - Optional configuration for waiting behavior
19
+ * @returns The transaction receipt
20
+ * @throws If the transaction fails and dontThrowOnRevert is not set
21
+ */
22
+ export declare function waitForTx(node: AztecNode, txHash: TxHash, opts?: WaitOpts): Promise<TxReceipt>;
23
+ export { createAztecNodeClient, type AztecNode, type AztecNodeClientOptions, } from '@aztec-labs/stdlib/interfaces/client';
24
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm9kZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWxzL25vZGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsTUFBTSxFQUFFLE1BQU0sNEJBQTRCLENBQUM7QUFHekQsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0sc0NBQXNDLENBQUM7QUFDdEUsT0FBTyxLQUFLLEVBQUUsTUFBTSxFQUFFL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import { sleep } from '@aztec-labs/foundation/sleep';
3
+ import { SortedTxStatuses, TxStatus } from '@aztec-labs/stdlib/tx';
4
+ import { DefaultWaitOpts } from '../contract/wait_opts.js';
5
+ /**
6
+ * Waits for an Aztec node to become reachable, polling {@link AztecNode.getNodeInfo} until it succeeds.
7
+ * @param node - The Aztec node to contact.
8
+ * @param logger - Optional logger for polling progress.
9
+ * @param opts - Optional timeout and interval (in seconds). `timeout` defaults to {@link DefaultWaitOpts.timeout};
10
+ * pass `timeout: 0` to wait indefinitely.
11
+ * @throws TimeoutError if the node stays unreachable past the timeout.
12
+ */ export const waitForNode = async (node, logger, opts)=>{
13
+ await retryUntil(async ()=>{
14
+ try {
15
+ logger?.verbose('Attempting to contact Aztec node...');
16
+ await node.getNodeInfo();
17
+ logger?.verbose('Contacted Aztec node');
18
+ return true;
19
+ } catch {
20
+ logger?.verbose('Failed to contact Aztec Node');
21
+ }
22
+ return undefined;
23
+ }, 'RPC Get Node Info', opts?.timeout ?? DefaultWaitOpts.timeout, opts?.interval ?? DefaultWaitOpts.interval);
24
+ };
25
+ /** Returns true if the receipt status is at least the desired status level. */ function hasReachedStatus(receipt, desiredStatus) {
26
+ return SortedTxStatuses.indexOf(receipt.status) >= SortedTxStatuses.indexOf(desiredStatus);
27
+ }
28
+ /**
29
+ * Waits for a transaction to be mined and returns its receipt.
30
+ * @param node - The Aztec node to query for transaction status
31
+ * @param txHash - The hash of the transaction to wait for
32
+ * @param opts - Optional configuration for waiting behavior
33
+ * @returns The transaction receipt
34
+ * @throws If the transaction fails and dontThrowOnRevert is not set
35
+ */ export async function waitForTx(node, txHash, opts) {
36
+ const ignoreDroppedReceiptsFor = opts?.ignoreDroppedReceiptsFor ?? DefaultWaitOpts.ignoreDroppedReceiptsFor;
37
+ const waitForStatus = opts?.waitForStatus ?? TxStatus.CHECKPOINTED;
38
+ const timeout = opts?.timeout ?? DefaultWaitOpts.timeout;
39
+ // The initial delay counts against the timeout: the deadline is fixed before sleeping, and the sleep never
40
+ // exceeds it.
41
+ const deadline = timeout ? {
42
+ deadline: new Date(Date.now() + timeout * 1000)
43
+ } : undefined;
44
+ if (opts?.initialDelay) {
45
+ const delay = Math.min(opts.initialDelay, timeout ?? Infinity);
46
+ await sleep(delay * 1000);
47
+ }
48
+ // The grace period for DROPPED receipts starts at the first poll, so the initial delay does not consume it.
49
+ const startTime = Date.now();
50
+ const receipt = await retryUntil(async ()=>{
51
+ const txReceipt = await node.getTxReceipt(txHash);
52
+ // If receipt is not yet available, try again
53
+ if (txReceipt.isPending()) {
54
+ return undefined;
55
+ }
56
+ // If the tx was "dropped", either return it or ignore based on timing.
57
+ // 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.
58
+ // If we don't allow a short grace period, we could incorrectly return a TxReceipt with status DROPPED.
59
+ if (txReceipt.isDropped()) {
60
+ const elapsedSeconds = (Date.now() - startTime) / 1000;
61
+ if (!ignoreDroppedReceiptsFor || elapsedSeconds > ignoreDroppedReceiptsFor) {
62
+ return txReceipt;
63
+ }
64
+ return undefined;
65
+ }
66
+ // Check if the receipt has reached the desired status level
67
+ if (!hasReachedStatus(txReceipt, waitForStatus)) {
68
+ return undefined;
69
+ }
70
+ return txReceipt;
71
+ }, 'isMined', deadline, opts?.interval ?? DefaultWaitOpts.interval);
72
+ if (!receipt.isMined()) {
73
+ throw new Error(`Transaction ${txHash.toString()} was ${receipt.status}. Reason: ${receipt.error ?? 'unknown'}`);
74
+ }
75
+ if (!receipt.hasExecutionSucceeded() && !opts?.dontThrowOnRevert) {
76
+ throw new Error(`Transaction ${txHash.toString()} reverted: ${receipt.executionResult}. Reason: ${receipt.error ?? 'unknown'}`);
77
+ }
78
+ return receipt;
79
+ }
80
+ export { createAztecNodeClient } from '@aztec-labs/stdlib/interfaces/client';
@@ -0,0 +1,9 @@
1
+ import type { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
2
+ import type { PublicKey } from '@aztec-labs/stdlib/keys';
3
+ /**
4
+ * Method for generating a public grumpkin key from a private key.
5
+ * @param privateKey - The private key.
6
+ * @returns The generated public key.
7
+ */
8
+ export declare function generatePublicKey(privateKey: GrumpkinScalar): Promise<PublicKey>;
9
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHViX2tleS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWxzL3B1Yl9rZXkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxLQUFLLEVBQUUsY0FBYyxFQUFFLE1BQU0sd0NBQXdDLENBQUM7QUFDN0UsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFFekQ7Ozs7R0FJRztBQUNILHdCQUFnQixpQkFBaUIsQ0FBQyxVQUFVLEVBQUUsY0FBYyxHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUMsQ0FFaEYifQ==
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pub_key.d.ts","sourceRoot":"","sources":["../../src/utils/pub_key.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,CAEhF"}
@@ -0,0 +1,8 @@
1
+ import { Grumpkin } from '@aztec-labs/foundation/crypto/grumpkin';
2
+ /**
3
+ * Method for generating a public grumpkin key from a private key.
4
+ * @param privateKey - The private key.
5
+ * @returns The generated public key.
6
+ */ export function generatePublicKey(privateKey) {
7
+ return Grumpkin.mul(Grumpkin.generator, privateKey);
8
+ }
@@ -0,0 +1,33 @@
1
+ import type { ChainInfo } from '@aztec-labs/entrypoints/interfaces';
2
+ import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
3
+ import type { GasSettings } from '@aztec-labs/stdlib/gas';
4
+ import { ExecutionPayload } from '@aztec-labs/stdlib/tx';
5
+ import type { Account } from '../account/account.js';
6
+ import type { FeePaymentMethod } from '../fee/fee_payment_method.js';
7
+ /**
8
+ * Fee payment method that allows an account contract to pay for its own deployment
9
+ * It works by rerouting the provided fee payment method through the account's entrypoint,
10
+ * which sets itself as fee payer. If no payment method is provided, it is assumed the
11
+ * account will pay with its own fee juice balance.
12
+ *
13
+ * Usually, in order to pay fees it is necessary to obtain an ExecutionPayload that encodes the necessary information
14
+ * that is sent to the user's account entrypoint, that has plumbing to handle it.
15
+ * If there's no account contract yet (it's being deployed) a MultiCallContract is used, which doesn't have a concept of fees or
16
+ * how to handle this payload.
17
+ * HOWEVER, the account contract's entrypoint does, so this method reshapes that fee payload into a call to the account contract entrypoint
18
+ * being deployed with the original fee payload.
19
+ *
20
+ * This class can be seen in action in DeployAccountMethod.ts#getSelfPaymentMethod
21
+ */
22
+ export declare class AccountEntrypointMetaPaymentMethod implements FeePaymentMethod {
23
+ private account;
24
+ private chainInfo;
25
+ private paymentMethod?;
26
+ private feeEntrypointOptions?;
27
+ constructor(account: Account, chainInfo: ChainInfo, paymentMethod?: FeePaymentMethod | undefined, feeEntrypointOptions?: any);
28
+ getAsset(): Promise<AztecAddress>;
29
+ getExecutionPayload(): Promise<ExecutionPayload>;
30
+ getFeePayer(): Promise<AztecAddress>;
31
+ getGasSettings(): GasSettings | undefined;
32
+ }
33
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWNjb3VudF9lbnRyeXBvaW50X21ldGFfcGF5bWVudF9tZXRob2QuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93YWxsZXQvYWNjb3VudF9lbnRyeXBvaW50X21ldGFfcGF5bWVudF9tZXRob2QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0sb0NBQW9DLENBQUM7QUFFcEUsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLGtDQUFrQyxDQUFDO0FBQ2hFLE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQzFELE9BQU8sRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBRXpELE9BQU8sS0FBSyxFQUFFLE9BQU8sRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBQ3JELE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFFLE1BQU0sOEJBQThCLENBQUM7QUFFckU7Ozs7Ozs7Ozs7Ozs7O0dBY0c7QUFDSCxxQkFBYSxrQ0FBbUMsWUFBVyxnQkFBZ0I7SUFFdkUsT0FBTyxDQUFDLE9BQU87SUFDZixPQUFPLENBQUMsU0FBUztJQUNqQixPQUFPLENBQUMsYUFBYSxDQUFDO0lBQ3RCLE9BQU8sQ0FBQyxvQkFBb0IsQ0FBQztJQUovQixZQUNVLE9BQU8sRUFBRSxPQUFPLEVBQ2hCLFNBQVMsRUFBRSxTQUFTLEVBQ3BCLGFBQWEsQ0FBQyw4QkFBa0IsRUFDaEMsb0JBQW9CLENBQUMsS0FBSyxFQUNoQztJQUVKLFFBQVEsSUFBSSxPQUFPLENBQUMsWUFBWSxDQUFDLENBRWhDO0lBRUssbUJBQW1CLElBQUksT0FBTyxDQUFDLGdCQUFnQixDQUFDLENBNkJyRDtJQUVELFdBQVcsSUFBSSxPQUFPLENBQUMsWUFBWSxDQUFDLENBRW5DO0lBRUQsY0FBYyxJQUFJLFdBQVcsR0FBRyxTQUFTLENBRXhDO0NBQ0YifQ==
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account_entrypoint_meta_payment_method.d.ts","sourceRoot":"","sources":["../../src/wallet/account_entrypoint_meta_payment_method.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAEpE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAErE;;;;;;;;;;;;;;GAcG;AACH,qBAAa,kCAAmC,YAAW,gBAAgB;IAEvE,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,aAAa,CAAC;IACtB,OAAO,CAAC,oBAAoB,CAAC;IAJ/B,YACU,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,SAAS,EACpB,aAAa,CAAC,8BAAkB,EAChC,oBAAoB,CAAC,KAAK,EAChC;IAEJ,QAAQ,IAAI,OAAO,CAAC,YAAY,CAAC,CAEhC;IAEK,mBAAmB,IAAI,OAAO,CAAC,gBAAgB,CAAC,CA6BrD;IAED,WAAW,IAAI,OAAO,CAAC,YAAY,CAAC,CAEnC;IAED,cAAc,IAAI,WAAW,GAAG,SAAS,CAExC;CACF"}
@@ -0,0 +1,63 @@
1
+ import { AccountFeePaymentMethodOptions } from '@aztec-labs/entrypoints/account';
2
+ import { ProtocolContractAddress } from '@aztec-labs/protocol-contracts';
3
+ import { ExecutionPayload } from '@aztec-labs/stdlib/tx';
4
+ /**
5
+ * Fee payment method that allows an account contract to pay for its own deployment
6
+ * It works by rerouting the provided fee payment method through the account's entrypoint,
7
+ * which sets itself as fee payer. If no payment method is provided, it is assumed the
8
+ * account will pay with its own fee juice balance.
9
+ *
10
+ * Usually, in order to pay fees it is necessary to obtain an ExecutionPayload that encodes the necessary information
11
+ * that is sent to the user's account entrypoint, that has plumbing to handle it.
12
+ * If there's no account contract yet (it's being deployed) a MultiCallContract is used, which doesn't have a concept of fees or
13
+ * how to handle this payload.
14
+ * HOWEVER, the account contract's entrypoint does, so this method reshapes that fee payload into a call to the account contract entrypoint
15
+ * being deployed with the original fee payload.
16
+ *
17
+ * This class can be seen in action in DeployAccountMethod.ts#getSelfPaymentMethod
18
+ */ export class AccountEntrypointMetaPaymentMethod {
19
+ account;
20
+ chainInfo;
21
+ paymentMethod;
22
+ feeEntrypointOptions;
23
+ constructor(account, chainInfo, paymentMethod, feeEntrypointOptions){
24
+ this.account = account;
25
+ this.chainInfo = chainInfo;
26
+ this.paymentMethod = paymentMethod;
27
+ this.feeEntrypointOptions = feeEntrypointOptions;
28
+ }
29
+ getAsset() {
30
+ return this.paymentMethod?.getAsset() ?? Promise.resolve(ProtocolContractAddress.FeeJuice);
31
+ }
32
+ async getExecutionPayload() {
33
+ // Get the execution payload for the fee
34
+ const innerPayload = await this.paymentMethod?.getExecutionPayload() ?? ExecutionPayload.empty();
35
+ // If no fee entrypoint options were provided, compute them based on the wrapped payment method
36
+ // This mimics how the actual account contract works when invoked directly:
37
+ // - If we are the fee payer, are there calls in the inner payload? In that case, those calls can
38
+ // only be claiming fee juice, so we use FEE_JUICE_WITH_CLAIM
39
+ // - If we are the fee payer, but there are no calls, then we assume the account already has
40
+ // fee juice and can pay directly with PREEXISTING_FEE_JUICE
41
+ // - If we are not the fee payer, then EXTERNAL is used
42
+ let options = this.feeEntrypointOptions;
43
+ if (!options) {
44
+ const feePayer = await this.paymentMethod?.getFeePayer() ?? this.account.getAddress();
45
+ const isFeePayer = feePayer.equals(this.account.getAddress());
46
+ let accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.EXTERNAL;
47
+ if (isFeePayer) {
48
+ accountFeePaymentMethodOptions = innerPayload.calls.length === 0 ? AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE : AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM;
49
+ }
50
+ options = {
51
+ feePaymentMethodOptions: accountFeePaymentMethodOptions
52
+ };
53
+ }
54
+ // Use the generic wrapping mechanism from the account interface
55
+ return this.account.wrapExecutionPayload(innerPayload, this.chainInfo, options);
56
+ }
57
+ getFeePayer() {
58
+ return this.paymentMethod?.getFeePayer() ?? Promise.resolve(this.account.getAddress());
59
+ }
60
+ getGasSettings() {
61
+ return this.paymentMethod?.getGasSettings();
62
+ }
63
+ }
@@ -0,0 +1,73 @@
1
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
2
+ import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
3
+ import { CompleteAddress, type ContractInstanceWithAddress } from '@aztec-labs/stdlib/contract';
4
+ import type { PublicKeys } from '@aztec-labs/stdlib/keys';
5
+ import type { AccountContract } from '../account/account_contract.js';
6
+ import type { Account, Salt } from '../account/index.js';
7
+ import { DeployAccountMethod } from './deploy_account_method.js';
8
+ import type { Wallet } from './wallet.js';
9
+ /**
10
+ * Optional overrides passed to {@link AccountManager.create}.
11
+ */
12
+ export interface AccountManagerCreateOptions {
13
+ /** Contract instantiation salt. Defaults to a random `Fr`. */
14
+ salt?: Salt;
15
+ /**
16
+ * Commitment to the contract's immutable storage values. Folded into the salted initialization
17
+ * hash, so a non-zero value affects the derived address. Defaults to `Fr.ZERO`.
18
+ */
19
+ immutablesHash?: Fr;
20
+ /** Address recorded as the instance deployer. Defaults to `AztecAddress.ZERO`. */
21
+ deployer?: AztecAddress;
22
+ }
23
+ /**
24
+ * Manages a user account. Provides methods for calculating the account's address and other related data,
25
+ * plus a helper to return a preconfigured deploy method.
26
+ */
27
+ export declare class AccountManager {
28
+ private wallet;
29
+ private secretKey;
30
+ private accountContract;
31
+ private instance;
32
+ private constructor();
33
+ static create(wallet: Wallet, secretKey: Fr, accountContract: AccountContract, opts?: AccountManagerCreateOptions): Promise<AccountManager>;
34
+ protected getPublicKeys(): PublicKeys;
35
+ protected getPublicKeysHash(): Promise<Fr>;
36
+ /**
37
+ * Gets the calculated complete address associated with this account.
38
+ * Does not require the account to have been published for public execution.
39
+ * @returns The address, partial address, and encryption public key.
40
+ */
41
+ getCompleteAddress(): Promise<CompleteAddress>;
42
+ /**
43
+ * Returns the secret key used to derive the rest of the privacy keys for this contract
44
+ */
45
+ getSecretKey(): Fr;
46
+ get address(): AztecAddress;
47
+ /**
48
+ * Returns the contract instance definition associated with this account.
49
+ * Does not require the account to have been published for public execution.
50
+ * @returns ContractInstance instance.
51
+ */
52
+ getInstance(): ContractInstanceWithAddress;
53
+ /**
54
+ * Returns the account (the transaction signer) backed by this account contract. Use it to build and authorize
55
+ * transactions from this account.
56
+ */
57
+ getAccount(): Promise<Account>;
58
+ /**
59
+ * Returns the account contract that backs this account.
60
+ * @returns The account contract
61
+ */
62
+ getAccountContract(): AccountContract;
63
+ /**
64
+ * Returns a preconfigured deploy method that contains all the necessary function
65
+ * calls to deploy the account contract.
66
+ */
67
+ getDeployMethod(): Promise<DeployAccountMethod>;
68
+ /**
69
+ * Returns whether this account contract has an initializer function.
70
+ */
71
+ hasInitializer(): Promise<boolean>;
72
+ }
73
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWNjb3VudF9tYW5hZ2VyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvd2FsbGV0L2FjY291bnRfbWFuYWdlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0scUNBQXFDLENBQUM7QUFDekQsT0FBTyxLQUFLLEVBQUUsWUFBWSxFQUFFLE1BQU0sa0NBQWtDLENBQUM7QUFDckUsT0FBTyxFQUNMLGVBQWUsRUFDZixLQUFLLDJCQUEyQixFQUVqQyxNQUFNLDZCQUE2QixDQUFDO0FBQ3JDLE9BQU8sS0FBSyxFQUFFLFVBQVUsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBRzFELE9BQU8sS0FBSyxFQUFFLGVBQWUsRUFBRSxNQUFNLGdDQUFnQyxDQ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IAEJ,OAAa,MAAM,CACjB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,EAAE,EACb,eAAe,EAAE,eAAe,EAChC,IAAI,CAAC,EAAE,2BAA2B,2BAqBnC;IAED,SAAS,CAAC,aAAa,IAAI,UAAU,CAEpC;IAED,SAAS,CAAC,iBAAiB,IAAI,OAAO,CAAC,EAAE,CAAC,CAEzC;IAED;;;;OAIG;IACI,kBAAkB,IAAI,OAAO,CAAC,eAAe,CAAC,CAEpD;IAED;;OAEG;IACI,YAAY,OAElB;IAED,IAAI,OAAO,IAAI,YAAY,CAE1B;IAED;;;;OAIG;IACI,WAAW,IAAI,2BAA2B,CAEhD;IAED;;;OAGG;IACU,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,CAG1C;IAED;;;OAGG;IACH,kBAAkB,IAAI,eAAe,CAEpC;IAED;;;OAGG;IACU,eAAe,IAAI,OAAO,CAAC,mBAAmB,CAAC,CA2B3D;IAED;;OAEG;IACU,cAAc,qBAE1B;CACF"}
@@ -0,0 +1,102 @@
1
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
2
+ import { CompleteAddress, getContractInstanceFromInstantiationParams } from '@aztec-labs/stdlib/contract';
3
+ import { deriveKeys } from '@aztec-labs/stdlib/keys';
4
+ import { Contract } from '../contract/contract.js';
5
+ import { DeployAccountMethod } from './deploy_account_method.js';
6
+ /**
7
+ * Manages a user account. Provides methods for calculating the account's address and other related data,
8
+ * plus a helper to return a preconfigured deploy method.
9
+ */ export class AccountManager {
10
+ wallet;
11
+ secretKey;
12
+ accountContract;
13
+ instance;
14
+ constructor(wallet, secretKey, accountContract, instance){
15
+ this.wallet = wallet;
16
+ this.secretKey = secretKey;
17
+ this.accountContract = accountContract;
18
+ this.instance = instance;
19
+ }
20
+ static async create(wallet, secretKey, accountContract, opts) {
21
+ const { publicKeys } = await deriveKeys(secretKey);
22
+ const salt = opts?.salt !== undefined ? new Fr(opts.salt) : Fr.random();
23
+ const { constructorName, constructorArgs } = await accountContract.getInitializationFunctionAndArgs() ?? {
24
+ constructorName: undefined,
25
+ constructorArgs: undefined
26
+ };
27
+ const artifact = await accountContract.getContractArtifact();
28
+ const instance = await getContractInstanceFromInstantiationParams(artifact, {
29
+ constructorArtifact: constructorName,
30
+ constructorArgs,
31
+ salt,
32
+ publicKeys,
33
+ deployer: opts?.deployer,
34
+ immutablesHash: opts?.immutablesHash ?? await accountContract.getImmutablesHash()
35
+ });
36
+ return new AccountManager(wallet, secretKey, accountContract, instance);
37
+ }
38
+ getPublicKeys() {
39
+ return this.instance.publicKeys;
40
+ }
41
+ getPublicKeysHash() {
42
+ return this.getPublicKeys().hash();
43
+ }
44
+ /**
45
+ * Gets the calculated complete address associated with this account.
46
+ * Does not require the account to have been published for public execution.
47
+ * @returns The address, partial address, and encryption public key.
48
+ */ getCompleteAddress() {
49
+ return CompleteAddress.fromSecretKeyAndInstance(this.secretKey, this.instance);
50
+ }
51
+ /**
52
+ * Returns the secret key used to derive the rest of the privacy keys for this contract
53
+ */ getSecretKey() {
54
+ return this.secretKey;
55
+ }
56
+ get address() {
57
+ return this.instance.address;
58
+ }
59
+ /**
60
+ * Returns the contract instance definition associated with this account.
61
+ * Does not require the account to have been published for public execution.
62
+ * @returns ContractInstance instance.
63
+ */ getInstance() {
64
+ return this.instance;
65
+ }
66
+ /**
67
+ * Returns the account (the transaction signer) backed by this account contract. Use it to build and authorize
68
+ * transactions from this account.
69
+ */ async getAccount() {
70
+ const completeAddress = await this.getCompleteAddress();
71
+ return this.accountContract.getAccount(completeAddress);
72
+ }
73
+ /**
74
+ * Returns the account contract that backs this account.
75
+ * @returns The account contract
76
+ */ getAccountContract() {
77
+ return this.accountContract;
78
+ }
79
+ /**
80
+ * Returns a preconfigured deploy method that contains all the necessary function
81
+ * calls to deploy the account contract.
82
+ */ async getDeployMethod() {
83
+ const artifact = await this.accountContract.getContractArtifact();
84
+ if (!await this.hasInitializer()) {
85
+ // TODO(https://github.com/AztecProtocol/aztec-packages/issues/15576):
86
+ // there should be a path which enables an account contract's class & instance to be published,
87
+ // even if the account contract doesn't have an initializer function. This should not throw.
88
+ throw new Error(`Account contract ${artifact.name} does not have an initializer function to call.`);
89
+ }
90
+ const { constructorName, constructorArgs } = await this.accountContract.getInitializationFunctionAndArgs() ?? {
91
+ constructorName: undefined,
92
+ constructorArgs: undefined
93
+ };
94
+ const account = await this.getAccount();
95
+ return new DeployAccountMethod(this.getPublicKeys(), this.wallet, artifact, (instance)=>Contract.at(instance.address, artifact, this.wallet), this.instance.salt, this.instance.immutablesHash, account, constructorArgs, constructorName);
96
+ }
97
+ /**
98
+ * Returns whether this account contract has an initializer function.
99
+ */ async hasInitializer() {
100
+ return await this.accountContract.getInitializationFunctionAndArgs() !== undefined;
101
+ }
102
+ }