Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Latest commit

 

History

History
1017 lines (619 loc) · 24.5 KB

README.md

File metadata and controls

1017 lines (619 loc) · 24.5 KB

ethereumjs-util

Index

Interfaces

Variables

Functions


Variables

<Const> Buffer

● Buffer: any = require('safe-buffer').Buffer

Defined in index.ts:7


<Const> KECCAK256_NULL

● KECCAK256_NULL: Buffer = Buffer.from(KECCAK256_NULL_S, 'hex')

Defined in index.ts:42

Keccak-256 hash of null


<Const> KECCAK256_NULL_S

● KECCAK256_NULL_S: string = "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"

Defined in index.ts:36

Keccak-256 hash of null


<Const> KECCAK256_RLP

● KECCAK256_RLP: Buffer = Buffer.from(KECCAK256_RLP_S, 'hex')

Defined in index.ts:64

Keccak-256 hash of the RLP of null


<Const> KECCAK256_RLP_ARRAY

● KECCAK256_RLP_ARRAY: Buffer = Buffer.from(KECCAK256_RLP_ARRAY_S, 'hex')

Defined in index.ts:53

Keccak-256 of an RLP of an empty array


<Const> KECCAK256_RLP_ARRAY_S

● KECCAK256_RLP_ARRAY_S: string = "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"

Defined in index.ts:47

Keccak-256 of an RLP of an empty array


<Const> KECCAK256_RLP_S

● KECCAK256_RLP_S: string = "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"

Defined in index.ts:58

Keccak-256 hash of the RLP of null


<Const> MAX_INTEGER

● MAX_INTEGER: BN = new BN( 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16, )

Defined in index.ts:20

The max integer that this VM can handle


<Const> TWO_POW256

● TWO_POW256: BN = new BN( '10000000000000000000000000000000000000000000000000000000000000000', 16, )

Defined in index.ts:28

2^256


<Const> assert

● assert: any = require('assert')

Defined in index.ts:5


<Const> createHash

● createHash: any = require('create-hash')

Defined in index.ts:6


<Const> createKeccakHash

● createKeccakHash: any = require('keccak')

Defined in index.ts:3


<Const> ethjsUtil

● ethjsUtil: any = require('ethjs-util')

Defined in index.ts:8


<Const> publicToAddress

● publicToAddress: pubToAddress = pubToAddress

Defined in index.ts:315


<Const> secp256k1

● secp256k1: any = require('secp256k1')

Defined in index.ts:4


<Const> setLength

● setLength: setLengthLeft = setLengthLeft

Defined in index.ts:123


<Const> stripZeros

● stripZeros: unpad = unpad

Defined in index.ts:150


Functions

<Const> addHexPrefix

addHexPrefix(str: string): string

Defined in index.ts:532

Adds "0x" to a given String if it does not already start with "0x".

Parameters:

Name Type
str string

Returns: string


<Const> baToJSON

baToJSON(ba: any): undefined | string | any[]

Defined in index.ts:584

Converts a Buffer or Array to JSON.

Parameters:

Name Type Description
ba any (Buffer

Returns: undefined | string | any[] (Array|String|null)


<Const> bufferToHex

bufferToHex(buf: Buffer): string

Defined in index.ts:195

Converts a Buffer into a hex String.

Parameters:

Name Type Description
buf Buffer `Buffer` object to convert

Returns: string


<Const> bufferToInt

bufferToInt(buf: Buffer): number

Defined in index.ts:187

Converts a Buffer to a Number.

Parameters:

Name Type Description
buf Buffer `Buffer` object to convert

Returns: number


calculateSigRecovery

calculateSigRecovery(v: number, chainId?: undefined | number): number

Defined in index.ts:708

Parameters:

Name Type
v number
Optional chainId undefined

Returns: number


<Const> defineProperties

defineProperties(self: any, fields: any, data: any): void

Defined in index.ts:606

Defines properties on a Object. It make the assumption that underlying data is binary.

Parameters:

Name Type Description
self any the `Object` to define properties on
fields any an array fields to define. Fields can contain:* `name` - the name of the properties* `length` - the number of bytes the field can have* `allowLess` - if the field can be less than the length* `allowEmpty`
data any data to be validated against the definitions

Returns: void


<Const> ecrecover

ecrecover(msgHash: Buffer, v: number, r: Buffer, s: Buffer, chainId?: undefined | number): Buffer

Defined in index.ts:373

ECDSA public key recovery from signature.

Parameters:

Name Type
msgHash Buffer
v number
r Buffer
s Buffer
Optional chainId undefined

Returns: Buffer Recovered public key


<Const> ecsign

ecsign(msgHash: Buffer, privateKey: Buffer, chainId?: undefined | number): ECDSASignature

Defined in index.ts:341

Returns the ECDSA signature of a message hash.

Parameters:

Name Type
msgHash Buffer
privateKey Buffer
Optional chainId undefined

Returns: ECDSASignature


<Const> fromRpcSig

fromRpcSig(sig: string): ECDSASignature

Defined in index.ts:407

Convert signature format of the eth_sign RPC method to signature parameters NOTE: all because of a bug in geth: ethereum/go-ethereum#2053

Parameters:

Name Type
sig string

Returns: ECDSASignature


<Const> fromSigned

fromSigned(num: Buffer): BN

Defined in index.ts:204

Interprets a Buffer as a signed integer and returns a BN. Assumes 256-bit numbers.

Parameters:

Name Type Description
num Buffer Signed integer value

Returns: BN


<Const> generateAddress

generateAddress(from: Buffer, nonce: Buffer): Buffer

Defined in index.ts:482

Generates an address of a newly created contract.

Parameters:

Name Type Description
from Buffer The address which is creating this new address
nonce Buffer The nonce of the from account

Returns: Buffer


<Const> generateAddress2

generateAddress2(from: Buffer | string, salt: Buffer | string, initCode: Buffer | string): Buffer

Defined in index.ts:502

Generates an address for a contract created using CREATE2.

Parameters:

Name Type Description
from Buffer string
salt Buffer string
initCode Buffer string

Returns: Buffer


<Const> hashPersonalMessage

hashPersonalMessage(message: any): Buffer

Defined in index.ts:364

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 any

Returns: Buffer


<Const> importPublic

importPublic(publicKey: Buffer): Buffer

Defined in index.ts:330

Converts a public key to the Ethereum format.

Parameters:

Name Type
publicKey Buffer

Returns: Buffer


<Const> isPrecompiled

isPrecompiled(address: Buffer | string): boolean

Defined in index.ts:524

Returns true if the supplied address belongs to a precompiled account (Byzantium).

Parameters:

Name Type
address Buffer

Returns: boolean


<Const> isValidAddress

isValidAddress(address: string): boolean

Defined in index.ts:439

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

Parameters:

Name Type
address string

Returns: boolean


<Const> isValidChecksumAddress

isValidChecksumAddress(address: string): boolean

Defined in index.ts:473

Checks if the address is a valid checksummed address.

Parameters:

Name Type
address string

Returns: boolean


<Const> isValidPrivate

isValidPrivate(privateKey: Buffer): boolean

Defined in index.ts:277

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

Parameters:

Name Type
privateKey Buffer

Returns: boolean


<Const> isValidPublic

isValidPublic(publicKey: Buffer, sanitize?: boolean): boolean

Defined in index.ts:287

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

Parameters:

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

Returns: boolean


isValidSigRecovery

isValidSigRecovery(recovery: number): boolean

Defined in index.ts:712

Parameters:

Name Type
recovery number

Returns: boolean


<Const> isValidSignature

isValidSignature(v: number, r: Buffer, s: Buffer, homestead?: boolean, chainId?: undefined | number): boolean

Defined in index.ts:544

Validate a ECDSA signature.

Parameters:

Name Type Default value
v number -
r Buffer -
s Buffer -
Default value homestead boolean true
Optional chainId undefined number

Returns: boolean


<Const> isZeroAddress

isZeroAddress(address: string): boolean

Defined in index.ts:446

Checks if a given address is a zero address.

Parameters:

Name Type
address string

Returns: boolean


<Const> keccak

keccak(a: any, bits?: number): Buffer

Defined in index.ts:221

Creates Keccak hash of the input

Parameters:

Name Type Default value Description
a any - The input data (Buffer
Default value bits number 256 The Keccak width

Returns: Buffer


<Const> keccak256

keccak256(a: any): Buffer

Defined in index.ts:234

Creates Keccak-256 hash of the input, alias for keccak(a, 256).

Parameters:

Name Type Description
a any The input data (Buffer

Returns: Buffer


<Const> privateToAddress

privateToAddress(privateKey: Buffer): Buffer

Defined in index.ts:432

Returns the ethereum address of a given private key.

Parameters:

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

Returns: Buffer


<Const> privateToPublic

privateToPublic(privateKey: Buffer): Buffer

Defined in index.ts:321

Returns the ethereum public key of a given private key.

Parameters:

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

Returns: Buffer


<Const> pubToAddress

pubToAddress(pubKey: Buffer, sanitize?: boolean): Buffer

Defined in index.ts:306

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

Parameters:

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

Returns: Buffer


<Const> ripemd160

ripemd160(a: any, padded: boolean): Buffer

Defined in index.ts:254

Creates RIPEMD160 hash of the input.

Parameters:

Name Type Description
a any The input data (Buffer
padded boolean Whether it should be padded to 256 bits or not

Returns: Buffer


<Const> rlphash

rlphash(a: rlp.Input): Buffer

Defined in index.ts:270

Creates SHA-3 hash of the RLP encoded version of the input.

Parameters:

Name Type Description
a rlp.Input The input data

Returns: Buffer


<Const> setLengthLeft

setLengthLeft(msg: any, length: number, right?: boolean): any

Defined in index.ts:106

Left Pads an Array or Buffer with leading zeros till it has length bytes. Or it truncates the beginning if it exceeds.

Parameters:

Name Type Default value Description
msg any - the value to pad (Buffer
length number - the number of bytes the output should be
Default value right boolean false whether to start padding form the left or right

Returns: any (Buffer|Array)


<Const> setLengthRight

setLengthRight(msg: any, length: number): any

Defined in index.ts:132

Right Pads an Array or Buffer with leading zeros till it has length bytes. Or it truncates the beginning if it exceeds.

Parameters:

Name Type Description
msg any the value to pad (Buffer
length number the number of bytes the output should be

Returns: any (Buffer|Array)


<Const> sha256

sha256(a: any): Buffer

Defined in index.ts:242

Creates SHA256 hash of the input.

Parameters:

Name Type Description
a any The input data (Buffer

Returns: Buffer


<Const> toBuffer

toBuffer(v: any): Buffer

Defined in index.ts:156

Attempts to turn a value into a Buffer. As input it supports Buffer, String, Number, null/undefined, BN and other objects with a toArray() method.

Parameters:

Name Type Description
v any the value

Returns: Buffer


<Const> toChecksumAddress

toChecksumAddress(address: string): string

Defined in index.ts:454

Returns a checksummed address.

Parameters:

Name Type
address string

Returns: string


<Const> toRpcSig

toRpcSig(v: number, r: Buffer, s: Buffer, chainId?: undefined | number): string

Defined in index.ts:393

Convert signature parameters into the format of eth_sign RPC method.

Parameters:

Name Type
v number
r Buffer
s Buffer
Optional chainId undefined

Returns: string Signature


<Const> toUnsigned

toUnsigned(num: BN): Buffer

Defined in index.ts:212

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

Parameters:

Name Type Description
num BN

Returns: Buffer


<Const> unpad

unpad(a: any): any

Defined in index.ts:141

Trims leading zeros from a Buffer or an Array.

Parameters:

Name Type Description
a any (Buffer

Returns: any (Buffer|Array|String)


<Const> zeroAddress

zeroAddress(): string

Defined in index.ts:92

Returns a zero address.

Returns: string


<Const> zeros

zeros(bytes: number): Buffer

Defined in index.ts:85

Returns a buffer filled with 0s.

Parameters:

Name Type Description
bytes number the number of bytes the buffer should be

Returns: Buffer