@walletmesh/aztec-rpc-wallet 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/README.md +290 -228
- package/dist/.tsbuildinfo +1 -1
- package/dist/client/aztec-dapp-wallet.d.ts +401 -0
- package/dist/client/aztec-dapp-wallet.d.ts.map +1 -0
- package/dist/client/aztec-dapp-wallet.js +705 -0
- package/dist/client/aztec-router-provider.d.ts +58 -0
- package/dist/client/aztec-router-provider.d.ts.map +1 -0
- package/dist/client/aztec-router-provider.js +62 -0
- package/dist/client/helpers.d.ts +44 -0
- package/dist/client/helpers.d.ts.map +1 -0
- package/dist/client/helpers.js +79 -0
- package/dist/client/register-serializers.d.ts +41 -0
- package/dist/client/register-serializers.d.ts.map +1 -0
- package/dist/client/register-serializers.js +97 -0
- package/dist/contractArtifactCache.d.ts +49 -32
- package/dist/contractArtifactCache.d.ts.map +1 -1
- package/dist/contractArtifactCache.js +47 -34
- package/dist/errors.d.ts +50 -8
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +50 -10
- package/dist/index.d.ts +53 -40
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -17
- package/dist/types.d.ts +345 -268
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +10 -8
- package/dist/wallet/create-node.d.ts +73 -0
- package/dist/wallet/create-node.d.ts.map +1 -0
- package/dist/wallet/create-node.js +99 -0
- package/dist/wallet/handlers/account.d.ts +67 -0
- package/dist/wallet/handlers/account.d.ts.map +1 -0
- package/dist/wallet/handlers/account.js +85 -0
- package/dist/wallet/handlers/contract-interaction.d.ts +77 -0
- package/dist/wallet/handlers/contract-interaction.d.ts.map +1 -0
- package/dist/wallet/handlers/contract-interaction.js +219 -0
- package/dist/wallet/handlers/contract.d.ts +96 -0
- package/dist/wallet/handlers/contract.d.ts.map +1 -0
- package/dist/wallet/handlers/contract.js +146 -0
- package/dist/wallet/handlers/event.d.ts +62 -0
- package/dist/wallet/handlers/event.d.ts.map +1 -0
- package/dist/wallet/handlers/event.js +85 -0
- package/dist/wallet/handlers/index.d.ts +88 -0
- package/dist/wallet/handlers/index.d.ts.map +1 -0
- package/dist/wallet/handlers/index.js +47 -0
- package/dist/wallet/handlers/node.d.ts +117 -0
- package/dist/wallet/handlers/node.d.ts.map +1 -0
- package/dist/wallet/handlers/node.js +196 -0
- package/dist/wallet/handlers/senders.d.ts +70 -0
- package/dist/wallet/handlers/senders.d.ts.map +1 -0
- package/dist/wallet/handlers/senders.js +92 -0
- package/dist/wallet/handlers/transaction.d.ts +123 -0
- package/dist/wallet/handlers/transaction.d.ts.map +1 -0
- package/dist/wallet/handlers/transaction.js +191 -0
- package/dist/wallet/serializers.d.ts +75 -0
- package/dist/wallet/serializers.d.ts.map +1 -0
- package/dist/wallet/serializers.js +501 -0
- package/docs/README.md +290 -229
- package/docs/classes/AztecDappWallet.md +1304 -0
- package/docs/classes/AztecRouterProvider.md +1058 -0
- package/docs/classes/AztecWalletError.md +124 -47
- package/docs/classes/ContractArtifactCache.md +48 -31
- package/docs/functions/connectAztec.md +62 -0
- package/docs/functions/createAztecWallet.md +46 -0
- package/docs/functions/createAztecWalletNode.md +96 -0
- package/docs/functions/registerAztecSerializers.md +61 -0
- package/docs/functions/registerWalletAztecSerializers.md +39 -0
- package/docs/globals.md +16 -14
- package/docs/interfaces/AztecHandlerContext.md +54 -0
- package/docs/interfaces/AztecWalletContext.md +50 -0
- package/docs/interfaces/AztecWalletMethodMap.md +471 -470
- package/docs/type-aliases/AztecChainId.md +16 -3
- package/docs/variables/ALL_AZTEC_METHODS.md +20 -0
- package/docs/variables/AztecWalletErrorMap.md +9 -4
- package/docs/variables/AztecWalletSerializer.md +45 -0
- package/package.json +9 -9
- package/src/client/aztec-dapp-wallet.test.ts +628 -0
- package/src/client/aztec-dapp-wallet.ts +879 -0
- package/src/client/aztec-router-provider.test.ts +235 -0
- package/src/client/aztec-router-provider.ts +64 -0
- package/src/client/helpers.test.ts +187 -0
- package/src/client/helpers.ts +91 -0
- package/src/client/register-serializers.ts +108 -0
- package/src/contractArtifactCache.test.ts +21 -10
- package/src/contractArtifactCache.ts +54 -35
- package/src/errors.ts +58 -10
- package/src/index.test.ts +2 -6
- package/src/index.ts +73 -37
- package/src/types.ts +379 -217
- package/src/wallet/create-node.test.ts +332 -0
- package/src/wallet/create-node.ts +120 -0
- package/src/wallet/handlers/account.test.ts +172 -0
- package/src/wallet/handlers/account.ts +99 -0
- package/src/wallet/handlers/contract-interaction.test.ts +248 -0
- package/src/wallet/handlers/contract-interaction.ts +269 -0
- package/src/wallet/handlers/contract.test.ts +245 -0
- package/src/wallet/handlers/contract.ts +174 -0
- package/src/wallet/handlers/event.test.ts +216 -0
- package/src/wallet/handlers/event.ts +99 -0
- package/src/wallet/handlers/index.ts +84 -0
- package/src/wallet/handlers/node.test.ts +304 -0
- package/src/wallet/handlers/node.ts +230 -0
- package/src/wallet/handlers/senders.test.ts +172 -0
- package/src/wallet/handlers/senders.ts +106 -0
- package/src/wallet/handlers/transaction.test.ts +371 -0
- package/src/wallet/handlers/transaction.ts +239 -0
- package/src/wallet/serializers.test.ts +253 -0
- package/src/wallet/serializers.ts +586 -0
- package/typedoc.json +23 -1
- package/dist/aztecRemoteWallet.d.ts +0 -70
- package/dist/aztecRemoteWallet.d.ts.map +0 -1
- package/dist/aztecRemoteWallet.js +0 -335
- package/dist/chainProvider.d.ts +0 -56
- package/dist/chainProvider.d.ts.map +0 -1
- package/dist/chainProvider.js +0 -98
- package/dist/handlers/aztecAccountWallet.d.ts +0 -4
- package/dist/handlers/aztecAccountWallet.d.ts.map +0 -1
- package/dist/handlers/aztecAccountWallet.js +0 -296
- package/dist/handlers/transactions.d.ts +0 -21
- package/dist/handlers/transactions.d.ts.map +0 -1
- package/dist/handlers/transactions.js +0 -98
- package/dist/handlers.d.ts +0 -27
- package/dist/handlers.d.ts.map +0 -1
- package/dist/handlers.js +0 -55
- package/dist/provider.d.ts +0 -105
- package/dist/provider.d.ts.map +0 -1
- package/dist/provider.js +0 -160
- package/dist/serializers/account.d.ts +0 -164
- package/dist/serializers/account.d.ts.map +0 -1
- package/dist/serializers/account.js +0 -244
- package/dist/serializers/contract.d.ts +0 -62
- package/dist/serializers/contract.d.ts.map +0 -1
- package/dist/serializers/contract.js +0 -130
- package/dist/serializers/index.d.ts +0 -21
- package/dist/serializers/index.d.ts.map +0 -1
- package/dist/serializers/index.js +0 -154
- package/dist/serializers/log.d.ts +0 -66
- package/dist/serializers/log.d.ts.map +0 -1
- package/dist/serializers/log.js +0 -222
- package/dist/serializers/note.d.ts +0 -124
- package/dist/serializers/note.d.ts.map +0 -1
- package/dist/serializers/note.js +0 -208
- package/dist/serializers/transaction.d.ts +0 -99
- package/dist/serializers/transaction.d.ts.map +0 -1
- package/dist/serializers/transaction.js +0 -275
- package/dist/wallet.d.ts +0 -62
- package/dist/wallet.d.ts.map +0 -1
- package/dist/wallet.js +0 -77
- package/docs/classes/AztecChainProvider.md +0 -553
- package/docs/classes/AztecChainWallet.md +0 -409
- package/docs/classes/AztecProvider.md +0 -1112
- package/docs/interfaces/AztecWalletBaseMethodMap.md +0 -135
- package/docs/interfaces/AztecWalletEventMap.md +0 -17
- package/docs/type-aliases/AztecChainWalletMiddleware.md +0 -13
- package/docs/type-aliases/AztecWalletContext.md +0 -29
- package/docs/type-aliases/AztecWalletMethodHandler.md +0 -37
- package/docs/type-aliases/AztecWalletMiddleware.md +0 -13
- package/docs/type-aliases/AztecWalletRouterClient.md +0 -13
- package/docs/type-aliases/TransactionFunctionCall.md +0 -33
- package/docs/type-aliases/TransactionParams.md +0 -27
- package/src/aztecRemoteWallet.test.ts +0 -504
- package/src/aztecRemoteWallet.ts +0 -467
- package/src/chainProvider.test.ts +0 -401
- package/src/chainProvider.ts +0 -116
- package/src/handlers/aztecAccountWallet.test.ts +0 -649
- package/src/handlers/aztecAccountWallet.ts +0 -532
- package/src/handlers/transactions.ts +0 -124
- package/src/handlers.test.ts +0 -270
- package/src/handlers.ts +0 -70
- package/src/provider.test.ts +0 -274
- package/src/provider.ts +0 -189
- package/src/serializers/account.test.ts +0 -125
- package/src/serializers/account.ts +0 -301
- package/src/serializers/contract.test.ts +0 -24
- package/src/serializers/contract.ts +0 -183
- package/src/serializers/index.test.ts +0 -136
- package/src/serializers/index.ts +0 -191
- package/src/serializers/log.test.ts +0 -286
- package/src/serializers/log.ts +0 -292
- package/src/serializers/note.test.ts +0 -125
- package/src/serializers/note.ts +0 -250
- package/src/serializers/transaction.test.ts +0 -320
- package/src/serializers/transaction.ts +0 -409
- package/src/wallet.test.ts +0 -275
- package/src/wallet.ts +0 -94
package/src/provider.ts
DELETED
@@ -1,189 +0,0 @@
|
|
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
|
-
}
|
@@ -1,125 +0,0 @@
|
|
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 { schemas } from '@aztec/foundation/schemas';
|
10
|
-
|
11
|
-
describe('Account Serializers', () => {
|
12
|
-
describe('aztec_setScopes', () => {
|
13
|
-
const METHOD = 'aztec_setScopes';
|
14
|
-
|
15
|
-
it('should serialize and deserialize params', async () => {
|
16
|
-
const scopes = [await AztecAddress.random(), await AztecAddress.random()];
|
17
|
-
const params = { scopes };
|
18
|
-
|
19
|
-
const serialized = await aztecSetScopesSerializer.params.serialize(METHOD, params);
|
20
|
-
expect(serialized.method).toBe(METHOD);
|
21
|
-
|
22
|
-
const deserialized = await aztecSetScopesSerializer.params.deserialize(METHOD, serialized);
|
23
|
-
expect(deserialized.scopes.map((s) => s.toString())).toEqual(scopes.map((s) => s.toString()));
|
24
|
-
});
|
25
|
-
|
26
|
-
it('should serialize and deserialize result', async () => {
|
27
|
-
const result = true;
|
28
|
-
|
29
|
-
const serialized = await aztecSetScopesSerializer.result.serialize(METHOD, result);
|
30
|
-
expect(serialized.method).toBe(METHOD);
|
31
|
-
|
32
|
-
const deserialized = await aztecSetScopesSerializer.result.deserialize(METHOD, serialized);
|
33
|
-
expect(deserialized).toBe(result);
|
34
|
-
});
|
35
|
-
});
|
36
|
-
|
37
|
-
describe('aztec_registerAccount', () => {
|
38
|
-
const METHOD = 'aztec_registerAccount';
|
39
|
-
|
40
|
-
it('should serialize and deserialize params', async () => {
|
41
|
-
const secretKey = await Fr.random();
|
42
|
-
const partialAddress = await Fr.random();
|
43
|
-
const params = { secretKey, partialAddress };
|
44
|
-
|
45
|
-
const serialized = await aztecRegisterAccountSerializer.params.serialize(METHOD, params);
|
46
|
-
expect(serialized.method).toBe(METHOD);
|
47
|
-
|
48
|
-
const deserialized = await aztecRegisterAccountSerializer.params.deserialize(METHOD, serialized);
|
49
|
-
expect(deserialized.secretKey.toString()).toBe(secretKey.toString());
|
50
|
-
expect(deserialized.partialAddress.toString()).toBe(partialAddress.toString());
|
51
|
-
});
|
52
|
-
|
53
|
-
it('should serialize and deserialize result', async () => {
|
54
|
-
const result = await CompleteAddress.random();
|
55
|
-
|
56
|
-
const serialized = await aztecRegisterAccountSerializer.result.serialize(METHOD, result);
|
57
|
-
expect(serialized.method).toBe(METHOD);
|
58
|
-
|
59
|
-
const deserialized = await aztecRegisterAccountSerializer.result.deserialize(METHOD, serialized);
|
60
|
-
expect(deserialized.toString()).toBe(result.toString());
|
61
|
-
});
|
62
|
-
});
|
63
|
-
|
64
|
-
describe('aztec_addAuthWitness', () => {
|
65
|
-
const METHOD = 'aztec_addAuthWitness';
|
66
|
-
|
67
|
-
it('should serialize and deserialize params', async () => {
|
68
|
-
const authWitness = await AuthWitness.random();
|
69
|
-
const params = { authWitness };
|
70
|
-
|
71
|
-
const serialized = await aztecAddAuthWitnessSerializer.params.serialize(METHOD, params);
|
72
|
-
expect(serialized.method).toBe(METHOD);
|
73
|
-
|
74
|
-
const deserialized = await aztecAddAuthWitnessSerializer.params.deserialize(METHOD, serialized);
|
75
|
-
expect(deserialized.authWitness.toString()).toBe(authWitness.toString());
|
76
|
-
});
|
77
|
-
|
78
|
-
it('should serialize and deserialize result', async () => {
|
79
|
-
const result = true;
|
80
|
-
|
81
|
-
const serialized = await aztecAddAuthWitnessSerializer.result.serialize(METHOD, result);
|
82
|
-
expect(serialized.method).toBe(METHOD);
|
83
|
-
|
84
|
-
const deserialized = await aztecAddAuthWitnessSerializer.result.deserialize(METHOD, serialized);
|
85
|
-
expect(deserialized).toBe(result);
|
86
|
-
});
|
87
|
-
});
|
88
|
-
|
89
|
-
describe('aztec_getAuthWitness', () => {
|
90
|
-
const METHOD = 'aztec_getAuthWitness';
|
91
|
-
|
92
|
-
it('should serialize and deserialize params', async () => {
|
93
|
-
const messageHash = await Fr.random();
|
94
|
-
const params = { messageHash };
|
95
|
-
|
96
|
-
const serialized = await aztecGetAuthWitnessSerializer.params.serialize(METHOD, params);
|
97
|
-
expect(serialized.method).toBe(METHOD);
|
98
|
-
|
99
|
-
const deserialized = await aztecGetAuthWitnessSerializer.params.deserialize(METHOD, serialized);
|
100
|
-
expect(deserialized.messageHash.toString()).toBe(messageHash.toString());
|
101
|
-
});
|
102
|
-
|
103
|
-
it('should serialize and deserialize result', async () => {
|
104
|
-
const result = [await Fr.random(), await Fr.random()];
|
105
|
-
|
106
|
-
const serialized = await aztecGetAuthWitnessSerializer.result.serialize(METHOD, result);
|
107
|
-
expect(serialized.method).toBe(METHOD);
|
108
|
-
|
109
|
-
const deserialized = await aztecGetAuthWitnessSerializer.result.deserialize(METHOD, serialized);
|
110
|
-
expect(deserialized.map((w) => w.toString())).toEqual(result.map((w) => w.toString()));
|
111
|
-
});
|
112
|
-
});
|
113
|
-
|
114
|
-
describe('Base64 encoding/decoding', () => {
|
115
|
-
it('should properly encode and decode data', async () => {
|
116
|
-
const messageHash = await Fr.random();
|
117
|
-
|
118
|
-
const serialized = await aztecGetAuthWitnessSerializer.params.serialize('aztec_getAuthWitness', {
|
119
|
-
messageHash,
|
120
|
-
});
|
121
|
-
const decoded = schemas.Fr.parse(JSON.parse(serialized.serialized));
|
122
|
-
expect(decoded.toString()).toBe(messageHash.toString());
|
123
|
-
});
|
124
|
-
});
|
125
|
-
});
|
@@ -1,301 +0,0 @@
|
|
1
|
-
import type { AztecWalletMethodMap } from '../types.js';
|
2
|
-
import type { JSONRPCSerializedData, JSONRPCSerializer } from '@walletmesh/jsonrpc';
|
3
|
-
import type { PartialAddress } from '@aztec/aztec.js';
|
4
|
-
import { CompleteAddress, AuthWitness, AztecAddress, Fr } from '@aztec/aztec.js';
|
5
|
-
|
6
|
-
/**
|
7
|
-
* Serializer for the aztec_setScopes RPC method.
|
8
|
-
* Handles serialization of account scope settings between JSON-RPC format and native Aztec types.
|
9
|
-
*/
|
10
|
-
export class AztecSetScopesSerializer
|
11
|
-
implements
|
12
|
-
JSONRPCSerializer<
|
13
|
-
AztecWalletMethodMap['aztec_setScopes']['params'],
|
14
|
-
AztecWalletMethodMap['aztec_setScopes']['result']
|
15
|
-
>
|
16
|
-
{
|
17
|
-
params = {
|
18
|
-
/**
|
19
|
-
* Serializes scope setting parameters for RPC transport.
|
20
|
-
* @param method - The RPC method name
|
21
|
-
* @param value - The parameters containing an array of Aztec addresses representing scopes
|
22
|
-
* @returns Serialized scope data
|
23
|
-
*/
|
24
|
-
serialize: async (
|
25
|
-
method: string,
|
26
|
-
value: AztecWalletMethodMap['aztec_setScopes']['params'],
|
27
|
-
): Promise<JSONRPCSerializedData> => {
|
28
|
-
const { scopes } = value;
|
29
|
-
return Promise.resolve({
|
30
|
-
method,
|
31
|
-
serialized: JSON.stringify({
|
32
|
-
scopes: scopes.map((s) => s.toString()),
|
33
|
-
}),
|
34
|
-
});
|
35
|
-
},
|
36
|
-
/**
|
37
|
-
* Deserializes scope setting parameters from RPC transport.
|
38
|
-
* @param _method - The RPC method name
|
39
|
-
* @param data - The serialized scope data
|
40
|
-
* @returns Deserialized scope parameters
|
41
|
-
*/
|
42
|
-
deserialize: async (
|
43
|
-
_method: string,
|
44
|
-
data: JSONRPCSerializedData,
|
45
|
-
): Promise<AztecWalletMethodMap['aztec_setScopes']['params']> => {
|
46
|
-
const { scopes } = JSON.parse(data.serialized);
|
47
|
-
return Promise.resolve({
|
48
|
-
scopes: scopes.map((s: string) => AztecAddress.fromString(s)),
|
49
|
-
});
|
50
|
-
},
|
51
|
-
};
|
52
|
-
|
53
|
-
result = {
|
54
|
-
/**
|
55
|
-
* Serializes the scope setting result.
|
56
|
-
* @param method - The RPC method name
|
57
|
-
* @param value - Boolean indicating success of the scope setting operation
|
58
|
-
* @returns Serialized result
|
59
|
-
*/
|
60
|
-
serialize: async (method: string, value: boolean): Promise<JSONRPCSerializedData> => {
|
61
|
-
return Promise.resolve({
|
62
|
-
method,
|
63
|
-
serialized: JSON.stringify(value),
|
64
|
-
});
|
65
|
-
},
|
66
|
-
/**
|
67
|
-
* Deserializes the scope setting result.
|
68
|
-
* @param _method - The RPC method name
|
69
|
-
* @param data - The serialized result data
|
70
|
-
* @returns Boolean indicating success
|
71
|
-
*/
|
72
|
-
deserialize: async (_method: string, data: JSONRPCSerializedData): Promise<boolean> => {
|
73
|
-
return Promise.resolve(JSON.parse(data.serialized));
|
74
|
-
},
|
75
|
-
};
|
76
|
-
}
|
77
|
-
|
78
|
-
/**
|
79
|
-
* Serializer for the aztec_registerAccount RPC method.
|
80
|
-
* Handles serialization of account registration data between JSON-RPC format and native Aztec types.
|
81
|
-
*/
|
82
|
-
export class AztecRegisterAccountSerializer
|
83
|
-
implements
|
84
|
-
JSONRPCSerializer<
|
85
|
-
AztecWalletMethodMap['aztec_registerAccount']['params'],
|
86
|
-
AztecWalletMethodMap['aztec_registerAccount']['result']
|
87
|
-
>
|
88
|
-
{
|
89
|
-
params = {
|
90
|
-
/**
|
91
|
-
* Serializes account registration parameters for RPC transport.
|
92
|
-
* @param method - The RPC method name
|
93
|
-
* @param value - The parameters containing secret key and partial address
|
94
|
-
* @returns Serialized registration data
|
95
|
-
*/
|
96
|
-
serialize: async (
|
97
|
-
method: string,
|
98
|
-
value: AztecWalletMethodMap['aztec_registerAccount']['params'],
|
99
|
-
): Promise<JSONRPCSerializedData> => {
|
100
|
-
const { secretKey, partialAddress } = value;
|
101
|
-
return Promise.resolve({
|
102
|
-
method,
|
103
|
-
serialized: JSON.stringify({
|
104
|
-
secretKey: secretKey.toString(),
|
105
|
-
partialAddress: partialAddress.toString(),
|
106
|
-
}),
|
107
|
-
});
|
108
|
-
},
|
109
|
-
/**
|
110
|
-
* Deserializes account registration parameters from RPC transport.
|
111
|
-
* @param _method - The RPC method name
|
112
|
-
* @param data - The serialized registration data
|
113
|
-
* @returns Deserialized registration parameters
|
114
|
-
*/
|
115
|
-
deserialize: async (
|
116
|
-
_method: string,
|
117
|
-
data: JSONRPCSerializedData,
|
118
|
-
): Promise<AztecWalletMethodMap['aztec_registerAccount']['params']> => {
|
119
|
-
const { secretKey, partialAddress } = JSON.parse(data.serialized);
|
120
|
-
return Promise.resolve({
|
121
|
-
secretKey: Fr.fromString(secretKey),
|
122
|
-
partialAddress: Fr.fromString(partialAddress) as PartialAddress,
|
123
|
-
});
|
124
|
-
},
|
125
|
-
};
|
126
|
-
|
127
|
-
result = {
|
128
|
-
/**
|
129
|
-
* Serializes the account registration result.
|
130
|
-
* @param method - The RPC method name
|
131
|
-
* @param value - The complete address of the registered account
|
132
|
-
* @returns Serialized complete address
|
133
|
-
*/
|
134
|
-
serialize: async (method: string, value: CompleteAddress): Promise<JSONRPCSerializedData> => {
|
135
|
-
return Promise.resolve({
|
136
|
-
method,
|
137
|
-
serialized: JSON.stringify(value.toString()),
|
138
|
-
});
|
139
|
-
},
|
140
|
-
/**
|
141
|
-
* Deserializes the account registration result.
|
142
|
-
* @param _method - The RPC method name
|
143
|
-
* @param data - The serialized complete address
|
144
|
-
* @returns Deserialized complete address
|
145
|
-
*/
|
146
|
-
deserialize: async (_method: string, data: JSONRPCSerializedData): Promise<CompleteAddress> => {
|
147
|
-
return Promise.resolve(CompleteAddress.fromString(JSON.parse(data.serialized)));
|
148
|
-
},
|
149
|
-
};
|
150
|
-
}
|
151
|
-
|
152
|
-
/**
|
153
|
-
* Serializer for the aztec_addAuthWitness RPC method.
|
154
|
-
* Handles serialization of authentication witness data between JSON-RPC format and native Aztec types.
|
155
|
-
*/
|
156
|
-
export class AztecAddAuthWitnessSerializer
|
157
|
-
implements
|
158
|
-
JSONRPCSerializer<
|
159
|
-
AztecWalletMethodMap['aztec_addAuthWitness']['params'],
|
160
|
-
AztecWalletMethodMap['aztec_addAuthWitness']['result']
|
161
|
-
>
|
162
|
-
{
|
163
|
-
params = {
|
164
|
-
/**
|
165
|
-
* Serializes auth witness addition parameters for RPC transport.
|
166
|
-
* @param method - The RPC method name
|
167
|
-
* @param value - The parameters containing the auth witness to add
|
168
|
-
* @returns Serialized auth witness data
|
169
|
-
*/
|
170
|
-
serialize: async (
|
171
|
-
method: string,
|
172
|
-
value: AztecWalletMethodMap['aztec_addAuthWitness']['params'],
|
173
|
-
): Promise<JSONRPCSerializedData> => {
|
174
|
-
const { authWitness } = value;
|
175
|
-
return Promise.resolve({
|
176
|
-
method,
|
177
|
-
serialized: JSON.stringify(authWitness.toString()),
|
178
|
-
});
|
179
|
-
},
|
180
|
-
/**
|
181
|
-
* Deserializes auth witness addition parameters from RPC transport.
|
182
|
-
* @param _method - The RPC method name
|
183
|
-
* @param data - The serialized auth witness data
|
184
|
-
* @returns Deserialized auth witness parameters
|
185
|
-
*/
|
186
|
-
deserialize: async (
|
187
|
-
_method: string,
|
188
|
-
data: JSONRPCSerializedData,
|
189
|
-
): Promise<AztecWalletMethodMap['aztec_addAuthWitness']['params']> => {
|
190
|
-
const authWitness = AuthWitness.fromString(JSON.parse(data.serialized));
|
191
|
-
return Promise.resolve({ authWitness });
|
192
|
-
},
|
193
|
-
};
|
194
|
-
|
195
|
-
result = {
|
196
|
-
/**
|
197
|
-
* Serializes the auth witness addition result.
|
198
|
-
* @param method - The RPC method name
|
199
|
-
* @param value - Boolean indicating success of the witness addition
|
200
|
-
* @returns Serialized result
|
201
|
-
*/
|
202
|
-
serialize: async (method: string, value: boolean): Promise<JSONRPCSerializedData> => {
|
203
|
-
return Promise.resolve({
|
204
|
-
method,
|
205
|
-
serialized: JSON.stringify(value),
|
206
|
-
});
|
207
|
-
},
|
208
|
-
/**
|
209
|
-
* Deserializes the auth witness addition result.
|
210
|
-
* @param _method - The RPC method name
|
211
|
-
* @param data - The serialized result data
|
212
|
-
* @returns Boolean indicating success
|
213
|
-
*/
|
214
|
-
deserialize: async (_method: string, data: JSONRPCSerializedData): Promise<boolean> => {
|
215
|
-
return Promise.resolve(JSON.parse(data.serialized));
|
216
|
-
},
|
217
|
-
};
|
218
|
-
}
|
219
|
-
|
220
|
-
/**
|
221
|
-
* Serializer for the aztec_getAuthWitness RPC method.
|
222
|
-
* Handles serialization of authentication witness retrieval between JSON-RPC format and native Aztec types.
|
223
|
-
*/
|
224
|
-
export class AztecGetAuthWitnessSerializer
|
225
|
-
implements
|
226
|
-
JSONRPCSerializer<
|
227
|
-
AztecWalletMethodMap['aztec_getAuthWitness']['params'],
|
228
|
-
AztecWalletMethodMap['aztec_getAuthWitness']['result']
|
229
|
-
>
|
230
|
-
{
|
231
|
-
params = {
|
232
|
-
/**
|
233
|
-
* Serializes auth witness retrieval parameters for RPC transport.
|
234
|
-
* @param method - The RPC method name
|
235
|
-
* @param value - The parameters containing the message hash to look up
|
236
|
-
* @returns Serialized message hash data
|
237
|
-
*/
|
238
|
-
serialize: async (
|
239
|
-
method: string,
|
240
|
-
value: AztecWalletMethodMap['aztec_getAuthWitness']['params'],
|
241
|
-
): Promise<JSONRPCSerializedData> => {
|
242
|
-
const { messageHash } = value;
|
243
|
-
return Promise.resolve({
|
244
|
-
method,
|
245
|
-
serialized: JSON.stringify(messageHash.toString()),
|
246
|
-
});
|
247
|
-
},
|
248
|
-
/**
|
249
|
-
* Deserializes auth witness retrieval parameters from RPC transport.
|
250
|
-
* @param _method - The RPC method name
|
251
|
-
* @param data - The serialized message hash data
|
252
|
-
* @returns Deserialized message hash parameters
|
253
|
-
*/
|
254
|
-
deserialize: async (
|
255
|
-
_method: string,
|
256
|
-
data: JSONRPCSerializedData,
|
257
|
-
): Promise<AztecWalletMethodMap['aztec_getAuthWitness']['params']> => {
|
258
|
-
const messageHash = Fr.fromString(JSON.parse(data.serialized));
|
259
|
-
return Promise.resolve({ messageHash });
|
260
|
-
},
|
261
|
-
};
|
262
|
-
|
263
|
-
result = {
|
264
|
-
/**
|
265
|
-
* Serializes the auth witness retrieval result.
|
266
|
-
* @param method - The RPC method name
|
267
|
-
* @param value - Array of field elements representing auth witnesses
|
268
|
-
* @returns Serialized witness array
|
269
|
-
*/
|
270
|
-
serialize: async (
|
271
|
-
method: string,
|
272
|
-
value: AztecWalletMethodMap['aztec_getAuthWitness']['result'],
|
273
|
-
): Promise<JSONRPCSerializedData> => {
|
274
|
-
return Promise.resolve({
|
275
|
-
method,
|
276
|
-
serialized: JSON.stringify(value.map((w) => w.toString())),
|
277
|
-
});
|
278
|
-
},
|
279
|
-
/**
|
280
|
-
* Deserializes the auth witness retrieval result.
|
281
|
-
* @param _method - The RPC method name
|
282
|
-
* @param data - The serialized witness array data
|
283
|
-
* @returns Array of deserialized field elements
|
284
|
-
*/
|
285
|
-
deserialize: async (
|
286
|
-
_method: string,
|
287
|
-
data: JSONRPCSerializedData,
|
288
|
-
): Promise<AztecWalletMethodMap['aztec_getAuthWitness']['result']> => {
|
289
|
-
return Promise.resolve(JSON.parse(data.serialized).map((w: string) => Fr.fromString(w)));
|
290
|
-
},
|
291
|
-
};
|
292
|
-
}
|
293
|
-
|
294
|
-
/**
|
295
|
-
* Pre-instantiated serializer instances for Aztec account-related RPC methods.
|
296
|
-
* These instances can be used directly by the RPC handler implementation.
|
297
|
-
*/
|
298
|
-
export const aztecSetScopesSerializer = new AztecSetScopesSerializer();
|
299
|
-
export const aztecRegisterAccountSerializer = new AztecRegisterAccountSerializer();
|
300
|
-
export const aztecAddAuthWitnessSerializer = new AztecAddAuthWitnessSerializer();
|
301
|
-
export const aztecGetAuthWitnessSerializer = new AztecGetAuthWitnessSerializer();
|
@@ -1,24 +0,0 @@
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
2
|
-
import { aztecRegisterContractSerializer } from './contract.js';
|
3
|
-
import { randomDeployedContract } from '@aztec/circuit-types';
|
4
|
-
describe('Contract Serializers', () => {
|
5
|
-
describe('aztec_registerContract', () => {
|
6
|
-
it('should serialize and deserialize params', async () => {
|
7
|
-
const { instance, artifact } = await randomDeployedContract();
|
8
|
-
const serialized = await aztecRegisterContractSerializer.params.serialize('aztec_registerContract', {
|
9
|
-
instance,
|
10
|
-
artifact,
|
11
|
-
});
|
12
|
-
expect(serialized.method).toBe('aztec_registerContract');
|
13
|
-
|
14
|
-
const deserialized = await aztecRegisterContractSerializer.params.deserialize(
|
15
|
-
'aztec_registerContract',
|
16
|
-
serialized,
|
17
|
-
);
|
18
|
-
expect(deserialized.instance.address.toString()).toBe(instance.address.toString());
|
19
|
-
expect(deserialized.instance.contractClassId.toString()).toBe(instance.contractClassId.toString());
|
20
|
-
expect(deserialized.instance.deployer.toString()).toBe(instance.deployer.toString());
|
21
|
-
expect(deserialized.artifact).toEqual(artifact);
|
22
|
-
});
|
23
|
-
});
|
24
|
-
});
|