A collection of utility functions for ethereum. It can be used in node.js or can be in the browser with browserify.
MAX_INTEGER- The max integer that the VM can handleTWO_POW256- 2^256SHA3_NULL- SHA3-256 hash ofnullSHA3_RLP_ARRAY- SHA3-256 of an RLP of an empty arraySHA3_RLP- SHA3-256 hash of the RLP ofnullETH_UNITS- an array of ethereum unitsBNrlp
Returns buffer filled with 0's
Parameters
number- the number of bytes to return
Return: Buffer
Pads an Array or Buffer with leading zeros till it has length bytes
Parameters
val- the value to padlength- the of the resulting value
Return: Array or Buffer
Pads an Array or Buffer with trailing zeros till it has length bytes
Parameters
val- the value to padlength- the of the resulting value
Return: Array or Buffer
Trims leading zeros from a Buffer or an Array
Parameters
val- aBufferor anArrayto unpad
Return: Buffer or Array
Attempts to turn a value into a Buffer. Attempts to turn a value into a Buffer. Supports Buffer, string, number, null/undefined, BN.js or other objects with a toArray() method.
Parameters
valthe object to be converted
Return: Buffer
Converts an Integer into a hex String
Parameters
int
Return: String
Converts an Integer to a Buffer
Parameters
int
Return: Buffer
Converts a Buffer to an Integer
Parameters
buf
Return: Interger
Interprets a Buffer as a signed Integer
Parameters
buf
Return: BN.js
Converts a BN.js to an unsigned integer
Parameters
num- aBN.js
Return: buffer
Returns the ethereum address of a given public key
Parameters
pubKey- the public key as aBuffer
Return: : Buffer
Returns the ethereum address of a given private key
Parameters
privateKey- the private key as aBuffer
Return: Buffer
Returns the ethereum public key of a given private key Parameters
privateKey- the private key as aBuffer
Return: Buffer
Generates an address of a newly created contract. Don't forget to increment the nonce to get the correct address. Parameters
from- the address of the account creating the contractnonce- the creating accounts nonce
Return: Buffer
Returns a sha3 of a of the length of bytes
Parameters
a- the value to hashbytes- how many bytes the hash should be
Return: Buffer
Returns a sha256 of a
Parameters
a- the value to hash
Return: Buffer
Returns a ripemd160 of a
Parameters
a- the value to hashpadded- pad the hash to 256 bits with zeroes
Return: Buffer
Print a Buffer Array
Parameters
ba- anArrayofBuffers
Return: a Buffer Array
Converts a buffer array to JSON Parameters
ba- anArrayofBuffers
Return: a JSON Object
Returns a Boolean on whether or not the String starts with 0x
Parameters
string- aString
Return: Boolean
Removes 0x from a given String
Parameters
string- aString
Return: String
Adds 0x to a given string if it does not already start with 0x
Parameters
string- aString
Return: string
Defines properties on a Object. It make the assumption that underlying data is binary.
Parameters
self- theObjectto define properties onfields- an array fields to define. Fields can contain:namethe name of the propertieslengththe number of bytes the field can haveallowLessif the field can be less than thelengthallowEmpty
Validate defined fields
Parameters
fieldsdata
Return: Boolean
Node.js Tests use Mocha. Test in the browser use Testling.
MPL-2.0