Skip to content

Commit

Permalink
fix(providers): fix validation and add sample data
Browse files Browse the repository at this point in the history
  • Loading branch information
martonmoro committed Nov 28, 2024
1 parent eeec05e commit b4cf2f7
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 4 deletions.
134 changes: 134 additions & 0 deletions apps/docs/src/components/sample-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,137 @@ export const samplePresentationRequestHttps = {
action: "POST /api/verify",
},
};

export const samplePresentationRequestHttpsRecrusiveNoContext = {
type: "no-context",
spec: {
inputs: {
provedData: {
type: "credential",
credentialType: "recursive",
witness: {
type: { type: "Constant", value: "recursive" },
vk: { _type: "VerificationKey" },
proof: {
_type: "Proof",
proof: {
name: "InputProof",
publicInput: {
_type: "Struct",
properties: {
context: { _type: "Field" },
claims: {
inputOwner: { _type: "PublicKey" },
data: {
age: { _type: "Field" },
name: { _type: "Bytes", size: 32 },
},
},
},
},
publicOutput: {
_type: "Struct",
properties: {
owner: { _type: "PublicKey" },
data: {
age: { _type: "Field" },
name: { _type: "Bytes", size: 32 },
},
},
},
maxProofsVerified: 0,
featureFlags: {
rangeCheck0: false,
rangeCheck1: false,
foreignFieldAdd: false,
foreignFieldMul: false,
xor: false,
rot: false,
lookup: false,
runtimeTables: false,
},
},
},
},
data: {
_type: "Struct",
properties: {
age: { _type: "Field" },
name: { _type: "Bytes", size: 32 },
},
},
},
targetAge: { type: "claim", data: { _type: "Field" } },
targetName: {
type: "constant",
data: { _type: "Bytes", size: 32 },
value:
"416c696365000000000000000000000000000000000000000000000000000000",
},
},
logic: {
assert: {
type: "and",
inputs: [
{
type: "equals",
left: {
type: "property",
key: "age",
inner: {
type: "property",
key: "data",
inner: {
type: "property",
key: "provedData",
inner: { type: "root" },
},
},
},
right: {
type: "property",
key: "targetAge",
inner: { type: "root" },
},
},
{
type: "equals",
left: {
type: "property",
key: "name",
inner: {
type: "property",
key: "data",
inner: {
type: "property",
key: "provedData",
inner: { type: "root" },
},
},
},
right: {
type: "property",
key: "targetName",
inner: { type: "root" },
},
},
],
},
outputClaim: {
type: "property",
key: "age",
inner: {
type: "property",
key: "data",
inner: {
type: "property",
key: "provedData",
inner: { type: "root" },
},
},
},
},
},
claims: { targetAge: { _type: "Field", value: "18" } },
inputContext: null,
};
8 changes: 4 additions & 4 deletions apps/docs/src/components/test-zkapp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useLocalStorage, useObjectState } from "@uidotdev/usehooks";
import { clsx } from "clsx";
import { useState, useSyncExternalStore } from "react";
import {
sampleCredentialSimpleFromExample,
samplePresentationRequestHttps,
sampleCredentialSimple,
samplePresentationRequestHttpsRecrusiveNoContext,
} from "./sample-data";

const store = createStore();
Expand All @@ -24,10 +24,10 @@ export const TestZkApp = () => {
const [signFieldsWithPassphraseInput, setSignFieldsWithPassphraseInput] =
useState(JSON.stringify(sampleSignFieldsWithPassphrase, null, 2));
const [credentialInput, setCredentialInput] = useState(
JSON.stringify(sampleCredentialSimpleFromExample, null, 2),
JSON.stringify(sampleCredentialSimple, null, 2),
);
const [presentationRequest, setPresentationRequest] = useState(
JSON.stringify(samplePresentationRequestHttps, null, 2),
JSON.stringify(samplePresentationRequestHttpsRecrusiveNoContext, null, 2),
);
const [transactionBody, setTransactionBody] = useObjectState({
to: "B62qnVUL6A53E4ZaGd3qbTr6RCtEZYTu3kTijVrrquNpPo4d3MuJ3nb",
Expand Down
6 changes: 6 additions & 0 deletions packages/utils/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ const SerializedTypeSchema: z.ZodType<SerializedType> = z.lazy(() =>
size: z.number(),
})
.strict(),
z
.object({
_type: z.literal('Struct'),
properties: z.record(SerializedTypeSchema),
})
.strict(),
// Allow records of nested types for Struct
z.record(SerializedTypeSchema),
]),
Expand Down

0 comments on commit b4cf2f7

Please sign in to comment.