Skip to content

Latest commit

 

History

History
610 lines (344 loc) · 24.9 KB

index.md

File metadata and controls

610 lines (344 loc) · 24.9 KB

Table of Contents

addHexPrefix

index.js:550-556

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

Parameters

Returns String

baToJSON

index.js:599-609

Converts a Buffer or Array to JSON

Parameters

Returns (Array | String | null)

BN

index.js:68-68

BN

Type: Function

bufferToHex

index.js:200-203

Converts a Buffer into a hex String

Parameters

Returns String

bufferToInt

index.js:191-193

Converts a Buffer to a Number

Parameters

  • buf Buffer

  • Throws any If the input number exceeds 53 bits.

Returns Number

defineProperties

index.js:621-714

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:395-403

ECDSA public key recovery from signature

Parameters

Returns Buffer publicKey

ecsign

index.js:364-372

ECDSA sign

Parameters

Returns Object

fromRpcSig

index.js:433-452

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:210-212

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

Parameters

Returns BN

generateAddress

index.js:519-533

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

hashPersonalMessage

index.js:382-385

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:350-356

Converts a public key to the Ethereum format.

Parameters

Returns Buffer

isPrecompiled

index.js:540-543

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

Parameters

Returns Boolean

isValidAddress

index.js:468-470

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

Parameters

Returns Boolean

isValidChecksumAddress

index.js:509-511

Checks if the address is a valid checksummed address

Parameters

Returns Boolean

isValidPrivate

index.js:293-295

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

Parameters

Returns Boolean

isValidPublic

index.js:304-315

Checks if the public key satisfies the rules of the curve secp256k1 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:229-234

Creates Keccak hash of the input

Parameters

Returns Buffer

keccak256

index.js:241-243

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

Parameters

Returns Buffer

privateToAddress

index.js:459-461

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:324-332

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:269-277

Creates RIPEMD160 hash of the input

Parameters

Returns Buffer

rlp

index.js:74-74

rlp

Type: Function

rlphash

index.js:284-286

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

Parameters

Returns Buffer

secp256k1

index.js:80-80

secp256k1

Type: Object

setLengthRight

index.js:137-139

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:258-261

Creates SHA256 hash of the input

Parameters

Returns Buffer

sha3

index.js:251-251

Creates SHA-3 (Keccak) hash of the input [OBSOLETE]

Parameters

Returns Buffer

toBuffer

index.js:159-183

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:488-502

Returns a checksummed address

Parameters

Returns String

toRpcSig

index.js:412-425

Convert signature parameters into the format of eth_sign RPC method

Parameters

Returns String sig

toUnsigned

index.js:219-221

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:146-154

Trims leading zeros from a Buffer or an Array

Parameters

Returns (Buffer | Array | String)

isValidSignature

index.js:568-592

Validate ECDSA signature

Parameters

Returns Boolean

isZeroAddress

index.js:478-481

Checks if a given address is a zero address

Parameters

Returns Boolean

KECCAK256_NULL

index.js:33-33

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:61-61

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

Type: Buffer

KECCAK256_RLP_ARRAY

index.js:47-47

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

Type: Buffer

KECCAK256_RLP_ARRAY_S

index.js:40-40

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

Type: String

KECCAK256_RLP_S

index.js:54-54

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

Type: String

lsetLength

index.js:112-128

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:339-343

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:97-101

Returns a zero address

Returns String

zeros

index.js:88-90

Returns a buffer filled with 0s

Parameters

  • bytes Number the number of bytes the buffer should be

Returns Buffer