@aztec/aztec.js 0.0.1-commit.d431d1c → 0.0.1-commit.d6f2b3f94

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 (125) hide show
  1. package/dest/api/block.d.ts +2 -2
  2. package/dest/api/block.d.ts.map +1 -1
  3. package/dest/api/block.js +1 -1
  4. package/dest/api/contract.d.ts +18 -12
  5. package/dest/api/contract.d.ts.map +1 -1
  6. package/dest/api/contract.js +16 -10
  7. package/dest/api/deployment.d.ts +1 -2
  8. package/dest/api/deployment.d.ts.map +1 -1
  9. package/dest/api/deployment.js +0 -1
  10. package/dest/api/events.d.ts +10 -6
  11. package/dest/api/events.d.ts.map +1 -1
  12. package/dest/api/events.js +30 -20
  13. package/dest/api/fields.d.ts +2 -1
  14. package/dest/api/fields.d.ts.map +1 -1
  15. package/dest/api/fields.js +1 -0
  16. package/dest/api/keys.d.ts +1 -1
  17. package/dest/api/keys.js +1 -1
  18. package/dest/api/node.d.ts +8 -4
  19. package/dest/api/node.d.ts.map +1 -1
  20. package/dest/api/node.js +7 -3
  21. package/dest/api/tx.d.ts +2 -2
  22. package/dest/api/tx.d.ts.map +1 -1
  23. package/dest/api/tx.js +1 -1
  24. package/dest/api/wallet.d.ts +3 -2
  25. package/dest/api/wallet.d.ts.map +1 -1
  26. package/dest/api/wallet.js +2 -1
  27. package/dest/contract/base_contract_interaction.d.ts +8 -10
  28. package/dest/contract/base_contract_interaction.d.ts.map +1 -1
  29. package/dest/contract/base_contract_interaction.js +5 -17
  30. package/dest/contract/contract_function_interaction.d.ts +3 -12
  31. package/dest/contract/contract_function_interaction.d.ts.map +1 -1
  32. package/dest/contract/contract_function_interaction.js +6 -6
  33. package/dest/contract/deploy_method.d.ts +63 -16
  34. package/dest/contract/deploy_method.d.ts.map +1 -1
  35. package/dest/contract/deploy_method.js +36 -19
  36. package/dest/contract/interaction_options.d.ts +42 -5
  37. package/dest/contract/interaction_options.d.ts.map +1 -1
  38. package/dest/contract/interaction_options.js +8 -1
  39. package/dest/contract/protocol_contracts/auth-registry.d.ts +1 -10
  40. package/dest/contract/protocol_contracts/auth-registry.d.ts.map +1 -1
  41. package/dest/contract/protocol_contracts/auth-registry.js +61 -479
  42. package/dest/contract/protocol_contracts/contract-class-registry.d.ts +2 -22
  43. package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -1
  44. package/dest/contract/protocol_contracts/contract-class-registry.js +2 -672
  45. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +2 -11
  46. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -1
  47. package/dest/contract/protocol_contracts/contract-instance-registry.js +80 -486
  48. package/dest/contract/protocol_contracts/fee-juice.d.ts +1 -10
  49. package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -1
  50. package/dest/contract/protocol_contracts/fee-juice.js +0 -414
  51. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts +3 -3
  52. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts.map +1 -1
  53. package/dest/contract/protocol_contracts/multi-call-entrypoint.js +23 -14
  54. package/dest/contract/protocol_contracts/public-checks.d.ts +3 -3
  55. package/dest/contract/protocol_contracts/public-checks.d.ts.map +1 -1
  56. package/dest/contract/protocol_contracts/public-checks.js +23 -22
  57. package/dest/contract/wait_for_proven.js +1 -1
  58. package/dest/contract/wait_opts.d.ts +16 -0
  59. package/dest/contract/wait_opts.d.ts.map +1 -0
  60. package/dest/contract/wait_opts.js +5 -0
  61. package/dest/fee/fee_juice_payment_method_with_claim.js +6 -6
  62. package/dest/fee/private_fee_payment_method.js +10 -10
  63. package/dest/fee/public_fee_payment_method.js +10 -10
  64. package/dest/fee/sponsored_fee_payment.js +3 -3
  65. package/dest/utils/authwit.d.ts +6 -6
  66. package/dest/utils/authwit.d.ts.map +1 -1
  67. package/dest/utils/authwit.js +2 -6
  68. package/dest/utils/node.d.ts +12 -1
  69. package/dest/utils/node.d.ts.map +1 -1
  70. package/dest/utils/node.js +46 -0
  71. package/dest/wallet/capabilities.d.ts +444 -0
  72. package/dest/wallet/capabilities.d.ts.map +1 -0
  73. package/dest/wallet/capabilities.js +3 -0
  74. package/dest/wallet/deploy_account_method.d.ts +19 -5
  75. package/dest/wallet/deploy_account_method.d.ts.map +1 -1
  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 +1491 -92
  80. package/dest/wallet/wallet.d.ts.map +1 -1
  81. package/dest/wallet/wallet.js +158 -25
  82. package/package.json +19 -10
  83. package/src/api/block.ts +1 -1
  84. package/src/api/contract.ts +24 -9
  85. package/src/api/deployment.ts +0 -1
  86. package/src/api/events.ts +35 -27
  87. package/src/api/fields.ts +1 -0
  88. package/src/api/keys.ts +2 -2
  89. package/src/api/node.ts +7 -3
  90. package/src/api/tx.ts +2 -0
  91. package/src/api/wallet.ts +47 -1
  92. package/src/contract/base_contract_interaction.ts +27 -15
  93. package/src/contract/contract_function_interaction.ts +13 -6
  94. package/src/contract/deploy_method.ts +115 -23
  95. package/src/contract/interaction_options.ts +49 -4
  96. package/src/contract/protocol_contracts/auth-registry.ts +37 -240
  97. package/src/contract/protocol_contracts/contract-class-registry.ts +1 -347
  98. package/src/contract/protocol_contracts/contract-instance-registry.ts +34 -234
  99. package/src/contract/protocol_contracts/fee-juice.ts +0 -202
  100. package/src/contract/protocol_contracts/multi-call-entrypoint.ts +6 -12
  101. package/src/contract/protocol_contracts/public-checks.ts +6 -14
  102. package/src/contract/wait_for_proven.ts +1 -1
  103. package/src/contract/wait_opts.ts +21 -0
  104. package/src/fee/fee_juice_payment_method_with_claim.ts +5 -5
  105. package/src/fee/private_fee_payment_method.ts +7 -7
  106. package/src/fee/public_fee_payment_method.ts +8 -8
  107. package/src/fee/sponsored_fee_payment.ts +3 -3
  108. package/src/utils/authwit.ts +16 -4
  109. package/src/utils/node.ts +62 -0
  110. package/src/wallet/capabilities.ts +491 -0
  111. package/src/wallet/deploy_account_method.ts +19 -4
  112. package/src/wallet/index.ts +1 -0
  113. package/src/wallet/wallet.ts +213 -46
  114. package/dest/contract/deploy_sent_tx.d.ts +0 -48
  115. package/dest/contract/deploy_sent_tx.d.ts.map +0 -1
  116. package/dest/contract/deploy_sent_tx.js +0 -46
  117. package/dest/contract/sent_tx.d.ts +0 -50
  118. package/dest/contract/sent_tx.d.ts.map +0 -1
  119. package/dest/contract/sent_tx.js +0 -90
  120. package/dest/deployment/broadcast_function.d.ts +0 -24
  121. package/dest/deployment/broadcast_function.d.ts.map +0 -1
  122. package/dest/deployment/broadcast_function.js +0 -74
  123. package/src/contract/deploy_sent_tx.ts +0 -75
  124. package/src/contract/sent_tx.ts +0 -129
  125. package/src/deployment/broadcast_function.ts +0 -148
@@ -2,7 +2,7 @@ import { retryUntil } from '@aztec/foundation/retry';
2
2
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
3
3
  import type { TxReceipt } from '@aztec/stdlib/tx';
4
4
 
5
- import { DefaultWaitOpts } from './sent_tx.js';
5
+ import { DefaultWaitOpts } from './wait_opts.js';
6
6
 
7
7
  /**
8
8
  * Options for waiting for a transaction to be proven.
@@ -0,0 +1,21 @@
1
+ import type { TxStatus } from '@aztec/stdlib/tx';
2
+
3
+ /** Options related to waiting for a tx. */
4
+ export type WaitOpts = {
5
+ /** The amount of time to ignore TxStatus.DROPPED receipts (in seconds) due to the presumption that it is being propagated by the p2p network. Defaults to 5. */
6
+ ignoreDroppedReceiptsFor?: number;
7
+ /** The maximum time (in seconds) to wait for the transaction to be mined. Defaults to 60. */
8
+ timeout?: number;
9
+ /** The time interval (in seconds) between retries to fetch the transaction receipt. Defaults to 1. */
10
+ interval?: number;
11
+ /** Whether to accept a revert as a status code for the tx when waiting for it. If false, will throw if the tx reverts. */
12
+ dontThrowOnRevert?: boolean;
13
+ /** The minimum inclusion status to wait for. If set, waits until the receipt reaches this status or higher. Defaults to CHECKPOINTED. */
14
+ waitForStatus?: TxStatus;
15
+ };
16
+
17
+ export const DefaultWaitOpts: WaitOpts = {
18
+ ignoreDroppedReceiptsFor: 5,
19
+ timeout: 300,
20
+ interval: 1,
21
+ };
@@ -1,6 +1,6 @@
1
1
  import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
3
- import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
3
+ import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
4
4
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
5
  import type { GasSettings } from '@aztec/stdlib/gas';
6
6
  import { ExecutionPayload } from '@aztec/stdlib/tx';
@@ -27,10 +27,11 @@ export class FeeJuicePaymentMethodWithClaim implements FeePaymentMethod {
27
27
 
28
28
  return new ExecutionPayload(
29
29
  [
30
- {
31
- to: ProtocolContractAddress.FeeJuice,
30
+ FunctionCall.from({
32
31
  name: 'claim_and_end_setup',
32
+ to: ProtocolContractAddress.FeeJuice,
33
33
  selector,
34
+ type: FunctionType.PRIVATE,
34
35
  hideMsgSender: false,
35
36
  isStatic: false,
36
37
  args: [
@@ -40,8 +41,7 @@ export class FeeJuicePaymentMethodWithClaim implements FeePaymentMethod {
40
41
  new Fr(this.claim.messageLeafIndex),
41
42
  ],
42
43
  returnTypes: [],
43
- type: FunctionType.PRIVATE,
44
- },
44
+ }),
45
45
  ],
46
46
  [],
47
47
  [],
@@ -1,5 +1,5 @@
1
1
  import { Fr } from '@aztec/foundation/curves/bn254';
2
- import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
2
+ import { type FunctionAbi, FunctionCall, FunctionSelector, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
3
3
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import type { GasSettings } from '@aztec/stdlib/gas';
5
5
  import { ExecutionPayload } from '@aztec/stdlib/tx';
@@ -102,21 +102,21 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
102
102
 
103
103
  const witness = await this.wallet.createAuthWit(this.sender, {
104
104
  caller: this.paymentContract,
105
- call: {
105
+ call: FunctionCall.from({
106
106
  name: 'transfer_to_public',
107
- args: [this.sender.toField(), this.paymentContract.toField(), maxFee, txNonce],
107
+ to: await this.getAsset(),
108
108
  selector: await FunctionSelector.fromSignature('transfer_to_public((Field),(Field),u128,Field)'),
109
109
  type: FunctionType.PRIVATE,
110
110
  hideMsgSender: false,
111
111
  isStatic: false,
112
- to: await this.getAsset(),
112
+ args: [this.sender.toField(), this.paymentContract.toField(), maxFee, txNonce],
113
113
  returnTypes: [],
114
- },
114
+ }),
115
115
  });
116
116
 
117
117
  return new ExecutionPayload(
118
118
  [
119
- {
119
+ FunctionCall.from({
120
120
  name: 'fee_entrypoint_private',
121
121
  to: this.paymentContract,
122
122
  selector: await FunctionSelector.fromSignature('fee_entrypoint_private(u128,Field)'),
@@ -125,7 +125,7 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
125
125
  isStatic: false,
126
126
  args: [maxFee, txNonce],
127
127
  returnTypes: [],
128
- },
128
+ }),
129
129
  ],
130
130
  [witness],
131
131
  [],
@@ -1,5 +1,5 @@
1
1
  import { Fr } from '@aztec/foundation/curves/bn254';
2
- import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
2
+ import { type FunctionAbi, FunctionCall, FunctionSelector, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
3
3
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import { GasSettings } from '@aztec/stdlib/gas';
5
5
  import { ExecutionPayload } from '@aztec/stdlib/tx';
@@ -94,16 +94,16 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
94
94
 
95
95
  const intent = {
96
96
  caller: this.paymentContract,
97
- call: {
97
+ call: FunctionCall.from({
98
98
  name: 'transfer_in_public',
99
- args: [this.sender.toField(), this.paymentContract.toField(), maxFee, txNonce],
99
+ to: await this.getAsset(),
100
100
  selector: await FunctionSelector.fromSignature('transfer_in_public((Field),(Field),u128,Field)'),
101
101
  type: FunctionType.PUBLIC,
102
- isStatic: false,
103
102
  hideMsgSender: false /** The target function performs an authwit check, so msg_sender is needed */,
104
- to: await this.getAsset(),
103
+ isStatic: false,
104
+ args: [this.sender.toField(), this.paymentContract.toField(), maxFee, txNonce],
105
105
  returnTypes: [],
106
- },
106
+ }),
107
107
  };
108
108
 
109
109
  const setPublicAuthWitInteraction = await SetPublicAuthwitContractInteraction.create(
@@ -116,7 +116,7 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
116
116
  return new ExecutionPayload(
117
117
  [
118
118
  ...(await setPublicAuthWitInteraction.request()).calls,
119
- {
119
+ FunctionCall.from({
120
120
  name: 'fee_entrypoint_public',
121
121
  to: this.paymentContract,
122
122
  selector: await FunctionSelector.fromSignature('fee_entrypoint_public(u128,Field)'),
@@ -125,7 +125,7 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
125
125
  isStatic: false,
126
126
  args: [maxFee, txNonce],
127
127
  returnTypes: [],
128
- },
128
+ }),
129
129
  ],
130
130
  [],
131
131
  [],
@@ -1,5 +1,5 @@
1
1
  import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
2
- import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
2
+ import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
3
3
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import type { GasSettings } from '@aztec/stdlib/gas';
5
5
  import { ExecutionPayload } from '@aztec/stdlib/tx';
@@ -22,7 +22,7 @@ export class SponsoredFeePaymentMethod implements FeePaymentMethod {
22
22
  async getExecutionPayload(): Promise<ExecutionPayload> {
23
23
  return new ExecutionPayload(
24
24
  [
25
- {
25
+ FunctionCall.from({
26
26
  name: 'sponsor_unconditionally',
27
27
  to: this.paymentContract,
28
28
  selector: await FunctionSelector.fromSignature('sponsor_unconditionally()'),
@@ -31,7 +31,7 @@ export class SponsoredFeePaymentMethod implements FeePaymentMethod {
31
31
  isStatic: false,
32
32
  args: [],
33
33
  returnTypes: [],
34
- },
34
+ }),
35
35
  ],
36
36
  [],
37
37
  [],
@@ -5,16 +5,18 @@ import { type ABIParameterVisibility, type FunctionAbi, type FunctionCall, Funct
5
5
  import { AuthWitness, computeInnerAuthWitHash, computeOuterAuthWitHash } from '@aztec/stdlib/auth-witness';
6
6
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
7
7
  import { computeVarArgsHash } from '@aztec/stdlib/hash';
8
- import type { TxProfileResult } from '@aztec/stdlib/tx';
8
+ import type { TxHash, TxProfileResult, TxReceipt } from '@aztec/stdlib/tx';
9
9
 
10
10
  import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
11
11
  import type {
12
+ InteractionWaitOptions,
12
13
  ProfileInteractionOptions,
13
14
  SendInteractionOptions,
15
+ SendInteractionOptionsWithoutWait,
16
+ SendReturn,
14
17
  SimulateInteractionOptions,
15
18
  SimulationReturn,
16
19
  } from '../contract/interaction_options.js';
17
- import type { SentTx } from '../contract/sent_tx.js';
18
20
  import type { Wallet } from '../wallet/index.js';
19
21
 
20
22
  /** Intent with an inner hash */
@@ -286,9 +288,19 @@ export class SetPublicAuthwitContractInteraction extends ContractFunctionInterac
286
288
  * Overrides the send method, adding the sender of the authwit (authorizer) as from
287
289
  * and preventing misuse
288
290
  * @param options - An optional object containing 'fee' options information
289
- * @returns A SentTx instance for tracking the transaction status and information.
291
+ * @returns A TxReceipt (if wait is true/undefined) or TxHash (if wait is false)
290
292
  */
291
- public override send(options: Omit<SendInteractionOptions, 'from'> = {}): SentTx {
293
+ // Overload for when wait is not specified at all - returns TxReceipt
294
+ public override send(options?: Omit<SendInteractionOptionsWithoutWait, 'from'>): Promise<TxReceipt>;
295
+ // Generic overload for explicit wait values
296
+ // eslint-disable-next-line jsdoc/require-jsdoc
297
+ public override send<W extends InteractionWaitOptions>(
298
+ options?: Omit<SendInteractionOptions<W>, 'from'>,
299
+ ): Promise<SendReturn<W>>;
300
+ // eslint-disable-next-line jsdoc/require-jsdoc
301
+ public override send(
302
+ options?: Omit<SendInteractionOptions<InteractionWaitOptions>, 'from'>,
303
+ ): Promise<TxReceipt | TxHash> {
292
304
  return super.send({ ...options, from: this.from });
293
305
  }
294
306
 
package/src/utils/node.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import type { Logger } from '@aztec/foundation/log';
2
2
  import { retryUntil } from '@aztec/foundation/retry';
3
3
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
4
+ import type { TxHash, TxReceipt } from '@aztec/stdlib/tx';
5
+ import { SortedTxStatuses, TxStatus } from '@aztec/stdlib/tx';
6
+
7
+ import { DefaultWaitOpts, type WaitOpts } from '../contract/wait_opts.js';
4
8
 
5
9
  export const waitForNode = async (node: AztecNode, logger?: Logger) => {
6
10
  await retryUntil(async () => {
@@ -16,4 +20,62 @@ export const waitForNode = async (node: AztecNode, logger?: Logger) => {
16
20
  }, 'RPC Get Node Info');
17
21
  };
18
22
 
23
+ /** Returns true if the receipt status is at least the desired status level. */
24
+ function hasReachedStatus(receipt: TxReceipt, desiredStatus: TxStatus): boolean {
25
+ return SortedTxStatuses.indexOf(receipt.status) >= SortedTxStatuses.indexOf(desiredStatus);
26
+ }
27
+
28
+ /**
29
+ * Waits for a transaction to be mined and returns its receipt.
30
+ * @param node - The Aztec node to query for transaction status
31
+ * @param txHash - The hash of the transaction to wait for
32
+ * @param opts - Optional configuration for waiting behavior
33
+ * @returns The transaction receipt
34
+ * @throws If the transaction fails and dontThrowOnRevert is not set
35
+ */
36
+ export async function waitForTx(node: AztecNode, txHash: TxHash, opts?: WaitOpts): Promise<TxReceipt> {
37
+ const startTime = Date.now();
38
+ const ignoreDroppedReceiptsFor = opts?.ignoreDroppedReceiptsFor ?? DefaultWaitOpts.ignoreDroppedReceiptsFor;
39
+ const waitForStatus = opts?.waitForStatus ?? TxStatus.CHECKPOINTED;
40
+
41
+ const receipt = await retryUntil(
42
+ async () => {
43
+ const txReceipt = await node.getTxReceipt(txHash);
44
+ // If receipt is not yet available, try again
45
+ if (txReceipt.isPending()) {
46
+ return undefined;
47
+ }
48
+ // If the tx was "dropped", either return it or ignore based on timing.
49
+ // We can ignore it at first because the transaction may have been sent to node 1, and now we're asking node 2 for the receipt.
50
+ // If we don't allow a short grace period, we could incorrectly return a TxReceipt with status DROPPED.
51
+ if (txReceipt.isDropped()) {
52
+ const elapsedSeconds = (Date.now() - startTime) / 1000;
53
+ if (!ignoreDroppedReceiptsFor || elapsedSeconds > ignoreDroppedReceiptsFor) {
54
+ return txReceipt;
55
+ }
56
+ return undefined;
57
+ }
58
+ // Check if the receipt has reached the desired status level
59
+ if (!hasReachedStatus(txReceipt, waitForStatus)) {
60
+ return undefined;
61
+ }
62
+ return txReceipt;
63
+ },
64
+ 'isMined',
65
+ opts?.timeout ?? DefaultWaitOpts.timeout,
66
+ opts?.interval ?? DefaultWaitOpts.interval,
67
+ );
68
+
69
+ if (!receipt.isMined()) {
70
+ throw new Error(`Transaction ${txHash.toString()} was ${receipt.status}. Reason: ${receipt.error ?? 'unknown'}`);
71
+ }
72
+ if (!receipt.hasExecutionSucceeded() && !opts?.dontThrowOnRevert) {
73
+ throw new Error(
74
+ `Transaction ${txHash.toString()} reverted: ${receipt.executionResult}. Reason: ${receipt.error ?? 'unknown'}`,
75
+ );
76
+ }
77
+
78
+ return receipt;
79
+ }
80
+
19
81
  export { createAztecNodeClient, type AztecNode } from '@aztec/stdlib/interfaces/client';