"""Sign a piece of AI-generated text and verify it round-trips. Run: python examples/sign_llm_output.py """ from __future__ import annotations from quantumshield import AgentIdentity from pqc_content_provenance import ( AIGeneratedAssertion, ContentManifest, GenerationContext, ManifestSigner, ModelAttribution, UsageAssertion, embed_manifest, extract_manifest, ) def main() -> None: identity = AgentIdentity.create("llama-3-signer") signer = ManifestSigner(identity) # The AI output we want to prove provenance for content = b"Post-quantum cryptography will be mandatory by 2027." manifest = ContentManifest.create( content=content, content_type="text/plain", model_attribution=ModelAttribution( model_did="did:pqaid:llama3-reference", model_name="Llama-3-8B-Instruct", model_version="1.0", registry_url="https://quantamrkt.com/models/meta-llama-Llama-3-8B-Instruct", ), generation_context=GenerationContext( prompt_hash="ab" * 32, parameters={"temperature": 0.7}, generated_at="2026-04-20T12:00:00Z", ), assertions=[ AIGeneratedAssertion( model_name="Llama-3-8B-Instruct", model_version="1.0", generator_type="text", human_edited=False, ), UsageAssertion( license="cc-by-4.0", commercial_use=True, attribution_required=True, attribution_text="Generated by Llama-3-8B, verified via QuantaMrkt.", ), ], ) signed = signer.sign(manifest) print(f"Signed manifest: {signed.manifest_id}") print(f" signer: {signed.signer_did}") print(f" algorithm: {signed.algorithm}") print(f" content hash: {signed.content_hash}") # Package content + manifest into a sidecar envelope envelope = embed_manifest(content, signed, mode="sidecar") print(f"\nEnvelope size: {len(envelope)} bytes") # Consumer extracts and verifies recovered_manifest, recovered_content = extract_manifest(envelope, mode="sidecar") result = ManifestSigner.verify(recovered_manifest, recovered_content) print(f"\nVerification: valid={result.valid}, content_match={result.content_hash_match}") if __name__ == "__main__": main()