wowok
Version:
Wowok Blockchain TypeScript API
23 lines (22 loc) • 1.34 kB
TypeScript
import type { BcsType } from "../_deps/bcs/index.js";
export type BasePureType = "u8" | "u16" | "u32" | "u64" | "u128" | "u256" | "bool" | "id" | "string" | "address";
interface PureShapeByType {
u8: number;
u16: number;
u32: number;
u64: bigint | string | number;
u128: bigint | string | number;
u256: bigint | string | number;
bool: boolean;
string: string;
id: string | Uint8Array;
address: string | Uint8Array;
}
export type PureTypeName = BasePureType | `vector<${string}>` | `option<${string}>`;
export type ValidPureTypeName<T extends string> = T extends BasePureType ? PureTypeName : T extends `vector<${infer U}>` ? ValidPureTypeName<U> : T extends `option<${infer U}>` ? ValidPureTypeName<U> : PureTypeValidationError<T>;
export type ShapeFromPureTypeName<T extends PureTypeName> = T extends BasePureType ? PureShapeByType[T] : T extends `vector<${infer U extends PureTypeName}>` ? ShapeFromPureTypeName<U>[] : T extends `option<${infer U extends PureTypeName}>` ? ShapeFromPureTypeName<U> | null : never;
type PureTypeValidationError<T extends string> = {
error: `Invalid Pure type name: ${T}`;
} & {};
export declare function pureBcsSchemaFromTypeName<T extends PureTypeName>(name: T extends PureTypeName ? ValidPureTypeName<T> : T): BcsType<ShapeFromPureTypeName<T>>;
export {};