Skip to content

Commit

Permalink
Merge pull request #9 from cryptocoinjs/nobrows
Browse files Browse the repository at this point in the history
No browserify requirement
  • Loading branch information
jprichardson committed Oct 3, 2014
2 parents 004c261 + 6966e4f commit a873b19
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
8 changes: 3 additions & 5 deletions lib/bs58.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// Merged Buffer refactorings from base58-native by Stephen Pair
// Copyright (c) 2013 BitPay Inc

var assert = require('assert')

var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
var ALPHABET_MAP = {}
for(var i = 0; i < ALPHABET.length; i++) {
Expand Down Expand Up @@ -45,12 +43,12 @@ function encode(buffer) {
}

function decode(string) {
if (string.length === 0) return new Buffer(0)
if (string.length === 0) return []

var i, j, bytes = [0]
for (i = 0; i < string.length; i++) {
var c = string[i]
assert(c in ALPHABET_MAP, 'Non-base58 character')
if (!(c in ALPHABET_MAP)) throw new Error('Non-base58 character')

for (j = 0; j < bytes.length; j++) bytes[j] *= BASE
bytes[0] += ALPHABET_MAP[c]
Expand All @@ -73,7 +71,7 @@ function decode(string) {
// deal with leading zeros
for (i = 0; string[i] === '1' && i < string.length - 1; i++) bytes.push(0)

return new Buffer(bytes.reverse())
return bytes.reverse()
}

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"litecoin"
],
"devDependencies": {
"coveralls": "^2.10.0",
"coveralls": "^2.11.2",
"istanbul": "^0.2.10",
"jshint": "2.5.1",
"mocha": "^1.19.0",
"mocha": "^1.21.4",
"mocha-lcov-reporter": "0.0.1",
"mochify": "~0.4.2"
},
Expand Down
2 changes: 1 addition & 1 deletion test/bs58.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('base58', function() {
describe('decode', function() {
fixtures.valid.forEach(function(f) {
it('can decode ' + f.string, function() {
var actual = base58.decode(f.string).toString('hex')
var actual = new Buffer(base58.decode(f.string)).toString('hex')

assert.strictEqual(actual, f.hex)
})
Expand Down

0 comments on commit a873b19

Please sign in to comment.