@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.
- package/CHANGELOG.md +26 -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 -268
- 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 +471 -470
- 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 -296
- 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 -504
- 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 -649
- package/src/handlers/aztecAccountWallet.ts +0 -532
- 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 -274
- 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,92 @@
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
2
|
+
const logger = createLogger('aztec-rpc-wallet:senders');
|
3
|
+
/**
|
4
|
+
* Creates handlers for managing authorized senders in an Aztec wallet via JSON-RPC.
|
5
|
+
* Authorized senders are {@link AztecAddress}es permitted to submit transactions
|
6
|
+
* on behalf of the user's account. This functionality is crucial for delegation,
|
7
|
+
* enabling other accounts or smart contracts to act for the user under controlled conditions.
|
8
|
+
*
|
9
|
+
* Each handler function receives an {@link AztecHandlerContext}, providing access to the
|
10
|
+
* {@link AccountWallet} instance necessary for sender management.
|
11
|
+
*
|
12
|
+
* @returns An object where keys are sender-related method names
|
13
|
+
* (e.g., "aztec_registerSender", "aztec_getSenders", "aztec_removeSender")
|
14
|
+
* and values are their corresponding handler functions.
|
15
|
+
* @see {@link AztecWalletMethodMap} for method definitions.
|
16
|
+
*/
|
17
|
+
export function createSenderHandlers() {
|
18
|
+
return {
|
19
|
+
/**
|
20
|
+
* Handles the "aztec_registerSender" JSON-RPC method.
|
21
|
+
* Registers a new {@link AztecAddress} as an authorized sender for the account
|
22
|
+
* managed by the {@link AccountWallet} in the context.
|
23
|
+
*
|
24
|
+
* This allows the specified sender address to initiate transactions on behalf of the user.
|
25
|
+
* Common use cases include:
|
26
|
+
* - Delegating transaction submission to a different account.
|
27
|
+
* - Authorizing a smart contract to perform actions for the user.
|
28
|
+
* - Setting up automated transaction systems or relayers.
|
29
|
+
*
|
30
|
+
* @param ctx - The {@link AztecHandlerContext} containing the `wallet` instance.
|
31
|
+
* @param paramsTuple - A tuple containing the sender's address to register.
|
32
|
+
* Defined by {@link AztecWalletMethodMap.aztec_registerSender.params}.
|
33
|
+
* @param paramsTuple.0 - The {@link AztecAddress} to authorize as a sender.
|
34
|
+
* @returns A promise that resolves to the registered {@link AztecAddress}.
|
35
|
+
* Type defined by {@link AztecWalletMethodMap.aztec_registerSender.result}.
|
36
|
+
* @throws {Error} If the `sender` parameter is missing or invalid, though type checking
|
37
|
+
* and serializer validation should catch this earlier.
|
38
|
+
*/
|
39
|
+
aztec_registerSender: async (ctx, paramsTuple) => {
|
40
|
+
const [sender] = paramsTuple;
|
41
|
+
logger.debug(`[HANDLER] aztec_registerSender: sender = ${sender?.toString()}`);
|
42
|
+
if (!sender || typeof sender.toString !== 'function') {
|
43
|
+
// Basic check
|
44
|
+
throw new Error('Invalid sender parameter received in tuple');
|
45
|
+
}
|
46
|
+
return await ctx.wallet.registerSender(sender);
|
47
|
+
},
|
48
|
+
/**
|
49
|
+
* Handles the "aztec_getSenders" JSON-RPC method.
|
50
|
+
* Retrieves a list of all {@link AztecAddress}es currently authorized to send
|
51
|
+
* transactions on behalf of the account managed by the {@link AccountWallet} in the context.
|
52
|
+
* This is useful for auditing and managing delegation permissions.
|
53
|
+
*
|
54
|
+
* @param ctx - The {@link AztecHandlerContext} containing the `wallet` instance.
|
55
|
+
* @param _paramsTuple - Parameters for this method (expected to be an empty array).
|
56
|
+
* Defined by {@link AztecWalletMethodMap.aztec_getSenders.params}.
|
57
|
+
* @returns A promise that resolves to an array of authorized {@link AztecAddress}es.
|
58
|
+
* Type defined by {@link AztecWalletMethodMap.aztec_getSenders.result}.
|
59
|
+
*/
|
60
|
+
aztec_getSenders: async (ctx, _paramsTuple) => {
|
61
|
+
logger.debug('[HANDLER] aztec_getSenders');
|
62
|
+
return await ctx.wallet.getSenders();
|
63
|
+
},
|
64
|
+
/**
|
65
|
+
* Handles the "aztec_removeSender" JSON-RPC method.
|
66
|
+
* Revokes the authorization for a previously registered sender for the account
|
67
|
+
* managed by the {@link AccountWallet} in the context.
|
68
|
+
* After successful removal, the specified address will no longer be able to
|
69
|
+
* submit transactions on behalf of this wallet.
|
70
|
+
*
|
71
|
+
* @param ctx - The {@link AztecHandlerContext} containing the `wallet` instance.
|
72
|
+
* @param paramsTuple - A tuple containing the sender's address to remove.
|
73
|
+
* Defined by {@link AztecWalletMethodMap.aztec_removeSender.params}.
|
74
|
+
* @param paramsTuple.0 - The {@link AztecAddress} to remove from the list of authorized senders.
|
75
|
+
* @returns A promise that resolves to `true` if the removal was successful.
|
76
|
+
* Type defined by {@link AztecWalletMethodMap.aztec_removeSender.result}.
|
77
|
+
* @throws {Error} If the `sender` parameter is missing or invalid, though type checking
|
78
|
+
* and serializer validation should catch this earlier.
|
79
|
+
*/
|
80
|
+
aztec_removeSender: async (ctx, paramsTuple) => {
|
81
|
+
const [sender] = paramsTuple;
|
82
|
+
logger.debug(`[HANDLER] aztec_removeSender: sender = ${sender?.toString()}`);
|
83
|
+
if (!sender || typeof sender.toString !== 'function') {
|
84
|
+
// Basic check
|
85
|
+
throw new Error('Invalid sender parameter received in tuple');
|
86
|
+
}
|
87
|
+
await ctx.wallet.removeSender(sender);
|
88
|
+
return true;
|
89
|
+
},
|
90
|
+
};
|
91
|
+
}
|
92
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VuZGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy93YWxsZXQvaGFuZGxlcnMvc2VuZGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sdUJBQXVCLENB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TUFBTSxDQUFDLE1BQU0sQ0FBQyxHQUFHLFdBQVcsQ0FBQztZQUM3QixNQUFNLENBQUMsS0FBSyxDQUFDLDBDQUEwQyxNQUFNLEVBQUUsUUFBUSxFQUFFLEVBQUUsQ0FBQyxDQUFDO1lBQzdFLElBQUksQ0FBQyxNQUFNLElBQUksT0FBTyxNQUFNLENBQUMsUUFBUSxLQUFLLFVBQVUsRUFBRSxDQUFDO2dCQUNyRCxjQUFjO2dCQUNkLE1BQU0sSUFBSSxLQUFLLENBQUMsNENBQTRDLENBQUMsQ0FBQztZQUNoRSxDQUFDO1lBQ0QsTUFBTSxHQUFHLENBQUMsTUFBTSxDQUFDLFlBQVksQ0FBQyxNQUFNLENBQUMsQ0FBQztZQUN0QyxPQUFPLElBQUksQ0FBQztRQUNkLENBQUM7S0FDRixDQUFDO0FBQ0osQ0FBQyJ9
|
@@ -0,0 +1,123 @@
|
|
1
|
+
import type { AztecHandlerContext } from './index.js';
|
2
|
+
import type { AztecWalletMethodMap } from '../../types.js';
|
3
|
+
/**
|
4
|
+
* Creates handlers for transaction-related Aztec wallet JSON-RPC methods.
|
5
|
+
* These handlers are responsible for the core lifecycle of an Aztec transaction,
|
6
|
+
* including proving, sending, simulating, and retrieving receipts.
|
7
|
+
*
|
8
|
+
* Each handler function receives an {@link AztecHandlerContext}, providing access to the
|
9
|
+
* {@link AccountWallet} and {@link PXE} client instances necessary for these operations.
|
10
|
+
*
|
11
|
+
* @returns An object where keys are transaction-related method names
|
12
|
+
* (e.g., "aztec_proveTx", "aztec_sendTx") and values are their
|
13
|
+
* corresponding handler functions.
|
14
|
+
* @see {@link AztecWalletMethodMap} for method definitions.
|
15
|
+
*/
|
16
|
+
export declare function createTransactionHandlers(): {
|
17
|
+
/**
|
18
|
+
* Handles the "aztec_proveTx" JSON-RPC method.
|
19
|
+
* Generates zero-knowledge proofs for a given {@link TxExecutionRequest}.
|
20
|
+
* If the {@link PrivateExecutionResult} is not provided, this handler will first
|
21
|
+
* simulate the private execution of the transaction to obtain it.
|
22
|
+
*
|
23
|
+
* @param ctx - The {@link AztecHandlerContext} containing the `wallet` instance.
|
24
|
+
* @param paramsTuple - A tuple containing the transaction execution request and an optional private execution result.
|
25
|
+
* Defined by {@link AztecWalletMethodMap.aztec_proveTx.params}.
|
26
|
+
* @param paramsTuple.0 - The {@link TxExecutionRequest} to prove.
|
27
|
+
* @param paramsTuple.1 - Optional: The {@link PrivateExecutionResult} from a prior private simulation.
|
28
|
+
* If not provided, a private simulation will be performed internally.
|
29
|
+
* @returns A promise that resolves to the {@link TxProvingResult}, which includes the proven transaction.
|
30
|
+
* Type defined by {@link AztecWalletMethodMap.aztec_proveTx.result}.
|
31
|
+
* @throws {Error} If `txRequest` is missing, or if simulation is needed but fails to produce a `PrivateExecutionResult`.
|
32
|
+
*/
|
33
|
+
aztec_proveTx: (ctx: AztecHandlerContext, paramsTuple: AztecWalletMethodMap["aztec_proveTx"]["params"]) => Promise<AztecWalletMethodMap["aztec_proveTx"]["result"]>;
|
34
|
+
/**
|
35
|
+
* Handles the "aztec_sendTx" JSON-RPC method.
|
36
|
+
* Sends a proven {@link Tx} (transaction object) to the Aztec network via the
|
37
|
+
* {@link AccountWallet} in the context.
|
38
|
+
*
|
39
|
+
* This is typically the final step in submitting a transaction after it has been
|
40
|
+
* successfully proven by `aztec_proveTx`.
|
41
|
+
*
|
42
|
+
* @param ctx - The {@link AztecHandlerContext} containing the `wallet` instance.
|
43
|
+
* @param paramsTuple - A tuple containing the proven transaction.
|
44
|
+
* Defined by {@link AztecWalletMethodMap.aztec_sendTx.params}.
|
45
|
+
* @param paramsTuple.0 - The proven {@link Tx} object to send.
|
46
|
+
* @returns A promise that resolves to the {@link TxHash} of the sent transaction.
|
47
|
+
* Type defined by {@link AztecWalletMethodMap.aztec_sendTx.result}.
|
48
|
+
* @throws {Error} If the `tx` parameter is missing or invalid.
|
49
|
+
*/
|
50
|
+
aztec_sendTx: (ctx: AztecHandlerContext, paramsTuple: AztecWalletMethodMap["aztec_sendTx"]["params"]) => Promise<AztecWalletMethodMap["aztec_sendTx"]["result"]>;
|
51
|
+
/**
|
52
|
+
* Handles the "aztec_getTxReceipt" JSON-RPC method.
|
53
|
+
* Retrieves the {@link TxReceipt} for a transaction identified by its {@link TxHash},
|
54
|
+
* using the {@link AccountWallet} in the context.
|
55
|
+
*
|
56
|
+
* The receipt provides information about the transaction's execution status
|
57
|
+
* (e.g., success, failure, reverted), block inclusion, and any emitted events.
|
58
|
+
*
|
59
|
+
* @param ctx - The {@link AztecHandlerContext} containing the `wallet` instance.
|
60
|
+
* @param paramsTuple - A tuple containing the transaction hash.
|
61
|
+
* Defined by {@link AztecWalletMethodMap.aztec_getTxReceipt.params}.
|
62
|
+
* @param paramsTuple.0 - The {@link TxHash} of the transaction.
|
63
|
+
* @returns A promise that resolves to the {@link TxReceipt}.
|
64
|
+
* Type defined by {@link AztecWalletMethodMap.aztec_getTxReceipt.result}.
|
65
|
+
* @throws {Error} If the `txHash` parameter is missing or invalid.
|
66
|
+
*/
|
67
|
+
aztec_getTxReceipt: (ctx: AztecHandlerContext, paramsTuple: AztecWalletMethodMap["aztec_getTxReceipt"]["params"]) => Promise<AztecWalletMethodMap["aztec_getTxReceipt"]["result"]>;
|
68
|
+
/**
|
69
|
+
* Handles the "aztec_simulateTx" JSON-RPC method.
|
70
|
+
* Simulates the execution of a {@link TxExecutionRequest} without actually proving
|
71
|
+
* or sending it to the network. This is useful for estimating gas, verifying
|
72
|
+
* correctness, or debugging.
|
73
|
+
*
|
74
|
+
* @param ctx - The {@link AztecHandlerContext} containing the `wallet` instance.
|
75
|
+
* @param paramsTuple - A tuple containing the parameters for simulation.
|
76
|
+
* Defined by {@link AztecWalletMethodMap.aztec_simulateTx.params}.
|
77
|
+
* @param paramsTuple.0 - The {@link TxExecutionRequest} to simulate.
|
78
|
+
* @param paramsTuple.1 - Optional: Boolean indicating whether to simulate public parts of the transaction. Defaults to `false`.
|
79
|
+
* @param paramsTuple.2 - Optional: The {@link AztecAddress} of the message sender for simulation context.
|
80
|
+
* @param paramsTuple.3 - Optional: Boolean flag to skip transaction validation during simulation.
|
81
|
+
* @param paramsTuple.4 - Optional: Boolean flag to skip fee enforcement during simulation.
|
82
|
+
* @returns A promise that resolves to the {@link TxSimulationResult}.
|
83
|
+
* Type defined by {@link AztecWalletMethodMap.aztec_simulateTx.result}.
|
84
|
+
* @throws {Error} If the `txRequest` parameter is missing or invalid.
|
85
|
+
*/
|
86
|
+
aztec_simulateTx: (ctx: AztecHandlerContext, paramsTuple: AztecWalletMethodMap["aztec_simulateTx"]["params"]) => Promise<AztecWalletMethodMap["aztec_simulateTx"]["result"]>;
|
87
|
+
/**
|
88
|
+
* Handles the "aztec_profileTx" JSON-RPC method.
|
89
|
+
* Profiles a {@link TxExecutionRequest} to gather performance metrics, such as
|
90
|
+
* gate counts and execution steps, without sending it to the network.
|
91
|
+
*
|
92
|
+
* @param ctx - The {@link AztecHandlerContext} containing the `wallet` instance.
|
93
|
+
* @param paramsTuple - A tuple containing the parameters for profiling.
|
94
|
+
* Defined by {@link AztecWalletMethodMap.aztec_profileTx.params}.
|
95
|
+
* @param paramsTuple.0 - The {@link TxExecutionRequest} to profile.
|
96
|
+
* @param paramsTuple.1 - Optional: The profiling mode ('gates', 'execution-steps', or 'full'). Defaults to 'gates'.
|
97
|
+
* @param paramsTuple.2 - Optional: Boolean flag to skip proof generation during profiling.
|
98
|
+
* @param paramsTuple.3 - Optional: The {@link AztecAddress} of the message sender for profiling context.
|
99
|
+
* @returns A promise that resolves to the {@link TxProfileResult}.
|
100
|
+
* Type defined by {@link AztecWalletMethodMap.aztec_profileTx.result}.
|
101
|
+
* @throws {Error} If the `txRequest` parameter is missing or invalid.
|
102
|
+
*/
|
103
|
+
aztec_profileTx: (ctx: AztecHandlerContext, paramsTuple: AztecWalletMethodMap["aztec_profileTx"]["params"]) => Promise<AztecWalletMethodMap["aztec_profileTx"]["result"]>;
|
104
|
+
/**
|
105
|
+
* Handles the "aztec_simulateUtility" JSON-RPC method.
|
106
|
+
* Simulates a call to a utility (view) function on a contract. Utility functions
|
107
|
+
* are read-only and do not modify state or require a transaction.
|
108
|
+
*
|
109
|
+
* @param ctx - The {@link AztecHandlerContext} containing the `wallet` instance.
|
110
|
+
* @param paramsTuple - A tuple containing the parameters for the utility function call.
|
111
|
+
* Defined by {@link AztecWalletMethodMap.aztec_simulateUtility.params}.
|
112
|
+
* @param paramsTuple.0 - The name of the utility function to call.
|
113
|
+
* @param paramsTuple.1 - An array of arguments for the function call.
|
114
|
+
* @param paramsTuple.2 - The {@link AztecAddress} of the contract or account to call.
|
115
|
+
* @param paramsTuple.3 - Optional: An array of {@link AuthWitness} for authorization, if needed.
|
116
|
+
* @param paramsTuple.4 - Optional: The {@link AztecAddress} of the sender, if relevant for the utility call.
|
117
|
+
* @returns A promise that resolves to the {@link UtilitySimulationResult}.
|
118
|
+
* Type defined by {@link AztecWalletMethodMap.aztec_simulateUtility.result}.
|
119
|
+
* @throws {Error} If required parameters like `functionName`, `args`, or `to` are missing or invalid.
|
120
|
+
*/
|
121
|
+
aztec_simulateUtility: (ctx: AztecHandlerContext, paramsTuple: AztecWalletMethodMap["aztec_simulateUtility"]["params"]) => Promise<AztecWalletMethodMap["aztec_simulateUtility"]["result"]>;
|
122
|
+
};
|
123
|
+
//# sourceMappingURL=transaction.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../../src/wallet/handlers/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAK3D;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB;IAErC;;;;;;;;;;;;;;;OAeG;yBAEI,mBAAmB,eACX,oBAAoB,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,KAC3D,OAAO,CAAC,oBAAoB,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,CAAC;IAgC3D;;;;;;;;;;;;;;;OAeG;wBAEI,mBAAmB,eACX,oBAAoB,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,KAC1D,OAAO,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,CAAC;IAU1D;;;;;;;;;;;;;;;OAeG;8BAEI,mBAAmB,eACX,oBAAoB,CAAC,oBAAoB,CAAC,CAAC,QAAQ,CAAC,KAChE,OAAO,CAAC,oBAAoB,CAAC,oBAAoB,CAAC,CAAC,QAAQ,CAAC,CAAC;IAUhE;;;;;;;;;;;;;;;;;OAiBG;4BAEI,mBAAmB,eACX,oBAAoB,CAAC,kBAAkB,CAAC,CAAC,QAAQ,CAAC,KAC9D,OAAO,CAAC,oBAAoB,CAAC,kBAAkB,CAAC,CAAC,QAAQ,CAAC,CAAC;IA0B9D;;;;;;;;;;;;;;;OAeG;2BAEI,mBAAmB,eACX,oBAAoB,CAAC,iBAAiB,CAAC,CAAC,QAAQ,CAAC,KAC7D,OAAO,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,CAAC,QAAQ,CAAC,CAAC;IAY7D;;;;;;;;;;;;;;;;OAgBG;iCAEI,mBAAmB,eACX,oBAAoB,CAAC,uBAAuB,CAAC,CAAC,QAAQ,CAAC,KACnE,OAAO,CAAC,oBAAoB,CAAC,uBAAuB,CAAC,CAAC,QAAQ,CAAC,CAAC;EAUtE"}
|
@@ -0,0 +1,191 @@
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
2
|
+
const logger = createLogger('aztec-rpc-wallet:transaction');
|
3
|
+
/**
|
4
|
+
* Creates handlers for transaction-related Aztec wallet JSON-RPC methods.
|
5
|
+
* These handlers are responsible for the core lifecycle of an Aztec transaction,
|
6
|
+
* including proving, sending, simulating, and retrieving receipts.
|
7
|
+
*
|
8
|
+
* Each handler function receives an {@link AztecHandlerContext}, providing access to the
|
9
|
+
* {@link AccountWallet} and {@link PXE} client instances necessary for these operations.
|
10
|
+
*
|
11
|
+
* @returns An object where keys are transaction-related method names
|
12
|
+
* (e.g., "aztec_proveTx", "aztec_sendTx") and values are their
|
13
|
+
* corresponding handler functions.
|
14
|
+
* @see {@link AztecWalletMethodMap} for method definitions.
|
15
|
+
*/
|
16
|
+
export function createTransactionHandlers() {
|
17
|
+
return {
|
18
|
+
/**
|
19
|
+
* Handles the "aztec_proveTx" JSON-RPC method.
|
20
|
+
* Generates zero-knowledge proofs for a given {@link TxExecutionRequest}.
|
21
|
+
* If the {@link PrivateExecutionResult} is not provided, this handler will first
|
22
|
+
* simulate the private execution of the transaction to obtain it.
|
23
|
+
*
|
24
|
+
* @param ctx - The {@link AztecHandlerContext} containing the `wallet` instance.
|
25
|
+
* @param paramsTuple - A tuple containing the transaction execution request and an optional private execution result.
|
26
|
+
* Defined by {@link AztecWalletMethodMap.aztec_proveTx.params}.
|
27
|
+
* @param paramsTuple.0 - The {@link TxExecutionRequest} to prove.
|
28
|
+
* @param paramsTuple.1 - Optional: The {@link PrivateExecutionResult} from a prior private simulation.
|
29
|
+
* If not provided, a private simulation will be performed internally.
|
30
|
+
* @returns A promise that resolves to the {@link TxProvingResult}, which includes the proven transaction.
|
31
|
+
* Type defined by {@link AztecWalletMethodMap.aztec_proveTx.result}.
|
32
|
+
* @throws {Error} If `txRequest` is missing, or if simulation is needed but fails to produce a `PrivateExecutionResult`.
|
33
|
+
*/
|
34
|
+
aztec_proveTx: async (ctx, paramsTuple) => {
|
35
|
+
let [txRequest, privateExecutionResult] = paramsTuple; // privateExecutionResult can now be undefined
|
36
|
+
logger.debug(`[HANDLER] aztec_proveTx: txRequest received = ${!!txRequest}`);
|
37
|
+
if (!txRequest) {
|
38
|
+
// Only txRequest is mandatory now
|
39
|
+
throw new Error('Invalid parameters received in tuple for aztec_proveTx: txRequest is missing');
|
40
|
+
}
|
41
|
+
if (!privateExecutionResult) {
|
42
|
+
logger.debug('[HANDLER] aztec_proveTx: privateExecutionResult not provided, simulating transaction first.');
|
43
|
+
// Simulate the private part of the transaction to get the PrivateExecutionResult
|
44
|
+
// Pass false for simulatePublic, as we only need the private execution.
|
45
|
+
// Pass undefined for msgSender, skipTxValidation, skipFeeEnforcement to use defaults.
|
46
|
+
const simulationResult = await ctx.wallet.simulateTx(txRequest, false, undefined, undefined, undefined);
|
47
|
+
privateExecutionResult = simulationResult.privateExecutionResult;
|
48
|
+
if (!privateExecutionResult) {
|
49
|
+
throw new Error('Failed to obtain PrivateExecutionResult from simulation for aztec_proveTx');
|
50
|
+
}
|
51
|
+
logger.debug('[HANDLER] aztec_proveTx: privateExecutionResult obtained from simulation.');
|
52
|
+
}
|
53
|
+
return await ctx.wallet.proveTx(txRequest, privateExecutionResult);
|
54
|
+
},
|
55
|
+
/**
|
56
|
+
* Handles the "aztec_sendTx" JSON-RPC method.
|
57
|
+
* Sends a proven {@link Tx} (transaction object) to the Aztec network via the
|
58
|
+
* {@link AccountWallet} in the context.
|
59
|
+
*
|
60
|
+
* This is typically the final step in submitting a transaction after it has been
|
61
|
+
* successfully proven by `aztec_proveTx`.
|
62
|
+
*
|
63
|
+
* @param ctx - The {@link AztecHandlerContext} containing the `wallet` instance.
|
64
|
+
* @param paramsTuple - A tuple containing the proven transaction.
|
65
|
+
* Defined by {@link AztecWalletMethodMap.aztec_sendTx.params}.
|
66
|
+
* @param paramsTuple.0 - The proven {@link Tx} object to send.
|
67
|
+
* @returns A promise that resolves to the {@link TxHash} of the sent transaction.
|
68
|
+
* Type defined by {@link AztecWalletMethodMap.aztec_sendTx.result}.
|
69
|
+
* @throws {Error} If the `tx` parameter is missing or invalid.
|
70
|
+
*/
|
71
|
+
aztec_sendTx: async (ctx, paramsTuple) => {
|
72
|
+
const [tx] = paramsTuple;
|
73
|
+
logger.debug(`[HANDLER] aztec_sendTx: tx hash = ${tx?.getTxHash()?.toString()}`);
|
74
|
+
if (!tx) {
|
75
|
+
// tx is mandatory
|
76
|
+
throw new Error('Invalid tx parameter received in tuple');
|
77
|
+
}
|
78
|
+
return await ctx.wallet.sendTx(tx);
|
79
|
+
},
|
80
|
+
/**
|
81
|
+
* Handles the "aztec_getTxReceipt" JSON-RPC method.
|
82
|
+
* Retrieves the {@link TxReceipt} for a transaction identified by its {@link TxHash},
|
83
|
+
* using the {@link AccountWallet} in the context.
|
84
|
+
*
|
85
|
+
* The receipt provides information about the transaction's execution status
|
86
|
+
* (e.g., success, failure, reverted), block inclusion, and any emitted events.
|
87
|
+
*
|
88
|
+
* @param ctx - The {@link AztecHandlerContext} containing the `wallet` instance.
|
89
|
+
* @param paramsTuple - A tuple containing the transaction hash.
|
90
|
+
* Defined by {@link AztecWalletMethodMap.aztec_getTxReceipt.params}.
|
91
|
+
* @param paramsTuple.0 - The {@link TxHash} of the transaction.
|
92
|
+
* @returns A promise that resolves to the {@link TxReceipt}.
|
93
|
+
* Type defined by {@link AztecWalletMethodMap.aztec_getTxReceipt.result}.
|
94
|
+
* @throws {Error} If the `txHash` parameter is missing or invalid.
|
95
|
+
*/
|
96
|
+
aztec_getTxReceipt: async (ctx, paramsTuple) => {
|
97
|
+
const [txHash] = paramsTuple;
|
98
|
+
logger.debug(`[HANDLER] aztec_getTxReceipt: txHash = ${txHash?.toString()}`);
|
99
|
+
if (!txHash) {
|
100
|
+
// txHash is mandatory
|
101
|
+
throw new Error('Invalid txHash parameter received in tuple');
|
102
|
+
}
|
103
|
+
return await ctx.wallet.getTxReceipt(txHash);
|
104
|
+
},
|
105
|
+
/**
|
106
|
+
* Handles the "aztec_simulateTx" JSON-RPC method.
|
107
|
+
* Simulates the execution of a {@link TxExecutionRequest} without actually proving
|
108
|
+
* or sending it to the network. This is useful for estimating gas, verifying
|
109
|
+
* correctness, or debugging.
|
110
|
+
*
|
111
|
+
* @param ctx - The {@link AztecHandlerContext} containing the `wallet` instance.
|
112
|
+
* @param paramsTuple - A tuple containing the parameters for simulation.
|
113
|
+
* Defined by {@link AztecWalletMethodMap.aztec_simulateTx.params}.
|
114
|
+
* @param paramsTuple.0 - The {@link TxExecutionRequest} to simulate.
|
115
|
+
* @param paramsTuple.1 - Optional: Boolean indicating whether to simulate public parts of the transaction. Defaults to `false`.
|
116
|
+
* @param paramsTuple.2 - Optional: The {@link AztecAddress} of the message sender for simulation context.
|
117
|
+
* @param paramsTuple.3 - Optional: Boolean flag to skip transaction validation during simulation.
|
118
|
+
* @param paramsTuple.4 - Optional: Boolean flag to skip fee enforcement during simulation.
|
119
|
+
* @returns A promise that resolves to the {@link TxSimulationResult}.
|
120
|
+
* Type defined by {@link AztecWalletMethodMap.aztec_simulateTx.result}.
|
121
|
+
* @throws {Error} If the `txRequest` parameter is missing or invalid.
|
122
|
+
*/
|
123
|
+
aztec_simulateTx: async (ctx, paramsTuple) => {
|
124
|
+
const [txRequest, simulatePublicInput, // simulatePublic is optional in PXE interface
|
125
|
+
msgSender, skipTxValidation, skipFeeEnforcementInput, // skipFeeEnforcement is optional in PXE interface
|
126
|
+
] = paramsTuple;
|
127
|
+
// Handle optional params with defaults if necessary, matching PXE behavior
|
128
|
+
const simulatePublic = simulatePublicInput === undefined ? false : simulatePublicInput;
|
129
|
+
const skipFeeEnforcement = skipFeeEnforcementInput === undefined ? false : skipFeeEnforcementInput;
|
130
|
+
logger.debug(`[HANDLER] aztec_simulateTx: txRequest received = ${!!txRequest}`);
|
131
|
+
if (!txRequest) {
|
132
|
+
// txRequest is mandatory
|
133
|
+
throw new Error('Invalid txRequest parameter received in tuple');
|
134
|
+
}
|
135
|
+
return await ctx.wallet.simulateTx(txRequest, simulatePublic, msgSender, skipTxValidation, skipFeeEnforcement);
|
136
|
+
},
|
137
|
+
/**
|
138
|
+
* Handles the "aztec_profileTx" JSON-RPC method.
|
139
|
+
* Profiles a {@link TxExecutionRequest} to gather performance metrics, such as
|
140
|
+
* gate counts and execution steps, without sending it to the network.
|
141
|
+
*
|
142
|
+
* @param ctx - The {@link AztecHandlerContext} containing the `wallet` instance.
|
143
|
+
* @param paramsTuple - A tuple containing the parameters for profiling.
|
144
|
+
* Defined by {@link AztecWalletMethodMap.aztec_profileTx.params}.
|
145
|
+
* @param paramsTuple.0 - The {@link TxExecutionRequest} to profile.
|
146
|
+
* @param paramsTuple.1 - Optional: The profiling mode ('gates', 'execution-steps', or 'full'). Defaults to 'gates'.
|
147
|
+
* @param paramsTuple.2 - Optional: Boolean flag to skip proof generation during profiling.
|
148
|
+
* @param paramsTuple.3 - Optional: The {@link AztecAddress} of the message sender for profiling context.
|
149
|
+
* @returns A promise that resolves to the {@link TxProfileResult}.
|
150
|
+
* Type defined by {@link AztecWalletMethodMap.aztec_profileTx.result}.
|
151
|
+
* @throws {Error} If the `txRequest` parameter is missing or invalid.
|
152
|
+
*/
|
153
|
+
aztec_profileTx: async (ctx, paramsTuple) => {
|
154
|
+
const [txRequest, profileModeInput, skipProofGeneration, msgSender] = paramsTuple;
|
155
|
+
const profileMode = profileModeInput === undefined ? 'gates' : profileModeInput; // Default for optional
|
156
|
+
logger.debug(`[HANDLER] aztec_profileTx: txRequest received = ${!!txRequest}`);
|
157
|
+
if (!txRequest) {
|
158
|
+
// txRequest is mandatory
|
159
|
+
throw new Error('Invalid txRequest parameter received in tuple');
|
160
|
+
}
|
161
|
+
return await ctx.wallet.profileTx(txRequest, profileMode, skipProofGeneration, msgSender);
|
162
|
+
},
|
163
|
+
/**
|
164
|
+
* Handles the "aztec_simulateUtility" JSON-RPC method.
|
165
|
+
* Simulates a call to a utility (view) function on a contract. Utility functions
|
166
|
+
* are read-only and do not modify state or require a transaction.
|
167
|
+
*
|
168
|
+
* @param ctx - The {@link AztecHandlerContext} containing the `wallet` instance.
|
169
|
+
* @param paramsTuple - A tuple containing the parameters for the utility function call.
|
170
|
+
* Defined by {@link AztecWalletMethodMap.aztec_simulateUtility.params}.
|
171
|
+
* @param paramsTuple.0 - The name of the utility function to call.
|
172
|
+
* @param paramsTuple.1 - An array of arguments for the function call.
|
173
|
+
* @param paramsTuple.2 - The {@link AztecAddress} of the contract or account to call.
|
174
|
+
* @param paramsTuple.3 - Optional: An array of {@link AuthWitness} for authorization, if needed.
|
175
|
+
* @param paramsTuple.4 - Optional: The {@link AztecAddress} of the sender, if relevant for the utility call.
|
176
|
+
* @returns A promise that resolves to the {@link UtilitySimulationResult}.
|
177
|
+
* Type defined by {@link AztecWalletMethodMap.aztec_simulateUtility.result}.
|
178
|
+
* @throws {Error} If required parameters like `functionName`, `args`, or `to` are missing or invalid.
|
179
|
+
*/
|
180
|
+
aztec_simulateUtility: async (ctx, paramsTuple) => {
|
181
|
+
const [functionName, args, to, authWits, from] = paramsTuple;
|
182
|
+
logger.debug(`[HANDLER] aztec_simulateUtility: functionName = ${functionName}, to = ${to?.toString()}`);
|
183
|
+
if (!functionName || !args || !to) {
|
184
|
+
// Mandatory params
|
185
|
+
throw new Error('Invalid parameters received in tuple for aztec_simulateUtility');
|
186
|
+
}
|
187
|
+
return await ctx.wallet.simulateUtility(functionName, args, to, authWits, from);
|
188
|
+
},
|
189
|
+
};
|
190
|
+
}
|
191
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHJhbnNhY3Rpb24uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvd2FsbGV0L2hhbmRsZXJzL3RyYW5zYWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUVyRCxNQUFNLE1BQU0sR0FBRyxZQUFZLENBQUMsOEJBQThCLENBQUMsQ0FBQztBQUU1RDs7Ozs7Ozs7Ozs7O0dBWUc7QUFDSCxNQUFNLFVBQVUseUJBQXlCO0lBQ3ZDLE9BQU87UUFDTDs7Ozs7Ozs7Ozs7Ozs7O1dBZUc7UUFDSCxhQUFhLEVBQUUsS0FBSyxFQUNsQixHQUF3QixFQUN4QixXQUE0RCxFQUNGLEVBQUU7WUFDNUQsSUFBS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FBQztRQUNsRixDQUFDO0tBQ0YsQ0FBQztBQUNKLENBQUMifQ==
|
@@ -0,0 +1,75 @@
|
|
1
|
+
/**
|
2
|
+
* @module @walletmesh/aztec-rpc-wallet/wallet/serializers
|
3
|
+
*
|
4
|
+
* This module provides the primary JSON-RPC serializer (`AztecWalletSerializer`)
|
5
|
+
* for handling Aztec-specific data types over JSON-RPC. It leverages Zod schemas
|
6
|
+
* from `@aztec/foundation/schemas` and `@aztec/aztec.js` for robust serialization
|
7
|
+
* and deserialization of parameters and results for all Aztec wallet methods.
|
8
|
+
*
|
9
|
+
* It also includes a helper function `registerAztecSerializers` for applying these
|
10
|
+
* serializers to a `JSONRPCNode` instance, typically used on the wallet-side
|
11
|
+
* implementation (e.g., in `createAztecWalletNode`).
|
12
|
+
*
|
13
|
+
* The serialization strategy involves:
|
14
|
+
* - Using Aztec's `jsonStringify` and `jsonParseWithSchema` for types that have
|
15
|
+
* corresponding Zod schemas.
|
16
|
+
* - Custom logic for arrays of specific types (e.g., `AztecAddress[]`).
|
17
|
+
* - A fallback serializer for parameters and results not explicitly covered.
|
18
|
+
* - Detailed parameter deserialization logic within `AztecWalletSerializer.params.deserialize`
|
19
|
+
* to reconstruct complex Aztec objects from their JSON representations.
|
20
|
+
*/
|
21
|
+
import type { AztecWalletMethodMap } from '../types.js';
|
22
|
+
import type { JSONRPCNode, JSONRPCSerializer, JSONRPCParams } from '@walletmesh/jsonrpc';
|
23
|
+
/**
|
24
|
+
* A comprehensive {@link JSONRPCSerializer} for all Aztec wallet methods.
|
25
|
+
*
|
26
|
+
* This serializer handles both parameters and results:
|
27
|
+
*
|
28
|
+
* **Parameters (`params`):**
|
29
|
+
* - `serialize`: Currently uses a fallback mechanism (`createFallbackSerializer`) which
|
30
|
+
* stringifies parameters using `jsonStringify`. This assumes the client-side
|
31
|
+
* (e.g., {@link AztecDappWallet} via {@link AztecRouterProvider}) sends parameters
|
32
|
+
* already in a format that can be processed by the `deserialize` logic after
|
33
|
+
* basic JSON parsing.
|
34
|
+
* - `deserialize`: Contains detailed, method-specific logic to parse the JSON string
|
35
|
+
* of incoming parameters and reconstruct them into their correct Aztec types
|
36
|
+
* (e.g., `AztecAddress.fromString`, `TxExecutionRequest.schema.parse`). It uses
|
37
|
+
* Zod schemas and helper functions (`ensureParam`, `getOptionalParam`) for
|
38
|
+
* validation and type conversion.
|
39
|
+
*
|
40
|
+
* **Results (`result`):**
|
41
|
+
* - `serialize`: For each method, it attempts to use a specific serializer defined in
|
42
|
+
* `RESULT_SERIALIZERS`. These typically use `jsonStringify` with a Zod schema
|
43
|
+
* for the specific result type (e.g., `AztecAddress.schema`, `TxHash.schema`).
|
44
|
+
* If no specific serializer is found, it uses `createFallbackSerializer`.
|
45
|
+
* - `deserialize`: Similar to result serialization, it uses `RESULT_SERIALIZERS`
|
46
|
+
* to find a method-specific deserializer, often employing `jsonParseWithSchema`
|
47
|
+
* with the appropriate Zod schema. If no specific deserializer exists, it may
|
48
|
+
* return the raw data or attempt a simple JSON parse.
|
49
|
+
*
|
50
|
+
* This serializer is crucial for ensuring that complex Aztec objects maintain their
|
51
|
+
* type integrity and structure when transmitted over JSON-RPC.
|
52
|
+
*
|
53
|
+
* @see {@link AztecWalletMethodMap} for the definitions of methods, params, and results.
|
54
|
+
* @see {@link JSONRPCSerializer} for the interface it implements.
|
55
|
+
*/
|
56
|
+
export declare const AztecWalletSerializer: JSONRPCSerializer<JSONRPCParams, unknown>;
|
57
|
+
/**
|
58
|
+
* Registers the {@link AztecWalletSerializer} for all relevant Aztec JSON-RPC methods
|
59
|
+
* on a given {@link JSONRPCNode} instance.
|
60
|
+
*
|
61
|
+
* This function is typically called on the wallet-side (e.g., within
|
62
|
+
* `createAztecWalletNode`) to equip the node with the necessary serialization
|
63
|
+
* capabilities for handling Aztec methods.
|
64
|
+
*
|
65
|
+
* It iterates through a predefined list of Aztec methods and associates each
|
66
|
+
* with the `AztecWalletSerializer`.
|
67
|
+
*
|
68
|
+
* @param node - The {@link JSONRPCNode} instance on which to register the serializers.
|
69
|
+
* This node should be typed with {@link AztecWalletMethodMap}.
|
70
|
+
*
|
71
|
+
* @see {@link createAztecWalletNode} where this function is used.
|
72
|
+
* @see {@link AztecWalletSerializer} which provides the serialization logic.
|
73
|
+
*/
|
74
|
+
export declare function registerAztecSerializers(node: JSONRPCNode<AztecWalletMethodMap>): void;
|
75
|
+
//# sourceMappingURL=serializers.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"serializers.d.ts","sourceRoot":"","sources":["../../src/wallet/serializers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EAEjB,aAAa,EACd,MAAM,qBAAqB,CAAC;AA2M7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,qBAAqB,EAAE,iBAAiB,CAAC,aAAa,EAAE,OAAO,CAwQ3E,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,WAAW,CAAC,oBAAoB,CAAC,QAsC/E"}
|