@aztec/aztec.js 0.0.1-commit.2ed92850 → 0.0.1-commit.43597cc1

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 (64) hide show
  1. package/dest/api/events.d.ts +10 -6
  2. package/dest/api/events.d.ts.map +1 -1
  3. package/dest/api/events.js +30 -20
  4. package/dest/api/fields.d.ts +2 -1
  5. package/dest/api/fields.d.ts.map +1 -1
  6. package/dest/api/fields.js +1 -0
  7. package/dest/api/keys.d.ts +1 -1
  8. package/dest/api/keys.js +1 -1
  9. package/dest/api/wallet.d.ts +3 -2
  10. package/dest/api/wallet.d.ts.map +1 -1
  11. package/dest/api/wallet.js +2 -1
  12. package/dest/contract/contract_function_interaction.d.ts +3 -12
  13. package/dest/contract/contract_function_interaction.d.ts.map +1 -1
  14. package/dest/contract/contract_function_interaction.js +6 -6
  15. package/dest/contract/protocol_contracts/auth-registry.d.ts +1 -10
  16. package/dest/contract/protocol_contracts/auth-registry.d.ts.map +1 -1
  17. package/dest/contract/protocol_contracts/auth-registry.js +61 -466
  18. package/dest/contract/protocol_contracts/contract-class-registry.d.ts +2 -11
  19. package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -1
  20. package/dest/contract/protocol_contracts/contract-class-registry.js +10 -409
  21. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +2 -11
  22. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -1
  23. package/dest/contract/protocol_contracts/contract-instance-registry.js +80 -473
  24. package/dest/contract/protocol_contracts/fee-juice.d.ts +1 -10
  25. package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -1
  26. package/dest/contract/protocol_contracts/fee-juice.js +0 -401
  27. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts +1 -1
  28. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts.map +1 -1
  29. package/dest/contract/protocol_contracts/multi-call-entrypoint.js +22 -0
  30. package/dest/contract/protocol_contracts/public-checks.d.ts +1 -1
  31. package/dest/contract/protocol_contracts/public-checks.d.ts.map +1 -1
  32. package/dest/contract/protocol_contracts/public-checks.js +22 -8
  33. package/dest/fee/fee_juice_payment_method_with_claim.js +6 -6
  34. package/dest/fee/private_fee_payment_method.js +10 -10
  35. package/dest/fee/public_fee_payment_method.js +10 -10
  36. package/dest/fee/sponsored_fee_payment.js +3 -3
  37. package/dest/wallet/capabilities.d.ts +444 -0
  38. package/dest/wallet/capabilities.d.ts.map +1 -0
  39. package/dest/wallet/capabilities.js +3 -0
  40. package/dest/wallet/index.d.ts +2 -1
  41. package/dest/wallet/index.d.ts.map +1 -1
  42. package/dest/wallet/index.js +1 -0
  43. package/dest/wallet/wallet.d.ts +1442 -88
  44. package/dest/wallet/wallet.d.ts.map +1 -1
  45. package/dest/wallet/wallet.js +142 -22
  46. package/package.json +19 -10
  47. package/src/api/events.ts +35 -27
  48. package/src/api/fields.ts +1 -0
  49. package/src/api/keys.ts +2 -2
  50. package/src/api/wallet.ts +42 -1
  51. package/src/contract/contract_function_interaction.ts +13 -6
  52. package/src/contract/protocol_contracts/auth-registry.ts +37 -231
  53. package/src/contract/protocol_contracts/contract-class-registry.ts +3 -195
  54. package/src/contract/protocol_contracts/contract-instance-registry.ts +34 -225
  55. package/src/contract/protocol_contracts/fee-juice.ts +0 -193
  56. package/src/contract/protocol_contracts/multi-call-entrypoint.ts +3 -0
  57. package/src/contract/protocol_contracts/public-checks.ts +3 -2
  58. package/src/fee/fee_juice_payment_method_with_claim.ts +5 -5
  59. package/src/fee/private_fee_payment_method.ts +7 -7
  60. package/src/fee/public_fee_payment_method.ts +8 -8
  61. package/src/fee/sponsored_fee_payment.ts +3 -3
  62. package/src/wallet/capabilities.ts +491 -0
  63. package/src/wallet/index.ts +1 -0
  64. package/src/wallet/wallet.ts +182 -35
@@ -7,14 +7,14 @@ import {
7
7
  type ContractArtifact,
8
8
  ContractArtifactSchema,
9
9
  type EventMetadataDefinition,
10
- type FunctionCall,
11
- FunctionType,
10
+ FunctionCall,
12
11
  } from '@aztec/stdlib/abi';
13
12
  import { AuthWitness } from '@aztec/stdlib/auth-witness';
14
13
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
15
14
  import { type ContractInstanceWithAddress, ContractInstanceWithAddressSchema } from '@aztec/stdlib/contract';
16
15
  import { Gas } from '@aztec/stdlib/gas';
17
16
  import { AbiDecodedSchema, type ApiSchemaFor, optional, schemas, zodFor } from '@aztec/stdlib/schemas';
17
+ import type { ExecutionPayload, InTx } from '@aztec/stdlib/tx';
18
18
  import {
19
19
  Capsule,
20
20
  HashedValues,
@@ -25,7 +25,6 @@ import {
25
25
  UtilitySimulationResult,
26
26
  inTxSchema,
27
27
  } from '@aztec/stdlib/tx';
28
- import type { ExecutionPayload, InTx } from '@aztec/stdlib/tx';
29
28
 
30
29
  import { z } from 'zod';
31
30
 
@@ -40,6 +39,7 @@ import {
40
39
  type SimulateInteractionOptions,
41
40
  } from '../contract/interaction_options.js';
42
41
  import type { CallIntent, IntentInnerHash } from '../utils/authwit.js';
42
+ import type { AppCapabilities, WalletCapabilities } from './capabilities.js';
43
43
 
44
44
  /**
45
45
  * A wrapper type that allows any item to be associated with an alias.
@@ -139,37 +139,66 @@ export type BatchResults<T extends readonly BatchedMethod[]> = {
139
139
  };
140
140
 
141
141
  /**
142
- * Filter options when querying private events.
142
+ * Base filter options for event queries.
143
143
  */
144
- export type PrivateEventFilter = {
145
- /** The address of the contract that emitted the events. */
146
- contractAddress: AztecAddress;
147
- /** Addresses of accounts that are in scope for this filter. */
148
- scopes: AztecAddress[];
144
+ export type EventFilterBase = {
149
145
  /** Transaction in which the events were emitted. */
150
146
  txHash?: TxHash;
151
147
  /** The block number from which to start fetching events (inclusive).
152
148
  * Optional. If provided, it must be greater or equal than 1.
153
149
  * Defaults to the initial L2 block number (INITIAL_L2_BLOCK_NUM).
154
- * */
150
+ */
155
151
  fromBlock?: BlockNumber;
156
152
  /** The block number until which to fetch logs (not inclusive).
157
153
  * Optional. If provided, it must be greater than fromBlock.
158
- * Defaults to the latest known block to PXE + 1.
159
154
  */
160
155
  toBlock?: BlockNumber;
161
156
  };
162
157
 
163
158
  /**
164
- * An ABI decoded private event with associated metadata.
159
+ * Filter options when querying private events.
165
160
  */
166
- export type PrivateEvent<T> = {
161
+ export type PrivateEventFilter = EventFilterBase & {
162
+ /** The address of the contract that emitted the events. */
163
+ contractAddress: AztecAddress;
164
+ /** Addresses of accounts that are in scope for this filter. */
165
+ scopes: AztecAddress[];
166
+ };
167
+
168
+ /**
169
+ * Filter options when querying public events.
170
+ */
171
+ export type PublicEventFilter = EventFilterBase & {
172
+ /** The address of the contract that emitted the events. */
173
+ contractAddress?: AztecAddress;
174
+ };
175
+
176
+ /**
177
+ * An ABI decoded event with associated metadata.
178
+ * @typeParam T - The decoded event type
179
+ * @typeParam M - Additional metadata fields (empty by default)
180
+ */
181
+ export type Event<T, M extends object = object> = {
167
182
  /** The ABI decoded event */
168
183
  event: T;
169
184
  /** Metadata describing event context information such as tx and block */
170
- metadata: InTx;
185
+ metadata: InTx & M;
171
186
  };
172
187
 
188
+ /** An ABI decoded private event with associated metadata. */
189
+ export type PrivateEvent<T> = Event<T>;
190
+
191
+ /** An ABI decoded public event with associated metadata (includes contract address). */
192
+ export type PublicEvent<T> = Event<
193
+ T,
194
+ {
195
+ /**
196
+ * Address of the contract that emitted this event
197
+ */
198
+ contractAddress: AztecAddress;
199
+ }
200
+ >;
201
+
173
202
  /**
174
203
  * Contract metadata including deployment and registration status.
175
204
  */
@@ -223,22 +252,12 @@ export type Wallet = {
223
252
  opts: SendOptions<W>,
224
253
  ): Promise<SendReturn<W>>;
225
254
  createAuthWit(from: AztecAddress, messageHashOrIntent: IntentInnerHash | CallIntent): Promise<AuthWitness>;
255
+ requestCapabilities(manifest: AppCapabilities): Promise<WalletCapabilities>;
226
256
  batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>>;
227
257
  };
228
258
 
229
- export const FunctionCallSchema = z.object({
230
- name: z.string(),
231
- to: schemas.AztecAddress,
232
- selector: schemas.FunctionSelector,
233
- type: z.nativeEnum(FunctionType),
234
- isStatic: z.boolean(),
235
- hideMsgSender: z.boolean(),
236
- args: z.array(schemas.Fr),
237
- returnTypes: z.array(AbiTypeSchema),
238
- });
239
-
240
259
  export const ExecutionPayloadSchema = z.object({
241
- calls: z.array(FunctionCallSchema),
260
+ calls: z.array(FunctionCall.schema),
242
261
  authWitnesses: z.array(AuthWitness.schema),
243
262
  capsules: z.array(Capsule.schema),
244
263
  extraHashedArgs: z.array(HashedValues.schema),
@@ -295,7 +314,7 @@ export const MessageHashOrIntentSchema = z.union([
295
314
  z.object({ consumer: schemas.AztecAddress, innerHash: schemas.Fr }),
296
315
  z.object({
297
316
  caller: schemas.AztecAddress,
298
- call: FunctionCallSchema,
317
+ call: FunctionCall.schema,
299
318
  }),
300
319
  ]);
301
320
 
@@ -305,6 +324,21 @@ export const EventMetadataDefinitionSchema = z.object({
305
324
  fieldNames: z.array(z.string()),
306
325
  });
307
326
 
327
+ const EventFilterBaseSchema = z.object({
328
+ txHash: optional(TxHash.schema),
329
+ fromBlock: optional(BlockNumberPositiveSchema),
330
+ toBlock: optional(BlockNumberPositiveSchema),
331
+ });
332
+
333
+ export const PrivateEventFilterSchema = EventFilterBaseSchema.extend({
334
+ contractAddress: schemas.AztecAddress,
335
+ scopes: z.array(schemas.AztecAddress),
336
+ });
337
+
338
+ export const PublicEventFilterSchema = EventFilterBaseSchema.extend({
339
+ contractAddress: optional(schemas.AztecAddress),
340
+ });
341
+
308
342
  export const PrivateEventSchema: z.ZodType<any> = zodFor<PrivateEvent<AbiDecoded>>()(
309
343
  z.object({
310
344
  event: AbiDecodedSchema,
@@ -312,13 +346,12 @@ export const PrivateEventSchema: z.ZodType<any> = zodFor<PrivateEvent<AbiDecoded
312
346
  }),
313
347
  );
314
348
 
315
- export const PrivateEventFilterSchema = z.object({
316
- contractAddress: schemas.AztecAddress,
317
- scopes: z.array(schemas.AztecAddress),
318
- txHash: optional(TxHash.schema),
319
- fromBlock: optional(BlockNumberPositiveSchema),
320
- toBlock: optional(BlockNumberPositiveSchema),
321
- });
349
+ export const PublicEventSchema = zodFor<PublicEvent<AbiDecoded>>()(
350
+ z.object({
351
+ event: AbiDecodedSchema,
352
+ metadata: z.intersection(inTxSchema(), z.object({ contractAddress: schemas.AztecAddress })),
353
+ }),
354
+ );
322
355
 
323
356
  export const ContractMetadataSchema = z.object({
324
357
  instance: optional(ContractInstanceWithAddressSchema),
@@ -333,6 +366,119 @@ export const ContractClassMetadataSchema = z.object({
333
366
  isContractClassPubliclyRegistered: z.boolean(),
334
367
  });
335
368
 
369
+ export const ContractFunctionPatternSchema = z.object({
370
+ contract: z.union([schemas.AztecAddress, z.literal('*')]),
371
+ function: z.union([z.string(), z.literal('*')]),
372
+ });
373
+
374
+ export const AccountsCapabilitySchema = z.object({
375
+ type: z.literal('accounts'),
376
+ canGet: optional(z.boolean()),
377
+ canCreateAuthWit: optional(z.boolean()),
378
+ });
379
+
380
+ export const GrantedAccountsCapabilitySchema = AccountsCapabilitySchema.extend({
381
+ accounts: z.array(z.object({ alias: z.string(), item: schemas.AztecAddress })),
382
+ });
383
+
384
+ export const ContractsCapabilitySchema = z.object({
385
+ type: z.literal('contracts'),
386
+ contracts: z.union([z.literal('*'), z.array(schemas.AztecAddress)]),
387
+ canRegister: optional(z.boolean()),
388
+ canGetMetadata: optional(z.boolean()),
389
+ });
390
+
391
+ export const GrantedContractsCapabilitySchema = ContractsCapabilitySchema;
392
+
393
+ export const ContractClassesCapabilitySchema = z.object({
394
+ type: z.literal('contractClasses'),
395
+ classes: z.union([z.literal('*'), z.array(schemas.Fr)]),
396
+ canGetMetadata: z.boolean(),
397
+ });
398
+
399
+ export const GrantedContractClassesCapabilitySchema = ContractClassesCapabilitySchema;
400
+
401
+ export const SimulationCapabilitySchema = z.object({
402
+ type: z.literal('simulation'),
403
+ transactions: optional(
404
+ z.object({
405
+ scope: z.union([z.literal('*'), z.array(ContractFunctionPatternSchema)]),
406
+ }),
407
+ ),
408
+ utilities: optional(
409
+ z.object({
410
+ scope: z.union([z.literal('*'), z.array(ContractFunctionPatternSchema)]),
411
+ }),
412
+ ),
413
+ });
414
+
415
+ export const GrantedSimulationCapabilitySchema = SimulationCapabilitySchema;
416
+
417
+ export const TransactionCapabilitySchema = z.object({
418
+ type: z.literal('transaction'),
419
+ scope: z.union([z.literal('*'), z.array(ContractFunctionPatternSchema)]),
420
+ });
421
+
422
+ export const GrantedTransactionCapabilitySchema = TransactionCapabilitySchema;
423
+
424
+ export const DataCapabilitySchema = z.object({
425
+ type: z.literal('data'),
426
+ addressBook: optional(z.boolean()),
427
+ privateEvents: optional(
428
+ z.object({
429
+ contracts: z.union([z.literal('*'), z.array(schemas.AztecAddress)]),
430
+ }),
431
+ ),
432
+ });
433
+
434
+ export const GrantedDataCapabilitySchema = DataCapabilitySchema;
435
+
436
+ export const CapabilitySchema = z.discriminatedUnion('type', [
437
+ AccountsCapabilitySchema,
438
+ ContractsCapabilitySchema,
439
+ ContractClassesCapabilitySchema,
440
+ SimulationCapabilitySchema,
441
+ TransactionCapabilitySchema,
442
+ DataCapabilitySchema,
443
+ ]);
444
+
445
+ export const GrantedCapabilitySchema = z.discriminatedUnion('type', [
446
+ GrantedAccountsCapabilitySchema,
447
+ GrantedContractsCapabilitySchema,
448
+ GrantedContractClassesCapabilitySchema,
449
+ GrantedSimulationCapabilitySchema,
450
+ GrantedTransactionCapabilitySchema,
451
+ GrantedDataCapabilitySchema,
452
+ ]);
453
+
454
+ export const AppCapabilitiesSchema = z.object({
455
+ version: z.literal('1.0'),
456
+ metadata: z.object({
457
+ name: z.string(),
458
+ version: z.string(),
459
+ description: optional(z.string()),
460
+ url: optional(z.string()),
461
+ icon: optional(z.string()),
462
+ }),
463
+ capabilities: z.array(CapabilitySchema),
464
+ behavior: optional(
465
+ z.object({
466
+ mode: optional(z.enum(['strict', 'permissive'])),
467
+ expiration: optional(z.number()),
468
+ }),
469
+ ),
470
+ });
471
+
472
+ export const WalletCapabilitiesSchema = z.object({
473
+ version: z.literal('1.0'),
474
+ granted: z.array(GrantedCapabilitySchema),
475
+ wallet: z.object({
476
+ name: z.string(),
477
+ version: z.string(),
478
+ }),
479
+ expiresAt: optional(z.number()),
480
+ });
481
+
336
482
  /**
337
483
  * Record of all wallet method schemas (excluding batch).
338
484
  * This is the single source of truth for method schemas - batch schemas are derived from this.
@@ -364,7 +510,7 @@ const WalletMethodSchemas = {
364
510
  simulateTx: z.function().args(ExecutionPayloadSchema, SimulateOptionsSchema).returns(TxSimulationResult.schema),
365
511
  simulateUtility: z
366
512
  .function()
367
- .args(FunctionCallSchema, optional(z.array(AuthWitness.schema)))
513
+ .args(FunctionCall.schema, optional(z.array(AuthWitness.schema)))
368
514
  .returns(UtilitySimulationResult.schema),
369
515
  profileTx: z.function().args(ExecutionPayloadSchema, ProfileOptionsSchema).returns(TxProfileResult.schema),
370
516
  sendTx: z
@@ -372,6 +518,7 @@ const WalletMethodSchemas = {
372
518
  .args(ExecutionPayloadSchema, SendOptionsSchema)
373
519
  .returns(z.union([TxHash.schema, TxReceipt.schema])),
374
520
  createAuthWit: z.function().args(schemas.AztecAddress, MessageHashOrIntentSchema).returns(AuthWitness.schema),
521
+ requestCapabilities: z.function().args(AppCapabilitiesSchema).returns(WalletCapabilitiesSchema),
375
522
  };
376
523
 
377
524
  /**