From 3f7b9c15445f30ece7a3285980258fc642069343 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Sat, 5 Jul 2025 01:11:06 +0100 Subject: [PATCH 1/2] init --- scripts/author-create.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/author-create.sh b/scripts/author-create.sh index 6cb9958..865446f 100755 --- a/scripts/author-create.sh +++ b/scripts/author-create.sh @@ -3,6 +3,7 @@ ################################################## DEFAULT_AUTHOR_NAME="Intersect" DEFAULT_USE_CIP8="false" # default to false, to the script uses Ed25519 +DEFAULT_NEW_FILE="false" # default to false, to the script overwrites the input file ################################################## # This is just a script for testing purposes. @@ -20,9 +21,10 @@ fi # Usage message usage() { - echo "Usage: $0 [--author-name NAME] [--use-cip8]" + echo "Usage: $0 [--author-name NAME] [--use-cip8] [--new-file]" echo "Options:" echo " --author-name NAME Specify the author name (default: $DEFAULT_AUTHOR_NAME)" + echo " --new-file Create a new file with the signed metadata (default: $DEFAULT_NEW_FILE)" echo " --use-cip8 Use CIP-8 signing algorithm (default: $DEFAULT_USE_CIP8)" exit 1 } @@ -32,6 +34,7 @@ input_path="" input_key="" author_name="$DEFAULT_AUTHOR_NAME" use_cip8="$DEFAULT_USE_CIP8" +new_file="$DEFAULT_NEW_FILE" # Parse command line arguments while [[ $# -gt 0 ]]; do @@ -44,6 +47,11 @@ while [[ $# -gt 0 ]]; do use_cip8="true" shift ;; + --new-file) + new_file="true" + shift + ;; + -h|--help) usage ;; @@ -76,6 +84,7 @@ fi sign_file() { local file="$1" local use_cip8="$2" + local output_path="$3" if [ "$use_cip8" = "true" ]; then echo "Signing with CIP-8 algorithm..." From 1a332df6119e845409621ddbd4abdace4e74a551 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Sat, 5 Jul 2025 12:59:53 +0100 Subject: [PATCH 2/2] plug in new option --- scripts/author-create.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/author-create.sh b/scripts/author-create.sh index 865446f..5369139 100755 --- a/scripts/author-create.sh +++ b/scripts/author-create.sh @@ -84,7 +84,15 @@ fi sign_file() { local file="$1" local use_cip8="$2" - local output_path="$3" + local new_file="$3" + + if [ $new_file = "true" ]; then + echo "Creating a new file with the signed metadata..." + extension=".authored.jsonld" # New file will have .authored.jsonld extension + else + echo "Overwriting the original file with the signed metadata..." + extension=".jsonld" + fi if [ "$use_cip8" = "true" ]; then echo "Signing with CIP-8 algorithm..." @@ -110,7 +118,7 @@ sign_file() { --secret-key "$input_key" \ --author-name "$author_name" \ --address "$public_key_hash" \ - --out-file "${file%.jsonld}.authored.jsonld" + --out-file "${file%.jsonld}$extension" return else echo "Signing with Ed25519 algorithm..." @@ -118,7 +126,7 @@ sign_file() { --data-file "$file" \ --secret-key "$input_key" \ --author-name "$author_name" \ - --out-file "${file%.jsonld}.authored.jsonld" + --out-file "${file%.jsonld}$extension" return fi } @@ -136,11 +144,11 @@ if [ -d "$input_path" ]; then fi # for each .jsonld file in the directory, sign it for file in "${jsonld_files[@]}"; do - sign_file "$file" "$use_cip8" + sign_file "$file" "$use_cip8" "$new_file" done elif [ -f "$input_path" ]; then # Input is a single file - sign_file "$input_path" "$use_cip8" + sign_file "$input_path" "$use_cip8" "$new_file" else echo "Error: '$input_path' is not a valid file or directory." exit 1