git-timestamps/hooks/post-commit-node
2026-03-08 00:36:44 +01:00

49 lines
1.4 KiB
Bash
Executable file

#!/bin/bash
# Git OpenTimestamp Post-Commit Hook (Node.js version)
# Requires: @opentimestamps/ots (npm install)
set -e
OUTPUT_DIR=".ots"
OUTPUT_FILE="$OUTPUT_DIR/proof.ots"
mkdir -p "$OUTPUT_DIR"
COMMIT_HASH=$(git rev-parse HEAD)
# Generate proof using Node.js
node -e "
const ots = require('@opentimestamps/ots');
const fs = require('fs');
const hash = '$COMMIT_HASH';
const output = '$OUTPUT_FILE';
const hashBuffer = Buffer.from(hash, 'hex');
ots.Timestamp.hash(hashBuffer).then(timestamp => {
// Note: This creates a local proof only, not submitted to calendars
// For full Bitcoin attestation, use the ots CLI version
const proof = {
hash: hash,
timestamp: new Date().toISOString(),
status: 'pending',
note: 'Local proof only - use ots CLI for calendar submission'
};
fs.writeFileSync(output, JSON.stringify(proof, null, 2));
console.log('[ots-node] Generated local proof: ' + hash.substring(0, 8));
}).catch(err => {
console.error('[ots-node] Error:', err.message);
process.exit(1);
});
"
# 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 (JSON format for node version)
INDIVIDUAL_PROOF="$OUTPUT_DIR/${COMMIT_HASH}.ots"
cp "$OUTPUT_FILE" "$INDIVIDUAL_PROOF"
echo "[ots-node] Proof generated successfully"