Skip to main content
AccessTokenIssuer handles JWT creation and verification for the Key0 payment flow. After a client completes an on-chain USDC payment, the engine uses AccessTokenIssuer to mint a signed JWT that grants access to the purchased resource. It supports two signing algorithms:
  • HS256 — symmetric shared secret (default). Suitable for single-service deployments.
  • RS256 — asymmetric RSA key pair. Suitable for distributed systems where multiple services verify tokens using the public key.

Constructor

Parameters

AccessTokenIssuerConfig | string
required
Either a plain string (interpreted as an HS256 shared secret) or a configuration object.

AccessTokenIssuerConfig

Validation

The constructor throws immediately if:
  • An HS256 secret is shorter than 32 characters.
  • RS256 is selected but no privateKey is provided.
  • HS256 is selected (or defaulted) but no secret is provided.

Methods

sign

Signs a JWT containing the provided claims.
TokenClaims
required
The claims to embed in the JWT payload. See TokenClaims below.
number
required
Token time-to-live in seconds. The exp claim is set to iat + ttlSeconds.
string
The signed JWT string.
Returns Promise<TokenResult> — an object with a single token property.

verify

Verifies a JWT signed with HS256 and returns the decoded payload.
string
required
The JWT string to verify.
Returns the decoded payload including standard iat and exp claims.
This method only supports HS256. Calling verify on an RS256 issuer throws an error. For RS256 token verification, use validateKey0Token from the middleware layer, which accepts a public key.

verifyWithFallback

Attempts verification with the primary secret first, then iterates through fallback secrets. Designed for zero-downtime secret rotation.
string
required
The JWT string to verify.
string[]
required
An ordered list of previous secrets to try if the primary secret fails.
Returns the decoded payload if any secret succeeds. Throws "Token verification failed with all secrets" if the primary and all fallback secrets fail.

Types

TokenClaims

Claims embedded in every Key0 access token. Standard JWT claims iat (issued at) and exp (expiration) are set automatically by sign and included in the return type of verify and verifyWithFallback.

TokenResult


Usage

Signing and verifying a token

Zero-downtime secret rotation

When rotating secrets, pass the old secret(s) as fallbacks so that tokens signed with the previous secret remain valid until they expire.

RS256 signing

Token Issuance

Security design behind JWT creation, claims, and verification.

Middleware

Framework middleware that validates tokens issued by AccessTokenIssuer.