@aztec/wallet-sdk 0.0.1-commit.d3ec352c → 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 (81) hide show
  1. package/README.md +228 -331
  2. package/dest/base-wallet/base_wallet.d.ts +53 -13
  3. package/dest/base-wallet/base_wallet.d.ts.map +1 -1
  4. package/dest/base-wallet/base_wallet.js +102 -27
  5. package/dest/base-wallet/index.d.ts +2 -1
  6. package/dest/base-wallet/index.d.ts.map +1 -1
  7. package/dest/base-wallet/index.js +1 -0
  8. package/dest/base-wallet/utils.d.ts +48 -0
  9. package/dest/base-wallet/utils.d.ts.map +1 -0
  10. package/dest/base-wallet/utils.js +128 -0
  11. package/dest/crypto.d.ts +192 -0
  12. package/dest/crypto.d.ts.map +1 -0
  13. package/dest/crypto.js +394 -0
  14. package/dest/emoji_alphabet.d.ts +35 -0
  15. package/dest/emoji_alphabet.d.ts.map +1 -0
  16. package/dest/emoji_alphabet.js +299 -0
  17. package/dest/extension/handlers/background_connection_handler.d.ts +158 -0
  18. package/dest/extension/handlers/background_connection_handler.d.ts.map +1 -0
  19. package/dest/extension/handlers/background_connection_handler.js +258 -0
  20. package/dest/extension/handlers/content_script_connection_handler.d.ts +56 -0
  21. package/dest/extension/handlers/content_script_connection_handler.d.ts.map +1 -0
  22. package/dest/extension/handlers/content_script_connection_handler.js +174 -0
  23. package/dest/extension/handlers/index.d.ts +12 -0
  24. package/dest/extension/handlers/index.d.ts.map +1 -0
  25. package/dest/extension/handlers/index.js +10 -0
  26. package/dest/extension/handlers/internal_message_types.d.ts +63 -0
  27. package/dest/extension/handlers/internal_message_types.d.ts.map +1 -0
  28. package/dest/extension/handlers/internal_message_types.js +22 -0
  29. package/dest/extension/provider/extension_provider.d.ts +107 -0
  30. package/dest/extension/provider/extension_provider.d.ts.map +1 -0
  31. package/dest/extension/provider/extension_provider.js +160 -0
  32. package/dest/extension/provider/extension_wallet.d.ts +131 -0
  33. package/dest/extension/provider/extension_wallet.d.ts.map +1 -0
  34. package/dest/extension/provider/extension_wallet.js +271 -0
  35. package/dest/extension/provider/index.d.ts +3 -0
  36. package/dest/extension/provider/index.d.ts.map +1 -0
  37. package/dest/manager/index.d.ts +2 -7
  38. package/dest/manager/index.d.ts.map +1 -1
  39. package/dest/manager/index.js +0 -4
  40. package/dest/manager/types.d.ts +108 -5
  41. package/dest/manager/types.d.ts.map +1 -1
  42. package/dest/manager/types.js +17 -1
  43. package/dest/manager/wallet_manager.d.ts +50 -7
  44. package/dest/manager/wallet_manager.d.ts.map +1 -1
  45. package/dest/manager/wallet_manager.js +178 -29
  46. package/dest/types.d.ts +123 -0
  47. package/dest/types.d.ts.map +1 -0
  48. package/dest/types.js +11 -0
  49. package/package.json +20 -11
  50. package/src/base-wallet/base_wallet.ts +157 -53
  51. package/src/base-wallet/index.ts +1 -0
  52. package/src/base-wallet/utils.ts +229 -0
  53. package/src/crypto.ts +499 -0
  54. package/src/emoji_alphabet.ts +317 -0
  55. package/src/extension/handlers/background_connection_handler.ts +423 -0
  56. package/src/extension/handlers/content_script_connection_handler.ts +246 -0
  57. package/src/extension/handlers/index.ts +25 -0
  58. package/src/extension/handlers/internal_message_types.ts +69 -0
  59. package/src/extension/provider/extension_provider.ts +233 -0
  60. package/src/extension/provider/extension_wallet.ts +321 -0
  61. package/src/extension/provider/index.ts +7 -0
  62. package/src/manager/index.ts +3 -15
  63. package/src/manager/types.ts +112 -4
  64. package/src/manager/wallet_manager.ts +204 -31
  65. package/src/types.ts +132 -0
  66. package/dest/providers/extension/extension_provider.d.ts +0 -17
  67. package/dest/providers/extension/extension_provider.d.ts.map +0 -1
  68. package/dest/providers/extension/extension_provider.js +0 -56
  69. package/dest/providers/extension/extension_wallet.d.ts +0 -23
  70. package/dest/providers/extension/extension_wallet.d.ts.map +0 -1
  71. package/dest/providers/extension/extension_wallet.js +0 -96
  72. package/dest/providers/extension/index.d.ts +0 -4
  73. package/dest/providers/extension/index.d.ts.map +0 -1
  74. package/dest/providers/types.d.ts +0 -67
  75. package/dest/providers/types.d.ts.map +0 -1
  76. package/dest/providers/types.js +0 -3
  77. package/src/providers/extension/extension_provider.ts +0 -72
  78. package/src/providers/extension/extension_wallet.ts +0 -124
  79. package/src/providers/extension/index.ts +0 -3
  80. package/src/providers/types.ts +0 -71
  81. /package/dest/{providers/extension → extension/provider}/index.js +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD;;;GAGG;AACH,oBAAY,iBAAiB;IAC3B,kDAAkD;IAClD,SAAS,2BAA2B;IACpC,uCAAuC;IACvC,kBAAkB,oCAAoC;IACtD,sEAAsE;IACtE,UAAU,4BAA4B;IACtC,oDAAoD;IACpD,oBAAoB,sCAAsC;IAC1D,qDAAqD;IACrD,qBAAqB,uCAAuC;CAC7D;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,uCAAuC;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qBAAqB;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAoB,SAAQ,UAAU;IACrD,gEAAgE;IAChE,SAAS,EAAE,iBAAiB,CAAC;IAC7B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAC;IAClB,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,wBAAwB;IACxB,SAAS,EAAE,SAAS,CAAC;IACrB,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,kCAAkC;IAClC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,6BAA6B;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,uCAAuC;IACvC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,iCAAiC;IACjC,IAAI,EAAE,iBAAiB,CAAC,SAAS,CAAC;IAClC,iBAAiB;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,iEAAiE;IACjE,SAAS,EAAE,SAAS,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,0CAA0C;IAC1C,IAAI,EAAE,iBAAiB,CAAC,kBAAkB,CAAC;IAC3C,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,+BAA+B;IAC/B,UAAU,EAAE,UAAU,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,mBAAmB;IACnB,IAAI,EAAE,iBAAiB,CAAC,oBAAoB,CAAC;IAC7C,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,SAAS,EAAE,iBAAiB,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,mBAAmB;IACnB,IAAI,EAAE,iBAAiB,CAAC,qBAAqB,CAAC;IAC9C,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,SAAS,EAAE,iBAAiB,CAAC;CAC9B"}
package/dest/types.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Message types for wallet SDK communication.
3
+ * All types are prefixed with 'aztec-wallet-' for namespacing.
4
+ */ export var WalletMessageType = /*#__PURE__*/ function(WalletMessageType) {
5
+ /** Discovery request to find installed wallets */ WalletMessageType["DISCOVERY"] = "aztec-wallet-discovery";
6
+ /** Discovery response from a wallet */ WalletMessageType["DISCOVERY_RESPONSE"] = "aztec-wallet-discovery-response";
7
+ /** Disconnect message (unencrypted control message, bidirectional) */ WalletMessageType["DISCONNECT"] = "aztec-wallet-disconnect";
8
+ /** Key exchange request sent over MessageChannel */ WalletMessageType["KEY_EXCHANGE_REQUEST"] = "aztec-wallet-key-exchange-request";
9
+ /** Key exchange response sent over MessageChannel */ WalletMessageType["KEY_EXCHANGE_RESPONSE"] = "aztec-wallet-key-exchange-response";
10
+ return WalletMessageType;
11
+ }({});
package/package.json CHANGED
@@ -1,17 +1,26 @@
1
1
  {
2
2
  "name": "@aztec/wallet-sdk",
3
3
  "homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/wallet-sdk",
4
- "version": "0.0.1-commit.d3ec352c",
4
+ "version": "0.0.1-commit.d6f2b3f94",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  "./base-wallet": "./dest/base-wallet/index.js",
8
- "./providers/extension": "./dest/providers/extension/index.js",
8
+ "./extension/handlers": "./dest/extension/handlers/index.js",
9
+ "./extension/provider": "./dest/extension/provider/index.js",
10
+ "./crypto": "./dest/crypto.js",
11
+ "./types": "./dest/types.js",
9
12
  "./manager": "./dest/manager/index.js"
10
13
  },
11
14
  "typedocOptions": {
12
15
  "entryPoints": [
13
- "./src/index.ts"
16
+ "./src/base-wallet/index.ts",
17
+ "./src/extension/handlers/index.ts",
18
+ "./src/extension/provider/index.ts",
19
+ "./src/crypto.ts",
20
+ "./src/types.ts",
21
+ "./src/manager/index.ts"
14
22
  ],
23
+ "name": "Wallet SDK",
15
24
  "tsconfig": "./tsconfig.json"
16
25
  },
17
26
  "scripts": {
@@ -62,19 +71,19 @@
62
71
  ]
63
72
  },
64
73
  "dependencies": {
65
- "@aztec/aztec.js": "0.0.1-commit.d3ec352c",
66
- "@aztec/constants": "0.0.1-commit.d3ec352c",
67
- "@aztec/entrypoints": "0.0.1-commit.d3ec352c",
68
- "@aztec/foundation": "0.0.1-commit.d3ec352c",
69
- "@aztec/pxe": "0.0.1-commit.d3ec352c",
70
- "@aztec/stdlib": "0.0.1-commit.d3ec352c"
74
+ "@aztec/aztec.js": "0.0.1-commit.d6f2b3f94",
75
+ "@aztec/constants": "0.0.1-commit.d6f2b3f94",
76
+ "@aztec/entrypoints": "0.0.1-commit.d6f2b3f94",
77
+ "@aztec/foundation": "0.0.1-commit.d6f2b3f94",
78
+ "@aztec/pxe": "0.0.1-commit.d6f2b3f94",
79
+ "@aztec/stdlib": "0.0.1-commit.d6f2b3f94"
71
80
  },
72
81
  "devDependencies": {
73
- "@aztec/noir-contracts.js": "0.0.1-commit.d3ec352c",
82
+ "@aztec/noir-contracts.js": "0.0.1-commit.d6f2b3f94",
74
83
  "@jest/globals": "^30.0.0",
75
84
  "@types/jest": "^30.0.0",
76
85
  "@types/node": "^22.15.17",
77
- "@typescript/native-preview": "7.0.0-dev.20251126.1",
86
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
78
87
  "jest": "^30.0.0",
79
88
  "jest-mock-extended": "^4.0.0",
80
89
  "resolve-typescript-plugin": "^2.0.1",
@@ -1,15 +1,20 @@
1
1
  import type { Account } from '@aztec/aztec.js/account';
2
2
  import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
3
+ import { type InteractionWaitOptions, NO_WAIT, type SendReturn } from '@aztec/aztec.js/contracts';
3
4
  import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
5
+ import { waitForTx } from '@aztec/aztec.js/node';
4
6
  import type {
5
7
  Aliased,
8
+ AppCapabilities,
6
9
  BatchResults,
7
- BatchableMethods,
8
10
  BatchedMethod,
11
+ PrivateEvent,
12
+ PrivateEventFilter,
9
13
  ProfileOptions,
10
14
  SendOptions,
11
15
  SimulateOptions,
12
16
  Wallet,
17
+ WalletCapabilities,
13
18
  } from '@aztec/aztec.js/wallet';
14
19
  import {
15
20
  GAS_ESTIMATION_DA_GAS_LIMIT,
@@ -19,10 +24,10 @@ import {
19
24
  } from '@aztec/constants';
20
25
  import { AccountFeePaymentMethodOptions, type DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
21
26
  import type { ChainInfo } from '@aztec/entrypoints/interfaces';
22
- import { Fr } from '@aztec/foundation/fields';
27
+ import { Fr } from '@aztec/foundation/curves/bn254';
23
28
  import { createLogger } from '@aztec/foundation/log';
24
29
  import type { FieldsOf } from '@aztec/foundation/types';
25
- import type { PXE } from '@aztec/pxe/server';
30
+ import type { PXE, PackedPrivateEvent } from '@aztec/pxe/server';
26
31
  import {
27
32
  type ContractArtifact,
28
33
  type EventMetadataDefinition,
@@ -32,27 +37,26 @@ import {
32
37
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
33
38
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
34
39
  import {
35
- type ContractClassMetadata,
36
40
  type ContractInstanceWithAddress,
37
- type ContractMetadata,
38
41
  computePartialAddress,
39
42
  getContractClassFromArtifact,
40
43
  } from '@aztec/stdlib/contract';
41
44
  import { SimulationError } from '@aztec/stdlib/errors';
42
45
  import { Gas, GasSettings } from '@aztec/stdlib/gas';
46
+ import { siloNullifier } from '@aztec/stdlib/hash';
43
47
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
44
- import type {
45
- TxExecutionRequest,
46
- TxHash,
47
- TxProfileResult,
48
- TxReceipt,
48
+ import {
49
+ type TxExecutionRequest,
50
+ type TxProfileResult,
49
51
  TxSimulationResult,
50
- UtilitySimulationResult,
52
+ type UtilitySimulationResult,
51
53
  } from '@aztec/stdlib/tx';
52
54
  import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
53
55
 
54
56
  import { inspect } from 'util';
55
57
 
58
+ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
59
+
56
60
  /**
57
61
  * Options to configure fee payment for a transaction
58
62
  */
@@ -74,7 +78,7 @@ export type FeeOptions = {
74
78
  export abstract class BaseWallet implements Wallet {
75
79
  protected log = createLogger('wallet-sdk:base_wallet');
76
80
 
77
- protected baseFeePadding = 0.5;
81
+ protected minFeePadding = 0.5;
78
82
  protected cancellableTransactions = false;
79
83
 
80
84
  // Protected because we want to force wallets to instantiate their own PXE.
@@ -119,20 +123,42 @@ export abstract class BaseWallet implements Wallet {
119
123
  ? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
120
124
  : executionPayload;
121
125
  const fromAccount = await this.getAccountFromAddress(from);
122
- return fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, executionOptions);
126
+ const chainInfo = await this.getChainInfo();
127
+ return fromAccount.createTxExecutionRequest(
128
+ finalExecutionPayload,
129
+ feeOptions.gasSettings,
130
+ chainInfo,
131
+ executionOptions,
132
+ );
123
133
  }
124
134
 
125
135
  public async createAuthWit(
126
136
  from: AztecAddress,
127
- messageHashOrIntent: Fr | IntentInnerHash | CallIntent,
137
+ messageHashOrIntent: IntentInnerHash | CallIntent,
128
138
  ): Promise<AuthWitness> {
129
139
  const account = await this.getAccountFromAddress(from);
130
- return account.createAuthWit(messageHashOrIntent);
140
+ const chainInfo = await this.getChainInfo();
141
+ return account.createAuthWit(messageHashOrIntent, chainInfo);
131
142
  }
132
143
 
133
- public async batch<const T extends readonly BatchedMethod<keyof BatchableMethods>[]>(
134
- methods: T,
135
- ): Promise<BatchResults<T>> {
144
+ /**
145
+ * Request capabilities from the wallet.
146
+ *
147
+ * This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
148
+ * Embedded wallets typically don't support capability-based authorization (no user authorization flow),
149
+ * while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
150
+ * friction by allowing apps to request permissions upfront.
151
+ *
152
+ * TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
153
+ * while the feature stabilizes.
154
+ *
155
+ * @param _manifest - Application capability manifest declaring what operations the app needs
156
+ */
157
+ public requestCapabilities(_manifest: AppCapabilities): Promise<WalletCapabilities> {
158
+ throw new Error('Not implemented');
159
+ }
160
+
161
+ public async batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>> {
136
162
  const results: any[] = [];
137
163
  for (const method of methods) {
138
164
  const { name, args } = method;
@@ -163,7 +189,7 @@ export abstract class BaseWallet implements Wallet {
163
189
  gasSettings?: Partial<FieldsOf<GasSettings>>,
164
190
  ): Promise<FeeOptions> {
165
191
  const maxFeesPerGas =
166
- gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentBaseFees()).mul(1 + this.baseFeePadding);
192
+ gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentMinFees()).mul(1 + this.minFeePadding);
167
193
  let accountFeePaymentMethodOptions;
168
194
  // The transaction does not include a fee payment method, so we set the flag
169
195
  // for the account to use its fee juice balance
@@ -225,7 +251,7 @@ export abstract class BaseWallet implements Wallet {
225
251
  artifact?: ContractArtifact,
226
252
  secretKey?: Fr,
227
253
  ): Promise<ContractInstanceWithAddress> {
228
- const { contractInstance: existingInstance } = await this.pxe.getContractMetadata(instance.address);
254
+ const existingInstance = await this.pxe.getContractInstance(instance.address);
229
255
 
230
256
  if (existingInstance) {
231
257
  // Instance already registered in the wallet
@@ -242,13 +268,12 @@ export abstract class BaseWallet implements Wallet {
242
268
  // Instance not registered yet
243
269
  if (!artifact) {
244
270
  // Try to get the artifact from the wallet's contract class storage
245
- const classMetadata = await this.pxe.getContractClassMetadata(instance.currentContractClassId, true);
246
- if (!classMetadata.artifact) {
271
+ artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
272
+ if (!artifact) {
247
273
  throw new Error(
248
274
  `Cannot register contract at ${instance.address.toString()}: artifact is required but not provided, and wallet does not have the artifact for contract class ${instance.currentContractClassId.toString()}`,
249
275
  );
250
276
  }
251
- artifact = classMetadata.artifact;
252
277
  }
253
278
  await this.pxe.registerContract({ artifact, instance });
254
279
  }
@@ -259,17 +284,67 @@ export abstract class BaseWallet implements Wallet {
259
284
  return instance;
260
285
  }
261
286
 
287
+ /**
288
+ * Simulates calls through the standard PXE path (account entrypoint).
289
+ * @param executionPayload - The execution payload to simulate.
290
+ * @param from - The sender address.
291
+ * @param feeOptions - Fee options for the transaction.
292
+ * @param skipTxValidation - Whether to skip tx validation.
293
+ * @param skipFeeEnforcement - Whether to skip fee enforcement.
294
+ */
295
+ protected async simulateViaEntrypoint(
296
+ executionPayload: ExecutionPayload,
297
+ from: AztecAddress,
298
+ feeOptions: FeeOptions,
299
+ skipTxValidation?: boolean,
300
+ skipFeeEnforcement?: boolean,
301
+ ) {
302
+ const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions);
303
+ return this.pxe.simulateTx(txRequest, true /* simulatePublic */, skipTxValidation, skipFeeEnforcement);
304
+ }
305
+
306
+ /**
307
+ * Simulates a transaction, optimizing leading public static calls by running them directly
308
+ * on the node while sending the remaining calls through the standard PXE path.
309
+ * Return values from both paths are merged back in original call order.
310
+ * @param executionPayload - The execution payload to simulate.
311
+ * @param opts - Simulation options (from address, fee settings, etc.).
312
+ * @returns The merged simulation result.
313
+ */
262
314
  async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
263
315
  const feeOptions = opts.fee?.estimateGas
264
316
  ? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings)
265
317
  : await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
266
- const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
267
- return this.pxe.simulateTx(
268
- txRequest,
269
- true /* simulatePublic */,
270
- opts?.skipTxValidation,
271
- opts?.skipFeeEnforcement ?? true,
272
- );
318
+ const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
319
+ const remainingPayload = { ...executionPayload, calls: remainingCalls };
320
+
321
+ const chainInfo = await this.getChainInfo();
322
+ const blockHeader = await this.pxe.getSyncedBlockHeader();
323
+
324
+ const [optimizedResults, normalResult] = await Promise.all([
325
+ optimizableCalls.length > 0
326
+ ? simulateViaNode(
327
+ this.aztecNode,
328
+ optimizableCalls,
329
+ opts.from,
330
+ chainInfo,
331
+ feeOptions.gasSettings,
332
+ blockHeader,
333
+ opts.skipFeeEnforcement ?? true,
334
+ )
335
+ : Promise.resolve([]),
336
+ remainingCalls.length > 0
337
+ ? this.simulateViaEntrypoint(
338
+ remainingPayload,
339
+ opts.from,
340
+ feeOptions,
341
+ opts.skipTxValidation,
342
+ opts.skipFeeEnforcement ?? true,
343
+ )
344
+ : Promise.resolve(null),
345
+ ]);
346
+
347
+ return buildMergedSimulationResult(optimizedResults, normalResult);
273
348
  }
274
349
 
275
350
  async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
@@ -278,7 +353,10 @@ export abstract class BaseWallet implements Wallet {
278
353
  return this.pxe.profileTx(txRequest, opts.profileMode, opts.skipProofGeneration ?? true);
279
354
  }
280
355
 
281
- async sendTx(executionPayload: ExecutionPayload, opts: SendOptions): Promise<TxHash> {
356
+ public async sendTx<W extends InteractionWaitOptions = undefined>(
357
+ executionPayload: ExecutionPayload,
358
+ opts: SendOptions<W>,
359
+ ): Promise<SendReturn<W>> {
282
360
  const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
283
361
  const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
284
362
  const provenTx = await this.pxe.proveTx(txRequest);
@@ -292,7 +370,15 @@ export abstract class BaseWallet implements Wallet {
292
370
  throw this.contextualizeError(err, inspect(tx));
293
371
  });
294
372
  this.log.info(`Sent transaction ${txHash}`);
295
- return txHash;
373
+
374
+ // If wait is NO_WAIT, return txHash immediately
375
+ if (opts.wait === NO_WAIT) {
376
+ return txHash as SendReturn<W>;
377
+ }
378
+
379
+ // Otherwise, wait for the full receipt (default behavior on wait: undefined)
380
+ const waitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
381
+ return (await waitForTx(this.aztecNode, txHash, waitOpts)) as SendReturn<W>;
296
382
  }
297
383
 
298
384
  protected contextualizeError(err: Error, ...context: string[]): Error {
@@ -313,30 +399,48 @@ export abstract class BaseWallet implements Wallet {
313
399
  return this.pxe.simulateUtility(call, authwits);
314
400
  }
315
401
 
316
- getContractClassMetadata(id: Fr, includeArtifact: boolean = false): Promise<ContractClassMetadata> {
317
- return this.pxe.getContractClassMetadata(id, includeArtifact);
318
- }
319
- getContractMetadata(address: AztecAddress): Promise<ContractMetadata> {
320
- return this.pxe.getContractMetadata(address);
321
- }
322
-
323
- getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
324
- return this.aztecNode.getTxReceipt(txHash);
325
- }
326
-
327
402
  async getPrivateEvents<T>(
328
- contractAddress: AztecAddress,
329
403
  eventDef: EventMetadataDefinition,
330
- from: number,
331
- limit: number,
332
- recipients: AztecAddress[] = [],
333
- ): Promise<T[]> {
334
- const events = await this.pxe.getPrivateEvents(contractAddress, eventDef.eventSelector, from, limit, recipients);
335
-
336
- const decodedEvents = events.map(
337
- (event: any /** PrivateEvent */): T => decodeFromAbi([eventDef.abiType], event.packedEvent) as T,
338
- );
404
+ eventFilter: PrivateEventFilter,
405
+ ): Promise<PrivateEvent<T>[]> {
406
+ const pxeEvents = await this.pxe.getPrivateEvents(eventDef.eventSelector, eventFilter);
407
+
408
+ const decodedEvents = pxeEvents.map((pxeEvent: PackedPrivateEvent): PrivateEvent<T> => {
409
+ return {
410
+ event: decodeFromAbi([eventDef.abiType], pxeEvent.packedEvent) as T,
411
+ metadata: {
412
+ l2BlockNumber: pxeEvent.l2BlockNumber,
413
+ l2BlockHash: pxeEvent.l2BlockHash,
414
+ txHash: pxeEvent.txHash,
415
+ },
416
+ };
417
+ });
339
418
 
340
419
  return decodedEvents;
341
420
  }
421
+
422
+ async getContractMetadata(address: AztecAddress) {
423
+ const instance = await this.pxe.getContractInstance(address);
424
+ const initNullifier = await siloNullifier(address, address.toField());
425
+ const publiclyRegisteredContract = await this.aztecNode.getContract(address);
426
+ const initNullifierMembershipWitness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
427
+ const isContractUpdated =
428
+ publiclyRegisteredContract &&
429
+ !publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
430
+ return {
431
+ instance: instance ?? undefined,
432
+ isContractInitialized: !!initNullifierMembershipWitness,
433
+ isContractPublished: !!publiclyRegisteredContract,
434
+ isContractUpdated: !!isContractUpdated,
435
+ updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined,
436
+ };
437
+ }
438
+
439
+ async getContractClassMetadata(id: Fr) {
440
+ const publiclyRegisteredContractClass = await this.aztecNode.getContractClass(id);
441
+ return {
442
+ isArtifactRegistered: !!(await this.pxe.getContractArtifact(id)),
443
+ isContractClassPubliclyRegistered: !!publiclyRegisteredContractClass,
444
+ };
445
+ }
342
446
  }
@@ -1 +1,2 @@
1
1
  export { BaseWallet, type FeeOptions } from './base_wallet.js';
2
+ export { simulateViaNode, buildMergedSimulationResult, extractOptimizablePublicStaticCalls } from './utils.js';
@@ -0,0 +1,229 @@
1
+ import type { AztecNode } from '@aztec/aztec.js/node';
2
+ import { MAX_ENQUEUED_CALLS_PER_CALL } from '@aztec/constants';
3
+ import type { ChainInfo } from '@aztec/entrypoints/interfaces';
4
+ import { makeTuple } from '@aztec/foundation/array';
5
+ import { Fr } from '@aztec/foundation/curves/bn254';
6
+ import type { Tuple } from '@aztec/foundation/serialize';
7
+ import { generateSimulatedProvingResult } from '@aztec/pxe/simulator';
8
+ import { type FunctionCall, FunctionSelector } from '@aztec/stdlib/abi';
9
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
10
+ import type { GasSettings } from '@aztec/stdlib/gas';
11
+ import {
12
+ ClaimedLengthArray,
13
+ CountedPublicCallRequest,
14
+ PrivateCircuitPublicInputs,
15
+ PublicCallRequest,
16
+ } from '@aztec/stdlib/kernel';
17
+ import { ChonkProof } from '@aztec/stdlib/proofs';
18
+ import {
19
+ type BlockHeader,
20
+ type ExecutionPayload,
21
+ HashedValues,
22
+ PrivateCallExecutionResult,
23
+ PrivateExecutionResult,
24
+ PublicSimulationOutput,
25
+ Tx,
26
+ TxContext,
27
+ TxSimulationResult,
28
+ } from '@aztec/stdlib/tx';
29
+
30
+ /**
31
+ * Splits an execution payload into a leading prefix of public static calls
32
+ * (eligible for direct node simulation) and the remaining calls.
33
+ *
34
+ * Only a leading run of public static calls is eligible for optimization.
35
+ * Any non-public-static call may enqueue public state mutations
36
+ * (e.g. private calls can enqueue public calls), so all calls that follow
37
+ * must go through the normal simulation path to see the correct state.
38
+ *
39
+ */
40
+ export function extractOptimizablePublicStaticCalls(payload: ExecutionPayload): {
41
+ /** Leading public static calls eligible for direct node simulation. */
42
+ optimizableCalls: FunctionCall[];
43
+ /** All remaining calls. */
44
+ remainingCalls: FunctionCall[];
45
+ } {
46
+ const splitIndex = payload.calls.findIndex(call => !call.isPublicStatic());
47
+ const boundary = splitIndex === -1 ? payload.calls.length : splitIndex;
48
+ return {
49
+ optimizableCalls: payload.calls.slice(0, boundary),
50
+ remainingCalls: payload.calls.slice(boundary),
51
+ };
52
+ }
53
+
54
+ /**
55
+ * Simulates a batch of public static calls by bypassing account entrypoint and private execution,
56
+ * directly constructing a minimal Tx and calling node.simulatePublicCalls.
57
+ *
58
+ * @param node - The Aztec node to simulate on.
59
+ * @param publicStaticCalls - Array of public static function calls (max MAX_ENQUEUED_CALLS_PER_CALL).
60
+ * @param from - The account address making the calls.
61
+ * @param chainInfo - Chain information (chainId and version).
62
+ * @param gasSettings - Gas settings for the transaction.
63
+ * @param blockHeader - Block header to use as anchor.
64
+ * @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
65
+ * @returns TxSimulationResult with public return values.
66
+ */
67
+ async function simulateBatchViaNode(
68
+ node: AztecNode,
69
+ publicStaticCalls: FunctionCall[],
70
+ from: AztecAddress,
71
+ chainInfo: ChainInfo,
72
+ gasSettings: GasSettings,
73
+ blockHeader: BlockHeader,
74
+ skipFeeEnforcement: boolean,
75
+ ): Promise<TxSimulationResult> {
76
+ const txContext = new TxContext(chainInfo.chainId, chainInfo.version, gasSettings);
77
+
78
+ const publicFunctionCalldata: HashedValues[] = [];
79
+ for (const call of publicStaticCalls) {
80
+ const calldata = await HashedValues.fromCalldata([call.selector.toField(), ...call.args]);
81
+ publicFunctionCalldata.push(calldata);
82
+ }
83
+
84
+ const publicCallRequests = makeTuple(MAX_ENQUEUED_CALLS_PER_CALL, i => {
85
+ const call = publicStaticCalls[i];
86
+ if (!call) {
87
+ return CountedPublicCallRequest.empty();
88
+ }
89
+ const publicCallRequest = new PublicCallRequest(from, call.to, call.isStatic, publicFunctionCalldata[i]!.hash);
90
+ // Counter starts at 1 (minRevertibleSideEffectCounter) so all calls are revertible
91
+ return new CountedPublicCallRequest(publicCallRequest, i + 1);
92
+ });
93
+
94
+ const publicCallRequestsArray: ClaimedLengthArray<CountedPublicCallRequest, typeof MAX_ENQUEUED_CALLS_PER_CALL> =
95
+ new ClaimedLengthArray(
96
+ publicCallRequests as Tuple<CountedPublicCallRequest, typeof MAX_ENQUEUED_CALLS_PER_CALL>,
97
+ publicStaticCalls.length,
98
+ );
99
+
100
+ const publicInputs = PrivateCircuitPublicInputs.from({
101
+ ...PrivateCircuitPublicInputs.empty(),
102
+ anchorBlockHeader: blockHeader,
103
+ txContext: txContext,
104
+ publicCallRequests: publicCallRequestsArray,
105
+ startSideEffectCounter: new Fr(0),
106
+ endSideEffectCounter: new Fr(publicStaticCalls.length + 1),
107
+ });
108
+
109
+ // Minimal entrypoint structure — no real private execution, just public call requests
110
+ const emptyEntrypoint = new PrivateCallExecutionResult(
111
+ Buffer.alloc(0),
112
+ Buffer.alloc(0),
113
+ new Map(),
114
+ publicInputs,
115
+ [],
116
+ new Map(),
117
+ [],
118
+ [],
119
+ [],
120
+ [],
121
+ [],
122
+ );
123
+
124
+ const privateResult = new PrivateExecutionResult(emptyEntrypoint, Fr.random(), publicFunctionCalldata);
125
+
126
+ const provingResult = await generateSimulatedProvingResult(
127
+ privateResult,
128
+ (_contractAddress: AztecAddress, _functionSelector: FunctionSelector) => Promise.resolve(''),
129
+ 1, // minRevertibleSideEffectCounter
130
+ );
131
+
132
+ provingResult.publicInputs.feePayer = from;
133
+
134
+ const tx = await Tx.create({
135
+ data: provingResult.publicInputs,
136
+ chonkProof: ChonkProof.empty(),
137
+ contractClassLogFields: [],
138
+ publicFunctionCalldata: publicFunctionCalldata,
139
+ });
140
+
141
+ const publicOutput = await node.simulatePublicCalls(tx, skipFeeEnforcement);
142
+
143
+ if (publicOutput.revertReason) {
144
+ throw publicOutput.revertReason;
145
+ }
146
+
147
+ return new TxSimulationResult(privateResult, provingResult.publicInputs, publicOutput, undefined);
148
+ }
149
+
150
+ /**
151
+ * Simulates public static calls by splitting them into batches of MAX_ENQUEUED_CALLS_PER_CALL
152
+ * and sending each batch directly to the node.
153
+ *
154
+ * @param node - The Aztec node to simulate on.
155
+ * @param publicStaticCalls - Array of public static function calls to optimize.
156
+ * @param from - The account address making the calls.
157
+ * @param chainInfo - Chain information (chainId and version).
158
+ * @param gasSettings - Gas settings for the transaction.
159
+ * @param blockHeader - Block header to use as anchor.
160
+ * @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
161
+ * @returns Array of TxSimulationResult, one per batch.
162
+ */
163
+ export async function simulateViaNode(
164
+ node: AztecNode,
165
+ publicStaticCalls: FunctionCall[],
166
+ from: AztecAddress,
167
+ chainInfo: ChainInfo,
168
+ gasSettings: GasSettings,
169
+ blockHeader: BlockHeader,
170
+ skipFeeEnforcement: boolean = true,
171
+ ): Promise<TxSimulationResult[]> {
172
+ const batches: FunctionCall[][] = [];
173
+
174
+ for (let i = 0; i < publicStaticCalls.length; i += MAX_ENQUEUED_CALLS_PER_CALL) {
175
+ batches.push(publicStaticCalls.slice(i, i + MAX_ENQUEUED_CALLS_PER_CALL));
176
+ }
177
+
178
+ const results: TxSimulationResult[] = [];
179
+
180
+ for (const batch of batches) {
181
+ const result = await simulateBatchViaNode(
182
+ node,
183
+ batch,
184
+ from,
185
+ chainInfo,
186
+ gasSettings,
187
+ blockHeader,
188
+ skipFeeEnforcement,
189
+ );
190
+ results.push(result);
191
+ }
192
+
193
+ return results;
194
+ }
195
+
196
+ /**
197
+ * Merges simulation results from the optimized (public static) and normal paths.
198
+ * Since optimized calls are always a leading prefix, return values are simply
199
+ * concatenated: optimized first, then normal.
200
+ * Stats are taken from the normal result only (the optimized path doesn't produce them).
201
+ *
202
+ * @param optimizedResults - Results from optimized public static call batches.
203
+ * @param normalResult - Result from normal simulation (null if all calls were optimized).
204
+ * @returns A single TxSimulationResult with return values in original call order.
205
+ */
206
+ export function buildMergedSimulationResult(
207
+ optimizedResults: TxSimulationResult[],
208
+ normalResult: TxSimulationResult | null,
209
+ ): TxSimulationResult {
210
+ const optimizedReturnValues = optimizedResults.flatMap(r => r.publicOutput?.publicReturnValues ?? []);
211
+ const normalReturnValues = normalResult?.publicOutput?.publicReturnValues ?? [];
212
+ const allReturnValues = [...optimizedReturnValues, ...normalReturnValues];
213
+
214
+ const baseResult = normalResult ?? optimizedResults[0];
215
+
216
+ const mergedPublicOutput: PublicSimulationOutput | undefined = baseResult.publicOutput
217
+ ? {
218
+ ...baseResult.publicOutput,
219
+ publicReturnValues: allReturnValues,
220
+ }
221
+ : undefined;
222
+
223
+ return new TxSimulationResult(
224
+ baseResult.privateExecutionResult,
225
+ baseResult.publicInputs,
226
+ mergedPublicOutput,
227
+ normalResult?.stats,
228
+ );
229
+ }