Merge pull request #206 from dcousens/base58rework

Base58 Check rework
This commit is contained in:
Kyle Drake 2014-06-04 16:54:18 -07:00
commit 9b5dfbd865
11 changed files with 108 additions and 336 deletions

View file

@ -28,9 +28,11 @@ function Address(hash, version) {
// Import functions
Address.fromBase58Check = function(string) {
var decode = base58check.decode(string)
var payload = base58check.decode(string)
var version = payload.readUInt8(0)
var hash = payload.slice(1)
return new Address(decode.payload, decode.version)
return new Address(hash, version)
}
Address.fromScriptPubKey = function(script, network) {
@ -51,7 +53,11 @@ Address.fromScriptPubKey = function(script, network) {
// Export functions
Address.prototype.toBase58Check = function () {
return base58check.encode(this.hash, this.version)
var payload = new Buffer(21)
payload.writeUInt8(this.version, 0)
this.hash.copy(payload, 1)
return base58check.encode(payload)
}
Address.prototype.toScriptPubKey = function() {

View file

@ -4,13 +4,11 @@ var base58 = require('./base58')
var crypto = require('./crypto')
// Encode a buffer as a base58-check-encoded string
function encode(payload, version) {
var version = new Buffer([version])
var message = Buffer.concat([version, payload])
var checksum = crypto.hash256(message).slice(0, 4)
function encode(payload) {
var checksum = crypto.hash256(payload).slice(0, 4)
return base58.encode(Buffer.concat([
message,
payload,
checksum
]))
}
@ -19,20 +17,13 @@ function encode(payload, version) {
function decode(string) {
var buffer = base58.decode(string)
var message = buffer.slice(0, -4)
var payload = buffer.slice(0, -4)
var checksum = buffer.slice(-4)
var newChecksum = crypto.hash256(message).slice(0, 4)
var newChecksum = crypto.hash256(payload).slice(0, 4)
assert.deepEqual(newChecksum, checksum, 'Invalid checksum')
var version = message.readUInt8(0)
var payload = message.slice(1)
return {
version: version,
payload: payload,
checksum: checksum
}
return payload
}
module.exports = {

View file

@ -22,13 +22,16 @@ function ECKey(D, compressed) {
// Static constructors
ECKey.fromWIF = function(string) {
var decode = base58check.decode(string)
var payload = decode.payload
var payload = base58check.decode(string)
var compressed = false
// Ignore the version byte
payload = payload.slice(1)
if (payload.length === 33) {
assert.strictEqual(payload[32], 0x01, 'Invalid compression flag')
// Truncate the compression flag
payload = payload.slice(0, -1)
compressed = true
}
@ -50,15 +53,20 @@ ECKey.makeRandom = function(compressed, rng) {
}
// Export functions
ECKey.prototype.toWIF = function(version) {
version = version || networks.bitcoin.wif
ECKey.prototype.toWIF = function(network) {
network = network || networks.bitcoin
var bufferLen = this.pub.compressed ? 34 : 33
var buffer = new Buffer(bufferLen)
buffer.writeUInt8(network.wif, 0)
this.D.toBuffer(32).copy(buffer, 1)
var buffer = this.D.toBuffer(32)
if (this.pub.compressed) {
buffer = Buffer.concat([buffer, new Buffer([0x01])])
buffer.writeUInt8(0x01, 33)
}
return base58check.encode(buffer, version)
return base58check.encode(buffer)
}
// Operations

View file

@ -30,10 +30,10 @@ ECPubKey.fromHex = function(hex) {
}
// Operations
ECPubKey.prototype.getAddress = function(version) {
version = version || networks.bitcoin.pubKeyHash
ECPubKey.prototype.getAddress = function(network) {
network = network || networks.bitcoin
return new Address(crypto.hash160(this.toBuffer()), version)
return new Address(crypto.hash160(this.toBuffer()), network.pubKeyHash)
}
ECPubKey.prototype.verify = function(hash, signature) {

View file

@ -1,5 +1,5 @@
var assert = require('assert')
var base58 = require('./base58')
var base58check = require('./base58check')
var BigInteger = require('bigi')
var crypto = require('./crypto')
@ -68,15 +68,7 @@ HDNode.fromSeedHex = function(hex, network) {
}
HDNode.fromBase58 = function(string) {
var buffer = base58.decode(string)
var payload = buffer.slice(0, -4)
var checksum = buffer.slice(-4)
var newChecksum = crypto.hash256(payload).slice(0, 4)
assert.deepEqual(newChecksum, checksum, 'Invalid checksum')
return HDNode.fromBuffer(payload)
return HDNode.fromBuffer(base58check.decode(string))
}
HDNode.fromBuffer = function(buffer) {
@ -144,17 +136,11 @@ HDNode.prototype.getFingerprint = function() {
}
HDNode.prototype.getAddress = function() {
return this.pubKey.getAddress(this.network.pubKeyHash)
return this.pubKey.getAddress(this.network)
}
HDNode.prototype.toBase58 = function(isPrivate) {
var buffer = this.toBuffer(isPrivate)
var checksum = crypto.hash256(buffer).slice(0, 4)
return base58.encode(Buffer.concat([
buffer,
checksum
]))
return base58check.encode(this.toBuffer(isPrivate))
}
HDNode.prototype.toBuffer = function(isPrivate) {

View file

@ -37,10 +37,9 @@ function sign(key, message, network) {
// TODO: network could be implied from address
function verify(address, compactSig, message, network) {
if (typeof address === 'string') {
address = Address.fromBase58Check(address)
if (address instanceof Address) {
address = address.toString()
}
network = network || networks.bitcoin
var hash = magicHash(message, network)
@ -49,7 +48,7 @@ function verify(address, compactSig, message, network) {
var Q = ecdsa.recoverPubKey(ecparams, e, parsed.signature, parsed.i)
var pubKey = new ECPubKey(Q, parsed.compressed)
return pubKey.getAddress(address.version).toString() === address.toString()
return pubKey.getAddress(network).toString() === address
}
module.exports = {

View file

@ -10,20 +10,16 @@ describe('base58check', function() {
fixtures.valid.forEach(function(f) {
it('can decode ' + f.string, function() {
var actual = base58check.decode(f.string)
var expected = {
version: f.decode.version || 0,
payload: h2b(f.decode.payload),
checksum: h2b(f.decode.checksum)
}
var expected = h2b(f.payload)
assert.deepEqual(actual, expected)
})
})
fixtures.invalid.forEach(function(f) {
it('throws on ' + f.description, function() {
it('throws on ' + f, function() {
assert.throws(function() {
base58check.decode(f.string)
base58check.decode(f)
}, /Invalid checksum/)
})
})
@ -32,7 +28,7 @@ describe('base58check', function() {
describe('encode', function() {
fixtures.valid.forEach(function(f) {
it('can encode ' + f.string, function() {
var actual = base58check.encode(h2b(f.decode.payload), f.decode.version)
var actual = base58check.encode(h2b(f.payload))
var expected = f.string
assert.strictEqual(actual, expected)

View file

@ -1,11 +1,11 @@
var assert = require('assert')
var crypto = require('../src/crypto')
var networks = require('../src/networks')
var BigInteger = require('bigi')
var ECKey = require('../src/eckey')
var fixtures = require('./fixtures/eckey.json')
var networks = require('../src/networks')
describe('ECKey', function() {
describe('constructor', function() {
@ -66,8 +66,8 @@ describe('ECKey', function() {
f.WIFs.forEach(function(wif) {
it('exports ' + wif.string + ' correctly', function() {
var privKey = ECKey.fromWIF(wif.string)
var version = networks[wif.network].wif
var result = privKey.toWIF(version)
var network = networks[wif.network]
var result = privKey.toWIF(network)
assert.equal(result, wif.string)
})

View file

@ -1,5 +1,6 @@
var assert = require('assert')
var crypto = require('../src/crypto')
var networks = require('../src/networks')
var sec = require('../src/sec')
var ecparams = sec('secp256k1')
@ -71,9 +72,9 @@ describe('ECPubKey', function() {
it('supports alternative networks', function() {
var pubKey = new ECPubKey(Q)
var address = pubKey.getAddress(0x09)
var address = pubKey.getAddress(networks.testnet)
assert.equal(address.version, 0x09)
assert.equal(address.version, networks.testnet.pubKeyHash)
assert.equal(address.hash.toString('hex'), fixtures.compressed.hash160)
})
})

View file

@ -2,424 +2,208 @@
"valid": [
{
"string": "1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i",
"decode": {
"payload": "65a16059864a2fdbc7c99a4723a8395bc6f188eb",
"checksum": "c046b2ff"
}
},
{
"string": "1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i",
"decode": {
"version": 0,
"payload": "65a16059864a2fdbc7c99a4723a8395bc6f188eb",
"checksum": "c046b2ff"
}
"payload": "0065a16059864a2fdbc7c99a4723a8395bc6f188eb"
},
{
"string": "3CMNFxN1oHBc4R1EpboAL5yzHGgE611Xou",
"decode": {
"version": 5,
"payload": "74f209f6ea907e2ea48f74fae05782ae8a665257",
"checksum": "a2353eb8"
}
"payload": "0574f209f6ea907e2ea48f74fae05782ae8a665257"
},
{
"string": "mo9ncXisMeAoXwqcV5EWuyncbmCcQN4rVs",
"decode": {
"version": 111,
"payload": "53c0307d6851aa0ce7825ba883c6bd9ad242b486",
"checksum": "3aa11ed6"
}
"payload": "6f53c0307d6851aa0ce7825ba883c6bd9ad242b486"
},
{
"string": "2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br",
"decode": {
"version": 196,
"payload": "6349a418fc4578d10a372b54b45c280cc8c4382f",
"checksum": "c4a2b951"
}
"payload": "c46349a418fc4578d10a372b54b45c280cc8c4382f"
},
{
"string": "5Kd3NBUAdUnhyzenEwVLy9pBKxSwXvE9FMPyR4UKZvpe6E3AgLr",
"decode": {
"version": 128,
"payload": "eddbdc1168f1daeadbd3e44c1e3f8f5a284c2029f78ad26af98583a499de5b19",
"checksum": "13a4f863"
}
"payload": "80eddbdc1168f1daeadbd3e44c1e3f8f5a284c2029f78ad26af98583a499de5b19"
},
{
"string": "Kz6UJmQACJmLtaQj5A3JAge4kVTNQ8gbvXuwbmCj7bsaabudb3RD",
"decode": {
"version": 128,
"payload": "55c9bccb9ed68446d1b75273bbce89d7fe013a8acd1625514420fb2aca1a21c401",
"checksum": "99a16fd4"
}
"payload": "8055c9bccb9ed68446d1b75273bbce89d7fe013a8acd1625514420fb2aca1a21c401"
},
{
"string": "9213qJab2HNEpMpYNBa7wHGFKKbkDn24jpANDs2huN3yi4J11ko",
"decode": {
"version": 239,
"payload": "36cb93b9ab1bdabf7fb9f2c04f1b9cc879933530ae7842398eef5a63a56800c2",
"checksum": "6a84391c"
}
"payload": "ef36cb93b9ab1bdabf7fb9f2c04f1b9cc879933530ae7842398eef5a63a56800c2"
},
{
"string": "cTpB4YiyKiBcPxnefsDpbnDxFDffjqJob8wGCEDXxgQ7zQoMXJdH",
"decode": {
"version": 239,
"payload": "b9f4892c9e8282028fea1d2667c4dc5213564d41fc5783896a0d843fc15089f301",
"checksum": "b008368c"
}
"payload": "efb9f4892c9e8282028fea1d2667c4dc5213564d41fc5783896a0d843fc15089f301"
},
{
"string": "1Ax4gZtb7gAit2TivwejZHYtNNLT18PUXJ",
"decode": {
"version": 0,
"payload": "6d23156cbbdcc82a5a47eee4c2c7c583c18b6bf4",
"checksum": "0680e989"
}
"payload": "006d23156cbbdcc82a5a47eee4c2c7c583c18b6bf4"
},
{
"string": "3QjYXhTkvuj8qPaXHTTWb5wjXhdsLAAWVy",
"decode": {
"version": 5,
"payload": "fcc5460dd6e2487c7d75b1963625da0e8f4c5975",
"checksum": "8b495dfc"
}
"payload": "05fcc5460dd6e2487c7d75b1963625da0e8f4c5975"
},
{
"string": "n3ZddxzLvAY9o7184TB4c6FJasAybsw4HZ",
"decode": {
"version": 111,
"payload": "f1d470f9b02370fdec2e6b708b08ac431bf7a5f7",
"checksum": "b663687c"
}
"payload": "6ff1d470f9b02370fdec2e6b708b08ac431bf7a5f7"
},
{
"string": "2NBFNJTktNa7GZusGbDbGKRZTxdK9VVez3n",
"decode": {
"version": 196,
"payload": "c579342c2c4c9220205e2cdc285617040c924a0a",
"checksum": "ba7d11ad"
}
"payload": "c4c579342c2c4c9220205e2cdc285617040c924a0a"
},
{
"string": "5K494XZwps2bGyeL71pWid4noiSNA2cfCibrvRWqcHSptoFn7rc",
"decode": {
"version": 128,
"payload": "a326b95ebae30164217d7a7f57d72ab2b54e3be64928a19da0210b9568d4015e",
"checksum": "171a2dfd"
}
"payload": "80a326b95ebae30164217d7a7f57d72ab2b54e3be64928a19da0210b9568d4015e"
},
{
"string": "L1RrrnXkcKut5DEMwtDthjwRcTTwED36thyL1DebVrKuwvohjMNi",
"decode": {
"version": 128,
"payload": "7d998b45c219a1e38e99e7cbd312ef67f77a455a9b50c730c27f02c6f730dfb401",
"checksum": "cd40f1cb"
}
"payload": "807d998b45c219a1e38e99e7cbd312ef67f77a455a9b50c730c27f02c6f730dfb401"
},
{
"string": "93DVKyFYwSN6wEo3E2fCrFPUp17FtrtNi2Lf7n4G3garFb16CRj",
"decode": {
"version": 239,
"payload": "d6bca256b5abc5602ec2e1c121a08b0da2556587430bcf7e1898af2224885203",
"checksum": "f0bf192e"
}
"payload": "efd6bca256b5abc5602ec2e1c121a08b0da2556587430bcf7e1898af2224885203"
},
{
"string": "cTDVKtMGVYWTHCb1AFjmVbEbWjvKpKqKgMaR3QJxToMSQAhmCeTN",
"decode": {
"version": 239,
"payload": "a81ca4e8f90181ec4b61b6a7eb998af17b2cb04de8a03b504b9e34c4c61db7d901",
"checksum": "7f570e65"
}
"payload": "efa81ca4e8f90181ec4b61b6a7eb998af17b2cb04de8a03b504b9e34c4c61db7d901"
},
{
"string": "1C5bSj1iEGUgSTbziymG7Cn18ENQuT36vv",
"decode": {
"version": 0,
"payload": "7987ccaa53d02c8873487ef919677cd3db7a6912",
"checksum": "11a2e19b"
}
"payload": "007987ccaa53d02c8873487ef919677cd3db7a6912"
},
{
"string": "3AnNxabYGoTxYiTEZwFEnerUoeFXK2Zoks",
"decode": {
"version": 5,
"payload": "63bcc565f9e68ee0189dd5cc67f1b0e5f02f45cb",
"checksum": "35e6c138"
}
"payload": "0563bcc565f9e68ee0189dd5cc67f1b0e5f02f45cb"
},
{
"string": "n3LnJXCqbPjghuVs8ph9CYsAe4Sh4j97wk",
"decode": {
"version": 111,
"payload": "ef66444b5b17f14e8fae6e7e19b045a78c54fd79",
"checksum": "7d48bb7f"
}
"payload": "6fef66444b5b17f14e8fae6e7e19b045a78c54fd79"
},
{
"string": "2NB72XtkjpnATMggui83aEtPawyyKvnbX2o",
"decode": {
"version": 196,
"payload": "c3e55fceceaa4391ed2a9677f4a4d34eacd021a0",
"checksum": "03bf5e60"
}
"payload": "c4c3e55fceceaa4391ed2a9677f4a4d34eacd021a0"
},
{
"string": "5KaBW9vNtWNhc3ZEDyNCiXLPdVPHCikRxSBWwV9NrpLLa4LsXi9",
"decode": {
"version": 128,
"payload": "e75d936d56377f432f404aabb406601f892fd49da90eb6ac558a733c93b47252",
"checksum": "135d832a"
}
"payload": "80e75d936d56377f432f404aabb406601f892fd49da90eb6ac558a733c93b47252"
},
{
"string": "L1axzbSyynNYA8mCAhzxkipKkfHtAXYF4YQnhSKcLV8YXA874fgT",
"decode": {
"version": 128,
"payload": "8248bd0375f2f75d7e274ae544fb920f51784480866b102384190b1addfbaa5c01",
"checksum": "2daf30c0"
}
"payload": "808248bd0375f2f75d7e274ae544fb920f51784480866b102384190b1addfbaa5c01"
},
{
"string": "927CnUkUbasYtDwYwVn2j8GdTuACNnKkjZ1rpZd2yBB1CLcnXpo",
"decode": {
"version": 239,
"payload": "44c4f6a096eac5238291a94cc24c01e3b19b8d8cef72874a079e00a242237a52",
"checksum": "bc446ce4"
}
"payload": "ef44c4f6a096eac5238291a94cc24c01e3b19b8d8cef72874a079e00a242237a52"
},
{
"string": "cUcfCMRjiQf85YMzzQEk9d1s5A4K7xL5SmBCLrezqXFuTVefyhY7",
"decode": {
"version": 239,
"payload": "d1de707020a9059d6d3abaf85e17967c6555151143db13dbb06db78df0f15c6901",
"checksum": "db1645ec"
}
"payload": "efd1de707020a9059d6d3abaf85e17967c6555151143db13dbb06db78df0f15c6901"
},
{
"string": "1Gqk4Tv79P91Cc1STQtU3s1W6277M2CVWu",
"decode": {
"version": 0,
"payload": "adc1cc2081a27206fae25792f28bbc55b831549d",
"checksum": "4c762f7e"
}
"payload": "00adc1cc2081a27206fae25792f28bbc55b831549d"
},
{
"string": "33vt8ViH5jsr115AGkW6cEmEz9MpvJSwDk",
"decode": {
"version": 5,
"payload": "188f91a931947eddd7432d6e614387e32b244709",
"checksum": "36a8fc53"
}
"payload": "05188f91a931947eddd7432d6e614387e32b244709"
},
{
"string": "mhaMcBxNh5cqXm4aTQ6EcVbKtfL6LGyK2H",
"decode": {
"version": 111,
"payload": "1694f5bc1a7295b600f40018a618a6ea48eeb498",
"checksum": "047e9722"
}
"payload": "6f1694f5bc1a7295b600f40018a618a6ea48eeb498"
},
{
"string": "2MxgPqX1iThW3oZVk9KoFcE5M4JpiETssVN",
"decode": {
"version": 196,
"payload": "3b9b3fd7a50d4f08d1a5b0f62f644fa7115ae2f3",
"checksum": "0fd6ecc5"
}
"payload": "c43b9b3fd7a50d4f08d1a5b0f62f644fa7115ae2f3"
},
{
"string": "5HtH6GdcwCJA4ggWEL1B3jzBBUB8HPiBi9SBc5h9i4Wk4PSeApR",
"decode": {
"version": 128,
"payload": "091035445ef105fa1bb125eccfb1882f3fe69592265956ade751fd095033d8d0",
"checksum": "9c5b305a"
}
"payload": "80091035445ef105fa1bb125eccfb1882f3fe69592265956ade751fd095033d8d0"
},
{
"string": "L2xSYmMeVo3Zek3ZTsv9xUrXVAmrWxJ8Ua4cw8pkfbQhcEFhkXT8",
"decode": {
"version": 128,
"payload": "ab2b4bcdfc91d34dee0ae2a8c6b6668dadaeb3a88b9859743156f462325187af01",
"checksum": "271c74db"
}
"payload": "80ab2b4bcdfc91d34dee0ae2a8c6b6668dadaeb3a88b9859743156f462325187af01"
},
{
"string": "92xFEve1Z9N8Z641KQQS7ByCSb8kGjsDzw6fAmjHN1LZGKQXyMq",
"decode": {
"version": 239,
"payload": "b4204389cef18bbe2b353623cbf93e8678fbc92a475b664ae98ed594e6cf0856",
"checksum": "13985bb8"
}
"payload": "efb4204389cef18bbe2b353623cbf93e8678fbc92a475b664ae98ed594e6cf0856"
},
{
"string": "cVM65tdYu1YK37tNoAyGoJTR13VBYFva1vg9FLuPAsJijGvG6NEA",
"decode": {
"version": 239,
"payload": "e7b230133f1b5489843260236b06edca25f66adb1be455fbd38d4010d48faeef01",
"checksum": "45de6187"
}
"payload": "efe7b230133f1b5489843260236b06edca25f66adb1be455fbd38d4010d48faeef01"
},
{
"string": "1JwMWBVLtiqtscbaRHai4pqHokhFCbtoB4",
"decode": {
"version": 0,
"payload": "c4c1b72491ede1eedaca00618407ee0b772cad0d",
"checksum": "27a58137"
}
"payload": "00c4c1b72491ede1eedaca00618407ee0b772cad0d"
},
{
"string": "3QCzvfL4ZRvmJFiWWBVwxfdaNBT8EtxB5y",
"decode": {
"version": 5,
"payload": "f6fe69bcb548a829cce4c57bf6fff8af3a5981f9",
"checksum": "80242330"
}
"payload": "05f6fe69bcb548a829cce4c57bf6fff8af3a5981f9"
},
{
"string": "mizXiucXRCsEriQCHUkCqef9ph9qtPbZZ6",
"decode": {
"version": 111,
"payload": "261f83568a098a8638844bd7aeca039d5f2352c0",
"checksum": "56892155"
}
"payload": "6f261f83568a098a8638844bd7aeca039d5f2352c0"
},
{
"string": "2NEWDzHWwY5ZZp8CQWbB7ouNMLqCia6YRda",
"decode": {
"version": 196,
"payload": "e930e1834a4d234702773951d627cce82fbb5d2e",
"checksum": "3ac92331"
}
"payload": "c4e930e1834a4d234702773951d627cce82fbb5d2e"
},
{
"string": "5KQmDryMNDcisTzRp3zEq9e4awRmJrEVU1j5vFRTKpRNYPqYrMg",
"decode": {
"version": 128,
"payload": "d1fab7ab7385ad26872237f1eb9789aa25cc986bacc695e07ac571d6cdac8bc0",
"checksum": "d6f7166b"
}
"payload": "80d1fab7ab7385ad26872237f1eb9789aa25cc986bacc695e07ac571d6cdac8bc0"
},
{
"string": "L39Fy7AC2Hhj95gh3Yb2AU5YHh1mQSAHgpNixvm27poizcJyLtUi",
"decode": {
"version": 128,
"payload": "b0bbede33ef254e8376aceb1510253fc3550efd0fcf84dcd0c9998b288f166b301",
"checksum": "e396e2cb"
}
"payload": "80b0bbede33ef254e8376aceb1510253fc3550efd0fcf84dcd0c9998b288f166b301"
},
{
"string": "91cTVUcgydqyZLgaANpf1fvL55FH53QMm4BsnCADVNYuWuqdVys",
"decode": {
"version": 239,
"payload": "037f4192c630f399d9271e26c575269b1d15be553ea1a7217f0cb8513cef41cb",
"checksum": "504ffa32"
}
"payload": "ef037f4192c630f399d9271e26c575269b1d15be553ea1a7217f0cb8513cef41cb"
},
{
"string": "cQspfSzsgLeiJGB2u8vrAiWpCU4MxUT6JseWo2SjXy4Qbzn2fwDw",
"decode": {
"version": 239,
"payload": "6251e205e8ad508bab5596bee086ef16cd4b239e0cc0c5d7c4e6035441e7d5de01",
"checksum": "070c22e6"
}
"payload": "ef6251e205e8ad508bab5596bee086ef16cd4b239e0cc0c5d7c4e6035441e7d5de01"
},
{
"string": "19dcawoKcZdQz365WpXWMhX6QCUpR9SY4r",
"decode": {
"version": 0,
"payload": "5eadaf9bb7121f0f192561a5a62f5e5f54210292",
"checksum": "ef7a7be3"
}
"payload": "005eadaf9bb7121f0f192561a5a62f5e5f54210292"
},
{
"string": "37Sp6Rv3y4kVd1nQ1JV5pfqXccHNyZm1x3",
"decode": {
"version": 5,
"payload": "3f210e7277c899c3a155cc1c90f4106cbddeec6e",
"checksum": "0f6e5c98"
}
"payload": "053f210e7277c899c3a155cc1c90f4106cbddeec6e"
},
{
"string": "myoqcgYiehufrsnnkqdqbp69dddVDMopJu",
"decode": {
"version": 111,
"payload": "c8a3c2a09a298592c3e180f02487cd91ba3400b5",
"checksum": "30c3769a"
}
"payload": "6fc8a3c2a09a298592c3e180f02487cd91ba3400b5"
},
{
"string": "2N7FuwuUuoTBrDFdrAZ9KxBmtqMLxce9i1C",
"decode": {
"version": 196,
"payload": "99b31df7c9068d1481b596578ddbb4d3bd90baeb",
"checksum": "02eca37f"
}
"payload": "c499b31df7c9068d1481b596578ddbb4d3bd90baeb"
},
{
"string": "5KL6zEaMtPRXZKo1bbMq7JDjjo1bJuQcsgL33je3oY8uSJCR5b4",
"decode": {
"version": 128,
"payload": "c7666842503db6dc6ea061f092cfb9c388448629a6fe868d068c42a488b478ae",
"checksum": "88451297"
}
"payload": "80c7666842503db6dc6ea061f092cfb9c388448629a6fe868d068c42a488b478ae"
},
{
"string": "KwV9KAfwbwt51veZWNscRTeZs9CKpojyu1MsPnaKTF5kz69H1UN2",
"decode": {
"version": 128,
"payload": "07f0803fc5399e773555ab1e8939907e9badacc17ca129e67a2f5f2ff84351dd01",
"checksum": "004d964f"
}
"payload": "8007f0803fc5399e773555ab1e8939907e9badacc17ca129e67a2f5f2ff84351dd01"
},
{
"string": "93N87D6uxSBzwXvpokpzg8FFmfQPmvX4xHoWQe3pLdYpbiwT5YV",
"decode": {
"version": 239,
"payload": "ea577acfb5d1d14d3b7b195c321566f12f87d2b77ea3a53f68df7ebf8604a801",
"checksum": "babac8c2"
}
"payload": "efea577acfb5d1d14d3b7b195c321566f12f87d2b77ea3a53f68df7ebf8604a801"
},
{
"string": "cMxXusSihaX58wpJ3tNuuUcZEQGt6DKJ1wEpxys88FFaQCYjku9h",
"decode": {
"version": 239,
"payload": "0b3b34f0958d8a268193a9814da92c3e8b58b4a4378a542863e34ac289cd830c01",
"checksum": "61073840"
}
"payload": "ef0b3b34f0958d8a268193a9814da92c3e8b58b4a4378a542863e34ac289cd830c01"
},
{
"string": "13p1ijLwsnrcuyqcTvJXkq2ASdXqcnEBLE",
"decode": {
"version": 0,
"payload": "1ed467017f043e91ed4c44b4e8dd674db211c4e6",
"checksum": "6cc37d7b"
}
"payload": "001ed467017f043e91ed4c44b4e8dd674db211c4e6"
},
{
"string": "3ALJH9Y951VCGcVZYAdpA3KchoP9McEj1G",
"decode": {
"version": 5,
"payload": "5ece0cadddc415b1980f001785947120acdb36fc",
"checksum": "b43c48af"
}
"payload": "055ece0cadddc415b1980f001785947120acdb36fc"
}
],
"invalid": [
{
"description": "bad version byte",
"string": "Z9inZq4e2HGQRZQezDjFMmqgUE8NwMRok"
},
{
"description": "bad payload",
"string": "3HK7MezAm6qEZQUMPRf8jX7wDv6zig6Ky8"
},
{
"description": "bad SHA256 checksum",
"string": "3AW8j12DUk8mgA7kkfZ1BrrzCVFuH1LsXS"
}
"Z9inZq4e2HGQRZQezDjFMmqgUE8NwMRok",
"3HK7MezAm6qEZQUMPRf8jX7wDv6zig6Ky8",
"3AW8j12DUk8mgA7kkfZ1BrrzCVFuH1LsXS"
]
}

View file

@ -24,21 +24,22 @@ describe('Bitcoin-js', function() {
return ECKey.fromWIF(wif)
})
// how much to withdraw if we run dry
var coldAmount = 2e4
var outputAmount = 1e4
var pubKeys = privKeys.map(function(eck) { return eck.pub })
var redeemScript = Script.createMultisigScriptPubKey(2, pubKeys)
var multisigAddress = new Address(redeemScript.getHash(), networks.testnet.scriptHash).toString()
var scriptPubKey = Script.createP2SHScriptPubKey(redeemScript.getHash())
// Send some testnet coins to the multisig address to ensure it has some unspents for later
var multisigAddress = Address.fromScriptPubKey(scriptPubKey, networks.testnet).toString()
// Attempt to send funds to the source address, providing some unspents for later
helloblock.faucet.withdraw(multisigAddress, coldAmount, function(err) {
if (err) return done(err)
})
// make a random private key
var targetAddress = ECKey.makeRandom().pub.getAddress(networks.testnet.pubKeyHash).toString()
var targetAddress = ECKey.makeRandom().pub.getAddress(networks.testnet).toString()
// get latest unspents from the multisigAddress
helloblock.addresses.getUnspents(multisigAddress, function(err, resp, resource) {