Metadata-Version: 2.4
Name: fleetmesh-core
Version: 0.3.0
Summary: Core protocols, typed contracts, and wire primitives for Fleetmesh
License: CC0-1.0
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fleetmesh-schema>=0.2.0
Provides-Extra: postgres
Requires-Dist: psycopg[binary]==3.3.6; extra == "postgres"
Provides-Extra: crypto
Requires-Dist: cryptography>=42; extra == "crypto"
Dynamic: license-file

# Fleetmesh Core

Core protocol primitives, typed contracts, Negentropy reconciliation, and signed budget accounting for **Fleetmesh** ([fleetmesh.org](https://www.fleetmesh.org)).

## Domain Subpackages

`fleetmesh_core` is standard-library-only Python (zero external dependencies, no I/O, no wall clock) organized into eight domain subpackages:

- **`fleetmesh_core.crypto`**:
  - `crypto.py`, `keys.py`, `curve.py`, `bech32.py`: BIP-340 Schnorr, X25519 ECDH, Ed25519, Multikey (`z6Mk...`), HKDF-SHA256, ChaCha20-Poly1305.
  - `nip44.py`, `giftwrap.py`: NIP-44 v2 padded encryption and NIP-59 gift-wrapping (kinds 1059 / 21059).
  - `zk.py`: BN254 pairing and Groth16 verification for `compute:zk-verify-groth16/1.0` (`vectors/groth16.json`).
  - `http_signatures.py`: RFC 9421 HTTP Message Signatures and Digest headers for ActivityPub federation.
  - `ssb.py`: Secure Scuttlebutt Secret Handshake (SHS), Box Stream framing, and V1 feed verification.
- **`fleetmesh_core.identity`**:
  - `identity.py`, `did.py`, `origin.py`, `relaylist.py`: Descriptor validation, PoW, blinded tags, `did:nostr`, `did:key`, `did:peer:2`, and NIP-65 relay lists.
  - `atproto.py`: ATProto `did:plc` genesis operation signing, `did:web` resolution, and K-256 ECDSA verification.
  - `didcomm.py`: DIDComm v2 ECDH-1PU / ECDH-ES envelope packing.
  - `cid.py`, `iroh_ticket.py`: CIDv1 (`bafkrei...`) content addressing and Iroh `NodeTicket` serialization.
- **`fleetmesh_core.peering`**:
  - `peering.py`, `coverage.py`, `projection.py`: Bilateral `peering/1.0` state machine, Kind 30803 coverage claims and handovers, and NIP-85 Kind 30385 projections.
  - `complaint.py`, `reports.py`, `release.py`, `badpeer.py`: `complaint/1.0` notices, Kind 30802 admissibility, Kind 9900/9901 signed releases, and synthetic adversarial peer.
- **`fleetmesh_core.accounting`**:
  - `accounting.py`, `window.py`, `capacity.py`, `strain.py`, `standing.py`: Monotonic receipt chains, AIMD window evaluation, capacity shedding, directional strain, and `standing/1.0`.
  - `cashu.py`, `paidfetch.py`, `market.py`: Cashu BDHKE (NUT-00..24), HTTP 402 PaidFetch quotes, and compute market commitments.
- **`fleetmesh_core.storage`**:
  - `store.py`, `store_postgres.py`: SQLite and PostgreSQL event store and range indexing.
  - `negentropy.py`, `sync.py`, `replication.py`: NIP-77 V1 range-based set reconciliation, delivery envelopes, and blob replication.
  - `blossom_auth.py`, `linked_data.py`: Blossom BUD-01/04 authorization and JSON-LD / Schema.org projections.
  - `car.py`, `mst.py`: Content Addressable aRchives (CAR v1) and ATProto Merkle Search Trees (MST).
- **`fleetmesh_core.services`**:
  - `compute.py`, `dvm.py`, `gossip.py`, `mediation.py`, `nsite.py`, `nwc.py`, `settlement.py`, `sidecar.py`, `ucan.py`.
- **`fleetmesh_core.wire`**:
  - `interfaces.py`, `wire_types.py`, `validate.py`, `schema_files.py`: Typed contracts, strict wire parsers, and cached schema loaders.
  - `cbor.py`, `p2panda.py`: Canonical DAG-CBOR (with Tag 42 CID links) and p2panda Ed25519 + CBOR append-only operation logs.
- **`fleetmesh_core.conformance`**:
  - `runner.py`: Clean-room JSON-lines conformance harness responder (`python3 -m fleetmesh_core.conformance`).
- **`fleetmesh_core.network`** (private networks, fleets and enrolment; kinds 30830–30834, see [fleetmesh.org/networks.html](https://fleetmesh.org/networks.html)):
  - `definition.py`, `roster.py`, `join.py`: Kind 30830 network definitions (`validate`, `read`, `current`), the roster derived from a definition plus the descriptors it names (`roster`, `member_set`), and the join-policy decision for `open` / `credentialed` / `approved` / `invite` (`decide`, `credential_ok`; declines with `network_policy`, `not_member`, `credential_refused`).
  - `fleet.py`, `descriptor_split.py`: A fleet as the set of current Kind 11801 descriptors whose `operator` tag names one DID (`operator_of`, `members`), and the public / network split of a descriptor (`split`, `leaks`).
  - `relay_allow.py`: The roster-protected relay rule (`allow(roster, pubkey, kind, op)`): NIP-42 authenticated roster members only, with Kind 30830 admitted on an empty roster.
  - `grant.py`: Kind 30832 capability grants as BIP-340 UCANs (`issue`, `decode`, `envelope`, `grant_id`), Kind 30833 revocation lists (`revoked`, `revoked_by_issuer`), the capability vocabulary (`capability_uri`, `is_capability`), and the chain verifier (`verify` / `decide`): at most four links from the operator, tier TTLs, attenuation and revocation, each refusal a `ChainRefused` code.
  - `enrol_token.py`: The `fleet/enrol` token (`fmenrol1` + UCAN) bound to one node key: `issue`, `decode`, `verify` / `decide`; refusals are `TokenRefused` codes such as `audience_mismatch`, `token_malformed`, `token_legacy`, plus any grant verifier code.

## Installation

```sh
pip install -e .
```

## Running Tests

```sh
PYTHONPATH=. python3 tests/test_discovery.py
PYTHONPATH=. python3 tests/test_negentropy.py
PYTHONPATH=. python3 tests/test_strain.py
```

## Licence

[CC0 1.0 Universal](LICENSE)
