Created
January 18, 2018 07:02
-
-
Save svyatonik/2af91761fbc7d8b89b036573ca830b3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var BN = require('bn.js'); | |
var EC = require('elliptic').ec; | |
var ec = new EC('secp256k1'); | |
// Create key pair from secret | |
var key = ec.keyFromPrivate('00000000000000000000000000000000000000000000000000000000000000A5'); | |
console.log('PRIVATE: ' + key.getPrivate('hex')); | |
console.log('PUBLIC: ' + key.getPublic('hex')); | |
console.log('ADDRESS: ' + '16NzBsb7vAboEfdbdsnno4Dfc5xuMECL85'); // http://gobittest.appspot.com/Address | |
// Sign the message's hash (input must be an array, or a hex-string) | |
var msgHash = '0000000000000000000000000000000000000000000000000000000000000076'; | |
var signOptions = { | |
k: function(iter) { | |
return new BN('0000000000000000000000000000000000000000000000000000000000000042', 16); | |
} | |
}; | |
var signature = key.sign(msgHash, signOptions); | |
console.log(signature); | |
console.log(signature.toDER('hex')); | |
// signature in DER format | |
var signature = '30450220079264c4b4bfcd7fe3a7b7b92b6c439f3a5b3abcd29189bf7b54d781ff03d722022100ec24497f28b8b80d4c8824853a220de6342addca559231c7b42d633c77e62e4c'; | |
console.log(key.verify(msgHash, signature)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment