@kya-os/contracts 1.3.5 → 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.
Files changed (87) hide show
  1. package/dist/agentshield-api/endpoints.d.ts +50 -0
  2. package/dist/agentshield-api/endpoints.js +46 -0
  3. package/dist/agentshield-api/index.d.ts +13 -0
  4. package/dist/agentshield-api/index.js +38 -0
  5. package/dist/agentshield-api/schemas.d.ts +9914 -0
  6. package/dist/agentshield-api/schemas.js +165 -0
  7. package/dist/agentshield-api/types.d.ts +168 -0
  8. package/dist/agentshield-api/types.js +27 -0
  9. package/dist/cli.d.ts +13 -0
  10. package/dist/cli.js +13 -1
  11. package/dist/config/base.d.ts +96 -0
  12. package/dist/config/base.js +11 -0
  13. package/dist/config/delegation.d.ts +194 -0
  14. package/dist/config/delegation.js +10 -0
  15. package/dist/config/identity.d.ts +117 -0
  16. package/dist/config/identity.js +11 -0
  17. package/dist/config/index.d.ts +33 -0
  18. package/dist/config/index.js +11 -0
  19. package/dist/config/proofing.d.ts +120 -0
  20. package/dist/config/proofing.js +10 -0
  21. package/dist/config/tool-protection.d.ts +139 -0
  22. package/dist/config/tool-protection.js +10 -0
  23. package/dist/dashboard-config/index.d.ts +10 -0
  24. package/dist/dashboard-config/index.js +31 -0
  25. package/dist/dashboard-config/schemas.d.ts +5847 -0
  26. package/dist/dashboard-config/schemas.js +251 -0
  27. package/dist/dashboard-config/types.d.ts +331 -0
  28. package/dist/dashboard-config/types.js +11 -0
  29. package/dist/delegation/constraints.d.ts +991 -0
  30. package/dist/delegation/constraints.js +209 -0
  31. package/dist/delegation/index.d.ts +7 -0
  32. package/dist/delegation/index.js +23 -0
  33. package/dist/delegation/schemas.d.ts +8381 -0
  34. package/dist/delegation/schemas.js +475 -0
  35. package/dist/did/index.d.ts +8 -0
  36. package/dist/did/index.js +24 -0
  37. package/dist/did/resolve-contract.d.ts +219 -0
  38. package/dist/did/resolve-contract.js +31 -0
  39. package/dist/did/schemas.d.ts +112 -0
  40. package/dist/did/schemas.js +172 -0
  41. package/dist/did/types.d.ts +163 -0
  42. package/dist/did/types.js +70 -0
  43. package/dist/env/constants.d.ts +57 -0
  44. package/dist/env/constants.js +59 -0
  45. package/dist/env/index.d.ts +4 -0
  46. package/dist/env/index.js +20 -0
  47. package/dist/handshake.d.ts +20 -0
  48. package/dist/handshake.js +10 -3
  49. package/dist/index.d.ts +14 -0
  50. package/dist/index.js +28 -0
  51. package/dist/proof/index.d.ts +8 -0
  52. package/dist/proof/index.js +24 -0
  53. package/dist/proof/proof-record.d.ts +837 -0
  54. package/dist/proof/proof-record.js +133 -0
  55. package/dist/proof/signing-spec.d.ts +146 -0
  56. package/dist/proof/signing-spec.js +122 -0
  57. package/dist/proof.d.ts +53 -16
  58. package/dist/proof.js +27 -3
  59. package/dist/registry.d.ts +16 -0
  60. package/dist/registry.js +29 -9
  61. package/dist/runtime/errors.d.ts +347 -0
  62. package/dist/runtime/errors.js +119 -0
  63. package/dist/runtime/headers.d.ts +83 -0
  64. package/dist/runtime/headers.js +81 -0
  65. package/dist/runtime/index.d.ts +5 -0
  66. package/dist/runtime/index.js +21 -0
  67. package/dist/test.d.ts +36 -0
  68. package/dist/test.js +36 -0
  69. package/dist/tlkrc/index.d.ts +4 -0
  70. package/dist/tlkrc/index.js +20 -0
  71. package/dist/tlkrc/rotation.d.ts +245 -0
  72. package/dist/tlkrc/rotation.js +126 -0
  73. package/dist/tool-protection/index.d.ts +227 -0
  74. package/dist/tool-protection/index.js +113 -0
  75. package/dist/utils/validation.d.ts +16 -0
  76. package/dist/utils/validation.js +13 -0
  77. package/dist/vc/index.d.ts +7 -0
  78. package/dist/vc/index.js +23 -0
  79. package/dist/vc/schemas.d.ts +2483 -0
  80. package/dist/vc/schemas.js +224 -0
  81. package/dist/vc/statuslist.d.ts +493 -0
  82. package/dist/vc/statuslist.js +132 -0
  83. package/dist/verifier.d.ts +3 -0
  84. package/dist/verifier.js +7 -0
  85. package/dist/well-known/index.d.ts +308 -0
  86. package/dist/well-known/index.js +134 -0
  87. package/package.json +6 -1
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /**
3
+ * DID Document Types (W3C Compliant)
4
+ *
5
+ * These types conform to the W3C DID Core specification and provide
6
+ * TypeScript parity with the Python implementation.
7
+ *
8
+ * Related Spec: MCP-I §2.1, §2.3
9
+ * Python Reference: DID-Documentation.md, DID-Service.md
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.isVerificationMethod = isVerificationMethod;
13
+ exports.isVerificationMethodReference = isVerificationMethodReference;
14
+ exports.isDidDocument = isDidDocument;
15
+ exports.extractDidMethod = extractDidMethod;
16
+ exports.extractKeyId = extractKeyId;
17
+ /**
18
+ * Helper type guards
19
+ */
20
+ /**
21
+ * Type guard to check if a value is a VerificationMethod
22
+ */
23
+ function isVerificationMethod(value) {
24
+ return (typeof value === 'object' &&
25
+ value !== null &&
26
+ typeof value.id === 'string' &&
27
+ typeof value.type === 'string' &&
28
+ typeof value.controller === 'string');
29
+ }
30
+ /**
31
+ * Type guard to check if a value is a string reference to a verification method
32
+ */
33
+ function isVerificationMethodReference(value) {
34
+ return typeof value === 'string';
35
+ }
36
+ /**
37
+ * Type guard to check if a DID Document is valid (basic structural check)
38
+ */
39
+ function isDidDocument(value) {
40
+ return (typeof value === 'object' &&
41
+ value !== null &&
42
+ typeof value.id === 'string' &&
43
+ value.id.startsWith('did:'));
44
+ }
45
+ /**
46
+ * Extract DID method from a DID string
47
+ *
48
+ * @param did - The DID string (e.g., "did:key:z6Mk...")
49
+ * @returns The method name (e.g., "key") or null if invalid
50
+ */
51
+ function extractDidMethod(did) {
52
+ const parts = did.split(':');
53
+ if (parts.length < 3 || parts[0] !== 'did') {
54
+ return null;
55
+ }
56
+ return parts[1];
57
+ }
58
+ /**
59
+ * Extract key ID from a DID URL
60
+ *
61
+ * @param didUrl - A DID URL with fragment (e.g., "did:key:z6Mk...#key-1")
62
+ * @returns The fragment part (e.g., "key-1") or null if no fragment
63
+ */
64
+ function extractKeyId(didUrl) {
65
+ const hashIndex = didUrl.indexOf('#');
66
+ if (hashIndex === -1) {
67
+ return null;
68
+ }
69
+ return didUrl.substring(hashIndex + 1);
70
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Environment Constants
3
+ *
4
+ * System-wide constants for algorithms, TTLs, and limits
5
+ *
6
+ * Related Spec: MCP-I §8
7
+ * Python Reference: All service documentation files
8
+ */
9
+ /**
10
+ * Hash algorithm for cryptographic operations
11
+ */
12
+ export declare const HASH_ALGO: "SHA-256";
13
+ /**
14
+ * Supported signature algorithms
15
+ */
16
+ export declare const SIG_ALGOS: readonly ["Ed25519", "ES256"];
17
+ export type SignatureAlgorithm = (typeof SIG_ALGOS)[number];
18
+ /**
19
+ * Nonce TTL in milliseconds (5 minutes)
20
+ */
21
+ export declare const NONCE_TTL_MS: number;
22
+ /**
23
+ * Resume token TTL in milliseconds (10 minutes)
24
+ */
25
+ export declare const RESUME_TOKEN_TTL_MS: number;
26
+ /**
27
+ * StatusList2021 cache TTL in seconds (1 minute)
28
+ */
29
+ export declare const STATUSLIST_CACHE_SEC = 60;
30
+ /**
31
+ * DID resolution timeout in milliseconds (500ms)
32
+ */
33
+ export declare const DID_RESOLVE_TIMEOUT_MS = 500;
34
+ /**
35
+ * Default session TTL in minutes (30 minutes)
36
+ */
37
+ export declare const DEFAULT_SESSION_TTL_MINUTES = 30;
38
+ /**
39
+ * Maximum timestamp skew in seconds (2 minutes)
40
+ */
41
+ export declare const MAX_TIMESTAMP_SKEW_SEC = 120;
42
+ /**
43
+ * Maximum delegation chain depth
44
+ */
45
+ export declare const MAX_DELEGATION_CHAIN_DEPTH = 10;
46
+ /**
47
+ * Maximum status list size (1 million entries)
48
+ */
49
+ export declare const MAX_STATUSLIST_SIZE = 1000000;
50
+ /**
51
+ * Proof archive TTL in seconds (30 days)
52
+ */
53
+ export declare const PROOF_ARCHIVE_TTL_SEC: number;
54
+ /**
55
+ * Key rotation grace period in seconds (24 hours)
56
+ */
57
+ export declare const KEY_ROTATION_GRACE_PERIOD_SEC: number;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /**
3
+ * Environment Constants
4
+ *
5
+ * System-wide constants for algorithms, TTLs, and limits
6
+ *
7
+ * Related Spec: MCP-I §8
8
+ * Python Reference: All service documentation files
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.KEY_ROTATION_GRACE_PERIOD_SEC = exports.PROOF_ARCHIVE_TTL_SEC = exports.MAX_STATUSLIST_SIZE = exports.MAX_DELEGATION_CHAIN_DEPTH = exports.MAX_TIMESTAMP_SKEW_SEC = exports.DEFAULT_SESSION_TTL_MINUTES = exports.DID_RESOLVE_TIMEOUT_MS = exports.STATUSLIST_CACHE_SEC = exports.RESUME_TOKEN_TTL_MS = exports.NONCE_TTL_MS = exports.SIG_ALGOS = exports.HASH_ALGO = void 0;
12
+ /**
13
+ * Hash algorithm for cryptographic operations
14
+ */
15
+ exports.HASH_ALGO = 'SHA-256';
16
+ /**
17
+ * Supported signature algorithms
18
+ */
19
+ exports.SIG_ALGOS = ['Ed25519', 'ES256'];
20
+ /**
21
+ * Nonce TTL in milliseconds (5 minutes)
22
+ */
23
+ exports.NONCE_TTL_MS = 5 * 60 * 1000;
24
+ /**
25
+ * Resume token TTL in milliseconds (10 minutes)
26
+ */
27
+ exports.RESUME_TOKEN_TTL_MS = 10 * 60 * 1000;
28
+ /**
29
+ * StatusList2021 cache TTL in seconds (1 minute)
30
+ */
31
+ exports.STATUSLIST_CACHE_SEC = 60;
32
+ /**
33
+ * DID resolution timeout in milliseconds (500ms)
34
+ */
35
+ exports.DID_RESOLVE_TIMEOUT_MS = 500;
36
+ /**
37
+ * Default session TTL in minutes (30 minutes)
38
+ */
39
+ exports.DEFAULT_SESSION_TTL_MINUTES = 30;
40
+ /**
41
+ * Maximum timestamp skew in seconds (2 minutes)
42
+ */
43
+ exports.MAX_TIMESTAMP_SKEW_SEC = 120;
44
+ /**
45
+ * Maximum delegation chain depth
46
+ */
47
+ exports.MAX_DELEGATION_CHAIN_DEPTH = 10;
48
+ /**
49
+ * Maximum status list size (1 million entries)
50
+ */
51
+ exports.MAX_STATUSLIST_SIZE = 1000000;
52
+ /**
53
+ * Proof archive TTL in seconds (30 days)
54
+ */
55
+ exports.PROOF_ARCHIVE_TTL_SEC = 30 * 24 * 60 * 60;
56
+ /**
57
+ * Key rotation grace period in seconds (24 hours)
58
+ */
59
+ exports.KEY_ROTATION_GRACE_PERIOD_SEC = 24 * 60 * 60;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Environment Constants Module
3
+ */
4
+ export * from './constants.js';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /**
3
+ * Environment Constants Module
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ __exportStar(require("./constants.js"), exports);
@@ -1,4 +1,7 @@
1
1
  import { z } from "zod";
2
+ /**
3
+ * Handshake and session management schemas
4
+ */
2
5
  export declare const HandshakeRequestSchema: z.ZodObject<{
3
6
  nonce: z.ZodString;
4
7
  audience: z.ZodString;
@@ -56,11 +59,28 @@ export declare const NonceCacheEntrySchema: z.ZodObject<{
56
59
  export type HandshakeRequest = z.infer<typeof HandshakeRequestSchema>;
57
60
  export type SessionContext = z.infer<typeof SessionContextSchema>;
58
61
  export type NonceCacheEntry = z.infer<typeof NonceCacheEntrySchema>;
62
+ /**
63
+ * Nonce cache interface for replay prevention
64
+ */
59
65
  export interface NonceCache {
66
+ /**
67
+ * Check if a nonce exists in the cache
68
+ */
60
69
  has(nonce: string): Promise<boolean>;
70
+ /**
71
+ * Add a nonce to the cache with TTL
72
+ * MUST ensure atomic add-if-absent semantics for replay prevention
73
+ */
61
74
  add(nonce: string, ttl: number): Promise<void>;
75
+ /**
76
+ * Clean up expired entries
77
+ * Should be safe to call frequently and should be no-op for backends that auto-expire
78
+ */
62
79
  cleanup(): Promise<void>;
63
80
  }
81
+ /**
82
+ * Configuration for nonce cache implementations
83
+ */
64
84
  export declare const NonceCacheConfigSchema: z.ZodObject<{
65
85
  type: z.ZodOptional<z.ZodEnum<["memory", "redis", "dynamodb", "cloudflare-kv"]>>;
66
86
  redis: z.ZodOptional<z.ZodObject<{
package/dist/handshake.js CHANGED
@@ -2,11 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NONCE_LENGTH_BYTES = exports.DEFAULT_TIMESTAMP_SKEW_SECONDS = exports.DEFAULT_SESSION_TTL_MINUTES = exports.NonceCacheConfigSchema = exports.NonceCacheEntrySchema = exports.SessionContextSchema = exports.HandshakeRequestSchema = void 0;
4
4
  const zod_1 = require("zod");
5
+ /**
6
+ * Handshake and session management schemas
7
+ */
5
8
  exports.HandshakeRequestSchema = zod_1.z.object({
6
9
  nonce: zod_1.z.string().min(1),
7
10
  audience: zod_1.z.string().min(1),
8
11
  timestamp: zod_1.z.number().int().positive(),
9
- agentDid: zod_1.z.string().startsWith("did:").optional(),
12
+ agentDid: zod_1.z.string().startsWith("did:").optional(), // Agent DID for delegation verification
10
13
  });
11
14
  exports.SessionContextSchema = zod_1.z.object({
12
15
  sessionId: zod_1.z.string().min(1),
@@ -16,12 +19,15 @@ exports.SessionContextSchema = zod_1.z.object({
16
19
  createdAt: zod_1.z.number().int().positive(),
17
20
  lastActivity: zod_1.z.number().int().positive(),
18
21
  ttlMinutes: zod_1.z.number().int().positive().default(30),
19
- agentDid: zod_1.z.string().optional(),
22
+ agentDid: zod_1.z.string().optional(), // Agent DID for delegation verification
20
23
  });
21
24
  exports.NonceCacheEntrySchema = zod_1.z.object({
22
25
  sessionId: zod_1.z.string().min(1),
23
26
  expiresAt: zod_1.z.number().int().positive(),
24
27
  });
28
+ /**
29
+ * Configuration for nonce cache implementations
30
+ */
25
31
  exports.NonceCacheConfigSchema = zod_1.z.object({
26
32
  type: zod_1.z.enum(["memory", "redis", "dynamodb", "cloudflare-kv"]).optional(),
27
33
  redis: zod_1.z
@@ -45,6 +51,7 @@ exports.NonceCacheConfigSchema = zod_1.z.object({
45
51
  })
46
52
  .optional(),
47
53
  });
54
+ // Constants
48
55
  exports.DEFAULT_SESSION_TTL_MINUTES = 30;
49
56
  exports.DEFAULT_TIMESTAMP_SKEW_SECONDS = 120;
50
- exports.NONCE_LENGTH_BYTES = 16;
57
+ exports.NONCE_LENGTH_BYTES = 16; // 128-bit
package/dist/index.d.ts CHANGED
@@ -1,3 +1,17 @@
1
+ /**
2
+ * @kya-os/contracts - Shared types and schemas for XMCP-I ecosystem
3
+ *
4
+ * This package provides a single source of truth for all types and contracts
5
+ * used across the XMCP-I ecosystem, including runtime, CLI, verifier, and registry.
6
+ *
7
+ * NOTE: Some exports may conflict. Use subpath imports for new modules:
8
+ * - import { ... } from '@kya-os/contracts/did'
9
+ * - import { ... } from '@kya-os/contracts/vc'
10
+ * - import { ... } from '@kya-os/contracts/delegation'
11
+ * - import { ... } from '@kya-os/contracts/runtime'
12
+ * - import { ... } from '@kya-os/contracts/tlkrc'
13
+ * - import { ... } from '@kya-os/contracts/env'
14
+ */
1
15
  export * from "./handshake.js";
2
16
  export * from "./proof.js";
3
17
  export * from "./verifier.js";
package/dist/index.js CHANGED
@@ -1,4 +1,18 @@
1
1
  "use strict";
2
+ /**
3
+ * @kya-os/contracts - Shared types and schemas for XMCP-I ecosystem
4
+ *
5
+ * This package provides a single source of truth for all types and contracts
6
+ * used across the XMCP-I ecosystem, including runtime, CLI, verifier, and registry.
7
+ *
8
+ * NOTE: Some exports may conflict. Use subpath imports for new modules:
9
+ * - import { ... } from '@kya-os/contracts/did'
10
+ * - import { ... } from '@kya-os/contracts/vc'
11
+ * - import { ... } from '@kya-os/contracts/delegation'
12
+ * - import { ... } from '@kya-os/contracts/runtime'
13
+ * - import { ... } from '@kya-os/contracts/tlkrc'
14
+ * - import { ... } from '@kya-os/contracts/env'
15
+ */
2
16
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
17
  if (k2 === undefined) k2 = k;
4
18
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -15,6 +29,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
29
  };
16
30
  Object.defineProperty(exports, "__esModule", { value: true });
17
31
  exports.SUPPORTED_XMCP_I_VERSION = exports.CONTRACTS_VERSION = void 0;
32
+ // Legacy exports (maintain backward compatibility)
18
33
  __exportStar(require("./handshake.js"), exports);
19
34
  __exportStar(require("./proof.js"), exports);
20
35
  __exportStar(require("./verifier.js"), exports);
@@ -22,7 +37,20 @@ __exportStar(require("./registry.js"), exports);
22
37
  __exportStar(require("./cli.js"), exports);
23
38
  __exportStar(require("./test.js"), exports);
24
39
  __exportStar(require("./utils/validation.js"), exports);
40
+ // W3C VC and Delegation exports (for mcp-i-core compatibility)
25
41
  __exportStar(require("./vc/index.js"), exports);
26
42
  __exportStar(require("./delegation/index.js"), exports);
43
+ // Version information
27
44
  exports.CONTRACTS_VERSION = "1.2.1";
28
45
  exports.SUPPORTED_XMCP_I_VERSION = "^1.0.0";
46
+ // New MCP-I contract types are available via subpath imports:
47
+ // import { ... } from '@kya-os/contracts/did'
48
+ // import { ... } from '@kya-os/contracts/vc'
49
+ // import { ... } from '@kya-os/contracts/delegation'
50
+ // import { ... } from '@kya-os/contracts/runtime'
51
+ // import { ... } from '@kya-os/contracts/tlkrc'
52
+ // import { ... } from '@kya-os/contracts/env'
53
+ // import { ... } from '@kya-os/contracts/agentshield-api'
54
+ // import { ... } from '@kya-os/contracts/tool-protection'
55
+ // import { ... } from '@kya-os/contracts/well-known'
56
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Proof Module Exports
3
+ *
4
+ * Note: This module exports proof record and signing spec types.
5
+ * The existing proof.ts file with DetachedProofSchema is separate.
6
+ */
7
+ export * from './signing-spec.js';
8
+ export * from './proof-record.js';
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /**
3
+ * Proof Module Exports
4
+ *
5
+ * Note: This module exports proof record and signing spec types.
6
+ * The existing proof.ts file with DetachedProofSchema is separate.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ __exportStar(require("./signing-spec.js"), exports);
24
+ __exportStar(require("./proof-record.js"), exports);