@walletmesh/aztec-rpc-wallet 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +201 -0
  3. package/README.md +260 -0
  4. package/dist/.tsbuildinfo +1 -0
  5. package/dist/aztecRemoteWallet.d.ts +73 -0
  6. package/dist/aztecRemoteWallet.d.ts.map +1 -0
  7. package/dist/aztecRemoteWallet.js +354 -0
  8. package/dist/chainProvider.d.ts +56 -0
  9. package/dist/chainProvider.d.ts.map +1 -0
  10. package/dist/chainProvider.js +98 -0
  11. package/dist/contractArtifactCache.d.ts +50 -0
  12. package/dist/contractArtifactCache.d.ts.map +1 -0
  13. package/dist/contractArtifactCache.js +66 -0
  14. package/dist/errors.d.ts +50 -0
  15. package/dist/errors.d.ts.map +1 -0
  16. package/dist/errors.js +62 -0
  17. package/dist/handlers/aztecAccountWallet.d.ts +4 -0
  18. package/dist/handlers/aztecAccountWallet.d.ts.map +1 -0
  19. package/dist/handlers/aztecAccountWallet.js +329 -0
  20. package/dist/handlers/transactions.d.ts +21 -0
  21. package/dist/handlers/transactions.d.ts.map +1 -0
  22. package/dist/handlers/transactions.js +90 -0
  23. package/dist/handlers.d.ts +27 -0
  24. package/dist/handlers.d.ts.map +1 -0
  25. package/dist/handlers.js +55 -0
  26. package/dist/index.d.ts +58 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +33 -0
  29. package/dist/provider.d.ts +105 -0
  30. package/dist/provider.d.ts.map +1 -0
  31. package/dist/provider.js +160 -0
  32. package/dist/serializers/account.d.ts +167 -0
  33. package/dist/serializers/account.d.ts.map +1 -0
  34. package/dist/serializers/account.js +245 -0
  35. package/dist/serializers/contract-utils.d.ts +40 -0
  36. package/dist/serializers/contract-utils.d.ts.map +1 -0
  37. package/dist/serializers/contract-utils.js +102 -0
  38. package/dist/serializers/contract.d.ts +168 -0
  39. package/dist/serializers/contract.d.ts.map +1 -0
  40. package/dist/serializers/contract.js +268 -0
  41. package/dist/serializers/core.d.ts +110 -0
  42. package/dist/serializers/core.d.ts.map +1 -0
  43. package/dist/serializers/core.js +130 -0
  44. package/dist/serializers/index.d.ts +28 -0
  45. package/dist/serializers/index.d.ts.map +1 -0
  46. package/dist/serializers/index.js +159 -0
  47. package/dist/serializers/log.d.ts +113 -0
  48. package/dist/serializers/log.d.ts.map +1 -0
  49. package/dist/serializers/log.js +231 -0
  50. package/dist/serializers/note.d.ts +127 -0
  51. package/dist/serializers/note.d.ts.map +1 -0
  52. package/dist/serializers/note.js +182 -0
  53. package/dist/serializers/transaction-utils.d.ts +107 -0
  54. package/dist/serializers/transaction-utils.d.ts.map +1 -0
  55. package/dist/serializers/transaction-utils.js +130 -0
  56. package/dist/serializers/transaction.d.ts +103 -0
  57. package/dist/serializers/transaction.d.ts.map +1 -0
  58. package/dist/serializers/transaction.js +238 -0
  59. package/dist/serializers/types.d.ts +49 -0
  60. package/dist/serializers/types.d.ts.map +1 -0
  61. package/dist/serializers/types.js +22 -0
  62. package/dist/types.d.ts +391 -0
  63. package/dist/types.d.ts.map +1 -0
  64. package/dist/types.js +8 -0
  65. package/dist/wallet.d.ts +62 -0
  66. package/dist/wallet.d.ts.map +1 -0
  67. package/dist/wallet.js +77 -0
  68. package/package.json +44 -0
  69. package/src/aztecRemoteWallet.test.ts +542 -0
  70. package/src/aztecRemoteWallet.ts +484 -0
  71. package/src/chainProvider.test.ts +322 -0
  72. package/src/chainProvider.ts +122 -0
  73. package/src/contractArtifactCache.test.ts +126 -0
  74. package/src/contractArtifactCache.ts +75 -0
  75. package/src/errors.ts +71 -0
  76. package/src/handlers/aztecAccountWallet.test.ts +720 -0
  77. package/src/handlers/aztecAccountWallet.ts +593 -0
  78. package/src/handlers/transactions.ts +110 -0
  79. package/src/handlers.test.ts +270 -0
  80. package/src/handlers.ts +70 -0
  81. package/src/index.test.ts +23 -0
  82. package/src/index.ts +64 -0
  83. package/src/provider.test.ts +276 -0
  84. package/src/provider.ts +189 -0
  85. package/src/serializers/account.test.ts +125 -0
  86. package/src/serializers/account.ts +319 -0
  87. package/src/serializers/contract-utils.ts +104 -0
  88. package/src/serializers/contract.test.ts +162 -0
  89. package/src/serializers/contract.ts +350 -0
  90. package/src/serializers/core.test.ts +56 -0
  91. package/src/serializers/core.ts +141 -0
  92. package/src/serializers/index.test.ts +122 -0
  93. package/src/serializers/index.ts +213 -0
  94. package/src/serializers/log.test.ts +119 -0
  95. package/src/serializers/log.ts +283 -0
  96. package/src/serializers/note.test.ts +100 -0
  97. package/src/serializers/note.ts +227 -0
  98. package/src/serializers/transaction-utils.ts +237 -0
  99. package/src/serializers/transaction.test.ts +153 -0
  100. package/src/serializers/transaction.ts +342 -0
  101. package/src/serializers/types.ts +58 -0
  102. package/src/types.ts +295 -0
  103. package/src/wallet.test.ts +275 -0
  104. package/src/wallet.ts +94 -0
  105. package/tsconfig.build.json +6 -0
  106. package/tsconfig.json +11 -0
  107. package/typedoc.json +15 -0
  108. package/vitest.config.ts +10 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @walletmesh/aztec-rpc-wallet
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0597281: Overhaul of (formerly) @walletmesh/aztec-rpc & rename to @walletmesh/aztec-rpc-wallet
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,260 @@
1
+ # WalletMesh Aztec RPC Wallet Library
2
+
3
+ [@walletmesh/aztec-rpc-wallet](https://github.com/WalletMesh/aztec/tree/main/packages/aztec-rpc-wallet) provides a type-safe RPC interface for interacting with [Aztec](https://aztec.network) wallets. It consists of three main components:
4
+
5
+ - **AztecProvider**: Client-side provider for dApps to communicate with Aztec wallets
6
+ - **AztecChainWallet**: Server-side implementation that handles RPC requests using an Aztec wallet instance
7
+ - **AztecOperationBuilder**: Fluent API for chaining multiple RPC method calls
8
+
9
+ The library is built on [@walletmesh/jsonrpc](https://github.com/WalletMesh/wm-core/tree/main/packages/jsonrpc#readme) and [@walletmesh/router](https://github.com/WalletMesh/wm-core/tree/main/packages/router#readme).
10
+
11
+ ## Features
12
+
13
+ - Connect to multiple Aztec chains simultaneously
14
+ - Flexible chain ID support (any string with 'aztec:' prefix)
15
+ - Type-safe RPC interfaces with comprehensive TypeScript definitions
16
+ - Efficient batching of multiple method calls
17
+ - Fluent chaining API for bulk operations
18
+ - Comprehensive error handling
19
+ - Contract artifact caching
20
+ - Event handling for wallet state changes
21
+ - Serialization support for all Aztec data types
22
+ - Support for encrypted and unencrypted events/logs
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ npm install @walletmesh/aztec-rpc-wallet
28
+ ```
29
+
30
+ ## Core RPC Methods
31
+
32
+ The library supports a comprehensive set of RPC methods:
33
+
34
+ ### Chain Operations
35
+ - `aztec_connect`: Connect to Aztec chains
36
+ - `aztec_getBlock`: Get block by number
37
+ - `aztec_getBlockNumber`: Get current block number
38
+ - `aztec_getProvenBlockNumber`: Get proven block number
39
+ - `aztec_getChainId`: Get chain ID
40
+ - `aztec_getVersion`: Get protocol version
41
+ - `aztec_getNodeInfo`: Get node information
42
+ - `aztec_getPXEInfo`: Get PXE information
43
+ - `aztec_getCurrentBaseFees`: Get current base fees
44
+
45
+ ### Account Operations
46
+ - `aztec_getAccount`: Get wallet's account address
47
+ - `aztec_getAddress`: Get wallet's Aztec address
48
+ - `aztec_getCompleteAddress`: Get complete address details
49
+ - `aztec_registerAccount`: Register a new account
50
+ - `aztec_getRegisteredAccounts`: Get all registered accounts
51
+
52
+ ### Transaction Operations
53
+ - `aztec_sendTransaction`: Send one or more transactions
54
+ - `aztec_simulateTransaction`: Simulate transaction without executing
55
+ - `aztec_sendTx`: Send raw transaction
56
+ - `aztec_createTxExecutionRequest`: Create transaction execution request
57
+ - `aztec_proveTx`: Generate transaction proof
58
+ - `aztec_getTxEffect`: Get transaction effect
59
+ - `aztec_getTxReceipt`: Get transaction receipt
60
+
61
+ ### Contract Operations
62
+ - `aztec_registerContract`: Register contract instance
63
+ - `aztec_registerContractClass`: Register contract class
64
+ - `aztec_getContracts`: Get registered contracts
65
+ - `aztec_getContractInstance`: Get contract instance details
66
+ - `aztec_getContractClass`: Get contract class details
67
+ - `aztec_getContractArtifact`: Get contract artifact
68
+ - `aztec_isContractClassPubliclyRegistered`: Check if contract class is publicly registered
69
+ - `aztec_isContractPubliclyDeployed`: Check if contract is publicly deployed
70
+ - `aztec_isContractInitialized`: Check if contract is initialized
71
+ - `aztec_getPublicStorageAt`: Get public storage value
72
+
73
+ ### Authorization & Scope Management
74
+ - `aztec_setScopes`: Set authorization scopes
75
+ - `aztec_getScopes`: Get current scopes
76
+ - `aztec_addAuthWitness`: Add authorization witness
77
+ - `aztec_getAuthWitness`: Get authorization witness
78
+ - `aztec_createAuthWit`: Create authorization witness
79
+
80
+ ### Notes and Events
81
+ - `aztec_getIncomingNotes`: Get incoming notes
82
+ - `aztec_addNote`: Add note
83
+ - `aztec_addNullifiedNote`: Add nullified note
84
+ - `aztec_getUnencryptedLogs`: Get unencrypted logs
85
+ - `aztec_getContractClassLogs`: Get contract class logs
86
+ - `aztec_getEncryptedEvents`: Get encrypted events
87
+ - `aztec_getUnencryptedEvents`: Get unencrypted events
88
+
89
+ ### L1->L2 Bridge Operations
90
+ - `aztec_isL1ToL2MessageSynced`: Check if L1->L2 message is synced
91
+ - `aztec_getL1ToL2MembershipWitness`: Get L1->L2 membership witness
92
+
93
+ See [src/types.ts](https://github.com/WalletMesh/aztec/blob/main/packages/aztec-rpc-wallet/src/types.ts) for complete method definitions and parameters.
94
+
95
+ ## Usage Examples
96
+
97
+ ### Basic Provider Usage
98
+
99
+ ```typescript
100
+ import { AztecProvider } from '@walletmesh/aztec-rpc-wallet';
101
+
102
+ // Create provider with transport
103
+ const provider = new AztecProvider(transport);
104
+
105
+ // Connect to chains
106
+ await provider.connect(['aztec:testnet', 'aztec:devnet']);
107
+
108
+ // Get account address
109
+ const address = await provider.getAccount('aztec:testnet');
110
+
111
+ // Send transaction
112
+ const txHash = await provider.sendTransaction('aztec:testnet', {
113
+ functionCalls: [{
114
+ contractAddress: "0x1234...",
115
+ functionName: "transfer",
116
+ args: [recipient, amount]
117
+ }]
118
+ });
119
+
120
+ // Register contract
121
+ await provider.registerContract('aztec:testnet', {
122
+ instance: contractInstance,
123
+ artifact: contractArtifact // optional if class already registered
124
+ });
125
+
126
+ // Listen for chain connection events
127
+ provider.on('chain:connected', ({ chainId }) => {
128
+ console.log(`Connected to chain: ${chainId}`);
129
+ });
130
+
131
+ // Listen for chain disconnection events
132
+ provider.on('chain:disconnected', ({ chainId }) => {
133
+ console.log(`Disconnected from chain: ${chainId}`);
134
+ });
135
+ ```
136
+
137
+ ### Chaining API for Bulk Operations
138
+
139
+ The provider supports a fluent chaining API for executing multiple operations efficiently:
140
+
141
+ ```typescript
142
+ // Multiple reads in single batch
143
+ const [account, contracts, blockNumber] = await provider
144
+ .chain('aztec:testnet')
145
+ .call('aztec_getAccount')
146
+ .call('aztec_getContracts')
147
+ .call('aztec_getBlockNumber')
148
+ .execute();
149
+
150
+ // Contract setup and interaction
151
+ const [classId, instanceId, txHash] = await provider
152
+ .chain('aztec:testnet')
153
+ .call('aztec_registerContractClass', { artifact: contractArtifact })
154
+ .call('aztec_registerContract', {
155
+ instance: contractInstance,
156
+ artifact: contractArtifact
157
+ })
158
+ .call('aztec_sendTransaction', {
159
+ functionCalls: [{
160
+ contractAddress: contractInstance.address,
161
+ functionName: 'initialize',
162
+ args: [param1, param2]
163
+ }]
164
+ })
165
+ .execute();
166
+
167
+ // Multi-chain operations
168
+ const [testnetData, devnetData] = await Promise.all([
169
+ provider
170
+ .chain('aztec:testnet')
171
+ .call('aztec_getAccount')
172
+ .call('aztec_getContracts')
173
+ .execute(),
174
+ provider
175
+ .chain('aztec:devnet')
176
+ .call('aztec_getAccount')
177
+ .call('aztec_getContracts')
178
+ .execute()
179
+ ]);
180
+ ```
181
+
182
+ ### Error Handling
183
+
184
+ The library provides comprehensive error handling through `AztecWalletError`:
185
+
186
+ ```typescript
187
+ try {
188
+ await provider.sendTransaction('aztec:testnet', {
189
+ functionCalls: [{
190
+ contractAddress: "0x1234...",
191
+ functionName: "transfer",
192
+ args: [recipient, amount]
193
+ }]
194
+ });
195
+ } catch (error) {
196
+ if (error instanceof AztecWalletError) {
197
+ switch (error.code) {
198
+ case -32001: // User refused
199
+ console.log('Transaction rejected by user');
200
+ break;
201
+ case -32002: // Wallet not connected
202
+ console.log('Please connect wallet first');
203
+ break;
204
+ default:
205
+ console.error('RPC error:', error.message);
206
+ }
207
+ }
208
+ }
209
+ ```
210
+
211
+ ### Implementing a Wallet
212
+
213
+ Server-side implementation using `AztecWallet`:
214
+
215
+ ```typescript
216
+ import { AztecChainWallet } from '@walletmesh/aztec-rpc-wallet';
217
+ import type { PXE, AccountWallet } from '@aztec/aztec.js';
218
+
219
+ // Create wallet instance
220
+ const wallet = new AztecChainWallet(
221
+ pxe, // PXE instance
222
+ accountWallet, // Aztec AccountWallet instance
223
+ transport // Transport layer
224
+ );
225
+
226
+ // Handle incoming requests
227
+ transport.on('message', async (request) => {
228
+ const response = await wallet.handleRequest(request);
229
+ // Send response back to dApp
230
+ });
231
+
232
+ // Use with WalletMesh router
233
+ const routerClient = wallet.asWalletRouterClient();
234
+ ```
235
+
236
+ ## Error Codes
237
+
238
+ Common error codes returned by the library:
239
+
240
+ - -32000: Unknown internal error
241
+ - -32001: User refused transaction
242
+ - -32002: Wallet not connected
243
+ - -32003: Contract instance not registered
244
+ - -32004: Contract class not registered
245
+ - -32005: Sender not registered
246
+ - -32006: Invalid response format
247
+ - -32007: Not connected to any chain
248
+ - -32008: Chain not supported
249
+ - -32009: Invalid request format
250
+ - -32010: Invalid parameters
251
+ - -32011: Permission denied
252
+ - -32012: Session not found
253
+ - -32013: Session expired
254
+ - -32014: Transaction not found
255
+ - -32015: Block not found
256
+ - -32016: Authorization witness not found
257
+
258
+ ## Example Project
259
+
260
+ See the [example project](https://github.com/WalletMesh/aztec/tree/main/packages/example) for a complete implementation using this library.