@darkwolf/base58
Advanced tools
Comparing version 13.21.71 to 13.21.72
10
index.js
@@ -6,6 +6,6 @@ const constants = require('./constants') | ||
function base58(alphabet) { | ||
if (!validator.isString(alphabet) || !validator.isAlphabet(alphabet)) throw new Base58Error('invalid-alphabet', `"alphabet" argument must be a non-empty alphabetical string consisting of characters in the range: [${constants.BITCOIN_ALPHABET}]`) | ||
if (!(validator.isNonEmptyString(alphabet) && validator.isAlphabet(alphabet))) throw new Base58Error('invalid-alphabet', `"alphabet" argument must be a non-empty alphabetical string consisting of characters in the range: [${constants.BITCOIN_ALPHABET}]`) | ||
function encode(input) { | ||
if (!validator.isString(input) || !validator.isASCII(input)) throw new Base58Error('invalid-input', '"input" argument must be a non-empty ASCII encoded string') | ||
if (!(validator.isNonEmptyString(input) && validator.isASCII(input))) throw new Base58Error('invalid-input', '"input" argument must be a non-empty ASCII encoded string') | ||
return Buffer.from(input).reduce((bytes, carry, i) => { | ||
@@ -25,3 +25,3 @@ if (!(carry || bytes.length ^ i)) bytes.push(1) | ||
function decode(input) { | ||
if (!validator.isString(input) || !validator.isBase58(input)) throw new Base58Error('invalid-input', '"input" argument must be a non-empty Base58 encoded string') | ||
if (!(validator.isNonEmptyString(input) && validator.isBase58(input))) throw new Base58Error('invalid-input', '"input" argument must be a non-empty Base58 encoded string') | ||
return String.fromCharCode(...input.split('').map(o => alphabet.indexOf(o)).reduce((bytes, carry, i) => { | ||
@@ -41,3 +41,3 @@ if (!(carry || bytes.length ^ i)) bytes.push(0) | ||
function encodeInt(input) { | ||
if (!validator.isSafeInteger(input) || !validator.isNonNegative(input)) throw new Base58Error('invalid-input', '"input" argument must be a non-negative safe integer') | ||
if (!(validator.isSafeInteger(input) && validator.isNonNegative(input))) throw new Base58Error('invalid-input', '"input" argument must be a non-negative safe integer') | ||
let int = input | ||
@@ -55,3 +55,3 @@ let str = '' | ||
function decodeInt(input) { | ||
if (!validator.isString(input) || !validator.isBase58(input)) throw new Base58Error('invalid-input', '"input" argument must be a non-empty Base58 encoded string') | ||
if (!(validator.isNonEmptyString(input) && validator.isBase58(input))) throw new Base58Error('invalid-input', '"input" argument must be a non-empty Base58 encoded string') | ||
return input.split('').reverse().reduce((int, char, i) => int + alphabet.indexOf(char) * Math.pow(58, i), 0) | ||
@@ -58,0 +58,0 @@ } |
{ | ||
"name": "@darkwolf/base58", | ||
"version": "13.21.71", | ||
"version": "13.21.72", | ||
"description": "Base58", | ||
@@ -26,4 +26,4 @@ "main": "index.js", | ||
"@darkwolf/code-error": "^13.21.69", | ||
"@darkwolf/validator": "^13.21.69" | ||
"@darkwolf/validator": "^13.21.70" | ||
} | ||
} |
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
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
6242