|
|
@ -1,6 +1,7 @@ |
|
|
|
var assert = require('assert') |
|
|
|
var networks = require('../src/networks') |
|
|
|
|
|
|
|
var BigInteger = require('bigi') |
|
|
|
var ECKey = require('../src/eckey') |
|
|
|
var Message = require('../src/message') |
|
|
|
|
|
|
@ -16,10 +17,10 @@ describe('Message', function() { |
|
|
|
describe('magicHash', function() { |
|
|
|
it('matches the test vectors', function() { |
|
|
|
fixtures.magicHash.forEach(function(f) { |
|
|
|
var actual = Message.magicHash(f.message) |
|
|
|
var expected = f.hash256 |
|
|
|
var network = networks[f.network] |
|
|
|
var actual = Message.magicHash(f.message, network) |
|
|
|
|
|
|
|
assert.equal(actual.toString('hex'), expected) |
|
|
|
assert.equal(actual.toString('hex'), f.magicHash) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -50,23 +51,22 @@ describe('Message', function() { |
|
|
|
assert.ok(!Message.verify('1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nK9', csig, message)) |
|
|
|
}) |
|
|
|
|
|
|
|
it('supports alternate network addresses', function() { |
|
|
|
var taddr = 'mxnQZKxSKjzaMgrdXzk35rif3u62TLDrg9' |
|
|
|
var tsig = new Buffer('IGucnrTku3KLCCHUMwq9anawfrlN8RK1HWMN+10LhsHJeysBdWfj5ohJcS/+oqrlVFNvEgbgEeAQUL6r3sZwnj8=', 'base64') |
|
|
|
|
|
|
|
assert.ok(Message.verify(taddr, tsig, message)) |
|
|
|
assert.ok(!Message.verify(taddr, tsig, 'foobar')) |
|
|
|
}) |
|
|
|
|
|
|
|
it('does not cross verify (compressed/uncompressed)', function() { |
|
|
|
assert.ok(!Message.verify(addr, csig, message)) |
|
|
|
assert.ok(!Message.verify(caddr, sig, message)) |
|
|
|
}) |
|
|
|
|
|
|
|
it('supports alternate networks', function() { |
|
|
|
var dogeaddr = 'DFpN6QqFfUm3gKNaxN6tNcab1FArL9cZLE' |
|
|
|
var dogesig = new Buffer('H6k+dZwJ8oOei3PCSpdj603fDvhlhQ+sqaFNIDvo/bI+Xh6zyIKGzZpyud6YhZ1a5mcrwMVtTWL+VXq/hC5Zj7s=', 'base64') |
|
|
|
|
|
|
|
assert.ok(Message.verify(dogeaddr, dogesig, message, networks.dogecoin)) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
describe('signing', function() { |
|
|
|
it('gives matching signatures irrespective of point compression', function() { |
|
|
|
var privKey = ECKey.makeRandom(false) |
|
|
|
var privKey = new ECKey(BigInteger.ONE, false) |
|
|
|
var compressedKey = new ECKey(privKey.D, true) |
|
|
|
|
|
|
|
var sig = Message.sign(privKey, message) |
|
|
@ -75,5 +75,12 @@ describe('Message', function() { |
|
|
|
assert.notDeepEqual(sig.slice(0, 2), csig.slice(0, 2)) // unequal compression flags
|
|
|
|
assert.deepEqual(sig.slice(2), csig.slice(2)) // equal signatures
|
|
|
|
}) |
|
|
|
|
|
|
|
it('supports alternate networks', function() { |
|
|
|
var privKey = new ECKey(BigInteger.ONE) |
|
|
|
var signature = Message.sign(privKey, message, networks.dogecoin) |
|
|
|
|
|
|
|
assert.equal(signature.toString('base64'), 'H6k+dZwJ8oOei3PCSpdj603fDvhlhQ+sqaFNIDvo/bI+Xh6zyIKGzZpyud6YhZ1a5mcrwMVtTWL+VXq/hC5Zj7s=') |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|