Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion yarn-project/archiver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"lodash.omit": "^4.5.0",
"tslib": "^2.5.0",
"viem": "npm:@aztec/viem@2.38.2",
"zod": "^3.23.8"
"zod": "^4"
},
"devDependencies": {
"@jest/globals": "^30.0.0",
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"axios": "^1.15.1",
"tslib": "^2.4.0",
"viem": "npm:@aztec/viem@2.38.2",
"zod": "^3.23.8"
"zod": "^4"
},
"devDependencies": {
"@aztec/builder": "workspace:^",
Expand Down
112 changes: 62 additions & 50 deletions yarn-project/aztec.js/src/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
import { type ContractInstanceWithAddress, ContractInstanceWithAddressSchema } from '@aztec/stdlib/contract';
import { Gas, ManaUsageEstimate } from '@aztec/stdlib/gas';
import { LogId } from '@aztec/stdlib/logs';
import { AbiDecodedSchema, type ApiSchemaFor, optional, schemas, zodFor } from '@aztec/stdlib/schemas';
import {
AbiDecodedSchema,
type ApiSchemaFor,
getSchemaParameters,
getSchemaReturnType,
optional,
schemas,
zodFor,
} from '@aztec/stdlib/schemas';
import type { ExecutionPayload, InTx } from '@aztec/stdlib/tx';
import {
Capsule,
Expand Down Expand Up @@ -545,56 +553,60 @@ const OffchainOutputSchema = z.object({
* This is the single source of truth for method schemas - batch schemas are derived from this.
*/
const WalletMethodSchemas = {
getChainInfo: z
.function()
.args()
.returns(z.object({ chainId: schemas.Fr, version: schemas.Fr })),
getContractMetadata: z.function().args(schemas.AztecAddress).returns(ContractMetadataSchema),
getContractClassMetadata: z.function().args(schemas.Fr).returns(ContractClassMetadataSchema),
getPrivateEvents: z
.function()
.args(EventMetadataDefinitionSchema, PrivateEventFilterSchema)
.returns(z.array(PrivateEventSchema)),
registerSender: z.function().args(schemas.AztecAddress, optional(z.string())).returns(schemas.AztecAddress),
getAddressBook: z
.function()
.args()
.returns(z.array(z.object({ alias: z.string(), item: schemas.AztecAddress }))),
getAccounts: z
.function()
.args()
.returns(z.array(z.object({ alias: z.string(), item: schemas.AztecAddress }))),
registerContract: z
.function()
.args(ContractInstanceWithAddressSchema, optional(ContractArtifactSchema), optional(schemas.Fr))
.returns(ContractInstanceWithAddressSchema),
registerContractClass: z.function().args(ContractArtifactSchema).returns(z.void()),
simulateTx: z
.function()
.args(ExecutionPayloadSchema, SimulateOptionsSchema)
.returns(TxSimulationResultWithAppOffset.schema),
executeUtility: z
.function()
.args(
getChainInfo: z.function({ input: z.tuple([]), output: z.object({ chainId: schemas.Fr, version: schemas.Fr }) }),
getContractMetadata: z.function({ input: z.tuple([schemas.AztecAddress]), output: ContractMetadataSchema }),
getContractClassMetadata: z.function({ input: z.tuple([schemas.Fr]), output: ContractClassMetadataSchema }),
getPrivateEvents: z.function({
input: z.tuple([EventMetadataDefinitionSchema, PrivateEventFilterSchema]),
output: z.array(PrivateEventSchema),
}),
registerSender: z.function({
input: z.tuple([schemas.AztecAddress, optional(z.string())]),
output: schemas.AztecAddress,
}),
getAddressBook: z.function({
input: z.tuple([]),
output: z.array(z.object({ alias: z.string(), item: schemas.AztecAddress })),
}),
getAccounts: z.function({
input: z.tuple([]),
output: z.array(z.object({ alias: z.string(), item: schemas.AztecAddress })),
}),
registerContract: z.function({
input: z.tuple([ContractInstanceWithAddressSchema, optional(ContractArtifactSchema), optional(schemas.Fr)]),
output: ContractInstanceWithAddressSchema,
}),
registerContractClass: z.function({ input: z.tuple([ContractArtifactSchema]), output: z.void() }),
simulateTx: z.function({
input: z.tuple([ExecutionPayloadSchema, SimulateOptionsSchema]),
output: TxSimulationResultWithAppOffset.schema,
}),
executeUtility: z.function({
input: z.tuple([
FunctionCall.schema,
z.object({
scopes: z.array(schemas.AztecAddress),
authWitnesses: optional(z.array(AuthWitness.schema)),
}),
)
.returns(UtilityExecutionResult.schema),
profileTx: z.function().args(ExecutionPayloadSchema, ProfileOptionsSchema).returns(TxProfileResult.schema),
sendTx: z
.function()
.args(ExecutionPayloadSchema, SendOptionsSchema)
.returns(
z.union([
z.object({ txHash: TxHash.schema }).merge(OffchainOutputSchema),
z.object({ receipt: TxReceipt.schema }).merge(OffchainOutputSchema),
]),
),
createAuthWit: z.function().args(schemas.AztecAddress, MessageHashOrIntentSchema).returns(AuthWitness.schema),
requestCapabilities: z.function().args(AppCapabilitiesSchema).returns(WalletCapabilitiesSchema),
]),
output: UtilityExecutionResult.schema,
}),
profileTx: z.function({
input: z.tuple([ExecutionPayloadSchema, ProfileOptionsSchema]),
output: TxProfileResult.schema,
}),
sendTx: z.function({
input: z.tuple([ExecutionPayloadSchema, SendOptionsSchema]),
output: z.union([
z.object({ txHash: TxHash.schema }).merge(OffchainOutputSchema),
z.object({ receipt: TxReceipt.schema }).merge(OffchainOutputSchema),
]),
}),
createAuthWit: z.function({
input: z.tuple([schemas.AztecAddress, MessageHashOrIntentSchema]),
output: AuthWitness.schema,
}),
requestCapabilities: z.function({ input: z.tuple([AppCapabilitiesSchema]), output: WalletCapabilitiesSchema }),
};

/**
Expand All @@ -605,19 +617,19 @@ const WalletMethodSchemas = {
function createBatchSchemas<T extends Record<string, z.ZodFunction<z.ZodTuple<any, any>, z.ZodTypeAny>>>(
methodSchemas: T,
) {
const names = Object.keys(methodSchemas) as (keyof T)[];
const names = Object.keys(methodSchemas) as Extract<keyof T, string>[];

const namesAndArgs = names.map(name =>
z.object({
name: z.literal(name),
args: methodSchemas[name].parameters(),
args: getSchemaParameters(methodSchemas[name]),
}),
);

const namesAndReturns = names.map(name =>
z.object({
name: z.literal(name),
result: methodSchemas[name].returnType(),
result: getSchemaReturnType(methodSchemas[name]),
}),
);

Expand All @@ -636,5 +648,5 @@ export { BatchedMethodSchema, BatchedResultSchema };
export const WalletSchema: ApiSchemaFor<Wallet> = {
...WalletMethodSchemas,
// @ts-expect-error - ApiSchemaFor cannot properly type generic methods with readonly arrays
batch: z.function().args(z.array(BatchedMethodSchema)).returns(z.array(BatchedResultSchema)),
batch: z.function({ input: z.tuple([z.array(BatchedMethodSchema)]), output: z.array(BatchedResultSchema) }),
};
2 changes: 1 addition & 1 deletion yarn-project/blob-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"source-map-support": "^0.5.21",
"tslib": "^2.4.0",
"viem": "npm:@aztec/viem@2.38.2",
"zod": "^3.23.8"
"zod": "^4"
},
"devDependencies": {
"@jest/globals": "^30.0.0",
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"source-map-support": "^0.5.21",
"tslib": "^2.4.0",
"viem": "npm:@aztec/viem@2.38.2",
"zod": "^3.23.8"
"zod": "^4"
},
"devDependencies": {
"@jest/globals": "^30.0.0",
Expand Down
14 changes: 7 additions & 7 deletions yarn-project/bot/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export interface BotRunnerApi {
}

export const BotRunnerApiSchema: ApiSchemaFor<BotRunnerApi> = {
start: z.function().args().returns(z.void()),
stop: z.function().args().returns(z.void()),
run: z.function().args().returns(z.void()),
setup: z.function().args().returns(z.void()),
getInfo: z.function().args().returns(BotInfoSchema),
getConfig: z.function().args().returns(BotConfigSchema),
update: z.function().args(BotConfigSchema).returns(z.void()),
start: z.function({ input: z.tuple([]), output: z.void() }),
stop: z.function({ input: z.tuple([]), output: z.void() }),
run: z.function({ input: z.tuple([]), output: z.void() }),
setup: z.function({ input: z.tuple([]), output: z.void() }),
getInfo: z.function({ input: z.tuple([]), output: BotInfoSchema }),
getConfig: z.function({ input: z.tuple([]), output: BotConfigSchema }),
update: z.function({ input: z.tuple([BotConfigSchema]), output: z.void() }),
};
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"typescript": "^5.3.3",
"util": "^0.12.5",
"viem": "npm:@aztec/viem@2.38.2",
"zod": "^3.23.8"
"zod": "^4"
},
"devDependencies": {
"0x": "^5.7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { SendOptions } from '@aztec/aztec.js/wallet';
import { jsonStringify } from '@aztec/foundation/json-rpc';
import { createLogger } from '@aztec/foundation/log';
import type { ApiSchema, Fr } from '@aztec/foundation/schemas';
import { parseWithOptionals, schemaHasMethod } from '@aztec/foundation/schemas';
import { getSchemaParameters, parseWithOptionals, schemaHasMethod } from '@aztec/foundation/schemas';
import { NodeListener, TransportServer } from '@aztec/foundation/transport';
import { ExecutionPayload, Tx } from '@aztec/stdlib/tx';

Expand Down Expand Up @@ -46,7 +46,7 @@ try {
throw new Error(`Unknown method: ${msg.fn}`);
}
const jsonParams = JSON.parse(msg.args) as unknown[];
const args: any[] = await parseWithOptionals(jsonParams, schema[msg.fn].parameters());
const args: any[] = await parseWithOptionals(jsonParams, getSchemaParameters(schema[msg.fn]));
// we have to erase the fn type in order to be able to spread ...args
const handler: ((...args: any[]) => Promise<any>) | undefined =
msg.fn in customMethods ? customMethods[msg.fn as keyof typeof customMethods] : undefined;
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/test-wallet/worker_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type { Fr } from '@aztec/foundation/curves/bn254';
import { jsonStringify } from '@aztec/foundation/json-rpc';
import { createLogger } from '@aztec/foundation/log';
import { promiseWithResolvers } from '@aztec/foundation/promise';
import type { ApiSchema } from '@aztec/foundation/schemas';
import { type ApiSchema, getSchemaReturnType } from '@aztec/foundation/schemas';
import { sleep } from '@aztec/foundation/sleep';
import { NodeConnector, TransportClient } from '@aztec/foundation/transport';
import type { PXEConfig } from '@aztec/pxe/config';
Expand Down Expand Up @@ -124,7 +124,7 @@ export class WorkerWallet implements Wallet {
private async call(fn: string, ...args: any[]): Promise<any> {
const resultJson = await this.callRaw(fn, ...args);
const methodSchema = (WorkerWalletSchema as ApiSchema)[fn];
return methodSchema.returnType().parseAsync(JSON.parse(resultJson));
return getSchemaReturnType(methodSchema).parseAsync(JSON.parse(resultJson));
}

getChainInfo(): Promise<ChainInfo> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import { z } from 'zod';
/** Schema for the WorkerWallet API — extends WalletSchema with proveTx and registerAccount. */
export const WorkerWalletSchema = {
...WalletSchema,
proveTx: z.function().args(ExecutionPayloadSchema, SendOptionsSchema).returns(Tx.schema),
registerAccount: z.function().args(schemas.Fr, schemas.Fr).returns(AztecAddress.schema),
proveTx: z.function({ input: z.tuple([ExecutionPayloadSchema, SendOptionsSchema]), output: Tx.schema }),
registerAccount: z.function({ input: z.tuple([schemas.Fr, schemas.Fr]), output: AztecAddress.schema }),
};
2 changes: 1 addition & 1 deletion yarn-project/entrypoints/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@aztec/protocol-contracts": "workspace:^",
"@aztec/stdlib": "workspace:^",
"tslib": "^2.4.0",
"zod": "^3.23.8"
"zod": "^4"
},
"devDependencies": {
"@jest/globals": "^30.0.0",
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/epoch-cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"jest-mock-extended": "^4.0.0",
"tslib": "^2.4.0",
"viem": "npm:@aztec/viem@2.38.2",
"zod": "^3.23.8"
"zod": "^4"
},
"devDependencies": {
"@jest/globals": "^30.0.0",
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"lodash.pickby": "^4.5.0",
"tslib": "^2.4.0",
"viem": "npm:@aztec/viem@2.38.2",
"zod": "^3.23.8"
"zod": "^4"
},
"devDependencies": {
"@jest/globals": "^30.0.0",
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/foundation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
"pino-pretty": "^13.0.0",
"sha3": "^2.1.4",
"undici": "^5.28.5",
"zod": "^3.23.8"
"zod": "^4"
},
"devDependencies": {
"@jest/globals": "^30.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ CheckpointNumber.INITIAL = CheckpointNumber(1);
function makeCheckpointNumberSchema(minValue: number) {
return z
.union([z.number(), z.bigint(), z.string()])
.pipe(z.coerce.number().int().min(minValue))
.pipe(z.coerce.number<string | number | bigint>().int().min(minValue))
.transform(value => CheckpointNumber(value));
}

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/foundation/src/branded-types/epoch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,5 @@ EpochNumber.ZERO = EpochNumber(0);
*/
export const EpochNumberSchema = z
.union([z.number(), z.bigint(), z.string()])
.pipe(z.coerce.number().int().min(0))
.pipe(z.coerce.number<string | number | bigint>().int().min(0))
.transform(value => EpochNumber(value));
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,5 @@ IndexWithinCheckpoint.ZERO = IndexWithinCheckpoint(0);
*/
export const IndexWithinCheckpointSchema = z
.union([z.number(), z.bigint(), z.string()])
.pipe(z.coerce.number().int().min(0))
.pipe(z.coerce.number<string | number | bigint>().int().min(0))
.transform(value => IndexWithinCheckpoint(value));
2 changes: 1 addition & 1 deletion yarn-project/foundation/src/branded-types/slot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@ SlotNumber.ZERO = SlotNumber(0);
*/
export const SlotNumberSchema = z
.union([z.number(), z.bigint(), z.string()])
.pipe(z.coerce.number().int().min(0))
.pipe(z.coerce.number<string | number | bigint>().int().min(0))
.transform(value => SlotNumber(value));
2 changes: 1 addition & 1 deletion yarn-project/foundation/src/config/secret_value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class SecretValue<T> {
/**
* Returns a Zod schema
*/
static schema<O>(valueSchema: ZodType<O, any, any>): ZodType<SecretValue<O>, any, any> {
static schema<O>(valueSchema: ZodType<O, any>): ZodType<SecretValue<O>, any> {
return valueSchema.transform(value => new SecretValue<O>(value));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ interface TestService {
}

const schema: ApiSchemaFor<TestService> = {
setValue: z.function().args(z.string()).returns(z.string()),
getValue: z.function().args().returns(z.string().optional()),
badReturn: z.function().args().returns(z.number()),
setValue: z.function({ input: z.tuple([z.string()]), output: z.string() }),
getValue: z.function({ input: z.tuple([]), output: z.string().optional() }),
badReturn: z.function({ input: z.tuple([]), output: z.number() }),
};

describe('SafeJsonRpcClient', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { format } from 'util';

import { type Logger, createLogger } from '../../log/pino-logger.js';
import { type PromiseWithResolvers, promiseWithResolvers } from '../../promise/utils.js';
import { type ApiSchema, type ApiSchemaFor, schemaHasMethod } from '../../schemas/api.js';
import { type ApiSchema, type ApiSchemaFor, getSchemaReturnType, schemaHasMethod } from '../../schemas/api.js';
import { jsonStringify } from '../convert.js';
import { type JsonRpcFetch, defaultFetch } from './fetch.js';

Expand Down Expand Up @@ -236,7 +236,7 @@ export function createSafeJsonRpcClient<T extends object>(
if ([null, undefined, 'null', 'undefined'].includes(response.result)) {
return;
}
return (schema as ApiSchema)[methodName].returnType().parseAsync(response.result);
return getSchemaReturnType((schema as ApiSchema)[methodName]).parseAsync(response.result);
};

const clientId = nextClientId++;
Expand Down
20 changes: 10 additions & 10 deletions yarn-project/foundation/src/json-rpc/fixtures/test_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ export class TestState implements TestStateApi {
}

export const TestStateSchema: ApiSchemaFor<TestStateApi> = {
getNote: z.function().args(z.number()).returns(TestNote.schema.optional()),
getNotes: z.function().args(optional(schemas.Integer)).returns(z.array(TestNote.schema)),
getNotes2: z.function().args(optional(schemas.BigInt)).returns(z.array(TestNote.schema)),
getNotes3: z.function().args(optional(schemas.Integer)).returns(z.array(TestNote.schema)),
clear: z.function().returns(z.void()),
addNotes: z.function().args(z.array(TestNote.schema)).returns(z.array(TestNote.schema)),
fail: z.function().returns(z.void()),
count: z.function().returns(z.number()),
getStatus: z.function().returns(z.object({ status: z.string(), count: schemas.BigInt })),
getTuple: z.function().returns(z.tuple([z.string(), optional(z.string()), z.number()])),
getNote: z.function({ input: z.tuple([z.number()]), output: TestNote.schema.optional() }),
getNotes: z.function({ input: z.tuple([optional(schemas.Integer)]), output: z.array(TestNote.schema) }),
getNotes2: z.function({ input: z.tuple([optional(schemas.BigInt)]), output: z.array(TestNote.schema) }),
getNotes3: z.function({ input: z.tuple([optional(schemas.Integer)]), output: z.array(TestNote.schema) }),
clear: z.function({ input: z.tuple([]), output: z.void() }),
addNotes: z.function({ input: z.tuple([z.array(TestNote.schema)]), output: z.array(TestNote.schema) }),
fail: z.function({ input: z.tuple([]), output: z.void() }),
count: z.function({ input: z.tuple([]), output: z.number() }),
getStatus: z.function({ input: z.tuple([]), output: z.object({ status: z.string(), count: schemas.BigInt }) }),
getTuple: z.function({ input: z.tuple([]), output: z.tuple([z.string(), optional(z.string()), z.number()]) }),
};
Loading
Loading