Skip to content

Instantly share code, notes, and snippets.

@jakehemmerle
Created May 28, 2021 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakehemmerle/85cb78696e706de97e7339c60c629718 to your computer and use it in GitHub Desktop.
Save jakehemmerle/85cb78696e706de97e7339c60c629718 to your computer and use it in GitHub Desktop.
tests to make sure that subkey keygen generates same keys from the same seedphrase
#!/bin/bash
compare_strings() {
if [ "$1" == "$2" ]; then
:
else
echo "wtf! some values that should match dont match"
echo "values:"
echo $1
echo $2
exit
fi
}
echo "Starting key generation and comparison..."
counter=1
until [ $counter -lt 0 ]
do
echo $counter
# generate new seed phrase
genData=$(./subkey generate)
seedPhrase=$(echo $genData | awk '{print $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14}' | sed -e "s/\`//g")
seed=$(echo $genData | awk '{print $19}')
pubKeyHex=$(echo $genData | awk '{print $23}')
pubKeySs58=$(echo $genData | awk '{print $27}')
accountId=$(echo $genData | awk '{print $30}')
Ss58=$(echo $genData | awk '{print $33}')
# regenerate keys from seed phrase
inspectData=$(./subkey inspect "${seedPhrase}")
generatedSeed=$(echo $inspectData | awk '{print $19}')
generatedPubKeyHex=$(echo $inspectData | awk '{print $23}')
generatedPubKeySs58=$(echo $inspectData | awk '{print $27}')
generatedAccountId=$(echo $inspectData | awk '{print $30}')
generatedSs58=$(echo $inspectData | awk '{print $33}')
# compare string against their own strings
compare_strings $pubKeyHex $accountId
compare_strings $pubKeySs58 $Ss58
compare_strings $generatedPubKeyHex $generatedAccountId
compare_strings $generatedPubKeySs58 $generatedSs58
# compare strings against initially and regenerated strings
compare_strings $seed $generatedSeed
compare_strings $pubKeyHex $generatedPubKeyHex
compare_strings $pubKeySs58 $generatedPubKeySs58
compare_strings $accountId $generatedAccountId
compare_strings $Ss58 $generatedSs58
((counter++))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment