Created
March 31, 2017 22:29
-
-
Save mishfit/0ad0ce9f8a6e20763f0287985ea1d028 to your computer and use it in GitHub Desktop.
ZeroNet "signers_sign" Property Formatter
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
#!/usr/bin/env node | |
var program = require('commander'), | |
bitcoin = require('bitcoinjs-lib'), | |
fs = require('fs'); | |
program | |
.version('0.0.1') | |
.usage('[options]') | |
.option('-c, --number-required <n>', 'number required', parseInt) | |
.option('-k, --private-key [value]', 'private key') | |
.option('-a, --additional-addresses <values>', 'public keys', (val) => val.split(',')) | |
.parse(process.argv); | |
var privateKey = program.privateKey, | |
pair = bitcoin | |
.ECPair | |
.fromWIF(privateKey); | |
// add the address of the private key signing this message | |
// (in fact, make it the first address in the list) | |
if (!program.additionalAddresses.includes(pair.getAddress())) { | |
program | |
.additionalAddresses | |
.unshift(pair.getAddress()); | |
} | |
var clearText = `${program.numberRequired}:${program.additionalAddresses.join(',')}`, | |
cipherText = pair | |
.sign( | |
bitcoin | |
.crypto | |
.sha256(clearText)) | |
.toDER() | |
.toString('base64'); | |
console.log(`signs_required: ${clearText}`); | |
console.log(`signed message: ${cipherText}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment