@walletmesh/aztec-rpc-wallet 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +7 -0
- package/LICENSE +201 -0
- package/README.md +260 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/aztecRemoteWallet.d.ts +73 -0
- package/dist/aztecRemoteWallet.d.ts.map +1 -0
- package/dist/aztecRemoteWallet.js +354 -0
- package/dist/chainProvider.d.ts +56 -0
- package/dist/chainProvider.d.ts.map +1 -0
- package/dist/chainProvider.js +98 -0
- package/dist/contractArtifactCache.d.ts +50 -0
- package/dist/contractArtifactCache.d.ts.map +1 -0
- package/dist/contractArtifactCache.js +66 -0
- package/dist/errors.d.ts +50 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +62 -0
- package/dist/handlers/aztecAccountWallet.d.ts +4 -0
- package/dist/handlers/aztecAccountWallet.d.ts.map +1 -0
- package/dist/handlers/aztecAccountWallet.js +329 -0
- package/dist/handlers/transactions.d.ts +21 -0
- package/dist/handlers/transactions.d.ts.map +1 -0
- package/dist/handlers/transactions.js +90 -0
- package/dist/handlers.d.ts +27 -0
- package/dist/handlers.d.ts.map +1 -0
- package/dist/handlers.js +55 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/provider.d.ts +105 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +160 -0
- package/dist/serializers/account.d.ts +167 -0
- package/dist/serializers/account.d.ts.map +1 -0
- package/dist/serializers/account.js +245 -0
- package/dist/serializers/contract-utils.d.ts +40 -0
- package/dist/serializers/contract-utils.d.ts.map +1 -0
- package/dist/serializers/contract-utils.js +102 -0
- package/dist/serializers/contract.d.ts +168 -0
- package/dist/serializers/contract.d.ts.map +1 -0
- package/dist/serializers/contract.js +268 -0
- package/dist/serializers/core.d.ts +110 -0
- package/dist/serializers/core.d.ts.map +1 -0
- package/dist/serializers/core.js +130 -0
- package/dist/serializers/index.d.ts +28 -0
- package/dist/serializers/index.d.ts.map +1 -0
- package/dist/serializers/index.js +159 -0
- package/dist/serializers/log.d.ts +113 -0
- package/dist/serializers/log.d.ts.map +1 -0
- package/dist/serializers/log.js +231 -0
- package/dist/serializers/note.d.ts +127 -0
- package/dist/serializers/note.d.ts.map +1 -0
- package/dist/serializers/note.js +182 -0
- package/dist/serializers/transaction-utils.d.ts +107 -0
- package/dist/serializers/transaction-utils.d.ts.map +1 -0
- package/dist/serializers/transaction-utils.js +130 -0
- package/dist/serializers/transaction.d.ts +103 -0
- package/dist/serializers/transaction.d.ts.map +1 -0
- package/dist/serializers/transaction.js +238 -0
- package/dist/serializers/types.d.ts +49 -0
- package/dist/serializers/types.d.ts.map +1 -0
- package/dist/serializers/types.js +22 -0
- package/dist/types.d.ts +391 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/wallet.d.ts +62 -0
- package/dist/wallet.d.ts.map +1 -0
- package/dist/wallet.js +77 -0
- package/package.json +44 -0
- package/src/aztecRemoteWallet.test.ts +542 -0
- package/src/aztecRemoteWallet.ts +484 -0
- package/src/chainProvider.test.ts +322 -0
- package/src/chainProvider.ts +122 -0
- package/src/contractArtifactCache.test.ts +126 -0
- package/src/contractArtifactCache.ts +75 -0
- package/src/errors.ts +71 -0
- package/src/handlers/aztecAccountWallet.test.ts +720 -0
- package/src/handlers/aztecAccountWallet.ts +593 -0
- package/src/handlers/transactions.ts +110 -0
- package/src/handlers.test.ts +270 -0
- package/src/handlers.ts +70 -0
- package/src/index.test.ts +23 -0
- package/src/index.ts +64 -0
- package/src/provider.test.ts +276 -0
- package/src/provider.ts +189 -0
- package/src/serializers/account.test.ts +125 -0
- package/src/serializers/account.ts +319 -0
- package/src/serializers/contract-utils.ts +104 -0
- package/src/serializers/contract.test.ts +162 -0
- package/src/serializers/contract.ts +350 -0
- package/src/serializers/core.test.ts +56 -0
- package/src/serializers/core.ts +141 -0
- package/src/serializers/index.test.ts +122 -0
- package/src/serializers/index.ts +213 -0
- package/src/serializers/log.test.ts +119 -0
- package/src/serializers/log.ts +283 -0
- package/src/serializers/note.test.ts +100 -0
- package/src/serializers/note.ts +227 -0
- package/src/serializers/transaction-utils.ts +237 -0
- package/src/serializers/transaction.test.ts +153 -0
- package/src/serializers/transaction.ts +342 -0
- package/src/serializers/types.ts +58 -0
- package/src/types.ts +295 -0
- package/src/wallet.test.ts +275 -0
- package/src/wallet.ts +94 -0
- package/tsconfig.build.json +6 -0
- package/tsconfig.json +11 -0
- package/typedoc.json +15 -0
- package/vitest.config.ts +10 -0
package/src/provider.ts
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
import type { JSONRPCTransport } from '@walletmesh/jsonrpc';
|
2
|
+
import type { RouterEventMap } from '@walletmesh/router';
|
3
|
+
import { WalletRouterProvider } from '@walletmesh/router';
|
4
|
+
import { AztecWalletError, AztecWalletErrorType } from './errors.js';
|
5
|
+
import type { AztecChainId, AztecWalletMethodMap, TransactionParams } from './types.js';
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Provider for interacting with multiple Aztec chains through WalletMesh router.
|
9
|
+
*
|
10
|
+
* This class implements the client-side interface for dApps to communicate with Aztec wallets.
|
11
|
+
* It handles:
|
12
|
+
* - Connection management for multiple chains
|
13
|
+
* - Session tracking
|
14
|
+
* - Method calls with proper context
|
15
|
+
* - Event handling for wallet state changes
|
16
|
+
*
|
17
|
+
* @example
|
18
|
+
* ```typescript
|
19
|
+
* // Create provider with transport
|
20
|
+
* const provider = new AztecProvider(transport);
|
21
|
+
*
|
22
|
+
* // Connect to chains
|
23
|
+
* await provider.connect(['aztec:testnet', 'aztec:devnet']);
|
24
|
+
*
|
25
|
+
* // Single operation using convenience method
|
26
|
+
* const address = await provider.getAccount('aztec:testnet');
|
27
|
+
*
|
28
|
+
* // Single operation using chain builder
|
29
|
+
* const txHash = await provider.chain('aztec:testnet')
|
30
|
+
* .call('aztec_sendTransaction', {
|
31
|
+
* functionCalls: [{
|
32
|
+
* contractAddress: "0x...",
|
33
|
+
* functionName: "transfer",
|
34
|
+
* args: [recipient, amount]
|
35
|
+
* }]
|
36
|
+
* })
|
37
|
+
* .execute();
|
38
|
+
*
|
39
|
+
* // Multiple operations in one call
|
40
|
+
* const [account, contracts, blockNumber] = await provider
|
41
|
+
* .chain('aztec:testnet')
|
42
|
+
* .call('aztec_getAccount')
|
43
|
+
* .call('aztec_getContracts')
|
44
|
+
* .call('aztec_getBlockNumber')
|
45
|
+
* .execute();
|
46
|
+
* ```
|
47
|
+
*/
|
48
|
+
export class AztecProvider extends WalletRouterProvider {
|
49
|
+
private connectedChains: Set<AztecChainId>;
|
50
|
+
private requestedChains: Set<AztecChainId>;
|
51
|
+
|
52
|
+
constructor(transport: JSONRPCTransport) {
|
53
|
+
super(transport);
|
54
|
+
this.connectedChains = new Set();
|
55
|
+
this.requestedChains = new Set();
|
56
|
+
|
57
|
+
// Bind event handlers
|
58
|
+
this.handleWalletStateChanged = this.handleWalletStateChanged.bind(this);
|
59
|
+
this.handleSessionTerminated = this.handleSessionTerminated.bind(this);
|
60
|
+
|
61
|
+
// Register event handlers
|
62
|
+
this.on('wm_walletStateChanged', this.handleWalletStateChanged);
|
63
|
+
this.on('wm_sessionTerminated', this.handleSessionTerminated);
|
64
|
+
}
|
65
|
+
|
66
|
+
/**
|
67
|
+
* Handles wallet state change events from the router.
|
68
|
+
* Updates the set of connected chains based on account availability.
|
69
|
+
* @param params - Event parameters containing chain ID and changes
|
70
|
+
*/
|
71
|
+
private handleWalletStateChanged(params: RouterEventMap['wm_walletStateChanged']): void {
|
72
|
+
const { chainId, changes } = params;
|
73
|
+
const aztecChainId = chainId as AztecChainId;
|
74
|
+
|
75
|
+
// Only handle events for requested chains
|
76
|
+
if (this.requestedChains.has(aztecChainId)) {
|
77
|
+
if (changes.accounts && changes.accounts.length > 0) {
|
78
|
+
this.connectedChains.add(aztecChainId);
|
79
|
+
console.log('Chain connected:', aztecChainId);
|
80
|
+
} else {
|
81
|
+
this.connectedChains.delete(aztecChainId);
|
82
|
+
console.log('Chain disconnected:', aztecChainId);
|
83
|
+
}
|
84
|
+
console.log('Connected chains:', Array.from(this.connectedChains));
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Handles session termination events from the router.
|
90
|
+
* Cleans up session state and connected chains.
|
91
|
+
* @param params - Event parameters containing session ID
|
92
|
+
*/
|
93
|
+
private handleSessionTerminated(params: RouterEventMap['wm_sessionTerminated']): void {
|
94
|
+
const { sessionId } = params;
|
95
|
+
if (sessionId === this.sessionId) {
|
96
|
+
this.connectedChains.clear();
|
97
|
+
this.requestedChains.clear();
|
98
|
+
console.log('Session terminated, all chains cleared');
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
/**
|
103
|
+
* Gets the list of currently connected chain IDs.
|
104
|
+
* @returns Array of connected chain IDs
|
105
|
+
*/
|
106
|
+
public getSupportedChains(): AztecChainId[] {
|
107
|
+
return Array.from(this.connectedChains);
|
108
|
+
}
|
109
|
+
|
110
|
+
public async getAccount(chainId: AztecChainId): Promise<string> {
|
111
|
+
const result = await this.chain(chainId).call('aztec_getAccount').execute();
|
112
|
+
if (typeof result !== 'string' || !result) {
|
113
|
+
throw new AztecWalletError(AztecWalletErrorType.invalidResponse, 'Invalid account address returned');
|
114
|
+
}
|
115
|
+
return result;
|
116
|
+
}
|
117
|
+
|
118
|
+
/**
|
119
|
+
* Sends a transaction to the specified chain.
|
120
|
+
* @param chainId - ID of the chain to send transaction to
|
121
|
+
* @param params - Transaction parameters including function calls and optional auth witnesses
|
122
|
+
* @returns Transaction hash
|
123
|
+
* @throws {AztecWalletError} If transaction fails or response invalid
|
124
|
+
*/
|
125
|
+
public async sendTransaction(chainId: AztecChainId, params: TransactionParams): Promise<string> {
|
126
|
+
const result = await this.chain(chainId).call('aztec_sendTransaction', params).execute();
|
127
|
+
if (typeof result !== 'string' || !result) {
|
128
|
+
throw new AztecWalletError(AztecWalletErrorType.invalidResponse, 'Invalid transaction hash returned');
|
129
|
+
}
|
130
|
+
return result;
|
131
|
+
}
|
132
|
+
|
133
|
+
/**
|
134
|
+
* Simulates a transaction without submitting it.
|
135
|
+
* @param chainId - ID of the chain to simulate on
|
136
|
+
* @param params - Transaction parameters to simulate
|
137
|
+
* @returns Simulation result
|
138
|
+
* @throws {AztecWalletError} If simulation fails
|
139
|
+
*/
|
140
|
+
public async simulateTransaction(
|
141
|
+
chainId: AztecChainId,
|
142
|
+
params: TransactionParams['functionCalls'][0],
|
143
|
+
): Promise<unknown> {
|
144
|
+
const result = await this.chain(chainId).call('aztec_simulateTransaction', params).execute();
|
145
|
+
if (result === undefined || result === null) {
|
146
|
+
throw new AztecWalletError(AztecWalletErrorType.invalidResponse, 'Invalid simulation result returned');
|
147
|
+
}
|
148
|
+
return result;
|
149
|
+
}
|
150
|
+
|
151
|
+
/**
|
152
|
+
* Registers a contract instance with the wallet.
|
153
|
+
* @param chainId - ID of the chain where contract is deployed
|
154
|
+
* @param params - Contract registration parameters
|
155
|
+
* @throws {AztecWalletError} If registration fails
|
156
|
+
*/
|
157
|
+
public async registerContract(
|
158
|
+
chainId: AztecChainId,
|
159
|
+
params: AztecWalletMethodMap['aztec_registerContract']['params'],
|
160
|
+
): Promise<void> {
|
161
|
+
await this.chain(chainId).call('aztec_registerContract', params).execute();
|
162
|
+
}
|
163
|
+
|
164
|
+
/**
|
165
|
+
* Registers a contract class with the wallet.
|
166
|
+
* @param chainId - ID of the chain to register on
|
167
|
+
* @param params - Contract class registration parameters
|
168
|
+
* @throws {AztecWalletError} If registration fails
|
169
|
+
*/
|
170
|
+
public async registerContractClass(
|
171
|
+
chainId: AztecChainId,
|
172
|
+
params: AztecWalletMethodMap['aztec_registerContractClass']['params'],
|
173
|
+
): Promise<void> {
|
174
|
+
await this.chain(chainId).call('aztec_registerContractClass', params).execute();
|
175
|
+
}
|
176
|
+
|
177
|
+
/**
|
178
|
+
* Registers a transaction sender with the wallet.
|
179
|
+
* @param chainId - ID of the chain to register on
|
180
|
+
* @param params - Sender registration parameters
|
181
|
+
* @throws {AztecWalletError} If registration fails
|
182
|
+
*/
|
183
|
+
public async registerSender(
|
184
|
+
chainId: AztecChainId,
|
185
|
+
params: AztecWalletMethodMap['aztec_registerSender']['params'],
|
186
|
+
): Promise<void> {
|
187
|
+
await this.chain(chainId).call('aztec_registerSender', params).execute();
|
188
|
+
}
|
189
|
+
}
|
@@ -0,0 +1,125 @@
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
2
|
+
import { Fr, AztecAddress, CompleteAddress, AuthWitness } from '@aztec/aztec.js';
|
3
|
+
import {
|
4
|
+
aztecSetScopesSerializer,
|
5
|
+
aztecRegisterAccountSerializer,
|
6
|
+
aztecAddAuthWitnessSerializer,
|
7
|
+
aztecGetAuthWitnessSerializer,
|
8
|
+
} from './account.js';
|
9
|
+
import { decodeBase64 } from './types.js';
|
10
|
+
import { frSerializer } from './core.js';
|
11
|
+
|
12
|
+
describe('Account Serializers', () => {
|
13
|
+
describe('aztec_setScopes', () => {
|
14
|
+
const METHOD = 'aztec_setScopes';
|
15
|
+
|
16
|
+
it('should serialize and deserialize params', () => {
|
17
|
+
const scopes = [AztecAddress.random(), AztecAddress.random()];
|
18
|
+
const params = { scopes };
|
19
|
+
|
20
|
+
const serialized = aztecSetScopesSerializer.params.serialize(METHOD, params);
|
21
|
+
expect(serialized.method).toBe(METHOD);
|
22
|
+
|
23
|
+
const deserialized = aztecSetScopesSerializer.params.deserialize(METHOD, serialized);
|
24
|
+
expect(deserialized.scopes.map((s) => s.toString())).toEqual(scopes.map((s) => s.toString()));
|
25
|
+
});
|
26
|
+
|
27
|
+
it('should serialize and deserialize result', () => {
|
28
|
+
const result = true;
|
29
|
+
|
30
|
+
const serialized = aztecSetScopesSerializer.result.serialize(METHOD, result);
|
31
|
+
expect(serialized.method).toBe(METHOD);
|
32
|
+
|
33
|
+
const deserialized = aztecSetScopesSerializer.result.deserialize(METHOD, serialized);
|
34
|
+
expect(deserialized).toBe(result);
|
35
|
+
});
|
36
|
+
});
|
37
|
+
|
38
|
+
describe('aztec_registerAccount', () => {
|
39
|
+
const METHOD = 'aztec_registerAccount';
|
40
|
+
|
41
|
+
it('should serialize and deserialize params', () => {
|
42
|
+
const secretKey = Fr.random();
|
43
|
+
const partialAddress = Fr.random();
|
44
|
+
const params = { secretKey, partialAddress };
|
45
|
+
|
46
|
+
const serialized = aztecRegisterAccountSerializer.params.serialize(METHOD, params);
|
47
|
+
expect(serialized.method).toBe(METHOD);
|
48
|
+
|
49
|
+
const deserialized = aztecRegisterAccountSerializer.params.deserialize(METHOD, serialized);
|
50
|
+
expect(deserialized.secretKey.toString()).toBe(secretKey.toString());
|
51
|
+
expect(deserialized.partialAddress.toString()).toBe(partialAddress.toString());
|
52
|
+
});
|
53
|
+
|
54
|
+
it('should serialize and deserialize result', () => {
|
55
|
+
const result = CompleteAddress.random();
|
56
|
+
|
57
|
+
const serialized = aztecRegisterAccountSerializer.result.serialize(METHOD, result);
|
58
|
+
expect(serialized.method).toBe(METHOD);
|
59
|
+
|
60
|
+
const deserialized = aztecRegisterAccountSerializer.result.deserialize(METHOD, serialized);
|
61
|
+
expect(deserialized.toString()).toBe(result.toString());
|
62
|
+
});
|
63
|
+
});
|
64
|
+
|
65
|
+
describe('aztec_addAuthWitness', () => {
|
66
|
+
const METHOD = 'aztec_addAuthWitness';
|
67
|
+
|
68
|
+
it('should serialize and deserialize params', () => {
|
69
|
+
const authWitness = AuthWitness.random();
|
70
|
+
const params = { authWitness };
|
71
|
+
|
72
|
+
const serialized = aztecAddAuthWitnessSerializer.params.serialize(METHOD, params);
|
73
|
+
expect(serialized.method).toBe(METHOD);
|
74
|
+
|
75
|
+
const deserialized = aztecAddAuthWitnessSerializer.params.deserialize(METHOD, serialized);
|
76
|
+
expect(deserialized.authWitness.toString()).toBe(authWitness.toString());
|
77
|
+
});
|
78
|
+
|
79
|
+
it('should serialize and deserialize result', () => {
|
80
|
+
const result = true;
|
81
|
+
|
82
|
+
const serialized = aztecAddAuthWitnessSerializer.result.serialize(METHOD, result);
|
83
|
+
expect(serialized.method).toBe(METHOD);
|
84
|
+
|
85
|
+
const deserialized = aztecAddAuthWitnessSerializer.result.deserialize(METHOD, serialized);
|
86
|
+
expect(deserialized).toBe(result);
|
87
|
+
});
|
88
|
+
});
|
89
|
+
|
90
|
+
describe('aztec_getAuthWitness', () => {
|
91
|
+
const METHOD = 'aztec_getAuthWitness';
|
92
|
+
|
93
|
+
it('should serialize and deserialize params', () => {
|
94
|
+
const messageHash = Fr.random();
|
95
|
+
const params = { messageHash };
|
96
|
+
|
97
|
+
const serialized = aztecGetAuthWitnessSerializer.params.serialize(METHOD, params);
|
98
|
+
expect(serialized.method).toBe(METHOD);
|
99
|
+
|
100
|
+
const deserialized = aztecGetAuthWitnessSerializer.params.deserialize(METHOD, serialized);
|
101
|
+
expect(deserialized.messageHash.toString()).toBe(messageHash.toString());
|
102
|
+
});
|
103
|
+
|
104
|
+
it('should serialize and deserialize result', () => {
|
105
|
+
const result = [Fr.random(), Fr.random()];
|
106
|
+
|
107
|
+
const serialized = aztecGetAuthWitnessSerializer.result.serialize(METHOD, result);
|
108
|
+
expect(serialized.method).toBe(METHOD);
|
109
|
+
|
110
|
+
const deserialized = aztecGetAuthWitnessSerializer.result.deserialize(METHOD, serialized);
|
111
|
+
expect(deserialized.map((w) => w.toString())).toEqual(result.map((w) => w.toString()));
|
112
|
+
});
|
113
|
+
});
|
114
|
+
|
115
|
+
describe('Base64 encoding/decoding', () => {
|
116
|
+
it('should properly encode and decode data', () => {
|
117
|
+
const messageHash = Fr.random();
|
118
|
+
const serialized = aztecGetAuthWitnessSerializer.params.serialize('aztec_getAuthWitness', {
|
119
|
+
messageHash,
|
120
|
+
});
|
121
|
+
const decoded = frSerializer.deserialize(decodeBase64(serialized.serialized));
|
122
|
+
expect(decoded.toString()).toBe(messageHash.toString());
|
123
|
+
});
|
124
|
+
});
|
125
|
+
});
|
@@ -0,0 +1,319 @@
|
|
1
|
+
import type { AztecWalletMethodMap } from '../types.js';
|
2
|
+
import type { JSONRPCSerializedData, JSONRPCSerializer } from './types.js';
|
3
|
+
import { encodeBase64, decodeBase64 } from './types.js';
|
4
|
+
import {
|
5
|
+
aztecAddressSerializer,
|
6
|
+
completeAddressSerializer,
|
7
|
+
frSerializer,
|
8
|
+
authWitnessSerializer,
|
9
|
+
} from './core.js';
|
10
|
+
import type { PartialAddress, AztecAddress } from '@aztec/aztec.js';
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Serializer for the aztec_setScopes RPC method.
|
14
|
+
* Handles serialization of account scope settings between JSON-RPC format and native Aztec types.
|
15
|
+
* Scopes define which contracts can interact with an account.
|
16
|
+
*/
|
17
|
+
export class AztecSetScopesSerializer
|
18
|
+
implements
|
19
|
+
JSONRPCSerializer<
|
20
|
+
AztecWalletMethodMap['aztec_setScopes']['params'],
|
21
|
+
AztecWalletMethodMap['aztec_setScopes']['result']
|
22
|
+
>
|
23
|
+
{
|
24
|
+
params = {
|
25
|
+
/**
|
26
|
+
* Serializes scope setting parameters for RPC transport.
|
27
|
+
* @param method - The RPC method name
|
28
|
+
* @param value - The parameters containing an array of Aztec addresses representing scopes
|
29
|
+
* @returns Serialized scope data
|
30
|
+
*/
|
31
|
+
serialize: (
|
32
|
+
method: string,
|
33
|
+
value: AztecWalletMethodMap['aztec_setScopes']['params'],
|
34
|
+
): JSONRPCSerializedData => {
|
35
|
+
const { scopes } = value;
|
36
|
+
return {
|
37
|
+
method,
|
38
|
+
serialized: encodeBase64(
|
39
|
+
JSON.stringify(scopes.map((s: AztecAddress) => aztecAddressSerializer.serialize(s))),
|
40
|
+
),
|
41
|
+
};
|
42
|
+
},
|
43
|
+
/**
|
44
|
+
* Deserializes scope setting parameters from RPC transport.
|
45
|
+
* @param method - The RPC method name
|
46
|
+
* @param data - The serialized scope data
|
47
|
+
* @returns Deserialized scope parameters
|
48
|
+
*/
|
49
|
+
deserialize: (
|
50
|
+
method: string,
|
51
|
+
data: JSONRPCSerializedData,
|
52
|
+
): AztecWalletMethodMap['aztec_setScopes']['params'] => {
|
53
|
+
const scopes = JSON.parse(decodeBase64(data.serialized)).map((s: string) =>
|
54
|
+
aztecAddressSerializer.deserialize(s),
|
55
|
+
);
|
56
|
+
return { scopes };
|
57
|
+
},
|
58
|
+
};
|
59
|
+
|
60
|
+
result = {
|
61
|
+
/**
|
62
|
+
* Serializes the scope setting result.
|
63
|
+
* @param method - The RPC method name
|
64
|
+
* @param value - Boolean indicating success of the scope setting operation
|
65
|
+
* @returns Serialized result
|
66
|
+
*/
|
67
|
+
serialize: (method: string, value: boolean): JSONRPCSerializedData => {
|
68
|
+
return {
|
69
|
+
method,
|
70
|
+
serialized: encodeBase64(JSON.stringify(value)),
|
71
|
+
};
|
72
|
+
},
|
73
|
+
/**
|
74
|
+
* Deserializes the scope setting result.
|
75
|
+
* @param method - The RPC method name
|
76
|
+
* @param data - The serialized result data
|
77
|
+
* @returns Boolean indicating success
|
78
|
+
*/
|
79
|
+
deserialize: (method: string, data: JSONRPCSerializedData): boolean => {
|
80
|
+
return JSON.parse(decodeBase64(data.serialized));
|
81
|
+
},
|
82
|
+
};
|
83
|
+
}
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Serializer for the aztec_registerAccount RPC method.
|
87
|
+
* Handles serialization of account registration data between JSON-RPC format and native Aztec types.
|
88
|
+
* Account registration involves creating a new account with a secret key and partial address.
|
89
|
+
*/
|
90
|
+
export class AztecRegisterAccountSerializer
|
91
|
+
implements
|
92
|
+
JSONRPCSerializer<
|
93
|
+
AztecWalletMethodMap['aztec_registerAccount']['params'],
|
94
|
+
AztecWalletMethodMap['aztec_registerAccount']['result']
|
95
|
+
>
|
96
|
+
{
|
97
|
+
params = {
|
98
|
+
/**
|
99
|
+
* Serializes account registration parameters for RPC transport.
|
100
|
+
* @param method - The RPC method name
|
101
|
+
* @param value - The parameters containing secret key and partial address
|
102
|
+
* @returns Serialized registration data
|
103
|
+
*/
|
104
|
+
serialize: (
|
105
|
+
method: string,
|
106
|
+
value: AztecWalletMethodMap['aztec_registerAccount']['params'],
|
107
|
+
): JSONRPCSerializedData => {
|
108
|
+
const { secretKey, partialAddress } = value;
|
109
|
+
return {
|
110
|
+
method,
|
111
|
+
serialized: encodeBase64(
|
112
|
+
JSON.stringify([
|
113
|
+
frSerializer.serialize(secretKey),
|
114
|
+
frSerializer.serialize(partialAddress as unknown as PartialAddress),
|
115
|
+
]),
|
116
|
+
),
|
117
|
+
};
|
118
|
+
},
|
119
|
+
/**
|
120
|
+
* Deserializes account registration parameters from RPC transport.
|
121
|
+
* @param method - The RPC method name
|
122
|
+
* @param data - The serialized registration data
|
123
|
+
* @returns Deserialized registration parameters
|
124
|
+
*/
|
125
|
+
deserialize: (
|
126
|
+
method: string,
|
127
|
+
data: JSONRPCSerializedData,
|
128
|
+
): AztecWalletMethodMap['aztec_registerAccount']['params'] => {
|
129
|
+
const [secretKey, partialAddress] = JSON.parse(decodeBase64(data.serialized));
|
130
|
+
return {
|
131
|
+
secretKey: frSerializer.deserialize(secretKey),
|
132
|
+
partialAddress: frSerializer.deserialize(partialAddress) as PartialAddress,
|
133
|
+
};
|
134
|
+
},
|
135
|
+
};
|
136
|
+
|
137
|
+
result = {
|
138
|
+
/**
|
139
|
+
* Serializes the account registration result.
|
140
|
+
* @param method - The RPC method name
|
141
|
+
* @param value - The complete address of the registered account
|
142
|
+
* @returns Serialized complete address
|
143
|
+
*/
|
144
|
+
serialize: (
|
145
|
+
method: string,
|
146
|
+
value: AztecWalletMethodMap['aztec_registerAccount']['result'],
|
147
|
+
): JSONRPCSerializedData => {
|
148
|
+
return {
|
149
|
+
method,
|
150
|
+
serialized: encodeBase64(completeAddressSerializer.serialize(value)),
|
151
|
+
};
|
152
|
+
},
|
153
|
+
/**
|
154
|
+
* Deserializes the account registration result.
|
155
|
+
* @param method - The RPC method name
|
156
|
+
* @param data - The serialized complete address
|
157
|
+
* @returns Deserialized complete address
|
158
|
+
*/
|
159
|
+
deserialize: (
|
160
|
+
method: string,
|
161
|
+
data: JSONRPCSerializedData,
|
162
|
+
): AztecWalletMethodMap['aztec_registerAccount']['result'] => {
|
163
|
+
return completeAddressSerializer.deserialize(decodeBase64(data.serialized));
|
164
|
+
},
|
165
|
+
};
|
166
|
+
}
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Serializer for the aztec_addAuthWitness RPC method.
|
170
|
+
* Handles serialization of authentication witness data between JSON-RPC format and native Aztec types.
|
171
|
+
* Auth witnesses are used to prove transaction authorization.
|
172
|
+
*/
|
173
|
+
export class AztecAddAuthWitnessSerializer
|
174
|
+
implements
|
175
|
+
JSONRPCSerializer<
|
176
|
+
AztecWalletMethodMap['aztec_addAuthWitness']['params'],
|
177
|
+
AztecWalletMethodMap['aztec_addAuthWitness']['result']
|
178
|
+
>
|
179
|
+
{
|
180
|
+
params = {
|
181
|
+
/**
|
182
|
+
* Serializes auth witness addition parameters for RPC transport.
|
183
|
+
* @param method - The RPC method name
|
184
|
+
* @param value - The parameters containing the auth witness to add
|
185
|
+
* @returns Serialized auth witness data
|
186
|
+
*/
|
187
|
+
serialize: (
|
188
|
+
method: string,
|
189
|
+
value: AztecWalletMethodMap['aztec_addAuthWitness']['params'],
|
190
|
+
): JSONRPCSerializedData => {
|
191
|
+
const { authWitness } = value;
|
192
|
+
return {
|
193
|
+
method,
|
194
|
+
serialized: encodeBase64(authWitnessSerializer.serialize(authWitness)),
|
195
|
+
};
|
196
|
+
},
|
197
|
+
/**
|
198
|
+
* Deserializes auth witness addition parameters from RPC transport.
|
199
|
+
* @param method - The RPC method name
|
200
|
+
* @param data - The serialized auth witness data
|
201
|
+
* @returns Deserialized auth witness parameters
|
202
|
+
*/
|
203
|
+
deserialize: (
|
204
|
+
method: string,
|
205
|
+
data: JSONRPCSerializedData,
|
206
|
+
): AztecWalletMethodMap['aztec_addAuthWitness']['params'] => {
|
207
|
+
const authWitness = authWitnessSerializer.deserialize(decodeBase64(data.serialized));
|
208
|
+
return { authWitness };
|
209
|
+
},
|
210
|
+
};
|
211
|
+
|
212
|
+
result = {
|
213
|
+
/**
|
214
|
+
* Serializes the auth witness addition result.
|
215
|
+
* @param method - The RPC method name
|
216
|
+
* @param value - Boolean indicating success of the witness addition
|
217
|
+
* @returns Serialized result
|
218
|
+
*/
|
219
|
+
serialize: (method: string, value: boolean): JSONRPCSerializedData => {
|
220
|
+
return {
|
221
|
+
method,
|
222
|
+
serialized: encodeBase64(JSON.stringify(value)),
|
223
|
+
};
|
224
|
+
},
|
225
|
+
/**
|
226
|
+
* Deserializes the auth witness addition result.
|
227
|
+
* @param method - The RPC method name
|
228
|
+
* @param data - The serialized result data
|
229
|
+
* @returns Boolean indicating success
|
230
|
+
*/
|
231
|
+
deserialize: (method: string, data: JSONRPCSerializedData): boolean => {
|
232
|
+
return JSON.parse(decodeBase64(data.serialized));
|
233
|
+
},
|
234
|
+
};
|
235
|
+
}
|
236
|
+
|
237
|
+
/**
|
238
|
+
* Serializer for the aztec_getAuthWitness RPC method.
|
239
|
+
* Handles serialization of authentication witness retrieval between JSON-RPC format and native Aztec types.
|
240
|
+
* Retrieves auth witnesses associated with a specific message hash.
|
241
|
+
*/
|
242
|
+
export class AztecGetAuthWitnessSerializer
|
243
|
+
implements
|
244
|
+
JSONRPCSerializer<
|
245
|
+
AztecWalletMethodMap['aztec_getAuthWitness']['params'],
|
246
|
+
AztecWalletMethodMap['aztec_getAuthWitness']['result']
|
247
|
+
>
|
248
|
+
{
|
249
|
+
params = {
|
250
|
+
/**
|
251
|
+
* Serializes auth witness retrieval parameters for RPC transport.
|
252
|
+
* @param method - The RPC method name
|
253
|
+
* @param value - The parameters containing the message hash to look up
|
254
|
+
* @returns Serialized message hash data
|
255
|
+
*/
|
256
|
+
serialize: (
|
257
|
+
method: string,
|
258
|
+
value: AztecWalletMethodMap['aztec_getAuthWitness']['params'],
|
259
|
+
): JSONRPCSerializedData => {
|
260
|
+
const { messageHash } = value;
|
261
|
+
return {
|
262
|
+
method,
|
263
|
+
serialized: encodeBase64(frSerializer.serialize(messageHash)),
|
264
|
+
};
|
265
|
+
},
|
266
|
+
/**
|
267
|
+
* Deserializes auth witness retrieval parameters from RPC transport.
|
268
|
+
* @param method - The RPC method name
|
269
|
+
* @param data - The serialized message hash data
|
270
|
+
* @returns Deserialized message hash parameters
|
271
|
+
*/
|
272
|
+
deserialize: (
|
273
|
+
method: string,
|
274
|
+
data: JSONRPCSerializedData,
|
275
|
+
): AztecWalletMethodMap['aztec_getAuthWitness']['params'] => {
|
276
|
+
const messageHash = frSerializer.deserialize(decodeBase64(data.serialized));
|
277
|
+
return { messageHash };
|
278
|
+
},
|
279
|
+
};
|
280
|
+
|
281
|
+
result = {
|
282
|
+
/**
|
283
|
+
* Serializes the auth witness retrieval result.
|
284
|
+
* @param method - The RPC method name
|
285
|
+
* @param value - Array of field elements representing auth witnesses
|
286
|
+
* @returns Serialized witness array
|
287
|
+
*/
|
288
|
+
serialize: (
|
289
|
+
method: string,
|
290
|
+
value: AztecWalletMethodMap['aztec_getAuthWitness']['result'],
|
291
|
+
): JSONRPCSerializedData => {
|
292
|
+
return {
|
293
|
+
method,
|
294
|
+
serialized: encodeBase64(JSON.stringify(value.map((w) => frSerializer.serialize(w)))),
|
295
|
+
};
|
296
|
+
},
|
297
|
+
/**
|
298
|
+
* Deserializes the auth witness retrieval result.
|
299
|
+
* @param method - The RPC method name
|
300
|
+
* @param data - The serialized witness array data
|
301
|
+
* @returns Array of deserialized field elements
|
302
|
+
*/
|
303
|
+
deserialize: (
|
304
|
+
method: string,
|
305
|
+
data: JSONRPCSerializedData,
|
306
|
+
): AztecWalletMethodMap['aztec_getAuthWitness']['result'] => {
|
307
|
+
return JSON.parse(decodeBase64(data.serialized)).map((w: string) => frSerializer.deserialize(w));
|
308
|
+
},
|
309
|
+
};
|
310
|
+
}
|
311
|
+
|
312
|
+
/**
|
313
|
+
* Pre-instantiated serializer instances for Aztec account-related RPC methods.
|
314
|
+
* These instances can be used directly by the RPC handler implementation.
|
315
|
+
*/
|
316
|
+
export const aztecSetScopesSerializer = new AztecSetScopesSerializer();
|
317
|
+
export const aztecRegisterAccountSerializer = new AztecRegisterAccountSerializer();
|
318
|
+
export const aztecAddAuthWitnessSerializer = new AztecAddAuthWitnessSerializer();
|
319
|
+
export const aztecGetAuthWitnessSerializer = new AztecGetAuthWitnessSerializer();
|