moreinlaw-kernel 0.3.3

The MoreInLaw federation protocol: what every instance must agree on to stay on the network.
Documentation
# moreinlaw-kernel

The rules every copy of MoreInLaw must share to stay on the network. An organization can fork
the app, rebrand it and rebuild every screen; as long as it depends on this crate unchanged, the
other instances still find it, prove its address and count its verifications.

A copy that edits these rules still runs. It just stops being seen: other instances refuse its
events, and it refuses theirs.

## The one rule for what belongs here

Code belongs in the kernel if two instances must agree on it byte for byte to understand and
trust each other. Anything one instance could change without another noticing stays out.

| In the kernel | Outside it |
|---|---|
| Event kinds, tags, `d` values, schema version | Screens, branding, wording |
| How a registration, list or badge is built and checked | Where rows are stored |
| The paths peers call on each other | Which relays an instance actually uses (the kernel only ships the defaults) or which HTTP client |
| Size limits and time windows that decide acceptance | Sync timers, retries, logging |

## Constraints

- **Pure.** No tokio, sqlx, actix, reqwest, filesystem or environment access. Functions take
  their inputs as arguments, including the clock where it matters (`*_at` variants).
- **Same `nostr` as the backend** (0.33), re-exported as `moreinlaw_kernel::nostr`, so an
  `Event` crosses the boundary without conversion.
- **Frozen values.** `params.rs` is never edited, only extended. A different value means a new
  schema version that old and new instances can tell apart.

## Modules

| Module | Holds |
|---|---|
| `params` | Event kinds (`BADGE_KIND`, `ORG_DIRECTORY_KIND`, `REGISTRATION_KIND`, `LIST_KIND`, `ROSTER_KIND`, `NIP98_KIND`, `MANIFEST_KIND`), `SCHEMA_VERSION`, `DISCOVERY_TAG`, `d` values (`ORGS_SET_D`, `VERIFIED_SET_D`, `ROSTER_D`, `NIP58_DEFINITION_SLUG`) and limits (`MAX_NAME_CHARS`, `MAX_RELAYS`, `MAX_URL_CHARS`, `MAX_LIST_COORDS`, `NIP98_WINDOW_SECS`) and the default relay list `DEFAULT_RELAYS` |
| `params::routes` | The paths peers call on each other: `HOST_IDENTITY`, `HOST_BRANDING_LOGO`, `FEDERATION_SUMMARY`, `FEDERATION_HELLO`, `FEDERATION_VERIFICATIONS`, `DEFAULT_API_SUFFIX` |
| `registration` | The kind-30779 registration: `RegistrationInput`, `HostRegistration`, `validate_input`, `build_registration_event`, `build_registration_event_at`, `parse_registration`, `valid_slug`, `check_https_url`, `check_relay`, `effective_api_base` |
| `lists` | `30779:<hex>:<slug>` coordinates and the two kind-30003 lists: `coord`, `parse_coord`, `build_org_set`, `build_org_set_at`, `build_verified_list`, `parse_list` |
| `nip98` | Peer-to-peer request auth: `nip98_header`, `verify_nip98`, `verify_nip98_at` |
| `proof` | The address proof: `HostIdentityResponse`, `check_identity`, `api_on_own_site`, `registration_for`, `accept_registration`, `is_public_ip`, `NO_REGISTRATION_ERROR` |
| `count` | How many organizations vouch for another: `PeerList`, `verified_by_count` |
| `badge` | The kind-30777 lawyer badge: `Badge`, `build_badge`, `build_badge_at`, `parse_badge`, `STATUS_ACTIVE`, `STATUS_REVOKED` |
| `directory` | The maintainer-signed kind-30778 entry, behind the `directory` feature: `EntryStatus`, `DirectoryOrg`, `build_directory_event`, `build_directory_event_at`, `build_withdrawal` |
| `manifest` | The kind-4777 verification manifest: `verify_manifest`, `reviewed_hash`, `sha256_hex`, `ManifestObject`, `VerifiedManifest`, `ManifestRejection`, `KINDS`, `CIPHER`, `SCREENING_LABELS` and limits (`FUTURE_SKEW_SECS`, `MAX_NAME_LEN`, `MAX_COUNTRY_LEN`, `MAX_ADDRESS_LEN`, `MAX_CONTENT_LEN`, `MAX_WRAPPED_KEY_LEN`) |

`routes` lives inside `params`; it has its own row only to keep the table readable. Each module
also re-exports the kind it handles from `params`, and the crate root re-exports `nostr`.

```toml
moreinlaw-kernel = "0.3"
# the maintainer instance also signs directory entries:
moreinlaw-kernel = { version = "0.3", features = ["directory"] }
```

## Tests

```bash
cargo test
```

Each module carries its own unit tests. The frozen vectors (`tests/vectors/`, events signed once
with a published test key and never regenerated) and their generator (`examples/gen_vectors.rs`)
are kept by the maintainers outside this repository; they catch a change that would make other
organizations' existing events unreadable.

To add a vector for a new schema version:

```bash
cargo run --example gen_vectors -- <name> > tests/vectors/<name>.json
```

## Changing the kernel

A change that alters what is accepted or produced is a protocol change, not a refactor:

1. Add a new schema version; keep parsing the old one.
2. Add vectors for the new version; leave the old vectors untouched and passing.
3. Raise the crate's minor version (major, once past 1.0).