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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# sovereign_capacity_seal.py
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import json
|
| 6 |
+
from datetime import datetime, timezone
|
| 7 |
+
from typing import Any, Dict, Optional
|
| 8 |
+
|
| 9 |
+
from sovereign_crypto_seal import SovereignCryptoSeal, build_manifest
|
| 10 |
+
from sovereign_capacity_report import generate_capacity_report
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def _utc_now() -> str:
|
| 14 |
+
return datetime.now(timezone.utc).isoformat()
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class SovereignCapacitySeal:
|
| 18 |
+
"""
|
| 19 |
+
Seals and verifies Sovereign capacity artifacts.
|
| 20 |
+
|
| 21 |
+
Primary use:
|
| 22 |
+
- capacity report
|
| 23 |
+
- capacity manifest
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
def __init__(self, sealer: Optional[SovereignCryptoSeal] = None) -> None:
|
| 27 |
+
self.sealer = sealer or SovereignCryptoSeal()
|
| 28 |
+
|
| 29 |
+
# ---------------------------------------------------------
|
| 30 |
+
# Capacity report sealing
|
| 31 |
+
# ---------------------------------------------------------
|
| 32 |
+
def seal_capacity_report(
|
| 33 |
+
self,
|
| 34 |
+
report: Dict[str, Any],
|
| 35 |
+
metadata: Optional[Dict[str, Any]] = None,
|
| 36 |
+
) -> Dict[str, Any]:
|
| 37 |
+
sealed = self.sealer.seal_object(
|
| 38 |
+
report,
|
| 39 |
+
object_type="capacity_report",
|
| 40 |
+
metadata=metadata or {
|
| 41 |
+
"domain": "banking",
|
| 42 |
+
"artifact_class": "capacity_report",
|
| 43 |
+
},
|
| 44 |
+
)
|
| 45 |
+
return {
|
| 46 |
+
"ok": True,
|
| 47 |
+
"sealed": True,
|
| 48 |
+
"report": report,
|
| 49 |
+
"crypto_seal": sealed["seal"],
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
def verify_capacity_report(
|
| 53 |
+
self,
|
| 54 |
+
report: Dict[str, Any],
|
| 55 |
+
seal: Dict[str, Any],
|
| 56 |
+
) -> Dict[str, Any]:
|
| 57 |
+
verified = self.sealer.verify_object(report, seal)
|
| 58 |
+
return {
|
| 59 |
+
"ok": bool(verified.get("ok")),
|
| 60 |
+
"verified": bool(verified.get("verified")),
|
| 61 |
+
"artifact_type": "capacity_report",
|
| 62 |
+
"verification": verified,
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
# ---------------------------------------------------------
|
| 66 |
+
# Generate + seal convenience
|
| 67 |
+
# ---------------------------------------------------------
|
| 68 |
+
def generate_and_seal_capacity_report(
|
| 69 |
+
self,
|
| 70 |
+
iterations_per_case: int = 25,
|
| 71 |
+
warmup_runs: int = 2,
|
| 72 |
+
output_dir: str = "sovereign_capacity_outputs",
|
| 73 |
+
base_name: Optional[str] = None,
|
| 74 |
+
metadata: Optional[Dict[str, Any]] = None,
|
| 75 |
+
) -> Dict[str, Any]:
|
| 76 |
+
generated = generate_capacity_report(
|
| 77 |
+
iterations_per_case=iterations_per_case,
|
| 78 |
+
warmup_runs=warmup_runs,
|
| 79 |
+
output_dir=output_dir,
|
| 80 |
+
base_name=base_name,
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
report = generated.get("report", {}) if isinstance(generated, dict) else {}
|
| 84 |
+
sealed_bundle = self.seal_capacity_report(
|
| 85 |
+
report=report,
|
| 86 |
+
metadata=metadata or {
|
| 87 |
+
"domain": "banking",
|
| 88 |
+
"artifact_class": "capacity_report",
|
| 89 |
+
"generated_at": _utc_now(),
|
| 90 |
+
"iterations_per_case": iterations_per_case,
|
| 91 |
+
"warmup_runs": warmup_runs,
|
| 92 |
+
},
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
return {
|
| 96 |
+
"ok": True,
|
| 97 |
+
"generated_at": _utc_now(),
|
| 98 |
+
"report": report,
|
| 99 |
+
"files": generated.get("files", {}) if isinstance(generated, dict) else {},
|
| 100 |
+
"crypto_seal": sealed_bundle["crypto_seal"],
|
| 101 |
+
"sealed": True,
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
# ---------------------------------------------------------
|
| 105 |
+
# Capacity manifest
|
| 106 |
+
# ---------------------------------------------------------
|
| 107 |
+
def build_capacity_manifest(
|
| 108 |
+
self,
|
| 109 |
+
*,
|
| 110 |
+
subject_name: str,
|
| 111 |
+
subject_version: str,
|
| 112 |
+
capacity_report: Dict[str, Any],
|
| 113 |
+
metadata: Optional[Dict[str, Any]] = None,
|
| 114 |
+
) -> Dict[str, Any]:
|
| 115 |
+
manifest_bundle = build_manifest(
|
| 116 |
+
manifest_type="sovereign_capacity_bundle",
|
| 117 |
+
subject_name=subject_name,
|
| 118 |
+
subject_version=subject_version,
|
| 119 |
+
artifacts={
|
| 120 |
+
"capacity_report": capacity_report,
|
| 121 |
+
},
|
| 122 |
+
metadata=metadata or {
|
| 123 |
+
"domain": "banking",
|
| 124 |
+
"artifact_class": "capacity_bundle",
|
| 125 |
+
},
|
| 126 |
+
)
|
| 127 |
+
return {
|
| 128 |
+
"ok": True,
|
| 129 |
+
"manifest_bundle": manifest_bundle,
|
| 130 |
+
"artifacts_included": ["capacity_report"],
|
| 131 |
+
"artifact_count": 1,
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
SEALER = SovereignCapacitySeal()
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def seal_capacity_report(
|
| 139 |
+
report: Dict[str, Any],
|
| 140 |
+
metadata: Optional[Dict[str, Any]] = None,
|
| 141 |
+
) -> Dict[str, Any]:
|
| 142 |
+
return SEALER.seal_capacity_report(report, metadata)
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def verify_capacity_report(
|
| 146 |
+
report: Dict[str, Any],
|
| 147 |
+
seal: Dict[str, Any],
|
| 148 |
+
) -> Dict[str, Any]:
|
| 149 |
+
return SEALER.verify_capacity_report(report, seal)
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def generate_and_seal_capacity_report(
|
| 153 |
+
iterations_per_case: int = 25,
|
| 154 |
+
warmup_runs: int = 2,
|
| 155 |
+
output_dir: str = "sovereign_capacity_outputs",
|
| 156 |
+
base_name: Optional[str] = None,
|
| 157 |
+
metadata: Optional[Dict[str, Any]] = None,
|
| 158 |
+
) -> Dict[str, Any]:
|
| 159 |
+
return SEALER.generate_and_seal_capacity_report(
|
| 160 |
+
iterations_per_case=iterations_per_case,
|
| 161 |
+
warmup_runs=warmup_runs,
|
| 162 |
+
output_dir=output_dir,
|
| 163 |
+
base_name=base_name,
|
| 164 |
+
metadata=metadata,
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
def build_capacity_manifest(
|
| 169 |
+
*,
|
| 170 |
+
subject_name: str,
|
| 171 |
+
subject_version: str,
|
| 172 |
+
capacity_report: Dict[str, Any],
|
| 173 |
+
metadata: Optional[Dict[str, Any]] = None,
|
| 174 |
+
) -> Dict[str, Any]:
|
| 175 |
+
return SEALER.build_capacity_manifest(
|
| 176 |
+
subject_name=subject_name,
|
| 177 |
+
subject_version=subject_version,
|
| 178 |
+
capacity_report=capacity_report,
|
| 179 |
+
metadata=metadata,
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
if __name__ == "__main__":
|
| 184 |
+
out = generate_and_seal_capacity_report(iterations_per_case=10, warmup_runs=1)
|
| 185 |
+
print(json.dumps(out, indent=2, ensure_ascii=False))
|
| 186 |
+
|
| 187 |
+
manifest = build_capacity_manifest(
|
| 188 |
+
subject_name="Sovereign Bank Runtime",
|
| 189 |
+
subject_version="v1",
|
| 190 |
+
capacity_report=out.get("report", {}),
|
| 191 |
+
metadata={"pack_type": "capacity_identity_seed"},
|
| 192 |
+
)
|
| 193 |
+
print(json.dumps(manifest, indent=2, ensure_ascii=False))
|
| 194 |
+
|