@darkwolf/base58
Advanced tools
Comparing version 1.0.2 to 1.0.3
50
index.js
class Base58 { | ||
constructor(alphabet) { | ||
this.alphabet = alphabet || 'AveDarkwo1f23456789BCEFGHJKLMNPQRSTUVWXYZbcdghijmnpqstuxyz' | ||
this.DARKWOLF_ALPHABET = 'AveDarkwo1f23456789BCEFGHJKLMNPQRSTUVWXYZbcdghijmnpqstuxyz' | ||
this.BITCOIN_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' | ||
this.RIPPLE_ALPHABET = 'rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz' | ||
this.alphabet = alphabet || this.DARKWOLF_ALPHABET | ||
this.Base58 = Base58 | ||
} | ||
encode(string) { | ||
return string.split('').map(o => o.charCodeAt()).reduce((d, c, i) => { | ||
encode(input) { | ||
const buffer = Buffer.isBuffer(input) ? input : Buffer.from(input) | ||
return buffer.reduce((bytes, carry, i) => { | ||
if (!(carry || bytes.length ^ i)) bytes.push(1) | ||
let j = 0 | ||
let n | ||
if (!(c || d.length ^ i)) d.push(1) | ||
while (j in d || c) { | ||
n = d[j] | ||
n = n ? n * 256 + c : c | ||
c = n / 58 | 0 | ||
d[j] = n % 58 | ||
while (j in bytes || carry) { | ||
let byte = bytes[j] | ||
byte = byte ? byte * 256 + carry : carry | ||
bytes[j] = byte % 58 | ||
carry = byte / 58 | 0 | ||
j++ | ||
} | ||
return d | ||
return bytes | ||
}, []).reverse().map(o => this.alphabet[o]).join('') | ||
} | ||
decode(string) { | ||
return String.fromCharCode(...string.split('').map(o => this.alphabet.indexOf(o)).reduce((d, c, i) => { | ||
decode(input) { | ||
const string = Buffer.isBuffer(input) ? input.toString() : input | ||
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 | ||
let n | ||
if (!(c || d.length ^ i)) d.push(0) | ||
while (j in d || c) { | ||
n = d[j] | ||
n = n ? n * 58 + c : c | ||
c = n >> 8 | ||
d[j] = n % 256 | ||
while (j in bytes || carry) { | ||
let byte = bytes[j] | ||
byte = byte ? byte * 58 + carry : carry | ||
bytes[j] = byte % 256 | ||
carry = byte >> 8 | ||
j++ | ||
} | ||
return d | ||
return bytes | ||
}, []).reverse()) | ||
@@ -37,0 +45,0 @@ } |
{ | ||
"name": "@darkwolf/base58", | ||
"version": "1.0.2", | ||
"description": "Base58", | ||
"version": "1.0.3", | ||
"description": "Base58 Encoder/Decoder", | ||
"main": "index.js", | ||
@@ -14,3 +14,5 @@ "scripts": { | ||
"keywords": [ | ||
"base58" | ||
"base58", | ||
"encoder", | ||
"decoder" | ||
], | ||
@@ -17,0 +19,0 @@ "author": "Pavel Wolf", |
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
3704
5
40
1
25