Created
April 11, 2018 20:38
-
-
Save mycroft/3accaf2a2e3ea325f670707b3ea4605d to your computer and use it in GitHub Desktop.
Recovering BCH from ninki wallet.
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
#!/bin/sh | |
# You need to retrieve the hot, the cold and ninki pub using the | |
# patch script you'll find on https://github.com/mycroft/ninki-recover | |
# Fill the inputs, start sweeping, open console, and you'll see outputs like the | |
# following: | |
# used path is: m/0/1000/00 | |
# balance is 0 on this key: | |
# address: 32aVrFpfoACPiGFJiLUfkNnbkBoWnGu1Sp | |
# hot (priv): L42FdtAvqUkPNNAbFp7YFc8pbs1TaLQorAPi8vSwWGvaFrbRrxdr | |
# cold (priv): L58aryNNUgKvaQJswTdXufqqXZbD4JweMPT5vvfso8J8vVX8qioX | |
# hot (pub): 020ad6805b97c88afa8f05f66bc7bdfd0be0fe4721db37a7248c0cee43921f8975 | |
# cold (pub): 03b03aebc07309392db371cd87d01f3e5c9779f8420c208664988625817f66a117 | |
# ninki (pub): 0341ab3e62575553475bfa6a8cb8b2940a23c54e054255366dd09ad4198b63ed3b# | |
# When you have those, fill the keys bellow. | |
## Edit the following keys: | |
# Private keys: | |
HOT_PRIV= | |
COLD_PRIV= | |
# Public keys: | |
HOT_PUB= | |
COLD_PUB= | |
NINKI_PUB= | |
ADDRESS= | |
# Where your coins are going: | |
NEW_ADDRESS= | |
# https://bitcoincash.blockexplorer.com/address/35FynW7vYFvhbeLA2mYH2zHUk9PR5gpDj5 | |
UTXO_TXID=a84dea55686a0cc9cbc07bea345b9f0137a457effd5fc42c5cf65fd397797055 | |
UTXO_TXN=1 | |
SPENT=0.35297486 | |
VALUE=0.35296486 | |
## TEST | |
# HOT_PRIV=L42FdtAvqUkPNNAbFp7YFc8pbs1TaLQorAPi8vSwWGvaFrbRrxdr | |
# COLD_PRIV=L58aryNNUgKvaQJswTdXufqqXZbD4JweMPT5vvfso8J8vVX8qioX | |
# HOT_PUB=020ad6805b97c88afa8f05f66bc7bdfd0be0fe4721db37a7248c0cee43921f8975 | |
# COLD_PUB=03b03aebc07309392db371cd87d01f3e5c9779f8420c208664988625817f66a117 | |
# NINKI_PUB=0341ab3e62575553475bfa6a8cb8b2940a23c54e054255366dd09ad4198b63ed3b | |
# UTXO_TXID=4586a06afd71bb22110c4891e2c89760e5c302c8ead1676f1ba6560030fcd64b | |
# UTXO_TXN=0 | |
# SPENT=30 | |
# VALUE=29.999500 | |
# NEW_ADDRESS=bchtest:qzrv9ylf4mn7rufgku0xpq9v5ac5a9plfvphmw2gdv | |
## | |
## Do not modify the following code: | |
set -e | |
SERVER=xxxx | |
PORT=xxxx | |
TESTNET= | |
BCHTGZ=bitcoin-abc-0.17.0-osx64.tar.gz | |
BCHURL=https://download.bitcoinabc.org/0.17.0/osx/$BCHTGZ | |
## TEST | |
# set -x | |
# TESTNET=-testnet | |
# BCHTGZ=bitcoin-abc-0.17.0-x86_64-linux-gnu.tar.gz | |
# BCHURL=https://download.bitcoinabc.org/0.17.0/linux/$BCHTGZ | |
# SERVER=shuttle | |
# PORT=19333 | |
## END TEST | |
ADDR1_PRIVATE_KEY=$HOT_PRIV | |
ADDR2_PRIVATE_KEY=$COLD_PRIV | |
NEW_PUBKEY1=$HOT_PUB | |
NEW_PUBKEY2=$COLD_PUB | |
NEW_PUBKEY3=$NINKI_PUB | |
cd $HOME | |
if test ! -d abc_recover; then | |
mkdir abc_recover | |
fi | |
cd abc_recover | |
if test ! -e $BCHTGZ; then | |
echo "Downloading Bitcoin ABC..." | |
curl -O $BCHURL | |
tar xfz $BCHTGZ | |
fi | |
cd bitcoin-abc-0.17.0/bin | |
CMD="./bitcoin-cli ${TESTNET} -rpcconnect=${SERVER} -rpcport=${PORT} -rpcuser=rpc -rpcpassword=\"xxx\"" | |
alias bch=$CMD | |
OLD_ADDRESS=$(bch createmultisig 2 "[\"$NEW_PUBKEY1\", \"$NEW_PUBKEY2\", \"$NEW_PUBKEY3\"]" | python -c 'import json,sys;print json.load(sys.stdin)["address"]') | |
REDEEMSCRIPT=$(bch createmultisig 2 "[\"$NEW_PUBKEY1\", \"$NEW_PUBKEY2\", \"$NEW_PUBKEY3\"]" | python -c 'import json,sys;print json.load(sys.stdin)["redeemScript"]') | |
echo "Coins come from $OLD_ADDRESS" | |
echo "Check with https://cashaddr.bitcoincash.org/ to know legacy address!" | |
RAW_TX=$(bch getrawtransaction $UTXO_TXID $UTXO_TXN) | |
UTXO_OUTPUT_SCRIPT=$(bch decoderawtransaction $RAW_TX | python -c "import json,sys;print json.load(sys.stdin)[\"vout\"][$UTXO_TXN][\"scriptPubKey\"][\"hex\"]") | |
# NEW_ADDRESS=$(bch getaccountaddress "") | |
echo "Your coins will be sent to ${NEW_ADDRESS}" | |
RAW_TX=$(bch createrawtransaction "[{\"txid\": \"$UTXO_TXID\", \"vout\": $UTXO_TXN}]" "{\"$NEW_ADDRESS\": $VALUE}") | |
PARTIAL_RAW_TX=$(bch signrawtransaction $RAW_TX "[{\"txid\": \"$UTXO_TXID\", \"vout\": $UTXO_TXN, \"redeemScript\": \"$REDEEMSCRIPT\", \"scriptPubKey\": \"$UTXO_OUTPUT_SCRIPT\", \"amount\": $SPENT}]" "[\"$ADDR1_PRIVATE_KEY\"]" | python -c 'import json,sys;print json.load(sys.stdin)["hex"]') | |
COMPLETE_TX=$(bch signrawtransaction $PARTIAL_RAW_TX "[{\"txid\": \"$UTXO_TXID\", \"vout\": $UTXO_TXN, \"redeemScript\": \"$REDEEMSCRIPT\", \"scriptPubKey\": \"$UTXO_OUTPUT_SCRIPT\", \"amount\": $SPENT}]" "[\"$ADDR2_PRIVATE_KEY\"]" | python -c 'import json,sys;print json.load(sys.stdin)["hex"]') | |
bch signrawtransaction $PARTIAL_RAW_TX "[{\"txid\": \"$UTXO_TXID\", \"vout\": $UTXO_TXN, \"redeemScript\": \"$REDEEMSCRIPT\", \"scriptPubKey\": \"$UTXO_OUTPUT_SCRIPT\", \"amount\": $SPENT}]" "[\"$ADDR2_PRIVATE_KEY\"]" | |
echo | |
echo "Yout transaction, decoded: " | |
bch decoderawtransaction ${COMPLETE_TX} | |
echo | |
echo "Your transaction: $COMPLETE_TX" | |
echo | |
echo "To send (Make it only if absolutely sure!!!" | |
echo "$CMD sendrawtransaction $COMPLETE_TX" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment