@aztec/aztec.js 0.0.1-commit.d3ec352c → 0.0.1-commit.e310a4c8

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 (197) hide show
  1. package/dest/account/account.d.ts +25 -40
  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 +21 -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 +6 -7
  13. package/dest/account/signerless_account.d.ts.map +1 -1
  14. package/dest/account/signerless_account.js +8 -11
  15. package/dest/api/account.d.ts +2 -4
  16. package/dest/api/account.d.ts.map +1 -1
  17. package/dest/api/account.js +1 -3
  18. package/dest/api/authorization.d.ts +2 -2
  19. package/dest/api/authorization.d.ts.map +1 -1
  20. package/dest/api/authorization.js +1 -1
  21. package/dest/api/contract.d.ts +16 -10
  22. package/dest/api/contract.d.ts.map +1 -1
  23. package/dest/api/contract.js +14 -8
  24. package/dest/api/fields.d.ts +3 -2
  25. package/dest/api/fields.d.ts.map +1 -1
  26. package/dest/api/fields.js +2 -1
  27. package/dest/api/keys.d.ts +1 -1
  28. package/dest/api/keys.js +1 -1
  29. package/dest/api/node.d.ts +8 -4
  30. package/dest/api/node.d.ts.map +1 -1
  31. package/dest/api/node.js +7 -3
  32. package/dest/api/protocol.d.ts +7 -1
  33. package/dest/api/protocol.d.ts.map +1 -1
  34. package/dest/api/protocol.js +6 -0
  35. package/dest/api/tx.d.ts +2 -2
  36. package/dest/api/tx.d.ts.map +1 -1
  37. package/dest/api/tx.js +1 -1
  38. package/dest/api/wallet.d.ts +3 -2
  39. package/dest/api/wallet.d.ts.map +1 -1
  40. package/dest/api/wallet.js +2 -1
  41. package/dest/authorization/call_authorization_request.d.ts +23 -2
  42. package/dest/authorization/call_authorization_request.d.ts.map +1 -1
  43. package/dest/contract/base_contract_interaction.d.ts +8 -10
  44. package/dest/contract/base_contract_interaction.d.ts.map +1 -1
  45. package/dest/contract/base_contract_interaction.js +5 -17
  46. package/dest/contract/batch_call.d.ts +1 -1
  47. package/dest/contract/batch_call.d.ts.map +1 -1
  48. package/dest/contract/batch_call.js +3 -1
  49. package/dest/contract/contract_base.d.ts +4 -1
  50. package/dest/contract/contract_base.d.ts.map +1 -1
  51. package/dest/contract/contract_function_interaction.d.ts +1 -1
  52. package/dest/contract/deploy_method.d.ts +64 -17
  53. package/dest/contract/deploy_method.d.ts.map +1 -1
  54. package/dest/contract/deploy_method.js +42 -24
  55. package/dest/contract/interaction_options.d.ts +42 -5
  56. package/dest/contract/interaction_options.d.ts.map +1 -1
  57. package/dest/contract/interaction_options.js +8 -1
  58. package/dest/contract/protocol_contracts/auth-registry.d.ts +27 -0
  59. package/dest/contract/protocol_contracts/auth-registry.d.ts.map +1 -0
  60. package/dest/contract/protocol_contracts/auth-registry.js +558 -0
  61. package/dest/contract/protocol_contracts/contract-class-registry.d.ts +26 -0
  62. package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -0
  63. package/dest/contract/protocol_contracts/contract-class-registry.js +385 -0
  64. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +22 -0
  65. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -0
  66. package/dest/contract/protocol_contracts/contract-instance-registry.js +465 -0
  67. package/dest/contract/protocol_contracts/fee-juice.d.ts +21 -0
  68. package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -0
  69. package/dest/contract/protocol_contracts/fee-juice.js +426 -0
  70. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts +34 -0
  71. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts.map +1 -0
  72. package/dest/contract/protocol_contracts/multi-call-entrypoint.js +575 -0
  73. package/dest/contract/protocol_contracts/public-checks.d.ts +26 -0
  74. package/dest/contract/protocol_contracts/public-checks.d.ts.map +1 -0
  75. package/dest/contract/protocol_contracts/public-checks.js +583 -0
  76. package/dest/contract/wait_for_proven.d.ts +2 -2
  77. package/dest/contract/wait_for_proven.d.ts.map +1 -1
  78. package/dest/contract/wait_for_proven.js +1 -1
  79. package/dest/contract/wait_opts.d.ts +16 -0
  80. package/dest/contract/wait_opts.d.ts.map +1 -0
  81. package/dest/contract/wait_opts.js +5 -0
  82. package/dest/deployment/broadcast_function.js +4 -4
  83. package/dest/deployment/publish_class.js +3 -3
  84. package/dest/deployment/publish_instance.d.ts +2 -2
  85. package/dest/deployment/publish_instance.d.ts.map +1 -1
  86. package/dest/deployment/publish_instance.js +3 -3
  87. package/dest/ethereum/portal_manager.d.ts +9 -6
  88. package/dest/ethereum/portal_manager.d.ts.map +1 -1
  89. package/dest/ethereum/portal_manager.js +17 -18
  90. package/dest/fee/fee_juice_payment_method_with_claim.js +1 -1
  91. package/dest/fee/private_fee_payment_method.js +1 -1
  92. package/dest/fee/public_fee_payment_method.js +1 -1
  93. package/dest/scripts/generate_protocol_contract_types.d.ts +2 -0
  94. package/dest/scripts/generate_protocol_contract_types.d.ts.map +1 -0
  95. package/dest/scripts/generate_protocol_contract_types.js +120 -0
  96. package/dest/utils/abi_types.d.ts +2 -2
  97. package/dest/utils/abi_types.d.ts.map +1 -1
  98. package/dest/utils/authwit.d.ts +9 -7
  99. package/dest/utils/authwit.d.ts.map +1 -1
  100. package/dest/utils/authwit.js +6 -10
  101. package/dest/utils/cross_chain.d.ts +2 -2
  102. package/dest/utils/cross_chain.d.ts.map +1 -1
  103. package/dest/utils/fee_juice.js +1 -1
  104. package/dest/utils/field_compressed_string.js +1 -1
  105. package/dest/utils/node.d.ts +12 -1
  106. package/dest/utils/node.d.ts.map +1 -1
  107. package/dest/utils/node.js +46 -0
  108. package/dest/utils/pub_key.d.ts +2 -2
  109. package/dest/utils/pub_key.d.ts.map +1 -1
  110. package/dest/utils/pub_key.js +1 -1
  111. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts +5 -8
  112. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts.map +1 -1
  113. package/dest/wallet/account_entrypoint_meta_payment_method.js +28 -43
  114. package/dest/wallet/account_manager.d.ts +6 -9
  115. package/dest/wallet/account_manager.d.ts.map +1 -1
  116. package/dest/wallet/account_manager.js +6 -12
  117. package/dest/wallet/capabilities.d.ts +444 -0
  118. package/dest/wallet/capabilities.d.ts.map +1 -0
  119. package/dest/wallet/capabilities.js +3 -0
  120. package/dest/wallet/deploy_account_method.d.ts +35 -7
  121. package/dest/wallet/deploy_account_method.d.ts.map +1 -1
  122. package/dest/wallet/deploy_account_method.js +8 -6
  123. package/dest/wallet/index.d.ts +2 -1
  124. package/dest/wallet/index.d.ts.map +1 -1
  125. package/dest/wallet/index.js +1 -0
  126. package/dest/wallet/wallet.d.ts +1542 -917
  127. package/dest/wallet/wallet.d.ts.map +1 -1
  128. package/dest/wallet/wallet.js +191 -86
  129. package/package.json +14 -12
  130. package/src/account/account.ts +34 -58
  131. package/src/account/account_contract.ts +7 -8
  132. package/src/account/account_with_secret_key.ts +34 -9
  133. package/src/account/index.ts +3 -2
  134. package/src/account/signerless_account.ts +14 -13
  135. package/src/api/account.ts +9 -3
  136. package/src/api/authorization.ts +1 -0
  137. package/src/api/contract.ts +22 -7
  138. package/src/api/fields.ts +2 -1
  139. package/src/api/keys.ts +2 -2
  140. package/src/api/node.ts +7 -3
  141. package/src/api/protocol.ts +7 -0
  142. package/src/api/tx.ts +2 -0
  143. package/src/api/wallet.ts +47 -2
  144. package/src/authorization/call_authorization_request.ts +1 -1
  145. package/src/contract/base_contract_interaction.ts +27 -15
  146. package/src/contract/batch_call.ts +4 -2
  147. package/src/contract/deploy_method.ts +123 -30
  148. package/src/contract/interaction_options.ts +49 -4
  149. package/src/contract/protocol_contracts/auth-registry.ts +351 -0
  150. package/src/contract/protocol_contracts/contract-class-registry.ts +241 -0
  151. package/src/contract/protocol_contracts/contract-instance-registry.ts +302 -0
  152. package/src/contract/protocol_contracts/fee-juice.ts +264 -0
  153. package/src/contract/protocol_contracts/multi-call-entrypoint.ts +332 -0
  154. package/src/contract/protocol_contracts/public-checks.ts +316 -0
  155. package/src/contract/wait_for_proven.ts +1 -1
  156. package/src/contract/wait_opts.ts +21 -0
  157. package/src/deployment/broadcast_function.ts +4 -4
  158. package/src/deployment/publish_class.ts +3 -3
  159. package/src/deployment/publish_instance.ts +3 -6
  160. package/src/ethereum/portal_manager.ts +20 -24
  161. package/src/fee/fee_juice_payment_method_with_claim.ts +1 -1
  162. package/src/fee/private_fee_payment_method.ts +1 -1
  163. package/src/fee/public_fee_payment_method.ts +1 -1
  164. package/src/scripts/generate_protocol_contract_types.ts +150 -0
  165. package/src/utils/abi_types.ts +1 -1
  166. package/src/utils/authwit.ts +20 -8
  167. package/src/utils/cross_chain.ts +1 -1
  168. package/src/utils/fee_juice.ts +1 -1
  169. package/src/utils/field_compressed_string.ts +1 -1
  170. package/src/utils/node.ts +62 -0
  171. package/src/utils/pub_key.ts +2 -2
  172. package/src/wallet/account_entrypoint_meta_payment_method.ts +28 -60
  173. package/src/wallet/account_manager.ts +6 -14
  174. package/src/wallet/capabilities.ts +491 -0
  175. package/src/wallet/deploy_account_method.ts +38 -14
  176. package/src/wallet/index.ts +1 -0
  177. package/src/wallet/wallet.ts +307 -92
  178. package/dest/account/interface.d.ts +0 -19
  179. package/dest/account/interface.d.ts.map +0 -1
  180. package/dest/account/interface.js +0 -5
  181. package/dest/contract/deploy_sent_tx.d.ts +0 -48
  182. package/dest/contract/deploy_sent_tx.d.ts.map +0 -1
  183. package/dest/contract/deploy_sent_tx.js +0 -46
  184. package/dest/contract/protocol_contracts.d.ts +0 -9
  185. package/dest/contract/protocol_contracts.d.ts.map +0 -1
  186. package/dest/contract/protocol_contracts.js +0 -26
  187. package/dest/contract/sent_tx.d.ts +0 -51
  188. package/dest/contract/sent_tx.d.ts.map +0 -1
  189. package/dest/contract/sent_tx.js +0 -90
  190. package/dest/contract/unsafe_contract.d.ts +0 -15
  191. package/dest/contract/unsafe_contract.d.ts.map +0 -1
  192. package/dest/contract/unsafe_contract.js +0 -6
  193. package/src/account/interface.ts +0 -25
  194. package/src/contract/deploy_sent_tx.ts +0 -75
  195. package/src/contract/protocol_contracts.ts +0 -35
  196. package/src/contract/sent_tx.ts +0 -130
  197. package/src/contract/unsafe_contract.ts +0 -19
@@ -1,34 +1,62 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { ContractArtifact, FunctionArtifact } from '@aztec/stdlib/abi';
3
3
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
5
5
  import type { PublicKeys } from '@aztec/stdlib/keys';
6
6
  import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
7
7
 
8
+ import type { Account } from '../account/account.js';
8
9
  import type { Contract } from '../contract/contract.js';
9
10
  import type { ContractBase } from '../contract/contract_base.js';
10
11
  import {
11
12
  DeployMethod,
12
- type DeployOptions,
13
+ type DeployOptionsWithoutWait,
13
14
  type RequestDeployOptions,
14
15
  type SimulateDeployOptions,
15
16
  } from '../contract/deploy_method.js';
17
+ import type { FeePaymentMethodOption, InteractionWaitOptions } from '../contract/interaction_options.js';
16
18
  import type { FeePaymentMethod } from '../fee/fee_payment_method.js';
17
19
  import { AccountEntrypointMetaPaymentMethod } from './account_entrypoint_meta_payment_method.js';
18
20
  import type { Wallet } from './index.js';
19
21
 
22
+ /**
23
+ * Extended fee payment method option for account deployments that includes entrypoint wrapping options
24
+ */
25
+ export type DeployAccountFeePaymentMethodOption = FeePaymentMethodOption & {
26
+ /** Optional entrypoint-specific options for wrapping execution payloads */
27
+ feeEntrypointOptions?: unknown;
28
+ };
29
+
20
30
  /**
21
31
  * The configuration options for the request method. Omits the contractAddressSalt, since
22
32
  * for account contracts that is fixed in the constructor
23
33
  */
24
- export type RequestDeployAccountOptions = Omit<RequestDeployOptions, 'contractAddressSalt'>;
34
+ export type RequestDeployAccountOptions = Omit<RequestDeployOptions, 'contractAddressSalt' | 'fee'> & {
35
+ /** Fee options specific to account deployment */
36
+ fee?: DeployAccountFeePaymentMethodOption;
37
+ };
38
+
39
+ /**
40
+ * Base configuration options for the send/prove methods without wait parameter. Omits:
41
+ * - The contractAddressSalt, since for account contracts that is fixed in the constructor.
42
+ * - UniversalDeployment flag, since account contracts are always deployed with it set to true
43
+ */
44
+ export type DeployAccountOptionsWithoutWait = Omit<DeployOptionsWithoutWait, 'contractAddressSalt' | 'universalDeploy'>;
25
45
 
26
46
  /**
27
47
  * The configuration options for the send/prove methods. Omits:
28
48
  * - The contractAddressSalt, since for account contracts that is fixed in the constructor.
29
49
  * - UniversalDeployment flag, since account contracts are always deployed with it set to true
30
50
  */
31
- export type DeployAccountOptions = Omit<DeployOptions, 'contractAddressSalt' | 'universalDeploy'>;
51
+ export type DeployAccountOptions<W extends InteractionWaitOptions = undefined> = DeployAccountOptionsWithoutWait & {
52
+ /**
53
+ * Whether to wait for the transaction to be mined.
54
+ * - undefined (default): wait with default options and return TxReceipt
55
+ * - WaitOpts object: wait with custom options and return TxReceipt
56
+ * - false: return txHash immediately without waiting
57
+ */
58
+ wait?: W;
59
+ };
32
60
 
33
61
  /**
34
62
  * The configuration options for the simulate method. Omits the contractAddressSalt, since
@@ -47,6 +75,7 @@ export class DeployAccountMethod<TContract extends ContractBase = Contract> exte
47
75
  artifact: ContractArtifact,
48
76
  postDeployCtor: (instance: ContractInstanceWithAddress, wallet: Wallet) => TContract,
49
77
  private salt: Fr,
78
+ private account: Account,
50
79
  args: any[] = [],
51
80
  constructorNameOrArtifact?: string | FunctionArtifact,
52
81
  ) {
@@ -61,19 +90,14 @@ export class DeployAccountMethod<TContract extends ContractBase = Contract> exte
61
90
  * For more details on how the fee payment routing works see documentation of AccountEntrypointMetaPaymentMethod class.
62
91
  *
63
92
  * @param originalPaymentMethod - originalPaymentMethod The original payment method to be wrapped.
93
+ * @param feeEntrypointOptions - Optional entrypoint-specific options for wrapping. If not provided, will be auto-computed based on the payment method.
64
94
  * @returns A FeePaymentMethod that routes the original one through the account's entrypoint (AccountEntrypointMetaPaymentMethod)
65
95
  */
66
- private getSelfFeePaymentMethod(originalPaymentMethod?: FeePaymentMethod) {
96
+ private getSelfFeePaymentMethod(originalPaymentMethod?: FeePaymentMethod, feeEntrypointOptions?: any) {
67
97
  if (!this.address) {
68
98
  throw new Error('Instance is not yet constructed. This is a bug!');
69
99
  }
70
- return new AccountEntrypointMetaPaymentMethod(
71
- this.wallet,
72
- this.artifact,
73
- 'entrypoint',
74
- this.address,
75
- originalPaymentMethod,
76
- );
100
+ return new AccountEntrypointMetaPaymentMethod(this.account, originalPaymentMethod, feeEntrypointOptions);
77
101
  }
78
102
 
79
103
  /**
@@ -97,7 +121,7 @@ export class DeployAccountMethod<TContract extends ContractBase = Contract> exte
97
121
  const executionPayloads = [deploymentExecutionPayload];
98
122
  // If this is a self-deployment, manage the fee accordingly
99
123
  if (opts?.deployer?.equals(AztecAddress.ZERO)) {
100
- const feePaymentMethod = this.getSelfFeePaymentMethod(opts?.fee?.paymentMethod);
124
+ const feePaymentMethod = this.getSelfFeePaymentMethod(opts?.fee?.paymentMethod, opts?.fee?.feeEntrypointOptions);
101
125
  const feeExecutionPayload = await feePaymentMethod.getExecutionPayload();
102
126
  // Notice they are reversed (fee payment usually goes first):
103
127
  // this is because we need to construct the contract BEFORE it can pay for its own fee
@@ -113,7 +137,7 @@ export class DeployAccountMethod<TContract extends ContractBase = Contract> exte
113
137
  return mergeExecutionPayloads(executionPayloads);
114
138
  }
115
139
 
116
- override convertDeployOptionsToRequestOptions(options: DeployOptions): RequestDeployOptions {
140
+ override convertDeployOptionsToRequestOptions(options: DeployAccountOptionsWithoutWait): RequestDeployOptions {
117
141
  return {
118
142
  ...options,
119
143
  // Deployer is handled in the request method and forcibly set to undefined,
@@ -1,2 +1,3 @@
1
1
  export * from './wallet.js';
2
2
  export * from './account_manager.js';
3
+ export * from './capabilities.js';
@@ -1,6 +1,8 @@
1
1
  import type { ChainInfo } from '@aztec/entrypoints/interfaces';
2
- 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';
3
4
  import {
5
+ type AbiDecoded,
4
6
  AbiTypeSchema,
5
7
  type ContractArtifact,
6
8
  ContractArtifactSchema,
@@ -10,15 +12,10 @@ import {
10
12
  } from '@aztec/stdlib/abi';
11
13
  import { AuthWitness } from '@aztec/stdlib/auth-witness';
12
14
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
13
- import {
14
- type ContractClassMetadata,
15
- ContractClassWithIdSchema,
16
- type ContractInstanceWithAddress,
17
- ContractInstanceWithAddressSchema,
18
- type ContractMetadata,
19
- } from '@aztec/stdlib/contract';
15
+ import { type ContractInstanceWithAddress, ContractInstanceWithAddressSchema } from '@aztec/stdlib/contract';
20
16
  import { Gas } from '@aztec/stdlib/gas';
21
- import { AbiDecodedSchema, type ApiSchemaFor, type ZodFor, optional, schemas } from '@aztec/stdlib/schemas';
17
+ import { AbiDecodedSchema, type ApiSchemaFor, optional, schemas, zodFor } from '@aztec/stdlib/schemas';
18
+ import type { ExecutionPayload, InTx } from '@aztec/stdlib/tx';
22
19
  import {
23
20
  Capsule,
24
21
  HashedValues,
@@ -27,19 +24,23 @@ import {
27
24
  TxReceipt,
28
25
  TxSimulationResult,
29
26
  UtilitySimulationResult,
27
+ inTxSchema,
30
28
  } from '@aztec/stdlib/tx';
31
- import type { ExecutionPayload } from '@aztec/stdlib/tx';
32
29
 
33
30
  import { z } from 'zod';
34
31
 
35
- import type {
36
- FeeEstimationOptions,
37
- GasSettingsOption,
38
- ProfileInteractionOptions,
39
- SendInteractionOptions,
40
- SimulateInteractionOptions,
32
+ import {
33
+ type FeeEstimationOptions,
34
+ type GasSettingsOption,
35
+ type InteractionWaitOptions,
36
+ NO_WAIT,
37
+ type ProfileInteractionOptions,
38
+ type SendInteractionOptionsWithoutWait,
39
+ type SendReturn,
40
+ type SimulateInteractionOptions,
41
41
  } from '../contract/interaction_options.js';
42
42
  import type { CallIntent, IntentInnerHash } from '../utils/authwit.js';
43
+ import type { AppCapabilities, WalletCapabilities } from './capabilities.js';
43
44
 
44
45
  /**
45
46
  * A wrapper type that allows any item to be associated with an alias.
@@ -57,7 +58,7 @@ export type Aliased<T> = {
57
58
 
58
59
  /**
59
60
  * Options for simulating interactions with the wallet. Overrides the fee settings of an interaction with
60
- * a simplified version that only hints at the wallet wether the interaction contains a
61
+ * a simplified version that only hints at the wallet whether the interaction contains a
61
62
  * fee payment method or not
62
63
  */
63
64
  export type SimulateOptions = Omit<SimulateInteractionOptions, 'fee'> & {
@@ -67,7 +68,7 @@ export type SimulateOptions = Omit<SimulateInteractionOptions, 'fee'> & {
67
68
 
68
69
  /**
69
70
  * Options for profiling interactions with the wallet. Overrides the fee settings of an interaction with
70
- * a simplified version that only hints at the wallet wether the interaction contains a
71
+ * a simplified version that only hints at the wallet whether the interaction contains a
71
72
  * fee payment method or not
72
73
  */
73
74
  export type ProfileOptions = Omit<ProfileInteractionOptions, 'fee'> & {
@@ -77,45 +78,54 @@ export type ProfileOptions = Omit<ProfileInteractionOptions, 'fee'> & {
77
78
 
78
79
  /**
79
80
  * Options for sending/proving interactions with the wallet. Overrides the fee settings of an interaction with
80
- * a simplified version that only hints at the wallet wether the interaction contains a
81
+ * a simplified version that only hints at the wallet whether the interaction contains a
81
82
  * fee payment method or not
82
83
  */
83
- export type SendOptions = Omit<SendInteractionOptions, 'fee'> & {
84
+ export type SendOptions<W extends InteractionWaitOptions = undefined> = Omit<
85
+ SendInteractionOptionsWithoutWait,
86
+ 'fee'
87
+ > & {
84
88
  /** The fee options */
85
89
  fee?: GasSettingsOption;
90
+ /** Whether to wait for the transaction to be mined */
91
+ wait?: W;
86
92
  };
87
93
 
88
94
  /**
89
- * Helper type that represents all methods that can be batched.
95
+ * Helper type that represents all methods that can be batched (all methods except batch itself).
90
96
  */
91
- export type BatchableMethods = Pick<
92
- Wallet,
93
- 'registerContract' | 'sendTx' | 'registerSender' | 'simulateUtility' | 'simulateTx'
94
- >;
97
+ export type BatchableMethods = Omit<Wallet, 'batch'>;
95
98
 
96
99
  /**
97
- * From the batchable methods, we create a type that represents a method call with its name and arguments.
98
- * This is what the wallet will accept as arguments to the `batch` method.
100
+ * A method call with its name and arguments.
99
101
  */
100
- export type BatchedMethod<T extends keyof BatchableMethods> = {
102
+ type BatchedMethodInternal<T extends keyof BatchableMethods> = {
101
103
  /** The method name */
102
104
  name: T;
103
105
  /** The method arguments */
104
106
  args: Parameters<BatchableMethods[T]>;
105
107
  };
106
108
 
109
+ /**
110
+ * Union of all possible batched method calls.
111
+ * This ensures type safety: the `args` must match the specific `name`.
112
+ */
113
+ export type BatchedMethod = {
114
+ [K in keyof BatchableMethods]: BatchedMethodInternal<K>;
115
+ }[keyof BatchableMethods];
116
+
107
117
  /**
108
118
  * Helper type to extract the return type of a batched method
109
119
  */
110
120
  export type BatchedMethodResult<T> =
111
- T extends BatchedMethod<infer K> ? Awaited<ReturnType<BatchableMethods[K]>> : never;
121
+ T extends BatchedMethodInternal<infer K> ? Awaited<ReturnType<BatchableMethods[K]>> : never;
112
122
 
113
123
  /**
114
124
  * Wrapper type for batch results that includes the method name for discriminated union deserialization.
115
125
  * Each result is wrapped as \{ name: 'methodName', result: ActualResult \} to allow proper deserialization
116
126
  * when AztecAddress and TxHash would otherwise be ambiguous (both are hex strings).
117
127
  */
118
- export type BatchedMethodResultWrapper<T extends BatchedMethod<keyof BatchableMethods>> = {
128
+ export type BatchedMethodResultWrapper<T extends BatchedMethod> = {
119
129
  /** The method name */
120
130
  name: T['name'];
121
131
  /** The method result */
@@ -125,25 +135,79 @@ export type BatchedMethodResultWrapper<T extends BatchedMethod<keyof BatchableMe
125
135
  /**
126
136
  * Maps a tuple of BatchedMethod to a tuple of their wrapped return types
127
137
  */
128
- export type BatchResults<T extends readonly BatchedMethod<keyof BatchableMethods>[]> = {
138
+ export type BatchResults<T extends readonly BatchedMethod[]> = {
129
139
  [K in keyof T]: BatchedMethodResultWrapper<T[K]>;
130
140
  };
131
141
 
142
+ /**
143
+ * Filter options when querying private events.
144
+ */
145
+ export type PrivateEventFilter = {
146
+ /** The address of the contract that emitted the events. */
147
+ contractAddress: AztecAddress;
148
+ /** Addresses of accounts that are in scope for this filter. */
149
+ scopes: AztecAddress[];
150
+ /** Transaction in which the events were emitted. */
151
+ txHash?: TxHash;
152
+ /** The block number from which to start fetching events (inclusive).
153
+ * Optional. If provided, it must be greater or equal than 1.
154
+ * Defaults to the initial L2 block number (INITIAL_L2_BLOCK_NUM).
155
+ * */
156
+ fromBlock?: BlockNumber;
157
+ /** The block number until which to fetch logs (not inclusive).
158
+ * Optional. If provided, it must be greater than fromBlock.
159
+ * Defaults to the latest known block to PXE + 1.
160
+ */
161
+ toBlock?: BlockNumber;
162
+ };
163
+
164
+ /**
165
+ * An ABI decoded private event with associated metadata.
166
+ */
167
+ export type PrivateEvent<T> = {
168
+ /** The ABI decoded event */
169
+ event: T;
170
+ /** Metadata describing event context information such as tx and block */
171
+ metadata: InTx;
172
+ };
173
+
174
+ /**
175
+ * Contract metadata including deployment and registration status.
176
+ */
177
+ export type ContractMetadata = {
178
+ /** The contract instance */
179
+ instance?: ContractInstanceWithAddress;
180
+ /** Whether the contract has been initialized (init nullifier exists) */
181
+ isContractInitialized: boolean;
182
+ /** Whether the contract instance is publicly deployed on-chain */
183
+ isContractPublished: boolean;
184
+ /** Whether the contract has been updated to a different class */
185
+ isContractUpdated: boolean;
186
+ /** The updated contract class ID if the contract has been updated */
187
+ updatedContractClassId?: Fr | undefined;
188
+ };
189
+
190
+ /**
191
+ * Contract class metadata.
192
+ */
193
+ export type ContractClassMetadata = {
194
+ /** Whether the artifact is registered in the wallet */
195
+ isArtifactRegistered: boolean;
196
+ /** Whether the contract class is publicly registered on-chain */
197
+ isContractClassPubliclyRegistered: boolean;
198
+ };
199
+
132
200
  /**
133
201
  * The wallet interface.
134
202
  */
135
203
  export type Wallet = {
136
- getContractClassMetadata(id: Fr, includeArtifact?: boolean): Promise<ContractClassMetadata>;
137
- getContractMetadata(address: AztecAddress): Promise<ContractMetadata>;
138
204
  getPrivateEvents<T>(
139
- contractAddress: AztecAddress,
140
205
  eventMetadata: EventMetadataDefinition,
141
- from: number,
142
- numBlocks: number,
143
- recipients: AztecAddress[],
144
- ): Promise<T[]>;
206
+ eventFilter: PrivateEventFilter,
207
+ ): Promise<PrivateEvent<T>[]>;
145
208
  getChainInfo(): Promise<ChainInfo>;
146
- getTxReceipt(txHash: TxHash): Promise<TxReceipt>;
209
+ getContractMetadata(address: AztecAddress): Promise<ContractMetadata>;
210
+ getContractClassMetadata(id: Fr): Promise<ContractClassMetadata>;
147
211
  registerSender(address: AztecAddress, alias?: string): Promise<AztecAddress>;
148
212
  getAddressBook(): Promise<Aliased<AztecAddress>[]>;
149
213
  getAccounts(): Promise<Aliased<AztecAddress>[]>;
@@ -155,9 +219,13 @@ export type Wallet = {
155
219
  simulateTx(exec: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult>;
156
220
  simulateUtility(call: FunctionCall, authwits?: AuthWitness[]): Promise<UtilitySimulationResult>;
157
221
  profileTx(exec: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult>;
158
- sendTx(exec: ExecutionPayload, opts: SendOptions): Promise<TxHash>;
159
- createAuthWit(from: AztecAddress, messageHashOrIntent: Fr | IntentInnerHash | CallIntent): Promise<AuthWitness>;
160
- batch<const T extends readonly BatchedMethod<keyof BatchableMethods>[]>(methods: T): Promise<BatchResults<T>>;
222
+ sendTx<W extends InteractionWaitOptions = undefined>(
223
+ exec: ExecutionPayload,
224
+ opts: SendOptions<W>,
225
+ ): Promise<SendReturn<W>>;
226
+ createAuthWit(from: AztecAddress, messageHashOrIntent: IntentInnerHash | CallIntent): Promise<AuthWitness>;
227
+ requestCapabilities(manifest: AppCapabilities): Promise<WalletCapabilities>;
228
+ batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>>;
161
229
  };
162
230
 
163
231
  export const FunctionCallSchema = z.object({
@@ -195,11 +263,19 @@ export const WalletSimulationFeeOptionSchema = GasSettingsOptionSchema.extend({
195
263
  estimateGas: optional(z.boolean()),
196
264
  });
197
265
 
266
+ export const WaitOptsSchema = z.object({
267
+ ignoreDroppedReceiptsFor: optional(z.number()),
268
+ timeout: optional(z.number()),
269
+ interval: optional(z.number()),
270
+ dontThrowOnRevert: optional(z.boolean()),
271
+ });
272
+
198
273
  export const SendOptionsSchema = z.object({
199
274
  from: schemas.AztecAddress,
200
275
  authWitnesses: optional(z.array(AuthWitness.schema)),
201
276
  capsules: optional(z.array(Capsule.schema)),
202
277
  fee: optional(GasSettingsOptionSchema),
278
+ wait: optional(z.union([z.literal(NO_WAIT), WaitOptsSchema])),
203
279
  });
204
280
 
205
281
  export const SimulateOptionsSchema = z.object({
@@ -218,7 +294,6 @@ export const ProfileOptionsSchema = SimulateOptionsSchema.extend({
218
294
  });
219
295
 
220
296
  export const MessageHashOrIntentSchema = z.union([
221
- schemas.Fr,
222
297
  z.object({ consumer: schemas.AztecAddress, innerHash: schemas.Fr }),
223
298
  z.object({
224
299
  caller: schemas.AztecAddress,
@@ -226,59 +301,168 @@ export const MessageHashOrIntentSchema = z.union([
226
301
  }),
227
302
  ]);
228
303
 
229
- export const BatchedMethodSchema = z.union([
230
- z.object({
231
- name: z.literal('registerSender'),
232
- args: z.tuple([schemas.AztecAddress, optional(z.string())]),
233
- }),
234
- z.object({
235
- name: z.literal('registerContract'),
236
- args: z.tuple([ContractInstanceWithAddressSchema, optional(ContractArtifactSchema), optional(schemas.Fr)]),
237
- }),
238
- z.object({
239
- name: z.literal('sendTx'),
240
- args: z.tuple([ExecutionPayloadSchema, SendOptionsSchema]),
241
- }),
242
- z.object({
243
- name: z.literal('simulateUtility'),
244
- args: z.tuple([FunctionCallSchema, optional(z.array(AuthWitness.schema))]),
245
- }),
304
+ export const EventMetadataDefinitionSchema = z.object({
305
+ eventSelector: schemas.EventSelector,
306
+ abiType: AbiTypeSchema,
307
+ fieldNames: z.array(z.string()),
308
+ });
309
+
310
+ export const PrivateEventSchema: z.ZodType<any> = zodFor<PrivateEvent<AbiDecoded>>()(
246
311
  z.object({
247
- name: z.literal('simulateTx'),
248
- args: z.tuple([ExecutionPayloadSchema, SimulateOptionsSchema]),
312
+ event: AbiDecodedSchema,
313
+ metadata: inTxSchema(),
249
314
  }),
250
- ]);
315
+ );
316
+
317
+ export const PrivateEventFilterSchema = z.object({
318
+ contractAddress: schemas.AztecAddress,
319
+ scopes: z.array(schemas.AztecAddress),
320
+ txHash: optional(TxHash.schema),
321
+ fromBlock: optional(BlockNumberPositiveSchema),
322
+ toBlock: optional(BlockNumberPositiveSchema),
323
+ });
251
324
 
252
325
  export const ContractMetadataSchema = z.object({
253
- contractInstance: z.union([ContractInstanceWithAddressSchema, z.undefined()]),
326
+ instance: optional(ContractInstanceWithAddressSchema),
254
327
  isContractInitialized: z.boolean(),
255
328
  isContractPublished: z.boolean(),
256
- }) satisfies ZodFor<ContractMetadata>;
329
+ isContractUpdated: z.boolean(),
330
+ updatedContractClassId: optional(schemas.Fr),
331
+ });
257
332
 
258
333
  export const ContractClassMetadataSchema = z.object({
259
- contractClass: z.union([ContractClassWithIdSchema, z.undefined()]),
334
+ isArtifactRegistered: z.boolean(),
260
335
  isContractClassPubliclyRegistered: z.boolean(),
261
- artifact: z.union([ContractArtifactSchema, z.undefined()]),
262
- }) satisfies ZodFor<ContractClassMetadata>;
336
+ });
263
337
 
264
- export const EventMetadataDefinitionSchema = z.object({
265
- eventSelector: schemas.EventSelector,
266
- abiType: AbiTypeSchema,
267
- fieldNames: z.array(z.string()),
338
+ export const ContractFunctionPatternSchema = z.object({
339
+ contract: z.union([schemas.AztecAddress, z.literal('*')]),
340
+ function: z.union([z.string(), z.literal('*')]),
268
341
  });
269
342
 
270
- export const WalletSchema: ApiSchemaFor<Wallet> = {
343
+ export const AccountsCapabilitySchema = z.object({
344
+ type: z.literal('accounts'),
345
+ canGet: optional(z.boolean()),
346
+ canCreateAuthWit: optional(z.boolean()),
347
+ });
348
+
349
+ export const GrantedAccountsCapabilitySchema = AccountsCapabilitySchema.extend({
350
+ accounts: z.array(z.object({ alias: z.string(), item: schemas.AztecAddress })),
351
+ });
352
+
353
+ export const ContractsCapabilitySchema = z.object({
354
+ type: z.literal('contracts'),
355
+ contracts: z.union([z.literal('*'), z.array(schemas.AztecAddress)]),
356
+ canRegister: optional(z.boolean()),
357
+ canGetMetadata: optional(z.boolean()),
358
+ });
359
+
360
+ export const GrantedContractsCapabilitySchema = ContractsCapabilitySchema;
361
+
362
+ export const ContractClassesCapabilitySchema = z.object({
363
+ type: z.literal('contractClasses'),
364
+ classes: z.union([z.literal('*'), z.array(schemas.Fr)]),
365
+ canGetMetadata: z.boolean(),
366
+ });
367
+
368
+ export const GrantedContractClassesCapabilitySchema = ContractClassesCapabilitySchema;
369
+
370
+ export const SimulationCapabilitySchema = z.object({
371
+ type: z.literal('simulation'),
372
+ transactions: optional(
373
+ z.object({
374
+ scope: z.union([z.literal('*'), z.array(ContractFunctionPatternSchema)]),
375
+ }),
376
+ ),
377
+ utilities: optional(
378
+ z.object({
379
+ scope: z.union([z.literal('*'), z.array(ContractFunctionPatternSchema)]),
380
+ }),
381
+ ),
382
+ });
383
+
384
+ export const GrantedSimulationCapabilitySchema = SimulationCapabilitySchema;
385
+
386
+ export const TransactionCapabilitySchema = z.object({
387
+ type: z.literal('transaction'),
388
+ scope: z.union([z.literal('*'), z.array(ContractFunctionPatternSchema)]),
389
+ });
390
+
391
+ export const GrantedTransactionCapabilitySchema = TransactionCapabilitySchema;
392
+
393
+ export const DataCapabilitySchema = z.object({
394
+ type: z.literal('data'),
395
+ addressBook: optional(z.boolean()),
396
+ privateEvents: optional(
397
+ z.object({
398
+ contracts: z.union([z.literal('*'), z.array(schemas.AztecAddress)]),
399
+ }),
400
+ ),
401
+ });
402
+
403
+ export const GrantedDataCapabilitySchema = DataCapabilitySchema;
404
+
405
+ export const CapabilitySchema = z.discriminatedUnion('type', [
406
+ AccountsCapabilitySchema,
407
+ ContractsCapabilitySchema,
408
+ ContractClassesCapabilitySchema,
409
+ SimulationCapabilitySchema,
410
+ TransactionCapabilitySchema,
411
+ DataCapabilitySchema,
412
+ ]);
413
+
414
+ export const GrantedCapabilitySchema = z.discriminatedUnion('type', [
415
+ GrantedAccountsCapabilitySchema,
416
+ GrantedContractsCapabilitySchema,
417
+ GrantedContractClassesCapabilitySchema,
418
+ GrantedSimulationCapabilitySchema,
419
+ GrantedTransactionCapabilitySchema,
420
+ GrantedDataCapabilitySchema,
421
+ ]);
422
+
423
+ export const AppCapabilitiesSchema = z.object({
424
+ version: z.literal('1.0'),
425
+ metadata: z.object({
426
+ name: z.string(),
427
+ version: z.string(),
428
+ description: optional(z.string()),
429
+ url: optional(z.string()),
430
+ icon: optional(z.string()),
431
+ }),
432
+ capabilities: z.array(CapabilitySchema),
433
+ behavior: optional(
434
+ z.object({
435
+ mode: optional(z.enum(['strict', 'permissive'])),
436
+ expiration: optional(z.number()),
437
+ }),
438
+ ),
439
+ });
440
+
441
+ export const WalletCapabilitiesSchema = z.object({
442
+ version: z.literal('1.0'),
443
+ granted: z.array(GrantedCapabilitySchema),
444
+ wallet: z.object({
445
+ name: z.string(),
446
+ version: z.string(),
447
+ }),
448
+ expiresAt: optional(z.number()),
449
+ });
450
+
451
+ /**
452
+ * Record of all wallet method schemas (excluding batch).
453
+ * This is the single source of truth for method schemas - batch schemas are derived from this.
454
+ */
455
+ const WalletMethodSchemas = {
271
456
  getChainInfo: z
272
457
  .function()
273
458
  .args()
274
459
  .returns(z.object({ chainId: schemas.Fr, version: schemas.Fr })),
275
- getContractClassMetadata: z.function().args(schemas.Fr, optional(z.boolean())).returns(ContractClassMetadataSchema),
276
460
  getContractMetadata: z.function().args(schemas.AztecAddress).returns(ContractMetadataSchema),
277
- getTxReceipt: z.function().args(TxHash.schema).returns(TxReceipt.schema),
461
+ getContractClassMetadata: z.function().args(schemas.Fr).returns(ContractClassMetadataSchema),
278
462
  getPrivateEvents: z
279
463
  .function()
280
- .args(schemas.AztecAddress, EventMetadataDefinitionSchema, z.number(), z.number(), z.array(schemas.AztecAddress))
281
- .returns(z.array(AbiDecodedSchema)),
464
+ .args(EventMetadataDefinitionSchema, PrivateEventFilterSchema)
465
+ .returns(z.array(PrivateEventSchema)),
282
466
  registerSender: z.function().args(schemas.AztecAddress, optional(z.string())).returns(schemas.AztecAddress),
283
467
  getAddressBook: z
284
468
  .function()
@@ -298,21 +482,52 @@ export const WalletSchema: ApiSchemaFor<Wallet> = {
298
482
  .args(FunctionCallSchema, optional(z.array(AuthWitness.schema)))
299
483
  .returns(UtilitySimulationResult.schema),
300
484
  profileTx: z.function().args(ExecutionPayloadSchema, ProfileOptionsSchema).returns(TxProfileResult.schema),
301
- sendTx: z.function().args(ExecutionPayloadSchema, SendOptionsSchema).returns(TxHash.schema),
485
+ sendTx: z
486
+ .function()
487
+ .args(ExecutionPayloadSchema, SendOptionsSchema)
488
+ .returns(z.union([TxHash.schema, TxReceipt.schema])),
302
489
  createAuthWit: z.function().args(schemas.AztecAddress, MessageHashOrIntentSchema).returns(AuthWitness.schema),
490
+ requestCapabilities: z.function().args(AppCapabilitiesSchema).returns(WalletCapabilitiesSchema),
491
+ };
492
+
493
+ /**
494
+ * Creates batch schemas from the individual wallet methods.
495
+ * This allows us to define them once and derive batch schemas automatically,
496
+ * reducing duplication and ensuring consistency.
497
+ */
498
+ function createBatchSchemas<T extends Record<string, z.ZodFunction<z.ZodTuple<any, any>, z.ZodTypeAny>>>(
499
+ methodSchemas: T,
500
+ ) {
501
+ const names = Object.keys(methodSchemas) as (keyof T)[];
502
+
503
+ const namesAndArgs = names.map(name =>
504
+ z.object({
505
+ name: z.literal(name),
506
+ args: methodSchemas[name].parameters(),
507
+ }),
508
+ );
509
+
510
+ const namesAndReturns = names.map(name =>
511
+ z.object({
512
+ name: z.literal(name),
513
+ result: methodSchemas[name].returnType(),
514
+ }),
515
+ );
516
+
517
+ // Type assertion needed because discriminatedUnion expects a tuple type [T, T, ...T[]]
518
+ // but we're building the array dynamically. The runtime behavior is correct.
519
+ return {
520
+ input: z.discriminatedUnion('name', namesAndArgs as [(typeof namesAndArgs)[0], ...typeof namesAndArgs]),
521
+ output: z.discriminatedUnion('name', namesAndReturns as [(typeof namesAndReturns)[0], ...typeof namesAndReturns]),
522
+ };
523
+ }
524
+
525
+ const { input: BatchedMethodSchema, output: BatchedResultSchema } = createBatchSchemas(WalletMethodSchemas);
526
+
527
+ export { BatchedMethodSchema, BatchedResultSchema };
528
+
529
+ export const WalletSchema: ApiSchemaFor<Wallet> = {
530
+ ...WalletMethodSchemas,
303
531
  // @ts-expect-error - ApiSchemaFor cannot properly type generic methods with readonly arrays
304
- batch: z
305
- .function()
306
- .args(z.array(BatchedMethodSchema))
307
- .returns(
308
- z.array(
309
- z.discriminatedUnion('name', [
310
- z.object({ name: z.literal('registerSender'), result: schemas.AztecAddress }),
311
- z.object({ name: z.literal('registerContract'), result: ContractInstanceWithAddressSchema }),
312
- z.object({ name: z.literal('sendTx'), result: TxHash.schema }),
313
- z.object({ name: z.literal('simulateUtility'), result: UtilitySimulationResult.schema }),
314
- z.object({ name: z.literal('simulateTx'), result: TxSimulationResult.schema }),
315
- ]),
316
- ),
317
- ),
532
+ batch: z.function().args(z.array(BatchedMethodSchema)).returns(z.array(BatchedResultSchema)),
318
533
  };