@aztec-labs/aztec.js 6.0.0-nightly.20260829

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 (275) hide show
  1. package/README.md +44 -0
  2. package/dest/account/account.d.ts +44 -0
  3. package/dest/account/account.d.ts.map +1 -0
  4. package/dest/account/account.js +31 -0
  5. package/dest/account/account_contract.d.ts +49 -0
  6. package/dest/account/account_contract.d.ts.map +1 -0
  7. package/dest/account/account_contract.js +20 -0
  8. package/dest/account/index.d.ts +11 -0
  9. package/dest/account/index.d.ts.map +1 -0
  10. package/dest/account/index.js +6 -0
  11. package/dest/api/abi.d.ts +4 -0
  12. package/dest/api/abi.d.ts.map +1 -0
  13. package/dest/api/abi.js +1 -0
  14. package/dest/api/account.d.ts +5 -0
  15. package/dest/api/account.d.ts.map +1 -0
  16. package/dest/api/account.js +3 -0
  17. package/dest/api/addresses.d.ts +4 -0
  18. package/dest/api/addresses.d.ts.map +1 -0
  19. package/dest/api/addresses.js +3 -0
  20. package/dest/api/authorization.d.ts +5 -0
  21. package/dest/api/authorization.d.ts.map +1 -0
  22. package/dest/api/authorization.js +4 -0
  23. package/dest/api/block.d.ts +3 -0
  24. package/dest/api/block.d.ts.map +1 -0
  25. package/dest/api/block.js +2 -0
  26. package/dest/api/contract.d.ts +48 -0
  27. package/dest/api/contract.d.ts.map +1 -0
  28. package/dest/api/contract.js +46 -0
  29. package/dest/api/crypto.d.ts +2 -0
  30. package/dest/api/crypto.d.ts.map +1 -0
  31. package/dest/api/crypto.js +1 -0
  32. package/dest/api/deployment.d.ts +4 -0
  33. package/dest/api/deployment.d.ts.map +1 -0
  34. package/dest/api/deployment.js +3 -0
  35. package/dest/api/eth_address.d.ts +2 -0
  36. package/dest/api/eth_address.d.ts.map +1 -0
  37. package/dest/api/eth_address.js +1 -0
  38. package/dest/api/ethereum.d.ts +2 -0
  39. package/dest/api/ethereum.d.ts.map +1 -0
  40. package/dest/api/ethereum.js +1 -0
  41. package/dest/api/event_cursor.d.ts +44 -0
  42. package/dest/api/event_cursor.d.ts.map +1 -0
  43. package/dest/api/event_cursor.js +42 -0
  44. package/dest/api/events.d.ts +36 -0
  45. package/dest/api/events.d.ts.map +1 -0
  46. package/dest/api/events.js +59 -0
  47. package/dest/api/fee.d.ts +6 -0
  48. package/dest/api/fee.d.ts.map +1 -0
  49. package/dest/api/fee.js +4 -0
  50. package/dest/api/fee_testing.d.ts +2 -0
  51. package/dest/api/fee_testing.d.ts.map +1 -0
  52. package/dest/api/fee_testing.js +1 -0
  53. package/dest/api/fields.d.ts +4 -0
  54. package/dest/api/fields.d.ts.map +1 -0
  55. package/dest/api/fields.js +3 -0
  56. package/dest/api/keys.d.ts +4 -0
  57. package/dest/api/keys.d.ts.map +1 -0
  58. package/dest/api/keys.js +3 -0
  59. package/dest/api/log.d.ts +3 -0
  60. package/dest/api/log.d.ts.map +1 -0
  61. package/dest/api/log.js +2 -0
  62. package/dest/api/messaging.d.ts +3 -0
  63. package/dest/api/messaging.d.ts.map +1 -0
  64. package/dest/api/messaging.js +2 -0
  65. package/dest/api/node.d.ts +25 -0
  66. package/dest/api/node.d.ts.map +1 -0
  67. package/dest/api/node.js +22 -0
  68. package/dest/api/note.d.ts +2 -0
  69. package/dest/api/note.d.ts.map +1 -0
  70. package/dest/api/note.js +1 -0
  71. package/dest/api/protocol.d.ts +6 -0
  72. package/dest/api/protocol.d.ts.map +1 -0
  73. package/dest/api/protocol.js +5 -0
  74. package/dest/api/trees.d.ts +3 -0
  75. package/dest/api/trees.d.ts.map +1 -0
  76. package/dest/api/trees.js +2 -0
  77. package/dest/api/tx.d.ts +3 -0
  78. package/dest/api/tx.d.ts.map +1 -0
  79. package/dest/api/tx.js +1 -0
  80. package/dest/api/utils.d.ts +13 -0
  81. package/dest/api/utils.d.ts.map +1 -0
  82. package/dest/api/utils.js +12 -0
  83. package/dest/api/wallet.d.ts +8 -0
  84. package/dest/api/wallet.d.ts.map +1 -0
  85. package/dest/api/wallet.js +7 -0
  86. package/dest/authorization/call_authorization_request.d.ts +46 -0
  87. package/dest/authorization/call_authorization_request.d.ts.map +1 -0
  88. package/dest/authorization/call_authorization_request.js +72 -0
  89. package/dest/contract/base_contract_interaction.d.ts +32 -0
  90. package/dest/contract/base_contract_interaction.d.ts.map +1 -0
  91. package/dest/contract/base_contract_interaction.js +24 -0
  92. package/dest/contract/batch_call.d.ts +27 -0
  93. package/dest/contract/batch_call.d.ts.map +1 -0
  94. package/dest/contract/batch_call.js +152 -0
  95. package/dest/contract/checker.d.ts +11 -0
  96. package/dest/contract/checker.d.ts.map +1 -0
  97. package/dest/contract/checker.js +107 -0
  98. package/dest/contract/contract.d.ts +33 -0
  99. package/dest/contract/contract.d.ts.map +1 -0
  100. package/dest/contract/contract.js +36 -0
  101. package/dest/contract/contract_base.d.ts +51 -0
  102. package/dest/contract/contract_base.d.ts.map +1 -0
  103. package/dest/contract/contract_base.js +38 -0
  104. package/dest/contract/contract_function_interaction.d.ts +67 -0
  105. package/dest/contract/contract_function_interaction.d.ts.map +1 -0
  106. package/dest/contract/contract_function_interaction.js +218 -0
  107. package/dest/contract/deploy_method.d.ts +433 -0
  108. package/dest/contract/deploy_method.d.ts.map +1 -0
  109. package/dest/contract/deploy_method.js +471 -0
  110. package/dest/contract/fastforward_contract_update.d.ts +25 -0
  111. package/dest/contract/fastforward_contract_update.d.ts.map +1 -0
  112. package/dest/contract/fastforward_contract_update.js +57 -0
  113. package/dest/contract/interaction_options.d.ts +213 -0
  114. package/dest/contract/interaction_options.d.ts.map +1 -0
  115. package/dest/contract/interaction_options.js +87 -0
  116. package/dest/contract/protocol_contracts/contract-class-registry.d.ts +18 -0
  117. package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -0
  118. package/dest/contract/protocol_contracts/contract-class-registry.js +137 -0
  119. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +25 -0
  120. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -0
  121. package/dest/contract/protocol_contracts/contract-instance-registry.js +366 -0
  122. package/dest/contract/protocol_contracts/fee-juice.d.ts +24 -0
  123. package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -0
  124. package/dest/contract/protocol_contracts/fee-juice.js +383 -0
  125. package/dest/contract/wait_for_proven.d.ts +18 -0
  126. package/dest/contract/wait_for_proven.d.ts.map +1 -0
  127. package/dest/contract/wait_for_proven.js +17 -0
  128. package/dest/contract/wait_opts.d.ts +21 -0
  129. package/dest/contract/wait_opts.d.ts.map +1 -0
  130. package/dest/contract/wait_opts.js +5 -0
  131. package/dest/deployment/contract_deployer.d.ts +28 -0
  132. package/dest/deployment/contract_deployer.d.ts.map +1 -0
  133. package/dest/deployment/contract_deployer.js +35 -0
  134. package/dest/deployment/publish_class.d.ts +6 -0
  135. package/dest/deployment/publish_class.d.ts.map +1 -0
  136. package/dest/deployment/publish_class.js +17 -0
  137. package/dest/deployment/publish_instance.d.ts +10 -0
  138. package/dest/deployment/publish_instance.d.ts.map +1 -0
  139. package/dest/deployment/publish_instance.js +11 -0
  140. package/dest/ethereum/portal_manager.d.ts +146 -0
  141. package/dest/ethereum/portal_manager.d.ts.map +1 -0
  142. package/dest/ethereum/portal_manager.js +415 -0
  143. package/dest/fee/fee_juice_payment_method_with_claim.d.ts +23 -0
  144. package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -0
  145. package/dest/fee/fee_juice_payment_method_with_claim.js +46 -0
  146. package/dest/fee/fee_payment_method.d.ts +26 -0
  147. package/dest/fee/fee_payment_method.d.ts.map +1 -0
  148. package/dest/fee/fee_payment_method.js +3 -0
  149. package/dest/fee/private_fee_payment_method.d.ts +69 -0
  150. package/dest/fee/private_fee_payment_method.d.ts.map +1 -0
  151. package/dest/fee/private_fee_payment_method.js +122 -0
  152. package/dest/fee/public_fee_payment_method.d.ts +59 -0
  153. package/dest/fee/public_fee_payment_method.d.ts.map +1 -0
  154. package/dest/fee/public_fee_payment_method.js +116 -0
  155. package/dest/fee/sponsored_fee_payment.d.ts +17 -0
  156. package/dest/fee/sponsored_fee_payment.d.ts.map +1 -0
  157. package/dest/fee/sponsored_fee_payment.js +33 -0
  158. package/dest/scripts/generate_protocol_contract_types.d.ts +2 -0
  159. package/dest/scripts/generate_protocol_contract_types.d.ts.map +1 -0
  160. package/dest/scripts/generate_protocol_contract_types.js +128 -0
  161. package/dest/test/fixtures.d.ts +13 -0
  162. package/dest/test/fixtures.d.ts.map +1 -0
  163. package/dest/test/fixtures.js +185 -0
  164. package/dest/utils/abi_types.d.ts +32 -0
  165. package/dest/utils/abi_types.d.ts.map +1 -0
  166. package/dest/utils/abi_types.js +1 -0
  167. package/dest/utils/authwit.d.ts +119 -0
  168. package/dest/utils/authwit.d.ts.map +1 -0
  169. package/dest/utils/authwit.js +266 -0
  170. package/dest/utils/cross_chain.d.ts +28 -0
  171. package/dest/utils/cross_chain.d.ts.map +1 -0
  172. package/dest/utils/cross_chain.js +26 -0
  173. package/dest/utils/fee_juice.d.ts +8 -0
  174. package/dest/utils/fee_juice.d.ts.map +1 -0
  175. package/dest/utils/fee_juice.js +10 -0
  176. package/dest/utils/field_compressed_string.d.ts +17 -0
  177. package/dest/utils/field_compressed_string.d.ts.map +1 -0
  178. package/dest/utils/field_compressed_string.js +15 -0
  179. package/dest/utils/node.d.ts +24 -0
  180. package/dest/utils/node.d.ts.map +1 -0
  181. package/dest/utils/node.js +80 -0
  182. package/dest/utils/pub_key.d.ts +9 -0
  183. package/dest/utils/pub_key.d.ts.map +1 -0
  184. package/dest/utils/pub_key.js +8 -0
  185. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts +33 -0
  186. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts.map +1 -0
  187. package/dest/wallet/account_entrypoint_meta_payment_method.js +63 -0
  188. package/dest/wallet/account_manager.d.ts +73 -0
  189. package/dest/wallet/account_manager.d.ts.map +1 -0
  190. package/dest/wallet/account_manager.js +102 -0
  191. package/dest/wallet/capabilities.d.ts +456 -0
  192. package/dest/wallet/capabilities.d.ts.map +1 -0
  193. package/dest/wallet/capabilities.js +3 -0
  194. package/dest/wallet/deploy_account_method.d.ts +97 -0
  195. package/dest/wallet/deploy_account_method.d.ts.map +1 -0
  196. package/dest/wallet/deploy_account_method.js +127 -0
  197. package/dest/wallet/index.d.ts +5 -0
  198. package/dest/wallet/index.d.ts.map +1 -0
  199. package/dest/wallet/index.js +4 -0
  200. package/dest/wallet/tx_simulation_result_with_app_offset.d.ts +40 -0
  201. package/dest/wallet/tx_simulation_result_with_app_offset.d.ts.map +1 -0
  202. package/dest/wallet/tx_simulation_result_with_app_offset.js +65 -0
  203. package/dest/wallet/wallet.d.ts +1451 -0
  204. package/dest/wallet/wallet.d.ts.map +1 -0
  205. package/dest/wallet/wallet.js +430 -0
  206. package/package.json +138 -0
  207. package/src/account/account.ts +72 -0
  208. package/src/account/account_contract.ts +80 -0
  209. package/src/account/index.ts +12 -0
  210. package/src/api/README.md +7 -0
  211. package/src/api/abi.ts +42 -0
  212. package/src/api/account.ts +12 -0
  213. package/src/api/addresses.ts +3 -0
  214. package/src/api/authorization.ts +15 -0
  215. package/src/api/block.ts +2 -0
  216. package/src/api/contract.ts +86 -0
  217. package/src/api/crypto.ts +1 -0
  218. package/src/api/deployment.ts +3 -0
  219. package/src/api/eth_address.ts +1 -0
  220. package/src/api/ethereum.ts +10 -0
  221. package/src/api/event_cursor.ts +60 -0
  222. package/src/api/events.ts +79 -0
  223. package/src/api/fee.ts +5 -0
  224. package/src/api/fee_testing.ts +1 -0
  225. package/src/api/fields.ts +3 -0
  226. package/src/api/keys.ts +8 -0
  227. package/src/api/log.ts +2 -0
  228. package/src/api/messaging.ts +2 -0
  229. package/src/api/node.ts +30 -0
  230. package/src/api/note.ts +1 -0
  231. package/src/api/protocol.ts +6 -0
  232. package/src/api/trees.ts +2 -0
  233. package/src/api/tx.ts +20 -0
  234. package/src/api/utils.ts +14 -0
  235. package/src/api/wallet.ts +83 -0
  236. package/src/authorization/call_authorization_request.ts +93 -0
  237. package/src/contract/base_contract_interaction.ts +62 -0
  238. package/src/contract/batch_call.ts +188 -0
  239. package/src/contract/checker.ts +122 -0
  240. package/src/contract/contract.ts +52 -0
  241. package/src/contract/contract_base.ts +73 -0
  242. package/src/contract/contract_function_interaction.ts +297 -0
  243. package/src/contract/deploy_method.ts +877 -0
  244. package/src/contract/fastforward_contract_update.ts +71 -0
  245. package/src/contract/interaction_options.ts +301 -0
  246. package/src/contract/protocol_contracts/contract-class-registry.ts +104 -0
  247. package/src/contract/protocol_contracts/contract-instance-registry.ts +241 -0
  248. package/src/contract/protocol_contracts/fee-juice.ts +257 -0
  249. package/src/contract/wait_for_proven.ts +43 -0
  250. package/src/contract/wait_opts.ts +26 -0
  251. package/src/deployment/contract_deployer.ts +40 -0
  252. package/src/deployment/publish_class.ts +34 -0
  253. package/src/deployment/publish_instance.ts +24 -0
  254. package/src/ethereum/portal_manager.ts +539 -0
  255. package/src/fee/fee_juice_payment_method_with_claim.ts +63 -0
  256. package/src/fee/fee_payment_method.ts +26 -0
  257. package/src/fee/private_fee_payment_method.ts +145 -0
  258. package/src/fee/public_fee_payment_method.ts +145 -0
  259. package/src/fee/sponsored_fee_payment.ts +45 -0
  260. package/src/scripts/generate_protocol_contract_types.ts +160 -0
  261. package/src/test/fixtures.ts +126 -0
  262. package/src/utils/abi_types.ts +32 -0
  263. package/src/utils/authwit.ts +327 -0
  264. package/src/utils/cross_chain.ts +55 -0
  265. package/src/utils/fee_juice.ts +14 -0
  266. package/src/utils/field_compressed_string.ts +27 -0
  267. package/src/utils/node.ts +110 -0
  268. package/src/utils/pub_key.ts +12 -0
  269. package/src/wallet/account_entrypoint_meta_payment_method.ts +76 -0
  270. package/src/wallet/account_manager.ts +164 -0
  271. package/src/wallet/capabilities.ts +505 -0
  272. package/src/wallet/deploy_account_method.ts +234 -0
  273. package/src/wallet/index.ts +4 -0
  274. package/src/wallet/tx_simulation_result_with_app_offset.ts +100 -0
  275. package/src/wallet/wallet.ts +668 -0
@@ -0,0 +1,164 @@
1
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
2
+ import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
3
+ import {
4
+ CompleteAddress,
5
+ type ContractInstanceWithAddress,
6
+ getContractInstanceFromInstantiationParams,
7
+ } from '@aztec-labs/stdlib/contract';
8
+ import type { PublicKeys } from '@aztec-labs/stdlib/keys';
9
+ import { deriveKeys } from '@aztec-labs/stdlib/keys';
10
+
11
+ import type { AccountContract } from '../account/account_contract.js';
12
+ import type { Account, Salt } from '../account/index.js';
13
+ import { Contract } from '../contract/contract.js';
14
+ import { DeployAccountMethod } from './deploy_account_method.js';
15
+ import type { Wallet } from './wallet.js';
16
+
17
+ /**
18
+ * Optional overrides passed to {@link AccountManager.create}.
19
+ */
20
+ export interface AccountManagerCreateOptions {
21
+ /** Contract instantiation salt. Defaults to a random `Fr`. */
22
+ salt?: Salt;
23
+ /**
24
+ * Commitment to the contract's immutable storage values. Folded into the salted initialization
25
+ * hash, so a non-zero value affects the derived address. Defaults to `Fr.ZERO`.
26
+ */
27
+ immutablesHash?: Fr;
28
+ /** Address recorded as the instance deployer. Defaults to `AztecAddress.ZERO`. */
29
+ deployer?: AztecAddress;
30
+ }
31
+
32
+ /**
33
+ * Manages a user account. Provides methods for calculating the account's address and other related data,
34
+ * plus a helper to return a preconfigured deploy method.
35
+ */
36
+ export class AccountManager {
37
+ private constructor(
38
+ private wallet: Wallet,
39
+ private secretKey: Fr,
40
+ private accountContract: AccountContract,
41
+ private instance: ContractInstanceWithAddress,
42
+ ) {}
43
+
44
+ static async create(
45
+ wallet: Wallet,
46
+ secretKey: Fr,
47
+ accountContract: AccountContract,
48
+ opts?: AccountManagerCreateOptions,
49
+ ) {
50
+ const { publicKeys } = await deriveKeys(secretKey);
51
+ const salt = opts?.salt !== undefined ? new Fr(opts.salt) : Fr.random();
52
+
53
+ const { constructorName, constructorArgs } = (await accountContract.getInitializationFunctionAndArgs()) ?? {
54
+ constructorName: undefined,
55
+ constructorArgs: undefined,
56
+ };
57
+
58
+ const artifact = await accountContract.getContractArtifact();
59
+ const instance = await getContractInstanceFromInstantiationParams(artifact, {
60
+ constructorArtifact: constructorName,
61
+ constructorArgs,
62
+ salt,
63
+ publicKeys,
64
+ deployer: opts?.deployer,
65
+ immutablesHash: opts?.immutablesHash ?? (await accountContract.getImmutablesHash()),
66
+ });
67
+
68
+ return new AccountManager(wallet, secretKey, accountContract, instance);
69
+ }
70
+
71
+ protected getPublicKeys(): PublicKeys {
72
+ return this.instance.publicKeys;
73
+ }
74
+
75
+ protected getPublicKeysHash(): Promise<Fr> {
76
+ return this.getPublicKeys().hash();
77
+ }
78
+
79
+ /**
80
+ * Gets the calculated complete address associated with this account.
81
+ * Does not require the account to have been published for public execution.
82
+ * @returns The address, partial address, and encryption public key.
83
+ */
84
+ public getCompleteAddress(): Promise<CompleteAddress> {
85
+ return CompleteAddress.fromSecretKeyAndInstance(this.secretKey, this.instance);
86
+ }
87
+
88
+ /**
89
+ * Returns the secret key used to derive the rest of the privacy keys for this contract
90
+ */
91
+ public getSecretKey() {
92
+ return this.secretKey;
93
+ }
94
+
95
+ get address(): AztecAddress {
96
+ return this.instance.address;
97
+ }
98
+
99
+ /**
100
+ * Returns the contract instance definition associated with this account.
101
+ * Does not require the account to have been published for public execution.
102
+ * @returns ContractInstance instance.
103
+ */
104
+ public getInstance(): ContractInstanceWithAddress {
105
+ return this.instance;
106
+ }
107
+
108
+ /**
109
+ * Returns the account (the transaction signer) backed by this account contract. Use it to build and authorize
110
+ * transactions from this account.
111
+ */
112
+ public async getAccount(): Promise<Account> {
113
+ const completeAddress = await this.getCompleteAddress();
114
+ return this.accountContract.getAccount(completeAddress);
115
+ }
116
+
117
+ /**
118
+ * Returns the account contract that backs this account.
119
+ * @returns The account contract
120
+ */
121
+ getAccountContract(): AccountContract {
122
+ return this.accountContract;
123
+ }
124
+
125
+ /**
126
+ * Returns a preconfigured deploy method that contains all the necessary function
127
+ * calls to deploy the account contract.
128
+ */
129
+ public async getDeployMethod(): Promise<DeployAccountMethod> {
130
+ const artifact = await this.accountContract.getContractArtifact();
131
+
132
+ if (!(await this.hasInitializer())) {
133
+ // TODO(https://github.com/AztecProtocol/aztec-packages/issues/15576):
134
+ // there should be a path which enables an account contract's class & instance to be published,
135
+ // even if the account contract doesn't have an initializer function. This should not throw.
136
+ throw new Error(`Account contract ${artifact.name} does not have an initializer function to call.`);
137
+ }
138
+
139
+ const { constructorName, constructorArgs } = (await this.accountContract.getInitializationFunctionAndArgs()) ?? {
140
+ constructorName: undefined,
141
+ constructorArgs: undefined,
142
+ };
143
+
144
+ const account = await this.getAccount();
145
+ return new DeployAccountMethod(
146
+ this.getPublicKeys(),
147
+ this.wallet,
148
+ artifact,
149
+ instance => Contract.at(instance.address, artifact, this.wallet),
150
+ this.instance.salt,
151
+ this.instance.immutablesHash,
152
+ account,
153
+ constructorArgs,
154
+ constructorName,
155
+ );
156
+ }
157
+
158
+ /**
159
+ * Returns whether this account contract has an initializer function.
160
+ */
161
+ public async hasInitializer() {
162
+ return (await this.accountContract.getInitializationFunctionAndArgs()) !== undefined;
163
+ }
164
+ }
@@ -0,0 +1,505 @@
1
+ import type { Fr } from '@aztec-labs/foundation/curves/bn254';
2
+ import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
3
+
4
+ import type { Aliased } from './wallet.js';
5
+
6
+ /**
7
+ * Current capability manifest version.
8
+ */
9
+ export const CAPABILITY_VERSION = '1.0' as const;
10
+
11
+ /**
12
+ * Pattern for matching contract functions with wildcards.
13
+ *
14
+ * Used in simulation and transaction capabilities to specify which
15
+ * contract functions are allowed.
16
+ *
17
+ * @example
18
+ * // Allow any function on a specific contract
19
+ * \{ contract: ammAddress, function: '*' \}
20
+ *
21
+ * @example
22
+ * // Allow only 'swap' function on a specific contract
23
+ * \{ contract: ammAddress, function: 'swap' \}
24
+ *
25
+ * @example
26
+ * // Allow 'transfer' on any contract
27
+ * \{ contract: '*', function: 'transfer' \}
28
+ */
29
+ export interface ContractFunctionPattern {
30
+ /** Contract address or '*' for any contract */
31
+ contract: AztecAddress | '*';
32
+
33
+ /** Function name or '*' for any function */
34
+ function: string;
35
+
36
+ /**
37
+ * Additional addresses whose private state and keys are accessible
38
+ * when calling this function, beyond the sender's.
39
+ * - undefined: No additional scopes allowed
40
+ * - AztecAddress[]: Only these specific addresses allowed as additional scopes
41
+ * - '*': All known address allowed as an additional scope
42
+ */
43
+ additionalScopes?: AztecAddress[] | '*';
44
+ }
45
+
46
+ /**
47
+ * Account access capability - grants access to user accounts.
48
+ *
49
+ * Maps to wallet methods:
50
+ * - getAccounts (when canGet: true)
51
+ * - createAuthWit (when canCreateAuthWit: true)
52
+ *
53
+ * The wallet decides which accounts to reveal to the app.
54
+ * Apps don't specify which accounts they want - they just request
55
+ * the capability and the wallet shows them the available accounts.
56
+ */
57
+ export interface AccountsCapability {
58
+ /** Discriminator for capability type */
59
+ type: 'accounts';
60
+
61
+ /** Can get accounts from wallet. Maps to: getAccounts */
62
+ canGet?: boolean;
63
+
64
+ /** Can create auth witnesses for accounts. Maps to: createAuthWit */
65
+ canCreateAuthWit?: boolean;
66
+ }
67
+
68
+ /**
69
+ * Granted account access capability.
70
+ *
71
+ * Extends the request with specific accounts that were granted by the wallet.
72
+ */
73
+ export interface GrantedAccountsCapability extends AccountsCapability {
74
+ /** Specific accounts granted by the wallet with their aliases. The wallet adds this when granting the capability. */
75
+ accounts: Aliased<AztecAddress>[];
76
+ }
77
+
78
+ /**
79
+ * Contract interaction capability - for registering and querying contracts.
80
+ *
81
+ * Maps to wallet methods:
82
+ * - registerContract (when canRegister: true)
83
+ * - getContractMetadata (when canGetMetadata: true)
84
+ *
85
+ * Matching is done by contract address, not class ID. This allows updating
86
+ * existing contracts with new artifacts (e.g., when contract is upgraded
87
+ * to a new contractClassId onchain).
88
+ *
89
+ * Note: For querying contract class metadata, use ContractClassesCapability instead.
90
+ *
91
+ * @example
92
+ * // Register and query specific contracts
93
+ * \{
94
+ * type: 'contracts',
95
+ * contracts: [ammAddress, tokenAddress],
96
+ * canRegister: true,
97
+ * canGetMetadata: true
98
+ * \}
99
+ *
100
+ * @example
101
+ * // Query any contract (read-only)
102
+ * \{
103
+ * type: 'contracts',
104
+ * contracts: '*',
105
+ * canGetMetadata: true
106
+ * \}
107
+ */
108
+ export interface ContractsCapability {
109
+ /** Discriminator for capability type */
110
+ type: 'contracts';
111
+
112
+ /**
113
+ * Which contracts this applies to:
114
+ * - '*': Any contract address
115
+ * - AztecAddress[]: Specific contract addresses
116
+ */
117
+ contracts: '*' | AztecAddress[];
118
+
119
+ /**
120
+ * Can register contracts and update existing registrations.
121
+ * Maps to: registerContract
122
+ *
123
+ * When true, allows:
124
+ * - Registering new contract instances at specified addresses
125
+ * - Re-registering existing contracts with updated artifacts (e.g., after upgrade)
126
+ */
127
+ canRegister?: boolean;
128
+
129
+ /** Can query contract metadata. Maps to: getContractMetadata */
130
+ canGetMetadata?: boolean;
131
+ }
132
+
133
+ /**
134
+ * Granted contract interaction capability.
135
+ *
136
+ * The wallet may reduce the scope (e.g., from '*' to specific addresses).
137
+ */
138
+ export interface GrantedContractsCapability extends ContractsCapability {}
139
+
140
+ /**
141
+ * Contract class capability - for querying contract class metadata and registering contract classes.
142
+ *
143
+ * Maps to wallet methods:
144
+ * - getContractClassMetadata (when canGetMetadata: true)
145
+ * - registerContractClass (when canRegister: true)
146
+ *
147
+ * Contract classes are identified by their class ID (Fr), not by contract address.
148
+ * Multiple contract instances can share the same class. This capability grants
149
+ * permission to query metadata for, and register, specific contract classes.
150
+ *
151
+ * Apps typically acquire this permission automatically when registering a contract
152
+ * with an artifact (the wallet auto-grants permission for that contract's class ID).
153
+ *
154
+ * @example
155
+ * // Register and query a specific contract class
156
+ * \{
157
+ * type: 'contractClasses',
158
+ * classes: [classId1],
159
+ * canRegister: true,
160
+ * canGetMetadata: true
161
+ * \}
162
+ *
163
+ * @example
164
+ * // Query any contract class (wildcard)
165
+ * \{
166
+ * type: 'contractClasses',
167
+ * classes: '*',
168
+ * canGetMetadata: true
169
+ * \}
170
+ */
171
+ export interface ContractClassesCapability {
172
+ /** Discriminator for capability type */
173
+ type: 'contractClasses';
174
+
175
+ /**
176
+ * Which contract classes this applies to:
177
+ * - '*': Any contract class ID
178
+ * - Fr[]: Specific contract class IDs
179
+ */
180
+ classes: '*' | Fr[];
181
+
182
+ /** Can register a contract class artifact in the local PXE. Maps to: registerContractClass */
183
+ canRegister?: boolean;
184
+
185
+ /** Can query contract class metadata. Maps to: getContractClassMetadata */
186
+ canGetMetadata: boolean;
187
+ }
188
+
189
+ /**
190
+ * Granted contract class capability.
191
+ *
192
+ * The wallet may reduce the scope (e.g., from '*' to specific class IDs).
193
+ */
194
+ export interface GrantedContractClassesCapability extends ContractClassesCapability {}
195
+
196
+ /**
197
+ * Transaction simulation capability - for simulating transactions and executing utilities.
198
+ *
199
+ * Maps to wallet methods:
200
+ * - simulateTx (when transactions scope specified)
201
+ * - executeUtility (when utilities scope specified)
202
+ * - profileTx (when transactions scope specified)
203
+ *
204
+ * @example
205
+ * // Simulate any transaction on specific contracts
206
+ * \{
207
+ * type: 'simulation',
208
+ * transactions: \{
209
+ * scope: [
210
+ * \{ contract: ammAddress, function: '*' \},
211
+ * \{ contract: tokenAddress, function: 'transfer' \}
212
+ * ]
213
+ * \}
214
+ * \}
215
+ *
216
+ * @example
217
+ * // Simulate any transaction and execute any utility call
218
+ * \{
219
+ * type: 'simulation',
220
+ * transactions: \{ scope: '*' \},
221
+ * utilities: \{ scope: '*' \}
222
+ * \}
223
+ */
224
+ export interface SimulationCapability {
225
+ /** Discriminator for capability type */
226
+ type: 'simulation';
227
+
228
+ /** Transaction simulation scope. Maps to: simulateTx, profileTx */
229
+ transactions?: {
230
+ /**
231
+ * Which contracts/functions to allow:
232
+ * - '*': Any transaction
233
+ * - ContractFunctionPattern[]: Specific contract functions
234
+ */
235
+ scope: '*' | ContractFunctionPattern[];
236
+ };
237
+
238
+ /** Utility execution scope (unconstrained calls). Maps to: executeUtility */
239
+ utilities?: {
240
+ /**
241
+ * Which contracts/functions to allow:
242
+ * - '*': Any utility call
243
+ * - ContractFunctionPattern[]: Specific contract functions
244
+ */
245
+ scope: '*' | ContractFunctionPattern[];
246
+ };
247
+ }
248
+
249
+ /**
250
+ * Granted transaction simulation capability.
251
+ *
252
+ * The wallet may reduce the scope (e.g., from '*' to specific patterns).
253
+ */
254
+ export interface GrantedSimulationCapability extends SimulationCapability {}
255
+
256
+ /**
257
+ * Transaction execution capability - for sending transactions.
258
+ *
259
+ * Maps to wallet methods:
260
+ * - sendTx
261
+ *
262
+ * Policy enforcement (rate limits, spending limits) should be handled
263
+ * at the contract level in Aztec, not at the wallet level.
264
+ *
265
+ * @example
266
+ * // Send specific transactions with approval
267
+ * \{
268
+ * type: 'transaction',
269
+ * scope: [
270
+ * \{ contract: ammAddress, function: 'swap' \},
271
+ * \{ contract: ammAddress, function: 'addLiquidity' \}
272
+ * ]
273
+ * \}
274
+ *
275
+ * @example
276
+ * // Send any transaction
277
+ * \{
278
+ * type: 'transaction',
279
+ * scope: '*'
280
+ * \}
281
+ */
282
+ export interface TransactionCapability {
283
+ /** Discriminator for capability type */
284
+ type: 'transaction';
285
+
286
+ /**
287
+ * Which contracts/functions to allow:
288
+ * - '*': Any transaction
289
+ * - ContractFunctionPattern[]: Specific patterns
290
+ */
291
+ scope: '*' | ContractFunctionPattern[];
292
+ }
293
+
294
+ /**
295
+ * Granted transaction execution capability.
296
+ *
297
+ * The wallet may reduce the scope (e.g., from '*' to specific patterns).
298
+ */
299
+ export interface GrantedTransactionCapability extends TransactionCapability {}
300
+
301
+ /**
302
+ * Data access capability - for querying private data.
303
+ *
304
+ * Maps to wallet methods:
305
+ * - getAddressBook (when addressBook: true)
306
+ * - getPrivateEvents (when privateEvents specified)
307
+ *
308
+ * @example
309
+ * // Access address book and events from specific contract
310
+ * \{
311
+ * type: 'data',
312
+ * addressBook: true,
313
+ * privateEvents: \{
314
+ * contracts: [ammAddress],
315
+ * events: ['Swap', 'LiquidityAdded']
316
+ * \}
317
+ * \}
318
+ *
319
+ * @example
320
+ * // Access all events from any contract
321
+ * \{
322
+ * type: 'data',
323
+ * privateEvents: \{
324
+ * contracts: '*',
325
+ * events: '*'
326
+ * \}
327
+ * \}
328
+ */
329
+ export interface DataCapability {
330
+ /** Discriminator for capability type */
331
+ type: 'data';
332
+
333
+ /** Access to address book. Maps to: getAddressBook */
334
+ addressBook?: boolean;
335
+
336
+ /** Access to private events. Maps to: getPrivateEvents */
337
+ privateEvents?: {
338
+ /**
339
+ * Which contracts to allow event queries from:
340
+ * - '*': Any contract
341
+ * - AztecAddress[]: Specific contracts
342
+ */
343
+ contracts: '*' | AztecAddress[];
344
+ };
345
+ }
346
+
347
+ /**
348
+ * Granted data access capability.
349
+ *
350
+ * The wallet may reduce the scope (e.g., from '*' to specific contracts).
351
+ */
352
+ export interface GrantedDataCapability extends DataCapability {}
353
+
354
+ /**
355
+ * Union type of all capability scopes (app request).
356
+ *
357
+ * Capabilities group wallet operations by their security sensitivity
358
+ * and functional cohesion, making permission requests understandable
359
+ * to users.
360
+ */
361
+ export type Capability =
362
+ | AccountsCapability
363
+ | ContractsCapability
364
+ | ContractClassesCapability
365
+ | SimulationCapability
366
+ | TransactionCapability
367
+ | DataCapability;
368
+
369
+ /**
370
+ * Union type of all granted capabilities (wallet response).
371
+ *
372
+ * The wallet may augment capabilities with additional information:
373
+ * - AccountsCapability: adds specific accounts granted
374
+ * - Other capabilities: may reduce scope (e.g., '*' to specific addresses)
375
+ */
376
+ export type GrantedCapability =
377
+ | GrantedAccountsCapability
378
+ | GrantedContractsCapability
379
+ | GrantedContractClassesCapability
380
+ | GrantedSimulationCapability
381
+ | GrantedTransactionCapability
382
+ | GrantedDataCapability;
383
+
384
+ /**
385
+ * Application capability manifest.
386
+ *
387
+ * Sent by dApp to declare all operations it needs. This reduces authorization
388
+ * friction from multiple dialogs to a single comprehensive permission request.
389
+ *
390
+ * @example
391
+ * // DEX application manifest
392
+ * const manifest: AppCapabilities = \{
393
+ * version: CAPABILITY_VERSION,
394
+ * metadata: \{
395
+ * name: 'MyDEX',
396
+ * version: '1.0.0',
397
+ * description: 'Decentralized exchange for private token swaps',
398
+ * url: 'https://example.com',
399
+ * icon: 'https://example.com/icon.png'
400
+ * \},
401
+ * capabilities: [
402
+ * \{
403
+ * type: 'accounts',
404
+ * canGet: true,
405
+ * canCreateAuthWit: true
406
+ * \},
407
+ * \{
408
+ * type: 'contracts',
409
+ * contracts: [ammAddress, tokenAAddress, tokenBAddress],
410
+ * canRegister: true,
411
+ * canGetMetadata: true
412
+ * \},
413
+ * \{
414
+ * type: 'simulation',
415
+ * transactions: \{
416
+ * scope: [\{ contract: ammAddress, function: '*' \}]
417
+ * \}
418
+ * \},
419
+ * \{
420
+ * type: 'transaction',
421
+ * scope: [\{ contract: ammAddress, function: 'swap' \}]
422
+ * \}
423
+ * ]
424
+ * \};
425
+ */
426
+ export interface AppCapabilities {
427
+ /**
428
+ * Manifest version for forward compatibility.
429
+ * Currently only '1.0' is supported.
430
+ */
431
+ version: typeof CAPABILITY_VERSION;
432
+
433
+ /** Application metadata for display in authorization dialogs. */
434
+ metadata: {
435
+ /** Human-readable app name */
436
+ name: string;
437
+
438
+ /** App version */
439
+ version: string;
440
+
441
+ /** Optional description of what the app does */
442
+ description?: string;
443
+
444
+ /** Optional website URL */
445
+ url?: string;
446
+
447
+ /** Optional icon URL or data URI */
448
+ icon?: string;
449
+ };
450
+
451
+ /**
452
+ * Requested capabilities grouped by scope.
453
+ */
454
+ capabilities: Capability[];
455
+ }
456
+
457
+ /**
458
+ * Wallet capability response.
459
+ *
460
+ * Returned by wallet after user reviews and approves/denies the capability request.
461
+ *
462
+ * The wallet can modify requested capabilities:
463
+ * - Reduce scope (e.g., restrict to specific contracts instead of '*')
464
+ * - Add information (e.g., specify which accounts are granted)
465
+ * - Deny capabilities (by omitting them from the `granted` array)
466
+ *
467
+ * @example
468
+ * // App requests
469
+ * const manifest: AppCapabilities = \{
470
+ * version: '1.0',
471
+ * metadata: \{ name: 'MyDApp', version: '1.0.0' \},
472
+ * capabilities: [
473
+ * \{ type: 'accounts', canGet: true \},
474
+ * \{ type: 'contracts', contracts: '*', canRegister: true \}
475
+ * ]
476
+ * \};
477
+ *
478
+ * // Wallet responds with specific accounts and restricted contracts
479
+ * const response = await wallet.requestCapabilities(manifest);
480
+ * console.log(response.granted);
481
+ * // [
482
+ * // \{ type: 'accounts', canGet: true, accounts: [addr1, addr2] \},
483
+ * // \{ type: 'contracts', contracts: [specificContract], canRegister: true \}
484
+ * // ]
485
+ */
486
+ export interface WalletCapabilities {
487
+ /** Response version for forward compatibility. */
488
+ version: typeof CAPABILITY_VERSION;
489
+
490
+ /**
491
+ * Capabilities granted by the wallet.
492
+ * Capabilities not in this array were implicitly denied.
493
+ * Empty array means the user denied all capabilities.
494
+ */
495
+ granted: GrantedCapability[];
496
+
497
+ /** Wallet implementation details. */
498
+ wallet: {
499
+ /** Wallet name/implementation */
500
+ name: string;
501
+
502
+ /** Wallet version */
503
+ version: string;
504
+ };
505
+ }