@walletmesh/aztec-rpc-wallet 0.4.0 → 0.5.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 +12 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/client/aztec-dapp-wallet.d.ts +6 -6
- package/dist/client/aztec-dapp-wallet.d.ts.map +1 -1
- package/dist/client/aztec-dapp-wallet.js +7 -7
- package/dist/client/aztec-router-provider.d.ts +1 -1
- package/dist/client/aztec-router-provider.d.ts.map +1 -1
- package/dist/client/aztec-router-provider.js +1 -1
- package/dist/client/helpers.d.ts.map +1 -1
- package/dist/client/helpers.js +2 -2
- package/dist/client/register-serializers.js +1 -1
- package/dist/index.d.ts +18 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/types.d.ts +11 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/wallet/create-node.d.ts +1 -1
- package/dist/wallet/create-node.d.ts.map +1 -1
- package/dist/wallet/create-node.js +1 -1
- package/dist/wallet/handlers/account.d.ts +1 -1
- package/dist/wallet/handlers/account.d.ts.map +1 -1
- package/dist/wallet/handlers/account.js +1 -1
- package/dist/wallet/handlers/contract-interaction.d.ts +1 -1
- package/dist/wallet/handlers/contract-interaction.d.ts.map +1 -1
- package/dist/wallet/handlers/contract-interaction.js +4 -4
- package/dist/wallet/handlers/contract.d.ts.map +1 -1
- package/dist/wallet/handlers/contract.js +1 -1
- package/dist/wallet/handlers/event.d.ts +1 -1
- package/dist/wallet/handlers/event.d.ts.map +1 -1
- package/dist/wallet/handlers/event.js +1 -1
- package/dist/wallet/handlers/index.d.ts.map +1 -1
- package/dist/wallet/handlers/index.js +2 -2
- package/dist/wallet/handlers/node.d.ts +1 -1
- package/dist/wallet/handlers/node.d.ts.map +1 -1
- package/dist/wallet/handlers/node.js +1 -1
- package/dist/wallet/handlers/senders.d.ts +1 -1
- package/dist/wallet/handlers/senders.d.ts.map +1 -1
- package/dist/wallet/handlers/senders.js +1 -1
- package/dist/wallet/handlers/transaction.d.ts +5 -4
- package/dist/wallet/handlers/transaction.d.ts.map +1 -1
- package/dist/wallet/handlers/transaction.js +9 -6
- package/dist/wallet/serializers.d.ts +1 -1
- package/dist/wallet/serializers.d.ts.map +1 -1
- package/dist/wallet/serializers.js +25 -25
- package/docs/README.md +1 -1
- package/docs/classes/AztecDappWallet.md +47 -47
- package/docs/classes/AztecRouterProvider.md +4 -4
- package/docs/classes/AztecWalletError.md +31 -7
- package/docs/classes/ContractArtifactCache.md +4 -4
- package/docs/functions/connectAztec.md +2 -2
- package/docs/functions/createAztecWallet.md +2 -2
- package/docs/functions/createAztecWalletNode.md +2 -2
- package/docs/functions/registerAztecSerializers.md +2 -2
- package/docs/functions/registerWalletAztecSerializers.md +2 -2
- package/docs/globals.md +2 -2
- package/docs/interfaces/AztecHandlerContext.md +5 -5
- package/docs/interfaces/AztecWalletContext.md +5 -5
- package/docs/interfaces/AztecWalletMethodMap.md +41 -37
- package/docs/type-aliases/AztecChainId.md +2 -2
- package/docs/variables/ALL_AZTEC_METHODS.md +2 -2
- package/docs/variables/AztecWalletErrorMap.md +2 -2
- package/docs/variables/AztecWalletSerializer.md +2 -2
- package/package.json +11 -9
- package/src/client/aztec-dapp-wallet.test.ts +8 -6
- package/src/client/aztec-dapp-wallet.ts +15 -14
- package/src/client/aztec-router-provider.test.ts +2 -2
- package/src/client/aztec-router-provider.ts +1 -1
- package/src/client/helpers.test.ts +3 -3
- package/src/client/helpers.ts +1 -2
- package/src/client/register-serializers.ts +1 -1
- package/src/contractArtifactCache.test.ts +1 -1
- package/src/index.test.ts +1 -1
- package/src/index.ts +21 -28
- package/src/types.ts +20 -20
- package/src/wallet/create-node.test.ts +3 -3
- package/src/wallet/create-node.ts +3 -4
- package/src/wallet/handlers/account.test.ts +6 -6
- package/src/wallet/handlers/account.ts +2 -2
- package/src/wallet/handlers/contract-interaction.test.ts +6 -7
- package/src/wallet/handlers/contract-interaction.ts +7 -7
- package/src/wallet/handlers/contract.test.ts +5 -5
- package/src/wallet/handlers/contract.ts +1 -1
- package/src/wallet/handlers/event.test.ts +4 -4
- package/src/wallet/handlers/event.ts +2 -2
- package/src/wallet/handlers/index.ts +1 -1
- package/src/wallet/handlers/node.test.ts +5 -6
- package/src/wallet/handlers/node.ts +2 -2
- package/src/wallet/handlers/senders.test.ts +4 -4
- package/src/wallet/handlers/senders.ts +2 -2
- package/src/wallet/handlers/transaction.test.ts +22 -13
- package/src/wallet/handlers/transaction.ts +10 -7
- package/src/wallet/serializers.test.ts +4 -6
- package/src/wallet/serializers.ts +44 -42
@@ -1,12 +1,10 @@
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
2
|
-
import { AztecAddress, Fr, AuthWitness } from '@aztec/aztec.js';
|
3
1
|
import type { ContractArtifact } from '@aztec/aztec.js';
|
4
|
-
import {
|
5
|
-
import { FunctionType } from '@aztec/stdlib/abi';
|
6
|
-
import { Capsule, HashedValues } from '@aztec/stdlib/tx';
|
2
|
+
import { AuthWitness, AztecAddress, Fr } from '@aztec/aztec.js';
|
7
3
|
import { ExecutionPayload } from '@aztec/entrypoints/payload';
|
4
|
+
import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
5
|
+
import { Capsule, HashedValues } from '@aztec/stdlib/tx';
|
6
|
+
import { describe, expect, it } from 'vitest';
|
8
7
|
import { AztecWalletSerializer } from './serializers.js';
|
9
|
-
import { FunctionCall } from '@aztec/stdlib/abi';
|
10
8
|
|
11
9
|
describe('ExecutionPayload Serialization', () => {
|
12
10
|
it('should serialize and deserialize ExecutionPayload correctly', async () => {
|
@@ -19,33 +19,23 @@
|
|
19
19
|
* to reconstruct complex Aztec objects from their JSON representations.
|
20
20
|
*/
|
21
21
|
|
22
|
-
import type {
|
23
|
-
|
24
|
-
import type {
|
25
|
-
JSONRPCNode,
|
26
|
-
JSONRPCSerializer,
|
27
|
-
JSONRPCSerializedData,
|
28
|
-
JSONRPCParams,
|
29
|
-
} from '@walletmesh/jsonrpc';
|
30
|
-
import { JSONRPCError } from '@walletmesh/jsonrpc';
|
31
|
-
|
22
|
+
import type { NodeInfo } from '@aztec/aztec.js';
|
32
23
|
import {
|
24
|
+
AuthWitness,
|
33
25
|
AztecAddress,
|
34
26
|
CompleteAddress,
|
35
|
-
TxExecutionRequest,
|
36
27
|
Fr,
|
37
28
|
Tx,
|
29
|
+
TxExecutionRequest,
|
38
30
|
TxHash,
|
39
|
-
AuthWitness,
|
40
31
|
} from '@aztec/aztec.js';
|
41
|
-
import type { NodeInfo } from '@aztec/aztec.js';
|
42
|
-
|
43
32
|
import type { IntentAction, IntentInnerHash } from '@aztec/aztec.js/utils';
|
33
|
+
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
34
|
+
import { createLogger } from '@aztec/foundation/log';
|
35
|
+
import type { ZodFor } from '@aztec/foundation/schemas';
|
44
36
|
|
45
37
|
import { AbiTypeSchema, ContractArtifactSchema, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
46
|
-
import {
|
47
|
-
|
48
|
-
import type { PXEInfo, ContractMetadata, ContractClassMetadata } from '@aztec/stdlib/interfaces/client';
|
38
|
+
import { L2Block } from '@aztec/stdlib/block';
|
49
39
|
import {
|
50
40
|
ContractClassWithIdSchema,
|
51
41
|
ContractInstanceWithAddressSchema,
|
@@ -53,7 +43,8 @@ import {
|
|
53
43
|
ProtocolContractAddressesSchema,
|
54
44
|
} from '@aztec/stdlib/contract';
|
55
45
|
import { GasFees } from '@aztec/stdlib/gas';
|
56
|
-
import {
|
46
|
+
import type { ContractClassMetadata, ContractMetadata, PXEInfo } from '@aztec/stdlib/interfaces/client';
|
47
|
+
import { schemas } from '@aztec/stdlib/schemas';
|
57
48
|
import {
|
58
49
|
Capsule,
|
59
50
|
HashedValues,
|
@@ -64,12 +55,15 @@ import {
|
|
64
55
|
TxSimulationResult,
|
65
56
|
UtilitySimulationResult,
|
66
57
|
} from '@aztec/stdlib/tx';
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
58
|
+
import type {
|
59
|
+
JSONRPCNode,
|
60
|
+
JSONRPCParams,
|
61
|
+
JSONRPCSerializedData,
|
62
|
+
JSONRPCSerializer,
|
63
|
+
} from '@walletmesh/jsonrpc';
|
64
|
+
import { JSONRPCError } from '@walletmesh/jsonrpc';
|
65
|
+
import { type ZodTypeAny, z } from 'zod';
|
66
|
+
import type { AztecWalletMethodMap } from '../types.js';
|
73
67
|
|
74
68
|
// These aren't exported by @aztec/stdlib/interfaces/client, we've copied them here
|
75
69
|
const ContractMetadataSchema = z.object({
|
@@ -128,13 +122,17 @@ const DeployContractResultSchema = z.object({
|
|
128
122
|
|
129
123
|
const logger = createLogger('aztec-rpc-wallet:serializers');
|
130
124
|
|
125
|
+
async function jsonParseWithSchemaAsync<T>(json: string, schema: ZodTypeAny): Promise<T> {
|
126
|
+
return schema.parseAsync(JSON.parse(json));
|
127
|
+
}
|
128
|
+
|
131
129
|
function createResultSerializer<R>(resultSchema?: ZodTypeAny): Pick<JSONRPCSerializer<unknown, R>, 'result'> {
|
132
130
|
return {
|
133
131
|
result: {
|
134
132
|
serialize: async (method: string, value: R) => ({ method, serialized: jsonStringify(value) }),
|
135
133
|
deserialize: async (method: string, data: JSONRPCSerializedData) => {
|
136
134
|
if (resultSchema) {
|
137
|
-
return await
|
135
|
+
return await jsonParseWithSchemaAsync(data.serialized, resultSchema);
|
138
136
|
}
|
139
137
|
// If no schema is provided, parse as JSON
|
140
138
|
logger.debug(`Deserializing result for method without schema: ${method}`);
|
@@ -348,14 +346,12 @@ export const AztecWalletSerializer: JSONRPCSerializer<JSONRPCParams, unknown> =
|
|
348
346
|
return [];
|
349
347
|
case 'aztec_createAuthWit': {
|
350
348
|
const intentRaw = ensureParam<unknown>(dAppParams, 'intent');
|
351
|
-
let intentInput: Fr |
|
349
|
+
let intentInput: Fr | IntentAction | IntentInnerHash;
|
352
350
|
if (
|
353
351
|
typeof intentRaw === 'string' &&
|
354
352
|
(intentRaw.startsWith('0x') || !Number.isNaN(Number(intentRaw)))
|
355
353
|
) {
|
356
354
|
intentInput = Fr.fromString(intentRaw);
|
357
|
-
} else if (intentRaw instanceof Buffer) {
|
358
|
-
intentInput = intentRaw;
|
359
355
|
} else if (typeof intentRaw === 'object' && intentRaw !== null) {
|
360
356
|
intentInput = intentRaw as
|
361
357
|
| import('@aztec/aztec.js/utils').IntentAction
|
@@ -385,13 +381,13 @@ export const AztecWalletSerializer: JSONRPCSerializer<JSONRPCParams, unknown> =
|
|
385
381
|
case 'aztec_registerContract': {
|
386
382
|
const instanceRaw = ensureParam<Record<string, unknown>>(dAppParams, 'instance');
|
387
383
|
const artifactRaw = getOptionalParam<Record<string, unknown>>(dAppParams, 'artifact');
|
388
|
-
const instance = ContractInstanceWithAddressSchema.
|
389
|
-
const artifact = artifactRaw ? ContractArtifactSchema.
|
384
|
+
const instance = await ContractInstanceWithAddressSchema.parseAsync(instanceRaw);
|
385
|
+
const artifact = artifactRaw ? await ContractArtifactSchema.parseAsync(artifactRaw) : undefined;
|
390
386
|
return [instance, artifact];
|
391
387
|
}
|
392
388
|
case 'aztec_registerContractClass': {
|
393
389
|
const artifactRaw = ensureParam<Record<string, unknown>>(dAppParams, 'artifact');
|
394
|
-
const artifact = ContractArtifactSchema.
|
390
|
+
const artifact = await ContractArtifactSchema.parseAsync(artifactRaw);
|
395
391
|
return [artifact];
|
396
392
|
}
|
397
393
|
case 'aztec_proveTx': {
|
@@ -402,16 +398,16 @@ export const AztecWalletSerializer: JSONRPCSerializer<JSONRPCParams, unknown> =
|
|
402
398
|
dAppParams,
|
403
399
|
'privateExecutionResult',
|
404
400
|
);
|
405
|
-
const txRequest = TxExecutionRequest.schema.
|
401
|
+
const txRequest = await TxExecutionRequest.schema.parseAsync(txRequestRaw);
|
406
402
|
// Conditionally parse if privateExecutionResultRaw is present
|
407
403
|
const privateExecutionResult = privateExecutionResultRaw
|
408
|
-
? PrivateExecutionResult.schema.
|
404
|
+
? await PrivateExecutionResult.schema.parseAsync(privateExecutionResultRaw)
|
409
405
|
: undefined;
|
410
406
|
return [txRequest, privateExecutionResult];
|
411
407
|
}
|
412
408
|
case 'aztec_sendTx': {
|
413
409
|
const txRaw = ensureParam<Record<string, unknown>>(dAppParams, 'tx');
|
414
|
-
const tx = Tx.schema.
|
410
|
+
const tx = await Tx.schema.parseAsync(txRaw);
|
415
411
|
return [tx];
|
416
412
|
}
|
417
413
|
case 'aztec_getTxReceipt': {
|
@@ -421,7 +417,7 @@ export const AztecWalletSerializer: JSONRPCSerializer<JSONRPCParams, unknown> =
|
|
421
417
|
}
|
422
418
|
case 'aztec_simulateTx': {
|
423
419
|
const txRequestRaw = ensureParam<Record<string, unknown>>(dAppParams, 'txRequest');
|
424
|
-
const txRequest = TxExecutionRequest.schema.
|
420
|
+
const txRequest = await TxExecutionRequest.schema.parseAsync(txRequestRaw);
|
425
421
|
const simulatePublic = getOptionalParam<boolean>(dAppParams, 'simulatePublic', 'boolean');
|
426
422
|
const msgSenderStr = getOptionalParam<string>(dAppParams, 'msgSender', 'string');
|
427
423
|
const msgSender = msgSenderStr ? AztecAddress.fromString(msgSenderStr) : undefined;
|
@@ -433,7 +429,7 @@ export const AztecWalletSerializer: JSONRPCSerializer<JSONRPCParams, unknown> =
|
|
433
429
|
}
|
434
430
|
case 'aztec_profileTx': {
|
435
431
|
const txRequestRaw = ensureParam<Record<string, unknown>>(dAppParams, 'txRequest');
|
436
|
-
const txRequest = TxExecutionRequest.schema.
|
432
|
+
const txRequest = await TxExecutionRequest.schema.parseAsync(txRequestRaw);
|
437
433
|
const profileMode = getOptionalParam<'gates' | 'execution-steps' | 'full'>(
|
438
434
|
dAppParams,
|
439
435
|
'profileMode',
|
@@ -450,7 +446,7 @@ export const AztecWalletSerializer: JSONRPCSerializer<JSONRPCParams, unknown> =
|
|
450
446
|
const toStr = ensureParam<string>(dAppParams, 'to', 'string');
|
451
447
|
const to = AztecAddress.fromString(toStr);
|
452
448
|
const authWitsRaw = getOptionalParam<Record<string, unknown>[]>(dAppParams, 'authWits');
|
453
|
-
const authWits = authWitsRaw?.map((aw) => AuthWitness.schema.
|
449
|
+
const authWits = await authWitsRaw?.map((aw) => AuthWitness.schema.parseAsync(aw)); // Use AuthWitness from @aztec/aztec.js
|
454
450
|
const fromStr = getOptionalParam<string>(dAppParams, 'from', 'string');
|
455
451
|
const from = fromStr ? AztecAddress.fromString(fromStr) : undefined;
|
456
452
|
return [functionName, args, to, authWits, from];
|
@@ -459,7 +455,10 @@ export const AztecWalletSerializer: JSONRPCSerializer<JSONRPCParams, unknown> =
|
|
459
455
|
const contractAddressStr = ensureParam<string>(dAppParams, 'contractAddress', 'string');
|
460
456
|
const contractAddress = AztecAddress.fromString(contractAddressStr);
|
461
457
|
const eventMetadataRaw = ensureParam<string>(dAppParams, 'eventMetadata');
|
462
|
-
const eventMetadata =
|
458
|
+
const eventMetadata = await jsonParseWithSchemaAsync(
|
459
|
+
eventMetadataRaw,
|
460
|
+
EventMetadataDefinitionSchema,
|
461
|
+
);
|
463
462
|
const fromBlock = ensureParam<number>(dAppParams, 'from', 'number');
|
464
463
|
const numBlocks = ensureParam<number>(dAppParams, 'numBlocks', 'number');
|
465
464
|
const recipientsRaw = ensureParam<string[]>(dAppParams, 'recipients');
|
@@ -468,23 +467,26 @@ export const AztecWalletSerializer: JSONRPCSerializer<JSONRPCParams, unknown> =
|
|
468
467
|
}
|
469
468
|
case 'aztec_getPublicEvents': {
|
470
469
|
const eventMetadataRaw = ensureParam<string>(dAppParams, 'eventMetadata');
|
471
|
-
const eventMetadata =
|
470
|
+
const eventMetadata = await jsonParseWithSchemaAsync(
|
471
|
+
eventMetadataRaw,
|
472
|
+
EventMetadataDefinitionSchema,
|
473
|
+
);
|
472
474
|
const fromBlock = ensureParam<number>(dAppParams, 'from', 'number');
|
473
475
|
const limit = ensureParam<number>(dAppParams, 'limit', 'number');
|
474
476
|
return [eventMetadata, fromBlock, limit];
|
475
477
|
}
|
476
478
|
case 'aztec_wmExecuteTx': {
|
477
479
|
const executionPayloadRaw = ensureParam<Record<string, unknown>>(dAppParams, 'executionPayload');
|
478
|
-
const executionPayload = ExecutionPayloadSchema.
|
480
|
+
const executionPayload = await ExecutionPayloadSchema.parseAsync(executionPayloadRaw);
|
479
481
|
return [executionPayload];
|
480
482
|
}
|
481
483
|
case 'aztec_wmSimulateTx': {
|
482
484
|
const executionPayloadRaw = ensureParam<Record<string, unknown>>(dAppParams, 'executionPayload');
|
483
|
-
const executionPayload = ExecutionPayloadSchema.
|
485
|
+
const executionPayload = await ExecutionPayloadSchema.parseAsync(executionPayloadRaw);
|
484
486
|
return [executionPayload];
|
485
487
|
}
|
486
488
|
case 'aztec_wmDeployContract': {
|
487
|
-
const deployParams = DeployContractParamsSchema.
|
489
|
+
const deployParams = await DeployContractParamsSchema.parseAsync(dAppParams);
|
488
490
|
return [deployParams];
|
489
491
|
}
|
490
492
|
case 'wm_getSupportedMethods':
|