web3-validator
Advanced tools
Comparing version 0.1.1-alpha.1 to 0.1.1-alpha.2
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.padLeft = exports.numberToHex = exports.hexToNumber = exports.codePointToInt = exports.transformJsonDataToAbiFormat = exports.fetchArrayElement = exports.ethAbiToJsonSchema = exports.abiSchemaToJsonSchema = exports.parseBaseType = void 0; | ||
const web3_errors_1 = require("web3-errors"); | ||
const constants_1 = require("./constants"); | ||
@@ -241,3 +242,5 @@ const abi_1 = require("./validation/abi"); | ||
if (typeof value === 'string' && (0, string_1.isHexStrict)(value)) { | ||
return (0, exports.numberToHex)((0, exports.hexToNumber)(value)); | ||
const [negative, hex] = value.startsWith('-') ? [true, value.slice(1)] : [false, value]; | ||
const hexValue = hex.split(/^(-)?0(x|X)/).slice(-1)[0]; | ||
return `${negative ? '-' : ''}0x${hexValue.replace(/^0+/, '').toLowerCase()}`; | ||
} | ||
@@ -247,3 +250,3 @@ if (typeof value === 'string' && !(0, string_1.isHexStrict)(value)) { | ||
} | ||
throw new Error('Invalid number value'); | ||
throw new web3_errors_1.InvalidNumberError(value); | ||
}; | ||
@@ -250,0 +253,0 @@ exports.numberToHex = numberToHex; |
@@ -6,7 +6,7 @@ "use strict"; | ||
exports.isString = isString; | ||
const isHexStrict = (hex) => typeof hex === 'string' && /^(-)?0x[0-9a-f]*$/i.test(hex); | ||
const isHexStrict = (hex) => typeof hex === 'string' && /^((-)?0x[0-9a-f]+|(0x))$/i.test(hex); | ||
exports.isHexStrict = isHexStrict; | ||
const isHex = (hex) => typeof hex === 'number' || | ||
typeof hex === 'bigint' || | ||
(typeof hex === 'string' && /^(-0x|0x)?[0-9a-f]*$/i.test(hex)); | ||
(typeof hex === 'string' && /^((-0x|0x|-)?[0-9a-f]+|(0x))$/i.test(hex)); | ||
exports.isHex = isHex; | ||
@@ -13,0 +13,0 @@ const isHexString8Bytes = (value, prefixed = true) => prefixed ? (0, exports.isHexStrict)(value) && value.length === 18 : (0, exports.isHex)(value) && value.length === 16; |
{ | ||
"name": "web3-validator", | ||
"version": "0.1.1-alpha.1", | ||
"version": "0.1.1-alpha.2", | ||
"description": "JSON-Schema compatible validator for web3", | ||
@@ -32,4 +32,4 @@ "main": "dist/index.js", | ||
"ethereum-cryptography": "^1.1.2", | ||
"web3-errors": "^0.1.1-alpha.1", | ||
"web3-types": "^0.1.1-alpha.1" | ||
"web3-errors": "^0.1.1-alpha.2", | ||
"web3-types": "^0.1.1-alpha.2" | ||
}, | ||
@@ -50,3 +50,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "a754e3a965c30f42a6e639df27462650062833ee" | ||
"gitHead": "7d5de3b049bf7929669c89e474387b16bd27c612" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
1117144
2050
1
Updatedweb3-errors@^0.1.1-alpha.2
Updatedweb3-types@^0.1.1-alpha.2