@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.
Files changed (185) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +290 -228
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/client/aztec-dapp-wallet.d.ts +401 -0
  5. package/dist/client/aztec-dapp-wallet.d.ts.map +1 -0
  6. package/dist/client/aztec-dapp-wallet.js +705 -0
  7. package/dist/client/aztec-router-provider.d.ts +58 -0
  8. package/dist/client/aztec-router-provider.d.ts.map +1 -0
  9. package/dist/client/aztec-router-provider.js +62 -0
  10. package/dist/client/helpers.d.ts +44 -0
  11. package/dist/client/helpers.d.ts.map +1 -0
  12. package/dist/client/helpers.js +79 -0
  13. package/dist/client/register-serializers.d.ts +41 -0
  14. package/dist/client/register-serializers.d.ts.map +1 -0
  15. package/dist/client/register-serializers.js +97 -0
  16. package/dist/contractArtifactCache.d.ts +49 -32
  17. package/dist/contractArtifactCache.d.ts.map +1 -1
  18. package/dist/contractArtifactCache.js +47 -34
  19. package/dist/errors.d.ts +50 -8
  20. package/dist/errors.d.ts.map +1 -1
  21. package/dist/errors.js +50 -10
  22. package/dist/index.d.ts +53 -40
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +52 -17
  25. package/dist/types.d.ts +345 -270
  26. package/dist/types.d.ts.map +1 -1
  27. package/dist/types.js +10 -8
  28. package/dist/wallet/create-node.d.ts +73 -0
  29. package/dist/wallet/create-node.d.ts.map +1 -0
  30. package/dist/wallet/create-node.js +99 -0
  31. package/dist/wallet/handlers/account.d.ts +67 -0
  32. package/dist/wallet/handlers/account.d.ts.map +1 -0
  33. package/dist/wallet/handlers/account.js +85 -0
  34. package/dist/wallet/handlers/contract-interaction.d.ts +77 -0
  35. package/dist/wallet/handlers/contract-interaction.d.ts.map +1 -0
  36. package/dist/wallet/handlers/contract-interaction.js +219 -0
  37. package/dist/wallet/handlers/contract.d.ts +96 -0
  38. package/dist/wallet/handlers/contract.d.ts.map +1 -0
  39. package/dist/wallet/handlers/contract.js +146 -0
  40. package/dist/wallet/handlers/event.d.ts +62 -0
  41. package/dist/wallet/handlers/event.d.ts.map +1 -0
  42. package/dist/wallet/handlers/event.js +85 -0
  43. package/dist/wallet/handlers/index.d.ts +88 -0
  44. package/dist/wallet/handlers/index.d.ts.map +1 -0
  45. package/dist/wallet/handlers/index.js +47 -0
  46. package/dist/wallet/handlers/node.d.ts +117 -0
  47. package/dist/wallet/handlers/node.d.ts.map +1 -0
  48. package/dist/wallet/handlers/node.js +196 -0
  49. package/dist/wallet/handlers/senders.d.ts +70 -0
  50. package/dist/wallet/handlers/senders.d.ts.map +1 -0
  51. package/dist/wallet/handlers/senders.js +92 -0
  52. package/dist/wallet/handlers/transaction.d.ts +123 -0
  53. package/dist/wallet/handlers/transaction.d.ts.map +1 -0
  54. package/dist/wallet/handlers/transaction.js +191 -0
  55. package/dist/wallet/serializers.d.ts +75 -0
  56. package/dist/wallet/serializers.d.ts.map +1 -0
  57. package/dist/wallet/serializers.js +501 -0
  58. package/docs/README.md +290 -229
  59. package/docs/classes/AztecDappWallet.md +1304 -0
  60. package/docs/classes/AztecRouterProvider.md +1058 -0
  61. package/docs/classes/AztecWalletError.md +124 -47
  62. package/docs/classes/ContractArtifactCache.md +48 -31
  63. package/docs/functions/connectAztec.md +62 -0
  64. package/docs/functions/createAztecWallet.md +46 -0
  65. package/docs/functions/createAztecWalletNode.md +96 -0
  66. package/docs/functions/registerAztecSerializers.md +61 -0
  67. package/docs/functions/registerWalletAztecSerializers.md +39 -0
  68. package/docs/globals.md +16 -14
  69. package/docs/interfaces/AztecHandlerContext.md +54 -0
  70. package/docs/interfaces/AztecWalletContext.md +50 -0
  71. package/docs/interfaces/AztecWalletMethodMap.md +470 -477
  72. package/docs/type-aliases/AztecChainId.md +16 -3
  73. package/docs/variables/ALL_AZTEC_METHODS.md +20 -0
  74. package/docs/variables/AztecWalletErrorMap.md +9 -4
  75. package/docs/variables/AztecWalletSerializer.md +45 -0
  76. package/package.json +9 -9
  77. package/src/client/aztec-dapp-wallet.test.ts +628 -0
  78. package/src/client/aztec-dapp-wallet.ts +879 -0
  79. package/src/client/aztec-router-provider.test.ts +235 -0
  80. package/src/client/aztec-router-provider.ts +64 -0
  81. package/src/client/helpers.test.ts +187 -0
  82. package/src/client/helpers.ts +91 -0
  83. package/src/client/register-serializers.ts +108 -0
  84. package/src/contractArtifactCache.test.ts +21 -10
  85. package/src/contractArtifactCache.ts +54 -35
  86. package/src/errors.ts +58 -10
  87. package/src/index.test.ts +2 -6
  88. package/src/index.ts +73 -37
  89. package/src/types.ts +379 -217
  90. package/src/wallet/create-node.test.ts +332 -0
  91. package/src/wallet/create-node.ts +120 -0
  92. package/src/wallet/handlers/account.test.ts +172 -0
  93. package/src/wallet/handlers/account.ts +99 -0
  94. package/src/wallet/handlers/contract-interaction.test.ts +248 -0
  95. package/src/wallet/handlers/contract-interaction.ts +269 -0
  96. package/src/wallet/handlers/contract.test.ts +245 -0
  97. package/src/wallet/handlers/contract.ts +174 -0
  98. package/src/wallet/handlers/event.test.ts +216 -0
  99. package/src/wallet/handlers/event.ts +99 -0
  100. package/src/wallet/handlers/index.ts +84 -0
  101. package/src/wallet/handlers/node.test.ts +304 -0
  102. package/src/wallet/handlers/node.ts +230 -0
  103. package/src/wallet/handlers/senders.test.ts +172 -0
  104. package/src/wallet/handlers/senders.ts +106 -0
  105. package/src/wallet/handlers/transaction.test.ts +371 -0
  106. package/src/wallet/handlers/transaction.ts +239 -0
  107. package/src/wallet/serializers.test.ts +253 -0
  108. package/src/wallet/serializers.ts +586 -0
  109. package/typedoc.json +23 -1
  110. package/dist/aztecRemoteWallet.d.ts +0 -70
  111. package/dist/aztecRemoteWallet.d.ts.map +0 -1
  112. package/dist/aztecRemoteWallet.js +0 -335
  113. package/dist/chainProvider.d.ts +0 -56
  114. package/dist/chainProvider.d.ts.map +0 -1
  115. package/dist/chainProvider.js +0 -98
  116. package/dist/handlers/aztecAccountWallet.d.ts +0 -4
  117. package/dist/handlers/aztecAccountWallet.d.ts.map +0 -1
  118. package/dist/handlers/aztecAccountWallet.js +0 -295
  119. package/dist/handlers/transactions.d.ts +0 -21
  120. package/dist/handlers/transactions.d.ts.map +0 -1
  121. package/dist/handlers/transactions.js +0 -98
  122. package/dist/handlers.d.ts +0 -27
  123. package/dist/handlers.d.ts.map +0 -1
  124. package/dist/handlers.js +0 -55
  125. package/dist/provider.d.ts +0 -105
  126. package/dist/provider.d.ts.map +0 -1
  127. package/dist/provider.js +0 -160
  128. package/dist/serializers/account.d.ts +0 -164
  129. package/dist/serializers/account.d.ts.map +0 -1
  130. package/dist/serializers/account.js +0 -244
  131. package/dist/serializers/contract.d.ts +0 -62
  132. package/dist/serializers/contract.d.ts.map +0 -1
  133. package/dist/serializers/contract.js +0 -130
  134. package/dist/serializers/index.d.ts +0 -21
  135. package/dist/serializers/index.d.ts.map +0 -1
  136. package/dist/serializers/index.js +0 -154
  137. package/dist/serializers/log.d.ts +0 -66
  138. package/dist/serializers/log.d.ts.map +0 -1
  139. package/dist/serializers/log.js +0 -222
  140. package/dist/serializers/note.d.ts +0 -124
  141. package/dist/serializers/note.d.ts.map +0 -1
  142. package/dist/serializers/note.js +0 -208
  143. package/dist/serializers/transaction.d.ts +0 -99
  144. package/dist/serializers/transaction.d.ts.map +0 -1
  145. package/dist/serializers/transaction.js +0 -275
  146. package/dist/wallet.d.ts +0 -62
  147. package/dist/wallet.d.ts.map +0 -1
  148. package/dist/wallet.js +0 -77
  149. package/docs/classes/AztecChainProvider.md +0 -553
  150. package/docs/classes/AztecChainWallet.md +0 -409
  151. package/docs/classes/AztecProvider.md +0 -1112
  152. package/docs/interfaces/AztecWalletBaseMethodMap.md +0 -135
  153. package/docs/interfaces/AztecWalletEventMap.md +0 -17
  154. package/docs/type-aliases/AztecChainWalletMiddleware.md +0 -13
  155. package/docs/type-aliases/AztecWalletContext.md +0 -29
  156. package/docs/type-aliases/AztecWalletMethodHandler.md +0 -37
  157. package/docs/type-aliases/AztecWalletMiddleware.md +0 -13
  158. package/docs/type-aliases/AztecWalletRouterClient.md +0 -13
  159. package/docs/type-aliases/TransactionFunctionCall.md +0 -33
  160. package/docs/type-aliases/TransactionParams.md +0 -27
  161. package/src/aztecRemoteWallet.test.ts +0 -505
  162. package/src/aztecRemoteWallet.ts +0 -467
  163. package/src/chainProvider.test.ts +0 -401
  164. package/src/chainProvider.ts +0 -116
  165. package/src/handlers/aztecAccountWallet.test.ts +0 -650
  166. package/src/handlers/aztecAccountWallet.ts +0 -531
  167. package/src/handlers/transactions.ts +0 -124
  168. package/src/handlers.test.ts +0 -270
  169. package/src/handlers.ts +0 -70
  170. package/src/provider.test.ts +0 -277
  171. package/src/provider.ts +0 -189
  172. package/src/serializers/account.test.ts +0 -125
  173. package/src/serializers/account.ts +0 -301
  174. package/src/serializers/contract.test.ts +0 -24
  175. package/src/serializers/contract.ts +0 -183
  176. package/src/serializers/index.test.ts +0 -136
  177. package/src/serializers/index.ts +0 -191
  178. package/src/serializers/log.test.ts +0 -286
  179. package/src/serializers/log.ts +0 -292
  180. package/src/serializers/note.test.ts +0 -125
  181. package/src/serializers/note.ts +0 -250
  182. package/src/serializers/transaction.test.ts +0 -320
  183. package/src/serializers/transaction.ts +0 -409
  184. package/src/wallet.test.ts +0 -275
  185. package/src/wallet.ts +0 -94
@@ -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 a complete mock of AztecAddress
17
-
18
- const { instance, artifact } = await randomDeployedContract();
19
-
20
- mockContractAddress = instance.address;
21
- mockContractClassId = instance.contractClassId;
22
- mockArtifact = artifact;
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: { contractClassId: mockContractClassId },
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: { contractClassId: mockContractClassId },
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
- * Caches contract artifacts to optimize contract interactions.
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
- * This class maintains an in-memory cache of contract artifacts indexed by contract address.
16
- * When a contract artifact is requested:
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
- * This caching mechanism helps reduce:
23
- * - Network requests to fetch contract data
24
- * - Processing overhead of parsing contract artifacts
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
- /** Map of contract addresses to their artifacts */
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
- /** Reference to the wallet instance for fetching contract data */
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
- * @param wallet - Wallet instance used to fetch contract data when cache misses occur
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 contract artifact for a given contract address.
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
- * The process:
46
- * 1. Check if artifact exists in cache
47
- * 2. If not, get contract instance from wallet
48
- * 3. Use instance to get contract class ID
49
- * 4. Fetch artifact using class ID
50
- * 5. Cache the artifact for future use
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 contract address to retrieve the artifact for
53
- * @returns Promise resolving to the contract artifact
54
- * @throws {AztecWalletError} If contract instance or class not registered
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(contract.contractClassId);
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.contractClassId.toString());
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
- * Enum of available Aztec Wallet RPC error types.
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
- * Type representing valid Aztec Wallet RPC error types.
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
- * Map of error codes and messages for Aztec Wallet RPC errors.
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 Wallet RPC errors.
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
- * Creates a new AztecWalletError.
64
- * @param err - The error type from AztecWalletErrorMap
65
- * @param data - Optional additional error data
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(err: AztecWalletErrorType, data?: string) {
68
- super(AztecWalletErrorMap[err].code, AztecWalletErrorMap[err].message, data);
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 AztecProvider', () => {
6
- expect(exports.AztecProvider).toBeDefined();
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
- * This module provides a JSON-RPC implementation for interacting with Aztec Network.
5
- * It enables communication between dApps and wallets through a standardized interface.
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
- * Provider class for dApps to interact with Aztec wallets
10
- * @see AztecProvider
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 { AztecProvider } from './provider.js';
14
+ export { createAztecWalletNode } from './wallet/create-node.js';
13
15
 
14
16
  /**
15
- * Minimal provider for direct interaction with an Aztec chain wallet
16
- * @see AztecChainProvider
17
+ * Context interface provided to all handler functions in the wallet implementation.
18
+ * @see {@link AztecHandlerContext}
17
19
  */
18
- export { AztecChainProvider } from './chainProvider.js';
20
+ export type { AztecHandlerContext } from './wallet/handlers/index.js';
19
21
 
22
+ // Client-side exports
20
23
  /**
21
- * Wallet implementation that handles RPC requests from dApps
22
- * @see AztecChainWallet
24
+ * DApp-side wallet class that implements the aztec.js Wallet interface.
25
+ * @see {@link AztecDappWallet}
23
26
  */
24
- export { AztecChainWallet } from './wallet.js';
25
- export { AztecChainWalletMiddleware } from './types.js';
27
+ export { AztecDappWallet, createAztecWallet } from './client/aztec-dapp-wallet.js';
26
28
 
27
29
  /**
28
- * Cache for contract artifacts
29
- * @see ContractArtifactCache
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 { ContractArtifactCache } from './contractArtifactCache.js';
35
+ export { AztecRouterProvider } from './client/aztec-router-provider.js';
32
36
 
33
37
  /**
34
- * Error handling utilities for RPC communication
35
- * @see AztecWalletError
36
- * @see AztecWalletErrorMap
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 { AztecWalletError, AztecWalletErrorMap } from './errors.js';
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
- * Type definitions for RPC interfaces
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.