Metadata-Version: 2.4
Name: hornet-cpl
Version: 1.0.0
Summary: Coordinate Provenance Layer - Model-agnostic, verifiable output attribution
Author: HORNET CPL contributors
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/bsenff-unicornsecurity/hornet-provenance
Project-URL: Documentation, https://github.com/bsenff-unicornsecurity/hornet-provenance#readme
Project-URL: Repository, https://github.com/bsenff-unicornsecurity/hornet-provenance
Project-URL: Issues, https://github.com/bsenff-unicornsecurity/hornet-provenance/issues
Project-URL: Changelog, https://github.com/bsenff-unicornsecurity/hornet-provenance/blob/main/CHANGELOG.md
Keywords: ai,provenance,llm,attribution,traceability
Classifier: Development Status :: 5 - Production/Stable
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Requires-Dist: black==26.5.1; extra == "dev"
Requires-Dist: ruff==0.16.8; extra == "dev"
Requires-Dist: mypy==2.3.1; extra == "dev"
Provides-Extra: sign
Requires-Dist: cryptography==50.0.2; extra == "sign"
Dynamic: license-file

# hornet-cpl (Python SDK and CLI)

> Signed, chained provenance receipts for AI work, verifiable offline.

`hornet-cpl` emits and verifies **CPL records**: small JSON provenance receipts that say
who or what produced an AI output (a model, agent, tool or person), from which inputs,
through which operation, and what came out. Every input is bound by hash, prompts are
only ever hashed, and records are canonicalized (RFC 8785), hashed (SHA-256) and signed
(Ed25519). Records chain into a tamper-evident DAG that anyone holding your public key can
verify offline, with no call back to your systems.

This package implements the CPL/PEL v0.2 draft specification. A TypeScript
implementation of the same format is published on npm as `hornet-cpl`.

## Install

```bash
pip install "hornet-cpl[sign]"
```

Python 3.10 or later. The core has no runtime dependencies: hashing, canonicalization,
record building and the checks that precede signature verification use only the standard
library. The `sign` extra adds `cryptography`, which is needed to generate keys, sign, and
run the final Ed25519 check of verification. Without it, `hornet_cpl.SIGNING_AVAILABLE`
is `False` and those functions raise a clear error.

## Python API

Everything below imports from `hornet_cpl` itself. The top-level names are the same set
the TypeScript package exports from its index, in snake_case (`verifyBundle` is
`verify_bundle`); `tests/python/test_public_api.py` keeps the two lists in step. The
submodules `hornet_cpl.chain`, `hornet_cpl.pel`, `hornet_cpl.signing`, `hornet_cpl.trust`
and `hornet_cpl.validator` hold the rest.

| Area | Names | What it does |
|---|---|---|
| Emitting | `CPLEmitter`, `EMPTY_HASH` | `emit(...)` builds a record: hashes the content, parameters, prompts (optionally keyed with HMAC) and inputs, links parent records, and signs when given a `signer`. |
| Records | `CPLRecord`, `Origin`, `InputRef`, `Transformation`, `Context`, `Parameters`, `Integrity`, `Signature`, `ProducerType`, `Operation`, `RefType`, `ExecutionEnvironment`, `CPLRecordError`, `CPL_VERSION`, `is_valid_timestamp` | The immutable record model; `to_dict()`, `to_json()`, `from_dict()`, `from_json()`. |
| Encoding | `pel` | `canonicalize` (RFC 8785 JCS), `content_hash`, `parameters_hash`, `record_hash`, `prompt_hash`. |
| Signing | `Signer`, `generate_keypair`, `sign_record`, `verify_signature`, `key_id_for`, `load_private_key` | Ed25519 signing over the PEL signing input. |
| Trust | `load_key_file`, `TrustStore`, `PinnedKey`, `KeyResolver` | Pinned public keys: a verifier trusts exactly the keys in its own key file. |
| Verifying a record | `CPLValidator`, `validate_record`, `validate_record_bytes`, `ValidationReport`, `parse_strict`, `check_record_model`, `check_value`, `Finding` | The PEL verification procedure; returns a report with `valid`, `error_code`, `error_path`, `signed` and more. |
| Chains and bundles | `collect`, `verify_bundle`, `MemoryRecordStore`, `DirectoryRecordStore`, `RecordStore`, `ChainReport`, `CollectError`, `BUNDLE_VERSION`, `DEFAULT_LIMITS` | Collect a record and its complete ancestry into a bundle; verify a bundle against a key file and the artifact bytes. |

```python
from hornet_cpl import (CPLEmitter, MemoryRecordStore, Signer, collect, generate_keypair,
                        key_id_for, pel, validate_record_bytes, verify_bundle)

private_key, public_key = generate_keypair()
signer = Signer(private_key, signer_id="example-agent")
keys = pel.canonicalize([{"key_id": key_id_for(public_key), "algorithm": "ed25519",
                          "public_key": public_key, "signer_id": "example-agent"}])

emitter = CPLEmitter()
draft = emitter.emit(producer_type="local_llm", producer_id="ollama:qwen3:8b",
                     operation="generate", content="A draft.",
                     input_prompt="Write a draft.", signer=signer)
final = emitter.emit(producer_type="local_llm", producer_id="ollama:gemma3:4b",
                     operation="summarize", content="Short.",
                     parent_records=[draft], signer=signer)

report = validate_record_bytes(pel.canonicalize(final.to_dict()), trust=keys,
                               content=b"Short.")
assert report.valid and report.signed

store = MemoryRecordStore()
store.put(draft)
store.put(final)
bundle = collect(final, store, name="final.txt")
assert verify_bundle(pel.canonicalize(bundle), keys, artifact=b"Short.").valid
```

## Command line

The package installs the `hornet-cpl` command:

| Command | What it does |
|---|---|
| `hornet-cpl keygen --out-private F --out-key-file F [--signer-id S]` | Create an Ed25519 private key file (mode 0600) and a key file with the pinned public key. |
| `hornet-cpl emit --spec F [--sign-key F --signer-id S] [--hmac-key-file F]` | Build a record from a JSON spec, optionally signed and with keyed prompt hashes, and print it. |
| `hornet-cpl verify RECORD [--keys F] [--content F] [--require-signature] [--json]` | Verify a record and print the report. |
| `hornet-cpl hash content\|parameters\|record\|prompt [FILE]` | Print a PEL hash. |
| `hornet-cpl bundle --subject F --store DIR -o F [--name N] [--keys F]` | Collect a record and its ancestry from a directory store into a bundle file. |
| `hornet-cpl verify-chain --bundle F --keys F [--artifact F] [--accept-profile chained-only] [--build-info] [--json]` | Verify a bundle and, with `--artifact`, that it covers the artifact bytes; print the chain report. `--accept-profile chained-only` accepts unsigned records that declare that profile; `--build-info` names the build on stderr. |
| `hornet-cpl key-id --public-key PK [--legacy-compat]` | Print the key_id of a public key and, with `--legacy-compat`, the legacy v0.1 identifier a registry may still hold. |
| `hornet-cpl version [--build]` | Print the SDK and CPL versions and, with `--build`, the source commit of this build. |

Exit status: 0 success or valid, 1 verification failed, 2 usage, input or I/O error. The
key-file and spec formats are described in
[FORMATS.md](https://github.com/bsenff-unicornsecurity/hornet-provenance/blob/main/docs/FORMATS.md).

## What a record does not claim

A signature attests that the signer observed the producer produce the record; it does not
prove that a model actually ran. `signed_at` is the signer's claim, not a trusted
timestamp. CPL signatures are not eIDAS qualified electronic signatures or seals, and
nothing here is a conformity assessment: a chain **supports evidence for** an obligation,
it does not comply with one. The full list is in the
[claims register](https://github.com/bsenff-unicornsecurity/hornet-provenance/blob/main/docs/CLAIMS.md).

## Links

- [Project README and quickstart](https://github.com/bsenff-unicornsecurity/hornet-provenance#readme)
- [CPL specification](https://github.com/bsenff-unicornsecurity/hornet-provenance/blob/main/docs/specs/CPL.md)
  (records, chains, bundles) and
  [PEL specification](https://github.com/bsenff-unicornsecurity/hornet-provenance/blob/main/docs/specs/PEL.md)
  (canonical bytes, hashing, signing, verification)
- [Why CPL](https://github.com/bsenff-unicornsecurity/hornet-provenance/blob/main/docs/WHY.md)
- [Changelog](https://github.com/bsenff-unicornsecurity/hornet-provenance/blob/main/CHANGELOG.md)
- [Issues](https://github.com/bsenff-unicornsecurity/hornet-provenance/issues)

## License

Apache-2.0.

## SDK stability in 1.0

The documented public SDK and CLI follow semantic versioning. The 1.x
verifiers continue to accept existing CPL wire 0.2 bundles and the frozen
signed fixtures. Verification dispatches by the declared wire version and
rejects unsupported versions.

Python CLI emission specs require `origin.producer_version` and
`origin.execution_environment`. The TypeScript CLI can default these fields.
Set both explicitly in portable emission specs.
