import type { BigNumberish } from '@ethersproject/bignumber'; import { BigNumber } from '@ethersproject/bignumber'; import * as t from 'io-ts'; /** * Decode/validate like codec.decode, but throw or return right instead of Either * * @param codec - io-ts codec to be used for decoding/validation * @param data - data to decode/validate * @param customError - Message or error to throw if the decoding fails * @param log - Logger to log error to * @returns Decoded value of codec type */ export declare function decode(codec: C, data: C['_I'], customError?: string | Error, log?: (...args: any[]) => void): C['_A']; /** * Test for value's non-nulliness * Like lodash's negate(isNil), but also works as type guard (e.g. useful for filters) * * @param value - to be tested * @returns true if value is not null nor undefined */ export declare function isntNil(value: T): value is NonNullable; /** * Codec of ethers.utils.BigNumber objects * * Input can be anything BigNumber.from-able: number, string or jsonStringified BigNumber object * Output is string, so we can JSON-serialize with 'number's types bigger than JS VM limits * of ±2^53, as Raiden python client stdlib json encode longs as string. */ export interface BigNumberC extends t.Type { } export declare const BigNumberC: BigNumberC; export interface SizedB { readonly size: S; } export interface HexStringB extends SizedB { readonly HexString: unique symbol; } export declare type HexString = string & t.Brand>; export interface HexStringC extends t.RefinementType, string> { } /** * Helper function to create codecs to validate an arbitrary or variable-sized hex bytestring * A branded codec to indicate validated hex-strings * * @param size - Required number of bytes. Pass undefined or zero to have a variable-sized type * @returns branded codec for hex-encoded bytestrings */ export declare const HexString: (size?: S) => HexStringC; export interface IntB extends SizedB { readonly Int: unique symbol; } export declare type Int = BigNumber & t.Brand>; export interface IntC extends t.RefinementType, t.OutputOf> { } /** * Helper function to create codecs to validate an arbitrary or variable-sized BigNumbers * A branded codec/type to indicate size-validated BigNumbers * * @param size - Required number of bytes. Pass undefined to have a variable-sized type * @returns branded codec for hex-encoded bytestrings */ export declare const Int: (size?: S) => IntC; export interface UIntB extends SizedB { readonly UInt: unique symbol; } export declare type UInt = BigNumber & t.Brand>; export interface UIntC extends t.RefinementType, t.OutputOf> { } /** * Helper function to create codecs to validate an arbitrary or variable-sized BigNumbers * A branded codec/type to indicate size-validated BigNumbers * * @param size - Required number of bytes. Pass undefined to have a variable-sized type * @returns branded codec for hex-encoded bytestrings */ export declare const UInt: (size?: S) => UIntC; export declare const Signature: HexStringC<65>; export declare type Signature = HexString<65>; export declare const Hash: HexStringC<32>; export declare type Hash = HexString<32>; export declare const Secret: HexStringC<32>; export declare type Secret = HexString<32>; export declare const PrivateKey: HexStringC<32>; export declare type PrivateKey = HexString<32>; export declare const PublicKey: HexStringC<65>; export declare type PublicKey = HexString<65>; export interface AddressB { readonly Address: unique symbol; } export declare type Address = HexString<20> & t.Brand; export interface AddressC extends t.RefinementType, Address, string> { } export declare const Address: AddressC; /** * Helper type to extend a given type T to contain a timestamp ts member */ export declare type Timed = T & { readonly ts: number; }; export interface TimedC extends t.IntersectionC<[T, t.ReadonlyC>]> { } /** * Helper function to create codecs to validate derived types containing a timestamp ts * * @param codec - Codec to compose with a ts timestamp property * @returns Codec validating such subtype */ export declare const Timed: (codec: T) => TimedC; /** * Given a value of type T, returns a Timed with current time as 'ts' member * * @param v - Value to return with time * @param ts - Timestamp to use, defaults to now * @returns copy of v added of a ts numeric timestamp */ export declare function timed(v: T, ts?: number): Timed; /** * Remove ts timestamp field (from timed) from object passed as parameter (immutably) * * @param v - Timed object * @returns return a copy of v without ts property */ export declare function untime(v: T): Omit; export declare type Signed = M & { readonly signature: Signature; }; export interface SignedC extends t.IntersectionC<[C, t.ReadonlyC>]> { } export declare const Signed: (codec: C) => SignedC; /** * Memoized factory to create codecs validating an arbitrary class C * * @param name - Class to create a codec for * @returns Codec validating class C */ export declare const instanceOf: (name: string) => t.Type; /** * Infer type of last element of a tuple or array * Currently supports tuples of up to 9 elements before falling back to array's inference */ export declare type Last = T extends readonly [...unknown[], infer L] ? L : T[number] | undefined; /** * Like lodash's last, but properly infer return type when argument is a tuple * * @param arr - Tuple or array to get last element from * @returns Last element from arr */ export declare function last(arr: T): Last; /** * Math.max for BigNumbers * * @param args - Parameters to compare, must have at least one element * @returns Maxium of parameters as per BigNumber's lt comparison */ export declare function bnMax(...args: [T, ...T[]]): T; /** * Type helper to recursively map decodable properties to their simpler encoded types; * This allows e.g. types decodable as BigNumbers to be passed in [recursive] properties where * BigNumbers are expected at runtime, as long as the object is decoded/validated before use. */ export declare type Decodable = T extends BigNumber ? BigNumberish : T extends string ? string : T extends boolean ? boolean : T extends number ? number : T extends null | symbol ? T : unknown extends T ? unknown : { [K in keyof T]: Decodable; }; /** * Converts a union to the respective intersection * Example: type UnionToIntersection<{ a: string } | { b: number }> = { a: string } & { b: number } */ export declare type UnionToIntersection = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; /** * Creates a refinement of t.string which validates a template literal string * * @param regex - Regex which matches the generic parameter L * @param name - codec name * @returns refinement type of string to tempalte literal */ export declare function templateLiteral(regex: RegExp | string, name?: string): t.RefinementType;