1 | /// <reference types="node" />
|
2 | import BN from 'bn.js';
|
3 | import { PrefixedHexString, TransformableToArray, TransformableToBuffer } from './types';
|
4 | /**
|
5 | * Converts a `Number` into a hex `String`
|
6 | * @param {Number} i
|
7 | * @return {String}
|
8 | */
|
9 | export declare const intToHex: (i: number) => string;
|
10 | /**
|
11 | * Converts an `Number` to a `Buffer`
|
12 | * @param {Number} i
|
13 | * @return {Buffer}
|
14 | */
|
15 | export declare const intToBuffer: (i: number) => Buffer;
|
16 | /**
|
17 | * Returns a buffer filled with 0s.
|
18 | * @param bytes the number of bytes the buffer should be
|
19 | */
|
20 | export declare const zeros: (bytes: number) => Buffer;
|
21 | /**
|
22 | * Left Pads a `Buffer` with leading zeros till it has `length` bytes.
|
23 | * Or it truncates the beginning if it exceeds.
|
24 | * @param msg the value to pad (Buffer)
|
25 | * @param length the number of bytes the output should be
|
26 | * @return (Buffer)
|
27 | */
|
28 | export declare const setLengthLeft: (msg: Buffer, length: number) => Buffer;
|
29 | /**
|
30 | * Right Pads a `Buffer` with trailing zeros till it has `length` bytes.
|
31 | * it truncates the end if it exceeds.
|
32 | * @param msg the value to pad (Buffer)
|
33 | * @param length the number of bytes the output should be
|
34 | * @return (Buffer)
|
35 | */
|
36 | export declare const setLengthRight: (msg: Buffer, length: number) => Buffer;
|
37 | /**
|
38 | * Trims leading zeros from a `Buffer`.
|
39 | * @param a (Buffer)
|
40 | * @return (Buffer)
|
41 | */
|
42 | export declare const unpadBuffer: (a: Buffer) => Buffer;
|
43 | /**
|
44 | * Trims leading zeros from an `Array` (of numbers).
|
45 | * @param a (number[])
|
46 | * @return (number[])
|
47 | */
|
48 | export declare const unpadArray: (a: number[]) => number[];
|
49 | /**
|
50 | * Trims leading zeros from a hex-prefixed `String`.
|
51 | * @param a (String)
|
52 | * @return (String)
|
53 | */
|
54 | export declare const unpadHexString: (a: string) => string;
|
55 | export declare type ToBufferInputTypes = PrefixedHexString | number | BN | Buffer | Uint8Array | number[] | TransformableToArray | TransformableToBuffer | null | undefined;
|
56 | /**
|
57 | * Attempts to turn a value into a `Buffer`.
|
58 | * Inputs supported: `Buffer`, `String` (hex-prefixed), `Number`, null/undefined, `BN` and other objects
|
59 | * with a `toArray()` or `toBuffer()` method.
|
60 | * @param v the value
|
61 | */
|
62 | export declare const toBuffer: (v: ToBufferInputTypes) => Buffer;
|
63 | /**
|
64 | * Converts a `Buffer` to a `Number`.
|
65 | * @param buf `Buffer` object to convert
|
66 | * @throws If the input number exceeds 53 bits.
|
67 | */
|
68 | export declare const bufferToInt: (buf: Buffer) => number;
|
69 | /**
|
70 | * Converts a `Buffer` into a `0x`-prefixed hex `String`.
|
71 | * @param buf `Buffer` object to convert
|
72 | */
|
73 | export declare const bufferToHex: (buf: Buffer) => string;
|
74 | /**
|
75 | * Interprets a `Buffer` as a signed integer and returns a `BN`. Assumes 256-bit numbers.
|
76 | * @param num Signed integer value
|
77 | */
|
78 | export declare const fromSigned: (num: Buffer) => BN;
|
79 | /**
|
80 | * Converts a `BN` to an unsigned integer and returns it as a `Buffer`. Assumes 256-bit numbers.
|
81 | * @param num
|
82 | */
|
83 | export declare const toUnsigned: (num: BN) => Buffer;
|
84 | /**
|
85 | * Adds "0x" to a given `String` if it does not already start with "0x".
|
86 | */
|
87 | export declare const addHexPrefix: (str: string) => string;
|
88 | /**
|
89 | * Returns the utf8 string representation from a hex string.
|
90 | *
|
91 | * Examples:
|
92 | *
|
93 | * Input 1: '657468657265756d000000000000000000000000000000000000000000000000'
|
94 | * Input 2: '657468657265756d'
|
95 | * Input 3: '000000000000000000000000000000000000000000000000657468657265756d'
|
96 | *
|
97 | * Output (all 3 input variants): 'ethereum'
|
98 | *
|
99 | * Note that this method is not intended to be used with hex strings
|
100 | * representing quantities in both big endian or little endian notation.
|
101 | *
|
102 | * @param string Hex string, should be `0x` prefixed
|
103 | * @return Utf8 string
|
104 | */
|
105 | export declare const toUtf8: (hex: string) => string;
|
106 | /**
|
107 | * Converts a `Buffer` or `Array` to JSON.
|
108 | * @param ba (Buffer|Array)
|
109 | * @return (Array|String|null)
|
110 | */
|
111 | export declare const baToJSON: (ba: any) => any;
|