import { z } from "zod"; /** * @see https://www.ietf.org/archive/id/draft-ietf-oauth-rar-03.html#name-authorization-data-elements */ export const authorizationDetailsSchema = ( credentialTypesSupported: string[][], ) => z .array( z.object({ format: z.union([z.literal("jwt_vc"), z.literal("jwt_vc_json")], { errorMap: () => ({ message: 'Invalid literal value, expected "jwt_vc" or "jwt_vc_json"', }), }), locations: z.array(z.string().url()).nonempty().optional(), type: z.literal("openid_credential"), types: z .array(z.string()) // Ensures that all the valid credential types are present .refine( (arr) => credentialTypesSupported.some( (types) => arr.toString() === types.toString(), ), { message: `Array must match one of the supported lists of types: ${credentialTypesSupported.map((list) => JSON.stringify(list)).join(" or ")}`, }, ), }), ) .nonempty(); export type AuthorizationDetails = z.infer< ReturnType >;