kavachos 0.3.0 → 0.4.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/dist/a2a/index.d.ts +2 -2
- package/dist/agent/index.d.ts +3 -3
- package/dist/agent/index.js +4 -0
- package/dist/agent/index.js.map +1 -1
- package/dist/audit/index.d.ts +2 -2
- package/dist/audit/index.js +4 -0
- package/dist/audit/index.js.map +1 -1
- package/dist/auth/index.d.ts +34 -3
- package/dist/auth/index.js +91 -2
- package/dist/auth/index.js.map +1 -1
- package/dist/index.d.ts +33 -4
- package/dist/index.js +851 -67
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.js +38 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/permission/index.d.ts +8 -3
- package/dist/permission/index.js +68 -59
- package/dist/permission/index.js.map +1 -1
- package/dist/standards/index.d.ts +139 -0
- package/dist/standards/index.js +72 -0
- package/dist/standards/index.js.map +1 -0
- package/dist/{types-BuHrZcjE.d.ts → types-BiUe9e8u.d.ts} +24 -0
- package/dist/{types-B02D3kZy.d.ts → types-RJPOU4un.d.ts} +114 -2
- package/dist/vc/index.d.ts +254 -65
- package/dist/vc/index.js +160 -12
- package/dist/vc/index.js.map +1 -1
- package/package.json +7 -1
package/dist/vc/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as AuditEntry } from '../types-RJPOU4un.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
import { R as Result } from '../types-BiUe9e8u.js';
|
|
4
|
+
import 'drizzle-orm/sqlite-core';
|
|
5
|
+
import '../redirect/index.js';
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* W3C Verifiable Credentials Data Model 2.0 types for KavachOS.
|
|
@@ -84,35 +87,55 @@ declare const CredentialSubjectSchema: z.ZodObject<{
|
|
|
84
87
|
}>, "many">>;
|
|
85
88
|
name: z.ZodOptional<z.ZodString>;
|
|
86
89
|
type: z.ZodOptional<z.ZodString>;
|
|
87
|
-
}, "
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
91
|
+
id: z.ZodOptional<z.ZodString>;
|
|
92
|
+
agentId: z.ZodOptional<z.ZodString>;
|
|
93
|
+
permissions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
94
|
+
trustLevel: z.ZodOptional<z.ZodNumber>;
|
|
95
|
+
delegationScope: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
96
|
+
delegationChain: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
97
|
+
delegator: z.ZodString;
|
|
98
|
+
delegatee: z.ZodString;
|
|
99
|
+
permissions: z.ZodArray<z.ZodString, "many">;
|
|
100
|
+
createdAt: z.ZodString;
|
|
101
|
+
}, "strip", z.ZodTypeAny, {
|
|
96
102
|
createdAt: string;
|
|
97
103
|
permissions: string[];
|
|
98
104
|
delegator: string;
|
|
99
105
|
delegatee: string;
|
|
100
|
-
}
|
|
101
|
-
}, {
|
|
102
|
-
name?: string | undefined;
|
|
103
|
-
id?: string | undefined;
|
|
104
|
-
type?: string | undefined;
|
|
105
|
-
agentId?: string | undefined;
|
|
106
|
-
permissions?: string[] | undefined;
|
|
107
|
-
trustLevel?: number | undefined;
|
|
108
|
-
delegationScope?: string[] | undefined;
|
|
109
|
-
delegationChain?: {
|
|
106
|
+
}, {
|
|
110
107
|
createdAt: string;
|
|
111
108
|
permissions: string[];
|
|
112
109
|
delegator: string;
|
|
113
110
|
delegatee: string;
|
|
114
|
-
}
|
|
115
|
-
|
|
111
|
+
}>, "many">>;
|
|
112
|
+
name: z.ZodOptional<z.ZodString>;
|
|
113
|
+
type: z.ZodOptional<z.ZodString>;
|
|
114
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
115
|
+
id: z.ZodOptional<z.ZodString>;
|
|
116
|
+
agentId: z.ZodOptional<z.ZodString>;
|
|
117
|
+
permissions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
118
|
+
trustLevel: z.ZodOptional<z.ZodNumber>;
|
|
119
|
+
delegationScope: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
120
|
+
delegationChain: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
121
|
+
delegator: z.ZodString;
|
|
122
|
+
delegatee: z.ZodString;
|
|
123
|
+
permissions: z.ZodArray<z.ZodString, "many">;
|
|
124
|
+
createdAt: z.ZodString;
|
|
125
|
+
}, "strip", z.ZodTypeAny, {
|
|
126
|
+
createdAt: string;
|
|
127
|
+
permissions: string[];
|
|
128
|
+
delegator: string;
|
|
129
|
+
delegatee: string;
|
|
130
|
+
}, {
|
|
131
|
+
createdAt: string;
|
|
132
|
+
permissions: string[];
|
|
133
|
+
delegator: string;
|
|
134
|
+
delegatee: string;
|
|
135
|
+
}>, "many">>;
|
|
136
|
+
name: z.ZodOptional<z.ZodString>;
|
|
137
|
+
type: z.ZodOptional<z.ZodString>;
|
|
138
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
116
139
|
type CredentialSubject = z.infer<typeof CredentialSubjectSchema>;
|
|
117
140
|
declare const VerifiableCredentialSchema: z.ZodObject<{
|
|
118
141
|
"@context": z.ZodArray<z.ZodString, "many">;
|
|
@@ -154,35 +177,55 @@ declare const VerifiableCredentialSchema: z.ZodObject<{
|
|
|
154
177
|
}>, "many">>;
|
|
155
178
|
name: z.ZodOptional<z.ZodString>;
|
|
156
179
|
type: z.ZodOptional<z.ZodString>;
|
|
157
|
-
}, "
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
180
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
181
|
+
id: z.ZodOptional<z.ZodString>;
|
|
182
|
+
agentId: z.ZodOptional<z.ZodString>;
|
|
183
|
+
permissions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
184
|
+
trustLevel: z.ZodOptional<z.ZodNumber>;
|
|
185
|
+
delegationScope: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
186
|
+
delegationChain: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
187
|
+
delegator: z.ZodString;
|
|
188
|
+
delegatee: z.ZodString;
|
|
189
|
+
permissions: z.ZodArray<z.ZodString, "many">;
|
|
190
|
+
createdAt: z.ZodString;
|
|
191
|
+
}, "strip", z.ZodTypeAny, {
|
|
166
192
|
createdAt: string;
|
|
167
193
|
permissions: string[];
|
|
168
194
|
delegator: string;
|
|
169
195
|
delegatee: string;
|
|
170
|
-
}
|
|
171
|
-
}, {
|
|
172
|
-
name?: string | undefined;
|
|
173
|
-
id?: string | undefined;
|
|
174
|
-
type?: string | undefined;
|
|
175
|
-
agentId?: string | undefined;
|
|
176
|
-
permissions?: string[] | undefined;
|
|
177
|
-
trustLevel?: number | undefined;
|
|
178
|
-
delegationScope?: string[] | undefined;
|
|
179
|
-
delegationChain?: {
|
|
196
|
+
}, {
|
|
180
197
|
createdAt: string;
|
|
181
198
|
permissions: string[];
|
|
182
199
|
delegator: string;
|
|
183
200
|
delegatee: string;
|
|
184
|
-
}
|
|
185
|
-
|
|
201
|
+
}>, "many">>;
|
|
202
|
+
name: z.ZodOptional<z.ZodString>;
|
|
203
|
+
type: z.ZodOptional<z.ZodString>;
|
|
204
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
205
|
+
id: z.ZodOptional<z.ZodString>;
|
|
206
|
+
agentId: z.ZodOptional<z.ZodString>;
|
|
207
|
+
permissions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
208
|
+
trustLevel: z.ZodOptional<z.ZodNumber>;
|
|
209
|
+
delegationScope: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
210
|
+
delegationChain: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
211
|
+
delegator: z.ZodString;
|
|
212
|
+
delegatee: z.ZodString;
|
|
213
|
+
permissions: z.ZodArray<z.ZodString, "many">;
|
|
214
|
+
createdAt: z.ZodString;
|
|
215
|
+
}, "strip", z.ZodTypeAny, {
|
|
216
|
+
createdAt: string;
|
|
217
|
+
permissions: string[];
|
|
218
|
+
delegator: string;
|
|
219
|
+
delegatee: string;
|
|
220
|
+
}, {
|
|
221
|
+
createdAt: string;
|
|
222
|
+
permissions: string[];
|
|
223
|
+
delegator: string;
|
|
224
|
+
delegatee: string;
|
|
225
|
+
}>, "many">>;
|
|
226
|
+
name: z.ZodOptional<z.ZodString>;
|
|
227
|
+
type: z.ZodOptional<z.ZodString>;
|
|
228
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
186
229
|
credentialStatus: z.ZodOptional<z.ZodObject<{
|
|
187
230
|
id: z.ZodString;
|
|
188
231
|
type: z.ZodString;
|
|
@@ -246,6 +289,8 @@ declare const VerifiableCredentialSchema: z.ZodObject<{
|
|
|
246
289
|
delegator: string;
|
|
247
290
|
delegatee: string;
|
|
248
291
|
}[] | undefined;
|
|
292
|
+
} & {
|
|
293
|
+
[k: string]: unknown;
|
|
249
294
|
};
|
|
250
295
|
id?: string | undefined;
|
|
251
296
|
expirationDate?: string | undefined;
|
|
@@ -286,6 +331,8 @@ declare const VerifiableCredentialSchema: z.ZodObject<{
|
|
|
286
331
|
delegator: string;
|
|
287
332
|
delegatee: string;
|
|
288
333
|
}[] | undefined;
|
|
334
|
+
} & {
|
|
335
|
+
[k: string]: unknown;
|
|
289
336
|
};
|
|
290
337
|
id?: string | undefined;
|
|
291
338
|
expirationDate?: string | undefined;
|
|
@@ -351,35 +398,55 @@ declare const VerifiablePresentationSchema: z.ZodObject<{
|
|
|
351
398
|
}>, "many">>;
|
|
352
399
|
name: z.ZodOptional<z.ZodString>;
|
|
353
400
|
type: z.ZodOptional<z.ZodString>;
|
|
354
|
-
}, "
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
401
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
402
|
+
id: z.ZodOptional<z.ZodString>;
|
|
403
|
+
agentId: z.ZodOptional<z.ZodString>;
|
|
404
|
+
permissions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
405
|
+
trustLevel: z.ZodOptional<z.ZodNumber>;
|
|
406
|
+
delegationScope: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
407
|
+
delegationChain: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
408
|
+
delegator: z.ZodString;
|
|
409
|
+
delegatee: z.ZodString;
|
|
410
|
+
permissions: z.ZodArray<z.ZodString, "many">;
|
|
411
|
+
createdAt: z.ZodString;
|
|
412
|
+
}, "strip", z.ZodTypeAny, {
|
|
363
413
|
createdAt: string;
|
|
364
414
|
permissions: string[];
|
|
365
415
|
delegator: string;
|
|
366
416
|
delegatee: string;
|
|
367
|
-
}
|
|
368
|
-
}, {
|
|
369
|
-
name?: string | undefined;
|
|
370
|
-
id?: string | undefined;
|
|
371
|
-
type?: string | undefined;
|
|
372
|
-
agentId?: string | undefined;
|
|
373
|
-
permissions?: string[] | undefined;
|
|
374
|
-
trustLevel?: number | undefined;
|
|
375
|
-
delegationScope?: string[] | undefined;
|
|
376
|
-
delegationChain?: {
|
|
417
|
+
}, {
|
|
377
418
|
createdAt: string;
|
|
378
419
|
permissions: string[];
|
|
379
420
|
delegator: string;
|
|
380
421
|
delegatee: string;
|
|
381
|
-
}
|
|
382
|
-
|
|
422
|
+
}>, "many">>;
|
|
423
|
+
name: z.ZodOptional<z.ZodString>;
|
|
424
|
+
type: z.ZodOptional<z.ZodString>;
|
|
425
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
426
|
+
id: z.ZodOptional<z.ZodString>;
|
|
427
|
+
agentId: z.ZodOptional<z.ZodString>;
|
|
428
|
+
permissions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
429
|
+
trustLevel: z.ZodOptional<z.ZodNumber>;
|
|
430
|
+
delegationScope: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
431
|
+
delegationChain: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
432
|
+
delegator: z.ZodString;
|
|
433
|
+
delegatee: z.ZodString;
|
|
434
|
+
permissions: z.ZodArray<z.ZodString, "many">;
|
|
435
|
+
createdAt: z.ZodString;
|
|
436
|
+
}, "strip", z.ZodTypeAny, {
|
|
437
|
+
createdAt: string;
|
|
438
|
+
permissions: string[];
|
|
439
|
+
delegator: string;
|
|
440
|
+
delegatee: string;
|
|
441
|
+
}, {
|
|
442
|
+
createdAt: string;
|
|
443
|
+
permissions: string[];
|
|
444
|
+
delegator: string;
|
|
445
|
+
delegatee: string;
|
|
446
|
+
}>, "many">>;
|
|
447
|
+
name: z.ZodOptional<z.ZodString>;
|
|
448
|
+
type: z.ZodOptional<z.ZodString>;
|
|
449
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
383
450
|
credentialStatus: z.ZodOptional<z.ZodObject<{
|
|
384
451
|
id: z.ZodString;
|
|
385
452
|
type: z.ZodString;
|
|
@@ -443,6 +510,8 @@ declare const VerifiablePresentationSchema: z.ZodObject<{
|
|
|
443
510
|
delegator: string;
|
|
444
511
|
delegatee: string;
|
|
445
512
|
}[] | undefined;
|
|
513
|
+
} & {
|
|
514
|
+
[k: string]: unknown;
|
|
446
515
|
};
|
|
447
516
|
id?: string | undefined;
|
|
448
517
|
expirationDate?: string | undefined;
|
|
@@ -483,6 +552,8 @@ declare const VerifiablePresentationSchema: z.ZodObject<{
|
|
|
483
552
|
delegator: string;
|
|
484
553
|
delegatee: string;
|
|
485
554
|
}[] | undefined;
|
|
555
|
+
} & {
|
|
556
|
+
[k: string]: unknown;
|
|
486
557
|
};
|
|
487
558
|
id?: string | undefined;
|
|
488
559
|
expirationDate?: string | undefined;
|
|
@@ -549,6 +620,8 @@ declare const VerifiablePresentationSchema: z.ZodObject<{
|
|
|
549
620
|
delegator: string;
|
|
550
621
|
delegatee: string;
|
|
551
622
|
}[] | undefined;
|
|
623
|
+
} & {
|
|
624
|
+
[k: string]: unknown;
|
|
552
625
|
};
|
|
553
626
|
id?: string | undefined;
|
|
554
627
|
expirationDate?: string | undefined;
|
|
@@ -603,6 +676,8 @@ declare const VerifiablePresentationSchema: z.ZodObject<{
|
|
|
603
676
|
delegator: string;
|
|
604
677
|
delegatee: string;
|
|
605
678
|
}[] | undefined;
|
|
679
|
+
} & {
|
|
680
|
+
[k: string]: unknown;
|
|
606
681
|
};
|
|
607
682
|
id?: string | undefined;
|
|
608
683
|
expirationDate?: string | undefined;
|
|
@@ -691,6 +766,120 @@ interface ExtractedPermissions {
|
|
|
691
766
|
delegationScope: string[];
|
|
692
767
|
}
|
|
693
768
|
|
|
769
|
+
/**
|
|
770
|
+
* Export audit records as W3C Verifiable Credentials.
|
|
771
|
+
*
|
|
772
|
+
* Takes a time range of audit log entries and returns either individual
|
|
773
|
+
* credentials per record or a single Verifiable Presentation wrapping
|
|
774
|
+
* all of them. Useful for compliance exports that must be
|
|
775
|
+
* cryptographically verifiable (EU AI Act Article 12, SOC 2 CC7).
|
|
776
|
+
*
|
|
777
|
+
* Context URL: https://kavachos.com/contexts/audit/v1.jsonld
|
|
778
|
+
* This context is defined locally — the URL does not need to resolve at
|
|
779
|
+
* runtime. It serves as a stable identifier for the credential schema.
|
|
780
|
+
*/
|
|
781
|
+
|
|
782
|
+
declare const KAVACHOS_AUDIT_CREDENTIAL = "KavachosAuditCredential";
|
|
783
|
+
/**
|
|
784
|
+
* Context URL for KavachosAuditCredential.
|
|
785
|
+
* Defined locally — the URL does not need to resolve at runtime.
|
|
786
|
+
*/
|
|
787
|
+
declare const KAVACHOS_AUDIT_CONTEXT = "https://kavachos.com/contexts/audit/v1.jsonld";
|
|
788
|
+
/** AuditRecord is an alias for AuditEntry used in the VC export surface. */
|
|
789
|
+
type AuditRecord = AuditEntry;
|
|
790
|
+
/** Options passed to `exportAuditAsVC`. */
|
|
791
|
+
interface ExportAuditOptions {
|
|
792
|
+
/** Start of the time range (inclusive). */
|
|
793
|
+
since: Date;
|
|
794
|
+
/** End of the time range (inclusive). */
|
|
795
|
+
until: Date;
|
|
796
|
+
/**
|
|
797
|
+
* DID of the issuer signing the credentials.
|
|
798
|
+
* Must match the keypair in `issuerConfig`.
|
|
799
|
+
*/
|
|
800
|
+
issuerDid: string;
|
|
801
|
+
/** Private/public keypair config for signing. */
|
|
802
|
+
issuerConfig: VCIssuerConfig;
|
|
803
|
+
/** Output format. Default: `"ldp_vc"` (JSON-LD with embedded proof). */
|
|
804
|
+
format?: "ldp_vc" | "jwt_vc";
|
|
805
|
+
/** Output structure. Default: `"individual"` (one VC per record). */
|
|
806
|
+
output?: "individual" | "presentation";
|
|
807
|
+
/** Optional filter applied after the time range query. */
|
|
808
|
+
filter?: (record: AuditRecord) => boolean;
|
|
809
|
+
/** Records to export. Pass the results of `listAuditRecords` or `kavach.audit.query()`. */
|
|
810
|
+
records: AuditRecord[];
|
|
811
|
+
}
|
|
812
|
+
/** The result of `exportAuditAsVC`. */
|
|
813
|
+
interface AuditExportResult {
|
|
814
|
+
/**
|
|
815
|
+
* Individual credentials — one per audit record.
|
|
816
|
+
* When `output === "presentation"`, these are also embedded in `presentation`.
|
|
817
|
+
*/
|
|
818
|
+
credentials: VerifiableCredential[];
|
|
819
|
+
/**
|
|
820
|
+
* JWT strings when `format === "jwt_vc"`. Parallel to `credentials`.
|
|
821
|
+
* Pass these to `verifyCredential()` instead of the credential objects.
|
|
822
|
+
*/
|
|
823
|
+
jwts?: string[];
|
|
824
|
+
/** Present only when `output === "presentation"`. */
|
|
825
|
+
presentation?: VerifiablePresentation;
|
|
826
|
+
/** The format used. */
|
|
827
|
+
format: "ldp_vc" | "jwt_vc";
|
|
828
|
+
/** Timestamp of the export run. */
|
|
829
|
+
issuedAt: Date;
|
|
830
|
+
/** Number of credentials produced. */
|
|
831
|
+
count: number;
|
|
832
|
+
}
|
|
833
|
+
/** The credentialSubject for a KavachosAuditCredential. */
|
|
834
|
+
interface AuditCredentialSubject {
|
|
835
|
+
id: string;
|
|
836
|
+
agentId: string;
|
|
837
|
+
principalId?: string;
|
|
838
|
+
operation: string;
|
|
839
|
+
target: string;
|
|
840
|
+
decision: "allow" | "deny" | "approval_required";
|
|
841
|
+
policyName?: string;
|
|
842
|
+
timestamp: string;
|
|
843
|
+
traceId?: string;
|
|
844
|
+
kavachosVersion: string;
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* Export a set of audit records as Verifiable Credentials.
|
|
848
|
+
*
|
|
849
|
+
* Pass `records` from `kavach.audit.query()` or `listAuditRecords`.
|
|
850
|
+
* The function applies the optional `filter`, signs each record with
|
|
851
|
+
* the issuer keypair, and returns either individual VCs or a single
|
|
852
|
+
* Verifiable Presentation.
|
|
853
|
+
*
|
|
854
|
+
* ```ts
|
|
855
|
+
* const result = await exportAuditAsVC({
|
|
856
|
+
* since: new Date('2025-01-01'),
|
|
857
|
+
* until: new Date('2025-01-31'),
|
|
858
|
+
* issuerDid: keyPair.did,
|
|
859
|
+
* issuerConfig: {
|
|
860
|
+
* issuerDid: keyPair.did,
|
|
861
|
+
* privateKeyJwk: keyPair.privateKeyJwk,
|
|
862
|
+
* publicKeyJwk: keyPair.publicKeyJwk,
|
|
863
|
+
* },
|
|
864
|
+
* records,
|
|
865
|
+
* });
|
|
866
|
+
* console.log(result.count); // 42
|
|
867
|
+
* ```
|
|
868
|
+
*/
|
|
869
|
+
declare function exportAuditAsVC(options: ExportAuditOptions): Promise<AuditExportResult>;
|
|
870
|
+
/**
|
|
871
|
+
* Filter audit records by time range with an optional predicate.
|
|
872
|
+
*
|
|
873
|
+
* Convenience helper for callers that already have records in memory
|
|
874
|
+
* and want to slice them before passing to `exportAuditAsVC`.
|
|
875
|
+
*
|
|
876
|
+
* ```ts
|
|
877
|
+
* const records = await kavach.audit.query({ since, until });
|
|
878
|
+
* const denyRecords = listAuditRecords(records, since, until, r => r.result === 'denied');
|
|
879
|
+
* ```
|
|
880
|
+
*/
|
|
881
|
+
declare function listAuditRecords(records: AuditRecord[], since: Date, until: Date, filter?: (record: AuditRecord) => boolean): AuditRecord[];
|
|
882
|
+
|
|
694
883
|
/**
|
|
695
884
|
* W3C Verifiable Credential issuance for KavachOS.
|
|
696
885
|
*
|
|
@@ -797,4 +986,4 @@ interface VCVerifier {
|
|
|
797
986
|
*/
|
|
798
987
|
declare function createVCVerifier(config?: VCVerifierConfig): VCVerifier;
|
|
799
988
|
|
|
800
|
-
export { type CredentialFormat, type CredentialStatus, CredentialStatusSchema, type CredentialSubject, CredentialSubjectSchema, type DelegationLink, type ExtractedPermissions, type IssueAgentCredentialInput, type IssueDelegationCredentialInput, type IssuePermissionCredentialInput, KAVACH_AGENT_CREDENTIAL, KAVACH_DELEGATION_CREDENTIAL, KAVACH_PERMISSION_CREDENTIAL, type Proof, ProofSchema, type VCIssuer, type VCIssuerConfig, type VCJwtPayload, type VCVerifier, type VCVerifierConfig, VC_CONTEXT_V1, VC_CONTEXT_V2, VC_TYPE_CREDENTIAL, VC_TYPE_PRESENTATION, type VerifiableCredential, VerifiableCredentialSchema, type VerifiablePresentation, VerifiablePresentationSchema, type VerifiedCredential, type VerifiedPresentation, createVCIssuer, createVCVerifier };
|
|
989
|
+
export { type AuditCredentialSubject, type AuditExportResult, type AuditRecord, type CredentialFormat, type CredentialStatus, CredentialStatusSchema, type CredentialSubject, CredentialSubjectSchema, type DelegationLink, type ExportAuditOptions, type ExtractedPermissions, type IssueAgentCredentialInput, type IssueDelegationCredentialInput, type IssuePermissionCredentialInput, KAVACHOS_AUDIT_CONTEXT, KAVACHOS_AUDIT_CREDENTIAL, KAVACH_AGENT_CREDENTIAL, KAVACH_DELEGATION_CREDENTIAL, KAVACH_PERMISSION_CREDENTIAL, type Proof, ProofSchema, type VCIssuer, type VCIssuerConfig, type VCJwtPayload, type VCVerifier, type VCVerifierConfig, VC_CONTEXT_V1, VC_CONTEXT_V2, VC_TYPE_CREDENTIAL, VC_TYPE_PRESENTATION, type VerifiableCredential, VerifiableCredentialSchema, type VerifiablePresentation, VerifiablePresentationSchema, type VerifiedCredential, type VerifiedPresentation, createVCIssuer, createVCVerifier, exportAuditAsVC, listAuditRecords };
|
package/dist/vc/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { importJWK, jwtVerify, errors, compactVerify
|
|
1
|
+
import { importJWK, jwtVerify, SignJWT, CompactSign, errors, compactVerify } from 'jose';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
|
-
// src/vc/
|
|
4
|
+
// src/vc/audit-export.ts
|
|
5
5
|
|
|
6
6
|
// src/crypto/web-crypto.ts
|
|
7
7
|
function generateId() {
|
|
@@ -46,7 +46,7 @@ var CredentialSubjectSchema = z.object({
|
|
|
46
46
|
).optional(),
|
|
47
47
|
name: z.string().optional(),
|
|
48
48
|
type: z.string().optional()
|
|
49
|
-
});
|
|
49
|
+
}).passthrough();
|
|
50
50
|
var VerifiableCredentialSchema = z.object({
|
|
51
51
|
"@context": z.array(z.string()).min(1),
|
|
52
52
|
id: z.string().optional(),
|
|
@@ -67,8 +67,156 @@ var VerifiablePresentationSchema = z.object({
|
|
|
67
67
|
proof: ProofSchema.optional()
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
// src/vc/
|
|
70
|
+
// src/vc/audit-export.ts
|
|
71
|
+
var KAVACHOS_AUDIT_CREDENTIAL = "KavachosAuditCredential";
|
|
72
|
+
var KAVACHOS_AUDIT_CONTEXT = "https://kavachos.com/contexts/audit/v1.jsonld";
|
|
73
|
+
var KAVACHOS_VERSION = "0.3.0";
|
|
71
74
|
var DEFAULT_TTL_SECONDS = 86400;
|
|
75
|
+
function toDecision(result) {
|
|
76
|
+
if (result === "allowed") return "allow";
|
|
77
|
+
return "deny";
|
|
78
|
+
}
|
|
79
|
+
function buildAuditCredential(record, issuerDid) {
|
|
80
|
+
const subject = {
|
|
81
|
+
id: record.id,
|
|
82
|
+
agentId: record.agentId,
|
|
83
|
+
...record.userId ? { principalId: record.userId } : {},
|
|
84
|
+
operation: record.action,
|
|
85
|
+
target: record.resource,
|
|
86
|
+
decision: toDecision(record.result),
|
|
87
|
+
...record.reason ? { policyName: record.reason } : {},
|
|
88
|
+
timestamp: record.timestamp.toISOString(),
|
|
89
|
+
kavachosVersion: KAVACHOS_VERSION
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
"@context": [VC_CONTEXT_V2, KAVACHOS_AUDIT_CONTEXT],
|
|
93
|
+
id: `urn:uuid:${generateId()}`,
|
|
94
|
+
type: [VC_TYPE_CREDENTIAL, KAVACHOS_AUDIT_CREDENTIAL],
|
|
95
|
+
issuer: issuerDid,
|
|
96
|
+
issuanceDate: (/* @__PURE__ */ new Date()).toISOString(),
|
|
97
|
+
expirationDate: new Date(Date.now() + DEFAULT_TTL_SECONDS * 1e3).toISOString(),
|
|
98
|
+
// Cast: AuditCredentialSubject is intentionally wider than CredentialSubject
|
|
99
|
+
// because the VC schema uses an open-ended subject. The additional fields
|
|
100
|
+
// (operation, target, decision, etc.) are preserved via spread at runtime.
|
|
101
|
+
credentialSubject: subject
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
async function signAsJsonLd(credential, config) {
|
|
105
|
+
const { issuerDid, privateKeyJwk } = config;
|
|
106
|
+
const kid = `${issuerDid}#${issuerDid.split(":").pop() ?? "key-1"}`;
|
|
107
|
+
const key = await importJWK(privateKeyJwk, "EdDSA");
|
|
108
|
+
const { proof: _proof, ...vcWithoutProof } = credential;
|
|
109
|
+
const payload = new TextEncoder().encode(JSON.stringify(vcWithoutProof));
|
|
110
|
+
const jws = await new CompactSign(payload).setProtectedHeader({ alg: "EdDSA", kid }).sign(key);
|
|
111
|
+
const proof = {
|
|
112
|
+
type: "JsonWebSignature2020",
|
|
113
|
+
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
114
|
+
verificationMethod: kid,
|
|
115
|
+
proofPurpose: "assertionMethod",
|
|
116
|
+
jws
|
|
117
|
+
};
|
|
118
|
+
return { ...credential, proof };
|
|
119
|
+
}
|
|
120
|
+
async function signAsJwt(credential, config) {
|
|
121
|
+
const { issuerDid, privateKeyJwk } = config;
|
|
122
|
+
const ttl = config.defaultTtl ?? DEFAULT_TTL_SECONDS;
|
|
123
|
+
const kid = `${issuerDid}#${issuerDid.split(":").pop() ?? "key-1"}`;
|
|
124
|
+
const key = await importJWK(privateKeyJwk, "EdDSA");
|
|
125
|
+
const { proof: _proof, ...vcWithoutProof } = credential;
|
|
126
|
+
const builder = new SignJWT({ vc: vcWithoutProof }).setProtectedHeader({ alg: "EdDSA", kid, typ: "JWT" }).setIssuer(issuerDid).setIssuedAt().setExpirationTime(Math.floor(Date.now() / 1e3) + ttl);
|
|
127
|
+
if (credential.id) builder.setJti(credential.id);
|
|
128
|
+
if (credential.credentialSubject.id) builder.setSubject(credential.credentialSubject.id);
|
|
129
|
+
const jwt = await builder.sign(key);
|
|
130
|
+
return { credential, jwt };
|
|
131
|
+
}
|
|
132
|
+
async function signPresentationAsJsonLd(presentation, config) {
|
|
133
|
+
const { issuerDid, privateKeyJwk } = config;
|
|
134
|
+
const kid = `${issuerDid}#${issuerDid.split(":").pop() ?? "key-1"}`;
|
|
135
|
+
const key = await importJWK(privateKeyJwk, "EdDSA");
|
|
136
|
+
const { proof: _proof, ...vpWithoutProof } = presentation;
|
|
137
|
+
const payload = new TextEncoder().encode(JSON.stringify(vpWithoutProof));
|
|
138
|
+
const jws = await new CompactSign(payload).setProtectedHeader({ alg: "EdDSA", kid }).sign(key);
|
|
139
|
+
const proof = {
|
|
140
|
+
type: "JsonWebSignature2020",
|
|
141
|
+
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
142
|
+
verificationMethod: kid,
|
|
143
|
+
proofPurpose: "assertionMethod",
|
|
144
|
+
jws
|
|
145
|
+
};
|
|
146
|
+
return { ...presentation, proof };
|
|
147
|
+
}
|
|
148
|
+
async function exportAuditAsVC(options) {
|
|
149
|
+
const {
|
|
150
|
+
since,
|
|
151
|
+
until,
|
|
152
|
+
issuerDid,
|
|
153
|
+
issuerConfig,
|
|
154
|
+
format = "ldp_vc",
|
|
155
|
+
output = "individual",
|
|
156
|
+
filter,
|
|
157
|
+
records
|
|
158
|
+
} = options;
|
|
159
|
+
const inRange = records.filter((r) => {
|
|
160
|
+
const t = r.timestamp.getTime();
|
|
161
|
+
return t >= since.getTime() && t <= until.getTime();
|
|
162
|
+
});
|
|
163
|
+
const filtered = filter ? inRange.filter(filter) : inRange;
|
|
164
|
+
if (filtered.length === 0) {
|
|
165
|
+
return {
|
|
166
|
+
credentials: [],
|
|
167
|
+
format,
|
|
168
|
+
issuedAt: /* @__PURE__ */ new Date(),
|
|
169
|
+
count: 0
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
const credentials = [];
|
|
173
|
+
const jwts = [];
|
|
174
|
+
for (const record of filtered) {
|
|
175
|
+
const base = buildAuditCredential(record, issuerDid);
|
|
176
|
+
if (format === "jwt_vc") {
|
|
177
|
+
const { credential, jwt } = await signAsJwt(base, issuerConfig);
|
|
178
|
+
credentials.push(credential);
|
|
179
|
+
jwts.push(jwt);
|
|
180
|
+
} else {
|
|
181
|
+
const signed = await signAsJsonLd(base, issuerConfig);
|
|
182
|
+
credentials.push(signed);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const issuedAt = /* @__PURE__ */ new Date();
|
|
186
|
+
if (output === "individual") {
|
|
187
|
+
return {
|
|
188
|
+
credentials,
|
|
189
|
+
...format === "jwt_vc" ? { jwts } : {},
|
|
190
|
+
format,
|
|
191
|
+
issuedAt,
|
|
192
|
+
count: credentials.length
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
const basePresentation = {
|
|
196
|
+
"@context": [VC_CONTEXT_V2, KAVACHOS_AUDIT_CONTEXT],
|
|
197
|
+
id: `urn:uuid:${generateId()}`,
|
|
198
|
+
type: [VC_TYPE_PRESENTATION],
|
|
199
|
+
holder: issuerDid,
|
|
200
|
+
verifiableCredential: credentials
|
|
201
|
+
};
|
|
202
|
+
const presentation = format === "jwt_vc" ? basePresentation : await signPresentationAsJsonLd(basePresentation, issuerConfig);
|
|
203
|
+
return {
|
|
204
|
+
credentials,
|
|
205
|
+
...format === "jwt_vc" ? { jwts } : {},
|
|
206
|
+
presentation,
|
|
207
|
+
format,
|
|
208
|
+
issuedAt,
|
|
209
|
+
count: credentials.length
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function listAuditRecords(records, since, until, filter) {
|
|
213
|
+
const inRange = records.filter((r) => {
|
|
214
|
+
const t = r.timestamp.getTime();
|
|
215
|
+
return t >= since.getTime() && t <= until.getTime();
|
|
216
|
+
});
|
|
217
|
+
return filter ? inRange.filter(filter) : inRange;
|
|
218
|
+
}
|
|
219
|
+
var DEFAULT_TTL_SECONDS2 = 86400;
|
|
72
220
|
function makeError(code, message, details) {
|
|
73
221
|
return { code, message, ...{} };
|
|
74
222
|
}
|
|
@@ -79,9 +227,9 @@ function futureISO(seconds) {
|
|
|
79
227
|
return new Date(Date.now() + seconds * 1e3).toISOString();
|
|
80
228
|
}
|
|
81
229
|
function createVCIssuer(config) {
|
|
82
|
-
const { issuerDid, privateKeyJwk, defaultTtl =
|
|
230
|
+
const { issuerDid, privateKeyJwk, defaultTtl = DEFAULT_TTL_SECONDS2 } = config;
|
|
83
231
|
const kid = `${issuerDid}#${issuerDid.split(":").pop() ?? "key-1"}`;
|
|
84
|
-
async function
|
|
232
|
+
async function signAsJwt2(credential, subject, ttl) {
|
|
85
233
|
try {
|
|
86
234
|
const key = await importJWK(privateKeyJwk, "EdDSA");
|
|
87
235
|
const { proof: _proof, ...vcWithoutProof } = credential;
|
|
@@ -106,13 +254,13 @@ function createVCIssuer(config) {
|
|
|
106
254
|
};
|
|
107
255
|
}
|
|
108
256
|
}
|
|
109
|
-
async function
|
|
257
|
+
async function signAsJsonLd2(credential) {
|
|
110
258
|
try {
|
|
111
259
|
const key = await importJWK(privateKeyJwk, "EdDSA");
|
|
112
260
|
const { proof: _proof, ...vcWithoutProof } = credential;
|
|
113
261
|
const payload = new TextEncoder().encode(JSON.stringify(vcWithoutProof));
|
|
114
|
-
const { CompactSign } = await import('jose');
|
|
115
|
-
const jws = await new
|
|
262
|
+
const { CompactSign: CompactSign2 } = await import('jose');
|
|
263
|
+
const jws = await new CompactSign2(payload).setProtectedHeader({ alg: "EdDSA", kid }).sign(key);
|
|
116
264
|
const proof = {
|
|
117
265
|
type: "JsonWebSignature2020",
|
|
118
266
|
created: nowISO(),
|
|
@@ -148,9 +296,9 @@ function createVCIssuer(config) {
|
|
|
148
296
|
}
|
|
149
297
|
async function signCredential(credential, subject, ttl, format) {
|
|
150
298
|
if (format === "jwt") {
|
|
151
|
-
return
|
|
299
|
+
return signAsJwt2(credential, subject, ttl);
|
|
152
300
|
}
|
|
153
|
-
return
|
|
301
|
+
return signAsJsonLd2(credential);
|
|
154
302
|
}
|
|
155
303
|
async function issueAgentCredential(input) {
|
|
156
304
|
const {
|
|
@@ -539,6 +687,6 @@ function createVCVerifier(config = {}) {
|
|
|
539
687
|
};
|
|
540
688
|
}
|
|
541
689
|
|
|
542
|
-
export { CredentialStatusSchema, CredentialSubjectSchema, KAVACH_AGENT_CREDENTIAL, KAVACH_DELEGATION_CREDENTIAL, KAVACH_PERMISSION_CREDENTIAL, ProofSchema, VC_CONTEXT_V1, VC_CONTEXT_V2, VC_TYPE_CREDENTIAL, VC_TYPE_PRESENTATION, VerifiableCredentialSchema, VerifiablePresentationSchema, createVCIssuer, createVCVerifier };
|
|
690
|
+
export { CredentialStatusSchema, CredentialSubjectSchema, KAVACHOS_AUDIT_CONTEXT, KAVACHOS_AUDIT_CREDENTIAL, KAVACH_AGENT_CREDENTIAL, KAVACH_DELEGATION_CREDENTIAL, KAVACH_PERMISSION_CREDENTIAL, ProofSchema, VC_CONTEXT_V1, VC_CONTEXT_V2, VC_TYPE_CREDENTIAL, VC_TYPE_PRESENTATION, VerifiableCredentialSchema, VerifiablePresentationSchema, createVCIssuer, createVCVerifier, exportAuditAsVC, listAuditRecords };
|
|
543
691
|
//# sourceMappingURL=index.js.map
|
|
544
692
|
//# sourceMappingURL=index.js.map
|