diff --git a/src/base58check.js b/src/base58check.js index 10afce2..a905ec9 100644 --- a/src/base58check.js +++ b/src/base58check.js @@ -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) diff --git a/test/base58check.js b/test/base58check.js index c4d1030..0a88952 100644 --- a/test/base58check.js +++ b/test/base58check.js @@ -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() { }) }) }) - diff --git a/test/fixtures/base58check.json b/test/fixtures/base58check.json index dc4928f..3314ec5 100644 --- a/test/fixtures/base58check.json +++ b/test/fixtures/base58check.json @@ -1,5 +1,12 @@ { "valid": [ + { + "string": "1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i", + "decode": { + "payload": "65a16059864a2fdbc7c99a4723a8395bc6f188eb", + "checksum": "c046b2ff" + } + }, { "string": "1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i", "decode": {