@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.
- package/dist/consent/schemas.d.ts +149 -77
- package/dist/consent/schemas.js +29 -2
- package/package.json +23 -1
- package/.turbo/turbo-build.log +0 -17
- package/.turbo/turbo-test$colon$coverage.log +0 -85
- package/.turbo/turbo-test.log +0 -32
- package/coverage/coverage-final.json +0 -38
- package/schemas/cli/register-output/v1.0.0.json +0 -69
- package/schemas/identity/v1.0.0.json +0 -46
- package/schemas/proof/v1.0.0.json +0 -80
- package/schemas/registry/receipt-v1.0.0.json +0 -60
- package/schemas/verifier/verify-page/v1.0.0.json +0 -94
- package/schemas/well-known/agent/v1.0.0.json +0 -67
- package/schemas/well-known/did/v1.0.0.json +0 -174
- package/scripts/emit-schemas.js +0 -11
- package/src/agentshield-api/admin-schemas.ts +0 -31
- package/src/agentshield-api/admin-types.ts +0 -47
- package/src/agentshield-api/endpoints.ts +0 -60
- package/src/agentshield-api/index.ts +0 -70
- package/src/agentshield-api/schemas.ts +0 -304
- package/src/agentshield-api/types.ts +0 -317
- package/src/audit/index.ts +0 -128
- package/src/cli.ts +0 -156
- package/src/config/base.ts +0 -107
- package/src/config/builder.ts +0 -97
- package/src/config/delegation.ts +0 -232
- package/src/config/identity.ts +0 -252
- package/src/config/index.ts +0 -78
- package/src/config/proofing.ts +0 -138
- package/src/config/tool-context.ts +0 -41
- package/src/config/tool-protection.ts +0 -174
- package/src/consent/index.ts +0 -32
- package/src/consent/schemas.ts +0 -334
- package/src/consent/types.ts +0 -199
- package/src/dashboard-config/default-config.json +0 -86
- package/src/dashboard-config/default-config.ts +0 -266
- package/src/dashboard-config/index.ts +0 -48
- package/src/dashboard-config/schemas.ts +0 -286
- package/src/dashboard-config/types.ts +0 -404
- package/src/delegation/constraints.ts +0 -267
- package/src/delegation/index.ts +0 -8
- package/src/delegation/schemas.ts +0 -595
- package/src/did/index.ts +0 -9
- package/src/did/resolve-contract.ts +0 -255
- package/src/did/schemas.ts +0 -190
- package/src/did/types.ts +0 -224
- package/src/env/constants.ts +0 -70
- package/src/env/index.ts +0 -5
- package/src/handshake.ts +0 -125
- package/src/index.ts +0 -45
- package/src/proof/index.ts +0 -31
- package/src/proof/proof-record.ts +0 -163
- package/src/proof/signing-spec.ts +0 -146
- package/src/proof.ts +0 -99
- package/src/registry.ts +0 -146
- package/src/runtime/errors.ts +0 -153
- package/src/runtime/headers.ts +0 -136
- package/src/runtime/index.ts +0 -6
- package/src/test.ts +0 -143
- package/src/tlkrc/index.ts +0 -5
- package/src/tlkrc/rotation.ts +0 -153
- package/src/tool-protection/index.ts +0 -406
- package/src/utils/validation.ts +0 -93
- package/src/vc/index.ts +0 -8
- package/src/vc/schemas.ts +0 -277
- package/src/vc/statuslist.ts +0 -279
- package/src/verifier/index.ts +0 -2
- package/src/verifier.ts +0 -92
- package/src/well-known/index.ts +0 -237
package/src/registry.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Registry integration schemas (Know-That-AI and MCP Registry)
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export const RegistrationInputSchema = z.object({
|
|
8
|
-
agentDID: z.string().min(1),
|
|
9
|
-
agentURL: z.string().url(),
|
|
10
|
-
verificationEndpoint: z.string().url(),
|
|
11
|
-
conformanceCapabilities: z.array(
|
|
12
|
-
z.enum(["handshake", "signing", "verification"])
|
|
13
|
-
),
|
|
14
|
-
metadata: z.record(z.any()).optional(),
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
export const RegistrationResultSchema = z.object({
|
|
18
|
-
agentDID: z.string().min(1),
|
|
19
|
-
agentURL: z.string().url(),
|
|
20
|
-
agentId: z.string().min(1),
|
|
21
|
-
agentSlug: z.string().min(1),
|
|
22
|
-
claimURL: z.string().url().optional(),
|
|
23
|
-
verificationEndpoint: z.string().url(),
|
|
24
|
-
conformanceCapabilities: z.tuple([
|
|
25
|
-
z.literal("handshake"),
|
|
26
|
-
z.literal("signing"),
|
|
27
|
-
z.literal("verification"),
|
|
28
|
-
]),
|
|
29
|
-
mirrorStatus: z.enum(["pending", "success", "error"]),
|
|
30
|
-
mirrorLink: z.string().url().optional(),
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
export const ClaimTokenSchema = z.object({
|
|
34
|
-
token: z.string().min(1),
|
|
35
|
-
expiresAt: z.number().int().positive(),
|
|
36
|
-
ttlHours: z.number().int().positive().default(24),
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
export const MirrorStatusSchema = z.object({
|
|
40
|
-
status: z.enum(["pending", "success", "error"]),
|
|
41
|
-
lastUpdated: z.number().int().positive(),
|
|
42
|
-
errorMessage: z.string().optional(),
|
|
43
|
-
registryURL: z.string().url().optional(),
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
export const AgentStatusSchema = z.object({
|
|
47
|
-
did: z.string().min(1),
|
|
48
|
-
kid: z.string().min(1),
|
|
49
|
-
ktaURL: z.string().url(),
|
|
50
|
-
mirrorStatus: MirrorStatusSchema,
|
|
51
|
-
lastHandshake: z.number().int().positive().optional(),
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Delegation schemas for verifiable credentials
|
|
56
|
-
*/
|
|
57
|
-
export const DelegationSchema = z.object({
|
|
58
|
-
issuer: z.string().min(1), // DID of the issuer
|
|
59
|
-
subject: z.string().min(1), // DID of the subject
|
|
60
|
-
scopes: z.array(z.string()),
|
|
61
|
-
nbf: z.number().int().positive(), // Not before (unix timestamp)
|
|
62
|
-
exp: z.number().int().positive(), // Expires (unix timestamp)
|
|
63
|
-
aud: z.string().optional(), // Audience (optional)
|
|
64
|
-
delegationRef: z.string().optional(), // Reference to parent delegation
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
export const DelegationRequestSchema = z.object({
|
|
68
|
-
subject: z.string().min(1),
|
|
69
|
-
scopes: z.array(z.string()),
|
|
70
|
-
duration: z.number().int().positive().optional(), // Duration in seconds
|
|
71
|
-
audience: z.string().optional(),
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Storage mode configuration for verifiable credentials and delegations
|
|
76
|
-
*/
|
|
77
|
-
export const StorageModeSchema = z.enum([
|
|
78
|
-
"ktaEncrypted",
|
|
79
|
-
"hybridReceiptsOnly",
|
|
80
|
-
"selfHostedAuthoritative",
|
|
81
|
-
]);
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Receipt object returned by KTA for verifiable operations
|
|
85
|
-
* Schema ID: https://schemas.kya-os.ai/mcpi/receipt/v1.0.0.json
|
|
86
|
-
*/
|
|
87
|
-
export const ReceiptSchema = z.object({
|
|
88
|
-
$schema: z
|
|
89
|
-
.literal("https://schemas.kya-os.ai/mcpi/receipt/v1.0.0.json")
|
|
90
|
-
.optional(),
|
|
91
|
-
ref: z.string().min(1),
|
|
92
|
-
contentHash: z.string().regex(/^sha256:[a-f0-9]{64}$/),
|
|
93
|
-
action: z.enum(["issue", "revoke"]),
|
|
94
|
-
// Back-compat: accept ISO string (preferred) or legacy epoch number
|
|
95
|
-
ts: z.union([z.string().datetime(), z.number().int().positive()]),
|
|
96
|
-
logIndex: z.number().int().nonnegative(),
|
|
97
|
-
logRoot: z.string().min(1),
|
|
98
|
-
inclusionProof: z.array(z.string()),
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
export const DelegationResponseSchema = z.object({
|
|
102
|
-
delegation: DelegationSchema,
|
|
103
|
-
receipt: ReceiptSchema,
|
|
104
|
-
encryptedPayload: z.string().optional(), // For ktaEncrypted mode
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Storage configuration for different deployment modes
|
|
109
|
-
*/
|
|
110
|
-
export const StorageConfigSchema = z.object({
|
|
111
|
-
mode: StorageModeSchema,
|
|
112
|
-
encryptionEnabled: z.boolean().default(false),
|
|
113
|
-
receiptVerificationEnabled: z.boolean().default(true),
|
|
114
|
-
ktaBaseURL: z.string().url().default("https://knowthat.ai"),
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
// Type exports
|
|
118
|
-
export type RegistrationInput = z.infer<typeof RegistrationInputSchema>;
|
|
119
|
-
export type RegistrationResult = z.infer<typeof RegistrationResultSchema>;
|
|
120
|
-
export type ClaimToken = z.infer<typeof ClaimTokenSchema>;
|
|
121
|
-
export type MirrorStatus = z.infer<typeof MirrorStatusSchema>;
|
|
122
|
-
export type AgentStatus = z.infer<typeof AgentStatusSchema>;
|
|
123
|
-
export type StorageMode = z.infer<typeof StorageModeSchema>;
|
|
124
|
-
export type Receipt = z.infer<typeof ReceiptSchema>;
|
|
125
|
-
export type StorageConfig = z.infer<typeof StorageConfigSchema>;
|
|
126
|
-
export type Delegation = z.infer<typeof DelegationSchema>;
|
|
127
|
-
export type DelegationRequest = z.infer<typeof DelegationRequestSchema>;
|
|
128
|
-
export type DelegationResponse = z.infer<typeof DelegationResponseSchema>;
|
|
129
|
-
|
|
130
|
-
// Constants
|
|
131
|
-
export const MCP_I_CAPABILITIES = [
|
|
132
|
-
"handshake",
|
|
133
|
-
"signing",
|
|
134
|
-
"verification",
|
|
135
|
-
] as const;
|
|
136
|
-
export const CLAIM_TOKEN_TTL_HOURS = 24;
|
|
137
|
-
export const KTA_BASE_URL = "https://knowthat.ai"; // Placeholder for docs/tests
|
|
138
|
-
|
|
139
|
-
// Storage mode constants
|
|
140
|
-
export const DEFAULT_STORAGE_MODE: StorageMode = "ktaEncrypted";
|
|
141
|
-
export const STORAGE_MODE_ENV_VAR = "MCPI_STORAGE_MODE";
|
|
142
|
-
|
|
143
|
-
// Receipt schema constants
|
|
144
|
-
export const RECEIPT_SCHEMA_ID =
|
|
145
|
-
"https://schemas.kya-os.ai/mcpi/receipt/v1.0.0.json";
|
|
146
|
-
export const CONTENT_HASH_REGEX = /^sha256:[a-f0-9]{64}$/;
|
package/src/runtime/errors.ts
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Runtime Error Contracts
|
|
3
|
-
*
|
|
4
|
-
* Error types and schemas for runtime errors, especially authorization errors
|
|
5
|
-
*
|
|
6
|
-
* Related Spec: MCP-I §6
|
|
7
|
-
* Python Reference: Core-Documentation.md
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { z } from 'zod';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Display hint types for authorization UI
|
|
14
|
-
*/
|
|
15
|
-
export const DisplayHintSchema = z.enum(['link', 'qr', 'code']);
|
|
16
|
-
export type DisplayHint = z.infer<typeof DisplayHintSchema>;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Display options for authorization flow
|
|
20
|
-
*/
|
|
21
|
-
export const AuthorizationDisplaySchema = z.object({
|
|
22
|
-
/** Optional title for the authorization screen */
|
|
23
|
-
title: z.string().optional(),
|
|
24
|
-
|
|
25
|
-
/** Hints for how to display authorization (link, QR code, or code) */
|
|
26
|
-
hint: z.array(DisplayHintSchema).optional(),
|
|
27
|
-
|
|
28
|
-
/** Optional short authorization code */
|
|
29
|
-
authorizationCode: z.string().optional(),
|
|
30
|
-
|
|
31
|
-
/** Optional QR code URL */
|
|
32
|
-
qrUrl: z.string().url().optional(),
|
|
33
|
-
}).passthrough();
|
|
34
|
-
|
|
35
|
-
export type AuthorizationDisplay = z.infer<typeof AuthorizationDisplaySchema>;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* NeedsAuthorizationError Schema
|
|
39
|
-
*
|
|
40
|
-
* Error returned when a request requires authorization.
|
|
41
|
-
* Includes a resumeToken and authorizationUrl for the authorization flow.
|
|
42
|
-
*/
|
|
43
|
-
export const NeedsAuthorizationErrorSchema = z.object({
|
|
44
|
-
/** Error code */
|
|
45
|
-
error: z.literal('needs_authorization'),
|
|
46
|
-
|
|
47
|
-
/** Human-readable error message */
|
|
48
|
-
message: z.string().min(1),
|
|
49
|
-
|
|
50
|
-
/** URL for the user to authorize (includes resume token) */
|
|
51
|
-
authorizationUrl: z.string().url(),
|
|
52
|
-
|
|
53
|
-
/** Short-lived resume token for continuing after authorization */
|
|
54
|
-
resumeToken: z.string().min(1),
|
|
55
|
-
|
|
56
|
-
/** Expiration timestamp for the resume token (milliseconds since epoch) */
|
|
57
|
-
expiresAt: z.number().int().positive(),
|
|
58
|
-
|
|
59
|
-
/** Required scopes for authorization */
|
|
60
|
-
scopes: z.array(z.string()),
|
|
61
|
-
|
|
62
|
-
/** Optional display configuration for authorization UI */
|
|
63
|
-
display: AuthorizationDisplaySchema.optional(),
|
|
64
|
-
|
|
65
|
-
/** Optional additional context */
|
|
66
|
-
context: z.record(z.any()).optional(),
|
|
67
|
-
}).passthrough();
|
|
68
|
-
|
|
69
|
-
export type NeedsAuthorizationError = z.infer<typeof NeedsAuthorizationErrorSchema>;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Generic Error Schema
|
|
73
|
-
*
|
|
74
|
-
* Standard error format for all runtime errors
|
|
75
|
-
*/
|
|
76
|
-
export const RuntimeErrorSchema = z.object({
|
|
77
|
-
/** Error code */
|
|
78
|
-
error: z.string().min(1),
|
|
79
|
-
|
|
80
|
-
/** Human-readable error message */
|
|
81
|
-
message: z.string().min(1),
|
|
82
|
-
|
|
83
|
-
/** Optional error details */
|
|
84
|
-
details: z.record(z.any()).optional(),
|
|
85
|
-
|
|
86
|
-
/** HTTP status code (if applicable) */
|
|
87
|
-
httpStatus: z.number().int().min(400).max(599).optional(),
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
export type RuntimeError = z.infer<typeof RuntimeErrorSchema>;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Validation Helpers
|
|
94
|
-
*/
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Validate a needs authorization error
|
|
98
|
-
*
|
|
99
|
-
* @param error - The error to validate
|
|
100
|
-
* @returns Validation result
|
|
101
|
-
*/
|
|
102
|
-
export function validateNeedsAuthorizationError(error: unknown) {
|
|
103
|
-
return NeedsAuthorizationErrorSchema.safeParse(error);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Check if error is a needs authorization error
|
|
108
|
-
*
|
|
109
|
-
* @param error - The error to check
|
|
110
|
-
* @returns true if it's a needs authorization error
|
|
111
|
-
*/
|
|
112
|
-
export function isNeedsAuthorizationError(error: any): error is NeedsAuthorizationError {
|
|
113
|
-
return error && error.error === 'needs_authorization';
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Create a needs authorization error
|
|
118
|
-
*
|
|
119
|
-
* @param config - Configuration for the error
|
|
120
|
-
* @returns NeedsAuthorizationError instance
|
|
121
|
-
*/
|
|
122
|
-
export function createNeedsAuthorizationError(config: {
|
|
123
|
-
message: string;
|
|
124
|
-
authorizationUrl: string;
|
|
125
|
-
resumeToken: string;
|
|
126
|
-
expiresAt: number;
|
|
127
|
-
scopes: string[];
|
|
128
|
-
display?: AuthorizationDisplay;
|
|
129
|
-
}): NeedsAuthorizationError {
|
|
130
|
-
return {
|
|
131
|
-
error: 'needs_authorization',
|
|
132
|
-
...config,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Constants
|
|
138
|
-
*/
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Error codes
|
|
142
|
-
*/
|
|
143
|
-
export const ERROR_CODES = Object.freeze({
|
|
144
|
-
NEEDS_AUTHORIZATION: 'needs_authorization',
|
|
145
|
-
INVALID_TOKEN: 'invalid_token',
|
|
146
|
-
TOKEN_EXPIRED: 'token_expired',
|
|
147
|
-
INSUFFICIENT_SCOPE: 'insufficient_scope',
|
|
148
|
-
INVALID_SIGNATURE: 'invalid_signature',
|
|
149
|
-
DELEGATION_REVOKED: 'delegation_revoked',
|
|
150
|
-
CREDENTIAL_REVOKED: 'credential_revoked',
|
|
151
|
-
} as const);
|
|
152
|
-
|
|
153
|
-
export type ErrorCode = typeof ERROR_CODES[keyof typeof ERROR_CODES];
|
package/src/runtime/headers.ts
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Runtime Header Contracts
|
|
3
|
-
*
|
|
4
|
-
* Header contracts for downstream services
|
|
5
|
-
*
|
|
6
|
-
* Related Spec: MCP-I §6
|
|
7
|
-
* Python Reference: Core-Documentation.md
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Downstream Headers Interface
|
|
12
|
-
*
|
|
13
|
-
* Headers passed to downstream services after verification
|
|
14
|
-
*/
|
|
15
|
-
export interface DownstreamHeaders {
|
|
16
|
-
/** DID of the verified agent */
|
|
17
|
-
'X-Agent-DID': string;
|
|
18
|
-
|
|
19
|
-
/** Optional delegation ID */
|
|
20
|
-
'X-Delegation-Id'?: string;
|
|
21
|
-
|
|
22
|
-
/** Optional delegation chain (format: vc_id>del_id>...) */
|
|
23
|
-
'X-Delegation-Chain'?: string;
|
|
24
|
-
|
|
25
|
-
/** Proof ID for audit trail */
|
|
26
|
-
'X-MCPI-Proof-Id': string;
|
|
27
|
-
|
|
28
|
-
/** Optional CRISP spend info (JSON string: {unit, delta, remaining}) */
|
|
29
|
-
'X-CRISP-Spend'?: string;
|
|
30
|
-
|
|
31
|
-
/** Optional session ID */
|
|
32
|
-
'X-Session-Id'?: string;
|
|
33
|
-
|
|
34
|
-
/** Optional scopes */
|
|
35
|
-
'X-Scopes'?: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Header names as constants for type safety
|
|
40
|
-
*/
|
|
41
|
-
export const DOWNSTREAM_HEADER_NAMES = Object.freeze({
|
|
42
|
-
AGENT_DID: 'X-Agent-DID',
|
|
43
|
-
DELEGATION_ID: 'X-Delegation-Id',
|
|
44
|
-
DELEGATION_CHAIN: 'X-Delegation-Chain',
|
|
45
|
-
PROOF_ID: 'X-MCPI-Proof-Id',
|
|
46
|
-
CRISP_SPEND: 'X-CRISP-Spend',
|
|
47
|
-
SESSION_ID: 'X-Session-Id',
|
|
48
|
-
SCOPES: 'X-Scopes',
|
|
49
|
-
} as const);
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* CRISP Spend Info
|
|
53
|
-
*
|
|
54
|
-
* Structure for X-CRISP-Spend header value
|
|
55
|
-
*/
|
|
56
|
-
export interface CrispSpendInfo {
|
|
57
|
-
/** Unit of spending */
|
|
58
|
-
unit: 'USD' | 'ops' | 'points';
|
|
59
|
-
|
|
60
|
-
/** Amount spent in this request */
|
|
61
|
-
delta?: number;
|
|
62
|
-
|
|
63
|
-
/** Remaining budget */
|
|
64
|
-
remaining?: number;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Helper to serialize CRISP spend info to header value
|
|
69
|
-
*
|
|
70
|
-
* @param info - CRISP spend info
|
|
71
|
-
* @returns JSON string for header
|
|
72
|
-
*/
|
|
73
|
-
export function serializeCrispSpend(info: CrispSpendInfo): string {
|
|
74
|
-
return JSON.stringify(info);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Helper to parse CRISP spend info from header value
|
|
79
|
-
*
|
|
80
|
-
* @param headerValue - JSON string from header
|
|
81
|
-
* @returns Parsed CRISP spend info or null if invalid
|
|
82
|
-
*/
|
|
83
|
-
export function parseCrispSpend(headerValue: string): CrispSpendInfo | null {
|
|
84
|
-
try {
|
|
85
|
-
const parsed = JSON.parse(headerValue);
|
|
86
|
-
if (parsed && typeof parsed.unit === 'string') {
|
|
87
|
-
return parsed as CrispSpendInfo;
|
|
88
|
-
}
|
|
89
|
-
return null;
|
|
90
|
-
} catch {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Helper to create downstream headers
|
|
97
|
-
*
|
|
98
|
-
* @param config - Configuration for headers
|
|
99
|
-
* @returns DownstreamHeaders object
|
|
100
|
-
*/
|
|
101
|
-
export function createDownstreamHeaders(config: {
|
|
102
|
-
agentDid: string;
|
|
103
|
-
proofId: string;
|
|
104
|
-
delegationId?: string;
|
|
105
|
-
delegationChain?: string;
|
|
106
|
-
crispSpend?: CrispSpendInfo;
|
|
107
|
-
sessionId?: string;
|
|
108
|
-
scopes?: string[];
|
|
109
|
-
}): DownstreamHeaders {
|
|
110
|
-
const headers: DownstreamHeaders = {
|
|
111
|
-
'X-Agent-DID': config.agentDid,
|
|
112
|
-
'X-MCPI-Proof-Id': config.proofId,
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
if (config.delegationId) {
|
|
116
|
-
headers['X-Delegation-Id'] = config.delegationId;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (config.delegationChain) {
|
|
120
|
-
headers['X-Delegation-Chain'] = config.delegationChain;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (config.crispSpend) {
|
|
124
|
-
headers['X-CRISP-Spend'] = serializeCrispSpend(config.crispSpend);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (config.sessionId) {
|
|
128
|
-
headers['X-Session-Id'] = config.sessionId;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (config.scopes && config.scopes.length > 0) {
|
|
132
|
-
headers['X-Scopes'] = config.scopes.join(',');
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return headers;
|
|
136
|
-
}
|
package/src/runtime/index.ts
DELETED
package/src/test.ts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Test infrastructure types and schemas for XMCP-I
|
|
3
|
-
*
|
|
4
|
-
* This module provides types and utilities for testing XMCP-I applications
|
|
5
|
-
* without hitting external services like KTA.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { z } from "zod";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Test environment configuration
|
|
12
|
-
*/
|
|
13
|
-
export const TestEnvironmentSchema = z.object({
|
|
14
|
-
mode: z.literal("test"),
|
|
15
|
-
seed: z.string().optional(),
|
|
16
|
-
deterministicKeys: z.boolean().default(true),
|
|
17
|
-
skipKTACalls: z.boolean().default(true),
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
export type TestEnvironment = z.infer<typeof TestEnvironmentSchema>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Mock identity configuration for testing
|
|
24
|
-
*/
|
|
25
|
-
export const MockIdentitySchema = z.object({
|
|
26
|
-
did: z.string(),
|
|
27
|
-
kid: z.string(),
|
|
28
|
-
privateKey: z.string().regex(/^[A-Za-z0-9+/]{43}=$/, "Must be a valid base64-encoded Ed25519 private key (44 characters)"),
|
|
29
|
-
publicKey: z.string().regex(/^[A-Za-z0-9+/]{43}=$/, "Must be a valid base64-encoded Ed25519 public key (44 characters)"),
|
|
30
|
-
createdAt: z.string(),
|
|
31
|
-
lastRotated: z.string().optional(),
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
export type MockIdentity = z.infer<typeof MockIdentitySchema>;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Mock delegation status for testing
|
|
38
|
-
*/
|
|
39
|
-
export const MockDelegationStatusSchema = z.enum([
|
|
40
|
-
"active",
|
|
41
|
-
"revoked",
|
|
42
|
-
"pending",
|
|
43
|
-
]);
|
|
44
|
-
export type MockDelegationStatus = z.infer<typeof MockDelegationStatusSchema>;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Mock KTA failure scenarios for testing
|
|
48
|
-
*/
|
|
49
|
-
export const MockKTAFailureTypeSchema = z.enum([
|
|
50
|
-
"network",
|
|
51
|
-
"auth",
|
|
52
|
-
"invalid",
|
|
53
|
-
"timeout",
|
|
54
|
-
]);
|
|
55
|
-
export type MockKTAFailureType = z.infer<typeof MockKTAFailureTypeSchema>;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Mock identity provider configuration
|
|
59
|
-
*/
|
|
60
|
-
export const MockIdentityProviderConfigSchema = z.object({
|
|
61
|
-
identities: z.record(z.string(), MockIdentitySchema),
|
|
62
|
-
delegations: z.record(z.string(), MockDelegationStatusSchema),
|
|
63
|
-
ktaFailures: z.array(MockKTAFailureTypeSchema).default([]),
|
|
64
|
-
deterministicSeed: z.string().optional(),
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
export type MockIdentityProviderConfig = z.infer<
|
|
68
|
-
typeof MockIdentityProviderConfigSchema
|
|
69
|
-
>;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Local verification result for offline testing
|
|
73
|
-
*/
|
|
74
|
-
export const LocalVerificationResultSchema = z.object({
|
|
75
|
-
valid: z.boolean(),
|
|
76
|
-
did: z.string().optional(),
|
|
77
|
-
kid: z.string().optional(),
|
|
78
|
-
signature: z.object({
|
|
79
|
-
valid: z.boolean(),
|
|
80
|
-
algorithm: z.string(),
|
|
81
|
-
error: z.string().optional(),
|
|
82
|
-
}),
|
|
83
|
-
proof: z.object({
|
|
84
|
-
valid: z.boolean(),
|
|
85
|
-
structure: z.boolean(),
|
|
86
|
-
timestamps: z.boolean(),
|
|
87
|
-
hashes: z.boolean(),
|
|
88
|
-
error: z.string().optional(),
|
|
89
|
-
}),
|
|
90
|
-
session: z.object({
|
|
91
|
-
valid: z.boolean(),
|
|
92
|
-
expired: z.boolean(),
|
|
93
|
-
error: z.string().optional(),
|
|
94
|
-
}),
|
|
95
|
-
errors: z.array(z.string()).default([]),
|
|
96
|
-
warnings: z.array(z.string()).default([]),
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
export type LocalVerificationResult = z.infer<
|
|
100
|
-
typeof LocalVerificationResultSchema
|
|
101
|
-
>;
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Test DID and Key ID constants
|
|
105
|
-
*/
|
|
106
|
-
export const TEST_DIDS = {
|
|
107
|
-
AGENT_1: "did:test:agent-1",
|
|
108
|
-
AGENT_2: "did:test:agent-2",
|
|
109
|
-
VERIFIER_1: "did:test:verifier-1",
|
|
110
|
-
} as const;
|
|
111
|
-
|
|
112
|
-
export const TEST_KEY_IDS = {
|
|
113
|
-
KEY_TEST_1: "key-test-1",
|
|
114
|
-
KEY_TEST_2: "key-test-2",
|
|
115
|
-
KEY_VERIFIER_1: "key-verifier-1",
|
|
116
|
-
} as const;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Test environment detection
|
|
120
|
-
*/
|
|
121
|
-
export function isTestEnvironment(): boolean {
|
|
122
|
-
return process.env.XMCP_ENV === "test";
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Get test seed from environment or test name
|
|
127
|
-
*/
|
|
128
|
-
export function getTestSeed(testName?: string): string {
|
|
129
|
-
return process.env.XMCP_TEST_SEED || testName || "default-test-seed";
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Error codes for test infrastructure
|
|
134
|
-
*/
|
|
135
|
-
export const TEST_ERROR_CODES = {
|
|
136
|
-
MOCK_KTA_FAILURE: "XMCP_I_TEST_MOCK_KTA_FAILURE",
|
|
137
|
-
DETERMINISTIC_KEY_GENERATION_FAILED: "XMCP_I_TEST_DETERMINISTIC_KEY_FAILED",
|
|
138
|
-
LOCAL_VERIFICATION_FAILED: "XMCP_I_TEST_LOCAL_VERIFICATION_FAILED",
|
|
139
|
-
INVALID_TEST_CONFIGURATION: "XMCP_I_TEST_INVALID_CONFIG",
|
|
140
|
-
} as const;
|
|
141
|
-
|
|
142
|
-
export type TestErrorCode =
|
|
143
|
-
(typeof TEST_ERROR_CODES)[keyof typeof TEST_ERROR_CODES];
|