UNPKG

minauth

Version:

A TypeScript library for building authentication systems on top of the Mina blockchain and other zero-knowledge proofs solutions.

45 lines (44 loc) 2.09 kB
import { InterfaceKind, WithInterfaceTag, TsInterfaceType, FpInterfaceType, ChooseType } from './interfacekind.js'; import { Either } from 'fp-ts/lib/Either.js'; import * as z from 'zod'; /** * An interface for the decoder concept. * Availble in both idiomatic typescript and functional styles. */ export interface Decoder<InterfaceType extends InterfaceKind, T> extends WithInterfaceTag<InterfaceType> { decode: (_: unknown) => ChooseType<InterfaceType, Either<string, T>, T | undefined>; } /** * Convert a decoder from the idiomatic typescript interface to the functional style. */ export declare const tsToFpDecoder: <T>(tsDec: Decoder<"ts", T>) => Decoder<"fp", T>; /** * An interface for the encoder concept. * Encoding MUST NOT fail. * The returned value MUST serializable via `JSON.stringify`. */ export interface Encoder<InterfaceType extends InterfaceKind, T> extends WithInterfaceTag<InterfaceType> { encode: (_: T) => unknown; } /** * Convert an encoder from the idiomatic typescript interface to the functional style */ export declare const tsToFpEncoder: <T>(tsEnc: Encoder<"ts", T>) => Encoder<"fp", T>; /** A combined encoder and decoder */ export type EncodeDecoder<InterfaceType extends InterfaceKind, T> = Encoder<InterfaceType, T> & Decoder<InterfaceType, T>; /** * This laws should hold */ export declare const __encDecLaw: <T>(input: T, enc: Encoder<"fp", T>, dec: Decoder<"fp", T>) => boolean; /** * This is an encoder that just casts the object using "as unknown" */ export declare const noOpEncoder: <InterfaceType extends InterfaceKind, T>(i: InterfaceType) => Encoder<InterfaceType, T>; /** * Create a decoder out of a zod schema parser */ export declare const wrapZodDec: <InterfaceType extends InterfaceKind, T>(i: InterfaceType, s: z.ZodType<T, z.ZodTypeDef, T>) => Decoder<InterfaceType, T>; /** * Combine a decoder and an encoder into a single object. */ export declare const combineEncDec: <InterfaceType extends InterfaceKind, T>(enc: Encoder<InterfaceType, T>, dec: Decoder<InterfaceType, T>) => EncodeDecoder<InterfaceType, T>;