minauth
Version:
A TypeScript library for building authentication systems on top of the Mina blockchain and other zero-knowledge proofs solutions.
72 lines (71 loc) • 3.08 kB
TypeScript
import { TaskEither } from 'fp-ts/lib/TaskEither.js';
import z from 'zod';
import * as O from 'fp-ts/lib/Option.js';
import { Field } from 'o1js';
/**
* Converts a promise that may resolve into an empty value into
* a TaskEither object that fails with a message if the promise resolves into an empty value
* or is rejected, or throws an exception.
*/
export declare function fromFailablePromise<T>(p: () => Promise<T | undefined>, msg?: string): TaskEither<string, T>;
/**
* Discards the task's return value.
*/
export declare function dropResult<E, T>(t: TaskEither<E, T>): TaskEither<E, void>;
/**
* Lifts zod parsing results into the TaskEither monad.
*/
export declare function liftZodParseResult<I, O>(r: z.SafeParseReturnType<I, O>): TaskEither<string, O>;
/**
* Having found a kv pair in a record by its key it applies given function on the value
* and returns the results.
*/
export declare function getParam<T>(onSome: (param: string) => TaskEither<string, T>): (key: string, params: {
[key: string]: string;
}) => TaskEither<string, T>;
/**
* Safely construct a value from string.
*/
export declare function safeFromString<T>(ctor: (s: string) => T): (s: string) => TaskEither<string, T>;
/**
* Safely retrieve a number from a record.
*/
export declare function safeGetNumberParam(key: string, params: {
[key: string]: string;
}): TaskEither<string, number>;
/**
* Safely retrieve a o1js Field value from a record.
*/
export declare function safeGetFieldParam(key: string, params: {
[key: string]: string;
}): TaskEither<string, Field>;
/**
* Converts a promise that may resolve into an empty value into a TaskEither
* object that fails with a message if the promise resolves into an empty value
* or is rejected, or throws an exception.
*/
export declare function fromFailableIO<A>(f: () => A | undefined, msg?: string): TaskEither<string, A>;
/**
* Converts a TaskEither to a Promise treating its left value as an promise rejection argument.
* and its right value as a promise resolution argument.
*/
export declare const launchTE: <T>(t: TaskEither<string, T>) => Promise<T>;
/**
* Given an assertion and an error stop the task execution when the condition is false.
* All that within TaskEither monad.
*/
export declare const guard: (cond: boolean, msg: string) => TaskEither<string, void>;
/**
* Given an assertion and error it will give function that either
* stops the execution with the error on failed assertion or acts as identity function.
* All that within TaskEither monad.
*/
export declare function guardPassthrough<E>(cond: boolean, err: E): <T>(ret: T) => TaskEither<E, T>;
/**
* Find the first element in the array that satisfies the given predicate.
* @param f A predicate, that can be a failible async action.
* @param arr An array to search.
* @returns A failible async action that returns the first element in the array
* that satisfies the given predicate.
*/
export declare const findM: <T>(f: (x: T) => TaskEither<string, boolean>) => (arr: T[]) => TaskEither<string, O.Option<T>>;