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 2.6.0 to 3.0.0

192

docs/index.md

@@ -1,58 +0,4 @@

# BN
[index.js:60-60](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L60-L60 "Source code on GitHub")
[`BN`](https://github.com/indutny/bn.js)
# MAX_INTEGER
[index.js:12-12](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L12-L12 "Source code on GitHub")
the max integer that this VM can handle (a `BN`)
# SHA3_NULL
[index.js:30-30](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L30-L30 "Source code on GitHub")
SHA3-256 hash of null (a `Buffer`)
# SHA3_NULL_S
[index.js:24-24](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L24-L24 "Source code on GitHub")
SHA3-256 hash of null (a `String`)
# SHA3_RLP
[index.js:54-54](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L54-L54 "Source code on GitHub")
SHA3-256 hash of the RLP of null (a `Buffer`)
# SHA3_RLP_ARRAY
[index.js:42-42](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L42-L42 "Source code on GitHub")
SHA3-256 of an RLP of an empty array (a `Buffer`)
# SHA3_RLP_ARRAY_S
[index.js:36-36](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L36-L36 "Source code on GitHub")
SHA3-256 of an RLP of an empty array (a `String`)
# SHA3_RLP_S
[index.js:48-48](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L48-L48 "Source code on GitHub")
SHA3-256 hash of the RLP of null (a `String`)
# TWO_POW256
[index.js:18-18](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L18-L18 "Source code on GitHub")
2^256 (a `BN`)
# addHexPrefix
[index.js:397-403](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L397-L403 "Source code on GitHub")
[index.js:398-404](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L398-L404 "Source code on GitHub")

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

[index.js:502-512](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L502-L512 "Source code on GitHub")
[index.js:503-513](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L503-L513 "Source code on GitHub")

@@ -78,7 +24,13 @@ Converts a `Buffer` or `Array` to JSON

Returns **Array**
Returns **Array or String or **
# BN
[index.js:60-60](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L60-L60 "Source code on GitHub")
[`BN`](https://github.com/indutny/bn.js)
# bufferToInt
[index.js:200-207](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L200-L207 "Source code on GitHub")
[index.js:200-207](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L200-L207 "Source code on GitHub")

@@ -95,3 +47,3 @@ Converts a `Buffer` to a `Number`

[index.js:416-494](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L416-L494 "Source code on GitHub")
[index.js:417-495](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L417-L495 "Source code on GitHub")

@@ -109,5 +61,33 @@ Defines properties on a `Object`. It make the assumption that underlying data is binary.

# ecrecover
[index.js:552-557](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L552-L557 "Source code on GitHub")
ECDSA public key recovery from signature
**Parameters**
- `msgHash` **Buffer**
- `v` **Buffer**
- `r` **Buffer**
- `s` **Buffer**
Returns **Buffer** publicKey
# ecsign
[index.js:533-541](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L533-L541 "Source code on GitHub")
ECDSA sign
**Parameters**
- `msgHash` **Buffer**
- `privateKey` **Buffer**
Returns **Object**
# fromSigned
[index.js:215-222](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L215-L222 "Source code on GitHub")
[index.js:215-222](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L215-L222 "Source code on GitHub")

@@ -124,3 +104,3 @@ Interprets a `Buffer` as a signed integer and returns a `BN`

[index.js:342-355](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L342-L355 "Source code on GitHub")
[index.js:342-356](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L342-L356 "Source code on GitHub")

@@ -138,3 +118,3 @@ Generates an address of a newly created contract

[index.js:189-192](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L189-L192 "Source code on GitHub")
[index.js:189-192](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L189-L192 "Source code on GitHub")

@@ -151,3 +131,3 @@ Converts an `Number` to a `Buffer`

[index.js:172-181](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L172-L181 "Source code on GitHub")
[index.js:172-181](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L172-L181 "Source code on GitHub")

@@ -164,3 +144,3 @@ Converts a `Number` into a hex `String`

[index.js:374-376](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L374-L376 "Source code on GitHub")
[index.js:375-377](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L375-L377 "Source code on GitHub")

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

[index.js:363-366](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L363-L366 "Source code on GitHub")
[index.js:364-367](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L364-L367 "Source code on GitHub")

@@ -188,5 +168,11 @@ Returns true if the supplied address belongs to a precompiled account

# MAX_INTEGER
[index.js:12-12](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L12-L12 "Source code on GitHub")
the max integer that this VM can handle (a `BN`)
# pad
[index.js:94-102](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L94-L102 "Source code on GitHub")
[index.js:94-102](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L94-L102 "Source code on GitHub")

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

[index.js:520-523](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L520-L523 "Source code on GitHub")
[index.js:521-524](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L521-L524 "Source code on GitHub")

@@ -218,3 +204,3 @@ Pads a `String` to have an even length

[index.js:331-333](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L331-L333 "Source code on GitHub")
[index.js:331-333](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L331-L333 "Source code on GitHub")

@@ -231,3 +217,3 @@ Returns the ethereum address of a given private key

[index.js:301-311](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L301-L311 "Source code on GitHub")
[index.js:301-311](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L301-L311 "Source code on GitHub")

@@ -245,3 +231,3 @@ Returns the ethereum address of a given public key.

[index.js:274-282](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L274-L282 "Source code on GitHub")
[index.js:274-282](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L274-L282 "Source code on GitHub")

@@ -259,3 +245,3 @@ Creates RIPEMD160 hash of the input

[index.js:66-66](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L66-L66 "Source code on GitHub")
[index.js:66-66](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L66-L66 "Source code on GitHub")

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

[index.js:290-292](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L290-L292 "Source code on GitHub")
[index.js:290-292](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L290-L292 "Source code on GitHub")

@@ -279,3 +265,3 @@ Creates SHA-3 hash of the RLP encoded version of the input

[index.js:112-120](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L112-L120 "Source code on GitHub")
[index.js:112-120](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L112-L120 "Source code on GitHub")

@@ -294,3 +280,3 @@ Pads an `Array` or `Buffer` with trailing zeros till it has `length` bytes

[index.js:72-72](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L72-L72 "Source code on GitHub")
[index.js:72-72](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L72-L72 "Source code on GitHub")

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

[index.js:262-265](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L262-L265 "Source code on GitHub")
[index.js:262-265](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L262-L265 "Source code on GitHub")

@@ -314,3 +300,3 @@ Creates SHA256 hash of the input

[index.js:245-254](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L245-L254 "Source code on GitHub")
[index.js:245-254](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L245-L254 "Source code on GitHub")

@@ -326,5 +312,41 @@ Creates SHA-3 hash of the input

# SHA3_NULL
[index.js:30-30](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L30-L30 "Source code on GitHub")
SHA3-256 hash of null (a `Buffer`)
# SHA3_NULL_S
[index.js:24-24](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L24-L24 "Source code on GitHub")
SHA3-256 hash of null (a `String`)
# SHA3_RLP
[index.js:54-54](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L54-L54 "Source code on GitHub")
SHA3-256 hash of the RLP of null (a `Buffer`)
# SHA3_RLP_ARRAY
[index.js:42-42](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L42-L42 "Source code on GitHub")
SHA3-256 of an RLP of an empty array (a `Buffer`)
# SHA3_RLP_ARRAY_S
[index.js:36-36](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L36-L36 "Source code on GitHub")
SHA3-256 of an RLP of an empty array (a `String`)
# SHA3_RLP_S
[index.js:48-48](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L48-L48 "Source code on GitHub")
SHA3-256 hash of the RLP of null (a `String`)
# stripHexPrefix
[index.js:384-389](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L384-L389 "Source code on GitHub")
[index.js:385-390](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L385-L390 "Source code on GitHub")

@@ -341,3 +363,3 @@ Removes "0x" from a given `String`

[index.js:142-164](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L142-L164 "Source code on GitHub")
[index.js:142-164](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L142-L164 "Source code on GitHub")

@@ -352,3 +374,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:230-236](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L230-L236 "Source code on GitHub")
[index.js:230-236](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L230-L236 "Source code on GitHub")

@@ -363,5 +385,11 @@ Converts a `BN` to an unsigned integer and returns it as a `Buffer`

# TWO_POW256
[index.js:18-18](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L18-L18 "Source code on GitHub")
2^256 (a `BN`)
# unpad
[index.js:128-136](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L128-L136 "Source code on GitHub")
[index.js:128-136](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L128-L136 "Source code on GitHub")

@@ -378,3 +406,3 @@ Trims leading zeros from a `Buffer` or an `Array`

[index.js:80-84](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L80-L84 "Source code on GitHub")
[index.js:80-84](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L80-L84 "Source code on GitHub")

@@ -391,3 +419,3 @@ Returns a buffer filled with 0s

[index.js:319-323](https://github.com/ethereumjs/ethereumjs-util/blob/f4083cff39ead1804124f2cda3f4b83402e016f6/index.js#L319-L323 "Source code on GitHub")
[index.js:319-323](https://github.com/ethereumjs/ethereumjs-util/blob/37971507cc9a5c9ad7c9bad59ecd7f2e4a7f0db1/index.js#L319-L323 "Source code on GitHub")

@@ -394,0 +422,0 @@ Returns the ethereum public key of a given private key

@@ -1,2 +0,2 @@

const SHA3 = require('sha3')
const SHA3 = require('keccakjs')
const secp256k1 = require('secp256k1')

@@ -249,3 +249,3 @@ const assert = require('assert')

var h = new SHA3.SHA3Hash(bytes)
var h = new SHA3(bytes)
if (a) {

@@ -297,13 +297,12 @@ h.update(a)

* Returns the ethereum address of a given public key.
* Accepts "Ethereum public keys" and DER encoded keys.
* Accepts "Ethereum public keys" and SEC1 encoded keys.
* @method publicToAddress
* @param {Buffer} pubKey
* @param {Buffer} pubKey The two points of an uncompressed key, unless sanitize is enabled
* @param {Boolean} sanitize Accept public keys in other formats
* @return {Buffer}
*/
exports.pubToAddress = exports.publicToAddress = function (pubKey) {
exports.pubToAddress = exports.publicToAddress = function (pubKey, sanitize) {
pubKey = exports.toBuffer(pubKey)
// Handle uncompressed DER keys
// FIXME: should we do this here?
if (pubKey.length === 65 && pubKey[0] === 4) {
pubKey = pubKey.slice(1)
if (sanitize && (pubKey.length !== 64)) {
pubKey = secp256k1.publicKeyConvert(pubKey, false).slice(1)
}

@@ -318,3 +317,3 @@ assert(pubKey.length === 64)

* @method privateToPublic
* @param {Buffer} privateKey
* @param {Buffer} privateKey A private key must be 256 bits wide
* @return {Buffer}

@@ -331,3 +330,3 @@ */

* @method privateToAddress
* @param {Buffer} privateKey
* @param {Buffer} privateKey A private key must be 256 bits wide
* @return {Buffer}

@@ -358,3 +357,4 @@ */

return exports.sha3(rlp.encode([from, nonce])).slice(12)
// Only take the lower 160bits of the hash
return exports.rlphash([from, nonce]).slice(-20)
}

@@ -505,3 +505,3 @@

* @param {Buffer|Array} ba
* @return {Array}
* @return {Array|String|null}
*/

@@ -530,1 +530,34 @@ exports.baToJSON = function (ba) {

}
/**
* ECDSA sign
* @method ecsign
* @param {Buffer} msgHash
* @param {Buffer} privateKey
* @return {Object}
*/
exports.ecsign = function (msgHash, privateKey) {
var sig = secp256k1.signSync(msgHash, privateKey)
var ret = {}
ret.r = sig.signature.slice(0, 32)
ret.s = sig.signature.slice(32, 64)
ret.v = sig.recovery + 27
return ret
}
/**
* ECDSA public key recovery from signature
* @method ecrecover
* @param {Buffer} msgHash
* @param {Buffer} v
* @param {Buffer} r
* @param {Buffer} s
* @return {Buffer} publicKey
*/
exports.ecrecover = function (msgHash, v, r, s) {
var signature = Buffer.concat([exports.pad(r, 32), exports.pad(s, 32)], 64)
var recovery = exports.bufferToInt(v) - 27
var senderPubKey = secp256k1.recoverSync(msgHash, signature, recovery)
return secp256k1.publicKeyConvert(senderPubKey, false).slice(1)
}
{
"name": "ethereumjs-util",
"version": "2.6.0",
"version": "3.0.0",
"description": "a collection of utility functions for Ethereum",

@@ -34,11 +34,7 @@ "main": "index.js",

"dependencies": {
"bn.js": "^4.6.2",
"browserify-sha3": "^0.0.1",
"bn.js": "^4.6.4",
"keccakjs": "^0.1.0",
"rlp": "^2.0.0",
"secp256k1": "^2.0.7",
"sha3": "^1.1.0"
"secp256k1": "^2.0.10"
},
"browser": {
"sha3": "browserify-sha3"
},
"testling": {

@@ -45,0 +41,0 @@ "browsers": [

@@ -14,2 +14,6 @@ var assert = require('assert')

}, {
name: 'cannotBeZero',
allowZero: false,
default: new Buffer([ 0 ])
}, {
name: 'value',

@@ -34,2 +38,13 @@ default: new Buffer([])

})
it('shouldn\'t allow wrong size for exact size requirements', function () {
assert.throws(function () {
const tmp = [{
name: 'mustBeExactSize',
allowZero: false,
length: 20,
default: new Buffer([1, 2, 3, 4])
}]
ethUtil.defineProperties(someOb, tmp)
})
})
})

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

describe('sha3-512', function () {
it('should produce a sha3', function () {
var msg = '0x3c9229289a6125f7fdf1885a77bb12c37a8d3b4962d936f7e3084dece32a3ca1'
var r = '36fdacd0339307068e9ed191773a6f11f6f9f99016bd50f87fd529ab7c87e1385f2b7ef1ac257cc78a12dcb3e5804254c6a7b404a6484966b831eadc721c3d24'
var hash = ethUtils.sha3(msg, 512)
assert.equal(hash.toString('hex'), r)
})
})
describe('sha256', function () {

@@ -173,3 +182,3 @@ it('should produce a sha256', function () {

describe('pubToAddress', function () {
describe('publicToAddress', function () {
it('should produce an address given a public key', function () {

@@ -179,17 +188,17 @@ var pubKey = '3a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a001cf066d56a8156fc201cd5df8a36ef694eecd258903fca7086c1fae7441e1d'

pubKey = new Buffer(pubKey, 'hex')
var r = ethUtils.pubToAddress(pubKey)
var r = ethUtils.publicToAddress(pubKey)
assert.equal(r.toString('hex'), address)
})
it('should produce an address given a DER public key', function () {
it('should produce an address given a SEC1 public key', function () {
var pubKey = '043a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a001cf066d56a8156fc201cd5df8a36ef694eecd258903fca7086c1fae7441e1d'
var address = '2f015c60e0be116b1f0cd534704db9c92118fb6a'
pubKey = new Buffer(pubKey, 'hex')
var r = ethUtils.pubToAddress(pubKey)
var r = ethUtils.publicToAddress(pubKey, true)
assert.equal(r.toString('hex'), address)
})
it('shouldn\'t produce an address given an invalid DER public key', function () {
it('shouldn\'t produce an address given an invalid SEC1 public key', function () {
var pubKey = '023a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a001cf066d56a8156fc201cd5df8a36ef694eecd258903fca7086c1fae7441e1d'
pubKey = new Buffer(pubKey, 'hex')
assert.throws(function () {
ethUtils.pubToAddress(pubKey)
ethUtils.publicToAddress(pubKey, true)
})

@@ -201,3 +210,3 @@ })

assert.throws(function () {
ethUtils.pubToAddress(pubKey)
ethUtils.publicToAddress(pubKey)
})

@@ -207,7 +216,7 @@ })

describe('pubToAddress 0x', function () {
describe('publicToAddress 0x', function () {
it('should produce an address given a public key', function () {
var pubKey = '0x3a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a001cf066d56a8156fc201cd5df8a36ef694eecd258903fca7086c1fae7441e1d'
var address = '2f015c60e0be116b1f0cd534704db9c92118fb6a'
var r = ethUtils.pubToAddress(pubKey)
var r = ethUtils.publicToAddress(pubKey)
assert.equal(r.toString('hex'), address)

@@ -323,2 +332,40 @@ })

})
it('should turn a buffers into string', function () {
assert.deepEqual(ethUtils.baToJSON(new Buffer([0])), '00')
})
})
var echash = new Buffer('82ff40c0a986c6a5cfad4ddf4c3aa6996f1a7837f9c398e17e5de5cbd5a12b28', 'hex')
var ecprivkey = new Buffer('3c9229289a6125f7fdf1885a77bb12c37a8d3b4962d936f7e3084dece32a3ca1', 'hex')
describe('ecsign', function () {
it('should produce a signature', function () {
var sig = ethUtils.ecsign(echash, ecprivkey)
assert.deepEqual(sig.r, new Buffer('99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9', 'hex'))
assert.deepEqual(sig.s, new Buffer('129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66', 'hex'))
assert.equal(sig.v, 27)
})
})
describe('ecrecover', function () {
it('should recover a public key', function () {
var r = new Buffer('99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9', 'hex')
var s = new Buffer('129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66', 'hex')
var pubkey = ethUtils.ecrecover(echash, 27, r, s)
assert.deepEqual(pubkey, ethUtils.privateToPublic(ecprivkey))
})
it('should fail on an invalid signature (v)', function () {
var r = new Buffer('99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9', 'hex')
var s = new Buffer('129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66', 'hex')
assert.throws(function () {
ethUtils.ecrecover(echash, 21, r, s)
})
})
it('should fail on an invalid signature (swapped points)', function () {
var r = new Buffer('99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9', 'hex')
var s = new Buffer('129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66', 'hex')
assert.throws(function () {
ethUtils.ecrecover(echash, 27, s, r)
})
})
})
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