@walletmesh/aztec-rpc-wallet 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +290 -228
- package/dist/.tsbuildinfo +1 -1
- package/dist/client/aztec-dapp-wallet.d.ts +401 -0
- package/dist/client/aztec-dapp-wallet.d.ts.map +1 -0
- package/dist/client/aztec-dapp-wallet.js +705 -0
- package/dist/client/aztec-router-provider.d.ts +58 -0
- package/dist/client/aztec-router-provider.d.ts.map +1 -0
- package/dist/client/aztec-router-provider.js +62 -0
- package/dist/client/helpers.d.ts +44 -0
- package/dist/client/helpers.d.ts.map +1 -0
- package/dist/client/helpers.js +79 -0
- package/dist/client/register-serializers.d.ts +41 -0
- package/dist/client/register-serializers.d.ts.map +1 -0
- package/dist/client/register-serializers.js +97 -0
- package/dist/contractArtifactCache.d.ts +49 -32
- package/dist/contractArtifactCache.d.ts.map +1 -1
- package/dist/contractArtifactCache.js +47 -34
- package/dist/errors.d.ts +50 -8
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +50 -10
- package/dist/index.d.ts +53 -40
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -17
- package/dist/types.d.ts +345 -270
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +10 -8
- package/dist/wallet/create-node.d.ts +73 -0
- package/dist/wallet/create-node.d.ts.map +1 -0
- package/dist/wallet/create-node.js +99 -0
- package/dist/wallet/handlers/account.d.ts +67 -0
- package/dist/wallet/handlers/account.d.ts.map +1 -0
- package/dist/wallet/handlers/account.js +85 -0
- package/dist/wallet/handlers/contract-interaction.d.ts +77 -0
- package/dist/wallet/handlers/contract-interaction.d.ts.map +1 -0
- package/dist/wallet/handlers/contract-interaction.js +219 -0
- package/dist/wallet/handlers/contract.d.ts +96 -0
- package/dist/wallet/handlers/contract.d.ts.map +1 -0
- package/dist/wallet/handlers/contract.js +146 -0
- package/dist/wallet/handlers/event.d.ts +62 -0
- package/dist/wallet/handlers/event.d.ts.map +1 -0
- package/dist/wallet/handlers/event.js +85 -0
- package/dist/wallet/handlers/index.d.ts +88 -0
- package/dist/wallet/handlers/index.d.ts.map +1 -0
- package/dist/wallet/handlers/index.js +47 -0
- package/dist/wallet/handlers/node.d.ts +117 -0
- package/dist/wallet/handlers/node.d.ts.map +1 -0
- package/dist/wallet/handlers/node.js +196 -0
- package/dist/wallet/handlers/senders.d.ts +70 -0
- package/dist/wallet/handlers/senders.d.ts.map +1 -0
- package/dist/wallet/handlers/senders.js +92 -0
- package/dist/wallet/handlers/transaction.d.ts +123 -0
- package/dist/wallet/handlers/transaction.d.ts.map +1 -0
- package/dist/wallet/handlers/transaction.js +191 -0
- package/dist/wallet/serializers.d.ts +75 -0
- package/dist/wallet/serializers.d.ts.map +1 -0
- package/dist/wallet/serializers.js +501 -0
- package/docs/README.md +290 -229
- package/docs/classes/AztecDappWallet.md +1304 -0
- package/docs/classes/AztecRouterProvider.md +1058 -0
- package/docs/classes/AztecWalletError.md +124 -47
- package/docs/classes/ContractArtifactCache.md +48 -31
- package/docs/functions/connectAztec.md +62 -0
- package/docs/functions/createAztecWallet.md +46 -0
- package/docs/functions/createAztecWalletNode.md +96 -0
- package/docs/functions/registerAztecSerializers.md +61 -0
- package/docs/functions/registerWalletAztecSerializers.md +39 -0
- package/docs/globals.md +16 -14
- package/docs/interfaces/AztecHandlerContext.md +54 -0
- package/docs/interfaces/AztecWalletContext.md +50 -0
- package/docs/interfaces/AztecWalletMethodMap.md +470 -477
- package/docs/type-aliases/AztecChainId.md +16 -3
- package/docs/variables/ALL_AZTEC_METHODS.md +20 -0
- package/docs/variables/AztecWalletErrorMap.md +9 -4
- package/docs/variables/AztecWalletSerializer.md +45 -0
- package/package.json +9 -9
- package/src/client/aztec-dapp-wallet.test.ts +628 -0
- package/src/client/aztec-dapp-wallet.ts +879 -0
- package/src/client/aztec-router-provider.test.ts +235 -0
- package/src/client/aztec-router-provider.ts +64 -0
- package/src/client/helpers.test.ts +187 -0
- package/src/client/helpers.ts +91 -0
- package/src/client/register-serializers.ts +108 -0
- package/src/contractArtifactCache.test.ts +21 -10
- package/src/contractArtifactCache.ts +54 -35
- package/src/errors.ts +58 -10
- package/src/index.test.ts +2 -6
- package/src/index.ts +73 -37
- package/src/types.ts +379 -217
- package/src/wallet/create-node.test.ts +332 -0
- package/src/wallet/create-node.ts +120 -0
- package/src/wallet/handlers/account.test.ts +172 -0
- package/src/wallet/handlers/account.ts +99 -0
- package/src/wallet/handlers/contract-interaction.test.ts +248 -0
- package/src/wallet/handlers/contract-interaction.ts +269 -0
- package/src/wallet/handlers/contract.test.ts +245 -0
- package/src/wallet/handlers/contract.ts +174 -0
- package/src/wallet/handlers/event.test.ts +216 -0
- package/src/wallet/handlers/event.ts +99 -0
- package/src/wallet/handlers/index.ts +84 -0
- package/src/wallet/handlers/node.test.ts +304 -0
- package/src/wallet/handlers/node.ts +230 -0
- package/src/wallet/handlers/senders.test.ts +172 -0
- package/src/wallet/handlers/senders.ts +106 -0
- package/src/wallet/handlers/transaction.test.ts +371 -0
- package/src/wallet/handlers/transaction.ts +239 -0
- package/src/wallet/serializers.test.ts +253 -0
- package/src/wallet/serializers.ts +586 -0
- package/typedoc.json +23 -1
- package/dist/aztecRemoteWallet.d.ts +0 -70
- package/dist/aztecRemoteWallet.d.ts.map +0 -1
- package/dist/aztecRemoteWallet.js +0 -335
- package/dist/chainProvider.d.ts +0 -56
- package/dist/chainProvider.d.ts.map +0 -1
- package/dist/chainProvider.js +0 -98
- package/dist/handlers/aztecAccountWallet.d.ts +0 -4
- package/dist/handlers/aztecAccountWallet.d.ts.map +0 -1
- package/dist/handlers/aztecAccountWallet.js +0 -295
- package/dist/handlers/transactions.d.ts +0 -21
- package/dist/handlers/transactions.d.ts.map +0 -1
- package/dist/handlers/transactions.js +0 -98
- package/dist/handlers.d.ts +0 -27
- package/dist/handlers.d.ts.map +0 -1
- package/dist/handlers.js +0 -55
- package/dist/provider.d.ts +0 -105
- package/dist/provider.d.ts.map +0 -1
- package/dist/provider.js +0 -160
- package/dist/serializers/account.d.ts +0 -164
- package/dist/serializers/account.d.ts.map +0 -1
- package/dist/serializers/account.js +0 -244
- package/dist/serializers/contract.d.ts +0 -62
- package/dist/serializers/contract.d.ts.map +0 -1
- package/dist/serializers/contract.js +0 -130
- package/dist/serializers/index.d.ts +0 -21
- package/dist/serializers/index.d.ts.map +0 -1
- package/dist/serializers/index.js +0 -154
- package/dist/serializers/log.d.ts +0 -66
- package/dist/serializers/log.d.ts.map +0 -1
- package/dist/serializers/log.js +0 -222
- package/dist/serializers/note.d.ts +0 -124
- package/dist/serializers/note.d.ts.map +0 -1
- package/dist/serializers/note.js +0 -208
- package/dist/serializers/transaction.d.ts +0 -99
- package/dist/serializers/transaction.d.ts.map +0 -1
- package/dist/serializers/transaction.js +0 -275
- package/dist/wallet.d.ts +0 -62
- package/dist/wallet.d.ts.map +0 -1
- package/dist/wallet.js +0 -77
- package/docs/classes/AztecChainProvider.md +0 -553
- package/docs/classes/AztecChainWallet.md +0 -409
- package/docs/classes/AztecProvider.md +0 -1112
- package/docs/interfaces/AztecWalletBaseMethodMap.md +0 -135
- package/docs/interfaces/AztecWalletEventMap.md +0 -17
- package/docs/type-aliases/AztecChainWalletMiddleware.md +0 -13
- package/docs/type-aliases/AztecWalletContext.md +0 -29
- package/docs/type-aliases/AztecWalletMethodHandler.md +0 -37
- package/docs/type-aliases/AztecWalletMiddleware.md +0 -13
- package/docs/type-aliases/AztecWalletRouterClient.md +0 -13
- package/docs/type-aliases/TransactionFunctionCall.md +0 -33
- package/docs/type-aliases/TransactionParams.md +0 -27
- package/src/aztecRemoteWallet.test.ts +0 -505
- package/src/aztecRemoteWallet.ts +0 -467
- package/src/chainProvider.test.ts +0 -401
- package/src/chainProvider.ts +0 -116
- package/src/handlers/aztecAccountWallet.test.ts +0 -650
- package/src/handlers/aztecAccountWallet.ts +0 -531
- package/src/handlers/transactions.ts +0 -124
- package/src/handlers.test.ts +0 -270
- package/src/handlers.ts +0 -70
- package/src/provider.test.ts +0 -277
- package/src/provider.ts +0 -189
- package/src/serializers/account.test.ts +0 -125
- package/src/serializers/account.ts +0 -301
- package/src/serializers/contract.test.ts +0 -24
- package/src/serializers/contract.ts +0 -183
- package/src/serializers/index.test.ts +0 -136
- package/src/serializers/index.ts +0 -191
- package/src/serializers/log.test.ts +0 -286
- package/src/serializers/log.ts +0 -292
- package/src/serializers/note.test.ts +0 -125
- package/src/serializers/note.ts +0 -250
- package/src/serializers/transaction.test.ts +0 -320
- package/src/serializers/transaction.ts +0 -409
- package/src/wallet.test.ts +0 -275
- package/src/wallet.ts +0 -94
package/docs/README.md
CHANGED
@@ -1,264 +1,325 @@
|
|
1
|
-
**@walletmesh/aztec-rpc-wallet v0.
|
1
|
+
**@walletmesh/aztec-rpc-wallet v0.4.0**
|
2
2
|
|
3
3
|
***
|
4
4
|
|
5
|
-
#
|
5
|
+
# @walletmesh/aztec-rpc-wallet
|
6
6
|
|
7
|
-
|
7
|
+
JSON-RPC wallet integration for Aztec Protocol, built on WalletMesh router for multi-chain support.
|
8
8
|
|
9
|
-
|
10
|
-
- **AztecChainWallet**: Server-side implementation that handles RPC requests using an Aztec wallet instance
|
11
|
-
- **AztecOperationBuilder**: Fluent API for chaining multiple RPC method calls
|
9
|
+
## Overview
|
12
10
|
|
13
|
-
|
11
|
+
This package provides an integration between Aztec wallets and dApps using the WalletMesh router system. It implements the aztec.js `Wallet` interface while leveraging WalletRouter for session management, permissions, and multi-chain support.
|
14
12
|
|
15
|
-
##
|
13
|
+
## Architecture
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
15
|
+
```mermaid
|
16
|
+
graph LR
|
17
|
+
subgraph DApp Side
|
18
|
+
DApp[DApp Code] --> AztecDappWallet[AztecDappWallet]
|
19
|
+
AztecDappWallet --> AztecRouterProvider[AztecRouterProvider]
|
20
|
+
end
|
21
|
+
|
22
|
+
subgraph WalletMesh Core
|
23
|
+
AztecRouterProvider -- JSON-RPC --> WalletRouter[WalletRouter]
|
24
|
+
end
|
25
|
+
|
26
|
+
subgraph Wallet Side
|
27
|
+
WalletRouter -- JSON-RPC --> AztecWalletNode[AztecWalletNode]
|
28
|
+
AztecWalletNode --> AccountWallet[AccountWallet Instance]
|
29
|
+
AztecWalletNode --> PXE[PXE Instance]
|
30
|
+
end
|
31
|
+
|
32
|
+
style DApp fill:#cde4ff,stroke:#777,stroke-width:2px
|
33
|
+
style WalletRouter fill:#e6ffcd,stroke:#777,stroke-width:2px
|
34
|
+
style AztecWalletNode fill:#ffe6cd,stroke:#777,stroke-width:2px
|
35
|
+
style AccountWallet fill:#ffe6cd,stroke:#777,stroke-width:2px
|
36
|
+
style PXE fill:#ffe6cd,stroke:#777,stroke-width:2px
|
37
|
+
```
|
38
|
+
|
39
|
+
- **DApp Side**: The dApp uses `AztecDappWallet` (an implementation of `aztec.js` `Wallet`) which communicates through `AztecRouterProvider`.
|
40
|
+
- **WalletRouter**: The central router from `@walletmesh/router` that directs requests to the appropriate wallet node based on chain ID.
|
41
|
+
- **Wallet Side**: `createAztecWalletNode` creates a `JSONRPCNode` (referred to as `AztecWalletNode` in the diagram) that wraps the user's `AccountWallet` and `PXE` instance, handling RPC requests.
|
27
42
|
|
28
43
|
## Installation
|
29
44
|
|
30
45
|
```bash
|
31
|
-
|
46
|
+
pnpm add @walletmesh/aztec-rpc-wallet
|
32
47
|
```
|
33
48
|
|
34
|
-
##
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
- `aztec_connect`: Connect to Aztec chains
|
40
|
-
- `aztec_getBlock`: Get block by number
|
41
|
-
- `aztec_getBlockNumber`: Get current block number
|
42
|
-
- `aztec_getProvenBlockNumber`: Get proven block number
|
43
|
-
- `aztec_getChainId`: Get chain ID
|
44
|
-
- `aztec_getVersion`: Get protocol version
|
45
|
-
- `aztec_getNodeInfo`: Get node information
|
46
|
-
- `aztec_getPXEInfo`: Get PXE information
|
47
|
-
- `aztec_getCurrentBaseFees`: Get current base fees
|
48
|
-
|
49
|
-
### Account Operations
|
50
|
-
- `aztec_getAccount`: Get wallet's account address
|
51
|
-
- `aztec_getAddress`: Get wallet's Aztec address
|
52
|
-
- `aztec_getCompleteAddress`: Get complete address details
|
53
|
-
- `aztec_registerAccount`: Register a new account
|
54
|
-
- `aztec_getRegisteredAccounts`: Get all registered accounts
|
55
|
-
|
56
|
-
### Transaction Operations
|
57
|
-
- `aztec_sendTransaction`: Send one or more transactions
|
58
|
-
- `aztec_simulateTransaction`: Simulate transaction without executing
|
59
|
-
- `aztec_sendTx`: Send raw transaction
|
60
|
-
- `aztec_createTxExecutionRequest`: Create transaction execution request
|
61
|
-
- `aztec_proveTx`: Generate transaction proof
|
62
|
-
- `aztec_getTxEffect`: Get transaction effect
|
63
|
-
- `aztec_getTxReceipt`: Get transaction receipt
|
64
|
-
|
65
|
-
### Contract Operations
|
66
|
-
- `aztec_registerContract`: Register contract instance
|
67
|
-
- `aztec_registerContractClass`: Register contract class
|
68
|
-
- `aztec_getContracts`: Get registered contracts
|
69
|
-
- `aztec_getContractInstance`: Get contract instance details
|
70
|
-
- `aztec_getContractClass`: Get contract class details
|
71
|
-
- `aztec_getContractArtifact`: Get contract artifact
|
72
|
-
- `aztec_isContractClassPubliclyRegistered`: Check if contract class is publicly registered
|
73
|
-
- `aztec_isContractPubliclyDeployed`: Check if contract is publicly deployed
|
74
|
-
- `aztec_isContractInitialized`: Check if contract is initialized
|
75
|
-
- `aztec_getPublicStorageAt`: Get public storage value
|
76
|
-
|
77
|
-
### Authorization & Scope Management
|
78
|
-
- `aztec_setScopes`: Set authorization scopes
|
79
|
-
- `aztec_getScopes`: Get current scopes
|
80
|
-
- `aztec_addAuthWitness`: Add authorization witness
|
81
|
-
- `aztec_getAuthWitness`: Get authorization witness
|
82
|
-
- `aztec_createAuthWit`: Create authorization witness
|
83
|
-
|
84
|
-
### Notes and Events
|
85
|
-
- `aztec_getIncomingNotes`: Get incoming notes
|
86
|
-
- `aztec_addNote`: Add note
|
87
|
-
- `aztec_addNullifiedNote`: Add nullified note
|
88
|
-
- `aztec_getUnencryptedLogs`: Get unencrypted logs
|
89
|
-
- `aztec_getContractClassLogs`: Get contract class logs
|
90
|
-
- `aztec_getEncryptedEvents`: Get encrypted events
|
91
|
-
- `aztec_getUnencryptedEvents`: Get unencrypted events
|
92
|
-
|
93
|
-
### L1->L2 Bridge Operations
|
94
|
-
- `aztec_isL1ToL2MessageSynced`: Check if L1->L2 message is synced
|
95
|
-
- `aztec_getL1ToL2MembershipWitness`: Get L1->L2 membership witness
|
96
|
-
|
97
|
-
See [src/types.ts](https://github.com/WalletMesh/walletmesh-packages/blob/main/aztec/aztec-rpc-wallet/src/types.ts) for complete method definitions and parameters.
|
98
|
-
|
99
|
-
## Usage Examples
|
100
|
-
|
101
|
-
### Basic Provider Usage
|
49
|
+
## Quick Start
|
50
|
+
|
51
|
+
### DApp Usage
|
52
|
+
|
53
|
+
This example demonstrates connecting to an Aztec wallet and performing a simple action.
|
102
54
|
|
103
55
|
```typescript
|
104
|
-
import {
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
//
|
110
|
-
|
111
|
-
|
112
|
-
//
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
//
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
56
|
+
import { AztecRouterProvider, connectAztec } from '@walletmesh/aztec-rpc-wallet';
|
57
|
+
import { Contract } from '@aztec/aztec.js'; // Assuming you have a contract instance
|
58
|
+
|
59
|
+
// Define a transport (example: window postMessage for browser extensions)
|
60
|
+
const transport = {
|
61
|
+
send: async (msg: unknown) => window.parent.postMessage(msg, '*'), // Or specific targetOrigin
|
62
|
+
onMessage: (handler: (data: unknown) => void) => {
|
63
|
+
const listener = (event: MessageEvent) => {
|
64
|
+
// Add origin check for security if applicable
|
65
|
+
// if (event.origin !== 'expected-origin') return;
|
66
|
+
handler(event.data);
|
67
|
+
};
|
68
|
+
window.addEventListener('message', listener);
|
69
|
+
// Return a cleanup function if your transport needs it
|
70
|
+
// return () => window.removeEventListener('message', listener);
|
71
|
+
},
|
72
|
+
};
|
73
|
+
|
74
|
+
async function main() {
|
75
|
+
// 1. Create AztecRouterProvider with your transport
|
76
|
+
// This provider automatically handles serialization of Aztec types.
|
77
|
+
const provider = new AztecRouterProvider(transport);
|
78
|
+
|
79
|
+
// 2. Connect to the Aztec chain and get an initialized wallet instance
|
80
|
+
// This requests permissions for all Aztec methods by default.
|
81
|
+
// Replace 'aztec:testnet' with your target chainId if different.
|
82
|
+
const { sessionId, wallet } = await connectAztec(provider, 'aztec:testnet');
|
83
|
+
console.log('Connected to Aztec wallet with session ID:', sessionId);
|
84
|
+
|
85
|
+
// 3. Use the wallet (which implements aztec.js Wallet interface)
|
86
|
+
const address = wallet.getAddress(); // Synchronous access after initialization
|
87
|
+
console.log('Wallet address:', address.toString());
|
88
|
+
|
89
|
+
// Example: Interacting with a contract (assuming 'myContract' is an aztec.js Contract instance)
|
90
|
+
const myContract = await Contract.at(contractAddress, contractArtifact, wallet);
|
91
|
+
const interaction = myContract.methods.someFunction(arg1, arg2);
|
92
|
+
|
93
|
+
// Option A: Using WalletMesh high-level execution (Wallet gets passed high-level interaction
|
94
|
+
// and can see the actual function call & arguments rather than just hashed values)
|
95
|
+
const sentTx = await wallet.wmExecuteTx(interaction);
|
96
|
+
const txHash = await sentTx.getTxHash();
|
97
|
+
console.log('Transaction sent with wmExecuteTx, hash:', txHash.toString());
|
98
|
+
const receipt = await sentTx.getReceipt();
|
99
|
+
|
100
|
+
// Option B: Using standard aztec.js flow (only implemented for Aztec.js `Wallet` interface compatibility)
|
101
|
+
const executionPayload = await interaction.request();
|
102
|
+
const txExecutionRequest = await wallet.createTxExecutionRequest(executionPayload, feeOptions, txOptions);
|
103
|
+
const provingResult = await wallet.proveTx(txExecutionRequest);
|
104
|
+
const txHashStd = await wallet.sendTx(provingResult.toTx());
|
105
|
+
console.log('Transaction sent with standard flow, hash:', txHashStd.toString());
|
106
|
+
const receiptStd = await wallet.getTxReceipt(txHashStd);
|
107
|
+
|
108
|
+
// For a read-only call
|
109
|
+
const simulateResult = await myContract.methods.balanceOf(address).simulate();
|
110
|
+
console.log('Simulate function result:', simulateResult);
|
111
|
+
}
|
139
112
|
```
|
140
113
|
|
141
|
-
###
|
114
|
+
### Wallet Implementation
|
115
|
+
|
116
|
+
```typescript
|
117
|
+
import { createAztecWalletNode } from '@walletmesh/aztec-rpc-wallet';
|
118
|
+
import { WalletRouter } from '@walletmesh/router';
|
119
|
+
|
120
|
+
// 1. Create Aztec wallet node
|
121
|
+
const walletNode = createAztecWalletNode(
|
122
|
+
accountWallet, // Your AccountWallet instance
|
123
|
+
pxe, // Your PXE instance
|
124
|
+
transport // JSON-RPC transport
|
125
|
+
);
|
142
126
|
|
143
|
-
|
127
|
+
// 2. Register with router
|
128
|
+
const router = new WalletRouter(
|
129
|
+
routerTransport,
|
130
|
+
new Map([
|
131
|
+
['aztec:testnet', walletNode],
|
132
|
+
// Add other chains as needed
|
133
|
+
]),
|
134
|
+
permissionManager
|
135
|
+
);
|
136
|
+
```
|
137
|
+
|
138
|
+
## API Reference
|
139
|
+
|
140
|
+
### DApp API
|
141
|
+
|
142
|
+
#### `AztecRouterProvider`
|
143
|
+
Extended WalletRouterProvider with built-in Aztec serialization support. Automatically handles serialization/deserialization of Aztec types (AztecAddress, CompleteAddress, Fr, etc.) when communicating through the router.
|
144
|
+
|
145
|
+
```typescript
|
146
|
+
const provider = new AztecRouterProvider(transport);
|
147
|
+
// All Aztec types are automatically serialized/deserialized
|
148
|
+
```
|
149
|
+
|
150
|
+
#### `createAztecWallet(provider, chainId)`
|
151
|
+
Creates an Aztec wallet instance that implements the aztec.js `Wallet` interface.
|
144
152
|
|
145
153
|
```typescript
|
146
|
-
|
147
|
-
const [account, contracts, blockNumber] = await provider
|
148
|
-
.chain('aztec:testnet')
|
149
|
-
.call('aztec_getAccount')
|
150
|
-
.call('aztec_getContracts')
|
151
|
-
.call('aztec_getBlockNumber')
|
152
|
-
.execute();
|
153
|
-
|
154
|
-
// Contract setup and interaction
|
155
|
-
const [classId, instanceId, txHash] = await provider
|
156
|
-
.chain('aztec:testnet')
|
157
|
-
.call('aztec_registerContractClass', { artifact: contractArtifact })
|
158
|
-
.call('aztec_registerContract', {
|
159
|
-
instance: contractInstance,
|
160
|
-
artifact: contractArtifact
|
161
|
-
})
|
162
|
-
.call('aztec_sendTransaction', {
|
163
|
-
functionCalls: [{
|
164
|
-
contractAddress: contractInstance.address,
|
165
|
-
functionName: 'initialize',
|
166
|
-
args: [param1, param2]
|
167
|
-
}]
|
168
|
-
})
|
169
|
-
.execute();
|
170
|
-
|
171
|
-
// Multi-chain operations
|
172
|
-
const [testnetData, devnetData] = await Promise.all([
|
173
|
-
provider
|
174
|
-
.chain('aztec:testnet')
|
175
|
-
.call('aztec_getAccount')
|
176
|
-
.call('aztec_getContracts')
|
177
|
-
.execute(),
|
178
|
-
provider
|
179
|
-
.chain('aztec:devnet')
|
180
|
-
.call('aztec_getAccount')
|
181
|
-
.call('aztec_getContracts')
|
182
|
-
.execute()
|
183
|
-
]);
|
154
|
+
const wallet = createAztecWallet(provider, 'aztec:testnet');
|
184
155
|
```
|
185
156
|
|
186
|
-
|
157
|
+
#### `connectAztec(provider, chainId?, methods?)`
|
158
|
+
Connects to an Aztec wallet service and returns an initialized `AztecDappWallet` instance.
|
159
|
+
- `provider`: An initialized `AztecRouterProvider`.
|
160
|
+
- `chainId?`: The target `AztecChainId` (e.g., `'aztec:testnet'`). Defaults to `'aztec:mainnet'`.
|
161
|
+
- `methods?`: Optional array of method names to request permissions for. Defaults to `ALL_AZTEC_METHODS`.
|
162
|
+
Returns: `Promise<{ sessionId: string; wallet: AztecDappWallet }>`
|
163
|
+
|
164
|
+
```typescript
|
165
|
+
const { sessionId, wallet } = await connectAztec(provider, 'aztec:testnet');
|
166
|
+
const address = wallet.getAddress(); // Wallet is ready
|
167
|
+
```
|
187
168
|
|
188
|
-
|
169
|
+
#### `AztecDappWallet`
|
170
|
+
The main client-side wallet class that implements the `aztec.js` `Wallet` interface. It interacts with the remote wallet via the `AztecRouterProvider`. Instances are typically created using `createAztecWallet` or `connectAztec`.
|
171
|
+
|
172
|
+
**Key `Wallet` Interface Methods (implemented by `AztecDappWallet`):**
|
173
|
+
|
174
|
+
* **Account Information:**
|
175
|
+
* `getAddress(): AztecAddress` - Gets the wallet's primary Aztec address (cached after initialization).
|
176
|
+
* `getCompleteAddress(): CompleteAddress` - Gets the wallet's complete address including public keys (cached).
|
177
|
+
* `getChainId(): Fr` - Gets the chain ID (cached).
|
178
|
+
* `getVersion(): Fr` - Gets the wallet/PXE version (cached).
|
179
|
+
* Async versions for direct fetching: `getAddressAsync()`, `getCompleteAddressAsync()`, `getChainIdAsync()`, `getVersionAsync()`.
|
180
|
+
|
181
|
+
* **Transaction Lifecycle:**
|
182
|
+
* `createTxExecutionRequest(exec: ExecutionPayload, fee: FeeOptions, options: TxExecutionOptions): Promise<TxExecutionRequest>` - Creates a transaction execution request using the wallet's local entrypoint.
|
183
|
+
* `proveTx(txRequest: TxExecutionRequest, privateExecutionResult?: PrivateExecutionResult): Promise<TxProvingResult>` - Generates proofs for a transaction.
|
184
|
+
* `sendTx(tx: Tx): Promise<TxHash>` - Sends a proven transaction to the network.
|
185
|
+
* `getTxReceipt(txHash: TxHash): Promise<TxReceipt>` - Retrieves a transaction receipt.
|
186
|
+
* `simulateTx(txRequest: TxExecutionRequest, simulatePublic: boolean, msgSender?: AztecAddress, skipTxValidation?: boolean, skipFeeEnforcement?: boolean, scopes?: AztecAddress[]): Promise<TxSimulationResult>` - Simulates a transaction.
|
187
|
+
* `profileTx(txRequest: TxExecutionRequest, profileMode: 'gates' | 'execution-steps' | 'full', skipProofGeneration?: boolean, msgSender?: AztecAddress): Promise<TxProfileResult>` - Profiles a transaction.
|
188
|
+
* `simulateUtility(functionName: string, args: unknown[], to: AztecAddress, authWits?: AuthWitness[], from?: AztecAddress): Promise<UtilitySimulationResult>` - Simulates a view function call.
|
189
|
+
|
190
|
+
* **Contract Management:**
|
191
|
+
* `registerContract(contract: { artifact?: ContractArtifact; instance: ContractInstanceWithAddress }): Promise<void>` - Registers a deployed contract instance.
|
192
|
+
* `registerContractClass(artifact: ContractArtifact): Promise<void>` - Registers a contract class/artifact.
|
193
|
+
* `getContracts(): Promise<AztecAddress[]>` - Gets all registered contract addresses.
|
194
|
+
* `getContractMetadata(address: AztecAddress): Promise<ContractMetadata>` - Gets metadata for a specific contract.
|
195
|
+
* `getContractClassMetadata(id: Fr, includeArtifact?: boolean): Promise<ContractClassMetadata>` - Gets metadata for a contract class.
|
196
|
+
* `updateContract(_contractAddress: AztecAddress, artifact: ContractArtifact): Promise<void>` - Updates a contract's artifact (typically re-registers its class).
|
197
|
+
|
198
|
+
* **Authorization & Senders:**
|
199
|
+
* `createAuthWit(intent: Fr | Buffer | IntentInnerHash | IntentAction): Promise<AuthWitness>` - Creates an authorization witness.
|
200
|
+
* `registerSender(address: AztecAddress): Promise<AztecAddress>` - Registers an authorized sender.
|
201
|
+
* `getSenders(): Promise<AztecAddress[]>` - Gets all authorized senders.
|
202
|
+
* `removeSender(sender: AztecAddress): Promise<void>` - Removes an authorized sender.
|
203
|
+
|
204
|
+
* **Network & Node Information:**
|
205
|
+
* `getBlock(number: number): Promise<L2Block | undefined>` - Gets a block by its number.
|
206
|
+
* `getBlockNumber(): Promise<number>` - Gets the current block number.
|
207
|
+
* `getCurrentBaseFees(): Promise<GasFees>` - Gets current base gas fees.
|
208
|
+
* `getNodeInfo(): Promise<NodeInfo>` - Gets node information.
|
209
|
+
* `getPXEInfo(): Promise<PXEInfo>` - Gets PXE service information.
|
210
|
+
|
211
|
+
* **Event Querying:**
|
212
|
+
* `getPrivateEvents<T>(contractAddress: AztecAddress, eventMetadata: EventMetadataDefinition, from: number, numBlocks: number, recipients: AztecAddress[]): Promise<T[]>` - Queries private (encrypted) events.
|
213
|
+
* `getPublicEvents<T>(eventMetadata: EventMetadataDefinition, from: number, limit: number): Promise<T[]>` - Queries public (unencrypted) events.
|
214
|
+
|
215
|
+
**WalletMesh Extended Methods on `AztecDappWallet`:**
|
216
|
+
These methods simplify common dApp workflows by leveraging WalletMesh capabilities.
|
217
|
+
- `wmExecuteTx(interaction: ContractFunctionInteraction): Promise<SentTx>` - High-level method to execute a transaction from a `ContractFunctionInteraction`. Handles payload creation, proving, and sending via the remote wallet.
|
218
|
+
- `wmSimulateTx(interaction: ContractFunctionInteraction): Promise<TxSimulationResult>` - High-level method to simulate a transaction from a `ContractFunctionInteraction`.
|
219
|
+
- `deployContract(artifact: ContractArtifact, args: unknown[], constructorName?: string): Promise<DeploySentTx>` - High-level method to deploy a contract.
|
220
|
+
|
221
|
+
Refer to `aztec.js` documentation for detailed explanations of the standard `Wallet` interface methods.
|
222
|
+
|
223
|
+
### Wallet API
|
224
|
+
|
225
|
+
#### `createAztecWalletNode(wallet, pxe, transport)`
|
226
|
+
Creates a JSONRPCNode configured for Aztec wallet operations.
|
189
227
|
|
190
228
|
```typescript
|
191
|
-
|
192
|
-
await provider.sendTransaction('aztec:testnet', {
|
193
|
-
functionCalls: [{
|
194
|
-
contractAddress: "0x1234...",
|
195
|
-
functionName: "transfer",
|
196
|
-
args: [recipient, amount]
|
197
|
-
}]
|
198
|
-
});
|
199
|
-
} catch (error) {
|
200
|
-
if (error instanceof AztecWalletError) {
|
201
|
-
switch (error.code) {
|
202
|
-
case -32001: // User refused
|
203
|
-
console.log('Transaction rejected by user');
|
204
|
-
break;
|
205
|
-
case -32002: // Wallet not connected
|
206
|
-
console.log('Please connect wallet first');
|
207
|
-
break;
|
208
|
-
default:
|
209
|
-
console.error('RPC error:', error.message);
|
210
|
-
}
|
211
|
-
}
|
212
|
-
}
|
229
|
+
const walletNode = createAztecWalletNode(accountWallet, pxe, transport);
|
213
230
|
```
|
214
231
|
|
215
|
-
|
232
|
+
## Method Permissions
|
233
|
+
|
234
|
+
### Default Methods
|
235
|
+
When using `connectAztec()` without specifying methods:
|
236
|
+
- `aztec_getAddress`
|
237
|
+
- `aztec_getCompleteAddress`
|
238
|
+
- `aztec_sendTx`
|
239
|
+
- `aztec_getTxReceipt`
|
240
|
+
- `aztec_createTxExecutionRequest`
|
241
|
+
- `aztec_simulateTx`
|
242
|
+
- `aztec_getNodeInfo`
|
243
|
+
- `aztec_getBlockNumber`
|
244
|
+
- `aztec_getCurrentBaseFees`
|
216
245
|
|
217
|
-
|
246
|
+
### All Available Methods
|
247
|
+
See `ALL_AZTEC_METHODS` export for the complete list of supported methods.
|
248
|
+
|
249
|
+
## Transport Layer
|
250
|
+
|
251
|
+
This library uses the `JSONRPCTransport` interface from `@walletmesh/jsonrpc` for communication:
|
218
252
|
|
219
253
|
```typescript
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
254
|
+
interface JSONRPCTransport {
|
255
|
+
send(data: unknown): Promise<void>;
|
256
|
+
onMessage(callback: (data: unknown) => void): void;
|
257
|
+
}
|
258
|
+
```
|
259
|
+
|
260
|
+
## Architecture Details
|
261
|
+
|
262
|
+
### Components
|
229
263
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
});
|
264
|
+
1. **Wallet Side** (`wallet/` directory)
|
265
|
+
- `create-node.ts` - Factory for JSONRPCNode
|
266
|
+
- `handlers/` - Pure function handlers for each method
|
267
|
+
- `serializers/` - Type serialization for Aztec objects
|
235
268
|
|
236
|
-
|
237
|
-
|
269
|
+
2. **DApp Side** (`client/` directory)
|
270
|
+
- `aztec-dapp-wallet.ts` - Implements aztec.js Wallet interface
|
271
|
+
- `helpers.ts` - Convenience functions
|
272
|
+
|
273
|
+
3. **Shared** (`types.ts`)
|
274
|
+
- Method definitions
|
275
|
+
- Aztec-specific types
|
276
|
+
|
277
|
+
### Handler Pattern
|
278
|
+
|
279
|
+
```typescript
|
280
|
+
export function createAccountHandlers() {
|
281
|
+
return {
|
282
|
+
aztec_getAddress: async (
|
283
|
+
ctx: AztecHandlerContext,
|
284
|
+
_paramsTuple: AztecWalletMethodMap['aztec_getAddress']['params'],
|
285
|
+
): Promise<AztecWalletMethodMap['aztec_getAddress']['result']> => {
|
286
|
+
return ctx.wallet.getAddress();
|
287
|
+
},
|
288
|
+
// ... more handlers
|
289
|
+
};
|
290
|
+
}
|
238
291
|
```
|
239
292
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
293
|
+
### Serializer Architecture
|
294
|
+
|
295
|
+
This package relies on Aztec's serialization mechanisms to handle complex Aztec data types over JSON-RPC. This is managed by the `AztecWalletSerializer` on the wallet-side and automatically handled by `AztecRouterProvider` on the dApp-side.
|
296
|
+
|
297
|
+
**Key Aspects:**
|
298
|
+
|
299
|
+
1. **`AztecWalletSerializer`**:
|
300
|
+
* A single, comprehensive serializer object (see `wallet/serializers.ts`) is responsible for all Aztec methods.
|
301
|
+
* **Parameter Deserialization (Wallet Side)**: When the wallet node receives a request, `AztecWalletSerializer` uses a detailed `switch` statement for `params.deserialize`. It parses the JSON parameters and reconstructs them into their proper Aztec object types (e.g., `AztecAddress.fromString(str)`, `TxExecutionRequest.schema.parse(obj)`), leveraging Zod schemas from `@aztec/aztec.js` and `@aztec/stdlib`.
|
302
|
+
* **Result Serialization (Wallet Side)**: For results being sent back to the dApp, `AztecWalletSerializer` uses `result.serialize`. It often employs `jsonStringify` from `@aztec/foundation/json-rpc` along with Zod schemas for specific Aztec result types.
|
303
|
+
* **Parameter Serialization (Client Side via `AztecRouterProvider`)**: The `AztecRouterProvider` ensures that when the dApp calls a method on `AztecDappWallet`, the parameters (which are already proper Aztec objects) are serialized correctly before being sent. This typically involves `jsonStringify` with appropriate schemas.
|
304
|
+
* **Result Deserialization (Client Side via `AztecRouterProvider`)**: When the dApp receives a response, `AztecRouterProvider` uses the serializer to convert the JSON data back into rich Aztec objects (e.g., an `AztecAddress` instance, not just a string).
|
305
|
+
|
306
|
+
2. **Zod Schemas**: The serialization heavily relies on Zod schemas defined within the Aztec protocol's libraries (e.g., `AztecAddress.schema`, `Tx.schema`) and some custom Zod schemas defined in this package for types not having them upstream.
|
307
|
+
|
308
|
+
3. **Automatic Handling for dApps**: DApp developers using `AztecRouterProvider` and `AztecDappWallet` generally do not need to worry about serialization details, as it's handled transparently.
|
309
|
+
|
310
|
+
This architecture ensures type safety and data integrity when complex Aztec objects are transmitted between the dApp and the wallet.
|
311
|
+
|
312
|
+
## DApp Usage Example
|
313
|
+
|
314
|
+
```typescript
|
315
|
+
import { AztecRouterProvider, connectAztecWithWallet, createAztecWallet } from '@walletmesh/aztec-rpc-wallet';
|
316
|
+
|
317
|
+
// Initialize the Aztec-specific router provider
|
318
|
+
const provider = new AztecRouterProvider(dAppTransportToRouter);
|
319
|
+
|
320
|
+
// Connect and get an initialized wallet instance
|
321
|
+
const { sessionId, wallet } = await connectAztecWithWallet(provider, 'aztec:testnet');
|
322
|
+
|
323
|
+
// 'wallet' is now an AztecDappWallet instance, ready for use
|
324
|
+
const address = wallet.getAddress();
|
325
|
+
```
|