You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
704 B
21 lines
704 B
var ECDSA = require('../lib/ecdsa');
|
|
var Keypair = require('../lib/keypair');
|
|
var Hash = require('../lib/hash');
|
|
|
|
//ECDSA is the signature algorithm used in bitcoin
|
|
|
|
//start with a keypair that you will use for signing
|
|
var keypair = Keypair().fromRandom();
|
|
|
|
//a message to be signed (normally you would have the hash of a transaction)
|
|
var messagebuf = new Buffer('This is a message I would like to sign');
|
|
|
|
//calculate a 32 byte hash for use in ECDSA. one way to do that is sha256.
|
|
var hashbuf = Hash.sha256(messagebuf);
|
|
|
|
var sig = ECDSA.sign(hashbuf, keypair);
|
|
|
|
//Anyone with the public key can verify
|
|
var pubkey = keypair.pubkey;
|
|
console.log('Valid signature? ' + ECDSA.verify(hashbuf, sig, pubkey));
|
|
|
|
|