Browse Source

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.
hk-custom-address
Daniel Cousens 11 years ago
parent
commit
2b2081bed9
  1. 7
      src/base58check.js
  2. 3
      test/base58check.js
  3. 7
      test/fixtures/base58check.json

7
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)

3
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() {
})
})
})

7
test/fixtures/base58check.json

@ -1,5 +1,12 @@
{
"valid": [
{
"string": "1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i",
"decode": {
"payload": "65a16059864a2fdbc7c99a4723a8395bc6f188eb",
"checksum": "c046b2ff"
}
},
{
"string": "1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i",
"decode": {

Loading…
Cancel
Save