@aztec/aztec.js 0.0.1-commit.b655e406 → 0.0.1-commit.c0b82b2

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 (261) hide show
  1. package/dest/account/account.d.ts +26 -42
  2. package/dest/account/account.d.ts.map +1 -1
  3. package/dest/account/account.js +19 -47
  4. package/dest/account/account_contract.d.ts +9 -10
  5. package/dest/account/account_contract.d.ts.map +1 -1
  6. package/dest/account/account_with_secret_key.d.ts +20 -9
  7. package/dest/account/account_with_secret_key.d.ts.map +1 -1
  8. package/dest/account/account_with_secret_key.js +21 -4
  9. package/dest/account/index.d.ts +4 -3
  10. package/dest/account/index.d.ts.map +1 -1
  11. package/dest/account/index.js +2 -0
  12. package/dest/account/signerless_account.d.ts +7 -9
  13. package/dest/account/signerless_account.d.ts.map +1 -1
  14. package/dest/account/signerless_account.js +8 -11
  15. package/dest/api/abi.d.ts +1 -1
  16. package/dest/api/account.d.ts +3 -4
  17. package/dest/api/account.d.ts.map +1 -1
  18. package/dest/api/account.js +2 -3
  19. package/dest/api/addresses.d.ts +1 -1
  20. package/dest/api/authorization.d.ts +2 -2
  21. package/dest/api/authorization.d.ts.map +1 -1
  22. package/dest/api/authorization.js +1 -1
  23. package/dest/api/block.d.ts +1 -1
  24. package/dest/api/contract.d.ts +19 -13
  25. package/dest/api/contract.d.ts.map +1 -1
  26. package/dest/api/contract.js +17 -11
  27. package/dest/api/crypto.d.ts +1 -1
  28. package/dest/api/deployment.d.ts +1 -2
  29. package/dest/api/deployment.d.ts.map +1 -1
  30. package/dest/api/deployment.js +0 -1
  31. package/dest/api/eth_address.d.ts +1 -1
  32. package/dest/api/ethereum.d.ts +1 -1
  33. package/dest/api/events.d.ts +10 -6
  34. package/dest/api/events.d.ts.map +1 -1
  35. package/dest/api/events.js +30 -20
  36. package/dest/api/fee.d.ts +1 -1
  37. package/dest/api/fee_testing.d.ts +1 -1
  38. package/dest/api/fields.d.ts +4 -2
  39. package/dest/api/fields.d.ts.map +1 -1
  40. package/dest/api/fields.js +3 -1
  41. package/dest/api/keys.d.ts +2 -2
  42. package/dest/api/keys.js +1 -1
  43. package/dest/api/log.d.ts +1 -1
  44. package/dest/api/messaging.d.ts +1 -1
  45. package/dest/api/node.d.ts +8 -4
  46. package/dest/api/node.d.ts.map +1 -1
  47. package/dest/api/node.js +7 -3
  48. package/dest/api/note.d.ts +2 -2
  49. package/dest/api/note.d.ts.map +1 -1
  50. package/dest/api/note.js +1 -1
  51. package/dest/api/protocol.d.ts +7 -1
  52. package/dest/api/protocol.d.ts.map +1 -1
  53. package/dest/api/protocol.js +6 -0
  54. package/dest/api/trees.d.ts +1 -1
  55. package/dest/api/tx.d.ts +2 -2
  56. package/dest/api/tx.d.ts.map +1 -1
  57. package/dest/api/tx.js +1 -1
  58. package/dest/api/utils.d.ts +1 -1
  59. package/dest/api/wallet.d.ts +3 -3
  60. package/dest/api/wallet.d.ts.map +1 -1
  61. package/dest/api/wallet.js +2 -2
  62. package/dest/authorization/call_authorization_request.d.ts +2 -2
  63. package/dest/authorization/call_authorization_request.d.ts.map +1 -1
  64. package/dest/contract/base_contract_interaction.d.ts +8 -11
  65. package/dest/contract/base_contract_interaction.d.ts.map +1 -1
  66. package/dest/contract/base_contract_interaction.js +5 -17
  67. package/dest/contract/batch_call.d.ts +8 -9
  68. package/dest/contract/batch_call.d.ts.map +1 -1
  69. package/dest/contract/batch_call.js +59 -36
  70. package/dest/contract/checker.d.ts +1 -1
  71. package/dest/contract/contract.d.ts +2 -2
  72. package/dest/contract/contract.d.ts.map +1 -1
  73. package/dest/contract/contract.js +4 -5
  74. package/dest/contract/contract_base.d.ts +6 -10
  75. package/dest/contract/contract_base.d.ts.map +1 -1
  76. package/dest/contract/contract_base.js +5 -12
  77. package/dest/contract/contract_function_interaction.d.ts +5 -14
  78. package/dest/contract/contract_function_interaction.d.ts.map +1 -1
  79. package/dest/contract/contract_function_interaction.js +18 -12
  80. package/dest/contract/deploy_method.d.ts +85 -24
  81. package/dest/contract/deploy_method.d.ts.map +1 -1
  82. package/dest/contract/deploy_method.js +71 -36
  83. package/dest/contract/get_gas_limits.d.ts +1 -1
  84. package/dest/contract/get_gas_limits.js +3 -3
  85. package/dest/contract/interaction_options.d.ts +51 -7
  86. package/dest/contract/interaction_options.d.ts.map +1 -1
  87. package/dest/contract/interaction_options.js +12 -11
  88. package/dest/contract/protocol_contracts/auth-registry.d.ts +36 -0
  89. package/dest/contract/protocol_contracts/auth-registry.d.ts.map +1 -0
  90. package/dest/contract/protocol_contracts/auth-registry.js +1005 -0
  91. package/dest/contract/protocol_contracts/contract-class-registry.d.ts +15 -0
  92. package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -0
  93. package/dest/contract/protocol_contracts/contract-class-registry.js +139 -0
  94. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +22 -0
  95. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -0
  96. package/dest/contract/protocol_contracts/contract-instance-registry.js +465 -0
  97. package/dest/contract/protocol_contracts/fee-juice.d.ts +21 -0
  98. package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -0
  99. package/dest/contract/protocol_contracts/fee-juice.js +434 -0
  100. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts +34 -0
  101. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts.map +1 -0
  102. package/dest/contract/protocol_contracts/multi-call-entrypoint.js +601 -0
  103. package/dest/contract/protocol_contracts/public-checks.d.ts +26 -0
  104. package/dest/contract/protocol_contracts/public-checks.d.ts.map +1 -0
  105. package/dest/contract/protocol_contracts/public-checks.js +609 -0
  106. package/dest/contract/wait_for_proven.d.ts +2 -2
  107. package/dest/contract/wait_for_proven.d.ts.map +1 -1
  108. package/dest/contract/wait_for_proven.js +1 -1
  109. package/dest/contract/wait_opts.d.ts +16 -0
  110. package/dest/contract/wait_opts.d.ts.map +1 -0
  111. package/dest/contract/wait_opts.js +5 -0
  112. package/dest/deployment/contract_deployer.d.ts +1 -1
  113. package/dest/deployment/contract_deployer.d.ts.map +1 -1
  114. package/dest/deployment/contract_deployer.js +1 -1
  115. package/dest/deployment/publish_class.d.ts +1 -1
  116. package/dest/deployment/publish_class.js +3 -3
  117. package/dest/deployment/publish_instance.d.ts +2 -2
  118. package/dest/deployment/publish_instance.d.ts.map +1 -1
  119. package/dest/deployment/publish_instance.js +3 -3
  120. package/dest/ethereum/portal_manager.d.ts +7 -6
  121. package/dest/ethereum/portal_manager.d.ts.map +1 -1
  122. package/dest/ethereum/portal_manager.js +48 -22
  123. package/dest/fee/fee_juice_payment_method_with_claim.d.ts +2 -2
  124. package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -1
  125. package/dest/fee/fee_juice_payment_method_with_claim.js +9 -9
  126. package/dest/fee/fee_payment_method.d.ts +2 -2
  127. package/dest/fee/fee_payment_method.d.ts.map +1 -1
  128. package/dest/fee/private_fee_payment_method.d.ts +2 -2
  129. package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
  130. package/dest/fee/private_fee_payment_method.js +14 -14
  131. package/dest/fee/public_fee_payment_method.d.ts +2 -2
  132. package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
  133. package/dest/fee/public_fee_payment_method.js +14 -14
  134. package/dest/fee/sponsored_fee_payment.d.ts +2 -2
  135. package/dest/fee/sponsored_fee_payment.d.ts.map +1 -1
  136. package/dest/fee/sponsored_fee_payment.js +5 -5
  137. package/dest/scripts/generate_protocol_contract_types.d.ts +2 -0
  138. package/dest/scripts/generate_protocol_contract_types.d.ts.map +1 -0
  139. package/dest/scripts/generate_protocol_contract_types.js +120 -0
  140. package/dest/utils/abi_types.d.ts +2 -2
  141. package/dest/utils/abi_types.d.ts.map +1 -1
  142. package/dest/utils/authwit.d.ts +14 -12
  143. package/dest/utils/authwit.d.ts.map +1 -1
  144. package/dest/utils/authwit.js +27 -20
  145. package/dest/utils/cross_chain.d.ts +2 -2
  146. package/dest/utils/cross_chain.d.ts.map +1 -1
  147. package/dest/utils/fee_juice.d.ts +2 -2
  148. package/dest/utils/fee_juice.js +2 -2
  149. package/dest/utils/field_compressed_string.d.ts +1 -1
  150. package/dest/utils/field_compressed_string.d.ts.map +1 -1
  151. package/dest/utils/field_compressed_string.js +1 -1
  152. package/dest/utils/node.d.ts +13 -2
  153. package/dest/utils/node.d.ts.map +1 -1
  154. package/dest/utils/node.js +46 -0
  155. package/dest/utils/pub_key.d.ts +2 -2
  156. package/dest/utils/pub_key.d.ts.map +1 -1
  157. package/dest/utils/pub_key.js +1 -1
  158. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts +6 -9
  159. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts.map +1 -1
  160. package/dest/wallet/account_entrypoint_meta_payment_method.js +29 -44
  161. package/dest/wallet/account_manager.d.ts +3 -9
  162. package/dest/wallet/account_manager.d.ts.map +1 -1
  163. package/dest/wallet/account_manager.js +6 -12
  164. package/dest/wallet/capabilities.d.ts +452 -0
  165. package/dest/wallet/capabilities.d.ts.map +1 -0
  166. package/dest/wallet/capabilities.js +3 -0
  167. package/dest/wallet/deploy_account_method.d.ts +49 -10
  168. package/dest/wallet/deploy_account_method.d.ts.map +1 -1
  169. package/dest/wallet/deploy_account_method.js +35 -7
  170. package/dest/wallet/index.d.ts +2 -2
  171. package/dest/wallet/index.d.ts.map +1 -1
  172. package/dest/wallet/index.js +1 -1
  173. package/dest/wallet/wallet.d.ts +1853 -1533
  174. package/dest/wallet/wallet.d.ts.map +1 -1
  175. package/dest/wallet/wallet.js +223 -124
  176. package/package.json +27 -15
  177. package/src/account/account.ts +35 -60
  178. package/src/account/account_contract.ts +7 -8
  179. package/src/account/account_with_secret_key.ts +34 -9
  180. package/src/account/index.ts +3 -2
  181. package/src/account/signerless_account.ts +15 -15
  182. package/src/api/account.ts +10 -3
  183. package/src/api/authorization.ts +1 -0
  184. package/src/api/contract.ts +26 -10
  185. package/src/api/deployment.ts +0 -1
  186. package/src/api/events.ts +35 -27
  187. package/src/api/fields.ts +3 -1
  188. package/src/api/keys.ts +2 -2
  189. package/src/api/node.ts +7 -3
  190. package/src/api/note.ts +1 -1
  191. package/src/api/protocol.ts +7 -0
  192. package/src/api/tx.ts +4 -0
  193. package/src/api/wallet.ts +52 -9
  194. package/src/authorization/call_authorization_request.ts +1 -1
  195. package/src/contract/base_contract_interaction.ts +27 -16
  196. package/src/contract/batch_call.ts +62 -48
  197. package/src/contract/contract.ts +7 -5
  198. package/src/contract/contract_base.ts +5 -15
  199. package/src/contract/contract_function_interaction.ts +26 -17
  200. package/src/contract/deploy_method.ts +175 -47
  201. package/src/contract/get_gas_limits.ts +3 -3
  202. package/src/contract/interaction_options.ts +59 -13
  203. package/src/contract/protocol_contracts/auth-registry.ts +553 -0
  204. package/src/contract/protocol_contracts/contract-class-registry.ts +99 -0
  205. package/src/contract/protocol_contracts/contract-instance-registry.ts +302 -0
  206. package/src/contract/protocol_contracts/fee-juice.ts +266 -0
  207. package/src/contract/protocol_contracts/multi-call-entrypoint.ts +336 -0
  208. package/src/contract/protocol_contracts/public-checks.ts +320 -0
  209. package/src/contract/wait_for_proven.ts +1 -1
  210. package/src/contract/wait_opts.ts +21 -0
  211. package/src/deployment/contract_deployer.ts +3 -2
  212. package/src/deployment/publish_class.ts +3 -3
  213. package/src/deployment/publish_instance.ts +3 -6
  214. package/src/ethereum/portal_manager.ts +65 -34
  215. package/src/fee/fee_juice_payment_method_with_claim.ts +9 -7
  216. package/src/fee/fee_payment_method.ts +1 -1
  217. package/src/fee/private_fee_payment_method.ts +12 -10
  218. package/src/fee/public_fee_payment_method.ts +13 -11
  219. package/src/fee/sponsored_fee_payment.ts +6 -4
  220. package/src/scripts/generate_protocol_contract_types.ts +150 -0
  221. package/src/utils/abi_types.ts +1 -1
  222. package/src/utils/authwit.ts +40 -22
  223. package/src/utils/cross_chain.ts +1 -1
  224. package/src/utils/fee_juice.ts +2 -2
  225. package/src/utils/field_compressed_string.ts +1 -1
  226. package/src/utils/node.ts +62 -0
  227. package/src/utils/pub_key.ts +2 -2
  228. package/src/wallet/account_entrypoint_meta_payment_method.ts +29 -60
  229. package/src/wallet/account_manager.ts +7 -15
  230. package/src/wallet/capabilities.ts +500 -0
  231. package/src/wallet/deploy_account_method.ts +78 -16
  232. package/src/wallet/index.ts +1 -1
  233. package/src/wallet/wallet.ts +387 -166
  234. package/dest/account/interface.d.ts +0 -19
  235. package/dest/account/interface.d.ts.map +0 -1
  236. package/dest/account/interface.js +0 -5
  237. package/dest/contract/deploy_sent_tx.d.ts +0 -43
  238. package/dest/contract/deploy_sent_tx.d.ts.map +0 -1
  239. package/dest/contract/deploy_sent_tx.js +0 -40
  240. package/dest/contract/protocol_contracts.d.ts +0 -9
  241. package/dest/contract/protocol_contracts.d.ts.map +0 -1
  242. package/dest/contract/protocol_contracts.js +0 -26
  243. package/dest/contract/sent_tx.d.ts +0 -51
  244. package/dest/contract/sent_tx.d.ts.map +0 -1
  245. package/dest/contract/sent_tx.js +0 -90
  246. package/dest/contract/unsafe_contract.d.ts +0 -15
  247. package/dest/contract/unsafe_contract.d.ts.map +0 -1
  248. package/dest/contract/unsafe_contract.js +0 -6
  249. package/dest/deployment/broadcast_function.d.ts +0 -24
  250. package/dest/deployment/broadcast_function.d.ts.map +0 -1
  251. package/dest/deployment/broadcast_function.js +0 -74
  252. package/dest/wallet/base_wallet.d.ts +0 -91
  253. package/dest/wallet/base_wallet.d.ts.map +0 -1
  254. package/dest/wallet/base_wallet.js +0 -238
  255. package/src/account/interface.ts +0 -25
  256. package/src/contract/deploy_sent_tx.ts +0 -68
  257. package/src/contract/protocol_contracts.ts +0 -35
  258. package/src/contract/sent_tx.ts +0 -130
  259. package/src/contract/unsafe_contract.ts +0 -19
  260. package/src/deployment/broadcast_function.ts +0 -148
  261. package/src/wallet/base_wallet.ts +0 -350
@@ -1,27 +1,20 @@
1
1
  import type { ChainInfo } from '@aztec/entrypoints/interfaces';
2
- import type { ExecutionPayload } from '@aztec/entrypoints/payload';
3
- import type { Fr } from '@aztec/foundation/fields';
2
+ import { BlockNumber, BlockNumberPositiveSchema } from '@aztec/foundation/branded-types';
3
+ import type { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import {
5
+ type AbiDecoded,
5
6
  AbiTypeSchema,
6
7
  type ContractArtifact,
7
8
  ContractArtifactSchema,
8
9
  type EventMetadataDefinition,
9
- FunctionAbiSchema,
10
- FunctionType,
10
+ FunctionCall,
11
11
  } from '@aztec/stdlib/abi';
12
12
  import { AuthWitness } from '@aztec/stdlib/auth-witness';
13
13
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
14
- import {
15
- type ContractClassMetadata,
16
- ContractClassWithIdSchema,
17
- type ContractInstanceWithAddress,
18
- ContractInstanceWithAddressSchema,
19
- type ContractInstantiationData,
20
- type ContractMetadata,
21
- } from '@aztec/stdlib/contract';
14
+ import { type ContractInstanceWithAddress, ContractInstanceWithAddressSchema } from '@aztec/stdlib/contract';
22
15
  import { Gas } from '@aztec/stdlib/gas';
23
- import { PublicKeys } from '@aztec/stdlib/keys';
24
- import { AbiDecodedSchema, type ApiSchemaFor, type ZodFor, optional, schemas } from '@aztec/stdlib/schemas';
16
+ import { AbiDecodedSchema, type ApiSchemaFor, optional, schemas, zodFor } from '@aztec/stdlib/schemas';
17
+ import type { ExecutionPayload, InTx } from '@aztec/stdlib/tx';
25
18
  import {
26
19
  Capsule,
27
20
  HashedValues,
@@ -29,20 +22,24 @@ import {
29
22
  TxProfileResult,
30
23
  TxReceipt,
31
24
  TxSimulationResult,
32
- UtilitySimulationResult,
25
+ UtilityExecutionResult,
26
+ inTxSchema,
33
27
  } from '@aztec/stdlib/tx';
34
28
 
35
29
  import { z } from 'zod';
36
30
 
37
- import type { Contract } from '../contract/contract.js';
38
- import type {
39
- FeeEstimationOptions,
40
- GasSettingsOption,
41
- ProfileInteractionOptions,
42
- SendInteractionOptions,
43
- SimulateInteractionOptions,
31
+ import {
32
+ type FeeEstimationOptions,
33
+ type GasSettingsOption,
34
+ type InteractionWaitOptions,
35
+ NO_WAIT,
36
+ type ProfileInteractionOptions,
37
+ type SendInteractionOptionsWithoutWait,
38
+ type SendReturn,
39
+ type SimulateInteractionOptions,
44
40
  } from '../contract/interaction_options.js';
45
41
  import type { CallIntent, IntentInnerHash } from '../utils/authwit.js';
42
+ import type { AppCapabilities, WalletCapabilities } from './capabilities.js';
46
43
 
47
44
  /**
48
45
  * A wrapper type that allows any item to be associated with an alias.
@@ -58,80 +55,76 @@ export type Aliased<T> = {
58
55
  item: T;
59
56
  };
60
57
 
61
- /**
62
- * A reduced representation of a Contract, only including its instance and artifact
63
- */
64
- export type ContractInstanceAndArtifact = Pick<Contract, 'artifact' | 'instance'>;
65
-
66
- /**
67
- * Options that can be provided to the wallet for configuration of the fee payment.
68
- */
69
- export type UserFeeOptions = {
70
- /**
71
- * Informs the wallet that the crafted tx already contains the necessary calls to pay for its fee
72
- * and who is paying
73
- */
74
- embeddedPaymentMethodFeePayer?: AztecAddress;
75
- } & GasSettingsOption;
76
-
77
58
  /**
78
59
  * Options for simulating interactions with the wallet. Overrides the fee settings of an interaction with
79
- * a simplified version that only hints at the wallet wether the interaction contains a
60
+ * a simplified version that only hints at the wallet whether the interaction contains a
80
61
  * fee payment method or not
81
62
  */
82
63
  export type SimulateOptions = Omit<SimulateInteractionOptions, 'fee'> & {
83
64
  /** The fee options */
84
- fee?: UserFeeOptions & FeeEstimationOptions;
65
+ fee?: GasSettingsOption & FeeEstimationOptions;
85
66
  };
86
67
 
87
68
  /**
88
69
  * Options for profiling interactions with the wallet. Overrides the fee settings of an interaction with
89
- * a simplified version that only hints at the wallet wether the interaction contains a
70
+ * a simplified version that only hints at the wallet whether the interaction contains a
90
71
  * fee payment method or not
91
72
  */
92
73
  export type ProfileOptions = Omit<ProfileInteractionOptions, 'fee'> & {
93
74
  /** The fee options */
94
- fee?: UserFeeOptions;
75
+ fee?: GasSettingsOption;
95
76
  };
96
77
 
97
78
  /**
98
79
  * Options for sending/proving interactions with the wallet. Overrides the fee settings of an interaction with
99
- * a simplified version that only hints at the wallet wether the interaction contains a
80
+ * a simplified version that only hints at the wallet whether the interaction contains a
100
81
  * fee payment method or not
101
82
  */
102
- export type SendOptions = Omit<SendInteractionOptions, 'fee'> & {
83
+ export type SendOptions<W extends InteractionWaitOptions = undefined> = Omit<
84
+ SendInteractionOptionsWithoutWait,
85
+ 'fee'
86
+ > & {
103
87
  /** The fee options */
104
- fee?: UserFeeOptions;
88
+ fee?: GasSettingsOption;
89
+ /** Whether to wait for the transaction to be mined */
90
+ wait?: W;
105
91
  };
106
92
 
107
93
  /**
108
- * Helper type that represents all methods that can be batched.
94
+ * Helper type that represents all methods that can be batched (all methods except batch itself).
109
95
  */
110
- export type BatchableMethods = Pick<Wallet, 'registerContract' | 'sendTx' | 'registerSender' | 'simulateUtility'>;
96
+ export type BatchableMethods = Omit<Wallet, 'batch'>;
111
97
 
112
98
  /**
113
- * From the batchable methods, we create a type that represents a method call with its name and arguments.
114
- * This is what the wallet will accept as arguments to the `batch` method.
99
+ * A method call with its name and arguments.
115
100
  */
116
- export type BatchedMethod<T extends keyof BatchableMethods> = {
101
+ type BatchedMethodInternal<T extends keyof BatchableMethods> = {
117
102
  /** The method name */
118
103
  name: T;
119
104
  /** The method arguments */
120
105
  args: Parameters<BatchableMethods[T]>;
121
106
  };
122
107
 
108
+ /**
109
+ * Union of all possible batched method calls.
110
+ * This ensures type safety: the `args` must match the specific `name`.
111
+ */
112
+ export type BatchedMethod = {
113
+ [K in keyof BatchableMethods]: BatchedMethodInternal<K>;
114
+ }[keyof BatchableMethods];
115
+
123
116
  /**
124
117
  * Helper type to extract the return type of a batched method
125
118
  */
126
119
  export type BatchedMethodResult<T> =
127
- T extends BatchedMethod<infer K> ? Awaited<ReturnType<BatchableMethods[K]>> : never;
120
+ T extends BatchedMethodInternal<infer K> ? Awaited<ReturnType<BatchableMethods[K]>> : never;
128
121
 
129
122
  /**
130
123
  * Wrapper type for batch results that includes the method name for discriminated union deserialization.
131
124
  * Each result is wrapped as \{ name: 'methodName', result: ActualResult \} to allow proper deserialization
132
125
  * when AztecAddress and TxHash would otherwise be ambiguous (both are hex strings).
133
126
  */
134
- export type BatchedMethodResultWrapper<T extends BatchedMethod<keyof BatchableMethods>> = {
127
+ export type BatchedMethodResultWrapper<T extends BatchedMethod> = {
135
128
  /** The method name */
136
129
  name: T['name'];
137
130
  /** The method result */
@@ -141,85 +134,147 @@ export type BatchedMethodResultWrapper<T extends BatchedMethod<keyof BatchableMe
141
134
  /**
142
135
  * Maps a tuple of BatchedMethod to a tuple of their wrapped return types
143
136
  */
144
- export type BatchResults<T extends readonly BatchedMethod<keyof BatchableMethods>[]> = {
137
+ export type BatchResults<T extends readonly BatchedMethod[]> = {
145
138
  [K in keyof T]: BatchedMethodResultWrapper<T[K]>;
146
139
  };
147
140
 
141
+ /**
142
+ * Base filter options for event queries.
143
+ */
144
+ export type EventFilterBase = {
145
+ /** Transaction in which the events were emitted. */
146
+ txHash?: TxHash;
147
+ /** The block number from which to start fetching events (inclusive).
148
+ * Optional. If provided, it must be greater or equal than 1.
149
+ * Defaults to the initial L2 block number (INITIAL_L2_BLOCK_NUM).
150
+ */
151
+ fromBlock?: BlockNumber;
152
+ /** The block number until which to fetch logs (not inclusive).
153
+ * Optional. If provided, it must be greater than fromBlock.
154
+ */
155
+ toBlock?: BlockNumber;
156
+ };
157
+
158
+ /**
159
+ * Filter options when querying private events.
160
+ */
161
+ export type PrivateEventFilter = EventFilterBase & {
162
+ /** The address of the contract that emitted the events. */
163
+ contractAddress: AztecAddress;
164
+ /** Addresses of accounts that are in scope for this filter. */
165
+ scopes: AztecAddress[];
166
+ };
167
+
168
+ /**
169
+ * Filter options when querying public events.
170
+ */
171
+ export type PublicEventFilter = EventFilterBase & {
172
+ /** The address of the contract that emitted the events. */
173
+ contractAddress?: AztecAddress;
174
+ };
175
+
176
+ /**
177
+ * An ABI decoded event with associated metadata.
178
+ * @typeParam T - The decoded event type
179
+ * @typeParam M - Additional metadata fields (empty by default)
180
+ */
181
+ export type Event<T, M extends object = object> = {
182
+ /** The ABI decoded event */
183
+ event: T;
184
+ /** Metadata describing event context information such as tx and block */
185
+ metadata: InTx & M;
186
+ };
187
+
188
+ /** An ABI decoded private event with associated metadata. */
189
+ export type PrivateEvent<T> = Event<T>;
190
+
191
+ /** An ABI decoded public event with associated metadata (includes contract address). */
192
+ export type PublicEvent<T> = Event<
193
+ T,
194
+ {
195
+ /**
196
+ * Address of the contract that emitted this event
197
+ */
198
+ contractAddress: AztecAddress;
199
+ }
200
+ >;
201
+
202
+ /**
203
+ * Contract metadata including deployment and registration status.
204
+ */
205
+ export type ContractMetadata = {
206
+ /** The contract instance */
207
+ instance?: ContractInstanceWithAddress;
208
+ /** Whether the contract has been initialized (init nullifier exists) */
209
+ isContractInitialized: boolean;
210
+ /** Whether the contract instance is publicly deployed on-chain */
211
+ isContractPublished: boolean;
212
+ /** Whether the contract has been updated to a different class */
213
+ isContractUpdated: boolean;
214
+ /** The updated contract class ID if the contract has been updated */
215
+ updatedContractClassId?: Fr | undefined;
216
+ };
217
+
218
+ /**
219
+ * Contract class metadata.
220
+ */
221
+ export type ContractClassMetadata = {
222
+ /** Whether the artifact is registered in the wallet */
223
+ isArtifactRegistered: boolean;
224
+ /** Whether the contract class is publicly registered on-chain */
225
+ isContractClassPubliclyRegistered: boolean;
226
+ };
227
+
228
+ /**
229
+ * Options for executing a utility function call.
230
+ */
231
+ export type ExecuteUtilityOptions = {
232
+ /** The scope for the utility execution (determines which notes and keys are visible). */
233
+ scope: AztecAddress;
234
+ /** Optional auth witnesses to use during execution. */
235
+ authWitnesses?: AuthWitness[];
236
+ };
237
+
148
238
  /**
149
239
  * The wallet interface.
150
240
  */
151
241
  export type Wallet = {
152
- getContractClassMetadata(id: Fr, includeArtifact?: boolean): Promise<ContractClassMetadata>;
153
- getContractMetadata(address: AztecAddress): Promise<ContractMetadata>;
154
242
  getPrivateEvents<T>(
155
- contractAddress: AztecAddress,
156
243
  eventMetadata: EventMetadataDefinition,
157
- from: number,
158
- numBlocks: number,
159
- recipients: AztecAddress[],
160
- ): Promise<T[]>;
244
+ eventFilter: PrivateEventFilter,
245
+ ): Promise<PrivateEvent<T>[]>;
161
246
  getChainInfo(): Promise<ChainInfo>;
162
- getTxReceipt(txHash: TxHash): Promise<TxReceipt>;
247
+ getContractMetadata(address: AztecAddress): Promise<ContractMetadata>;
248
+ getContractClassMetadata(id: Fr): Promise<ContractClassMetadata>;
163
249
  registerSender(address: AztecAddress, alias?: string): Promise<AztecAddress>;
164
250
  getAddressBook(): Promise<Aliased<AztecAddress>[]>;
165
251
  getAccounts(): Promise<Aliased<AztecAddress>[]>;
166
252
  registerContract(
167
- instanceData: AztecAddress | ContractInstanceWithAddress | ContractInstantiationData | ContractInstanceAndArtifact,
168
- ): Promise<ContractInstanceWithAddress>;
169
- // Overloaded definition to avoid zod issues
170
- registerContract(
171
- instanceData: AztecAddress | ContractInstanceWithAddress | ContractInstantiationData | ContractInstanceAndArtifact,
172
- artifact: ContractArtifact,
173
- ): Promise<ContractInstanceWithAddress>;
174
- registerContract(
175
- instanceData: AztecAddress | ContractInstanceWithAddress | ContractInstantiationData | ContractInstanceAndArtifact,
176
- artifact: ContractArtifact | undefined,
177
- secretKey: Fr | undefined,
253
+ instance: ContractInstanceWithAddress,
254
+ artifact?: ContractArtifact,
255
+ secretKey?: Fr,
178
256
  ): Promise<ContractInstanceWithAddress>;
179
257
  simulateTx(exec: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult>;
180
- simulateUtility(
181
- functionName: string,
182
- args: any[],
183
- to: AztecAddress,
184
- authwits?: AuthWitness[],
185
- ): Promise<UtilitySimulationResult>;
258
+ executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult>;
186
259
  profileTx(exec: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult>;
187
- sendTx(exec: ExecutionPayload, opts: SendOptions): Promise<TxHash>;
188
- createAuthWit(
189
- from: AztecAddress,
190
- messageHashOrIntent: Fr | Buffer<ArrayBuffer> | IntentInnerHash | CallIntent,
191
- ): Promise<AuthWitness>;
192
- batch<const T extends readonly BatchedMethod<keyof BatchableMethods>[]>(methods: T): Promise<BatchResults<T>>;
260
+ sendTx<W extends InteractionWaitOptions = undefined>(
261
+ exec: ExecutionPayload,
262
+ opts: SendOptions<W>,
263
+ ): Promise<SendReturn<W>>;
264
+ createAuthWit(from: AztecAddress, messageHashOrIntent: IntentInnerHash | CallIntent): Promise<AuthWitness>;
265
+ requestCapabilities(manifest: AppCapabilities): Promise<WalletCapabilities>;
266
+ batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>>;
193
267
  };
194
268
 
195
- export const ContractInstantiationDataSchema = z.object({
196
- constructorArtifact: optional(z.union([FunctionAbiSchema, z.string()])),
197
- constructorArgs: optional(z.array(z.any())),
198
- skipArgsDecoding: optional(z.boolean()),
199
- salt: schemas.Fr,
200
- publicKeys: optional(PublicKeys.schema),
201
- deployer: optional(schemas.AztecAddress),
202
- });
203
-
204
- export const FunctionCallSchema = z.object({
205
- name: z.string(),
206
- to: schemas.AztecAddress,
207
- selector: schemas.FunctionSelector,
208
- type: z.nativeEnum(FunctionType),
209
- isStatic: z.boolean(),
210
- hideMsgSender: z.boolean(),
211
- args: z.array(schemas.Fr),
212
- returnTypes: z.array(AbiTypeSchema),
213
- });
214
-
215
269
  export const ExecutionPayloadSchema = z.object({
216
- calls: z.array(FunctionCallSchema),
270
+ calls: z.array(FunctionCall.schema),
217
271
  authWitnesses: z.array(AuthWitness.schema),
218
272
  capsules: z.array(Capsule.schema),
219
273
  extraHashedArgs: z.array(HashedValues.schema),
274
+ feePayer: optional(schemas.AztecAddress),
220
275
  });
221
276
 
222
- export const UserFeeOptionsSchema = z.object({
277
+ export const GasSettingsOptionSchema = z.object({
223
278
  gasSettings: optional(
224
279
  z.object({
225
280
  gasLimits: optional(Gas.schema),
@@ -228,19 +283,27 @@ export const UserFeeOptionsSchema = z.object({
228
283
  maxPriorityFeePerGas: optional(z.object({ feePerDaGas: schemas.BigInt, feePerL2Gas: schemas.BigInt })),
229
284
  }),
230
285
  ),
231
- embeddedPaymentMethodFeePayer: optional(schemas.AztecAddress),
232
286
  });
233
287
 
234
- export const WalletSimulationFeeOptionSchema = UserFeeOptionsSchema.extend({
288
+ export const WalletSimulationFeeOptionSchema = GasSettingsOptionSchema.extend({
235
289
  estimatedGasPadding: optional(z.number()),
236
290
  estimateGas: optional(z.boolean()),
237
291
  });
238
292
 
293
+ export const WaitOptsSchema = z.object({
294
+ ignoreDroppedReceiptsFor: optional(z.number()),
295
+ timeout: optional(z.number()),
296
+ interval: optional(z.number()),
297
+ dontThrowOnRevert: optional(z.boolean()),
298
+ });
299
+
239
300
  export const SendOptionsSchema = z.object({
240
301
  from: schemas.AztecAddress,
241
302
  authWitnesses: optional(z.array(AuthWitness.schema)),
242
303
  capsules: optional(z.array(Capsule.schema)),
243
- fee: optional(UserFeeOptionsSchema),
304
+ fee: optional(GasSettingsOptionSchema),
305
+ wait: optional(z.union([z.literal(NO_WAIT), WaitOptsSchema])),
306
+ additionalScopes: optional(z.array(schemas.AztecAddress)),
244
307
  });
245
308
 
246
309
  export const SimulateOptionsSchema = z.object({
@@ -251,6 +314,7 @@ export const SimulateOptionsSchema = z.object({
251
314
  skipTxValidation: optional(z.boolean()),
252
315
  skipFeeEnforcement: optional(z.boolean()),
253
316
  includeMetadata: optional(z.boolean()),
317
+ additionalScopes: optional(z.array(schemas.AztecAddress)),
254
318
  });
255
319
 
256
320
  export const ProfileOptionsSchema = SimulateOptionsSchema.extend({
@@ -258,72 +322,191 @@ export const ProfileOptionsSchema = SimulateOptionsSchema.extend({
258
322
  skipProofGeneration: optional(z.boolean()),
259
323
  });
260
324
 
261
- export const InstanceDataSchema = z.union([
262
- schemas.AztecAddress,
263
- ContractInstanceWithAddressSchema,
264
- ContractInstantiationDataSchema,
265
- z.object({ instance: ContractInstanceWithAddressSchema, artifact: ContractArtifactSchema }),
266
- ]);
267
-
268
325
  export const MessageHashOrIntentSchema = z.union([
269
- schemas.Fr,
270
- schemas.Buffer,
271
- z.object({ consumer: schemas.AztecAddress, innerHash: z.union([schemas.Buffer, schemas.Fr]) }),
326
+ z.object({ consumer: schemas.AztecAddress, innerHash: schemas.Fr }),
272
327
  z.object({
273
328
  caller: schemas.AztecAddress,
274
- call: FunctionCallSchema,
329
+ call: FunctionCall.schema,
275
330
  }),
276
331
  ]);
277
332
 
278
- export const BatchedMethodSchema = z.union([
279
- z.object({
280
- name: z.literal('registerSender'),
281
- args: z.tuple([schemas.AztecAddress, optional(z.string())]),
282
- }),
283
- z.object({
284
- name: z.literal('registerContract'),
285
- args: z.tuple([InstanceDataSchema, optional(ContractArtifactSchema), optional(schemas.Fr)]),
286
- }),
333
+ export const EventMetadataDefinitionSchema = z.object({
334
+ eventSelector: schemas.EventSelector,
335
+ abiType: AbiTypeSchema,
336
+ fieldNames: z.array(z.string()),
337
+ });
338
+
339
+ const EventFilterBaseSchema = z.object({
340
+ txHash: optional(TxHash.schema),
341
+ fromBlock: optional(BlockNumberPositiveSchema),
342
+ toBlock: optional(BlockNumberPositiveSchema),
343
+ });
344
+
345
+ export const PrivateEventFilterSchema = EventFilterBaseSchema.extend({
346
+ contractAddress: schemas.AztecAddress,
347
+ scopes: z.array(schemas.AztecAddress),
348
+ });
349
+
350
+ export const PublicEventFilterSchema = EventFilterBaseSchema.extend({
351
+ contractAddress: optional(schemas.AztecAddress),
352
+ });
353
+
354
+ export const PrivateEventSchema: z.ZodType<any> = zodFor<PrivateEvent<AbiDecoded>>()(
287
355
  z.object({
288
- name: z.literal('sendTx'),
289
- args: z.tuple([ExecutionPayloadSchema, SendOptionsSchema]),
356
+ event: AbiDecodedSchema,
357
+ metadata: inTxSchema(),
290
358
  }),
359
+ );
360
+
361
+ export const PublicEventSchema = zodFor<PublicEvent<AbiDecoded>>()(
291
362
  z.object({
292
- name: z.literal('simulateUtility'),
293
- args: z.tuple([z.string(), z.array(z.any()), schemas.AztecAddress, optional(z.array(AuthWitness.schema))]),
363
+ event: AbiDecodedSchema,
364
+ metadata: z.intersection(inTxSchema(), z.object({ contractAddress: schemas.AztecAddress })),
294
365
  }),
295
- ]);
366
+ );
296
367
 
297
368
  export const ContractMetadataSchema = z.object({
298
- contractInstance: z.union([ContractInstanceWithAddressSchema, z.undefined()]),
369
+ instance: optional(ContractInstanceWithAddressSchema),
299
370
  isContractInitialized: z.boolean(),
300
371
  isContractPublished: z.boolean(),
301
- }) satisfies ZodFor<ContractMetadata>;
372
+ isContractUpdated: z.boolean(),
373
+ updatedContractClassId: optional(schemas.Fr),
374
+ });
302
375
 
303
376
  export const ContractClassMetadataSchema = z.object({
304
- contractClass: z.union([ContractClassWithIdSchema, z.undefined()]),
377
+ isArtifactRegistered: z.boolean(),
305
378
  isContractClassPubliclyRegistered: z.boolean(),
306
- artifact: z.union([ContractArtifactSchema, z.undefined()]),
307
- }) satisfies ZodFor<ContractClassMetadata>;
379
+ });
308
380
 
309
- export const EventMetadataDefinitionSchema = z.object({
310
- eventSelector: schemas.EventSelector,
311
- abiType: AbiTypeSchema,
312
- fieldNames: z.array(z.string()),
381
+ export const ContractFunctionPatternSchema = z.object({
382
+ contract: z.union([schemas.AztecAddress, z.literal('*')]),
383
+ function: z.union([z.string(), z.literal('*')]),
384
+ additionalScopes: optional(z.union([z.array(schemas.AztecAddress), z.literal('*')])),
313
385
  });
314
386
 
315
- export const WalletSchema: ApiSchemaFor<Wallet> = {
387
+ export const AccountsCapabilitySchema = z.object({
388
+ type: z.literal('accounts'),
389
+ canGet: optional(z.boolean()),
390
+ canCreateAuthWit: optional(z.boolean()),
391
+ });
392
+
393
+ export const GrantedAccountsCapabilitySchema = AccountsCapabilitySchema.extend({
394
+ accounts: z.array(z.object({ alias: z.string(), item: schemas.AztecAddress })),
395
+ });
396
+
397
+ export const ContractsCapabilitySchema = z.object({
398
+ type: z.literal('contracts'),
399
+ contracts: z.union([z.literal('*'), z.array(schemas.AztecAddress)]),
400
+ canRegister: optional(z.boolean()),
401
+ canGetMetadata: optional(z.boolean()),
402
+ });
403
+
404
+ export const GrantedContractsCapabilitySchema = ContractsCapabilitySchema;
405
+
406
+ export const ContractClassesCapabilitySchema = z.object({
407
+ type: z.literal('contractClasses'),
408
+ classes: z.union([z.literal('*'), z.array(schemas.Fr)]),
409
+ canGetMetadata: z.boolean(),
410
+ });
411
+
412
+ export const GrantedContractClassesCapabilitySchema = ContractClassesCapabilitySchema;
413
+
414
+ export const SimulationCapabilitySchema = z.object({
415
+ type: z.literal('simulation'),
416
+ transactions: optional(
417
+ z.object({
418
+ scope: z.union([z.literal('*'), z.array(ContractFunctionPatternSchema)]),
419
+ }),
420
+ ),
421
+ utilities: optional(
422
+ z.object({
423
+ scope: z.union([z.literal('*'), z.array(ContractFunctionPatternSchema)]),
424
+ }),
425
+ ),
426
+ });
427
+
428
+ export const GrantedSimulationCapabilitySchema = SimulationCapabilitySchema;
429
+
430
+ export const TransactionCapabilitySchema = z.object({
431
+ type: z.literal('transaction'),
432
+ scope: z.union([z.literal('*'), z.array(ContractFunctionPatternSchema)]),
433
+ });
434
+
435
+ export const GrantedTransactionCapabilitySchema = TransactionCapabilitySchema;
436
+
437
+ export const DataCapabilitySchema = z.object({
438
+ type: z.literal('data'),
439
+ addressBook: optional(z.boolean()),
440
+ privateEvents: optional(
441
+ z.object({
442
+ contracts: z.union([z.literal('*'), z.array(schemas.AztecAddress)]),
443
+ }),
444
+ ),
445
+ });
446
+
447
+ export const GrantedDataCapabilitySchema = DataCapabilitySchema;
448
+
449
+ export const CapabilitySchema = z.discriminatedUnion('type', [
450
+ AccountsCapabilitySchema,
451
+ ContractsCapabilitySchema,
452
+ ContractClassesCapabilitySchema,
453
+ SimulationCapabilitySchema,
454
+ TransactionCapabilitySchema,
455
+ DataCapabilitySchema,
456
+ ]);
457
+
458
+ export const GrantedCapabilitySchema = z.discriminatedUnion('type', [
459
+ GrantedAccountsCapabilitySchema,
460
+ GrantedContractsCapabilitySchema,
461
+ GrantedContractClassesCapabilitySchema,
462
+ GrantedSimulationCapabilitySchema,
463
+ GrantedTransactionCapabilitySchema,
464
+ GrantedDataCapabilitySchema,
465
+ ]);
466
+
467
+ export const AppCapabilitiesSchema = z.object({
468
+ version: z.literal('1.0'),
469
+ metadata: z.object({
470
+ name: z.string(),
471
+ version: z.string(),
472
+ description: optional(z.string()),
473
+ url: optional(z.string()),
474
+ icon: optional(z.string()),
475
+ }),
476
+ capabilities: z.array(CapabilitySchema),
477
+ behavior: optional(
478
+ z.object({
479
+ mode: optional(z.enum(['strict', 'permissive'])),
480
+ expiration: optional(z.number()),
481
+ }),
482
+ ),
483
+ });
484
+
485
+ export const WalletCapabilitiesSchema = z.object({
486
+ version: z.literal('1.0'),
487
+ granted: z.array(GrantedCapabilitySchema),
488
+ wallet: z.object({
489
+ name: z.string(),
490
+ version: z.string(),
491
+ }),
492
+ expiresAt: optional(z.number()),
493
+ });
494
+
495
+ /**
496
+ * Record of all wallet method schemas (excluding batch).
497
+ * This is the single source of truth for method schemas - batch schemas are derived from this.
498
+ */
499
+ const WalletMethodSchemas = {
316
500
  getChainInfo: z
317
501
  .function()
318
502
  .args()
319
503
  .returns(z.object({ chainId: schemas.Fr, version: schemas.Fr })),
320
- getContractClassMetadata: z.function().args(schemas.Fr, optional(z.boolean())).returns(ContractClassMetadataSchema),
321
504
  getContractMetadata: z.function().args(schemas.AztecAddress).returns(ContractMetadataSchema),
322
- getTxReceipt: z.function().args(TxHash.schema).returns(TxReceipt.schema),
505
+ getContractClassMetadata: z.function().args(schemas.Fr).returns(ContractClassMetadataSchema),
323
506
  getPrivateEvents: z
324
507
  .function()
325
- .args(schemas.AztecAddress, EventMetadataDefinitionSchema, z.number(), z.number(), z.array(schemas.AztecAddress))
326
- .returns(z.array(AbiDecodedSchema)),
508
+ .args(EventMetadataDefinitionSchema, PrivateEventFilterSchema)
509
+ .returns(z.array(PrivateEventSchema)),
327
510
  registerSender: z.function().args(schemas.AztecAddress, optional(z.string())).returns(schemas.AztecAddress),
328
511
  getAddressBook: z
329
512
  .function()
@@ -335,28 +518,66 @@ export const WalletSchema: ApiSchemaFor<Wallet> = {
335
518
  .returns(z.array(z.object({ alias: z.string(), item: schemas.AztecAddress }))),
336
519
  registerContract: z
337
520
  .function()
338
- .args(InstanceDataSchema, optional(ContractArtifactSchema), optional(schemas.Fr))
521
+ .args(ContractInstanceWithAddressSchema, optional(ContractArtifactSchema), optional(schemas.Fr))
339
522
  .returns(ContractInstanceWithAddressSchema),
340
523
  simulateTx: z.function().args(ExecutionPayloadSchema, SimulateOptionsSchema).returns(TxSimulationResult.schema),
341
- simulateUtility: z
524
+ executeUtility: z
342
525
  .function()
343
- .args(z.string(), z.array(z.any()), schemas.AztecAddress, optional(z.array(AuthWitness.schema)))
344
- .returns(UtilitySimulationResult.schema),
526
+ .args(
527
+ FunctionCall.schema,
528
+ z.object({
529
+ scope: schemas.AztecAddress,
530
+ authWitnesses: optional(z.array(AuthWitness.schema)),
531
+ }),
532
+ )
533
+ .returns(UtilityExecutionResult.schema),
345
534
  profileTx: z.function().args(ExecutionPayloadSchema, ProfileOptionsSchema).returns(TxProfileResult.schema),
346
- sendTx: z.function().args(ExecutionPayloadSchema, SendOptionsSchema).returns(TxHash.schema),
535
+ sendTx: z
536
+ .function()
537
+ .args(ExecutionPayloadSchema, SendOptionsSchema)
538
+ .returns(z.union([TxHash.schema, TxReceipt.schema])),
347
539
  createAuthWit: z.function().args(schemas.AztecAddress, MessageHashOrIntentSchema).returns(AuthWitness.schema),
540
+ requestCapabilities: z.function().args(AppCapabilitiesSchema).returns(WalletCapabilitiesSchema),
541
+ };
542
+
543
+ /**
544
+ * Creates batch schemas from the individual wallet methods.
545
+ * This allows us to define them once and derive batch schemas automatically,
546
+ * reducing duplication and ensuring consistency.
547
+ */
548
+ function createBatchSchemas<T extends Record<string, z.ZodFunction<z.ZodTuple<any, any>, z.ZodTypeAny>>>(
549
+ methodSchemas: T,
550
+ ) {
551
+ const names = Object.keys(methodSchemas) as (keyof T)[];
552
+
553
+ const namesAndArgs = names.map(name =>
554
+ z.object({
555
+ name: z.literal(name),
556
+ args: methodSchemas[name].parameters(),
557
+ }),
558
+ );
559
+
560
+ const namesAndReturns = names.map(name =>
561
+ z.object({
562
+ name: z.literal(name),
563
+ result: methodSchemas[name].returnType(),
564
+ }),
565
+ );
566
+
567
+ // Type assertion needed because discriminatedUnion expects a tuple type [T, T, ...T[]]
568
+ // but we're building the array dynamically. The runtime behavior is correct.
569
+ return {
570
+ input: z.discriminatedUnion('name', namesAndArgs as [(typeof namesAndArgs)[0], ...typeof namesAndArgs]),
571
+ output: z.discriminatedUnion('name', namesAndReturns as [(typeof namesAndReturns)[0], ...typeof namesAndReturns]),
572
+ };
573
+ }
574
+
575
+ const { input: BatchedMethodSchema, output: BatchedResultSchema } = createBatchSchemas(WalletMethodSchemas);
576
+
577
+ export { BatchedMethodSchema, BatchedResultSchema };
578
+
579
+ export const WalletSchema: ApiSchemaFor<Wallet> = {
580
+ ...WalletMethodSchemas,
348
581
  // @ts-expect-error - ApiSchemaFor cannot properly type generic methods with readonly arrays
349
- batch: z
350
- .function()
351
- .args(z.array(BatchedMethodSchema))
352
- .returns(
353
- z.array(
354
- z.discriminatedUnion('name', [
355
- z.object({ name: z.literal('registerSender'), result: schemas.AztecAddress }),
356
- z.object({ name: z.literal('registerContract'), result: ContractInstanceWithAddressSchema }),
357
- z.object({ name: z.literal('sendTx'), result: TxHash.schema }),
358
- z.object({ name: z.literal('simulateUtility'), result: UtilitySimulationResult.schema }),
359
- ]),
360
- ),
361
- ),
582
+ batch: z.function().args(z.array(BatchedMethodSchema)).returns(z.array(BatchedResultSchema)),
362
583
  };