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

web3-utils

Package Overview
Dependencies
Maintainers
1
Versions
494
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

web3-utils - npm Package Compare versions

Comparing version 1.0.0-beta.22 to 1.0.0-beta.23

2

package.json
{
"name": "web3-utils",
"namespace": "ethereum",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "Collection of utility functions used in web3.js.",

@@ -6,0 +6,0 @@ "repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-utils",

@@ -117,3 +117,3 @@ /*

var hexToAscii = function(hex) {
if (!utils.isHex(hex))
if (!utils.isHexStrict(hex))
throw new Error('The parameter must be a valid HEX string.');

@@ -271,2 +271,3 @@

isHex: utils.isHex,
isHexStrict: utils.isHexStrict,
sha3: utils.sha3,

@@ -312,4 +313,5 @@ keccak256: utils.sha3,

padRight: utils.rightPad,
rightPad: utils.rightPad
rightPad: utils.rightPad,
toTwosComplement: utils.toTwosComplement
};

@@ -66,3 +66,3 @@ /*

if (type === 'string') {
if (utils.isHex(arg)) {
if (utils.isHexStrict(arg)) {
return new BN(arg.replace(/0x/i,''), 16);

@@ -69,0 +69,0 @@ } else {

@@ -70,2 +70,13 @@ /*

/**
* Takes and input transforms it into BN and if it is negative value, into two's complement
*
* @method toTwosComplement
* @param {Number|String|BN} number
* @return {String}
*/
var toTwosComplement = function (number) {
return '0x'+ toBN(number).toTwos(256).toString(16, 64);
};
/**
* Checks if the given string is an address

@@ -186,3 +197,3 @@ *

var hexToUtf8 = function(hex) {
if (!isHex(hex))
if (!isHexStrict(hex))
throw new Error('The parameter "'+ hex +'" must be a valid HEX string.');

@@ -292,3 +303,3 @@

if (!isHex(hex)) {
if (!isHexStrict(hex)) {
throw new Error('Given value "'+ hex +'" is not a valid hex string.');

@@ -346,2 +357,13 @@ }

/**
* Check if string is HEX, requires a 0x in front
*
* @method isHexStrict
* @param {String} hex to be checked
* @returns {Boolean}
*/
var isHexStrict = function (hex) {
return ((_.isString(hex) || _.isNumber(hex)) && /^(-)?0x[0-9a-f]*$/i.test(hex));
};
/**
* Check if string is HEX

@@ -354,3 +376,3 @@ *

var isHex = function (hex) {
return ((_.isString(hex) || _.isNumber(hex)) && /^(-)?0x[0-9a-f]*$/i.test(hex));
return ((_.isString(hex) || _.isNumber(hex)) && /^(-0x)?(0x)?[0-9a-f]*$/i.test(hex));
};

@@ -407,3 +429,3 @@

var sha3 = function (value) {
if (isHex(value) && /^0x/i.test((value).toString())) {
if (isHexStrict(value) && /^0x/i.test((value).toString())) {
value = hexToBytes(value);

@@ -442,5 +464,7 @@ }

isHex: isHex,
isHexStrict: isHexStrict,
leftPad: leftPad,
rightPad: rightPad,
toTwosComplement: toTwosComplement,
sha3: sha3
};
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