web3-utils
Advanced tools
Comparing version 1.2.11 to 1.3.0-rc.0
{ | ||
"name": "web3-utils", | ||
"version": "1.2.11", | ||
"version": "1.3.0-rc.0", | ||
"description": "Collection of utility functions used in web3.js.", | ||
@@ -12,5 +12,6 @@ "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-utils", | ||
"scripts": { | ||
"tsc": "tsc -b tsconfig.json", | ||
"dtslint": "dtslint --localTs ../../node_modules/typescript/lib types" | ||
}, | ||
"main": "src/index.js", | ||
"main": "lib/index.js", | ||
"dependencies": { | ||
@@ -30,3 +31,3 @@ "bn.js": "^4.11.9", | ||
}, | ||
"gitHead": "87e668275ac7d9b8af7c909137fc0626c3866929" | ||
"gitHead": "83c9f65c7cb3b4f4532f890ec5a3608fd1879e35" | ||
} |
@@ -30,5 +30,5 @@ /* | ||
var randombytes = require('randombytes'); | ||
var BN = require('bn.js'); | ||
/** | ||
@@ -310,3 +310,3 @@ * Fires an error in an event emitter and callback and returns the eventemitter | ||
for (var i = 0; i < address.length; i++ ) { | ||
// If ith character is 9 to f then make it uppercase | ||
// If ith character is 8 to f then make it uppercase | ||
if (parseInt(addressHash[i], 16) > 7) { | ||
@@ -321,2 +321,58 @@ checksumAddress += address[i].toUpperCase(); | ||
/** | ||
* Returns -1 if a<b, 1 if a>b; 0 if a == b. | ||
* For more details on this type of function, see | ||
* developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort | ||
* | ||
* @method compareBlockNumbers | ||
* | ||
* @param {String|Number|BN} a | ||
* | ||
* @param {String|Number|BN} b | ||
* | ||
* @returns {Number} -1, 0, or 1 | ||
*/ | ||
var compareBlockNumbers = function(a, b) { | ||
if (a == b) { | ||
return 0; | ||
} else if (("genesis" == a || "earliest" == a || 0 == a) && ("genesis" == b || "earliest" == b || 0 == b)) { | ||
return 0; | ||
} else if ("genesis" == a || "earliest" == a) { | ||
// b !== a, thus a < b | ||
return -1; | ||
} else if ("genesis" == b || "earliest" == b) { | ||
// b !== a, thus a > b | ||
return 1; | ||
} else if (a == "latest") { | ||
if (b == "pending") { | ||
return -1; | ||
} else { | ||
// b !== ("pending" OR "latest"), thus a > b | ||
return 1; | ||
} | ||
} else if (b === "latest") { | ||
if (a == "pending") { | ||
return 1; | ||
} else { | ||
// b !== ("pending" OR "latest"), thus a > b | ||
return -1 | ||
} | ||
} else if (a == "pending") { | ||
// b (== OR <) "latest", thus a > b | ||
return 1; | ||
} else if (b == "pending") { | ||
return -1; | ||
} else { | ||
let bnA = new BN(a); | ||
let bnB = new BN(b); | ||
if(bnA.lt(bnB)) { | ||
return -1; | ||
} else if(bnA.eq(bnB)) { | ||
return 0; | ||
} else { | ||
return 1; | ||
} | ||
} | ||
}; | ||
module.exports = { | ||
@@ -340,2 +396,3 @@ _fireError: _fireError, | ||
soliditySha3Raw: soliditySha3.soliditySha3Raw, | ||
encodePacked: soliditySha3.encodePacked, | ||
isAddress: utils.isAddress, | ||
@@ -386,3 +443,5 @@ checkAddressChecksum: utils.checkAddressChecksum, | ||
isTopicInBloom: utils.isTopicInBloom, | ||
isInBloom: utils.isInBloom | ||
isInBloom: utils.isInBloom, | ||
compareBlockNumbers: compareBlockNumbers | ||
}; |
@@ -172,3 +172,3 @@ /* | ||
var _processSoliditySha3Args = function (arg) { | ||
var _processSolidityEncodePackedArgs = function (arg) { | ||
/*jshint maxcomplexity:false */ | ||
@@ -237,3 +237,3 @@ | ||
var hexArgs = _.map(args, _processSoliditySha3Args); | ||
var hexArgs = _.map(args, _processSolidityEncodePackedArgs); | ||
@@ -253,9 +253,26 @@ // console.log(args, hexArgs); | ||
var soliditySha3Raw = function () { | ||
return utils.sha3Raw('0x'+ _.map(Array.prototype.slice.call(arguments), _processSoliditySha3Args).join('')); | ||
return utils.sha3Raw('0x'+ _.map(Array.prototype.slice.call(arguments), _processSolidityEncodePackedArgs).join('')); | ||
}; | ||
/** | ||
* Encode packed args to hex | ||
* | ||
* @method encodePacked | ||
* @return {String} the hex encoded arguments | ||
*/ | ||
var encodePacked = function () { | ||
/*jshint maxcomplexity:false */ | ||
var args = Array.prototype.slice.call(arguments); | ||
var hexArgs = _.map(args, _processSolidityEncodePackedArgs); | ||
return '0x'+ hexArgs.join('').toLowerCase(); | ||
}; | ||
module.exports = { | ||
soliditySha3: soliditySha3, | ||
soliditySha3Raw: soliditySha3Raw | ||
soliditySha3Raw: soliditySha3Raw, | ||
encodePacked: encodePacked | ||
}; |
@@ -118,2 +118,3 @@ /* | ||
export function soliditySha3Raw(...val: Mixed[]): string; | ||
export function encodePacked(...val: Mixed[]): string | null; | ||
export function getUnitValue(unit: Unit): string; | ||
@@ -174,2 +175,3 @@ export function unitMap(): Units; | ||
soliditySha3Raw(...val: Mixed[]): string; | ||
encodePacked(...val: Mixed[]): string | null; | ||
getUnitValue(unit: Unit): string; | ||
@@ -176,0 +178,0 @@ unitMap(): Units; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
161026
67
4715
2
1