@walletmesh/aztec-rpc-wallet 0.4.1 → 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 +6 -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 -22
- 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 -11
- 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 +43 -39
@@ -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}`);
|
@@ -383,13 +381,13 @@ export const AztecWalletSerializer: JSONRPCSerializer<JSONRPCParams, unknown> =
|
|
383
381
|
case 'aztec_registerContract': {
|
384
382
|
const instanceRaw = ensureParam<Record<string, unknown>>(dAppParams, 'instance');
|
385
383
|
const artifactRaw = getOptionalParam<Record<string, unknown>>(dAppParams, 'artifact');
|
386
|
-
const instance = ContractInstanceWithAddressSchema.
|
387
|
-
const artifact = artifactRaw ? ContractArtifactSchema.
|
384
|
+
const instance = await ContractInstanceWithAddressSchema.parseAsync(instanceRaw);
|
385
|
+
const artifact = artifactRaw ? await ContractArtifactSchema.parseAsync(artifactRaw) : undefined;
|
388
386
|
return [instance, artifact];
|
389
387
|
}
|
390
388
|
case 'aztec_registerContractClass': {
|
391
389
|
const artifactRaw = ensureParam<Record<string, unknown>>(dAppParams, 'artifact');
|
392
|
-
const artifact = ContractArtifactSchema.
|
390
|
+
const artifact = await ContractArtifactSchema.parseAsync(artifactRaw);
|
393
391
|
return [artifact];
|
394
392
|
}
|
395
393
|
case 'aztec_proveTx': {
|
@@ -400,16 +398,16 @@ export const AztecWalletSerializer: JSONRPCSerializer<JSONRPCParams, unknown> =
|
|
400
398
|
dAppParams,
|
401
399
|
'privateExecutionResult',
|
402
400
|
);
|
403
|
-
const txRequest = TxExecutionRequest.schema.
|
401
|
+
const txRequest = await TxExecutionRequest.schema.parseAsync(txRequestRaw);
|
404
402
|
// Conditionally parse if privateExecutionResultRaw is present
|
405
403
|
const privateExecutionResult = privateExecutionResultRaw
|
406
|
-
? PrivateExecutionResult.schema.
|
404
|
+
? await PrivateExecutionResult.schema.parseAsync(privateExecutionResultRaw)
|
407
405
|
: undefined;
|
408
406
|
return [txRequest, privateExecutionResult];
|
409
407
|
}
|
410
408
|
case 'aztec_sendTx': {
|
411
409
|
const txRaw = ensureParam<Record<string, unknown>>(dAppParams, 'tx');
|
412
|
-
const tx = Tx.schema.
|
410
|
+
const tx = await Tx.schema.parseAsync(txRaw);
|
413
411
|
return [tx];
|
414
412
|
}
|
415
413
|
case 'aztec_getTxReceipt': {
|
@@ -419,7 +417,7 @@ export const AztecWalletSerializer: JSONRPCSerializer<JSONRPCParams, unknown> =
|
|
419
417
|
}
|
420
418
|
case 'aztec_simulateTx': {
|
421
419
|
const txRequestRaw = ensureParam<Record<string, unknown>>(dAppParams, 'txRequest');
|
422
|
-
const txRequest = TxExecutionRequest.schema.
|
420
|
+
const txRequest = await TxExecutionRequest.schema.parseAsync(txRequestRaw);
|
423
421
|
const simulatePublic = getOptionalParam<boolean>(dAppParams, 'simulatePublic', 'boolean');
|
424
422
|
const msgSenderStr = getOptionalParam<string>(dAppParams, 'msgSender', 'string');
|
425
423
|
const msgSender = msgSenderStr ? AztecAddress.fromString(msgSenderStr) : undefined;
|
@@ -431,7 +429,7 @@ export const AztecWalletSerializer: JSONRPCSerializer<JSONRPCParams, unknown> =
|
|
431
429
|
}
|
432
430
|
case 'aztec_profileTx': {
|
433
431
|
const txRequestRaw = ensureParam<Record<string, unknown>>(dAppParams, 'txRequest');
|
434
|
-
const txRequest = TxExecutionRequest.schema.
|
432
|
+
const txRequest = await TxExecutionRequest.schema.parseAsync(txRequestRaw);
|
435
433
|
const profileMode = getOptionalParam<'gates' | 'execution-steps' | 'full'>(
|
436
434
|
dAppParams,
|
437
435
|
'profileMode',
|
@@ -448,7 +446,7 @@ export const AztecWalletSerializer: JSONRPCSerializer<JSONRPCParams, unknown> =
|
|
448
446
|
const toStr = ensureParam<string>(dAppParams, 'to', 'string');
|
449
447
|
const to = AztecAddress.fromString(toStr);
|
450
448
|
const authWitsRaw = getOptionalParam<Record<string, unknown>[]>(dAppParams, 'authWits');
|
451
|
-
const authWits = authWitsRaw?.map((aw) => AuthWitness.schema.
|
449
|
+
const authWits = await authWitsRaw?.map((aw) => AuthWitness.schema.parseAsync(aw)); // Use AuthWitness from @aztec/aztec.js
|
452
450
|
const fromStr = getOptionalParam<string>(dAppParams, 'from', 'string');
|
453
451
|
const from = fromStr ? AztecAddress.fromString(fromStr) : undefined;
|
454
452
|
return [functionName, args, to, authWits, from];
|
@@ -457,7 +455,10 @@ export const AztecWalletSerializer: JSONRPCSerializer<JSONRPCParams, unknown> =
|
|
457
455
|
const contractAddressStr = ensureParam<string>(dAppParams, 'contractAddress', 'string');
|
458
456
|
const contractAddress = AztecAddress.fromString(contractAddressStr);
|
459
457
|
const eventMetadataRaw = ensureParam<string>(dAppParams, 'eventMetadata');
|
460
|
-
const eventMetadata =
|
458
|
+
const eventMetadata = await jsonParseWithSchemaAsync(
|
459
|
+
eventMetadataRaw,
|
460
|
+
EventMetadataDefinitionSchema,
|
461
|
+
);
|
461
462
|
const fromBlock = ensureParam<number>(dAppParams, 'from', 'number');
|
462
463
|
const numBlocks = ensureParam<number>(dAppParams, 'numBlocks', 'number');
|
463
464
|
const recipientsRaw = ensureParam<string[]>(dAppParams, 'recipients');
|
@@ -466,23 +467,26 @@ export const AztecWalletSerializer: JSONRPCSerializer<JSONRPCParams, unknown> =
|
|
466
467
|
}
|
467
468
|
case 'aztec_getPublicEvents': {
|
468
469
|
const eventMetadataRaw = ensureParam<string>(dAppParams, 'eventMetadata');
|
469
|
-
const eventMetadata =
|
470
|
+
const eventMetadata = await jsonParseWithSchemaAsync(
|
471
|
+
eventMetadataRaw,
|
472
|
+
EventMetadataDefinitionSchema,
|
473
|
+
);
|
470
474
|
const fromBlock = ensureParam<number>(dAppParams, 'from', 'number');
|
471
475
|
const limit = ensureParam<number>(dAppParams, 'limit', 'number');
|
472
476
|
return [eventMetadata, fromBlock, limit];
|
473
477
|
}
|
474
478
|
case 'aztec_wmExecuteTx': {
|
475
479
|
const executionPayloadRaw = ensureParam<Record<string, unknown>>(dAppParams, 'executionPayload');
|
476
|
-
const executionPayload = ExecutionPayloadSchema.
|
480
|
+
const executionPayload = await ExecutionPayloadSchema.parseAsync(executionPayloadRaw);
|
477
481
|
return [executionPayload];
|
478
482
|
}
|
479
483
|
case 'aztec_wmSimulateTx': {
|
480
484
|
const executionPayloadRaw = ensureParam<Record<string, unknown>>(dAppParams, 'executionPayload');
|
481
|
-
const executionPayload = ExecutionPayloadSchema.
|
485
|
+
const executionPayload = await ExecutionPayloadSchema.parseAsync(executionPayloadRaw);
|
482
486
|
return [executionPayload];
|
483
487
|
}
|
484
488
|
case 'aztec_wmDeployContract': {
|
485
|
-
const deployParams = DeployContractParamsSchema.
|
489
|
+
const deployParams = await DeployContractParamsSchema.parseAsync(dAppParams);
|
486
490
|
return [deployParams];
|
487
491
|
}
|
488
492
|
case 'wm_getSupportedMethods':
|