From 0fe08f96983cf2eef04603887ff3bb3eca489d3c Mon Sep 17 00:00:00 2001 From: agent-23e5c897f40fd19e Date: Wed, 15 Apr 2026 22:45:53 +0200 Subject: [PATCH] build(agent): molt-y#23e5c8 iteration --- .../__init__.py | 2 ++ .../governance.py | 13 +++++++++ .../privacy.py | 29 +++++++++++++++++++ tests/test_basic.py | 7 +++++ 4 files changed, 51 insertions(+) create mode 100644 src/gridguard_secure_attested_cross_domain_e/privacy.py diff --git a/src/gridguard_secure_attested_cross_domain_e/__init__.py b/src/gridguard_secure_attested_cross_domain_e/__init__.py index 5b20ae5..ea3a777 100644 --- a/src/gridguard_secure_attested_cross_domain_e/__init__.py +++ b/src/gridguard_secure_attested_cross_domain_e/__init__.py @@ -11,6 +11,7 @@ from .transport import TransportLayer from .governance import GovernanceLedger, DeltaSync from .marketplace import AdaptersMarketplace from .simulation import SimulationHarness +from .privacy import SecureAggregator from .dsl import LocalProblem, SharedVariables, PlanDelta, PolicyBlock, AttestationHint from .bridge import to_canonical, from_canonical @@ -23,6 +24,7 @@ __all__ = [ "DeltaSync", "AdaptersMarketplace", "SimulationHarness", + "SecureAggregator", "LocalProblem", "SharedVariables", "PlanDelta", diff --git a/src/gridguard_secure_attested_cross_domain_e/governance.py b/src/gridguard_secure_attested_cross_domain_e/governance.py index 84b8bbe..f127c72 100644 --- a/src/gridguard_secure_attested_cross_domain_e/governance.py +++ b/src/gridguard_secure_attested_cross_domain_e/governance.py @@ -34,3 +34,16 @@ class DeltaSync: merged = dict(local_state) merged.update(remote_state) return merged + + + def anchor_to_public(self, public_anchor_url: str) -> str: + """Create a simple anchor string for cross-organization auditability. + + This simulates anchoring the current ledger state to an external, public + anchor (e.g., a blockchain or public logs). It returns a URL-like anchor + combining the provided base with a hash of the ledger contents. + """ + # Simple hash of all events to serve as a tamper-evident root + ledger_bytes = str(self.get_events()).encode() + root_hash = hashlib.sha256(ledger_bytes).hexdigest() + return f"{public_anchor_url}#root={root_hash}" diff --git a/src/gridguard_secure_attested_cross_domain_e/privacy.py b/src/gridguard_secure_attested_cross_domain_e/privacy.py new file mode 100644 index 0000000..3d040bc --- /dev/null +++ b/src/gridguard_secure_attested_cross_domain_e/privacy.py @@ -0,0 +1,29 @@ +from typing import List, Tuple +import hashlib + + +class SecureAggregator: + """Tiny privacy-preserving aggregator prototype. + + This MVP provides a deterministic aggregation over numeric signals and a + stub of a cryptographic proof that can be consumed by the verifiable + optimization flow. In a real system, this would perform secure aggregation + to avoid leaking individual inputs. + """ + + @staticmethod + def aggregate(signals: List[float]) -> Tuple[float, str]: + # Simple sum as the aggregate result (privacy-preserving in MVP context) + total = sum(signals) if signals else 0.0 + # Mock proof that changes with input; deterministic for testability + seed_input = ",".join(map(str, signals)) + proof = f"PROOF-{hashlib.sha256(seed_input.encode()).hexdigest()}" if seed_input else "PROOF-EMPTY" + return total, proof + + @staticmethod + def verify_aggregate(proof: str, expected_total: float) -> bool: + # In a real system, verify a cryptographic proof. Here we perform a lightweight check. + if not proof: + return False + # We just ensure the proof looks like the mock format and total is non-negative. + return isinstance(expected_total, float) and expected_total >= 0.0 diff --git a/tests/test_basic.py b/tests/test_basic.py index 0886df2..eabafd5 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -5,6 +5,7 @@ from gridguard_secure_attested_cross_domain_e.optimization import VerifiableOpti from gridguard_secure_attested_cross_domain_e.attestation import AttestedAgent from gridguard_secure_attested_cross_domain_e.governance import GovernanceLedger, DeltaSync from gridguard_secure_attested_cross_domain_e.transport import TransportLayer +from gridguard_secure_attested_cross_domain_e.privacy import SecureAggregator from gridguard_secure_attested_cross_domain_e.marketplace import AdaptersMarketplace from gridguard_secure_attested_cross_domain_e.simulation import SimulationHarness @@ -52,3 +53,9 @@ def test_adapters_marketplace(): def test_simulation_harness(): sim = SimulationHarness.simulate({"grid": "test"}) assert sim["state"] == "initialized" + + +def test_secure_aggregator_basic(): + total, proof = SecureAggregator.aggregate([1.0, 2.0, 3.0]) + assert total == 6.0 + assert isinstance(proof, str) and proof.startswith("PROOF-")