DialectoInContext.LaunchToken (dialecto_in_context v0.1.0)

Copy Markdown View Source

Verifies the launch token Dialecto mints for an editor (spec-0025 §3), with no call to Dialecto:

token  = base64url(payload) "." base64url(signature)
signed = "dialecto-live-edit-v1." base64url(payload)

The signature is Ed25519 under the repo's key. The purpose prefix keeps a signature made for another purpose (a release manifest, say) from verifying here. Pure: the caller passes the key, the site's origin and the time.

Summary

Functions

The Unix time the token's session ends.

Checks token against public_key (32 bytes), the configured origin and now (Unix seconds). phase is :start when the token first arrives, which also requires start_by not to have passed, or :session for the cookie on later requests, which only needs exp. With repo ("owner/name") the token's repo claim must match it, ignoring case: a cheap check against a key pasted from the wrong repo.

Types

claims()

@type claims() :: %{required(String.t()) => term()}

phase()

@type phase() :: :start | :session

reason()

@type reason() ::
  :malformed | :bad_signature | :expired | :late | :wrong_origin | :wrong_repo

Functions

expires_at(map)

@spec expires_at(claims()) :: integer()

The Unix time the token's session ends.

verify(token, public_key, origin, now, phase \\ :session, repo \\ nil)

@spec verify(term(), binary(), String.t(), integer(), phase(), String.t() | nil) ::
  {:ok, claims()} | {:error, reason()}

Checks token against public_key (32 bytes), the configured origin and now (Unix seconds). phase is :start when the token first arrives, which also requires start_by not to have passed, or :session for the cookie on later requests, which only needs exp. With repo ("owner/name") the token's repo claim must match it, ignoring case: a cheap check against a key pasted from the wrong repo.