#!/usr/bin/env bash
# Recompute a flexibility digest outside Rust: `sha256:` and the SHA-256 of a canon@1 text.
#
#   scripts/digest.sh settlement.json      # or: ... | scripts/digest.sh
#
# The file holds the canonical text exactly as `Settlement::canonical()` returns it; a single
# trailing newline is ignored, nothing else is changed.
set -euo pipefail
text=$(cat "${1:-/dev/stdin}")
if command -v sha256sum >/dev/null; then
  hex=$(printf '%s' "$text" | sha256sum | cut -d' ' -f1)
else
  hex=$(printf '%s' "$text" | shasum -a 256 | cut -d' ' -f1)
fi
printf 'sha256:%s\n' "$hex"
