bitcoinjs-lib/test/ecdsa.js

22 lines
842 B
JavaScript
Raw Normal View History

2014-03-28 18:24:23 +01:00
var assert = require('assert')
var convert = require('../').convert
var ecdsa = require('../').ecdsa
2014-03-29 07:44:03 +01:00
var ECPubKey = require('../').ECPubKey
2014-03-28 18:24:23 +01:00
var Message = require('../').Message
describe('ecdsa', function() {
describe('recoverPubKey', function() {
it('succesfully recovers a public key', function() {
var addr = 'mgQK8S6CfSXKjPmnujArSmVxafeJfrZsa3'
var signature = convert.base64ToBytes('H0PG6+PUo96UPTJ/DVj8aBU5it+Nuli4YdsLuTMvfJxoHH9Jb7jYTQXCCOX2jrTChD5S1ic3vCrUQHdmB5/sEQY=')
var sighex = convert.bytesToHex(signature)
var hash = Message.getHash('1111')
var obj = ecdsa.parseSigCompact(signature)
2014-03-29 07:44:03 +01:00
var pubKey = new ECPubKey(ecdsa.recoverPubKey(obj.r, obj.s, hash, obj.i))
2014-03-28 18:24:23 +01:00
assert.equal(pubKey.toHex(true), '02e8fcf4d749b35879bc1f3b14b49e67ab7301da3558c5a9b74a54f1e6339c334c')
})
})
})