@kya-os/contracts 1.3.4 → 1.4.0
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/agentshield-api/endpoints.d.ts +50 -0
- package/dist/agentshield-api/endpoints.js +46 -0
- package/dist/agentshield-api/index.d.ts +13 -0
- package/dist/agentshield-api/index.js +38 -0
- package/dist/agentshield-api/schemas.d.ts +9914 -0
- package/dist/agentshield-api/schemas.js +165 -0
- package/dist/agentshield-api/types.d.ts +168 -0
- package/dist/agentshield-api/types.js +27 -0
- package/dist/cli.d.ts +388 -0
- package/dist/cli.js +121 -0
- package/dist/config/base.d.ts +96 -0
- package/dist/config/base.js +11 -0
- package/dist/config/delegation.d.ts +194 -0
- package/dist/config/delegation.js +10 -0
- package/dist/config/identity.d.ts +117 -0
- package/dist/config/identity.js +11 -0
- package/dist/config/index.d.ts +33 -0
- package/dist/config/index.js +11 -0
- package/dist/config/proofing.d.ts +120 -0
- package/dist/config/proofing.js +10 -0
- package/dist/config/tool-protection.d.ts +139 -0
- package/dist/config/tool-protection.js +10 -0
- package/dist/dashboard-config/index.d.ts +10 -0
- package/dist/dashboard-config/index.js +31 -0
- package/dist/dashboard-config/schemas.d.ts +5847 -0
- package/dist/dashboard-config/schemas.js +251 -0
- package/dist/dashboard-config/types.d.ts +331 -0
- package/dist/dashboard-config/types.js +11 -0
- package/dist/delegation/constraints.d.ts +991 -0
- package/dist/delegation/constraints.js +209 -0
- package/dist/delegation/index.d.ts +7 -0
- package/dist/delegation/index.js +23 -0
- package/dist/delegation/schemas.d.ts +8381 -0
- package/dist/delegation/schemas.js +475 -0
- package/dist/did/index.d.ts +8 -0
- package/dist/did/index.js +24 -0
- package/dist/did/resolve-contract.d.ts +219 -0
- package/dist/did/resolve-contract.js +31 -0
- package/dist/did/schemas.d.ts +112 -0
- package/dist/did/schemas.js +172 -0
- package/dist/did/types.d.ts +163 -0
- package/dist/did/types.js +70 -0
- package/dist/env/constants.d.ts +57 -0
- package/dist/env/constants.js +59 -0
- package/dist/env/index.d.ts +4 -0
- package/dist/env/index.js +20 -0
- package/dist/handshake.d.ts +158 -0
- package/dist/handshake.js +57 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +56 -0
- package/dist/proof/index.d.ts +8 -0
- package/dist/proof/index.js +24 -0
- package/dist/proof/proof-record.d.ts +837 -0
- package/dist/proof/proof-record.js +133 -0
- package/dist/proof/signing-spec.d.ts +146 -0
- package/dist/proof/signing-spec.js +122 -0
- package/dist/proof.d.ts +415 -0
- package/dist/proof.js +83 -0
- package/dist/registry.d.ts +342 -0
- package/dist/registry.js +118 -0
- package/dist/runtime/errors.d.ts +347 -0
- package/dist/runtime/errors.js +119 -0
- package/dist/runtime/headers.d.ts +83 -0
- package/dist/runtime/headers.js +81 -0
- package/dist/runtime/index.d.ts +5 -0
- package/dist/runtime/index.js +21 -0
- package/dist/test.d.ts +251 -0
- package/dist/test.js +119 -0
- package/dist/tlkrc/index.d.ts +4 -0
- package/dist/tlkrc/index.js +20 -0
- package/dist/tlkrc/rotation.d.ts +245 -0
- package/dist/tlkrc/rotation.js +126 -0
- package/dist/tool-protection/index.d.ts +227 -0
- package/dist/tool-protection/index.js +113 -0
- package/dist/utils/validation.d.ts +30 -0
- package/dist/utils/validation.js +69 -0
- package/dist/vc/index.d.ts +7 -0
- package/dist/vc/index.js +23 -0
- package/dist/vc/schemas.d.ts +2483 -0
- package/dist/vc/schemas.js +224 -0
- package/dist/vc/statuslist.d.ts +493 -0
- package/dist/vc/statuslist.js +132 -0
- package/dist/verifier.d.ts +205 -0
- package/dist/verifier.js +83 -0
- package/dist/well-known/index.d.ts +308 -0
- package/dist/well-known/index.js +134 -0
- package/package.json +6 -1
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DID Resolver Contract
|
|
3
|
+
*
|
|
4
|
+
* Interface contracts for DID resolution across different implementations.
|
|
5
|
+
* This file contains ONLY interfaces and types - no functional code.
|
|
6
|
+
*
|
|
7
|
+
* Related Spec: MCP-I §2.3
|
|
8
|
+
* Python Reference: DID-Service.md
|
|
9
|
+
*/
|
|
10
|
+
import type { DidDocument } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Options for DID resolution
|
|
13
|
+
*/
|
|
14
|
+
export interface ResolveOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Maximum time in milliseconds to wait for resolution
|
|
17
|
+
* Default: 500ms (as per env/constants.ts)
|
|
18
|
+
*/
|
|
19
|
+
timeoutMs?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Whether to accept cached resolution results
|
|
22
|
+
* If false, forces a fresh resolution
|
|
23
|
+
* Default: true
|
|
24
|
+
*/
|
|
25
|
+
acceptCache?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Desired cache TTL for this resolution in seconds
|
|
28
|
+
* Implementation may ignore if not applicable
|
|
29
|
+
*/
|
|
30
|
+
cacheTtlSec?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Additional metadata to pass to the resolver
|
|
33
|
+
* Used for method-specific resolution options
|
|
34
|
+
*/
|
|
35
|
+
metadata?: Record<string, any>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Result of DID resolution
|
|
39
|
+
*
|
|
40
|
+
* Contains the resolved DID Document and metadata about the resolution.
|
|
41
|
+
*/
|
|
42
|
+
export interface ResolveResult {
|
|
43
|
+
/**
|
|
44
|
+
* The resolved DID Document
|
|
45
|
+
*/
|
|
46
|
+
doc: DidDocument;
|
|
47
|
+
/**
|
|
48
|
+
* Timestamp (milliseconds since epoch) when the document was fetched
|
|
49
|
+
*/
|
|
50
|
+
fetchedAt: number;
|
|
51
|
+
/**
|
|
52
|
+
* Cache TTL in seconds (if applicable)
|
|
53
|
+
* Indicates how long this result may be cached
|
|
54
|
+
*/
|
|
55
|
+
cacheTtlSec?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Metadata about the resolution process
|
|
58
|
+
* May include method-specific information
|
|
59
|
+
*/
|
|
60
|
+
metadata?: {
|
|
61
|
+
/** Source of the resolution (e.g., "cache", "network", "local") */
|
|
62
|
+
source?: string;
|
|
63
|
+
/** Method used for resolution */
|
|
64
|
+
method?: string;
|
|
65
|
+
/** Whether the document was retrieved from cache */
|
|
66
|
+
fromCache?: boolean;
|
|
67
|
+
/** Additional method-specific metadata */
|
|
68
|
+
[key: string]: any;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Resolution Error Details
|
|
73
|
+
*
|
|
74
|
+
* Structure for errors during DID resolution.
|
|
75
|
+
*/
|
|
76
|
+
export interface ResolutionError {
|
|
77
|
+
/** Error code (e.g., "notFound", "invalidDid", "methodNotSupported") */
|
|
78
|
+
code: string;
|
|
79
|
+
/** Human-readable error message */
|
|
80
|
+
message: string;
|
|
81
|
+
/** Original error if available */
|
|
82
|
+
cause?: Error;
|
|
83
|
+
/** Additional error details */
|
|
84
|
+
details?: Record<string, any>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* DID Resolver Interface
|
|
88
|
+
*
|
|
89
|
+
* Defines the contract for resolving DIDs to DID Documents.
|
|
90
|
+
* Implementations must handle different DID methods and provide caching.
|
|
91
|
+
*
|
|
92
|
+
* **Implementation Notes:**
|
|
93
|
+
* - Resolvers SHOULD support caching to improve performance
|
|
94
|
+
* - Resolvers MUST respect timeoutMs to prevent hanging
|
|
95
|
+
* - Resolvers MUST validate DID format before attempting resolution
|
|
96
|
+
* - Resolvers MAY support multiple DID methods via a registry pattern
|
|
97
|
+
*
|
|
98
|
+
* **Edge Compatibility:**
|
|
99
|
+
* Implementations intended for edge environments should:
|
|
100
|
+
* - Minimize dependencies
|
|
101
|
+
* - Support offline resolution where possible (e.g., did:key)
|
|
102
|
+
* - Use efficient caching strategies
|
|
103
|
+
* - Handle network failures gracefully
|
|
104
|
+
*/
|
|
105
|
+
export interface DidResolver {
|
|
106
|
+
/**
|
|
107
|
+
* Resolve a DID to its DID Document
|
|
108
|
+
*
|
|
109
|
+
* @param did - The DID to resolve (e.g., "did:key:z6Mk...")
|
|
110
|
+
* @param opts - Resolution options
|
|
111
|
+
* @returns Promise resolving to the DID Document and metadata
|
|
112
|
+
* @throws {ResolutionError} If resolution fails
|
|
113
|
+
*/
|
|
114
|
+
resolve(did: string, opts?: ResolveOptions): Promise<ResolveResult>;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* DID Method Resolver Interface
|
|
118
|
+
*
|
|
119
|
+
* Interface for method-specific resolvers.
|
|
120
|
+
* A universal resolver delegates to method resolvers based on the DID method.
|
|
121
|
+
*/
|
|
122
|
+
export interface DidMethodResolver {
|
|
123
|
+
/**
|
|
124
|
+
* The DID method this resolver handles (e.g., "key", "web")
|
|
125
|
+
*/
|
|
126
|
+
readonly method: string;
|
|
127
|
+
/**
|
|
128
|
+
* Resolve a DID using this method
|
|
129
|
+
*
|
|
130
|
+
* @param did - The DID to resolve
|
|
131
|
+
* @param opts - Resolution options
|
|
132
|
+
* @returns Promise resolving to the DID Document and metadata
|
|
133
|
+
* @throws {ResolutionError} If resolution fails
|
|
134
|
+
*/
|
|
135
|
+
resolve(did: string, opts?: ResolveOptions): Promise<ResolveResult>;
|
|
136
|
+
/**
|
|
137
|
+
* Check if this resolver supports the given DID
|
|
138
|
+
*
|
|
139
|
+
* @param did - The DID to check
|
|
140
|
+
* @returns true if this resolver can handle the DID
|
|
141
|
+
*/
|
|
142
|
+
supports(did: string): boolean;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* DID Resolution Cache Interface
|
|
146
|
+
*
|
|
147
|
+
* Interface for caching resolved DID Documents.
|
|
148
|
+
*/
|
|
149
|
+
export interface DidResolutionCache {
|
|
150
|
+
/**
|
|
151
|
+
* Get a cached resolution result
|
|
152
|
+
*
|
|
153
|
+
* @param did - The DID to look up
|
|
154
|
+
* @returns Promise resolving to cached result or null if not found/expired
|
|
155
|
+
*/
|
|
156
|
+
get(did: string): Promise<ResolveResult | null>;
|
|
157
|
+
/**
|
|
158
|
+
* Store a resolution result in cache
|
|
159
|
+
*
|
|
160
|
+
* @param did - The DID being cached
|
|
161
|
+
* @param result - The resolution result
|
|
162
|
+
* @param ttlSec - TTL in seconds
|
|
163
|
+
* @returns Promise resolving when stored
|
|
164
|
+
*/
|
|
165
|
+
set(did: string, result: ResolveResult, ttlSec: number): Promise<void>;
|
|
166
|
+
/**
|
|
167
|
+
* Invalidate cached result for a DID
|
|
168
|
+
*
|
|
169
|
+
* @param did - The DID to invalidate
|
|
170
|
+
* @returns Promise resolving when invalidated
|
|
171
|
+
*/
|
|
172
|
+
invalidate(did: string): Promise<void>;
|
|
173
|
+
/**
|
|
174
|
+
* Clear all cached results
|
|
175
|
+
*
|
|
176
|
+
* @returns Promise resolving when cleared
|
|
177
|
+
*/
|
|
178
|
+
clear(): Promise<void>;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Universal DID Resolver Configuration
|
|
182
|
+
*
|
|
183
|
+
* Configuration for a universal resolver that delegates to method-specific resolvers.
|
|
184
|
+
*/
|
|
185
|
+
export interface UniversalResolverConfig {
|
|
186
|
+
/**
|
|
187
|
+
* Method-specific resolvers
|
|
188
|
+
* Key is the method name (e.g., "key", "web")
|
|
189
|
+
*/
|
|
190
|
+
methodResolvers?: Map<string, DidMethodResolver> | Record<string, DidMethodResolver>;
|
|
191
|
+
/**
|
|
192
|
+
* Optional cache implementation
|
|
193
|
+
*/
|
|
194
|
+
cache?: DidResolutionCache;
|
|
195
|
+
/**
|
|
196
|
+
* Default resolution options
|
|
197
|
+
*/
|
|
198
|
+
defaultOptions?: ResolveOptions;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Common resolution error codes
|
|
202
|
+
*/
|
|
203
|
+
export declare const RESOLUTION_ERROR_CODES: {
|
|
204
|
+
/** DID not found */
|
|
205
|
+
readonly NOT_FOUND: "notFound";
|
|
206
|
+
/** Invalid DID format */
|
|
207
|
+
readonly INVALID_DID: "invalidDid";
|
|
208
|
+
/** DID method not supported */
|
|
209
|
+
readonly METHOD_NOT_SUPPORTED: "methodNotSupported";
|
|
210
|
+
/** Resolution timeout */
|
|
211
|
+
readonly TIMEOUT: "timeout";
|
|
212
|
+
/** Network error during resolution */
|
|
213
|
+
readonly NETWORK_ERROR: "networkError";
|
|
214
|
+
/** Invalid DID Document structure */
|
|
215
|
+
readonly INVALID_DOCUMENT: "invalidDocument";
|
|
216
|
+
/** Internal resolver error */
|
|
217
|
+
readonly INTERNAL_ERROR: "internalError";
|
|
218
|
+
};
|
|
219
|
+
export type ResolutionErrorCode = (typeof RESOLUTION_ERROR_CODES)[keyof typeof RESOLUTION_ERROR_CODES];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* DID Resolver Contract
|
|
4
|
+
*
|
|
5
|
+
* Interface contracts for DID resolution across different implementations.
|
|
6
|
+
* This file contains ONLY interfaces and types - no functional code.
|
|
7
|
+
*
|
|
8
|
+
* Related Spec: MCP-I §2.3
|
|
9
|
+
* Python Reference: DID-Service.md
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RESOLUTION_ERROR_CODES = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* Common resolution error codes
|
|
15
|
+
*/
|
|
16
|
+
exports.RESOLUTION_ERROR_CODES = {
|
|
17
|
+
/** DID not found */
|
|
18
|
+
NOT_FOUND: 'notFound',
|
|
19
|
+
/** Invalid DID format */
|
|
20
|
+
INVALID_DID: 'invalidDid',
|
|
21
|
+
/** DID method not supported */
|
|
22
|
+
METHOD_NOT_SUPPORTED: 'methodNotSupported',
|
|
23
|
+
/** Resolution timeout */
|
|
24
|
+
TIMEOUT: 'timeout',
|
|
25
|
+
/** Network error during resolution */
|
|
26
|
+
NETWORK_ERROR: 'networkError',
|
|
27
|
+
/** Invalid DID Document structure */
|
|
28
|
+
INVALID_DOCUMENT: 'invalidDocument',
|
|
29
|
+
/** Internal resolver error */
|
|
30
|
+
INTERNAL_ERROR: 'internalError',
|
|
31
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DID Document Zod Schemas
|
|
3
|
+
*
|
|
4
|
+
* Runtime validation schemas for DID Documents conforming to W3C DID Core specification.
|
|
5
|
+
* These schemas complement the TypeScript types in types.ts with runtime validation.
|
|
6
|
+
*
|
|
7
|
+
* Related Spec: MCP-I §2.1, §2.3, W3C DID Core 1.0
|
|
8
|
+
*/
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
import type { DidDocument, VerificationMethod, DidService } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Standard W3C DID Core context
|
|
13
|
+
*/
|
|
14
|
+
export declare const DID_CONTEXT: "https://www.w3.org/ns/did/v1";
|
|
15
|
+
/**
|
|
16
|
+
* DID Context Entry Schema
|
|
17
|
+
*
|
|
18
|
+
* A context entry can be:
|
|
19
|
+
* - A URL string (most common)
|
|
20
|
+
* - A context definition object
|
|
21
|
+
*/
|
|
22
|
+
export declare const DidContextEntrySchema: z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>]>;
|
|
23
|
+
/**
|
|
24
|
+
* DID @context Schema
|
|
25
|
+
*
|
|
26
|
+
* The @context property in DID Documents can be:
|
|
27
|
+
* - A single string (typically the base DID context)
|
|
28
|
+
* - An array of strings/objects (base context + additional contexts)
|
|
29
|
+
* - A context definition object (for custom contexts)
|
|
30
|
+
*
|
|
31
|
+
* Per W3C DID Core spec, the base DID context should be present,
|
|
32
|
+
* but we allow flexibility for different DID methods and extensions.
|
|
33
|
+
*/
|
|
34
|
+
export declare const DidContextSchema: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>]>, "atleastone">, z.ZodRecord<z.ZodString, z.ZodAny>]>;
|
|
35
|
+
/**
|
|
36
|
+
* Verification Method Type Schema
|
|
37
|
+
*/
|
|
38
|
+
export declare const VerificationMethodTypeSchema: z.ZodEnum<["Ed25519VerificationKey2020", "JsonWebKey2020", "EcdsaSecp256k1VerificationKey2019"]>;
|
|
39
|
+
/**
|
|
40
|
+
* Public Key JWK Schema (RFC 7517)
|
|
41
|
+
*/
|
|
42
|
+
export declare const PublicKeyJwkSchema: z.ZodObject<{
|
|
43
|
+
/** Key Type */
|
|
44
|
+
kty: z.ZodString;
|
|
45
|
+
/** Curve (for elliptic curve keys) */
|
|
46
|
+
crv: z.ZodString;
|
|
47
|
+
/** X coordinate */
|
|
48
|
+
x: z.ZodString;
|
|
49
|
+
/** Y coordinate (optional for some key types) */
|
|
50
|
+
y: z.ZodOptional<z.ZodString>;
|
|
51
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
52
|
+
/** Key Type */
|
|
53
|
+
kty: z.ZodString;
|
|
54
|
+
/** Curve (for elliptic curve keys) */
|
|
55
|
+
crv: z.ZodString;
|
|
56
|
+
/** X coordinate */
|
|
57
|
+
x: z.ZodString;
|
|
58
|
+
/** Y coordinate (optional for some key types) */
|
|
59
|
+
y: z.ZodOptional<z.ZodString>;
|
|
60
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
61
|
+
/** Key Type */
|
|
62
|
+
kty: z.ZodString;
|
|
63
|
+
/** Curve (for elliptic curve keys) */
|
|
64
|
+
crv: z.ZodString;
|
|
65
|
+
/** X coordinate */
|
|
66
|
+
x: z.ZodString;
|
|
67
|
+
/** Y coordinate (optional for some key types) */
|
|
68
|
+
y: z.ZodOptional<z.ZodString>;
|
|
69
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
70
|
+
/**
|
|
71
|
+
* Verification Method Schema
|
|
72
|
+
*/
|
|
73
|
+
export declare const VerificationMethodSchema: z.ZodType<VerificationMethod>;
|
|
74
|
+
/**
|
|
75
|
+
* DID Service Schema
|
|
76
|
+
*/
|
|
77
|
+
export declare const DidServiceSchema: z.ZodType<DidService>;
|
|
78
|
+
/**
|
|
79
|
+
* Verification Relationship Entry Schema
|
|
80
|
+
*
|
|
81
|
+
* Can be either a string reference to a verification method
|
|
82
|
+
* or an embedded verification method object.
|
|
83
|
+
*/
|
|
84
|
+
export declare const VerificationRelationshipEntrySchema: z.ZodUnion<[z.ZodString, z.ZodType<VerificationMethod, z.ZodTypeDef, VerificationMethod>]>;
|
|
85
|
+
/**
|
|
86
|
+
* DID Document Schema
|
|
87
|
+
*
|
|
88
|
+
* Validates a DID Document structure per W3C DID Core specification.
|
|
89
|
+
*/
|
|
90
|
+
export declare const DidDocumentSchema: z.ZodType<DidDocument>;
|
|
91
|
+
/**
|
|
92
|
+
* DID Method Schema
|
|
93
|
+
*/
|
|
94
|
+
export declare const DidMethodSchema: z.ZodEnum<["key", "web", "jwk", "ion", "ebsi"]>;
|
|
95
|
+
/**
|
|
96
|
+
* Helper function to validate a DID Document
|
|
97
|
+
*
|
|
98
|
+
* @param doc - The document to validate
|
|
99
|
+
* @returns The validated document or throws ZodError
|
|
100
|
+
*/
|
|
101
|
+
export declare function validateDidDocument(doc: unknown): DidDocument;
|
|
102
|
+
/**
|
|
103
|
+
* Helper function to safely validate a DID Document
|
|
104
|
+
*
|
|
105
|
+
* @param doc - The document to validate
|
|
106
|
+
* @returns Result object with success status and data/error
|
|
107
|
+
*/
|
|
108
|
+
export declare function safeValidateDidDocument(doc: unknown): {
|
|
109
|
+
success: boolean;
|
|
110
|
+
data?: DidDocument;
|
|
111
|
+
error?: z.ZodError;
|
|
112
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* DID Document Zod Schemas
|
|
4
|
+
*
|
|
5
|
+
* Runtime validation schemas for DID Documents conforming to W3C DID Core specification.
|
|
6
|
+
* These schemas complement the TypeScript types in types.ts with runtime validation.
|
|
7
|
+
*
|
|
8
|
+
* Related Spec: MCP-I §2.1, §2.3, W3C DID Core 1.0
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.DidMethodSchema = exports.DidDocumentSchema = exports.VerificationRelationshipEntrySchema = exports.DidServiceSchema = exports.VerificationMethodSchema = exports.PublicKeyJwkSchema = exports.VerificationMethodTypeSchema = exports.DidContextSchema = exports.DidContextEntrySchema = exports.DID_CONTEXT = void 0;
|
|
12
|
+
exports.validateDidDocument = validateDidDocument;
|
|
13
|
+
exports.safeValidateDidDocument = safeValidateDidDocument;
|
|
14
|
+
const zod_1 = require("zod");
|
|
15
|
+
/**
|
|
16
|
+
* Standard W3C DID Core context
|
|
17
|
+
*/
|
|
18
|
+
exports.DID_CONTEXT = 'https://www.w3.org/ns/did/v1';
|
|
19
|
+
/**
|
|
20
|
+
* DID Context Entry Schema
|
|
21
|
+
*
|
|
22
|
+
* A context entry can be:
|
|
23
|
+
* - A URL string (most common)
|
|
24
|
+
* - A context definition object
|
|
25
|
+
*/
|
|
26
|
+
exports.DidContextEntrySchema = zod_1.z.union([
|
|
27
|
+
zod_1.z.string().url(),
|
|
28
|
+
zod_1.z.record(zod_1.z.any()),
|
|
29
|
+
]);
|
|
30
|
+
/**
|
|
31
|
+
* DID @context Schema
|
|
32
|
+
*
|
|
33
|
+
* The @context property in DID Documents can be:
|
|
34
|
+
* - A single string (typically the base DID context)
|
|
35
|
+
* - An array of strings/objects (base context + additional contexts)
|
|
36
|
+
* - A context definition object (for custom contexts)
|
|
37
|
+
*
|
|
38
|
+
* Per W3C DID Core spec, the base DID context should be present,
|
|
39
|
+
* but we allow flexibility for different DID methods and extensions.
|
|
40
|
+
*/
|
|
41
|
+
exports.DidContextSchema = zod_1.z.union([
|
|
42
|
+
// Single string context (e.g., "https://www.w3.org/ns/did/v1")
|
|
43
|
+
zod_1.z.string().url(),
|
|
44
|
+
// Array of contexts (strings or objects)
|
|
45
|
+
zod_1.z.array(exports.DidContextEntrySchema).nonempty(),
|
|
46
|
+
// Context definition object
|
|
47
|
+
zod_1.z.record(zod_1.z.any()),
|
|
48
|
+
]);
|
|
49
|
+
/**
|
|
50
|
+
* Verification Method Type Schema
|
|
51
|
+
*/
|
|
52
|
+
exports.VerificationMethodTypeSchema = zod_1.z.enum([
|
|
53
|
+
'Ed25519VerificationKey2020',
|
|
54
|
+
'JsonWebKey2020',
|
|
55
|
+
'EcdsaSecp256k1VerificationKey2019',
|
|
56
|
+
]);
|
|
57
|
+
/**
|
|
58
|
+
* Public Key JWK Schema (RFC 7517)
|
|
59
|
+
*/
|
|
60
|
+
exports.PublicKeyJwkSchema = zod_1.z
|
|
61
|
+
.object({
|
|
62
|
+
/** Key Type */
|
|
63
|
+
kty: zod_1.z.string(),
|
|
64
|
+
/** Curve (for elliptic curve keys) */
|
|
65
|
+
crv: zod_1.z.string(),
|
|
66
|
+
/** X coordinate */
|
|
67
|
+
x: zod_1.z.string(),
|
|
68
|
+
/** Y coordinate (optional for some key types) */
|
|
69
|
+
y: zod_1.z.string().optional(),
|
|
70
|
+
})
|
|
71
|
+
.passthrough(); // Allow additional JWK properties
|
|
72
|
+
/**
|
|
73
|
+
* Verification Method Schema
|
|
74
|
+
*/
|
|
75
|
+
exports.VerificationMethodSchema = zod_1.z.object({
|
|
76
|
+
/** Verification method identifier */
|
|
77
|
+
id: zod_1.z.string(),
|
|
78
|
+
/** Type of verification method */
|
|
79
|
+
type: exports.VerificationMethodTypeSchema,
|
|
80
|
+
/** Controller DID */
|
|
81
|
+
controller: zod_1.z.string(),
|
|
82
|
+
/** Multibase-encoded public key (for Ed25519VerificationKey2020) */
|
|
83
|
+
publicKeyMultibase: zod_1.z.string().optional(),
|
|
84
|
+
/** JSON Web Key (for JsonWebKey2020) */
|
|
85
|
+
publicKeyJwk: exports.PublicKeyJwkSchema.optional(),
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* DID Service Schema
|
|
89
|
+
*/
|
|
90
|
+
exports.DidServiceSchema = zod_1.z.object({
|
|
91
|
+
/** Service identifier */
|
|
92
|
+
id: zod_1.z.string(),
|
|
93
|
+
/** Service type(s) */
|
|
94
|
+
type: zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())]),
|
|
95
|
+
/** Service endpoint(s) */
|
|
96
|
+
serviceEndpoint: zod_1.z.union([
|
|
97
|
+
zod_1.z.string(),
|
|
98
|
+
zod_1.z.array(zod_1.z.string()),
|
|
99
|
+
zod_1.z.record(zod_1.z.any()),
|
|
100
|
+
]),
|
|
101
|
+
});
|
|
102
|
+
/**
|
|
103
|
+
* Verification Relationship Entry Schema
|
|
104
|
+
*
|
|
105
|
+
* Can be either a string reference to a verification method
|
|
106
|
+
* or an embedded verification method object.
|
|
107
|
+
*/
|
|
108
|
+
exports.VerificationRelationshipEntrySchema = zod_1.z.union([
|
|
109
|
+
zod_1.z.string(), // Reference to verification method
|
|
110
|
+
exports.VerificationMethodSchema, // Embedded verification method
|
|
111
|
+
]);
|
|
112
|
+
/**
|
|
113
|
+
* DID Document Schema
|
|
114
|
+
*
|
|
115
|
+
* Validates a DID Document structure per W3C DID Core specification.
|
|
116
|
+
*/
|
|
117
|
+
exports.DidDocumentSchema = zod_1.z
|
|
118
|
+
.object({
|
|
119
|
+
/** JSON-LD context */
|
|
120
|
+
'@context': exports.DidContextSchema.optional(),
|
|
121
|
+
/** The DID this document describes */
|
|
122
|
+
id: zod_1.z.string().refine((val) => val.startsWith('did:'), {
|
|
123
|
+
message: 'DID must start with "did:"',
|
|
124
|
+
}),
|
|
125
|
+
/** Alternative identifiers */
|
|
126
|
+
alsoKnownAs: zod_1.z.array(zod_1.z.string()).optional(),
|
|
127
|
+
/** Verification methods */
|
|
128
|
+
verificationMethod: zod_1.z.array(exports.VerificationMethodSchema).optional(),
|
|
129
|
+
/** Authentication verification relationship */
|
|
130
|
+
authentication: zod_1.z.array(exports.VerificationRelationshipEntrySchema).optional(),
|
|
131
|
+
/** Assertion method verification relationship */
|
|
132
|
+
assertionMethod: zod_1.z.array(exports.VerificationRelationshipEntrySchema).optional(),
|
|
133
|
+
/** Key agreement verification relationship */
|
|
134
|
+
keyAgreement: zod_1.z.array(exports.VerificationRelationshipEntrySchema).optional(),
|
|
135
|
+
/** Capability invocation verification relationship */
|
|
136
|
+
capabilityInvocation: zod_1.z
|
|
137
|
+
.array(exports.VerificationRelationshipEntrySchema)
|
|
138
|
+
.optional(),
|
|
139
|
+
/** Capability delegation verification relationship */
|
|
140
|
+
capabilityDelegation: zod_1.z
|
|
141
|
+
.array(exports.VerificationRelationshipEntrySchema)
|
|
142
|
+
.optional(),
|
|
143
|
+
/** Service endpoints */
|
|
144
|
+
service: zod_1.z.array(exports.DidServiceSchema).optional(),
|
|
145
|
+
})
|
|
146
|
+
.passthrough(); // Allow additional properties for extensibility
|
|
147
|
+
/**
|
|
148
|
+
* DID Method Schema
|
|
149
|
+
*/
|
|
150
|
+
exports.DidMethodSchema = zod_1.z.enum(['key', 'web', 'jwk', 'ion', 'ebsi']);
|
|
151
|
+
/**
|
|
152
|
+
* Helper function to validate a DID Document
|
|
153
|
+
*
|
|
154
|
+
* @param doc - The document to validate
|
|
155
|
+
* @returns The validated document or throws ZodError
|
|
156
|
+
*/
|
|
157
|
+
function validateDidDocument(doc) {
|
|
158
|
+
return exports.DidDocumentSchema.parse(doc);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Helper function to safely validate a DID Document
|
|
162
|
+
*
|
|
163
|
+
* @param doc - The document to validate
|
|
164
|
+
* @returns Result object with success status and data/error
|
|
165
|
+
*/
|
|
166
|
+
function safeValidateDidDocument(doc) {
|
|
167
|
+
const result = exports.DidDocumentSchema.safeParse(doc);
|
|
168
|
+
if (result.success) {
|
|
169
|
+
return { success: true, data: result.data };
|
|
170
|
+
}
|
|
171
|
+
return { success: false, error: result.error };
|
|
172
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DID Document Types (W3C Compliant)
|
|
3
|
+
*
|
|
4
|
+
* These types conform to the W3C DID Core specification and provide
|
|
5
|
+
* TypeScript parity with the Python implementation.
|
|
6
|
+
*
|
|
7
|
+
* Related Spec: MCP-I §2.1, §2.3
|
|
8
|
+
* Python Reference: DID-Documentation.md, DID-Service.md
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Verification Method Types
|
|
12
|
+
*
|
|
13
|
+
* Supported types for verification methods in DID Documents.
|
|
14
|
+
*/
|
|
15
|
+
export type VerificationMethodType = 'Ed25519VerificationKey2020' | 'JsonWebKey2020' | 'EcdsaSecp256k1VerificationKey2019';
|
|
16
|
+
/**
|
|
17
|
+
* Verification Method
|
|
18
|
+
*
|
|
19
|
+
* A verification method as defined in the W3C DID Core specification.
|
|
20
|
+
* Used for cryptographic verification of signatures and authentication.
|
|
21
|
+
*
|
|
22
|
+
* **kid Derivation Guidelines:**
|
|
23
|
+
* - For did:key: kid = `${did}#${multibaseKey}`
|
|
24
|
+
* - For did:web: kid = `${did}#${kid}` where kid is from DID Document
|
|
25
|
+
* - The kid MUST be resolvable to a verification method in the DID Document
|
|
26
|
+
*/
|
|
27
|
+
export interface VerificationMethod {
|
|
28
|
+
/** Verification method identifier (e.g., "#key-1" or full DID URL) */
|
|
29
|
+
id: string;
|
|
30
|
+
/** Type of verification method */
|
|
31
|
+
type: VerificationMethodType;
|
|
32
|
+
/** DID of the controller of this verification method */
|
|
33
|
+
controller: string;
|
|
34
|
+
/**
|
|
35
|
+
* Public key encoded as multibase for Ed25519VerificationKey2020
|
|
36
|
+
* Format: z + base58btc(public key bytes)
|
|
37
|
+
*/
|
|
38
|
+
publicKeyMultibase?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Public key as JSON Web Key for JsonWebKey2020
|
|
41
|
+
* See RFC 7517 for JWK format
|
|
42
|
+
*/
|
|
43
|
+
publicKeyJwk?: {
|
|
44
|
+
kty: string;
|
|
45
|
+
crv: string;
|
|
46
|
+
x: string;
|
|
47
|
+
y?: string;
|
|
48
|
+
[key: string]: any;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* DID Service
|
|
53
|
+
*
|
|
54
|
+
* A service endpoint as defined in the W3C DID Core specification.
|
|
55
|
+
* Services enable discovery of service endpoints for the DID subject.
|
|
56
|
+
*/
|
|
57
|
+
export interface DidService {
|
|
58
|
+
/** Service identifier (e.g., "#service-1") */
|
|
59
|
+
id: string;
|
|
60
|
+
/** Service type (e.g., "LinkedDomains", "CredentialRegistry") */
|
|
61
|
+
type: string | string[];
|
|
62
|
+
/** Service endpoint URL(s) or endpoint descriptor object */
|
|
63
|
+
serviceEndpoint: string | string[] | Record<string, any>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* DID Document
|
|
67
|
+
*
|
|
68
|
+
* A DID Document as defined in the W3C DID Core specification.
|
|
69
|
+
* Represents the full descriptor of a DID, including verification methods
|
|
70
|
+
* and service endpoints.
|
|
71
|
+
*
|
|
72
|
+
* **Supported DID Methods:**
|
|
73
|
+
* - did:key - Self-contained, ephemeral identities
|
|
74
|
+
* - did:web - Domain-bound identities resolved via HTTPS
|
|
75
|
+
* - did:jwk - JWK-based identities
|
|
76
|
+
*
|
|
77
|
+
* **@context:**
|
|
78
|
+
* While the W3C spec requires @context, it's optional in this type to support
|
|
79
|
+
* simplified parsing. Implementations should include "https://www.w3.org/ns/did/v1"
|
|
80
|
+
* as the base context.
|
|
81
|
+
*/
|
|
82
|
+
export interface DidDocument {
|
|
83
|
+
/** JSON-LD context (typically "https://www.w3.org/ns/did/v1") */
|
|
84
|
+
'@context'?: string | string[] | Record<string, any>;
|
|
85
|
+
/** The DID this document describes (e.g., "did:key:z6Mk...") */
|
|
86
|
+
id: string;
|
|
87
|
+
/** Also known as - alternative identifiers for this DID */
|
|
88
|
+
alsoKnownAs?: string[];
|
|
89
|
+
/**
|
|
90
|
+
* Verification methods available for this DID
|
|
91
|
+
* Contains public key information for signature verification
|
|
92
|
+
*/
|
|
93
|
+
verificationMethod?: VerificationMethod[];
|
|
94
|
+
/**
|
|
95
|
+
* Authentication verification relationship
|
|
96
|
+
* References to verification methods or embedded methods
|
|
97
|
+
* Used for authenticating as the DID subject
|
|
98
|
+
*/
|
|
99
|
+
authentication?: (string | VerificationMethod)[];
|
|
100
|
+
/**
|
|
101
|
+
* Assertion method verification relationship
|
|
102
|
+
* References to verification methods or embedded methods
|
|
103
|
+
* Used for issuing verifiable credentials
|
|
104
|
+
*/
|
|
105
|
+
assertionMethod?: (string | VerificationMethod)[];
|
|
106
|
+
/**
|
|
107
|
+
* Key agreement verification relationship
|
|
108
|
+
* References to verification methods or embedded methods
|
|
109
|
+
* Used for encryption and key agreement protocols
|
|
110
|
+
*/
|
|
111
|
+
keyAgreement?: (string | VerificationMethod)[];
|
|
112
|
+
/**
|
|
113
|
+
* Capability invocation verification relationship
|
|
114
|
+
* References to verification methods or embedded methods
|
|
115
|
+
* Used for invoking capabilities
|
|
116
|
+
*/
|
|
117
|
+
capabilityInvocation?: (string | VerificationMethod)[];
|
|
118
|
+
/**
|
|
119
|
+
* Capability delegation verification relationship
|
|
120
|
+
* References to verification methods or embedded methods
|
|
121
|
+
* Used for delegating capabilities
|
|
122
|
+
*/
|
|
123
|
+
capabilityDelegation?: (string | VerificationMethod)[];
|
|
124
|
+
/** Service endpoints for the DID */
|
|
125
|
+
service?: DidService[];
|
|
126
|
+
/** Additional properties allowed for extensibility */
|
|
127
|
+
[key: string]: any;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* DID Method
|
|
131
|
+
*
|
|
132
|
+
* String literal type for supported DID methods
|
|
133
|
+
*/
|
|
134
|
+
export type DidMethod = 'key' | 'web' | 'jwk' | 'ion' | 'ebsi';
|
|
135
|
+
/**
|
|
136
|
+
* Helper type guards
|
|
137
|
+
*/
|
|
138
|
+
/**
|
|
139
|
+
* Type guard to check if a value is a VerificationMethod
|
|
140
|
+
*/
|
|
141
|
+
export declare function isVerificationMethod(value: any): value is VerificationMethod;
|
|
142
|
+
/**
|
|
143
|
+
* Type guard to check if a value is a string reference to a verification method
|
|
144
|
+
*/
|
|
145
|
+
export declare function isVerificationMethodReference(value: any): value is string;
|
|
146
|
+
/**
|
|
147
|
+
* Type guard to check if a DID Document is valid (basic structural check)
|
|
148
|
+
*/
|
|
149
|
+
export declare function isDidDocument(value: any): value is DidDocument;
|
|
150
|
+
/**
|
|
151
|
+
* Extract DID method from a DID string
|
|
152
|
+
*
|
|
153
|
+
* @param did - The DID string (e.g., "did:key:z6Mk...")
|
|
154
|
+
* @returns The method name (e.g., "key") or null if invalid
|
|
155
|
+
*/
|
|
156
|
+
export declare function extractDidMethod(did: string): string | null;
|
|
157
|
+
/**
|
|
158
|
+
* Extract key ID from a DID URL
|
|
159
|
+
*
|
|
160
|
+
* @param didUrl - A DID URL with fragment (e.g., "did:key:z6Mk...#key-1")
|
|
161
|
+
* @returns The fragment part (e.g., "key-1") or null if no fragment
|
|
162
|
+
*/
|
|
163
|
+
export declare function extractKeyId(didUrl: string): string | null;
|