@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,12 +1,13 @@
1
- import type { FeePaymentMethod } from '@aztec/entrypoints/interfaces';
2
1
  import { ExecutionPayload } from '@aztec/entrypoints/payload';
3
2
  import { Fr } from '@aztec/foundation/fields';
4
- import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
3
+ import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
5
4
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
6
5
  import { GasSettings } from '@aztec/stdlib/gas';
7
6
 
8
- import type { AccountWallet } from '../wallet/account_wallet.js';
9
- import { simulateWithoutSignature } from './utils.js';
7
+ import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
8
+ import { SetPublicAuthwitContractInteraction } from '../utils/authwit.js';
9
+ import type { Wallet } from '../wallet/wallet.js';
10
+ import type { FeePaymentMethod } from './fee_payment_method.js';
10
11
 
11
12
  /**
12
13
  * Holds information about how the fee for a transaction is to be paid.
@@ -22,45 +23,58 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
22
23
  /**
23
24
  * An auth witness provider to authorize fee payments
24
25
  */
25
- protected wallet: AccountWallet,
26
+ protected sender: AztecAddress,
27
+ /**
28
+ * A wallet to perform the simulation to get the accepted asset
29
+ */
30
+ protected wallet: Wallet,
31
+ /**
32
+ * Gas settings used to compute the maximum fee the user is willing to pay
33
+ */
34
+ protected gasSettings: GasSettings,
26
35
  ) {}
27
36
 
28
37
  /**
29
38
  * The asset used to pay the fee.
30
39
  * @returns The asset used to pay the fee.
31
40
  */
32
- getAsset(): Promise<AztecAddress> {
41
+ async getAsset(): Promise<AztecAddress> {
33
42
  if (!this.assetPromise) {
34
- // We use the utility method to avoid a signature because this function could be triggered
35
- // before the associated account is deployed.
36
- this.assetPromise = simulateWithoutSignature(
37
- this.wallet,
38
- this.paymentContract,
39
- {
40
- name: 'get_accepted_asset',
41
- functionType: FunctionType.PRIVATE,
42
- isInternal: false,
43
- isStatic: false,
44
- parameters: [],
45
- returnTypes: [
46
- {
47
- kind: 'struct',
48
- path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
49
- fields: [
50
- {
51
- name: 'inner',
52
- type: {
53
- kind: 'field',
54
- },
43
+ const abi = {
44
+ name: 'get_accepted_asset',
45
+ functionType: FunctionType.PRIVATE,
46
+ isInternal: false,
47
+ isStatic: false,
48
+ parameters: [],
49
+ returnTypes: [
50
+ {
51
+ kind: 'struct',
52
+ path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
53
+ fields: [
54
+ {
55
+ name: 'inner',
56
+ type: {
57
+ kind: 'field',
55
58
  },
56
- ],
57
- },
58
- ],
59
- errorTypes: {},
60
- isInitializer: false,
61
- },
62
- [],
63
- ) as Promise<AztecAddress>;
59
+ },
60
+ ],
61
+ },
62
+ ],
63
+ errorTypes: {},
64
+ isInitializer: false,
65
+ } as FunctionAbi;
66
+ const interaction = new ContractFunctionInteraction(this.wallet, this.paymentContract, abi, []);
67
+
68
+ const executionPayload = await interaction.request();
69
+ this.assetPromise = this.wallet
70
+ .simulateTx(executionPayload, {
71
+ from: AztecAddress.ZERO,
72
+ skipFeeEnforcement: true,
73
+ })
74
+ .then(simulationResult => {
75
+ const rawReturnValues = simulationResult.getPrivateReturnValues().nested[0].values;
76
+ return decodeFromAbi(abi.returnTypes, rawReturnValues!);
77
+ }) as Promise<AztecAddress>;
64
78
  }
65
79
  return this.assetPromise!;
66
80
  }
@@ -74,23 +88,28 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
74
88
  * @param gasSettings - The gas settings.
75
89
  * @returns An execution payload that contains the required function calls.
76
90
  */
77
- async getExecutionPayload(gasSettings: GasSettings): Promise<ExecutionPayload> {
91
+ async getExecutionPayload(): Promise<ExecutionPayload> {
78
92
  const txNonce = Fr.random();
79
- const maxFee = gasSettings.getFeeLimit();
93
+ const maxFee = this.gasSettings.getFeeLimit();
80
94
 
81
- const setPublicAuthWitInteraction = await this.wallet.setPublicAuthWit(
82
- {
83
- caller: this.paymentContract,
84
- action: {
85
- name: 'transfer_in_public',
86
- args: [this.wallet.getAddress().toField(), this.paymentContract.toField(), maxFee, txNonce],
87
- selector: await FunctionSelector.fromSignature('transfer_in_public((Field),(Field),u128,Field)'),
88
- type: FunctionType.PUBLIC,
89
- isStatic: false,
90
- to: await this.getAsset(),
91
- returnTypes: [],
92
- },
95
+ const intent = {
96
+ caller: this.paymentContract,
97
+ call: {
98
+ name: 'transfer_in_public',
99
+ args: [this.sender.toField(), this.paymentContract.toField(), maxFee, txNonce],
100
+ selector: await FunctionSelector.fromSignature('transfer_in_public((Field),(Field),u128,Field)'),
101
+ type: FunctionType.PUBLIC,
102
+ isStatic: false,
103
+ hideMsgSender: false /** The target function performs an authwit check, so msg_sender is needed */,
104
+ to: await this.getAsset(),
105
+ returnTypes: [],
93
106
  },
107
+ };
108
+
109
+ const setPublicAuthWitInteraction = await SetPublicAuthwitContractInteraction.create(
110
+ this.wallet,
111
+ this.sender,
112
+ intent,
94
113
  true,
95
114
  );
96
115
 
@@ -102,6 +121,7 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
102
121
  to: this.paymentContract,
103
122
  selector: await FunctionSelector.fromSignature('fee_entrypoint_public(u128,Field)'),
104
123
  type: FunctionType.PRIVATE,
124
+ hideMsgSender: false,
105
125
  isStatic: false,
106
126
  args: [maxFee, txNonce],
107
127
  returnTypes: [],
@@ -111,4 +131,8 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
111
131
  [],
112
132
  );
113
133
  }
134
+
135
+ getGasSettings(): GasSettings | undefined {
136
+ return this.gasSettings;
137
+ }
114
138
  }
@@ -2,6 +2,7 @@ import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
2
2
  import { ExecutionPayload } from '@aztec/entrypoints/payload';
3
3
  import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
4
4
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
+ import type { GasSettings } from '@aztec/stdlib/gas';
5
6
 
6
7
  /**
7
8
  * A fee payment method that uses a contract that blindly sponsors transactions.
@@ -26,6 +27,7 @@ export class SponsoredFeePaymentMethod implements FeePaymentMethod {
26
27
  to: this.paymentContract,
27
28
  selector: await FunctionSelector.fromSignature('sponsor_unconditionally()'),
28
29
  type: FunctionType.PRIVATE,
30
+ hideMsgSender: false,
29
31
  isStatic: false,
30
32
  args: [],
31
33
  returnTypes: [],
@@ -35,4 +37,8 @@ export class SponsoredFeePaymentMethod implements FeePaymentMethod {
35
37
  [],
36
38
  );
37
39
  }
40
+
41
+ getGasSettings(): GasSettings | undefined {
42
+ return;
43
+ }
38
44
  }
@@ -1,36 +1,57 @@
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 { computeInnerAuthWitHash, computeOuterAuthWitHash } from '@aztec/stdlib/auth-witness';
3
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
4
+ import { type ABIParameterVisibility, type FunctionAbi, type FunctionCall, FunctionType } from '@aztec/stdlib/abi';
5
+ import { AuthWitness, computeInnerAuthWitHash, computeOuterAuthWitHash } from '@aztec/stdlib/auth-witness';
4
6
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
7
  import { computeVarArgsHash } from '@aztec/stdlib/hash';
8
+ import type { TxProfileResult } from '@aztec/stdlib/tx';
6
9
 
7
10
  import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
8
-
9
- /** Metadata for the intent */
10
- export type IntentMetadata = {
11
- /** The chain id to approve */
12
- chainId: Fr;
13
- /** The version to approve */
14
- version: Fr;
15
- };
11
+ import type {
12
+ ProfileInteractionOptions,
13
+ SendInteractionOptions,
14
+ SimulateInteractionOptions,
15
+ SimulationReturn,
16
+ } from '../contract/interaction_options.js';
17
+ import type { SentTx } from '../contract/sent_tx.js';
18
+ import type { Wallet } from '../wallet/index.js';
16
19
 
17
20
  /** Intent with an inner hash */
18
21
  export type IntentInnerHash = {
19
22
  /** The consumer */
20
23
  consumer: AztecAddress;
21
24
  /** The action to approve */
22
- innerHash: Buffer | Fr;
25
+ innerHash: Buffer<ArrayBuffer> | Fr;
26
+ };
27
+
28
+ /** Intent with a call */
29
+ export type CallIntent = {
30
+ /** The caller to approve */
31
+ caller: AztecAddress;
32
+ /** The call to approve */
33
+ call: FunctionCall;
23
34
  };
24
35
 
25
- /** Intent with an action */
26
- export type IntentAction = {
36
+ /** Intent with a ContractFunctionInteraction */
37
+ export type ContractFunctionInteractionCallIntent = {
27
38
  /** The caller to approve */
28
39
  caller: AztecAddress;
29
40
  /** The action to approve */
30
- action: ContractFunctionInteraction | FunctionCall;
41
+ action: ContractFunctionInteraction;
31
42
  };
32
43
 
33
- // docs:start:authwit_computeAuthWitMessageHash
44
+ /** Identifies ContractFunctionInteractionCallIntents */
45
+ function isContractFunctionIntractionCallIntent(
46
+ messageHashOrIntent: Fr | Buffer | IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
47
+ ): messageHashOrIntent is ContractFunctionInteractionCallIntent {
48
+ return (
49
+ 'caller' in messageHashOrIntent &&
50
+ 'action' in messageHashOrIntent &&
51
+ messageHashOrIntent.action instanceof ContractFunctionInteraction
52
+ );
53
+ }
54
+
34
55
  /**
35
56
  * Compute an authentication witness message hash from an intent and metadata
36
57
  *
@@ -41,7 +62,7 @@ export type IntentAction = {
41
62
  * and use it for the authentication check.
42
63
  * Therefore, any allowed `innerHash` will therefore also have information around where it can be spent (version, chainId) and who can spend it (consumer).
43
64
  *
44
- * 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.
65
+ * 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.
45
66
  * The action is then used along with the `caller` to compute the `innerHash` and the consumer.
46
67
  *
47
68
  *
@@ -52,49 +73,240 @@ export type IntentAction = {
52
73
  * @param metadata - The metadata for the intent (chainId, version)
53
74
  * @returns The message hash for the action
54
75
  */
55
- export const computeAuthWitMessageHash = async (intent: IntentInnerHash | IntentAction, metadata: IntentMetadata) => {
76
+ export const computeAuthWitMessageHash = async (
77
+ intent: IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
78
+ metadata: ChainInfo,
79
+ ) => {
56
80
  const chainId = metadata.chainId;
57
81
  const version = metadata.version;
58
82
 
59
83
  if ('caller' in intent) {
60
- const fnCall =
61
- intent.action instanceof ContractFunctionInteraction ? (await intent.action.request()).calls[0] : intent.action;
84
+ const call = isContractFunctionIntractionCallIntent(intent) ? await intent.action.getFunctionCall() : intent.call;
62
85
  return computeOuterAuthWitHash(
63
- fnCall.to,
86
+ call.to,
64
87
  chainId,
65
88
  version,
66
- await computeInnerAuthWitHashFromFunctionCall(intent.caller, fnCall),
89
+ await computeInnerAuthWitHashFromAction(intent.caller, call),
67
90
  );
68
91
  } else {
69
92
  const inner = Buffer.isBuffer(intent.innerHash) ? Fr.fromBuffer(intent.innerHash) : intent.innerHash;
70
93
  return computeOuterAuthWitHash(intent.consumer, chainId, version, inner);
71
94
  }
72
95
  };
73
- // docs:end:authwit_computeAuthWitMessageHash
74
96
 
75
97
  /**
76
- * Computes the inner authwitness hash for a function call, for it to later be combined with the metadata
77
- * required for the outer hash and eventually the full AuthWitness.
78
- * @param caller - Who is going to be calling the function
79
- * @param fnCall - The function call to compute the inner hash from
80
- * @returns The inner hash for the function call
81
- **/
82
- export const computeInnerAuthWitHashFromFunctionCall = async (caller: AztecAddress, fnCall: FunctionCall) => {
83
- return computeInnerAuthWitHash([caller.toField(), fnCall.selector.toField(), await computeVarArgsHash(fnCall.args)]);
84
- };
98
+ * Compute an authentication witness message hash from an intent and metadata. This is just
99
+ * a wrapper around computeAuthwitMessageHash that allows receiving an already computed messageHash as input
100
+ * @param messageHashOrIntent - The precomputed messageHash or intent to approve (consumer and innerHash or caller and call/action)
101
+ * @param metadata - The metadata for the intent (chainId, version)
102
+ * @returns The message hash for the intent
103
+ */
104
+ export async function getMessageHashFromIntent(
105
+ messageHashOrIntent: Fr | Buffer | IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
106
+ chainInfo: ChainInfo,
107
+ ) {
108
+ let messageHash: Fr;
109
+ const { chainId, version } = chainInfo;
110
+ if (Buffer.isBuffer(messageHashOrIntent)) {
111
+ messageHash = Fr.fromBuffer(messageHashOrIntent);
112
+ } else if (messageHashOrIntent instanceof Fr) {
113
+ messageHash = messageHashOrIntent;
114
+ } else {
115
+ messageHash = await computeAuthWitMessageHash(messageHashOrIntent, { chainId, version });
116
+ }
117
+ return messageHash;
118
+ }
85
119
 
86
120
  /**
87
- * Computes the inner authwitness hash for an action, that can either be a ContractFunctionInteraction
88
- * or an isolated FunctionCall. Since the former is just a wrapper around the latter, we can just extract
89
- * the first (and only) call from the ContractFunctionInteraction and use it to compute the inner hash.
90
- * @param caller - Who is going to be performing the action
91
- * @param action - The ContractFunctionInteraction or FunctionCall to compute the inner hash for
121
+ * Computes the inner authwitness hash for either a function call or an action, for it to later be combined with the metadata
122
+ * required for the outer hash and eventually the full AuthWitness.
123
+ * @param caller - Who is going to be calling the function
124
+ * @param action - The action to compute the inner hash from
92
125
  * @returns The inner hash for the action
93
126
  **/
94
127
  export const computeInnerAuthWitHashFromAction = async (
95
128
  caller: AztecAddress,
96
129
  action: FunctionCall | ContractFunctionInteraction,
97
130
  ) => {
98
- action = action instanceof ContractFunctionInteraction ? (await action.request()).calls[0] : action;
99
- return computeInnerAuthWitHash([caller.toField(), action.selector.toField(), await computeVarArgsHash(action.args)]);
131
+ const call = action instanceof ContractFunctionInteraction ? await action.getFunctionCall() : action;
132
+ return computeInnerAuthWitHash([caller.toField(), call.selector.toField(), await computeVarArgsHash(call.args)]);
100
133
  };
134
+
135
+ /**
136
+ * Lookup the validity of an authwit in private and public contexts.
137
+ *
138
+ * Uses the chain id and version of the wallet.
139
+ *
140
+ * @param wallet - The wallet use to simulate and read the public data
141
+ * @param onBehalfOf - The address of the "approver"
142
+ * @param intent - The consumer and inner hash or the caller and action to lookup
143
+ * @param witness - The computed authentication witness to check
144
+ * @returns - A struct containing the validity of the authwit in private and public contexts.
145
+ */
146
+ export async function lookupValidity(
147
+ wallet: Wallet,
148
+ onBehalfOf: AztecAddress,
149
+ intent: IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
150
+ witness: AuthWitness,
151
+ ): Promise<{
152
+ /** boolean flag indicating if the authwit is valid in private context */
153
+ isValidInPrivate: boolean;
154
+ /** boolean flag indicating if the authwit is valid in public context */
155
+ isValidInPublic: boolean;
156
+ }> {
157
+ let innerHash, consumer;
158
+ if ('caller' in intent) {
159
+ const call = isContractFunctionIntractionCallIntent(intent) ? await intent.action.getFunctionCall() : intent.call;
160
+ innerHash = await computeInnerAuthWitHashFromAction(intent.caller, call);
161
+ consumer = call.to;
162
+ } else if (Buffer.isBuffer(intent.innerHash)) {
163
+ innerHash = Fr.fromBuffer(intent.innerHash);
164
+ consumer = intent.consumer;
165
+ } else {
166
+ ({ innerHash, consumer } = intent);
167
+ }
168
+ const chainInfo = await wallet.getChainInfo();
169
+ const messageHash = await getMessageHashFromIntent(intent, chainInfo);
170
+ const results = { isValidInPrivate: false, isValidInPublic: false };
171
+
172
+ // Check private
173
+ const lookupValidityAbi = {
174
+ name: 'lookup_validity',
175
+ isInitializer: false,
176
+ functionType: FunctionType.UTILITY,
177
+ isInternal: false,
178
+ isStatic: false,
179
+ parameters: [{ name: 'message_hash', type: { kind: 'field' }, visibility: 'private' as ABIParameterVisibility }],
180
+ returnTypes: [{ kind: 'boolean' }],
181
+ errorTypes: {},
182
+ } as FunctionAbi;
183
+ try {
184
+ results.isValidInPrivate = (await new ContractFunctionInteraction(wallet, onBehalfOf, lookupValidityAbi, [
185
+ consumer,
186
+ innerHash,
187
+ ]).simulate({ from: onBehalfOf, authWitnesses: [witness] })) as boolean;
188
+ // TODO: Narrow down the error to make sure simulation failed due to an invalid authwit
189
+ // eslint-disable-next-line no-empty
190
+ } catch {}
191
+
192
+ // check public
193
+ const isConsumableAbi = {
194
+ name: 'utility_is_consumable',
195
+ isInitializer: false,
196
+ functionType: FunctionType.UTILITY,
197
+ isInternal: false,
198
+ isStatic: false,
199
+ parameters: [
200
+ {
201
+ name: 'address',
202
+ type: {
203
+ fields: [{ name: 'inner', type: { kind: 'field' } }],
204
+ kind: 'struct',
205
+ path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
206
+ },
207
+ visibility: 'private' as ABIParameterVisibility,
208
+ },
209
+ { name: 'message_hash', type: { kind: 'field' }, visibility: 'private' as ABIParameterVisibility },
210
+ ],
211
+ returnTypes: [{ kind: 'boolean' }],
212
+ errorTypes: {},
213
+ } as FunctionAbi;
214
+ results.isValidInPublic = (await new ContractFunctionInteraction(
215
+ wallet,
216
+ ProtocolContractAddress.AuthRegistry,
217
+ isConsumableAbi,
218
+ [onBehalfOf, messageHash],
219
+ ).simulate({ from: onBehalfOf })) as boolean;
220
+
221
+ return results;
222
+ }
223
+
224
+ /**
225
+ * Convenience class designed to wrap the very common interaction of setting a public authwit in the AuthRegistry contract
226
+ */
227
+ export class SetPublicAuthwitContractInteraction extends ContractFunctionInteraction {
228
+ private constructor(
229
+ wallet: Wallet,
230
+ private from: AztecAddress,
231
+ messageHash: Fr,
232
+ authorized: boolean,
233
+ ) {
234
+ super(wallet, ProtocolContractAddress.AuthRegistry, SetPublicAuthwitContractInteraction.getSetAuthorizedAbi(), [
235
+ messageHash,
236
+ authorized,
237
+ ]);
238
+ }
239
+
240
+ static async create(
241
+ wallet: Wallet,
242
+ from: AztecAddress,
243
+ messageHashOrIntent: Fr | Buffer | IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
244
+ authorized: boolean,
245
+ ) {
246
+ const chainInfo = await wallet.getChainInfo();
247
+ const messageHash = await getMessageHashFromIntent(messageHashOrIntent, chainInfo);
248
+ return new SetPublicAuthwitContractInteraction(wallet, from, messageHash, authorized);
249
+ }
250
+
251
+ /**
252
+ * Overrides the simulate method, adding the sender of the authwit (authorizer) as from
253
+ * and preventing misuse
254
+ * @param options - An optional object containing additional configuration for the transaction.
255
+ * @returns The result of the transaction as returned by the contract function.
256
+ */
257
+ public override simulate<T extends SimulateInteractionOptions>(
258
+ options: Omit<T, 'from'>,
259
+ ): Promise<SimulationReturn<T['includeMetadata']>>;
260
+ // eslint-disable-next-line jsdoc/require-jsdoc
261
+ public override simulate(
262
+ options: Omit<SimulateInteractionOptions, 'from'> = {},
263
+ ): Promise<SimulationReturn<typeof options.includeMetadata>> {
264
+ return super.simulate({ ...options, from: this.from });
265
+ }
266
+
267
+ /**
268
+ * Overrides the profile method, adding the sender of the authwit (authorizer) as from
269
+ * and preventing misuse
270
+ * @param options - Same options as `simulate`, plus profiling method
271
+ * @returns An object containing the function return value and profile result.
272
+ */
273
+ public override profile(
274
+ options: Omit<ProfileInteractionOptions, 'from'> = { profileMode: 'gates' },
275
+ ): Promise<TxProfileResult> {
276
+ return super.profile({ ...options, from: this.from });
277
+ }
278
+
279
+ /**
280
+ * Overrides the send method, adding the sender of the authwit (authorizer) as from
281
+ * and preventing misuse
282
+ * @param options - An optional object containing 'fee' options information
283
+ * @returns A SentTx instance for tracking the transaction status and information.
284
+ */
285
+ public override send(options: Omit<SendInteractionOptions, 'from'> = {}): SentTx {
286
+ return super.send({ ...options, from: this.from });
287
+ }
288
+
289
+ private static getSetAuthorizedAbi(): FunctionAbi {
290
+ return {
291
+ name: 'set_authorized',
292
+ isInitializer: false,
293
+ functionType: FunctionType.PUBLIC,
294
+ isInternal: true,
295
+ isStatic: false,
296
+ parameters: [
297
+ {
298
+ name: 'message_hash',
299
+ type: { kind: 'field' },
300
+ visibility: 'private' as ABIParameterVisibility,
301
+ },
302
+ {
303
+ name: 'authorize',
304
+ type: { kind: 'boolean' },
305
+ visibility: 'private' as ABIParameterVisibility,
306
+ },
307
+ ],
308
+ returnTypes: [],
309
+ errorTypes: {},
310
+ };
311
+ }
312
+ }
@@ -0,0 +1,53 @@
1
+ import type { Fr } from '@aztec/foundation/fields';
2
+ import { retryUntil } from '@aztec/foundation/retry';
3
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
4
+
5
+ /**
6
+ * Waits for the L1 to L2 message to be ready to be consumed.
7
+ * @param node - Aztec node instance used to obtain the information about the message
8
+ * @param l1ToL2MessageHash - Hash of the L1 to L2 message
9
+ * @param opts - Options
10
+ */
11
+ export async function waitForL1ToL2MessageReady(
12
+ node: Pick<AztecNode, 'getBlockNumber' | 'getL1ToL2MessageBlock'>,
13
+ l1ToL2MessageHash: Fr,
14
+ opts: {
15
+ /** Timeout for the operation in seconds */ timeoutSeconds: number;
16
+ /** True if the message is meant to be consumed from a public function */ forPublicConsumption: boolean;
17
+ },
18
+ ) {
19
+ const messageBlockNumber = await node.getL1ToL2MessageBlock(l1ToL2MessageHash);
20
+ return retryUntil(
21
+ () => isL1ToL2MessageReady(node, l1ToL2MessageHash, { ...opts, messageBlockNumber }),
22
+ `L1 to L2 message ${l1ToL2MessageHash.toString()} ready`,
23
+ opts.timeoutSeconds,
24
+ 1,
25
+ );
26
+ }
27
+
28
+ /**
29
+ * Returns whether the L1 to L2 message is ready to be consumed.
30
+ * @param node - Aztec node instance used to obtain the information about the message
31
+ * @param l1ToL2MessageHash - Hash of the L1 to L2 message
32
+ * @param opts - Options
33
+ * @returns True if the message is ready to be consumed, false otherwise
34
+ */
35
+ export async function isL1ToL2MessageReady(
36
+ node: Pick<AztecNode, 'getBlockNumber' | 'getL1ToL2MessageBlock'>,
37
+ l1ToL2MessageHash: Fr,
38
+ opts: {
39
+ /** True if the message is meant to be consumed from a public function */ forPublicConsumption: boolean;
40
+ /** Cached synced block number for the message (will be fetched from PXE otherwise) */ messageBlockNumber?: number;
41
+ },
42
+ ): Promise<boolean> {
43
+ const blockNumber = await node.getBlockNumber();
44
+ const messageBlockNumber = opts.messageBlockNumber ?? (await node.getL1ToL2MessageBlock(l1ToL2MessageHash));
45
+ if (messageBlockNumber === undefined) {
46
+ return false;
47
+ }
48
+
49
+ // Note that public messages can be consumed 1 block earlier, since the sequencer will include the messages
50
+ // in the L1 to L2 message tree before executing the txs for the block. In private, however, we need to wait
51
+ // until the message is included so we can make use of the membership witness.
52
+ return opts.forPublicConsumption ? blockNumber + 1 >= messageBlockNumber : blockNumber >= messageBlockNumber;
53
+ }
@@ -2,12 +2,13 @@ import { Fr } from '@aztec/foundation/fields';
2
2
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
3
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import { deriveStorageSlotInMap } from '@aztec/stdlib/hash';
5
- import type { PXE } from '@aztec/stdlib/interfaces/client';
5
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
6
6
 
7
7
  /**
8
8
  * Returns the owner's fee juice balance.
9
+ * Note: This is used only e2e_sandbox_example test. TODO: Consider nuking.
9
10
  */
10
- export async function getFeeJuiceBalance(owner: AztecAddress, pxe: PXE): Promise<bigint> {
11
+ export async function getFeeJuiceBalance(owner: AztecAddress, node: AztecNode): Promise<bigint> {
11
12
  const slot = await deriveStorageSlotInMap(new Fr(1), owner);
12
- return (await pxe.getPublicStorageAt(ProtocolContractAddress.FeeJuice, slot)).toBigInt();
13
+ return (await node.getPublicStorageAt('latest', ProtocolContractAddress.FeeJuice, slot)).toBigInt();
13
14
  }