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

@darkwolf/base58

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@darkwolf/base58 - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

87

index.js

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

const { validator, errors } = require('./utils')
const { validator, Base58Error } = require('./utils')
const { Validator } = validator

@@ -6,11 +6,16 @@

constructor(alphabet) {
if (validator.isExists(alphabet)) new Validator(alphabet)
new Validator(alphabet)
.isOptional()
.isString()
.throw(() => errors.INVALID_ALPHABET
.setType('invalid-argument-type')
.setMessage('"alphabet" argument must be a string'))
.throw(() => new Base58Error({
code: 'invalid-alphabet',
type: 'invalid-argument-type',
message: '"alphabet" argument must be a string'
}))
.isAlphabet()
.throw(() => errors.INVALID_ALPHABET
.setType('invalid-argument-value')
.setMessage('"alphabet" argument has the wrong format'))
.throw(() => new Base58Error({
code: 'invalid-alphabet',
type: 'invalid-argument-value',
message: '"alphabet" argument has the wrong format'
}))

@@ -29,14 +34,20 @@ this.DARKWOLF_ALPHABET = 'AveDarkwo1f23456789BCEFGHJKLMNPQRSTUVWXYZbcdghijmnpqstuxyz'

new Validator(alphabet)
.isExists()
.throw(() => errors.INVALID_ALPHABET
.setType('argument-required')
.setMessage('"alphabet" argument is required'))
.isRequired()
.throw(() => new Base58Error({
code: 'invalid-alphabet',
type: 'argument-required',
message: '"alphabet" argument is required'
}))
.isString()
.throw(() => errors.INVALID_ALPHABET
.setType('invalid-argument-type')
.setMessage('"alphabet" argument must be a string'))
.throw(() => new Base58Error({
code: 'invalid-alphabet',
type: 'invalid-argument-type',
message: '"alphabet" argument must be a string'
}))
.isAlphabet()
.throw(() => errors.INVALID_ALPHABET
.setType('invalid-argument-value')
.setMessage('"alphabet" argument has the wrong format'))
.throw(() => new Base58Error({
code: 'invalid-alphabet',
type: 'invalid-argument-value',
message: '"alphabet" argument has the wrong format'
}))
this.alphabet = alphabet

@@ -48,6 +59,8 @@ return this

new Validator(input)
.isExists()
.throw(() => errors.INVALID_INPUT
.setType('argument-required')
.setMessage('"input" argument is required'))
.isRequired()
.throw(() => new Base58Error({
code: 'invalid-input',
type: 'argument-required',
message: '"input" argument is required'
}))
let buffer

@@ -59,9 +72,10 @@ if (validator.isString(input)) {

} else {
throw errors.INVALID_INPUT
.setType('invalid-argument-type')
.setMessage('"input" argument must be a string or a buffer')
throw new Base58Error({
code: 'invalid-input',
type: 'invalid-argument-type',
message: '"input" argument must be a string or a buffer'
})
}
return buffer.reduce((bytes, carry, i) => {
if (!(carry || bytes.length ^ i)) bytes.push(1)
let j = 0

@@ -75,3 +89,2 @@ while (j in bytes || carry) {

}
return bytes

@@ -83,6 +96,8 @@ }, []).reverse().map(o => this.alphabet[o]).join('')

new Validator(input)
.isExists()
.throw(() => errors.INVALID_INPUT
.setType('argument-required')
.setMessage('"input" argument is required'))
.isRequired()
.throw(() => new Base58Error({
code: 'invalid-input',
type: 'argument-required',
message: '"input" argument is required'
}))
let string

@@ -94,9 +109,10 @@ if (validator.isString(input)) {

} else {
throw errors.INVALID_INPUT
.setType('invalid-argument-type')
.setMessage('"input" argument must be a string or a buffer')
throw new Base58Error({
code: 'invalid-input',
type: 'invalid-argument-type',
message: '"input" argument must be a string or a buffer'
})
}
return String.fromCharCode(...string.split('').map(o => this.alphabet.indexOf(o)).reduce((bytes, carry, i) => {
if (!(carry || bytes.length ^ i)) bytes.push(0)
let j = 0

@@ -110,3 +126,2 @@ while (j in bytes || carry) {

}
return bytes

@@ -113,0 +128,0 @@ }, []).reverse())

{
"name": "@darkwolf/base58",
"version": "1.0.7",
"version": "1.0.8",
"description": "Base58 Encoder/Decoder Utility",

@@ -27,5 +27,5 @@ "main": "index.js",

"dependencies": {
"@darkwolf/code-error": "^2.0.8",
"@darkwolf/validator": "^2.0.3"
"@darkwolf/code-error": "^2.0.9",
"@darkwolf/validator": "^2.0.8"
}
}

@@ -5,18 +5,4 @@ const CodeError = require('@darkwolf/code-error')

constructor(...args) {
const options = {
namespace: 'base58'
}
if (args.length > 2) {
const [code, type, message] = args
options.code = code
options.type = type
options.message = message
} else {
const [code, message] = args
options.code = code
options.message = message
}
super(options)
super(...args)
this.namespace = 'base58'
}

@@ -23,0 +9,0 @@ }

const Base58Error = require('./Base58Error')
const validator = require('./validator')
const errors = require('./errors')
module.exports = {
Base58Error,
validator,
errors
validator
}

@@ -13,3 +13,3 @@ const { Validator } = require('@darkwolf/Validator')

_isAlphabet(value) {
return value.length === 58 && /^[AveDarkwo1f23456789BCEFGHJKLMNPQRSTUVWXYZbcdghijmnpqstuxyz]{58}$/.test([...new Set(value)].join(''))
return this._isLength(value, 58) && /^[AveDarkwo1f23456789BCEFGHJKLMNPQRSTUVWXYZbcdghijmnpqstuxyz]{58}$/.test([...new Set(value)].join(''))
}

@@ -16,0 +16,0 @@

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