@aztec/aztec.js 0.0.1-commit.e6bd8901 → 0.0.1-commit.f146247c

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 (44) hide show
  1. package/dest/api/keys.d.ts +1 -1
  2. package/dest/api/keys.js +1 -1
  3. package/dest/api/wallet.d.ts +3 -2
  4. package/dest/api/wallet.d.ts.map +1 -1
  5. package/dest/api/wallet.js +2 -1
  6. package/dest/contract/protocol_contracts/auth-registry.d.ts +1 -10
  7. package/dest/contract/protocol_contracts/auth-registry.d.ts.map +1 -1
  8. package/dest/contract/protocol_contracts/auth-registry.js +61 -466
  9. package/dest/contract/protocol_contracts/contract-class-registry.d.ts +2 -11
  10. package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -1
  11. package/dest/contract/protocol_contracts/contract-class-registry.js +10 -409
  12. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +2 -11
  13. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -1
  14. package/dest/contract/protocol_contracts/contract-instance-registry.js +80 -473
  15. package/dest/contract/protocol_contracts/fee-juice.d.ts +1 -10
  16. package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -1
  17. package/dest/contract/protocol_contracts/fee-juice.js +0 -401
  18. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts +1 -1
  19. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts.map +1 -1
  20. package/dest/contract/protocol_contracts/multi-call-entrypoint.js +12 -0
  21. package/dest/contract/protocol_contracts/public-checks.d.ts +1 -1
  22. package/dest/contract/protocol_contracts/public-checks.d.ts.map +1 -1
  23. package/dest/contract/protocol_contracts/public-checks.js +12 -8
  24. package/dest/wallet/capabilities.d.ts +444 -0
  25. package/dest/wallet/capabilities.d.ts.map +1 -0
  26. package/dest/wallet/capabilities.js +3 -0
  27. package/dest/wallet/index.d.ts +2 -1
  28. package/dest/wallet/index.d.ts.map +1 -1
  29. package/dest/wallet/index.js +1 -0
  30. package/dest/wallet/wallet.d.ts +1307 -14
  31. package/dest/wallet/wallet.d.ts.map +1 -1
  32. package/dest/wallet/wallet.js +120 -1
  33. package/package.json +9 -9
  34. package/src/api/keys.ts +2 -2
  35. package/src/api/wallet.ts +38 -0
  36. package/src/contract/protocol_contracts/auth-registry.ts +37 -231
  37. package/src/contract/protocol_contracts/contract-class-registry.ts +3 -195
  38. package/src/contract/protocol_contracts/contract-instance-registry.ts +34 -225
  39. package/src/contract/protocol_contracts/fee-juice.ts +0 -193
  40. package/src/contract/protocol_contracts/multi-call-entrypoint.ts +3 -0
  41. package/src/contract/protocol_contracts/public-checks.ts +3 -2
  42. package/src/wallet/capabilities.ts +491 -0
  43. package/src/wallet/index.ts +1 -0
  44. package/src/wallet/wallet.ts +117 -1
@@ -0,0 +1,491 @@
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
+ import type { AztecAddress } from '@aztec/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
+ /**
38
+ * Account access capability - grants access to user accounts.
39
+ *
40
+ * Maps to wallet methods:
41
+ * - getAccounts (when canGet: true)
42
+ * - createAuthWit (when canCreateAuthWit: true)
43
+ *
44
+ * The wallet decides which accounts to reveal to the app.
45
+ * Apps don't specify which accounts they want - they just request
46
+ * the capability and the wallet shows them the available accounts.
47
+ */
48
+ export interface AccountsCapability {
49
+ /** Discriminator for capability type */
50
+ type: 'accounts';
51
+
52
+ /** Can get accounts from wallet. Maps to: getAccounts */
53
+ canGet?: boolean;
54
+
55
+ /** Can create auth witnesses for accounts. Maps to: createAuthWit */
56
+ canCreateAuthWit?: boolean;
57
+ }
58
+
59
+ /**
60
+ * Granted account access capability.
61
+ *
62
+ * Extends the request with specific accounts that were granted by the wallet.
63
+ */
64
+ export interface GrantedAccountsCapability extends AccountsCapability {
65
+ /** Specific accounts granted by the wallet with their aliases. The wallet adds this when granting the capability. */
66
+ accounts: Aliased<AztecAddress>[];
67
+ }
68
+
69
+ /**
70
+ * Contract interaction capability - for registering and querying contracts.
71
+ *
72
+ * Maps to wallet methods:
73
+ * - registerContract (when canRegister: true)
74
+ * - getContractMetadata (when canGetMetadata: true)
75
+ *
76
+ * Matching is done by contract address, not class ID. This allows updating
77
+ * existing contracts with new artifacts (e.g., when contract is upgraded
78
+ * to a new contractClassId on-chain).
79
+ *
80
+ * Note: For querying contract class metadata, use ContractClassesCapability instead.
81
+ *
82
+ * @example
83
+ * // Register and query specific contracts
84
+ * \{
85
+ * type: 'contracts',
86
+ * contracts: [ammAddress, tokenAddress],
87
+ * canRegister: true,
88
+ * canGetMetadata: true
89
+ * \}
90
+ *
91
+ * @example
92
+ * // Query any contract (read-only)
93
+ * \{
94
+ * type: 'contracts',
95
+ * contracts: '*',
96
+ * canGetMetadata: true
97
+ * \}
98
+ */
99
+ export interface ContractsCapability {
100
+ /** Discriminator for capability type */
101
+ type: 'contracts';
102
+
103
+ /**
104
+ * Which contracts this applies to:
105
+ * - '*': Any contract address
106
+ * - AztecAddress[]: Specific contract addresses
107
+ */
108
+ contracts: '*' | AztecAddress[];
109
+
110
+ /**
111
+ * Can register contracts and update existing registrations.
112
+ * Maps to: registerContract
113
+ *
114
+ * When true, allows:
115
+ * - Registering new contract instances at specified addresses
116
+ * - Re-registering existing contracts with updated artifacts (e.g., after upgrade)
117
+ */
118
+ canRegister?: boolean;
119
+
120
+ /** Can query contract metadata. Maps to: getContractMetadata */
121
+ canGetMetadata?: boolean;
122
+ }
123
+
124
+ /**
125
+ * Granted contract interaction capability.
126
+ *
127
+ * The wallet may reduce the scope (e.g., from '*' to specific addresses).
128
+ */
129
+ export interface GrantedContractsCapability extends ContractsCapability {}
130
+
131
+ /**
132
+ * Contract class capability - for querying contract class metadata.
133
+ *
134
+ * Maps to wallet methods:
135
+ * - getContractClassMetadata
136
+ *
137
+ * Contract classes are identified by their class ID (Fr), not by contract address.
138
+ * Multiple contract instances can share the same class. This capability grants
139
+ * permission to query metadata for specific contract classes.
140
+ *
141
+ * Apps typically acquire this permission automatically when registering a contract
142
+ * with an artifact (the wallet auto-grants permission for that contract's class ID).
143
+ *
144
+ * @example
145
+ * // Query specific contract classes
146
+ * \{
147
+ * type: 'contractClasses',
148
+ * classes: [classId1, classId2],
149
+ * canGetMetadata: true
150
+ * \}
151
+ *
152
+ * @example
153
+ * // Query any contract class (wildcard)
154
+ * \{
155
+ * type: 'contractClasses',
156
+ * classes: '*',
157
+ * canGetMetadata: true
158
+ * \}
159
+ */
160
+ export interface ContractClassesCapability {
161
+ /** Discriminator for capability type */
162
+ type: 'contractClasses';
163
+
164
+ /**
165
+ * Which contract classes this applies to:
166
+ * - '*': Any contract class ID
167
+ * - Fr[]: Specific contract class IDs
168
+ */
169
+ classes: '*' | Fr[];
170
+
171
+ /** Can query contract class metadata. Maps to: getContractClassMetadata */
172
+ canGetMetadata: boolean;
173
+ }
174
+
175
+ /**
176
+ * Granted contract class capability.
177
+ *
178
+ * The wallet may reduce the scope (e.g., from '*' to specific class IDs).
179
+ */
180
+ export interface GrantedContractClassesCapability extends ContractClassesCapability {}
181
+
182
+ /**
183
+ * Transaction simulation capability - for simulating transactions and utilities.
184
+ *
185
+ * Maps to wallet methods:
186
+ * - simulateTx (when transactions scope specified)
187
+ * - simulateUtility (when utilities scope specified)
188
+ * - profileTx (when transactions scope specified)
189
+ *
190
+ * @example
191
+ * // Simulate any transaction on specific contracts
192
+ * \{
193
+ * type: 'simulation',
194
+ * transactions: \{
195
+ * scope: [
196
+ * \{ contract: ammAddress, function: '*' \},
197
+ * \{ contract: tokenAddress, function: 'transfer' \}
198
+ * ]
199
+ * \}
200
+ * \}
201
+ *
202
+ * @example
203
+ * // Simulate any transaction and utility call
204
+ * \{
205
+ * type: 'simulation',
206
+ * transactions: \{ scope: '*' \},
207
+ * utilities: \{ scope: '*' \}
208
+ * \}
209
+ */
210
+ export interface SimulationCapability {
211
+ /** Discriminator for capability type */
212
+ type: 'simulation';
213
+
214
+ /** Transaction simulation scope. Maps to: simulateTx, profileTx */
215
+ transactions?: {
216
+ /**
217
+ * Which contracts/functions to allow:
218
+ * - '*': Any transaction
219
+ * - ContractFunctionPattern[]: Specific contract functions
220
+ */
221
+ scope: '*' | ContractFunctionPattern[];
222
+ };
223
+
224
+ /** Utility simulation scope (unconstrained calls). Maps to: simulateUtility */
225
+ utilities?: {
226
+ /**
227
+ * Which contracts/functions to allow:
228
+ * - '*': Any utility call
229
+ * - ContractFunctionPattern[]: Specific contract functions
230
+ */
231
+ scope: '*' | ContractFunctionPattern[];
232
+ };
233
+ }
234
+
235
+ /**
236
+ * Granted transaction simulation capability.
237
+ *
238
+ * The wallet may reduce the scope (e.g., from '*' to specific patterns).
239
+ */
240
+ export interface GrantedSimulationCapability extends SimulationCapability {}
241
+
242
+ /**
243
+ * Transaction execution capability - for sending transactions.
244
+ *
245
+ * Maps to wallet methods:
246
+ * - sendTx
247
+ *
248
+ * Policy enforcement (rate limits, spending limits) should be handled
249
+ * at the contract level in Aztec, not at the wallet level.
250
+ *
251
+ * @example
252
+ * // Send specific transactions with approval
253
+ * \{
254
+ * type: 'transaction',
255
+ * scope: [
256
+ * \{ contract: ammAddress, function: 'swap' \},
257
+ * \{ contract: ammAddress, function: 'addLiquidity' \}
258
+ * ]
259
+ * \}
260
+ *
261
+ * @example
262
+ * // Send any transaction
263
+ * \{
264
+ * type: 'transaction',
265
+ * scope: '*'
266
+ * \}
267
+ */
268
+ export interface TransactionCapability {
269
+ /** Discriminator for capability type */
270
+ type: 'transaction';
271
+
272
+ /**
273
+ * Which contracts/functions to allow:
274
+ * - '*': Any transaction
275
+ * - ContractFunctionPattern[]: Specific patterns
276
+ */
277
+ scope: '*' | ContractFunctionPattern[];
278
+ }
279
+
280
+ /**
281
+ * Granted transaction execution capability.
282
+ *
283
+ * The wallet may reduce the scope (e.g., from '*' to specific patterns).
284
+ */
285
+ export interface GrantedTransactionCapability extends TransactionCapability {}
286
+
287
+ /**
288
+ * Data access capability - for querying private data.
289
+ *
290
+ * Maps to wallet methods:
291
+ * - getAddressBook (when addressBook: true)
292
+ * - getPrivateEvents (when privateEvents specified)
293
+ *
294
+ * @example
295
+ * // Access address book and events from specific contract
296
+ * \{
297
+ * type: 'data',
298
+ * addressBook: true,
299
+ * privateEvents: \{
300
+ * contracts: [ammAddress],
301
+ * events: ['Swap', 'LiquidityAdded']
302
+ * \}
303
+ * \}
304
+ *
305
+ * @example
306
+ * // Access all events from any contract
307
+ * \{
308
+ * type: 'data',
309
+ * privateEvents: \{
310
+ * contracts: '*',
311
+ * events: '*'
312
+ * \}
313
+ * \}
314
+ */
315
+ export interface DataCapability {
316
+ /** Discriminator for capability type */
317
+ type: 'data';
318
+
319
+ /** Access to address book. Maps to: getAddressBook */
320
+ addressBook?: boolean;
321
+
322
+ /** Access to private events. Maps to: getPrivateEvents */
323
+ privateEvents?: {
324
+ /**
325
+ * Which contracts to allow event queries from:
326
+ * - '*': Any contract
327
+ * - AztecAddress[]: Specific contracts
328
+ */
329
+ contracts: '*' | AztecAddress[];
330
+ };
331
+ }
332
+
333
+ /**
334
+ * Granted data access capability.
335
+ *
336
+ * The wallet may reduce the scope (e.g., from '*' to specific contracts).
337
+ */
338
+ export interface GrantedDataCapability extends DataCapability {}
339
+
340
+ /**
341
+ * Union type of all capability scopes (app request).
342
+ *
343
+ * Capabilities group wallet operations by their security sensitivity
344
+ * and functional cohesion, making permission requests understandable
345
+ * to users.
346
+ */
347
+ export type Capability =
348
+ | AccountsCapability
349
+ | ContractsCapability
350
+ | ContractClassesCapability
351
+ | SimulationCapability
352
+ | TransactionCapability
353
+ | DataCapability;
354
+
355
+ /**
356
+ * Union type of all granted capabilities (wallet response).
357
+ *
358
+ * The wallet may augment capabilities with additional information:
359
+ * - AccountsCapability: adds specific accounts granted
360
+ * - Other capabilities: may reduce scope (e.g., '*' to specific addresses)
361
+ */
362
+ export type GrantedCapability =
363
+ | GrantedAccountsCapability
364
+ | GrantedContractsCapability
365
+ | GrantedContractClassesCapability
366
+ | GrantedSimulationCapability
367
+ | GrantedTransactionCapability
368
+ | GrantedDataCapability;
369
+
370
+ /**
371
+ * Application capability manifest.
372
+ *
373
+ * Sent by dApp to declare all operations it needs. This reduces authorization
374
+ * friction from multiple dialogs to a single comprehensive permission request.
375
+ *
376
+ * @example
377
+ * // DEX application manifest
378
+ * const manifest: AppCapabilities = \{
379
+ * version: CAPABILITY_VERSION,
380
+ * metadata: \{
381
+ * name: 'MyDEX',
382
+ * version: '1.0.0',
383
+ * description: 'Decentralized exchange for private token swaps',
384
+ * url: 'https://example.com',
385
+ * icon: 'https://example.com/icon.png'
386
+ * \},
387
+ * capabilities: [
388
+ * \{
389
+ * type: 'accounts',
390
+ * canGet: true,
391
+ * canCreateAuthWit: true
392
+ * \},
393
+ * \{
394
+ * type: 'contracts',
395
+ * contracts: [ammAddress, tokenAAddress, tokenBAddress],
396
+ * canRegister: true,
397
+ * canGetMetadata: true
398
+ * \},
399
+ * \{
400
+ * type: 'simulation',
401
+ * transactions: \{
402
+ * scope: [\{ contract: ammAddress, function: '*' \}]
403
+ * \}
404
+ * \},
405
+ * \{
406
+ * type: 'transaction',
407
+ * scope: [\{ contract: ammAddress, function: 'swap' \}]
408
+ * \}
409
+ * ]
410
+ * \};
411
+ */
412
+ export interface AppCapabilities {
413
+ /**
414
+ * Manifest version for forward compatibility.
415
+ * Currently only '1.0' is supported.
416
+ */
417
+ version: typeof CAPABILITY_VERSION;
418
+
419
+ /** Application metadata for display in authorization dialogs. */
420
+ metadata: {
421
+ /** Human-readable app name */
422
+ name: string;
423
+
424
+ /** App version */
425
+ version: string;
426
+
427
+ /** Optional description of what the app does */
428
+ description?: string;
429
+
430
+ /** Optional website URL */
431
+ url?: string;
432
+
433
+ /** Optional icon URL or data URI */
434
+ icon?: string;
435
+ };
436
+
437
+ /**
438
+ * Requested capabilities grouped by scope.
439
+ */
440
+ capabilities: Capability[];
441
+ }
442
+
443
+ /**
444
+ * Wallet capability response.
445
+ *
446
+ * Returned by wallet after user reviews and approves/denies the capability request.
447
+ *
448
+ * The wallet can modify requested capabilities:
449
+ * - Reduce scope (e.g., restrict to specific contracts instead of '*')
450
+ * - Add information (e.g., specify which accounts are granted)
451
+ * - Deny capabilities (by omitting them from the `granted` array)
452
+ *
453
+ * @example
454
+ * // App requests
455
+ * const manifest: AppCapabilities = \{
456
+ * version: '1.0',
457
+ * metadata: \{ name: 'MyDApp', version: '1.0.0' \},
458
+ * capabilities: [
459
+ * \{ type: 'accounts', canGet: true \},
460
+ * \{ type: 'contracts', contracts: '*', canRegister: true \}
461
+ * ]
462
+ * \};
463
+ *
464
+ * // Wallet responds with specific accounts and restricted contracts
465
+ * const response = await wallet.requestCapabilities(manifest);
466
+ * console.log(response.granted);
467
+ * // [
468
+ * // \{ type: 'accounts', canGet: true, accounts: [addr1, addr2] \},
469
+ * // \{ type: 'contracts', contracts: [specificContract], canRegister: true \}
470
+ * // ]
471
+ */
472
+ export interface WalletCapabilities {
473
+ /** Response version for forward compatibility. */
474
+ version: typeof CAPABILITY_VERSION;
475
+
476
+ /**
477
+ * Capabilities granted by the wallet.
478
+ * Capabilities not in this array were implicitly denied.
479
+ * Empty array means the user denied all capabilities.
480
+ */
481
+ granted: GrantedCapability[];
482
+
483
+ /** Wallet implementation details. */
484
+ wallet: {
485
+ /** Wallet name/implementation */
486
+ name: string;
487
+
488
+ /** Wallet version */
489
+ version: string;
490
+ };
491
+ }
@@ -1,2 +1,3 @@
1
1
  export * from './wallet.js';
2
2
  export * from './account_manager.js';
3
+ export * from './capabilities.js';
@@ -15,6 +15,7 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
15
15
  import { type ContractInstanceWithAddress, ContractInstanceWithAddressSchema } from '@aztec/stdlib/contract';
16
16
  import { Gas } from '@aztec/stdlib/gas';
17
17
  import { AbiDecodedSchema, type ApiSchemaFor, optional, schemas, zodFor } from '@aztec/stdlib/schemas';
18
+ import type { ExecutionPayload, InTx } from '@aztec/stdlib/tx';
18
19
  import {
19
20
  Capsule,
20
21
  HashedValues,
@@ -25,7 +26,6 @@ import {
25
26
  UtilitySimulationResult,
26
27
  inTxSchema,
27
28
  } from '@aztec/stdlib/tx';
28
- import type { ExecutionPayload, InTx } from '@aztec/stdlib/tx';
29
29
 
30
30
  import { z } from 'zod';
31
31
 
@@ -40,6 +40,7 @@ import {
40
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.
@@ -223,6 +224,7 @@ export type Wallet = {
223
224
  opts: SendOptions<W>,
224
225
  ): Promise<SendReturn<W>>;
225
226
  createAuthWit(from: AztecAddress, messageHashOrIntent: IntentInnerHash | CallIntent): Promise<AuthWitness>;
227
+ requestCapabilities(manifest: AppCapabilities): Promise<WalletCapabilities>;
226
228
  batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>>;
227
229
  };
228
230
 
@@ -333,6 +335,119 @@ export const ContractClassMetadataSchema = z.object({
333
335
  isContractClassPubliclyRegistered: z.boolean(),
334
336
  });
335
337
 
338
+ export const ContractFunctionPatternSchema = z.object({
339
+ contract: z.union([schemas.AztecAddress, z.literal('*')]),
340
+ function: z.union([z.string(), z.literal('*')]),
341
+ });
342
+
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
+
336
451
  /**
337
452
  * Record of all wallet method schemas (excluding batch).
338
453
  * This is the single source of truth for method schemas - batch schemas are derived from this.
@@ -372,6 +487,7 @@ const WalletMethodSchemas = {
372
487
  .args(ExecutionPayloadSchema, SendOptionsSchema)
373
488
  .returns(z.union([TxHash.schema, TxReceipt.schema])),
374
489
  createAuthWit: z.function().args(schemas.AztecAddress, MessageHashOrIntentSchema).returns(AuthWitness.schema),
490
+ requestCapabilities: z.function().args(AppCapabilitiesSchema).returns(WalletCapabilitiesSchema),
375
491
  };
376
492
 
377
493
  /**