-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthforge.d.ts
More file actions
106 lines (95 loc) · 3.28 KB
/
authforge.d.ts
File metadata and controls
106 lines (95 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
export type HeartbeatMode = "SERVER" | "LOCAL";
export interface SessionData {
[key: string]: unknown;
}
export interface VariableMap {
[key: string]: unknown;
}
export interface AuthForgeClientOptions {
appId: string;
appSecret: string;
/**
* Trusted Ed25519 public key(s). Pass a single base64 string for the common
* case, or an array (current key first, previous key(s) after) to remain
* verifying during a server-side rotation. A comma-separated string is also
* accepted for environment-variable convenience.
*/
publicKey: string | readonly string[];
heartbeatMode: string;
heartbeatInterval?: number;
apiBaseUrl?: string;
onFailure?: ((reason: string, error: Error | null) => void) | null;
requestTimeout?: number;
/**
* Requested session token lifetime in seconds. Server clamps to
* [3600, 604800]; out-of-range values are silently clamped.
* Omitted/null → server default (24h). Heartbeats preserve this TTL.
*/
ttlSeconds?: number | null;
/** Custom HWID / identity (e.g. `discord:123`, `tg:456`). */
hwidOverride?: string | null;
}
export type ValidateLicenseSuccess = {
valid: true;
sessionToken: string;
expiresIn: number;
sessionData: SessionData;
appVariables: VariableMap | null;
licenseVariables: VariableMap | null;
keyId: string | null;
/** ISO 8601 session expiry (newer servers). */
sessionExpiresAt?: string;
/** ISO 8601 license expiry; `null` when key is lifetime (explicit JSON null). */
licenseExpiresAt?: string | null;
maxHwidSlots?: number;
hwidCount?: number;
licenseLabel?: string;
};
export type ValidateLicenseFailure = {
valid: false;
/** Machine-readable code (e.g. invalid_key, signature_mismatch, url_error: …). */
code: string;
error: Error;
};
export type ValidateLicenseResult = ValidateLicenseSuccess | ValidateLicenseFailure;
export declare function verifyPayloadSignatureEd25519(
payloadBase64: string,
signatureBase64: string,
publicKey: string | readonly string[],
): boolean;
export declare class AuthForgeClient {
constructor(options: AuthForgeClientOptions);
constructor(
appId: string,
appSecret: string,
publicKey: string | readonly string[],
heartbeatMode: string,
heartbeatInterval?: number,
apiBaseUrl?: string,
onFailure?: ((reason: string, error: Error | null) => void) | null,
requestTimeout?: number,
ttlSeconds?: number | null,
);
readonly appId: string;
readonly appSecret: string;
/** Primary (first) trusted public key. See `publicKeys` for the full list. */
readonly publicKey: string;
readonly publicKeys: readonly string[];
readonly heartbeatMode: HeartbeatMode;
readonly heartbeatInterval: number;
readonly apiBaseUrl: string;
readonly onFailure: ((reason: string, error: Error | null) => void) | null;
readonly requestTimeout: number;
readonly ttlSeconds: number | null;
login(licenseKey: string): Promise<boolean>;
/**
* Same cryptographic validation as login, without session mutation or heartbeats.
*/
validateLicense(licenseKey: string): Promise<ValidateLicenseResult>;
logout(): void;
isAuthenticated(): boolean;
getSessionData(): SessionData | null;
getAppVariables(): VariableMap | null;
getLicenseVariables(): VariableMap | null;
}
export declare const knownServerErrors: string[];