happyucjs-util
Version:
a collection of utility functions for HappyUC
598 lines (337 loc) • 24.7 kB
Markdown
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
### Table of Contents
- [addHexPrefix](#addhexprefix)
- [baToJSON](#batojson)
- [BN](#bn)
- [bufferToHex](#buffertohex)
- [bufferToInt](#buffertoint)
- [defineProperties](#defineproperties)
- [ecrecover](#ecrecover)
- [ecsign](#ecsign)
- [fromRpcSig](#fromrpcsig)
- [fromSigned](#fromsigned)
- [generateAddress](#generateaddress)
- [hashPersonalMessage](#hashpersonalmessage)
- [importPublic](#importpublic)
- [isPrecompiled](#isprecompiled)
- [isValidAddress](#isvalidaddress)
- [isValidChecksumAddress](#isvalidchecksumaddress)
- [isValidPrivate](#isvalidprivate)
- [isValidPublic](#isvalidpublic)
- [keccak](#keccak)
- [privateToAddress](#privatetoaddress)
- [pubToAddress](#pubtoaddress)
- [ripemd160](#ripemd160)
- [rlp](#rlp)
- [rlphash](#rlphash)
- [secp256k1](#secp256k1)
- [setLengthRight](#setlengthright)
- [sha256](#sha256)
- [sha3](#sha3)
- [toBuffer](#tobuffer)
- [toChecksumAddress](#tochecksumaddress)
- [toRpcSig](#torpcsig)
- [toUnsigned](#tounsigned)
- [unpad](#unpad)
- [isValidSignature](#isvalidsignature)
- [isZeroAddress](#iszeroaddress)
- [KECCAK256_NULL](#keccak256_null)
- [KECCAK256_NULL_S](#keccak256_null_s)
- [KECCAK256_RLP](#keccak256_rlp)
- [KECCAK256_RLP_ARRAY](#keccak256_rlp_array)
- [KECCAK256_RLP_ARRAY_S](#keccak256_rlp_array_s)
- [KECCAK256_RLP_S](#keccak256_rlp_s)
- [lsetLength](#lsetlength)
- [MAX_INTEGER](#max_integer)
- [privateToPublic](#privatetopublic)
- [TWO_POW256](#two_pow256)
- [zeroAddress](#zeroaddress)
- [zeros](#zeros)
## addHexPrefix
[index.js:541-547](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L541-L547 "Source code on GitHub")
Adds "0x" to a given `String` if it does not already start with "0x"
**Parameters**
- `str` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
## baToJSON
[index.js:590-600](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L590-L600 "Source code on GitHub")
Converts a `Buffer` or `Array` to JSON
**Parameters**
- `ba` **([Buffer](https://nodejs.org/api/buffer.html) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array))**
Returns **([Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | null)**
## BN
[index.js:68-68](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L68-L68 "Source code on GitHub")
[`BN`](https://github.com/indutny/bn.js)
Type: [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)
## bufferToHex
[index.js:200-203](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L200-L203 "Source code on GitHub")
Converts a `Buffer` into a hex `String`
**Parameters**
- `buf` **[Buffer](https://nodejs.org/api/buffer.html)**
Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
## bufferToInt
[index.js:191-193](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L191-L193 "Source code on GitHub")
Converts a `Buffer` to a `Number`
**Parameters**
- `buf` **[Buffer](https://nodejs.org/api/buffer.html)**
- Throws **any** If the input number exceeds 53 bits.
Returns **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
## defineProperties
[index.js:612-705](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L612-L705 "Source code on GitHub")
Defines properties on a `Object`. It make the assumption that underlying data is binary.
**Parameters**
- `self` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the `Object` to define properties on
- `fields` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/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](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L386-L394 "Source code on GitHub")
ECDSA public key recovery from signature
**Parameters**
- `msgHash` **[Buffer](https://nodejs.org/api/buffer.html)**
- `v` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
- `r` **[Buffer](https://nodejs.org/api/buffer.html)**
- `s` **[Buffer](https://nodejs.org/api/buffer.html)**
Returns **[Buffer](https://nodejs.org/api/buffer.html)** publicKey
## ecsign
[index.js:355-363](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L355-L363 "Source code on GitHub")
ECDSA sign
**Parameters**
- `msgHash` **[Buffer](https://nodejs.org/api/buffer.html)**
- `privateKey` **[Buffer](https://nodejs.org/api/buffer.html)**
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
## fromRpcSig
[index.js:424-443](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L424-L443 "Source code on GitHub")
Convert signature format of the `huc_sign` RPC method to signature parameters
NOTE: all because of a bug in ghuc: <https://github.com/happyuc-project/happyuc-go/issues/2053>
**Parameters**
- `sig` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
## fromSigned
[index.js:210-212](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L210-L212 "Source code on GitHub")
Interprets a `Buffer` as a signed integer and returns a `BN`. Assumes 256-bit numbers.
**Parameters**
- `num` **[Buffer](https://nodejs.org/api/buffer.html)**
Returns **BN**
## generateAddress
[index.js:510-524](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L510-L524 "Source code on GitHub")
Generates an address of a newly created contract
**Parameters**
- `from` **[Buffer](https://nodejs.org/api/buffer.html)** the address which is creating this new address
- `nonce` **[Buffer](https://nodejs.org/api/buffer.html)** the nonce of the from account
Returns **[Buffer](https://nodejs.org/api/buffer.html)**
## hashPersonalMessage
[index.js:373-376](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L373-L376 "Source code on GitHub")
Returns the keccak-256 hash of `message`, prefixed with the header used by the `huc_sign` RPC call.
The output of this function can be fed into `ecsign` to produce the same signature as the `huc_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](https://nodejs.org/api/buffer.html)** hash
## importPublic
[index.js:341-347](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L341-L347 "Source code on GitHub")
Converts a public key to the HappyUC format.
**Parameters**
- `publicKey` **[Buffer](https://nodejs.org/api/buffer.html)**
Returns **[Buffer](https://nodejs.org/api/buffer.html)**
## isPrecompiled
[index.js:531-534](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L531-L534 "Source code on GitHub")
Returns true if the supplied address belongs to a precompiled account (Byzantium)
**Parameters**
- `address` **([Buffer](https://nodejs.org/api/buffer.html) \| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))**
Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
## isValidAddress
[index.js:459-461](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L459-L461 "Source code on GitHub")
Checks if the address is a valid. Accepts checksummed addresses too
**Parameters**
- `address` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
## isValidChecksumAddress
[index.js:500-502](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L500-L502 "Source code on GitHub")
Checks if the address is a valid checksummed address
**Parameters**
- `address` **[Buffer](https://nodejs.org/api/buffer.html)**
Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
## isValidPrivate
[index.js:284-286](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L284-L286 "Source code on GitHub")
Checks if the private key satisfies the rules of the curve secp256k1.
**Parameters**
- `privateKey` **[Buffer](https://nodejs.org/api/buffer.html)**
Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
## isValidPublic
[index.js:295-306](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L295-L306 "Source code on GitHub")
Checks if the public key satisfies the rules of the curve secp256k1
and the requirements of HappyUC.
**Parameters**
- `publicKey` **[Buffer](https://nodejs.org/api/buffer.html)** The two points of an uncompressed key, unless sanitize is enabled
- `sanitize` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Accept public keys in other formats (optional, default `false`)
Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
## keccak
[index.js:229-234](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L229-L234 "Source code on GitHub")
Creates Keccak hash of the input
**Parameters**
- `a` **([Buffer](https://nodejs.org/api/buffer.html) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** the input data
- `bits` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the Keccak width (optional, default `256`)
Returns **[Buffer](https://nodejs.org/api/buffer.html)**
## privateToAddress
[index.js:450-452](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L450-L452 "Source code on GitHub")
Returns the happyuc address of a given private key
**Parameters**
- `privateKey` **[Buffer](https://nodejs.org/api/buffer.html)** A private key must be 256 bits wide
Returns **[Buffer](https://nodejs.org/api/buffer.html)**
## pubToAddress
[index.js:315-323](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L315-L323 "Source code on GitHub")
Returns the happyuc address of a given public key.
Accepts "HappyUC public keys" and SEC1 encoded keys.
**Parameters**
- `pubKey` **[Buffer](https://nodejs.org/api/buffer.html)** The two points of an uncompressed key, unless sanitize is enabled
- `sanitize` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Accept public keys in other formats (optional, default `false`)
Returns **[Buffer](https://nodejs.org/api/buffer.html)**
## ripemd160
[index.js:260-268](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L260-L268 "Source code on GitHub")
Creates RIPEMD160 hash of the input
**Parameters**
- `a` **([Buffer](https://nodejs.org/api/buffer.html) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** the input data
- `padded` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** whether it should be padded to 256 bits or not
Returns **[Buffer](https://nodejs.org/api/buffer.html)**
## rlp
[index.js:74-74](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L74-L74 "Source code on GitHub")
[`rlp`](https://github.com/happyucjs/rlp)
Type: [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)
## rlphash
[index.js:275-277](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L275-L277 "Source code on GitHub")
Creates SHA-3 hash of the RLP encoded version of the input
**Parameters**
- `a` **([Buffer](https://nodejs.org/api/buffer.html) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** the input data
Returns **[Buffer](https://nodejs.org/api/buffer.html)**
## secp256k1
[index.js:80-80](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L80-L80 "Source code on GitHub")
[`secp256k1`](https://github.com/cryptocoinjs/secp256k1-node/)
Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
## setLengthRight
[index.js:137-139](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L137-L139 "Source code on GitHub")
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](https://nodejs.org/api/buffer.html) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array))** the value to pad
- `length` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the number of bytes the output should be
Returns **([Buffer](https://nodejs.org/api/buffer.html) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array))**
## sha256
[index.js:249-252](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L249-L252 "Source code on GitHub")
Creates SHA256 hash of the input
**Parameters**
- `a` **([Buffer](https://nodejs.org/api/buffer.html) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** the input data
Returns **[Buffer](https://nodejs.org/api/buffer.html)**
## sha3
[index.js:242-242](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L242-L242 "Source code on GitHub")
Creates SHA-3 (Keccak) hash of the input [OBSOLETE]
**Parameters**
- `a` **([Buffer](https://nodejs.org/api/buffer.html) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** the input data
- `bits` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the SHA-3 width (optional, default `256`)
Returns **[Buffer](https://nodejs.org/api/buffer.html)**
## toBuffer
[index.js:159-183](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L159-L183 "Source code on GitHub")
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](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L479-L493 "Source code on GitHub")
Returns a checksummed address
**Parameters**
- `address` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
## toRpcSig
[index.js:403-416](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L403-L416 "Source code on GitHub")
Convert signature parameters into the format of `huc_sign` RPC method
**Parameters**
- `v` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
- `r` **[Buffer](https://nodejs.org/api/buffer.html)**
- `s` **[Buffer](https://nodejs.org/api/buffer.html)**
Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** sig
## toUnsigned
[index.js:219-221](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L219-L221 "Source code on GitHub")
Converts a `BN` to an unsigned integer and returns it as a `Buffer`. Assumes 256-bit numbers.
**Parameters**
- `num` **BN**
Returns **[Buffer](https://nodejs.org/api/buffer.html)**
## unpad
[index.js:146-154](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L146-L154 "Source code on GitHub")
Trims leading zeros from a `Buffer` or an `Array`
**Parameters**
- `a` **([Buffer](https://nodejs.org/api/buffer.html) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))**
Returns **([Buffer](https://nodejs.org/api/buffer.html) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))**
## isValidSignature
[index.js:559-583](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L559-L583 "Source code on GitHub")
Validate ECDSA signature
**Parameters**
- `v` **[Buffer](https://nodejs.org/api/buffer.html)**
- `r` **[Buffer](https://nodejs.org/api/buffer.html)**
- `s` **[Buffer](https://nodejs.org/api/buffer.html)**
- `homestead` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** (optional, default `true`)
Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
## isZeroAddress
[index.js:469-472](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L469-L472 "Source code on GitHub")
Checks if a given address is a zero address
**Parameters**
- `address` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
## KECCAK256_NULL
[index.js:33-33](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L33-L33 "Source code on GitHub")
Keccak-256 hash of null (a `Buffer`)
Type: [Buffer](https://nodejs.org/api/buffer.html)
## KECCAK256_NULL_S
[index.js:26-26](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L26-L26 "Source code on GitHub")
Keccak-256 hash of null (a `String`)
Type: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)
## KECCAK256_RLP
[index.js:61-61](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L61-L61 "Source code on GitHub")
Keccak-256 hash of the RLP of null (a `Buffer`)
Type: [Buffer](https://nodejs.org/api/buffer.html)
## KECCAK256_RLP_ARRAY
[index.js:47-47](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L47-L47 "Source code on GitHub")
Keccak-256 of an RLP of an empty array (a `Buffer`)
Type: [Buffer](https://nodejs.org/api/buffer.html)
## KECCAK256_RLP_ARRAY_S
[index.js:40-40](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L40-L40 "Source code on GitHub")
Keccak-256 of an RLP of an empty array (a `String`)
Type: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)
## KECCAK256_RLP_S
[index.js:54-54](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L54-L54 "Source code on GitHub")
Keccak-256 hash of the RLP of null (a `String`)
Type: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)
## lsetLength
[index.js:112-128](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L112-L128 "Source code on GitHub")
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](https://nodejs.org/api/buffer.html) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array))** the value to pad
- `length` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the number of bytes the output should be
- `right` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** whether to start padding form the left or right (optional, default `false`)
Returns **([Buffer](https://nodejs.org/api/buffer.html) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array))**
## MAX_INTEGER
[index.js:14-14](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L14-L14 "Source code on GitHub")
the max integer that this VM can handle (a `BN`)
Type: BN
## privateToPublic
[index.js:330-334](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L330-L334 "Source code on GitHub")
Returns the happyuc public key of a given private key
**Parameters**
- `privateKey` **[Buffer](https://nodejs.org/api/buffer.html)** A private key must be 256 bits wide
Returns **[Buffer](https://nodejs.org/api/buffer.html)**
## TWO_POW256
[index.js:20-20](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L20-L20 "Source code on GitHub")
2^256 (a `BN`)
Type: BN
## zeroAddress
[index.js:97-101](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L97-L101 "Source code on GitHub")
Returns a zero address
Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
## zeros
[index.js:88-90](https://github.com/happyucjs/happyucjs-util/blob/fde15dd0cc65885dc8731d1bd2facbba78fb39ac/index.js#L88-L90 "Source code on GitHub")
Returns a buffer filled with 0s
**Parameters**
- `bytes` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the number of bytes the buffer should be
Returns **[Buffer](https://nodejs.org/api/buffer.html)**