@kya-os/contracts 1.5.3-canary.21 → 1.5.3-canary.23

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