@ractive-ch/tab-mcp 0.2.1 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/jwt.d.ts ADDED
@@ -0,0 +1,75 @@
1
+ /**
2
+ * JWT signature checks on WebCrypto, without a JOSE library (DEC-076): the tab
3
+ * assertion and the provider's ID token. Only asymmetric algorithms, each tied
4
+ * to its key type; keys come only from a configured JWKS URL, never from the
5
+ * token's header (`jwk`, `jku`, `x5u` are ignored).
6
+ */
7
+ /** The accepted algorithms; never `none` or HMAC. */
8
+ export declare const JWT_ALGORITHMS: readonly ["RS256", "RS384", "RS512", "PS256", "PS384", "PS512", "ES256", "ES384", "ES512", "EdDSA"];
9
+ export type JwtAlgorithm = (typeof JWT_ALGORITHMS)[number];
10
+ /** Longest JWT the relay reads. */
11
+ export declare const MAX_JWT_BYTES = 8192;
12
+ export declare class JwtError extends Error {
13
+ name: string;
14
+ /** A short reason for the log. */
15
+ readonly reason: string;
16
+ constructor(reason: string, message: string);
17
+ }
18
+ export interface Jwk {
19
+ kty?: string;
20
+ kid?: string;
21
+ use?: string;
22
+ alg?: string;
23
+ crv?: string;
24
+ n?: string;
25
+ e?: string;
26
+ x?: string;
27
+ y?: string;
28
+ [key: string]: unknown;
29
+ }
30
+ export interface DecodedJwt {
31
+ header: Record<string, unknown>;
32
+ payload: Record<string, unknown>;
33
+ signingInput: Uint8Array<ArrayBuffer>;
34
+ signature: Uint8Array<ArrayBuffer>;
35
+ }
36
+ /** Split and decode a compact JWS (no signature check). */
37
+ export declare function decodeJwt(token: string): DecodedJwt;
38
+ /** A source of verification keys (a JWKS URL in production). */
39
+ export interface KeySource {
40
+ /** Keys for `kid`; may fetch again when the kid is unknown. */
41
+ keys(kid: string | undefined): Promise<Jwk[]>;
42
+ }
43
+ /** Fetch JSON from an operator-configured URL with a timeout and a size limit. */
44
+ export declare function fetchJson(url: string, init?: RequestInit, maxBytes?: number): Promise<unknown>;
45
+ export declare class HttpJsonError extends Error {
46
+ name: string;
47
+ readonly status: number;
48
+ readonly error: string;
49
+ constructor(status: number, error: string, url: string);
50
+ }
51
+ /**
52
+ * A JWKS URL, cached 10 minutes, fetched again for an unknown kid at most every
53
+ * 30 s. After a failed fetch the last good keys are served for up to an hour
54
+ * (an outage must not refuse every token at once), and the next attempt waits
55
+ * the same 30 s, so a dead endpoint is not hit (and waited for) on every check.
56
+ */
57
+ export declare class JwksCache implements KeySource {
58
+ #private;
59
+ constructor(url: string | (() => Promise<string>), options?: {
60
+ now?: () => number;
61
+ });
62
+ keys(kid: string | undefined): Promise<Jwk[]>;
63
+ }
64
+ export interface VerifyOptions {
65
+ /** Required header `typ` (compared exactly), if any. */
66
+ typ?: string;
67
+ /** Allowed algorithms; default all of `JWT_ALGORITHMS`. */
68
+ algorithms?: readonly JwtAlgorithm[];
69
+ }
70
+ /** Check the signature of a compact JWS; returns the decoded token. */
71
+ export declare function verifyJwt(token: string, source: KeySource, options?: VerifyOptions): Promise<DecodedJwt>;
72
+ /** Claim helpers shared by the assertion and ID token checks. */
73
+ export declare function numericDate(payload: Record<string, unknown>, name: string): number | undefined;
74
+ /** `aud` as a list (a string or an array of strings). */
75
+ export declare function audiences(payload: Record<string, unknown>): string[];