Socket
Socket
Sign inDemoInstall

@arcblock/forge-util

Package Overview
Dependencies
Maintainers
4
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arcblock/forge-util - npm Package Compare versions

Comparing version 1.5.7 to 1.5.8

51

lib/index.js

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

/* eslint-disable max-len */
/* eslint-disable no-bitwise */

@@ -20,3 +21,2 @@ /* eslint-disable implicit-arrow-linebreak */

const isNull = require('lodash/isNull');
const numberToBN = require('number-to-bn');
const multibase = require('multibase');

@@ -32,2 +32,46 @@ const utf8 = require('utf8');

/**
* Returns a BN object, converts a number value to a BN
* @param {String|Number|Object} `arg` input a string number, hex string number, number, BigNumber or BN object
* @return {Object} `output` BN object of the number
* @throws if the argument is not an array, object that isn't a bignumber, not a string number or number
*/
const numberToBN = arg => {
if (typeof arg === 'string' || typeof arg === 'number') {
let multiplier = new BN(1); // eslint-disable-line
const formattedString = String(arg)
.toLowerCase()
.trim();
const isHexPrefixed = formattedString.substr(0, 2) === '0x' || formattedString.substr(0, 3) === '-0x';
let stringArg = stripHexPrefix(formattedString); // eslint-disable-line
if (stringArg.substr(0, 1) === '-') {
stringArg = stripHexPrefix(stringArg.slice(1));
multiplier = new BN(-1, 10);
}
stringArg = stringArg === '' ? '0' : stringArg;
if (
(!stringArg.match(/^-?[0-9]+$/) && stringArg.match(/^[0-9A-Fa-f]+$/)) ||
stringArg.match(/^[a-fA-F]+$/) ||
(isHexPrefixed === true && stringArg.match(/^[0-9A-Fa-f]+$/))
) {
return new BN(stringArg, 16).mul(multiplier);
}
if ((stringArg.match(/^-?[0-9]+$/) || stringArg === '') && isHexPrefixed === false) {
return new BN(stringArg, 10).mul(multiplier);
}
} else if (typeof arg === 'object' && arg.toString && !arg.pop && !arg.push) {
if (arg.toString(10).match(/^-?[0-9]+$/) && (arg.mul || arg.dividedToIntegerBy)) {
return new BN(arg.toString(10), 10);
}
}
throw new Error(
`[number-to-bn] while converting number ${JSON.stringify(
arg
)} to BN.js instance, error: invalid number value. Value must be an integer, hex string, BN or BigNumber instance. Note, decimals are not supported.`
);
};
/**
* Returns a `boolean` on whether or not the `string` starts with '0x'

@@ -567,3 +611,4 @@ *

function toBase58(v) {
return multibase.encode('base58btc', toBuffer(v)).toString();
const buf = multibase.encode('base58btc', toUint8Array(v));
return Buffer.from(buf).toString('utf-8');
}

@@ -584,3 +629,3 @@

return multibase.decode(v);
return Buffer.from(multibase.decode(v));
}

@@ -587,0 +632,0 @@

15

package.json
{
"name": "@arcblock/forge-util",
"version": "1.5.7",
"version": "1.5.8",
"description": "utils shared across mutlipe forge js libs, works in both node.js and browser",

@@ -16,9 +16,12 @@ "keywords": [

"dependencies": {
"base64-url": "^2.3.2",
"bn.js": "4.11.6",
"base64-url": "^2.3.3",
"bn.js": "5.1.3",
"lodash": "^4.17.20",
"multibase": "^0.6.0",
"number-to-bn": "^1.7.0",
"multibase": "^3.1.1",
"utf8": "^3.0.0"
},
"resolutions": {
"bn.js": "5.1.3",
"elliptic": "6.5.3"
},
"devDependencies": {

@@ -59,3 +62,3 @@ "jest": "^24.8.0",

},
"gitHead": "c3b531936730cbee0d9a0f4e7ccd5ed917a7f4cf"
"gitHead": "b494b9123023e94ff3faf9a05f1f9c2ae62c82cc"
}
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