/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; /** * The intended use of the key. 'sig' for signature, 'enc' for encryption. */ export const Use = { Sig: "sig", Enc: "enc", } as const; /** * The intended use of the key. 'sig' for signature, 'enc' for encryption. */ export type Use = ClosedEnum; /** * Describes an [RFC7517](https://datatracker.ietf.org/doc/html/rfc7517) web key. */ export type JSONWebKey = { /** * The cryptographic algorithm family used with the key (e.g., 'RSA', 'EC', 'oct'). */ kty: string; /** * The intended use of the key. 'sig' for signature, 'enc' for encryption. */ use?: Use | undefined; /** * The permitted operations for the key, e.g., 'sign', 'verify', 'encrypt', 'decrypt'. */ keyOps?: Array | undefined; /** * The algorithm intended for use with the key, e.g., 'RS256' or 'ES256'. */ alg?: string | undefined; /** * A unique identifier for the key. */ kid?: string | undefined; /** * The curve for Elliptic Curve keys, e.g., 'P-256', 'P-384', or 'P-521'. * * @remarks * * This field is required when `kty` is 'EC'. */ crv?: string | undefined; /** * The x coordinate for Elliptic Curve keys. * * @remarks * * This field is required when `kty` is 'EC'. */ x?: string | undefined; /** * The y coordinate for Elliptic Curve keys. * * @remarks * * This field is required when `kty` is 'EC'. */ y?: string | undefined; /** * The modulus value for RSA keys. * * @remarks * * This field is required when `kty` is 'RSA'. */ n?: string | undefined; /** * The exponent value for RSA keys. * * @remarks * * This field is required when `kty` is 'RSA'. */ e?: string | undefined; }; /** @internal */ export const Use$inboundSchema: z.ZodNativeEnum = z.nativeEnum(Use); /** @internal */ export const Use$outboundSchema: z.ZodNativeEnum = Use$inboundSchema; /** @internal */ export const JSONWebKey$inboundSchema: z.ZodType< JSONWebKey, z.ZodTypeDef, unknown > = z.object({ kty: z.string(), use: Use$inboundSchema.optional(), key_ops: z.array(z.string()).optional(), alg: z.string().optional(), kid: z.string().optional(), crv: z.string().optional(), x: z.string().optional(), y: z.string().optional(), n: z.string().optional(), e: z.string().optional(), }).transform((v) => { return remap$(v, { "key_ops": "keyOps", }); }); /** @internal */ export type JSONWebKey$Outbound = { kty: string; use?: string | undefined; key_ops?: Array | undefined; alg?: string | undefined; kid?: string | undefined; crv?: string | undefined; x?: string | undefined; y?: string | undefined; n?: string | undefined; e?: string | undefined; }; /** @internal */ export const JSONWebKey$outboundSchema: z.ZodType< JSONWebKey$Outbound, z.ZodTypeDef, JSONWebKey > = z.object({ kty: z.string(), use: Use$outboundSchema.optional(), keyOps: z.array(z.string()).optional(), alg: z.string().optional(), kid: z.string().optional(), crv: z.string().optional(), x: z.string().optional(), y: z.string().optional(), n: z.string().optional(), e: z.string().optional(), }).transform((v) => { return remap$(v, { keyOps: "key_ops", }); }); export function jsonWebKeyToJSON(jsonWebKey: JSONWebKey): string { return JSON.stringify(JSONWebKey$outboundSchema.parse(jsonWebKey)); } export function jsonWebKeyFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => JSONWebKey$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'JSONWebKey' from JSON`, ); }