Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ethereumjs-util

Package Overview
Dependencies
Maintainers
2
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ethereumjs-util - npm Package Compare versions

Comparing version 4.5.0 to 5.0.0

.package.json

114

docs/index.md
# addHexPrefix
[index.js:560-566](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L560-L566 "Source code on GitHub")
[index.js:535-541](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L535-L541 "Source code on GitHub")

@@ -15,3 +15,3 @@ Adds "0x" to a given `String` if it does not already start with "0x"

[index.js:585-595](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L585-L595 "Source code on GitHub")
[index.js:594-604](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L594-L604 "Source code on GitHub")

@@ -28,3 +28,3 @@ Converts a `Buffer` or `Array` to JSON

[index.js:60-60](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L60-L60 "Source code on GitHub")
[index.js:60-60](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L60-L60 "Source code on GitHub")

@@ -35,3 +35,3 @@ [`BN`](https://github.com/indutny/bn.js)

[index.js:213-220](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L213-L220 "Source code on GitHub")
[index.js:207-214](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L207-L214 "Source code on GitHub")

@@ -48,3 +48,3 @@ Converts a `Buffer` into a hex `String`

[index.js:203-205](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L203-L205 "Source code on GitHub")
[index.js:198-200](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L198-L200 "Source code on GitHub")

@@ -61,3 +61,3 @@ Converts a `Buffer` to a `Number`

[index.js:608-701](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L608-L701 "Source code on GitHub")
[index.js:616-709](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L616-L709 "Source code on GitHub")

@@ -77,3 +77,3 @@ Defines properties on a `Object`. It make the assumption that underlying data is binary.

[index.js:399-407](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L399-L407 "Source code on GitHub")
[index.js:380-388](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L380-L388 "Source code on GitHub")

@@ -85,3 +85,3 @@ ECDSA public key recovery from signature

- `msgHash` **Buffer**
- `v` **Buffer**
- `v` **Number**
- `r` **Buffer**

@@ -94,3 +94,3 @@ - `s` **Buffer**

[index.js:380-388](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L380-L388 "Source code on GitHub")
[index.js:362-370](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L362-L370 "Source code on GitHub")

@@ -108,5 +108,6 @@ ECDSA sign

[index.js:429-443](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L429-L443 "Source code on GitHub")
[index.js:409-427](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L409-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: <https://github.com/ethereum/go-ethereum/issues/2053>

@@ -121,3 +122,3 @@ **Parameters**

[index.js:228-230](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L228-L230 "Source code on GitHub")
[index.js:221-223](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L221-L223 "Source code on GitHub")

@@ -134,3 +135,3 @@ Interprets a `Buffer` as a signed integer and returns a `BN`. Assumes 256-bit numbers.

[index.js:504-518](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L504-L518 "Source code on GitHub")
[index.js:483-497](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L483-L497 "Source code on GitHub")

@@ -148,3 +149,3 @@ Generates an address of a newly created contract

[index.js:365-371](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L365-L371 "Source code on GitHub")
[index.js:348-354](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L348-L354 "Source code on GitHub")

@@ -161,3 +162,3 @@ Converts a public key to the Ethereum format.

[index.js:192-195](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L192-L195 "Source code on GitHub")
[index.js:187-190](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L187-L190 "Source code on GitHub")

@@ -174,3 +175,3 @@ Converts an `Number` to a `Buffer`

[index.js:175-184](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L175-L184 "Source code on GitHub")
[index.js:171-180](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L171-L180 "Source code on GitHub")

@@ -187,3 +188,3 @@ Converts a `Number` into a hex `String`

[index.js:537-539](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L537-L539 "Source code on GitHub")
[index.js:514-516](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L514-L516 "Source code on GitHub")

@@ -200,3 +201,3 @@ Returns a `Boolean` on whether or not the a `String` starts with "0x"

[index.js:526-529](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L526-L529 "Source code on GitHub")
[index.js:504-507](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L504-L507 "Source code on GitHub")

@@ -213,3 +214,3 @@ Returns true if the supplied address belongs to a precompiled account

[index.js:461-463](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L461-L463 "Source code on GitHub")
[index.js:443-445](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L443-L445 "Source code on GitHub")

@@ -226,3 +227,3 @@ Checks if the address is a valid. Accepts checksummed addresses too

[index.js:493-495](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L493-L495 "Source code on GitHub")
[index.js:473-475](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L473-L475 "Source code on GitHub")

@@ -239,3 +240,3 @@ Checks if the address is a valid checksummed address

[index.js:304-306](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L304-L306 "Source code on GitHub")
[index.js:291-293](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L291-L293 "Source code on GitHub")

@@ -252,3 +253,3 @@ Checks if the private key satisfies the rules of the curve secp256k1.

[index.js:316-327](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L316-L327 "Source code on GitHub")
[index.js:302-313](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L302-L313 "Source code on GitHub")

@@ -267,3 +268,3 @@ Checks if the public key satisfies the rules of the curve secp256k1

[index.js:12-12](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L12-L12 "Source code on GitHub")
[index.js:12-12](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L12-L12 "Source code on GitHub")

@@ -274,3 +275,3 @@ the max integer that this VM can handle (a `BN`)

[index.js:574-577](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L574-L577 "Source code on GitHub")
[index.js:548-551](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L548-L551 "Source code on GitHub")

@@ -287,3 +288,3 @@ Pads a `String` to have an even length

[index.js:451-453](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L451-L453 "Source code on GitHub")
[index.js:434-436](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L434-L436 "Source code on GitHub")

@@ -300,3 +301,3 @@ Returns the ethereum address of a given private key

[index.js:337-345](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L337-L345 "Source code on GitHub")
[index.js:322-330](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L322-L330 "Source code on GitHub")

@@ -315,3 +316,3 @@ Returns the ethereum address of a given public key.

[index.js:278-286](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L278-L286 "Source code on GitHub")
[index.js:267-275](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L267-L275 "Source code on GitHub")

@@ -329,3 +330,3 @@ Creates RIPEMD160 hash of the input

[index.js:66-66](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L66-L66 "Source code on GitHub")
[index.js:66-66](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L66-L66 "Source code on GitHub")

@@ -336,3 +337,3 @@ [`rlp`](https://github.com/ethereumjs/rlp)

[index.js:294-296](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L294-L296 "Source code on GitHub")
[index.js:282-284](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L282-L284 "Source code on GitHub")

@@ -349,3 +350,3 @@ Creates SHA-3 hash of the RLP encoded version of the input

[index.js:72-72](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L72-L72 "Source code on GitHub")
[index.js:72-72](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L72-L72 "Source code on GitHub")

@@ -356,3 +357,3 @@ [`secp256k1`](https://github.com/cryptocoinjs/secp256k1-node/)

[index.js:95-111](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L95-L111 "Source code on GitHub")
[index.js:95-111](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L95-L111 "Source code on GitHub")

@@ -372,3 +373,3 @@ Left Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes.

[index.js:121-123](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L121-L123 "Source code on GitHub")
[index.js:120-122](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L120-L122 "Source code on GitHub")

@@ -387,3 +388,3 @@ Right Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes.

[index.js:266-269](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L266-L269 "Source code on GitHub")
[index.js:256-259](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L256-L259 "Source code on GitHub")

@@ -400,3 +401,3 @@ Creates SHA256 hash of the input

[index.js:249-258](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L249-L258 "Source code on GitHub")
[index.js:240-249](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L240-L249 "Source code on GitHub")

@@ -408,3 +409,3 @@ Creates SHA-3 hash of the input

- `a` **Buffer or Array or String or Number** the input data
- `bytes` **[Number]** the SHA width (optional, default `256`)
- `bits` **[Number]** the SHA width (optional, default `256`)

@@ -415,3 +416,3 @@ Returns **Buffer**

[index.js:30-30](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L30-L30 "Source code on GitHub")
[index.js:30-30](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L30-L30 "Source code on GitHub")

@@ -422,3 +423,3 @@ SHA3-256 hash of null (a `Buffer`)

[index.js:24-24](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L24-L24 "Source code on GitHub")
[index.js:24-24](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L24-L24 "Source code on GitHub")

@@ -429,3 +430,3 @@ SHA3-256 hash of null (a `String`)

[index.js:54-54](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L54-L54 "Source code on GitHub")
[index.js:54-54](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L54-L54 "Source code on GitHub")

@@ -436,3 +437,3 @@ SHA3-256 hash of the RLP of null (a `Buffer`)

[index.js:42-42](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L42-L42 "Source code on GitHub")
[index.js:42-42](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L42-L42 "Source code on GitHub")

@@ -443,3 +444,3 @@ SHA3-256 of an RLP of an empty array (a `Buffer`)

[index.js:36-36](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L36-L36 "Source code on GitHub")
[index.js:36-36](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L36-L36 "Source code on GitHub")

@@ -450,3 +451,3 @@ SHA3-256 of an RLP of an empty array (a `String`)

[index.js:48-48](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L48-L48 "Source code on GitHub")
[index.js:48-48](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L48-L48 "Source code on GitHub")

@@ -457,3 +458,3 @@ SHA3-256 hash of the RLP of null (a `String`)

[index.js:547-552](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L547-L552 "Source code on GitHub")
[index.js:523-528](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L523-L528 "Source code on GitHub")

@@ -470,3 +471,3 @@ Removes "0x" from a given `String`

[index.js:145-167](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L145-L167 "Source code on GitHub")
[index.js:142-164](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L142-L164 "Source code on GitHub")

@@ -481,3 +482,3 @@ 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.

[index.js:471-485](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L471-L485 "Source code on GitHub")
[index.js:452-466](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L452-L466 "Source code on GitHub")

@@ -494,3 +495,3 @@ Returns a checksummed address

[index.js:417-421](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L417-L421 "Source code on GitHub")
[index.js:397-401](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L397-L401 "Source code on GitHub")

@@ -509,3 +510,3 @@ Convert signature parameters into the format of `eth_sign` RPC method

[index.js:238-240](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L238-L240 "Source code on GitHub")
[index.js:230-232](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L230-L232 "Source code on GitHub")

@@ -522,3 +523,3 @@ Converts a `BN` to an unsigned integer and returns it as a `Buffer`. Assumes 256-bit numbers.

[index.js:18-18](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L18-L18 "Source code on GitHub")
[index.js:18-18](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L18-L18 "Source code on GitHub")

@@ -529,3 +530,3 @@ 2^256 (a `BN`)

[index.js:131-139](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L131-L139 "Source code on GitHub")
[index.js:129-137](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L129-L137 "Source code on GitHub")

@@ -542,3 +543,3 @@ Trims leading zeros from a `Buffer` or an `Array`

[index.js:80-84](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L80-L84 "Source code on GitHub")
[index.js:80-84](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L80-L84 "Source code on GitHub")

@@ -555,3 +556,3 @@ Returns a buffer filled with 0s

[index.js:353-357](https://github.com/ethereumjs/ethereumjs-util/blob/3527634ea80decbf2915ceafd8f3e259c004b9d3/index.js#L353-L357 "Source code on GitHub")
[index.js:337-341](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L337-L341 "Source code on GitHub")

@@ -565,1 +566,16 @@ Returns the ethereum public key of a given private key

Returns **Buffer**
# SECP256K1_N_DIV_2
[index.js:563-563](https://github.com/ethereum/ethereumjs-util/blob/dc680ef2824775a01398fd92d1a3716a383510c7/index.js#L563-L563 "Source code on GitHub")
Validate ECDSA signature
**Parameters**
- `v` **Buffer**
- `r` **Buffer**
- `s` **Buffer**
- `homestead` **[Boolean]** (optional, default `true`)
Returns **Boolean**

@@ -116,3 +116,2 @@ const SHA3 = require('keccakjs')

* Or it truncates the beginning if it exceeds.
* @method lsetLength
* @param {Buffer|Array} msg the value to pad

@@ -128,3 +127,2 @@ * @param {Number} length the number of bytes the output should be

* Trims leading zeros from a `Buffer` or an `Array`
* @method unpad
* @param {Buffer|Array|String} a

@@ -144,3 +142,2 @@ * @return {Buffer|Array|String}

* 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
* @param {*} v the value

@@ -174,3 +171,2 @@ */

* Converts a `Number` into a hex `String`
* @method intToHex
* @param {Number} i

@@ -192,3 +188,2 @@ * @return {String}

* Converts an `Number` to a `Buffer`
* @method intToBuffer
* @param {Number} i

@@ -204,8 +199,8 @@ * @return {Buffer}

* Converts a `Buffer` to a `Number`
* @method bufferToInt
* @param {Buffer} buf
* @return {Number}
* @throws If the input number exceeds 53 bits.
*/
exports.bufferToInt = function (buf) {
return parseInt(exports.bufferToHex(buf), 16)
return new BN(exports.toBuffer(buf)).toNumber()
}

@@ -215,3 +210,2 @@

* Converts a `Buffer` into a hex `String`
* @method bufferToHex
* @param {Buffer} buf

@@ -231,3 +225,2 @@ * @return {String}

* Interprets a `Buffer` as a signed integer and returns a `BN`. Assumes 256-bit numbers.
* @method fromSigned
* @param {Buffer} num

@@ -242,3 +235,2 @@ * @return {BN}

* Converts a `BN` to an unsigned integer and returns it as a `Buffer`. Assumes 256-bit numbers.
* @method toUnsigned
* @param {BN} num

@@ -253,12 +245,11 @@ * @return {Buffer}

* Creates SHA-3 hash of the input
* @method sha3
* @param {Buffer|Array|String|Number} a the input data
* @param {Number} [bytes=256] the SHA width
* @param {Number} [bits=256] the SHA width
* @return {Buffer}
*/
exports.sha3 = function (a, bytes) {
exports.sha3 = function (a, bits) {
a = exports.toBuffer(a)
if (!bytes) bytes = 256
if (!bits) bits = 256
var h = new SHA3(bytes)
var h = new SHA3(bits)
if (a) {

@@ -272,3 +263,2 @@ h.update(a)

* Creates SHA256 hash of the input
* @method sha256
* @param {Buffer|Array|String|Number} a the input data

@@ -284,3 +274,2 @@ * @return {Buffer}

* Creates RIPEMD160 hash of the input
* @method ripemd160
* @param {Buffer|Array|String|Number} a the input data

@@ -302,3 +291,2 @@ * @param {Boolean} padded whether it should be padded to 256 bits or not

* Creates SHA-3 hash of the RLP encoded version of the input
* @method rlphash
* @param {Buffer|Array|String|Number} a the input data

@@ -313,3 +301,2 @@ * @return {Buffer}

* Checks if the private key satisfies the rules of the curve secp256k1.
* @method isValidPrivate
* @param {Buffer} privateKey

@@ -325,3 +312,2 @@ * @return {Boolean}

* and the requirements of Ethereum.
* @method isValidPublic
* @param {Buffer} publicKey The two points of an uncompressed key, unless sanitize is enabled

@@ -347,3 +333,2 @@ * @param {Boolean} [sanitize=false] Accept public keys in other formats

* Accepts "Ethereum public keys" and SEC1 encoded keys.
* @method publicToAddress
* @param {Buffer} pubKey The two points of an uncompressed key, unless sanitize is enabled

@@ -365,3 +350,2 @@ * @param {Boolean} [sanitize=false] Accept public keys in other formats

* Returns the ethereum public key of a given private key
* @method privateToPublic
* @param {Buffer} privateKey A private key must be 256 bits wide

@@ -378,3 +362,2 @@ * @return {Buffer}

* Converts a public key to the Ethereum format.
* @method importPublic
* @param {Buffer} publicKey

@@ -393,3 +376,2 @@ * @return {Buffer}

* ECDSA sign
* @method ecsign
* @param {Buffer} msgHash

@@ -411,5 +393,4 @@ * @param {Buffer} privateKey

* ECDSA public key recovery from signature
* @method ecrecover
* @param {Buffer} msgHash
* @param {Buffer} v
* @param {Number} v
* @param {Buffer} r

@@ -421,3 +402,3 @@ * @param {Buffer} s

var signature = Buffer.concat([exports.setLength(r, 32), exports.setLength(s, 32)], 64)
var recovery = exports.bufferToInt(v) - 27
var recovery = v - 27
if (recovery !== 0 && recovery !== 1) {

@@ -432,3 +413,2 @@ throw new Error('Invalid signature v value')

* Convert signature parameters into the format of `eth_sign` RPC method
* @method toRpcSig
* @param {Number} v

@@ -447,3 +427,3 @@ * @param {Buffer} r

* Convert signature format of the `eth_sign` RPC method to signature parameters
* @method fromRpcSig
* NOTE: all because of a bug in geth: https://github.com/ethereum/go-ethereum/issues/2053
* @param {String} sig

@@ -455,2 +435,6 @@ * @return {Object}

if (sig.length !== 65) {
throw new Error('Invalid signature length')
}
var v = sig[64]

@@ -471,3 +455,2 @@ // support both versions of `eth_sign` responses

* Returns the ethereum address of a given private key
* @method privateToAddress
* @param {Buffer} privateKey A private key must be 256 bits wide

@@ -482,3 +465,2 @@ * @return {Buffer}

* Checks if the address is a valid. Accepts checksummed addresses too
* @method isValidAddress
* @param {String} address

@@ -493,3 +475,2 @@ * @return {Boolean}

* Returns a checksummed address
* @method toChecksumAddress
* @param {String} address

@@ -516,3 +497,2 @@ * @return {String}

* Checks if the address is a valid checksummed address
* @method isValidChecksumAddress
* @param {Buffer} address

@@ -527,3 +507,2 @@ * @return {Boolean}

* Generates an address of a newly created contract
* @method generateAddress
* @param {Buffer} from the address which is creating this new address

@@ -551,3 +530,2 @@ * @param {Buffer} nonce the nonce of the from account

* Returns true if the supplied address belongs to a precompiled account
* @method isPrecompiled
* @param {Buffer|String} address

@@ -563,3 +541,2 @@ * @return {Boolean}

* Returns a `Boolean` on whether or not the a `String` starts with "0x"
* @method isHexPrefixed
* @param {String} str

@@ -574,3 +551,2 @@ * @return {Boolean}

* Removes "0x" from a given `String`
* @method stripHexPrefix
* @param {String} str

@@ -588,3 +564,2 @@ * @return {String}

* Adds "0x" to a given `String` if it does not already start with "0x"
* @method addHexPrefix
* @param {String} str

@@ -603,3 +578,2 @@ * @return {String}

* Pads a `String` to have an even length
* @method padToEven
* @param {String} a

@@ -614,4 +588,39 @@ * @return {String}

/**
* Validate ECDSA signature
* @method isValidSignature
* @param {Buffer} v
* @param {Buffer} r
* @param {Buffer} s
* @param {Boolean} [homestead=true]
* @return {Boolean}
*/
const SECP256K1_N_DIV_2 = new BN('7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0', 16)
const SECP256K1_N = new BN('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141', 16)
exports.isValidSignature = function (v, r, s, homestead) {
if (r.length !== 32 || s.length !== 32) {
return false
}
if (v !== 27 && v !== 28) {
return false
}
r = new BN(r)
s = new BN(s)
if (r.isZero() || r.gt(SECP256K1_N) || s.isZero() || s.gt(SECP256K1_N)) {
return false
}
if ((homestead === false) && (new BN(s).cmp(SECP256K1_N_DIV_2) === 1)) {
return false
}
return true
}
/**
* Converts a `Buffer` or `Array` to JSON
* @method BAToJSON
* @param {Buffer|Array} ba

@@ -634,3 +643,2 @@ * @return {Array|String|null}

* Defines properties on a `Object`. It make the assumption that underlying data is binary.
* @method defineProperties
* @param {Object} self the `Object` to define properties on

@@ -728,7 +736,7 @@ * @param {Array} fields an array fields to define. Fields can contain:

} else if (typeof data === 'object') {
for (var prop in data) {
if (self._fields.indexOf(prop) !== -1) {
self[prop] = data[prop]
}
}
const keys = Object.keys(data)
fields.forEach(function (field) {
if (keys.indexOf(field.name) !== -1) self[field.name] = data[field.name]
if (keys.indexOf(field.alias) !== -1) self[field.alias] = data[field.alias]
})
} else {

@@ -735,0 +743,0 @@ throw new Error('invalid data')

{
"name": "ethereumjs-util",
"version": "4.5.0",
"version": "5.0.0",
"description": "a collection of utility functions for Ethereum",

@@ -14,3 +14,3 @@ "main": "index.js",

"test:node": "istanbul test mocha -- --reporter spec",
"build:docs": "documentation --github -f md ./index.js > ./docs/index.md"
"build:docs": "documentation --github -f md ./index.js > ./docs/index.md && contributor"
},

@@ -27,3 +27,70 @@ "repository": {

"contributors": [
"Alex Beregszaszi <alex@rtfs.hu>"
{
"name": "Tim Coulter",
"email": "tim@timothyjcoulter.com",
"url": "https://github.com/tcoulter",
"contributions": 1,
"additions": 2,
"deletions": 2
},
{
"name": "Nick Dodson",
"url": "https://github.com/SilentCicero",
"contributions": 2,
"additions": 26,
"deletions": 2
},
{
"url": "https://github.com/MrChico",
"contributions": 1,
"additions": 11,
"deletions": 1
},
{
"name": "Dũng Trần",
"email": "tad88.dev@gmail.com",
"url": "https://github.com/tad88dev",
"contributions": 2,
"additions": 5,
"deletions": 5
},
{
"name": "Alex Beregszaszi",
"email": "alex@rtfs.hu",
"url": "https://github.com/axic",
"contributions": 77,
"additions": 1796,
"deletions": 642
},
{
"name": "Taylor Gerring",
"url": "https://github.com/tgerring",
"contributions": 1,
"additions": 1,
"deletions": 1
},
{
"name": "Kirill Fomichev",
"email": "fanatid@ya.ru",
"url": "https://github.com/fanatid",
"contributions": 8,
"additions": 32,
"deletions": 16
},
{
"name": "kumavis",
"email": "aaron@kumavis.me",
"url": "https://github.com/kumavis",
"contributions": 2,
"additions": 2,
"deletions": 2
},
{
"name": "Alexander Sinyagin",
"email": "sinyagin.alexander@gmail.com",
"url": "https://github.com/asinyagin",
"contributions": 1,
"additions": 3,
"deletions": 1
}
],

@@ -44,2 +111,3 @@ "license": "MPL-2.0",

"browserify": "^13.0.0",
"contributor": "^0.1.25",
"coveralls": "^2.11.4",

@@ -51,3 +119,3 @@ "documentation": "^3.0.4",

"karma-chrome-launcher": "^0.2.2",
"karma-detect-browsers": "^2.0.2",
"karma-detect-browsers": "2.0.2",
"karma-env-preprocessor": "^0.1.1",

@@ -57,3 +125,3 @@ "karma-firefox-launcher": "^0.1.7",

"mocha": "^2.3.4",
"standard": "^5.4.1"
"standard": "*"
},

@@ -60,0 +128,0 @@ "standard": {

@@ -115,2 +115,11 @@ var assert = require('assert')

})
it('alias should work #2', function () {
var someOb = {}
var data = { blah: '42' }
ethUtil.defineProperties(someOb, fields, data)
assert.equal(someOb.blah, '42')
assert.equal(someOb.aword, '42')
})
})

@@ -479,2 +479,31 @@ var assert = require('assert')

describe('isValidSignature', function () {
it('should fail on an invalid signature (shorter r))', function () {
var r = new Buffer('99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1ab', 'hex')
var s = new Buffer('129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66', 'hex')
assert.equal(ethUtils.isValidSignature(27, r, s), false)
})
it('should fail on an invalid signature (shorter s))', function () {
var r = new Buffer('99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9', 'hex')
var s = new Buffer('129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca', 'hex')
assert.equal(ethUtils.isValidSignature(27, r, s), false)
})
it('should fail on an invalid signature (v = 21)', function () {
var r = new Buffer('99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9', 'hex')
var s = new Buffer('129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66', 'hex')
assert.equal(ethUtils.isValidSignature(21, r, s), false)
})
it('should fail on an invalid signature (v = 29)', function () {
var r = new Buffer('99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9', 'hex')
var s = new Buffer('129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66', 'hex')
assert.equal(ethUtils.isValidSignature(29, r, s), false)
})
it('should work otherwise', function () {
var r = new Buffer('99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9', 'hex')
var s = new Buffer('129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66', 'hex')
assert.equal(ethUtils.isValidSignature(27, r, s), true)
})
// FIXME: add homestead test
})
var checksumAddresses = [

@@ -539,2 +568,11 @@ // All caps

})
it('should throw on invalid length', function () {
assert.throws(function () {
ethUtils.fromRpcSig('')
})
assert.throws(function () {
ethUtils.fromRpcSig('0x99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca660042')
})
})
})

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc