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

ethereumjs-util

Package Overview
Dependencies
Maintainers
1
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.3.2 to 2.4.0

14

index.js

@@ -175,3 +175,3 @@ const SHA3 = require('sha3')

exports.toUnsigned = function (num) {
if (num.cmpn(0) === -1) {
if (num.isNeg()) {
return new Buffer(num.add(exports.TWO_POW256).toArray())

@@ -230,2 +230,12 @@ }

/**
* Creates SHA-3 hash of the RLP encoded version of the input
* @method rlphash
* @param {Buffer|Array|String|Number} a the input data
* @return {Buffer}
*/
exports.rlphash = function (a) {
return exports.sha3(rlp.encode(a))
}
/**
* Returns the ethereum address of a given public key

@@ -350,3 +360,3 @@ * @method pubToAddress

} else if (!(field.allowZero && v.length === 0) && field.length) {
assert(field.length === v.length, 'The field ' + field.name + 'must have byte length of ' + field.length)
assert(field.length === v.length, 'The field ' + field.name + ' must have byte length of ' + field.length)
}

@@ -353,0 +363,0 @@

2

package.json
{
"name": "ethereumjs-util",
"version": "2.3.2",
"version": "2.4.0",
"description": "a collection of utility functions for Ethereum",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -20,3 +20,2 @@ # SYNOPSIS

- `SHA3_RLP` - SHA3-256 hash of the RLP of `null`
- `ETH_UNITS` - an array of ethereum units
- [`BN`](https://github.com/indutny/bn.js)

@@ -151,2 +150,9 @@ - [`rlp`](https://github.com/wanderer/rlp)

### `rlphash(a)`
Returns a sha3 of the RLP encoded version of `a`
**Parameters**
- `a` - the value to encode and hash
**Return:** `Buffer`
### `printBA(ba)`

@@ -153,0 +159,0 @@ Print a Buffer Array

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

describe('rlphash', function () {
it('should produce a sha3 of the rlp data', function () {
var msg = '0x3c9229289a6125f7fdf1885a77bb12c37a8d3b4962d936f7e3084dece32a3ca1'
var r = '33f491f24abdbdbf175e812b94e7ede338d1c7f01efb68574acd279a15a39cbe'
var hash = ethUtils.rlphash(msg)
assert.equal(hash.toString('hex'), r)
})
})
describe('unpad', function () {

@@ -114,3 +123,3 @@ it('should unpad a string', function () {

describe('fromSigned', function () {
it('should converts an unsigned buffer to a singed number', function () {
it('should convert an unsigned (negative) buffer to a singed number', function () {
var neg = '-452312848583266388373324160190187140051835877600158453279131187530910662656'

@@ -123,6 +132,14 @@ var buf = new Buffer(32)

})
it('should convert an unsigned (positive) buffer to a singed number', function () {
var neg = '452312848583266388373324160190187140051835877600158453279131187530910662656'
var buf = new Buffer(32)
buf.fill(0)
buf[0] = 1
assert.equal(ethUtils.fromSigned(buf), neg)
})
})
describe('toUnsigned', function () {
it('should convert a signed number to unsigned', function () {
it('should convert a signed (negative) number to unsigned', function () {
var neg = '-452312848583266388373324160190187140051835877600158453279131187530910662656'

@@ -134,2 +151,10 @@ var hex = 'ff00000000000000000000000000000000000000000000000000000000000000'

})
it('should convert a signed (positive) number to unsigned', function () {
var neg = '452312848583266388373324160190187140051835877600158453279131187530910662656'
var hex = '0100000000000000000000000000000000000000000000000000000000000000'
var num = new BN(neg)
assert.equal(ethUtils.toUnsigned(num).toString('hex'), hex)
})
})

@@ -136,0 +161,0 @@

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