import { NonNegativeInteger } from '../crypto/non-negative.js'; import { GenericSignableField } from './generic.js'; export { Binable, defineBinable, withVersionNumber, tuple, record, enumWithArgument, prefixToField, bytesToBits, bitsToBytes, withBits, withCheck, BinableWithBits, stringToBytes, stringFromBytes, stringLengthInBytes, BinableString, BinableInt32, BinableInt64, BinableUint32, BinableUint64, }; type Binable = { toBytes(t: T): number[]; readBytes(bytes: number[], offset: NonNegativeInteger): [value: T, offset: number]; fromBytes(bytes: number[]): T; }; type BinableWithBits = Binable & { toBits(t: T): boolean[]; fromBits(bits: boolean[]): T; sizeInBytes: number; sizeInBits: number; }; declare function defineBinable({ toBytes, readBytes, }: { toBytes(t: T): number[]; readBytes(bytes: number[], offset: NonNegativeInteger): [value: T, offset: number]; }): Binable; declare function withVersionNumber(binable: Binable, versionNumber: number): Binable; declare function withCheck({ toBytes, readBytes }: Binable, check: (t: T) => void): Binable; type Tuple = [T, ...T[]] | []; declare function record>(binables: { [i in keyof Types]: Binable; }, keys: Tuple): Binable; declare function tuple>(binables: { [i in keyof Types]: Binable; }): Binable; type EnumNoArgument = { type: T; }; type EnumWithArgument = { type: T; value: V; }; type AnyEnum = EnumNoArgument | EnumWithArgument; declare function enumWithArgument>(types: { [i in number]: Enum_[i] extends EnumWithArgument ? { type: Enum_[i]['type']; value: Binable; } : { type: Enum_[i]['type']; }; }): Binable; declare const BinableString: Binable; declare const BinableInt64: Binable; declare const BinableInt32: Binable; declare const BinableUint64: Binable; declare const BinableUint32: Binable; declare function prefixToField(Field: GenericSignableField, prefix: string): Field; declare function bitsToBytes([...bits]: boolean[]): number[]; declare function bytesToBits(bytes: number[]): boolean[]; /** * This takes a `Binable` plus an optional `sizeInBits`, and derives toBits() / fromBits() functions. * - `sizeInBits` has to observe `Math.ceil(sizeInBits / 8) === sizeInBytes`, so the bit size can be slightly smaller than the byte size * - If `sizeInBits` is `< sizeInBytes * 8`, then we assume that toBytes() returns a byte sequence where the bits * higher than `sizeInBits` are all 0. This assumption manifests in toBits(), where we slice off those higher bits, * to return a result that is of length `sizeInBits`. * * This is useful for serializing field elements, where -- depending on the circumstance -- we either want a * 32-byte (= 256-bit) serialization, or a 255-bit serialization */ declare function withBits(binable: Binable, sizeInBits: number): BinableWithBits; declare function stringToBytes(s: string): number[]; declare function stringFromBytes(bytes: number[]): string; declare function stringLengthInBytes(s: string): number;