@walletmesh/aztec-rpc-wallet 0.3.0 → 0.4.0

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 (185) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +290 -228
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/client/aztec-dapp-wallet.d.ts +401 -0
  5. package/dist/client/aztec-dapp-wallet.d.ts.map +1 -0
  6. package/dist/client/aztec-dapp-wallet.js +705 -0
  7. package/dist/client/aztec-router-provider.d.ts +58 -0
  8. package/dist/client/aztec-router-provider.d.ts.map +1 -0
  9. package/dist/client/aztec-router-provider.js +62 -0
  10. package/dist/client/helpers.d.ts +44 -0
  11. package/dist/client/helpers.d.ts.map +1 -0
  12. package/dist/client/helpers.js +79 -0
  13. package/dist/client/register-serializers.d.ts +41 -0
  14. package/dist/client/register-serializers.d.ts.map +1 -0
  15. package/dist/client/register-serializers.js +97 -0
  16. package/dist/contractArtifactCache.d.ts +49 -32
  17. package/dist/contractArtifactCache.d.ts.map +1 -1
  18. package/dist/contractArtifactCache.js +47 -34
  19. package/dist/errors.d.ts +50 -8
  20. package/dist/errors.d.ts.map +1 -1
  21. package/dist/errors.js +50 -10
  22. package/dist/index.d.ts +53 -40
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +52 -17
  25. package/dist/types.d.ts +345 -268
  26. package/dist/types.d.ts.map +1 -1
  27. package/dist/types.js +10 -8
  28. package/dist/wallet/create-node.d.ts +73 -0
  29. package/dist/wallet/create-node.d.ts.map +1 -0
  30. package/dist/wallet/create-node.js +99 -0
  31. package/dist/wallet/handlers/account.d.ts +67 -0
  32. package/dist/wallet/handlers/account.d.ts.map +1 -0
  33. package/dist/wallet/handlers/account.js +85 -0
  34. package/dist/wallet/handlers/contract-interaction.d.ts +77 -0
  35. package/dist/wallet/handlers/contract-interaction.d.ts.map +1 -0
  36. package/dist/wallet/handlers/contract-interaction.js +219 -0
  37. package/dist/wallet/handlers/contract.d.ts +96 -0
  38. package/dist/wallet/handlers/contract.d.ts.map +1 -0
  39. package/dist/wallet/handlers/contract.js +146 -0
  40. package/dist/wallet/handlers/event.d.ts +62 -0
  41. package/dist/wallet/handlers/event.d.ts.map +1 -0
  42. package/dist/wallet/handlers/event.js +85 -0
  43. package/dist/wallet/handlers/index.d.ts +88 -0
  44. package/dist/wallet/handlers/index.d.ts.map +1 -0
  45. package/dist/wallet/handlers/index.js +47 -0
  46. package/dist/wallet/handlers/node.d.ts +117 -0
  47. package/dist/wallet/handlers/node.d.ts.map +1 -0
  48. package/dist/wallet/handlers/node.js +196 -0
  49. package/dist/wallet/handlers/senders.d.ts +70 -0
  50. package/dist/wallet/handlers/senders.d.ts.map +1 -0
  51. package/dist/wallet/handlers/senders.js +92 -0
  52. package/dist/wallet/handlers/transaction.d.ts +123 -0
  53. package/dist/wallet/handlers/transaction.d.ts.map +1 -0
  54. package/dist/wallet/handlers/transaction.js +191 -0
  55. package/dist/wallet/serializers.d.ts +75 -0
  56. package/dist/wallet/serializers.d.ts.map +1 -0
  57. package/dist/wallet/serializers.js +501 -0
  58. package/docs/README.md +290 -229
  59. package/docs/classes/AztecDappWallet.md +1304 -0
  60. package/docs/classes/AztecRouterProvider.md +1058 -0
  61. package/docs/classes/AztecWalletError.md +124 -47
  62. package/docs/classes/ContractArtifactCache.md +48 -31
  63. package/docs/functions/connectAztec.md +62 -0
  64. package/docs/functions/createAztecWallet.md +46 -0
  65. package/docs/functions/createAztecWalletNode.md +96 -0
  66. package/docs/functions/registerAztecSerializers.md +61 -0
  67. package/docs/functions/registerWalletAztecSerializers.md +39 -0
  68. package/docs/globals.md +16 -14
  69. package/docs/interfaces/AztecHandlerContext.md +54 -0
  70. package/docs/interfaces/AztecWalletContext.md +50 -0
  71. package/docs/interfaces/AztecWalletMethodMap.md +471 -470
  72. package/docs/type-aliases/AztecChainId.md +16 -3
  73. package/docs/variables/ALL_AZTEC_METHODS.md +20 -0
  74. package/docs/variables/AztecWalletErrorMap.md +9 -4
  75. package/docs/variables/AztecWalletSerializer.md +45 -0
  76. package/package.json +9 -9
  77. package/src/client/aztec-dapp-wallet.test.ts +628 -0
  78. package/src/client/aztec-dapp-wallet.ts +879 -0
  79. package/src/client/aztec-router-provider.test.ts +235 -0
  80. package/src/client/aztec-router-provider.ts +64 -0
  81. package/src/client/helpers.test.ts +187 -0
  82. package/src/client/helpers.ts +91 -0
  83. package/src/client/register-serializers.ts +108 -0
  84. package/src/contractArtifactCache.test.ts +21 -10
  85. package/src/contractArtifactCache.ts +54 -35
  86. package/src/errors.ts +58 -10
  87. package/src/index.test.ts +2 -6
  88. package/src/index.ts +73 -37
  89. package/src/types.ts +379 -217
  90. package/src/wallet/create-node.test.ts +332 -0
  91. package/src/wallet/create-node.ts +120 -0
  92. package/src/wallet/handlers/account.test.ts +172 -0
  93. package/src/wallet/handlers/account.ts +99 -0
  94. package/src/wallet/handlers/contract-interaction.test.ts +248 -0
  95. package/src/wallet/handlers/contract-interaction.ts +269 -0
  96. package/src/wallet/handlers/contract.test.ts +245 -0
  97. package/src/wallet/handlers/contract.ts +174 -0
  98. package/src/wallet/handlers/event.test.ts +216 -0
  99. package/src/wallet/handlers/event.ts +99 -0
  100. package/src/wallet/handlers/index.ts +84 -0
  101. package/src/wallet/handlers/node.test.ts +304 -0
  102. package/src/wallet/handlers/node.ts +230 -0
  103. package/src/wallet/handlers/senders.test.ts +172 -0
  104. package/src/wallet/handlers/senders.ts +106 -0
  105. package/src/wallet/handlers/transaction.test.ts +371 -0
  106. package/src/wallet/handlers/transaction.ts +239 -0
  107. package/src/wallet/serializers.test.ts +253 -0
  108. package/src/wallet/serializers.ts +586 -0
  109. package/typedoc.json +23 -1
  110. package/dist/aztecRemoteWallet.d.ts +0 -70
  111. package/dist/aztecRemoteWallet.d.ts.map +0 -1
  112. package/dist/aztecRemoteWallet.js +0 -335
  113. package/dist/chainProvider.d.ts +0 -56
  114. package/dist/chainProvider.d.ts.map +0 -1
  115. package/dist/chainProvider.js +0 -98
  116. package/dist/handlers/aztecAccountWallet.d.ts +0 -4
  117. package/dist/handlers/aztecAccountWallet.d.ts.map +0 -1
  118. package/dist/handlers/aztecAccountWallet.js +0 -296
  119. package/dist/handlers/transactions.d.ts +0 -21
  120. package/dist/handlers/transactions.d.ts.map +0 -1
  121. package/dist/handlers/transactions.js +0 -98
  122. package/dist/handlers.d.ts +0 -27
  123. package/dist/handlers.d.ts.map +0 -1
  124. package/dist/handlers.js +0 -55
  125. package/dist/provider.d.ts +0 -105
  126. package/dist/provider.d.ts.map +0 -1
  127. package/dist/provider.js +0 -160
  128. package/dist/serializers/account.d.ts +0 -164
  129. package/dist/serializers/account.d.ts.map +0 -1
  130. package/dist/serializers/account.js +0 -244
  131. package/dist/serializers/contract.d.ts +0 -62
  132. package/dist/serializers/contract.d.ts.map +0 -1
  133. package/dist/serializers/contract.js +0 -130
  134. package/dist/serializers/index.d.ts +0 -21
  135. package/dist/serializers/index.d.ts.map +0 -1
  136. package/dist/serializers/index.js +0 -154
  137. package/dist/serializers/log.d.ts +0 -66
  138. package/dist/serializers/log.d.ts.map +0 -1
  139. package/dist/serializers/log.js +0 -222
  140. package/dist/serializers/note.d.ts +0 -124
  141. package/dist/serializers/note.d.ts.map +0 -1
  142. package/dist/serializers/note.js +0 -208
  143. package/dist/serializers/transaction.d.ts +0 -99
  144. package/dist/serializers/transaction.d.ts.map +0 -1
  145. package/dist/serializers/transaction.js +0 -275
  146. package/dist/wallet.d.ts +0 -62
  147. package/dist/wallet.d.ts.map +0 -1
  148. package/dist/wallet.js +0 -77
  149. package/docs/classes/AztecChainProvider.md +0 -553
  150. package/docs/classes/AztecChainWallet.md +0 -409
  151. package/docs/classes/AztecProvider.md +0 -1112
  152. package/docs/interfaces/AztecWalletBaseMethodMap.md +0 -135
  153. package/docs/interfaces/AztecWalletEventMap.md +0 -17
  154. package/docs/type-aliases/AztecChainWalletMiddleware.md +0 -13
  155. package/docs/type-aliases/AztecWalletContext.md +0 -29
  156. package/docs/type-aliases/AztecWalletMethodHandler.md +0 -37
  157. package/docs/type-aliases/AztecWalletMiddleware.md +0 -13
  158. package/docs/type-aliases/AztecWalletRouterClient.md +0 -13
  159. package/docs/type-aliases/TransactionFunctionCall.md +0 -33
  160. package/docs/type-aliases/TransactionParams.md +0 -27
  161. package/src/aztecRemoteWallet.test.ts +0 -504
  162. package/src/aztecRemoteWallet.ts +0 -467
  163. package/src/chainProvider.test.ts +0 -401
  164. package/src/chainProvider.ts +0 -116
  165. package/src/handlers/aztecAccountWallet.test.ts +0 -649
  166. package/src/handlers/aztecAccountWallet.ts +0 -532
  167. package/src/handlers/transactions.ts +0 -124
  168. package/src/handlers.test.ts +0 -270
  169. package/src/handlers.ts +0 -70
  170. package/src/provider.test.ts +0 -274
  171. package/src/provider.ts +0 -189
  172. package/src/serializers/account.test.ts +0 -125
  173. package/src/serializers/account.ts +0 -301
  174. package/src/serializers/contract.test.ts +0 -24
  175. package/src/serializers/contract.ts +0 -183
  176. package/src/serializers/index.test.ts +0 -136
  177. package/src/serializers/index.ts +0 -191
  178. package/src/serializers/log.test.ts +0 -286
  179. package/src/serializers/log.ts +0 -292
  180. package/src/serializers/note.test.ts +0 -125
  181. package/src/serializers/note.ts +0 -250
  182. package/src/serializers/transaction.test.ts +0 -320
  183. package/src/serializers/transaction.ts +0 -409
  184. package/src/wallet.test.ts +0 -275
  185. package/src/wallet.ts +0 -94
@@ -0,0 +1,58 @@
1
+ import { WalletRouterProvider } from '@walletmesh/router';
2
+ import type { JSONRPCTransport } from '@walletmesh/jsonrpc';
3
+ /**
4
+ * An extended {@link WalletRouterProvider} specifically for Aztec network interactions.
5
+ *
6
+ * This class automatically registers all necessary Aztec-specific type serializers
7
+ * (e.g., for `AztecAddress`, `Fr`, `TxExecutionRequest`) upon instantiation.
8
+ * This ensures that when dApps communicate with an Aztec wallet via this provider,
9
+ * all Aztec types are correctly serialized for JSON-RPC transport and deserialized
10
+ * back into their proper object instances on receipt.
11
+ *
12
+ * It simplifies the setup for dApp developers, as they do not need to manually
13
+ * register serializers for Aztec types.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { AztecRouterProvider, createAztecWallet } from '@walletmesh/aztec-rpc-wallet';
18
+ * import { MyCustomTransport } from './my-custom-transport'; // Assuming a custom transport
19
+ *
20
+ * // 1. Create a JSON-RPC transport
21
+ * const transport = new MyCustomTransport();
22
+ *
23
+ * // 2. Create the AztecRouterProvider instance
24
+ * const provider = new AztecRouterProvider(transport);
25
+ *
26
+ * // 3. Connect to the Aztec chain (e.g., testnet) and request permissions
27
+ * await provider.connect({
28
+ * 'aztec:testnet': ['aztec_getAddress', 'aztec_sendTx']
29
+ * });
30
+ *
31
+ * // 4. Create an AztecDappWallet instance using the provider
32
+ * const wallet = await createAztecWallet(provider, 'aztec:testnet');
33
+ *
34
+ * // Now, calls made through 'wallet' will automatically handle Aztec type serialization:
35
+ * const address = await wallet.getAddress(); // AztecAddress instance
36
+ * // const txRequest = ...;
37
+ * // const txHash = await wallet.sendTx(await wallet.proveTx(txRequest)); // Tx, TxHash instances
38
+ * ```
39
+ *
40
+ * @see {@link WalletRouterProvider} for the base class functionality.
41
+ * @see {@link registerAztecSerializers} for the underlying serializer registration.
42
+ * @see {@link AztecDappWallet} which is typically used with this provider.
43
+ */
44
+ export declare class AztecRouterProvider extends WalletRouterProvider {
45
+ /**
46
+ * Constructs an instance of `AztecRouterProvider`.
47
+ *
48
+ * Upon construction, it immediately registers all Aztec-specific serializers
49
+ * with the underlying JSON-RPC node managed by the `WalletRouterProvider`.
50
+ *
51
+ * @param transport - The {@link JSONRPCTransport} instance to be used for
52
+ * communication between the dApp and the WalletRouter.
53
+ * @param context - Optional context object that can be passed to the
54
+ * `WalletRouterProvider` constructor.
55
+ */
56
+ constructor(transport: JSONRPCTransport, context?: Record<string, unknown>);
57
+ }
58
+ //# sourceMappingURL=aztec-router-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aztec-router-provider.d.ts","sourceRoot":"","sources":["../../src/client/aztec-router-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,qBAAa,mBAAoB,SAAQ,oBAAoB;IAC3D;;;;;;;;;;OAUG;gBACS,SAAS,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAM3E"}
@@ -0,0 +1,62 @@
1
+ import { WalletRouterProvider } from '@walletmesh/router';
2
+ import { registerAztecSerializers } from './register-serializers.js';
3
+ /**
4
+ * An extended {@link WalletRouterProvider} specifically for Aztec network interactions.
5
+ *
6
+ * This class automatically registers all necessary Aztec-specific type serializers
7
+ * (e.g., for `AztecAddress`, `Fr`, `TxExecutionRequest`) upon instantiation.
8
+ * This ensures that when dApps communicate with an Aztec wallet via this provider,
9
+ * all Aztec types are correctly serialized for JSON-RPC transport and deserialized
10
+ * back into their proper object instances on receipt.
11
+ *
12
+ * It simplifies the setup for dApp developers, as they do not need to manually
13
+ * register serializers for Aztec types.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { AztecRouterProvider, createAztecWallet } from '@walletmesh/aztec-rpc-wallet';
18
+ * import { MyCustomTransport } from './my-custom-transport'; // Assuming a custom transport
19
+ *
20
+ * // 1. Create a JSON-RPC transport
21
+ * const transport = new MyCustomTransport();
22
+ *
23
+ * // 2. Create the AztecRouterProvider instance
24
+ * const provider = new AztecRouterProvider(transport);
25
+ *
26
+ * // 3. Connect to the Aztec chain (e.g., testnet) and request permissions
27
+ * await provider.connect({
28
+ * 'aztec:testnet': ['aztec_getAddress', 'aztec_sendTx']
29
+ * });
30
+ *
31
+ * // 4. Create an AztecDappWallet instance using the provider
32
+ * const wallet = await createAztecWallet(provider, 'aztec:testnet');
33
+ *
34
+ * // Now, calls made through 'wallet' will automatically handle Aztec type serialization:
35
+ * const address = await wallet.getAddress(); // AztecAddress instance
36
+ * // const txRequest = ...;
37
+ * // const txHash = await wallet.sendTx(await wallet.proveTx(txRequest)); // Tx, TxHash instances
38
+ * ```
39
+ *
40
+ * @see {@link WalletRouterProvider} for the base class functionality.
41
+ * @see {@link registerAztecSerializers} for the underlying serializer registration.
42
+ * @see {@link AztecDappWallet} which is typically used with this provider.
43
+ */
44
+ export class AztecRouterProvider extends WalletRouterProvider {
45
+ /**
46
+ * Constructs an instance of `AztecRouterProvider`.
47
+ *
48
+ * Upon construction, it immediately registers all Aztec-specific serializers
49
+ * with the underlying JSON-RPC node managed by the `WalletRouterProvider`.
50
+ *
51
+ * @param transport - The {@link JSONRPCTransport} instance to be used for
52
+ * communication between the dApp and the WalletRouter.
53
+ * @param context - Optional context object that can be passed to the
54
+ * `WalletRouterProvider` constructor.
55
+ */
56
+ constructor(transport, context) {
57
+ super(transport, context);
58
+ // Register all Aztec serializers on this provider instance
59
+ registerAztecSerializers(this);
60
+ }
61
+ }
62
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXp0ZWMtcm91dGVyLXByb3ZpZGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NsaWVudC9henRlYy1yb3V0ZXItcHJvdmlkZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLG9CQUFvQixFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFFMUQsT0FBTyxFQUFFLHdCQUF3QixFQUFFLE1BQU0sMkJBQTJCLENBQUM7QUFFckU7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7R0F3Q0c7QUFDSCxNQUFNLE9BQU8sbUJBQW9CLFNBQVEsb0JBQW9CO0lBQzNEOzs7Ozs7Ozs7O09BVUc7SUFDSCxZQUFZLFNBQTJCLEVBQUUsT0FBaUM7UUFDeEUsS0FBSyxDQUFDLFNBQVMsRUFBRSxPQUFPLENBQUMsQ0FBQztRQUUxQiwyREFBMkQ7UUFDM0Qsd0JBQXdCLENBQUMsSUFBSSxDQUFDLENBQUM7SUFDakMsQ0FBQztDQUNGIn0=
@@ -0,0 +1,44 @@
1
+ import type { AztecChainId } from '../types.js';
2
+ import type { AztecDappWallet } from './aztec-dapp-wallet.js';
3
+ import type { AztecRouterProvider } from './aztec-router-provider.js';
4
+ /**
5
+ * A comprehensive list of all JSON-RPC methods supported by the Aztec RPC wallet.
6
+ * This array includes standard Aztec wallet methods as well as WalletMesh-specific extensions (prefixed with `wm_`).
7
+ * It can be used when establishing a connection to request permissions for all available functionalities.
8
+ *
9
+ * @see {@link AztecWalletMethodMap} for detailed type information on each method.
10
+ * @see {@link connectAztec} and {@link connectAztecWithWallet} which use this list by default.
11
+ */
12
+ export declare const ALL_AZTEC_METHODS: readonly ["aztec_getAddress", "aztec_getCompleteAddress", "aztec_getChainId", "aztec_getVersion", "aztec_sendTx", "aztec_getTxReceipt", "aztec_simulateTx", "aztec_getNodeInfo", "aztec_getBlockNumber", "aztec_getCurrentBaseFees", "aztec_registerSender", "aztec_getSenders", "aztec_removeSender", "aztec_registerContract", "aztec_registerContractClass", "aztec_getContractMetadata", "aztec_getContractClassMetadata", "aztec_proveTx", "aztec_profileTx", "aztec_simulateUtility", "aztec_getPrivateEvents", "aztec_getPublicEvents", "aztec_getPXEInfo", "aztec_getBlock", "aztec_createAuthWit", "aztec_wmDeployContract", "aztec_wmExecuteTx", "aztec_wmSimulateTx"];
13
+ /**
14
+ * Establishes a connection to an Aztec wallet service and creates an initialized {@link AztecDappWallet} instance.
15
+ * This function requests permissions for the specified methods on the given Aztec chain,
16
+ * then instantiates and initializes the wallet.
17
+ * Initialization includes fetching and caching essential data like the wallet address and chain ID.
18
+ *
19
+ * By default, it requests permissions for all methods defined in {@link ALL_AZTEC_METHODS}
20
+ * on the 'aztec:mainnet' chain.
21
+ *
22
+ * @param provider - The {@link AztecRouterProvider} instance to use for the connection.
23
+ * This provider must be configured with appropriate transport and Aztec serializers.
24
+ * @param chainId - The {@link AztecChainId} to connect to (e.g., 'aztec:mainnet', 'aztec:31337').
25
+ * Defaults to 'aztec:mainnet'.
26
+ * @param methods - An array of method names for which permissions are requested.
27
+ * Defaults to {@link ALL_AZTEC_METHODS}.
28
+ * @returns A promise that resolves to an object containing the `sessionId` for the connection
29
+ * and a fully initialized {@link AztecDappWallet} instance.
30
+ * @throws If the connection or wallet initialization fails.
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const provider = new AztecRouterProvider(myTransport);
35
+ * const { sessionId, wallet } = await connectAztec(provider, 'aztec:testnet');
36
+ * const address = wallet.getAddress(); // Wallet is ready to use
37
+ * console.log('Connected with session ID:', sessionId, 'Wallet address:', address.toString());
38
+ * ```
39
+ */
40
+ export declare function connectAztec(provider: AztecRouterProvider, chainId?: AztecChainId, methods?: readonly (keyof import('../types.js').AztecWalletMethodMap | string)[]): Promise<{
41
+ sessionId: string;
42
+ wallet: AztecDappWallet;
43
+ }>;
44
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/client/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAKtE;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,kpBA6BpB,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,GAAE,YAA8B,EACvC,OAAO,GAAE,SAAS,CAAC,MAAM,OAAO,aAAa,EAAE,oBAAoB,GAAG,MAAM,CAAC,EAAsB,GAClG,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,CAAC,CAWzD"}
@@ -0,0 +1,79 @@
1
+ import { createAztecWallet } from './aztec-dapp-wallet.js';
2
+ import { createLogger } from '@aztec/foundation/log';
3
+ const logger = createLogger('aztec-rpc-wallet:helpers');
4
+ /**
5
+ * A comprehensive list of all JSON-RPC methods supported by the Aztec RPC wallet.
6
+ * This array includes standard Aztec wallet methods as well as WalletMesh-specific extensions (prefixed with `wm_`).
7
+ * It can be used when establishing a connection to request permissions for all available functionalities.
8
+ *
9
+ * @see {@link AztecWalletMethodMap} for detailed type information on each method.
10
+ * @see {@link connectAztec} and {@link connectAztecWithWallet} which use this list by default.
11
+ */
12
+ export const ALL_AZTEC_METHODS = [
13
+ 'aztec_getAddress',
14
+ 'aztec_getCompleteAddress',
15
+ 'aztec_getChainId',
16
+ 'aztec_getVersion',
17
+ 'aztec_sendTx',
18
+ 'aztec_getTxReceipt',
19
+ 'aztec_simulateTx',
20
+ 'aztec_getNodeInfo',
21
+ 'aztec_getBlockNumber',
22
+ 'aztec_getCurrentBaseFees',
23
+ 'aztec_registerSender',
24
+ 'aztec_getSenders',
25
+ 'aztec_removeSender',
26
+ 'aztec_registerContract',
27
+ 'aztec_registerContractClass',
28
+ 'aztec_getContractMetadata',
29
+ 'aztec_getContractClassMetadata',
30
+ 'aztec_proveTx',
31
+ 'aztec_profileTx',
32
+ 'aztec_simulateUtility',
33
+ 'aztec_getPrivateEvents',
34
+ 'aztec_getPublicEvents',
35
+ 'aztec_getPXEInfo',
36
+ 'aztec_getBlock',
37
+ 'aztec_createAuthWit',
38
+ 'aztec_wmDeployContract',
39
+ 'aztec_wmExecuteTx',
40
+ 'aztec_wmSimulateTx',
41
+ ];
42
+ /**
43
+ * Establishes a connection to an Aztec wallet service and creates an initialized {@link AztecDappWallet} instance.
44
+ * This function requests permissions for the specified methods on the given Aztec chain,
45
+ * then instantiates and initializes the wallet.
46
+ * Initialization includes fetching and caching essential data like the wallet address and chain ID.
47
+ *
48
+ * By default, it requests permissions for all methods defined in {@link ALL_AZTEC_METHODS}
49
+ * on the 'aztec:mainnet' chain.
50
+ *
51
+ * @param provider - The {@link AztecRouterProvider} instance to use for the connection.
52
+ * This provider must be configured with appropriate transport and Aztec serializers.
53
+ * @param chainId - The {@link AztecChainId} to connect to (e.g., 'aztec:mainnet', 'aztec:31337').
54
+ * Defaults to 'aztec:mainnet'.
55
+ * @param methods - An array of method names for which permissions are requested.
56
+ * Defaults to {@link ALL_AZTEC_METHODS}.
57
+ * @returns A promise that resolves to an object containing the `sessionId` for the connection
58
+ * and a fully initialized {@link AztecDappWallet} instance.
59
+ * @throws If the connection or wallet initialization fails.
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * const provider = new AztecRouterProvider(myTransport);
64
+ * const { sessionId, wallet } = await connectAztec(provider, 'aztec:testnet');
65
+ * const address = wallet.getAddress(); // Wallet is ready to use
66
+ * console.log('Connected with session ID:', sessionId, 'Wallet address:', address.toString());
67
+ * ```
68
+ */
69
+ export async function connectAztec(provider, chainId = 'aztec:mainnet', methods = ALL_AZTEC_METHODS) {
70
+ // Establish connection
71
+ const { sessionId } = await provider.connect({
72
+ [chainId]: [...methods],
73
+ });
74
+ // Create and initialize wallet (this pre-caches all synchronous values)
75
+ const wallet = await createAztecWallet(provider, chainId);
76
+ logger.debug(`Connected to Aztec wallet: ${sessionId}`);
77
+ return { sessionId, wallet };
78
+ }
79
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jbGllbnQvaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQUUsaUJBQWlCLEVBQU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BQUMsQ0FBQztJQUVILHdFQUF3RTtJQUN4RSxNQUFNLE1BQU0sR0FBRyxNQUFNLGlCQUFpQixDQUFDLFFBQVEsRUFBRSxPQUFPLENBQUMsQ0FBQztJQUMxRCxNQUFNLENBQUMsS0FBSyxDQUFDLDhCQUE4QixTQUFTLEVBQUUsQ0FBQyxDQUFDO0lBRXhELE9BQU8sRUFBRSxTQUFTLEVBQUUsTUFBTSxFQUFFLENBQUM7QUFDL0IsQ0FBQyJ9
@@ -0,0 +1,41 @@
1
+ import type { WalletRouterProvider } from '@walletmesh/router';
2
+ /**
3
+ * Registers the {@link AztecWalletSerializer} for all relevant Aztec JSON-RPC methods
4
+ * on a given {@link WalletRouterProvider} instance.
5
+ *
6
+ * This utility function ensures that any `WalletRouterProvider` (not just the specialized
7
+ * {@link AztecRouterProvider}) can be configured to correctly handle serialization and
8
+ * deserialization of Aztec-specific data types (e.g., `AztecAddress`, `Fr`, `TxExecutionRequest`)
9
+ * when interacting with an Aztec wallet.
10
+ *
11
+ * It iterates through a predefined list of Aztec methods and associates them with
12
+ * the comprehensive {@link AztecWalletSerializer}.
13
+ *
14
+ * @param provider - The {@link WalletRouterProvider} instance on which to register the serializers.
15
+ * After this function call, the provider will be equipped to handle Aztec methods.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { WalletRouterProvider } from '@walletmesh/router';
20
+ * import { registerAztecSerializers, ALL_AZTEC_METHODS } from '@walletmesh/aztec-rpc-wallet';
21
+ * import { MyCustomTransport } from './my-custom-transport';
22
+ *
23
+ * // 1. Create a generic WalletRouterProvider
24
+ * const transport = new MyCustomTransport();
25
+ * const provider = new WalletRouterProvider(transport);
26
+ *
27
+ * // 2. Register Aztec serializers on it
28
+ * registerAztecSerializers(provider);
29
+ *
30
+ * // 3. Now the provider can correctly handle Aztec methods and types
31
+ * await provider.connect({ 'aztec:testnet': ALL_AZTEC_METHODS });
32
+ * const address = await provider.call('aztec:testnet', { method: 'aztec_getAddress' });
33
+ * // 'address' will be correctly deserialized into an AztecAddress instance (or equivalent based on serializer)
34
+ * ```
35
+ *
36
+ * @see {@link AztecWalletSerializer} for the actual serialization logic.
37
+ * @see {@link AztecRouterProvider} for a provider that calls this automatically.
38
+ * @see {@link AztecWalletMethodMap} for the list of methods and their types.
39
+ */
40
+ export declare function registerAztecSerializers(provider: WalletRouterProvider): void;
41
+ //# sourceMappingURL=register-serializers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-serializers.d.ts","sourceRoot":"","sources":["../../src/client/register-serializers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAI/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,IAAI,CAiE7E"}
@@ -0,0 +1,97 @@
1
+ import { AztecWalletSerializer } from '../wallet/serializers.js';
2
+ /**
3
+ * Registers the {@link AztecWalletSerializer} for all relevant Aztec JSON-RPC methods
4
+ * on a given {@link WalletRouterProvider} instance.
5
+ *
6
+ * This utility function ensures that any `WalletRouterProvider` (not just the specialized
7
+ * {@link AztecRouterProvider}) can be configured to correctly handle serialization and
8
+ * deserialization of Aztec-specific data types (e.g., `AztecAddress`, `Fr`, `TxExecutionRequest`)
9
+ * when interacting with an Aztec wallet.
10
+ *
11
+ * It iterates through a predefined list of Aztec methods and associates them with
12
+ * the comprehensive {@link AztecWalletSerializer}.
13
+ *
14
+ * @param provider - The {@link WalletRouterProvider} instance on which to register the serializers.
15
+ * After this function call, the provider will be equipped to handle Aztec methods.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { WalletRouterProvider } from '@walletmesh/router';
20
+ * import { registerAztecSerializers, ALL_AZTEC_METHODS } from '@walletmesh/aztec-rpc-wallet';
21
+ * import { MyCustomTransport } from './my-custom-transport';
22
+ *
23
+ * // 1. Create a generic WalletRouterProvider
24
+ * const transport = new MyCustomTransport();
25
+ * const provider = new WalletRouterProvider(transport);
26
+ *
27
+ * // 2. Register Aztec serializers on it
28
+ * registerAztecSerializers(provider);
29
+ *
30
+ * // 3. Now the provider can correctly handle Aztec methods and types
31
+ * await provider.connect({ 'aztec:testnet': ALL_AZTEC_METHODS });
32
+ * const address = await provider.call('aztec:testnet', { method: 'aztec_getAddress' });
33
+ * // 'address' will be correctly deserialized into an AztecAddress instance (or equivalent based on serializer)
34
+ * ```
35
+ *
36
+ * @see {@link AztecWalletSerializer} for the actual serialization logic.
37
+ * @see {@link AztecRouterProvider} for a provider that calls this automatically.
38
+ * @see {@link AztecWalletMethodMap} for the list of methods and their types.
39
+ */
40
+ export function registerAztecSerializers(provider) {
41
+ // List of all Aztec wallet methods that need the AztecWalletSerializer.
42
+ // This list should ideally be kept in sync with ALL_AZTEC_METHODS or derived from AztecWalletMethodMap.
43
+ // Note: 'aztec_createTxExecutionRequest' is a client-side method, not a direct RPC method name.
44
+ // The actual RPC methods involved in tx creation are typically aztec_proveTx, aztec_sendTx, etc.
45
+ // However, if it were an RPC method, it would be listed here.
46
+ // For now, using a manually curated list that matches most of AztecWalletMethodMap.
47
+ const aztecMethods = [
48
+ // Chain/Node Methods
49
+ 'aztec_getBlock',
50
+ 'aztec_getBlockNumber',
51
+ 'aztec_getChainId',
52
+ 'aztec_getVersion',
53
+ 'aztec_getNodeInfo',
54
+ 'aztec_getProvenBlockNumber',
55
+ 'aztec_getPXEInfo',
56
+ 'aztec_getCurrentBaseFees',
57
+ // Account Methods
58
+ 'aztec_getAddress',
59
+ 'aztec_getCompleteAddress',
60
+ // AuthWitness Methods
61
+ 'aztec_createAuthWit',
62
+ // Sender Methods
63
+ 'aztec_registerSender',
64
+ 'aztec_getSenders',
65
+ 'aztec_removeSender',
66
+ // Contract Methods
67
+ 'aztec_getContracts',
68
+ 'aztec_getContractMetadata',
69
+ 'aztec_getContractClassMetadata',
70
+ 'aztec_registerContract',
71
+ 'aztec_registerContractClass',
72
+ // Transaction Methods
73
+ // 'aztec_createTxExecutionRequest', // This is a client-side method, not an RPC method.
74
+ 'aztec_proveTx',
75
+ 'aztec_sendTx',
76
+ 'aztec_getTxReceipt',
77
+ 'aztec_simulateTx',
78
+ 'aztec_profileTx',
79
+ 'aztec_simulateUtility',
80
+ // Event Methods
81
+ 'aztec_getPrivateEvents',
82
+ 'aztec_getPublicEvents',
83
+ // Contract Interaction Methods (WalletMesh specific)
84
+ 'aztec_wmExecuteTx',
85
+ 'aztec_wmSimulateTx',
86
+ 'aztec_wmDeployContract',
87
+ // Base WalletMesh method often included
88
+ 'wm_getSupportedMethods',
89
+ ];
90
+ // Register the unified Aztec serializer for all methods
91
+ for (const method of aztecMethods) {
92
+ // The AztecWalletSerializer is already set up with all the proper
93
+ // serialization logic for each method
94
+ provider.registerMethodSerializer(method, AztecWalletSerializer);
95
+ }
96
+ }
97
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVnaXN0ZXItc2VyaWFsaXplcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY2xpZW50L3JlZ2lzdGVyLXNlcmlhbGl6ZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxxQkFBcUIsRUFBRSxNQUFNLDBCQUEwQixDQUFDO0FBR2pFOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBcUNHO0FBQ0gsTUFBTSxVQUFVLHdCQUF3QixDQUFDLFFBQThCO0lBQ3JFLHdFQUF3RTtJQUN4RSx3R0FBd0c7SUFDeEcsZ0dBQWdHO0lBQ2hHLGlHQUFpRztJQUNqRyw4REFBOEQ7SUFDOUQsb0ZBQW9GO0lBQ3BGLE1BQU0sWUFBWSxHQUFtQztRQUNuRCxxQkFBcUI7UUFDckIsZ0JBQWdCO1FBQ2hCLHNCQUFzQjtRQUN0QixrQkFBa0I7UUFDbEIsa0JBQWtCO1FBQ2xCLG1CQUFtQjtRQUNuQiw0QkFBNEI7UUFDNUIsa0JBQWtCO1FBQ2xCLDBCQUEwQjtRQUUxQixrQkFBa0I7UUFDbEIsa0JBQWtCO1FBQ2xCLDBCQUEwQjtRQUUxQixzQkFBc0I7UUFDdEIscUJBQXFCO1FBRXJCLGlCQUFpQjtRQUNqQixzQkFBc0I7UUFDdEIsa0JBQWtCO1FBQ2xCLG9CQUFvQjtRQUVwQixtQkFBbUI7UUFDbkIsb0JBQW9CO1FBQ3BCLDJCQUEyQjtRQUMzQixnQ0FBZ0M7UUFDaEMsd0JBQXdCO1FBQ3hCLDZCQUE2QjtRQUU3QixzQkFBc0I7UUFDdEIsd0ZBQXdGO1FBQ3hGLGVBQWU7UUFDZixjQUFjO1FBQ2Qsb0JBQW9CO1FBQ3BCLGtCQUFrQjtRQUNsQixpQkFBaUI7UUFDakIsdUJBQXVCO1FBRXZCLGdCQUFnQjtRQUNoQix3QkFBd0I7UUFDeEIsdUJBQXVCO1FBRXZCLHFEQUFxRDtRQUNyRCxtQkFBbUI7UUFDbkIsb0JBQW9CO1FBQ3BCLHdCQUF3QjtRQUV4Qix3Q0FBd0M7UUFDeEMsd0JBQXdCO0tBQ3pCLENBQUM7SUFFRix3REFBd0Q7SUFDeEQsS0FBSyxNQUFNLE1BQU0sSUFBSSxZQUFZLEVBQUUsQ0FBQztRQUNsQyxrRUFBa0U7UUFDbEUsc0NBQXNDO1FBQ3RDLFFBQVEsQ0FBQyx3QkFBd0IsQ0FBQyxNQUFnQixFQUFFLHFCQUFxQixDQUFDLENBQUM7SUFDN0UsQ0FBQztBQUNILENBQUMifQ==
@@ -1,49 +1,66 @@
1
- /**
2
- * @module contractArtifactCache
3
- *
4
- * This module provides caching functionality for Aztec contract artifacts.
5
- * It helps improve performance by avoiding repeated fetches of the same contract artifacts.
6
- */
7
1
  import type { AztecAddress, ContractArtifact, Wallet } from '@aztec/aztec.js';
8
2
  /**
9
- * Caches contract artifacts to optimize contract interactions.
3
+ * Manages an in-memory cache for Aztec {@link ContractArtifact}s.
4
+ *
5
+ * This class is designed to optimize performance by reducing redundant fetches
6
+ * of contract artifacts. When an artifact is requested for a given contract address,
7
+ * the cache first checks its local store. If the artifact is not found (a cache miss),
8
+ * it uses the provided {@link Wallet} instance to retrieve the contract's metadata,
9
+ * then its class metadata (which includes the artifact), stores it in the cache,
10
+ * and finally returns it. Subsequent requests for the same artifact will be served
11
+ * directly from the cache.
12
+ *
13
+ * This caching strategy helps to:
14
+ * - Minimize network requests to the PXE or node for contract data.
15
+ * - Reduce processing overhead associated with fetching and parsing artifacts.
16
+ * - Conserve memory by reusing already loaded artifact instances.
10
17
  *
11
- * This class maintains an in-memory cache of contract artifacts indexed by contract address.
12
- * When a contract artifact is requested:
13
- * 1. First checks the cache for an existing artifact
14
- * 2. If not found, fetches the contract instance and its artifact from the wallet
15
- * 3. Stores the artifact in the cache for future use
16
- * 4. Returns the artifact to the caller
18
+ * The cache is typically used within the `AztecHandlerContext` on the wallet-side
19
+ * to provide efficient artifact access to RPC method handlers.
17
20
  *
18
- * This caching mechanism helps reduce:
19
- * - Network requests to fetch contract data
20
- * - Processing overhead of parsing contract artifacts
21
- * - Memory usage by reusing existing artifacts
21
+ * @see {@link AztecHandlerContext}
22
+ * @see {@link Wallet}
23
+ * @see {@link ContractArtifact}
22
24
  */
23
25
  export declare class ContractArtifactCache {
24
- /** Map of contract addresses to their artifacts */
26
+ /**
27
+ * In-memory map storing contract artifacts, keyed by their stringified {@link AztecAddress}.
28
+ * @internal
29
+ */
25
30
  private cache;
26
- /** Reference to the wallet instance for fetching contract data */
31
+ /**
32
+ * Reference to the `aztec.js` {@link Wallet} instance used to fetch contract
33
+ * metadata and artifacts in case of a cache miss.
34
+ * @internal
35
+ */
27
36
  private wallet;
28
37
  /**
29
- * Creates a new ContractArtifactCache instance.
30
- * @param wallet - Wallet instance used to fetch contract data when cache misses occur
38
+ * Creates a new `ContractArtifactCache` instance.
39
+ *
40
+ * @param wallet - The `aztec.js` {@link Wallet} instance that will be used to
41
+ * fetch contract metadata and artifacts if they are not found
42
+ * in the cache. This wallet should be capable of calling
43
+ * `getContractMetadata` and `getContractClassMetadata`.
31
44
  */
32
45
  constructor(wallet: Wallet);
33
46
  /**
34
- * Retrieves the contract artifact for a given contract address.
35
- * First checks the cache, then falls back to fetching from the wallet if needed.
47
+ * Retrieves the {@link ContractArtifact} for a given {@link AztecAddress}.
36
48
  *
37
- * The process:
38
- * 1. Check if artifact exists in cache
39
- * 2. If not, get contract instance from wallet
40
- * 3. Use instance to get contract class ID
41
- * 4. Fetch artifact using class ID
42
- * 5. Cache the artifact for future use
49
+ * This method implements a cache-aside pattern:
50
+ * 1. It first checks if the artifact for the `contractAddress` is already in the cache.
51
+ * 2. If found (cache hit), the cached artifact is returned immediately.
52
+ * 3. If not found (cache miss):
53
+ * a. It fetches the {@link ContractMetadata} for the `contractAddress` using the wallet.
54
+ * b. It then fetches the {@link ContractClassMetadata} using the class ID from the contract metadata.
55
+ * This class metadata is expected to contain the artifact.
56
+ * c. The retrieved artifact is stored in the cache, associated with the `contractAddress`.
57
+ * d. The artifact is then returned.
43
58
  *
44
- * @param contractAddress - The contract address to retrieve the artifact for
45
- * @returns Promise resolving to the contract artifact
46
- * @throws {AztecWalletError} If contract instance or class not registered
59
+ * @param contractAddress - The {@link AztecAddress} of the contract whose artifact is to be retrieved.
60
+ * @returns A promise that resolves to the {@link ContractArtifact}.
61
+ * @throws {AztecWalletError} if the contract instance or its class (and thus artifact)
62
+ * is not registered with the wallet or cannot be found.
63
+ * Also re-throws other errors encountered during wallet calls.
47
64
  */
48
65
  getContractArtifact(contractAddress: AztecAddress): Promise<ContractArtifact>;
49
66
  }
@@ -1 +1 @@
1
- {"version":3,"file":"contractArtifactCache.d.ts","sourceRoot":"","sources":["../src/contractArtifactCache.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAI9E;;;;;;;;;;;;;;GAcG;AACH,qBAAa,qBAAqB;IAChC,mDAAmD;IACnD,OAAO,CAAC,KAAK,CAAuC;IACpD,kEAAkE;IAClE,OAAO,CAAC,MAAM,CAAS;IAEvB;;;OAGG;gBACS,MAAM,EAAE,MAAM;IAI1B;;;;;;;;;;;;;;OAcG;IACU,mBAAmB,CAAC,eAAe,EAAE,YAAY,GAAG,OAAO,CAAC,gBAAgB,CAAC;CA6B3F"}
1
+ {"version":3,"file":"contractArtifactCache.d.ts","sourceRoot":"","sources":["../src/contractArtifactCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAI9E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,qBAAqB;IAChC;;;OAGG;IACH,OAAO,CAAC,KAAK,CAAuC;IAEpD;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAS;IAEvB;;;;;;;OAOG;gBACS,MAAM,EAAE,MAAM;IAI1B;;;;;;;;;;;;;;;;;;OAkBG;IACU,mBAAmB,CAAC,eAAe,EAAE,YAAY,GAAG,OAAO,CAAC,gBAAgB,CAAC;CA+B3F"}
@@ -1,49 +1,62 @@
1
- /**
2
- * @module contractArtifactCache
3
- *
4
- * This module provides caching functionality for Aztec contract artifacts.
5
- * It helps improve performance by avoiding repeated fetches of the same contract artifacts.
6
- */
7
1
  import { AztecWalletError } from './errors.js';
8
2
  /**
9
- * Caches contract artifacts to optimize contract interactions.
3
+ * Manages an in-memory cache for Aztec {@link ContractArtifact}s.
10
4
  *
11
- * This class maintains an in-memory cache of contract artifacts indexed by contract address.
12
- * When a contract artifact is requested:
13
- * 1. First checks the cache for an existing artifact
14
- * 2. If not found, fetches the contract instance and its artifact from the wallet
15
- * 3. Stores the artifact in the cache for future use
16
- * 4. Returns the artifact to the caller
5
+ * This class is designed to optimize performance by reducing redundant fetches
6
+ * of contract artifacts. When an artifact is requested for a given contract address,
7
+ * the cache first checks its local store. If the artifact is not found (a cache miss),
8
+ * it uses the provided {@link Wallet} instance to retrieve the contract's metadata,
9
+ * then its class metadata (which includes the artifact), stores it in the cache,
10
+ * and finally returns it. Subsequent requests for the same artifact will be served
11
+ * directly from the cache.
17
12
  *
18
- * This caching mechanism helps reduce:
19
- * - Network requests to fetch contract data
20
- * - Processing overhead of parsing contract artifacts
21
- * - Memory usage by reusing existing artifacts
13
+ * This caching strategy helps to:
14
+ * - Minimize network requests to the PXE or node for contract data.
15
+ * - Reduce processing overhead associated with fetching and parsing artifacts.
16
+ * - Conserve memory by reusing already loaded artifact instances.
17
+ *
18
+ * The cache is typically used within the `AztecHandlerContext` on the wallet-side
19
+ * to provide efficient artifact access to RPC method handlers.
20
+ *
21
+ * @see {@link AztecHandlerContext}
22
+ * @see {@link Wallet}
23
+ * @see {@link ContractArtifact}
22
24
  */
23
25
  export class ContractArtifactCache {
24
26
  /**
25
- * Creates a new ContractArtifactCache instance.
26
- * @param wallet - Wallet instance used to fetch contract data when cache misses occur
27
+ * Creates a new `ContractArtifactCache` instance.
28
+ *
29
+ * @param wallet - The `aztec.js` {@link Wallet} instance that will be used to
30
+ * fetch contract metadata and artifacts if they are not found
31
+ * in the cache. This wallet should be capable of calling
32
+ * `getContractMetadata` and `getContractClassMetadata`.
27
33
  */
28
34
  constructor(wallet) {
29
- /** Map of contract addresses to their artifacts */
35
+ /**
36
+ * In-memory map storing contract artifacts, keyed by their stringified {@link AztecAddress}.
37
+ * @internal
38
+ */
30
39
  this.cache = new Map();
31
40
  this.wallet = wallet;
32
41
  }
33
42
  /**
34
- * Retrieves the contract artifact for a given contract address.
35
- * First checks the cache, then falls back to fetching from the wallet if needed.
43
+ * Retrieves the {@link ContractArtifact} for a given {@link AztecAddress}.
36
44
  *
37
- * The process:
38
- * 1. Check if artifact exists in cache
39
- * 2. If not, get contract instance from wallet
40
- * 3. Use instance to get contract class ID
41
- * 4. Fetch artifact using class ID
42
- * 5. Cache the artifact for future use
45
+ * This method implements a cache-aside pattern:
46
+ * 1. It first checks if the artifact for the `contractAddress` is already in the cache.
47
+ * 2. If found (cache hit), the cached artifact is returned immediately.
48
+ * 3. If not found (cache miss):
49
+ * a. It fetches the {@link ContractMetadata} for the `contractAddress` using the wallet.
50
+ * b. It then fetches the {@link ContractClassMetadata} using the class ID from the contract metadata.
51
+ * This class metadata is expected to contain the artifact.
52
+ * c. The retrieved artifact is stored in the cache, associated with the `contractAddress`.
53
+ * d. The artifact is then returned.
43
54
  *
44
- * @param contractAddress - The contract address to retrieve the artifact for
45
- * @returns Promise resolving to the contract artifact
46
- * @throws {AztecWalletError} If contract instance or class not registered
55
+ * @param contractAddress - The {@link AztecAddress} of the contract whose artifact is to be retrieved.
56
+ * @returns A promise that resolves to the {@link ContractArtifact}.
57
+ * @throws {AztecWalletError} if the contract instance or its class (and thus artifact)
58
+ * is not registered with the wallet or cannot be found.
59
+ * Also re-throws other errors encountered during wallet calls.
47
60
  */
48
61
  async getContractArtifact(contractAddress) {
49
62
  const addressStr = contractAddress.toString();
@@ -57,10 +70,10 @@ export class ContractArtifactCache {
57
70
  if (!contract) {
58
71
  throw new AztecWalletError('contractInstanceNotRegistered', addressStr);
59
72
  }
60
- const contractClassMetadata = await this.wallet.getContractClassMetadata(contract.contractClassId);
73
+ const contractClassMetadata = await this.wallet.getContractClassMetadata(contract.currentContractClassId);
61
74
  const artifact = contractClassMetadata.artifact;
62
75
  if (!artifact) {
63
- throw new AztecWalletError('contractClassNotRegistered', contract.contractClassId.toString());
76
+ throw new AztecWalletError('contractClassNotRegistered', contract.currentContractClassId.toString());
64
77
  }
65
78
  this.cache.set(addressStr, artifact);
66
79
  return artifact;
@@ -74,4 +87,4 @@ export class ContractArtifactCache {
74
87
  }
75
88
  }
76
89
  }
77
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJhY3R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