diff --git a/packages/client-rpc/src/protocol.ts b/packages/client-rpc/src/protocol.ts index 582c0d5..8a56392 100644 --- a/packages/client-rpc/src/protocol.ts +++ b/packages/client-rpc/src/protocol.ts @@ -36,7 +36,7 @@ export type ParcnetRPCMethodName = | `pod.${keyof typeof ParcnetRPCSchema.pod}` | `identity.${keyof typeof ParcnetRPCSchema.identity}`; -export const RPCMessageSchema = v.union([ +export const RPCMessageSchema = v.variant("type", [ v.object({ type: v.literal(RPCMessageType.PARCNET_CLIENT_INVOKE), serial: v.number(), @@ -70,7 +70,7 @@ export const RPCMessageSchema = v.union([ }) ]); -export const InitializationMessageSchema = v.union([ +export const InitializationMessageSchema = v.variant("type", [ v.object({ type: v.literal(InitializationMessageType.PARCNET_CLIENT_CONNECT), zapp: ZappSchema diff --git a/packages/client-rpc/src/schema.ts b/packages/client-rpc/src/schema.ts index 33e0875..0f7fc94 100644 --- a/packages/client-rpc/src/schema.ts +++ b/packages/client-rpc/src/schema.ts @@ -3,7 +3,7 @@ import type { Groth16Proof } from "snarkjs"; import * as v from "valibot"; import type { ParcnetRPC } from "./rpc_interfaces.js"; -const PODValueSchema = v.union([ +const PODValueSchema = v.variant("type", [ v.object({ type: v.literal("string"), value: v.string() @@ -24,7 +24,7 @@ const PODValueSchema = v.union([ const PODEntriesSchema = v.record(v.string(), PODValueSchema); -const DefinedEntrySchema = v.union([ +const DefinedEntrySchema = v.variant("type", [ v.object({ type: v.literal("string"), isMemberOf: v.optional(v.array(PODValueSchema)), @@ -66,7 +66,10 @@ const OptionalEntrySchema = v.object({ innerType: DefinedEntrySchema }); -const EntrySchema = v.union([DefinedEntrySchema, OptionalEntrySchema]); +const EntrySchema = v.variant("type", [ + DefinedEntrySchema, + OptionalEntrySchema +]); const PODTupleSchema = v.object({ entries: v.array(v.string()), @@ -113,7 +116,7 @@ const PodspecProofRequestSchema = v.object({ watermark: v.optional(PODValueSchema) }); -const ProveResultSchema = v.union([ +const ProveResultSchema = v.variant("success", [ v.object({ success: v.literal(true), // TODO: More specific schemas for these