base58: fix missing exceptions
This commit is contained in:
parent
c9ad359520
commit
47ae862ae9
2 changed files with 7 additions and 2 deletions
|
@ -5,6 +5,7 @@
|
||||||
// Merged Buffer refactorings from base58-native by Stephen Pair
|
// Merged Buffer refactorings from base58-native by Stephen Pair
|
||||||
// Copyright (c) 2013 BitPay Inc
|
// Copyright (c) 2013 BitPay Inc
|
||||||
|
|
||||||
|
var assert = require('assert')
|
||||||
var BigInteger = require('bigi')
|
var BigInteger = require('bigi')
|
||||||
|
|
||||||
var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
||||||
|
@ -46,7 +47,11 @@ function decode(string) {
|
||||||
|
|
||||||
for (var i = 0; i < string.length; i++) {
|
for (var i = 0; i < string.length; i++) {
|
||||||
num = num.multiply(BASE)
|
num = num.multiply(BASE)
|
||||||
num = num.add(ALPHABET_MAP[string.charAt(i)])
|
|
||||||
|
var figure = ALPHABET_MAP[string.charAt(i)]
|
||||||
|
assert.notEqual(figure, undefined, 'Non-base58 character')
|
||||||
|
|
||||||
|
num = num.add(figure)
|
||||||
}
|
}
|
||||||
|
|
||||||
// deal with leading zeros
|
// deal with leading zeros
|
||||||
|
|
|
@ -18,7 +18,7 @@ describe('base58', function() {
|
||||||
it('throws on ' + f.description, function() {
|
it('throws on ' + f.description, function() {
|
||||||
assert.throws(function() {
|
assert.throws(function() {
|
||||||
base58.decode(f.string)
|
base58.decode(f.string)
|
||||||
})
|
}, /Non-base58 character/)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue