Skip to content

Instantly share code, notes, and snippets.

@daniel12fsp
Last active January 31, 2021 23:07
Show Gist options
  • Save daniel12fsp/f0758b874daa15e9fc1b7c45c57ae927 to your computer and use it in GitHub Desktop.
Save daniel12fsp/f0758b874daa15e9fc1b7c45c57ae927 to your computer and use it in GitHub Desktop.
wallet_bash_generator
#Generate random bitcoin address
## based from https://gist.github.com/gadiener/ebec8b39b15293fbc438b2d21b211dfe
## https://medium.com/coinmonks/how-to-generate-a-bitcoin-address-step-by-step-9d7fcbf1ad0b
PRIVATE_KEY="ECDSA"
PUBLIC_KEY="ECDSA.pub"
BITCOIN_PRIVATE_KEY="bitcoin"
BITCOIN_PUBLIC_KEY="bitcoin.pub"
# make seed from string
# echo "this is a group of words that should not be considered random anymore so never use this to generate a private key" | openssl sha256
echo "Generating private key"
openssl ecparam -genkey -name secp256k1 -rand /dev/random -out $PRIVATE_KEY
echo "Generating public key"
openssl ec -in $PRIVATE_KEY -pubout -out $PUBLIC_KEY
echo "Generating Bitcoin private key"
openssl ec -in $PRIVATE_KEY -outform DER|tail -c +8|head -c 32|xxd -p -c 32 > $BITCOIN_PRIVATE_KEY
echo "Generating Bitcoin public key"
openssl ec -in $PRIVATE_KEY -pubout -outform DER|tail -c 65|xxd -p -c 65 > $BITCOIN_PUBLIC_KEY
uncompressed_public_key=`cat $BITCOIN_PUBLIC_KEY`
compressed_public_key=`python -c "print(('02' if int('$uncompressed_public_key'[-1], 16)%2 ==0 else '03') + '$uncompressed_public_key='[2:65+1])"`
sha256=$(echo $compressed_public_key | xxd -r -p | openssl sha256 | awk '{print $2}')
ripem160=$(echo $sha256 | xxd -r -p | openssl ripemd160 | awk '{print $2}')
address=`echo "00$ripem160" | xxd -p -r | base58 -c && echo`
echo "bitcoin wallet: $address"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment