mina-attestations
Version:
Private Attestations on Mina
40 lines (39 loc) • 1.6 kB
TypeScript
import type { ProvableType } from 'o1js';
import type { z } from 'zod';
import type { Constructor } from './types.ts';
export { ProvableFactory, type SerializedFactory };
type ProvableConstructor<T = any, V = any> = Constructor<T> & ProvableType<T, V>;
/**
* Standard interface for polymorphic provable type that can be serialized.
*/
type ProvableFactory<N extends string = string, T = any, V = any> = ((...args: any) => ProvableConstructor<T, V>) & {
name: N;
Base: Constructor<T>;
};
type Serializer<A extends ProvableConstructor = ProvableConstructor, S extends Serialized = Serialized, V = any> = {
typeSchema: z.ZodType<S>;
valueSchema: z.ZodType<V>;
typeToJSON(constructor: A): S;
typeFromJSON(json: S): A;
valueToJSON(type: A, value: InstanceType<A>): V;
valueFromJSON(type: A, json: V): InstanceType<A>;
};
type SerializedFactory = {
_type: string;
_isFactory: true;
} & Serialized;
type Serialized = Record<string, any>;
type MapValue = {
base: Constructor;
} & Serializer;
declare const ProvableFactory: {
register<A extends ProvableFactory, S extends Serialized, V>(name: string, factory: A, serialize: Serializer<ReturnType<A>, S, V>): void;
getRegistered(value: unknown): [string, MapValue] | undefined;
tryToJSON(constructor: unknown): SerializedFactory | undefined;
tryValueToJSON(value: unknown): (SerializedFactory & {
value: any;
}) | undefined;
isSerialized(json: unknown): json is SerializedFactory;
fromJSON(json: unknown): Constructor & ProvableType;
valueFromJSON(json: unknown): any;
};