Skip to content

Latest commit

 

History

History
597 lines (337 loc) · 24 KB

index.md

File metadata and controls

597 lines (337 loc) · 24 KB

Table of Contents

addHexPrefix

index.js:541-547

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

Parameters

Returns String

baToJSON

index.js:590-600

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:612-705

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:386-394

ECDSA public key recovery from signature

Parameters

Returns Buffer publicKey

ecsign

index.js:355-363

ECDSA sign

Parameters

Returns Object

fromRpcSig

index.js:424-443

Convert signature format of the vap_sign RPC method to signature parameters NOTE: all because of a bug in gvap: https://github.com/vaporyco/go-vapory/issues/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:510-524

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:373-376

Returns the keccak-256 hash of message, prefixed with the header used by the vap_sign RPC call. The output of this function can be fed into ecsign to produce the same signature as the vap_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:341-347

Converts a public key to the Vapory format.

Parameters

Returns Buffer

isPrecompiled

index.js:531-534

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

Parameters

Returns Boolean

isValidAddress

index.js:459-461

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

Parameters

Returns Boolean

isValidChecksumAddress

index.js:500-502

Checks if the address is a valid checksummed address

Parameters

Returns Boolean

isValidPrivate

index.js:284-286

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

Parameters

Returns Boolean

isValidPublic

index.js:295-306

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

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

privateToAddress

index.js:450-452

Returns the vapory address of a given private key

Parameters

  • privateKey Buffer A private key must be 256 bits wide

Returns Buffer

pubToAddress

index.js:315-323

Returns the vapory address of a given public key. Accepts "Vapory 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:260-268

Creates RIPEMD160 hash of the input

Parameters

Returns Buffer

rlp

index.js:74-74

rlp

Type: Function

rlphash

index.js:275-277

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:249-252

Creates SHA256 hash of the input

Parameters

Returns Buffer

sha3

index.js:242-242

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:479-493

Returns a checksummed address

Parameters

Returns String

toRpcSig

index.js:403-416

Convert signature parameters into the format of vap_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:559-583

Validate ECDSA signature

Parameters

Returns Boolean

isZeroAddress

index.js:469-472

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:330-334

Returns the vapory 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