diff --git a/src/frontend/src/flows/verifiableCredentials/postMessageInterface.ts b/src/frontend/src/flows/verifiableCredentials/postMessageInterface.ts index 0ee2f82d33..bd08adcbab 100644 --- a/src/frontend/src/flows/verifiableCredentials/postMessageInterface.ts +++ b/src/frontend/src/flows/verifiableCredentials/postMessageInterface.ts @@ -7,19 +7,17 @@ export const VcFlowReady = { method: "vc-flow-ready", }; -const zodPrincipal = z.custom((val) => { - if (typeof val !== "string") { - return false; - } +const zodPrincipal = z.string().transform((val, ctx) => { let principal; try { principal = Principal.fromText(val); } catch { - return false; + ctx.addIssue({ code: z.ZodIssueCode.custom, message: "Not a principal " }); + return z.NEVER; } return principal; -}, "expected principal"); +}); // https://www.jsonrpc.org/specification // https://github.com/dfinity/internet-identity/blob/vc-mvp/docs/vc-spec.md#identity-provider-api @@ -41,7 +39,10 @@ export const VcFlowRequest = z.object({ }), }); -export type VcFlowRequest = z.infer; + +// The wire format of a VC flow request +export type VcFlowRequestWire = z.input; +export type VcFlowRequest = z.output; export type VcVerifiablePresentation = { id: VcFlowRequest["id"]; diff --git a/src/showcase/src/pages/vc-test-app.astro b/src/showcase/src/pages/vc-test-app.astro index 20048f04bd..d2b303bbc7 100644 --- a/src/showcase/src/pages/vc-test-app.astro +++ b/src/showcase/src/pages/vc-test-app.astro @@ -15,7 +15,7 @@ import Layout from "../layouts/Layout.astro"; import { toast } from "$src/components/toast"; import { createRef, ref } from "lit-html/directives/ref.js"; import { withRef } from "$src/utils/lit-html"; - import { VcFlowRequest } from "$src/flows/verifiableCredentials/postMessageInterface"; + import { VcFlowRequestWire } from "$src/flows/verifiableCredentials/postMessageInterface"; import { decodeJwt } from "jose"; const inferDefaultIIURL = () => { @@ -66,7 +66,7 @@ import Layout from "../layouts/Layout.astro"; }, credentialSubject: principal, }, - } satisfies VcFlowRequest, + } satisfies VcFlowRequestWire, ii.latest.origin ); }