@ethereumjs/util
Ƭ AccountBodyBytes: [Uint8Array
, Uint8Array
, Uint8Array
, Uint8Array
]
packages/util/src/account.ts:29
Ƭ AccountState: [balance: PrefixedHexString, code: PrefixedHexString, storage: StoragePair[], nonce: PrefixedHexString]
packages/util/src/genesis.ts:8
Ƭ AddressLike: Address
| Uint8Array
| PrefixedHexString
A type that represents an input that can be converted to an Address.
Ƭ BatchDBOp<TKey
, TValue
>: PutBatch
<TKey
, TValue
> | DelBatch
<TKey
>
Name | Type |
---|---|
TKey |
extends Uint8Array | string | number = Uint8Array |
TValue |
extends Uint8Array | string | DBObject = Uint8Array |
Ƭ BigIntLike: bigint
| PrefixedHexString
| number
| Uint8Array
Ƭ BytesLike: Uint8Array
| number
[] | number
| bigint
| TransformabletoBytes
| PrefixedHexString
Ƭ DBObject: Object
▪ [key: string
]: string
| string
[] | number
Ƭ EncodingOpts: Object
Name | Type |
---|---|
keyEncoding? |
KeyEncoding |
valueEncoding? |
ValueEncoding |
Ƭ NestedUint8Array: (Uint8Array
| NestedUint8Array
)[]
Ƭ PrefixedHexString: string
Ƭ StoragePair: [key: PrefixedHexString, value: PrefixedHexString]
packages/util/src/genesis.ts:6
Ƭ ToBytesInputTypes: PrefixedHexString
| number
| bigint
| Uint8Array
| number
[] | TransformabletoBytes
| null
| undefined
packages/util/src/bytes.ts:267
Ƭ TypeOutputReturnType: Object
Name | Type |
---|---|
0 |
number |
1 |
bigint |
2 |
Uint8Array |
3 |
PrefixedHexString |
Ƭ WithdrawalBytes: [Uint8Array
, Uint8Array
, Uint8Array
, Uint8Array
]
packages/util/src/withdrawal.ts:30
Ƭ WithdrawalData: Object
Flexible input data type for EIP-4895 withdrawal data with amount in Gwei to match CL representation and for eventual ssz withdrawalsRoot
Name | Type |
---|---|
address |
AddressLike |
amount |
BigIntLike |
index |
BigIntLike |
validatorIndex |
BigIntLike |
packages/util/src/withdrawal.ts:12
• Const
BIGINT_0: bigint
packages/util/src/constants.ts:82
• Const
BIGINT_1: bigint
packages/util/src/constants.ts:83
• Const
BIGINT_100: bigint
packages/util/src/constants.ts:100
• Const
BIGINT_128: bigint
packages/util/src/constants.ts:95
• Const
BIGINT_160: bigint
packages/util/src/constants.ts:101
• Const
BIGINT_2: bigint
packages/util/src/constants.ts:84
• Const
BIGINT_224: bigint
packages/util/src/constants.ts:102
• Const
BIGINT_255: bigint
packages/util/src/constants.ts:96
• Const
BIGINT_256: bigint
packages/util/src/constants.ts:97
• Const
BIGINT_27: bigint
packages/util/src/constants.ts:89
• Const
BIGINT_28: bigint
packages/util/src/constants.ts:90
• Const
BIGINT_2EXP160: bigint
packages/util/src/constants.ts:104
• Const
BIGINT_2EXP224: bigint
packages/util/src/constants.ts:105
• Const
BIGINT_2EXP256: bigint
packages/util/src/constants.ts:107
• Const
BIGINT_2EXP96: bigint
packages/util/src/constants.ts:103
• Const
BIGINT_3: bigint
packages/util/src/constants.ts:85
• Const
BIGINT_31: bigint
packages/util/src/constants.ts:91
• Const
BIGINT_32: bigint
packages/util/src/constants.ts:92
• Const
BIGINT_64: bigint
packages/util/src/constants.ts:93
• Const
BIGINT_7: bigint
packages/util/src/constants.ts:86
• Const
BIGINT_8: bigint
packages/util/src/constants.ts:87
• Const
BIGINT_96: bigint
packages/util/src/constants.ts:99
• Const
BIGINT_NEG1: bigint
BigInt constants
packages/util/src/constants.ts:80
• Const
GWEI_TO_WEI: bigint
Easy conversion from Gwei to wei
• Const
KECCAK256_NULL: Uint8Array
Keccak-256 hash of null
packages/util/src/constants.ts:44
• Const
KECCAK256_NULL_S: "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
Keccak-256 hash of null
packages/util/src/constants.ts:39
• Const
KECCAK256_RLP: Uint8Array
Keccak-256 hash of the RLP of null
packages/util/src/constants.ts:65
• Const
KECCAK256_RLP_ARRAY: Uint8Array
Keccak-256 of an RLP of an empty array
packages/util/src/constants.ts:55
• Const
KECCAK256_RLP_ARRAY_S: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
Keccak-256 of an RLP of an empty array
packages/util/src/constants.ts:49
• Const
KECCAK256_RLP_S: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
Keccak-256 hash of the RLP of null
packages/util/src/constants.ts:60
• Const
MAX_INTEGER: bigint
The max integer that the evm can handle (2^256-1)
packages/util/src/constants.ts:13
• 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.
packages/util/src/constants.ts:22
• Const
MAX_UINT64: bigint
2^64-1
packages/util/src/constants.ts:8
• Const
MAX_WITHDRAWALS_PER_PAYLOAD: 16
packages/util/src/constants.ts:72
• Const
RIPEMD160_ADDRESS_STRING: "0000000000000000000000000000000000000003"
packages/util/src/constants.ts:74
• Const
RLP_EMPTY_STRING: Uint8Array
RLP encoded empty string
packages/util/src/constants.ts:70
• Const
SECP256K1_ORDER: bigint
= secp256k1.CURVE.n
packages/util/src/constants.ts:26
• Const
SECP256K1_ORDER_DIV_2: bigint
packages/util/src/constants.ts:27
• Const
TWO_POW256: bigint
2^256
packages/util/src/constants.ts:32
• kzg: Kzg
▸ accountBodyFromSlim(body
): Uint8Array
[]
Name | Type |
---|---|
body |
AccountBodyBytes |
Uint8Array
[]
packages/util/src/account.ts:357
▸ accountBodyToRLP(body
, couldBeSlim?
): Uint8Array
Converts a slim account (per snap protocol spec) to the RLP encoded version of the account
Name | Type | Default value | Description |
---|---|---|---|
body |
AccountBodyBytes |
undefined |
Array of 4 Uint8Array-like items to represent the account |
couldBeSlim |
boolean |
true |
- |
Uint8Array
RLP encoded version of the account
packages/util/src/account.ts:383
▸ accountBodyToSlim(body
): Uint8Array
[]
Name | Type |
---|---|
body |
AccountBodyBytes |
Uint8Array
[]
packages/util/src/account.ts:368
▸ addHexPrefix(str
): string
Adds “0x” to a given string
if it does not already start with “0x”.
Name | Type |
---|---|
str |
string |
string
packages/util/src/bytes.ts:347
▸ arrayContainsArray(superset
, subset
, some?
): boolean
Returns TRUE if the first specified array contains all elements from the second one. FALSE otherwise.
Name | Type |
---|---|
superset |
unknown [] |
subset |
unknown [] |
some? |
boolean |
boolean
packages/util/src/internal.ts:91
▸ bigInt64ToBytes(value
, littleEndian?
): Uint8Array
Notice
Convert a 64-bit bigint to a Uint8Array.
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. |
Uint8Array
A Uint8Array of length 8 containing the bigint.
packages/util/src/bytes.ts:529
▸ bigIntMax(…args
): bigint
Calculates max bigint from an array of bigints
Name | Type | Description |
---|---|---|
...args |
bigint [] |
array of bigints |
bigint
packages/util/src/bytes.ts:409
▸ bigIntMin(…args
): bigint
Calculates min BigInt from an array of BigInts
Name | Type | Description |
---|---|---|
...args |
bigint [] |
array of bigints |
bigint
packages/util/src/bytes.ts:415
▸ bigIntToBytes(num
, littleEndian?
): Uint8Array
Converts a bigint to a Uint8Array *
Name | Type | Default value | Description |
---|---|---|---|
num |
bigint |
undefined |
the bigint to convert |
littleEndian |
boolean |
false |
- |
Uint8Array
packages/util/src/bytes.ts:156
▸ bigIntToHex(num
): string
Converts a bigint to a 0x
prefixed hex string
Name | Type | Description |
---|---|---|
num |
bigint |
the bigint to convert |
string
packages/util/src/bytes.ts:401
▸ bigIntToUnpaddedBytes(value
): Uint8Array
Convert value from bigint to an unpadded Uint8Array (useful for RLP transport)
Name | Type | Description |
---|---|---|
value |
bigint |
the bigint to convert |
Uint8Array
packages/util/src/bytes.ts:423
▸ blobsToCommitments(blobs
): Uint8Array
[]
Name | Type |
---|---|
blobs |
Uint8Array [] |
Uint8Array
[]
▸ blobsToProofs(blobs
, commitments
): Uint8Array
[]
Name | Type |
---|---|
blobs |
Uint8Array [] |
commitments |
Uint8Array [] |
Uint8Array
[]
▸ bytesToBigInt(bytes
, littleEndian?
): bigint
Converts a Uint8Array to a bigint
Name | Type | Default value | Description |
---|---|---|---|
bytes |
Uint8Array |
undefined |
the bytes to convert |
littleEndian |
boolean |
false |
- |
bigint
▸ bytesToBigInt64(bytes
, littleEndian?
): bigint
Notice
Convert a Uint8Array to a 64-bit bigint
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. |
bigint
The 64-bit bigint read from the input Uint8Array.
packages/util/src/bytes.ts:502
▸ bytesToHex(bytes
): string
Name | Type |
---|---|
bytes |
Uint8Array |
string
▸ bytesToInt(bytes
): number
Converts a Uint8Array to a number.
Throws
If the input number exceeds 53 bits.
Name | Type | Description |
---|---|---|
bytes |
Uint8Array |
the bytes to convert |
number
packages/util/src/bytes.ts:104
▸ bytesToInt32(bytes
, littleEndian?
): number
Notice
Convert a Uint8Array to a 32-bit integer
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. |
number
The 32-bit integer read from the input Uint8Array.
packages/util/src/bytes.ts:488
▸ bytesToUnprefixedHex(bytes
): string
Example
bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
Name | Type |
---|---|
bytes |
Uint8Array |
string
node_modules/@noble/hashes/utils.d.ts:11
▸ bytesToUtf8(data
): string
Name | Type |
---|---|
data |
Uint8Array |
string
node_modules/ethereum-cryptography/utils.d.ts:5
▸ calculateSigRecovery(v
, chainId?
): bigint
Name | Type |
---|---|
v |
bigint |
chainId? |
bigint |
bigint
packages/util/src/signature.ts:53
▸ commitmentsToVersionedHashes(commitments
): Uint8Array
[]
Generate an array of versioned hashes from corresponding kzg commitments
Name | Type | Description |
---|---|---|
commitments |
Uint8Array [] |
array of kzg commitments |
Uint8Array
[]
array of versioned hashes Note: assumes KZG commitments (version 1 version hashes)
▸ compareBytes(value1
, value2
): number
Compares two Uint8Arrays and returns a number indicating their order in a sorted array.
Name | Type | Description |
---|---|---|
value1 |
Uint8Array |
The first Uint8Array to compare. |
value2 |
Uint8Array |
The second Uint8Array to compare. |
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.
packages/util/src/bytes.ts:446
▸ 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
Name | Type | Description |
---|---|---|
commitment |
Uint8Array |
a vector commitment to a blob |
blobCommitmentVersion |
number |
the version number corresponding to the type of vector commitment |
Uint8Array
a versioned hash corresponding to a given blob vector commitment
▸ 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
Name | Type | Description |
---|---|---|
...arrays |
Uint8Array [] |
an array of Uint8Arrays |
Uint8Array
one Uint8Array with all the elements of the original set
works like Buffer.concat
packages/util/src/bytes.ts:470
▸ ecrecover(msgHash
, v
, r
, s
, chainId?
): Uint8Array
ECDSA public key recovery from signature.
NOTE: Accepts v === 0 | v === 1
for EIP1559 transactions
Name | Type |
---|---|
msgHash |
Uint8Array |
v |
bigint |
r |
Uint8Array |
s |
Uint8Array |
chainId? |
bigint |
Uint8Array
Recovered public key
packages/util/src/signature.ts:71
▸ 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
Name | Type |
---|---|
msgHash |
Uint8Array |
privateKey |
Uint8Array |
chainId? |
bigint |
packages/util/src/signature.ts:35
▸ equalsBytes(a
, b
): boolean
Name | Type |
---|---|
a |
Uint8Array |
b |
Uint8Array |
boolean
node_modules/ethereum-cryptography/utils.d.ts:7
▸ 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
Name | Type |
---|---|
params |
Record <string , string >[] |
key |
string |
allowEmpty? |
boolean |
string
[]
packages/util/src/internal.ts:174
▸ getProvider(provider
): string
Name | Type | Description |
---|---|---|
provider |
string | EthersProvider |
a URL string or EthersProvider |
string
the extracted URL string for the JSON-RPC Provider
packages/util/src/provider.ts:63
▸ 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.
Name | Type |
---|---|
message |
Uint8Array |
Uint8Array
packages/util/src/signature.ts:219
▸ hexToBytes(hex
): Uint8Array
Name | Type |
---|---|
hex |
string |
Uint8Array
packages/util/src/bytes.ts:110
▸ importPublic(publicKey
): Uint8Array
Converts a public key to the Ethereum format.
Name | Type |
---|---|
publicKey |
Uint8Array |
Uint8Array
packages/util/src/account.ts:326
▸ initKZG(kzgLib
, trustedSetupPath?
): void
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 |
void
▸ int32ToBytes(value
, littleEndian?
): Uint8Array
Notice
Convert a 32-bit integer to a Uint8Array.
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. |
Uint8Array
A Uint8Array of length 4 containing the integer.
packages/util/src/bytes.ts:516
▸ intToBytes(i
): Uint8Array
Converts an number to a Uint8Array
Name | Type |
---|---|
i |
number |
Uint8Array
packages/util/src/bytes.ts:146
▸ intToHex(i
): string
Converts a number into a PrefixedHexString
Name | Type |
---|---|
i |
number |
string
packages/util/src/bytes.ts:134
▸ intToUnpaddedBytes(value
): Uint8Array
Convert value from number to an unpadded Uint8Array (useful for RLP transport)
Name | Type | Description |
---|---|---|
value |
number |
the bigint to convert |
Uint8Array
packages/util/src/bytes.ts:433
▸ 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
Name | Type | Description |
---|---|---|
str |
string |
the string input value |
boolean
a boolean if it is or is not hex prefixed
packages/util/src/internal.ts:33
▸ isHexString(value
, length?
): boolean
Is the string a hex string.
Name | Type |
---|---|
value |
string |
length? |
number |
boolean
output the string is a hex string
packages/util/src/internal.ts:206
▸ isValidAddress(hexAddress
): boolean
Checks if the address is a valid. Accepts checksummed addresses too.
Name | Type |
---|---|
hexAddress |
string |
boolean
packages/util/src/account.ts:140
▸ isValidChecksumAddress(hexAddress
, eip1191ChainId?
): boolean
Checks if the address is a valid checksummed address.
See toChecksumAddress’ documentation for details about the eip1191ChainId parameter.
Name | Type |
---|---|
hexAddress |
string |
eip1191ChainId? |
BigIntLike |
boolean
packages/util/src/account.ts:195
▸ isValidPrivate(privateKey
): boolean
Checks if the private key satisfies the rules of the curve secp256k1.
Name | Type |
---|---|
privateKey |
Uint8Array |
boolean
packages/util/src/account.ts:251
▸ isValidPublic(publicKey
, sanitize?
): boolean
Checks if the public key satisfies the rules of the curve secp256k1 and the requirements of Ethereum.
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 |
boolean
packages/util/src/account.ts:261
▸ isValidSignature(v
, r
, s
, homesteadOrLater?
, chainId?
): boolean
Validate a ECDSA signature.
NOTE: Accepts v === 0 | v === 1
for EIP1559 transactions
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 |
- |
boolean
packages/util/src/signature.ts:179
▸ isZeroAddress(hexAddress
): boolean
Checks if a given address is the zero address.
Name | Type |
---|---|
hexAddress |
string |
boolean
packages/util/src/account.ts:346
▸ padToEven(value
): string
Pads a String
to have an even length
Name | Type |
---|---|
value |
string |
string
output
packages/util/src/internal.ts:58
▸ parseGethGenesisState(json
): GenesisState
Parses the geth genesis state into Blockchain GenesisState
Name | Type | Description |
---|---|---|
json |
any |
representing the alloc key in a Geth genesis file |
packages/util/src/genesis.ts:47
▸ privateToAddress(privateKey
): Uint8Array
Returns the ethereum address of a given private key.
Name | Type | Description |
---|---|---|
privateKey |
Uint8Array |
A private key must be 256 bits wide |
Uint8Array
packages/util/src/account.ts:319
▸ privateToPublic(privateKey
): Uint8Array
Returns the ethereum public key of a given private key.
Name | Type | Description |
---|---|---|
privateKey |
Uint8Array |
A private key must be 256 bits wide |
Uint8Array
packages/util/src/account.ts:309
▸ pubToAddress(pubKey
, sanitize?
): Uint8Array
Returns the ethereum address of a given public key. Accepts “Ethereum public keys” and SEC1 encoded keys.
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 |
Uint8Array
packages/util/src/account.ts:292
▸ publicToAddress(pubKey
, sanitize?
): Uint8Array
Returns the ethereum address of a given public key. Accepts “Ethereum public keys” and SEC1 encoded keys.
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 |
Uint8Array
packages/util/src/account.ts:292
▸ randomBytes(length
): Uint8Array
Generates a Uint8Array of random bytes of specified length.
Name | Type | Description |
---|---|---|
length |
number |
The length of the Uint8Array. |
Uint8Array
A Uint8Array of random bytes of specified length.
packages/util/src/bytes.ts:458
▸ setLengthLeft(msg
, length
): Uint8Array
Left Pads a Uint8Array
with leading zeros till it has length
bytes.
Or it truncates the beginning if it exceeds.
Name | Type | Description |
---|---|---|
msg |
Uint8Array |
the value to pad |
length |
number |
the number of bytes the output should be |
Uint8Array
packages/util/src/bytes.ts:201
▸ setLengthRight(msg
, length
): Uint8Array
Right Pads a Uint8Array
with trailing zeros till it has length
bytes.
it truncates the end if it exceeds.
Name | Type | Description |
---|---|---|
msg |
Uint8Array |
the value to pad |
length |
number |
the number of bytes the output should be |
Uint8Array
packages/util/src/bytes.ts:213
▸ short(bytes
, maxLength?
): string
Shortens a string or Uint8Array’s hex string representation to maxLength (default 50).
Examples:
Input: ‘657468657265756d000000000000000000000000000000000000000000000000’ Output: ‘657468657265756d0000000000000000000000000000000000…’
Name | Type | Default value |
---|---|---|
bytes |
string | Uint8Array |
undefined |
maxLength |
number |
50 |
string
packages/util/src/bytes.ts:366
▸ stripHexPrefix(str
): string
Removes ‘0x’ from a given String
if present
Name | Type | Description |
---|---|---|
str |
string |
the string value |
string
the string without 0x prefix
packages/util/src/internal.ts:46
▸ toAscii(hex
): string
Should be called to get ascii from its hex representation
Name | Type |
---|---|
hex |
string |
string
ascii string representation of hex value
packages/util/src/internal.ts:116
▸ 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.
Name | Type | Description |
---|---|---|
v |
ToBytesInputTypes |
the value |
Uint8Array
packages/util/src/bytes.ts:285
▸ 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.
Name | Type |
---|---|
hexAddress |
string |
eip1191ChainId? |
BigIntLike |
string
packages/util/src/account.ts:162
▸ 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
Name | Type |
---|---|
v |
bigint |
r |
Uint8Array |
s |
Uint8Array |
chainId? |
bigint |
string
Signature
packages/util/src/signature.ts:115
▸ 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
Name | Type |
---|---|
v |
bigint |
r |
Uint8Array |
s |
Uint8Array |
chainId? |
bigint |
string
Signature
packages/util/src/signature.ts:94
▸ toType<T
>(input
, outputType
): null
Convert an input to a specified type. Input of null/undefined returns null/undefined regardless of the output type.
Name | Type |
---|---|
T |
extends TypeOutput |
Name | Type | Description |
---|---|---|
input |
null |
value to convert |
outputType |
T |
type to output |
null
▸ toType<T
>(input
, outputType
): undefined
Name | Type |
---|---|
T |
extends TypeOutput |
Name | Type |
---|---|
input |
undefined |
outputType |
T |
undefined
▸ toType<T
>(input
, outputType
): TypeOutputReturnType
[T
]
Name | Type |
---|---|
T |
extends TypeOutput |
Name | Type |
---|---|
input |
ToBytesInputTypes |
outputType |
T |
▸ toUnsigned(num
): Uint8Array
Converts a BigInt
to an unsigned integer and returns it as a Uint8Array
. Assumes 256-bit numbers.
Name | Type |
---|---|
num |
bigint |
Uint8Array
packages/util/src/bytes.ts:338
▸ unpadArray(a
): number
[]
Trims leading zeros from an Array
(of numbers).
Name | Type |
---|---|
a |
number [] |
number
[]
packages/util/src/bytes.ts:251
▸ unpadBytes(a
): Uint8Array
Trims leading zeros from a Uint8Array
.
Name | Type |
---|---|
a |
Uint8Array |
Uint8Array
packages/util/src/bytes.ts:241
▸ unpadHex(a
): string
Trims leading zeros from a PrefixedHexString
.
Name | Type |
---|---|
a |
string |
string
packages/util/src/bytes.ts:261
▸ unprefixedHexToBytes(inp
): Uint8Array
Deprecated
Name | Type |
---|---|
inp |
string |
Uint8Array
▸ utf8ToBytes(str
): Uint8Array
Example
utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
Name | Type |
---|---|
str |
string |
Uint8Array
node_modules/@noble/hashes/utils.d.ts:21
▸ 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
Name | Type | Description |
---|---|---|
values |
Object |
An object containing string keys and Uint8Array values |
void
packages/util/src/bytes.ts:388
▸ zeroAddress(): string
Returns the zero address.
string
packages/util/src/account.ts:337
▸ zeros(bytes
): Uint8Array
Returns a Uint8Array filled with 0s.
Name | Type | Description |
---|---|---|
bytes |
number |
the number of bytes of the Uint8Array |
Uint8Array