@aztec/aztec.js 0.0.1-commit.29c6b1a3 → 0.0.1-commit.2c85e299c

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 (116) hide show
  1. package/dest/api/abi.d.ts +2 -2
  2. package/dest/api/abi.d.ts.map +1 -1
  3. package/dest/api/contract.d.ts +5 -5
  4. package/dest/api/contract.d.ts.map +1 -1
  5. package/dest/api/contract.js +3 -3
  6. package/dest/api/deployment.d.ts +1 -2
  7. package/dest/api/deployment.d.ts.map +1 -1
  8. package/dest/api/deployment.js +0 -1
  9. package/dest/api/events.d.ts +18 -6
  10. package/dest/api/events.d.ts.map +1 -1
  11. package/dest/api/events.js +37 -22
  12. package/dest/api/fields.d.ts +2 -1
  13. package/dest/api/fields.d.ts.map +1 -1
  14. package/dest/api/fields.js +1 -0
  15. package/dest/api/keys.d.ts +1 -1
  16. package/dest/api/keys.js +1 -1
  17. package/dest/api/wallet.d.ts +3 -2
  18. package/dest/api/wallet.d.ts.map +1 -1
  19. package/dest/api/wallet.js +2 -1
  20. package/dest/contract/base_contract_interaction.d.ts +3 -3
  21. package/dest/contract/base_contract_interaction.d.ts.map +1 -1
  22. package/dest/contract/batch_call.d.ts +3 -3
  23. package/dest/contract/batch_call.d.ts.map +1 -1
  24. package/dest/contract/batch_call.js +17 -8
  25. package/dest/contract/contract_function_interaction.d.ts +7 -16
  26. package/dest/contract/contract_function_interaction.d.ts.map +1 -1
  27. package/dest/contract/contract_function_interaction.js +107 -18
  28. package/dest/contract/deploy_method.d.ts +37 -12
  29. package/dest/contract/deploy_method.d.ts.map +1 -1
  30. package/dest/contract/deploy_method.js +42 -21
  31. package/dest/contract/get_gas_limits.js +3 -3
  32. package/dest/contract/interaction_options.d.ts +62 -21
  33. package/dest/contract/interaction_options.d.ts.map +1 -1
  34. package/dest/contract/interaction_options.js +33 -0
  35. package/dest/contract/protocol_contracts/auth-registry.d.ts +1 -1
  36. package/dest/contract/protocol_contracts/auth-registry.d.ts.map +1 -1
  37. package/dest/contract/protocol_contracts/auth-registry.js +48 -6
  38. package/dest/contract/protocol_contracts/contract-class-registry.d.ts +2 -22
  39. package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -1
  40. package/dest/contract/protocol_contracts/contract-class-registry.js +13 -658
  41. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +2 -11
  42. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -1
  43. package/dest/contract/protocol_contracts/contract-instance-registry.js +76 -473
  44. package/dest/contract/protocol_contracts/fee-juice.d.ts +1 -10
  45. package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -1
  46. package/dest/contract/protocol_contracts/fee-juice.js +7 -400
  47. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts +1 -1
  48. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts.map +1 -1
  49. package/dest/contract/protocol_contracts/multi-call-entrypoint.js +39 -1
  50. package/dest/contract/protocol_contracts/public-checks.d.ts +1 -1
  51. package/dest/contract/protocol_contracts/public-checks.d.ts.map +1 -1
  52. package/dest/contract/protocol_contracts/public-checks.js +39 -9
  53. package/dest/fee/fee_juice_payment_method_with_claim.js +6 -6
  54. package/dest/fee/private_fee_payment_method.d.ts +2 -1
  55. package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
  56. package/dest/fee/private_fee_payment_method.js +11 -10
  57. package/dest/fee/public_fee_payment_method.d.ts +2 -1
  58. package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
  59. package/dest/fee/public_fee_payment_method.js +11 -10
  60. package/dest/fee/sponsored_fee_payment.js +3 -3
  61. package/dest/utils/abi_types.d.ts +6 -1
  62. package/dest/utils/abi_types.d.ts.map +1 -1
  63. package/dest/utils/abi_types.js +1 -1
  64. package/dest/utils/authwit.d.ts +5 -5
  65. package/dest/utils/authwit.d.ts.map +1 -1
  66. package/dest/utils/authwit.js +10 -6
  67. package/dest/utils/cross_chain.d.ts +3 -8
  68. package/dest/utils/cross_chain.d.ts.map +1 -1
  69. package/dest/utils/cross_chain.js +8 -15
  70. package/dest/wallet/capabilities.d.ts +452 -0
  71. package/dest/wallet/capabilities.d.ts.map +1 -0
  72. package/dest/wallet/capabilities.js +3 -0
  73. package/dest/wallet/deploy_account_method.d.ts +15 -4
  74. package/dest/wallet/deploy_account_method.d.ts.map +1 -1
  75. package/dest/wallet/deploy_account_method.js +26 -0
  76. package/dest/wallet/index.d.ts +2 -1
  77. package/dest/wallet/index.d.ts.map +1 -1
  78. package/dest/wallet/index.js +1 -0
  79. package/dest/wallet/wallet.d.ts +1663 -89
  80. package/dest/wallet/wallet.d.ts.map +1 -1
  81. package/dest/wallet/wallet.js +175 -27
  82. package/package.json +20 -11
  83. package/src/api/abi.ts +1 -0
  84. package/src/api/contract.ts +10 -3
  85. package/src/api/deployment.ts +0 -1
  86. package/src/api/events.ts +50 -32
  87. package/src/api/fields.ts +1 -0
  88. package/src/api/keys.ts +2 -2
  89. package/src/api/wallet.ts +43 -1
  90. package/src/contract/base_contract_interaction.ts +3 -2
  91. package/src/contract/batch_call.ts +17 -14
  92. package/src/contract/contract_function_interaction.ts +114 -26
  93. package/src/contract/deploy_method.ts +77 -32
  94. package/src/contract/get_gas_limits.ts +3 -3
  95. package/src/contract/interaction_options.ts +96 -23
  96. package/src/contract/protocol_contracts/auth-registry.ts +10 -2
  97. package/src/contract/protocol_contracts/contract-class-registry.ts +4 -338
  98. package/src/contract/protocol_contracts/contract-instance-registry.ts +33 -225
  99. package/src/contract/protocol_contracts/fee-juice.ts +2 -193
  100. package/src/contract/protocol_contracts/multi-call-entrypoint.ts +8 -1
  101. package/src/contract/protocol_contracts/public-checks.ts +8 -3
  102. package/src/fee/fee_juice_payment_method_with_claim.ts +5 -5
  103. package/src/fee/private_fee_payment_method.ts +8 -7
  104. package/src/fee/public_fee_payment_method.ts +9 -8
  105. package/src/fee/sponsored_fee_payment.ts +3 -3
  106. package/src/utils/abi_types.ts +7 -0
  107. package/src/utils/authwit.ts +20 -22
  108. package/src/utils/cross_chain.ts +9 -18
  109. package/src/wallet/capabilities.ts +500 -0
  110. package/src/wallet/deploy_account_method.ts +39 -2
  111. package/src/wallet/index.ts +1 -0
  112. package/src/wallet/wallet.ts +230 -39
  113. package/dest/deployment/broadcast_function.d.ts +0 -24
  114. package/dest/deployment/broadcast_function.d.ts.map +0 -1
  115. package/dest/deployment/broadcast_function.js +0 -74
  116. package/src/deployment/broadcast_function.ts +0 -148
@@ -7,13 +7,13 @@ 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';
16
+ import { LogId } from '@aztec/stdlib/logs';
17
17
  import { AbiDecodedSchema, type ApiSchemaFor, optional, schemas, zodFor } from '@aztec/stdlib/schemas';
18
18
  import type { ExecutionPayload, InTx } from '@aztec/stdlib/tx';
19
19
  import {
@@ -23,7 +23,7 @@ import {
23
23
  TxProfileResult,
24
24
  TxReceipt,
25
25
  TxSimulationResult,
26
- UtilitySimulationResult,
26
+ UtilityExecutionResult,
27
27
  inTxSchema,
28
28
  } from '@aztec/stdlib/tx';
29
29
 
@@ -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.
@@ -139,37 +140,68 @@ export type BatchResults<T extends readonly BatchedMethod[]> = {
139
140
  };
140
141
 
141
142
  /**
142
- * Filter options when querying private events.
143
+ * Base filter options for event queries.
143
144
  */
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[];
145
+ export type EventFilterBase = {
149
146
  /** Transaction in which the events were emitted. */
150
147
  txHash?: TxHash;
151
148
  /** The block number from which to start fetching events (inclusive).
152
149
  * Optional. If provided, it must be greater or equal than 1.
153
150
  * Defaults to the initial L2 block number (INITIAL_L2_BLOCK_NUM).
154
- * */
151
+ */
155
152
  fromBlock?: BlockNumber;
156
153
  /** The block number until which to fetch logs (not inclusive).
157
154
  * Optional. If provided, it must be greater than fromBlock.
158
- * Defaults to the latest known block to PXE + 1.
159
155
  */
160
156
  toBlock?: BlockNumber;
157
+ /** Log id after which to start fetching logs. Used for pagination. */
158
+ afterLog?: LogId;
161
159
  };
162
160
 
163
161
  /**
164
- * An ABI decoded private event with associated metadata.
162
+ * Filter options when querying private events.
165
163
  */
166
- export type PrivateEvent<T> = {
164
+ export type PrivateEventFilter = EventFilterBase & {
165
+ /** The address of the contract that emitted the events. */
166
+ contractAddress: AztecAddress;
167
+ /** Addresses of accounts that are in scope for this filter. */
168
+ scopes: AztecAddress[];
169
+ };
170
+
171
+ /**
172
+ * Filter options when querying public events.
173
+ */
174
+ export type PublicEventFilter = EventFilterBase & {
175
+ /** The address of the contract that emitted the events. */
176
+ contractAddress?: AztecAddress;
177
+ };
178
+
179
+ /**
180
+ * An ABI decoded event with associated metadata.
181
+ * @typeParam T - The decoded event type
182
+ * @typeParam M - Additional metadata fields (empty by default)
183
+ */
184
+ export type Event<T, M extends object = object> = {
167
185
  /** The ABI decoded event */
168
186
  event: T;
169
187
  /** Metadata describing event context information such as tx and block */
170
- metadata: InTx;
188
+ metadata: InTx & M;
171
189
  };
172
190
 
191
+ /** An ABI decoded private event with associated metadata. */
192
+ export type PrivateEvent<T> = Event<T>;
193
+
194
+ /** An ABI decoded public event with associated metadata (includes contract address). */
195
+ export type PublicEvent<T> = Event<
196
+ T,
197
+ {
198
+ /**
199
+ * Address of the contract that emitted this event
200
+ */
201
+ contractAddress: AztecAddress;
202
+ }
203
+ >;
204
+
173
205
  /**
174
206
  * Contract metadata including deployment and registration status.
175
207
  */
@@ -196,6 +228,16 @@ export type ContractClassMetadata = {
196
228
  isContractClassPubliclyRegistered: boolean;
197
229
  };
198
230
 
231
+ /**
232
+ * Options for executing a utility function call.
233
+ */
234
+ export type ExecuteUtilityOptions = {
235
+ /** The scope for the utility execution (determines which notes and keys are visible). */
236
+ scope: AztecAddress;
237
+ /** Optional auth witnesses to use during execution. */
238
+ authWitnesses?: AuthWitness[];
239
+ };
240
+
199
241
  /**
200
242
  * The wallet interface.
201
243
  */
@@ -216,29 +258,19 @@ export type Wallet = {
216
258
  secretKey?: Fr,
217
259
  ): Promise<ContractInstanceWithAddress>;
218
260
  simulateTx(exec: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult>;
219
- simulateUtility(call: FunctionCall, authwits?: AuthWitness[]): Promise<UtilitySimulationResult>;
261
+ executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult>;
220
262
  profileTx(exec: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult>;
221
263
  sendTx<W extends InteractionWaitOptions = undefined>(
222
264
  exec: ExecutionPayload,
223
265
  opts: SendOptions<W>,
224
266
  ): Promise<SendReturn<W>>;
225
267
  createAuthWit(from: AztecAddress, messageHashOrIntent: IntentInnerHash | CallIntent): Promise<AuthWitness>;
268
+ requestCapabilities(manifest: AppCapabilities): Promise<WalletCapabilities>;
226
269
  batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>>;
227
270
  };
228
271
 
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
272
  export const ExecutionPayloadSchema = z.object({
241
- calls: z.array(FunctionCallSchema),
273
+ calls: z.array(FunctionCall.schema),
242
274
  authWitnesses: z.array(AuthWitness.schema),
243
275
  capsules: z.array(Capsule.schema),
244
276
  extraHashedArgs: z.array(HashedValues.schema),
@@ -274,6 +306,7 @@ export const SendOptionsSchema = z.object({
274
306
  capsules: optional(z.array(Capsule.schema)),
275
307
  fee: optional(GasSettingsOptionSchema),
276
308
  wait: optional(z.union([z.literal(NO_WAIT), WaitOptsSchema])),
309
+ additionalScopes: optional(z.array(schemas.AztecAddress)),
277
310
  });
278
311
 
279
312
  export const SimulateOptionsSchema = z.object({
@@ -284,6 +317,7 @@ export const SimulateOptionsSchema = z.object({
284
317
  skipTxValidation: optional(z.boolean()),
285
318
  skipFeeEnforcement: optional(z.boolean()),
286
319
  includeMetadata: optional(z.boolean()),
320
+ additionalScopes: optional(z.array(schemas.AztecAddress)),
287
321
  });
288
322
 
289
323
  export const ProfileOptionsSchema = SimulateOptionsSchema.extend({
@@ -295,7 +329,7 @@ export const MessageHashOrIntentSchema = z.union([
295
329
  z.object({ consumer: schemas.AztecAddress, innerHash: schemas.Fr }),
296
330
  z.object({
297
331
  caller: schemas.AztecAddress,
298
- call: FunctionCallSchema,
332
+ call: FunctionCall.schema,
299
333
  }),
300
334
  ]);
301
335
 
@@ -305,6 +339,22 @@ export const EventMetadataDefinitionSchema = z.object({
305
339
  fieldNames: z.array(z.string()),
306
340
  });
307
341
 
342
+ const EventFilterBaseSchema = z.object({
343
+ txHash: optional(TxHash.schema),
344
+ fromBlock: optional(BlockNumberPositiveSchema),
345
+ toBlock: optional(BlockNumberPositiveSchema),
346
+ afterLog: optional(LogId.schema),
347
+ });
348
+
349
+ export const PrivateEventFilterSchema = EventFilterBaseSchema.extend({
350
+ contractAddress: schemas.AztecAddress,
351
+ scopes: z.array(schemas.AztecAddress),
352
+ });
353
+
354
+ export const PublicEventFilterSchema = EventFilterBaseSchema.extend({
355
+ contractAddress: optional(schemas.AztecAddress),
356
+ });
357
+
308
358
  export const PrivateEventSchema: z.ZodType<any> = zodFor<PrivateEvent<AbiDecoded>>()(
309
359
  z.object({
310
360
  event: AbiDecodedSchema,
@@ -312,13 +362,12 @@ export const PrivateEventSchema: z.ZodType<any> = zodFor<PrivateEvent<AbiDecoded
312
362
  }),
313
363
  );
314
364
 
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
- });
365
+ export const PublicEventSchema = zodFor<PublicEvent<AbiDecoded>>()(
366
+ z.object({
367
+ event: AbiDecodedSchema,
368
+ metadata: z.intersection(inTxSchema(), z.object({ contractAddress: schemas.AztecAddress })),
369
+ }),
370
+ );
322
371
 
323
372
  export const ContractMetadataSchema = z.object({
324
373
  instance: optional(ContractInstanceWithAddressSchema),
@@ -333,6 +382,136 @@ export const ContractClassMetadataSchema = z.object({
333
382
  isContractClassPubliclyRegistered: z.boolean(),
334
383
  });
335
384
 
385
+ export const ContractFunctionPatternSchema = z.object({
386
+ contract: z.union([schemas.AztecAddress, z.literal('*')]),
387
+ function: z.union([z.string(), z.literal('*')]),
388
+ additionalScopes: optional(z.union([z.array(schemas.AztecAddress), z.literal('*')])),
389
+ });
390
+
391
+ export const AccountsCapabilitySchema = z.object({
392
+ type: z.literal('accounts'),
393
+ canGet: optional(z.boolean()),
394
+ canCreateAuthWit: optional(z.boolean()),
395
+ });
396
+
397
+ export const GrantedAccountsCapabilitySchema = AccountsCapabilitySchema.extend({
398
+ accounts: z.array(z.object({ alias: z.string(), item: schemas.AztecAddress })),
399
+ });
400
+
401
+ export const ContractsCapabilitySchema = z.object({
402
+ type: z.literal('contracts'),
403
+ contracts: z.union([z.literal('*'), z.array(schemas.AztecAddress)]),
404
+ canRegister: optional(z.boolean()),
405
+ canGetMetadata: optional(z.boolean()),
406
+ });
407
+
408
+ export const GrantedContractsCapabilitySchema = ContractsCapabilitySchema;
409
+
410
+ export const ContractClassesCapabilitySchema = z.object({
411
+ type: z.literal('contractClasses'),
412
+ classes: z.union([z.literal('*'), z.array(schemas.Fr)]),
413
+ canGetMetadata: z.boolean(),
414
+ });
415
+
416
+ export const GrantedContractClassesCapabilitySchema = ContractClassesCapabilitySchema;
417
+
418
+ export const SimulationCapabilitySchema = z.object({
419
+ type: z.literal('simulation'),
420
+ transactions: optional(
421
+ z.object({
422
+ scope: z.union([z.literal('*'), z.array(ContractFunctionPatternSchema)]),
423
+ }),
424
+ ),
425
+ utilities: optional(
426
+ z.object({
427
+ scope: z.union([z.literal('*'), z.array(ContractFunctionPatternSchema)]),
428
+ }),
429
+ ),
430
+ });
431
+
432
+ export const GrantedSimulationCapabilitySchema = SimulationCapabilitySchema;
433
+
434
+ export const TransactionCapabilitySchema = z.object({
435
+ type: z.literal('transaction'),
436
+ scope: z.union([z.literal('*'), z.array(ContractFunctionPatternSchema)]),
437
+ });
438
+
439
+ export const GrantedTransactionCapabilitySchema = TransactionCapabilitySchema;
440
+
441
+ export const DataCapabilitySchema = z.object({
442
+ type: z.literal('data'),
443
+ addressBook: optional(z.boolean()),
444
+ privateEvents: optional(
445
+ z.object({
446
+ contracts: z.union([z.literal('*'), z.array(schemas.AztecAddress)]),
447
+ }),
448
+ ),
449
+ });
450
+
451
+ export const GrantedDataCapabilitySchema = DataCapabilitySchema;
452
+
453
+ export const CapabilitySchema = z.discriminatedUnion('type', [
454
+ AccountsCapabilitySchema,
455
+ ContractsCapabilitySchema,
456
+ ContractClassesCapabilitySchema,
457
+ SimulationCapabilitySchema,
458
+ TransactionCapabilitySchema,
459
+ DataCapabilitySchema,
460
+ ]);
461
+
462
+ export const GrantedCapabilitySchema = z.discriminatedUnion('type', [
463
+ GrantedAccountsCapabilitySchema,
464
+ GrantedContractsCapabilitySchema,
465
+ GrantedContractClassesCapabilitySchema,
466
+ GrantedSimulationCapabilitySchema,
467
+ GrantedTransactionCapabilitySchema,
468
+ GrantedDataCapabilitySchema,
469
+ ]);
470
+
471
+ export const AppCapabilitiesSchema = z.object({
472
+ version: z.literal('1.0'),
473
+ metadata: z.object({
474
+ name: z.string(),
475
+ version: z.string(),
476
+ description: optional(z.string()),
477
+ url: optional(z.string()),
478
+ icon: optional(z.string()),
479
+ }),
480
+ capabilities: z.array(CapabilitySchema),
481
+ behavior: optional(
482
+ z.object({
483
+ mode: optional(z.enum(['strict', 'permissive'])),
484
+ expiration: optional(z.number()),
485
+ }),
486
+ ),
487
+ });
488
+
489
+ export const WalletCapabilitiesSchema = z.object({
490
+ version: z.literal('1.0'),
491
+ granted: z.array(GrantedCapabilitySchema),
492
+ wallet: z.object({
493
+ name: z.string(),
494
+ version: z.string(),
495
+ }),
496
+ expiresAt: optional(z.number()),
497
+ });
498
+
499
+ const OffchainEffectSchema = z.object({
500
+ data: z.array(schemas.Fr),
501
+ contractAddress: schemas.AztecAddress,
502
+ });
503
+
504
+ const OffchainMessageSchema = z.object({
505
+ recipient: schemas.AztecAddress,
506
+ payload: z.array(schemas.Fr),
507
+ contractAddress: schemas.AztecAddress,
508
+ });
509
+
510
+ const OffchainOutputSchema = z.object({
511
+ offchainEffects: z.array(OffchainEffectSchema),
512
+ offchainMessages: z.array(OffchainMessageSchema),
513
+ });
514
+
336
515
  /**
337
516
  * Record of all wallet method schemas (excluding batch).
338
517
  * This is the single source of truth for method schemas - batch schemas are derived from this.
@@ -362,16 +541,28 @@ const WalletMethodSchemas = {
362
541
  .args(ContractInstanceWithAddressSchema, optional(ContractArtifactSchema), optional(schemas.Fr))
363
542
  .returns(ContractInstanceWithAddressSchema),
364
543
  simulateTx: z.function().args(ExecutionPayloadSchema, SimulateOptionsSchema).returns(TxSimulationResult.schema),
365
- simulateUtility: z
544
+ executeUtility: z
366
545
  .function()
367
- .args(FunctionCallSchema, optional(z.array(AuthWitness.schema)))
368
- .returns(UtilitySimulationResult.schema),
546
+ .args(
547
+ FunctionCall.schema,
548
+ z.object({
549
+ scope: schemas.AztecAddress,
550
+ authWitnesses: optional(z.array(AuthWitness.schema)),
551
+ }),
552
+ )
553
+ .returns(UtilityExecutionResult.schema),
369
554
  profileTx: z.function().args(ExecutionPayloadSchema, ProfileOptionsSchema).returns(TxProfileResult.schema),
370
555
  sendTx: z
371
556
  .function()
372
557
  .args(ExecutionPayloadSchema, SendOptionsSchema)
373
- .returns(z.union([TxHash.schema, TxReceipt.schema])),
558
+ .returns(
559
+ z.union([
560
+ z.object({ txHash: TxHash.schema }).merge(OffchainOutputSchema),
561
+ z.object({ receipt: TxReceipt.schema }).merge(OffchainOutputSchema),
562
+ ]),
563
+ ),
374
564
  createAuthWit: z.function().args(schemas.AztecAddress, MessageHashOrIntentSchema).returns(AuthWitness.schema),
565
+ requestCapabilities: z.function().args(AppCapabilitiesSchema).returns(WalletCapabilitiesSchema),
375
566
  };
376
567
 
377
568
  /**
@@ -1,24 +0,0 @@
1
- import { type ContractArtifact, FunctionSelector } from '@aztec/stdlib/abi';
2
- import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
3
- import type { Wallet } from '../wallet/index.js';
4
- /**
5
- * Sets up a call to broadcast a private function's bytecode via the ClassRegistry contract.
6
- * Note that this is not required for users to call the function, but is rather a convenience to make
7
- * this code publicly available so dapps or wallets do not need to redistribute it.
8
- * @param wallet - Wallet to send the transaction.
9
- * @param artifact - Contract artifact that contains the function to be broadcast.
10
- * @param selector - Selector of the function to be broadcast.
11
- * @returns A ContractFunctionInteraction object that can be used to send the transaction.
12
- */
13
- export declare function broadcastPrivateFunction(wallet: Wallet, artifact: ContractArtifact, selector: FunctionSelector): Promise<ContractFunctionInteraction>;
14
- /**
15
- * Sets up a call to broadcast a utility function's bytecode via the ClassRegistry contract.
16
- * Note that this is not required for users to call the function, but is rather a convenience to make
17
- * this code publicly available so dapps or wallets do not need to redistribute it.
18
- * @param wallet - Wallet to send the transaction.
19
- * @param artifact - Contract artifact that contains the function to be broadcast.
20
- * @param selector - Selector of the function to be broadcast.
21
- * @returns A ContractFunctionInteraction object that can be used to send the transaction.
22
- */
23
- export declare function broadcastUtilityFunction(wallet: Wallet, artifact: ContractArtifact, selector: FunctionSelector): Promise<ContractFunctionInteraction>;
24
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnJvYWRjYXN0X2Z1bmN0aW9uLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZGVwbG95bWVudC9icm9hZGNhc3RfZnVuY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBUUEsT0FBTyxFQUFFLEtBQUssZ0JBQWdCLEVBQUUsZ0JBQWdCLEVBQWdDLE1BQU0sbUJBQW1CLENBQUM7QUFTMUcsT0FBTyxLQUFLLEVBQUUsMkJBQTJCLEVBQUUsTUFBTSw4Q0FBOEMsQ0FBQztBQUVoRyxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUVqRDs7Ozs7Ozs7R0FRRztBQUNILHdCQUFzQix3QkFBd0IsQ0FDNUMsTUFBTSxFQUFFLE1BQU0sRUFDZCxRQUFRLEVBQUUsZ0JBQWdCLEVBQzFCLFFBQVEsRUFBRSxnQkFBZ0IsR0FDekIsT0FBTyxDQUFDLDJCQUEyQixDQUFDLENBb0R0QztBQUVEOzs7Ozs7OztHQVFHO0FBQ0gsd0JBQXNCLHdCQUF3QixDQUM1QyxNQUFNLEVBQUUsTUFBTSxFQUNkLFFBQVEsRUFBRSxnQkFBZ0IsRUFDMUIsUUFBUSxFQUFFLGdCQUFnQixHQUN6QixPQUFPLENBQUMsMkJBQTJCLENBQUMsQ0E4Q3RDIn0=
@@ -1 +0,0 @@
1
- {"version":3,"file":"broadcast_function.d.ts","sourceRoot":"","sources":["../../src/deployment/broadcast_function.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,gBAAgB,EAAE,gBAAgB,EAAgC,MAAM,mBAAmB,CAAC;AAS1G,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,8CAA8C,CAAC;AAEhG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;;;;;;GAQG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,gBAAgB,EAC1B,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,2BAA2B,CAAC,CAoDtC;AAED;;;;;;;;GAQG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,gBAAgB,EAC1B,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,2BAA2B,CAAC,CA8CtC"}
@@ -1,74 +0,0 @@
1
- import { ARTIFACT_FUNCTION_TREE_MAX_HEIGHT, CONTRACT_CLASS_REGISTRY_BYTECODE_CAPSULE_SLOT, MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS } from '@aztec/constants';
2
- import { padArrayEnd } from '@aztec/foundation/collection';
3
- import { Fr } from '@aztec/foundation/curves/bn254';
4
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
5
- import { FunctionSelector, FunctionType, bufferAsFields } from '@aztec/stdlib/abi';
6
- import { computeVerificationKeyHash, createPrivateFunctionMembershipProof, createUtilityFunctionMembershipProof, getContractClassFromArtifact } from '@aztec/stdlib/contract';
7
- import { Capsule } from '@aztec/stdlib/tx';
8
- import { ContractClassRegistryContract } from '../contract/protocol_contracts/contract-class-registry.js';
9
- /**
10
- * Sets up a call to broadcast a private function's bytecode via the ClassRegistry contract.
11
- * Note that this is not required for users to call the function, but is rather a convenience to make
12
- * this code publicly available so dapps or wallets do not need to redistribute it.
13
- * @param wallet - Wallet to send the transaction.
14
- * @param artifact - Contract artifact that contains the function to be broadcast.
15
- * @param selector - Selector of the function to be broadcast.
16
- * @returns A ContractFunctionInteraction object that can be used to send the transaction.
17
- */ export async function broadcastPrivateFunction(wallet, artifact, selector) {
18
- const contractClass = await getContractClassFromArtifact(artifact);
19
- const privateFunctions = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PRIVATE);
20
- const functionsAndSelectors = await Promise.all(privateFunctions.map(async (fn)=>({
21
- f: fn,
22
- selector: await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters)
23
- })));
24
- const privateFunctionArtifact = functionsAndSelectors.find((fn)=>selector.equals(fn.selector))?.f;
25
- if (!privateFunctionArtifact) {
26
- throw new Error(`Private function with selector ${selector.toString()} not found`);
27
- }
28
- const { artifactTreeSiblingPath, artifactTreeLeafIndex, artifactMetadataHash, functionMetadataHash, utilityFunctionsTreeRoot, privateFunctionTreeSiblingPath, privateFunctionTreeLeafIndex } = await createPrivateFunctionMembershipProof(selector, artifact);
29
- const vkHash = await computeVerificationKeyHash(privateFunctionArtifact);
30
- const classRegistry = ContractClassRegistryContract.at(wallet);
31
- const bytecode = bufferAsFields(privateFunctionArtifact.bytecode, MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS);
32
- return classRegistry.methods.broadcast_private_function(contractClass.id, artifactMetadataHash, utilityFunctionsTreeRoot, privateFunctionTreeSiblingPath, privateFunctionTreeLeafIndex, padArrayEnd(artifactTreeSiblingPath, Fr.ZERO, ARTIFACT_FUNCTION_TREE_MAX_HEIGHT), artifactTreeLeafIndex, // eslint-disable-next-line camelcase
33
- {
34
- selector,
35
- metadata_hash: functionMetadataHash,
36
- vk_hash: vkHash
37
- }).with({
38
- capsules: [
39
- new Capsule(ProtocolContractAddress.ContractClassRegistry, new Fr(CONTRACT_CLASS_REGISTRY_BYTECODE_CAPSULE_SLOT), bytecode)
40
- ]
41
- });
42
- }
43
- /**
44
- * Sets up a call to broadcast a utility function's bytecode via the ClassRegistry contract.
45
- * Note that this is not required for users to call the function, but is rather a convenience to make
46
- * this code publicly available so dapps or wallets do not need to redistribute it.
47
- * @param wallet - Wallet to send the transaction.
48
- * @param artifact - Contract artifact that contains the function to be broadcast.
49
- * @param selector - Selector of the function to be broadcast.
50
- * @returns A ContractFunctionInteraction object that can be used to send the transaction.
51
- */ export async function broadcastUtilityFunction(wallet, artifact, selector) {
52
- const contractClass = await getContractClassFromArtifact(artifact);
53
- const utilityFunctions = artifact.functions.filter((fn)=>fn.functionType === FunctionType.UTILITY);
54
- const utilityFunctionsAndSelectors = await Promise.all(utilityFunctions.map(async (fn)=>({
55
- f: fn,
56
- selector: await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters)
57
- })));
58
- const utilityFunctionArtifact = utilityFunctionsAndSelectors.find((fn)=>selector.equals(fn.selector))?.f;
59
- if (!utilityFunctionArtifact) {
60
- throw new Error(`Utility function with selector ${selector.toString()} not found`);
61
- }
62
- const { artifactMetadataHash, artifactTreeLeafIndex, artifactTreeSiblingPath, functionMetadataHash, privateFunctionsArtifactTreeRoot } = await createUtilityFunctionMembershipProof(selector, artifact);
63
- const classRegistry = ContractClassRegistryContract.at(wallet);
64
- const bytecode = bufferAsFields(utilityFunctionArtifact.bytecode, MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS);
65
- return classRegistry.methods.broadcast_utility_function(contractClass.id, artifactMetadataHash, privateFunctionsArtifactTreeRoot, padArrayEnd(artifactTreeSiblingPath, Fr.ZERO, ARTIFACT_FUNCTION_TREE_MAX_HEIGHT), artifactTreeLeafIndex, // eslint-disable-next-line camelcase
66
- {
67
- selector,
68
- metadata_hash: functionMetadataHash
69
- }).with({
70
- capsules: [
71
- new Capsule(ProtocolContractAddress.ContractClassRegistry, new Fr(CONTRACT_CLASS_REGISTRY_BYTECODE_CAPSULE_SLOT), bytecode)
72
- ]
73
- });
74
- }
@@ -1,148 +0,0 @@
1
- import {
2
- ARTIFACT_FUNCTION_TREE_MAX_HEIGHT,
3
- CONTRACT_CLASS_REGISTRY_BYTECODE_CAPSULE_SLOT,
4
- MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
5
- } from '@aztec/constants';
6
- import { padArrayEnd } from '@aztec/foundation/collection';
7
- import { Fr } from '@aztec/foundation/curves/bn254';
8
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
9
- import { type ContractArtifact, FunctionSelector, FunctionType, bufferAsFields } from '@aztec/stdlib/abi';
10
- import {
11
- computeVerificationKeyHash,
12
- createPrivateFunctionMembershipProof,
13
- createUtilityFunctionMembershipProof,
14
- getContractClassFromArtifact,
15
- } from '@aztec/stdlib/contract';
16
- import { Capsule } from '@aztec/stdlib/tx';
17
-
18
- import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
19
- import { ContractClassRegistryContract } from '../contract/protocol_contracts/contract-class-registry.js';
20
- import type { Wallet } from '../wallet/index.js';
21
-
22
- /**
23
- * Sets up a call to broadcast a private function's bytecode via the ClassRegistry contract.
24
- * Note that this is not required for users to call the function, but is rather a convenience to make
25
- * this code publicly available so dapps or wallets do not need to redistribute it.
26
- * @param wallet - Wallet to send the transaction.
27
- * @param artifact - Contract artifact that contains the function to be broadcast.
28
- * @param selector - Selector of the function to be broadcast.
29
- * @returns A ContractFunctionInteraction object that can be used to send the transaction.
30
- */
31
- export async function broadcastPrivateFunction(
32
- wallet: Wallet,
33
- artifact: ContractArtifact,
34
- selector: FunctionSelector,
35
- ): Promise<ContractFunctionInteraction> {
36
- const contractClass = await getContractClassFromArtifact(artifact);
37
- const privateFunctions = artifact.functions.filter(fn => fn.functionType === FunctionType.PRIVATE);
38
- const functionsAndSelectors = await Promise.all(
39
- privateFunctions.map(async fn => ({
40
- f: fn,
41
- selector: await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters),
42
- })),
43
- );
44
- const privateFunctionArtifact = functionsAndSelectors.find(fn => selector.equals(fn.selector))?.f;
45
- if (!privateFunctionArtifact) {
46
- throw new Error(`Private function with selector ${selector.toString()} not found`);
47
- }
48
-
49
- const {
50
- artifactTreeSiblingPath,
51
- artifactTreeLeafIndex,
52
- artifactMetadataHash,
53
- functionMetadataHash,
54
- utilityFunctionsTreeRoot,
55
- privateFunctionTreeSiblingPath,
56
- privateFunctionTreeLeafIndex,
57
- } = await createPrivateFunctionMembershipProof(selector, artifact);
58
-
59
- const vkHash = await computeVerificationKeyHash(privateFunctionArtifact);
60
-
61
- const classRegistry = ContractClassRegistryContract.at(wallet);
62
- const bytecode = bufferAsFields(
63
- privateFunctionArtifact.bytecode,
64
- MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
65
- );
66
- return classRegistry.methods
67
- .broadcast_private_function(
68
- contractClass.id,
69
- artifactMetadataHash,
70
- utilityFunctionsTreeRoot,
71
- privateFunctionTreeSiblingPath,
72
- privateFunctionTreeLeafIndex,
73
- padArrayEnd(artifactTreeSiblingPath, Fr.ZERO, ARTIFACT_FUNCTION_TREE_MAX_HEIGHT),
74
- artifactTreeLeafIndex,
75
- // eslint-disable-next-line camelcase
76
- { selector, metadata_hash: functionMetadataHash, vk_hash: vkHash },
77
- )
78
- .with({
79
- capsules: [
80
- new Capsule(
81
- ProtocolContractAddress.ContractClassRegistry,
82
- new Fr(CONTRACT_CLASS_REGISTRY_BYTECODE_CAPSULE_SLOT),
83
- bytecode,
84
- ),
85
- ],
86
- });
87
- }
88
-
89
- /**
90
- * Sets up a call to broadcast a utility function's bytecode via the ClassRegistry contract.
91
- * Note that this is not required for users to call the function, but is rather a convenience to make
92
- * this code publicly available so dapps or wallets do not need to redistribute it.
93
- * @param wallet - Wallet to send the transaction.
94
- * @param artifact - Contract artifact that contains the function to be broadcast.
95
- * @param selector - Selector of the function to be broadcast.
96
- * @returns A ContractFunctionInteraction object that can be used to send the transaction.
97
- */
98
- export async function broadcastUtilityFunction(
99
- wallet: Wallet,
100
- artifact: ContractArtifact,
101
- selector: FunctionSelector,
102
- ): Promise<ContractFunctionInteraction> {
103
- const contractClass = await getContractClassFromArtifact(artifact);
104
- const utilityFunctions = artifact.functions.filter(fn => fn.functionType === FunctionType.UTILITY);
105
- const utilityFunctionsAndSelectors = await Promise.all(
106
- utilityFunctions.map(async fn => ({
107
- f: fn,
108
- selector: await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters),
109
- })),
110
- );
111
- const utilityFunctionArtifact = utilityFunctionsAndSelectors.find(fn => selector.equals(fn.selector))?.f;
112
- if (!utilityFunctionArtifact) {
113
- throw new Error(`Utility function with selector ${selector.toString()} not found`);
114
- }
115
-
116
- const {
117
- artifactMetadataHash,
118
- artifactTreeLeafIndex,
119
- artifactTreeSiblingPath,
120
- functionMetadataHash,
121
- privateFunctionsArtifactTreeRoot,
122
- } = await createUtilityFunctionMembershipProof(selector, artifact);
123
-
124
- const classRegistry = ContractClassRegistryContract.at(wallet);
125
- const bytecode = bufferAsFields(
126
- utilityFunctionArtifact.bytecode,
127
- MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
128
- );
129
- return classRegistry.methods
130
- .broadcast_utility_function(
131
- contractClass.id,
132
- artifactMetadataHash,
133
- privateFunctionsArtifactTreeRoot,
134
- padArrayEnd(artifactTreeSiblingPath, Fr.ZERO, ARTIFACT_FUNCTION_TREE_MAX_HEIGHT),
135
- artifactTreeLeafIndex,
136
- // eslint-disable-next-line camelcase
137
- { selector, metadata_hash: functionMetadataHash },
138
- )
139
- .with({
140
- capsules: [
141
- new Capsule(
142
- ProtocolContractAddress.ContractClassRegistry,
143
- new Fr(CONTRACT_CLASS_REGISTRY_BYTECODE_CAPSULE_SLOT),
144
- bytecode,
145
- ),
146
- ],
147
- });
148
- }