kavachos 0.0.4 → 0.0.6
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/dist/a2a/index.d.ts +2340 -0
- package/dist/a2a/index.js +821 -0
- package/dist/a2a/index.js.map +1 -0
- package/dist/agent/index.d.ts +3 -4
- package/dist/agent/index.js +4 -3
- package/dist/audit/index.d.ts +2 -3
- package/dist/audit/index.js +3 -3
- package/dist/auth/index.d.ts +490 -93
- package/dist/auth/index.js +4 -3
- package/dist/{chunk-KL6XW4S4.js → chunk-FKVAXCNJ.js} +2375 -633
- package/dist/chunk-FKVAXCNJ.js.map +1 -0
- package/dist/{chunk-5DT4DN4Y.js → chunk-IKTOSJ4O.js} +13 -13
- package/dist/chunk-IKTOSJ4O.js.map +1 -0
- package/dist/{chunk-V66UUIA7.js → chunk-KDL6A76K.js} +93 -4
- package/dist/chunk-KDL6A76K.js.map +1 -0
- package/dist/chunk-NSBPE2FW.js +15 -0
- package/dist/{chunk-PZ5AY32C.js.map → chunk-NSBPE2FW.js.map} +1 -1
- package/dist/chunk-NSTER7KE.js +538 -0
- package/dist/chunk-NSTER7KE.js.map +1 -0
- package/dist/chunk-QCRHJMDX.js +186 -0
- package/dist/chunk-QCRHJMDX.js.map +1 -0
- package/dist/{chunk-OVGNZ5OX.js → chunk-VHKZARMM.js} +6 -6
- package/dist/chunk-VHKZARMM.js.map +1 -0
- package/dist/{chunk-SJGSPIAD.js → chunk-Y3OWAJHK.js} +3 -3
- package/dist/{chunk-SJGSPIAD.js.map → chunk-Y3OWAJHK.js.map} +1 -1
- package/dist/index.d.ts +138 -6
- package/dist/index.js +580 -35
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.js +12 -16
- package/dist/mcp/index.js.map +1 -1
- package/dist/permission/index.d.ts +3 -4
- package/dist/permission/index.js +4 -3
- package/dist/{types-Xk83hv4O.d.ts → types-W8X0PXE7.d.ts} +1764 -99
- package/dist/vc/index.d.ts +800 -0
- package/dist/vc/index.js +5 -0
- package/dist/vc/index.js.map +1 -0
- package/package.json +17 -1
- package/dist/chunk-5DT4DN4Y.js.map +0 -1
- package/dist/chunk-KL6XW4S4.js.map +0 -1
- package/dist/chunk-OVGNZ5OX.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -9
- package/dist/chunk-V66UUIA7.js.map +0 -1
- package/dist/{types-mwupB57A.d.ts → types-BuHrZcjE.d.ts} +2 -2
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
3
|
-
export { u as AdminModule,
|
|
4
|
-
import { R as Result } from '../types-
|
|
2
|
+
import { a2 as AuthAdapter, o as ResolvedUser, L as KavachPlugin, D as Database, X as AdminConfig, p as SessionManager, $ as ApiKeyManagerConfig, a7 as EmailOtpConfig, P as Permission, ab as MagicLinkConfig, ag as OrgConfig, al as PasskeyConfig, I as PluginEndpoint, aF as TotpConfig } from '../types-W8X0PXE7.js';
|
|
3
|
+
export { u as AdminModule, Y as AdminUser, _ as ApiKey, v as ApiKeyManagerModule, a3 as CaptchaConfig, G as CaptchaModule, a4 as CaptchaVerifyResult, a5 as CreateTokenInput, E as EmailOtpModule, a8 as EmailVerificationConfig, y as EmailVerificationModule, r as MagicLinkModule, ad as OidcProvider, ae as OneTimeTokenConfig, z as OneTimeTokenModule, af as OneTimeTokenPurpose, ah as OrgInvitation, ai as OrgMember, O as OrgModule, aj as OrgRole, ak as Organization, am as PasskeyCredential, s as PasskeyModule, an as PasswordResetConfig, x as PasswordResetModule, ap as PhoneAuthConfig, F as PhoneAuthModule, av as RevokeTokensResult, aw as SSO_ERROR, ax as SamlProvider, aA as SsoAuditEvent, aB as SsoConfig, aC as SsoConnection, aD as SsoError, t as SsoModule, T as TotpModule, aG as TotpSetup, aH as UsernameAuthConfig, w as UsernameAuthModule, aI as ValidateTokenResult, bv as WebhookConfig, bw as WebhookEvent, W as WebhookModule, aS as createAdminModule, aT as createApiKeyManagerModule, aV as createCaptchaModule, aY as createEmailOtpModule, aZ as createEmailVerificationModule, a_ as createMagicLinkModule, a$ as createOneTimeTokenModule, b0 as createOrgModule, b1 as createPasskeyModule, b2 as createPasswordResetModule, b3 as createPhoneAuthModule, b7 as createSsoModule, b8 as createTotpModule, b9 as createUsernameAuthModule, bx as createWebhookModule } from '../types-W8X0PXE7.js';
|
|
4
|
+
import { R as Result } from '../types-BuHrZcjE.js';
|
|
5
5
|
import * as jose from 'jose';
|
|
6
|
-
import 'drizzle-orm/better-sqlite3';
|
|
7
6
|
import 'drizzle-orm/sqlite-core';
|
|
8
7
|
|
|
9
8
|
/**
|
|
@@ -288,6 +287,87 @@ declare function anonymousAuth(config?: AnonymousAuthConfig): KavachPlugin;
|
|
|
288
287
|
|
|
289
288
|
declare function apiKeys(config?: ApiKeyManagerConfig): KavachPlugin;
|
|
290
289
|
|
|
290
|
+
interface CostAttributionConfig {
|
|
291
|
+
/** ISO 4217 currency code, default 'USD' */
|
|
292
|
+
currency?: string;
|
|
293
|
+
/** Dollar amounts that trigger alerts */
|
|
294
|
+
alertThresholds?: {
|
|
295
|
+
warn: number;
|
|
296
|
+
critical: number;
|
|
297
|
+
};
|
|
298
|
+
/** Called when a threshold is crossed or budget exceeded */
|
|
299
|
+
onAlert?: (alert: CostAlert) => void | Promise<void>;
|
|
300
|
+
/** How many days of events to keep, default 90 */
|
|
301
|
+
retentionDays?: number;
|
|
302
|
+
}
|
|
303
|
+
interface RecordCostInput {
|
|
304
|
+
agentId: string;
|
|
305
|
+
/** e.g. 'openai:gpt-4o', 'anthropic:claude-3-5-sonnet', 'mcp:github' */
|
|
306
|
+
tool: string;
|
|
307
|
+
inputTokens?: number;
|
|
308
|
+
outputTokens?: number;
|
|
309
|
+
costUsd: number;
|
|
310
|
+
metadata?: Record<string, unknown>;
|
|
311
|
+
/** Attribute to a delegation chain */
|
|
312
|
+
delegationChainId?: string;
|
|
313
|
+
}
|
|
314
|
+
interface CostReport {
|
|
315
|
+
agentId: string;
|
|
316
|
+
period: {
|
|
317
|
+
start: Date;
|
|
318
|
+
end: Date;
|
|
319
|
+
};
|
|
320
|
+
totalCostUsd: number;
|
|
321
|
+
byTool: Array<{
|
|
322
|
+
tool: string;
|
|
323
|
+
costUsd: number;
|
|
324
|
+
callCount: number;
|
|
325
|
+
}>;
|
|
326
|
+
byDay: Array<{
|
|
327
|
+
date: string;
|
|
328
|
+
costUsd: number;
|
|
329
|
+
}>;
|
|
330
|
+
}
|
|
331
|
+
interface CostAlert {
|
|
332
|
+
type: "warn" | "critical" | "budget_exceeded";
|
|
333
|
+
agentId: string;
|
|
334
|
+
currentCostUsd: number;
|
|
335
|
+
threshold: number;
|
|
336
|
+
period: string;
|
|
337
|
+
}
|
|
338
|
+
interface BudgetCheckResult {
|
|
339
|
+
withinBudget: boolean;
|
|
340
|
+
spent: number;
|
|
341
|
+
limit: number | null;
|
|
342
|
+
remaining: number | null;
|
|
343
|
+
}
|
|
344
|
+
interface CostAttributionModule {
|
|
345
|
+
recordCost(input: RecordCostInput): Promise<Result<void>>;
|
|
346
|
+
getAgentCost(agentId: string, period?: {
|
|
347
|
+
start: Date;
|
|
348
|
+
end: Date;
|
|
349
|
+
}): Promise<Result<CostReport>>;
|
|
350
|
+
getOwnerCost(ownerId: string, period?: {
|
|
351
|
+
start: Date;
|
|
352
|
+
end: Date;
|
|
353
|
+
}): Promise<Result<CostReport>>;
|
|
354
|
+
getTopAgentsByCost(limit?: number, period?: {
|
|
355
|
+
start: Date;
|
|
356
|
+
end: Date;
|
|
357
|
+
}): Promise<Result<Array<{
|
|
358
|
+
agentId: string;
|
|
359
|
+
totalCostUsd: number;
|
|
360
|
+
}>>>;
|
|
361
|
+
getDelegationChainCost(chainId: string): Promise<Result<CostReport>>;
|
|
362
|
+
checkBudget(agentId: string): Promise<Result<BudgetCheckResult>>;
|
|
363
|
+
cleanup(options?: {
|
|
364
|
+
retentionDays?: number;
|
|
365
|
+
}): Promise<Result<{
|
|
366
|
+
deleted: number;
|
|
367
|
+
}>>;
|
|
368
|
+
}
|
|
369
|
+
declare function createCostAttributionModule(db: Database, config?: CostAttributionConfig): CostAttributionModule;
|
|
370
|
+
|
|
291
371
|
/**
|
|
292
372
|
* Custom session fields plugin for KavachOS.
|
|
293
373
|
*
|
|
@@ -423,6 +503,308 @@ declare function deviceAuth(config: DeviceAuthConfig): KavachPlugin;
|
|
|
423
503
|
|
|
424
504
|
declare function emailOtp(config: EmailOtpConfig): KavachPlugin;
|
|
425
505
|
|
|
506
|
+
/**
|
|
507
|
+
* Ephemeral agent sessions for KavachOS.
|
|
508
|
+
*
|
|
509
|
+
* Short-lived, auto-expiring agent credentials for single-task use. Designed
|
|
510
|
+
* for computer-use agents (Claude, GPT with browsing, operator loops) that
|
|
511
|
+
* should not hold persistent tokens across invocations.
|
|
512
|
+
*
|
|
513
|
+
* Each session spins up a temporary agent, issues a bounded bearer token, and
|
|
514
|
+
* tracks how many actions have been consumed. When the TTL lapses or the
|
|
515
|
+
* action budget is exhausted the token becomes invalid and the underlying
|
|
516
|
+
* agent is automatically revoked.
|
|
517
|
+
*
|
|
518
|
+
* @example
|
|
519
|
+
* ```typescript
|
|
520
|
+
* const mod = createEphemeralSessionModule({ db });
|
|
521
|
+
*
|
|
522
|
+
* // Create a 5-minute, 10-action session
|
|
523
|
+
* const result = await mod.createSession({
|
|
524
|
+
* ownerId: 'user-123',
|
|
525
|
+
* permissions: [{ resource: 'tool:browser', actions: ['navigate', 'click'] }],
|
|
526
|
+
* ttlSeconds: 300,
|
|
527
|
+
* maxActions: 10,
|
|
528
|
+
* });
|
|
529
|
+
*
|
|
530
|
+
* if (!result.success) throw new Error(result.error.message);
|
|
531
|
+
*
|
|
532
|
+
* const { token } = result.data;
|
|
533
|
+
*
|
|
534
|
+
* // Each time the agent performs an action
|
|
535
|
+
* await mod.consumeAction(token);
|
|
536
|
+
* ```
|
|
537
|
+
*/
|
|
538
|
+
|
|
539
|
+
interface EphemeralSessionConfig {
|
|
540
|
+
db: Database;
|
|
541
|
+
/** Default TTL for sessions in seconds (default: 300 = 5 min) */
|
|
542
|
+
defaultTtlSeconds?: number;
|
|
543
|
+
/** Hard ceiling on TTL in seconds (default: 3600 = 1 hour) */
|
|
544
|
+
maxTtlSeconds?: number;
|
|
545
|
+
/** Automatically revoke the underlying agent when the session expires (default: true) */
|
|
546
|
+
autoRevokeOnExpiry?: boolean;
|
|
547
|
+
/** Group all actions under a shared audit session ID (default: true) */
|
|
548
|
+
auditGrouping?: boolean;
|
|
549
|
+
}
|
|
550
|
+
interface CreateEphemeralSessionInput {
|
|
551
|
+
ownerId: string;
|
|
552
|
+
name?: string;
|
|
553
|
+
permissions: Permission[];
|
|
554
|
+
/** Seconds until the session expires (capped at maxTtlSeconds) */
|
|
555
|
+
ttlSeconds?: number;
|
|
556
|
+
/** Optional cap on the number of actions the token may authorize */
|
|
557
|
+
maxActions?: number;
|
|
558
|
+
metadata?: Record<string, unknown>;
|
|
559
|
+
}
|
|
560
|
+
interface EphemeralSession {
|
|
561
|
+
sessionId: string;
|
|
562
|
+
agentId: string;
|
|
563
|
+
/** Bearer token — shown once, never stored in plain text */
|
|
564
|
+
token: string;
|
|
565
|
+
expiresAt: Date;
|
|
566
|
+
maxActions: number | null;
|
|
567
|
+
actionsUsed: number;
|
|
568
|
+
status: "active" | "expired" | "exhausted" | "revoked";
|
|
569
|
+
/** Shared audit group ID for all actions within the session */
|
|
570
|
+
auditGroupId: string;
|
|
571
|
+
createdAt: Date;
|
|
572
|
+
}
|
|
573
|
+
interface EphemeralSessionValidateResult {
|
|
574
|
+
sessionId: string;
|
|
575
|
+
agentId: string;
|
|
576
|
+
remainingActions: number | null;
|
|
577
|
+
/** Seconds until the token expires */
|
|
578
|
+
expiresIn: number;
|
|
579
|
+
auditGroupId: string;
|
|
580
|
+
}
|
|
581
|
+
interface EphemeralSessionModule {
|
|
582
|
+
createSession(input: CreateEphemeralSessionInput): Promise<Result<EphemeralSession>>;
|
|
583
|
+
validateSession(token: string): Promise<Result<EphemeralSessionValidateResult>>;
|
|
584
|
+
consumeAction(token: string): Promise<Result<{
|
|
585
|
+
actionsRemaining: number | null;
|
|
586
|
+
}>>;
|
|
587
|
+
revokeSession(sessionId: string): Promise<Result<void>>;
|
|
588
|
+
listActiveSessions(ownerId: string): Promise<Result<EphemeralSession[]>>;
|
|
589
|
+
cleanupExpired(): Promise<Result<{
|
|
590
|
+
count: number;
|
|
591
|
+
}>>;
|
|
592
|
+
}
|
|
593
|
+
declare function createEphemeralSessionModule(config: EphemeralSessionConfig): EphemeralSessionModule;
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Real-time event streaming via Server-Sent Events (SSE) for KavachOS.
|
|
597
|
+
*
|
|
598
|
+
* Provides a persistent connection feed of audit events, agent lifecycle
|
|
599
|
+
* changes, auth events, and anomalies. SOC teams and monitoring systems can
|
|
600
|
+
* subscribe instead of polling the audit API or relying solely on webhooks.
|
|
601
|
+
*
|
|
602
|
+
* Endpoint: GET /api/kavach/events/stream
|
|
603
|
+
* Auth: Bearer token via Authorization header or `?token=` query param
|
|
604
|
+
* Filtering: `?types=audit,agent.created`
|
|
605
|
+
* Replay: `?since=2026-01-01T00:00:00Z` or Last-Event-ID header
|
|
606
|
+
*
|
|
607
|
+
* @example
|
|
608
|
+
* ```typescript
|
|
609
|
+
* const stream = createEventStreamModule({ db, requireAuth: true });
|
|
610
|
+
*
|
|
611
|
+
* // In your request handler
|
|
612
|
+
* const response = stream.handleRequest(request);
|
|
613
|
+
* if (response) return response;
|
|
614
|
+
*
|
|
615
|
+
* // Emit from anywhere in your app
|
|
616
|
+
* stream.emit({
|
|
617
|
+
* id: crypto.generateId(),
|
|
618
|
+
* type: 'agent.created',
|
|
619
|
+
* timestamp: new Date(),
|
|
620
|
+
* data: { agentId: 'ag_123', name: 'my-agent' },
|
|
621
|
+
* });
|
|
622
|
+
* ```
|
|
623
|
+
*/
|
|
624
|
+
|
|
625
|
+
declare const EVENT_TYPES: readonly ["audit", "agent.created", "agent.revoked", "agent.rotated", "auth.signin", "auth.signout", "auth.failed", "delegation.created", "delegation.revoked", "budget.exceeded", "anomaly.detected", "cost.recorded"];
|
|
626
|
+
type EventType = (typeof EVENT_TYPES)[number];
|
|
627
|
+
interface StreamEvent {
|
|
628
|
+
id: string;
|
|
629
|
+
type: EventType;
|
|
630
|
+
timestamp: Date;
|
|
631
|
+
data: Record<string, unknown>;
|
|
632
|
+
agentId?: string;
|
|
633
|
+
userId?: string;
|
|
634
|
+
}
|
|
635
|
+
interface EventStreamConfig {
|
|
636
|
+
db: Database;
|
|
637
|
+
/** Maximum concurrent SSE connections (default: 100) */
|
|
638
|
+
maxConnections?: number;
|
|
639
|
+
/** Heartbeat interval in milliseconds (default: 30000) */
|
|
640
|
+
heartbeatIntervalMs?: number;
|
|
641
|
+
/** Restrict which event types this stream delivers (default: all) */
|
|
642
|
+
eventTypes?: EventType[];
|
|
643
|
+
/** Require a valid Bearer token to connect (default: true) */
|
|
644
|
+
requireAuth?: boolean;
|
|
645
|
+
/**
|
|
646
|
+
* Validate a Bearer token and return the subscriber ID (userId or agentId)
|
|
647
|
+
* on success, or null on failure.
|
|
648
|
+
*
|
|
649
|
+
* Only called when `requireAuth` is true. When omitted, any non-empty token
|
|
650
|
+
* is accepted and used as the subscriber ID.
|
|
651
|
+
*/
|
|
652
|
+
validateToken?: (token: string) => Promise<string | null>;
|
|
653
|
+
}
|
|
654
|
+
interface EventStreamModule {
|
|
655
|
+
/** Emit an event to all connected clients. */
|
|
656
|
+
emit(event: StreamEvent): void;
|
|
657
|
+
/** Handle an incoming HTTP request. Returns a Response or null when the request is not an SSE request. */
|
|
658
|
+
handleRequest(request: Request): Response | null;
|
|
659
|
+
/** Current number of active SSE connections. */
|
|
660
|
+
getConnectionCount(): number;
|
|
661
|
+
/** Replay persisted events since a timestamp, optionally filtered by type. */
|
|
662
|
+
replay(since: Date, types?: EventType[]): Promise<Result<StreamEvent[]>>;
|
|
663
|
+
/** Close all active connections and stop heartbeats. */
|
|
664
|
+
close(): void;
|
|
665
|
+
}
|
|
666
|
+
declare function createEventStreamModule(config: EventStreamConfig): EventStreamModule;
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Agent identity federation for KavachOS.
|
|
670
|
+
*
|
|
671
|
+
* Allows an agent created in one KavachOS instance (Service A) to
|
|
672
|
+
* authenticate at another KavachOS instance (Service B) without
|
|
673
|
+
* re-registration. The agent's identity, trust score, permissions,
|
|
674
|
+
* and delegation scope travel with the federation token.
|
|
675
|
+
*
|
|
676
|
+
* Federation tokens are short-lived JWTs signed by the source instance.
|
|
677
|
+
* The target instance verifies them by fetching the source's public key
|
|
678
|
+
* from `/.well-known/kavach-federation.json`. Optionally, a Verifiable
|
|
679
|
+
* Credential can be embedded for offline verification.
|
|
680
|
+
*
|
|
681
|
+
* @example
|
|
682
|
+
* ```typescript
|
|
683
|
+
* import { createFederationModule } from 'kavachos/auth';
|
|
684
|
+
* import { generateKeyPair, exportJWK } from 'jose';
|
|
685
|
+
*
|
|
686
|
+
* const { publicKey, privateKey } = await generateKeyPair('EdDSA');
|
|
687
|
+
*
|
|
688
|
+
* const federation = createFederationModule({
|
|
689
|
+
* instanceId: 'instance-a',
|
|
690
|
+
* instanceUrl: 'https://a.example.com',
|
|
691
|
+
* signingKey: privateKey,
|
|
692
|
+
* });
|
|
693
|
+
*
|
|
694
|
+
* // Issue a token for an agent to carry to Service B
|
|
695
|
+
* const result = await federation.issueFederationToken('agent-123');
|
|
696
|
+
* ```
|
|
697
|
+
*/
|
|
698
|
+
|
|
699
|
+
declare const TrustLevelSchema: z.ZodEnum<["full", "limited", "verify-only"]>;
|
|
700
|
+
type TrustLevel = z.infer<typeof TrustLevelSchema>;
|
|
701
|
+
interface TrustedInstance {
|
|
702
|
+
instanceId: string;
|
|
703
|
+
instanceUrl: string;
|
|
704
|
+
publicKey?: JsonWebKey;
|
|
705
|
+
trustLevel?: TrustLevel;
|
|
706
|
+
}
|
|
707
|
+
interface FederationConfig {
|
|
708
|
+
/** Unique identifier for this KavachOS instance */
|
|
709
|
+
instanceId: string;
|
|
710
|
+
/** Public URL of this instance */
|
|
711
|
+
instanceUrl: string;
|
|
712
|
+
/** EdDSA private key for signing federation tokens */
|
|
713
|
+
signingKey: CryptoKey;
|
|
714
|
+
/** Pre-configured trusted instances */
|
|
715
|
+
trustedInstances?: TrustedInstance[];
|
|
716
|
+
/** Trust any KavachOS instance (dev mode only) */
|
|
717
|
+
autoTrust?: boolean;
|
|
718
|
+
/** Federation token lifetime in seconds. Default: 300 (5 minutes). */
|
|
719
|
+
tokenTtlSeconds?: number;
|
|
720
|
+
}
|
|
721
|
+
interface FederationToken {
|
|
722
|
+
/** Signed JWT */
|
|
723
|
+
token: string;
|
|
724
|
+
/** Token expiration */
|
|
725
|
+
expiresAt: Date;
|
|
726
|
+
/** Agent this token was issued for */
|
|
727
|
+
agentId: string;
|
|
728
|
+
/** Source instance ID */
|
|
729
|
+
sourceInstance: string;
|
|
730
|
+
}
|
|
731
|
+
interface FederatedAgent {
|
|
732
|
+
/** Agent ID from the source instance */
|
|
733
|
+
agentId: string;
|
|
734
|
+
/** Instance that issued this agent's identity */
|
|
735
|
+
sourceInstance: string;
|
|
736
|
+
/** Source instance URL */
|
|
737
|
+
sourceInstanceUrl: string;
|
|
738
|
+
/** Permissions carried by the token */
|
|
739
|
+
permissions: string[];
|
|
740
|
+
/** Trust level (0-1) from the source instance */
|
|
741
|
+
trustScore: number;
|
|
742
|
+
/** Delegation scope, if any */
|
|
743
|
+
delegationScope: string[];
|
|
744
|
+
/** When this token was verified */
|
|
745
|
+
verifiedAt: Date;
|
|
746
|
+
/** Embedded Verifiable Credential JWT, if present */
|
|
747
|
+
credential?: string;
|
|
748
|
+
}
|
|
749
|
+
interface InstanceIdentity {
|
|
750
|
+
/** This instance's ID */
|
|
751
|
+
instanceId: string;
|
|
752
|
+
/** This instance's URL */
|
|
753
|
+
instanceUrl: string;
|
|
754
|
+
/** Public key in JWK format for verifying federation tokens */
|
|
755
|
+
publicKeyJwk: JsonWebKey;
|
|
756
|
+
/** Protocol version */
|
|
757
|
+
protocolVersion: string;
|
|
758
|
+
/** Supported features */
|
|
759
|
+
features: string[];
|
|
760
|
+
}
|
|
761
|
+
interface IssueFederationTokenInput {
|
|
762
|
+
/** Agent ID to issue the token for */
|
|
763
|
+
agentId: string;
|
|
764
|
+
/** Optional target instance ID (audience restriction) */
|
|
765
|
+
targetInstance?: string;
|
|
766
|
+
/** Agent permissions to include in the token */
|
|
767
|
+
permissions?: string[];
|
|
768
|
+
/** Agent trust score (0-1) */
|
|
769
|
+
trustScore?: number;
|
|
770
|
+
/** Delegation scope */
|
|
771
|
+
delegationScope?: string[];
|
|
772
|
+
/** Optional VC JWT to embed */
|
|
773
|
+
credential?: string;
|
|
774
|
+
}
|
|
775
|
+
/** The well-known document served at /.well-known/kavach-federation.json */
|
|
776
|
+
interface FederationWellKnown {
|
|
777
|
+
instanceId: string;
|
|
778
|
+
instanceUrl: string;
|
|
779
|
+
publicKeyJwk: JsonWebKey;
|
|
780
|
+
protocolVersion: string;
|
|
781
|
+
features: string[];
|
|
782
|
+
}
|
|
783
|
+
interface FederationModule {
|
|
784
|
+
/** Issue a federation token for an agent to use at another service */
|
|
785
|
+
issueFederationToken(input: IssueFederationTokenInput): Promise<Result<FederationToken>>;
|
|
786
|
+
/** Verify a federation token from another KavachOS instance */
|
|
787
|
+
verifyFederationToken(token: string): Promise<Result<FederatedAgent>>;
|
|
788
|
+
/** Get this instance's identity (for the well-known endpoint) */
|
|
789
|
+
getInstanceIdentity(): Promise<InstanceIdentity>;
|
|
790
|
+
/** Add a trusted instance */
|
|
791
|
+
addTrustedInstance(instance: TrustedInstance): Result<void>;
|
|
792
|
+
/** Remove a trusted instance by ID */
|
|
793
|
+
removeTrustedInstance(instanceId: string): Result<void>;
|
|
794
|
+
/** List all trusted instances */
|
|
795
|
+
listTrustedInstances(): TrustedInstance[];
|
|
796
|
+
/** Discover another instance via its well-known URL */
|
|
797
|
+
discoverInstance(url: string, fetchFn?: typeof globalThis.fetch): Promise<Result<TrustedInstance>>;
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Create a federation module for cross-instance agent identity.
|
|
801
|
+
*
|
|
802
|
+
* The module signs short-lived JWTs that carry agent identity, permissions,
|
|
803
|
+
* and trust score. Remote instances verify these tokens using the source's
|
|
804
|
+
* public key, fetched from the well-known endpoint or pre-configured.
|
|
805
|
+
*/
|
|
806
|
+
declare function createFederationModule(config: FederationConfig): FederationModule;
|
|
807
|
+
|
|
426
808
|
/**
|
|
427
809
|
* GDPR module for KavachOS.
|
|
428
810
|
*
|
|
@@ -1219,93 +1601,6 @@ declare function createOneTapModule(config: OneTapConfig, db: Database, sessionM
|
|
|
1219
1601
|
|
|
1220
1602
|
declare function oneTap(config: OneTapConfig): KavachPlugin;
|
|
1221
1603
|
|
|
1222
|
-
/**
|
|
1223
|
-
* One-time token module for KavachOS.
|
|
1224
|
-
*
|
|
1225
|
-
* Issues single-use tokens for email verification, password resets,
|
|
1226
|
-
* invitations, and custom flows. The raw token is returned to the caller
|
|
1227
|
-
* once and never persisted — only a SHA-256 hash is stored. Tokens are
|
|
1228
|
-
* invalidated on first use or when they expire.
|
|
1229
|
-
*
|
|
1230
|
-
* @example
|
|
1231
|
-
* ```typescript
|
|
1232
|
-
* const tokens = createOneTimeTokenModule({}, db);
|
|
1233
|
-
*
|
|
1234
|
-
* // Create a password-reset token
|
|
1235
|
-
* const result = await tokens.createToken({
|
|
1236
|
-
* purpose: 'password-reset',
|
|
1237
|
-
* identifier: 'alice@example.com',
|
|
1238
|
-
* ttlSeconds: 1800,
|
|
1239
|
-
* });
|
|
1240
|
-
* if (result.success) {
|
|
1241
|
-
* await mailer.send({ to: 'alice@example.com', token: result.data.token });
|
|
1242
|
-
* }
|
|
1243
|
-
*
|
|
1244
|
-
* // Validate (and consume) on the reset page
|
|
1245
|
-
* const validation = await tokens.validateToken(incomingToken, 'password-reset');
|
|
1246
|
-
* if (validation.success) {
|
|
1247
|
-
* // validation.data.identifier === 'alice@example.com'
|
|
1248
|
-
* }
|
|
1249
|
-
* ```
|
|
1250
|
-
*/
|
|
1251
|
-
|
|
1252
|
-
/** Token purpose discriminator. Use 'custom' for any application-specific flow. */
|
|
1253
|
-
type OneTimeTokenPurpose = "email-verify" | "password-reset" | "invitation" | "custom";
|
|
1254
|
-
interface OneTimeTokenConfig {
|
|
1255
|
-
/** Default TTL in seconds when none is specified per-call. Default: 3600 (1 hour). */
|
|
1256
|
-
defaultTtlSeconds?: number;
|
|
1257
|
-
}
|
|
1258
|
-
interface CreateTokenInput {
|
|
1259
|
-
purpose: OneTimeTokenPurpose;
|
|
1260
|
-
/** Email address, user ID, or any caller-supplied key that scopes the token. */
|
|
1261
|
-
identifier: string;
|
|
1262
|
-
/** Arbitrary data to associate with the token (e.g. org ID, invited role). */
|
|
1263
|
-
metadata?: Record<string, unknown>;
|
|
1264
|
-
/** Override the module-level default TTL for this token only. */
|
|
1265
|
-
ttlSeconds?: number;
|
|
1266
|
-
}
|
|
1267
|
-
interface ValidateTokenResult {
|
|
1268
|
-
identifier: string;
|
|
1269
|
-
metadata?: Record<string, unknown>;
|
|
1270
|
-
}
|
|
1271
|
-
interface RevokeTokensResult {
|
|
1272
|
-
count: number;
|
|
1273
|
-
}
|
|
1274
|
-
interface OneTimeTokenModule {
|
|
1275
|
-
/**
|
|
1276
|
-
* Create a new one-time token.
|
|
1277
|
-
*
|
|
1278
|
-
* Returns the raw token (hex string) exactly once. Store it in your email
|
|
1279
|
-
* or link — it cannot be recovered from the database afterwards.
|
|
1280
|
-
*/
|
|
1281
|
-
createToken(input: CreateTokenInput): Promise<Result<{
|
|
1282
|
-
token: string;
|
|
1283
|
-
expiresAt: Date;
|
|
1284
|
-
}>>;
|
|
1285
|
-
/**
|
|
1286
|
-
* Validate a token and mark it as used.
|
|
1287
|
-
*
|
|
1288
|
-
* Fails when the token is unknown, already used, expired, or belongs to a
|
|
1289
|
-
* different purpose. On success the token is consumed immediately.
|
|
1290
|
-
*/
|
|
1291
|
-
validateToken(token: string, purpose: string): Promise<Result<ValidateTokenResult>>;
|
|
1292
|
-
/**
|
|
1293
|
-
* Revoke all active tokens for an identifier, optionally scoped to a purpose.
|
|
1294
|
-
*
|
|
1295
|
-
* Useful for invalidating outstanding password-reset links when a user
|
|
1296
|
-
* changes their password through another flow, or for cleaning up on account
|
|
1297
|
-
* deletion.
|
|
1298
|
-
*/
|
|
1299
|
-
revokeTokens(identifier: string, purpose?: string): Promise<Result<RevokeTokensResult>>;
|
|
1300
|
-
}
|
|
1301
|
-
/**
|
|
1302
|
-
* Create a one-time token module backed by the provided database.
|
|
1303
|
-
*
|
|
1304
|
-
* The module is stateless — no in-memory caches — so multiple instances
|
|
1305
|
-
* sharing the same database are safe.
|
|
1306
|
-
*/
|
|
1307
|
-
declare function createOneTimeTokenModule(config: OneTimeTokenConfig, db: Database): OneTimeTokenModule;
|
|
1308
|
-
|
|
1309
1604
|
/**
|
|
1310
1605
|
* OpenAPI 3.1 spec generation plugin for KavachOS.
|
|
1311
1606
|
*
|
|
@@ -1564,6 +1859,108 @@ interface RateLimitMiddlewareOptions {
|
|
|
1564
1859
|
}
|
|
1565
1860
|
declare function withRateLimit(handler: PluginEndpoint["handler"], limiter: RateLimiter, options?: RateLimitMiddlewareOptions): PluginEndpoint["handler"];
|
|
1566
1861
|
|
|
1862
|
+
/**
|
|
1863
|
+
* Relationship-Based Access Control (ReBAC) engine for KavachOS.
|
|
1864
|
+
*
|
|
1865
|
+
* Inspired by Google Zanzibar. Models authorization as a graph of typed
|
|
1866
|
+
* relationships between subjects (users, agents, teams) and objects
|
|
1867
|
+
* (orgs, workspaces, projects, documents). Permission checks traverse the
|
|
1868
|
+
* graph, following both direct relationships and parent-child inheritance.
|
|
1869
|
+
*
|
|
1870
|
+
* Key ideas:
|
|
1871
|
+
* - Resources live in a hierarchy (org > workspace > project > document).
|
|
1872
|
+
* - Relationships connect subjects to objects with a named relation.
|
|
1873
|
+
* - Permission rules define how relations compose. An "editor" implicitly
|
|
1874
|
+
* has "viewer" access; a "viewer" on a workspace inherits "viewer" on
|
|
1875
|
+
* child projects.
|
|
1876
|
+
* - Graph traversal is depth-limited to prevent runaway queries.
|
|
1877
|
+
*/
|
|
1878
|
+
|
|
1879
|
+
interface ReBACConfig {
|
|
1880
|
+
/** Maximum graph traversal depth for permission checks (default: 10). */
|
|
1881
|
+
maxDepth?: number;
|
|
1882
|
+
/** Permission rules per resource type. Key is the resource type. */
|
|
1883
|
+
permissionRules?: Record<string, PermissionRuleSet>;
|
|
1884
|
+
}
|
|
1885
|
+
/**
|
|
1886
|
+
* Defines how relations map to permissions for a given resource type.
|
|
1887
|
+
*
|
|
1888
|
+
* `implies` — relation X implies relation Y (e.g. editor implies viewer).
|
|
1889
|
+
* `inherits` — permission P on this resource's parent also grants P here.
|
|
1890
|
+
*/
|
|
1891
|
+
interface PermissionRuleSet {
|
|
1892
|
+
/** Which relations imply which other relations on the same object. */
|
|
1893
|
+
implies?: Record<string, string[]>;
|
|
1894
|
+
/** Permissions inherited from the parent resource. `true` = all, or list. */
|
|
1895
|
+
inheritFromParent?: boolean | string[];
|
|
1896
|
+
}
|
|
1897
|
+
interface ResourceNode {
|
|
1898
|
+
id: string;
|
|
1899
|
+
type: string;
|
|
1900
|
+
parentId?: string;
|
|
1901
|
+
parentType?: string;
|
|
1902
|
+
}
|
|
1903
|
+
interface Relationship {
|
|
1904
|
+
id: string;
|
|
1905
|
+
subjectType: string;
|
|
1906
|
+
subjectId: string;
|
|
1907
|
+
relation: string;
|
|
1908
|
+
objectType: string;
|
|
1909
|
+
objectId: string;
|
|
1910
|
+
createdAt: Date;
|
|
1911
|
+
}
|
|
1912
|
+
interface CheckParams {
|
|
1913
|
+
subjectType: string;
|
|
1914
|
+
subjectId: string;
|
|
1915
|
+
permission: string;
|
|
1916
|
+
objectType: string;
|
|
1917
|
+
objectId: string;
|
|
1918
|
+
}
|
|
1919
|
+
interface CheckResult {
|
|
1920
|
+
allowed: boolean;
|
|
1921
|
+
path?: string[];
|
|
1922
|
+
}
|
|
1923
|
+
interface ListObjectsParams {
|
|
1924
|
+
subjectType: string;
|
|
1925
|
+
subjectId: string;
|
|
1926
|
+
permission: string;
|
|
1927
|
+
objectType: string;
|
|
1928
|
+
}
|
|
1929
|
+
interface ListSubjectsParams {
|
|
1930
|
+
objectType: string;
|
|
1931
|
+
objectId: string;
|
|
1932
|
+
permission: string;
|
|
1933
|
+
subjectType: string;
|
|
1934
|
+
}
|
|
1935
|
+
interface ExpandParams {
|
|
1936
|
+
type: string;
|
|
1937
|
+
id: string;
|
|
1938
|
+
}
|
|
1939
|
+
interface ReBACModule {
|
|
1940
|
+
/** Register a resource in the hierarchy. */
|
|
1941
|
+
createResource(node: ResourceNode): Promise<Result<ResourceNode>>;
|
|
1942
|
+
/** Remove a resource and all its relationships. */
|
|
1943
|
+
deleteResource(type: string, id: string): Promise<Result<void>>;
|
|
1944
|
+
/** Get a resource by type and id. */
|
|
1945
|
+
getResource(type: string, id: string): Promise<Result<ResourceNode | null>>;
|
|
1946
|
+
/** Create a relationship between a subject and an object. */
|
|
1947
|
+
addRelationship(rel: Omit<Relationship, "id" | "createdAt">): Promise<Result<Relationship>>;
|
|
1948
|
+
/** Remove a specific relationship. */
|
|
1949
|
+
removeRelationship(subjectType: string, subjectId: string, relation: string, objectType: string, objectId: string): Promise<Result<void>>;
|
|
1950
|
+
/**
|
|
1951
|
+
* Check whether a subject has a permission on an object.
|
|
1952
|
+
* Returns the relationship path when access is granted.
|
|
1953
|
+
*/
|
|
1954
|
+
check(params: CheckParams): Promise<Result<CheckResult>>;
|
|
1955
|
+
/** List all object IDs of a given type that a subject can access with a permission. */
|
|
1956
|
+
listObjects(params: ListObjectsParams): Promise<Result<string[]>>;
|
|
1957
|
+
/** List all subject IDs of a given type that hold a permission on an object. */
|
|
1958
|
+
listSubjects(params: ListSubjectsParams): Promise<Result<string[]>>;
|
|
1959
|
+
/** Return all relationships where the given entity is subject or object. */
|
|
1960
|
+
expand(params: ExpandParams): Promise<Result<Relationship[]>>;
|
|
1961
|
+
}
|
|
1962
|
+
declare function createReBACModule(config: ReBACConfig, db: Database): ReBACModule;
|
|
1963
|
+
|
|
1567
1964
|
/**
|
|
1568
1965
|
* SCIM 2.0 directory sync for KavachOS.
|
|
1569
1966
|
*
|
|
@@ -1848,7 +2245,7 @@ interface TrustedDeviceModule {
|
|
|
1848
2245
|
* The same request will always produce the same fingerprint; changing
|
|
1849
2246
|
* user-agent or accept-language invalidates the fingerprint.
|
|
1850
2247
|
*/
|
|
1851
|
-
generateFingerprint(request: Request): string
|
|
2248
|
+
generateFingerprint(request: Request): Promise<string>;
|
|
1852
2249
|
}
|
|
1853
2250
|
declare function createTrustedDeviceModule(config: TrustedDeviceConfig, db: Database): TrustedDeviceModule;
|
|
1854
2251
|
/**
|
|
@@ -1857,4 +2254,4 @@ declare function createTrustedDeviceModule(config: TrustedDeviceConfig, db: Data
|
|
|
1857
2254
|
*/
|
|
1858
2255
|
declare function deviceLabelFromRequest(request: Request): string;
|
|
1859
2256
|
|
|
1860
|
-
export { type AccessTokenClaims, type AdditionalFieldsConfig, type AdditionalFieldsModule, AdminConfig, type AnonymousAuthConfig, type AnonymousAuthModule, ApiKeyManagerConfig, AuthAdapter, type AuthorizeParams, type BearerAuthOptions, type CheckoutOptions, type
|
|
2257
|
+
export { type AccessTokenClaims, type AdditionalFieldsConfig, type AdditionalFieldsModule, AdminConfig, type AnonymousAuthConfig, type AnonymousAuthModule, ApiKeyManagerConfig, AuthAdapter, type AuthorizeParams, type BearerAuthOptions, type BudgetCheckResult, type CheckParams, type CheckResult, type CheckoutOptions, type CostAlert, type CostAttributionConfig, type CostAttributionModule, type CostReport, type CreateEphemeralSessionInput, type CustomSessionConfig, type CustomSessionModule, type DeleteOptions, type DeleteResult, type DeviceAuthConfig, type DeviceAuthModule, type DeviceAuthStatus, type DeviceCodeResponse, EVENT_TYPES, EmailOtpConfig, type EndpointGroup, type EphemeralSession, type EphemeralSessionConfig, type EphemeralSessionModule, type EphemeralSessionValidateResult, type EventStreamConfig, type EventStreamModule, type EventType, type ExpandParams, type FederatedAgent, type FederationConfig, type FederationModule, type FederationToken, type FederationWellKnown, type FieldDefinition, type GdprModule, type GetUserClaimsFn, type GoogleUser, type HeaderAuthOptions, HibpApiError, HibpBreachedError, type HibpConfig, type HibpModule, type InstanceIdentity, type IssueFederationTokenInput, type JsonWebKeySet, type JwtSessionConfig, type JwtSessionModule, type LastLoginConfig, type LastLoginModule, type ListObjectsParams, type ListSubjectsParams, type LoginEvent, type LoginMethod, MagicLinkConfig, type OAuthProxyConfig, OAuthProxyError, type OAuthProxyModule, type OAuthProxyPluginConfig, type OidcClient, type OidcDiscoveryDocument, type OidcProviderConfig, type OidcProviderModule, type OneTapConfig, type OneTapModule, OneTapVerifyError, type OpenApiComponents, type OpenApiConfig, type OpenApiDocument, type OpenApiInfo, type OpenApiMediaType, type OpenApiModule, type OpenApiOperation, type OpenApiParameter, type OpenApiPathItem, type OpenApiRequestBody, type OpenApiResponse, type OpenApiSchema, type OpenApiSecurityRequirement, type OpenApiSecurityScheme, type OpenApiServer, OrgConfig, PasskeyConfig, type PermissionRuleSet, type PolarConfig, type PolarModule, type PolarSubscription, type ProxyTokens, type RateLimitConfig, type RateLimitMiddlewareOptions, type RateLimitResult, type RateLimiter, type ReBACConfig, type ReBACModule, type RecordCostInput, type RecordLoginInput, type RegisterClientInput, type Relationship, ResolvedUser, type ResourceNode, type ScimConfig, type ScimGroup, type ScimModule, type ScimUser, type SessionTokens, type SessionUser, type SiweConfig, type SiweModule, type SiweVerifyResult, type StreamEvent, type StripeConfig, type StripeModule, type SubscriptionInfo, type TokenParams, type TokenResponse, TotpConfig, type TrustLevel, type TrustedDevice, type TrustedDeviceConfig, type TrustedDeviceModule, type TrustedInstance, type TwoFactorConfig, type UserDataExport, type UserInfoClaims, type ValidationResult, type VerifiedSession, additionalFields, admin, anonymousAuth, apiKeys, bearerAuth, createAdditionalFieldsModule, createAnonymousAuthModule, createCostAttributionModule, createCustomSessionModule, createDeviceAuthModule, createEphemeralSessionModule, createEventStreamModule, createFederationModule, createGdprModule, createHibpModule, createJwtSessionModule, createLastLoginModule, createOAuthProxyModule, createOidcProviderModule, createOneTapModule, createOpenApiModule, createPolarModule, createRateLimiter, createReBACModule, createScimModule, createSiweModule, createStripeModule, createTrustedDeviceModule, customAuth, customSession, deviceAuth, deviceLabelFromRequest, emailOtp, gdpr, headerAuth, magicLink, oauthProxy, oneTap, organization, passkey, polar, scim, siwe, stripe, twoFactor, withRateLimit };
|
package/dist/auth/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { HibpApiError, HibpBreachedError, OAuthProxyError, OneTapVerifyError, SSO_ERROR, SsoError, additionalFields, admin, anonymousAuth, apiKeys, bearerAuth, createAdditionalFieldsModule, createAdminModule, createAnonymousAuthModule, createApiKeyManagerModule, createCaptchaModule, createCustomSessionModule, createDeviceAuthModule, createEmailOtpModule, createGdprModule, createHibpModule, createJwtSessionModule, createLastLoginModule, createMagicLinkModule, createOAuthProxyModule, createOidcProviderModule, createOneTapModule, createOneTimeTokenModule, createOpenApiModule, createOrgModule, createPasskeyModule, createPhoneAuthModule, createPolarModule, createRateLimiter, createScimModule, createSiweModule, createSsoModule, createStripeModule, createTotpModule, createTrustedDeviceModule, createUsernameAuthModule, createWebhookModule, customAuth, customSession, deviceAuth, deviceLabelFromRequest, emailOtp, gdpr, headerAuth, magicLink, oauthProxy, oneTap, organization, passkey, polar, scim, siwe, stripe, twoFactor, withRateLimit } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-
|
|
1
|
+
export { EVENT_TYPES, HibpApiError, HibpBreachedError, OAuthProxyError, OneTapVerifyError, SSO_ERROR, SsoError, additionalFields, admin, anonymousAuth, apiKeys, bearerAuth, createAdditionalFieldsModule, createAdminModule, createAnonymousAuthModule, createApiKeyManagerModule, createCaptchaModule, createCostAttributionModule, createCustomSessionModule, createDeviceAuthModule, createEmailOtpModule, createEmailVerificationModule, createEphemeralSessionModule, createEventStreamModule, createFederationModule, createGdprModule, createHibpModule, createJwtSessionModule, createLastLoginModule, createMagicLinkModule, createOAuthProxyModule, createOidcProviderModule, createOneTapModule, createOneTimeTokenModule, createOpenApiModule, createOrgModule, createPasskeyModule, createPasswordResetModule, createPhoneAuthModule, createPolarModule, createRateLimiter, createReBACModule, createScimModule, createSiweModule, createSsoModule, createStripeModule, createTotpModule, createTrustedDeviceModule, createUsernameAuthModule, createWebhookModule, customAuth, customSession, deviceAuth, deviceLabelFromRequest, emailOtp, gdpr, headerAuth, magicLink, oauthProxy, oneTap, organization, passkey, polar, scim, siwe, stripe, twoFactor, withRateLimit } from '../chunk-FKVAXCNJ.js';
|
|
2
|
+
import '../chunk-KDL6A76K.js';
|
|
3
|
+
import '../chunk-QCRHJMDX.js';
|
|
4
|
+
import '../chunk-NSBPE2FW.js';
|
|
4
5
|
//# sourceMappingURL=index.js.map
|
|
5
6
|
//# sourceMappingURL=index.js.map
|