#Display usage instructions
-
Usage: $(basename $0) new <voteKeyName> ... Generates a new VotingKeyPair with the given name
-
$(basename $0) new myvote ... Generates a new VotingKeyPair myvote.voting.skey/pkey
-
$(basename $0) qrcode <voteKeyName> <4-Digit-PinCode> ... Shows the QR code for the Catalyst-App with the given 4-digit PinCode
-
$(basename $0) qrcode myvote 1234 ... Shows the QR code for the VotingKey 'myvote' and protects it with the PinCode '1234'
+
Usage: $(basename $0) new cli <voteKeyName> ... Generates a new 24-Words-Mnemonic and derives the VotingKeyPair with the given name
+
$(basename $0) new cli <voteKeyName> "<24-words-mnenonics>" ... Generates a new VotingKeyPair with the given name from an existing 24-Words-Mnemonic
+
$(basename $0) new hw <voteKeyName> ... Generates a new VotingKeyPair with the given name from a HW-Wallet
-
$(basename $0) genmeta <voteKeyName> <stakeName-to-register> [Optional: <rewardsPayoutStakeAddr>]
-
... Generates the Catalyst-Registration-Metadata(cbor) for the given name, stakeAccountName and optional different rewardsPayoutStakeAddr
+
$(basename $0) genmeta <delegate_to_voteKeyName|voteBechPublicKey> <stakeAccountName> <rewardsPayoutPaymentName or bech adress>
+
... Generates the Catalyst-Registration-Metadata(cbor) to delegate the full VotingPower of the given stakeAccountName to the voteKeyName
+
or votePublicKey, rewards will be paid out to the rewardsPayoutPaymentName
-
$(basename $0) genmeta myvote owner
-
... Generates the Catalyst-Registration-Metadata(cbor) for the myvote VotingKey, amountToRegister via owner.staking,
-
RewardsPayout to the Address owner.staking.addr. With HW-Wallets, the RewardsPayout-Addr must be one of the HW-Wallet itself!
+
$(basename $0) genmeta "<delegate_to_voteKeyName|voteBechPublicKey> <weight>|..." <stakeAccountName> <rewardsPayoutPaymentName or bech adress>
+
... Generates the Catalyst-Registration-Metadata(cbor) to delegate to multiple voteKeyNames or votePublicKeys with the given amount of weight,
+
rewards will be paid out to the rewardsPayoutPaymentName. The weight values are relative ones to each other.
+
$(basename $0) qrcode <voteKeyName> <4-Digit-PinCode> ... Shows the QR code for the Catalyst-Voting-App protected via a 4-digit PinCode
+
$(basename $0) new cli myvote
+
... Generates a new VotingKeyPair myvote.voting.skey/vkey, writes Mnemonics to myvote.voting.mnemonics
$(basename $0) genmeta myvote owner myrewards
-
... Generates the Catalyst-Registration-Metadata(cbor) for the myvote VotingKey, amountToRegister via owner.staking,
-
RewardsPayout to the Address myrewards.payment.addr. With HW-Wallets, the RewardsPayout-Addr must be one of the HW-Wallet itself!
+
... Generates the Catalyst-Registration-Metadata(cbor) to delegate the full VotingPower of owner.staking to the myvote.voting votePublicKey,
+
VotingRewards payout to the Address myrewards.addr.
+
$(basename $0) qrcode myvote 1234
+
... Shows the QR code for the VotingKey 'myvote' and protects it with the PinCode '1234'. This QR code can be scanned
+
with the Catalyst-Voting-App on your mobile phone if you don't wanna use the Catalyst-Voting-Center
-
if ! exists "${jcli_bin}"; then
-
#Try the one in the scripts folder
-
if [[ -f "${scriptDir}/jcli" ]]; then jcli_bin="${scriptDir}/jcli";
-
else majorError "Path ERROR - Path to the 'jcli' binary is not correct or 'jcli' binaryfile is missing!\nYou can find it here: https://github.com/input-output-hk/jormungandr/releases \nThis is needed to generate the Voting Keys. Please check your 00_common.sh or common.inc settings."; exit 1; fi
-
jcliCheck=$(${jcli_bin} --version 2> /dev/null)
-
if [[ $? -ne 0 ]]; then echo -e "\e[35mERROR - This script needs a working 'jcli' binary. Please make sure you have it present with with the right path in '00_common.sh' !\e[0m\n\n"; exit 1; fi
-
jcliVersion=$(echo ${jcliCheck} | cut -d' ' -f 2)
-
if ! exists "${catalyst_toolbox_bin}"; then
-
#Try the one in the scripts folder
-
if [[ -f "${scriptDir}/catalyst-toolbox" ]]; then catalyst_toolbox_bin="${scriptDir}/catalyst-toolbox";
-
else majorError "Path ERROR - Path to the 'catalyst-toolbox' binary is not correct or 'catalyst-toolbox' binaryfile is missing!\nYou can find it here: https://github.com/input-output-hk/catalyst-toolbox/releases/latest \nThis is needed to generate the QR code for the Catalyst-App. Please check your 00_common.sh or common.inc settings."; exit 1; fi
-
catalystToolboxCheck=$(${catalyst_toolbox_bin} --version 2> /dev/null)
-
if [[ $? -ne 0 ]]; then echo -e "\e[35mERROR - This script needs a working 'catalyst-toolbox' binary. Please make sure you have it present with with the right path in '00_common.sh' !\e[0m\n\n"; exit 1; fi
-
catalystToolboxVersion=$(echo ${catalystToolboxCheck} | cut -d' ' -f 2)
+
accountNo=0 #set default accountNo
+
indexNo=0 #set default indexNo
+
payPath=0 #set default paymentPath
################################################
# Check commandline parameters
-
if [[ $# -eq 0 ]]; then $(showUsage); exit 1; fi
+
if [[ ${paramCnt} -lt 3 ]]; then showUsage; exit 1; fi
+
### Generate the QR code from the vote secret key for the mobile voting app
-
if [[ $# -eq 3 ]]; then voteKeyName="${2}"; voteKeyName=${voteKeyName/#.\//}; pinCode="${3}"; else echo -e "\e[35mMissing parameters!\e[0m\n"; showUsage; exit 1; fi
-
if [ ! -f "${voteKeyName}.voting.skey" ]; then echo -e "\e[35mError - ${voteKeyName}.voting.skey is missing, please generate it first with the subcommand 'new' !\e[0m\n"; showUsage; exit 1; fi
-
if [ -z "${pinCode##*[!0-9]*}" ] || [ ${#pinCode} -lt 4 ] || [ ${pinCode} -lt 0 ] || [ ${pinCode} -gt 9999 ]; then echo -e "\e[35mError - The PinCode must be a 4-Digit-Number between 0000 and 9999 !\e[0m\n"; exit 1; fi
-
if [ -f "${voteKeyName}.catalyst-qrcode.png" ]; then echo -e "\e[35mError - ${voteKeyName}.catalyst-qrcode.png already exists, please delete it first if you wanna overwrite it !\e[0m\n"; exit 1; fi
-
echo -e "\e[0mCatalyst-Toolbox-Version: \e[32m${catalystToolboxVersion}\e[0m"
-
echo -e "\e[0mGenerating the Catalyst-APP QR Code for the Voting-Signing-Key: \e[32m${voteKeyName}.voting.skey\e[0m"
+
#Check the catalyst-toolbox binary existance and version
+
if ! exists "${catalyst_toolbox_bin}"; then
+
#Try the one in the scripts folder
+
if [[ -f "${scriptDir}/catalyst-toolbox" ]]; then catalyst_toolbox_bin="${scriptDir}/catalyst-toolbox";
+
else majorError "Path ERROR - Path to the 'catalyst-toolbox' binary is not correct or 'catalyst-toolbox' binaryfile is missing!\nYou can find it here: https://github.com/input-output-hk/catalyst-toolbox/releases/latest \nThis is needed to generate the QR code for the Catalyst-App. Also please check your 00_common.sh or common.inc settings."; exit 1; fi
+
catalystToolboxCheck=$(${catalyst_toolbox_bin} --version 2> /dev/null)
+
if [[ $? -ne 0 ]]; then echo -e "\e[35mERROR - This script needs a working 'catalyst-toolbox' binary. Please make sure you have it present with with the right path in '00_common.sh' !\e[0m\n\n"; exit 1; fi
+
catalystToolboxVersion=$(echo ${catalystToolboxCheck} | cut -d' ' -f 2)
+
versionCheck "${minCatalystToolboxVersion}" "${catalystToolboxVersion}"
+
if [[ $? -ne 0 ]]; then majorError "Version ${catalystToolboxVersion} ERROR - Please use a cardano-toolbox version ${minCatalystToolboxVersion} or higher !\nOld versions are not compatible, please upgrade - thx."; exit 1; fi
+
voteKeyName="${allParameters[1]}"; voteKeyName=${voteKeyName/#.\//};
+
pinCode="${allParameters[2]}";
+
if [ ! -f "${voteKeyName}.voting.skey" ]; then echo -e "\e[35mError - ${voteKeyName}.voting.skey is missing, please generate it first with the subcommand 'new' !\e[0m\n"; showUsage; exit 1; fi
+
if [ -z "${pinCode##*[!0-9]*}" ] || [ ${#pinCode} -lt 4 ] || [ ${pinCode} -lt 0 ] || [ ${pinCode} -gt 9999 ]; then echo -e "\e[35mError - The PinCode must be a 4-Digit-Number between 0000 and 9999 !\e[0m\n"; exit 1; fi
+
if [ -f "${voteKeyName}.catalyst-qrcode.png" ]; then echo -e "\e[35mError - ${voteKeyName}.catalyst-qrcode.png already exists, please delete it first if you wanna overwrite it !\e[0m\n"; exit 1; fi
+
echo -e "\e[0mGenerating the Catalyst-Voting-App QR Code for the Voting-Signing-Key: \e[32m${voteKeyName}.voting.skey\e[0m"
echo -e "\e[0mYour Pin-Code for the Catalyst-APP: \e[32m${pinCode}\e[0m"
-
tmp=$(${catalyst_toolbox_bin} qr-code --pin ${pinCode} --input ${voteKeyName}.voting.skey --output ${voteKeyName}.catalyst-qrcode.png img)
-
checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi
-
file_lock ${voteKeyName}.voting.skey
-
echo -e "\e[0mCatalyst-QR-Code: \e[32m ${voteKeyName}.catalyst-qrcode.png \e[0m"
-
${catalyst_toolbox_bin} qr-code --pin ${pinCode} --input ${voteKeyName}.voting.skey img
+
#Read in the ${voteKeyName}.voting.skey and check that it is a valid json keyfile with a key in the cborHex entry and not the old bech format
+
skeyJSON=$(read_skeyFILE "${voteKeyName}.voting.skey"); if [ $? -ne 0 ]; then echo -e "\e[35m${skeyJSON}\e[0m\n"; exit 1; else echo -e "\e[32mOK\e[0m\n"; fi
+
cborVoteKey=$(jq -r ".cborHex" <<< "${skeyJSON}" 2> /dev/null);
+
if [[ $? -ne 0 ]]; then echo -e "\e[35mERROR - ${voteKeyName}.voting.skey is not a valid json file. Please make sure to use the new voting key format, you can generate it with the subcommand 'new' !\e[0m\n\n"; exit 1; fi
+
#Generate the voting key bech format for catalyst toolbox
+
bechVoteKey=$(cut -c 5-132 <<< ${cborVoteKey} | ${bech32_bin} "ed25519e_sk" 2> /dev/null)
+
checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi
-
if [[ $# -eq 2 ]]; then voteKeyName="${2}"; voteKeyName=${voteKeyName/#.\//}; else echo -e "\e[35mMissing parameters!\e[0m\n"; showUsage; exit 1; fi
-
if [ -f "${voteKeyName}.voting.skey" ]; then echo -e "\e[35mError - ${voteKeyName}.voting.skey already exists, please delete it first if you wanna overwrite it !\e[0m\n"; exit 1; fi
-
if [ -f "${voteKeyName}.voting.pkey" ]; then echo -e "\e[35mError - ${voteKeyName}.voting.pkey already exists, please delete it first if you wanna overwrite it !\e[0m\n"; exit 1; fi
-
echo -e "\e[0mJCLI-Version: \e[32m${jcliVersion}\e[0m"
-
echo -e "\e[0mGenerating a new Voting-KeyPair with the name: \e[32m${voteKeyName}\e[0m"
+
#Generate the QR code by passing on the bechVoteKey "as a file" to catalyst toolbox
+
echo -e "\e[0mGenerating with Cardano-Toolbox Version: \e[32m${catalystToolboxVersion}\e[0m\n";
+
tmp=$(${catalyst_toolbox_bin} qr-code encode --pin ${pinCode} --input <(echo -n ${bechVoteKey}) --output ${voteKeyName}.catalyst-qrcode.png img)
+
checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi
+
file_lock ${voteKeyName}.voting.skey
+
echo -e "\e[0mCatalyst-QR-Code: \e[32m ${voteKeyName}.catalyst-qrcode.png \e[0m"
+
${catalyst_toolbox_bin} qr-code encode --pin ${pinCode} --input <(echo -n ${bechVoteKey}) img
-
tmp=$(${jcli_bin} key generate --type ed25519extended 2> /dev/null > ${voteKeyName}.voting.skey)
-
checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi
-
file_lock ${voteKeyName}.voting.skey
-
echo -e "\e[0mVoting-Signing-Key: \e[32m ${voteKeyName}.voting.skey \e[90m"
-
cat ${voteKeyName}.voting.skey
+
echo -e "\e[33mIf you use this QR code with the Catalyst-Voting-App, please only vote with the Catalyst-Voting-App and not also with the Catalyst-Voting-Center. Thx!\e[0m\n";
-
tmp=$(${jcli_bin} key to-public 2> /dev/null < ${voteKeyName}.voting.skey > ${voteKeyName}.voting.pkey)
-
checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi
-
file_lock ${voteKeyName}.voting.pkey
-
echo -e "\e[0mVoting-Public-Key: \e[32m ${voteKeyName}.voting.pkey \e[90m"
-
cat ${voteKeyName}.voting.pkey
-
if [[ $# -eq 3 ]]; then #rewardsAccount is the same as the voting account
-
voteKeyName="${2}"; voteKeyName=${voteKeyName/#.\//};
-
stakeAddr="$(dirname $3)/$(basename $(basename $3 .addr) .staking).staking"; stakeAddr=${stakeAddr/#.\//};
-
rewardsAddr=${stakeAddr}
-
elif [[ $# -eq 4 ]]; then #rewardsAccount is a separate one account
-
voteKeyName="${2}"; voteKeyName=${voteKeyName/#.\//};
-
stakeAddr="$(dirname $3)/$(basename $(basename $3 .addr) .staking).staking"; stakeAddr=${stakeAddr/#.\//};
-
rewardsAddr="$(dirname $4)/$(basename $(basename $4 .addr) .staking).staking"; rewardsAddr=${rewardsAddr/#.\//};
-
else echo -e "\e[35mMissing parameters!\e[0m\n"; showUsage; exit 1; fi
-
if [ ! -f "${voteKeyName}.voting.pkey" ]; then echo -e "\e[35mError - ${voteKeyName}.voting.pkey is missing, please generate it first with the subcommand 'new' !\e[0m\n"; showUsage; exit 1; fi
-
if [ ! -f "${voteKeyName}.voting.skey" ]; then echo -e "\e[35mError - ${voteKeyName}.voting.skey is missing, please generate it first with the subcommand 'new' !\e[0m\n"; showUsage; exit 1; fi
-
if ! [[ -f "${stakeAddr}.skey" || -f "${stakeAddr}.hwsfile" ]]; then echo -e "\n\e[35mERROR - \"${stakeAddr}.skey(hwsfile)\" Staking Signing Key or HardwareFile does not exist! Please create it first with script 03a.\e[0m"; exit 1; fi
-
if ! [[ -f "${rewardsAddr}.skey" || -f "${rewardsAddr}.hwsfile" ]]; then echo -e "\n\e[35mERROR - \"${rewardsAddr}.skey(hwsfile)\" does not exist! Please create it first with script 03a or 02.\e[0m"; exit 1; fi
-
if [ ! -f "${rewardsAddr}.addr" ]; then echo -e "\n\e[35mERROR - \"${rewardsAddr}.addr\" does not exist! Please create it first with script 03a.\e[0m"; exit 1; fi
+
### Generate new Voting Keys
+
if [[ ${paramCnt} -ge 3 ]]; then
+
method="${allParameters[1]}";
+
voteKeyName="${allParameters[2]}"; voteKeyName=${voteKeyName/#.\//};
+
else echo -e "\e[35mMissing parameters!\e[0m\n"; showUsage; exit 1; fi