Repository Public BSD-3-Clause
1# The `.orixmap` region package — format 1.023Status: implemented in `Packages/ORIXMapPackage` (reader, writer, verifier, installer) and4`Infrastructure/package-builder` (`orix-package`). This document is the reference; the code follows it and the tests5in `Packages/ORIXMapPackage/Tests` check every rule stated here.67## 1. What it is89A `.orixmap` file is one region of the map, ready to be used offline: a **signed container of ordinary files**. It is10not a codec and it defines no new data encoding. After installation each component is a normal file that its consumer11opens by path.1213| Component id | File name in an installed region | Content | Media type recorded by the builder |14|---|---|---|---|15| `map` | `map.pmtiles` | PMTiles v3 archive of Mapbox Vector Tiles | `application/vnd.pmtiles` |16| `search` | `search.sqlite` | SQLite database (FTS5 + R-tree search index) | `application/vnd.sqlite3` |17| `routing` | `routing.orixgraph` | memory-mapped routing graph | `application/vnd.orix.graph` |18| `terrain` | `terrain.pmtiles` | PMTiles v3 archive of elevation tiles (optional; no producer yet) | `application/vnd.pmtiles` |1920The file extension is `.orixmap`, the media type `application/vnd.orix.map`.2122**File names never come from the package.** A package only carries component *identifiers*; the installer maps the four23identifiers above to the four fixed file names above and writes nothing else. An identifier it does not know is verified24and skipped. There is no path, no directory and no file name anywhere in the format, so path traversal is impossible by25construction — and identifiers are additionally restricted to `[a-z0-9-]{1,32}` (see 4.3), which the tests exercise with26hostile values (`../map`, `/etc/passwd`, `map.pmtiles`, NUL bytes, look-alike Unicode…).2728## 2. File layout2930All integers are **little-endian**. Offsets are from the start of the file.3132```33offset 0 ┌──────────────────────────────┐34 │ header (64 bytes in 1.0) │ fixed prefix: enough to know the size of the preamble35headerLength ├──────────────────────────────┤36 │ manifest (UTF-8 JSON) │ manifestLength bytes — the signed bytes37 ├──────────────────────────────┤38 │ signature (Ed25519, 64 B) │ over the exact manifest bytes39preambleLength ├──────────────────────────────┤40 │ zero padding │ up to the next multiple of 409641 ├──────────────────────────────┤42 │ component 1 │ at manifest.components[0].offset43 ├──────────────────────────────┤44 │ zero padding │ up to the next multiple of 409645 ├──────────────────────────────┤46 │ component 2 … │47totalLength └──────────────────────────────┘ the file ends with the last byte of the last component48```4950`preambleLength = headerLength + manifestLength + signatureLength`. A client learns it from the first 64 bytes, so it51can fetch the preamble alone with one or two HTTP Range requests, verify the signature and show the exact content,52sizes, licences and compatibility of a package **before downloading it**; the rest is then downloaded, and resumed, by53byte range.5455### 2.1 Header5657| Offset | Size | Type | Field | Value / rule |58|---:|---:|---|---|---|59| 0 | 8 | bytes | magic | `4F 52 49 58 4D 41 50 1A` (`ORIXMAP` + 0x1A) |60| 8 | 2 | u16 | format major | `1`. Any other value: reject |61| 10 | 2 | u16 | format minor | `0`. Any value is accepted (see 6) |62| 12 | 4 | u32 | header length | `64` in 1.0. Accepted range 64…4096; bytes beyond 64 are skipped |63| 16 | 4 | u32 | manifest length | 1…1 048 576 |64| 20 | 4 | u32 | signature length | `64` |65| 24 | 2 | u16 | signature algorithm | `1` = Ed25519. Any other value: reject |66| 26 | 2 | — | reserved | written as zero, ignored |67| 28 | 4 | u32 | flags | none defined in 1.0; written as zero, ignored |68| 32 | 8 | bytes | signing key identifier | the 8 raw bytes whose hexadecimal form is the 16-digit key id |69| 40 | 8 | u64 | total length | length of the whole file |70| 48 | 16 | — | reserved | written as zero, ignored |7172The header itself is not signed, and does not need to be: every field that matters is bound to the signed manifest.7374- *manifest length*, *header length*, *signature length*: any wrong value makes the signature check read other bytes and75 fail.76- *signing key identifier*: must equal `signingKeyId` of the manifest (`signingKeyMismatch` otherwise), and the signature77 must verify under that key.78- *total length*: must equal `downloadSize` of the manifest and the real size of the file.79- *minor version, flags, reserved bytes*: carry no meaning in 1.0 and are ignored. They are the only bytes of a file that80 can change without invalidating it.8182### 2.2 Manifest8384`manifestLength` bytes of UTF-8 JSON (no BOM; UTF-16/32 are refused), one object. See section 4.8586### 2.3 Signature878864 bytes: the Ed25519 signature (RFC 8032, as produced by CryptoKit `Curve25519.Signing`) of **exactly the89`manifestLength` manifest bytes as stored** — no canonicalisation, no re-encoding. A reader verifies the signature on the90raw bytes first and only then parses them: nothing in the manifest is interpreted before it is authenticated.9192The manifest contains the length and the SHA-256 of every component and the total length of the file, so the signature93authenticates the whole file.9495CryptoKit's Ed25519 signatures are randomised: building the same package twice gives two files that differ in these9664 bytes and nowhere else.9798### 2.4 Components and padding (canonical layout)99100- Components appear in the file in the order of `manifest.components`.101- Every component starts at a multiple of **4096**.102- The first component starts at the first multiple of 4096 that is ≥ `preambleLength`; each following component starts103 at the first multiple of 4096 that is ≥ the end of the previous one. No other gap is allowed.104- The file ends with the last byte of the last component: `totalLength = offset + length` of the last component.105- Padding bytes are zero. A reader checks them.106107With these rules a package has exactly one valid byte sequence for a given manifest, signature and set of components108(up to the ignored header fields of 2.1): there is no slack space in which unauthenticated data could travel.109110Container overhead is therefore `preamble + padding`: at most `4096 × (number of components)` bytes plus the size of a111manifest larger than one page (measured: 4 185 bytes for a 236 MB three-component package).112113## 3. Limits114115A reader rejects a package beyond any of these limits before using it (`PackageLimits.standard`; an application may116lower them).117118| What | Limit |119|---|---|120| Manifest size | 1 MiB (1 048 576 bytes) |121| Header length | 64…4096 bytes |122| Number of components (known + unknown) | 16 |123| Size of one component | 1 byte … 32 GiB |124| Total file size | 64 GiB |125| Short strings (names, sources, licence names, URLs) | 512 UTF-8 bytes, not empty, no control character |126| Attribution text | 4096 UTF-8 bytes |127| Media type, builder names and versions | 128 / 64 / 64 UTF-8 bytes |128| Number of licences | 1…32 |129| Number of languages, of localized names | 32 |130| Number of builder entries | 32 |131| Zoom levels | 0 ≤ minZoom ≤ maxZoom ≤ 24 |132| Region id | `[a-z0-9-]{1,64}` |133| Component id | `[a-z0-9-]{1,32}`, unique in a package |134| Version strings | 1 to 4 groups of 1 to 9 decimal digits separated by `.` |135136Arithmetic: every `offset + length`, every sum of lengths and every alignment is computed with overflow detection; an137overflow is an error (`invalidLayout(.offsetOverflow)`), never a wrapped value. JSON numbers that do not fit an unsigned13864-bit integer (negative, fractional, too large, quoted) make the manifest undecodable.139140Placement checks, in this order for each component: offset multiple of 4096; offset ≥ `preambleLength`; no overlap with141the previous component; `offset + length ≤ totalLength`; offset equal to the canonical one. Then `totalLength` equals142the end of the last component, the header value, `downloadSize` and the size of the file on disk. Then, while the143component is streamed: exactly `length` bytes are read (`truncated` otherwise) and their SHA-256 equals the manifest144value (`componentChecksumMismatch` otherwise).145146## 4. Manifest147148### 4.1 Example149150The manifest of the Greater Montréal development package built on 2026-11-25 from real components (pretty-printed151here; stored on one line with sorted keys):152153```json154{155 "bbox": { "maxLat": 45.95, "maxLon": -73.15, "minLat": 45.15, "minLon": -74.35 },156 "buildDate": "2026-11-25T08:33:51Z",157 "builder": { "orix-package": "1.0.0" },158 "capabilities": ["map", "search", "routing"],159 "components": [160 { "formatVersion": 3, "id": "map", "length": 96370599, "mediaType": "application/vnd.pmtiles",161 "offset": 4096, "sha256": "2a9051192b6e6b12ebca351ba0f71c8d1ce5b57b7015a28ca9a8e2f7c87ea807" },162 { "formatVersion": 1, "id": "search", "length": 40460288, "mediaType": "application/vnd.sqlite3",163 "offset": 96374784, "sha256": "ad542b9daacbdb9ad418ef518976a4e4c2c9335338015a58f37793a4e740bd01" },164 { "formatVersion": 1, "id": "routing", "length": 99315712, "mediaType": "application/vnd.orix.graph",165 "offset": 136835072, "sha256": "aaa26d20a0f2f942f76a9b4a0566b4d873bea22872f371f6f33dd12267c30486" }166 ],167 "dataTimestamp": "2026-11-24T00:00:00Z",168 "dataVersion": "2026.11.24",169 "downloadSize": 236150784,170 "format": "orixmap",171 "installedSize": 236146599,172 "languages": ["en", "fr"],173 "licences": [174 { "attribution": "© OpenStreetMap contributors", "licence": "ODbL-1.0", "source": "OpenStreetMap",175 "url": "https://www.openstreetmap.org/copyright" },176 { "attribution": "Made with Natural Earth", "licence": "Public domain", "source": "Natural Earth",177 "url": "https://www.naturalearthdata.com/about/terms-of-use/" }178 ],179 "mapZoom": { "maxZoom": 15, "minZoom": 0 },180 "names": { "en": "Greater Montréal", "fr": "Grand Montréal" },181 "regionId": "ca-qc-montreal",182 "schemaVersion": 1,183 "signingKeyId": "92853604e9033917"184}185```186187### 4.2 Members188189| Member | Type | Required | Rule |190|---|---|---|---|191| `format` | string | yes | `"orixmap"` |192| `schemaVersion` | integer | yes | `1`. A greater value is refused **before any other member is read** (`unsupportedSchemaVersion`) |193| `regionId` | string | yes | `[a-z0-9-]{1,64}`. Identifies the region across versions; used as a directory name by the store |194| `names` | object | yes | language tag → display name; `en` and `fr` mandatory |195| `bbox` | object | yes | `minLat`, `minLon`, `maxLat`, `maxLon` in WGS 84 degrees; finite, inside ±90 / ±180, `minLat < maxLat`, `minLon ≠ maxLon` (`minLon > maxLon` means the box crosses the antimeridian) |196| `dataVersion` | string | yes | dotted decimal version (`2026.11.24`, `7`), compared numerically group by group; **strictly increasing** from one publication of a region to the next |197| `dataTimestamp` | string | yes | timestamp of the OpenStreetMap data, `YYYY-MM-DDTHH:MM:SSZ` exactly |198| `buildDate` | string | yes | when the package was assembled and signed, same syntax |199| `mapZoom` | object | if `map` is present | `minZoom`, `maxZoom` of the `map` component |200| `languages` | array of strings | yes | language tags for which the data carries localized names |201| `licences` | array | yes, ≥ 1 | objects `{source, licence, attribution, url}`; `url` is `http(s)` |202| `capabilities` | array of strings | yes | exactly the known component ids present (`map`, `search`, `routing`, `terrain`), no duplicate; unknown values are tolerated |203| `downloadSize` | integer | yes | length of the whole file in bytes |204| `installedSize` | integer | yes | sum of the lengths of all components |205| `components` | array | yes, ≥ 1 | see 4.3; at least one known component |206| `signingKeyId` | string | yes | 16 lowercase hexadecimal digits; equals the header key id |207| `builder` | object | yes | tool name → version (`"orix-package": "1.0.0"`, `"tile-builder": "…"`) |208| `minAppVersion` | string | no | oldest application version able to use the package (dotted decimal) |209210Language tags: `[a-z]{2,3}` followed by up to three `-[A-Za-z0-9]{2,8}` subtags.211212Unknown members, at any level, are **ignored**. They are covered by the signature like everything else.213214### 4.3 Components215216| Member | Type | Rule |217|---|---|---|218| `id` | string | `[a-z0-9-]{1,32}`, unique. Known: `map`, `search`, `routing`, `terrain` |219| `offset` | integer | first byte of the payload (see 2.4) |220| `length` | integer | 1 … 32 GiB |221| `sha256` | string | 64 lowercase hexadecimal digits, SHA-256 of the `length` bytes at `offset` |222| `mediaType` | string | informative |223| `formatVersion` | integer | 1…65535: version of the component's own format (PMTiles: 3; search index and routing graph: their schema version). The application declares the range it supports per component and refuses a package outside it |224225A component with an unknown (but well-formed) identifier is an **optional extension**: it is verified like the others226(placement, length, SHA-256) and not installed. A component that an older application *must* understand cannot be added227without bumping `schemaVersion` or `minAppVersion`.228229## 5. Signature, keys and trust230231- Algorithm: Ed25519 (`Curve25519.Signing` in CryptoKit). Public key: 32 bytes. Signature: 64 bytes.232- **Key identifier**: the first 16 hexadecimal digits of the SHA-256 of the 32 raw public key bytes. Always computed233 from the key; a trust store entry whose declared `keyId` does not match its key is refused.234- **Trust store** (`TrustStore`): a list of `TrustedKey {keyId, publicKey, label?, notBefore?, notAfter?}` and a list235 `revokedKeyIds`. It is compiled into the application; it is never downloaded.236- Verification order: key revoked → `revokedSigningKey`; key unknown → `unknownSigningKey`; signature wrong →237 `invalidSignature`; then the manifest is decoded; header key id ≠ manifest key id → `signingKeyMismatch`;238 `buildDate` after `notAfter` → `expiredSigningKey`; `buildDate` before `notBefore` → `signingKeyNotYetValid`.239240`notAfter` / `notBefore` are compared with the **signed build date of the package**, not with the clock of the phone241(which is unreliable and would make installed maps expire). They express an orderly retirement: "this key signed nothing242after that date". They do not protect against a stolen key (the thief can write any build date): that is what243`revokedKeyIds` is for.244245Private keys never enter the repository or the application. The builder reads the key from a file given with `--key` or246named by the environment variable `ORIX_PACKAGE_SIGNING_KEY_FILE`; the file must be a regular file (not a symbolic247link), owned by the current user, with no permission for group or others (mode 600 or 400). Expected location on the248build machine: `~/.config/orix-maps/signing/`.249250### 5.1 Key rotation procedure2512521. On the build machine: `orix-package keygen --out ~/.config/orix-maps/signing --label "production 2027"`. Keep the253 `.key` file there (mode 600) and in the owner's offline backup; copy the printed Swift snippet.2542. Application release *N*: add the new public key to the trust store **next to** the old one. Packages are still signed255 with the old key, so every application version keeps working.2563. When release *N* is widely installed, switch the builder to the new key and set `--min-app-version N` on the packages257 it signs. An older application cannot verify them (`unknownSigningKey`); the catalog repeats `signingKeyId` and258 `minAppVersion` so that the application can say "update the app" before downloading anything259 (`trustStore.key(withId:) == nil`).2604. Application release *N+1*: give the old key a `notAfter` equal to the date of the switch. Packages it signed before261 stay valid; nothing built later is accepted under it.2625. Later: remove the old key from the trust store once no published package uses it.263264**Compromised key**: put its identifier in `revokedKeyIds` in an application release, re-sign and republish every265package with a new key under a new `dataVersion`. Installed regions signed by the revoked key keep working until266`RegionStore.verifyInstalled` is run on them (it fails with `revokedSigningKey`); the application then offers to download267them again. A revocation only reaches users who update the application — this is the price of a trust store that no268server can modify.269270## 6. Versioning and compatibility271272| Change | How it is expressed | Old reader |273|---|---|---|274| New optional component | new `id` | verifies it, does not install it |275| New optional manifest member | — | ignores it |276| New header field | `headerLength` > 64, minor version bumped | skips the extra bytes |277| New flag, use of reserved bytes | minor version bumped | ignores them |278| Incompatible manifest (member renamed, semantics changed) | `schemaVersion` 2 | refuses: `unsupportedSchemaVersion` |279| Incompatible component format | `formatVersion` of that component | refuses: `unsupportedComponentFormat` (store) |280| Feature that needs a newer application | `minAppVersion` | refuses: `appTooOld` (store) |281| Incompatible container (other signature placement, other alignment…) | format major 2 | refuses: `unsupportedFormatVersion` |282283Rules for writers: a minor version may only add things an old reader can ignore safely. Anything an old reader must not284ignore requires a new major, a new `schemaVersion`, a new `formatVersion` or a `minAppVersion`.285286## 7. Reading a package safely (normative summary)2872881. Read 64 bytes. Check magic, major, header length, manifest length (against the limit, **before allocating**),289 signature algorithm and length, total length (against the limit and ≥ `preambleLength`).2902. Read the manifest and the signature. Verify the signature under the trusted, non-revoked key named by the header.2913. Decode the manifest (UTF-8 only); refuse an unknown `schemaVersion`; validate every member against section 3 and 4.2924. Check that the header key id equals `signingKeyId`, then the validity window of the key against `buildDate`.2935. Check the layout (2.4, 3) against the header and the size of the file.2946. Stream every component through a bounded buffer: zero padding before it, exact length, SHA-256.2957. Only then make anything visible to the rest of the application (see the installer in296 `Packages/ORIXMapPackage/README.md`).297298Errors are values of `PackageError`; each rule above has its own case, and none of them carries text for the user.299300## 8. What the format deliberately does not do301302- **No compression.** PMTiles tiles are already compressed; the search index and the routing graph are opened in place303 (SQLite, `mmap`) and must not be compressed. Transport compression is the server's business and is disabled for304 artefacts (Range requests).305- **No encryption.** Map data is public; confidentiality is not a goal.306- **No delta updates.** An update is a whole new package. The catalog schema leaves room for it (unknown members are307 ignored).308- **No in-place use.** Components are extracted to their own files at installation: PMTiles, SQLite and the routing309 graph are then ordinary files for their libraries. The 4096 alignment keeps a future in-place or `clonefile`-based310 design possible but nothing relies on it today.311- **No timestamp authority.** `buildDate` is asserted by the signer.312