Last active
September 29, 2021 20:33
-
-
Save nuke-web3/b8587d676c38c4578634aa6fdf72b06b to your computer and use it in GitHub Desktop.
Use subkey tool to find polkadot / kusama / other substrate network's accounts from mnemonic seed words, passwords, and derivation paths.
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/bash | |
# Use this script to try various derivation paths and passowords for a known seed. | |
# ****NOTE!!!!**** | |
# DO NOT SAVE THIS FILE WITH YOUR SEED IN IT!!!! | |
# INSTEAD RUN THIS ONCE AS IS, THEN MANALLY SET | |
# YOU MUST EDIT THESE VARIABLES *NOT IN THIS FILE*!! | |
# SET THESE IN YOUR TERMINAL: | |
# SECRET="<put your seed words / mnemonic here>" | |
# PASSWORD="<put your password here, could be empty, so just quotes "">" | |
# Set your *real* variables like this in your terminal ONLY. | |
# Don't save your secrets here in the file!!! | |
# ---------------------------------- BEGIN SCRIPT ---------------------------------- | |
echo "------------------------------" | |
echo " *** Address finder *** " | |
echo "*** A Script using the \`subkey\` to search for your address over various derivation paths ***" | |
echo "------------------------------" | |
echo "*****" | |
echo "First check your seed words show up in the BIP39 list" | |
echo "https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt" | |
echo "If there are words that you have recorded that are *not* in this list," | |
echo "you should look for what you might have had mistaken!" | |
echo "all valid words are in this list!" | |
echo "*****" | |
# subkey needs to be installed. | |
if ! command -v subkey &> /dev/null | |
then | |
echo "Command subkey not found!! You must install this first." | |
echo "Instructions and instaliation found here:" | |
echo "https://substrate.dev/docs/en/knowledgebase/integrate/subkey" | |
exit | |
fi | |
# TODO: Do a check for existing *shell* (not env) variables, otherwise use a default for testing. | |
# https://www.baeldung.com/linux/bash-variables-export | |
# for now, we need them to exist in the env (exported) | |
if [[ -z "${SECRET}" ]]; then | |
echo "SECRET phrase / mnemonic not set! Using default for test: \"increase dust illegal pottery half kite broccoli force cheese miss arrange cushion\"" | |
SECRET="increase dust illegal pottery half kite broccoli force cheese miss arrange cushion" | |
echo "To set your secret, use \`export SECRET=\"<put your secret here>\"\`" | |
echo "Then re-run this script" | |
else | |
echo "!! Found user set SECRET phrase / mnemonic !!" | |
# echo $SECRET | |
fi | |
if [[ -z "${PASSWORD}" ]]; then | |
echo "PASSWORD not set! Using default: \"\"" | |
PASSWORD="" | |
echo "To set your password, use \`export PASSWORD=\"<put your password here>\"\`" | |
echo "Then re-run this script" | |
else | |
echo "!! Found user set PASSWORD !!" | |
# echo $PASSWORD | |
fi | |
if [[ -z "${NETWORK}" ]]; then | |
echo "NETWORK not set! Using default: \"polkadot\"" | |
NETWORK="polkadot" | |
echo "To set your network, use \`export NETWORK=\"<put your network here>\"\`" | |
echo "Then re-run this script" | |
else | |
echo "!! Found user set NETWORK !!" | |
# echo $NETWORK | |
fi | |
if [[ -z "${ADDRESS}" ]]; then | |
echo "ADDRESS not set! Using default: \"13KsHzKyUtHaXQNjzcPGk17wFzbyzkogwgRoEKYftrL8e7vV\"" | |
ADDRESS="13KsHzKyUtHaXQNjzcPGk17wFzbyzkogwgRoEKYftrL8e7vV" | |
echo "To set your address, use \`export ADDRESS=\"<put your address here>\"\`" | |
echo "Then re-run this script" | |
else | |
echo "!! Found user set ADDRESS !!" | |
# echo $ADDRESS | |
fi | |
echo "------------------------------" | |
echo "Running search for "$ADDRESS" in with provided information various derivation paths" | |
echo "...If nothing found, there will be no output..." | |
echo "------------------------------" | |
# ************************************************* | |
# NOTE: edit these to try other paths!! | |
# ************************************************* | |
# try with no path or password | |
subkey inspect --network $NETWORK "$SECRET" | grep -B4 $ADDRESS | |
# try with only password | |
subkey inspect --network $NETWORK "$SECRET///$PASSWORD" | grep -B4 $ADDRESS | |
# loop over various derivation paths | |
# parity signer uses a few: https://github.com/paritytech/parity-signer/blob/master/src/constants/networkSpecs.ts | |
# see the `pathId` variable | |
for i in "" 0 1 2 3 4 polkadot kusama kusama_dev centrifuge edgeware kulupu substrate_dev rococo westend | |
do subkey inspect --network $NETWORK "$SECRET//$i///$PASSWORD"; | |
done | grep -B4 $ADDRESS | |
for i in "" 0 1 2 3 4 polkadot kusama kusama_dev centrifuge edgeware kulupu substrate_dev rococo westend | |
do for j in 0 1 2 3 4; | |
do subkey inspect --network polkadot "$SECRET//$i//$j///$PASSWORD" | |
done | |
done | grep -B4 $ADDRESS | |
for i in "" 0 1 2 3 4 polkadot kusama kusama_dev centrifuge edgeware kulupu substrate_dev rococo westend | |
do for j in 0 1 2 3 4 | |
do for k in 0 1 2 3 4 | |
do subkey inspect --network $NETWORK "$SECRET//$i//$j//$k///$PASSWORD" | |
done | |
done | |
done | grep -B4 $ADDRESS | |
# Get more help if needed | |
echo "------------------------------" | |
echo "Search Complete! If nothing found above, try to edit the script for various other derivation paths." | |
echo "Need more help? Look for support: https://support.polkadot.network/support/home" | |
echo "------------------------------" | |
echo "BE SURE TO CLEAR YOUR BASH HISTORY NOW!!! run:" | |
echo "history -c" | |
echo "More infor here: https://linuxhint.com/clear_bash_history/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment