@walletmesh/aztec-rpc-wallet 0.3.1 → 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.
- package/CHANGELOG.md +20 -0
- package/README.md +290 -228
- package/dist/.tsbuildinfo +1 -1
- package/dist/client/aztec-dapp-wallet.d.ts +401 -0
- package/dist/client/aztec-dapp-wallet.d.ts.map +1 -0
- package/dist/client/aztec-dapp-wallet.js +705 -0
- package/dist/client/aztec-router-provider.d.ts +58 -0
- package/dist/client/aztec-router-provider.d.ts.map +1 -0
- package/dist/client/aztec-router-provider.js +62 -0
- package/dist/client/helpers.d.ts +44 -0
- package/dist/client/helpers.d.ts.map +1 -0
- package/dist/client/helpers.js +79 -0
- package/dist/client/register-serializers.d.ts +41 -0
- package/dist/client/register-serializers.d.ts.map +1 -0
- package/dist/client/register-serializers.js +97 -0
- package/dist/contractArtifactCache.d.ts +49 -32
- package/dist/contractArtifactCache.d.ts.map +1 -1
- package/dist/contractArtifactCache.js +47 -34
- package/dist/errors.d.ts +50 -8
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +50 -10
- package/dist/index.d.ts +53 -40
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -17
- package/dist/types.d.ts +345 -270
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +10 -8
- package/dist/wallet/create-node.d.ts +73 -0
- package/dist/wallet/create-node.d.ts.map +1 -0
- package/dist/wallet/create-node.js +99 -0
- package/dist/wallet/handlers/account.d.ts +67 -0
- package/dist/wallet/handlers/account.d.ts.map +1 -0
- package/dist/wallet/handlers/account.js +85 -0
- package/dist/wallet/handlers/contract-interaction.d.ts +77 -0
- package/dist/wallet/handlers/contract-interaction.d.ts.map +1 -0
- package/dist/wallet/handlers/contract-interaction.js +219 -0
- package/dist/wallet/handlers/contract.d.ts +96 -0
- package/dist/wallet/handlers/contract.d.ts.map +1 -0
- package/dist/wallet/handlers/contract.js +146 -0
- package/dist/wallet/handlers/event.d.ts +62 -0
- package/dist/wallet/handlers/event.d.ts.map +1 -0
- package/dist/wallet/handlers/event.js +85 -0
- package/dist/wallet/handlers/index.d.ts +88 -0
- package/dist/wallet/handlers/index.d.ts.map +1 -0
- package/dist/wallet/handlers/index.js +47 -0
- package/dist/wallet/handlers/node.d.ts +117 -0
- package/dist/wallet/handlers/node.d.ts.map +1 -0
- package/dist/wallet/handlers/node.js +196 -0
- package/dist/wallet/handlers/senders.d.ts +70 -0
- package/dist/wallet/handlers/senders.d.ts.map +1 -0
- package/dist/wallet/handlers/senders.js +92 -0
- package/dist/wallet/handlers/transaction.d.ts +123 -0
- package/dist/wallet/handlers/transaction.d.ts.map +1 -0
- package/dist/wallet/handlers/transaction.js +191 -0
- package/dist/wallet/serializers.d.ts +75 -0
- package/dist/wallet/serializers.d.ts.map +1 -0
- package/dist/wallet/serializers.js +501 -0
- package/docs/README.md +290 -229
- package/docs/classes/AztecDappWallet.md +1304 -0
- package/docs/classes/AztecRouterProvider.md +1058 -0
- package/docs/classes/AztecWalletError.md +124 -47
- package/docs/classes/ContractArtifactCache.md +48 -31
- package/docs/functions/connectAztec.md +62 -0
- package/docs/functions/createAztecWallet.md +46 -0
- package/docs/functions/createAztecWalletNode.md +96 -0
- package/docs/functions/registerAztecSerializers.md +61 -0
- package/docs/functions/registerWalletAztecSerializers.md +39 -0
- package/docs/globals.md +16 -14
- package/docs/interfaces/AztecHandlerContext.md +54 -0
- package/docs/interfaces/AztecWalletContext.md +50 -0
- package/docs/interfaces/AztecWalletMethodMap.md +470 -477
- package/docs/type-aliases/AztecChainId.md +16 -3
- package/docs/variables/ALL_AZTEC_METHODS.md +20 -0
- package/docs/variables/AztecWalletErrorMap.md +9 -4
- package/docs/variables/AztecWalletSerializer.md +45 -0
- package/package.json +9 -9
- package/src/client/aztec-dapp-wallet.test.ts +628 -0
- package/src/client/aztec-dapp-wallet.ts +879 -0
- package/src/client/aztec-router-provider.test.ts +235 -0
- package/src/client/aztec-router-provider.ts +64 -0
- package/src/client/helpers.test.ts +187 -0
- package/src/client/helpers.ts +91 -0
- package/src/client/register-serializers.ts +108 -0
- package/src/contractArtifactCache.test.ts +21 -10
- package/src/contractArtifactCache.ts +54 -35
- package/src/errors.ts +58 -10
- package/src/index.test.ts +2 -6
- package/src/index.ts +73 -37
- package/src/types.ts +379 -217
- package/src/wallet/create-node.test.ts +332 -0
- package/src/wallet/create-node.ts +120 -0
- package/src/wallet/handlers/account.test.ts +172 -0
- package/src/wallet/handlers/account.ts +99 -0
- package/src/wallet/handlers/contract-interaction.test.ts +248 -0
- package/src/wallet/handlers/contract-interaction.ts +269 -0
- package/src/wallet/handlers/contract.test.ts +245 -0
- package/src/wallet/handlers/contract.ts +174 -0
- package/src/wallet/handlers/event.test.ts +216 -0
- package/src/wallet/handlers/event.ts +99 -0
- package/src/wallet/handlers/index.ts +84 -0
- package/src/wallet/handlers/node.test.ts +304 -0
- package/src/wallet/handlers/node.ts +230 -0
- package/src/wallet/handlers/senders.test.ts +172 -0
- package/src/wallet/handlers/senders.ts +106 -0
- package/src/wallet/handlers/transaction.test.ts +371 -0
- package/src/wallet/handlers/transaction.ts +239 -0
- package/src/wallet/serializers.test.ts +253 -0
- package/src/wallet/serializers.ts +586 -0
- package/typedoc.json +23 -1
- package/dist/aztecRemoteWallet.d.ts +0 -70
- package/dist/aztecRemoteWallet.d.ts.map +0 -1
- package/dist/aztecRemoteWallet.js +0 -335
- package/dist/chainProvider.d.ts +0 -56
- package/dist/chainProvider.d.ts.map +0 -1
- package/dist/chainProvider.js +0 -98
- package/dist/handlers/aztecAccountWallet.d.ts +0 -4
- package/dist/handlers/aztecAccountWallet.d.ts.map +0 -1
- package/dist/handlers/aztecAccountWallet.js +0 -295
- package/dist/handlers/transactions.d.ts +0 -21
- package/dist/handlers/transactions.d.ts.map +0 -1
- package/dist/handlers/transactions.js +0 -98
- package/dist/handlers.d.ts +0 -27
- package/dist/handlers.d.ts.map +0 -1
- package/dist/handlers.js +0 -55
- package/dist/provider.d.ts +0 -105
- package/dist/provider.d.ts.map +0 -1
- package/dist/provider.js +0 -160
- package/dist/serializers/account.d.ts +0 -164
- package/dist/serializers/account.d.ts.map +0 -1
- package/dist/serializers/account.js +0 -244
- package/dist/serializers/contract.d.ts +0 -62
- package/dist/serializers/contract.d.ts.map +0 -1
- package/dist/serializers/contract.js +0 -130
- package/dist/serializers/index.d.ts +0 -21
- package/dist/serializers/index.d.ts.map +0 -1
- package/dist/serializers/index.js +0 -154
- package/dist/serializers/log.d.ts +0 -66
- package/dist/serializers/log.d.ts.map +0 -1
- package/dist/serializers/log.js +0 -222
- package/dist/serializers/note.d.ts +0 -124
- package/dist/serializers/note.d.ts.map +0 -1
- package/dist/serializers/note.js +0 -208
- package/dist/serializers/transaction.d.ts +0 -99
- package/dist/serializers/transaction.d.ts.map +0 -1
- package/dist/serializers/transaction.js +0 -275
- package/dist/wallet.d.ts +0 -62
- package/dist/wallet.d.ts.map +0 -1
- package/dist/wallet.js +0 -77
- package/docs/classes/AztecChainProvider.md +0 -553
- package/docs/classes/AztecChainWallet.md +0 -409
- package/docs/classes/AztecProvider.md +0 -1112
- package/docs/interfaces/AztecWalletBaseMethodMap.md +0 -135
- package/docs/interfaces/AztecWalletEventMap.md +0 -17
- package/docs/type-aliases/AztecChainWalletMiddleware.md +0 -13
- package/docs/type-aliases/AztecWalletContext.md +0 -29
- package/docs/type-aliases/AztecWalletMethodHandler.md +0 -37
- package/docs/type-aliases/AztecWalletMiddleware.md +0 -13
- package/docs/type-aliases/AztecWalletRouterClient.md +0 -13
- package/docs/type-aliases/TransactionFunctionCall.md +0 -33
- package/docs/type-aliases/TransactionParams.md +0 -27
- package/src/aztecRemoteWallet.test.ts +0 -505
- package/src/aztecRemoteWallet.ts +0 -467
- package/src/chainProvider.test.ts +0 -401
- package/src/chainProvider.ts +0 -116
- package/src/handlers/aztecAccountWallet.test.ts +0 -650
- package/src/handlers/aztecAccountWallet.ts +0 -531
- package/src/handlers/transactions.ts +0 -124
- package/src/handlers.test.ts +0 -270
- package/src/handlers.ts +0 -70
- package/src/provider.test.ts +0 -277
- package/src/provider.ts +0 -189
- package/src/serializers/account.test.ts +0 -125
- package/src/serializers/account.ts +0 -301
- package/src/serializers/contract.test.ts +0 -24
- package/src/serializers/contract.ts +0 -183
- package/src/serializers/index.test.ts +0 -136
- package/src/serializers/index.ts +0 -191
- package/src/serializers/log.test.ts +0 -286
- package/src/serializers/log.ts +0 -292
- package/src/serializers/note.test.ts +0 -125
- package/src/serializers/note.ts +0 -250
- package/src/serializers/transaction.test.ts +0 -320
- package/src/serializers/transaction.ts +0 -409
- package/src/wallet.test.ts +0 -275
- 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jbGllbnQvaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUUzRCxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFFckQsTUFBTSxNQUFNLEdBQUcsWUFBWSxDQUFDLDBCQUEwQixDQUFDLENBQUM7QUFFeEQ7Ozs7Ozs7R0FPRztBQUNILE1BQU0sQ0FBQyxNQUFNLGlCQUFpQixHQUFHO0lBQy9CLGtCQUFrQjtJQUNsQiwwQkFBMEI7SUFDMUIsa0JBQWtCO0lBQ2xCLGtCQUFrQjtJQUNsQixjQUFjO0lBQ2Qsb0JBQW9CO0lBQ3BCLGtCQUFrQjtJQUNsQixtQkFBbUI7SUFDbkIsc0JBQXNCO0lBQ3RCLDBCQUEwQjtJQUMxQixzQkFBc0I7SUFDdEIsa0JBQWtCO0lBQ2xCLG9CQUFvQjtJQUNwQix3QkFBd0I7SUFDeEIsNkJBQTZCO0lBQzdCLDJCQUEyQjtJQUMzQixnQ0FBZ0M7SUFDaEMsZUFBZTtJQUNmLGlCQUFpQjtJQUNqQix1QkFBdUI7SUFDdkIsd0JBQXdCO0lBQ3hCLHVCQUF1QjtJQUN2QixrQkFBa0I7SUFDbEIsZ0JBQWdCO0lBQ2hCLHFCQUFxQjtJQUNyQix3QkFBd0I7SUFDeEIsbUJBQW1CO0lBQ25CLG9CQUFvQjtDQUNaLENBQUM7QUFFWDs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7R0EwQkc7QUFDSCxNQUFNLENBQUMsS0FBSyxVQUFVLFlBQVksQ0FDaEMsUUFBNkIsRUFDN0IsVUFBd0IsZUFBZSxFQUN2QyxVQUFrRixpQkFBaUI7SUFFbkcsdUJBQXVCO0lBQ3ZCLE1BQU0sRUFBRSxTQUFTLEVBQUUsR0FBRyxNQUFNLFFBQVEsQ0FBQyxPQUFPLENBQUM7UUFDM0MsQ0FBQyxPQUFPLENBQUMsRUFBRSxDQUFDLEdBQUcsT0FBTyxDQUFhO0tBQ3BDLENBQUMsQ0FBQztJQUVILHdFQUF3RTtJQUN4RSxNQUFNLE1BQU0sR0FBRyxNQUFNLGlCQUFpQixDQUFDLFFBQVEsRUFBRSxPQUFPLENBQUMsQ0FBQztJQUMxRCxNQUFNLENBQUMsS0FBSyxDQUFDLDhCQUE4QixTQUFTLEVBQUUsQ0FBQyxDQUFDO0lBRXhELE9BQU8sRUFBRSxTQUFTLEVBQUUsTUFBTSxFQUFFLENBQUM7QUFDL0IsQ0FBQyJ9
|
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVnaXN0ZXItc2VyaWFsaXplcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY2xpZW50L3JlZ2lzdGVyLXNlcmlhbGl6ZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxxQkFBcUIsRUFBRSxNQUFNLDBCQUEwQixDQUFDO0FBR2pFOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBcUNHO0FBQ0gsTUFBTSxVQUFVLHdCQUF3QixDQUFDLFFBQThCO0lBQ3JFLHdFQUF3RTtJQUN4RSx3R0FBd0c7SUFDeEcsZ0dBQWdHO0lBQ2hHLGlHQUFpRztJQUNqRyw4REFBO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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
|
-
*
|
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
|
-
*
|
12
|
-
*
|
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
|
-
*
|
19
|
-
*
|
20
|
-
*
|
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
|
-
/**
|
26
|
+
/**
|
27
|
+
* In-memory map storing contract artifacts, keyed by their stringified {@link AztecAddress}.
|
28
|
+
* @internal
|
29
|
+
*/
|
25
30
|
private cache;
|
26
|
-
/**
|
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
|
-
*
|
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
|
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
|
-
*
|
38
|
-
* 1.
|
39
|
-
* 2. If
|
40
|
-
* 3.
|
41
|
-
*
|
42
|
-
*
|
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
|
45
|
-
* @returns
|
46
|
-
* @throws {AztecWalletError}
|
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
|
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
|
-
*
|
3
|
+
* Manages an in-memory cache for Aztec {@link ContractArtifact}s.
|
10
4
|
*
|
11
|
-
* This class
|
12
|
-
* When
|
13
|
-
*
|
14
|
-
*
|
15
|
-
*
|
16
|
-
*
|
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
|
19
|
-
* -
|
20
|
-
* -
|
21
|
-
* -
|
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
|
-
*
|
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
|
-
/**
|
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
|
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
|
-
*
|
38
|
-
* 1.
|
39
|
-
* 2. If
|
40
|
-
* 3.
|
41
|
-
*
|
42
|
-
*
|
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
|
45
|
-
* @returns
|
46
|
-
* @throws {AztecWalletError}
|
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.
|
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.
|
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
|
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