|
|
@ -1,7 +1,9 @@ |
|
|
|
var assert = require('assert') |
|
|
|
var convert = require('../').convert |
|
|
|
var ECKey = require('../src/eckey').ECKey |
|
|
|
var Message = require('../').Message |
|
|
|
var network = require('../').network |
|
|
|
|
|
|
|
var fixtures = require('./fixtures/message') |
|
|
|
|
|
|
|
describe('Message', function() { |
|
|
|
var msg |
|
|
@ -10,6 +12,17 @@ describe('Message', function() { |
|
|
|
msg = 'vires is numeris' |
|
|
|
}) |
|
|
|
|
|
|
|
describe('magicHash', function() { |
|
|
|
it('matches the test vectors', function() { |
|
|
|
fixtures.magicHash.forEach(function(f) { |
|
|
|
var actual = Message.magicHash(f.message) |
|
|
|
var expected = f.hash256 |
|
|
|
|
|
|
|
assert.equal(actual.toString('hex'), expected) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
describe('verify', function() { |
|
|
|
var addr, sig, caddr, csig |
|
|
|
|
|
|
@ -17,8 +30,8 @@ describe('Message', function() { |
|
|
|
addr = '16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM' // uncompressed
|
|
|
|
caddr = '1PMycacnJaSqwwJqjawXBErnLsZ7RkXUAs' // compressed
|
|
|
|
|
|
|
|
sig = convert.hexToBytes('1bc25ac0fb503abc9bad23f558742740fafaec1f52deaaf106b9759a5ce84c93921c4a669c5ec3dfeb7e2d7d177a2f49db407900874f6de2f701a4c16783776d8d') |
|
|
|
csig = convert.hexToBytes('1fc25ac0fb503abc9bad23f558742740fafaec1f52deaaf106b9759a5ce84c93921c4a669c5ec3dfeb7e2d7d177a2f49db407900874f6de2f701a4c16783776d8d') |
|
|
|
sig = new Buffer('1bc25ac0fb503abc9bad23f558742740fafaec1f52deaaf106b9759a5ce84c93921c4a669c5ec3dfeb7e2d7d177a2f49db407900874f6de2f701a4c16783776d8d', 'hex') |
|
|
|
csig = new Buffer('1fc25ac0fb503abc9bad23f558742740fafaec1f52deaaf106b9759a5ce84c93921c4a669c5ec3dfeb7e2d7d177a2f49db407900874f6de2f701a4c16783776d8d', 'hex') |
|
|
|
}) |
|
|
|
|
|
|
|
it('can verify a signed message', function() { |
|
|
@ -38,7 +51,7 @@ describe('Message', function() { |
|
|
|
|
|
|
|
it('supports alternate network addresses', function() { |
|
|
|
var taddr = 'mxnQZKxSKjzaMgrdXzk35rif3u62TLDrg9' |
|
|
|
var tsig = convert.base64ToBytes('IGucnrTku3KLCCHUMwq9anawfrlN8RK1HWMN+10LhsHJeysBdWfj5ohJcS/+oqrlVFNvEgbgEeAQUL6r3sZwnj8=') |
|
|
|
var tsig = new Buffer('IGucnrTku3KLCCHUMwq9anawfrlN8RK1HWMN+10LhsHJeysBdWfj5ohJcS/+oqrlVFNvEgbgEeAQUL6r3sZwnj8=', 'base64') |
|
|
|
|
|
|
|
assert.ok(Message.verify(taddr, tsig, msg)) |
|
|
|
assert.ok(!Message.verify(taddr, tsig, 'foobar')) |
|
|
@ -70,12 +83,10 @@ describe('Message', function() { |
|
|
|
|
|
|
|
describe('testnet address', function(){ |
|
|
|
it('works', function(){ |
|
|
|
var testnet = require('../').network.testnet |
|
|
|
|
|
|
|
var key = ECKey.makeRandom() |
|
|
|
var sig = Message.sign(key, msg) |
|
|
|
|
|
|
|
var addr = key.pub.getAddress(testnet.pubKeyHash) |
|
|
|
var addr = key.pub.getAddress(network.testnet.pubKeyHash) |
|
|
|
assert(Message.verify(addr, sig, msg)) |
|
|
|
}) |
|
|
|
}) |
|
|
|