Skip to content

Commit b4cf2f7

Browse files
committed
fix(providers): fix validation and add sample data
1 parent eeec05e commit b4cf2f7

File tree

3 files changed

+144
-4
lines changed

3 files changed

+144
-4
lines changed

apps/docs/src/components/sample-data.ts

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,3 +592,137 @@ export const samplePresentationRequestHttps = {
592592
action: "POST /api/verify",
593593
},
594594
};
595+
596+
export const samplePresentationRequestHttpsRecrusiveNoContext = {
597+
type: "no-context",
598+
spec: {
599+
inputs: {
600+
provedData: {
601+
type: "credential",
602+
credentialType: "recursive",
603+
witness: {
604+
type: { type: "Constant", value: "recursive" },
605+
vk: { _type: "VerificationKey" },
606+
proof: {
607+
_type: "Proof",
608+
proof: {
609+
name: "InputProof",
610+
publicInput: {
611+
_type: "Struct",
612+
properties: {
613+
context: { _type: "Field" },
614+
claims: {
615+
inputOwner: { _type: "PublicKey" },
616+
data: {
617+
age: { _type: "Field" },
618+
name: { _type: "Bytes", size: 32 },
619+
},
620+
},
621+
},
622+
},
623+
publicOutput: {
624+
_type: "Struct",
625+
properties: {
626+
owner: { _type: "PublicKey" },
627+
data: {
628+
age: { _type: "Field" },
629+
name: { _type: "Bytes", size: 32 },
630+
},
631+
},
632+
},
633+
maxProofsVerified: 0,
634+
featureFlags: {
635+
rangeCheck0: false,
636+
rangeCheck1: false,
637+
foreignFieldAdd: false,
638+
foreignFieldMul: false,
639+
xor: false,
640+
rot: false,
641+
lookup: false,
642+
runtimeTables: false,
643+
},
644+
},
645+
},
646+
},
647+
data: {
648+
_type: "Struct",
649+
properties: {
650+
age: { _type: "Field" },
651+
name: { _type: "Bytes", size: 32 },
652+
},
653+
},
654+
},
655+
targetAge: { type: "claim", data: { _type: "Field" } },
656+
targetName: {
657+
type: "constant",
658+
data: { _type: "Bytes", size: 32 },
659+
value:
660+
"416c696365000000000000000000000000000000000000000000000000000000",
661+
},
662+
},
663+
logic: {
664+
assert: {
665+
type: "and",
666+
inputs: [
667+
{
668+
type: "equals",
669+
left: {
670+
type: "property",
671+
key: "age",
672+
inner: {
673+
type: "property",
674+
key: "data",
675+
inner: {
676+
type: "property",
677+
key: "provedData",
678+
inner: { type: "root" },
679+
},
680+
},
681+
},
682+
right: {
683+
type: "property",
684+
key: "targetAge",
685+
inner: { type: "root" },
686+
},
687+
},
688+
{
689+
type: "equals",
690+
left: {
691+
type: "property",
692+
key: "name",
693+
inner: {
694+
type: "property",
695+
key: "data",
696+
inner: {
697+
type: "property",
698+
key: "provedData",
699+
inner: { type: "root" },
700+
},
701+
},
702+
},
703+
right: {
704+
type: "property",
705+
key: "targetName",
706+
inner: { type: "root" },
707+
},
708+
},
709+
],
710+
},
711+
outputClaim: {
712+
type: "property",
713+
key: "age",
714+
inner: {
715+
type: "property",
716+
key: "data",
717+
inner: {
718+
type: "property",
719+
key: "provedData",
720+
inner: { type: "root" },
721+
},
722+
},
723+
},
724+
},
725+
},
726+
claims: { targetAge: { _type: "Field", value: "18" } },
727+
inputContext: null,
728+
};

apps/docs/src/components/test-zkapp.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { useLocalStorage, useObjectState } from "@uidotdev/usehooks";
33
import { clsx } from "clsx";
44
import { useState, useSyncExternalStore } from "react";
55
import {
6-
sampleCredentialSimpleFromExample,
7-
samplePresentationRequestHttps,
6+
sampleCredentialSimple,
7+
samplePresentationRequestHttpsRecrusiveNoContext,
88
} from "./sample-data";
99

1010
const store = createStore();
@@ -24,10 +24,10 @@ export const TestZkApp = () => {
2424
const [signFieldsWithPassphraseInput, setSignFieldsWithPassphraseInput] =
2525
useState(JSON.stringify(sampleSignFieldsWithPassphrase, null, 2));
2626
const [credentialInput, setCredentialInput] = useState(
27-
JSON.stringify(sampleCredentialSimpleFromExample, null, 2),
27+
JSON.stringify(sampleCredentialSimple, null, 2),
2828
);
2929
const [presentationRequest, setPresentationRequest] = useState(
30-
JSON.stringify(samplePresentationRequestHttps, null, 2),
30+
JSON.stringify(samplePresentationRequestHttpsRecrusiveNoContext, null, 2),
3131
);
3232
const [transactionBody, setTransactionBody] = useObjectState({
3333
to: "B62qnVUL6A53E4ZaGd3qbTr6RCtEZYTu3kTijVrrquNpPo4d3MuJ3nb",

packages/utils/src/validation.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ const SerializedTypeSchema: z.ZodType<SerializedType> = z.lazy(() =>
335335
size: z.number(),
336336
})
337337
.strict(),
338+
z
339+
.object({
340+
_type: z.literal('Struct'),
341+
properties: z.record(SerializedTypeSchema),
342+
})
343+
.strict(),
338344
// Allow records of nested types for Struct
339345
z.record(SerializedTypeSchema),
340346
]),

0 commit comments

Comments
 (0)