diff --git a/apps/docs/src/components/sample-data.ts b/apps/docs/src/components/sample-data.ts index 760eeb0..1a960ec 100644 --- a/apps/docs/src/components/sample-data.ts +++ b/apps/docs/src/components/sample-data.ts @@ -392,107 +392,114 @@ export const sampleCredentialRecursive = { }; export const samplePresentationRequestZkApp = { - type: "zk-app", - spec: { - inputs: { - data: { - type: "credential", - credentialType: "simple", - witness: { - type: { type: "Constant", value: "simple" }, - issuer: { _type: "PublicKey" }, - issuerSignature: { _type: "Signature" }, - }, + presentationRequest: { + type: "zk-app", + spec: { + inputs: { data: { - person: { - age: { _type: "Field" }, - name: { _type: "Bytes", size: 32 }, + type: "credential", + credentialType: "simple", + witness: { + type: { type: "Constant", value: "simple" }, + issuer: { _type: "PublicKey" }, + issuerSignature: { _type: "Signature" }, + }, + data: { + person: { + age: { _type: "Field" }, + name: { _type: "Bytes", size: 32 }, + }, + points: { _type: "Field" }, }, - points: { _type: "Field" }, }, - }, - targetAge: { type: "claim", data: { _type: "Field" } }, - targetPoints: { type: "claim", data: { _type: "Field" } }, - }, - logic: { - assert: { - type: "and", - inputs: [ - { - type: "equals", - left: { - type: "property", - key: "age", - inner: { + targetAge: { type: "claim", data: { _type: "Field" } }, + targetPoints: { type: "claim", data: { _type: "Field" } }, + }, + logic: { + assert: { + type: "and", + inputs: [ + { + type: "equals", + left: { type: "property", - key: "person", + key: "age", inner: { type: "property", - key: "data", + key: "person", inner: { type: "property", key: "data", - inner: { type: "root" }, + inner: { + type: "property", + key: "data", + inner: { type: "root" }, + }, }, }, }, + right: { + type: "property", + key: "targetAge", + inner: { type: "root" }, + }, }, - right: { - type: "property", - key: "targetAge", - inner: { type: "root" }, - }, - }, - { - type: "equals", - left: { - type: "property", - key: "points", - inner: { + { + type: "equals", + left: { type: "property", - key: "data", + key: "points", inner: { type: "property", key: "data", - inner: { type: "root" }, + inner: { + type: "property", + key: "data", + inner: { type: "root" }, + }, }, }, + right: { + type: "property", + key: "targetPoints", + inner: { type: "root" }, + }, }, - right: { - type: "property", - key: "targetPoints", - inner: { type: "root" }, - }, - }, - ], - }, - outputClaim: { - type: "property", - key: "name", - inner: { + ], + }, + outputClaim: { type: "property", - key: "person", + key: "name", inner: { type: "property", - key: "data", - inner: { type: "property", key: "data", inner: { type: "root" } }, + key: "person", + inner: { + type: "property", + key: "data", + inner: { type: "property", key: "data", inner: { type: "root" } }, + }, }, }, }, }, - }, - claims: { - targetAge: { _type: "Field", value: "25" }, - targetPoints: { _type: "Field", value: "100" }, - }, - inputContext: { - type: "zk-app", - serverNonce: { - _type: "Field", - value: - "13282950667393837968514931367603124110006503770513488711847457500412027340795", + claims: { + targetAge: { _type: "Field", value: "25" }, + targetPoints: { _type: "Field", value: "100" }, + }, + inputContext: { + type: "zk-app", + serverNonce: { + _type: "Field", + value: + "13282950667393837968514931367603124110006503770513488711847457500412027340795", + }, + action: { _type: "Field", value: "123" }, }, - action: { _type: "Field", value: "123" }, + }, + zkAppAccount: { + address: "B62qiV4KJMMfAuUCs1b8T3RMRJrLk3paXcEPkLz9jbga1zKP782NmBA", + tokenId: "1", + network: "mainnet", }, }; @@ -728,204 +735,226 @@ export const samplePresentationRequestHttpsRecrusiveNoContext = { }; export const samplePresentationRequestHttpsFromExample = { - type: "https", - spec: { - inputs: { - credential: { - type: "credential", - credentialType: "simple", - witness: { - type: { type: "Constant", value: "simple" }, - issuer: { _type: "PublicKey" }, - issuerSignature: { _type: "Signature" }, - }, - data: { - _type: "DynamicRecord", - maxEntries: 20, - knownShape: { - nationality: { - _type: "DynamicString", - maxLength: 50, - _isFactory: true, + presentationRequest: { + type: "https", + spec: { + inputs: { + credential: { + type: "credential", + credentialType: "simple", + witness: { + type: { type: "Constant", value: "simple" }, + issuer: { _type: "PublicKey" }, + issuerSignature: { _type: "Signature" }, + }, + data: { + _type: "DynamicRecord", + maxEntries: 20, + knownShape: { + nationality: { + _type: "DynamicString", + maxLength: 50, + _isFactory: true, + }, + expiresAt: { _type: "UInt64" }, + id: { _type: "Bytes", size: 16 }, }, - expiresAt: { _type: "UInt64" }, - id: { _type: "Bytes", size: 16 }, + _isFactory: true, }, - _isFactory: true, }, - }, - acceptedNations: { - type: "claim", - data: { - _type: "DynamicArray", - maxLength: 100, - innerType: { _type: "Field" }, - _isFactory: true, + signedData: { + type: "credential", + credentialType: "simple", + witness: { + type: { type: "Constant", value: "simple" }, + issuer: { _type: "PublicKey" }, + issuerSignature: { _type: "Signature" }, + }, + data: { age: { _type: "Field" }, name: { _type: "Bytes", size: 32 } }, }, - }, - acceptedIssuers: { - type: "claim", - data: { - _type: "DynamicArray", - maxLength: 100, - innerType: { _type: "Field" }, - _isFactory: true, + signedData1: { + type: "credential", + credentialType: "simple", + witness: { + type: { type: "Constant", value: "simple" }, + issuer: { _type: "PublicKey" }, + issuerSignature: { _type: "Signature" }, + }, + data: { age: { _type: "Field" }, name: { _type: "Bytes", size: 32 } }, + }, + acceptedNations: { + type: "claim", + data: { + _type: "DynamicArray", + maxLength: 100, + innerType: { _type: "Field" }, + _isFactory: true, + }, + }, + acceptedIssuers: { + type: "claim", + data: { + _type: "DynamicArray", + maxLength: 100, + innerType: { _type: "Field" }, + _isFactory: true, + }, + }, + currentDate: { type: "claim", data: { _type: "UInt64" } }, + appId: { + type: "claim", + data: { _type: "DynamicString", maxLength: 50, _isFactory: true }, }, }, - currentDate: { type: "claim", data: { _type: "UInt64" } }, - appId: { - type: "claim", - data: { _type: "DynamicString", maxLength: 50, _isFactory: true }, - }, - }, - logic: { - assert: { - type: "and", - inputs: [ - { - type: "equalsOneOf", - input: { + logic: { + assert: { + type: "and", + inputs: [ + { + type: "equalsOneOf", + input: { + type: "hash", + inputs: [ + { + type: "property", + key: "nationality", + inner: { + type: "property", + key: "data", + inner: { + type: "property", + key: "credential", + inner: { type: "root" }, + }, + }, + }, + ], + prefix: null, + }, + options: { + type: "property", + key: "acceptedNations", + inner: { type: "root" }, + }, + }, + { + type: "equalsOneOf", + input: { type: "issuer", credentialKey: "credential" }, + options: { + type: "property", + key: "acceptedIssuers", + inner: { type: "root" }, + }, + }, + { + type: "lessThanEq", + left: { + type: "property", + key: "currentDate", + inner: { type: "root" }, + }, + right: { + type: "property", + key: "expiresAt", + inner: { + type: "property", + key: "data", + inner: { + type: "property", + key: "credential", + inner: { type: "root" }, + }, + }, + }, + }, + ], + }, + outputClaim: { + type: "record", + data: { + nullifier: { type: "hash", inputs: [ { type: "property", - key: "nationality", + key: "data", inner: { type: "property", - key: "data", - inner: { - type: "property", - key: "credential", - inner: { type: "root" }, - }, + key: "credential", + inner: { type: "root" }, }, }, + { type: "property", key: "appId", inner: { type: "root" } }, ], prefix: null, }, - options: { - type: "property", - key: "acceptedNations", - inner: { type: "root" }, - }, }, + }, + }, + }, + claims: { + acceptedNations: { + _type: "DynamicArray", + maxLength: 100, + innerType: { _type: "Field" }, + value: [ { - type: "equalsOneOf", - input: { type: "issuer", credentialKey: "credential" }, - options: { - type: "property", - key: "acceptedIssuers", - inner: { type: "root" }, - }, + _type: "Field", + value: + "1535750191209038276491867256345743424918048468505871420482779334664484555622", }, { - type: "lessThanEq", - left: { - type: "property", - key: "currentDate", - inner: { type: "root" }, - }, - right: { - type: "property", - key: "expiresAt", - inner: { - type: "property", - key: "data", - inner: { - type: "property", - key: "credential", - inner: { type: "root" }, - }, - }, - }, + _type: "Field", + value: + "22047996538609280301110666364818369992447508174403408199422649676981322383447", + }, + { + _type: "Field", + value: + "24056497251096418057564183210090983888753346776669738257197194846336719337693", }, ], + _isFactory: true, }, - outputClaim: { - type: "record", - data: { - nullifier: { - type: "hash", - inputs: [ - { - type: "property", - key: "data", - inner: { - type: "property", - key: "credential", - inner: { type: "root" }, - }, - }, - { type: "property", key: "appId", inner: { type: "root" } }, - ], - prefix: null, + acceptedIssuers: { + _type: "DynamicArray", + maxLength: 100, + innerType: { _type: "Field" }, + value: [ + { + _type: "Field", + value: + "22082189595001837884155357954513940807511340516883967417732126879116249560446", }, - }, + { + _type: "Field", + value: + "14379306716720988239391174911726766627815364252811450729810497452764493702952", + }, + { + _type: "Field", + value: + "13289235255715902058177069443910799078901994677003173861989269088691152237602", + }, + ], + _isFactory: true, + }, + currentDate: { _type: "UInt64", value: "1732881510253" }, + appId: { + _type: "DynamicString", + maxLength: 50, + value: "my-app-id:123", + _isFactory: true, }, }, - }, - claims: { - acceptedNations: { - _type: "DynamicArray", - maxLength: 100, - innerType: { _type: "Field" }, - value: [ - { - _type: "Field", - value: - "1535750191209038276491867256345743424918048468505871420482779334664484555622", - }, - { - _type: "Field", - value: - "22047996538609280301110666364818369992447508174403408199422649676981322383447", - }, - { - _type: "Field", - value: - "24056497251096418057564183210090983888753346776669738257197194846336719337693", - }, - ], - _isFactory: true, - }, - acceptedIssuers: { - _type: "DynamicArray", - maxLength: 100, - innerType: { _type: "Field" }, - value: [ - { - _type: "Field", - value: - "22082189595001837884155357954513940807511340516883967417732126879116249560446", - }, - { - _type: "Field", - value: - "14379306716720988239391174911726766627815364252811450729810497452764493702952", - }, - { - _type: "Field", - value: - "13289235255715902058177069443910799078901994677003173861989269088691152237602", - }, - ], - _isFactory: true, - }, - currentDate: { _type: "UInt64", value: "1732881510253" }, - appId: { - _type: "DynamicString", - maxLength: 50, - value: "my-app-id:123", - _isFactory: true, - }, - }, - inputContext: { - type: "https", - serverNonce: { - _type: "Field", - value: - "19727979349943398352101580661888473094612414811013987113443744841719874732783", + inputContext: { + type: "https", + serverNonce: { + _type: "Field", + value: + "19727979349943398352101580661888473094612414811013987113443744841719874732783", + }, + action: "my-app-id:123:authenticate", }, - action: "my-app-id:123:authenticate", }, }; diff --git a/bun.lockb b/bun.lockb index 1a6e5ca..02fe985 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/packages/providers/package.json b/packages/providers/package.json index e5c9f36..a738b97 100644 --- a/packages/providers/package.json +++ b/packages/providers/package.json @@ -16,6 +16,9 @@ "test": "bun test", "cleanup": "rimraf dist .turbo" }, + "dependencies": { + "mina-credentials": "0.2.5" + }, "devDependencies": { "@mina-js/utils": "workspace:*" }, diff --git a/packages/providers/src/validation.ts b/packages/providers/src/validation.ts index 49cb748..d17aa78 100644 --- a/packages/providers/src/validation.ts +++ b/packages/providers/src/validation.ts @@ -4,12 +4,10 @@ import { JsonSchema, NetworkId, NullifierSchema, - PresentationRequestSchema, PublicKeySchema, SignedFieldsSchema, SignedMessageSchema, SignedTransactionSchema, - StoredCredentialSchema, TransactionPayloadSchema, TransactionReceiptSchema, TypedSendableSchema, @@ -18,6 +16,11 @@ import { } from "@mina-js/utils"; import { z } from "zod"; +import { + PresentationRequestSchema, + StoredCredentialSchema, +} from "mina-credentials"; + export const SwitchChainRequestParams = z .object({ networkId: z.string(), @@ -97,14 +100,16 @@ export const GetStateRequestParamsSchema = RequestWithContext.extend({ export const StorePrivateCredentialRequestParamsSchema = RequestWithContext.extend({ method: z.literal("mina_storePrivateCredential"), - params: z.array(StoredCredentialSchema), + // biome-ignore lint/suspicious/noExplicitAny: nested types from mina-credentials + params: z.array(StoredCredentialSchema as z.ZodType), }).strict(); export const PresentationRequestParamsSchema = RequestWithContext.extend({ method: z.literal("mina_requestPresentation"), params: z.array( z .object({ - presentationRequest: PresentationRequestSchema, + // biome-ignore lint/suspicious/noExplicitAny: nested types from mina-credentials + presentationRequest: PresentationRequestSchema as z.ZodType, zkAppAccount: zkAppAccountSchema.optional(), }) .strict(), diff --git a/packages/utils/src/types.ts b/packages/utils/src/types.ts index 525626f..a6d537a 100644 --- a/packages/utils/src/types.ts +++ b/packages/utils/src/types.ts @@ -6,14 +6,12 @@ import type { LiteralSchema, NullifierSchema, PartialTransactionSchema, - PresentationRequestSchema, PrivateKeySchema, PublicKeySchema, SendableSchema, SignedFieldsSchema, SignedMessageSchema, SignedTransactionSchema, - StoredCredentialSchema, TransactionBodySchema, TransactionOrZkAppCommandSchema, TransactionPayloadSchema, @@ -58,5 +56,3 @@ export type KlesiaRpcResponseType = z.infer; /** * Private Credential types */ -export type StoredPrivateCredential = z.infer; -export type PresentationRequest = z.infer; diff --git a/packages/utils/src/validation.ts b/packages/utils/src/validation.ts index 2c661fd..b4ebf88 100644 --- a/packages/utils/src/validation.ts +++ b/packages/utils/src/validation.ts @@ -254,587 +254,8 @@ export const KlesiaRpcResponseSchema = z.union([ ErrorSchema, ]); -// TODO: Should probably move these validations to a separate file - -interface SerializedValue { - _type: string; - value: Json; - properties?: Record; -} - -interface ProofType { - name: string; - publicInput: SerializedType; - publicOutput: SerializedType; - maxProofsVerified: number; - featureFlags: Record; -} - -interface DynamicString { - _type: "DynamicString"; - _isFactory: true; - maxLength: number; - value?: string; -} - -interface DynamicArray { - _type: "DynamicArray"; - _isFactory: true; - maxLength: number; - innerType: SerializedType; - value?: SerializedValue[]; -} - -interface DynamicRecord { - _type: "DynamicRecord"; - _isFactory: true; - maxEntries: number; - knownShape: Record; - value?: Record; -} - -interface DynamicBytes { - _type: "DynamicBytes"; - _isFactory: true; - maxLength: number; - value?: string; // hex string -} - -interface BasicType { - _type: string; -} - -// TODO: type? -interface ConstantType { - type: "Constant"; - value: string; -} - -interface BytesType { - _type: "Bytes"; - size: number; -} - -interface ProofTypeWrapper { - _type: "Proof"; - proof: ProofType; -} - -interface ArrayType { - _type: "Array"; - innerType: SerializedType; - size: number; -} - -interface StructType { - _type: "Struct"; - properties: { [key: string]: SerializedType }; -} - -export type SerializedType = - | BasicType - | ConstantType - | BytesType - | ProofTypeWrapper - | ArrayType - | StructType - | DynamicString - | DynamicArray - | DynamicRecord - | DynamicBytes - | { [key: string]: SerializedType }; - -// Private Credentials: Serialized Type and Value Schemas - -const SerializedValueSchema = z - .object({ - _type: z.string(), - value: JsonSchema, - properties: z.record(z.any()).optional(), - }) - .strict(); - -const SerializedDataValueSchema = z.union([ - SerializedValueSchema, - z.string(), - z.number(), - z.boolean(), -]); - -// Dynamic type schemas -const DynamicTypeBaseSchema = z.object({ - _type: z.string(), - _isFactory: z.literal(true), -}); - -const DynamicStringSchema = DynamicTypeBaseSchema.extend({ - _type: z.literal("DynamicString"), - maxLength: z.number(), - value: z.string().optional(), -}).strict(); - -const DynamicArraySchema = DynamicTypeBaseSchema.extend({ - _type: z.literal("DynamicArray"), - maxLength: z.number(), - innerType: z.lazy(() => SerializedTypeSchema), - value: z.array(SerializedValueSchema).optional(), -}).strict(); - -const DynamicRecordSchema = DynamicTypeBaseSchema.extend({ - _type: z.literal("DynamicRecord"), - maxEntries: z.number(), - knownShape: z.record(z.lazy(() => SerializedTypeSchema)), - value: z.record(SerializedValueSchema).optional(), -}).strict(); - -const DynamicBytesSchema = DynamicTypeBaseSchema.extend({ - _type: z.literal("DynamicBytes"), - maxLength: z.number(), - value: z.string().optional(), // hex string -}).strict(); - -const ProofTypeSchema: z.ZodType = z.lazy(() => - z - .object({ - name: z.string(), - publicInput: SerializedTypeSchema, - publicOutput: SerializedTypeSchema, - maxProofsVerified: z.number(), - featureFlags: z.record(z.any()), - }) - .strict(), -); - -const SerializedTypeSchema: z.ZodType = z.lazy(() => - z.union([ - // Basic type - z - .object({ - _type: z.string(), - }) - .strict(), - // Constant type - z - .object({ - type: z.literal("Constant"), - value: z.string(), - }) - .strict(), - // Bytes type - z - .object({ - _type: z.literal("Bytes"), - size: z.number(), - }) - .strict(), - // Proof type - z - .object({ - _type: z.literal("Proof"), - proof: ProofTypeSchema, - }) - .strict(), - // Array type - z - .object({ - _type: z.literal("Array"), - innerType: SerializedTypeSchema, - size: z.number(), - }) - .strict(), - // Struct type - z - .object({ - _type: z.literal("Struct"), - properties: z.record(SerializedTypeSchema), - }) - .strict(), - // Dynamic types - DynamicStringSchema, - DynamicArraySchema, - DynamicRecordSchema, - DynamicBytesSchema, - // Allow records of nested types for Struct - z.record(SerializedTypeSchema), - ]), -); - -const SerializedFieldSchema = z - .object({ - _type: z.literal("Field"), - value: z.string(), - }) - .strict(); - -const SerializedPublicKeySchema = z - .object({ - _type: z.literal("PublicKey"), - value: z.string(), - }) - .strict(); - -const SerializedPublicKeyTypeSchema = z - .object({ - _type: z.literal("PublicKey"), - }) - .strict(); - -const SerializedSignatureSchema = z - .object({ - _type: z.literal("Signature"), - value: z.object({ - r: z.string(), - s: z.string(), - }), - }) - .strict(); - -// Private Credentials: Node schemas - -export type Node = - | { type: "owner" } - | { type: "issuer"; credentialKey: string } - | { type: "constant"; data: z.infer } - | { type: "root" } - | { type: "property"; key: string; inner: Node } - | { type: "record"; data: Record } - | { type: "equals"; left: Node; right: Node } - | { type: "equalsOneOf"; input: Node; options: Node[] | Node } - | { type: "lessThan"; left: Node; right: Node } - | { type: "lessThanEq"; left: Node; right: Node } - | { type: "add"; left: Node; right: Node } - | { type: "sub"; left: Node; right: Node } - | { type: "mul"; left: Node; right: Node } - | { type: "div"; left: Node; right: Node } - | { type: "and"; inputs: Node[] } - | { type: "or"; left: Node; right: Node } - | { type: "not"; inner: Node } - | { type: "hash"; inputs: Node[]; prefix?: string | null } - | { type: "ifThenElse"; condition: Node; thenNode: Node; elseNode: Node }; - -const NodeSchema: z.ZodType = z.lazy(() => - z.discriminatedUnion("type", [ - z - .object({ - type: z.literal("owner"), - }) - .strict(), - - z - .object({ - type: z.literal("issuer"), - credentialKey: z.string(), - }) - .strict(), - - z - .object({ - type: z.literal("constant"), - data: SerializedValueSchema, - }) - .strict(), - - z - .object({ - type: z.literal("root"), - }) - .strict(), - - z - .object({ - type: z.literal("property"), - key: z.string(), - inner: NodeSchema, - }) - .strict(), - - z - .object({ - type: z.literal("record"), - data: z.record(NodeSchema), - }) - .strict(), - - z - .object({ - type: z.literal("equals"), - left: NodeSchema, - right: NodeSchema, - }) - .strict(), - - z - .object({ - type: z.literal("equalsOneOf"), - input: NodeSchema, - options: z.union([ - z.array(NodeSchema), // For array of nodes case - NodeSchema, - ]), - }) - .strict(), - - z - .object({ - type: z.literal("lessThan"), - left: NodeSchema, - right: NodeSchema, - }) - .strict(), - - z - .object({ - type: z.literal("lessThanEq"), - left: NodeSchema, - right: NodeSchema, - }) - .strict(), - - z - .object({ - type: z.literal("add"), - left: NodeSchema, - right: NodeSchema, - }) - .strict(), - - z - .object({ - type: z.literal("sub"), - left: NodeSchema, - right: NodeSchema, - }) - .strict(), - - z - .object({ - type: z.literal("mul"), - left: NodeSchema, - right: NodeSchema, - }) - .strict(), - - z - .object({ - type: z.literal("div"), - left: NodeSchema, - right: NodeSchema, - }) - .strict(), - - z - .object({ - type: z.literal("and"), - inputs: z.array(NodeSchema), - }) - .strict(), - - z - .object({ - type: z.literal("or"), - left: NodeSchema, - right: NodeSchema, - }) - .strict(), - - z - .object({ - type: z.literal("not"), - inner: NodeSchema, - }) - .strict(), - - z - .object({ - type: z.literal("hash"), - inputs: z.array(NodeSchema), - prefix: z.union([z.string(), z.null()]).optional(), - }) - .strict(), - - z - .object({ - type: z.literal("ifThenElse"), - condition: NodeSchema, - thenNode: NodeSchema, - elseNode: NodeSchema, - }) - .strict(), - ]), -); - -// Private Credentials: Input Schema - -const InputSchema = z.discriminatedUnion("type", [ - z - .object({ - type: z.literal("credential"), - credentialType: z.union([ - z.literal("simple"), - z.literal("unsigned"), - z.literal("recursive"), - ]), - witness: z.union([z.record(SerializedTypeSchema), SerializedTypeSchema]), - data: z.union([z.record(SerializedTypeSchema), SerializedTypeSchema]), - }) - .strict(), - - z - .object({ - type: z.literal("constant"), - data: SerializedTypeSchema, - value: z.union([z.string(), z.record(z.string())]), - }) - .strict(), - - z - .object({ - type: z.literal("claim"), - data: z.union([z.record(SerializedTypeSchema), SerializedTypeSchema]), - }) - .strict(), -]); - -// Private Credentials: Context schemas - -const HttpsContextSchema = z - .object({ - type: z.literal("https"), - action: z.string(), - serverNonce: SerializedFieldSchema, - }) - .strict(); - -const ZkAppContextSchema = z - .object({ - type: z.literal("zk-app"), - action: SerializedFieldSchema, - serverNonce: SerializedFieldSchema, - }) - .strict(); - -const ContextSchema = z.union([HttpsContextSchema, ZkAppContextSchema]); - -// Private Credentials: PresentationRequestSchema - -export const PresentationRequestSchema = z - .object({ - type: z.union([ - z.literal("no-context"), - z.literal("zk-app"), - z.literal("https"), - ]), - spec: z - .object({ - inputs: z.record(InputSchema), - logic: z - .object({ - assert: NodeSchema, - outputClaim: NodeSchema, - }) - .strict(), - }) - .strict(), - claims: z.record( - z.union([ - SerializedValueSchema, - DynamicStringSchema, - DynamicArraySchema, - DynamicRecordSchema, - DynamicBytesSchema, - ]), - ), - inputContext: z.union([ContextSchema, z.null()]), - }) - .strict(); - export const zkAppAccountSchema = z.object({ address: PublicKeySchema, tokenId: z.string(), network: MinaScanNetwork, }); - -// Private Credentials: Witness Schemas - -const SimpleWitnessSchema = z - .object({ - type: z.literal("simple"), - issuer: SerializedPublicKeySchema, - issuerSignature: SerializedSignatureSchema, - }) - .strict(); - -const RecursiveWitnessSchema = z - .object({ - type: z.literal("recursive"), - vk: z - .object({ - data: z.string(), - hash: SerializedFieldSchema, - }) - .strict(), - proof: z - .object({ - _type: z.literal("Proof"), - value: z - .object({ - publicInput: JsonSchema, - publicOutput: JsonSchema, - maxProofsVerified: z.number().min(0).max(2), - proof: z.string(), - }) - .strict(), - }) - .strict(), - }) - .strict(); - -const UnsignedWitnessSchema = z - .object({ - type: z.literal("unsigned"), - }) - .strict(); - -const WitnessSchema = z.discriminatedUnion("type", [ - SimpleWitnessSchema, - RecursiveWitnessSchema, - UnsignedWitnessSchema, -]); - -// Private Credentials: Credential Schemas - -const SimpleCredentialSchema = z - .object({ - owner: SerializedPublicKeySchema, - data: z.record(SerializedDataValueSchema), - }) - .strict(); - -const StructCredentialSchema = z - .object({ - _type: z.literal("Struct"), - properties: z - .object({ - owner: SerializedPublicKeyTypeSchema, - data: JsonSchema, - }) - .strict(), - value: z - .object({ - owner: PublicKeySchema, - data: JsonSchema, - }) - .strict(), - }) - .strict(); - -// Private Credentials: Stored Credential Schema - -export const StoredCredentialSchema = z - .object({ - version: z.literal("v0"), - witness: WitnessSchema, - metadata: JsonSchema.optional(), - credential: z.union([SimpleCredentialSchema, StructCredentialSchema]), - }) - .strict();