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

bs58

Package Overview
Dependencies
Maintainers
4
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bs58 - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

13

CHANGELOG.md

@@ -0,1 +1,6 @@

1.1.0 / 2014-06-26
------------------
* user `Buffer` internally for calculations, providing cleaner code and a performance increase. [Daniel Cousens](https://github.com/cryptocoinjs/bs58/commit/129c71de8bc1e36f113bce06da0616066f41c5ca)
1.0.0 / 2014-05-27

@@ -7,3 +12,5 @@ ------------------

* added coveralls support
* modified tests and library to handle fixture style testing (thanks to bitcoinjs-lib devs and [Daniel Cousens](https://github.com/dcousens))
0.3.0 / 2014-02-24

@@ -13,2 +20,3 @@ ------------------

0.2.1 / 2014-02-24

@@ -19,2 +27,3 @@ ------------------

0.2.0 / 2013-12-07

@@ -24,2 +33,3 @@ ------------------

0.1.0 / 2013-11-20

@@ -29,4 +39,5 @@ ------------------

0.0.1 / 2013-11-04
------------------
* initial release
* initial release

90

lib/bs58.js

@@ -1,27 +0,27 @@

var BigInteger = require('bigi');
// Base58 encoding/decoding
// Originally written by Mike Hearn for BitcoinJ
// Copyright (c) 2011 Google Inc
// Ported to JavaScript by Stefan Thomas
// Merged Buffer refactorings from base58-native by Stephen Pair
// Copyright (c) 2013 BitPay Inc
'use strict'
var assert = require('assert')
var BigInteger = require('bigi')
module.exports.decode = decode;
module.exports.encode = encode;
var ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
var ALPHABET_BUF = new Buffer(ALPHABET)
var LOOKUP = {};
for (var i=0 ; i < ALPHABET.length ; ++i) {
LOOKUP[ALPHABET[i]] = i;
var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
var ALPHABET_BUF = new Buffer(ALPHABET, 'ascii')
var ALPHABET_MAP = {}
for(var i = 0; i < ALPHABET.length; i++) {
ALPHABET_MAP[ALPHABET.charAt(i)] = BigInteger.valueOf(i)
}
var BASE = new BigInteger('58')
var BASE = 58;
var base = BigInteger.valueOf(BASE);
function encode(buffer) {
var bi = BigInteger.fromBuffer(buffer)
var result = new Buffer(buffer.length << 1)
function encode (input) {
var bi = BigInteger.fromBuffer(input)
var result = new Buffer(input.length << 1)
var i = result.length - 1
while (bi.compareTo(BigInteger.ZERO) > 0) {
var remainder = bi.mod(base)
bi = bi.divide(base)
while (bi.signum() > 0) {
var remainder = bi.mod(BASE)
bi = bi.divide(BASE)

@@ -34,3 +34,3 @@ result[i] = ALPHABET_BUF[remainder.intValue()]

var j = 0
while (input[j] === 0) {
while (buffer[j] === 0) {
result[i] = ALPHABET_BUF[0]

@@ -41,37 +41,35 @@ j++

return result.slice(i + 1, result.length).toString()
return result.slice(i + 1, result.length).toString('ascii')
}
function decode(string) {
if (string.length === 0) return new Buffer(0)
function decode (input) {
var num = BigInteger.valueOf(0);
var leadingZero = 0;
var seenOther = false;
for (var i = 0; i < input.length ; ++i) {
var ch = input[i];
var p = LOOKUP[ch];
var num = BigInteger.ZERO
// if we encounter an invalid character, decoding fails
if (p === undefined) {
throw new Error('invalid base58 string: ' + input);
}
for (var i = 0; i < string.length; i++) {
num = num.multiply(BASE)
num = num.multiply(base).add(BigInteger.valueOf(p));
var figure = ALPHABET_MAP[string.charAt(i)]
assert.notEqual(figure, undefined, 'Non-base58 character')
if (ch == ALPHABET[0] && !seenOther) {
++leadingZero;
}
else {
seenOther = true;
}
num = num.add(figure)
}
var bytes = num.toByteArrayUnsigned();
// remove leading zeros
while (leadingZero-- > 0) {
bytes.unshift(0);
// deal with leading zeros
var j = 0
while ((j < string.length) && (string[j] === ALPHABET[0])) {
j++
}
return new Buffer(bytes);
var buffer = num.toBuffer()
var leadingZeros = new Buffer(j)
leadingZeros.fill(0)
return Buffer.concat([leadingZeros, buffer])
}
module.exports = {
encode: encode,
decode: decode
}
{
"name": "bs58",
"version": "1.0.0",
"version": "1.1.0",
"description": "Base 58 encoding / decoding",
"keywords": [
"base58",
"bitcoin",
"crypto",
"crytography",
"crypto",
"bitcoin",
"base58",
"encoding",
"decode",
"decoding",
"encode",
"decode",
"encoding",
"litecoin"
],
"devDependencies": {
"coveralls": "^2.10.0",
"istanbul": "^0.2.10",
"jshint": "2.5.1",
"mocha": "^1.19.0",
"terst": "^0.1.0",
"mochify": "~0.4.2",
"coveralls": "^2.10.0",
"mocha-lcov-reporter": "0.0.1",
"istanbul": "^0.2.10"
"mochify": "~0.4.2"
},

@@ -33,6 +33,8 @@ "repository": {

"scripts": {
"unit": "./node_modules/.bin/mocha",
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --reporter list test/*.js",
"coveralls": "npm run-script coverage && node ./node_modules/.bin/coveralls < coverage/lcov.info"
"coveralls": "npm run-script coverage && node ./node_modules/.bin/coveralls < coverage/lcov.info",
"jshint": "./node_modules/.bin/jshint --config jshint.json lib/*.js ; true",
"test": "npm run-script unit",
"unit": "./node_modules/.bin/mocha"
}
}
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