diff --git a/docs/index.md b/docs/index.md index 5598bfdc..09655f4d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,141 +1,197 @@ -# addHexPrefix - -[index.js:502-508](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L502-L508 "Source code on GitHub") + + +### 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) +- [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) +- [lsetLength](#lsetlength) +- [MAX_INTEGER](#max_integer) +- [privateToPublic](#privatetopublic) +- [SHA3_NULL](#sha3_null) +- [SHA3_NULL_S](#sha3_null_s) +- [SHA3_RLP](#sha3_rlp) +- [SHA3_RLP_ARRAY](#sha3_rlp_array) +- [SHA3_RLP_ARRAY_S](#sha3_rlp_array_s) +- [SHA3_RLP_S](#sha3_rlp_s) +- [TWO_POW256](#two_pow256) +- [zeroAddress](#zeroaddress) +- [zeros](#zeros) + +## addHexPrefix + +[index.js:525-531](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L525-L531 "Source code on GitHub") Adds "0x" to a given `String` if it does not already start with "0x" **Parameters** -- `str` **String** +- `str` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** -Returns **String** +Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** -# baToJSON +## baToJSON -[index.js:551-561](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L551-L561 "Source code on GitHub") +[index.js:574-584](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L574-L584 "Source code on GitHub") Converts a `Buffer` or `Array` to JSON **Parameters** -- `ba` **Buffer or Array** +- `ba` **([Buffer](https://nodejs.org/api/buffer.html) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array))** -Returns **Array or String or ** +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 +## BN -[index.js:61-61](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L61-L61 "Source code on GitHub") +[index.js:62-62](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L62-L62 "Source code on GitHub") [`BN`](https://github.com/indutny/bn.js) -# bufferToHex +Type: [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function) + +## bufferToHex -[index.js:180-183](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L180-L183 "Source code on GitHub") +[index.js:192-195](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L192-L195 "Source code on GitHub") Converts a `Buffer` into a hex `String` **Parameters** -- `buf` **Buffer** +- `buf` **[Buffer](https://nodejs.org/api/buffer.html)** -Returns **String** +Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** -# bufferToInt +## bufferToInt -[index.js:171-173](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L171-L173 "Source code on GitHub") +[index.js:183-185](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L183-L185 "Source code on GitHub") Converts a `Buffer` to a `Number` **Parameters** -- `buf` **Buffer** +- `buf` **[Buffer](https://nodejs.org/api/buffer.html)** + -Returns **Number** +- Throws **any** If the input number exceeds 53 bits. -# defineProperties +Returns **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** -[index.js:573-666](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L573-L666 "Source code on GitHub") +## defineProperties + +[index.js:596-689](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L596-L689 "Source code on GitHub") 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 +- `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 +- `data` **any** data to be validated against the definitions -# ecrecover +## ecrecover -[index.js:358-366](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L358-L366 "Source code on GitHub") +[index.js:370-378](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L370-L378 "Source code on GitHub") ECDSA public key recovery from signature **Parameters** -- `msgHash` **Buffer** -- `v` **Number** -- `r` **Buffer** -- `s` **Buffer** +- `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** publicKey +Returns **[Buffer](https://nodejs.org/api/buffer.html)** publicKey -# ecsign +## ecsign -[index.js:327-335](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L327-L335 "Source code on GitHub") +[index.js:339-347](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L339-L347 "Source code on GitHub") ECDSA sign **Parameters** -- `msgHash` **Buffer** -- `privateKey` **Buffer** +- `msgHash` **[Buffer](https://nodejs.org/api/buffer.html)** +- `privateKey` **[Buffer](https://nodejs.org/api/buffer.html)** -Returns **Object** +Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -# fromRpcSig +## fromRpcSig -[index.js:396-415](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L396-L415 "Source code on GitHub") +[index.js:408-427](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L408-L427 "Source code on GitHub") Convert signature format of the `eth_sign` RPC method to signature parameters NOTE: all because of a bug in geth: **Parameters** -- `sig` **String** +- `sig` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** -Returns **Object** +Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** -# fromSigned +## fromSigned -[index.js:190-192](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L190-L192 "Source code on GitHub") +[index.js:202-204](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L202-L204 "Source code on GitHub") Interprets a `Buffer` as a signed integer and returns a `BN`. Assumes 256-bit numbers. **Parameters** -- `num` **Buffer** +- `num` **[Buffer](https://nodejs.org/api/buffer.html)** Returns **BN** -# generateAddress +## generateAddress -[index.js:471-485](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L471-L485 "Source code on GitHub") +[index.js:494-508](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L494-L508 "Source code on GitHub") 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 +- `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** +Returns **[Buffer](https://nodejs.org/api/buffer.html)** -# hashPersonalMessage +## hashPersonalMessage -[index.js:345-348](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L345-L348 "Source code on GitHub") +[index.js:357-360](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L357-L360 "Source code on GitHub") 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` @@ -146,342 +202,382 @@ used to produce the signature. - `message` -Returns **Buffer** hash +Returns **[Buffer](https://nodejs.org/api/buffer.html)** hash -# importPublic +## importPublic -[index.js:313-319](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L313-L319 "Source code on GitHub") +[index.js:325-331](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L325-L331 "Source code on GitHub") Converts a public key to the Ethereum format. **Parameters** -- `publicKey` **Buffer** +- `publicKey` **[Buffer](https://nodejs.org/api/buffer.html)** -Returns **Buffer** +Returns **[Buffer](https://nodejs.org/api/buffer.html)** -# isPrecompiled +## isPrecompiled -[index.js:492-495](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L492-L495 "Source code on GitHub") +[index.js:515-518](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L515-L518 "Source code on GitHub") Returns true if the supplied address belongs to a precompiled account **Parameters** -- `address` **Buffer or String** +- `address` **([Buffer](https://nodejs.org/api/buffer.html) \| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))** -Returns **Boolean** +Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** -# isValidAddress +## isValidAddress -[index.js:431-433](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L431-L433 "Source code on GitHub") +[index.js:443-445](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L443-L445 "Source code on GitHub") Checks if the address is a valid. Accepts checksummed addresses too **Parameters** -- `address` **String** +- `address` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** -Returns **Boolean** +Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** -# isValidChecksumAddress +## isValidChecksumAddress -[index.js:461-463](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L461-L463 "Source code on GitHub") +[index.js:484-486](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L484-L486 "Source code on GitHub") Checks if the address is a valid checksummed address **Parameters** -- `address` **Buffer** +- `address` **[Buffer](https://nodejs.org/api/buffer.html)** -Returns **Boolean** +Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** -# isValidPrivate +## isValidPrivate -[index.js:256-258](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L256-L258 "Source code on GitHub") +[index.js:268-270](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L268-L270 "Source code on GitHub") Checks if the private key satisfies the rules of the curve secp256k1. **Parameters** -- `privateKey` **Buffer** +- `privateKey` **[Buffer](https://nodejs.org/api/buffer.html)** -Returns **Boolean** +Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** -# isValidPublic +## isValidPublic -[index.js:267-278](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L267-L278 "Source code on GitHub") +[index.js:279-290](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L279-L290 "Source code on GitHub") 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** - -# isValidSignature - -[index.js:520-544](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L520-L544 "Source code on GitHub") - -Validate ECDSA signature - -**Parameters** - -- `v` **Buffer** -- `r` **Buffer** -- `s` **Buffer** -- `homestead` **[Boolean]** (optional, default `true`) +- `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** +Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** -# MAX_INTEGER +## privateToAddress -[index.js:13-13](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L13-L13 "Source code on GitHub") - -the max integer that this VM can handle (a `BN`) - -# privateToAddress - -[index.js:422-424](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L422-L424 "Source code on GitHub") +[index.js:434-436](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L434-L436 "Source code on GitHub") Returns the ethereum address of a given private key **Parameters** -- `privateKey` **Buffer** A private key must be 256 bits wide +- `privateKey` **[Buffer](https://nodejs.org/api/buffer.html)** A private key must be 256 bits wide -Returns **Buffer** +Returns **[Buffer](https://nodejs.org/api/buffer.html)** -# pubToAddress +## pubToAddress -[index.js:287-295](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L287-L295 "Source code on GitHub") +[index.js:299-307](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L299-L307 "Source code on GitHub") 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`) +- `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** +Returns **[Buffer](https://nodejs.org/api/buffer.html)** -# ripemd160 +## ripemd160 -[index.js:232-240](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L232-L240 "Source code on GitHub") +[index.js:244-252](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L244-L252 "Source code on GitHub") Creates RIPEMD160 hash of the input **Parameters** -- `a` **Buffer or Array or String or Number** the input data -- `padded` **Boolean** whether it should be padded to 256 bits or not +- `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** +Returns **[Buffer](https://nodejs.org/api/buffer.html)** -# rlp +## rlp -[index.js:67-67](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L67-L67 "Source code on GitHub") +[index.js:68-68](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L68-L68 "Source code on GitHub") [`rlp`](https://github.com/ethereumjs/rlp) -# rlphash +Type: [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function) + +## rlphash -[index.js:247-249](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L247-L249 "Source code on GitHub") +[index.js:259-261](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L259-L261 "Source code on GitHub") Creates SHA-3 hash of the RLP encoded version of the input **Parameters** -- `a` **Buffer or Array or String or Number** the input data +- `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** +Returns **[Buffer](https://nodejs.org/api/buffer.html)** -# secp256k1 +## secp256k1 -[index.js:73-73](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L73-L73 "Source code on GitHub") +[index.js:74-74](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L74-L74 "Source code on GitHub") [`secp256k1`](https://github.com/cryptocoinjs/secp256k1-node/) -# setLengthLeft +Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) -[index.js:94-110](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L94-L110 "Source code on GitHub") +## setLengthRight -Left Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes. +[index.js:131-133](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L131-L133 "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 or 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`) +- `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 or Array** +Returns **([Buffer](https://nodejs.org/api/buffer.html) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array))** -# setLengthRight +## sha256 -[index.js:119-121](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L119-L121 "Source code on GitHub") +[index.js:233-236](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L233-L236 "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. +Creates SHA256 hash of the input **Parameters** -- `msg` **Buffer or Array** the value to pad -- `length` **Number** the number of bytes the output should be +- `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 or Array** +Returns **[Buffer](https://nodejs.org/api/buffer.html)** -# sha256 +## sha3 -[index.js:221-224](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L221-L224 "Source code on GitHub") +[index.js:221-226](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L221-L226 "Source code on GitHub") -Creates SHA256 hash of the input +Creates SHA-3 hash of the input **Parameters** -- `a` **Buffer or Array or String or Number** the input data +- `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 width (optional, default `256`) -Returns **Buffer** +Returns **[Buffer](https://nodejs.org/api/buffer.html)** -# sha3 +## toBuffer -[index.js:209-214](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L209-L214 "Source code on GitHub") +[index.js:153-175](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L153-L175 "Source code on GitHub") -Creates SHA-3 hash of the input +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** -- `a` **Buffer or Array or String or Number** the input data -- `bits` **[Number]** the SHA width (optional, default `256`) +- `v` **any** the value -Returns **Buffer** +## toChecksumAddress -# SHA3_NULL +[index.js:463-477](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L463-L477 "Source code on GitHub") -[index.js:31-31](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L31-L31 "Source code on GitHub") - -SHA3-256 hash of null (a `Buffer`) +Returns a checksummed address -# SHA3_NULL_S +**Parameters** -[index.js:25-25](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L25-L25 "Source code on GitHub") +- `address` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** -SHA3-256 hash of null (a `String`) +Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** -# SHA3_RLP +## toRpcSig -[index.js:55-55](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L55-L55 "Source code on GitHub") +[index.js:387-400](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L387-L400 "Source code on GitHub") -SHA3-256 hash of the RLP of null (a `Buffer`) +Convert signature parameters into the format of `eth_sign` RPC method -# SHA3_RLP_ARRAY +**Parameters** -[index.js:43-43](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L43-L43 "Source code on GitHub") +- `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)** -SHA3-256 of an RLP of an empty array (a `Buffer`) +Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** sig -# SHA3_RLP_ARRAY_S +## toUnsigned -[index.js:37-37](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L37-L37 "Source code on GitHub") +[index.js:211-213](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L211-L213 "Source code on GitHub") -SHA3-256 of an RLP of an empty array (a `String`) +Converts a `BN` to an unsigned integer and returns it as a `Buffer`. Assumes 256-bit numbers. -# SHA3_RLP_S +**Parameters** -[index.js:49-49](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L49-L49 "Source code on GitHub") +- `num` **BN** -SHA3-256 hash of the RLP of null (a `String`) +Returns **[Buffer](https://nodejs.org/api/buffer.html)** -# toBuffer +## unpad -[index.js:141-163](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L141-L163 "Source code on GitHub") +[index.js:140-148](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L140-L148 "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. +Trims leading zeros from a `Buffer` or an `Array` **Parameters** -- `v` **Any** the value +- `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))** -# toChecksumAddress +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))** -[index.js:440-454](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L440-L454 "Source code on GitHub") +## isValidSignature -Returns a checksummed address +[index.js:543-567](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L543-L567 "Source code on GitHub") + +Validate ECDSA signature **Parameters** -- `address` **String** +- `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 **String** +Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** -# toRpcSig +## isZeroAddress -[index.js:375-388](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L375-L388 "Source code on GitHub") +[index.js:453-456](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L453-L456 "Source code on GitHub") -Convert signature parameters into the format of `eth_sign` RPC method +Checks if a given address is a zero address **Parameters** -- `v` **Number** -- `r` **Buffer** -- `s` **Buffer** +- `address` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** -Returns **String** sig +Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** -# toUnsigned +## lsetLength -[index.js:199-201](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L199-L201 "Source code on GitHub") +[index.js:106-122](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L106-L122 "Source code on GitHub") -Converts a `BN` to an unsigned integer and returns it as a `Buffer`. Assumes 256-bit numbers. +Left Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes. +Or it truncates the beginning if it exceeds. **Parameters** -- `num` **BN** +- `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** +Returns **([Buffer](https://nodejs.org/api/buffer.html) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array))** -# TWO_POW256 +## MAX_INTEGER -[index.js:19-19](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L19-L19 "Source code on GitHub") +[index.js:14-14](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L14-L14 "Source code on GitHub") -2^256 (a `BN`) +the max integer that this VM can handle (a `BN`) -# unpad +Type: BN -[index.js:128-136](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L128-L136 "Source code on GitHub") +## privateToPublic -Trims leading zeros from a `Buffer` or an `Array` +[index.js:314-318](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L314-L318 "Source code on GitHub") + +Returns the ethereum public key of a given private key **Parameters** -- `a` **Buffer or Array or String** +- `privateKey` **[Buffer](https://nodejs.org/api/buffer.html)** A private key must be 256 bits wide -Returns **Buffer or Array or String** +Returns **[Buffer](https://nodejs.org/api/buffer.html)** -# zeros +## SHA3_NULL -[index.js:81-83](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L81-L83 "Source code on GitHub") +[index.js:32-32](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L32-L32 "Source code on GitHub") -Returns a buffer filled with 0s +SHA3-256 hash of null (a `Buffer`) -**Parameters** +Type: [Buffer](https://nodejs.org/api/buffer.html) -- `bytes` **Number** the number of bytes the buffer should be +## SHA3_NULL_S -Returns **Buffer** +[index.js:26-26](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L26-L26 "Source code on GitHub") -# privateToPublic +SHA3-256 hash of null (a `String`) -[index.js:302-306](https://github.com/ethereumjs/ethereumjs-util/blob/d03528e7da885539cad141c99ea5b88829f73e72/index.js#L302-L306 "Source code on GitHub") +Type: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) -Returns the ethereum public key of a given private key +## SHA3_RLP + +[index.js:56-56](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L56-L56 "Source code on GitHub") + +SHA3-256 hash of the RLP of null (a `Buffer`) + +Type: [Buffer](https://nodejs.org/api/buffer.html) + +## SHA3_RLP_ARRAY + +[index.js:44-44](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L44-L44 "Source code on GitHub") + +SHA3-256 of an RLP of an empty array (a `Buffer`) + +Type: [Buffer](https://nodejs.org/api/buffer.html) + +## SHA3_RLP_ARRAY_S + +[index.js:38-38](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L38-L38 "Source code on GitHub") + +SHA3-256 of an RLP of an empty array (a `String`) + +Type: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) + +## SHA3_RLP_S + +[index.js:50-50](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L50-L50 "Source code on GitHub") + +SHA3-256 hash of the RLP of null (a `String`) + +Type: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) + +## TWO_POW256 + +[index.js:20-20](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L20-L20 "Source code on GitHub") + +2^256 (a `BN`) + +Type: BN + +## zeroAddress + +[index.js:91-95](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L91-L95 "Source code on GitHub") + +Returns a zero address + +Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** + +## zeros + +[index.js:82-84](https://github.com/ethereumjs/ethereumjs-util/blob/0bc0616c2de0de0723f87c3b64923bb9f962a8e1/index.js#L82-L84 "Source code on GitHub") + +Returns a buffer filled with 0s **Parameters** -- `privateKey` **Buffer** A private key must be 256 bits wide +- `bytes` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the number of bytes the buffer should be -Returns **Buffer** +Returns **[Buffer](https://nodejs.org/api/buffer.html)** diff --git a/package.json b/package.json index d89e406b..5b4e8c45 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "test": "npm run test:node && npm run test:browser", "test:browser": "karma start karma.conf.js", "test:node": "istanbul test mocha -- --reporter spec", - "build:docs": "documentation --github -f md ./index.js > ./docs/index.md && contributor" + "build:docs": "documentation build ./index.js --github --sort-order='alpha' -f md > ./docs/index.md" }, "browserify": { "transform": [ @@ -125,7 +125,7 @@ "browserify": "^14.0.0", "contributor": "^0.1.25", "coveralls": "^2.11.4", - "documentation": "^4.0.0", + "documentation": "^5.2.0", "istanbul": "^0.4.1", "karma": "^1.3.0", "karma-browserify": "^5.0.0",