#!/bin/bash # Git OpenTimestamp Post-Commit Hook (ots CLI version) # Requires: opentimestamps-client (pipx install opentimestamps-client) set -e OUTPUT_DIR=".ots" OUTPUT_FILE="$OUTPUT_DIR/proof.ots" mkdir -p "$OUTPUT_DIR" COMMIT_HASH=$(git rev-parse HEAD) # Generate proof using ots CLI temp_file=$(mktemp) temp_ots="${temp_file}.ots" python3 -c "import sys; sys.stdout.buffer.write(bytes.fromhex('$COMMIT_HASH'))" > "$temp_file" ots stamp "$temp_file" 2>/dev/null if [ -f "$temp_ots" ]; then mv "$temp_ots" "$OUTPUT_FILE" rm -f "$temp_file" echo "[ots] Generated proof: ${COMMIT_HASH:0:8}" else rm -f "$temp_file" echo "[ots] Warning: Failed to generate proof" >&2 exit 0 fi # Save previous commit for chaining PREV_COMMIT=$(git rev-parse HEAD^1 2>/dev/null || echo "") if [ -n "$PREV_COMMIT" ]; then echo "$PREV_COMMIT" > "$OUTPUT_DIR/prev-commit.txt" fi # Create individual proof file INDIVIDUAL_PROOF="$OUTPUT_DIR/${COMMIT_HASH}.ots" cp "$OUTPUT_FILE" "$INDIVIDUAL_PROOF" echo "[ots] Proof generated successfully"