proof-engine-registry 1.33.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. proof_engine_registry-1.33.0/LICENSE +21 -0
  2. proof_engine_registry-1.33.0/PKG-INFO +136 -0
  3. proof_engine_registry-1.33.0/README.md +91 -0
  4. proof_engine_registry-1.33.0/pyproject.toml +40 -0
  5. proof_engine_registry-1.33.0/setup.cfg +4 -0
  6. proof_engine_registry-1.33.0/src/proof_engine_registry/__init__.py +4 -0
  7. proof_engine_registry-1.33.0/src/proof_engine_registry/badge.py +141 -0
  8. proof_engine_registry-1.33.0/src/proof_engine_registry/cli.py +163 -0
  9. proof_engine_registry-1.33.0/src/proof_engine_registry/client.py +100 -0
  10. proof_engine_registry-1.33.0/src/proof_engine_registry/config.py +68 -0
  11. proof_engine_registry-1.33.0/src/proof_engine_registry/emit.py +268 -0
  12. proof_engine_registry-1.33.0/src/proof_engine_registry/hashing.py +28 -0
  13. proof_engine_registry-1.33.0/src/proof_engine_registry/problems.py +57 -0
  14. proof_engine_registry-1.33.0/src/proof_engine_registry/schema.py +114 -0
  15. proof_engine_registry-1.33.0/src/proof_engine_registry/server.py +364 -0
  16. proof_engine_registry-1.33.0/src/proof_engine_registry.egg-info/PKG-INFO +136 -0
  17. proof_engine_registry-1.33.0/src/proof_engine_registry.egg-info/SOURCES.txt +29 -0
  18. proof_engine_registry-1.33.0/src/proof_engine_registry.egg-info/dependency_links.txt +1 -0
  19. proof_engine_registry-1.33.0/src/proof_engine_registry.egg-info/entry_points.txt +2 -0
  20. proof_engine_registry-1.33.0/src/proof_engine_registry.egg-info/requires.txt +8 -0
  21. proof_engine_registry-1.33.0/src/proof_engine_registry.egg-info/top_level.txt +1 -0
  22. proof_engine_registry-1.33.0/tests/test_badge.py +83 -0
  23. proof_engine_registry-1.33.0/tests/test_cli.py +55 -0
  24. proof_engine_registry-1.33.0/tests/test_client.py +167 -0
  25. proof_engine_registry-1.33.0/tests/test_config.py +79 -0
  26. proof_engine_registry-1.33.0/tests/test_conformance.py +143 -0
  27. proof_engine_registry-1.33.0/tests/test_emit.py +227 -0
  28. proof_engine_registry-1.33.0/tests/test_hashing.py +41 -0
  29. proof_engine_registry-1.33.0/tests/test_problems.py +63 -0
  30. proof_engine_registry-1.33.0/tests/test_schema.py +138 -0
  31. proof_engine_registry-1.33.0/tests/test_server.py +269 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yaniv Golan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,136 @@
1
+ Metadata-Version: 2.4
2
+ Name: proof-engine-registry
3
+ Version: 1.33.0
4
+ Summary: Proof Registry protocol: client, reference server, and static-JSON emitter.
5
+ Author-email: Yaniv Golan <yaniv@lool.vc>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Yaniv Golan
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://proofengine.info
29
+ Project-URL: Repository, https://github.com/yaniv-golan/proof-engine
30
+ Project-URL: Documentation, https://github.com/yaniv-golan/proof-engine/blob/main/docs/registry-protocol.md
31
+ Project-URL: Issues, https://github.com/yaniv-golan/proof-engine/issues
32
+ Project-URL: Changelog, https://github.com/yaniv-golan/proof-engine/blob/main/CHANGELOG.md
33
+ Project-URL: Source, https://github.com/yaniv-golan/proof-engine/tree/main/packages/proof-engine-registry
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Programming Language :: Python :: 3.11
36
+ Requires-Python: >=3.11
37
+ Description-Content-Type: text/markdown
38
+ License-File: LICENSE
39
+ Requires-Dist: requests>=2.31
40
+ Requires-Dist: tomli>=2.0; python_version < "3.11"
41
+ Provides-Extra: test
42
+ Requires-Dist: pytest; extra == "test"
43
+ Requires-Dist: jsonschema>=4.0; extra == "test"
44
+ Dynamic: license-file
45
+
46
+ # proof-engine-registry
47
+
48
+ Protocol, client, and reference server for the Proof Registry — the
49
+ JSON-over-HTTPS layer that lets LLM wikis (and other tools) ask
50
+ "is this claim already proven?" and either use the existing proof or
51
+ commission a new one.
52
+
53
+ Spec: [`docs/registry-protocol.md`](../../docs/registry-protocol.md).
54
+
55
+ ## Install
56
+
57
+ pip install proof-engine-registry
58
+
59
+ ## Config
60
+
61
+ ~/.config/proof-engine/registries.toml
62
+
63
+ ```toml
64
+ [[registry]]
65
+ name = "public"
66
+ url = "https://proofengine.info"
67
+
68
+ [[registry]]
69
+ name = "acme-internal"
70
+ url = "https://proofs.acme.com"
71
+ token_env = "ACME_PROOFS_TOKEN"
72
+ publish = true
73
+ ```
74
+
75
+ ## Client
76
+
77
+ ```python
78
+ from proof_engine_registry import RegistryClient, load_registries
79
+ client = RegistryClient(load_registries())
80
+ hit = client.lookup("The sky is blue.")
81
+ if hit:
82
+ print(hit.proof_url)
83
+ ```
84
+
85
+ ## Self-host
86
+
87
+ proof-registry serve ./my-proofs --port 8080 --token-env MY_TOKEN
88
+
89
+ Useful flags:
90
+
91
+ | Flag | Default | Purpose |
92
+ |-----------------------|--------------------------------------|------------------------------------------------------------------------------------------------------|
93
+ | `--token-env` | (none) | Env var holding the bearer token required for `POST /proofs`. Omit to disable publishing. |
94
+ | `--cors-origin` | `*` | Value for `Access-Control-Allow-Origin` on read responses. Use a specific origin to restrict access. |
95
+ | `--log-json` | off | Emit one JSON access record per request to stderr. Authorization headers are never logged. |
96
+ | `--problem-type-base` | `https://proofengine.info/errors` | Base URI for `type` fields in RFC 7807 error bodies. Override to point at your own docs. |
97
+
98
+ ### Production deployment
99
+
100
+ The reference server uses plain stdlib HTTP and binds to `127.0.0.1` by
101
+ default. Suitable for development and local team use. **For public
102
+ exposure over the open internet**, front the server with a TLS-terminating
103
+ reverse proxy (nginx, Caddy, Cloudflare, AWS ALB) and route only
104
+ encrypted traffic from the proxy to the server. Bearer tokens MUST NOT
105
+ travel the network in cleartext.
106
+
107
+ ## Errors
108
+
109
+ JSON error responses follow [RFC 7807 Problem Details](https://datatracker.ietf.org/doc/html/rfc7807):
110
+
111
+ ```http
112
+ HTTP/1.1 404 Not Found
113
+ Content-Type: application/problem+json
114
+
115
+ {
116
+ "type": "https://proofengine.info/errors/not-found",
117
+ "status": 404,
118
+ "title": "Resource not found",
119
+ "detail": "no proof with that claim_hash",
120
+ "code": "not_found"
121
+ }
122
+ ```
123
+
124
+ The `code` field preserves the legacy short machine key for
125
+ log-aggregation tooling. Full canonical-error table in the
126
+ [protocol spec](../../docs/registry-protocol.md).
127
+
128
+ ## Conformance
129
+
130
+ A protocol-version-aware conformance suite ships with the package:
131
+
132
+ cd packages/proof-engine-registry && python -m pytest tests/test_conformance.py -v
133
+
134
+ It runs against both the static-JSON emit and the reference server.
135
+ Any third-party server claiming to speak the protocol can run the same
136
+ suite.
@@ -0,0 +1,91 @@
1
+ # proof-engine-registry
2
+
3
+ Protocol, client, and reference server for the Proof Registry — the
4
+ JSON-over-HTTPS layer that lets LLM wikis (and other tools) ask
5
+ "is this claim already proven?" and either use the existing proof or
6
+ commission a new one.
7
+
8
+ Spec: [`docs/registry-protocol.md`](../../docs/registry-protocol.md).
9
+
10
+ ## Install
11
+
12
+ pip install proof-engine-registry
13
+
14
+ ## Config
15
+
16
+ ~/.config/proof-engine/registries.toml
17
+
18
+ ```toml
19
+ [[registry]]
20
+ name = "public"
21
+ url = "https://proofengine.info"
22
+
23
+ [[registry]]
24
+ name = "acme-internal"
25
+ url = "https://proofs.acme.com"
26
+ token_env = "ACME_PROOFS_TOKEN"
27
+ publish = true
28
+ ```
29
+
30
+ ## Client
31
+
32
+ ```python
33
+ from proof_engine_registry import RegistryClient, load_registries
34
+ client = RegistryClient(load_registries())
35
+ hit = client.lookup("The sky is blue.")
36
+ if hit:
37
+ print(hit.proof_url)
38
+ ```
39
+
40
+ ## Self-host
41
+
42
+ proof-registry serve ./my-proofs --port 8080 --token-env MY_TOKEN
43
+
44
+ Useful flags:
45
+
46
+ | Flag | Default | Purpose |
47
+ |-----------------------|--------------------------------------|------------------------------------------------------------------------------------------------------|
48
+ | `--token-env` | (none) | Env var holding the bearer token required for `POST /proofs`. Omit to disable publishing. |
49
+ | `--cors-origin` | `*` | Value for `Access-Control-Allow-Origin` on read responses. Use a specific origin to restrict access. |
50
+ | `--log-json` | off | Emit one JSON access record per request to stderr. Authorization headers are never logged. |
51
+ | `--problem-type-base` | `https://proofengine.info/errors` | Base URI for `type` fields in RFC 7807 error bodies. Override to point at your own docs. |
52
+
53
+ ### Production deployment
54
+
55
+ The reference server uses plain stdlib HTTP and binds to `127.0.0.1` by
56
+ default. Suitable for development and local team use. **For public
57
+ exposure over the open internet**, front the server with a TLS-terminating
58
+ reverse proxy (nginx, Caddy, Cloudflare, AWS ALB) and route only
59
+ encrypted traffic from the proxy to the server. Bearer tokens MUST NOT
60
+ travel the network in cleartext.
61
+
62
+ ## Errors
63
+
64
+ JSON error responses follow [RFC 7807 Problem Details](https://datatracker.ietf.org/doc/html/rfc7807):
65
+
66
+ ```http
67
+ HTTP/1.1 404 Not Found
68
+ Content-Type: application/problem+json
69
+
70
+ {
71
+ "type": "https://proofengine.info/errors/not-found",
72
+ "status": 404,
73
+ "title": "Resource not found",
74
+ "detail": "no proof with that claim_hash",
75
+ "code": "not_found"
76
+ }
77
+ ```
78
+
79
+ The `code` field preserves the legacy short machine key for
80
+ log-aggregation tooling. Full canonical-error table in the
81
+ [protocol spec](../../docs/registry-protocol.md).
82
+
83
+ ## Conformance
84
+
85
+ A protocol-version-aware conformance suite ships with the package:
86
+
87
+ cd packages/proof-engine-registry && python -m pytest tests/test_conformance.py -v
88
+
89
+ It runs against both the static-JSON emit and the reference server.
90
+ Any third-party server claiming to speak the protocol can run the same
91
+ suite.
@@ -0,0 +1,40 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "proof-engine-registry"
7
+ version = "1.33.0"
8
+ description = "Proof Registry protocol: client, reference server, and static-JSON emitter."
9
+ readme = "README.md"
10
+ license = { file = "LICENSE" }
11
+ authors = [{ name = "Yaniv Golan", email = "yaniv@lool.vc" }]
12
+ requires-python = ">=3.11"
13
+ dependencies = [
14
+ "requests>=2.31",
15
+ "tomli>=2.0; python_version<'3.11'",
16
+ ]
17
+ classifiers = [
18
+ "License :: OSI Approved :: MIT License",
19
+ "Programming Language :: Python :: 3.11",
20
+ ]
21
+
22
+ [project.optional-dependencies]
23
+ test = ["pytest", "jsonschema>=4.0"]
24
+
25
+ [project.scripts]
26
+ proof-registry = "proof_engine_registry.cli:main"
27
+
28
+ [project.urls]
29
+ Homepage = "https://proofengine.info"
30
+ Repository = "https://github.com/yaniv-golan/proof-engine"
31
+ Documentation = "https://github.com/yaniv-golan/proof-engine/blob/main/docs/registry-protocol.md"
32
+ Issues = "https://github.com/yaniv-golan/proof-engine/issues"
33
+ Changelog = "https://github.com/yaniv-golan/proof-engine/blob/main/CHANGELOG.md"
34
+ Source = "https://github.com/yaniv-golan/proof-engine/tree/main/packages/proof-engine-registry"
35
+
36
+ [tool.setuptools.packages.find]
37
+ where = ["src"]
38
+
39
+ [tool.pytest.ini_options]
40
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,4 @@
1
+ """proof-engine-registry — Proof Registry protocol implementation."""
2
+
3
+ __version__ = "1.33.0"
4
+ __protocol_version__ = "0.1"
@@ -0,0 +1,141 @@
1
+ """Proof badge: compact certificate for claim verification.
2
+
3
+ Two artifacts per proof:
4
+ - badge.json — machine-readable payload
5
+ - badge.svg — shields-style inline SVG for direct <img> embedding
6
+
7
+ The SVG uses a fixed sans-serif stack and estimated text widths. It won't be
8
+ pixel-perfect at all zoom levels, but it renders without external fonts and
9
+ is byte-identical across builds (important so git diffs stay clean).
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from typing import Optional
15
+
16
+ from proof_engine_registry.emit import (
17
+ claim_text, verdict_string, confidence_from_proof,
18
+ )
19
+ from proof_engine_registry.hashing import hash_claim
20
+
21
+
22
+ # Locked color map — see test_build_badge_pinned_colors.
23
+ VERDICT_COLORS: dict[str, str] = {
24
+ "PROVED": "#2d8f5f",
25
+ "SUPPORTED": "#5eb88a",
26
+ "PARTIALLY VERIFIED": "#d4a017",
27
+ "UNDETERMINED": "#888888",
28
+ "DISPROVED": "#c75450",
29
+ }
30
+
31
+ BADGE_SCHEMA_VERSION = "1.0"
32
+
33
+
34
+ def _color_for(verdict: str) -> str:
35
+ """Pick a color by the leading verdict family (ignoring any qualifier)."""
36
+ for family, color in VERDICT_COLORS.items():
37
+ if verdict.startswith(family):
38
+ return color
39
+ return VERDICT_COLORS["UNDETERMINED"]
40
+
41
+
42
+ def build_badge(proof: dict, slug: str, doi: Optional[str],
43
+ base_url: str) -> dict:
44
+ """Build the badge payload from a v3 proof.json dict.
45
+
46
+ `slug` and `doi` are passed explicitly because they live outside
47
+ proof.json (slug is the dir name; DOI is in a sibling doi.json).
48
+ """
49
+ base = base_url.rstrip("/")
50
+ claim = claim_text(proof)
51
+ verdict = verdict_string(proof)
52
+ gen = proof.get("generator") or {}
53
+ return {
54
+ "schema_version": BADGE_SCHEMA_VERSION,
55
+ "slug": slug,
56
+ "claim": claim,
57
+ "claim_hash": hash_claim(claim),
58
+ "verdict": verdict,
59
+ "confidence": confidence_from_proof(proof),
60
+ "doi": doi,
61
+ "proof_url": f"{base}/proofs/{slug}/",
62
+ "badge_svg_url": f"{base}/proofs/{slug}/badge.svg",
63
+ "generated_at": gen.get("generated_at", ""),
64
+ "colors": {
65
+ "verdict_bg": _color_for(verdict),
66
+ "verdict_fg": "#ffffff",
67
+ },
68
+ }
69
+
70
+
71
+ # SVG layout constants — keep in one place for easy theming.
72
+ _FONT_STACK = (
73
+ "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif"
74
+ )
75
+ _LABEL_BG = "#555555"
76
+ _LABEL_FG = "#ffffff"
77
+ _CHAR_WIDTH = 6.5 # px, estimated for 11px sans-serif
78
+ _PADDING = 10
79
+ _HEIGHT = 20
80
+
81
+
82
+ def _text_width(text: str) -> int:
83
+ return int(len(text) * _CHAR_WIDTH) + 2 * _PADDING
84
+
85
+
86
+ def render_badge_svg(badge: dict) -> str:
87
+ label = "proof"
88
+ value = badge["verdict"]
89
+ label_w = _text_width(label)
90
+ value_w = _text_width(value)
91
+ total_w = label_w + value_w
92
+ value_bg = badge["colors"]["verdict_bg"]
93
+ # Defense-in-depth: verdict is a controlled enum today, but escape on
94
+ # the way into XML attributes and text nodes so a future qualifier
95
+ # string with `<` / `&` / `"` cannot break the SVG.
96
+ value_esc = _escape_html(value)
97
+ label_esc = _escape_html(label)
98
+
99
+ svg = (
100
+ f'<svg xmlns="http://www.w3.org/2000/svg" '
101
+ f'width="{total_w}" height="{_HEIGHT}" role="img" '
102
+ f'aria-label="proof: {value_esc}">'
103
+ f'<title>proof: {value_esc}</title>'
104
+ f'<linearGradient id="s" x2="0" y2="100%">'
105
+ f'<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>'
106
+ f'<stop offset="1" stop-opacity=".1"/>'
107
+ f'</linearGradient>'
108
+ f'<rect width="{total_w}" height="{_HEIGHT}" rx="3" fill="{_LABEL_BG}"/>'
109
+ f'<rect x="{label_w}" width="{value_w}" height="{_HEIGHT}" rx="3" fill="{value_bg}"/>'
110
+ f'<rect width="{total_w}" height="{_HEIGHT}" rx="3" fill="url(#s)"/>'
111
+ f'<g fill="{_LABEL_FG}" text-anchor="middle" '
112
+ f'font-family="{_FONT_STACK}" font-size="11">'
113
+ f'<text x="{label_w // 2}" y="14">{label_esc}</text>'
114
+ f'<text x="{label_w + value_w // 2}" y="14">{value_esc}</text>'
115
+ f'</g></svg>'
116
+ )
117
+ return svg
118
+
119
+
120
+ def render_embed_snippets(badge: dict) -> dict[str, str]:
121
+ """Return the three copy-paste-ready embeds."""
122
+ proof_url = badge["proof_url"]
123
+ svg_url = badge["badge_svg_url"]
124
+ claim = badge["claim"]
125
+ return {
126
+ "html": (
127
+ f'<a href="{proof_url}" title="{_escape_html(claim)}">'
128
+ f'<img src="{svg_url}" alt="proof: {badge["verdict"]}"/></a>'
129
+ ),
130
+ "markdown": f'[![proof]({svg_url})]({proof_url})',
131
+ "url": svg_url,
132
+ }
133
+
134
+
135
+ def _escape_html(s: str) -> str:
136
+ return (
137
+ s.replace("&", "&amp;")
138
+ .replace("<", "&lt;")
139
+ .replace(">", "&gt;")
140
+ .replace('"', "&quot;")
141
+ )
@@ -0,0 +1,163 @@
1
+ """proof-registry CLI: serve | lookup | publish | emit."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import json
7
+ import os
8
+ import sys
9
+ from dataclasses import asdict
10
+ from pathlib import Path
11
+
12
+ from proof_engine_registry import __version__
13
+ from proof_engine_registry.client import RegistryClient
14
+ from proof_engine_registry.config import load_registries, Registry
15
+ from proof_engine_registry.emit import emit_registry_files
16
+ from proof_engine_registry.server import RegistryServer
17
+
18
+
19
+ def _cmd_serve(args) -> int:
20
+ token = os.environ.get(args.token_env) if args.token_env else None
21
+ srv = RegistryServer(
22
+ proofs_dir=Path(args.proofs_dir),
23
+ name=args.name,
24
+ base_url=args.base_url or f"http://{args.bind}:{args.port}",
25
+ bind=args.bind, port=args.port,
26
+ auth_token=token,
27
+ cors_origin=args.cors_origin,
28
+ log_json=args.log_json,
29
+ )
30
+ if args.print_port_to:
31
+ Path(args.print_port_to).write_text(str(srv.port))
32
+ print(f"proof-registry serving {args.proofs_dir} on http://{args.bind}:{srv.port}",
33
+ file=sys.stderr)
34
+ try:
35
+ srv.serve_forever()
36
+ except KeyboardInterrupt:
37
+ srv.shutdown()
38
+ return 0
39
+
40
+
41
+ def _cmd_emit(args) -> int:
42
+ emit_registry_files(
43
+ proofs_dir=Path(args.proofs_dir),
44
+ output_dir=Path(args.output_dir),
45
+ base_url=args.base_url,
46
+ registry_name=args.name,
47
+ publishes_supported=False,
48
+ )
49
+ print(f"emitted registry to {args.output_dir}", file=sys.stderr)
50
+ return 0
51
+
52
+
53
+ def _cmd_lookup(args) -> int:
54
+ registries = load_registries()
55
+ if not registries:
56
+ print("error: no registries configured (expected ~/.config/proof-engine/registries.toml)",
57
+ file=sys.stderr)
58
+ return 2
59
+ client = RegistryClient(registries)
60
+ hit = client.lookup(args.claim)
61
+ if hit is None:
62
+ if args.json:
63
+ sys.stdout.write(json.dumps({"hit": False}) + "\n")
64
+ else:
65
+ sys.stdout.write("no hit\n")
66
+ return 1
67
+ payload = asdict(hit.entry) | {"registry_name": hit.registry_name}
68
+ if args.json:
69
+ sys.stdout.write(json.dumps(payload, indent=2 if args.pretty else None) + "\n")
70
+ else:
71
+ sys.stdout.write(f"{hit.registry_name}: {hit.slug} → {hit.proof_url}\n")
72
+ return 0
73
+
74
+
75
+ def _cmd_publish(args) -> int:
76
+ # Find the one publish target.
77
+ registries = [r for r in load_registries() if r.publish]
78
+ if not registries:
79
+ print("error: no registry has publish = true", file=sys.stderr)
80
+ return 2
81
+ if len(registries) > 1:
82
+ print("error: more than one registry has publish = true (blocked by config loader)",
83
+ file=sys.stderr)
84
+ return 2
85
+ target = registries[0]
86
+ body = json.loads(Path(args.proof_json).read_text())
87
+ import requests
88
+ r = requests.post(
89
+ f"{target.url}/proofs",
90
+ json={"slug": body["slug"], "claim": body["claim"], "proof_json": body},
91
+ headers={"Authorization": f"Bearer {target.token}"} if target.token else {},
92
+ timeout=30,
93
+ )
94
+ if r.status_code == 201:
95
+ print(f"published {body['slug']} to {target.name}", file=sys.stderr)
96
+ return 0
97
+ print(f"publish failed: HTTP {r.status_code} {r.text}", file=sys.stderr)
98
+ return 1
99
+
100
+
101
+ def build_parser() -> argparse.ArgumentParser:
102
+ p = argparse.ArgumentParser(prog="proof-registry")
103
+ p.add_argument("--version", action="version", version=__version__)
104
+ sub = p.add_subparsers(dest="cmd", required=True)
105
+
106
+ s = sub.add_parser(
107
+ "serve",
108
+ help="Run a self-hosted registry server.",
109
+ description=(
110
+ "Stdlib HTTP server. Suitable for development and local team "
111
+ "deployments. For public deployment over the open internet, "
112
+ "front this with a TLS-terminating reverse proxy (nginx, Caddy, "
113
+ "Cloudflare, etc.) — bearer tokens travel in the Authorization "
114
+ "header and MUST NOT cross the network in cleartext."
115
+ ),
116
+ )
117
+ s.add_argument("proofs_dir")
118
+ s.add_argument("--name", default="Self-Hosted Proof Registry")
119
+ s.add_argument("--base-url", default=None)
120
+ s.add_argument("--bind", default="127.0.0.1")
121
+ s.add_argument("--port", type=int, default=8080)
122
+ s.add_argument("--token-env", default=None,
123
+ help="Env var holding the bearer token required for publishing.")
124
+ s.add_argument("--cors-origin", default="*",
125
+ help=("Value for Access-Control-Allow-Origin on read responses. "
126
+ "Default '*' for public registries; pass a specific origin "
127
+ "to restrict cross-origin browser access."))
128
+ s.add_argument("--log-json", action="store_true",
129
+ help=("Emit one structured JSON access log line per request to "
130
+ "stderr. Off by default; useful for compliance/audit. "
131
+ "Authorization headers are NEVER logged."))
132
+ s.add_argument("--print-port-to", default=None,
133
+ help="Write the bound port to this file (for test orchestration).")
134
+ s.set_defaults(func=_cmd_serve)
135
+
136
+ e = sub.add_parser("emit", help="Emit static registry JSON from a proofs dir.")
137
+ e.add_argument("proofs_dir")
138
+ e.add_argument("output_dir")
139
+ e.add_argument("--base-url", required=True)
140
+ e.add_argument("--name", default="Proof Registry")
141
+ e.set_defaults(func=_cmd_emit)
142
+
143
+ l = sub.add_parser("lookup", help="Look up a claim across configured registries.")
144
+ l.add_argument("claim")
145
+ l.add_argument("--json", action="store_true")
146
+ l.add_argument("--pretty", action="store_true")
147
+ l.set_defaults(func=_cmd_lookup)
148
+
149
+ pub = sub.add_parser("publish", help="Publish a proof.json to the publish-target registry.")
150
+ pub.add_argument("proof_json")
151
+ pub.set_defaults(func=_cmd_publish)
152
+
153
+ return p
154
+
155
+
156
+ def main(argv=None) -> int:
157
+ parser = build_parser()
158
+ args = parser.parse_args(argv)
159
+ return args.func(args)
160
+
161
+
162
+ if __name__ == "__main__":
163
+ raise SystemExit(main())