@aztec/aztec.js 0.0.0-test.0

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 (299) hide show
  1. package/README.md +44 -0
  2. package/dest/account/contract.d.ts +37 -0
  3. package/dest/account/contract.d.ts.map +1 -0
  4. package/dest/account/contract.js +16 -0
  5. package/dest/account/index.d.ts +15 -0
  6. package/dest/account/index.d.ts.map +1 -0
  7. package/dest/account/index.js +9 -0
  8. package/dest/account/interface.d.ts +31 -0
  9. package/dest/account/interface.d.ts.map +1 -0
  10. package/dest/account/interface.js +4 -0
  11. package/dest/account/wallet.d.ts +11 -0
  12. package/dest/account/wallet.d.ts.map +1 -0
  13. package/dest/account/wallet.js +3 -0
  14. package/dest/account_manager/deploy_account_method.d.ts +15 -0
  15. package/dest/account_manager/deploy_account_method.d.ts.map +1 -0
  16. package/dest/account_manager/deploy_account_method.js +43 -0
  17. package/dest/account_manager/deploy_account_sent_tx.d.ts +30 -0
  18. package/dest/account_manager/deploy_account_sent_tx.d.ts.map +1 -0
  19. package/dest/account_manager/deploy_account_sent_tx.js +29 -0
  20. package/dest/account_manager/index.d.ts +108 -0
  21. package/dest/account_manager/index.d.ts.map +1 -0
  22. package/dest/account_manager/index.js +159 -0
  23. package/dest/api/abi.d.ts +3 -0
  24. package/dest/api/abi.d.ts.map +1 -0
  25. package/dest/api/abi.js +1 -0
  26. package/dest/api/account.d.ts +3 -0
  27. package/dest/api/account.d.ts.map +1 -0
  28. package/dest/api/account.js +2 -0
  29. package/dest/api/addresses.d.ts +3 -0
  30. package/dest/api/addresses.d.ts.map +1 -0
  31. package/dest/api/addresses.js +2 -0
  32. package/dest/api/cheat_codes.d.ts +26 -0
  33. package/dest/api/cheat_codes.d.ts.map +1 -0
  34. package/dest/api/cheat_codes.js +25 -0
  35. package/dest/api/deployment.d.ts +4 -0
  36. package/dest/api/deployment.d.ts.map +1 -0
  37. package/dest/api/deployment.js +3 -0
  38. package/dest/api/entrypoint.d.ts +2 -0
  39. package/dest/api/entrypoint.d.ts.map +1 -0
  40. package/dest/api/entrypoint.js +1 -0
  41. package/dest/api/eth_address.d.ts +2 -0
  42. package/dest/api/eth_address.d.ts.map +1 -0
  43. package/dest/api/eth_address.js +1 -0
  44. package/dest/api/ethereum/anvil_test_watcher.d.ts +32 -0
  45. package/dest/api/ethereum/anvil_test_watcher.d.ts.map +1 -0
  46. package/dest/api/ethereum/anvil_test_watcher.js +133 -0
  47. package/dest/api/ethereum/chain_monitor.d.ts +25 -0
  48. package/dest/api/ethereum/chain_monitor.d.ts.map +1 -0
  49. package/dest/api/ethereum/chain_monitor.js +74 -0
  50. package/dest/api/ethereum/cheat_codes.d.ts +63 -0
  51. package/dest/api/ethereum/cheat_codes.d.ts.map +1 -0
  52. package/dest/api/ethereum/cheat_codes.js +162 -0
  53. package/dest/api/ethereum/index.d.ts +7 -0
  54. package/dest/api/ethereum/index.d.ts.map +1 -0
  55. package/dest/api/ethereum/index.js +6 -0
  56. package/dest/api/ethereum/l1_contracts.d.ts +3 -0
  57. package/dest/api/ethereum/l1_contracts.d.ts.map +1 -0
  58. package/dest/api/ethereum/l1_contracts.js +13 -0
  59. package/dest/api/ethereum/portal_manager.d.ts +136 -0
  60. package/dest/api/ethereum/portal_manager.d.ts.map +1 -0
  61. package/dest/api/ethereum/portal_manager.js +286 -0
  62. package/dest/api/fee.d.ts +6 -0
  63. package/dest/api/fee.d.ts.map +1 -0
  64. package/dest/api/fee.js +4 -0
  65. package/dest/api/fields.d.ts +2 -0
  66. package/dest/api/fields.d.ts.map +1 -0
  67. package/dest/api/fields.js +1 -0
  68. package/dest/api/interfaces/pxe.d.ts +2 -0
  69. package/dest/api/interfaces/pxe.d.ts.map +1 -0
  70. package/dest/api/interfaces/pxe.js +1 -0
  71. package/dest/api/log.d.ts +2 -0
  72. package/dest/api/log.d.ts.map +1 -0
  73. package/dest/api/log.js +1 -0
  74. package/dest/api/log_id.d.ts +2 -0
  75. package/dest/api/log_id.d.ts.map +1 -0
  76. package/dest/api/log_id.js +1 -0
  77. package/dest/api/tx_hash.d.ts +2 -0
  78. package/dest/api/tx_hash.d.ts.map +1 -0
  79. package/dest/api/tx_hash.js +1 -0
  80. package/dest/api/wallet.d.ts +2 -0
  81. package/dest/api/wallet.d.ts.map +1 -0
  82. package/dest/api/wallet.js +1 -0
  83. package/dest/contract/base_contract_interaction.d.ts +98 -0
  84. package/dest/contract/base_contract_interaction.d.ts.map +1 -0
  85. package/dest/contract/base_contract_interaction.js +149 -0
  86. package/dest/contract/batch_call.d.ts +28 -0
  87. package/dest/contract/batch_call.d.ts.map +1 -0
  88. package/dest/contract/batch_call.js +91 -0
  89. package/dest/contract/checker.d.ts +11 -0
  90. package/dest/contract/checker.d.ts.map +1 -0
  91. package/dest/contract/checker.js +107 -0
  92. package/dest/contract/contract.d.ts +41 -0
  93. package/dest/contract/contract.d.ts.map +1 -0
  94. package/dest/contract/contract.js +52 -0
  95. package/dest/contract/contract_base.d.ts +61 -0
  96. package/dest/contract/contract_base.d.ts.map +1 -0
  97. package/dest/contract/contract_base.js +45 -0
  98. package/dest/contract/contract_function_interaction.d.ts +68 -0
  99. package/dest/contract/contract_function_interaction.d.ts.map +1 -0
  100. package/dest/contract/contract_function_interaction.js +122 -0
  101. package/dest/contract/deploy_method.d.ts +113 -0
  102. package/dest/contract/deploy_method.d.ts.map +1 -0
  103. package/dest/contract/deploy_method.js +212 -0
  104. package/dest/contract/deploy_proven_tx.d.ts +21 -0
  105. package/dest/contract/deploy_proven_tx.d.ts.map +1 -0
  106. package/dest/contract/deploy_proven_tx.js +19 -0
  107. package/dest/contract/deploy_sent_tx.d.ts +45 -0
  108. package/dest/contract/deploy_sent_tx.d.ts.map +1 -0
  109. package/dest/contract/deploy_sent_tx.js +43 -0
  110. package/dest/contract/get_gas_limits.d.ts +18 -0
  111. package/dest/contract/get_gas_limits.d.ts.map +1 -0
  112. package/dest/contract/get_gas_limits.js +10 -0
  113. package/dest/contract/index.d.ts +45 -0
  114. package/dest/contract/index.d.ts.map +1 -0
  115. package/dest/contract/index.js +43 -0
  116. package/dest/contract/protocol_contracts.d.ts +9 -0
  117. package/dest/contract/protocol_contracts.d.ts.map +1 -0
  118. package/dest/contract/protocol_contracts.js +26 -0
  119. package/dest/contract/proven_tx.d.ts +17 -0
  120. package/dest/contract/proven_tx.d.ts.map +1 -0
  121. package/dest/contract/proven_tx.js +22 -0
  122. package/dest/contract/sent_tx.d.ts +61 -0
  123. package/dest/contract/sent_tx.d.ts.map +1 -0
  124. package/dest/contract/sent_tx.js +102 -0
  125. package/dest/contract/unsafe_contract.d.ts +15 -0
  126. package/dest/contract/unsafe_contract.d.ts.map +1 -0
  127. package/dest/contract/unsafe_contract.js +6 -0
  128. package/dest/deployment/broadcast_function.d.ts +24 -0
  129. package/dest/deployment/broadcast_function.d.ts.map +1 -0
  130. package/dest/deployment/broadcast_function.js +70 -0
  131. package/dest/deployment/contract_deployer.d.ts +27 -0
  132. package/dest/deployment/contract_deployer.d.ts.map +1 -0
  133. package/dest/deployment/contract_deployer.js +30 -0
  134. package/dest/deployment/deploy_instance.d.ts +10 -0
  135. package/dest/deployment/deploy_instance.d.ts.map +1 -0
  136. package/dest/deployment/deploy_instance.js +14 -0
  137. package/dest/deployment/index.d.ts +2 -0
  138. package/dest/deployment/index.d.ts.map +1 -0
  139. package/dest/deployment/index.js +1 -0
  140. package/dest/deployment/register_class.d.ts +6 -0
  141. package/dest/deployment/register_class.d.ts.map +1 -0
  142. package/dest/deployment/register_class.js +22 -0
  143. package/dest/entrypoint/default_entrypoint.d.ts +12 -0
  144. package/dest/entrypoint/default_entrypoint.d.ts.map +1 -0
  145. package/dest/entrypoint/default_entrypoint.js +28 -0
  146. package/dest/entrypoint/default_multi_call_entrypoint.d.ts +15 -0
  147. package/dest/entrypoint/default_multi_call_entrypoint.d.ts.map +1 -0
  148. package/dest/entrypoint/default_multi_call_entrypoint.js +130 -0
  149. package/dest/entrypoint/entrypoint.d.ts +35 -0
  150. package/dest/entrypoint/entrypoint.d.ts.map +1 -0
  151. package/dest/entrypoint/entrypoint.js +4 -0
  152. package/dest/entrypoint/payload.d.ts +128 -0
  153. package/dest/entrypoint/payload.d.ts.map +1 -0
  154. package/dest/entrypoint/payload.js +143 -0
  155. package/dest/fee/fee_juice_payment_method.d.ts +14 -0
  156. package/dest/fee/fee_juice_payment_method.d.ts.map +1 -0
  157. package/dest/fee/fee_juice_payment_method.js +20 -0
  158. package/dest/fee/fee_juice_payment_method_with_claim.d.ts +18 -0
  159. package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -0
  160. package/dest/fee/fee_juice_payment_method_with_claim.js +37 -0
  161. package/dest/fee/fee_payment_method.d.ts +22 -0
  162. package/dest/fee/fee_payment_method.d.ts.map +1 -0
  163. package/dest/fee/fee_payment_method.js +3 -0
  164. package/dest/fee/private_fee_payment_method.d.ts +51 -0
  165. package/dest/fee/private_fee_payment_method.d.ts.map +1 -0
  166. package/dest/fee/private_fee_payment_method.js +103 -0
  167. package/dest/fee/public_fee_payment_method.d.ts +41 -0
  168. package/dest/fee/public_fee_payment_method.d.ts.map +1 -0
  169. package/dest/fee/public_fee_payment_method.js +97 -0
  170. package/dest/index.d.ts +66 -0
  171. package/dest/index.d.ts.map +1 -0
  172. package/dest/index.js +69 -0
  173. package/dest/rpc_clients/index.d.ts +3 -0
  174. package/dest/rpc_clients/index.d.ts.map +1 -0
  175. package/dest/rpc_clients/index.js +2 -0
  176. package/dest/rpc_clients/node/index.d.ts +12 -0
  177. package/dest/rpc_clients/node/index.d.ts.map +1 -0
  178. package/dest/rpc_clients/node/index.js +78 -0
  179. package/dest/rpc_clients/pxe_client.d.ts +10 -0
  180. package/dest/rpc_clients/pxe_client.d.ts.map +1 -0
  181. package/dest/rpc_clients/pxe_client.js +23 -0
  182. package/dest/utils/abi_types.d.ts +29 -0
  183. package/dest/utils/abi_types.d.ts.map +1 -0
  184. package/dest/utils/abi_types.js +1 -0
  185. package/dest/utils/authwit.d.ts +60 -0
  186. package/dest/utils/authwit.d.ts.map +1 -0
  187. package/dest/utils/authwit.js +74 -0
  188. package/dest/utils/aztec_cheatcodes.d.ts +59 -0
  189. package/dest/utils/aztec_cheatcodes.d.ts.map +1 -0
  190. package/dest/utils/aztec_cheatcodes.js +62 -0
  191. package/dest/utils/fee_juice.d.ts +7 -0
  192. package/dest/utils/fee_juice.d.ts.map +1 -0
  193. package/dest/utils/fee_juice.js +9 -0
  194. package/dest/utils/field_compressed_string.d.ts +17 -0
  195. package/dest/utils/field_compressed_string.d.ts.map +1 -0
  196. package/dest/utils/field_compressed_string.js +15 -0
  197. package/dest/utils/index.d.ts +8 -0
  198. package/dest/utils/index.d.ts.map +1 -0
  199. package/dest/utils/index.js +6 -0
  200. package/dest/utils/node.d.ts +5 -0
  201. package/dest/utils/node.d.ts.map +1 -0
  202. package/dest/utils/node.js +15 -0
  203. package/dest/utils/pub_key.d.ts +9 -0
  204. package/dest/utils/pub_key.d.ts.map +1 -0
  205. package/dest/utils/pub_key.js +9 -0
  206. package/dest/utils/pxe.d.ts +4 -0
  207. package/dest/utils/pxe.d.ts.map +1 -0
  208. package/dest/utils/pxe.js +14 -0
  209. package/dest/wallet/account_wallet.d.ts +76 -0
  210. package/dest/wallet/account_wallet.d.ts.map +1 -0
  211. package/dest/wallet/account_wallet.js +231 -0
  212. package/dest/wallet/account_wallet_with_private_key.d.ts +26 -0
  213. package/dest/wallet/account_wallet_with_private_key.d.ts.map +1 -0
  214. package/dest/wallet/account_wallet_with_private_key.js +22 -0
  215. package/dest/wallet/base_wallet.d.ts +73 -0
  216. package/dest/wallet/base_wallet.d.ts.map +1 -0
  217. package/dest/wallet/base_wallet.js +123 -0
  218. package/dest/wallet/index.d.ts +17 -0
  219. package/dest/wallet/index.d.ts.map +1 -0
  220. package/dest/wallet/index.js +20 -0
  221. package/dest/wallet/signerless_wallet.d.ts +25 -0
  222. package/dest/wallet/signerless_wallet.d.ts.map +1 -0
  223. package/dest/wallet/signerless_wallet.js +36 -0
  224. package/package.json +116 -0
  225. package/src/account/contract.ts +56 -0
  226. package/src/account/index.ts +16 -0
  227. package/src/account/interface.ts +36 -0
  228. package/src/account/wallet.ts +13 -0
  229. package/src/account_manager/deploy_account_method.ts +86 -0
  230. package/src/account_manager/deploy_account_sent_tx.ts +42 -0
  231. package/src/account_manager/index.ts +229 -0
  232. package/src/api/README.md +7 -0
  233. package/src/api/abi.ts +10 -0
  234. package/src/api/account.ts +10 -0
  235. package/src/api/addresses.ts +2 -0
  236. package/src/api/cheat_codes.ts +35 -0
  237. package/src/api/deployment.ts +3 -0
  238. package/src/api/entrypoint.ts +1 -0
  239. package/src/api/eth_address.ts +1 -0
  240. package/src/api/ethereum/anvil_test_watcher.ts +158 -0
  241. package/src/api/ethereum/chain_monitor.ts +88 -0
  242. package/src/api/ethereum/cheat_codes.ts +184 -0
  243. package/src/api/ethereum/index.ts +19 -0
  244. package/src/api/ethereum/l1_contracts.ts +21 -0
  245. package/src/api/ethereum/portal_manager.ts +410 -0
  246. package/src/api/fee.ts +5 -0
  247. package/src/api/fields.ts +1 -0
  248. package/src/api/interfaces/pxe.ts +1 -0
  249. package/src/api/log.ts +1 -0
  250. package/src/api/log_id.ts +1 -0
  251. package/src/api/tx_hash.ts +1 -0
  252. package/src/api/wallet.ts +7 -0
  253. package/src/contract/base_contract_interaction.ts +192 -0
  254. package/src/contract/batch_call.ts +95 -0
  255. package/src/contract/checker.ts +117 -0
  256. package/src/contract/contract.ts +69 -0
  257. package/src/contract/contract_base.ts +90 -0
  258. package/src/contract/contract_function_interaction.ts +173 -0
  259. package/src/contract/deploy_method.ts +271 -0
  260. package/src/contract/deploy_proven_tx.ts +34 -0
  261. package/src/contract/deploy_sent_tx.ts +74 -0
  262. package/src/contract/get_gas_limits.ts +26 -0
  263. package/src/contract/index.ts +48 -0
  264. package/src/contract/protocol_contracts.ts +35 -0
  265. package/src/contract/proven_tx.ts +42 -0
  266. package/src/contract/sent_tx.ts +141 -0
  267. package/src/contract/unsafe_contract.ts +19 -0
  268. package/src/deployment/broadcast_function.ts +148 -0
  269. package/src/deployment/contract_deployer.ts +41 -0
  270. package/src/deployment/deploy_instance.ts +31 -0
  271. package/src/deployment/index.ts +1 -0
  272. package/src/deployment/register_class.ts +44 -0
  273. package/src/entrypoint/default_entrypoint.ts +39 -0
  274. package/src/entrypoint/default_multi_call_entrypoint.ts +93 -0
  275. package/src/entrypoint/entrypoint.ts +39 -0
  276. package/src/entrypoint/payload.ts +238 -0
  277. package/src/fee/fee_juice_payment_method.ts +26 -0
  278. package/src/fee/fee_juice_payment_method_with_claim.ts +49 -0
  279. package/src/fee/fee_payment_method.ts +22 -0
  280. package/src/fee/private_fee_payment_method.ts +118 -0
  281. package/src/fee/public_fee_payment_method.ts +114 -0
  282. package/src/index.ts +106 -0
  283. package/src/rpc_clients/index.ts +2 -0
  284. package/src/rpc_clients/node/index.ts +77 -0
  285. package/src/rpc_clients/pxe_client.ts +25 -0
  286. package/src/utils/abi_types.ts +25 -0
  287. package/src/utils/authwit.ts +110 -0
  288. package/src/utils/aztec_cheatcodes.ts +77 -0
  289. package/src/utils/fee_juice.ts +14 -0
  290. package/src/utils/field_compressed_string.ts +27 -0
  291. package/src/utils/index.ts +21 -0
  292. package/src/utils/node.ts +19 -0
  293. package/src/utils/pub_key.ts +13 -0
  294. package/src/utils/pxe.ts +17 -0
  295. package/src/wallet/account_wallet.ts +242 -0
  296. package/src/wallet/account_wallet_with_private_key.ts +40 -0
  297. package/src/wallet/base_wallet.ts +198 -0
  298. package/src/wallet/index.ts +33 -0
  299. package/src/wallet/signerless_wallet.ts +52 -0
@@ -0,0 +1,19 @@
1
+ import type { ContractArtifact } from '@aztec/stdlib/abi';
2
+ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
3
+
4
+ import type { Wallet } from '../wallet/index.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
+ }
@@ -0,0 +1,148 @@
1
+ import {
2
+ ARTIFACT_FUNCTION_TREE_MAX_HEIGHT,
3
+ MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
4
+ REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT,
5
+ } from '@aztec/constants';
6
+ import { padArrayEnd } from '@aztec/foundation/collection';
7
+ import { Fr } from '@aztec/foundation/fields';
8
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
9
+ import { type ContractArtifact, FunctionSelector, FunctionType, bufferAsFields } from '@aztec/stdlib/abi';
10
+ import {
11
+ computeVerificationKeyHash,
12
+ createPrivateFunctionMembershipProof,
13
+ createUnconstrainedFunctionMembershipProof,
14
+ getContractClassFromArtifact,
15
+ } from '@aztec/stdlib/contract';
16
+ import { Capsule } from '@aztec/stdlib/tx';
17
+
18
+ import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
19
+ import { getRegistererContract } from '../contract/protocol_contracts.js';
20
+ import type { Wallet } from '../wallet/index.js';
21
+
22
+ /**
23
+ * Sets up a call to broadcast a private function's bytecode via the ClassRegisterer contract.
24
+ * Note that this is not required for users to call the function, but is rather a convenience to make
25
+ * this code publicly available so dapps or wallets do not need to redistribute it.
26
+ * @param wallet - Wallet to send the transaction.
27
+ * @param artifact - Contract artifact that contains the function to be broadcast.
28
+ * @param selector - Selector of the function to be broadcast.
29
+ * @returns A ContractFunctionInteraction object that can be used to send the transaction.
30
+ */
31
+ export async function broadcastPrivateFunction(
32
+ wallet: Wallet,
33
+ artifact: ContractArtifact,
34
+ selector: FunctionSelector,
35
+ ): Promise<ContractFunctionInteraction> {
36
+ const contractClass = await getContractClassFromArtifact(artifact);
37
+ const privateFunctions = artifact.functions.filter(fn => fn.functionType === FunctionType.PRIVATE);
38
+ const functionsAndSelectors = await Promise.all(
39
+ privateFunctions.map(async fn => ({
40
+ f: fn,
41
+ selector: await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters),
42
+ })),
43
+ );
44
+ const privateFunctionArtifact = functionsAndSelectors.find(fn => selector.equals(fn.selector))?.f;
45
+ if (!privateFunctionArtifact) {
46
+ throw new Error(`Private function with selector ${selector.toString()} not found`);
47
+ }
48
+
49
+ const {
50
+ artifactTreeSiblingPath,
51
+ artifactTreeLeafIndex,
52
+ artifactMetadataHash,
53
+ functionMetadataHash,
54
+ unconstrainedFunctionsArtifactTreeRoot,
55
+ privateFunctionTreeSiblingPath,
56
+ privateFunctionTreeLeafIndex,
57
+ } = await createPrivateFunctionMembershipProof(selector, artifact);
58
+
59
+ const vkHash = await computeVerificationKeyHash(privateFunctionArtifact);
60
+
61
+ const registerer = await getRegistererContract(wallet);
62
+ const fn = registerer.methods.broadcast_private_function(
63
+ contractClass.id,
64
+ artifactMetadataHash,
65
+ unconstrainedFunctionsArtifactTreeRoot,
66
+ privateFunctionTreeSiblingPath,
67
+ privateFunctionTreeLeafIndex,
68
+ padArrayEnd(artifactTreeSiblingPath, Fr.ZERO, ARTIFACT_FUNCTION_TREE_MAX_HEIGHT),
69
+ artifactTreeLeafIndex,
70
+ // eslint-disable-next-line camelcase
71
+ { selector, metadata_hash: functionMetadataHash, vk_hash: vkHash },
72
+ );
73
+
74
+ const bytecode = bufferAsFields(
75
+ privateFunctionArtifact.bytecode,
76
+ MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
77
+ );
78
+ fn.addCapsule(
79
+ new Capsule(
80
+ ProtocolContractAddress.ContractClassRegisterer,
81
+ new Fr(REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT),
82
+ bytecode,
83
+ ),
84
+ );
85
+
86
+ return fn;
87
+ }
88
+
89
+ /**
90
+ * Sets up a call to broadcast an unconstrained function's bytecode via the ClassRegisterer contract.
91
+ * Note that this is not required for users to call the function, but is rather a convenience to make
92
+ * this code publicly available so dapps or wallets do not need to redistribute it.
93
+ * @param wallet - Wallet to send the transaction.
94
+ * @param artifact - Contract artifact that contains the function to be broadcast.
95
+ * @param selector - Selector of the function to be broadcast.
96
+ * @returns A ContractFunctionInteraction object that can be used to send the transaction.
97
+ */
98
+ export async function broadcastUnconstrainedFunction(
99
+ wallet: Wallet,
100
+ artifact: ContractArtifact,
101
+ selector: FunctionSelector,
102
+ ): Promise<ContractFunctionInteraction> {
103
+ const contractClass = await getContractClassFromArtifact(artifact);
104
+ const unconstrainedFunctions = artifact.functions.filter(fn => fn.functionType === FunctionType.UNCONSTRAINED);
105
+ const unconstrainedFunctionsAndSelectors = await Promise.all(
106
+ unconstrainedFunctions.map(async fn => ({
107
+ f: fn,
108
+ selector: await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters),
109
+ })),
110
+ );
111
+ const unconstrainedFunctionArtifact = unconstrainedFunctionsAndSelectors.find(fn => selector.equals(fn.selector))?.f;
112
+ if (!unconstrainedFunctionArtifact) {
113
+ throw new Error(`Unconstrained function with selector ${selector.toString()} not found`);
114
+ }
115
+
116
+ const {
117
+ artifactMetadataHash,
118
+ artifactTreeLeafIndex,
119
+ artifactTreeSiblingPath,
120
+ functionMetadataHash,
121
+ privateFunctionsArtifactTreeRoot,
122
+ } = await createUnconstrainedFunctionMembershipProof(selector, artifact);
123
+
124
+ const registerer = await getRegistererContract(wallet);
125
+ const fn = registerer.methods.broadcast_unconstrained_function(
126
+ contractClass.id,
127
+ artifactMetadataHash,
128
+ privateFunctionsArtifactTreeRoot,
129
+ padArrayEnd(artifactTreeSiblingPath, Fr.ZERO, ARTIFACT_FUNCTION_TREE_MAX_HEIGHT),
130
+ artifactTreeLeafIndex,
131
+ // eslint-disable-next-line camelcase
132
+ { selector, metadata_hash: functionMetadataHash },
133
+ );
134
+
135
+ const bytecode = bufferAsFields(
136
+ unconstrainedFunctionArtifact.bytecode,
137
+ MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
138
+ );
139
+ fn.addCapsule(
140
+ new Capsule(
141
+ ProtocolContractAddress.ContractClassRegisterer,
142
+ new Fr(REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT),
143
+ bytecode,
144
+ ),
145
+ );
146
+
147
+ return fn;
148
+ }
@@ -0,0 +1,41 @@
1
+ import type { ContractArtifact } from '@aztec/stdlib/abi';
2
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import { PublicKeys } from '@aztec/stdlib/keys';
4
+
5
+ import type { Wallet } from '../account/wallet.js';
6
+ import { Contract } from '../contract/contract.js';
7
+ import { DeployMethod } from '../contract/deploy_method.js';
8
+
9
+ /**
10
+ * A class for deploying contract.
11
+ * @remarks Keeping this around even though we have Aztec.nr contract types because it can be useful for non-TS users.
12
+ */
13
+ export class ContractDeployer {
14
+ constructor(
15
+ private artifact: ContractArtifact,
16
+ private wallet: Wallet,
17
+ private publicKeys?: PublicKeys,
18
+ private constructorName?: string,
19
+ ) {}
20
+
21
+ /**
22
+ * Deploy a contract using the provided ABI and constructor arguments.
23
+ * This function creates a new DeployMethod instance that can be used to send deployment transactions
24
+ * and query deployment status. The method accepts any number of constructor arguments, which will
25
+ * be passed to the contract's constructor during deployment.
26
+ *
27
+ * @param args - The constructor arguments for the contract being deployed.
28
+ * @returns A DeployMethod instance configured with the ABI, PXE, and constructor arguments.
29
+ */
30
+ public deploy(...args: any[]) {
31
+ const postDeployCtor = (address: AztecAddress, wallet: Wallet) => Contract.at(address, this.artifact, wallet);
32
+ return new DeployMethod(
33
+ this.publicKeys ?? PublicKeys.default(),
34
+ this.wallet,
35
+ this.artifact,
36
+ postDeployCtor,
37
+ args,
38
+ this.constructorName,
39
+ );
40
+ }
41
+ }
@@ -0,0 +1,31 @@
1
+ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
2
+
3
+ import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
4
+ import { getDeployerContract } from '../contract/protocol_contracts.js';
5
+ import type { Wallet } from '../wallet/index.js';
6
+
7
+ /**
8
+ * Sets up a call to the canonical deployer contract to publicly deploy a contract instance.
9
+ * @param wallet - The wallet to use for the deployment.
10
+ * @param instance - The instance to deploy.
11
+ */
12
+ export async function deployInstance(
13
+ wallet: Wallet,
14
+ instance: ContractInstanceWithAddress,
15
+ ): Promise<ContractFunctionInteraction> {
16
+ const deployerContract = await getDeployerContract(wallet);
17
+ const { salt, currentContractClassId: contractClassId, publicKeys, deployer } = instance;
18
+ const isUniversalDeploy = deployer.isZero();
19
+ if (!isUniversalDeploy && !wallet.getAddress().equals(deployer)) {
20
+ throw new Error(
21
+ `Expected deployer ${deployer.toString()} does not match sender wallet ${wallet.getAddress().toString()}`,
22
+ );
23
+ }
24
+ return deployerContract.methods.deploy(
25
+ salt,
26
+ contractClassId,
27
+ instance.initializationHash,
28
+ publicKeys,
29
+ isUniversalDeploy,
30
+ );
31
+ }
@@ -0,0 +1 @@
1
+ export * from './contract_deployer.js';
@@ -0,0 +1,44 @@
1
+ import { MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS, REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT } from '@aztec/constants';
2
+ import { Fr } from '@aztec/foundation/fields';
3
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
4
+ import { type ContractArtifact, bufferAsFields } from '@aztec/stdlib/abi';
5
+ import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
6
+ import { Capsule } from '@aztec/stdlib/tx';
7
+
8
+ import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
9
+ import { getRegistererContract } from '../contract/protocol_contracts.js';
10
+ import type { Wallet } from '../wallet/index.js';
11
+
12
+ const defaultEmitPublicBytecode =
13
+ // guard against `process` not being defined (e.g. in the browser)
14
+ typeof process === 'object' && typeof process.env === 'object'
15
+ ? ['1', 'true', 'yes', ''].includes(process.env.AZTEC_EMIT_PUBLIC_BYTECODE ?? '')
16
+ : true;
17
+
18
+ /** Sets up a call to register a contract class given its artifact. */
19
+ export async function registerContractClass(
20
+ wallet: Wallet,
21
+ artifact: ContractArtifact,
22
+ emitPublicBytecode = defaultEmitPublicBytecode,
23
+ ): Promise<ContractFunctionInteraction> {
24
+ const { artifactHash, privateFunctionsRoot, publicBytecodeCommitment, packedBytecode } =
25
+ await getContractClassFromArtifact(artifact);
26
+ const registerer = await getRegistererContract(wallet);
27
+ const fn = registerer.methods.register(
28
+ artifactHash,
29
+ privateFunctionsRoot,
30
+ publicBytecodeCommitment,
31
+ emitPublicBytecode,
32
+ );
33
+
34
+ const encodedBytecode = bufferAsFields(packedBytecode, MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS);
35
+ fn.addCapsule(
36
+ new Capsule(
37
+ ProtocolContractAddress.ContractClassRegisterer,
38
+ new Fr(REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT),
39
+ encodedBytecode,
40
+ ),
41
+ );
42
+
43
+ return fn;
44
+ }
@@ -0,0 +1,39 @@
1
+ import { FunctionType } from '@aztec/stdlib/abi';
2
+ import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
3
+
4
+ import type { EntrypointInterface, ExecutionRequestInit } from './entrypoint.js';
5
+
6
+ /**
7
+ * Default implementation of the entrypoint interface. It calls a function on a contract directly
8
+ */
9
+ export class DefaultEntrypoint implements EntrypointInterface {
10
+ constructor(private chainId: number, private protocolVersion: number) {}
11
+
12
+ async createTxExecutionRequest(exec: ExecutionRequestInit): Promise<TxExecutionRequest> {
13
+ const { fee, calls, authWitnesses = [], hashedArguments = [], capsules = [] } = exec;
14
+
15
+ if (calls.length > 1) {
16
+ throw new Error(`Expected a single call, got ${calls.length}`);
17
+ }
18
+
19
+ const call = calls[0];
20
+
21
+ if (call.type !== FunctionType.PRIVATE) {
22
+ throw new Error('Public entrypoints are not allowed');
23
+ }
24
+
25
+ const entrypointHashedValues = await HashedValues.fromValues(call.args);
26
+ const txContext = new TxContext(this.chainId, this.protocolVersion, fee.gasSettings);
27
+ return Promise.resolve(
28
+ new TxExecutionRequest(
29
+ call.to,
30
+ call.selector,
31
+ entrypointHashedValues.hash,
32
+ txContext,
33
+ [...hashedArguments, entrypointHashedValues],
34
+ authWitnesses,
35
+ capsules,
36
+ ),
37
+ );
38
+ }
39
+ }
@@ -0,0 +1,93 @@
1
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
2
+ import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
5
+
6
+ import { type EntrypointInterface, EntrypointPayload, type ExecutionRequestInit } from './entrypoint.js';
7
+
8
+ /**
9
+ * Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
10
+ */
11
+ export class DefaultMultiCallEntrypoint implements EntrypointInterface {
12
+ constructor(
13
+ private chainId: number,
14
+ private version: number,
15
+ private address: AztecAddress = ProtocolContractAddress.MultiCallEntrypoint,
16
+ ) {}
17
+
18
+ async createTxExecutionRequest(executions: ExecutionRequestInit): Promise<TxExecutionRequest> {
19
+ const { fee, calls, authWitnesses = [], hashedArguments = [], capsules = [] } = executions;
20
+ const payload = await EntrypointPayload.fromAppExecution(calls);
21
+ const abi = this.getEntrypointAbi();
22
+ const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [payload]));
23
+
24
+ const txRequest = TxExecutionRequest.from({
25
+ firstCallArgsHash: entrypointHashedArgs.hash,
26
+ origin: this.address,
27
+ functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
28
+ txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
29
+ argsOfCalls: [...payload.hashedArguments, ...hashedArguments, entrypointHashedArgs],
30
+ authWitnesses,
31
+ capsules,
32
+ });
33
+
34
+ return Promise.resolve(txRequest);
35
+ }
36
+
37
+ private getEntrypointAbi() {
38
+ return {
39
+ name: 'entrypoint',
40
+ isInitializer: false,
41
+ functionType: 'private',
42
+ isInternal: false,
43
+ isStatic: false,
44
+ parameters: [
45
+ {
46
+ name: 'app_payload',
47
+ type: {
48
+ kind: 'struct',
49
+ path: 'authwit::entrypoint::app::AppPayload',
50
+ fields: [
51
+ {
52
+ name: 'function_calls',
53
+ type: {
54
+ kind: 'array',
55
+ length: 4,
56
+ type: {
57
+ kind: 'struct',
58
+ path: 'authwit::entrypoint::function_call::FunctionCall',
59
+ fields: [
60
+ { name: 'args_hash', type: { kind: 'field' } },
61
+ {
62
+ name: 'function_selector',
63
+ type: {
64
+ kind: 'struct',
65
+ path: 'authwit::aztec::protocol_types::abis::function_selector::FunctionSelector',
66
+ fields: [{ name: 'inner', type: { kind: 'integer', sign: 'unsigned', width: 32 } }],
67
+ },
68
+ },
69
+ {
70
+ name: 'target_address',
71
+ type: {
72
+ kind: 'struct',
73
+ path: 'authwit::aztec::protocol_types::address::AztecAddress',
74
+ fields: [{ name: 'inner', type: { kind: 'field' } }],
75
+ },
76
+ },
77
+ { name: 'is_public', type: { kind: 'boolean' } },
78
+ { name: 'is_static', type: { kind: 'boolean' } },
79
+ ],
80
+ },
81
+ },
82
+ },
83
+ { name: 'nonce', type: { kind: 'field' } },
84
+ ],
85
+ },
86
+ visibility: 'public',
87
+ },
88
+ ],
89
+ returnTypes: [],
90
+ errorTypes: {},
91
+ } as FunctionAbi;
92
+ }
93
+ }
@@ -0,0 +1,39 @@
1
+ import type { Fr } from '@aztec/foundation/fields';
2
+ import type { FunctionCall } from '@aztec/stdlib/abi';
3
+ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
4
+ import type { Capsule, HashedValues, TxExecutionRequest } from '@aztec/stdlib/tx';
5
+
6
+ import { EntrypointPayload, type FeeOptions, computeCombinedPayloadHash } from './payload.js';
7
+
8
+ export { EntrypointPayload, type FeeOptions, computeCombinedPayloadHash };
9
+
10
+ export { DefaultEntrypoint } from './default_entrypoint.js';
11
+ export { DefaultMultiCallEntrypoint } from './default_multi_call_entrypoint.js';
12
+
13
+ /** Encodes the calls to be done in a transaction. */
14
+ export type ExecutionRequestInit = {
15
+ /** The function calls to be executed. */
16
+ calls: FunctionCall[];
17
+ /** Any transient auth witnesses needed for this execution */
18
+ authWitnesses?: AuthWitness[];
19
+ /** Any transient hashed arguments for this execution */
20
+ hashedArguments?: HashedValues[];
21
+ /** Data passed through an oracle for this execution. */
22
+ capsules?: Capsule[];
23
+ /** How the fee is going to be payed */
24
+ fee: FeeOptions;
25
+ /** An optional nonce. Used to repeat a previous tx with a higher fee so that the first one is cancelled */
26
+ nonce?: Fr;
27
+ /** Whether the transaction can be cancelled. If true, an extra nullifier will be emitted: H(nonce, GENERATOR_INDEX__TX_NULLIFIER) */
28
+ cancellable?: boolean;
29
+ };
30
+
31
+ /** Creates transaction execution requests out of a set of function calls. */
32
+ export interface EntrypointInterface {
33
+ /**
34
+ * Generates an execution request out of set of function calls.
35
+ * @param execution - The execution intents to be run.
36
+ * @returns The authenticated transaction execution request.
37
+ */
38
+ createTxExecutionRequest(execution: ExecutionRequestInit): Promise<TxExecutionRequest>;
39
+ }