# Decoder and Token Inspector

The Decoder turns encoded, compressed or hashed values from captured
traffic into something you can read, one step at a time, and the Token
Inspector shows what a JWT claims and when it expires. Open it from
Proxy → **Decoder**, the command palette, or **Send to Decoder** in the
right-click menu of any selected text.

**Offline only.** Every transformation runs in the browser tab. Nothing is
sent to the Phantom backend or anywhere else, and nothing is stored: the
input, the chain and its history live in memory and are gone when the tab
closes. Decoded values often hold tokens, so they never reach
localStorage.

## Decode

An input, then a chain of steps. Each step shows its output as text when
it is readable UTF-8, otherwise as a hex dump (toggle per step). A step
that fails shows its error inline and the steps after it wait.

| Group | Steps |
|---|---|
| Decode | URL (bytes, `+` as space), Base64 (standard or URL-safe, missing padding repaired), Base32, hex (`0x`, `\x`, spaces and colons accepted), HTML entities (named and numeric), Unicode escapes (`\uXXXX`, `\u{…}`, `\xXX`), quoted-printable |
| Encode | URL (component or full URL), Base64, Base64url, Base32, hex, HTML entities, Unicode escapes, quoted-printable |
| Compression | gzip, zlib deflate and raw deflate, both ways (browser `CompressionStream`); decompression stops at 16 MiB |
| Format | JSON pretty, JSON minify |
| Text | upper, lower, reverse, ROT13 |
| Hash | MD5 (implemented in Phantom, for identification only), SHA-1, SHA-256, SHA-384, SHA-512 (WebCrypto) |

Steps work on bytes, so binary data survives a chain; text-only steps
refuse binary input with a message. Suggestions for the next step (gzip
and zlib headers, JWTs, percent-encoding, entities, escapes, Base64, hex,
JSON) appear as chips and are never applied on their own.

Undo and redo cover chain edits (buttons, or Ctrl/⌘+Z and Shift+Ctrl/⌘+Z
outside the text fields). The final output can be copied, opened in
Repeater when it is a raw HTTP request, or added to a payload collection
(binary output cannot be).

## Token

Opens by itself when the input is a JWT (a leading `Bearer` is fine).

- Validity now, with a live countdown: valid and expiring in, expired
  ago, not valid yet, or no expiry claim.
- Claims as rows: registered claims (`iss`, `sub`, `aud`, `exp`, `nbf`,
  `iat`, `jti`) explained, times shown in local time, then custom claims.
- Header and signature. The signature is **shown, never verified**, and
  Phantom never guesses or tests secrets.
- Notes: `alg: none` is flagged; HS* is noted as a shared-secret
  signature; `kid`, `jku` and `x5u` are shown as data and never fetched.
- An encrypted token (JWE, five parts) shows its header only.

A selection that still shows a masked secret is refused by **Send to
Decoder**: reveal secrets in the viewer first, then select again.

Code: `frontend/src/utils/decoder/` (pure transforms, detection, JWT,
chain and history, all tested), `stores/decoder.ts`,
`components/proxy/decoder/`.
