@happyvertical/auth 0.74.8
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/AGENT.md +33 -0
- package/LICENSE +7 -0
- package/README.md +73 -0
- package/dist/chunks/cognito-dmypylFX.js +128 -0
- package/dist/chunks/cognito-dmypylFX.js.map +1 -0
- package/dist/chunks/decode_jwt-D2OK1b8a.js +1395 -0
- package/dist/chunks/decode_jwt-D2OK1b8a.js.map +1 -0
- package/dist/chunks/github-NSZp5tVm.js +413 -0
- package/dist/chunks/github-NSZp5tVm.js.map +1 -0
- package/dist/chunks/google-HXk2ctYR.js +483 -0
- package/dist/chunks/google-HXk2ctYR.js.map +1 -0
- package/dist/chunks/index-BpsMhFXS.js +151 -0
- package/dist/chunks/index-BpsMhFXS.js.map +1 -0
- package/dist/chunks/kanidm-hkw-YPVF.js +747 -0
- package/dist/chunks/kanidm-hkw-YPVF.js.map +1 -0
- package/dist/chunks/keycloak-t6JEUeOz.js +871 -0
- package/dist/chunks/keycloak-t6JEUeOz.js.map +1 -0
- package/dist/cli/claude-context.d.ts +3 -0
- package/dist/cli/claude-context.d.ts.map +1 -0
- package/dist/cli/claude-context.js +21 -0
- package/dist/cli/claude-context.js.map +1 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +499 -0
- package/dist/index.js.map +1 -0
- package/dist/shared/errors.d.ts +227 -0
- package/dist/shared/errors.d.ts.map +1 -0
- package/dist/shared/factory.d.ts +85 -0
- package/dist/shared/factory.d.ts.map +1 -0
- package/dist/shared/providers/cognito.d.ts +38 -0
- package/dist/shared/providers/cognito.d.ts.map +1 -0
- package/dist/shared/providers/github.d.ts +65 -0
- package/dist/shared/providers/github.d.ts.map +1 -0
- package/dist/shared/providers/google.d.ts +58 -0
- package/dist/shared/providers/google.d.ts.map +1 -0
- package/dist/shared/providers/kanidm.d.ts +78 -0
- package/dist/shared/providers/kanidm.d.ts.map +1 -0
- package/dist/shared/providers/keycloak.d.ts +67 -0
- package/dist/shared/providers/keycloak.d.ts.map +1 -0
- package/dist/shared/providers/nostr/index.d.ts +47 -0
- package/dist/shared/providers/nostr/index.d.ts.map +1 -0
- package/dist/shared/types.d.ts +812 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/metadata.json +32 -0
- package/package.json +60 -0
|
@@ -0,0 +1,812 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @happyvertical/auth - Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* Unified authentication interface supporting:
|
|
5
|
+
* - Keycloak (OIDC/OAuth2)
|
|
6
|
+
* - AWS Cognito (OAuth2)
|
|
7
|
+
* - Nostr (public key identity)
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Core authentication interface that all providers must implement.
|
|
11
|
+
*
|
|
12
|
+
* The interface is designed around concepts that can be mapped across
|
|
13
|
+
* different authentication paradigms:
|
|
14
|
+
* - OAuth/OIDC (Keycloak, Cognito): Traditional token-based flows
|
|
15
|
+
* - Decentralized (Nostr): Public key identity with event-based verification
|
|
16
|
+
*/
|
|
17
|
+
export interface AuthInterface {
|
|
18
|
+
/**
|
|
19
|
+
* Get the authorization URL for initiating OAuth/OIDC login flow.
|
|
20
|
+
*
|
|
21
|
+
* For Nostr: Returns a challenge URL/data for signing.
|
|
22
|
+
*/
|
|
23
|
+
getAuthorizationUrl(options?: AuthorizationOptions): Promise<AuthorizationResult>;
|
|
24
|
+
/**
|
|
25
|
+
* Exchange authorization code for tokens (OAuth callback handler).
|
|
26
|
+
*
|
|
27
|
+
* For Nostr: Verifies signed challenge and creates session.
|
|
28
|
+
*/
|
|
29
|
+
exchangeCode(params: CodeExchangeParams): Promise<AuthResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Authenticate with credentials directly (password grant / login).
|
|
32
|
+
*
|
|
33
|
+
* For Nostr: Authenticate with nsec (private key) or NIP-07 extension.
|
|
34
|
+
*/
|
|
35
|
+
authenticate(credentials: AuthCredentials): Promise<AuthResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Refresh an expired access token.
|
|
38
|
+
*
|
|
39
|
+
* For Nostr: Re-verify identity (optional, may return same session).
|
|
40
|
+
*/
|
|
41
|
+
refresh(refreshToken: string): Promise<AuthResult>;
|
|
42
|
+
/**
|
|
43
|
+
* End the user session (logout).
|
|
44
|
+
*/
|
|
45
|
+
logout(options?: LogoutOptions): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Validate a token and return claims if valid.
|
|
48
|
+
*
|
|
49
|
+
* For Nostr: Validates NIP-98 event signature and returns pubkey claims.
|
|
50
|
+
*/
|
|
51
|
+
validateToken(token: string, options?: TokenValidationOptions): Promise<TokenClaims | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Decode a token without validation (for inspection).
|
|
54
|
+
*
|
|
55
|
+
* For Nostr: Decodes event metadata.
|
|
56
|
+
*/
|
|
57
|
+
decodeToken(token: string): TokenPayload;
|
|
58
|
+
/**
|
|
59
|
+
* Introspect a token (active check with full claims).
|
|
60
|
+
*
|
|
61
|
+
* For Nostr: Check if pubkey is valid/not revoked.
|
|
62
|
+
*/
|
|
63
|
+
introspectToken(token: string): Promise<TokenIntrospection>;
|
|
64
|
+
/**
|
|
65
|
+
* Get the current user's profile from a valid token/session.
|
|
66
|
+
*
|
|
67
|
+
* For Nostr: Fetches profile (kind:0) from relays.
|
|
68
|
+
*/
|
|
69
|
+
getProfile(tokenOrSession: string): Promise<UserProfile>;
|
|
70
|
+
/**
|
|
71
|
+
* Update the current user's profile.
|
|
72
|
+
*
|
|
73
|
+
* For Nostr: Publishes updated profile event (kind:0).
|
|
74
|
+
*/
|
|
75
|
+
updateProfile(tokenOrSession: string, profile: Partial<UserProfile>): Promise<UserProfile>;
|
|
76
|
+
/**
|
|
77
|
+
* Get a user by ID (admin operation).
|
|
78
|
+
*
|
|
79
|
+
* For Nostr: Fetches profile by npub.
|
|
80
|
+
*/
|
|
81
|
+
getUser(userId: string, adminToken?: string): Promise<UserProfile>;
|
|
82
|
+
/**
|
|
83
|
+
* Create a new user (admin operation).
|
|
84
|
+
*
|
|
85
|
+
* For Nostr: Not applicable - returns error or generates keypair.
|
|
86
|
+
*/
|
|
87
|
+
createUser(user: CreateUserRequest, adminToken: string): Promise<UserProfile>;
|
|
88
|
+
/**
|
|
89
|
+
* Update a user (admin operation).
|
|
90
|
+
*
|
|
91
|
+
* For Nostr: Not applicable in centralized sense.
|
|
92
|
+
*/
|
|
93
|
+
updateUser(userId: string, updates: Partial<CreateUserRequest>, adminToken: string): Promise<UserProfile>;
|
|
94
|
+
/**
|
|
95
|
+
* Delete a user (admin operation).
|
|
96
|
+
*
|
|
97
|
+
* For Nostr: Not applicable - keys cannot be revoked centrally.
|
|
98
|
+
*/
|
|
99
|
+
deleteUser(userId: string, adminToken: string): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* List users (admin operation).
|
|
102
|
+
*
|
|
103
|
+
* For Nostr: Search profiles from relays.
|
|
104
|
+
*/
|
|
105
|
+
listUsers(query: UserQuery, adminToken?: string): Promise<UserListResult>;
|
|
106
|
+
/**
|
|
107
|
+
* Request password reset (admin or self-service).
|
|
108
|
+
*
|
|
109
|
+
* For Nostr: Not applicable.
|
|
110
|
+
*/
|
|
111
|
+
requestPasswordReset(email: string): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Reset password with token.
|
|
114
|
+
*
|
|
115
|
+
* For Nostr: Not applicable.
|
|
116
|
+
*/
|
|
117
|
+
resetPassword(token: string, newPassword: string): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* List active sessions for a user.
|
|
120
|
+
*
|
|
121
|
+
* For Nostr: List known relay connections or local sessions.
|
|
122
|
+
*/
|
|
123
|
+
listSessions(userId: string, adminToken?: string): Promise<Session[]>;
|
|
124
|
+
/**
|
|
125
|
+
* Revoke a specific session.
|
|
126
|
+
*
|
|
127
|
+
* For Nostr: Disconnect from relay or clear local session.
|
|
128
|
+
*/
|
|
129
|
+
revokeSession(sessionId: string, adminToken?: string): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* Revoke all sessions for a user.
|
|
132
|
+
*/
|
|
133
|
+
revokeAllSessions(userId: string, adminToken?: string): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Check if user has a specific role.
|
|
136
|
+
*
|
|
137
|
+
* For Nostr: Check against local role mapping or badge events.
|
|
138
|
+
*/
|
|
139
|
+
hasRole(tokenOrUserId: string, role: string): Promise<boolean>;
|
|
140
|
+
/**
|
|
141
|
+
* Check if user has a specific permission.
|
|
142
|
+
*
|
|
143
|
+
* For Nostr: Check against local permission mapping.
|
|
144
|
+
*/
|
|
145
|
+
hasPermission(tokenOrUserId: string, permission: string, resource?: string): Promise<boolean>;
|
|
146
|
+
/**
|
|
147
|
+
* Get all roles for a user.
|
|
148
|
+
*/
|
|
149
|
+
getRoles(tokenOrUserId: string, adminToken?: string): Promise<string[]>;
|
|
150
|
+
/**
|
|
151
|
+
* Assign role to user (admin operation).
|
|
152
|
+
*
|
|
153
|
+
* For Nostr: Managed locally or via badge events.
|
|
154
|
+
*/
|
|
155
|
+
assignRole(userId: string, role: string, adminToken: string): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Remove role from user (admin operation).
|
|
158
|
+
*/
|
|
159
|
+
removeRole(userId: string, role: string, adminToken: string): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Get provider capabilities.
|
|
162
|
+
*/
|
|
163
|
+
getCapabilities(): Promise<AuthCapabilities>;
|
|
164
|
+
/**
|
|
165
|
+
* Get OpenID Connect discovery document.
|
|
166
|
+
*
|
|
167
|
+
* For Nostr: Returns null or mock document.
|
|
168
|
+
*/
|
|
169
|
+
getDiscoveryDocument(): Promise<OIDCDiscoveryDocument | null>;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Base configuration options for all providers.
|
|
173
|
+
*/
|
|
174
|
+
export interface BaseAuthOptions {
|
|
175
|
+
/** Request timeout in milliseconds */
|
|
176
|
+
timeout?: number;
|
|
177
|
+
/** Maximum number of retries for failed requests */
|
|
178
|
+
maxRetries?: number;
|
|
179
|
+
/** Custom headers for HTTP requests */
|
|
180
|
+
headers?: Record<string, string>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Keycloak provider options.
|
|
184
|
+
*/
|
|
185
|
+
export interface KeycloakOptions extends BaseAuthOptions {
|
|
186
|
+
type: 'keycloak';
|
|
187
|
+
/** Keycloak server URL (e.g., 'https://auth.example.com') */
|
|
188
|
+
serverUrl: string;
|
|
189
|
+
/** Keycloak realm name */
|
|
190
|
+
realm: string;
|
|
191
|
+
/** Client ID for this application */
|
|
192
|
+
clientId: string;
|
|
193
|
+
/** Client secret (for confidential clients) */
|
|
194
|
+
clientSecret?: string;
|
|
195
|
+
/** OAuth callback URL for this application */
|
|
196
|
+
redirectUri?: string;
|
|
197
|
+
/** Default scopes to request */
|
|
198
|
+
scopes?: string[];
|
|
199
|
+
/**
|
|
200
|
+
* Use PKCE for public clients.
|
|
201
|
+
* @default true
|
|
202
|
+
*/
|
|
203
|
+
usePKCE?: boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Verify SSL certificates.
|
|
206
|
+
* @default true
|
|
207
|
+
*/
|
|
208
|
+
verifySsl?: boolean;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* AWS Cognito provider options.
|
|
212
|
+
*/
|
|
213
|
+
export interface CognitoOptions extends BaseAuthOptions {
|
|
214
|
+
type: 'cognito';
|
|
215
|
+
/** AWS region (e.g., 'us-east-1') */
|
|
216
|
+
region: string;
|
|
217
|
+
/** Cognito User Pool ID */
|
|
218
|
+
userPoolId: string;
|
|
219
|
+
/** App client ID */
|
|
220
|
+
clientId: string;
|
|
221
|
+
/** App client secret (if configured) */
|
|
222
|
+
clientSecret?: string;
|
|
223
|
+
/** OAuth callback URL */
|
|
224
|
+
redirectUri?: string;
|
|
225
|
+
/** Cognito domain for hosted UI (e.g., 'myapp.auth.us-east-1.amazoncognito.com') */
|
|
226
|
+
domain?: string;
|
|
227
|
+
/** Default scopes to request */
|
|
228
|
+
scopes?: string[];
|
|
229
|
+
/** AWS credentials (optional, uses default credential chain if not provided) */
|
|
230
|
+
credentials?: AWSCredentials;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* AWS credentials for Cognito.
|
|
234
|
+
*/
|
|
235
|
+
export interface AWSCredentials {
|
|
236
|
+
accessKeyId: string;
|
|
237
|
+
secretAccessKey: string;
|
|
238
|
+
sessionToken?: string;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Nostr provider options.
|
|
242
|
+
*/
|
|
243
|
+
export interface NostrOptions extends BaseAuthOptions {
|
|
244
|
+
type: 'nostr';
|
|
245
|
+
/** Relay URLs to connect to */
|
|
246
|
+
relays: string[];
|
|
247
|
+
/**
|
|
248
|
+
* Private key (nsec) for signing - only for server-side operations.
|
|
249
|
+
* WARNING: Never expose this in client-side code.
|
|
250
|
+
*/
|
|
251
|
+
privateKey?: string;
|
|
252
|
+
/**
|
|
253
|
+
* Challenge expiration time in seconds.
|
|
254
|
+
* @default 300 (5 minutes)
|
|
255
|
+
*/
|
|
256
|
+
challengeExpiration?: number;
|
|
257
|
+
/** Local role mapping storage */
|
|
258
|
+
roleStore?: RoleStoreConfig;
|
|
259
|
+
/** Session storage configuration */
|
|
260
|
+
sessionStore?: SessionStoreConfig;
|
|
261
|
+
/**
|
|
262
|
+
* Timeout for relay operations in milliseconds.
|
|
263
|
+
* @default 10000
|
|
264
|
+
*/
|
|
265
|
+
relayTimeout?: number;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Role store configuration for Nostr.
|
|
269
|
+
*/
|
|
270
|
+
export interface RoleStoreConfig {
|
|
271
|
+
type: 'memory' | 'file' | 'database';
|
|
272
|
+
path?: string;
|
|
273
|
+
/** DatabaseInterface from @happyvertical/sql */
|
|
274
|
+
database?: unknown;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Session store configuration for Nostr.
|
|
278
|
+
*/
|
|
279
|
+
export interface SessionStoreConfig {
|
|
280
|
+
type: 'memory' | 'file' | 'database';
|
|
281
|
+
path?: string;
|
|
282
|
+
database?: unknown;
|
|
283
|
+
/** Session TTL in seconds */
|
|
284
|
+
ttl?: number;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Kanidm provider options.
|
|
288
|
+
*/
|
|
289
|
+
export interface KanidmOptions extends BaseAuthOptions {
|
|
290
|
+
type: 'kanidm';
|
|
291
|
+
/** Kanidm server URL (e.g., 'https://idp.example.com') */
|
|
292
|
+
serverUrl: string;
|
|
293
|
+
/** OAuth2 client ID */
|
|
294
|
+
clientId: string;
|
|
295
|
+
/** Client secret (for confidential clients) */
|
|
296
|
+
clientSecret?: string;
|
|
297
|
+
/** OAuth callback URL for this application */
|
|
298
|
+
redirectUri?: string;
|
|
299
|
+
/** Default scopes to request */
|
|
300
|
+
scopes?: string[];
|
|
301
|
+
/**
|
|
302
|
+
* Use PKCE for authorization code flow.
|
|
303
|
+
* @default true (required by Kanidm)
|
|
304
|
+
*/
|
|
305
|
+
usePKCE?: boolean;
|
|
306
|
+
/**
|
|
307
|
+
* Verify SSL certificates.
|
|
308
|
+
* @default true
|
|
309
|
+
*/
|
|
310
|
+
verifySsl?: boolean;
|
|
311
|
+
/**
|
|
312
|
+
* Admin username for Kanidm API operations.
|
|
313
|
+
* Required for user management operations.
|
|
314
|
+
*/
|
|
315
|
+
adminUsername?: string;
|
|
316
|
+
/**
|
|
317
|
+
* Admin password for Kanidm API operations.
|
|
318
|
+
* Required for user management operations.
|
|
319
|
+
*/
|
|
320
|
+
adminPassword?: string;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Google provider options.
|
|
324
|
+
*/
|
|
325
|
+
export interface GoogleOptions extends BaseAuthOptions {
|
|
326
|
+
type: 'google';
|
|
327
|
+
/** OAuth2 client ID from Google Cloud Console */
|
|
328
|
+
clientId: string;
|
|
329
|
+
/** OAuth2 client secret from Google Cloud Console */
|
|
330
|
+
clientSecret: string;
|
|
331
|
+
/** OAuth callback URL for this application */
|
|
332
|
+
redirectUri?: string;
|
|
333
|
+
/**
|
|
334
|
+
* Default scopes to request.
|
|
335
|
+
* @default ['openid', 'profile', 'email']
|
|
336
|
+
*/
|
|
337
|
+
scopes?: string[];
|
|
338
|
+
/**
|
|
339
|
+
* Use PKCE for authorization code flow.
|
|
340
|
+
* @default true
|
|
341
|
+
*/
|
|
342
|
+
usePKCE?: boolean;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* GitHub provider options.
|
|
346
|
+
*/
|
|
347
|
+
export interface GitHubOptions extends BaseAuthOptions {
|
|
348
|
+
type: 'github';
|
|
349
|
+
/** OAuth App client ID from GitHub Developer Settings */
|
|
350
|
+
clientId: string;
|
|
351
|
+
/** OAuth App client secret from GitHub Developer Settings */
|
|
352
|
+
clientSecret: string;
|
|
353
|
+
/** OAuth callback URL for this application */
|
|
354
|
+
redirectUri?: string;
|
|
355
|
+
/**
|
|
356
|
+
* Default scopes to request.
|
|
357
|
+
* @default ['user:email', 'read:user']
|
|
358
|
+
*/
|
|
359
|
+
scopes?: string[];
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Union type for all provider options.
|
|
363
|
+
*/
|
|
364
|
+
export type GetAuthOptions = KeycloakOptions | CognitoOptions | NostrOptions | KanidmOptions | GoogleOptions | GitHubOptions;
|
|
365
|
+
/**
|
|
366
|
+
* Options for initiating authorization flow.
|
|
367
|
+
*/
|
|
368
|
+
export interface AuthorizationOptions {
|
|
369
|
+
/** OAuth scopes to request */
|
|
370
|
+
scopes?: string[];
|
|
371
|
+
/** State parameter for CSRF protection */
|
|
372
|
+
state?: string;
|
|
373
|
+
/** Nonce for ID token validation */
|
|
374
|
+
nonce?: string;
|
|
375
|
+
/** Custom redirect URI (overrides default) */
|
|
376
|
+
redirectUri?: string;
|
|
377
|
+
/** Prompt behavior ('login' | 'consent' | 'none') */
|
|
378
|
+
prompt?: 'login' | 'consent' | 'none';
|
|
379
|
+
/** Login hint (pre-fill email/username) */
|
|
380
|
+
loginHint?: string;
|
|
381
|
+
/** Additional custom parameters */
|
|
382
|
+
extraParams?: Record<string, string>;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Result from getAuthorizationUrl.
|
|
386
|
+
*/
|
|
387
|
+
export interface AuthorizationResult {
|
|
388
|
+
/**
|
|
389
|
+
* The authorization URL to redirect to.
|
|
390
|
+
* For Nostr: URL-encoded challenge data or NIP-07 compatible data.
|
|
391
|
+
*/
|
|
392
|
+
url: string;
|
|
393
|
+
/** State parameter to verify on callback */
|
|
394
|
+
state: string;
|
|
395
|
+
/** PKCE code verifier (store securely, needed for code exchange) */
|
|
396
|
+
codeVerifier?: string;
|
|
397
|
+
/** Nonce for ID token validation */
|
|
398
|
+
nonce?: string;
|
|
399
|
+
/** For Nostr: The challenge to be signed */
|
|
400
|
+
challenge?: string;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Parameters for code exchange.
|
|
404
|
+
*/
|
|
405
|
+
export interface CodeExchangeParams {
|
|
406
|
+
/** Authorization code from callback */
|
|
407
|
+
code: string;
|
|
408
|
+
/** State parameter from callback (for verification) */
|
|
409
|
+
state?: string;
|
|
410
|
+
/** PKCE code verifier */
|
|
411
|
+
codeVerifier?: string;
|
|
412
|
+
/** Redirect URI (must match authorization request) */
|
|
413
|
+
redirectUri?: string;
|
|
414
|
+
/** For Nostr: Signed challenge event */
|
|
415
|
+
signedEvent?: NostrSignedEvent;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Authentication credentials.
|
|
419
|
+
*/
|
|
420
|
+
export interface AuthCredentials {
|
|
421
|
+
/** OAuth grant type */
|
|
422
|
+
grantType?: 'password' | 'client_credentials';
|
|
423
|
+
/** Username or email */
|
|
424
|
+
username?: string;
|
|
425
|
+
/** Password */
|
|
426
|
+
password?: string;
|
|
427
|
+
/** For Nostr: Private key (nsec format) */
|
|
428
|
+
privateKey?: string;
|
|
429
|
+
/** For Nostr: Public key (npub format) */
|
|
430
|
+
publicKey?: string;
|
|
431
|
+
/** OAuth scopes to request */
|
|
432
|
+
scopes?: string[];
|
|
433
|
+
/** MFA/2FA code if required */
|
|
434
|
+
mfaCode?: string;
|
|
435
|
+
/** For Nostr: Authentication method */
|
|
436
|
+
method?: 'extension' | 'privateKey' | 'generate' | 'bunker';
|
|
437
|
+
/** For Nostr: NIP-46 bunker URL */
|
|
438
|
+
bunkerUrl?: string;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Authentication result.
|
|
442
|
+
*/
|
|
443
|
+
export interface AuthResult {
|
|
444
|
+
/** Access token (JWT for OAuth, session token for Nostr) */
|
|
445
|
+
accessToken: string;
|
|
446
|
+
/** Token type (usually 'Bearer') */
|
|
447
|
+
tokenType: string;
|
|
448
|
+
/** Access token expiration in seconds */
|
|
449
|
+
expiresIn: number;
|
|
450
|
+
/** Refresh token for obtaining new access tokens */
|
|
451
|
+
refreshToken?: string;
|
|
452
|
+
/** ID token (OIDC) */
|
|
453
|
+
idToken?: string;
|
|
454
|
+
/** Granted scopes */
|
|
455
|
+
scope?: string;
|
|
456
|
+
/** User identifier */
|
|
457
|
+
userId: string;
|
|
458
|
+
/** For Nostr: Public key (npub) */
|
|
459
|
+
publicKey?: string;
|
|
460
|
+
/** For Nostr: Private key (nsec) - only returned on key generation, shown once */
|
|
461
|
+
privateKey?: string;
|
|
462
|
+
/** Warning message (e.g., for Nostr key generation) */
|
|
463
|
+
warning?: string;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Logout options.
|
|
467
|
+
*/
|
|
468
|
+
export interface LogoutOptions {
|
|
469
|
+
/** Access token or ID token to invalidate */
|
|
470
|
+
token?: string;
|
|
471
|
+
/** Refresh token to revoke */
|
|
472
|
+
refreshToken?: string;
|
|
473
|
+
/** Session ID to end */
|
|
474
|
+
sessionId?: string;
|
|
475
|
+
/** Redirect after logout (for OIDC) */
|
|
476
|
+
postLogoutRedirectUri?: string;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Token validation options.
|
|
480
|
+
*/
|
|
481
|
+
export interface TokenValidationOptions {
|
|
482
|
+
/** Expected audience(s) */
|
|
483
|
+
audience?: string | string[];
|
|
484
|
+
/** Expected issuer */
|
|
485
|
+
issuer?: string;
|
|
486
|
+
/** Expected nonce (for ID tokens) */
|
|
487
|
+
nonce?: string;
|
|
488
|
+
/** Skip expiration check */
|
|
489
|
+
ignoreExpiration?: boolean;
|
|
490
|
+
/** Clock tolerance in seconds */
|
|
491
|
+
clockTolerance?: number;
|
|
492
|
+
/** For Nostr NIP-98: Expected URL */
|
|
493
|
+
expectedUrl?: string;
|
|
494
|
+
/** For Nostr NIP-98: Expected HTTP method */
|
|
495
|
+
expectedMethod?: string;
|
|
496
|
+
/** For Nostr NIP-98: Max age in seconds */
|
|
497
|
+
maxAge?: number;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Token claims (decoded and validated).
|
|
501
|
+
* Property names follow OIDC/JWT standard claim names.
|
|
502
|
+
*/
|
|
503
|
+
export interface TokenClaims {
|
|
504
|
+
/** Subject (user ID) */
|
|
505
|
+
sub: string;
|
|
506
|
+
/** Issuer */
|
|
507
|
+
iss: string;
|
|
508
|
+
/** Audience */
|
|
509
|
+
aud: string | string[];
|
|
510
|
+
/** Expiration timestamp */
|
|
511
|
+
exp: number;
|
|
512
|
+
/** Issued at timestamp */
|
|
513
|
+
iat: number;
|
|
514
|
+
/** Not before timestamp */
|
|
515
|
+
nbf?: number;
|
|
516
|
+
/** Authorized party (OIDC) */
|
|
517
|
+
azp?: string;
|
|
518
|
+
/** User email */
|
|
519
|
+
email?: string;
|
|
520
|
+
/** Email verified flag */
|
|
521
|
+
email_verified?: boolean;
|
|
522
|
+
/** User's preferred username */
|
|
523
|
+
preferred_username?: string;
|
|
524
|
+
/** User's name */
|
|
525
|
+
name?: string;
|
|
526
|
+
/** Roles (Keycloak resource_access or realm_access) */
|
|
527
|
+
roles?: string[];
|
|
528
|
+
/** For Nostr: Public key */
|
|
529
|
+
pubkey?: string;
|
|
530
|
+
/** Additional claims */
|
|
531
|
+
[key: string]: unknown;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Decoded token payload (without validation).
|
|
535
|
+
*/
|
|
536
|
+
export interface TokenPayload {
|
|
537
|
+
header: {
|
|
538
|
+
alg: string;
|
|
539
|
+
typ?: string;
|
|
540
|
+
kid?: string;
|
|
541
|
+
};
|
|
542
|
+
payload: TokenClaims;
|
|
543
|
+
signature: string;
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Token introspection result.
|
|
547
|
+
*/
|
|
548
|
+
export interface TokenIntrospection {
|
|
549
|
+
/** Is the token active? */
|
|
550
|
+
active: boolean;
|
|
551
|
+
/** Token claims (if active) */
|
|
552
|
+
claims?: TokenClaims;
|
|
553
|
+
/** Token type */
|
|
554
|
+
tokenType?: string;
|
|
555
|
+
/** Client ID that requested the token */
|
|
556
|
+
clientId?: string;
|
|
557
|
+
/** Scopes granted to this token */
|
|
558
|
+
scope?: string;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* User profile.
|
|
562
|
+
*/
|
|
563
|
+
export interface UserProfile {
|
|
564
|
+
/** User identifier */
|
|
565
|
+
id: string;
|
|
566
|
+
/** Username */
|
|
567
|
+
username?: string;
|
|
568
|
+
/** Email address */
|
|
569
|
+
email?: string;
|
|
570
|
+
/** Email verified status */
|
|
571
|
+
emailVerified?: boolean;
|
|
572
|
+
/** First name */
|
|
573
|
+
firstName?: string;
|
|
574
|
+
/** Last name */
|
|
575
|
+
lastName?: string;
|
|
576
|
+
/** Display name */
|
|
577
|
+
displayName?: string;
|
|
578
|
+
/** Profile picture URL */
|
|
579
|
+
picture?: string;
|
|
580
|
+
/** Phone number */
|
|
581
|
+
phone?: string;
|
|
582
|
+
/** Phone verified status */
|
|
583
|
+
phoneVerified?: boolean;
|
|
584
|
+
/** Account enabled status */
|
|
585
|
+
enabled?: boolean;
|
|
586
|
+
/** Account creation timestamp */
|
|
587
|
+
createdAt?: Date;
|
|
588
|
+
/** Last update timestamp */
|
|
589
|
+
updatedAt?: Date;
|
|
590
|
+
/** User's roles */
|
|
591
|
+
roles?: string[];
|
|
592
|
+
/** User's groups */
|
|
593
|
+
groups?: string[];
|
|
594
|
+
/** Custom attributes */
|
|
595
|
+
attributes?: Record<string, string | string[]>;
|
|
596
|
+
/** For Nostr: Public key (npub) */
|
|
597
|
+
publicKey?: string;
|
|
598
|
+
/** For Nostr: NIP-05 identifier */
|
|
599
|
+
nip05?: string;
|
|
600
|
+
/** For Nostr: Lightning address (LUD-16) */
|
|
601
|
+
lud16?: string;
|
|
602
|
+
/** For Nostr: About text */
|
|
603
|
+
about?: string;
|
|
604
|
+
/** For Nostr: Banner image URL */
|
|
605
|
+
banner?: string;
|
|
606
|
+
/** For Nostr: Website URL */
|
|
607
|
+
website?: string;
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Create user request.
|
|
611
|
+
*/
|
|
612
|
+
export interface CreateUserRequest {
|
|
613
|
+
username: string;
|
|
614
|
+
email?: string;
|
|
615
|
+
password?: string;
|
|
616
|
+
firstName?: string;
|
|
617
|
+
lastName?: string;
|
|
618
|
+
enabled?: boolean;
|
|
619
|
+
emailVerified?: boolean;
|
|
620
|
+
attributes?: Record<string, string | string[]>;
|
|
621
|
+
roles?: string[];
|
|
622
|
+
groups?: string[];
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* User query parameters.
|
|
626
|
+
*/
|
|
627
|
+
export interface UserQuery {
|
|
628
|
+
/** Search string (matches username, email, name) */
|
|
629
|
+
search?: string;
|
|
630
|
+
/** Filter by email */
|
|
631
|
+
email?: string;
|
|
632
|
+
/** Filter by username */
|
|
633
|
+
username?: string;
|
|
634
|
+
/** Filter by enabled status */
|
|
635
|
+
enabled?: boolean;
|
|
636
|
+
/** Maximum results to return */
|
|
637
|
+
limit?: number;
|
|
638
|
+
/** Offset for pagination */
|
|
639
|
+
offset?: number;
|
|
640
|
+
/** For Nostr: Search by npub */
|
|
641
|
+
publicKey?: string;
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* User list result.
|
|
645
|
+
*/
|
|
646
|
+
export interface UserListResult {
|
|
647
|
+
users: UserProfile[];
|
|
648
|
+
total: number;
|
|
649
|
+
limit: number;
|
|
650
|
+
offset: number;
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* User session.
|
|
654
|
+
*/
|
|
655
|
+
export interface Session {
|
|
656
|
+
/** Session identifier */
|
|
657
|
+
id: string;
|
|
658
|
+
/** User identifier */
|
|
659
|
+
userId: string;
|
|
660
|
+
/** Client identifier */
|
|
661
|
+
clientId?: string;
|
|
662
|
+
/** Session start time */
|
|
663
|
+
startedAt: Date;
|
|
664
|
+
/** Last activity time */
|
|
665
|
+
lastAccessedAt: Date;
|
|
666
|
+
/** Session expiration time */
|
|
667
|
+
expiresAt?: Date;
|
|
668
|
+
/** IP address */
|
|
669
|
+
ipAddress?: string;
|
|
670
|
+
/** User agent */
|
|
671
|
+
userAgent?: string;
|
|
672
|
+
/** For Nostr: Connected relays */
|
|
673
|
+
relays?: string[];
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Provider capabilities.
|
|
677
|
+
*/
|
|
678
|
+
export interface AuthCapabilities {
|
|
679
|
+
/** Supports OAuth 2.0 authorization code flow */
|
|
680
|
+
authorizationCode: boolean;
|
|
681
|
+
/** Supports resource owner password credentials grant */
|
|
682
|
+
passwordGrant: boolean;
|
|
683
|
+
/** Supports client credentials grant */
|
|
684
|
+
clientCredentials: boolean;
|
|
685
|
+
/** Supports token refresh */
|
|
686
|
+
tokenRefresh: boolean;
|
|
687
|
+
/** Supports OpenID Connect */
|
|
688
|
+
oidc: boolean;
|
|
689
|
+
/** Supports user management (CRUD) */
|
|
690
|
+
userManagement: boolean;
|
|
691
|
+
/** Supports session management */
|
|
692
|
+
sessionManagement: boolean;
|
|
693
|
+
/** Supports role-based access control */
|
|
694
|
+
rbac: boolean;
|
|
695
|
+
/** Supports password reset flow */
|
|
696
|
+
passwordReset: boolean;
|
|
697
|
+
/** Supports MFA/2FA */
|
|
698
|
+
mfa: boolean;
|
|
699
|
+
/** Supports social login */
|
|
700
|
+
socialLogin: boolean;
|
|
701
|
+
/** Supports federated identity */
|
|
702
|
+
federation: boolean;
|
|
703
|
+
/** Is a decentralized provider */
|
|
704
|
+
decentralized: boolean;
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* OIDC Discovery Document.
|
|
708
|
+
*/
|
|
709
|
+
export interface OIDCDiscoveryDocument {
|
|
710
|
+
issuer: string;
|
|
711
|
+
authorization_endpoint: string;
|
|
712
|
+
token_endpoint: string;
|
|
713
|
+
userinfo_endpoint: string;
|
|
714
|
+
jwks_uri: string;
|
|
715
|
+
registration_endpoint?: string;
|
|
716
|
+
scopes_supported: string[];
|
|
717
|
+
response_types_supported: string[];
|
|
718
|
+
grant_types_supported: string[];
|
|
719
|
+
subject_types_supported: string[];
|
|
720
|
+
id_token_signing_alg_values_supported: string[];
|
|
721
|
+
token_endpoint_auth_methods_supported: string[];
|
|
722
|
+
claims_supported: string[];
|
|
723
|
+
end_session_endpoint?: string;
|
|
724
|
+
introspection_endpoint?: string;
|
|
725
|
+
revocation_endpoint?: string;
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Nostr signed event (NIP-01).
|
|
729
|
+
* Property names follow Nostr protocol specification.
|
|
730
|
+
*/
|
|
731
|
+
export interface NostrSignedEvent {
|
|
732
|
+
id: string;
|
|
733
|
+
pubkey: string;
|
|
734
|
+
created_at: number;
|
|
735
|
+
kind: number;
|
|
736
|
+
tags: string[][];
|
|
737
|
+
content: string;
|
|
738
|
+
sig: string;
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* Nostr unsigned event (for signing).
|
|
742
|
+
* Property names follow Nostr protocol specification.
|
|
743
|
+
*/
|
|
744
|
+
export interface NostrUnsignedEvent {
|
|
745
|
+
kind: number;
|
|
746
|
+
created_at: number;
|
|
747
|
+
tags: string[][];
|
|
748
|
+
content: string;
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Nostr NIP-98 token options.
|
|
752
|
+
*/
|
|
753
|
+
export interface NostrTokenOptions {
|
|
754
|
+
/** The URL being accessed */
|
|
755
|
+
url: string;
|
|
756
|
+
/** HTTP method */
|
|
757
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
758
|
+
/** Optional payload hash for POST/PUT requests */
|
|
759
|
+
payloadHash?: string;
|
|
760
|
+
/**
|
|
761
|
+
* Token validity window in seconds.
|
|
762
|
+
* @default 60
|
|
763
|
+
*/
|
|
764
|
+
validityWindow?: number;
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* Nostr NIP-98 token.
|
|
768
|
+
*/
|
|
769
|
+
export interface NostrToken {
|
|
770
|
+
/** The signed NIP-98 event (kind 27235) */
|
|
771
|
+
event: NostrSignedEvent;
|
|
772
|
+
/** Base64-encoded event for Authorization header */
|
|
773
|
+
authorizationHeader: string;
|
|
774
|
+
/** When this token was created */
|
|
775
|
+
createdAt: Date;
|
|
776
|
+
/** When this token expires */
|
|
777
|
+
expiresAt: Date;
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Nostr signer interface.
|
|
781
|
+
*/
|
|
782
|
+
export interface NostrSigner {
|
|
783
|
+
/** Get the public key */
|
|
784
|
+
getPublicKey(): Promise<string>;
|
|
785
|
+
/** Sign an event */
|
|
786
|
+
signEvent(event: NostrUnsignedEvent): Promise<NostrSignedEvent>;
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Window.nostr interface (NIP-07).
|
|
790
|
+
*/
|
|
791
|
+
export interface WindowNostr {
|
|
792
|
+
getPublicKey(): Promise<string>;
|
|
793
|
+
signEvent(event: NostrUnsignedEvent): Promise<NostrSignedEvent>;
|
|
794
|
+
getRelays?(): Promise<Record<string, {
|
|
795
|
+
read: boolean;
|
|
796
|
+
write: boolean;
|
|
797
|
+
}>>;
|
|
798
|
+
nip04?: {
|
|
799
|
+
encrypt(pubkey: string, plaintext: string): Promise<string>;
|
|
800
|
+
decrypt(pubkey: string, ciphertext: string): Promise<string>;
|
|
801
|
+
};
|
|
802
|
+
nip44?: {
|
|
803
|
+
encrypt(pubkey: string, plaintext: string): Promise<string>;
|
|
804
|
+
decrypt(pubkey: string, ciphertext: string): Promise<string>;
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
declare global {
|
|
808
|
+
interface Window {
|
|
809
|
+
nostr?: WindowNostr;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
//# sourceMappingURL=types.d.ts.map
|