Skip to content

Latest commit

 

History

History
615 lines (349 loc) · 25.1 KB

index.md

File metadata and controls

615 lines (349 loc) · 25.1 KB

Table of Contents

addHexPrefix

index.js:563-569

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

Parameters

Returns String

baToJSON

index.js:613-623

Converts a Buffer or Array to JSON

Parameters

Returns (Array | String | null)

BN

index.js:62-62

BN

Type: Function

bufferToHex

index.js:194-197

Converts a Buffer into a hex String

Parameters

Returns String

bufferToInt

index.js:185-187

Converts a Buffer to a Number

Parameters

  • buf Buffer

  • Throws any If the input number exceeds 53 bits.

Returns Number

defineProperties

index.js:635-728

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

Parameters

  • self Object the Object to define properties on
  • fields Array 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

ecrecover

index.js:383-391

ECDSA public key recovery from signature

Parameters

Returns Buffer publicKey

ecsign

index.js:351-359

ECDSA sign

Parameters

Returns Object

fromRpcSig

index.js:421-440

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

Returns Object

fromSigned

index.js:204-206

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

Parameters

Returns BN

generateAddress

index.js:507-521

Generates an address of a newly created contract

Parameters

  • from Buffer the address which is creating this new address
  • nonce Buffer the nonce of the from account

Returns Buffer

generateAddress2

index.js:530-546

Generates an address for a contract created using CREATE2

Parameters

  • from Buffer the address which is creating this new address
  • salt Buffer a salt
  • initCode Buffer the init code of the contract being created

Returns Buffer

hashPersonalMessage

index.js:369-372

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

  • message

Returns Buffer hash

importPublic

index.js:336-342

Converts a public key to the Ethereum format.

Parameters

Returns Buffer

isPrecompiled

index.js:553-556

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

Parameters

Returns Boolean

isValidAddress

index.js:456-458

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

Parameters

Returns Boolean

isValidChecksumAddress

index.js:497-499

Checks if the address is a valid checksummed address

Parameters

Returns Boolean

isValidPrivate

index.js:279-281

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

Parameters

Returns Boolean

isValidPublic

index.js:290-301

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

Parameters

  • publicKey Buffer The two points of an uncompressed key, unless sanitize is enabled
  • sanitize Boolean Accept public keys in other formats (optional, default false)

Returns Boolean

keccak

index.js:223-228

Creates Keccak hash of the input

Parameters

Returns Buffer

keccak256

index.js:235-237

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

Parameters

Returns Buffer

privateToAddress

index.js:447-449

Returns the ethereum address of a given private key

Parameters

  • privateKey Buffer A private key must be 256 bits wide

Returns Buffer

pubToAddress

index.js:310-318

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

Parameters

  • pubKey Buffer The two points of an uncompressed key, unless sanitize is enabled
  • sanitize Boolean Accept public keys in other formats (optional, default false)

Returns Buffer

ripemd160

index.js:255-263

Creates RIPEMD160 hash of the input

Parameters

Returns Buffer

rlp

index.js:68-68

rlp

Type: Function

rlphash

index.js:270-272

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

Parameters

Returns Buffer

secp256r1

index.js:74-74

secp256r1

Type: Object

setLengthRight

index.js:131-133

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

Parameters

  • msg (Buffer | Array) the value to pad
  • length Number the number of bytes the output should be

Returns (Buffer | Array)

sha256

index.js:244-247

Creates SHA256 hash of the input

Parameters

Returns Buffer

toBuffer

index.js:153-177

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

  • v any the value

toChecksumAddress

index.js:476-490

Returns a checksummed address

Parameters

Returns String

toRpcSig

index.js:401-413

Convert signature parameters into the format of eth_sign RPC method

Parameters

Returns String sig

toUnsigned

index.js:213-215

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

Parameters

  • num BN

Returns Buffer

unpad

index.js:140-148

Trims leading zeros from a Buffer or an Array

Parameters

Returns (Buffer | Array | String)

isValidSignature

index.js:582-606

Validate ECDSA signature

Parameters

Returns Boolean

isZeroAddress

index.js:466-469

Checks if a given address is a zero address

Parameters

Returns Boolean

KECCAK256_NULL

index.js:32-32

Keccak-256 hash of null (a Buffer)

Type: Buffer

KECCAK256_NULL_S

index.js:26-26

Keccak-256 hash of null (a String)

Type: String

KECCAK256_RLP

index.js:56-56

Keccak-256 hash of the RLP of null (a Buffer)

Type: Buffer

KECCAK256_RLP_ARRAY

index.js:44-44

Keccak-256 of an RLP of an empty array (a Buffer)

Type: Buffer

KECCAK256_RLP_ARRAY_S

index.js:38-38

Keccak-256 of an RLP of an empty array (a String)

Type: String

KECCAK256_RLP_S

index.js:50-50

Keccak-256 hash of the RLP of null (a String)

Type: String

setLengthLeft

index.js:106-122

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

Parameters

  • msg (Buffer | Array) the value to pad
  • length Number the number of bytes the output should be
  • right Boolean whether to start padding form the left or right (optional, default false)

Returns (Buffer | Array)

MAX_INTEGER

index.js:14-14

the max integer that this VM can handle (a BN)

Type: BN

privateToPublic

index.js:325-329

Returns the ethereum public key of a given private key

Parameters

  • privateKey Buffer A private key must be 256 bits wide

Returns Buffer

TWO_POW256

index.js:20-20

2^256 (a BN)

Type: BN

zeroAddress

index.js:91-95

Returns a zero address

Returns String

zeros

index.js:82-84

Returns a buffer filled with 0s

Parameters

  • bytes Number the number of bytes the buffer should be

Returns Buffer