@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
@@ -1,27 +1,33 @@
1
+ import type { ChainInfo } from '@aztec/entrypoints/interfaces';
1
2
  import { Fr } from '@aztec/foundation/fields';
2
- import type { FunctionCall } from '@aztec/stdlib/abi';
3
+ import { type FunctionCall } from '@aztec/stdlib/abi';
4
+ import { AuthWitness } from '@aztec/stdlib/auth-witness';
3
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
6
+ import type { TxProfileResult } from '@aztec/stdlib/tx';
4
7
  import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
5
- /** Metadata for the intent */
6
- export type IntentMetadata = {
7
- /** The chain id to approve */
8
- chainId: Fr;
9
- /** The version to approve */
10
- version: Fr;
11
- };
8
+ import type { ProfileInteractionOptions, SendInteractionOptions, SimulateInteractionOptions, SimulationReturn } from '../contract/interaction_options.js';
9
+ import type { SentTx } from '../contract/sent_tx.js';
10
+ import type { Wallet } from '../wallet/index.js';
12
11
  /** Intent with an inner hash */
13
12
  export type IntentInnerHash = {
14
13
  /** The consumer */
15
14
  consumer: AztecAddress;
16
15
  /** The action to approve */
17
- innerHash: Buffer | Fr;
16
+ innerHash: Buffer<ArrayBuffer> | Fr;
17
+ };
18
+ /** Intent with a call */
19
+ export type CallIntent = {
20
+ /** The caller to approve */
21
+ caller: AztecAddress;
22
+ /** The call to approve */
23
+ call: FunctionCall;
18
24
  };
19
- /** Intent with an action */
20
- export type IntentAction = {
25
+ /** Intent with a ContractFunctionInteraction */
26
+ export type ContractFunctionInteractionCallIntent = {
21
27
  /** The caller to approve */
22
28
  caller: AztecAddress;
23
29
  /** The action to approve */
24
- action: ContractFunctionInteraction | FunctionCall;
30
+ action: ContractFunctionInteraction;
25
31
  };
26
32
  /**
27
33
  * Compute an authentication witness message hash from an intent and metadata
@@ -33,7 +39,7 @@ export type IntentAction = {
33
39
  * and use it for the authentication check.
34
40
  * Therefore, any allowed `innerHash` will therefore also have information around where it can be spent (version, chainId) and who can spend it (consumer).
35
41
  *
36
- * If using the `IntentAction`, the caller is the address that is making the call, for a token approval from Alice to Bob, this would be Bob.
42
+ * If using the `CallIntent`, the caller is the address that is making the call, for a token approval from Alice to Bob, this would be Bob.
37
43
  * The action is then used along with the `caller` to compute the `innerHash` and the consumer.
38
44
  *
39
45
  *
@@ -44,22 +50,68 @@ export type IntentAction = {
44
50
  * @param metadata - The metadata for the intent (chainId, version)
45
51
  * @returns The message hash for the action
46
52
  */
47
- export declare const computeAuthWitMessageHash: (intent: IntentInnerHash | IntentAction, metadata: IntentMetadata) => Promise<Fr>;
53
+ export declare const computeAuthWitMessageHash: (intent: IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent, metadata: ChainInfo) => Promise<Fr>;
48
54
  /**
49
- * Computes the inner authwitness hash for a function call, for it to later be combined with the metadata
55
+ * Compute an authentication witness message hash from an intent and metadata. This is just
56
+ * a wrapper around computeAuthwitMessageHash that allows receiving an already computed messageHash as input
57
+ * @param messageHashOrIntent - The precomputed messageHash or intent to approve (consumer and innerHash or caller and call/action)
58
+ * @param metadata - The metadata for the intent (chainId, version)
59
+ * @returns The message hash for the intent
60
+ */
61
+ export declare function getMessageHashFromIntent(messageHashOrIntent: Fr | Buffer | IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent, chainInfo: ChainInfo): Promise<Fr>;
62
+ /**
63
+ * Computes the inner authwitness hash for either a function call or an action, for it to later be combined with the metadata
50
64
  * required for the outer hash and eventually the full AuthWitness.
51
65
  * @param caller - Who is going to be calling the function
52
- * @param fnCall - The function call to compute the inner hash from
53
- * @returns The inner hash for the function call
54
- **/
55
- export declare const computeInnerAuthWitHashFromFunctionCall: (caller: AztecAddress, fnCall: FunctionCall) => Promise<Fr>;
56
- /**
57
- * Computes the inner authwitness hash for an action, that can either be a ContractFunctionInteraction
58
- * or an isolated FunctionCall. Since the former is just a wrapper around the latter, we can just extract
59
- * the first (and only) call from the ContractFunctionInteraction and use it to compute the inner hash.
60
- * @param caller - Who is going to be performing the action
61
- * @param action - The ContractFunctionInteraction or FunctionCall to compute the inner hash for
66
+ * @param action - The action to compute the inner hash from
62
67
  * @returns The inner hash for the action
63
68
  **/
64
69
  export declare const computeInnerAuthWitHashFromAction: (caller: AztecAddress, action: FunctionCall | ContractFunctionInteraction) => Promise<Fr>;
70
+ /**
71
+ * Lookup the validity of an authwit in private and public contexts.
72
+ *
73
+ * Uses the chain id and version of the wallet.
74
+ *
75
+ * @param wallet - The wallet use to simulate and read the public data
76
+ * @param onBehalfOf - The address of the "approver"
77
+ * @param intent - The consumer and inner hash or the caller and action to lookup
78
+ * @param witness - The computed authentication witness to check
79
+ * @returns - A struct containing the validity of the authwit in private and public contexts.
80
+ */
81
+ export declare function lookupValidity(wallet: Wallet, onBehalfOf: AztecAddress, intent: IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent, witness: AuthWitness): Promise<{
82
+ /** boolean flag indicating if the authwit is valid in private context */
83
+ isValidInPrivate: boolean;
84
+ /** boolean flag indicating if the authwit is valid in public context */
85
+ isValidInPublic: boolean;
86
+ }>;
87
+ /**
88
+ * Convenience class designed to wrap the very common interaction of setting a public authwit in the AuthRegistry contract
89
+ */
90
+ export declare class SetPublicAuthwitContractInteraction extends ContractFunctionInteraction {
91
+ private from;
92
+ private constructor();
93
+ static create(wallet: Wallet, from: AztecAddress, messageHashOrIntent: Fr | Buffer | IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent, authorized: boolean): Promise<SetPublicAuthwitContractInteraction>;
94
+ /**
95
+ * Overrides the simulate method, adding the sender of the authwit (authorizer) as from
96
+ * and preventing misuse
97
+ * @param options - An optional object containing additional configuration for the transaction.
98
+ * @returns The result of the transaction as returned by the contract function.
99
+ */
100
+ simulate<T extends SimulateInteractionOptions>(options: Omit<T, 'from'>): Promise<SimulationReturn<T['includeMetadata']>>;
101
+ /**
102
+ * Overrides the profile method, adding the sender of the authwit (authorizer) as from
103
+ * and preventing misuse
104
+ * @param options - Same options as `simulate`, plus profiling method
105
+ * @returns An object containing the function return value and profile result.
106
+ */
107
+ profile(options?: Omit<ProfileInteractionOptions, 'from'>): Promise<TxProfileResult>;
108
+ /**
109
+ * Overrides the send method, adding the sender of the authwit (authorizer) as from
110
+ * and preventing misuse
111
+ * @param options - An optional object containing 'fee' options information
112
+ * @returns A SentTx instance for tracking the transaction status and information.
113
+ */
114
+ send(options?: Omit<SendInteractionOptions, 'from'>): SentTx;
115
+ private static getSetAuthorizedAbi;
116
+ }
65
117
  //# sourceMappingURL=authwit.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authwit.d.ts","sourceRoot":"","sources":["../../src/utils/authwit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAGhE,OAAO,EAAE,2BAA2B,EAAE,MAAM,8CAA8C,CAAC;AAE3F,8BAA8B;AAC9B,MAAM,MAAM,cAAc,GAAG;IAC3B,8BAA8B;IAC9B,OAAO,EAAE,EAAE,CAAC;IACZ,8BAA8B;IAC9B,OAAO,EAAE,EAAE,CAAC;CACb,CAAC;AAEF,gCAAgC;AAChC,MAAM,MAAM,eAAe,GAAG;IAC5B,qBAAqB;IACrB,QAAQ,EAAE,YAAY,CAAC;IACvB,4BAA4B;IAC5B,SAAS,EAAE,MAAM,GAAG,EAAE,CAAC;CACxB,CAAC;AAEF,4BAA4B;AAC5B,MAAM,MAAM,YAAY,GAAG;IACzB,6BAA6B;IAC7B,MAAM,EAAE,YAAY,CAAC;IACrB,4BAA4B;IAC5B,MAAM,EAAE,2BAA2B,GAAG,YAAY,CAAC;CACpD,CAAC;AAGF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,yBAAyB,GAAU,QAAQ,eAAe,GAAG,YAAY,EAAE,UAAU,cAAc,gBAiB/G,CAAC;AAGF;;;;;;IAMI;AACJ,eAAO,MAAM,uCAAuC,GAAU,QAAQ,YAAY,EAAE,QAAQ,YAAY,gBAEvG,CAAC;AAEF;;;;;;;IAOI;AACJ,eAAO,MAAM,iCAAiC,GAC5C,QAAQ,YAAY,EACpB,QAAQ,YAAY,GAAG,2BAA2B,gBAInD,CAAC"}
1
+ {"version":3,"file":"authwit.d.ts","sourceRoot":"","sources":["../../src/utils/authwit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,EAAiD,KAAK,YAAY,EAAgB,MAAM,mBAAmB,CAAC;AACnH,OAAO,EAAE,WAAW,EAAoD,MAAM,4BAA4B,CAAC;AAC3G,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,EAAE,2BAA2B,EAAE,MAAM,8CAA8C,CAAC;AAC3F,OAAO,KAAK,EACV,yBAAyB,EACzB,sBAAsB,EACtB,0BAA0B,EAC1B,gBAAgB,EACjB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,gCAAgC;AAChC,MAAM,MAAM,eAAe,GAAG;IAC5B,qBAAqB;IACrB,QAAQ,EAAE,YAAY,CAAC;IACvB,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC;CACrC,CAAC;AAEF,yBAAyB;AACzB,MAAM,MAAM,UAAU,GAAG;IACvB,6BAA6B;IAC7B,MAAM,EAAE,YAAY,CAAC;IACrB,0BAA0B;IAC1B,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,gDAAgD;AAChD,MAAM,MAAM,qCAAqC,GAAG;IAClD,6BAA6B;IAC7B,MAAM,EAAE,YAAY,CAAC;IACrB,4BAA4B;IAC5B,MAAM,EAAE,2BAA2B,CAAC;CACrC,CAAC;AAaF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,yBAAyB,GACpC,QAAQ,eAAe,GAAG,UAAU,GAAG,qCAAqC,EAC5E,UAAU,SAAS,gBAiBpB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,wBAAwB,CAC5C,mBAAmB,EAAE,EAAE,GAAG,MAAM,GAAG,eAAe,GAAG,UAAU,GAAG,qCAAqC,EACvG,SAAS,EAAE,SAAS,eAYrB;AAED;;;;;;IAMI;AACJ,eAAO,MAAM,iCAAiC,GAC5C,QAAQ,YAAY,EACpB,QAAQ,YAAY,GAAG,2BAA2B,gBAInD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,YAAY,EACxB,MAAM,EAAE,eAAe,GAAG,UAAU,GAAG,qCAAqC,EAC5E,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC;IACT,yEAAyE;IACzE,gBAAgB,EAAE,OAAO,CAAC;IAC1B,wEAAwE;IACxE,eAAe,EAAE,OAAO,CAAC;CAC1B,CAAC,CAkED;AAED;;GAEG;AACH,qBAAa,mCAAoC,SAAQ,2BAA2B;IAGhF,OAAO,CAAC,IAAI;IAFd,OAAO;WAYM,MAAM,CACjB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,YAAY,EAClB,mBAAmB,EAAE,EAAE,GAAG,MAAM,GAAG,eAAe,GAAG,UAAU,GAAG,qCAAqC,EACvG,UAAU,EAAE,OAAO;IAOrB;;;;;OAKG;IACa,QAAQ,CAAC,CAAC,SAAS,0BAA0B,EAC3D,OAAO,EAAE,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,GACvB,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAQlD;;;;;OAKG;IACa,OAAO,CACrB,OAAO,GAAE,IAAI,CAAC,yBAAyB,EAAE,MAAM,CAA4B,GAC1E,OAAO,CAAC,eAAe,CAAC;IAI3B;;;;;OAKG;IACa,IAAI,CAAC,OAAO,GAAE,IAAI,CAAC,sBAAsB,EAAE,MAAM,CAAM,GAAG,MAAM;IAIhF,OAAO,CAAC,MAAM,CAAC,mBAAmB;CAuBnC"}
@@ -1,8 +1,12 @@
1
1
  import { Fr } from '@aztec/foundation/fields';
2
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
3
+ import { FunctionType } from '@aztec/stdlib/abi';
2
4
  import { computeInnerAuthWitHash, computeOuterAuthWitHash } from '@aztec/stdlib/auth-witness';
3
5
  import { computeVarArgsHash } from '@aztec/stdlib/hash';
4
6
  import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
5
- // docs:start:authwit_computeAuthWitMessageHash
7
+ /** Identifies ContractFunctionInteractionCallIntents */ function isContractFunctionIntractionCallIntent(messageHashOrIntent) {
8
+ return 'caller' in messageHashOrIntent && 'action' in messageHashOrIntent && messageHashOrIntent.action instanceof ContractFunctionInteraction;
9
+ }
6
10
  /**
7
11
  * Compute an authentication witness message hash from an intent and metadata
8
12
  *
@@ -13,7 +17,7 @@ import { ContractFunctionInteraction } from '../contract/contract_function_inter
13
17
  * and use it for the authentication check.
14
18
  * Therefore, any allowed `innerHash` will therefore also have information around where it can be spent (version, chainId) and who can spend it (consumer).
15
19
  *
16
- * If using the `IntentAction`, the caller is the address that is making the call, for a token approval from Alice to Bob, this would be Bob.
20
+ * If using the `CallIntent`, the caller is the address that is making the call, for a token approval from Alice to Bob, this would be Bob.
17
21
  * The action is then used along with the `caller` to compute the `innerHash` and the consumer.
18
22
  *
19
23
  *
@@ -27,39 +31,230 @@ import { ContractFunctionInteraction } from '../contract/contract_function_inter
27
31
  const chainId = metadata.chainId;
28
32
  const version = metadata.version;
29
33
  if ('caller' in intent) {
30
- const fnCall = intent.action instanceof ContractFunctionInteraction ? (await intent.action.request()).calls[0] : intent.action;
31
- return computeOuterAuthWitHash(fnCall.to, chainId, version, await computeInnerAuthWitHashFromFunctionCall(intent.caller, fnCall));
34
+ const call = isContractFunctionIntractionCallIntent(intent) ? await intent.action.getFunctionCall() : intent.call;
35
+ return computeOuterAuthWitHash(call.to, chainId, version, await computeInnerAuthWitHashFromAction(intent.caller, call));
32
36
  } else {
33
37
  const inner = Buffer.isBuffer(intent.innerHash) ? Fr.fromBuffer(intent.innerHash) : intent.innerHash;
34
38
  return computeOuterAuthWitHash(intent.consumer, chainId, version, inner);
35
39
  }
36
40
  };
37
- // docs:end:authwit_computeAuthWitMessageHash
38
41
  /**
39
- * Computes the inner authwitness hash for a function call, for it to later be combined with the metadata
42
+ * Compute an authentication witness message hash from an intent and metadata. This is just
43
+ * a wrapper around computeAuthwitMessageHash that allows receiving an already computed messageHash as input
44
+ * @param messageHashOrIntent - The precomputed messageHash or intent to approve (consumer and innerHash or caller and call/action)
45
+ * @param metadata - The metadata for the intent (chainId, version)
46
+ * @returns The message hash for the intent
47
+ */ export async function getMessageHashFromIntent(messageHashOrIntent, chainInfo) {
48
+ let messageHash;
49
+ const { chainId, version } = chainInfo;
50
+ if (Buffer.isBuffer(messageHashOrIntent)) {
51
+ messageHash = Fr.fromBuffer(messageHashOrIntent);
52
+ } else if (messageHashOrIntent instanceof Fr) {
53
+ messageHash = messageHashOrIntent;
54
+ } else {
55
+ messageHash = await computeAuthWitMessageHash(messageHashOrIntent, {
56
+ chainId,
57
+ version
58
+ });
59
+ }
60
+ return messageHash;
61
+ }
62
+ /**
63
+ * Computes the inner authwitness hash for either a function call or an action, for it to later be combined with the metadata
40
64
  * required for the outer hash and eventually the full AuthWitness.
41
65
  * @param caller - Who is going to be calling the function
42
- * @param fnCall - The function call to compute the inner hash from
43
- * @returns The inner hash for the function call
44
- **/ export const computeInnerAuthWitHashFromFunctionCall = async (caller, fnCall)=>{
45
- return computeInnerAuthWitHash([
46
- caller.toField(),
47
- fnCall.selector.toField(),
48
- await computeVarArgsHash(fnCall.args)
49
- ]);
50
- };
51
- /**
52
- * Computes the inner authwitness hash for an action, that can either be a ContractFunctionInteraction
53
- * or an isolated FunctionCall. Since the former is just a wrapper around the latter, we can just extract
54
- * the first (and only) call from the ContractFunctionInteraction and use it to compute the inner hash.
55
- * @param caller - Who is going to be performing the action
56
- * @param action - The ContractFunctionInteraction or FunctionCall to compute the inner hash for
66
+ * @param action - The action to compute the inner hash from
57
67
  * @returns The inner hash for the action
58
68
  **/ export const computeInnerAuthWitHashFromAction = async (caller, action)=>{
59
- action = action instanceof ContractFunctionInteraction ? (await action.request()).calls[0] : action;
69
+ const call = action instanceof ContractFunctionInteraction ? await action.getFunctionCall() : action;
60
70
  return computeInnerAuthWitHash([
61
71
  caller.toField(),
62
- action.selector.toField(),
63
- await computeVarArgsHash(action.args)
72
+ call.selector.toField(),
73
+ await computeVarArgsHash(call.args)
64
74
  ]);
65
75
  };
76
+ /**
77
+ * Lookup the validity of an authwit in private and public contexts.
78
+ *
79
+ * Uses the chain id and version of the wallet.
80
+ *
81
+ * @param wallet - The wallet use to simulate and read the public data
82
+ * @param onBehalfOf - The address of the "approver"
83
+ * @param intent - The consumer and inner hash or the caller and action to lookup
84
+ * @param witness - The computed authentication witness to check
85
+ * @returns - A struct containing the validity of the authwit in private and public contexts.
86
+ */ export async function lookupValidity(wallet, onBehalfOf, intent, witness) {
87
+ let innerHash, consumer;
88
+ if ('caller' in intent) {
89
+ const call = isContractFunctionIntractionCallIntent(intent) ? await intent.action.getFunctionCall() : intent.call;
90
+ innerHash = await computeInnerAuthWitHashFromAction(intent.caller, call);
91
+ consumer = call.to;
92
+ } else if (Buffer.isBuffer(intent.innerHash)) {
93
+ innerHash = Fr.fromBuffer(intent.innerHash);
94
+ consumer = intent.consumer;
95
+ } else {
96
+ ({ innerHash, consumer } = intent);
97
+ }
98
+ const chainInfo = await wallet.getChainInfo();
99
+ const messageHash = await getMessageHashFromIntent(intent, chainInfo);
100
+ const results = {
101
+ isValidInPrivate: false,
102
+ isValidInPublic: false
103
+ };
104
+ // Check private
105
+ const lookupValidityAbi = {
106
+ name: 'lookup_validity',
107
+ isInitializer: false,
108
+ functionType: FunctionType.UTILITY,
109
+ isInternal: false,
110
+ isStatic: false,
111
+ parameters: [
112
+ {
113
+ name: 'message_hash',
114
+ type: {
115
+ kind: 'field'
116
+ },
117
+ visibility: 'private'
118
+ }
119
+ ],
120
+ returnTypes: [
121
+ {
122
+ kind: 'boolean'
123
+ }
124
+ ],
125
+ errorTypes: {}
126
+ };
127
+ try {
128
+ results.isValidInPrivate = await new ContractFunctionInteraction(wallet, onBehalfOf, lookupValidityAbi, [
129
+ consumer,
130
+ innerHash
131
+ ]).simulate({
132
+ from: onBehalfOf,
133
+ authWitnesses: [
134
+ witness
135
+ ]
136
+ });
137
+ // TODO: Narrow down the error to make sure simulation failed due to an invalid authwit
138
+ // eslint-disable-next-line no-empty
139
+ } catch {}
140
+ // check public
141
+ const isConsumableAbi = {
142
+ name: 'utility_is_consumable',
143
+ isInitializer: false,
144
+ functionType: FunctionType.UTILITY,
145
+ isInternal: false,
146
+ isStatic: false,
147
+ parameters: [
148
+ {
149
+ name: 'address',
150
+ type: {
151
+ fields: [
152
+ {
153
+ name: 'inner',
154
+ type: {
155
+ kind: 'field'
156
+ }
157
+ }
158
+ ],
159
+ kind: 'struct',
160
+ path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress'
161
+ },
162
+ visibility: 'private'
163
+ },
164
+ {
165
+ name: 'message_hash',
166
+ type: {
167
+ kind: 'field'
168
+ },
169
+ visibility: 'private'
170
+ }
171
+ ],
172
+ returnTypes: [
173
+ {
174
+ kind: 'boolean'
175
+ }
176
+ ],
177
+ errorTypes: {}
178
+ };
179
+ results.isValidInPublic = await new ContractFunctionInteraction(wallet, ProtocolContractAddress.AuthRegistry, isConsumableAbi, [
180
+ onBehalfOf,
181
+ messageHash
182
+ ]).simulate({
183
+ from: onBehalfOf
184
+ });
185
+ return results;
186
+ }
187
+ /**
188
+ * Convenience class designed to wrap the very common interaction of setting a public authwit in the AuthRegistry contract
189
+ */ export class SetPublicAuthwitContractInteraction extends ContractFunctionInteraction {
190
+ from;
191
+ constructor(wallet, from, messageHash, authorized){
192
+ super(wallet, ProtocolContractAddress.AuthRegistry, SetPublicAuthwitContractInteraction.getSetAuthorizedAbi(), [
193
+ messageHash,
194
+ authorized
195
+ ]), this.from = from;
196
+ }
197
+ static async create(wallet, from, messageHashOrIntent, authorized) {
198
+ const chainInfo = await wallet.getChainInfo();
199
+ const messageHash = await getMessageHashFromIntent(messageHashOrIntent, chainInfo);
200
+ return new SetPublicAuthwitContractInteraction(wallet, from, messageHash, authorized);
201
+ }
202
+ // eslint-disable-next-line jsdoc/require-jsdoc
203
+ simulate(options = {}) {
204
+ return super.simulate({
205
+ ...options,
206
+ from: this.from
207
+ });
208
+ }
209
+ /**
210
+ * Overrides the profile method, adding the sender of the authwit (authorizer) as from
211
+ * and preventing misuse
212
+ * @param options - Same options as `simulate`, plus profiling method
213
+ * @returns An object containing the function return value and profile result.
214
+ */ profile(options = {
215
+ profileMode: 'gates'
216
+ }) {
217
+ return super.profile({
218
+ ...options,
219
+ from: this.from
220
+ });
221
+ }
222
+ /**
223
+ * Overrides the send method, adding the sender of the authwit (authorizer) as from
224
+ * and preventing misuse
225
+ * @param options - An optional object containing 'fee' options information
226
+ * @returns A SentTx instance for tracking the transaction status and information.
227
+ */ send(options = {}) {
228
+ return super.send({
229
+ ...options,
230
+ from: this.from
231
+ });
232
+ }
233
+ static getSetAuthorizedAbi() {
234
+ return {
235
+ name: 'set_authorized',
236
+ isInitializer: false,
237
+ functionType: FunctionType.PUBLIC,
238
+ isInternal: true,
239
+ isStatic: false,
240
+ parameters: [
241
+ {
242
+ name: 'message_hash',
243
+ type: {
244
+ kind: 'field'
245
+ },
246
+ visibility: 'private'
247
+ },
248
+ {
249
+ name: 'authorize',
250
+ type: {
251
+ kind: 'boolean'
252
+ },
253
+ visibility: 'private'
254
+ }
255
+ ],
256
+ returnTypes: [],
257
+ errorTypes: {}
258
+ };
259
+ }
260
+ }
@@ -0,0 +1,24 @@
1
+ import type { Fr } from '@aztec/foundation/fields';
2
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
3
+ /**
4
+ * Waits for the L1 to L2 message to be ready to be consumed.
5
+ * @param node - Aztec node instance used to obtain the information about the message
6
+ * @param l1ToL2MessageHash - Hash of the L1 to L2 message
7
+ * @param opts - Options
8
+ */
9
+ export declare function waitForL1ToL2MessageReady(node: Pick<AztecNode, 'getBlockNumber' | 'getL1ToL2MessageBlock'>, l1ToL2MessageHash: Fr, opts: {
10
+ /** Timeout for the operation in seconds */ timeoutSeconds: number;
11
+ /** True if the message is meant to be consumed from a public function */ forPublicConsumption: boolean;
12
+ }): Promise<boolean>;
13
+ /**
14
+ * Returns whether the L1 to L2 message is ready to be consumed.
15
+ * @param node - Aztec node instance used to obtain the information about the message
16
+ * @param l1ToL2MessageHash - Hash of the L1 to L2 message
17
+ * @param opts - Options
18
+ * @returns True if the message is ready to be consumed, false otherwise
19
+ */
20
+ export declare function isL1ToL2MessageReady(node: Pick<AztecNode, 'getBlockNumber' | 'getL1ToL2MessageBlock'>, l1ToL2MessageHash: Fr, opts: {
21
+ /** True if the message is meant to be consumed from a public function */ forPublicConsumption: boolean;
22
+ /** Cached synced block number for the message (will be fetched from PXE otherwise) */ messageBlockNumber?: number;
23
+ }): Promise<boolean>;
24
+ //# sourceMappingURL=cross_chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cross_chain.d.ts","sourceRoot":"","sources":["../../src/utils/cross_chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAEjE;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,gBAAgB,GAAG,uBAAuB,CAAC,EACjE,iBAAiB,EAAE,EAAE,EACrB,IAAI,EAAE;IACJ,2CAA2C,CAAC,cAAc,EAAE,MAAM,CAAC;IACnE,yEAAyE,CAAC,oBAAoB,EAAE,OAAO,CAAC;CACzG,oBASF;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,gBAAgB,GAAG,uBAAuB,CAAC,EACjE,iBAAiB,EAAE,EAAE,EACrB,IAAI,EAAE;IACJ,yEAAyE,CAAC,oBAAoB,EAAE,OAAO,CAAC;IACxG,sFAAsF,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;CACpH,GACA,OAAO,CAAC,OAAO,CAAC,CAWlB"}
@@ -0,0 +1,30 @@
1
+ import { retryUntil } from '@aztec/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 async function waitForL1ToL2MessageReady(node, l1ToL2MessageHash, opts) {
8
+ const messageBlockNumber = await node.getL1ToL2MessageBlock(l1ToL2MessageHash);
9
+ return retryUntil(()=>isL1ToL2MessageReady(node, l1ToL2MessageHash, {
10
+ ...opts,
11
+ messageBlockNumber
12
+ }), `L1 to L2 message ${l1ToL2MessageHash.toString()} ready`, opts.timeoutSeconds, 1);
13
+ }
14
+ /**
15
+ * Returns whether the L1 to L2 message is ready to be consumed.
16
+ * @param node - Aztec node instance used to obtain the information about the message
17
+ * @param l1ToL2MessageHash - Hash of the L1 to L2 message
18
+ * @param opts - Options
19
+ * @returns True if the message is ready to be consumed, false otherwise
20
+ */ export async function isL1ToL2MessageReady(node, l1ToL2MessageHash, opts) {
21
+ const blockNumber = await node.getBlockNumber();
22
+ const messageBlockNumber = opts.messageBlockNumber ?? await node.getL1ToL2MessageBlock(l1ToL2MessageHash);
23
+ if (messageBlockNumber === undefined) {
24
+ return false;
25
+ }
26
+ // Note that public messages can be consumed 1 block earlier, since the sequencer will include the messages
27
+ // in the L1 to L2 message tree before executing the txs for the block. In private, however, we need to wait
28
+ // until the message is included so we can make use of the membership witness.
29
+ return opts.forPublicConsumption ? blockNumber + 1 >= messageBlockNumber : blockNumber >= messageBlockNumber;
30
+ }
@@ -1,7 +1,8 @@
1
1
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
2
- import type { PXE } from '@aztec/stdlib/interfaces/client';
2
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
3
3
  /**
4
4
  * Returns the owner's fee juice balance.
5
+ * Note: This is used only e2e_sandbox_example test. TODO: Consider nuking.
5
6
  */
6
- export declare function getFeeJuiceBalance(owner: AztecAddress, pxe: PXE): Promise<bigint>;
7
+ export declare function getFeeJuiceBalance(owner: AztecAddress, node: AztecNode): Promise<bigint>;
7
8
  //# sourceMappingURL=fee_juice.d.ts.map
@@ -1 +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,6BAA6B,CAAC;AAEhE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAC;AAE3D;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAGvF"}
1
+ {"version":3,"file":"fee_juice.d.ts","sourceRoot":"","sources":["../../src/utils/fee_juice.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAEjE;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAG9F"}
@@ -3,7 +3,8 @@ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
3
3
  import { deriveStorageSlotInMap } from '@aztec/stdlib/hash';
4
4
  /**
5
5
  * Returns the owner's fee juice balance.
6
- */ export async function getFeeJuiceBalance(owner, pxe) {
6
+ * Note: This is used only e2e_sandbox_example test. TODO: Consider nuking.
7
+ */ export async function getFeeJuiceBalance(owner, node) {
7
8
  const slot = await deriveStorageSlotInMap(new Fr(1), owner);
8
- return (await pxe.getPublicStorageAt(ProtocolContractAddress.FeeJuice, slot)).toBigInt();
9
+ return (await node.getPublicStorageAt('latest', ProtocolContractAddress.FeeJuice, slot)).toBigInt();
9
10
  }
@@ -1,31 +1,34 @@
1
- import type { AuthWitnessProvider, FeePaymentMethod } from '@aztec/entrypoints/interfaces';
2
1
  import { ExecutionPayload } from '@aztec/entrypoints/payload';
3
2
  import { type ContractArtifact, type FunctionArtifact } from '@aztec/stdlib/abi';
4
3
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
4
  import type { GasSettings } from '@aztec/stdlib/gas';
5
+ import type { FeePaymentMethod } from '../fee/fee_payment_method.js';
6
+ import type { Wallet } from './index.js';
6
7
  /**
7
- * Fee payment method that allows a contract to pay for its own deployment
8
+ * Fee payment method that allows an account contract to pay for its own deployment
8
9
  * It works by rerouting the provided fee payment method through the account's entrypoint,
9
- * which sets itself as fee payer.
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.
10
12
  *
11
13
  * Usually, in order to pay fees it is necessary to obtain an ExecutionPayload that encodes the necessary information
12
- * that is sent to the user's account entrypoint, that has plumbing to handle a fee payload.
14
+ * that is sent to the user's account entrypoint, that has plumbing to handle it.
13
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
14
16
  * how to handle this payload.
15
17
  * HOWEVER, the account contract's entrypoint does, so this method reshapes that fee payload into a call to the account contract entrypoint
16
18
  * being deployed with the original fee payload.
17
19
  *
18
- * This class can be seen in action in AccountManager.ts#getSelfPaymentMethod
20
+ * This class can be seen in action in DeployAccountMethod.ts#getSelfPaymentMethod
19
21
  */
20
22
  export declare class AccountEntrypointMetaPaymentMethod implements FeePaymentMethod {
23
+ private wallet;
21
24
  private artifact;
22
- private authWitnessProvider;
23
25
  private feePaymentNameOrArtifact;
24
26
  private accountAddress;
25
- private paymentMethod;
26
- constructor(artifact: ContractArtifact, authWitnessProvider: AuthWitnessProvider, feePaymentNameOrArtifact: string | FunctionArtifact, accountAddress: AztecAddress, paymentMethod: FeePaymentMethod);
27
+ private paymentMethod?;
28
+ constructor(wallet: Wallet, artifact: ContractArtifact, feePaymentNameOrArtifact: string | FunctionArtifact, accountAddress: AztecAddress, paymentMethod?: FeePaymentMethod | undefined);
27
29
  getAsset(): Promise<AztecAddress>;
28
- getExecutionPayload(gasSettings: GasSettings): Promise<ExecutionPayload>;
29
- getFeePayer(gasSettings: GasSettings): Promise<AztecAddress>;
30
+ getExecutionPayload(): Promise<ExecutionPayload>;
31
+ getFeePayer(): Promise<AztecAddress>;
32
+ getGasSettings(): GasSettings | undefined;
30
33
  }
31
34
  //# sourceMappingURL=account_entrypoint_meta_payment_method.d.ts.map
@@ -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":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EAKtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC;;;;;;;;;;;;;;GAcG;AACH,qBAAa,kCAAmC,YAAW,gBAAgB;IAEvE,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,wBAAwB;IAChC,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,aAAa,CAAC;gBAJd,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,gBAAgB,EAC1B,wBAAwB,EAAE,MAAM,GAAG,gBAAgB,EACnD,cAAc,EAAE,YAAY,EAC5B,aAAa,CAAC,EAAE,gBAAgB,YAAA;IAG1C,QAAQ,IAAI,OAAO,CAAC,YAAY,CAAC;IAI3B,mBAAmB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAmDtD,WAAW,IAAI,OAAO,CAAC,YAAY,CAAC;IAIpC,cAAc,IAAI,WAAW,GAAG,SAAS;CAG1C"}
@@ -0,0 +1,76 @@
1
+ import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
2
+ import { EncodedAppEntrypointCalls } from '@aztec/entrypoints/encoding';
3
+ import { ExecutionPayload } from '@aztec/entrypoints/payload';
4
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
5
+ import { FunctionCall, FunctionSelector, encodeArguments, getFunctionArtifactByName } from '@aztec/stdlib/abi';
6
+ /**
7
+ * Fee payment method that allows an account contract to pay for its own deployment
8
+ * It works by rerouting the provided fee payment method through the account's entrypoint,
9
+ * which sets itself as fee payer. If no payment method is provided, it is assumed the
10
+ * account will pay with its own fee juice balance.
11
+ *
12
+ * Usually, in order to pay fees it is necessary to obtain an ExecutionPayload that encodes the necessary information
13
+ * that is sent to the user's account entrypoint, that has plumbing to handle it.
14
+ * If there's no account contract yet (it's being deployed) a MultiCallContract is used, which doesn't have a concept of fees or
15
+ * how to handle this payload.
16
+ * HOWEVER, the account contract's entrypoint does, so this method reshapes that fee payload into a call to the account contract entrypoint
17
+ * being deployed with the original fee payload.
18
+ *
19
+ * This class can be seen in action in DeployAccountMethod.ts#getSelfPaymentMethod
20
+ */ export class AccountEntrypointMetaPaymentMethod {
21
+ wallet;
22
+ artifact;
23
+ feePaymentNameOrArtifact;
24
+ accountAddress;
25
+ paymentMethod;
26
+ constructor(wallet, artifact, feePaymentNameOrArtifact, accountAddress, paymentMethod){
27
+ this.wallet = wallet;
28
+ this.artifact = artifact;
29
+ this.feePaymentNameOrArtifact = feePaymentNameOrArtifact;
30
+ this.accountAddress = accountAddress;
31
+ this.paymentMethod = paymentMethod;
32
+ }
33
+ getAsset() {
34
+ return this.paymentMethod?.getAsset() ?? Promise.resolve(ProtocolContractAddress.FeeJuice);
35
+ }
36
+ async getExecutionPayload() {
37
+ // Get the execution payload for the fee, it includes the calls and potentially authWitnesses
38
+ // It can be empty because the account might attempt to pay for the tx fee using its own
39
+ // FeeJuice balance
40
+ const { calls: feeCalls, authWitnesses: feeAuthwitnesses } = await this.paymentMethod?.getExecutionPayload() ?? ExecutionPayload.empty();
41
+ // Encode the calls for the fee
42
+ const feePayer = await this.paymentMethod?.getFeePayer() ?? this.accountAddress;
43
+ const isFeePayer = feePayer.equals(this.accountAddress);
44
+ let accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.EXTERNAL;
45
+ if (isFeePayer) {
46
+ // If the account is the fee payer, and the incoming fee payload has calls
47
+ // it can only be FeeJuicePaymentMethodWithClaim
48
+ // If the payload has no calls, it's paying using
49
+ // its own fee juice balance
50
+ accountFeePaymentMethodOptions = feeCalls.length === 0 ? AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE : AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM;
51
+ }
52
+ const feeEncodedCalls = await EncodedAppEntrypointCalls.create(feeCalls);
53
+ // Get the entrypoint args
54
+ const args = [
55
+ feeEncodedCalls,
56
+ accountFeePaymentMethodOptions,
57
+ false
58
+ ];
59
+ const feePaymentArtifact = typeof this.feePaymentNameOrArtifact === 'string' ? getFunctionArtifactByName(this.artifact, this.feePaymentNameOrArtifact) : this.feePaymentNameOrArtifact;
60
+ const entrypointCall = new FunctionCall(feePaymentArtifact.name, this.accountAddress, await FunctionSelector.fromNameAndParameters(feePaymentArtifact.name, feePaymentArtifact.parameters), feePaymentArtifact.functionType, false, feePaymentArtifact.isStatic, encodeArguments(feePaymentArtifact, args), feePaymentArtifact.returnTypes);
61
+ // Compute the authwitness required to verify the combined payload
62
+ const payloadAuthWitness = await this.wallet.createAuthWit(this.accountAddress, await feeEncodedCalls.hash());
63
+ return new ExecutionPayload([
64
+ entrypointCall
65
+ ], [
66
+ payloadAuthWitness,
67
+ ...feeAuthwitnesses
68
+ ], [], feeEncodedCalls.hashedArguments);
69
+ }
70
+ getFeePayer() {
71
+ return this.paymentMethod?.getFeePayer() ?? Promise.resolve(this.accountAddress);
72
+ }
73
+ getGasSettings() {
74
+ return this.paymentMethod?.getGasSettings();
75
+ }
76
+ }