solay
Version:
A powerful layout and serialization library for Solana smart contracts. Enhanced type-safe buffer layout with Solana-specific types support.
90 lines (87 loc) • 5.21 kB
text/typescript
import { PublicKey } from '@solana/web3.js';
import BN from 'bn.js';
import { Layout, UInt, Structure as Structure$1, Union as Union$1, Blob } from './buffer-layout.mjs';
export { BitStructure, GetStructureSchema, LayoutConstructor, bits, blob, cstr, f32, f32be, f64, f64be, greedy, ns64, ns64be, nu64, nu64be, offset, s16, s16be, s24, s24be, s32, s32be, s40, s40be, s48, s48be, s8, u16, u16be, u24, u24be, u32be, u40, u40be, u48, u48be, unionLayoutDiscriminator, utf8 } from './buffer-layout.mjs';
declare class BNLayout<P extends string = ""> extends Layout<BN, P> {
blob: Layout<Buffer>;
signed: boolean;
constructor(span: number, signed: boolean, property?: P);
/** @override */
decode(b: Buffer, offset?: number): BN;
/** @override */
encode(src: BN, b: Buffer, offset?: number): number;
}
declare class WideBits<P extends string = ""> extends Layout<Record<string, boolean>, P> {
_lower: any;
_upper: any;
constructor(property?: P);
addBoolean(property: string): void;
decode(b: Buffer, offset?: number): Record<string, boolean>;
encode(src: any, b: Buffer, offset?: number): any;
}
declare function u8<P extends string = "">(property?: P): UInt<number, P>;
declare function u32<P extends string = "">(property?: P): UInt<number, P>;
declare function u64<P extends string = "">(property?: P): BNLayout<P>;
declare function u128<P extends string = "">(property?: P): BNLayout<P>;
declare function i8<P extends string = "">(property?: P): BNLayout<P>;
declare function i64<P extends string = "">(property?: P): BNLayout<P>;
declare function i128<P extends string = "">(property?: P): BNLayout<P>;
declare class WrappedLayout<T, U, P extends string = ""> extends Layout<U, P> {
layout: Layout<T>;
decoder: (data: T) => U;
encoder: (src: U) => T;
constructor(layout: Layout<T>, decoder: (data: T) => U, encoder: (src: U) => T, property?: P);
decode(b: Buffer, offset?: number): U;
encode(src: U, b: Buffer, offset?: number): number;
getSpan(b: Buffer, offset?: number): number;
}
declare function publicKey<P extends string = "">(property?: P): Layout<PublicKey, P>;
declare class OptionLayout<T, P> extends Layout<T | null, P> {
layout: Layout<T>;
discriminator: Layout<number>;
constructor(layout: Layout<T>, property?: P);
encode(src: T | null, b: Buffer, offset?: number): number;
decode(b: Buffer, offset?: number): T | null;
getSpan(b: Buffer, offset?: number): number;
}
declare function option<T, P extends string = "">(layout: Layout<T>, property?: P): Layout<T | null, P>;
declare function bool<P extends string = "">(property?: P): Layout<boolean, P>;
declare function decodeBool(value: number): boolean;
declare function encodeBool(value: boolean): number;
declare function vec<T, P extends string = "">(elementLayout: Layout<T>, property?: P): Layout<T[], P>;
declare function tagged<T, P extends string = "">(tag: BN, layout: Layout<T>, property?: P): Layout<T, P>;
declare function vecU8<P extends string = "">(property?: P): Layout<Buffer, P>;
declare function str<P extends string = "">(property?: P): Layout<string, P>;
interface EnumLayout<T, P extends string = ""> extends Layout<T, P> {
registry: Record<string, Layout<any>>;
}
declare function rustEnum<T, P extends string = "">(variants: Layout<any>[], property?: P): EnumLayout<T, P>;
declare function array<T, P extends string = "">(elementLayout: Layout<T>, length: number, property?: P): Layout<T[], P>;
declare class Structure<T, P, D extends {
[key: string]: any;
}> extends Structure$1<T, P, D> {
/** @override */
decode(b: Buffer, offset?: number): D;
}
declare function struct<T, P extends string = "">(fields: T, property?: P, decodePrefixes?: boolean): T extends Layout<infer Value, infer Property>[] ? Structure<Value, P, {
[K in Exclude<Extract<Property, string>, "">]: Extract<T[number], Layout<any, K>> extends Layout<infer V, any> ? V : any;
}> : any;
type GetLayoutSchemaFromStructure<T extends Structure<any, any, any>> = T extends Structure<any, any, infer S> ? S : any;
type GetStructureFromLayoutSchema<S extends {
[key: string]: any;
}> = Structure<any, any, S>;
declare class Union<Schema extends {
[key: string]: any;
}> extends Union$1<Schema> {
encodeInstruction(instruction: any): Buffer;
decodeInstruction(instruction: any): Partial<Schema>;
}
declare function union<UnionSchema extends {
[key: string]: any;
} = any>(discr: any, defaultLayout?: any, property?: string): Union<UnionSchema>;
declare class Zeros extends Blob {
decode(b: Buffer, offset: number): Buffer;
}
declare function zeros(length: number): Zeros;
declare function seq<T, P extends string = "", AnotherP extends string = "">(elementLayout: Layout<T, P>, count: number | BN | Layout<BN | number, P>, property?: AnotherP): Layout<T[], AnotherP>;
export { BNLayout, Blob, type EnumLayout, type GetLayoutSchemaFromStructure, type GetStructureFromLayoutSchema, Layout, OptionLayout, Structure, UInt, Union, WideBits, WrappedLayout, array, bool, decodeBool, encodeBool, i128, i64, i8, option, publicKey, rustEnum, seq, str, struct, tagged, u128, u32, u64, u8, union, vec, vecU8, zeros };