Ryan X. Charles
10 years ago
1 changed files with 21 additions and 0 deletions
@ -0,0 +1,21 @@ |
|||
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)); |
|||
|
Loading…
Reference in new issue