@nori-zk/proof-conversion
Version:
Verifying zkVM proofs inside o1js circuits, to generate Mina compatible proof
68 lines (67 loc) • 2.59 kB
TypeScript
import { ComputationalPlanExecutor } from '../compute/executor.js';
import { SchemaNode } from './validation/guards/index.js';
/**
* Overload 1: ApiMethod with positional argument support (supportsArgs = true).
*
* Returns a decorator that adds a `fromArgs` function for converting ordered arguments into the input object.
*
* @param schema - Validation schema defining expected input structure
* @param supportsArgs - Must be true for this overload
* @param keys - Ordered array of input keys (must match schema keys in same order)
* @returns Decorator that enhances API methods with schema and fromArgs converter
*
* @example
* const decorator = ApiMethod(
* { proof: isProof, vk: isVK, publicInputs: isInputs },
* true,
* ['proof', 'vk', 'publicInputs'] as const
* );
*
* const convert = decorator(async (executor, input) => {
* return { result: input.proof };
* });
*
* // Convert positional args to input object
* const input = convert.fromArgs(proofData, vkData, inputsData);
* await convert(executor, input);
*/
export declare function ApiMethod<TInput, Schema extends {
[K in keyof TInput]: SchemaNode;
}, TKeys extends readonly (keyof TInput)[]>(schema: Schema, supportsArgs: true, keys: TKeys): <F extends (executor: ComputationalPlanExecutor, input: TInput) => Promise<object>>(fn: F) => F & {
fromArgs: ((...args: {
[I in keyof TKeys]: TInput[TKeys[I] & keyof TInput];
}) => TInput) & {
keys: TKeys;
};
schema: Schema;
};
/**
* Overload 2: ApiMethod without argument support (supportsArgs = false).
*
* Returns a decorator that only attaches the schema, with fromArgs set to false.
*
* @param schema - Validation schema defining expected input structure
* @param supportsArgs - Must be false for this overload
* @param keys - Unused (should be undefined)
* @returns Decorator that enhances API methods with schema only
*
* @example
* const decorator = ApiMethod(
* { config: isConfig, options: isOptions },
* false
* );
*
* const process = decorator(async (executor, input) => {
* return { result: input.config };
* });
*
* // Must use object form, no fromArgs
* await process(executor, { config: configData, options: optionsData });
* console.log(process.fromArgs); // false
*/
export declare function ApiMethod<TInput, Schema extends {
[K in keyof TInput]: SchemaNode;
}>(schema: Schema, supportsArgs: false, keys?: undefined): <F extends (executor: ComputationalPlanExecutor, input: TInput) => Promise<object>>(fn: F) => F & {
fromArgs: false;
schema: Schema;
};