name: sebbi.pro proof mirror
# Keeps an independent, verified copy of sebbi.pro's self-proving daily archive file.
# Put this file at .github/workflows/sebbi-proof-mirror.yml in any PUBLIC repository.
on:
  schedule: [{cron: "17 6 * * *"}]
  workflow_dispatch: {}
permissions:
  contents: write
jobs:
  mirror:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Fetch, verify and keep today's file
        run: |
          set -e
          curl -fsSL https://sebbi.pro/x/archive/latest -o meta.json
          URL=$(python3 -c "import json;d=json.load(open('meta.json'));d=d.get('latest',d);print(d['file'])")
          SHA=$(python3 -c "import json;d=json.load(open('meta.json'));d=d.get('latest',d);print(d['sha256'])")
          curl -fsSL "$URL" -o candidate.json
          python3 -c "import json,sys;exec(json.load(open(sys.argv[1]))['verifier_py'])" candidate.json | tee verify.txt
          GOT=$(python3 -c "import json,hashlib;print(hashlib.sha256(json.dumps(json.load(open('candidate.json')),sort_keys=True,separators=(',',':')).encode()).hexdigest())")
          test "$GOT" = "$SHA"
          mkdir -p files && cp candidate.json "files/$SHA.json" && mv candidate.json latest.json && rm meta.json
          git config user.name "sebbi-proof-mirror" && git config user.email "mirror@users.noreply.github.com"
          git add -A && (git commit -m "Verified sebbi.pro archive $SHA" || true) && git push
# Then register https://raw.githubusercontent.com/<you>/<repo>/main/latest.json at
# https://sebbi.pro/x/custody/offer?url=<that address>&name=<your name> to be counted as an independent holder.
