UNPKG

2.21 kBTypeScriptView Raw
1/// <reference types="bn.js" />
2/// <reference types="node" />
3import { BN } from './externals';
4import { Address } from './address';
5import { ToBufferInputTypes } from './bytes';
6export declare type BNLike = BN | PrefixedHexString | number | Buffer;
7export declare type BufferLike = Buffer | Uint8Array | number[] | number | BN | TransformableToBuffer | PrefixedHexString;
8export declare type PrefixedHexString = string;
9/**
10 * A type that represents an Address-like value.
11 * To convert to address, use `new Address(toBuffer(value))`
12 */
13export declare type AddressLike = Address | Buffer | PrefixedHexString;
14export interface TransformableToArray {
15 toArray(): Uint8Array;
16 toBuffer?(): Buffer;
17}
18export interface TransformableToBuffer {
19 toBuffer(): Buffer;
20 toArray?(): Uint8Array;
21}
22export declare type NestedUint8Array = Array<Uint8Array | NestedUint8Array>;
23export declare type NestedBufferArray = Array<Buffer | NestedBufferArray>;
24/**
25 * Convert BN to 0x-prefixed hex string.
26 */
27export declare function bnToHex(value: BN): PrefixedHexString;
28/**
29 * Convert value from BN to an unpadded Buffer
30 * (useful for RLP transport)
31 * @param value value to convert
32 */
33export declare function bnToUnpaddedBuffer(value: BN): Buffer;
34/**
35 * Deprecated alias for {@link bnToUnpaddedBuffer}
36 * @deprecated
37 */
38export declare function bnToRlp(value: BN): Buffer;
39/**
40 * Type output options
41 */
42export declare enum TypeOutput {
43 Number = 0,
44 BN = 1,
45 Buffer = 2,
46 PrefixedHexString = 3
47}
48export declare type TypeOutputReturnType = {
49 [TypeOutput.Number]: number;
50 [TypeOutput.BN]: BN;
51 [TypeOutput.Buffer]: Buffer;
52 [TypeOutput.PrefixedHexString]: PrefixedHexString;
53};
54/**
55 * Convert an input to a specified type.
56 * Input of null/undefined returns null/undefined regardless of the output type.
57 * @param input value to convert
58 * @param outputType type to output
59 */
60export declare function toType<T extends TypeOutput>(input: null, outputType: T): null;
61export declare function toType<T extends TypeOutput>(input: undefined, outputType: T): undefined;
62export declare function toType<T extends TypeOutput>(input: ToBufferInputTypes, outputType: T): TypeOutputReturnType[T];