Skip to content

Commit 46040b7

Browse files
committed
New features - Mnemonic wallet, Messages, Metadata
Generating Base/Staking-Keys with/from Mnemonics has been added to the script: - 03a_genStakingPaymentAddr.sh So you can now generate a set of Base(Payment)- and Staking-Keys derived from 24-Word Mnemonics. If Mnemonics are provided they are used, otherwise new ones are created. This makes it easier to use keys across the CLI and other wallets like Daedalus, Eternl, Typhoon, ... --- Sending transaction messages including the option to encrypt the messages (CIP-0083) has been added to the following scripts: - 03b_regStakingAddrCert.sh - 05c_regStakepoolCert.sh - 05d_poolWitness.sh - 06_regDelegationCert.sh - 07b_deregStakepoolCert.sh - 08b_deregStakingAddrCert.sh --- Attaching transaction metadata as *.json and *.cbor file has been added to the following scripts: - 03b_regStakingAddrCert.sh - 05c_regStakepoolCert.sh - 05d_poolWitness.sh - 06_regDelegationCert.sh - 07b_deregStakepoolCert.sh - 08b_deregStakingAddrCert.sh So you can now add a comment or an encrypted message or metadata to every transaction that is possible via the StakepoolOperatorScripts.
1 parent 97bdc70 commit 46040b7

8 files changed

+1048
-100
lines changed

cardano/mainnet/00_common.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ case "${network,,}" in
180180
_transactionExplorer="https://preview.cardanoscan.io/transaction"
181181
_koiosAPI="https://preview.koios.rest/api/v0"
182182
_adahandlePolicyID="f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a" #PolicyIDs for the adaHandles -> autoresolve into ${adahandlePolicyID}
183-
_catalystAPI="https://api.testnet.projectcatalyst.io/api/v1" #Catalyst-API URLs -> autoresolve into ${catalystAPI}
183+
_catalystAPI= #Catalyst-API URLs -> autoresolve into ${catalystAPI}
184184
;;
185185

186186

@@ -203,7 +203,7 @@ case "${network,,}" in
203203
_addrformat="--testnet-magic 1097911063"
204204
_byronToShelleyEpochs=74
205205
_tokenMetaServer="https://metadata.cardano-testnet.iohkdev.io/metadata"
206-
_transactionExplorer="https://testnet.cexplorer.io/tx"
206+
_transactionExplorer=
207207
_koiosAPI=
208208
_adahandlePolicyID="8d18d786e92776c824607fd8e193ec535c79dc61ea2405ddf3b09fe3"
209209
_catalystAPI= #Catalyst-API URLs -> autoresolve into ${catalystAPI}

cardano/mainnet/03a_genStakingPaymentAddr.sh

+166-26
Large diffs are not rendered by default.

cardano/mainnet/03b_regStakingAddrCert.sh

+152-12
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,160 @@
66
. "$(dirname "$0")"/00_common.sh
77

88

9-
case $# in
10-
2 ) stakeAddr="$(dirname $1)/$(basename $1 .staking).staking"; stakeAddr=${stakeAddr/#.\//};
11-
fromAddr="$(dirname $2)/$(basename $2 .addr)"; fromAddr=${fromAddr/#.\//};;
12-
* ) cat >&2 <<EOF
9+
#Check command line parameter
10+
if [ $# -lt 2 ]; then
11+
cat >&2 <<EOF
12+
1313
Usage: $(basename $0) <StakeAddressName> <Base/PaymentAddressName (paying for the registration fees)>
14-
Example: $(basename $0) atada.staking atada.payment
14+
15+
[Opt: Message comment, starting with "msg: ...", | is the separator]
16+
[Opt: encrypted message mode "enc:basic". Currently only 'basic' mode is available.]
17+
[Opt: passphrase for encrypted message mode "pass:<passphrase>", the default passphrase if 'cardano' is not provided]
18+
19+
Optional parameters:
20+
21+
- If you wanna attach a Transaction-Message like a short comment, invoice-number, etc with the transaction:
22+
You can just add one or more Messages in quotes starting with "msg: ..." as a parameter. Max. 64chars / Message
23+
"msg: This is a short comment for the transaction" ... that would be a one-liner comment
24+
"msg: This is a the first comment line|and that is the second one" ... that would be a two-liner comment, | is the separator !
25+
26+
If you also wanna encrypt it, set the encryption mode to basic by adding "enc: basic" to the parameters.
27+
To change the default passphrase 'cardano' to you own, add the passphrase via "pass:<passphrase>"
28+
29+
- If you wanna attach a Metadata JSON:
30+
You can add a Metadata.json (Auxilierydata) filename as a parameter to send it alone with the transaction.
31+
There will be a simple basic check that the transaction-metadata.json file is valid.
32+
33+
- If you wanna attach a Metadata CBOR:
34+
You can add a Metadata.cbor (Auxilierydata) filename as a parameter to send it along with the transaction.
35+
Catalyst-Voting for example is done via the voting_metadata.cbor file.
36+
37+
Examples:
38+
39+
$(basename $0) myWallet.staking myWallet.payment
40+
-> Register the myWallet StakeKey on Chain, Payment via the myWallet.paymet wallet
41+
42+
$(basename $0) myWallet.staking myWallet.payment "msg: StakeKey Registration for myWallet"
43+
-> Register the myWallet StakeKey on Chain, Payment via the myWallet.paymet wallet, Adding a Transaction-Message
44+
1545
EOF
16-
exit 1;; esac
46+
exit 1;
47+
fi
48+
49+
#At least 2 parameters were provided, use them
50+
stakeAddr="$(dirname $1)/$(basename $1 .staking).staking"; stakeAddr=${stakeAddr/#.\//};
51+
fromAddr="$(dirname $2)/$(basename $2 .addr)"; fromAddr=${fromAddr/#.\//};
1752

1853
#Check about required files: Registration Certificate, Signing Key and Address of the payment Account
1954
#For StakeKeyRegistration
2055
if [ ! -f "${stakeAddr}.cert" ]; then echo -e "\n\e[35mERROR - \"${stakeAddr}.cert\" Registration Certificate does not exist! Please create it first with script 03a.\e[0m"; exit 2; fi
2156
if [ ! -f "${stakeAddr}.addr" ]; then echo -e "\n\e[35mERROR - \"${stakeAddr}.addr\" Stake Address file does not exist! Please create it first with script 03a.\e[0m"; exit 2; fi
22-
#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 2; fi
23-
2457
#For payment
2558
if [ ! -f "${fromAddr}.addr" ]; then echo -e "\n\e[35mERROR - \"${fromAddr}.addr\" does not exist! Please create it first with script 03a or 02.\e[0m"; exit 1; fi
2659
if ! [[ -f "${fromAddr}.skey" || -f "${fromAddr}.hwsfile" ]]; then echo -e "\n\e[35mERROR - \"${fromAddr}.skey/hwsfile\" does not exist! Please create it first with script 03a or 02.\e[0m"; exit 1; fi
2760

2861

62+
63+
64+
#Setting default variables
65+
metafileParameter=""; metafile=""; transactionMessage="{}"; enc=""; passphrase="cardano" #Setting defaults
66+
67+
#Check all optional parameters about there types and set the corresponding variables
68+
#Starting with the 3th parameter (index=2) up to the last parameter
69+
paramCnt=$#;
70+
allParameters=( "$@" )
71+
for (( tmpCnt=2; tmpCnt<${paramCnt}; tmpCnt++ ))
72+
do
73+
paramValue=${allParameters[$tmpCnt]}
74+
#echo -n "${tmpCnt}: ${paramValue} -> "
75+
76+
#Check if an additional metadata.json/.cbor was set as parameter (not a Message, not a UTXO#IDX, not empty, not a number)
77+
if [[ ! "${paramValue,,}" =~ ^msg:(.*)$ ]] && [[ ! "${paramValue,,}" =~ ^enc:(.*)$ ]] && [[ ! "${paramValue,,}" =~ ^pass:(.*)$ ]] && [[ ! "${paramValue,,}" =~ ^utxolimit:(.*)$ ]] && [[ ! "${paramValue,,}" =~ ^onlyutxowithasset:(.*)$ ]] && [[ ! "${paramValue,,}" =~ ^skiputxowithasset:(.*)$ ]] && [[ ! "${paramValue}" =~ ^([[:xdigit:]]+#[[:digit:]]+(\|?)){1,}$ ]] && [[ ! ${paramValue} == "" ]] && [ -z "${paramValue##*[!0-9]*}" ]; then
78+
79+
metafile=${paramValue}; metafileExt=${metafile##*.}
80+
if [[ -f "${metafile}" && "${metafileExt^^}" == "JSON" ]]; then #its a json file
81+
#Do a simple basic check if the metadatum is in the 0..65535 range
82+
metadatum=$(jq -r "keys_unsorted[0]" "${metafile}" 2> /dev/null)
83+
if [[ $? -ne 0 ]]; then echo -e "\n\e[35mERROR - '${metafile}' is not a valid JSON file!\n\e[0m"; exit 1; fi
84+
#Check if it is null, a number, lower then zero, higher then 65535, otherwise exit with an error
85+
if [ "${metadatum}" == null ] || [ -z "${metadatum##*[!0-9]*}" ] || [ "${metadatum}" -lt 0 ] || [ "${metadatum}" -gt 65535 ]; then
86+
echo -e "\n\e[35mERROR - MetaDatum Value '${metadatum}' in '${metafile}' must be in the range of 0..65535!\n\e[0m"; exit 1; fi
87+
metafileParameter="${metafileParameter}--metadata-json-file ${metafile} "; metafileList="${metafileList}'${metafile}' "
88+
elif [[ -f "${metafile}" && "${metafileExt^^}" == "CBOR" ]]; then #its a cbor file
89+
metafileParameter="${metafileParameter}--metadata-cbor-file ${metafile} "; metafileList="${metafileList}'${metafile}' "
90+
else echo -e "\n\e[35mERROR - The specified Metadata JSON/CBOR-File '${metafile}' does not exist. Fileextension must be '.json' or '.cbor' Please try again.\n\e[0m"; exit 1;
91+
fi
92+
93+
#Check it its a MessageComment. Adding it to the JSON array if the length is <= 64 chars
94+
elif [[ "${paramValue,,}" =~ ^msg:(.*)$ ]]; then #if the parameter starts with "msg:" then add it
95+
msgString=$(trimString "${paramValue:4}");
96+
97+
#Split the messages within the parameter at the "|" char
98+
IFS='|' read -ra allMessages <<< "${msgString}"
99+
100+
#Add each message to the transactionMessage JSON
101+
for (( tmpCnt2=0; tmpCnt2<${#allMessages[@]}; tmpCnt2++ ))
102+
do
103+
tmpMessage=${allMessages[tmpCnt2]}
104+
if [[ $(byteLength "${tmpMessage}") -le 64 ]]; then
105+
transactionMessage=$( jq ".\"674\".msg += [ \"${tmpMessage}\" ]" <<< ${transactionMessage} 2> /dev/null);
106+
if [ $? -ne 0 ]; then echo -e "\n\e[35mMessage-Adding-ERROR: \"${tmpMessage}\" contain invalid chars for a JSON!\n\e[0m"; exit 1; fi
107+
else echo -e "\n\e[35mMessage-Adding-ERROR: \"${tmpMessage}\" is too long, max. 64 bytes allowed, yours is $(byteLength "${tmpMessage}") bytes long!\n\e[0m"; exit 1;
108+
fi
109+
done
110+
111+
#Check if its a transaction message encryption type
112+
elif [[ "${paramValue,,}" =~ ^enc:(.*)$ ]]; then #if the parameter starts with "enc:" then set the encryption variable
113+
encryption=$(trimString "${paramValue:4}");
114+
115+
#Check if its a transaction message encryption passphrase
116+
elif [[ "${paramValue,,}" =~ ^pass:(.*)$ ]]; then #if the parameter starts with "pass:" then set the passphrase variable
117+
passphrase="${paramValue:5}"; #don't do a trimstring here, because also spaces are a valid passphrase !
118+
119+
fi #end of different parameters check
120+
121+
done
122+
123+
#Check if there are transactionMessages, if so, save the messages to a xxx.transactionMessage.json temp-file and add it to the list. Encrypt it if enabled.
124+
if [[ ! "${transactionMessage}" == "{}" ]]; then
125+
126+
transactionMessageMetadataFile="${tempDir}/$(basename ${fromAddr}).transactionMessage.json";
127+
tmp=$( jq . <<< ${transactionMessage} 2> /dev/null)
128+
if [ $? -eq 0 ]; then #json is valid, so no bad chars found
129+
130+
#Check if encryption is enabled, encrypt the msg part
131+
if [[ "${encryption,,}" == "basic" ]]; then
132+
#check openssl
133+
if ! exists openssl; then echo -e "\e[33mYou need 'openssl', its needed to encrypt the transaction messages !\n\nInstall it on Ubuntu/Debian like:\n\e[97msudo apt update && sudo apt -y install openssl\n\n\e[33mThx! :-)\e[0m\n"; exit 2; fi
134+
msgPart=$( jq -crM ".\"674\".msg" <<< ${transactionMessage} 2> /dev/null )
135+
checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi
136+
encArray=$( openssl enc -e -aes-256-cbc -pbkdf2 -iter 10000 -a -k "${passphrase}" <<< ${msgPart} | awk {'print "\""$1"\","'} | sed '$ s/.$//' )
137+
checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi
138+
#compose new transactionMessage by using the encArray as the msg and also add the encryption mode 'basic' entry
139+
tmp=$( jq ".\"674\".msg = [ ${encArray} ]" <<< '{"674":{"enc":"basic"}}' )
140+
checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi
141+
142+
elif [[ "${encryption}" != "" ]]; then #another encryption method provided
143+
echo -e "\n\e[35mERROR - The given encryption mode '${encryption,,}' is not on the supported list of encryption methods. Only 'basic' from CIP-0083 is currently supported\n\n\e[0m"; exit 1;
144+
fi
145+
146+
echo "${tmp}" > ${transactionMessageMetadataFile}; metafileParameter="${metafileParameter}--metadata-json-file ${transactionMessageMetadataFile} "; #add it to the list of metadata.jsons to attach
147+
148+
else
149+
echo -e "\n\e[35mERROR - Additional Transaction Message-Metafile is not valid:\n\n$${transactionMessage}\n\nPlease check your added Message-Paramters.\n\e[0m"; exit 1;
150+
fi
151+
152+
fi
153+
154+
155+
156+
29157
echo
30158
echo -e "\e[0mRegister Staking Address\e[32m ${stakeAddr}.addr\e[0m with funds from Address\e[32m ${fromAddr}.addr\e[0m"
31159
echo
32160

33161

162+
34163
checkAddr=$(cat ${stakeAddr}.addr)
35164
typeOfAddr=$(get_addressType "${checkAddr}")
36165

@@ -63,7 +192,6 @@ fi
63192
#get live values
64193
currentTip=$(get_currentTip)
65194
ttl=$(get_currentTTL)
66-
currentEPOCH=$(get_currentEpoch)
67195

68196
echo -e "Current Slot-Height:\e[32m ${currentTip}\e[0m (setting TTL[invalid_hereafter] to ${ttl})"
69197

@@ -119,7 +247,6 @@ echo
119247
utxoHashIndex=${utxoHashIndexArray[${tmpCnt}]}
120248
utxoAmount=${utxoLovelaceArray[${tmpCnt}]} #Lovelaces
121249
totalLovelaces=$(bc <<< "${totalLovelaces} + ${utxoAmount}" )
122-
# echo -e "Hash#Index: ${utxoHashIndex}\tAmount: ${utxoAmount}";
123250
echo -e "Hash#Index: ${utxoHashIndex}\tADA: $(convertToADA ${utxoAmount}) \e[90m(${utxoAmount} lovelaces)\e[0m";
124251
if [[ ! "${utxoDatumHashArray[${tmpCnt}]}" == null ]]; then echo -e " DatumHash: ${utxoDatumHashArray[${tmpCnt}]}"; fi
125252
assetsEntryCnt=${assetsEntryCntArray[${tmpCnt}]}
@@ -207,6 +334,19 @@ echo
207334

208335
echo
209336

337+
#There are metadata file(s) attached, list them:
338+
if [[ ! "${metafileList}" == "" ]]; then echo -e "\e[0mInclude Metadata-File(s):\e[32m ${metafileList}\e[0m\n"; fi
339+
340+
#There are transactionMessages attached, show the metadatafile:
341+
if [[ ! "${transactionMessage}" == "{}" ]]; then
342+
if [[ "${encArray}" ]]; then #if there is an encryption, show the original Metadata first with the encryption paramteters
343+
echo -e "\e[0mOriginal Transaction-Message:\n\e[90m"; jq -rM <<< ${transactionMessage}; echo -e "\e[0m";
344+
echo -e "\e[0mEncrypted Transaction-Message mode \e[32m${encryption,,}\e[0m with Passphrase '\e[32m${passphrase}\e[0m'";
345+
echo
346+
fi
347+
echo -e "\e[0mInclude Transaction-Message-Metadata-File:\e[32m ${transactionMessageMetadataFile}\n\e[90m"; cat ${transactionMessageMetadataFile}; echo -e "\e[0m";
348+
fi
349+
210350
#Read ProtocolParameters
211351
if ${onlineMode}; then
212352
protocolParametersJSON=$(${cardanocli} query protocol-parameters ${magicparam} ); #onlinemode
@@ -222,7 +362,7 @@ minOutUTXO=$(calc_minOutUTXO "${protocolParametersJSON}" "${sendToAddr}+1000000$
222362
txBodyFile="${tempDir}/dummy.txbody"; rm ${txBodyFile} 2> /dev/null
223363
rm ${txBodyFile} 2> /dev/null
224364
#echo -e "${cardanocli} transaction build-raw ${nodeEraParam} ${txInString} --tx-out "${sendToAddr}+1000000${assetsOutString}" --invalid-hereafter ${ttl} --fee 100 --certificate ${stakeAddr}.cert --out-file ${txBodyFile}"
225-
${cardanocli} transaction build-raw ${nodeEraParam} ${txInString} --tx-out "${sendToAddr}+1000000${assetsOutString}" --invalid-hereafter ${ttl} --fee 100 --certificate ${stakeAddr}.cert --out-file ${txBodyFile}
365+
${cardanocli} transaction build-raw ${nodeEraParam} ${txInString} --tx-out "${sendToAddr}+1000000${assetsOutString}" --invalid-hereafter ${ttl} --fee 100 ${metafileParameter} --certificate ${stakeAddr}.cert --out-file ${txBodyFile}
226366
checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi
227367

228368
fee=$(${cardanocli} transaction calculate-min-fee --tx-body-file ${txBodyFile} --protocol-params-file <(echo ${protocolParametersJSON}) --tx-in-count ${txcnt} --tx-out-count ${rxcnt} ${magicparam} --witness-count 1 --byron-witness-count 0 | awk '{ print $1 }')
@@ -255,7 +395,7 @@ echo
255395

256396
#Building unsigned transaction body
257397
rm ${txBodyFile} 2> /dev/null
258-
${cardanocli} transaction build-raw ${nodeEraParam} ${txInString} --tx-out "${sendToAddr}+${lovelacesToSend}${assetsOutString}" --invalid-hereafter ${ttl} --fee ${fee} --certificate ${stakeAddr}.cert --out-file ${txBodyFile}
398+
${cardanocli} transaction build-raw ${nodeEraParam} ${txInString} --tx-out "${sendToAddr}+${lovelacesToSend}${assetsOutString}" --invalid-hereafter ${ttl} --fee ${fee} ${metafileParameter} --certificate ${stakeAddr}.cert --out-file ${txBodyFile}
259399
checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi
260400

261401
dispFile=$(cat ${txBodyFile}); if ${cropTxOutput} && [[ ${#dispFile} -gt 4000 ]]; then echo "${dispFile:0:4000} ... (cropped)"; else echo "${dispFile}"; fi

0 commit comments

Comments
 (0)