@synonymdev/pubky
    Preparing search index...

    Class AuthToken

    AuthToken: signed, time-bound proof of key ownership.

    Returned by [AuthFlow.awaitToken()] on the 3rd-party app side when doing authentication-only flows (no homeserver session). You can inspect who authenticated and which capabilities were requested, or serialize the token and send it to a backend to verify.

    // Start an auth-only flow (no capabilities)
    const flow = pubky.startCookieAuthFlow("", relay);

    // Wait for the signer to approve; returns an AuthToken
    const token = await flow.awaitToken();

    // Identify the user
    console.log(token.publicKey().toString());

    // Optionally forward to a server for verification:
    await fetch("/api/verify", { method: "POST", body: token.toBytes() });

    AuthToken serializes to a canonical binary (postcard) form; use [AuthToken.toBytes()] to get a Uint8Array, and [AuthToken.verify()] to parse + verify on the server.

    Index
    capabilities: string[]

    Returns the capabilities requested by the flow at the time this token was signed.

    Most auth-only flows pass an empty string to startCookieAuthFlow("", relay), so this will commonly be an empty array.

    Returns: string[], where each item is the canonical entry "<scope>:<actions>".

    Example entry: "/pub/my-cool-app/:rw"

    publicKey: PublicKey

    Returns the public key that authenticated with this token.

    Use .toString() on the returned PublicKey to get the pubky<z32> identifier. Call .z32() when you specifically need the raw z-base32 value (e.g. hostnames).

    const who = token.publicKey.toString();
    
    • Returns void

    • Returns void

    • Serialize the token to a Uint8Array in its canonical (postcard) binary format.

      Use this to send the token to a backend for verification.

      const bytes = token.toBytes();
      await fetch("/api/verify", { method: "POST", body: bytes });

      Returns Uint8Array

    • Deserialize an AuthToken without verification.

      Most apps should call [AuthToken.verify()]. This is provided for tooling or diagnostics where you want to inspect the structure first.

      Throws if the bytes cannot be parsed as a valid serialized token.

      Parameters

      • bytes: Uint8Array

      Returns AuthToken

    • Parse and verify an AuthToken from its canonical bytes.

      • Verifies version, timestamp freshness window, and signature.
      • Throws on invalid/expired/unknown version.

      Use this on your server after receiving Uint8Array from the client.

      import { AuthToken } from "@synonymdev/pubky";

      export async function POST(req) {
      const bytes = new Uint8Array(await req.arrayBuffer());
      const token = AuthToken.verify(bytes); // throws on failure
      return new Response(token.publicKey().toString(), { status: 200 });
      }

      Parameters

      • bytes: Uint8Array

      Returns AuthToken