Skip to content

Instantly share code, notes, and snippets.

@cardano-apexpool
Last active May 29, 2023 18:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save cardano-apexpool/99784308812bdf7aa01446fa95f47fd2 to your computer and use it in GitHub Desktop.
Save cardano-apexpool/99784308812bdf7aa01446fa95f47fd2 to your computer and use it in GitHub Desktop.
Extract the keys from the mnemonic for a Cardano wallet
#!/bin/bash
# For mainnet
NET="mainnet"
NET_WITH_PREFIX="--mainnet"
# For preprod
#NET="testnet"
#NET_WITH_PREFIX="--testnet-magic 1"
# For preview
#NET="testnet"
#NET_WITH_PREFIX="--testnet-magic 2"
ADDR_COUNT=1
umask 277
# Recover existing wallet
#echo "your wallet 24 words" > phrase.prv
# or create a new wallet
cardano-address recovery-phrase generate > phrase.prv
umask 077
cat phrase.prv | cardano-address key from-recovery-phrase Shelley > rootkey.prv
# cat rootkey.prv | cardano-address key public --with-chain-code > rootkey.pub
cat rootkey.prv | cardano-address key child 1852H/1815H/0H/2/0 > stake.prv
cat stake.prv | cardano-address key public --with-chain-code | cardano-address address stake --network-tag ${NET} > stake.addr
cardano-cli key convert-cardano-address-key --signing-key-file stake.prv --shelley-stake-key --out-file stake.skey
cardano-cli key verification-key --signing-key-file stake.skey --verification-key-file Ext_ShelleyStake.vkey
cardano-cli key non-extended-key --extended-verification-key-file Ext_ShelleyStake.vkey --verification-key-file stake.vkey
cardano-cli stake-address build --stake-verification-key-file stake.vkey --out-file stake.addr ${NET_WITH_PREFIX}
rm Ext_ShelleyStake.vkey stake.prv
for NR in $(seq 0 $(expr $ADDR_COUNT - 1))
do
cat rootkey.prv | cardano-address key child 1852H/1815H/0H/0/${NR} > addr-${NR}.prv
cat addr-${NR}.prv | cardano-address key public --with-chain-code | cardano-address address payment --network-tag ${NET} > payment-short-${NR}.addr
cardano-cli key convert-cardano-address-key --signing-key-file addr-${NR}.prv --shelley-payment-key --out-file payment-${NR}.skey
cardano-cli key verification-key --signing-key-file payment-${NR}.skey --verification-key-file Ext_ShelleyPayment-${NR}.vkey
cardano-cli key non-extended-key --extended-verification-key-file Ext_ShelleyPayment-${NR}.vkey --verification-key-file payment-${NR}.vkey
cardano-cli address build --payment-verification-key-file payment-${NR}.vkey --stake-verification-key-file stake.vkey --out-file payment-${NR}.addr ${NET_WITH_PREFIX}
rm Ext_ShelleyPayment-${NR}.vkey addr-${NR}.prv
done
rm rootkey.prv
@Wolfy18
Copy link

Wolfy18 commented Nov 8, 2022

Beautiful! I do have a question about the last line where the script deletes the Ext_ShelleyStake.vkey and stake.prv. Why are we doing this? I'm sure there's a security reason for this last step.

@cardano-apexpool
Copy link
Author

The .vkey is not needed anymore, and the .prv file is deleted for security reasons.

@Wolfy18
Copy link

Wolfy18 commented Nov 8, 2022

Awesome thank you! 🙏🏽

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment