@aztec/aztec.js 3.0.0-canary.a9708bd → 3.0.0-devnet.2

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 (278) hide show
  1. package/dest/account/account.d.ts +60 -0
  2. package/dest/account/account.d.ts.map +1 -0
  3. package/dest/account/account.js +59 -0
  4. package/dest/account/account_contract.d.ts +5 -5
  5. package/dest/account/account_contract.d.ts.map +1 -1
  6. package/dest/account/account_contract.js +0 -1
  7. package/dest/{wallet/account_wallet_with_private_key.d.ts → account/account_with_secret_key.d.ts} +7 -8
  8. package/dest/account/account_with_secret_key.d.ts.map +1 -0
  9. package/dest/{wallet/account_wallet_with_private_key.js → account/account_with_secret_key.js} +5 -5
  10. package/dest/account/index.d.ts +1 -4
  11. package/dest/account/index.d.ts.map +1 -1
  12. package/dest/account/index.js +1 -4
  13. package/dest/account/signerless_account.d.ts +24 -0
  14. package/dest/account/signerless_account.d.ts.map +1 -0
  15. package/dest/account/signerless_account.js +27 -0
  16. package/dest/api/abi.d.ts +1 -0
  17. package/dest/api/abi.d.ts.map +1 -1
  18. package/dest/api/account.d.ts +4 -2
  19. package/dest/api/account.d.ts.map +1 -1
  20. package/dest/api/account.js +3 -1
  21. package/dest/api/addresses.d.ts +1 -0
  22. package/dest/api/addresses.d.ts.map +1 -1
  23. package/dest/api/addresses.js +1 -0
  24. package/dest/api/authorization.d.ts +2 -0
  25. package/dest/api/authorization.d.ts.map +1 -1
  26. package/dest/api/authorization.js +2 -0
  27. package/dest/api/block.d.ts +3 -0
  28. package/dest/api/block.d.ts.map +1 -0
  29. package/dest/api/block.js +2 -0
  30. package/dest/api/contract.d.ts +4 -5
  31. package/dest/api/contract.d.ts.map +1 -1
  32. package/dest/api/contract.js +3 -3
  33. package/dest/api/crypto.d.ts +2 -0
  34. package/dest/api/crypto.d.ts.map +1 -0
  35. package/dest/api/crypto.js +1 -0
  36. package/dest/api/ethereum.d.ts +0 -1
  37. package/dest/api/ethereum.d.ts.map +1 -1
  38. package/dest/api/ethereum.js +0 -1
  39. package/dest/api/events.d.ts +12 -0
  40. package/dest/api/events.d.ts.map +1 -0
  41. package/dest/api/events.js +30 -0
  42. package/dest/api/fee.d.ts +1 -2
  43. package/dest/api/fee.d.ts.map +1 -1
  44. package/dest/api/fee.js +0 -1
  45. package/dest/api/keys.d.ts +4 -0
  46. package/dest/api/keys.d.ts.map +1 -0
  47. package/dest/api/keys.js +3 -0
  48. package/dest/api/log.d.ts +1 -0
  49. package/dest/api/log.d.ts.map +1 -1
  50. package/dest/api/log.js +1 -0
  51. package/dest/api/messaging.d.ts +3 -0
  52. package/dest/api/messaging.d.ts.map +1 -0
  53. package/dest/api/messaging.js +2 -0
  54. package/dest/api/node.d.ts +21 -0
  55. package/dest/api/node.d.ts.map +1 -0
  56. package/dest/api/node.js +18 -0
  57. package/dest/api/note.d.ts +2 -0
  58. package/dest/api/note.d.ts.map +1 -0
  59. package/dest/api/note.js +1 -0
  60. package/dest/api/protocol.d.ts +3 -0
  61. package/dest/api/protocol.d.ts.map +1 -0
  62. package/dest/api/protocol.js +2 -0
  63. package/dest/api/trees.d.ts +3 -0
  64. package/dest/api/trees.d.ts.map +1 -0
  65. package/dest/api/trees.js +2 -0
  66. package/dest/api/tx.d.ts +2 -0
  67. package/dest/api/tx.d.ts.map +1 -0
  68. package/dest/api/tx.js +1 -0
  69. package/dest/api/utils.d.ts +10 -6
  70. package/dest/api/utils.d.ts.map +1 -1
  71. package/dest/api/utils.js +10 -5
  72. package/dest/api/wallet.d.ts +4 -1
  73. package/dest/api/wallet.d.ts.map +1 -1
  74. package/dest/api/wallet.js +4 -1
  75. package/dest/contract/base_contract_interaction.d.ts +6 -48
  76. package/dest/contract/base_contract_interaction.d.ts.map +1 -1
  77. package/dest/contract/base_contract_interaction.js +6 -106
  78. package/dest/contract/batch_call.d.ts +6 -14
  79. package/dest/contract/batch_call.d.ts.map +1 -1
  80. package/dest/contract/batch_call.js +42 -52
  81. package/dest/contract/contract.d.ts +1 -1
  82. package/dest/contract/contract.d.ts.map +1 -1
  83. package/dest/contract/contract.js +2 -12
  84. package/dest/contract/contract_base.d.ts +1 -1
  85. package/dest/contract/contract_base.d.ts.map +1 -1
  86. package/dest/contract/contract_function_interaction.d.ts +29 -40
  87. package/dest/contract/contract_function_interaction.d.ts.map +1 -1
  88. package/dest/contract/contract_function_interaction.js +41 -53
  89. package/dest/contract/deploy_method.d.ts +63 -56
  90. package/dest/contract/deploy_method.d.ts.map +1 -1
  91. package/dest/contract/deploy_method.js +68 -86
  92. package/dest/contract/deploy_sent_tx.d.ts +0 -1
  93. package/dest/contract/deploy_sent_tx.d.ts.map +1 -1
  94. package/dest/contract/deploy_sent_tx.js +7 -10
  95. package/dest/contract/interaction_options.d.ts +74 -19
  96. package/dest/contract/interaction_options.d.ts.map +1 -1
  97. package/dest/contract/interaction_options.js +51 -3
  98. package/dest/contract/sent_tx.d.ts +3 -3
  99. package/dest/contract/sent_tx.d.ts.map +1 -1
  100. package/dest/contract/sent_tx.js +5 -5
  101. package/dest/contract/wait_for_proven.d.ts +3 -3
  102. package/dest/contract/wait_for_proven.d.ts.map +1 -1
  103. package/dest/contract/wait_for_proven.js +2 -2
  104. package/dest/deployment/publish_instance.d.ts +1 -1
  105. package/dest/deployment/publish_instance.d.ts.map +1 -1
  106. package/dest/deployment/publish_instance.js +2 -5
  107. package/dest/ethereum/portal_manager.d.ts +3 -4
  108. package/dest/ethereum/portal_manager.d.ts.map +1 -1
  109. package/dest/ethereum/portal_manager.js +3 -5
  110. package/dest/fee/fee_juice_payment_method_with_claim.d.ts +12 -7
  111. package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -1
  112. package/dest/fee/fee_juice_payment_method_with_claim.js +21 -12
  113. package/dest/fee/fee_payment_method.d.ts +26 -0
  114. package/dest/fee/fee_payment_method.d.ts.map +1 -0
  115. package/dest/fee/fee_payment_method.js +3 -0
  116. package/dest/fee/private_fee_payment_method.d.ts +22 -5
  117. package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
  118. package/dest/fee/private_fee_payment_method.js +34 -13
  119. package/dest/fee/public_fee_payment_method.d.ts +22 -5
  120. package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
  121. package/dest/fee/public_fee_payment_method.js +37 -14
  122. package/dest/fee/sponsored_fee_payment.d.ts +2 -0
  123. package/dest/fee/sponsored_fee_payment.d.ts.map +1 -1
  124. package/dest/fee/sponsored_fee_payment.js +4 -0
  125. package/dest/utils/authwit.d.ts +77 -25
  126. package/dest/utils/authwit.d.ts.map +1 -1
  127. package/dest/utils/authwit.js +219 -24
  128. package/dest/utils/cross_chain.d.ts +24 -0
  129. package/dest/utils/cross_chain.d.ts.map +1 -0
  130. package/dest/utils/cross_chain.js +30 -0
  131. package/dest/utils/fee_juice.d.ts +3 -2
  132. package/dest/utils/fee_juice.d.ts.map +1 -1
  133. package/dest/utils/fee_juice.js +3 -2
  134. package/dest/{fee → wallet}/account_entrypoint_meta_payment_method.d.ts +13 -10
  135. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts.map +1 -0
  136. package/dest/wallet/account_entrypoint_meta_payment_method.js +76 -0
  137. package/dest/wallet/account_manager.d.ts +69 -0
  138. package/dest/wallet/account_manager.d.ts.map +1 -0
  139. package/dest/wallet/account_manager.js +113 -0
  140. package/dest/wallet/base_wallet.d.ts +78 -35
  141. package/dest/wallet/base_wallet.d.ts.map +1 -1
  142. package/dest/wallet/base_wallet.js +216 -48
  143. package/dest/wallet/deploy_account_method.d.ts +52 -0
  144. package/dest/wallet/deploy_account_method.d.ts.map +1 -0
  145. package/dest/wallet/deploy_account_method.js +77 -0
  146. package/dest/wallet/index.d.ts +2 -15
  147. package/dest/wallet/index.d.ts.map +1 -1
  148. package/dest/wallet/index.js +2 -19
  149. package/dest/wallet/wallet.d.ts +2473 -6
  150. package/dest/wallet/wallet.d.ts.map +1 -1
  151. package/dest/wallet/wallet.js +202 -3
  152. package/package.json +25 -21
  153. package/src/account/account.ts +97 -0
  154. package/src/account/account_contract.ts +4 -6
  155. package/src/{wallet/account_wallet_with_private_key.ts → account/account_with_secret_key.ts} +6 -8
  156. package/src/account/index.ts +1 -4
  157. package/src/account/signerless_account.ts +46 -0
  158. package/src/api/abi.ts +11 -0
  159. package/src/api/account.ts +4 -2
  160. package/src/api/addresses.ts +1 -0
  161. package/src/api/authorization.ts +11 -0
  162. package/src/api/block.ts +2 -0
  163. package/src/api/contract.ts +16 -8
  164. package/src/api/crypto.ts +1 -0
  165. package/src/api/ethereum.ts +0 -1
  166. package/src/api/events.ts +44 -0
  167. package/src/api/fee.ts +1 -2
  168. package/src/api/keys.ts +8 -0
  169. package/src/api/log.ts +1 -0
  170. package/src/api/messaging.ts +2 -0
  171. package/src/api/node.ts +20 -0
  172. package/src/api/note.ts +1 -0
  173. package/src/api/protocol.ts +2 -0
  174. package/src/api/trees.ts +2 -0
  175. package/src/api/tx.ts +11 -0
  176. package/src/api/utils.ts +12 -19
  177. package/src/api/wallet.ts +33 -5
  178. package/src/contract/base_contract_interaction.ts +9 -138
  179. package/src/contract/batch_call.ts +52 -61
  180. package/src/contract/contract.ts +2 -12
  181. package/src/contract/contract_function_interaction.ts +65 -97
  182. package/src/contract/deploy_method.ts +117 -99
  183. package/src/contract/deploy_sent_tx.ts +4 -10
  184. package/src/contract/interaction_options.ts +126 -24
  185. package/src/contract/sent_tx.ts +4 -4
  186. package/src/contract/wait_for_proven.ts +4 -4
  187. package/src/deployment/publish_instance.ts +3 -8
  188. package/src/ethereum/portal_manager.ts +4 -12
  189. package/src/fee/fee_juice_payment_method_with_claim.ts +26 -17
  190. package/src/fee/fee_payment_method.ts +26 -0
  191. package/src/fee/private_fee_payment_method.ts +60 -41
  192. package/src/fee/public_fee_payment_method.ts +73 -49
  193. package/src/fee/sponsored_fee_payment.ts +6 -0
  194. package/src/utils/authwit.ts +250 -38
  195. package/src/utils/cross_chain.ts +53 -0
  196. package/src/utils/fee_juice.ts +4 -3
  197. package/src/wallet/account_entrypoint_meta_payment_method.ts +105 -0
  198. package/src/wallet/account_manager.ts +154 -0
  199. package/src/wallet/base_wallet.ts +287 -78
  200. package/src/wallet/deploy_account_method.ts +125 -0
  201. package/src/wallet/index.ts +2 -32
  202. package/src/wallet/wallet.ts +357 -29
  203. package/dest/account_manager/account_manager.d.ts +0 -119
  204. package/dest/account_manager/account_manager.d.ts.map +0 -1
  205. package/dest/account_manager/account_manager.js +0 -202
  206. package/dest/account_manager/deploy_account_sent_tx.d.ts +0 -30
  207. package/dest/account_manager/deploy_account_sent_tx.d.ts.map +0 -1
  208. package/dest/account_manager/deploy_account_sent_tx.js +0 -29
  209. package/dest/account_manager/index.d.ts +0 -3
  210. package/dest/account_manager/index.d.ts.map +0 -1
  211. package/dest/account_manager/index.js +0 -2
  212. package/dest/api/interfaces.d.ts +0 -2
  213. package/dest/api/interfaces.d.ts.map +0 -1
  214. package/dest/api/interfaces.js +0 -1
  215. package/dest/api/log_id.d.ts +0 -2
  216. package/dest/api/log_id.d.ts.map +0 -1
  217. package/dest/api/log_id.js +0 -1
  218. package/dest/api/rpc.d.ts +0 -3
  219. package/dest/api/rpc.d.ts.map +0 -1
  220. package/dest/api/rpc.js +0 -2
  221. package/dest/api/tx_hash.d.ts +0 -2
  222. package/dest/api/tx_hash.d.ts.map +0 -1
  223. package/dest/api/tx_hash.js +0 -1
  224. package/dest/contract/deploy_proven_tx.d.ts +0 -21
  225. package/dest/contract/deploy_proven_tx.d.ts.map +0 -1
  226. package/dest/contract/deploy_proven_tx.js +0 -21
  227. package/dest/contract/proven_tx.d.ts +0 -21
  228. package/dest/contract/proven_tx.d.ts.map +0 -1
  229. package/dest/contract/proven_tx.js +0 -23
  230. package/dest/ethereum/l1_contracts.d.ts +0 -3
  231. package/dest/ethereum/l1_contracts.d.ts.map +0 -1
  232. package/dest/ethereum/l1_contracts.js +0 -13
  233. package/dest/fee/account_entrypoint_meta_payment_method.d.ts.map +0 -1
  234. package/dest/fee/account_entrypoint_meta_payment_method.js +0 -64
  235. package/dest/fee/fee_juice_payment_method.d.ts +0 -14
  236. package/dest/fee/fee_juice_payment_method.d.ts.map +0 -1
  237. package/dest/fee/fee_juice_payment_method.js +0 -21
  238. package/dest/fee/utils.d.ts +0 -13
  239. package/dest/fee/utils.d.ts.map +0 -1
  240. package/dest/fee/utils.js +0 -32
  241. package/dest/index.d.ts +0 -59
  242. package/dest/index.d.ts.map +0 -1
  243. package/dest/index.js +0 -62
  244. package/dest/rpc_clients/node/index.d.ts +0 -12
  245. package/dest/rpc_clients/node/index.d.ts.map +0 -1
  246. package/dest/rpc_clients/node/index.js +0 -72
  247. package/dest/rpc_clients/pxe_client.d.ts +0 -10
  248. package/dest/rpc_clients/pxe_client.d.ts.map +0 -1
  249. package/dest/rpc_clients/pxe_client.js +0 -23
  250. package/dest/utils/pxe.d.ts +0 -4
  251. package/dest/utils/pxe.d.ts.map +0 -1
  252. package/dest/utils/pxe.js +0 -14
  253. package/dest/wallet/account_wallet.d.ts +0 -74
  254. package/dest/wallet/account_wallet.d.ts.map +0 -1
  255. package/dest/wallet/account_wallet.js +0 -232
  256. package/dest/wallet/account_wallet_with_private_key.d.ts.map +0 -1
  257. package/dest/wallet/signerless_wallet.d.ts +0 -23
  258. package/dest/wallet/signerless_wallet.d.ts.map +0 -1
  259. package/dest/wallet/signerless_wallet.js +0 -33
  260. package/src/account_manager/account_manager.ts +0 -276
  261. package/src/account_manager/deploy_account_sent_tx.ts +0 -46
  262. package/src/account_manager/index.ts +0 -2
  263. package/src/api/interfaces.ts +0 -1
  264. package/src/api/log_id.ts +0 -1
  265. package/src/api/rpc.ts +0 -2
  266. package/src/api/tx_hash.ts +0 -1
  267. package/src/contract/deploy_proven_tx.ts +0 -45
  268. package/src/contract/proven_tx.ts +0 -36
  269. package/src/ethereum/l1_contracts.ts +0 -21
  270. package/src/fee/account_entrypoint_meta_payment_method.ts +0 -89
  271. package/src/fee/fee_juice_payment_method.ts +0 -25
  272. package/src/fee/utils.ts +0 -39
  273. package/src/index.ts +0 -85
  274. package/src/rpc_clients/node/index.ts +0 -77
  275. package/src/rpc_clients/pxe_client.ts +0 -25
  276. package/src/utils/pxe.ts +0 -17
  277. package/src/wallet/account_wallet.ts +0 -246
  278. package/src/wallet/signerless_wallet.ts +0 -56
@@ -0,0 +1,69 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { CompleteAddress, type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
3
+ import type { AccountContract } from '../account/account_contract.js';
4
+ import { AccountWithSecretKey } from '../account/account_with_secret_key.js';
5
+ import type { Salt } from '../account/index.js';
6
+ import type { AccountInterface } from '../account/interface.js';
7
+ import { DeployAccountMethod } from './deploy_account_method.js';
8
+ import type { Wallet } from './wallet.js';
9
+ /**
10
+ * Manages a user account. Provides methods for calculating the account's address and other related data,
11
+ * plus a helper to return a preconfigured deploy method.
12
+ */
13
+ export declare class AccountManager {
14
+ private wallet;
15
+ private secretKey;
16
+ private accountContract;
17
+ private instance;
18
+ /**
19
+ * Contract instantiation salt for the account contract
20
+ */
21
+ readonly salt: Salt;
22
+ private constructor();
23
+ static create(wallet: Wallet, secretKey: Fr, accountContract: AccountContract, salt?: Salt): Promise<AccountManager>;
24
+ protected getPublicKeys(): import("@aztec/stdlib/keys").PublicKeys;
25
+ protected getPublicKeysHash(): Fr | Promise<Fr>;
26
+ /**
27
+ * Returns the entrypoint for this account as defined by its account contract.
28
+ * @returns An entrypoint.
29
+ */
30
+ getAccountInterface(): Promise<AccountInterface>;
31
+ /**
32
+ * Gets the calculated complete address associated with this account.
33
+ * Does not require the account to have been published for public execution.
34
+ * @returns The address, partial address, and encryption public key.
35
+ */
36
+ getCompleteAddress(): Promise<CompleteAddress>;
37
+ /**
38
+ * Returns the secret key used to derive the rest of the privacy keys for this contract
39
+ */
40
+ getSecretKey(): Fr;
41
+ get address(): import("../api/addresses.js").AztecAddress;
42
+ /**
43
+ * Returns the contract instance definition associated with this account.
44
+ * Does not require the account to have been published for public execution.
45
+ * @returns ContractInstance instance.
46
+ */
47
+ getInstance(): ContractInstanceWithAddress;
48
+ /**
49
+ * Returns a Wallet instance associated with this account. Use it to create Contract
50
+ * instances to be interacted with from this account.
51
+ * @returns A Wallet instance.
52
+ */
53
+ getAccount(): Promise<AccountWithSecretKey>;
54
+ /**
55
+ * Returns the account contract that backs this account.
56
+ * @returns The account contract
57
+ */
58
+ getAccountContract(): AccountContract;
59
+ /**
60
+ * Returns a preconfigured deploy method that contains all the necessary function
61
+ * calls to deploy the account contract.
62
+ */
63
+ getDeployMethod(): Promise<DeployAccountMethod>;
64
+ /**
65
+ * Returns whether this account contract has an initializer function.
66
+ */
67
+ hasInitializer(): Promise<boolean>;
68
+ }
69
+ //# sourceMappingURL=account_manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account_manager.d.ts","sourceRoot":"","sources":["../../src/wallet/account_manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EACL,eAAe,EACf,KAAK,2BAA2B,EAEjC,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;;GAGG;AACH,qBAAa,cAAc;IAEvB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,eAAe;IACvB,OAAO,CAAC,QAAQ;IAChB;;OAEG;aACa,IAAI,EAAE,IAAI;IAR5B,OAAO;WAWM,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,eAAe,EAAE,eAAe,EAAE,IAAI,CAAC,EAAE,IAAI;IAoBhG,SAAS,CAAC,aAAa;IAIvB,SAAS,CAAC,iBAAiB;IAI3B;;;OAGG;IACU,mBAAmB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAM7D;;;;OAIG;IACI,kBAAkB,IAAI,OAAO,CAAC,eAAe,CAAC;IAIrD;;OAEG;IACI,YAAY;IAInB,IAAI,OAAO,+CAEV;IAED;;;;OAIG;IACI,WAAW,IAAI,2BAA2B;IAIjD;;;;OAIG;IACU,UAAU,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAKxD;;;OAGG;IACH,kBAAkB,IAAI,eAAe;IAIrC;;;OAGG;IACU,eAAe,IAAI,OAAO,CAAC,mBAAmB,CAAC;IA0B5D;;OAEG;IACU,cAAc;CAG5B"}
@@ -0,0 +1,113 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { CompleteAddress, getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
3
+ import { deriveKeys } from '@aztec/stdlib/keys';
4
+ import { AccountWithSecretKey } from '../account/account_with_secret_key.js';
5
+ import { Contract } from '../contract/contract.js';
6
+ import { DeployAccountMethod } from './deploy_account_method.js';
7
+ /**
8
+ * Manages a user account. Provides methods for calculating the account's address and other related data,
9
+ * plus a helper to return a preconfigured deploy method.
10
+ */ export class AccountManager {
11
+ wallet;
12
+ secretKey;
13
+ accountContract;
14
+ instance;
15
+ salt;
16
+ constructor(wallet, secretKey, accountContract, instance, /**
17
+ * Contract instantiation salt for the account contract
18
+ */ salt){
19
+ this.wallet = wallet;
20
+ this.secretKey = secretKey;
21
+ this.accountContract = accountContract;
22
+ this.instance = instance;
23
+ this.salt = salt;
24
+ }
25
+ static async create(wallet, secretKey, accountContract, salt) {
26
+ const { publicKeys } = await deriveKeys(secretKey);
27
+ salt = salt !== undefined ? new Fr(salt) : Fr.random();
28
+ const { constructorName, constructorArgs } = await accountContract.getInitializationFunctionAndArgs() ?? {
29
+ constructorName: undefined,
30
+ constructorArgs: undefined
31
+ };
32
+ const artifact = await accountContract.getContractArtifact();
33
+ const instance = await getContractInstanceFromInstantiationParams(artifact, {
34
+ constructorArtifact: constructorName,
35
+ constructorArgs,
36
+ salt: salt,
37
+ publicKeys
38
+ });
39
+ return new AccountManager(wallet, secretKey, accountContract, instance, salt);
40
+ }
41
+ getPublicKeys() {
42
+ return this.instance.publicKeys;
43
+ }
44
+ getPublicKeysHash() {
45
+ return this.getPublicKeys().hash();
46
+ }
47
+ /**
48
+ * Returns the entrypoint for this account as defined by its account contract.
49
+ * @returns An entrypoint.
50
+ */ async getAccountInterface() {
51
+ const chainInfo = await this.wallet.getChainInfo();
52
+ const completeAddress = await this.getCompleteAddress();
53
+ return this.accountContract.getInterface(completeAddress, chainInfo);
54
+ }
55
+ /**
56
+ * Gets the calculated complete address associated with this account.
57
+ * Does not require the account to have been published for public execution.
58
+ * @returns The address, partial address, and encryption public key.
59
+ */ getCompleteAddress() {
60
+ return CompleteAddress.fromSecretKeyAndInstance(this.secretKey, this.instance);
61
+ }
62
+ /**
63
+ * Returns the secret key used to derive the rest of the privacy keys for this contract
64
+ */ getSecretKey() {
65
+ return this.secretKey;
66
+ }
67
+ get address() {
68
+ return this.instance.address;
69
+ }
70
+ /**
71
+ * Returns the contract instance definition associated with this account.
72
+ * Does not require the account to have been published for public execution.
73
+ * @returns ContractInstance instance.
74
+ */ getInstance() {
75
+ return this.instance;
76
+ }
77
+ /**
78
+ * Returns a Wallet instance associated with this account. Use it to create Contract
79
+ * instances to be interacted with from this account.
80
+ * @returns A Wallet instance.
81
+ */ async getAccount() {
82
+ const accountInterface = await this.getAccountInterface();
83
+ return new AccountWithSecretKey(accountInterface, this.secretKey, this.salt);
84
+ }
85
+ /**
86
+ * Returns the account contract that backs this account.
87
+ * @returns The account contract
88
+ */ getAccountContract() {
89
+ return this.accountContract;
90
+ }
91
+ /**
92
+ * Returns a preconfigured deploy method that contains all the necessary function
93
+ * calls to deploy the account contract.
94
+ */ async getDeployMethod() {
95
+ const artifact = await this.accountContract.getContractArtifact();
96
+ if (!await this.hasInitializer()) {
97
+ // TODO(https://github.com/AztecProtocol/aztec-packages/issues/15576):
98
+ // there should be a path which enables an account contract's class & instance to be published,
99
+ // even if the account contract doesn't have an initializer function. This should not throw.
100
+ throw new Error(`Account contract ${artifact.name} does not have an initializer function to call.`);
101
+ }
102
+ const { constructorName, constructorArgs } = await this.accountContract.getInitializationFunctionAndArgs() ?? {
103
+ constructorName: undefined,
104
+ constructorArgs: undefined
105
+ };
106
+ return new DeployAccountMethod(this.getPublicKeys(), this.wallet, artifact, (address)=>Contract.at(address, artifact, this.wallet), new Fr(this.salt), constructorArgs, constructorName);
107
+ }
108
+ /**
109
+ * Returns whether this account contract has an initializer function.
110
+ */ async hasInitializer() {
111
+ return await this.accountContract.getInitializationFunctionAndArgs() !== undefined;
112
+ }
113
+ }
@@ -1,48 +1,91 @@
1
- import type { FeeOptions, TxExecutionOptions } from '@aztec/entrypoints/interfaces';
2
- import type { ExecutionPayload } from '@aztec/entrypoints/payload';
3
- import type { Fr } from '@aztec/foundation/fields';
4
- import type { ContractArtifact } from '@aztec/stdlib/abi';
1
+ import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
2
+ import type { ChainInfo } from '@aztec/entrypoints/interfaces';
3
+ import { ExecutionPayload } from '@aztec/entrypoints/payload';
4
+ import { Fr } from '@aztec/foundation/fields';
5
+ import type { ContractArtifact, EventMetadataDefinition } from '@aztec/stdlib/abi';
5
6
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
6
7
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
7
- import type { CompleteAddress, ContractInstanceWithAddress, NodeInfo } from '@aztec/stdlib/contract';
8
- import type { GasFees } from '@aztec/stdlib/gas';
9
- import type { ContractClassMetadata, ContractMetadata, EventMetadataDefinition, PXE, PXEInfo } from '@aztec/stdlib/interfaces/client';
10
- import type { PrivateExecutionResult, SimulationOverrides, Tx, TxExecutionRequest, TxHash, TxProfileResult, TxProvingResult, TxReceipt, TxSimulationResult, UtilitySimulationResult } from '@aztec/stdlib/tx';
11
- import type { IntentAction, IntentInnerHash } from '../utils/authwit.js';
12
- import type { Wallet } from './wallet.js';
8
+ import { type ContractClassMetadata, type ContractInstanceWithAddress, type ContractInstantiationData, type ContractMetadata } from '@aztec/stdlib/contract';
9
+ import { GasSettings } from '@aztec/stdlib/gas';
10
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
11
+ import type { TxExecutionRequest, TxHash, TxProfileResult, TxReceipt, TxSimulationResult, UtilitySimulationResult } from '@aztec/stdlib/tx';
12
+ import type { Account } from '../account/account.js';
13
+ import type { FeePaymentMethod } from '../fee/fee_payment_method.js';
14
+ import type { CallIntent, IntentInnerHash } from '../utils/authwit.js';
15
+ import type { Aliased, BatchResults, BatchableMethods, BatchedMethod, ContractInstanceAndArtifact, ProfileOptions, SendOptions, SimulateOptions, UserFeeOptions, Wallet } from './wallet.js';
16
+ /**
17
+ * Options to configure fee payment for a transaction
18
+ */
19
+ export type FeeOptions = {
20
+ /**
21
+ * A wallet-provided fallback fee payment method that is used only if the transaction that is being constructed
22
+ * doesn't already include one
23
+ */
24
+ walletFeePaymentMethod?: FeePaymentMethod;
25
+ /** Configuration options for the account to properly handle the selected fee payment method */
26
+ accountFeePaymentMethodOptions: AccountFeePaymentMethodOptions;
27
+ /** The gas settings to use for the transaction */
28
+ gasSettings: GasSettings;
29
+ };
13
30
  /**
14
31
  * A base class for Wallet implementations
15
32
  */
16
33
  export declare abstract class BaseWallet implements Wallet {
17
- protected readonly pxe: PXE;
18
- constructor(pxe: PXE);
19
- abstract getCompleteAddress(): CompleteAddress;
20
- abstract getChainId(): Fr;
21
- abstract getVersion(): Fr;
22
- abstract createTxExecutionRequest(exec: ExecutionPayload, fee: FeeOptions, options: TxExecutionOptions): Promise<TxExecutionRequest>;
23
- abstract createAuthWit(intent: Fr | Buffer | IntentInnerHash | IntentAction): Promise<AuthWitness>;
24
- getAddress(): AztecAddress;
25
- registerSender(address: AztecAddress): Promise<AztecAddress>;
26
- getSenders(): Promise<AztecAddress[]>;
27
- removeSender(address: AztecAddress): Promise<void>;
28
- registerContract(contract: {
29
- /** Instance */ instance: ContractInstanceWithAddress;
30
- /** Associated artifact */ artifact?: ContractArtifact;
31
- }): Promise<void>;
32
- registerContractClass(artifact: ContractArtifact): Promise<void>;
33
- updateContract(contractAddress: AztecAddress, artifact: ContractArtifact): Promise<void>;
34
- proveTx(txRequest: TxExecutionRequest, privateExecutionResult: PrivateExecutionResult): Promise<TxProvingResult>;
35
- profileTx(txRequest: TxExecutionRequest, profileMode: 'gates' | 'execution-steps' | 'full', skipProofGeneration?: boolean, msgSender?: AztecAddress): Promise<TxProfileResult>;
36
- simulateTx(txRequest: TxExecutionRequest, simulatePublic: boolean, skipTxValidation?: boolean, skipFeeEnforcement?: boolean, overrides?: SimulationOverrides): Promise<TxSimulationResult>;
37
- sendTx(tx: Tx): Promise<TxHash>;
38
- getCurrentBaseFees(): Promise<GasFees>;
34
+ protected readonly pxe: any;
35
+ protected readonly aztecNode: AztecNode;
36
+ protected log: import("@aztec/foundation/log").Logger;
37
+ protected baseFeePadding: number;
38
+ protected cancellableTransactions: boolean;
39
+ protected constructor(pxe: any, aztecNode: AztecNode);
40
+ protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
41
+ abstract getAccounts(): Promise<Aliased<AztecAddress>[]>;
42
+ /**
43
+ * Returns the list of aliased contacts associated with the wallet.
44
+ * This base implementation directly returns PXE's senders, but note that in general contacts are a superset of senders.
45
+ * - Senders: Addresses we check during synching in case they sent us notes,
46
+ * - Contacts: more general concept akin to a phone's contact list.
47
+ * @returns The aliased collection of AztecAddresses that form this wallet's address book
48
+ */
49
+ getAddressBook(): Promise<Aliased<AztecAddress>[]>;
50
+ getChainInfo(): Promise<ChainInfo>;
51
+ protected createTxExecutionRequestFromPayloadAndFee(executionPayload: ExecutionPayload, from: AztecAddress, feeOptions: FeeOptions): Promise<TxExecutionRequest>;
52
+ createAuthWit(from: AztecAddress, messageHashOrIntent: Fr | Buffer | IntentInnerHash | CallIntent): Promise<AuthWitness>;
53
+ batch<const T extends readonly BatchedMethod<keyof BatchableMethods>[]>(methods: T): Promise<BatchResults<T>>;
54
+ /**
55
+ * Returns default values for the transaction fee options
56
+ * if they were omitted by the user.
57
+ * @param from - The address where the transaction is being sent from
58
+ * @param userFeeOptions - User-provided fee options, which might be incomplete
59
+ * @returns - Populated fee options that can be used to create a transaction execution request
60
+ */
61
+ protected getDefaultFeeOptions(from: AztecAddress, userFeeOptions?: UserFeeOptions): Promise<FeeOptions>;
62
+ /**
63
+ * Returns unreasonably high gas limits in order to execute a simulation
64
+ * with the goal of estimating its gas cost. It will otherwise try to respect
65
+ * the user-specified fee options, filling the gaps with default values as needed.
66
+ * @param from - The address where the transaction is being sent from
67
+ * @param userFeeOptions - User-provided fee options to use as a basis for the fully populated `FeeOptions` type.
68
+ */
69
+ protected getFeeOptionsForGasEstimation(from: AztecAddress, userFeeOptions?: UserFeeOptions): Promise<{
70
+ gasSettings: GasSettings;
71
+ /**
72
+ * A wallet-provided fallback fee payment method that is used only if the transaction that is being constructed
73
+ * doesn't already include one
74
+ */
75
+ walletFeePaymentMethod?: FeePaymentMethod;
76
+ /** Configuration options for the account to properly handle the selected fee payment method */
77
+ accountFeePaymentMethodOptions: AccountFeePaymentMethodOptions;
78
+ }>;
79
+ registerSender(address: AztecAddress, _alias?: string): Promise<AztecAddress>;
80
+ registerContract(instanceData: AztecAddress | ContractInstanceWithAddress | ContractInstantiationData | ContractInstanceAndArtifact, artifact?: ContractArtifact, secretKey?: Fr): Promise<ContractInstanceWithAddress>;
81
+ simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult>;
82
+ profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult>;
83
+ sendTx(executionPayload: ExecutionPayload, opts: SendOptions): Promise<TxHash>;
84
+ protected contextualizeError(err: Error, ...context: string[]): Error;
39
85
  simulateUtility(functionName: string, args: any[], to: AztecAddress, authwits?: AuthWitness[], from?: AztecAddress): Promise<UtilitySimulationResult>;
40
- getNodeInfo(): Promise<NodeInfo>;
41
- getPXEInfo(): Promise<PXEInfo>;
42
86
  getContractClassMetadata(id: Fr, includeArtifact?: boolean): Promise<ContractClassMetadata>;
43
87
  getContractMetadata(address: AztecAddress): Promise<ContractMetadata>;
44
88
  getTxReceipt(txHash: TxHash): Promise<TxReceipt>;
45
89
  getPrivateEvents<T>(contractAddress: AztecAddress, event: EventMetadataDefinition, from: number, limit: number, recipients?: AztecAddress[]): Promise<T[]>;
46
- getPublicEvents<T>(event: EventMetadataDefinition, from: number, limit: number): Promise<T[]>;
47
90
  }
48
91
  //# sourceMappingURL=base_wallet.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"base_wallet.d.ts","sourceRoot":"","sources":["../../src/wallet/base_wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACpF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,2BAA2B,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACrG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EACV,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,GAAG,EACH,OAAO,EACR,MAAM,iCAAiC,CAAC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,EAAE,GAAG,EAAE,EACX,EAAE,EAAE,YAAY,EAChB,QAAQ,CAAC,EAAE,WAAW,EAAE,EACxB,IAAI,CAAC,EAAE,YAAY,GAClB,OAAO,CAAC,uBAAuB,CAAC;IAInC,wBAAwB,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,GAAE,OAAe,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAGlG,mBAAmB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAIrE,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAIhD,gBAAgB,CAAC,CAAC,EAChB,eAAe,EAAE,YAAY,EAC7B,KAAK,EAAE,uBAAuB,EAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,UAAU,GAAE,YAAY,EAAO,GAC9B,OAAO,CAAC,CAAC,EAAE,CAAC;CAGhB"}
@@ -1,55 +1,228 @@
1
+ import { GAS_ESTIMATION_DA_GAS_LIMIT, GAS_ESTIMATION_L2_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT } from '@aztec/constants';
2
+ import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
3
+ import { mergeExecutionPayloads } from '@aztec/entrypoints/payload';
4
+ import { Fr } from '@aztec/foundation/fields';
5
+ import { createLogger } from '@aztec/foundation/log';
6
+ import { computePartialAddress, getContractClassFromArtifact, getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
7
+ import { SimulationError } from '@aztec/stdlib/errors';
8
+ import { Gas, GasSettings } from '@aztec/stdlib/gas';
9
+ import { inspect } from 'util';
1
10
  /**
2
11
  * A base class for Wallet implementations
3
12
  */ export class BaseWallet {
4
13
  pxe;
5
- constructor(pxe){
14
+ aztecNode;
15
+ log;
16
+ baseFeePadding;
17
+ cancellableTransactions;
18
+ // Protected because we want to force wallets to instantiate their own PXE.
19
+ constructor(// TODO: We cannot type here pxe because we cannot import that package as that would result in a circular
20
+ // dependency. This will eventually get resolved by the introduction of @aztec/wallet-sdk package.
21
+ pxe, aztecNode){
6
22
  this.pxe = pxe;
7
- }
8
- getAddress() {
9
- return this.getCompleteAddress().address;
10
- }
11
- registerSender(address) {
23
+ this.aztecNode = aztecNode;
24
+ this.log = createLogger('aztecjs:base_wallet');
25
+ this.baseFeePadding = 0.5;
26
+ this.cancellableTransactions = false;
27
+ }
28
+ /**
29
+ * Returns the list of aliased contacts associated with the wallet.
30
+ * This base implementation directly returns PXE's senders, but note that in general contacts are a superset of senders.
31
+ * - Senders: Addresses we check during synching in case they sent us notes,
32
+ * - Contacts: more general concept akin to a phone's contact list.
33
+ * @returns The aliased collection of AztecAddresses that form this wallet's address book
34
+ */ async getAddressBook() {
35
+ const senders = await this.pxe.getSenders();
36
+ return senders.map((sender)=>({
37
+ item: sender,
38
+ alias: ''
39
+ }));
40
+ }
41
+ async getChainInfo() {
42
+ const { l1ChainId, rollupVersion } = await this.aztecNode.getNodeInfo();
43
+ return {
44
+ chainId: new Fr(l1ChainId),
45
+ version: new Fr(rollupVersion)
46
+ };
47
+ }
48
+ async createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions) {
49
+ const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
50
+ const executionOptions = {
51
+ txNonce: Fr.random(),
52
+ cancellable: this.cancellableTransactions,
53
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
54
+ };
55
+ const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
56
+ feeExecutionPayload,
57
+ executionPayload
58
+ ]) : executionPayload;
59
+ const fromAccount = await this.getAccountFromAddress(from);
60
+ return fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, executionOptions);
61
+ }
62
+ async createAuthWit(from, messageHashOrIntent) {
63
+ const account = await this.getAccountFromAddress(from);
64
+ return account.createAuthWit(messageHashOrIntent);
65
+ }
66
+ async batch(methods) {
67
+ const results = [];
68
+ for (const method of methods){
69
+ const { name, args } = method;
70
+ // Type safety is guaranteed by the BatchedMethod type, which ensures that:
71
+ // 1. `name` is a valid batchable method name
72
+ // 2. `args` matches the parameter types of that specific method
73
+ // 3. The return type is correctly mapped in BatchResults<T>
74
+ // We use dynamic dispatch here for simplicity, but the types are enforced at the call site.
75
+ const fn = this[name];
76
+ const result = await fn.apply(this, args);
77
+ // Wrap result with method name for discriminated union deserialization
78
+ results.push({
79
+ name,
80
+ result
81
+ });
82
+ }
83
+ return results;
84
+ }
85
+ /**
86
+ * Returns default values for the transaction fee options
87
+ * if they were omitted by the user.
88
+ * @param from - The address where the transaction is being sent from
89
+ * @param userFeeOptions - User-provided fee options, which might be incomplete
90
+ * @returns - Populated fee options that can be used to create a transaction execution request
91
+ */ async getDefaultFeeOptions(from, userFeeOptions) {
92
+ const maxFeesPerGas = userFeeOptions?.gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentBaseFees()).mul(1 + this.baseFeePadding);
93
+ let accountFeePaymentMethodOptions;
94
+ // The transaction does not include a fee payment method, so we set the flag
95
+ // for the account to use its fee juice balance
96
+ if (!userFeeOptions?.embeddedPaymentMethodFeePayer) {
97
+ accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE;
98
+ } else {
99
+ // The transaction includes fee payment method, so we check if we are the fee payer for it
100
+ // (this can only happen if the embedded payment method is FeeJuiceWithClaim)
101
+ accountFeePaymentMethodOptions = from.equals(userFeeOptions.embeddedPaymentMethodFeePayer) ? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM : AccountFeePaymentMethodOptions.EXTERNAL;
102
+ }
103
+ const gasSettings = GasSettings.default({
104
+ ...userFeeOptions?.gasSettings,
105
+ maxFeesPerGas
106
+ });
107
+ this.log.debug(`Using L2 gas settings`, gasSettings);
108
+ return {
109
+ gasSettings,
110
+ walletFeePaymentMethod: undefined,
111
+ accountFeePaymentMethodOptions
112
+ };
113
+ }
114
+ /**
115
+ * Returns unreasonably high gas limits in order to execute a simulation
116
+ * with the goal of estimating its gas cost. It will otherwise try to respect
117
+ * the user-specified fee options, filling the gaps with default values as needed.
118
+ * @param from - The address where the transaction is being sent from
119
+ * @param userFeeOptions - User-provided fee options to use as a basis for the fully populated `FeeOptions` type.
120
+ */ async getFeeOptionsForGasEstimation(from, userFeeOptions) {
121
+ const defaultFeeOptions = await this.getDefaultFeeOptions(from, userFeeOptions);
122
+ const { gasSettings: { maxFeesPerGas, maxPriorityFeesPerGas } } = defaultFeeOptions;
123
+ // Use unrealistically high gas limits for estimation to avoid running out of gas.
124
+ // They will be tuned down after the simulation.
125
+ const gasSettingsForEstimation = new GasSettings(new Gas(GAS_ESTIMATION_DA_GAS_LIMIT, GAS_ESTIMATION_L2_GAS_LIMIT), new Gas(GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT), maxFeesPerGas, maxPriorityFeesPerGas);
126
+ return {
127
+ ...defaultFeeOptions,
128
+ gasSettings: gasSettingsForEstimation
129
+ };
130
+ }
131
+ registerSender(address, _alias = '') {
12
132
  return this.pxe.registerSender(address);
13
133
  }
14
- getSenders() {
15
- return this.pxe.getSenders();
16
- }
17
- async removeSender(address) {
18
- await this.pxe.removeSender(address);
19
- }
20
- registerContract(contract) {
21
- return this.pxe.registerContract(contract);
22
- }
23
- registerContractClass(artifact) {
24
- return this.pxe.registerContractClass(artifact);
25
- }
26
- updateContract(contractAddress, artifact) {
27
- return this.pxe.updateContract(contractAddress, artifact);
28
- }
29
- proveTx(txRequest, privateExecutionResult) {
30
- return this.pxe.proveTx(txRequest, privateExecutionResult);
31
- }
32
- profileTx(txRequest, profileMode, skipProofGeneration, msgSender) {
33
- return this.pxe.profileTx(txRequest, profileMode, skipProofGeneration, msgSender);
34
- }
35
- simulateTx(txRequest, simulatePublic, skipTxValidation, skipFeeEnforcement, overrides) {
36
- return this.pxe.simulateTx(txRequest, simulatePublic, skipTxValidation, skipFeeEnforcement, overrides);
37
- }
38
- sendTx(tx) {
39
- return this.pxe.sendTx(tx);
40
- }
41
- getCurrentBaseFees() {
42
- return this.pxe.getCurrentBaseFees();
134
+ async registerContract(instanceData, artifact, secretKey) {
135
+ /** Determines if the provided instance data is already a contract instance with an address. */ function isInstanceWithAddress(instanceData) {
136
+ return instanceData.address !== undefined;
137
+ }
138
+ /** Determines if the provided instance data is contract instantiation data */ function isContractInstantiationData(instanceData) {
139
+ return instanceData.salt !== undefined;
140
+ }
141
+ /** Determines if the provided instance data is already a contract */ function isContractInstanceAndArtifact(instanceData) {
142
+ return instanceData.instance !== undefined && instanceData.artifact !== undefined;
143
+ }
144
+ let instance;
145
+ if (isContractInstanceAndArtifact(instanceData)) {
146
+ instance = instanceData.instance;
147
+ await this.pxe.registerContract(instanceData);
148
+ } else if (isInstanceWithAddress(instanceData)) {
149
+ instance = instanceData;
150
+ await this.pxe.registerContract({
151
+ artifact,
152
+ instance
153
+ });
154
+ } else if (isContractInstantiationData(instanceData)) {
155
+ if (!artifact) {
156
+ throw new Error(`Contract artifact must be provided when registering a contract using instantiation data`);
157
+ }
158
+ instance = await getContractInstanceFromInstantiationParams(artifact, instanceData);
159
+ await this.pxe.registerContract({
160
+ artifact,
161
+ instance
162
+ });
163
+ } else {
164
+ if (!artifact) {
165
+ throw new Error(`Contract artifact must be provided when registering a contract using an address`);
166
+ }
167
+ const { contractInstance: maybeContractInstance } = await this.pxe.getContractMetadata(instanceData);
168
+ if (!maybeContractInstance) {
169
+ throw new Error(`Contract instance at ${instanceData.toString()} has not been registered in the wallet's PXE`);
170
+ }
171
+ instance = maybeContractInstance;
172
+ const thisContractClass = await getContractClassFromArtifact(artifact);
173
+ if (!thisContractClass.id.equals(instance.currentContractClassId)) {
174
+ // wallet holds an outdated version of this contract
175
+ await this.pxe.updateContract(instance.address, artifact);
176
+ instance.currentContractClassId = thisContractClass.id;
177
+ }
178
+ }
179
+ if (secretKey) {
180
+ await this.pxe.registerAccount(secretKey, await computePartialAddress(instance));
181
+ }
182
+ return instance;
183
+ }
184
+ async simulateTx(executionPayload, opts) {
185
+ const feeOptions = opts.fee?.estimateGas ? await this.getFeeOptionsForGasEstimation(opts.from, opts.fee) : await this.getDefaultFeeOptions(opts.from, opts.fee);
186
+ const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
187
+ return this.pxe.simulateTx(txRequest, true, opts?.skipTxValidation, opts?.skipFeeEnforcement ?? true);
188
+ }
189
+ async profileTx(executionPayload, opts) {
190
+ const fee = await this.getDefaultFeeOptions(opts.from, opts.fee);
191
+ const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, fee);
192
+ return this.pxe.profileTx(txRequest, opts.profileMode, opts.skipProofGeneration ?? true);
193
+ }
194
+ async sendTx(executionPayload, opts) {
195
+ const fee = await this.getDefaultFeeOptions(opts.from, opts.fee);
196
+ const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, fee);
197
+ const provenTx = await this.pxe.proveTx(txRequest);
198
+ const tx = await provenTx.toTx();
199
+ const txHash = tx.getTxHash();
200
+ if (await this.aztecNode.getTxEffect(txHash)) {
201
+ throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
202
+ }
203
+ this.log.debug(`Sending transaction ${txHash}`);
204
+ await this.aztecNode.sendTx(tx).catch((err)=>{
205
+ throw this.contextualizeError(err, inspect(tx));
206
+ });
207
+ this.log.info(`Sent transaction ${txHash}`);
208
+ return txHash;
209
+ }
210
+ contextualizeError(err, ...context) {
211
+ let contextStr = '';
212
+ if (context.length > 0) {
213
+ contextStr = `\nContext:\n${context.join('\n')}`;
214
+ }
215
+ if (err instanceof SimulationError) {
216
+ err.setAztecContext(contextStr);
217
+ } else {
218
+ this.log.error(err.name, err);
219
+ this.log.debug(contextStr);
220
+ }
221
+ return err;
43
222
  }
44
223
  simulateUtility(functionName, args, to, authwits, from) {
45
224
  return this.pxe.simulateUtility(functionName, args, to, authwits, from);
46
225
  }
47
- getNodeInfo() {
48
- return this.pxe.getNodeInfo();
49
- }
50
- getPXEInfo() {
51
- return this.pxe.getPXEInfo();
52
- }
53
226
  getContractClassMetadata(id, includeArtifact = false) {
54
227
  return this.pxe.getContractClassMetadata(id, includeArtifact);
55
228
  }
@@ -57,14 +230,9 @@
57
230
  return this.pxe.getContractMetadata(address);
58
231
  }
59
232
  getTxReceipt(txHash) {
60
- return this.pxe.getTxReceipt(txHash);
233
+ return this.aztecNode.getTxReceipt(txHash);
61
234
  }
62
- getPrivateEvents(contractAddress, event, from, limit, recipients = [
63
- this.getCompleteAddress().address
64
- ]) {
235
+ getPrivateEvents(contractAddress, event, from, limit, recipients = []) {
65
236
  return this.pxe.getPrivateEvents(contractAddress, event, from, limit, recipients);
66
237
  }
67
- getPublicEvents(event, from, limit) {
68
- return this.pxe.getPublicEvents(event, from, limit);
69
- }
70
238
  }