@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
@@ -1,6 +1,5 @@
|
|
1
1
|
import { describe, expect, it, vi, beforeEach, type Mock } from 'vitest';
|
2
2
|
import type { AztecAddress, ContractArtifact, Fr, Wallet } from '@aztec/aztec.js';
|
3
|
-
import { randomDeployedContract } from '@aztec/circuit-types';
|
4
3
|
import { ContractArtifactCache } from './contractArtifactCache.js';
|
5
4
|
import { AztecWalletError } from './errors.js';
|
6
5
|
|
@@ -13,13 +12,25 @@ describe('ContractArtifactCache', () => {
|
|
13
12
|
|
14
13
|
beforeEach(async () => {
|
15
14
|
// Mock contract address and class ID
|
16
|
-
// Create
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
// Create mocks instead of using randomDeployedContract to avoid native binding issues
|
16
|
+
mockContractAddress = {
|
17
|
+
toString: () => '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
|
18
|
+
equals: () => false,
|
19
|
+
isZero: () => false,
|
20
|
+
toField: () => mockContractClassId,
|
21
|
+
} as unknown as AztecAddress;
|
22
|
+
|
23
|
+
mockContractClassId = {
|
24
|
+
toString: () => '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
|
25
|
+
toBigInt: () => BigInt(123),
|
26
|
+
} as unknown as Fr;
|
27
|
+
|
28
|
+
mockArtifact = {
|
29
|
+
name: 'TestContract',
|
30
|
+
functions: [],
|
31
|
+
outputs: {},
|
32
|
+
fileMap: {},
|
33
|
+
} as unknown as ContractArtifact;
|
23
34
|
|
24
35
|
// Create mock wallet
|
25
36
|
wallet = {
|
@@ -50,7 +61,7 @@ describe('ContractArtifactCache', () => {
|
|
50
61
|
it('fetches and caches artifact on cache miss', async () => {
|
51
62
|
// Setup: Configure wallet mocks
|
52
63
|
(wallet.getContractMetadata as Mock).mockResolvedValue({
|
53
|
-
contractInstance: {
|
64
|
+
contractInstance: { currentContractClassId: mockContractClassId },
|
54
65
|
});
|
55
66
|
(wallet.getContractClassMetadata as Mock).mockResolvedValue({ artifact: mockArtifact });
|
56
67
|
|
@@ -90,7 +101,7 @@ describe('ContractArtifactCache', () => {
|
|
90
101
|
it('throws error if contract class metadata not found', async () => {
|
91
102
|
// Setup: Mock contract metadata found but class metadata missing
|
92
103
|
(wallet.getContractMetadata as Mock).mockResolvedValue({
|
93
|
-
contractInstance: {
|
104
|
+
contractInstance: { currentContractClassId: mockContractClassId },
|
94
105
|
});
|
95
106
|
(wallet.getContractClassMetadata as Mock).mockResolvedValue({ artifact: undefined });
|
96
107
|
|
@@ -1,57 +1,74 @@
|
|
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
|
-
|
8
1
|
import type { AztecAddress, ContractArtifact, Wallet } from '@aztec/aztec.js';
|
9
2
|
|
10
3
|
import { AztecWalletError } from './errors.js';
|
11
4
|
|
12
5
|
/**
|
13
|
-
*
|
6
|
+
* Manages an in-memory cache for Aztec {@link ContractArtifact}s.
|
7
|
+
*
|
8
|
+
* This class is designed to optimize performance by reducing redundant fetches
|
9
|
+
* of contract artifacts. When an artifact is requested for a given contract address,
|
10
|
+
* the cache first checks its local store. If the artifact is not found (a cache miss),
|
11
|
+
* it uses the provided {@link Wallet} instance to retrieve the contract's metadata,
|
12
|
+
* then its class metadata (which includes the artifact), stores it in the cache,
|
13
|
+
* and finally returns it. Subsequent requests for the same artifact will be served
|
14
|
+
* directly from the cache.
|
15
|
+
*
|
16
|
+
* This caching strategy helps to:
|
17
|
+
* - Minimize network requests to the PXE or node for contract data.
|
18
|
+
* - Reduce processing overhead associated with fetching and parsing artifacts.
|
19
|
+
* - Conserve memory by reusing already loaded artifact instances.
|
14
20
|
*
|
15
|
-
*
|
16
|
-
*
|
17
|
-
* 1. First checks the cache for an existing artifact
|
18
|
-
* 2. If not found, fetches the contract instance and its artifact from the wallet
|
19
|
-
* 3. Stores the artifact in the cache for future use
|
20
|
-
* 4. Returns the artifact to the caller
|
21
|
+
* The cache is typically used within the `AztecHandlerContext` on the wallet-side
|
22
|
+
* to provide efficient artifact access to RPC method handlers.
|
21
23
|
*
|
22
|
-
*
|
23
|
-
*
|
24
|
-
*
|
25
|
-
* - Memory usage by reusing existing artifacts
|
24
|
+
* @see {@link AztecHandlerContext}
|
25
|
+
* @see {@link Wallet}
|
26
|
+
* @see {@link ContractArtifact}
|
26
27
|
*/
|
27
28
|
export class ContractArtifactCache {
|
28
|
-
/**
|
29
|
+
/**
|
30
|
+
* In-memory map storing contract artifacts, keyed by their stringified {@link AztecAddress}.
|
31
|
+
* @internal
|
32
|
+
*/
|
29
33
|
private cache = new Map<string, ContractArtifact>();
|
30
|
-
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Reference to the `aztec.js` {@link Wallet} instance used to fetch contract
|
37
|
+
* metadata and artifacts in case of a cache miss.
|
38
|
+
* @internal
|
39
|
+
*/
|
31
40
|
private wallet: Wallet;
|
32
41
|
|
33
42
|
/**
|
34
|
-
* Creates a new ContractArtifactCache instance.
|
35
|
-
*
|
43
|
+
* Creates a new `ContractArtifactCache` instance.
|
44
|
+
*
|
45
|
+
* @param wallet - The `aztec.js` {@link Wallet} instance that will be used to
|
46
|
+
* fetch contract metadata and artifacts if they are not found
|
47
|
+
* in the cache. This wallet should be capable of calling
|
48
|
+
* `getContractMetadata` and `getContractClassMetadata`.
|
36
49
|
*/
|
37
50
|
constructor(wallet: Wallet) {
|
38
51
|
this.wallet = wallet;
|
39
52
|
}
|
40
53
|
|
41
54
|
/**
|
42
|
-
* Retrieves the
|
43
|
-
* First checks the cache, then falls back to fetching from the wallet if needed.
|
55
|
+
* Retrieves the {@link ContractArtifact} for a given {@link AztecAddress}.
|
44
56
|
*
|
45
|
-
*
|
46
|
-
* 1.
|
47
|
-
* 2. If
|
48
|
-
* 3.
|
49
|
-
*
|
50
|
-
*
|
57
|
+
* This method implements a cache-aside pattern:
|
58
|
+
* 1. It first checks if the artifact for the `contractAddress` is already in the cache.
|
59
|
+
* 2. If found (cache hit), the cached artifact is returned immediately.
|
60
|
+
* 3. If not found (cache miss):
|
61
|
+
* a. It fetches the {@link ContractMetadata} for the `contractAddress` using the wallet.
|
62
|
+
* b. It then fetches the {@link ContractClassMetadata} using the class ID from the contract metadata.
|
63
|
+
* This class metadata is expected to contain the artifact.
|
64
|
+
* c. The retrieved artifact is stored in the cache, associated with the `contractAddress`.
|
65
|
+
* d. The artifact is then returned.
|
51
66
|
*
|
52
|
-
* @param contractAddress - The
|
53
|
-
* @returns
|
54
|
-
* @throws {AztecWalletError}
|
67
|
+
* @param contractAddress - The {@link AztecAddress} of the contract whose artifact is to be retrieved.
|
68
|
+
* @returns A promise that resolves to the {@link ContractArtifact}.
|
69
|
+
* @throws {AztecWalletError} if the contract instance or its class (and thus artifact)
|
70
|
+
* is not registered with the wallet or cannot be found.
|
71
|
+
* Also re-throws other errors encountered during wallet calls.
|
55
72
|
*/
|
56
73
|
public async getContractArtifact(contractAddress: AztecAddress): Promise<ContractArtifact> {
|
57
74
|
const addressStr = contractAddress.toString();
|
@@ -67,10 +84,12 @@ export class ContractArtifactCache {
|
|
67
84
|
throw new AztecWalletError('contractInstanceNotRegistered', addressStr);
|
68
85
|
}
|
69
86
|
|
70
|
-
const contractClassMetadata = await this.wallet.getContractClassMetadata(
|
87
|
+
const contractClassMetadata = await this.wallet.getContractClassMetadata(
|
88
|
+
contract.currentContractClassId,
|
89
|
+
);
|
71
90
|
const artifact = contractClassMetadata.artifact;
|
72
91
|
if (!artifact) {
|
73
|
-
throw new AztecWalletError('contractClassNotRegistered', contract.
|
92
|
+
throw new AztecWalletError('contractClassNotRegistered', contract.currentContractClassId.toString());
|
74
93
|
}
|
75
94
|
this.cache.set(addressStr, artifact);
|
76
95
|
return artifact;
|
package/src/errors.ts
CHANGED
@@ -1,8 +1,21 @@
|
|
1
|
+
/**
|
2
|
+
* @module @walletmesh/aztec-rpc-wallet/errors
|
3
|
+
*
|
4
|
+
* This module defines custom error types and codes specific to the Aztec RPC Wallet.
|
5
|
+
* It provides a structured way to represent errors that can occur during
|
6
|
+
* interactions with the Aztec wallet, aligning with JSON-RPC error standards
|
7
|
+
* while offering more specific error information.
|
8
|
+
*/
|
9
|
+
|
1
10
|
import { JSONRPCError } from '@walletmesh/jsonrpc';
|
2
11
|
|
3
12
|
/**
|
4
|
-
*
|
13
|
+
* An object acting as an enum for specific Aztec Wallet RPC error types.
|
14
|
+
* Each key represents a distinct error condition that can occur within the Aztec wallet system.
|
15
|
+
* These keys are used to look up corresponding error codes and messages in {@link AztecWalletErrorMap}.
|
16
|
+
*
|
5
17
|
* @public
|
18
|
+
* @readonly
|
6
19
|
*/
|
7
20
|
export const AztecWalletErrorType = {
|
8
21
|
unknownInternalError: 'unknownInternalError',
|
@@ -25,18 +38,27 @@ export const AztecWalletErrorType = {
|
|
25
38
|
} as const;
|
26
39
|
|
27
40
|
/**
|
28
|
-
*
|
41
|
+
* A type alias representing the string literal union of all valid keys from {@link AztecWalletErrorType}.
|
42
|
+
* This provides type safety when referring to specific Aztec wallet error types.
|
43
|
+
*
|
29
44
|
* @public
|
30
45
|
*/
|
31
46
|
export type AztecWalletErrorType = (typeof AztecWalletErrorType)[keyof typeof AztecWalletErrorType];
|
32
47
|
|
33
48
|
/**
|
34
|
-
*
|
49
|
+
* A map associating each {@link AztecWalletErrorType} with a specific JSON-RPC error code
|
50
|
+
* and a human-readable message. This map is used by the {@link AztecWalletError} class
|
51
|
+
* to construct standardized error objects.
|
52
|
+
*
|
53
|
+
* The error codes are chosen from the range typically reserved for server-defined errors
|
54
|
+
* in JSON-RPC (e.g., -32000 to -32099).
|
55
|
+
*
|
35
56
|
* @public
|
57
|
+
* @readonly
|
36
58
|
*/
|
37
59
|
export const AztecWalletErrorMap: Record<AztecWalletErrorType, { code: number; message: string }> = {
|
38
60
|
unknownInternalError: { code: -32000, message: 'Unknown internal error' },
|
39
|
-
refused: { code: -32001, message: 'User refused transaction' },
|
61
|
+
refused: { code: -32001, message: 'User refused transaction' }, // Or request
|
40
62
|
walletNotConnected: { code: -32002, message: 'Wallet not connected' },
|
41
63
|
contractInstanceNotRegistered: { code: -32003, message: 'Contract instance not registered' },
|
42
64
|
contractClassNotRegistered: { code: -32004, message: 'Contract class not registered' },
|
@@ -55,16 +77,42 @@ export const AztecWalletErrorMap: Record<AztecWalletErrorType, { code: number; m
|
|
55
77
|
};
|
56
78
|
|
57
79
|
/**
|
58
|
-
* Custom error class for Aztec
|
80
|
+
* Custom error class for representing errors specific to the Aztec RPC Wallet.
|
81
|
+
* It extends the base {@link JSONRPCError} from `@walletmesh/jsonrpc` and uses
|
82
|
+
* predefined error types and messages from {@link AztecWalletErrorMap}.
|
83
|
+
*
|
84
|
+
* This class allows for consistent error handling and reporting within the
|
85
|
+
* Aztec wallet system, providing both a standard JSON-RPC error code and
|
86
|
+
* a more specific Aztec error type.
|
87
|
+
*
|
59
88
|
* @public
|
89
|
+
* @example
|
90
|
+
* ```typescript
|
91
|
+
* if (!isConnected) {
|
92
|
+
* throw new AztecWalletError('walletNotConnected', 'Attempted to call method while disconnected.');
|
93
|
+
* }
|
94
|
+
* ```
|
60
95
|
*/
|
61
96
|
export class AztecWalletError extends JSONRPCError {
|
62
97
|
/**
|
63
|
-
*
|
64
|
-
|
65
|
-
|
98
|
+
* The specific Aztec wallet error type.
|
99
|
+
*/
|
100
|
+
public readonly aztecErrorType: AztecWalletErrorType;
|
101
|
+
|
102
|
+
/**
|
103
|
+
* Creates a new `AztecWalletError` instance.
|
104
|
+
*
|
105
|
+
* @param errorType - The specific {@link AztecWalletErrorType} identifying the error.
|
106
|
+
* This key is used to look up the code and message from {@link AztecWalletErrorMap}.
|
107
|
+
* @param data - Optional additional data associated with the error. This can be a string
|
108
|
+
* or a record, providing more context. It will be included in the `data`
|
109
|
+
* field of the JSON-RPC error object.
|
66
110
|
*/
|
67
|
-
constructor(
|
68
|
-
|
111
|
+
constructor(errorType: AztecWalletErrorType, data?: string | Record<string, unknown>) {
|
112
|
+
const errorDetails = AztecWalletErrorMap[errorType];
|
113
|
+
super(errorDetails.code, errorDetails.message, data);
|
114
|
+
this.aztecErrorType = errorType;
|
115
|
+
// Ensure the name property is set to the class name
|
116
|
+
this.name = 'AztecWalletError';
|
69
117
|
}
|
70
118
|
}
|
package/src/index.test.ts
CHANGED
@@ -2,12 +2,8 @@ import { describe, it, expect } from 'vitest';
|
|
2
2
|
import * as exports from './index.js';
|
3
3
|
|
4
4
|
describe('index exports', () => {
|
5
|
-
it('should export
|
6
|
-
expect(exports.
|
7
|
-
});
|
8
|
-
|
9
|
-
it('should export AztecChainWallet', () => {
|
10
|
-
expect(exports.AztecChainWallet).toBeDefined();
|
5
|
+
it('should export AztecDappWallet', () => {
|
6
|
+
expect(exports.AztecDappWallet).toBeDefined();
|
11
7
|
});
|
12
8
|
|
13
9
|
it('should export error utilities', () => {
|
package/src/index.ts
CHANGED
@@ -1,64 +1,100 @@
|
|
1
1
|
/**
|
2
2
|
* @module @walletmesh/aztec-rpc-wallet
|
3
3
|
*
|
4
|
-
*
|
5
|
-
*
|
4
|
+
* JSON-RPC wallet integration for Aztec Protocol, built on WalletMesh router for multi-chain support.
|
5
|
+
* This package provides both wallet-side and dApp-side implementations for Aztec integration.
|
6
6
|
*/
|
7
7
|
|
8
|
+
// Wallet-side exports
|
8
9
|
/**
|
9
|
-
*
|
10
|
-
*
|
10
|
+
* Creates an Aztec wallet node that can be used with WalletRouter.
|
11
|
+
* This is the wallet-side implementation that handles JSON-RPC requests.
|
12
|
+
* @see {@link createAztecWalletNode}
|
11
13
|
*/
|
12
|
-
export {
|
14
|
+
export { createAztecWalletNode } from './wallet/create-node.js';
|
13
15
|
|
14
16
|
/**
|
15
|
-
*
|
16
|
-
* @see
|
17
|
+
* Context interface provided to all handler functions in the wallet implementation.
|
18
|
+
* @see {@link AztecHandlerContext}
|
17
19
|
*/
|
18
|
-
export {
|
20
|
+
export type { AztecHandlerContext } from './wallet/handlers/index.js';
|
19
21
|
|
22
|
+
// Client-side exports
|
20
23
|
/**
|
21
|
-
*
|
22
|
-
* @see
|
24
|
+
* DApp-side wallet class that implements the aztec.js Wallet interface.
|
25
|
+
* @see {@link AztecDappWallet}
|
23
26
|
*/
|
24
|
-
export {
|
25
|
-
export { AztecChainWalletMiddleware } from './types.js';
|
27
|
+
export { AztecDappWallet, createAztecWallet } from './client/aztec-dapp-wallet.js';
|
26
28
|
|
27
29
|
/**
|
28
|
-
*
|
29
|
-
*
|
30
|
+
* Extended WalletRouterProvider with built-in Aztec serialization support.
|
31
|
+
* Use this instead of the base WalletRouterProvider for automatic serialization
|
32
|
+
* of Aztec types on the client side.
|
33
|
+
* @see {@link AztecRouterProvider}
|
30
34
|
*/
|
31
|
-
export {
|
35
|
+
export { AztecRouterProvider } from './client/aztec-router-provider.js';
|
32
36
|
|
33
37
|
/**
|
34
|
-
*
|
35
|
-
*
|
36
|
-
*
|
38
|
+
* Helper constants and functions for connecting to Aztec wallets.
|
39
|
+
* - ALL_AZTEC_METHODS: Complete list of all available Aztec methods
|
40
|
+
* - connectAztec: Helper to connect to Aztec and create wallet instance
|
37
41
|
*/
|
38
|
-
export {
|
42
|
+
export {
|
43
|
+
ALL_AZTEC_METHODS,
|
44
|
+
connectAztec,
|
45
|
+
} from './client/helpers.js';
|
46
|
+
|
47
|
+
/**
|
48
|
+
* Helper function to register Aztec serializers with a WalletRouterProvider.
|
49
|
+
* This enables proper serialization of Aztec types when using the router.
|
50
|
+
* @see {@link registerAztecSerializers}
|
51
|
+
*/
|
52
|
+
export { registerAztecSerializers } from './client/register-serializers.js';
|
39
53
|
|
54
|
+
// Shared types
|
40
55
|
/**
|
41
|
-
*
|
56
|
+
* Core type definitions used throughout the package.
|
57
|
+
* - AztecChainId: Type-safe Aztec chain ID format (e.g., "aztec:mainnet")
|
58
|
+
* - AztecWalletContext: Context object for wallet implementations
|
59
|
+
* - AztecWalletMethodMap: Complete method map for all Aztec wallet methods
|
42
60
|
*/
|
43
61
|
export type {
|
44
|
-
/** Chain identifier type */
|
45
62
|
AztecChainId,
|
46
|
-
/** Context passed through RPC middleware */
|
47
63
|
AztecWalletContext,
|
48
|
-
/** Event map for wallet events */
|
49
|
-
AztecWalletEventMap,
|
50
|
-
/** Base method map for core wallet functionality */
|
51
|
-
AztecWalletBaseMethodMap,
|
52
|
-
/** Complete method map including all Aztec methods */
|
53
64
|
AztecWalletMethodMap,
|
54
|
-
/** Middleware type for processing RPC requests */
|
55
|
-
AztecWalletMiddleware,
|
56
|
-
/** Router client type for wallet mesh integration */
|
57
|
-
AztecWalletRouterClient,
|
58
|
-
/** Handler type for wallet methods */
|
59
|
-
AztecWalletMethodHandler,
|
60
|
-
/** Type for contract function calls */
|
61
|
-
TransactionFunctionCall,
|
62
|
-
/** Parameters for transaction requests */
|
63
|
-
TransactionParams,
|
64
65
|
} from './types.js';
|
66
|
+
|
67
|
+
// Utilities
|
68
|
+
/**
|
69
|
+
* Cache utility for managing contract artifacts in wallet implementations.
|
70
|
+
* @see {@link ContractArtifactCache}
|
71
|
+
*/
|
72
|
+
export { ContractArtifactCache } from './contractArtifactCache.js';
|
73
|
+
|
74
|
+
// Error utilities
|
75
|
+
/**
|
76
|
+
* Error handling utilities for Aztec wallet operations.
|
77
|
+
* - AztecWalletError: Custom error class for Aztec wallet errors
|
78
|
+
* - AztecWalletErrorMap: Map of error codes to error messages
|
79
|
+
*/
|
80
|
+
export { AztecWalletError, AztecWalletErrorMap } from './errors.js';
|
81
|
+
|
82
|
+
// Re-export serializers
|
83
|
+
/**
|
84
|
+
* Re-exports the primary {@link AztecWalletSerializer} and the wallet-side
|
85
|
+
* `registerAztecSerializers` function from the `wallet/serializers` module.
|
86
|
+
* These are crucial for handling Aztec-specific data types over JSON-RPC
|
87
|
+
* on the wallet (node) side.
|
88
|
+
*
|
89
|
+
* @see {@link AztecWalletSerializer} - The main serializer object.
|
90
|
+
* @see {@link module:@walletmesh/aztec-rpc-wallet/wallet/serializers} - The module providing these utilities.
|
91
|
+
* Note: The client-side `registerAztecSerializers` is exported separately from `./client/register-serializers.js`.
|
92
|
+
*/
|
93
|
+
export {
|
94
|
+
AztecWalletSerializer,
|
95
|
+
registerAztecSerializers as registerWalletAztecSerializers,
|
96
|
+
} from './wallet/serializers.js';
|
97
|
+
// To avoid naming collision with client/register-serializers.ts,
|
98
|
+
// the wallet-side registerAztecSerializers is re-exported as registerWalletAztecSerializers.
|
99
|
+
// AztecWalletSerializer is unique and can be re-exported directly.
|
100
|
+
// Other internal details of wallet/serializers.ts are not re-exported here.
|