fix(#832): bind receipt promotion to trusted observation
This commit is contained in:
@@ -9,6 +9,7 @@ as a payload input, preventing cryptographic self-reference.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import hashlib
|
||||
import hmac
|
||||
import struct
|
||||
@@ -164,6 +165,44 @@ def build_payload(
|
||||
)
|
||||
|
||||
|
||||
def build_payload_from_wire(value: object) -> ConstructionResult:
|
||||
"""Decode a bounded broker request then invoke the sole payload builder.
|
||||
|
||||
Wire inputs contain only source bytes and their claimed source digests. The
|
||||
authoritative ``build_payload`` implementation remains the only code that
|
||||
admits those bytes and derives ``h_source``/``h_payload``.
|
||||
"""
|
||||
|
||||
if not isinstance(value, dict) or set(value) != {
|
||||
"manifest_version", "generator_version", "fragments"
|
||||
}:
|
||||
raise ValueError("invalid construction")
|
||||
raw_fragments = value["fragments"]
|
||||
if not isinstance(raw_fragments, list):
|
||||
raise ValueError("invalid construction")
|
||||
fragments: list[NormativeFragment] = []
|
||||
for raw_fragment in raw_fragments:
|
||||
if not isinstance(raw_fragment, dict) or set(raw_fragment) != {
|
||||
"source_id", "content_base64", "expected_sha256"
|
||||
}:
|
||||
raise ValueError("invalid construction")
|
||||
source_id = raw_fragment["source_id"]
|
||||
encoded = raw_fragment["content_base64"]
|
||||
expected_sha256 = raw_fragment["expected_sha256"]
|
||||
if not isinstance(source_id, str) or not isinstance(encoded, str) or not isinstance(expected_sha256, str):
|
||||
raise ValueError("invalid construction")
|
||||
try:
|
||||
content = base64.b64decode(encoded.encode("ascii"), validate=True)
|
||||
except (UnicodeEncodeError, ValueError) as exc:
|
||||
raise ValueError("invalid construction") from exc
|
||||
fragments.append(NormativeFragment(source_id, content, expected_sha256))
|
||||
return build_payload(
|
||||
manifest_version=value["manifest_version"],
|
||||
generator_version=value["generator_version"],
|
||||
fragments=fragments,
|
||||
)
|
||||
|
||||
|
||||
def build_for_claude(**kwargs: object) -> ConstructionResult:
|
||||
"""Claude adapter entrypoint; delegates to the sole shared constructor."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user