Skip to main content

Module wasm_token_exchange

Module wasm_token_exchange 

Source
Expand description

Browser-side RFC 8693 token-exchange (#1314) for the wasm client. Pure parsing helpers compile on all targets (unit-tested on native); the browser fetch glue is wasm32-only. Browser-side RFC 8693 token-exchange (#1314) for the wasm client.

The browser VfsShell exchanges an atproto/external JWT for a short-lived hyprstream at+jwt Bearer, then presents that Bearer as the default JWT on every RPC. This module holds:

  • Pure helpers (exchange_form_body, parse_exchange_response, subject_from_access_token) — target-agnostic, unit-tested on native.
  • fetch_exchange_token — the browser fetch glue, wasm32-only (it uses web_sys), mirroring browser_provisioning::fetch_browser_provisioning.

§Authority note

subject_from_access_token decodes the at+jwt sub without signature verification. This is client-side bookkeeping only: it derives a display Subject from the freshly-exchanged Bearer. The token’s authority is never trusted from this decode — the server re-verifies the bearer on every RPC (require_bearer_token / validate_oauth_access_token). The exchange response does not echo sub, and the mint stamps sub = verified.sub (token_exchange.rs), so the client decodes it from the minted token rather than extending the server response.

Structs§

ExchangedToken
A successfully exchanged short-lived access token (#1314 / #1425).
SessionContext
Server-derived browser viewer authority.

Enums§

NonceOutcome
Outcome of one token-exchange fetch attempt, decided from the response’s status/body/headers (RFC 9449 §8 nonce lifecycle). Pure / native-testable: the wasm32 glue calls this after every fetch to decide whether to return, retry with a fresh nonce, or fail (#1425 r1 P1#4).
SessionKind
TokenType
The OAuth token_type of an ExchangedToken.

Constants§

BROWSER_PUBLIC_CLIENT_ID
The well-known public client_id the browser VfsShell presents at the RFC 8693 token-exchange endpoint (#1425).
GRANT_TYPE
The RFC 8693 token-exchange grant type.
ISSUED_TOKEN_TYPE
Issued-token type the #1314 endpoint always mints (at+jwt / access_token).
SESSION_EXCHANGE_PATH
Browser session exchange route on the hyprstream OAuth origin.
WHOAMI_PATH
Server-derived viewer context route on the hyprstream OAuth origin.

Functions§

assemble_dpop_proof
Assemble a complete DPoP proof JWT from the signing input and signature.
classify_exchange_error_code
Classify a fetch_exchange_token (or verify_sender_bound_token) failure message into a stable error code for hyprstream-rpc-std::browser_session.
decide_nonce_outcome
Decide the next action for a token-exchange fetch attempt.
dpop_ath
Compute the DPoP ath value: base64url(SHA-256(access_token)).
ed25519_dpop_jkt
Compute the RFC 7638 JWK thumbprint (cnf.jkt) for an Ed25519 public key.
ed25519_dpop_signing_input
Build the RFC 9449 DPoP JWT signing input (header.payload) for an Ed25519 key. The caller signs signing_input with the private key and assembles the proof via assemble_dpop_proof.
exchange_form_body
Build the application/x-www-form-urlencoded body for an RFC 8693 exchange.
expires_at_ms
Compute the absolute expiry (Date.now()-domain milliseconds) for a token whose expires_in (seconds, RFC 6749 §5.1) is expires_in_secs relative to now_ms. A non-positive expires_in clamps to now_ms (already expired) rather than underflowing.
generate_dpop_jti
Generate a fresh, random DPoP jti (RFC 9449 requires a unique value per proof so the AS can detect replay). Pure / native-testable so JTI freshness is a plain unit test rather than something only exercisable inside the wasm32-only fetch glue (#1425 r1 P1#4).
is_use_dpop_nonce_response
Check whether an HTTP error response body is a use_dpop_nonce error (RFC 9449 §8). The browser retries with a fresh proof carrying the DPoP-Nonce response header.
parse_exchange_response
Parse the JSON body of a successful POST /oauth/token exchange.
parse_session_context
Parse the exact session-exchange / whoami JSON response.
subject_from_access_token
Decode the sub claim from an exchanged at+jwt and build a Subject.
verify_sender_bound_token
Verify an ExchangedToken is actually sender-bound to dpop_pubkey before the caller (the browser sender-bound exchange) trusts it (#1425 r2 P2).