Metadata-Version: 2.4
Name: veritable-verify
Version: 0.3.1
Summary: Offline verification for Veritable signed certificates and report envelopes (ed25519, no dependencies).
Author: Intelth LLC
License-Expression: Apache-2.0
Project-URL: Homepage, https://veritabledatabase.com/verify
Project-URL: Documentation, https://veritabledatabase.com/verify
Keywords: verification,ed25519,certificates,signature,offline
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
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: Topic :: Security :: Cryptography
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Dynamic: license-file

# veritable-verify

Offline verification for **Veritable** signed certificates and report
envelopes produced by EnergyIR. Free, pure Python, zero dependencies.

```bash
pip install veritable-verify
veritable-verify certificate.json --pubkey <hex>
```

```python
from veritable_verify import verify_envelope

res = verify_envelope(envelope_dict_or_json, public_key_hex="<hex>")
res.valid, res.digest, res.licence  # bool, sha256, licence stamp dict
```

What it checks:

- envelope schema (`level`, `method`, `bound`, `artifact_b64`, `signed`)
- the ed25519 signature (RFC 8032) over `b"energyir-certificate/1\n"` + the signed artifact
  bytes. The prefix separates certificate signatures from everything else the same key signs
- that the envelope shown is the certificate that was signed, for every schema version: the
  signed bytes must be the canonical JSON object `{level, method, bound}`, the level and
  method shown must be the signed ones, and the bound shown (apart from the signature and
  licence fields added after signing) must be exactly the signed bound. A certificate that
  carries a witness signs it beside the body under a fixed key for its method
  (`WITNESS_ONLY_KEYS`); no other difference is allowed. An edited envelope has
  `signature_ok` True and `valid` False
- the artifact digest (`sha256` of the signed artifact; see https://veritabledatabase.com/verify)

It also **displays** the licence stamp (`license_id`, holder, org, type). The stamp is added
after signing and is **not covered by the signature**: treat it as information, not proof.

It cannot mint licences, sign artifacts, or run the engine — verification is
public-key-only math. Verification **fails closed**: any malformation returns
`valid=False` with a reason.

## Certificates issued before 2026-11-16

**Library callers:** in 0.3.1 an older certificate returns `res.valid == True` with
`res.warning` set. Check `res.warning` (or pass `accept_legacy=False`) if your program must
refuse the older form now.


They were signed over the bare artifact bytes, with no certificate prefix. 0.3.1 accepts them
with a warning. From 0.4.0 they are **refused by default**: a bare signature is tied to the bytes only, so the same key's signature
over anything that is byte for byte a certificate body would pass. To verify one you know was
issued as a certificate, ask for the older form by name:

```bash
veritable-verify old-certificate.json --pubkey <hex> --accept-legacy-signature
```

```python
res = verify_envelope(env, public_key_hex="<hex>", accept_legacy=True)  # only the literal True
res.signature_scheme  # "energyir-certificate/1" or "bare (issued before 2026-11-16; ...)"
```

The body comparison above applies to them too.

## Versions

See `CHANGELOG.md`. In short:

- **0.3.1**, the first release on PyPI, is a transition release: a certificate issued before
  2026-11-16 (bare signature) is accepted with a warning.
- **0.4.0** refuses such a certificate unless `--accept-legacy-signature` is given. Nothing
  else differs.

## Trust model

`bound.public_key` is self-asserted: it proves the envelope is internally
consistent, not that it came from a signer you trust. Pass `--pubkey` /
`public_key_hex=` to pin the expected key for a real authenticity decision.

## Certificate refs (schema v3)

From 0.2.0 the verifier reads `bound.schema_version` 1, 2 and 3, and refuses
any newer version. A v3 certificate carries `bound.ref`, the position in a
source's history it attests, as `kind:value` or `kind:value@scope`:

| kind | value | refused |
|---|---|---|
| `pg_lsn` | Postgres `X/Y`, canonical uppercase, no padding | `0/0` |
| `delta_version` | decimal, 0 to 2^63-1, no leading zeros; scope = table full name (required) | negatives |
| `iceberg_snapshot` | decimal int64; scope = table full name (required) | `-1` |

For v3 the verifier also checks that the displayed `bound` equals the signed
one (apart from the signature fields), so an edited `ref` is rejected even
though the signature still verifies (`signature_ok` stays True, `valid` is
False). An optional `bound.base_ref` must be valid and on the same axis.
`--expect-ref KIND:VALUE@SCOPE` requires a specific position.

```bash
veritable-verify cert.json --pubkey <hex> --expect-ref delta_version:41@main.sales.orders
```
