-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Github Action
committed
Feb 5, 2025
1 parent
b007f68
commit 48779b6
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env -S nix shell nixpkgs#jq .#cardano-cli .#cardano-address -c bash | ||
# shellcheck shell=bash | ||
|
||
set -euo pipefail | ||
|
||
if [ "$#" -ne 2 ]; then | ||
echo "Usage: $0 <mnemonic> <unsigned-tx-json>" >&2 | ||
exit 1 | ||
fi | ||
|
||
temp_dir=$(mktemp -d) | ||
|
||
# cleanup function | ||
cleanup() { | ||
rm -rf "$temp_dir" | ||
} | ||
|
||
trap cleanup EXIT | ||
trap cleanup ERR | ||
trap cleanup SIGINT | ||
|
||
# collect arguments | ||
mnemonic=$1 | ||
unsigned=$2 | ||
|
||
# create the root key | ||
cardano-address key from-recovery-phrase Shelley <<<"$mnemonic" >"$temp_dir/root.xsk" | ||
|
||
# extract bip32 paths from the unsigned tx json | ||
paths=$(jq -r '.bip32Paths[]' <<<"$unsigned") | ||
|
||
# derive keys, convert to cardano-cli format and collect --signing-key-file arguments | ||
index=0 | ||
signing_key_files="" | ||
for path in $paths; do | ||
key_file="$temp_dir/key${index}.xsk" | ||
cardano-address key child "$path" <"$temp_dir/root.xsk" >"$key_file" | ||
cli_key_file="$temp_dir/key${index}.skey" | ||
cardano-cli key convert-cardano-address-key \ | ||
--shelley-payment-key \ | ||
--signing-key-file "$key_file" \ | ||
--out-file "$cli_key_file" | ||
signing_key_files="$signing_key_files --signing-key-file $temp_dir/key${index}.skey" | ||
index=$((index + 1)) | ||
done | ||
|
||
# dump unsigned tx to a file | ||
echo "$unsigned" >"$temp_dir/tx.unsigned" | ||
|
||
# sign the transaction | ||
# shellcheck disable=SC2086 | ||
cardano-cli conway transaction sign \ | ||
$signing_key_files \ | ||
--tx-body-file "$temp_dir/tx.unsigned" \ | ||
--out-file "$temp_dir/tx.signed" \ | ||
--testnet-magic 1 | ||
|
||
# print the signed transaction | ||
cat "$temp_dir/tx.signed" |