ethereumjs-util
Advanced tools
Comparing version 2.5.0 to 2.6.0
# BN | ||
[index.js:60-60](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L60-L60 "Source code on GitHub") | ||
[index.js:60-60](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L60-L60 "Source code on GitHub") | ||
@@ -9,9 +9,9 @@ [`BN`](https://github.com/indutny/bn.js) | ||
[index.js:12-12](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L12-L12 "Source code on GitHub") | ||
[index.js:12-12](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L12-L12 "Source code on GitHub") | ||
the max interger that this VM can handle (a `BN`) | ||
the max integer that this VM can handle (a `BN`) | ||
# SHA3_NULL | ||
[index.js:30-30](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L30-L30 "Source code on GitHub") | ||
[index.js:30-30](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L30-L30 "Source code on GitHub") | ||
@@ -22,3 +22,3 @@ SHA3-256 hash of null (a `Buffer`) | ||
[index.js:24-24](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L24-L24 "Source code on GitHub") | ||
[index.js:24-24](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L24-L24 "Source code on GitHub") | ||
@@ -29,3 +29,3 @@ SHA3-256 hash of null (a `String`) | ||
[index.js:54-54](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L54-L54 "Source code on GitHub") | ||
[index.js:54-54](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L54-L54 "Source code on GitHub") | ||
@@ -36,3 +36,3 @@ SHA3-256 hash of the RLP of null (a `Buffer`) | ||
[index.js:42-42](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L42-L42 "Source code on GitHub") | ||
[index.js:42-42](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L42-L42 "Source code on GitHub") | ||
@@ -43,3 +43,3 @@ SHA3-256 of an RLP of an empty array (a `Buffer`) | ||
[index.js:36-36](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L36-L36 "Source code on GitHub") | ||
[index.js:36-36](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L36-L36 "Source code on GitHub") | ||
@@ -50,3 +50,3 @@ SHA3-256 of an RLP of an empty array (a `String`) | ||
[index.js:48-48](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L48-L48 "Source code on GitHub") | ||
[index.js:48-48](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L48-L48 "Source code on GitHub") | ||
@@ -57,3 +57,3 @@ SHA3-256 hash of the RLP of null (a `String`) | ||
[index.js:18-18](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L18-L18 "Source code on GitHub") | ||
[index.js:18-18](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L18-L18 "Source code on GitHub") | ||
@@ -64,10 +64,9 @@ 2^256 (a `BN`) | ||
[index.js:386-392](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L386-L392 "Source code on GitHub") | ||
[index.js:397-403](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L397-L403 "Source code on GitHub") | ||
Adds "0x" to a given string if it does not already start with "0x" | ||
Adds "0x" to a given `String` if it does not already start with "0x" | ||
**Parameters** | ||
- `String` | ||
- `str` | ||
- `str` **String** | ||
@@ -78,20 +77,21 @@ Returns **String** | ||
[index.js:514-524](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L514-L524 "Source code on GitHub") | ||
[index.js:502-512](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L502-L512 "Source code on GitHub") | ||
converts a buffer array to JSON | ||
Converts a `Buffer` or `Array` to JSON | ||
**Parameters** | ||
- `ba` | ||
- `ba` **Buffer or Array** | ||
Returns **Array** | ||
# bufferToInt | ||
[index.js:198-205](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L198-L205 "Source code on GitHub") | ||
[index.js:200-207](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L200-L207 "Source code on GitHub") | ||
Converts a `Buffer` to an `Interger` | ||
Converts a `Buffer` to a `Number` | ||
**Parameters** | ||
- `Buffer` | ||
- `buf` | ||
- `buf` **Buffer** | ||
@@ -102,5 +102,5 @@ Returns **Number** | ||
[index.js:405-483](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L405-L483 "Source code on GitHub") | ||
[index.js:416-494](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L416-L494 "Source code on GitHub") | ||
Defines properties on a Object. It make the assumption that underlying data is binary | ||
Defines properties on a `Object`. It make the assumption that underlying data is binary. | ||
@@ -114,10 +114,9 @@ **Parameters** | ||
- `allowEmpty` | ||
- `Data` **Any** data to be validated against the definitions | ||
- `data` | ||
- `data` **Any** data to be validated against the definitions | ||
# fromSigned | ||
[index.js:213-220](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L213-L220 "Source code on GitHub") | ||
[index.js:215-222](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L215-L222 "Source code on GitHub") | ||
interpets a `Buffer` as a signed integer and returns a `bignum` | ||
Interprets a `Buffer` as a signed integer and returns a `BN` | ||
@@ -132,3 +131,3 @@ **Parameters** | ||
[index.js:334-344](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L334-L344 "Source code on GitHub") | ||
[index.js:342-355](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L342-L355 "Source code on GitHub") | ||
@@ -146,10 +145,9 @@ Generates an address of a newly created contract | ||
[index.js:187-190](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L187-L190 "Source code on GitHub") | ||
[index.js:189-192](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L189-L192 "Source code on GitHub") | ||
Converts an `Integer` to a `Buffer` | ||
Converts an `Number` to a `Buffer` | ||
**Parameters** | ||
- `Integer` | ||
- `i` | ||
- `i` **Number** | ||
@@ -160,10 +158,9 @@ Returns **Buffer** | ||
[index.js:170-179](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L170-L179 "Source code on GitHub") | ||
[index.js:172-181](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L172-L181 "Source code on GitHub") | ||
Converts an integer into a hex string | ||
Converts a `Number` into a hex `String` | ||
**Parameters** | ||
- `Number` | ||
- `i` | ||
- `i` **Number** | ||
@@ -174,5 +171,5 @@ Returns **String** | ||
[index.js:363-365](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L363-L365 "Source code on GitHub") | ||
[index.js:374-376](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L374-L376 "Source code on GitHub") | ||
Returns a `Boolean` on whether or not the a `Sting` starts with "0x" | ||
Returns a `Boolean` on whether or not the a `String` starts with "0x" | ||
@@ -187,3 +184,3 @@ **Parameters** | ||
[index.js:352-355](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L352-L355 "Source code on GitHub") | ||
[index.js:363-366](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L363-L366 "Source code on GitHub") | ||
@@ -194,3 +191,3 @@ Returns true if the supplied address belongs to a precompiled account | ||
- `address` | ||
- `address` **Buffer or String** | ||
@@ -201,5 +198,6 @@ Returns **Boolean** | ||
[index.js:93-101](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L93-L101 "Source code on GitHub") | ||
[index.js:94-102](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L94-L102 "Source code on GitHub") | ||
pads an array of buffer with leading zeros till it has `length` bytes | ||
Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes. | ||
Or it truncates the beginning if it exceeds. | ||
@@ -209,3 +207,3 @@ **Parameters** | ||
- `msg` **Buffer or Array** the value to pad | ||
- `length` **Integer** the number of bytes the output should be | ||
- `length` **Number** the number of bytes the output should be | ||
@@ -216,24 +214,15 @@ Returns **Buffer or Array** | ||
[index.js:531-534](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L531-L534 "Source code on GitHub") | ||
[index.js:520-523](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L520-L523 "Source code on GitHub") | ||
Pads a String to have an even length | ||
Pads a `String` to have an even length | ||
**Parameters** | ||
- `String` | ||
- `a` | ||
- `a` **String** | ||
# printBA | ||
Returns **String** | ||
[index.js:490-507](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L490-L507 "Source code on GitHub") | ||
Print a Buffer Array | ||
**Parameters** | ||
- `ba` | ||
# privateToAddress | ||
[index.js:323-325](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L323-L325 "Source code on GitHub") | ||
[index.js:331-333](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L331-L333 "Source code on GitHub") | ||
@@ -250,10 +239,10 @@ Returns the ethereum address of a given private key | ||
[index.js:298-303](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L298-L303 "Source code on GitHub") | ||
[index.js:301-311](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L301-L311 "Source code on GitHub") | ||
Returns the ethereum address of a given public key | ||
Returns the ethereum address of a given public key. | ||
Accepts "Ethereum public keys" and DER encoded keys. | ||
**Parameters** | ||
- `Buffer` | ||
- `pubKey` | ||
- `pubKey` **Buffer** | ||
@@ -264,3 +253,3 @@ Returns **Buffer** | ||
[index.js:272-280](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L272-L280 "Source code on GitHub") | ||
[index.js:274-282](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L274-L282 "Source code on GitHub") | ||
@@ -278,9 +267,9 @@ Creates RIPEMD160 hash of the input | ||
[index.js:66-66](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L66-L66 "Source code on GitHub") | ||
[index.js:66-66](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L66-L66 "Source code on GitHub") | ||
[`rlp`](https://github.com/wanderer/rlp) | ||
[`rlp`](https://github.com/ethereumjs/rlp) | ||
# rlphash | ||
[index.js:288-290](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L288-L290 "Source code on GitHub") | ||
[index.js:290-292](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L290-L292 "Source code on GitHub") | ||
@@ -297,5 +286,6 @@ Creates SHA-3 hash of the RLP encoded version of the input | ||
[index.js:110-118](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L110-L118 "Source code on GitHub") | ||
[index.js:112-120](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L112-L120 "Source code on GitHub") | ||
pads an array of buffer with trailing zeros till it has `length` bytes | ||
Pads an `Array` or `Buffer` with trailing zeros till it has `length` bytes | ||
Or it truncates the end if it exceeds. | ||
@@ -305,3 +295,3 @@ **Parameters** | ||
- `msg` **Buffer or Array** the value to pad | ||
- `length` **Integer** the number of bytes the output should be | ||
- `length` **Number** the number of bytes the output should be | ||
@@ -312,3 +302,3 @@ Returns **Buffer or Array** | ||
[index.js:72-72](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L72-L72 "Source code on GitHub") | ||
[index.js:72-72](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L72-L72 "Source code on GitHub") | ||
@@ -319,3 +309,3 @@ [`secp256k1`](https://github.com/cryptocoinjs/secp256k1-node/) | ||
[index.js:260-263](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L260-L263 "Source code on GitHub") | ||
[index.js:262-265](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L262-L265 "Source code on GitHub") | ||
@@ -332,3 +322,3 @@ Creates SHA256 hash of the input | ||
[index.js:243-252](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L243-L252 "Source code on GitHub") | ||
[index.js:245-254](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L245-L254 "Source code on GitHub") | ||
@@ -346,3 +336,3 @@ Creates SHA-3 hash of the input | ||
[index.js:373-378](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L373-L378 "Source code on GitHub") | ||
[index.js:384-389](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L384-L389 "Source code on GitHub") | ||
@@ -359,5 +349,5 @@ Removes "0x" from a given `String` | ||
[index.js:140-162](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L140-L162 "Source code on GitHub") | ||
[index.js:142-164](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L142-L164 "Source code on GitHub") | ||
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. | ||
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. | ||
@@ -370,9 +360,9 @@ **Parameters** | ||
[index.js:228-234](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L228-L234 "Source code on GitHub") | ||
[index.js:230-236](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L230-L236 "Source code on GitHub") | ||
Converts a `Bignum` to an unsigned interger and returns it as a `Buffer` | ||
Converts a `BN` to an unsigned integer and returns it as a `Buffer` | ||
**Parameters** | ||
- `num` **Bignum** | ||
- `num` **BN** | ||
@@ -383,9 +373,9 @@ Returns **Buffer** | ||
[index.js:126-134](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L126-L134 "Source code on GitHub") | ||
[index.js:128-136](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L128-L136 "Source code on GitHub") | ||
Trims leading zeros from a buffer or an array | ||
Trims leading zeros from a `Buffer` or an `Array` | ||
**Parameters** | ||
- `a` | ||
- `a` **Buffer or Array or String** | ||
@@ -396,3 +386,3 @@ Returns **Buffer or Array or String** | ||
[index.js:80-84](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L80-L84 "Source code on GitHub") | ||
[index.js:80-84](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L80-L84 "Source code on GitHub") | ||
@@ -403,3 +393,3 @@ Returns a buffer filled with 0s | ||
- `bytes` **Integer** the number of bytes the buffer should be | ||
- `bytes` **Number** the number of bytes the buffer should be | ||
@@ -410,3 +400,3 @@ Returns **Buffer** | ||
[index.js:311-315](https://github.com/ethereumjs/ethereumjs-util/blob/1a7e3cc380dcdacc37186eb72eec4dafbceed66f/index.js#L311-L315 "Source code on GitHub") | ||
[index.js:319-323](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L319-L323 "Source code on GitHub") | ||
@@ -413,0 +403,0 @@ Returns the ethereum public key of a given private key |
121
index.js
@@ -9,3 +9,3 @@ const SHA3 = require('sha3') | ||
/** | ||
* the max interger that this VM can handle (a ```BN```) | ||
* the max integer that this VM can handle (a ```BN```) | ||
* @var {BN} MAX_INTEGER | ||
@@ -64,3 +64,3 @@ */ | ||
/** | ||
* [`rlp`](https://github.com/wanderer/rlp) | ||
* [`rlp`](https://github.com/ethereumjs/rlp) | ||
* @var {Function} | ||
@@ -79,3 +79,3 @@ */ | ||
* @method zeros | ||
* @param {Integer} bytes the number of bytes the buffer should be | ||
* @param {Number} bytes the number of bytes the buffer should be | ||
* @return {Buffer} | ||
@@ -90,6 +90,7 @@ */ | ||
/** | ||
* pads an array of buffer with leading zeros till it has `length` bytes | ||
* Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes. | ||
* Or it truncates the beginning if it exceeds. | ||
* @method pad | ||
* @param {Buffer|Array} msg the value to pad | ||
* @param {Integer} length the number of bytes the output should be | ||
* @param {Number} length the number of bytes the output should be | ||
* @return {Buffer|Array} | ||
@@ -108,6 +109,7 @@ */ | ||
/** | ||
* pads an array of buffer with trailing zeros till it has `length` bytes | ||
* Pads an `Array` or `Buffer` with trailing zeros till it has `length` bytes | ||
* Or it truncates the end if it exceeds. | ||
* @method rpad | ||
* @param {Buffer|Array} msg the value to pad | ||
* @param {Integer} length the number of bytes the output should be | ||
* @param {Number} length the number of bytes the output should be | ||
* @return {Buffer|Array} | ||
@@ -122,9 +124,9 @@ */ | ||
} | ||
return msg.slice(-length) | ||
return msg.slice(0, length) | ||
} | ||
/** | ||
* Trims leading zeros from a buffer or an array | ||
* Trims leading zeros from a `Buffer` or an `Array` | ||
* @method unpad | ||
* @param {Buffer|Array|String} | ||
* @param {Buffer|Array|String} a | ||
* @return {Buffer|Array|String} | ||
@@ -142,3 +144,3 @@ */ | ||
/** | ||
* 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. | ||
* 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. | ||
* @method toBuffer | ||
@@ -172,9 +174,9 @@ * @param {*} v the value | ||
/** | ||
* Converts an integer into a hex string | ||
* Converts a `Number` into a hex `String` | ||
* @method intToHex | ||
* @param {Number} | ||
* @param {Number} i | ||
* @return {String} | ||
*/ | ||
exports.intToHex = function (i) { | ||
assert(i % 1 === 0, 'number is not a interger') | ||
assert(i % 1 === 0, 'number is not a integer') | ||
assert(i >= 0, 'number must be positive') | ||
@@ -190,5 +192,5 @@ var hex = i.toString(16) | ||
/** | ||
* Converts an `Integer` to a `Buffer` | ||
* Converts an `Number` to a `Buffer` | ||
* @method intToBuffer | ||
* @param {Integer} | ||
* @param {Number} i | ||
* @return {Buffer} | ||
@@ -202,5 +204,5 @@ */ | ||
/** | ||
* Converts a `Buffer` to an `Interger` | ||
* Converts a `Buffer` to a `Number` | ||
* @method bufferToInt | ||
* @param {Buffer} | ||
* @param {Buffer} buf | ||
* @return {Number} | ||
@@ -218,3 +220,3 @@ */ | ||
/** | ||
* interpets a `Buffer` as a signed integer and returns a `bignum` | ||
* Interprets a `Buffer` as a signed integer and returns a `BN` | ||
* @method fromSigned | ||
@@ -234,5 +236,5 @@ * @param {Buffer} num | ||
/** | ||
* Converts a `Bignum` to an unsigned interger and returns it as a `Buffer` | ||
* Converts a `BN` to an unsigned integer and returns it as a `Buffer` | ||
* @method toUnsigned | ||
* @param {Bignum} num | ||
* @param {BN} num | ||
* @return {Buffer} | ||
@@ -305,5 +307,6 @@ */ | ||
/** | ||
* Returns the ethereum address of a given public key | ||
* @method pubToAddress | ||
* @param {Buffer} | ||
* Returns the ethereum address of a given public key. | ||
* Accepts "Ethereum public keys" and DER encoded keys. | ||
* @method publicToAddress | ||
* @param {Buffer} pubKey | ||
* @return {Buffer} | ||
@@ -313,5 +316,10 @@ */ | ||
pubKey = exports.toBuffer(pubKey) | ||
var hash = new SHA3.SHA3Hash(256) | ||
hash.update(pubKey.slice(-64)) | ||
return new Buffer(hash.digest('hex').slice(-40), 'hex') | ||
// Handle uncompressed DER keys | ||
// FIXME: should we do this here? | ||
if (pubKey.length === 65 && pubKey[0] === 4) { | ||
pubKey = pubKey.slice(1) | ||
} | ||
assert(pubKey.length === 64) | ||
// Only take the lower 160bits of the hash | ||
return exports.sha3(pubKey).slice(-20) | ||
} | ||
@@ -350,10 +358,13 @@ | ||
from = exports.toBuffer(from) | ||
nonce = new Buffer(new BN(nonce).toArray()) | ||
nonce = new BN(nonce) | ||
if (nonce.toString('hex') === '00') { | ||
nonce = 0 | ||
if (nonce.isZero()) { | ||
// in RLP we want to encode null in the case of zero nonce | ||
// read the RLP documentation for an answer if you dare | ||
nonce = null | ||
} else { | ||
nonce = new Buffer(nonce.toArray()) | ||
} | ||
var hash = exports.sha3(rlp.encode([new Buffer(from, 'hex'), nonce])) | ||
return hash.slice(12) | ||
return exports.sha3(rlp.encode([from, nonce])).slice(12) | ||
} | ||
@@ -364,3 +375,3 @@ | ||
* @method isPrecompiled | ||
* @param {Buffer|String} | ||
* @param {Buffer|String} address | ||
* @return {Boolean} | ||
@@ -374,3 +385,3 @@ */ | ||
/** | ||
* Returns a `Boolean` on whether or not the a `Sting` starts with "0x" | ||
* Returns a `Boolean` on whether or not the a `String` starts with "0x" | ||
* @method isHexPrefixed | ||
@@ -398,5 +409,5 @@ * @param {String} str | ||
/** | ||
* Adds "0x" to a given string if it does not already start with "0x" | ||
* Adds "0x" to a given `String` if it does not already start with "0x" | ||
* @method addHexPrefix | ||
* @param {String} | ||
* @param {String} str | ||
* @return {String} | ||
@@ -413,3 +424,3 @@ */ | ||
/** | ||
* Defines properties on a Object. It make the assumption that underlying data is binary | ||
* Defines properties on a `Object`. It make the assumption that underlying data is binary. | ||
* @method defineProperties | ||
@@ -422,3 +433,3 @@ * @param {Object} self the `Object` to define properties on | ||
* * `allowEmpty` | ||
* @param {*} Data data to be validated against the definitions | ||
* @param {*} data data to be validated against the definitions | ||
*/ | ||
@@ -506,29 +517,6 @@ exports.defineProperties = function (self, fields, data) { | ||
/** | ||
* Print a Buffer Array | ||
* @method printBA | ||
* @param {Buffer|Array} | ||
*/ | ||
exports.printBA = function (ba) { | ||
if (Buffer.isBuffer(ba)) { | ||
if (ba.length === 0) { | ||
console.log('new Buffer(0)') | ||
} else { | ||
console.log("new Buffer('" + ba.toString('hex') + "', 'hex')") | ||
} | ||
} else if (ba instanceof Array) { | ||
console.log('[') | ||
for (var i = 0; i < ba.length; i++) { | ||
exports.printBA(ba[i]) | ||
console.log(',') | ||
} | ||
console.log(']') | ||
} else { | ||
console.log(ba) | ||
} | ||
} | ||
/** | ||
* converts a buffer array to JSON | ||
* Converts a `Buffer` or `Array` to JSON | ||
* @method BAToJSON | ||
* @param {Buffer|Array} | ||
* @param {Buffer|Array} ba | ||
* @return {Array} | ||
*/ | ||
@@ -548,5 +536,6 @@ exports.baToJSON = function (ba) { | ||
/** | ||
* Pads a String to have an even length | ||
* Pads a `String` to have an even length | ||
* @method padToEven | ||
* @param {String} | ||
* @param {String} a | ||
* @return {String} | ||
*/ | ||
@@ -553,0 +542,0 @@ exports.padToEven = function (a) { |
{ | ||
"name": "ethereumjs-util", | ||
"version": "2.5.0", | ||
"version": "2.6.0", | ||
"description": "a collection of utility functions for Ethereum", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -25,5 +25,5 @@ var assert = require('assert') | ||
var msg = '3c9229289a6125f7fdf1885a77bb12c37a8d3b4962d936f7e3084dece32a3ca1' | ||
var r = '82ff40c0a986c6a5cfad4ddf4c3aa6996f1a7837f9c398e17e5de5cbd5a12b28' | ||
var r = '22ae1937ff93ec72c4d46ff3e854661e3363440acd6f6e4adf8f1a8978382251' | ||
var hash = ethUtils.sha3(msg) | ||
assert.notEqual(hash.toString('hex'), r) | ||
assert.equal(hash.toString('hex'), r) | ||
}) | ||
@@ -83,3 +83,3 @@ }) | ||
describe('pad', function () { | ||
it('should pad a Buffer', function () { | ||
it('should left pad a Buffer', function () { | ||
var buf = new Buffer([9, 9]) | ||
@@ -89,2 +89,7 @@ var padded = ethUtils.pad(buf, 3) | ||
}) | ||
it('should left truncate a Buffer', function () { | ||
var buf = new Buffer([9, 0, 9]) | ||
var padded = ethUtils.pad(buf, 2) | ||
assert.equal(padded.toString('hex'), '0009') | ||
}) | ||
}) | ||
@@ -98,2 +103,7 @@ | ||
}) | ||
it('should right truncate a Buffer', function () { | ||
var buf = new Buffer([9, 0, 9]) | ||
var padded = ethUtils.rpad(buf, 2) | ||
assert.equal(padded.toString('hex'), '0900') | ||
}) | ||
}) | ||
@@ -122,3 +132,7 @@ | ||
assert.equal(i, 6003400) | ||
assert.equal(ethUtils.bufferToInt(new Buffer([])), 0) | ||
}) | ||
it('should convert empty input to 0', function () { | ||
assert.equal(ethUtils.bufferToInt(new Buffer([])), 0) | ||
}) | ||
}) | ||
@@ -165,4 +179,4 @@ | ||
it('should produce an address given a public key', function () { | ||
var pubKey = 'f049a20000000000f0b08900000000000841b30200000000200000000d000000' | ||
var address = 'ef6a1274aa67f83eadf383016d584cd6185477ae' | ||
var pubKey = '3a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a001cf066d56a8156fc201cd5df8a36ef694eecd258903fca7086c1fae7441e1d' | ||
var address = '2f015c60e0be116b1f0cd534704db9c92118fb6a' | ||
pubKey = new Buffer(pubKey, 'hex') | ||
@@ -172,2 +186,23 @@ var r = ethUtils.pubToAddress(pubKey) | ||
}) | ||
it('should produce an address given a DER public key', function () { | ||
var pubKey = '043a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a001cf066d56a8156fc201cd5df8a36ef694eecd258903fca7086c1fae7441e1d' | ||
var address = '2f015c60e0be116b1f0cd534704db9c92118fb6a' | ||
pubKey = new Buffer(pubKey, 'hex') | ||
var r = ethUtils.pubToAddress(pubKey) | ||
assert.equal(r.toString('hex'), address) | ||
}) | ||
it('shouldn\'t produce an address given an invalid DER public key', function () { | ||
var pubKey = '023a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a001cf066d56a8156fc201cd5df8a36ef694eecd258903fca7086c1fae7441e1d' | ||
pubKey = new Buffer(pubKey, 'hex') | ||
assert.throws(function () { | ||
ethUtils.pubToAddress(pubKey) | ||
}) | ||
}) | ||
it('shouldn\'t produce an address given an invalid public key', function () { | ||
var pubKey = '3a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a001cf066d56a8156fc201cd5df8a36ef694eecd258903fca7086c1fae744' | ||
pubKey = new Buffer(pubKey, 'hex') | ||
assert.throws(function () { | ||
ethUtils.pubToAddress(pubKey) | ||
}) | ||
}) | ||
}) | ||
@@ -177,4 +212,4 @@ | ||
it('should produce an address given a public key', function () { | ||
var pubKey = '0xf049a20000000000f0b08900000000000841b30200000000200000000d000000' | ||
var address = 'ef6a1274aa67f83eadf383016d584cd6185477ae' | ||
var pubKey = '0x3a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a001cf066d56a8156fc201cd5df8a36ef694eecd258903fca7086c1fae7441e1d' | ||
var address = '2f015c60e0be116b1f0cd534704db9c92118fb6a' | ||
var r = ethUtils.pubToAddress(pubKey) | ||
@@ -217,3 +252,3 @@ assert.equal(r.toString('hex'), address) | ||
var add = ethUtils.generateAddress('990ccf8a0de58091c028d6ff76bb235ee67c1c39', 14).toString('hex') | ||
assert.notEqual(add.toString('hex'), 'd658a4b8247c14868f3c512fa5cbb6e458e4a989') | ||
assert.equal(add.toString('hex'), '936a4295d8d74e310c0c95f0a63e53737b998d12') | ||
}) | ||
@@ -229,7 +264,17 @@ }) | ||
describe('generateAddress with nonce 0 (special case)', function () { | ||
it('should produce an address given a public key', function () { | ||
var add = ethUtils.generateAddress('0x990ccf8a0de58091c028d6ff76bb235ee67c1c39', 0).toString('hex') | ||
assert.equal(add.toString('hex'), 'bfa69ba91385206bfdd2d8b9c1a5d6c10097a85b') | ||
}) | ||
}) | ||
describe('hex prefix', function () { | ||
var string = 'd658a4b8247c14868f3c512fa5cbb6e458e4a989' | ||
it(' should add', function () { | ||
it('should add', function () { | ||
assert.equal(ethUtils.addHexPrefix(string), '0x' + string) | ||
}) | ||
it('should return on non-string input', function () { | ||
assert.equal(ethUtils.addHexPrefix(1), 1) | ||
}) | ||
}) | ||
@@ -250,1 +295,35 @@ | ||
}) | ||
describe('toBuffer', function () { | ||
it('should work', function () { | ||
// Buffer | ||
assert.deepEqual(ethUtils.toBuffer(new Buffer([])), new Buffer([])) | ||
// Array | ||
assert.deepEqual(ethUtils.toBuffer([]), new Buffer([])) | ||
// String | ||
assert.deepEqual(ethUtils.toBuffer('11'), new Buffer([49, 49])) | ||
assert.deepEqual(ethUtils.toBuffer('0x11'), new Buffer([17])) | ||
assert.deepEqual(ethUtils.toBuffer('1234').toString('hex'), '31323334') | ||
assert.deepEqual(ethUtils.toBuffer('0x1234').toString('hex'), '1234') | ||
// Number | ||
assert.deepEqual(ethUtils.toBuffer(1), new Buffer([1])) | ||
// null | ||
assert.deepEqual(ethUtils.toBuffer(null), new Buffer([])) | ||
// undefined | ||
assert.deepEqual(ethUtils.toBuffer(), new Buffer([])) | ||
// 'toArray' | ||
assert.deepEqual(ethUtils.toBuffer(new BN(1)), new Buffer([1])) | ||
}) | ||
it('should fail', function () { | ||
assert.throws(function () { | ||
ethUtils.toBuffer({ test: 1 }) | ||
}) | ||
}) | ||
}) | ||
describe('baToJSON', function () { | ||
it('should turn a array of buffers into a pure json object', function () { | ||
var ba = [new Buffer([0]), new Buffer([1]), [new Buffer([2])]] | ||
assert.deepEqual(ethUtils.baToJSON(ba), ['00', '01', ['02']]) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41117
824