base58check: buffers only, remove explicit 0
Undefined is treated as zero if it ever gets to this point anyway, so no value is added by having this default param here. A test fixture to verify this behaviour is added.
This commit is contained in:
parent
77ed66b24d
commit
2b2081bed9
3 changed files with 9 additions and 8 deletions
|
@ -4,13 +4,8 @@ var base58 = require('./base58')
|
|||
var crypto = require('./crypto')
|
||||
|
||||
// Encode a buffer as a base58-check-encoded string
|
||||
function encode(buffer, version) {
|
||||
version = version || 0
|
||||
|
||||
// FIXME: `new Buffer(buffer)` is unnecessary if input is a Buffer
|
||||
function encode(payload, version) {
|
||||
var version = new Buffer([version])
|
||||
var payload = new Buffer(buffer)
|
||||
|
||||
var message = Buffer.concat([version, payload])
|
||||
var checksum = crypto.hash256(message).slice(0, 4)
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ describe('base58check', function() {
|
|||
it('can decode ' + f.string, function() {
|
||||
var actual = base58check.decode(f.string)
|
||||
var expected = {
|
||||
version: f.decode.version,
|
||||
version: f.decode.version || 0,
|
||||
payload: h2b(f.decode.payload),
|
||||
checksum: h2b(f.decode.checksum)
|
||||
}
|
||||
|
@ -40,4 +40,3 @@ describe('base58check', function() {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
|
7
test/fixtures/base58check.json
vendored
7
test/fixtures/base58check.json
vendored
|
@ -1,5 +1,12 @@
|
|||
{
|
||||
"valid": [
|
||||
{
|
||||
"string": "1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i",
|
||||
"decode": {
|
||||
"payload": "65a16059864a2fdbc7c99a4723a8395bc6f188eb",
|
||||
"checksum": "c046b2ff"
|
||||
}
|
||||
},
|
||||
{
|
||||
"string": "1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i",
|
||||
"decode": {
|
||||
|
|
Loading…
Add table
Reference in a new issue