@openagentid/client API
Exported TypeScript types, signatures and source documentation.
Package manifest, subpaths, and integration guide.
This reference resolves exported symbols from the package entry point with the TypeScript parser/type checker. It includes declarations and inferred types, not implementation bodies. External dependencies unavailable to the extraction environment can remain unresolved; this is source documentation, not proof that all packages typecheck or are published.
OpenAgentClient
Client for the OpenAgent Core challenge-response protocol.
The client owns an Ed25519 {@link KeyPair} and a per-origin session cache. On each {@link OpenAgentClient.fetch} call:
-
If a non-expired cached session token exists for the request origin, it is sent as
Authorization: Bearer <token>. If that returns 401, the cache is cleared and the client falls through to a challenge. -
Otherwise the client sends the request unauthenticated. If the server replies 401 with a
WWW-Authenticate: OpenAgentheader, the client decodes the challenge, freshness-checks the timestamp and origin, JCS-canonicalizes it (RFC 8785), signs the canonical bytes with Ed25519, and re-sends the request with the proof in theAuthorizationheader. -
The new session token from
X-OpenAgent-Sessionis cached for subsequent calls.
export declare class OpenAgentClient {
constructor(keyPair: KeyPair, options?: OpenAgentClientOptions): OpenAgentClient;
getKeyPair(): KeyPair;
getCachedSession(origin: string): string | undefined;
clearSession(): void;
fetch(url: string, options?: FetchOptions): Promise<AuthenticatedResponse>;
logout(): void;
}Source: openagents/openagent.id/clients/typescript/src/client.ts:72.
OpenAgentClientOptions
Optional configuration for the {@link OpenAgentClient}.
/**
* Optional configuration for the {@link OpenAgentClient}.
*/
export interface OpenAgentClientOptions {
/**
* Custom `fetch` implementation. Defaults to `globalThis.fetch`.
* Useful for tests, polyfills, or wiring through a proxy.
*/
fetch?: typeof fetch;
/**
* Optional clock used for session expiry checks. Defaults to
* `() => new Date()`. Allows tests to inject a fake clock.
*/
now?: () => Date;
/**
* Maximum acceptable age of a server-issued challenge before we refuse
* to sign it. Defaults to 60 seconds (matches the server's default
* 30-second nonce TTL with margin).
*/
maxChallengeAgeMs?: number;
}Source: openagents/openagent.id/clients/typescript/src/client.ts:33.
KeyPair
An Ed25519 signing key. Holds 32 raw secret bytes plus the lazily-derived public key.
Instances are immutable. Callers SHOULD NOT log or serialize the secret key — use {@link KeyPair.publicKeyBytes} for the safe public half.
export declare class KeyPair {
fromSecretBytes(secretKey: Uint8Array): KeyPair;
fromSecretBase64Url(secretBase64Url: string): KeyPair;
generate(): KeyPair;
publicKeyBytes(): Uint8Array;
publicKeyBase64Url(): string;
toDidKey(): string;
sign(message: Uint8Array): Uint8Array;
exportSecretBytes(): Uint8Array;
exportSecretBase64Url(): string;
}Source: openagents/openagent.id/clients/typescript/src/keypair.ts:31.
encodeDidKey
Encodes an Ed25519 public key as a did:key URI per the W3C
did:key method specification.
Multicodec prefix for Ed25519 public keys: 0xed 0x01 (varint of 0xed).
Multibase prefix: z for base58btc.
export declare const encodeDidKey: (publicKey: Uint8Array) => string;Source: openagents/openagent.id/clients/typescript/src/keypair.ts:161.
CHALLENGE_TYPE
export declare const CHALLENGE_TYPE: "openagent-challenge-v1";Source: openagents/openagent.id/clients/typescript/src/challenge.ts:10.
parseWwwAuthenticate
Parses an OpenAgent challenge from a WWW-Authenticate header value.
export declare const parseWwwAuthenticate: (headerValue: string) => Challenge;Source: openagents/openagent.id/clients/typescript/src/challenge.ts:42.
validateChallenge
Validates a parsed JSON object against the {@link Challenge} schema and returns it as a typed value.
export declare const validateChallenge: (value: unknown) => Challenge;Source: openagents/openagent.id/clients/typescript/src/challenge.ts:92.
canonicalizeChallenge
JCS-canonicalizes a challenge per RFC 8785 and returns the UTF-8 bytes.
The result MUST byte-equal what the openagent-server produces from
serde_jcs::to_string over the same logical object.
export declare const canonicalizeChallenge: (challenge: Challenge) => Uint8Array;Source: openagents/openagent.id/clients/typescript/src/challenge.ts:148.
isChallengeFresh
Optional sanity check on the challenge timestamp.
Returns true if the timestamp parses as a date and is within
maxAgeMs of now. Implementations SHOULD reject stale challenges
before signing them (per spec §3.3 step 3).
export declare const isChallengeFresh: (challenge: Challenge, options?: { now?: Date; maxAgeMs?: number; }) => boolean;Source: openagents/openagent.id/clients/typescript/src/challenge.ts:177.
Challenge
A challenge issued by an OpenAgent server, decoded from the
WWW-Authenticate: OpenAgent challenge="<base64url>" header.
Per OPENAGENT-CORE-SPEC.md §4:
typeMUST equal"openagent-challenge-v1"nonceMUST be a 64-character hex string (32 random bytes)timestampMUST be RFC 3339 / ISO 8601 UTCoriginMUST be the server origin inscheme://host[:port]formrealmis optional
/**
* A challenge issued by an OpenAgent server, decoded from the
* `WWW-Authenticate: OpenAgent challenge="<base64url>"` header.
*
* Per OPENAGENT-CORE-SPEC.md §4:
* - `type` MUST equal `"openagent-challenge-v1"`
* - `nonce` MUST be a 64-character hex string (32 random bytes)
* - `timestamp` MUST be RFC 3339 / ISO 8601 UTC
* - `origin` MUST be the server origin in `scheme://host[:port]` form
* - `realm` is optional
*/
export interface Challenge {
type: string;
nonce: string;
timestamp: string;
origin: string;
realm?: string;
}Source: openagents/openagent.id/clients/typescript/src/challenge.ts:23.
OpenAgentClientError
Base class for all OpenAgent client errors.
All thrown errors from OpenAgentClient are instances of this class —
callers may rely on instanceof OpenAgentClientError for control flow.
export declare class OpenAgentClientError {
code: string;
constructor(code: string, message: string, options?: ErrorOptions): OpenAgentClientError;
}Source: openagents/openagent.id/clients/typescript/src/errors.ts:11.
InvalidUrlError
The URL passed to {@link OpenAgentClient.fetch } could not be parsed.
export declare class InvalidUrlError {
constructor(url: string): InvalidUrlError;
}Source: openagents/openagent.id/clients/typescript/src/errors.ts:24.
NoChallengeHeaderError
The server returned 401 but no WWW-Authenticate header was present.
This indicates a server bug or a non-OpenAgent server returning 401.
export declare class NoChallengeHeaderError {
constructor(): NoChallengeHeaderError;
}Source: openagents/openagent.id/clients/typescript/src/errors.ts:36.
MalformedChallengeError
The WWW-Authenticate header was present but could not be parsed as
an OpenAgent challenge.
export declare class MalformedChallengeError {
constructor(reason: string): MalformedChallengeError;
}Source: openagents/openagent.id/clients/typescript/src/errors.ts:50.
NetworkError
Network error during the underlying fetch call. The original error is
exposed as cause for inspection.
export declare class NetworkError {
constructor(cause: unknown): NetworkError;
}Source: openagents/openagent.id/clients/typescript/src/errors.ts:61.
InvalidKeyError
The signing key is invalid (must be 32 raw bytes for Ed25519).
export declare class InvalidKeyError {
constructor(reason: string): InvalidKeyError;
}Source: openagents/openagent.id/clients/typescript/src/errors.ts:73.
bodyAsString
Helper: parses the response body as a UTF-8 string.
export declare const bodyAsString: (response: AuthenticatedResponse) => string;Source: openagents/openagent.id/clients/typescript/src/types.ts:71.
bodyAsJson
Helper: parses the response body as JSON. Throws on parse failure.
export declare const bodyAsJson: <T = unknown>(response: AuthenticatedResponse) => T;Source: openagents/openagent.id/clients/typescript/src/types.ts:78.
AuthenticatedResponse
Result of an authenticated request through {@link OpenAgentClient.fetch }.
Mirrors AuthenticatedResponse in the Rust client. Includes both the
raw HTTP response (status, headers, bodyBytes) and the OpenAgent
principal headers (did, trustTier, sessionToken) extracted from
the server's response.
// Public types returned by the OpenAgent client API.
/**
* Result of an authenticated request through {@link OpenAgentClient.fetch}.
*
* Mirrors `AuthenticatedResponse` in the Rust client. Includes both the
* raw HTTP response (`status`, `headers`, `bodyBytes`) and the OpenAgent
* principal headers (`did`, `trustTier`, `sessionToken`) extracted from
* the server's response.
*/
export interface AuthenticatedResponse {
/** HTTP status code. */
status: number;
/** All response headers. */
headers: Headers;
/** Raw response body bytes. */
bodyBytes: Uint8Array;
/**
* The agent's resolved DID, if the server returned `X-OpenAgent-DID`.
* Always present after a successful challenge-response round.
*/
did?: string;
/**
* Numeric trust tier (0-4), if the server returned
* `X-OpenAgent-Trust-Tier` and it parses as a number.
*/
trustTier?: number;
/**
* Session JWT issued by the server in the `X-OpenAgent-Session` header,
* if present. The client caches this internally and reuses it on
* subsequent requests until 401.
*/
sessionToken?: string;
/**
* Session expiration timestamp from `X-OpenAgent-Session-Expires`, if
* present. ISO 8601.
*/
sessionExpires?: string;
/**
* Legacy lineage response metadata retained only for migration and audit.
* It cannot satisfy an authorization predicate.
*/
legacyLineageEvidence?: InformationalLineageEvidence;
}Source: openagents/openagent.id/clients/typescript/src/types.ts:11.
FetchOptions
Options for {@link OpenAgentClient.fetch }.
/**
* Options for {@link OpenAgentClient.fetch}.
*/
export interface FetchOptions {
/** HTTP method. Defaults to `"GET"`, or `"POST"` if a body is given. */
method?: string;
/**
* Request body. Strings are sent as `text/plain`, objects are
* JSON-encoded with `application/json`, Uint8Array goes through as-is.
*/
body?: string | Uint8Array | Record<string, unknown>;
/** Extra headers to include on the request. */
headers?: Record<string, string>;
/**
* If true, do NOT consume the cached session token even if one exists
* for this origin. Forces a fresh challenge-response round.
*
* Use sparingly — only for debugging or after a logout.
*/
forceChallenge?: boolean;
/**
* Optional `AbortSignal` for cancellation, propagated to the underlying
* fetch calls.
*/
signal?: AbortSignal;
}Source: openagents/openagent.id/clients/typescript/src/types.ts:86.
InformationalLineageEvidence
Explicitly informational wrapper for a legacy response header.
/** Explicitly informational wrapper for a legacy response header. */
export interface InformationalLineageEvidence {
readonly status: "informational";
readonly profile: "agent-lineage-proof-2025";
readonly evidence: LegacyLineageEvidence;
}Source: openagents/openagent.id/clients/typescript/src/types.ts:62.
LegacyLineageEvidence
Legacy wire fields. None of these fields confer authority.
/** Legacy wire fields. None of these fields confer authority. */
export interface LegacyLineageEvidence {
subject: string;
root: string;
path_kind: string;
source: string;
path: string[];
finalized_block: number;
scopes: string[];
generation: number;
root_kind?: string;
org_root_commitment?: string;
expires_at?: string;
}Source: openagents/openagent.id/clients/typescript/src/types.ts:47.
base64url
export declare const base64url: typeof import("openagents/openagent.id/clients/typescript/src/base64url");Source: openagents/openagent.id/clients/typescript/src/base64url.ts:6.
hex
export declare const hex: typeof import("openagents/openagent.id/clients/typescript/src/hex");Source: openagents/openagent.id/clients/typescript/src/hex.ts:3.