# OIP-0016: Discovery and namespaces for planetary scale

| Field | Value |
|---|---|
| Status | DRAFT |
| Affects | §4.1 (UNI, authority and external identifier rows), §4.2 (AuthorityDocument row), new §14; schemas `authority-document` (new), `sensor-passport` and `node-manifest` (optional `externalIds`); new register `registers/external-id-schemes.yaml`; `registers/functions.yaml` (`federate` objects) |
| Protocol version | obsp/0.1 (additive) |

## Problem

A UNI (`uni:<kind>:<local>`) is unique only inside the trust domain that issued it. Two grids can both issue
`uni:site:site001`, and a record that crosses a federation boundary has no way to say whose identifier it carries.
There is also no standard place to find a trust domain's keys, gateway, exchange landing page, records catalogue or
transparency log, so every federation is configured by hand. Finally, identifiers that other bodies already assign to
the same stations, channels, ships, aircraft and floats (WIGOS, FDSN, IGS, COSPAR, IMO, ICAO and others) have no typed
home, so they end up in free text or, worse, personal identifiers (IMSI, IMEI, MAC addresses) are used as station keys.

## Change

### Normative text (new §14 "Authorities, discovery and external identifiers")

The full text is in `patches/spec.patch`; in short:

| Id | Requirement |
|---|---|
| DSC-1 | UNI form `uni:<kind>:<local>` or `uni:<authority>:<kind>:<local>`; authority a lower-case DNS name (two or more labels, last label starts with a letter, so never an IP address) or `did:web:<host>`; kind `^[a-z][a-z0-9-]{0,31}$`, never `did`; no colon in the local part, so the forms are unambiguous |
| DSC-2 | A UNI without an authority is read in the default authority (the issuer's trust domain); byte comparison; a UNI is never rewritten by a party that did not issue it |
| DSC-3 | The AuthorityDocument is served at `https://<host>/.well-known/obsp` (RFC 8615), `application/json` over TLS, and its `authority` equals the authority it is served for |
| DSC-4 | At least one key (public JWK, RFC 7517, or key-record reference); no private or symmetric key material; https endpoints and policies; the contact is a form URL, never an e-mail address or `mailto` |
| DSC-5 | A resolver refuses expired documents and lower sequence numbers, fetches only from authorities its operator configured (SOV-1) and works offline from pinned documents |
| DSC-6 | Every `externalIds` entry names a register scheme and a value matching its pattern and check digit |
| DSC-7 | Identifiers of people, subscriptions and personal devices (IMSI, SUPI, IMEI, MSISDN, MAC and the others under `neverSchemes`) are never schemes and never carried |
| DSC-8 | An external identifier is an alias: never the record's UNI, never a reason to merge records |
| DSC-9 | The AuthorityDocument SHOULD be signed with a key it lists (signature envelope of OIP-0008); an unsigned successor of a signed document SHOULD be refused |

The section ends with an informative table of design targets (100 000 authorities, 10^12 UNIs, 10^7 observations
per second across federated exchanges, a document of at most 64 KiB, one round trip to resolve, none when pinned,
constant-time lookup by scheme and value). They carry no key word and are not conformance requirements.

### Contract: `authority-document` (schemaVersion `3.1.0`)

| Property | Required | Shape |
|---|---|---|
| `schemaVersion`, `apiVersion`, `kind`, `protocolVersion` | yes | `3.1.0`, `obsp/authority-document/v3.1`, `AuthorityDocument`, `obsp/0.1` |
| `authority` | yes | `$defs.Authority` (DSC-1) |
| `sequence` | yes | integer ≥ 1, increases with every document (DSC-5) |
| `issuedAt`, `expires` | yes | date-time; invariant: `expires` after `issuedAt` |
| `operatorUni` | no | UNI; when it names an authority, it is this one |
| `keys` | yes | `jwks` (public JWKs; `d`, `p`, `q`, `dp`, `dq`, `qi`, `oth`, `k`, `priv` refused) and/or `keyRecords` (`kid` `uni:key:…`, https `uri`, `digest`) |
| `endpoints` | yes | at least one of `gateway`, `exchange` (OGC API landing page), `records` (catalogue), `transparencyLog`, `revocations`; https only |
| `profiles`, `protocolVersions` | yes | declared profiles (a declaration, never a level); `obsp/<major>.<minor>` |
| `uniKinds` | no | kinds the authority issues |
| `policies` | no | `{kind, uri, digest?}` with kinds `DATA`, `LICENCE`, `PRIVACY`, `RETENTION`, `ACCEPTABLE_USE`, `SECURITY_DISCLOSURE`, `CORRECTION` |
| `contact` | yes | `{form, topics?}`; `form` an https URL with no `@` and no `mailto`; no other member |
| `signature` | no | `$defs.SignatureEnvelope`, copied verbatim from OIP-0008 with its `Digest` and `ProtocolRole` |
| `extensions` | no | namespaced bag |

`sensor-passport` and `node-manifest` gain an optional `externalIds` array of `$defs.ExternalId` (`scheme`, `value`);
the schema refuses the never-schemes by name.

### Register `registers/external-id-schemes.yaml`

Thirteen schemes, each with the pattern, check digit where one exists, the assigning body, the defining document cited
by identifier (text not copied), a privacy class (`none` or `indirect`), examples and counter-examples, and
`checked: not checked`: `wigos`, `fdsn-nslc`, `igs-station`, `cospar`, `norad`, `mmsi`, `imo-ship` (check digit),
`icao24`, `lwm2m-endpoint` (refuses names built from IMEI or IMSI URNs), `opcua-nodeid` (namespace URI form only),
`gs1-gln` and `gs1-gtin` (check digit), `argo-wmo`. `neverSchemes`: `imsi`, `supi`, `suci`, `gpsi`, `imei`, `imeisv`,
`pei`, `msisdn`, `iccid`, `mac`. Layout: `registers/external-id-schemes.schema.json`. The validator (part of the
`registers` group) checks the layout, compiles every pattern, runs examples and counter-examples both ways with check
digits, refuses a never-scheme as a scheme and checks every schema with `externalIds` refuses all never-schemes.

### Reference code

`sdk/python/src/obsp/ids.py`: `parse_uni` reads both forms (`Uni.authority` is `None` for the default authority),
`Uni.qualified(authority)`, `is_authority`. `sdk/python/src/obsp/discovery.py`: the invariants
`authority-document-consistent` and `external-ids-registered`, registered when the package is imported.

## Compatibility

Additive. The UNI pattern (`$defs.Uni`) is unchanged and already admits the qualified form; every UNI written so far is
a default-authority UNI with the same kind and local part. `sdk/python/tests/test_discovery.py` proves it by parsing every typed
UNI in every positive fixture and example set (more than 50) and checking it reads with no authority and prints back
byte for byte. `externalIds` is optional on both schemas. No existing document changes except the two NODE example
documents, which gain an `externalIds` entry.

## Tests

| Requirement | Case | Kind |
|---|---|---|
| DSC-3, DSC-4, DSC-5, DSC-9 | CT-GRID-090 | invariant `authority-document-consistent` on `authority-document` |
| DSC-6, DSC-7 | CT-NODE-090 | invariant `external-ids-registered` on `node-manifest`, `sensor-passport` |
| DSC-1, DSC-2, DSC-8 | CT-NODE-091 | manual: `conformance/vectors/uni/uni.json` (7 valid, 13 invalid), relay without rewriting, no merge on alias |
| DSC-3, DSC-4, DSC-5, DSC-9 | CT-NODE-092 | manual: fetch from the well-known location; pinned, offline, unconfigured, expired, rolled-back, unsigned-successor |

Positive fixtures: `authority-document.dns.valid`, `.did-web.valid`, `sensor-passport.external-ids.valid`,
`node-manifest.external-ids.valid`. Negative fixtures, one rule each: `authority-document.email-contact`,
`.mailto-form`, `.private-jwk`, `.ip-authority`, `.uppercase-authority`, `.http-endpoint`, `.no-keys`,
`.did-web-with-path`, `.unknown-profile`; `sensor-passport.personal-external-id` (imei);
`node-manifest.personal-external-id` (mac), `.external-id-without-value`. Unknown schemes, pattern and check-digit
failures are invariant failures (schema cannot see the register) and are tested in `test_discovery.py`; the register
itself has seven validator tests in `tests/test_validate.py`.

## Relation rows proposed on acceptance (not in the patches)

`registers/implements-edges.json` is regenerated from `registers/relations.yaml` and several drafts change its count, so
the patches leave both files alone. On acceptance, append and run `python3 tools/build_edges.py`:

```yaml
  - { id: EXT-RFC8615, standard: 'RFC 8615 (well-known URIs)', kind: aligns-with, functions: [federate, exchange], schemas: [authority-document] }
  - { id: EXT-DIDWEB, standard: 'W3C DID 1.0 and the did:web method specification', kind: aligns-with, functions: [federate], schemas: [authority-document] }
  - { id: EXT-RFC7517, standard: 'RFC 7517 (JSON Web Key)', kind: aligns-with, schemas: [authority-document] }
  - { id: EXT-WIGOS-ID, standard: 'WMO-No. 1160, WIGOS station identifier', kind: aligns-with, functions: [describe], schemas: [node-manifest, sensor-passport] }
```

(If OIP-0008 is accepted first, its `EXT-JWK` row gains `authority-document` instead of a new `EXT-RFC7517`.)

## Open questions

1. Well-known suffix: `obsp` is not registered in the IANA well-known URI registry. Registering it is the steward's
   decision (RFC 8615, section 3.1); until then the suffix is provisional.
2. did:web: only the host form is an authority (no port, no path), which keeps parsing unambiguous. Is a path form
   needed for authorities hosted under a shared domain?
3. Key ids across authorities: OIP-0008's `kid` pattern admits only `uni:key:<local>` (default authority). Should a
   qualified key UNI (`uni:<authority>:key:<local>`) be allowed for cross-domain verification?
4. Every register row is `checked: not checked`; patterns, owners and clauses need checking against the cited sources
   (in particular the FDSN long form, the Alpha-5 catalogue numbers and the Argo numbering).
5. Coverage placement: the cases use `federate` and `join` because the index rows of §5.3 and §5.10 are being changed by
   OIP-0001, OIP-0005 and OIP-0009 to OIP-0013, and a case under `describe` or `exchange` would stop those patches
   applying. Manual cases for the authority (OBSP-GRID) and the resolver (OBSP-CONSUMER) should join on acceptance, with
   their attestations merged into the example sets those drafts also create.
6. Section number: §14 follows §13; OIP-0018 adds §15. If OIP-0018 is accepted first, the two sections swap numbers.
7. Last call: revision (30 days) or new capability (90 days)?
