forked from WebOfTrustInfo/btcr-did-tools-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilCmd.js
36 lines (25 loc) · 1.08 KB
/
utilCmd.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const bitcoin = require('bitcoinjs-lib');
const util = require('./util');
const program = require('commander');
program
.version("1.0.0")
.description("Extracts hex-encoded public key from a TXREF or a WIF")
.usage("[options]")
.option("-n, --network <network>", "Network to use if extacting the public key from process.env.WIF. Values are " +
"testnet or mainnet; default is testnet", "testnet")
.option("-t, --txref <network>", "TXREF to extract public key from. If not provided, this will try to extract" +
" a public key from process.env.WIF");
program.parse(process.argv);
let txref = program.txref;
if (txref) {
let publicKeyHex = util.extractPublicKeyHexFromTxref(txref).then( r => console.log(r.toString()));
} else {
let wif = process.env.WIF;
let chain = program.network === "mainnet" ? bitcoin.networks.mainnet : bitcoin.networks.testnet;
if (wif && chain) {
let publicKeyHex = util.publicKeyHexFromWif(wif, chain);
console.log(publicKeyHex);
} else {
console.log(program.helpInformation());
}
}