ethereumjs-monorepo

@ethereumjs/util

@ethereumjs/util

Table of contents

Enumerations

Classes

Interfaces

Type Aliases

Variables

Functions

Type Aliases

AccountBodyBytes

Ƭ AccountBodyBytes: [Uint8Array, Uint8Array, Uint8Array, Uint8Array]

Defined in

packages/util/src/account.ts:29


AccountState

Ƭ AccountState: [balance: PrefixedHexString, code: PrefixedHexString, storage: StoragePair[], nonce: PrefixedHexString]

Defined in

packages/util/src/genesis.ts:8


AddressLike

Ƭ AddressLike: Address | Uint8Array | PrefixedHexString

A type that represents an input that can be converted to an Address.

Defined in

packages/util/src/types.ts:31


BatchDBOp

Ƭ BatchDBOp<TKey, TValue>: PutBatch<TKey, TValue> | DelBatch<TKey>

Type parameters

Name Type
TKey extends Uint8Array | string | number = Uint8Array
TValue extends Uint8Array | string | DBObject = Uint8Array

Defined in

packages/util/src/db.ts:4


BigIntLike

Ƭ BigIntLike: bigint | PrefixedHexString | number | Uint8Array

Defined in

packages/util/src/types.ts:10


BytesLike

Ƭ BytesLike: Uint8Array | number[] | number | bigint | TransformabletoBytes | PrefixedHexString

Defined in

packages/util/src/types.ts:15


DBObject

Ƭ DBObject: Object

Index signature

▪ [key: string]: string | string[] | number

Defined in

packages/util/src/db.ts:1


EncodingOpts

Ƭ EncodingOpts: Object

Type declaration

Name Type
keyEncoding? KeyEncoding
valueEncoding? ValueEncoding

Defined in

packages/util/src/db.ts:21


NestedUint8Array

Ƭ NestedUint8Array: (Uint8Array | NestedUint8Array)[]

Defined in

packages/util/src/types.ts:37


PrefixedHexString

Ƭ PrefixedHexString: string

Defined in

packages/util/src/types.ts:26


StoragePair

Ƭ StoragePair: [key: PrefixedHexString, value: PrefixedHexString]

Defined in

packages/util/src/genesis.ts:6


ToBytesInputTypes

Ƭ ToBytesInputTypes: PrefixedHexString | number | bigint | Uint8Array | number[] | TransformabletoBytes | null | undefined

Defined in

packages/util/src/bytes.ts:267


TypeOutputReturnType

Ƭ TypeOutputReturnType: Object

Type declaration

Name Type
0 number
1 bigint
2 Uint8Array
3 PrefixedHexString

Defined in

packages/util/src/types.ts:49


WithdrawalBytes

Ƭ WithdrawalBytes: [Uint8Array, Uint8Array, Uint8Array, Uint8Array]

Defined in

packages/util/src/withdrawal.ts:30


WithdrawalData

Ƭ WithdrawalData: Object

Flexible input data type for EIP-4895 withdrawal data with amount in Gwei to match CL representation and for eventual ssz withdrawalsRoot

Type declaration

Name Type
address AddressLike
amount BigIntLike
index BigIntLike
validatorIndex BigIntLike

Defined in

packages/util/src/withdrawal.ts:12

Variables

BIGINT_0

Const BIGINT_0: bigint

Defined in

packages/util/src/constants.ts:82


BIGINT_1

Const BIGINT_1: bigint

Defined in

packages/util/src/constants.ts:83


BIGINT_100

Const BIGINT_100: bigint

Defined in

packages/util/src/constants.ts:100


BIGINT_128

Const BIGINT_128: bigint

Defined in

packages/util/src/constants.ts:95


BIGINT_160

Const BIGINT_160: bigint

Defined in

packages/util/src/constants.ts:101


BIGINT_2

Const BIGINT_2: bigint

Defined in

packages/util/src/constants.ts:84


BIGINT_224

Const BIGINT_224: bigint

Defined in

packages/util/src/constants.ts:102


BIGINT_255

Const BIGINT_255: bigint

Defined in

packages/util/src/constants.ts:96


BIGINT_256

Const BIGINT_256: bigint

Defined in

packages/util/src/constants.ts:97


BIGINT_27

Const BIGINT_27: bigint

Defined in

packages/util/src/constants.ts:89


BIGINT_28

Const BIGINT_28: bigint

Defined in

packages/util/src/constants.ts:90


BIGINT_2EXP160

Const BIGINT_2EXP160: bigint

Defined in

packages/util/src/constants.ts:104


BIGINT_2EXP224

Const BIGINT_2EXP224: bigint

Defined in

packages/util/src/constants.ts:105


BIGINT_2EXP256

Const BIGINT_2EXP256: bigint

Defined in

packages/util/src/constants.ts:107


BIGINT_2EXP96

Const BIGINT_2EXP96: bigint

Defined in

packages/util/src/constants.ts:103


BIGINT_3

Const BIGINT_3: bigint

Defined in

packages/util/src/constants.ts:85


BIGINT_31

Const BIGINT_31: bigint

Defined in

packages/util/src/constants.ts:91


BIGINT_32

Const BIGINT_32: bigint

Defined in

packages/util/src/constants.ts:92


BIGINT_64

Const BIGINT_64: bigint

Defined in

packages/util/src/constants.ts:93


BIGINT_7

Const BIGINT_7: bigint

Defined in

packages/util/src/constants.ts:86


BIGINT_8

Const BIGINT_8: bigint

Defined in

packages/util/src/constants.ts:87


BIGINT_96

Const BIGINT_96: bigint

Defined in

packages/util/src/constants.ts:99


BIGINT_NEG1

Const BIGINT_NEG1: bigint

BigInt constants

Defined in

packages/util/src/constants.ts:80


GWEI_TO_WEI

Const GWEI_TO_WEI: bigint

Easy conversion from Gwei to wei

Defined in

packages/util/src/units.ts:3


KECCAK256_NULL

Const KECCAK256_NULL: Uint8Array

Keccak-256 hash of null

Defined in

packages/util/src/constants.ts:44


KECCAK256_NULL_S

Const KECCAK256_NULL_S: "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"

Keccak-256 hash of null

Defined in

packages/util/src/constants.ts:39


KECCAK256_RLP

Const KECCAK256_RLP: Uint8Array

Keccak-256 hash of the RLP of null

Defined in

packages/util/src/constants.ts:65


KECCAK256_RLP_ARRAY

Const KECCAK256_RLP_ARRAY: Uint8Array

Keccak-256 of an RLP of an empty array

Defined in

packages/util/src/constants.ts:55


KECCAK256_RLP_ARRAY_S

Const KECCAK256_RLP_ARRAY_S: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"

Keccak-256 of an RLP of an empty array

Defined in

packages/util/src/constants.ts:49


KECCAK256_RLP_S

Const KECCAK256_RLP_S: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"

Keccak-256 hash of the RLP of null

Defined in

packages/util/src/constants.ts:60


MAX_INTEGER

Const MAX_INTEGER: bigint

The max integer that the evm can handle (2^256-1)

Defined in

packages/util/src/constants.ts:13


MAX_INTEGER_BIGINT

Const MAX_INTEGER_BIGINT: bigint

The max integer that the evm can handle (2^256-1) as a bigint 2^256-1 equals to 340282366920938463463374607431768211455 We use literal value instead of calculated value for compatibility issue.

Defined in

packages/util/src/constants.ts:22


MAX_UINT64

Const MAX_UINT64: bigint

2^64-1

Defined in

packages/util/src/constants.ts:8


MAX_WITHDRAWALS_PER_PAYLOAD

Const MAX_WITHDRAWALS_PER_PAYLOAD: 16

Defined in

packages/util/src/constants.ts:72


RIPEMD160_ADDRESS_STRING

Const RIPEMD160_ADDRESS_STRING: "0000000000000000000000000000000000000003"

Defined in

packages/util/src/constants.ts:74


RLP_EMPTY_STRING

Const RLP_EMPTY_STRING: Uint8Array

RLP encoded empty string

Defined in

packages/util/src/constants.ts:70


SECP256K1_ORDER

Const SECP256K1_ORDER: bigint = secp256k1.CURVE.n

Defined in

packages/util/src/constants.ts:26


SECP256K1_ORDER_DIV_2

Const SECP256K1_ORDER_DIV_2: bigint

Defined in

packages/util/src/constants.ts:27


TWO_POW256

Const TWO_POW256: bigint

2^256

Defined in

packages/util/src/constants.ts:32


kzg

kzg: Kzg

Defined in

packages/util/src/kzg.ts:26

Functions

accountBodyFromSlim

accountBodyFromSlim(body): Uint8Array[]

Parameters

Name Type
body AccountBodyBytes

Returns

Uint8Array[]

Defined in

packages/util/src/account.ts:357


accountBodyToRLP

accountBodyToRLP(body, couldBeSlim?): Uint8Array

Converts a slim account (per snap protocol spec) to the RLP encoded version of the account

Parameters

Name Type Default value Description
body AccountBodyBytes undefined Array of 4 Uint8Array-like items to represent the account
couldBeSlim boolean true -

Returns

Uint8Array

RLP encoded version of the account

Defined in

packages/util/src/account.ts:383


accountBodyToSlim

accountBodyToSlim(body): Uint8Array[]

Parameters

Name Type
body AccountBodyBytes

Returns

Uint8Array[]

Defined in

packages/util/src/account.ts:368


addHexPrefix

addHexPrefix(str): string

Adds “0x” to a given string if it does not already start with “0x”.

Parameters

Name Type
str string

Returns

string

Defined in

packages/util/src/bytes.ts:347


arrayContainsArray

arrayContainsArray(superset, subset, some?): boolean

Returns TRUE if the first specified array contains all elements from the second one. FALSE otherwise.

Parameters

Name Type
superset unknown[]
subset unknown[]
some? boolean

Returns

boolean

Defined in

packages/util/src/internal.ts:91


bigInt64ToBytes

bigInt64ToBytes(value, littleEndian?): Uint8Array

Notice

Convert a 64-bit bigint to a Uint8Array.

Parameters

Name Type Default value Description
value bigint undefined The 64-bit bigint to convert.
littleEndian boolean false True for little-endian, undefined or false for big-endian.

Returns

Uint8Array

A Uint8Array of length 8 containing the bigint.

Defined in

packages/util/src/bytes.ts:529


bigIntMax

bigIntMax(…args): bigint

Calculates max bigint from an array of bigints

Parameters

Name Type Description
...args bigint[] array of bigints

Returns

bigint

Defined in

packages/util/src/bytes.ts:409


bigIntMin

bigIntMin(…args): bigint

Calculates min BigInt from an array of BigInts

Parameters

Name Type Description
...args bigint[] array of bigints

Returns

bigint

Defined in

packages/util/src/bytes.ts:415


bigIntToBytes

bigIntToBytes(num, littleEndian?): Uint8Array

Converts a bigint to a Uint8Array *

Parameters

Name Type Default value Description
num bigint undefined the bigint to convert
littleEndian boolean false -

Returns

Uint8Array

Defined in

packages/util/src/bytes.ts:156


bigIntToHex

bigIntToHex(num): string

Converts a bigint to a 0x prefixed hex string

Parameters

Name Type Description
num bigint the bigint to convert

Returns

string

Defined in

packages/util/src/bytes.ts:401


bigIntToUnpaddedBytes

bigIntToUnpaddedBytes(value): Uint8Array

Convert value from bigint to an unpadded Uint8Array (useful for RLP transport)

Parameters

Name Type Description
value bigint the bigint to convert

Returns

Uint8Array

Defined in

packages/util/src/bytes.ts:423


blobsToCommitments

blobsToCommitments(blobs): Uint8Array[]

Parameters

Name Type
blobs Uint8Array[]

Returns

Uint8Array[]

Defined in

packages/util/src/blobs.ts:58


blobsToProofs

blobsToProofs(blobs, commitments): Uint8Array[]

Parameters

Name Type
blobs Uint8Array[]
commitments Uint8Array[]

Returns

Uint8Array[]

Defined in

packages/util/src/blobs.ts:66


bytesToBigInt

bytesToBigInt(bytes, littleEndian?): bigint

Converts a Uint8Array to a bigint

Parameters

Name Type Default value Description
bytes Uint8Array undefined the bytes to convert
littleEndian boolean false -

Returns

bigint

Defined in

packages/util/src/bytes.ts:80


bytesToBigInt64

bytesToBigInt64(bytes, littleEndian?): bigint

Notice

Convert a Uint8Array to a 64-bit bigint

Parameters

Name Type Default value Description
bytes Uint8Array undefined The input Uint8Array from which to read the 64-bit bigint.
littleEndian boolean false True for little-endian, undefined or false for big-endian.

Returns

bigint

The 64-bit bigint read from the input Uint8Array.

Defined in

packages/util/src/bytes.ts:502


bytesToHex

bytesToHex(bytes): string

Parameters

Name Type
bytes Uint8Array

Returns

string

Defined in

packages/util/src/bytes.ts:60


bytesToInt

bytesToInt(bytes): number

Converts a Uint8Array to a number.

Throws

If the input number exceeds 53 bits.

Parameters

Name Type Description
bytes Uint8Array the bytes to convert

Returns

number

Defined in

packages/util/src/bytes.ts:104


bytesToInt32

bytesToInt32(bytes, littleEndian?): number

Notice

Convert a Uint8Array to a 32-bit integer

Parameters

Name Type Default value Description
bytes Uint8Array undefined The input Uint8Array from which to read the 32-bit integer.
littleEndian boolean false True for little-endian, undefined or false for big-endian.

Returns

number

The 32-bit integer read from the input Uint8Array.

Defined in

packages/util/src/bytes.ts:488


bytesToUnprefixedHex

bytesToUnprefixedHex(bytes): string

Example

bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'

Parameters

Name Type
bytes Uint8Array

Returns

string

Defined in

node_modules/@noble/hashes/utils.d.ts:11


bytesToUtf8

bytesToUtf8(data): string

Parameters

Name Type
data Uint8Array

Returns

string

Defined in

node_modules/ethereum-cryptography/utils.d.ts:5


calculateSigRecovery

calculateSigRecovery(v, chainId?): bigint

Parameters

Name Type
v bigint
chainId? bigint

Returns

bigint

Defined in

packages/util/src/signature.ts:53


commitmentsToVersionedHashes

commitmentsToVersionedHashes(commitments): Uint8Array[]

Generate an array of versioned hashes from corresponding kzg commitments

Parameters

Name Type Description
commitments Uint8Array[] array of kzg commitments

Returns

Uint8Array[]

array of versioned hashes Note: assumes KZG commitments (version 1 version hashes)

Defined in

packages/util/src/blobs.ts:93


compareBytes

compareBytes(value1, value2): number

Compares two Uint8Arrays and returns a number indicating their order in a sorted array.

Parameters

Name Type Description
value1 Uint8Array The first Uint8Array to compare.
value2 Uint8Array The second Uint8Array to compare.

Returns

number

A positive number if value1 is larger than value2, A negative number if value1 is smaller than value2, or 0 if value1 and value2 are equal.

Defined in

packages/util/src/bytes.ts:446


computeVersionedHash

computeVersionedHash(commitment, blobCommitmentVersion): Uint8Array

Converts a vector commitment for a given data blob to its versioned hash. For 4844, this version number will be 0x01 for KZG vector commitments but could be different if future vector commitment types are introduced

Parameters

Name Type Description
commitment Uint8Array a vector commitment to a blob
blobCommitmentVersion number the version number corresponding to the type of vector commitment

Returns

Uint8Array

a versioned hash corresponding to a given blob vector commitment

Defined in

packages/util/src/blobs.ts:80


concatBytes

concatBytes(…arrays): Uint8Array

This mirrors the functionality of the ethereum-cryptography export except it skips the check to validate that every element of arrays is indead a uint8Array Can give small performance gains on large arrays

Parameters

Name Type Description
...arrays Uint8Array[] an array of Uint8Arrays

Returns

Uint8Array

one Uint8Array with all the elements of the original set works like Buffer.concat

Defined in

packages/util/src/bytes.ts:470


ecrecover

ecrecover(msgHash, v, r, s, chainId?): Uint8Array

ECDSA public key recovery from signature. NOTE: Accepts v === 0 | v === 1 for EIP1559 transactions

Parameters

Name Type
msgHash Uint8Array
v bigint
r Uint8Array
s Uint8Array
chainId? bigint

Returns

Uint8Array

Recovered public key

Defined in

packages/util/src/signature.ts:71


ecsign

ecsign(msgHash, privateKey, chainId?): ECDSASignature

Returns the ECDSA signature of a message hash.

If chainId is provided assume an EIP-155-style signature and calculate the v value accordingly, otherwise return a “static” v just derived from the recovery bit

Parameters

Name Type
msgHash Uint8Array
privateKey Uint8Array
chainId? bigint

Returns

ECDSASignature

Defined in

packages/util/src/signature.ts:35


equalsBytes

equalsBytes(a, b): boolean

Parameters

Name Type
a Uint8Array
b Uint8Array

Returns

boolean

Defined in

node_modules/ethereum-cryptography/utils.d.ts:7


fetchFromProvider

fetchFromProvider(url, params): Promise<any>

Makes a simple RPC call to a remote Ethereum JSON-RPC provider and passes through the response. No parameter or response validation is done.

Example

const provider = 'https://mainnet.infura.io/v3/...'
const params = {
  method: 'eth_getBlockByNumber',
  params: ['latest', false],
}
 const block = await fetchFromProvider(provider, params)

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `url` | `string` | the URL for the JSON RPC provider |
| `params` | `rpcParams` | the parameters for the JSON-RPC method - refer to https://ethereum.org/en/developers/docs/apis/json-rpc/ for details on RPC methods |

#### Returns

`Promise`<`any`\>

the `result` field from the JSON-RPC response

#### Defined in

[packages/util/src/provider.ts:23](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/util/src/provider.ts#L23)

___

### formatBigDecimal

 **formatBigDecimal**(`numerator`, `denominator`, `maxDecimalFactor`): `string`

#### Parameters

| Name | Type |
| :------ | :------ |
| `numerator` | `bigint` |
| `denominator` | `bigint` |
| `maxDecimalFactor` | `bigint` |

#### Returns

`string`

#### Defined in

[packages/util/src/units.ts:5](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/util/src/units.ts#L5)

___

### fromAscii

 **fromAscii**(`stringValue`): `string`

Should be called to get hex representation (prefixed by 0x) of ascii string

#### Parameters

| Name | Type |
| :------ | :------ |
| `stringValue` | `string` |

#### Returns

`string`

hex representation of input string

#### Defined in

[packages/util/src/internal.ts:152](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/util/src/internal.ts#L152)

___

### fromRpcSig

 **fromRpcSig**(`sig`): [`ECDSASignature`](/ethereumjs-monorepo/packages/util/docs/interfaces/ECDSASignature.html)

Convert signature format of the `eth_sign` RPC method to signature parameters

NOTE: For an extracted `v` value < 27 (see Geth bug https://github.com/ethereum/go-ethereum/issues/2053)
`v + 27` is returned for the `v` value
NOTE: After EIP1559, `v` could be `0` or `1` but this function assumes
it's a signed message (EIP-191 or EIP-712) adding `27` at the end. Remove if needed.

#### Parameters

| Name | Type |
| :------ | :------ |
| `sig` | `string` |

#### Returns

[`ECDSASignature`](/ethereumjs-monorepo/packages/util/docs/interfaces/ECDSASignature.html)

#### Defined in

[packages/util/src/signature.ts:142](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/util/src/signature.ts#L142)

___

### fromSigned

▸ **fromSigned**(`num`): `bigint`

Interprets a `Uint8Array` as a signed integer and returns a `BigInt`. Assumes 256-bit numbers.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `num` | `Uint8Array` | Signed integer value |

#### Returns

`bigint`

#### Defined in

[packages/util/src/bytes.ts:329](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/util/src/bytes.ts#L329)

___

### fromUtf8

▸ **fromUtf8**(`stringValue`): `string`

Should be called to get hex representation (prefixed by 0x) of utf8 string.
Strips leading and trailing 0's.

#### Parameters

| Name | Type |
| :------ | :------ |
| `stringValue` | `string` |

#### Returns

`string`

hex representation of input string

#### Defined in

[packages/util/src/internal.ts:139](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/util/src/internal.ts#L139)

___

### generateAddress

 **generateAddress**(`from`, `nonce`): `Uint8Array`

Generates an address of a newly created contract.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `from` | `Uint8Array` | The address which is creating this new address |
| `nonce` | `Uint8Array` | The nonce of the from account |

#### Returns

`Uint8Array`

#### Defined in

[packages/util/src/account.ts:207](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/util/src/account.ts#L207)

___

### generateAddress2

 **generateAddress2**(`from`, `salt`, `initCode`): `Uint8Array`

Generates an address for a contract created using CREATE2.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `from` | `Uint8Array` | The address which is creating this new address |
| `salt` | `Uint8Array` | A salt |
| `initCode` | `Uint8Array` | The init code of the contract being created |

#### Returns

`Uint8Array`

#### Defined in

[packages/util/src/account.ts:227](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/util/src/account.ts#L227)

___

### getBinarySize

 **getBinarySize**(`str`): `number`

Get the binary size of a string

#### Parameters

| Name | Type |
| :------ | :------ |
| `str` | `string` |

#### Returns

`number`

the number of bytes contained within the string

#### Defined in

[packages/util/src/internal.ts:75](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/util/src/internal.ts#L75)

___

### getBlobs

 **getBlobs**(`input`): `Uint8Array`[]

#### Parameters

| Name | Type |
| :------ | :------ |
| `input` | `string` |

#### Returns

`Uint8Array`[]

#### Defined in

[packages/util/src/blobs.ts:34](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/util/src/blobs.ts#L34)

___

### getKeys

 **getKeys**(`params`, `key`, `allowEmpty?`): `string`[]

Returns the keys from an array of objects.

**`Example`**

```js
getKeys([{a: '1', b: '2'}, {a: '3', b: '4'}], 'a') => ['1', '3']

@param params @param key @param allowEmpty @returns output just a simple array of output keys

Parameters

Name Type
params Record<string, string>[]
key string
allowEmpty? boolean

Returns

string[]

Defined in

packages/util/src/internal.ts:174


getProvider

getProvider(provider): string

Parameters

Name Type Description
provider string | EthersProvider a URL string or EthersProvider

Returns

string

the extracted URL string for the JSON-RPC Provider

Defined in

packages/util/src/provider.ts:63


hashPersonalMessage

hashPersonalMessage(message): Uint8Array

Returns the keccak-256 hash of message, prefixed with the header used by the eth_sign RPC call. The output of this function can be fed into ecsign to produce the same signature as the eth_sign call for a given message, or fed to ecrecover along with a signature to recover the public key used to produce the signature.

Parameters

Name Type
message Uint8Array

Returns

Uint8Array

Defined in

packages/util/src/signature.ts:219


hexToBytes

hexToBytes(hex): Uint8Array

Parameters

Name Type
hex string

Returns

Uint8Array

Defined in

packages/util/src/bytes.ts:110


importPublic

importPublic(publicKey): Uint8Array

Converts a public key to the Ethereum format.

Parameters

Name Type
publicKey Uint8Array

Returns

Uint8Array

Defined in

packages/util/src/account.ts:326


initKZG

initKZG(kzgLib, trustedSetupPath?): void

Parameters

Name Type Description
kzgLib Kzg a KZG implementation (defaults to c-kzg)
trustedSetupPath? string the full path (e.g. “/home/linux/devnet4.txt”) to a kzg trusted setup text file

Returns

void

Defined in

packages/util/src/kzg.ts:38


int32ToBytes

int32ToBytes(value, littleEndian?): Uint8Array

Notice

Convert a 32-bit integer to a Uint8Array.

Parameters

Name Type Default value Description
value number undefined The 32-bit integer to convert.
littleEndian boolean false True for little-endian, undefined or false for big-endian.

Returns

Uint8Array

A Uint8Array of length 4 containing the integer.

Defined in

packages/util/src/bytes.ts:516


intToBytes

intToBytes(i): Uint8Array

Converts an number to a Uint8Array

Parameters

Name Type
i number

Returns

Uint8Array

Defined in

packages/util/src/bytes.ts:146


intToHex

intToHex(i): string

Converts a number into a PrefixedHexString

Parameters

Name Type
i number

Returns

string

Defined in

packages/util/src/bytes.ts:134


intToUnpaddedBytes

intToUnpaddedBytes(value): Uint8Array

Convert value from number to an unpadded Uint8Array (useful for RLP transport)

Parameters

Name Type Description
value number the bigint to convert

Returns

Uint8Array

Defined in

packages/util/src/bytes.ts:433


isHexPrefixed

isHexPrefixed(str): boolean

Returns a Boolean on whether or not the a String starts with ‘0x’

Throws

if the str input is not a string

Parameters

Name Type Description
str string the string input value

Returns

boolean

a boolean if it is or is not hex prefixed

Defined in

packages/util/src/internal.ts:33


isHexString

isHexString(value, length?): boolean

Is the string a hex string.

Parameters

Name Type
value string
length? number

Returns

boolean

output the string is a hex string

Defined in

packages/util/src/internal.ts:206


isValidAddress

isValidAddress(hexAddress): boolean

Checks if the address is a valid. Accepts checksummed addresses too.

Parameters

Name Type
hexAddress string

Returns

boolean

Defined in

packages/util/src/account.ts:140


isValidChecksumAddress

isValidChecksumAddress(hexAddress, eip1191ChainId?): boolean

Checks if the address is a valid checksummed address.

See toChecksumAddress’ documentation for details about the eip1191ChainId parameter.

Parameters

Name Type
hexAddress string
eip1191ChainId? BigIntLike

Returns

boolean

Defined in

packages/util/src/account.ts:195


isValidPrivate

isValidPrivate(privateKey): boolean

Checks if the private key satisfies the rules of the curve secp256k1.

Parameters

Name Type
privateKey Uint8Array

Returns

boolean

Defined in

packages/util/src/account.ts:251


isValidPublic

isValidPublic(publicKey, sanitize?): boolean

Checks if the public key satisfies the rules of the curve secp256k1 and the requirements of Ethereum.

Parameters

Name Type Default value Description
publicKey Uint8Array undefined The two points of an uncompressed key, unless sanitize is enabled
sanitize boolean false Accept public keys in other formats

Returns

boolean

Defined in

packages/util/src/account.ts:261


isValidSignature

isValidSignature(v, r, s, homesteadOrLater?, chainId?): boolean

Validate a ECDSA signature. NOTE: Accepts v === 0 | v === 1 for EIP1559 transactions

Parameters

Name Type Default value Description
v bigint undefined -
r Uint8Array undefined -
s Uint8Array undefined -
homesteadOrLater boolean true Indicates whether this is being used on either the homestead hardfork or a later one
chainId? bigint undefined -

Returns

boolean

Defined in

packages/util/src/signature.ts:179


isZeroAddress

isZeroAddress(hexAddress): boolean

Checks if a given address is the zero address.

Parameters

Name Type
hexAddress string

Returns

boolean

Defined in

packages/util/src/account.ts:346


padToEven

padToEven(value): string

Pads a String to have an even length

Parameters

Name Type
value string

Returns

string

output

Defined in

packages/util/src/internal.ts:58


parseGethGenesisState

parseGethGenesisState(json): GenesisState

Parses the geth genesis state into Blockchain GenesisState

Parameters

Name Type Description
json any representing the alloc key in a Geth genesis file

Returns

GenesisState

Defined in

packages/util/src/genesis.ts:47


privateToAddress

privateToAddress(privateKey): Uint8Array

Returns the ethereum address of a given private key.

Parameters

Name Type Description
privateKey Uint8Array A private key must be 256 bits wide

Returns

Uint8Array

Defined in

packages/util/src/account.ts:319


privateToPublic

privateToPublic(privateKey): Uint8Array

Returns the ethereum public key of a given private key.

Parameters

Name Type Description
privateKey Uint8Array A private key must be 256 bits wide

Returns

Uint8Array

Defined in

packages/util/src/account.ts:309


pubToAddress

pubToAddress(pubKey, sanitize?): Uint8Array

Returns the ethereum address of a given public key. Accepts “Ethereum public keys” and SEC1 encoded keys.

Parameters

Name Type Default value Description
pubKey Uint8Array undefined The two points of an uncompressed key, unless sanitize is enabled
sanitize boolean false Accept public keys in other formats

Returns

Uint8Array

Defined in

packages/util/src/account.ts:292


publicToAddress

publicToAddress(pubKey, sanitize?): Uint8Array

Returns the ethereum address of a given public key. Accepts “Ethereum public keys” and SEC1 encoded keys.

Parameters

Name Type Default value Description
pubKey Uint8Array undefined The two points of an uncompressed key, unless sanitize is enabled
sanitize boolean false Accept public keys in other formats

Returns

Uint8Array

Defined in

packages/util/src/account.ts:292


randomBytes

randomBytes(length): Uint8Array

Generates a Uint8Array of random bytes of specified length.

Parameters

Name Type Description
length number The length of the Uint8Array.

Returns

Uint8Array

A Uint8Array of random bytes of specified length.

Defined in

packages/util/src/bytes.ts:458


setLengthLeft

setLengthLeft(msg, length): Uint8Array

Left Pads a Uint8Array with leading zeros till it has length bytes. Or it truncates the beginning if it exceeds.

Parameters

Name Type Description
msg Uint8Array the value to pad
length number the number of bytes the output should be

Returns

Uint8Array

Defined in

packages/util/src/bytes.ts:201


setLengthRight

setLengthRight(msg, length): Uint8Array

Right Pads a Uint8Array with trailing zeros till it has length bytes. it truncates the end if it exceeds.

Parameters

Name Type Description
msg Uint8Array the value to pad
length number the number of bytes the output should be

Returns

Uint8Array

Defined in

packages/util/src/bytes.ts:213


short

short(bytes, maxLength?): string

Shortens a string or Uint8Array’s hex string representation to maxLength (default 50).

Examples:

Input: ‘657468657265756d000000000000000000000000000000000000000000000000’ Output: ‘657468657265756d0000000000000000000000000000000000…’

Parameters

Name Type Default value
bytes string | Uint8Array undefined
maxLength number 50

Returns

string

Defined in

packages/util/src/bytes.ts:366


stripHexPrefix

stripHexPrefix(str): string

Removes ‘0x’ from a given String if present

Parameters

Name Type Description
str string the string value

Returns

string

the string without 0x prefix

Defined in

packages/util/src/internal.ts:46


toAscii

toAscii(hex): string

Should be called to get ascii from its hex representation

Parameters

Name Type
hex string

Returns

string

ascii string representation of hex value

Defined in

packages/util/src/internal.ts:116


toBytes

toBytes(v): Uint8Array

Attempts to turn a value into a Uint8Array. Inputs supported: Buffer, Uint8Array, String (hex-prefixed), Number, null/undefined, BigInt and other objects with a toArray() or toBytes() method.

Parameters

Name Type Description
v ToBytesInputTypes the value

Returns

Uint8Array

Defined in

packages/util/src/bytes.ts:285


toChecksumAddress

toChecksumAddress(hexAddress, eip1191ChainId?): string

Returns a checksummed address.

If an eip1191ChainId is provided, the chainId will be included in the checksum calculation. This has the effect of checksummed addresses for one chain having invalid checksums for others. For more details see EIP-1191.

WARNING: Checksums with and without the chainId will differ and the EIP-1191 checksum is not backwards compatible to the original widely adopted checksum format standard introduced in EIP-55, so this will break in existing applications. Usage of this EIP is therefore discouraged unless you have a very targeted use case.

Parameters

Name Type
hexAddress string
eip1191ChainId? BigIntLike

Returns

string

Defined in

packages/util/src/account.ts:162


toCompactSig

toCompactSig(v, r, s, chainId?): string

Convert signature parameters into the format of Compact Signature Representation (EIP-2098). NOTE: Accepts v === 0 | v === 1 for EIP1559 transactions

Parameters

Name Type
v bigint
r Uint8Array
s Uint8Array
chainId? bigint

Returns

string

Signature

Defined in

packages/util/src/signature.ts:115


toRpcSig

toRpcSig(v, r, s, chainId?): string

Convert signature parameters into the format of eth_sign RPC method. NOTE: Accepts v === 0 | v === 1 for EIP1559 transactions

Parameters

Name Type
v bigint
r Uint8Array
s Uint8Array
chainId? bigint

Returns

string

Signature

Defined in

packages/util/src/signature.ts:94


toType

toType<T>(input, outputType): null

Convert an input to a specified type. Input of null/undefined returns null/undefined regardless of the output type.

Type parameters

Name Type
T extends TypeOutput

Parameters

Name Type Description
input null value to convert
outputType T type to output

Returns

null

Defined in

packages/util/src/types.ts:62

toType<T>(input, outputType): undefined

Type parameters

Name Type
T extends TypeOutput

Parameters

Name Type
input undefined
outputType T

Returns

undefined

Defined in

packages/util/src/types.ts:63

toType<T>(input, outputType): TypeOutputReturnType[T]

Type parameters

Name Type
T extends TypeOutput

Parameters

Name Type
input ToBytesInputTypes
outputType T

Returns

TypeOutputReturnType[T]

Defined in

packages/util/src/types.ts:64


toUnsigned

toUnsigned(num): Uint8Array

Converts a BigInt to an unsigned integer and returns it as a Uint8Array. Assumes 256-bit numbers.

Parameters

Name Type
num bigint

Returns

Uint8Array

Defined in

packages/util/src/bytes.ts:338


unpadArray

unpadArray(a): number[]

Trims leading zeros from an Array (of numbers).

Parameters

Name Type
a number[]

Returns

number[]

Defined in

packages/util/src/bytes.ts:251


unpadBytes

unpadBytes(a): Uint8Array

Trims leading zeros from a Uint8Array.

Parameters

Name Type
a Uint8Array

Returns

Uint8Array

Defined in

packages/util/src/bytes.ts:241


unpadHex

unpadHex(a): string

Trims leading zeros from a PrefixedHexString.

Parameters

Name Type
a string

Returns

string

Defined in

packages/util/src/bytes.ts:261


unprefixedHexToBytes

unprefixedHexToBytes(inp): Uint8Array

Deprecated

Parameters

Name Type
inp string

Returns

Uint8Array

Defined in

packages/util/src/bytes.ts:48


utf8ToBytes

utf8ToBytes(str): Uint8Array

Example

utf8ToBytes('abc') // new Uint8Array([97, 98, 99])

Parameters

Name Type
str string

Returns

Uint8Array

Defined in

node_modules/@noble/hashes/utils.d.ts:21


validateNoLeadingZeroes

validateNoLeadingZeroes(values): void

Checks provided Uint8Array for leading zeroes and throws if found.

Examples:

Valid values: 0x1, 0x, 0x01, 0x1234 Invalid values: 0x0, 0x00, 0x001, 0x0001

Note: This method is useful for validating that RLP encoded integers comply with the rule that all integer values encoded to RLP must be in the most compact form and contain no leading zero bytes

Throws

if any provided value is found to have leading zero bytes

Parameters

Name Type Description
values Object An object containing string keys and Uint8Array values

Returns

void

Defined in

packages/util/src/bytes.ts:388


zeroAddress

zeroAddress(): string

Returns the zero address.

Returns

string

Defined in

packages/util/src/account.ts:337


zeros

zeros(bytes): Uint8Array

Returns a Uint8Array filled with 0s.

Parameters

Name Type Description
bytes number the number of bytes of the Uint8Array

Returns

Uint8Array

Defined in

packages/util/src/bytes.ts:168