# Export file format

> The documented JSON Lines format inside every export, and the rules for programs that read it.

From `docs/export.md` in tensile-tools/tensile-auth at commit `e66760d` (v0.4.1-7-ge66760d). The HTML page is https://auth.tensile.tools/docs/migrate/format.

An export file's name ends in `.jsonl.age`. Decrypted, it is UTF-8 JSON
Lines: one JSON object for each line, at most 1 MiB for each line.

- Binary values are base64url without padding.
- Times are RFC 3339 in UTC, with at most microseconds.
- Password hashes are PHC strings, or bcrypt strings that aren't
  upgraded yet.
- Passkey public keys are COSE keys.
- TOTP secrets are base32 without padding.

## Lines

| Line | `type` | Fields |
|---|---|---|
| First | `header` | `format` (`tensile-auth-export`), `version` (`1`), `created_at`, `library_version`, `store` (`postgres` or `sqlite`), `rp_id`, and `origins` |
| Middle | `user` | One user; see the next table |
| Middle | `agent` | `id`, `owner`, `name`, `scopes`, `created_at`, `disabled_at`, `claimed_type`, `type_verified`, and `claimed_at` |
| Last | `end` | `users`, `agents`, `emails`, `passwords`, `passkeys`, `totp`, `recovery_codes`, and `identities`: the count of each record |

## The user line

| Field | Contents |
|---|---|
| `id` | The user ID |
| `email` | `key` (the normalized address), `address`, `created_at`, and `verified_at`, which is left out for an unverified address |
| `password` | `hash`, `version`, and `changed_at`; or `invalidated: true` for a password an administrator invalidated |
| `passkeys` | `user_handle`, and `credentials`: for each, `id`, `name`, `public_key`, `aaguid`, `transports`, `sign_count`, `backup_eligible`, `backup_state`, `prf`, `created_at`, `last_used_at`, `clone_warned_at`, and `data` |
| `totp` | `secret`, `algorithm` (`SHA1`), `digits` (`6`), `period` (`30`), `last_step`, `created_at`, `confirmed_at`, and `disabled_at`, which is set for a locked factor |
| `recovery_codes` | The SHA-256 of each unused code, in lowercase hexadecimal, taken over the code as 24 uppercase Crockford base32 characters without dashes |
| `identities` | For each: `issuer`, `subject`, `created_at`, and `last_used_at`. Google's issuer is `https://accounts.google.com`, and GitHub's is `https://github.com` with the numeric user ID as the subject |

A field is left out when the user has no such record.

## Rules for readers

- Accept major version `1`, ignore unknown fields, and refuse an
  unknown `type`: an unknown record may hold credentials.
- Refuse a file without the `end` line, or with counts that differ from
  the lines read.
- `data` is the passkey credential as the `passkey` package stores it.
  Other products read the documented fields.
- `last_step` is the last TOTP time step used. Refuse a code at or
  before it.
- Unconfirmed TOTP factors and unclaimed agents aren't in the file.
- Sessions, tokens, the audit log, keys, and configuration aren't in
  the file.
