ethers.js/lib.esm/utils/data.d.ts

93 lines
3.1 KiB
TypeScript
Raw Normal View History

2022-11-30 23:44:23 +03:00
/**
* A [[HexString]] whose length is even, which ensures it is a valid
* representation of binary data.
*/
2023-02-02 12:05:47 +03:00
export type DataHexString = string;
2022-11-30 23:44:23 +03:00
/**
* A string which is prefixed with ``0x`` and followed by any number
* of case-agnostic hexadecimal characters.
*
* It must match the regular expression ``/0x[0-9A-Fa-f]*\/``.
*/
2023-02-02 12:05:47 +03:00
export type HexString = string;
2022-11-30 23:44:23 +03:00
/**
* An object that can be used to represent binary data.
*/
2023-02-02 12:05:47 +03:00
export type BytesLike = DataHexString | Uint8Array;
2022-09-16 05:58:45 +03:00
/**
* Get a typed Uint8Array for %%value%%. If already a Uint8Array
* the original %%value%% is returned; if a copy is required use
* [[getBytesCopy]].
*
* @see: getBytesCopy
*/
export declare function getBytes(value: BytesLike, name?: string): Uint8Array;
/**
* Get a typed Uint8Array for %%value%%, creating a copy if necessary
* to prevent any modifications of the returned value from being
* reflected elsewhere.
*
* @see: getBytes
*/
export declare function getBytesCopy(value: BytesLike, name?: string): Uint8Array;
/**
2022-11-30 23:44:23 +03:00
* Returns true if %%value%% is a valid [[HexString]].
2022-09-16 05:58:45 +03:00
*
2022-11-30 23:44:23 +03:00
* If %%length%% is ``true`` or a //number//, it also checks that
* %%value%% is a valid [[DataHexString]] of %%length%% (if a //number//)
2022-09-16 05:58:45 +03:00
* bytes of data (e.g. ``0x1234`` is 2 bytes).
*/
export declare function isHexString(value: any, length?: number | boolean): value is `0x${string}`;
/**
* Returns true if %%value%% is a valid representation of arbitrary
2022-11-30 23:44:23 +03:00
* data (i.e. a valid [[DataHexString]] or a Uint8Array).
2022-09-16 05:58:45 +03:00
*/
2022-09-05 23:57:11 +03:00
export declare function isBytesLike(value: any): value is BytesLike;
2022-09-16 05:58:45 +03:00
/**
2022-11-30 23:44:23 +03:00
* Returns a [[DataHexString]] representation of %%data%%.
2022-09-16 05:58:45 +03:00
*/
2022-09-05 23:57:11 +03:00
export declare function hexlify(data: BytesLike): string;
2022-09-16 05:58:45 +03:00
/**
2022-11-30 23:44:23 +03:00
* Returns a [[DataHexString]] by concatenating all values
2022-09-16 05:58:45 +03:00
* within %%data%%.
*/
2022-09-05 23:57:11 +03:00
export declare function concat(datas: ReadonlyArray<BytesLike>): string;
2022-09-16 05:58:45 +03:00
/**
* Returns the length of %%data%%, in bytes.
*/
2022-09-05 23:57:11 +03:00
export declare function dataLength(data: BytesLike): number;
2022-09-16 05:58:45 +03:00
/**
2022-11-30 23:44:23 +03:00
* Returns a [[DataHexString]] by slicing %%data%% from the %%start%%
2022-09-16 05:58:45 +03:00
* offset to the %%end%% offset.
*
* By default %%start%% is 0 and %%end%% is the length of %%data%%.
*/
2022-09-05 23:57:11 +03:00
export declare function dataSlice(data: BytesLike, start?: number, end?: number): string;
2022-09-16 05:58:45 +03:00
/**
2022-11-30 23:44:23 +03:00
* Return the [[DataHexString]] result by stripping all **leading**
2022-09-16 05:58:45 +03:00
** zero bytes from %%data%%.
*/
2022-09-05 23:57:11 +03:00
export declare function stripZerosLeft(data: BytesLike): string;
2022-09-16 05:58:45 +03:00
/**
2022-11-30 23:44:23 +03:00
* Return the [[DataHexString]] of %%data%% padded on the **left**
2022-09-16 05:58:45 +03:00
* to %%length%% bytes.
2022-12-30 19:30:03 +03:00
*
2023-02-13 06:14:26 +03:00
* If %%data%% already exceeds %%length%%, a [[BufferOverrunError]] is
2022-12-30 19:30:03 +03:00
* thrown.
*
* This pads data the same as **values** are in Solidity
* (e.g. ``uint128``).
2022-09-16 05:58:45 +03:00
*/
2022-09-05 23:57:11 +03:00
export declare function zeroPadValue(data: BytesLike, length: number): string;
2022-09-16 05:58:45 +03:00
/**
2022-11-30 23:44:23 +03:00
* Return the [[DataHexString]] of %%data%% padded on the **right**
2022-09-16 05:58:45 +03:00
* to %%length%% bytes.
2022-12-30 19:30:03 +03:00
*
2023-02-13 06:14:26 +03:00
* If %%data%% already exceeds %%length%%, a [[BufferOverrunError]] is
2022-12-30 19:30:03 +03:00
* thrown.
*
* This pads data the same as **bytes** are in Solidity
* (e.g. ``bytes16``).
2022-09-16 05:58:45 +03:00
*/
2022-09-05 23:57:11 +03:00
export declare function zeroPadBytes(data: BytesLike, length: number): string;
//# sourceMappingURL=data.d.ts.map