forked from nbd-wtf/bitcoin_signet
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathgen-signet-keys.sh
More file actions
executable file
·56 lines (51 loc) · 1.95 KB
/
gen-signet-keys.sh
File metadata and controls
executable file
·56 lines (51 loc) · 1.95 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
DATADIR=${DATADIR:-"regtest-temp"}
BITCOINCLI=${BITCOINCLI:-"bitcoin-cli -regtest -datadir=$DATADIR "}
BITCOIND=${BITCOIND:-"bitcoind -datadir=$DATADIR -regtest -daemon "}
write_files() {
echo "PRIVKEY="
cat $BITCOIN_DIR/PRIVKEY.txt
echo "SIGNETCHALLENGE=" $SIGNETCHALLENGE
echo $ADDR > $BITCOIN_DIR/ADDR.txt
echo $PUBKEY > $BITCOIN_DIR/PUBKEY.txt
echo $SIGNETCHALLENGE >$BITCOIN_DIR/SIGNETCHALLENGE.txt
}
if [[ "$MINERENABLED" == "1" ]]; then
if [[ ("$SIGNETCHALLENGE" == "" || "$PRIVKEY" == "") ]]; then
echo "Generating new signetchallange and privkey."
#clean if exists
rm -rf $DATADIR
#make it fresh
mkdir $DATADIR
#kill any daemon running stuff
pkill bitcoind
#minimal config file (hardcode bitcoin:bitcoin for rpc)
echo "
regtest=1
server=1
rpcauth=bitcoin:c8c8b9740a470454255b7a38d4f38a52\$e8530d1c739a3bb0ec6e9513290def11651afbfd2b979f38c16ec2cf76cf348a
rpcuser=bitcoin
rpcpassword=bitcoin
" >$DATADIR/bitcoin.conf
#start daemon
$BITCOIND -wallet="temp"
#wait a bit for startup
sleep 5s
#create wallet
$BITCOINCLI -named createwallet wallet_name="temp" descriptors=true
#Get the signet script from the 86 descriptor
ADDR=$($BITCOINCLI getnewaddress)
SIGNETCHALLENGE=$($BITCOINCLI getaddressinfo $ADDR | jq -r ".scriptPubKey")
PUBKEY=$($BITCOINCLI getaddressinfo $ADDR | jq .pubkey | tr -d '""')
# Dumping descriptor wallet privatekey
$BITCOINCLI listdescriptors true | jq -r ".descriptors | .[].desc" >> $BITCOIN_DIR/PRIVKEY.txt
#don't need regtest anymore
$BITCOINCLI stop
#cleanup
rm -rf $DATADIR
else
echo "$PRIVKEY" > $BITCOIN_DIR/PRIVKEY.txt
echo "$SIGNETCHALLENGE" > $BITCOIN_DIR/SIGNETCHALLENGE.txt
echo "Imported signetchallange and privkey being used."
fi
fi
write_files