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 0.0.5 to 0.0.6

62

index.js

@@ -203,11 +203,9 @@ const SHA3 = require('sha3'),

*/
exports.defineProperties = function(self, fields) {
exports.defineProperties = function(self, fields, data) {
self.raw = [];
self._fields = [];
fields.forEach(function(field, i) {
if (!field.name) {
field = {
name: field
};
}
self._fields.push(field.name);
Object.defineProperty(self, field.name, {

@@ -223,8 +221,14 @@ enumerable: true,

v = new Buffer(v, 'hex');
} else if (v !== null) {
} else if (typeof v === 'number') {
v = exports.intToBuffer(v);
} else if (v === null) {
v = new Buffer([]);
} else if (v.toBuffer) {
v = v.toBuffer();
} else {
throw new Error('invalid type');
}
}
if (field.length) {
if (!(field.empty && v.length === 0) && field.length) {
assert(field.length === v.length, 'The field ' + field.name + 'must have byte length of ' + field.length);

@@ -236,19 +240,27 @@ }

});
if(field.default){
self[field.name] = field.default;
}
});
};
/**
* Validate defined fields
* @method validate
* @param {Array} fields
* @param {Object} data
*/
exports.validate = function(fields, data) {
var i = 0;
fields.forEach(function(f) {
if (f.name && f.length) {
assert(data[i].length === f.length, 'invalid data for field: ' + f.name + ' needs length:' + f.length + 'got length: ' + data[i].length);
if (data) {
if (Buffer.isBuffer(data)) {
data = rlp.decode(data);
}
i++;
});
if (Array.isArray(data)) {
//make sure all the items are buffers
data.forEach(function(d, i) {
self[self._fields[i]] = typeof d === 'string' ? new Buffer(d, 'hex') : d;
});
} else {
for (var prop in data) {
if (self._fields.indexOf(prop) !== -1) {
self[prop] = data[prop];
}
}
}
}
};

@@ -325,3 +337,3 @@

var hex = this.toHex(str);
while (hex.length < pad * 2){
while (hex.length < pad * 2) {
hex += '00';

@@ -336,3 +348,3 @@ }

val = val.length > 2 ? val.substring(2) : '0';
return bignum(val, 16).toString(10);
return bignum(val, 16).toString(10);
};

@@ -339,0 +351,0 @@

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

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

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