@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
@@ -1,409 +0,0 @@
|
|
1
|
-
import type { AztecWalletMethodMap } from '../types.js';
|
2
|
-
import type { JSONRPCSerializedData, JSONRPCSerializer } from '@walletmesh/jsonrpc';
|
3
|
-
import {
|
4
|
-
FunctionCall,
|
5
|
-
PrivateExecutionResult,
|
6
|
-
TxEffect,
|
7
|
-
TxSimulationResult,
|
8
|
-
inBlockSchemaFor,
|
9
|
-
TxHash,
|
10
|
-
TxProvingResult,
|
11
|
-
} from '@aztec/circuit-types';
|
12
|
-
import { GasSettings } from '@aztec/circuits.js';
|
13
|
-
import {
|
14
|
-
AuthWitness,
|
15
|
-
AztecAddress,
|
16
|
-
Fr,
|
17
|
-
FunctionSelector,
|
18
|
-
HashedValues,
|
19
|
-
NoFeePaymentMethod,
|
20
|
-
TxExecutionRequest,
|
21
|
-
TxReceipt,
|
22
|
-
Tx,
|
23
|
-
} from '@aztec/aztec.js';
|
24
|
-
import { AbiTypeSchema, type FunctionType } from '@aztec/foundation/abi';
|
25
|
-
|
26
|
-
import { jsonParseWithSchema, jsonStringify } from '@aztec/foundation/json-rpc';
|
27
|
-
import type { ExecutionRequestInit, FeeOptions } from '@aztec/aztec.js/entrypoint';
|
28
|
-
|
29
|
-
interface SerializedFunctionCall {
|
30
|
-
name: string;
|
31
|
-
to: string;
|
32
|
-
selector: string;
|
33
|
-
type: string;
|
34
|
-
isStatic: boolean;
|
35
|
-
args: string[];
|
36
|
-
returnTypes: string[];
|
37
|
-
}
|
38
|
-
|
39
|
-
/**
|
40
|
-
* Serializer for the aztec_createTxExecutionRequest RPC method.
|
41
|
-
* Handles serialization of transaction execution requests between JSON-RPC format and native Aztec types.
|
42
|
-
*/
|
43
|
-
export class AztecCreateTxExecutionRequestSerializer
|
44
|
-
implements
|
45
|
-
JSONRPCSerializer<
|
46
|
-
AztecWalletMethodMap['aztec_createTxExecutionRequest']['params'],
|
47
|
-
AztecWalletMethodMap['aztec_createTxExecutionRequest']['result']
|
48
|
-
>
|
49
|
-
{
|
50
|
-
params = {
|
51
|
-
serialize: async (
|
52
|
-
method: string,
|
53
|
-
value: AztecWalletMethodMap['aztec_createTxExecutionRequest']['params'],
|
54
|
-
): Promise<JSONRPCSerializedData> => {
|
55
|
-
const { exec } = value;
|
56
|
-
|
57
|
-
const calls = exec.calls.map((call: FunctionCall) => {
|
58
|
-
return {
|
59
|
-
name: call.name,
|
60
|
-
to: jsonStringify(call.to),
|
61
|
-
selector: jsonStringify(call.selector),
|
62
|
-
type: call.type,
|
63
|
-
isStatic: call.isStatic,
|
64
|
-
args: call.args.map((arg) => jsonStringify(arg)),
|
65
|
-
returnTypes: call.returnTypes.map((r) => jsonStringify(r)),
|
66
|
-
};
|
67
|
-
});
|
68
|
-
const authWitnesses = exec.authWitnesses ? exec.authWitnesses.map((w) => jsonStringify(w)) : undefined;
|
69
|
-
const hashedArguments = exec.hashedArguments
|
70
|
-
? exec.hashedArguments.map((h) => jsonStringify(h))
|
71
|
-
: undefined;
|
72
|
-
const fee = { gasSettings: jsonStringify(exec.fee.gasSettings) };
|
73
|
-
const nonce = exec.nonce ? jsonStringify(exec.nonce) : undefined;
|
74
|
-
|
75
|
-
return {
|
76
|
-
method,
|
77
|
-
serialized: JSON.stringify({
|
78
|
-
calls,
|
79
|
-
fee,
|
80
|
-
authWitnesses,
|
81
|
-
hashedArguments,
|
82
|
-
nonce,
|
83
|
-
cancellable: exec.cancellable,
|
84
|
-
}),
|
85
|
-
};
|
86
|
-
},
|
87
|
-
deserialize: async (
|
88
|
-
_method: string,
|
89
|
-
data: JSONRPCSerializedData,
|
90
|
-
): Promise<AztecWalletMethodMap['aztec_createTxExecutionRequest']['params']> => {
|
91
|
-
const parsed = JSON.parse(data.serialized);
|
92
|
-
|
93
|
-
const calls: FunctionCall[] = await Promise.all(
|
94
|
-
parsed.calls.map(async (call: SerializedFunctionCall) => {
|
95
|
-
return new FunctionCall(
|
96
|
-
call.name,
|
97
|
-
await jsonParseWithSchema(call.to, AztecAddress.schema),
|
98
|
-
await jsonParseWithSchema(call.selector, FunctionSelector.schema),
|
99
|
-
call.type as FunctionType,
|
100
|
-
call.isStatic,
|
101
|
-
await Promise.all(call.args.map(async (arg: string) => jsonParseWithSchema(arg, Fr.schema))),
|
102
|
-
await Promise.all(
|
103
|
-
call.returnTypes.map(async (t: string) => jsonParseWithSchema(t, AbiTypeSchema)),
|
104
|
-
),
|
105
|
-
);
|
106
|
-
}),
|
107
|
-
);
|
108
|
-
const authWitnesses = parsed.authWitnesses
|
109
|
-
? parsed.authWitnesses.map(async (w: string) => await jsonParseWithSchema(w, AuthWitness.schema))
|
110
|
-
: undefined;
|
111
|
-
const hashedArguments = parsed.hashedArguments
|
112
|
-
? parsed.hashedArguments.map(async (h: string) => await jsonParseWithSchema(h, HashedValues.schema))
|
113
|
-
: undefined;
|
114
|
-
const cancellable = parsed.cancellable;
|
115
|
-
const nonce = parsed.nonce ? await jsonParseWithSchema(parsed.nonce, Fr.schema) : undefined;
|
116
|
-
|
117
|
-
const fee: FeeOptions = {
|
118
|
-
paymentMethod: new NoFeePaymentMethod(), // Default, caller should override
|
119
|
-
gasSettings: await jsonParseWithSchema(parsed.fee.gasSettings, GasSettings.schema),
|
120
|
-
};
|
121
|
-
|
122
|
-
const exec: ExecutionRequestInit = { calls, fee };
|
123
|
-
if (authWitnesses) exec.authWitnesses = authWitnesses;
|
124
|
-
if (hashedArguments) exec.hashedArguments = hashedArguments;
|
125
|
-
if (nonce) exec.nonce = nonce;
|
126
|
-
if (cancellable) exec.cancellable = cancellable;
|
127
|
-
|
128
|
-
return { exec };
|
129
|
-
},
|
130
|
-
};
|
131
|
-
|
132
|
-
result = {
|
133
|
-
serialize: async (method: string, value: TxExecutionRequest): Promise<JSONRPCSerializedData> => {
|
134
|
-
return {
|
135
|
-
method,
|
136
|
-
serialized: jsonStringify(value),
|
137
|
-
};
|
138
|
-
},
|
139
|
-
deserialize: async (_method: string, data: JSONRPCSerializedData): Promise<TxExecutionRequest> => {
|
140
|
-
return await jsonParseWithSchema(data.serialized, TxExecutionRequest.schema);
|
141
|
-
},
|
142
|
-
};
|
143
|
-
}
|
144
|
-
|
145
|
-
/**
|
146
|
-
* Serializer for the aztec_proveTx RPC method.
|
147
|
-
* Handles serialization of transaction proving requests and results between JSON-RPC format and native Aztec types.
|
148
|
-
*/
|
149
|
-
export class AztecProveTxSerializer
|
150
|
-
implements
|
151
|
-
JSONRPCSerializer<
|
152
|
-
AztecWalletMethodMap['aztec_proveTx']['params'],
|
153
|
-
AztecWalletMethodMap['aztec_proveTx']['result']
|
154
|
-
>
|
155
|
-
{
|
156
|
-
params = {
|
157
|
-
serialize: async (
|
158
|
-
method: string,
|
159
|
-
value: AztecWalletMethodMap['aztec_proveTx']['params'],
|
160
|
-
): Promise<JSONRPCSerializedData> => {
|
161
|
-
const { txRequest, privateExecutionResult } = value;
|
162
|
-
return {
|
163
|
-
method,
|
164
|
-
serialized: JSON.stringify({
|
165
|
-
txRequest: jsonStringify(txRequest),
|
166
|
-
privateExecutionResult: jsonStringify(privateExecutionResult),
|
167
|
-
}),
|
168
|
-
};
|
169
|
-
},
|
170
|
-
deserialize: async (
|
171
|
-
_method: string,
|
172
|
-
data: JSONRPCSerializedData,
|
173
|
-
): Promise<AztecWalletMethodMap['aztec_proveTx']['params']> => {
|
174
|
-
const { txRequest, privateExecutionResult } = JSON.parse(data.serialized);
|
175
|
-
return {
|
176
|
-
txRequest: await jsonParseWithSchema(txRequest, TxExecutionRequest.schema),
|
177
|
-
privateExecutionResult: await jsonParseWithSchema(
|
178
|
-
privateExecutionResult,
|
179
|
-
PrivateExecutionResult.schema,
|
180
|
-
),
|
181
|
-
};
|
182
|
-
},
|
183
|
-
};
|
184
|
-
|
185
|
-
result = {
|
186
|
-
serialize: async (method: string, value: TxProvingResult): Promise<JSONRPCSerializedData> => {
|
187
|
-
return {
|
188
|
-
method,
|
189
|
-
serialized: jsonStringify(value),
|
190
|
-
};
|
191
|
-
},
|
192
|
-
deserialize: async (_method: string, data: JSONRPCSerializedData): Promise<TxProvingResult> => {
|
193
|
-
return await jsonParseWithSchema(data.serialized, TxProvingResult.schema);
|
194
|
-
},
|
195
|
-
};
|
196
|
-
}
|
197
|
-
|
198
|
-
/**
|
199
|
-
* Serializer for the aztec_sendTx RPC method.
|
200
|
-
* Handles serialization of transaction sending requests and transaction hash results between JSON-RPC format and native Aztec types.
|
201
|
-
*/
|
202
|
-
export class AztecSendTxSerializer
|
203
|
-
implements
|
204
|
-
JSONRPCSerializer<
|
205
|
-
AztecWalletMethodMap['aztec_sendTx']['params'],
|
206
|
-
AztecWalletMethodMap['aztec_sendTx']['result']
|
207
|
-
>
|
208
|
-
{
|
209
|
-
params = {
|
210
|
-
serialize: async (
|
211
|
-
method: string,
|
212
|
-
value: AztecWalletMethodMap['aztec_sendTx']['params'],
|
213
|
-
): Promise<JSONRPCSerializedData> => {
|
214
|
-
const { tx } = value;
|
215
|
-
return {
|
216
|
-
method,
|
217
|
-
serialized: jsonStringify(tx),
|
218
|
-
};
|
219
|
-
},
|
220
|
-
deserialize: async (
|
221
|
-
_method: string,
|
222
|
-
data: JSONRPCSerializedData,
|
223
|
-
): Promise<AztecWalletMethodMap['aztec_sendTx']['params']> => {
|
224
|
-
return { tx: await jsonParseWithSchema(data.serialized, Tx.schema) };
|
225
|
-
},
|
226
|
-
};
|
227
|
-
|
228
|
-
result = {
|
229
|
-
serialize: async (
|
230
|
-
method: string,
|
231
|
-
value: AztecWalletMethodMap['aztec_sendTx']['result'],
|
232
|
-
): Promise<JSONRPCSerializedData> => {
|
233
|
-
return {
|
234
|
-
method,
|
235
|
-
serialized: jsonStringify(value),
|
236
|
-
};
|
237
|
-
},
|
238
|
-
deserialize: async (
|
239
|
-
_method: string,
|
240
|
-
data: JSONRPCSerializedData,
|
241
|
-
): Promise<AztecWalletMethodMap['aztec_sendTx']['result']> => {
|
242
|
-
return await jsonParseWithSchema(data.serialized, TxHash.schema);
|
243
|
-
},
|
244
|
-
};
|
245
|
-
}
|
246
|
-
|
247
|
-
/**
|
248
|
-
* Serializer for the aztec_getTxEffect RPC method.
|
249
|
-
* Handles serialization of transaction effect queries and results between JSON-RPC format and native Aztec types.
|
250
|
-
*/
|
251
|
-
export class AztecGetTxEffectSerializer
|
252
|
-
implements
|
253
|
-
JSONRPCSerializer<
|
254
|
-
AztecWalletMethodMap['aztec_getTxEffect']['params'],
|
255
|
-
AztecWalletMethodMap['aztec_getTxEffect']['result']
|
256
|
-
>
|
257
|
-
{
|
258
|
-
params = {
|
259
|
-
serialize: async (
|
260
|
-
method: string,
|
261
|
-
value: AztecWalletMethodMap['aztec_getTxEffect']['params'],
|
262
|
-
): Promise<JSONRPCSerializedData> => {
|
263
|
-
const { txHash } = value;
|
264
|
-
return {
|
265
|
-
method,
|
266
|
-
serialized: jsonStringify(txHash),
|
267
|
-
};
|
268
|
-
},
|
269
|
-
deserialize: async (
|
270
|
-
_method: string,
|
271
|
-
data: JSONRPCSerializedData,
|
272
|
-
): Promise<AztecWalletMethodMap['aztec_getTxEffect']['params']> => {
|
273
|
-
const txHash = await jsonParseWithSchema(data.serialized, TxHash.schema);
|
274
|
-
return { txHash };
|
275
|
-
},
|
276
|
-
};
|
277
|
-
|
278
|
-
result = {
|
279
|
-
serialize: async (
|
280
|
-
method: string,
|
281
|
-
value: AztecWalletMethodMap['aztec_getTxEffect']['result'],
|
282
|
-
): Promise<JSONRPCSerializedData> => {
|
283
|
-
return {
|
284
|
-
method,
|
285
|
-
serialized: jsonStringify(value),
|
286
|
-
};
|
287
|
-
},
|
288
|
-
deserialize: async (
|
289
|
-
_method: string,
|
290
|
-
data: JSONRPCSerializedData,
|
291
|
-
): Promise<AztecWalletMethodMap['aztec_getTxEffect']['result']> => {
|
292
|
-
return await jsonParseWithSchema(data.serialized, inBlockSchemaFor(TxEffect.schema));
|
293
|
-
},
|
294
|
-
};
|
295
|
-
}
|
296
|
-
|
297
|
-
/**
|
298
|
-
* Serializer for the aztec_getTxReceipt RPC method.
|
299
|
-
* Handles serialization of transaction receipt queries and results between JSON-RPC format and native Aztec types.
|
300
|
-
*/
|
301
|
-
export class AztecGetTxReceiptSerializer
|
302
|
-
implements
|
303
|
-
JSONRPCSerializer<
|
304
|
-
AztecWalletMethodMap['aztec_getTxReceipt']['params'],
|
305
|
-
AztecWalletMethodMap['aztec_getTxReceipt']['result']
|
306
|
-
>
|
307
|
-
{
|
308
|
-
params = {
|
309
|
-
serialize: async (
|
310
|
-
method: string,
|
311
|
-
value: AztecWalletMethodMap['aztec_getTxReceipt']['params'],
|
312
|
-
): Promise<JSONRPCSerializedData> => {
|
313
|
-
const { txHash } = value;
|
314
|
-
return {
|
315
|
-
method,
|
316
|
-
serialized: jsonStringify(txHash),
|
317
|
-
};
|
318
|
-
},
|
319
|
-
deserialize: async (
|
320
|
-
_method: string,
|
321
|
-
data: JSONRPCSerializedData,
|
322
|
-
): Promise<AztecWalletMethodMap['aztec_getTxReceipt']['params']> => {
|
323
|
-
const txHash = await jsonParseWithSchema(data.serialized, TxHash.schema);
|
324
|
-
return { txHash };
|
325
|
-
},
|
326
|
-
};
|
327
|
-
|
328
|
-
result = {
|
329
|
-
serialize: async (method: string, value: TxReceipt): Promise<JSONRPCSerializedData> => {
|
330
|
-
return {
|
331
|
-
method,
|
332
|
-
serialized: jsonStringify(value),
|
333
|
-
};
|
334
|
-
},
|
335
|
-
deserialize: async (_method: string, data: JSONRPCSerializedData): Promise<TxReceipt> => {
|
336
|
-
return await jsonParseWithSchema(data.serialized, TxReceipt.schema);
|
337
|
-
},
|
338
|
-
};
|
339
|
-
}
|
340
|
-
|
341
|
-
/**
|
342
|
-
* Serializer for the aztec_simulateTx RPC method.
|
343
|
-
* Handles serialization of transaction simulation requests and results between JSON-RPC format and native Aztec types.
|
344
|
-
*/
|
345
|
-
export class AztecSimulateTxSerializer
|
346
|
-
implements
|
347
|
-
JSONRPCSerializer<
|
348
|
-
AztecWalletMethodMap['aztec_simulateTx']['params'],
|
349
|
-
AztecWalletMethodMap['aztec_simulateTx']['result']
|
350
|
-
>
|
351
|
-
{
|
352
|
-
params = {
|
353
|
-
serialize: async (
|
354
|
-
method: string,
|
355
|
-
value: AztecWalletMethodMap['aztec_simulateTx']['params'],
|
356
|
-
): Promise<JSONRPCSerializedData> => {
|
357
|
-
const { txRequest, simulatePublic, msgSender, skipTxValidation, enforceFeePayment, profile } = value;
|
358
|
-
return {
|
359
|
-
method,
|
360
|
-
serialized: JSON.stringify({
|
361
|
-
txRequest: jsonStringify(txRequest),
|
362
|
-
simulatePublic,
|
363
|
-
msgSender: JSON.stringify(msgSender),
|
364
|
-
skipTxValidation,
|
365
|
-
enforceFeePayment,
|
366
|
-
profile,
|
367
|
-
}),
|
368
|
-
};
|
369
|
-
},
|
370
|
-
deserialize: async (
|
371
|
-
_method: string,
|
372
|
-
data: JSONRPCSerializedData,
|
373
|
-
): Promise<AztecWalletMethodMap['aztec_simulateTx']['params']> => {
|
374
|
-
const { txRequest, simulatePublic, msgSender, skipTxValidation, enforceFeePayment, profile } =
|
375
|
-
JSON.parse(data.serialized);
|
376
|
-
return {
|
377
|
-
txRequest: await jsonParseWithSchema(txRequest, TxExecutionRequest.schema),
|
378
|
-
simulatePublic,
|
379
|
-
msgSender: await jsonParseWithSchema(msgSender, AztecAddress.schema),
|
380
|
-
skipTxValidation,
|
381
|
-
enforceFeePayment,
|
382
|
-
profile,
|
383
|
-
};
|
384
|
-
},
|
385
|
-
};
|
386
|
-
|
387
|
-
result = {
|
388
|
-
serialize: async (method: string, value: TxSimulationResult): Promise<JSONRPCSerializedData> => {
|
389
|
-
return {
|
390
|
-
method,
|
391
|
-
serialized: jsonStringify(value),
|
392
|
-
};
|
393
|
-
},
|
394
|
-
deserialize: async (_method: string, data: JSONRPCSerializedData): Promise<TxSimulationResult> => {
|
395
|
-
return await jsonParseWithSchema(data.serialized, TxSimulationResult.schema);
|
396
|
-
},
|
397
|
-
};
|
398
|
-
}
|
399
|
-
|
400
|
-
/**
|
401
|
-
* Pre-instantiated serializer instances for each Aztec transaction-related RPC method.
|
402
|
-
* These instances can be used directly by the RPC handler implementation.
|
403
|
-
*/
|
404
|
-
export const aztecCreateTxExecutionRequestSerializer = new AztecCreateTxExecutionRequestSerializer();
|
405
|
-
export const aztecProveTxSerializer = new AztecProveTxSerializer();
|
406
|
-
export const aztecSendTxSerializer = new AztecSendTxSerializer();
|
407
|
-
export const aztecGetTxEffectSerializer = new AztecGetTxEffectSerializer();
|
408
|
-
export const aztecGetTxReceiptSerializer = new AztecGetTxReceiptSerializer();
|
409
|
-
export const aztecSimulateTxSerializer = new AztecSimulateTxSerializer();
|
package/src/wallet.test.ts
DELETED
@@ -1,275 +0,0 @@
|
|
1
|
-
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
2
|
-
import type { AccountWallet, PXE } from '@aztec/aztec.js';
|
3
|
-
import { JSONRPCWalletClient } from '@walletmesh/router';
|
4
|
-
import { AztecChainWallet } from './wallet.js';
|
5
|
-
import { ContractArtifactCache } from './contractArtifactCache.js';
|
6
|
-
import { AztecWalletError } from './errors.js';
|
7
|
-
import type { JSONRPCTransport } from '@walletmesh/jsonrpc';
|
8
|
-
import type { AztecWalletContext } from './types.js';
|
9
|
-
|
10
|
-
describe('AztecChainWallet', () => {
|
11
|
-
let pxe: PXE;
|
12
|
-
let wallet: AccountWallet;
|
13
|
-
let transport: JSONRPCTransport;
|
14
|
-
let aztecWallet: AztecChainWallet;
|
15
|
-
|
16
|
-
beforeEach(() => {
|
17
|
-
// Mock PXE
|
18
|
-
pxe = {
|
19
|
-
// Add required PXE methods as needed
|
20
|
-
} as unknown as PXE;
|
21
|
-
|
22
|
-
// Mock AccountWallet
|
23
|
-
wallet = {
|
24
|
-
getAddress: vi.fn().mockResolvedValue('mockAddress'),
|
25
|
-
} as unknown as AccountWallet;
|
26
|
-
|
27
|
-
// Mock Transport
|
28
|
-
transport = {
|
29
|
-
send: vi.fn().mockResolvedValue(undefined),
|
30
|
-
on: vi.fn(),
|
31
|
-
off: vi.fn(),
|
32
|
-
emit: vi.fn(),
|
33
|
-
} as unknown as JSONRPCTransport;
|
34
|
-
|
35
|
-
// Create wallet instance
|
36
|
-
aztecWallet = new AztecChainWallet(pxe, wallet, transport);
|
37
|
-
|
38
|
-
// Setup fallback handler and serializer
|
39
|
-
const mockHandler = vi.fn().mockImplementation(async (context, method, _params) => {
|
40
|
-
if (!isAztecWalletContext(context)) {
|
41
|
-
throw new AztecWalletError('unknownInternalError', 'Invalid context');
|
42
|
-
}
|
43
|
-
if (method === 'aztec_getAccount') {
|
44
|
-
return await context.wallet.getAddress();
|
45
|
-
}
|
46
|
-
throw new AztecWalletError('invalidRequest', `Method not supported: ${method}`);
|
47
|
-
});
|
48
|
-
|
49
|
-
const mockSerializer = {
|
50
|
-
serialize: vi.fn().mockImplementation((value) => value),
|
51
|
-
deserialize: vi.fn().mockImplementation((value) => value),
|
52
|
-
};
|
53
|
-
|
54
|
-
Object.defineProperties(aztecWallet, {
|
55
|
-
fallbackHandler: {
|
56
|
-
value: mockHandler,
|
57
|
-
writable: true,
|
58
|
-
configurable: true,
|
59
|
-
},
|
60
|
-
fallbackSerializer: {
|
61
|
-
value: mockSerializer,
|
62
|
-
writable: true,
|
63
|
-
configurable: true,
|
64
|
-
},
|
65
|
-
});
|
66
|
-
});
|
67
|
-
|
68
|
-
describe('constructor', () => {
|
69
|
-
it('initializes with valid context', () => {
|
70
|
-
expect(aztecWallet).toBeInstanceOf(AztecChainWallet);
|
71
|
-
const context = (aztecWallet as unknown as { context: AztecWalletContext }).context;
|
72
|
-
expect(context.pxe).toBe(pxe);
|
73
|
-
expect(context.wallet).toBe(wallet);
|
74
|
-
expect(context.contractArtifactCache).toBeInstanceOf(ContractArtifactCache);
|
75
|
-
});
|
76
|
-
|
77
|
-
it('sets up fallback handler and serializer', () => {
|
78
|
-
const instance = aztecWallet as unknown as {
|
79
|
-
fallbackHandler: unknown;
|
80
|
-
fallbackSerializer: unknown;
|
81
|
-
};
|
82
|
-
expect(instance.fallbackHandler).toBeDefined();
|
83
|
-
expect(instance.fallbackSerializer).toBeDefined();
|
84
|
-
});
|
85
|
-
|
86
|
-
it('throws error when handler receives invalid context', async () => {
|
87
|
-
// Create a mock transport that simulates an error response
|
88
|
-
const mockSend = vi
|
89
|
-
.fn()
|
90
|
-
.mockRejectedValue(new AztecWalletError('unknownInternalError', 'Invalid context'));
|
91
|
-
|
92
|
-
const invalidTransport = {
|
93
|
-
send: mockSend,
|
94
|
-
on: vi.fn(),
|
95
|
-
off: vi.fn(),
|
96
|
-
emit: vi.fn(),
|
97
|
-
} as unknown as JSONRPCTransport;
|
98
|
-
|
99
|
-
// Create wallet with invalid context
|
100
|
-
new AztecChainWallet(null as unknown as PXE, null as unknown as AccountWallet, invalidTransport);
|
101
|
-
|
102
|
-
// Attempt to send a request
|
103
|
-
const request = {
|
104
|
-
jsonrpc: '2.0',
|
105
|
-
id: 1,
|
106
|
-
method: 'test_method',
|
107
|
-
params: [],
|
108
|
-
};
|
109
|
-
|
110
|
-
// Verify the error is thrown
|
111
|
-
await expect(mockSend(request)).rejects.toThrow(AztecWalletError);
|
112
|
-
expect(mockSend).toHaveBeenCalledWith(request);
|
113
|
-
});
|
114
|
-
});
|
115
|
-
|
116
|
-
describe('isAztecWalletContext', () => {
|
117
|
-
it('returns true for valid context', () => {
|
118
|
-
const validContext = {
|
119
|
-
pxe,
|
120
|
-
wallet,
|
121
|
-
contractArtifactCache: new ContractArtifactCache(wallet),
|
122
|
-
};
|
123
|
-
expect(isAztecWalletContext(validContext)).toBe(true);
|
124
|
-
});
|
125
|
-
|
126
|
-
it('returns false for null', () => {
|
127
|
-
expect(isAztecWalletContext(null)).toBe(false);
|
128
|
-
});
|
129
|
-
|
130
|
-
it('returns false for non-object values', () => {
|
131
|
-
expect(isAztecWalletContext(123)).toBe(false);
|
132
|
-
expect(isAztecWalletContext('string')).toBe(false);
|
133
|
-
expect(isAztecWalletContext(undefined)).toBe(false);
|
134
|
-
expect(isAztecWalletContext(true)).toBe(false);
|
135
|
-
expect(isAztecWalletContext([])).toBe(false);
|
136
|
-
expect(isAztecWalletContext(() => {})).toBe(false);
|
137
|
-
});
|
138
|
-
|
139
|
-
it('returns false for missing required properties', () => {
|
140
|
-
expect(isAztecWalletContext({})).toBe(false);
|
141
|
-
expect(isAztecWalletContext({ pxe })).toBe(false);
|
142
|
-
expect(isAztecWalletContext({ pxe, wallet })).toBe(false);
|
143
|
-
expect(isAztecWalletContext({ wallet, contractArtifactCache: new ContractArtifactCache(wallet) })).toBe(
|
144
|
-
false,
|
145
|
-
);
|
146
|
-
});
|
147
|
-
|
148
|
-
it('returns false for objects with null properties', () => {
|
149
|
-
expect(isAztecWalletContext({ pxe: null, wallet: null, contractArtifactCache: null })).toBe(false);
|
150
|
-
expect(
|
151
|
-
isAztecWalletContext({ pxe, wallet: null, contractArtifactCache: new ContractArtifactCache(wallet) }),
|
152
|
-
).toBe(false);
|
153
|
-
expect(
|
154
|
-
isAztecWalletContext({ pxe: null, wallet, contractArtifactCache: new ContractArtifactCache(wallet) }),
|
155
|
-
).toBe(false);
|
156
|
-
});
|
157
|
-
});
|
158
|
-
|
159
|
-
describe('asWalletRouterClient', () => {
|
160
|
-
it('returns a JSONRPCWalletClient instance', () => {
|
161
|
-
const client = aztecWallet.asWalletRouterClient();
|
162
|
-
expect(client).toBeInstanceOf(JSONRPCWalletClient);
|
163
|
-
});
|
164
|
-
|
165
|
-
it('returns a valid router client', () => {
|
166
|
-
const client = aztecWallet.asWalletRouterClient();
|
167
|
-
// Verify the client is properly instantiated
|
168
|
-
expect(client).toBeDefined();
|
169
|
-
expect(client).toBeInstanceOf(JSONRPCWalletClient);
|
170
|
-
});
|
171
|
-
});
|
172
|
-
|
173
|
-
describe('request handling', () => {
|
174
|
-
it('handles valid context in fallback handler', async () => {
|
175
|
-
const result = await (
|
176
|
-
aztecWallet as unknown as {
|
177
|
-
fallbackHandler: (
|
178
|
-
context: AztecWalletContext,
|
179
|
-
method: string,
|
180
|
-
params: unknown[],
|
181
|
-
) => Promise<unknown>;
|
182
|
-
}
|
183
|
-
).fallbackHandler(
|
184
|
-
{
|
185
|
-
pxe,
|
186
|
-
wallet,
|
187
|
-
contractArtifactCache: new ContractArtifactCache(wallet),
|
188
|
-
},
|
189
|
-
'aztec_getAccount',
|
190
|
-
[],
|
191
|
-
);
|
192
|
-
expect(result).toBe('mockAddress');
|
193
|
-
});
|
194
|
-
|
195
|
-
it('throws error for invalid context in fallback handler', async () => {
|
196
|
-
await expect(
|
197
|
-
(
|
198
|
-
aztecWallet as unknown as {
|
199
|
-
fallbackHandler: (
|
200
|
-
context: AztecWalletContext,
|
201
|
-
method: string,
|
202
|
-
params: unknown[],
|
203
|
-
) => Promise<unknown>;
|
204
|
-
}
|
205
|
-
).fallbackHandler({ invalidContext: true } as unknown as AztecWalletContext, 'aztec_getAccount', []),
|
206
|
-
).rejects.toThrow(AztecWalletError);
|
207
|
-
});
|
208
|
-
});
|
209
|
-
|
210
|
-
describe('message handling', () => {
|
211
|
-
it('processes incoming messages through transport', async () => {
|
212
|
-
const message = {
|
213
|
-
jsonrpc: '2.0',
|
214
|
-
id: 1,
|
215
|
-
method: 'aztec_getAccount',
|
216
|
-
params: [],
|
217
|
-
};
|
218
|
-
|
219
|
-
// Setup request handler to use fallback handler
|
220
|
-
const handleRequest = async (msg: unknown) => {
|
221
|
-
const typedMessage = msg as { method: string; params: unknown[] };
|
222
|
-
return (
|
223
|
-
aztecWallet as unknown as {
|
224
|
-
fallbackHandler: (
|
225
|
-
context: AztecWalletContext,
|
226
|
-
method: string,
|
227
|
-
params: unknown[],
|
228
|
-
) => Promise<unknown>;
|
229
|
-
}
|
230
|
-
).fallbackHandler(
|
231
|
-
{ pxe, wallet, contractArtifactCache: new ContractArtifactCache(wallet) },
|
232
|
-
typedMessage.method,
|
233
|
-
typedMessage.params,
|
234
|
-
);
|
235
|
-
};
|
236
|
-
|
237
|
-
(aztecWallet as unknown as { handleRequest: typeof handleRequest }).handleRequest = handleRequest;
|
238
|
-
|
239
|
-
await handleRequest(message);
|
240
|
-
expect(wallet.getAddress).toHaveBeenCalled();
|
241
|
-
});
|
242
|
-
|
243
|
-
it('handles transport errors gracefully', async () => {
|
244
|
-
const message = {
|
245
|
-
jsonrpc: '2.0',
|
246
|
-
id: 1,
|
247
|
-
method: 'invalidMethod',
|
248
|
-
params: [],
|
249
|
-
};
|
250
|
-
|
251
|
-
// Setup request handler to throw error for invalid method
|
252
|
-
const handleRequest = async (_msg: unknown) => {
|
253
|
-
throw new AztecWalletError('invalidRequest', 'Invalid method');
|
254
|
-
};
|
255
|
-
|
256
|
-
(aztecWallet as unknown as { handleRequest: typeof handleRequest }).handleRequest = handleRequest;
|
257
|
-
|
258
|
-
await expect(handleRequest(message)).rejects.toThrow(AztecWalletError);
|
259
|
-
});
|
260
|
-
});
|
261
|
-
});
|
262
|
-
|
263
|
-
// Helper function to check context type
|
264
|
-
function isAztecWalletContext(value: unknown): value is AztecWalletContext {
|
265
|
-
return (
|
266
|
-
typeof value === 'object' &&
|
267
|
-
value !== null &&
|
268
|
-
'pxe' in value &&
|
269
|
-
'wallet' in value &&
|
270
|
-
'contractArtifactCache' in value &&
|
271
|
-
value.pxe !== null &&
|
272
|
-
value.wallet !== null &&
|
273
|
-
value.contractArtifactCache !== null
|
274
|
-
);
|
275
|
-
}
|