@kya-os/mcp 1.7.0 → 1.9.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/CHANGELOG.md +69 -0
- package/README.md +219 -3
- package/dist/card/build.d.ts +41 -0
- package/dist/card/build.d.ts.map +1 -0
- package/dist/card/build.js +47 -0
- package/dist/card/build.js.map +1 -0
- package/dist/card/builder.d.ts +99 -0
- package/dist/card/builder.d.ts.map +1 -0
- package/dist/card/builder.js +147 -0
- package/dist/card/builder.js.map +1 -0
- package/dist/card/cimd.d.ts +92 -0
- package/dist/card/cimd.d.ts.map +1 -0
- package/dist/card/cimd.js +225 -0
- package/dist/card/cimd.js.map +1 -0
- package/dist/card/delegation.d.ts +145 -0
- package/dist/card/delegation.d.ts.map +1 -0
- package/dist/card/delegation.js +293 -0
- package/dist/card/delegation.js.map +1 -0
- package/dist/card/emit.d.ts +133 -0
- package/dist/card/emit.d.ts.map +1 -0
- package/dist/card/emit.js +127 -0
- package/dist/card/emit.js.map +1 -0
- package/dist/card/index.d.ts +43 -0
- package/dist/card/index.d.ts.map +1 -0
- package/dist/card/index.js +46 -0
- package/dist/card/index.js.map +1 -0
- package/dist/card/middleware.d.ts +112 -0
- package/dist/card/middleware.d.ts.map +1 -0
- package/dist/card/middleware.js +121 -0
- package/dist/card/middleware.js.map +1 -0
- package/dist/card/proof/build.d.ts +22 -0
- package/dist/card/proof/build.d.ts.map +1 -0
- package/dist/card/proof/build.js +55 -0
- package/dist/card/proof/build.js.map +1 -0
- package/dist/card/proof/canonical.d.ts +66 -0
- package/dist/card/proof/canonical.d.ts.map +1 -0
- package/dist/card/proof/canonical.js +131 -0
- package/dist/card/proof/canonical.js.map +1 -0
- package/dist/card/proof/http-sig.d.ts +69 -0
- package/dist/card/proof/http-sig.d.ts.map +1 -0
- package/dist/card/proof/http-sig.js +101 -0
- package/dist/card/proof/http-sig.js.map +1 -0
- package/dist/card/proof/index.d.ts +25 -0
- package/dist/card/proof/index.d.ts.map +1 -0
- package/dist/card/proof/index.js +25 -0
- package/dist/card/proof/index.js.map +1 -0
- package/dist/card/proof/nonce-cache.d.ts +67 -0
- package/dist/card/proof/nonce-cache.d.ts.map +1 -0
- package/dist/card/proof/nonce-cache.js +88 -0
- package/dist/card/proof/nonce-cache.js.map +1 -0
- package/dist/card/proof/signer.d.ts +32 -0
- package/dist/card/proof/signer.d.ts.map +1 -0
- package/dist/card/proof/signer.js +59 -0
- package/dist/card/proof/signer.js.map +1 -0
- package/dist/card/proof/types.d.ts +219 -0
- package/dist/card/proof/types.d.ts.map +1 -0
- package/dist/card/proof/types.js +87 -0
- package/dist/card/proof/types.js.map +1 -0
- package/dist/card/proof/verify.d.ts +27 -0
- package/dist/card/proof/verify.d.ts.map +1 -0
- package/dist/card/proof/verify.js +236 -0
- package/dist/card/proof/verify.js.map +1 -0
- package/dist/card/resolve.d.ts +97 -0
- package/dist/card/resolve.d.ts.map +1 -0
- package/dist/card/resolve.js +223 -0
- package/dist/card/resolve.js.map +1 -0
- package/dist/card/revocation.d.ts +96 -0
- package/dist/card/revocation.d.ts.map +1 -0
- package/dist/card/revocation.js +190 -0
- package/dist/card/revocation.js.map +1 -0
- package/dist/card/schema.d.ts +177 -0
- package/dist/card/schema.d.ts.map +1 -0
- package/dist/card/schema.js +119 -0
- package/dist/card/schema.js.map +1 -0
- package/dist/card/verify.d.ts +144 -0
- package/dist/card/verify.d.ts.map +1 -0
- package/dist/card/verify.js +132 -0
- package/dist/card/verify.js.map +1 -0
- package/dist/delegation/bitstring.d.ts +9 -7
- package/dist/delegation/bitstring.d.ts.map +1 -1
- package/dist/delegation/bitstring.js +70 -37
- package/dist/delegation/bitstring.js.map +1 -1
- package/dist/delegation/did-linkage.d.ts +23 -0
- package/dist/delegation/did-linkage.d.ts.map +1 -0
- package/dist/delegation/did-linkage.js +57 -0
- package/dist/delegation/did-linkage.js.map +1 -0
- package/dist/delegation/did-resolver-registry.d.ts +7 -0
- package/dist/delegation/did-resolver-registry.d.ts.map +1 -0
- package/dist/delegation/did-resolver-registry.js +20 -0
- package/dist/delegation/did-resolver-registry.js.map +1 -0
- package/dist/delegation/did-web-resolver.d.ts +29 -18
- package/dist/delegation/did-web-resolver.d.ts.map +1 -1
- package/dist/delegation/did-web-resolver.js +65 -35
- package/dist/delegation/did-web-resolver.js.map +1 -1
- package/dist/delegation/index.d.ts +3 -0
- package/dist/delegation/index.d.ts.map +1 -1
- package/dist/delegation/index.js +3 -0
- package/dist/delegation/index.js.map +1 -1
- package/dist/delegation/statuslist-manager.d.ts.map +1 -1
- package/dist/delegation/statuslist-manager.js +16 -1
- package/dist/delegation/statuslist-manager.js.map +1 -1
- package/dist/delegation/vc-jwt-verify.d.ts +61 -0
- package/dist/delegation/vc-jwt-verify.d.ts.map +1 -0
- package/dist/delegation/vc-jwt-verify.js +131 -0
- package/dist/delegation/vc-jwt-verify.js.map +1 -0
- package/dist/delegation/vc-verification-checks.d.ts +50 -0
- package/dist/delegation/vc-verification-checks.d.ts.map +1 -0
- package/dist/delegation/vc-verification-checks.js +212 -0
- package/dist/delegation/vc-verification-checks.js.map +1 -0
- package/dist/delegation/vc-verifier.d.ts +24 -61
- package/dist/delegation/vc-verifier.d.ts.map +1 -1
- package/dist/delegation/vc-verifier.js +57 -180
- package/dist/delegation/vc-verifier.js.map +1 -1
- package/dist/delegation/vc-verifier.types.d.ts +88 -0
- package/dist/delegation/vc-verifier.types.d.ts.map +1 -0
- package/dist/delegation/vc-verifier.types.js +9 -0
- package/dist/delegation/vc-verifier.types.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/integrations/cheqd/dlr.d.ts +44 -0
- package/dist/integrations/cheqd/dlr.d.ts.map +1 -0
- package/dist/integrations/cheqd/dlr.js +86 -0
- package/dist/integrations/cheqd/dlr.js.map +1 -0
- package/dist/integrations/cheqd/index.d.ts +5 -0
- package/dist/integrations/cheqd/index.d.ts.map +1 -0
- package/dist/integrations/cheqd/index.js +5 -0
- package/dist/integrations/cheqd/index.js.map +1 -0
- package/dist/integrations/cheqd/linkage.d.ts +20 -0
- package/dist/integrations/cheqd/linkage.d.ts.map +1 -0
- package/dist/integrations/cheqd/linkage.js +32 -0
- package/dist/integrations/cheqd/linkage.js.map +1 -0
- package/dist/integrations/cheqd/registrar.d.ts +85 -0
- package/dist/integrations/cheqd/registrar.d.ts.map +1 -0
- package/dist/integrations/cheqd/registrar.js +304 -0
- package/dist/integrations/cheqd/registrar.js.map +1 -0
- package/dist/integrations/cheqd/resolver.d.ts +38 -0
- package/dist/integrations/cheqd/resolver.d.ts.map +1 -0
- package/dist/integrations/cheqd/resolver.js +156 -0
- package/dist/integrations/cheqd/resolver.js.map +1 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/middleware/index.js +5 -0
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/with-kya-os.config-types.d.ts +139 -0
- package/dist/middleware/with-kya-os.config-types.d.ts.map +1 -0
- package/dist/middleware/with-kya-os.config-types.js +9 -0
- package/dist/middleware/with-kya-os.config-types.js.map +1 -0
- package/dist/middleware/with-kya-os.d.ts +3 -267
- package/dist/middleware/with-kya-os.d.ts.map +1 -1
- package/dist/middleware/with-kya-os.delegation-gate.d.ts +19 -0
- package/dist/middleware/with-kya-os.delegation-gate.d.ts.map +1 -0
- package/dist/middleware/with-kya-os.delegation-gate.js +175 -0
- package/dist/middleware/with-kya-os.delegation-gate.js.map +1 -0
- package/dist/middleware/with-kya-os.delegation-verify.d.ts +51 -0
- package/dist/middleware/with-kya-os.delegation-verify.d.ts.map +1 -0
- package/dist/middleware/with-kya-os.delegation-verify.js +165 -0
- package/dist/middleware/with-kya-os.delegation-verify.js.map +1 -0
- package/dist/middleware/with-kya-os.deps.d.ts +40 -0
- package/dist/middleware/with-kya-os.deps.d.ts.map +1 -0
- package/dist/middleware/with-kya-os.deps.js +9 -0
- package/dist/middleware/with-kya-os.deps.js.map +1 -0
- package/dist/middleware/with-kya-os.grants.d.ts +30 -0
- package/dist/middleware/with-kya-os.grants.d.ts.map +1 -0
- package/dist/middleware/with-kya-os.grants.js +145 -0
- package/dist/middleware/with-kya-os.grants.js.map +1 -0
- package/dist/middleware/with-kya-os.helpers.d.ts +24 -0
- package/dist/middleware/with-kya-os.helpers.d.ts.map +1 -0
- package/dist/middleware/with-kya-os.helpers.js +57 -0
- package/dist/middleware/with-kya-os.helpers.js.map +1 -0
- package/dist/middleware/with-kya-os.js +45 -891
- package/dist/middleware/with-kya-os.js.map +1 -1
- package/dist/middleware/with-kya-os.policy-gate.d.ts +16 -0
- package/dist/middleware/with-kya-os.policy-gate.d.ts.map +1 -0
- package/dist/middleware/with-kya-os.policy-gate.js +98 -0
- package/dist/middleware/with-kya-os.policy-gate.js.map +1 -0
- package/dist/middleware/with-kya-os.protocol.d.ts +29 -0
- package/dist/middleware/with-kya-os.protocol.d.ts.map +1 -0
- package/dist/middleware/with-kya-os.protocol.js +121 -0
- package/dist/middleware/with-kya-os.protocol.js.map +1 -0
- package/dist/middleware/with-kya-os.session.d.ts +32 -0
- package/dist/middleware/with-kya-os.session.d.ts.map +1 -0
- package/dist/middleware/with-kya-os.session.js +201 -0
- package/dist/middleware/with-kya-os.session.js.map +1 -0
- package/dist/middleware/with-kya-os.types.d.ts +178 -0
- package/dist/middleware/with-kya-os.types.d.ts.map +1 -0
- package/dist/middleware/with-kya-os.types.js +13 -0
- package/dist/middleware/with-kya-os.types.js.map +1 -0
- package/dist/providers/runtime-fetch.d.ts +8 -0
- package/dist/providers/runtime-fetch.d.ts.map +1 -1
- package/dist/providers/runtime-fetch.js +17 -0
- package/dist/providers/runtime-fetch.js.map +1 -1
- package/dist/providers/web-crypto.d.ts.map +1 -1
- package/dist/providers/web-crypto.js +15 -7
- package/dist/providers/web-crypto.js.map +1 -1
- package/dist/utils/guards.d.ts +2 -0
- package/dist/utils/guards.d.ts.map +1 -0
- package/dist/utils/guards.js +4 -0
- package/dist/utils/guards.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/ip-classifier.d.ts +12 -0
- package/dist/utils/ip-classifier.d.ts.map +1 -0
- package/dist/utils/ip-classifier.js +153 -0
- package/dist/utils/ip-classifier.js.map +1 -0
- package/dist/utils/safe-fetch-transports.d.ts +40 -0
- package/dist/utils/safe-fetch-transports.d.ts.map +1 -0
- package/dist/utils/safe-fetch-transports.js +121 -0
- package/dist/utils/safe-fetch-transports.js.map +1 -0
- package/dist/utils/safe-fetch-types.d.ts +66 -0
- package/dist/utils/safe-fetch-types.d.ts.map +1 -0
- package/dist/utils/safe-fetch-types.js +10 -0
- package/dist/utils/safe-fetch-types.js.map +1 -0
- package/dist/utils/safe-fetch.d.ts +40 -0
- package/dist/utils/safe-fetch.d.ts.map +1 -0
- package/dist/utils/safe-fetch.js +188 -0
- package/dist/utils/safe-fetch.js.map +1 -0
- package/dist/utils/statuslist-purpose.d.ts +12 -0
- package/dist/utils/statuslist-purpose.d.ts.map +1 -0
- package/dist/utils/statuslist-purpose.js +19 -0
- package/dist/utils/statuslist-purpose.js.map +1 -0
- package/dist/utils/url.d.ts +2 -0
- package/dist/utils/url.d.ts.map +1 -0
- package/dist/utils/url.js +8 -0
- package/dist/utils/url.js.map +1 -0
- package/package.json +25 -5
- package/schemas/README.md +2 -1
- package/schemas/card-delegation-credential.json +239 -0
- package/schemas/kya-os-card.schema.json +284 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KYA-OS Entity Card — DELEGATION (W3C VC 2.0 + ZCAP-LD profile, CRISP attenuation).
|
|
3
|
+
*
|
|
4
|
+
* A DelegationCredential is a W3C VC 2.0 whose `credentialSubject` IS an attenuated ZCAP-LD
|
|
5
|
+
* capability (`@context` carries `w3id.org/security/zcap/v1` + the KYA-OS delegation namespace).
|
|
6
|
+
* One credential per HOP; a delegation CHAIN runs `root → … → leaf`. We PROFILE, not fork.
|
|
7
|
+
*
|
|
8
|
+
* CRISP attenuation is enforced structurally on resolve and is FAIL-CLOSED — any broadening hop
|
|
9
|
+
* invalidates the whole chain: child `allowedAction` ⊆ parent; caveats monotone-narrowing (child
|
|
10
|
+
* `MaxAmount`/`ValidUntil` ≤ parent, no parent caveat silently dropped, unknown caveats replicated
|
|
11
|
+
* verbatim); top-level `validUntil` narrowing; CONTINUITY (the parent's delegate `invoker` MUST be
|
|
12
|
+
* the child's `issuer` — you only re-delegate what was delegated to YOUR key — and
|
|
13
|
+
* `child.parentCapability` references the parent `id`); a constant `invocationTarget`; depth ≤
|
|
14
|
+
* {@link MAX_DELEGATION_DEPTH}; ROOT `parentCapability` = the resource, `issuer`/`invocationTarget`
|
|
15
|
+
* = (optional) resource owner / resource. THE JOIN (recomputed, asserted nowhere):
|
|
16
|
+
* {@link responsiblePartyOf} = `issuer(rootVC)`, {@link leafInvokerOf} = the leaf delegate a verifier
|
|
17
|
+
* asserts equals `proof.did`. Revocation reuses the injected {@link RevocationChecker} seam from
|
|
18
|
+
* `./revocation` (no status-list churn reaches callers; NO `mcp-i-core` runtime dep). Per-hop
|
|
19
|
+
* signature verification is a SEPARATE injected concern; this module owns the CRISP + continuity recompute.
|
|
20
|
+
*/
|
|
21
|
+
import { z } from 'zod';
|
|
22
|
+
import { Did } from './schema.js';
|
|
23
|
+
import { evaluateRevocationChain, } from './revocation.js';
|
|
24
|
+
export const DELEGATION_CONTEXT_V2 = 'https://www.w3.org/ns/credentials/v2'; // VC 2.0 base `@context`
|
|
25
|
+
export const ZCAP_CONTEXT = 'https://w3id.org/security/zcap/v1'; // ZCAP-LD capability context
|
|
26
|
+
export const KYA_OS_DELEGATION_CONTEXT = 'https://kya-os.org/ns/delegation/v1'; // KYA-OS ns
|
|
27
|
+
export const DELEGATION_CREDENTIAL_TYPE = 'DelegationCredential'; // 2nd `type` after VerifiableCredential
|
|
28
|
+
export const MAX_DELEGATION_DEPTH = 10; // fail-closed beyond this
|
|
29
|
+
/** A monotone-narrowing constraint: `{type:'ValidUntil',date}` or `{type:'MaxAmount',limit,currency}`.
|
|
30
|
+
* The flat shape keeps typing clean; unknown caveat types are compared verbatim (fail-closed). */
|
|
31
|
+
export const CaveatSchema = z
|
|
32
|
+
.object({
|
|
33
|
+
type: z.string().min(1),
|
|
34
|
+
date: z.string().optional(),
|
|
35
|
+
limit: z.string().optional(),
|
|
36
|
+
currency: z.string().optional(),
|
|
37
|
+
})
|
|
38
|
+
.passthrough();
|
|
39
|
+
/** The attenuated ZCAP capability carried as the VC `credentialSubject`. */
|
|
40
|
+
export const ZcapCapabilitySchema = z
|
|
41
|
+
.object({
|
|
42
|
+
id: z.string().min(1),
|
|
43
|
+
controller: Did.optional(),
|
|
44
|
+
invoker: Did.optional(),
|
|
45
|
+
parentCapability: z.string().min(1),
|
|
46
|
+
invocationTarget: z.string().min(1),
|
|
47
|
+
allowedAction: z.array(z.string().min(1)),
|
|
48
|
+
caveats: z.array(CaveatSchema).optional(),
|
|
49
|
+
})
|
|
50
|
+
.passthrough()
|
|
51
|
+
.refine((s) => Boolean(s.controller ?? s.invoker), {
|
|
52
|
+
message: 'ZCAP capability MUST name a controller or invoker (the delegate)',
|
|
53
|
+
});
|
|
54
|
+
/** W3C Bitstring Status List v1.0 `credentialStatus` entry (the StatusList2021 successor). */
|
|
55
|
+
export const DelegationCredentialStatusSchema = z.object({
|
|
56
|
+
id: z.string().optional(),
|
|
57
|
+
type: z.literal('BitstringStatusListEntry'),
|
|
58
|
+
statusPurpose: z.string().optional(),
|
|
59
|
+
statusListIndex: z.string().min(1),
|
|
60
|
+
statusListCredential: z.string().min(1),
|
|
61
|
+
});
|
|
62
|
+
/** Data Integrity proof, `eddsa-jcs-2022` cryptosuite (verified by a separate injected seam). */
|
|
63
|
+
export const DataIntegrityProofSchema = z
|
|
64
|
+
.object({ type: z.literal('DataIntegrityProof'), cryptosuite: z.literal('eddsa-jcs-2022') })
|
|
65
|
+
.passthrough();
|
|
66
|
+
const IssuerSchema = z.union([Did, z.object({ id: Did }).passthrough()]);
|
|
67
|
+
export const DelegationCredentialSchema = z
|
|
68
|
+
.object({
|
|
69
|
+
// >= 2 to match the published JSON Schema (VC 2.0 base + the ZCAP/KYA-OS delegation contexts).
|
|
70
|
+
'@context': z.array(z.union([z.string(), z.record(z.string(), z.unknown())])).min(2),
|
|
71
|
+
id: z.string().optional(),
|
|
72
|
+
type: z.array(z.string()),
|
|
73
|
+
issuer: IssuerSchema,
|
|
74
|
+
validFrom: z.string().optional(),
|
|
75
|
+
validUntil: z.string().optional(),
|
|
76
|
+
credentialSubject: ZcapCapabilitySchema,
|
|
77
|
+
credentialStatus: DelegationCredentialStatusSchema.optional(),
|
|
78
|
+
proof: DataIntegrityProofSchema.optional(),
|
|
79
|
+
})
|
|
80
|
+
.passthrough();
|
|
81
|
+
/** The issuer (delegator) DID, whether `issuer` is a bare string or an `{id}` object. */
|
|
82
|
+
export function issuerDid(vc) {
|
|
83
|
+
return typeof vc.issuer === 'string' ? vc.issuer : vc.issuer.id;
|
|
84
|
+
}
|
|
85
|
+
/** The delegate DID granted this capability (`invoker`, falling back to `controller`). */
|
|
86
|
+
export function invokerDid(vc) {
|
|
87
|
+
return vc.credentialSubject.invoker ?? vc.credentialSubject.controller;
|
|
88
|
+
}
|
|
89
|
+
/** `responsibleParty` = the issuer of the ROOT VC (ultimately accountable). */
|
|
90
|
+
export function responsiblePartyOf(chain) {
|
|
91
|
+
const root = chain[0];
|
|
92
|
+
return root ? issuerDid(root) : undefined;
|
|
93
|
+
}
|
|
94
|
+
/** The LEAF invoker — a verifier asserts this equals `proof.did`. */
|
|
95
|
+
export function leafInvokerOf(chain) {
|
|
96
|
+
const leaf = chain[chain.length - 1];
|
|
97
|
+
return leaf ? invokerDid(leaf) : undefined;
|
|
98
|
+
}
|
|
99
|
+
/** Project a hop's `credentialStatus` onto the revocation-seam entry shape (if present). */
|
|
100
|
+
export function statusEntryOf(vc) {
|
|
101
|
+
const status = vc.credentialStatus;
|
|
102
|
+
if (!status)
|
|
103
|
+
return undefined;
|
|
104
|
+
return { statusListCredential: status.statusListCredential, statusListIndex: status.statusListIndex };
|
|
105
|
+
}
|
|
106
|
+
function toScaled(dec) {
|
|
107
|
+
const match = /^(\d+)(?:\.(\d+))?$/.exec(dec.trim());
|
|
108
|
+
if (!match?.[1])
|
|
109
|
+
return undefined;
|
|
110
|
+
const frac = (match[2] ?? '').padEnd(6, '0').slice(0, 6);
|
|
111
|
+
try {
|
|
112
|
+
return BigInt(match[1]) * 1000000n + BigInt(frac);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// `child ≤ parent`, fail-closed (any unparseable value ⇒ false).
|
|
119
|
+
function decimalLte(child, parent) {
|
|
120
|
+
const c = toScaled(child);
|
|
121
|
+
const p = toScaled(parent);
|
|
122
|
+
return c !== undefined && p !== undefined && c <= p;
|
|
123
|
+
}
|
|
124
|
+
function dateLte(child, parent) {
|
|
125
|
+
const c = Date.parse(child);
|
|
126
|
+
const p = Date.parse(parent);
|
|
127
|
+
return !Number.isNaN(c) && !Number.isNaN(p) && c <= p;
|
|
128
|
+
}
|
|
129
|
+
// Stable structural equality (sorted-key JSON) for verbatim unknown-caveat comparison.
|
|
130
|
+
function deepEqual(a, b) {
|
|
131
|
+
return JSON.stringify(sortKeys(a)) === JSON.stringify(sortKeys(b));
|
|
132
|
+
}
|
|
133
|
+
function sortKeys(value) {
|
|
134
|
+
if (Array.isArray(value))
|
|
135
|
+
return value.map(sortKeys);
|
|
136
|
+
if (value && typeof value === 'object') {
|
|
137
|
+
const record = value;
|
|
138
|
+
return Object.fromEntries(Object.keys(record).sort().map((k) => [k, sortKeys(record[k])]));
|
|
139
|
+
}
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
/** True iff `child` is at least as narrow as `parent` for the same caveat. */
|
|
143
|
+
function caveatNarrows(parent, child) {
|
|
144
|
+
if (parent.type !== child.type)
|
|
145
|
+
return false;
|
|
146
|
+
if (parent.type === 'ValidUntil') {
|
|
147
|
+
return typeof parent.date === 'string' && typeof child.date === 'string' && dateLte(child.date, parent.date);
|
|
148
|
+
}
|
|
149
|
+
if (parent.type === 'MaxAmount') {
|
|
150
|
+
// Currency is monotone, not strict-equal: a currency-LESS parent (any currency, per the optional
|
|
151
|
+
// schema) may be narrowed by a child that pins one; a parent that already pins a currency requires
|
|
152
|
+
// the SAME one (dropping/switching it broadens). Never fail-open — the amount must still narrow.
|
|
153
|
+
const currencyNarrows = parent.currency === undefined || parent.currency === child.currency;
|
|
154
|
+
return (currencyNarrows &&
|
|
155
|
+
typeof parent.limit === 'string' &&
|
|
156
|
+
typeof child.limit === 'string' &&
|
|
157
|
+
decimalLte(child.limit, parent.limit));
|
|
158
|
+
}
|
|
159
|
+
return deepEqual(parent, child); // unknown caveat type — must be replicated verbatim
|
|
160
|
+
}
|
|
161
|
+
function actionReasons(parent, child) {
|
|
162
|
+
const parentSet = new Set(parent);
|
|
163
|
+
const escalated = child.filter((action) => !parentSet.has(action));
|
|
164
|
+
return escalated.length === 0 ? [] : [`allowedAction escalation: [${escalated.join(', ')}] ⊄ parent`];
|
|
165
|
+
}
|
|
166
|
+
function caveatReasons(parent, child) {
|
|
167
|
+
return parent
|
|
168
|
+
.filter((pc) => !child.some((cc) => caveatNarrows(pc, cc)))
|
|
169
|
+
.map((pc) => `caveat "${pc.type}" broadened or dropped by child (monotone-narrowing violated)`);
|
|
170
|
+
}
|
|
171
|
+
/** Reasons the `child` FAILS to attenuate its `parent` (empty ⇒ valid hop): action subset, caveat
|
|
172
|
+
* monotonicity, `validUntil` narrowing, invoker→issuer continuity, `parentCapability` linkage,
|
|
173
|
+
* constant `invocationTarget`. */
|
|
174
|
+
export function attenuates(parent, child) {
|
|
175
|
+
const p = parent.credentialSubject;
|
|
176
|
+
const c = child.credentialSubject;
|
|
177
|
+
const reasons = [
|
|
178
|
+
...actionReasons(p.allowedAction, c.allowedAction),
|
|
179
|
+
...caveatReasons(p.caveats ?? [], c.caveats ?? []),
|
|
180
|
+
];
|
|
181
|
+
if (parent.validUntil !== undefined && (child.validUntil === undefined || !dateLte(child.validUntil, parent.validUntil))) {
|
|
182
|
+
reasons.push('validUntil broadened: child must expire no later than its parent');
|
|
183
|
+
}
|
|
184
|
+
const delegate = invokerDid(parent);
|
|
185
|
+
if (delegate === undefined || delegate !== issuerDid(child)) {
|
|
186
|
+
reasons.push('broken continuity: parent invoker ≠ child issuer (only the delegate may re-delegate)');
|
|
187
|
+
}
|
|
188
|
+
if (c.parentCapability !== p.id) {
|
|
189
|
+
reasons.push('broken continuity: child.parentCapability ≠ parent capability id');
|
|
190
|
+
}
|
|
191
|
+
if (c.invocationTarget !== p.invocationTarget) {
|
|
192
|
+
reasons.push('invocationTarget drift: the resource must be constant along the chain');
|
|
193
|
+
}
|
|
194
|
+
return reasons;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Reasons any hop is temporally INVALID at `nowMs`: an expired top-level `validUntil` or `ValidUntil`
|
|
198
|
+
* caveat, or a not-yet-valid `validFrom`. Fail-closed on a present-but-unparseable timestamp. Empty ⇒
|
|
199
|
+
* every hop is inside its validity window. This is the wall-clock gate — CRISP narrowing only proves a
|
|
200
|
+
* child expires no later than its parent, which a FULLY-expired-but-well-attenuated chain still satisfies.
|
|
201
|
+
*/
|
|
202
|
+
function expiryReasons(chain, nowMs) {
|
|
203
|
+
const reasons = [];
|
|
204
|
+
chain.forEach((vc, i) => {
|
|
205
|
+
if (vc.validUntil !== undefined) {
|
|
206
|
+
const t = Date.parse(vc.validUntil);
|
|
207
|
+
if (Number.isNaN(t))
|
|
208
|
+
reasons.push(`hop ${i}: unparseable validUntil "${vc.validUntil}"`);
|
|
209
|
+
else if (t < nowMs)
|
|
210
|
+
reasons.push(`hop ${i}: expired (validUntil ${vc.validUntil} is in the past)`);
|
|
211
|
+
}
|
|
212
|
+
if (vc.validFrom !== undefined) {
|
|
213
|
+
const t = Date.parse(vc.validFrom);
|
|
214
|
+
if (Number.isNaN(t))
|
|
215
|
+
reasons.push(`hop ${i}: unparseable validFrom "${vc.validFrom}"`);
|
|
216
|
+
else if (t > nowMs)
|
|
217
|
+
reasons.push(`hop ${i}: not yet valid (validFrom ${vc.validFrom} is in the future)`);
|
|
218
|
+
}
|
|
219
|
+
for (const caveat of vc.credentialSubject.caveats ?? []) {
|
|
220
|
+
if (caveat.type === 'ValidUntil' && typeof caveat.date === 'string') {
|
|
221
|
+
const t = Date.parse(caveat.date);
|
|
222
|
+
if (Number.isNaN(t))
|
|
223
|
+
reasons.push(`hop ${i}: unparseable ValidUntil caveat "${caveat.date}"`);
|
|
224
|
+
else if (t < nowMs)
|
|
225
|
+
reasons.push(`hop ${i}: expired caveat (ValidUntil ${caveat.date} is in the past)`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
return reasons;
|
|
230
|
+
}
|
|
231
|
+
function rootReasons(root, ctx) {
|
|
232
|
+
const subject = root.credentialSubject;
|
|
233
|
+
const reasons = [];
|
|
234
|
+
if (subject.parentCapability !== subject.invocationTarget) {
|
|
235
|
+
reasons.push('root delegation: parentCapability MUST equal invocationTarget (the resource)');
|
|
236
|
+
}
|
|
237
|
+
if (ctx.resource !== undefined && subject.invocationTarget !== ctx.resource) {
|
|
238
|
+
reasons.push('root invocationTarget ≠ the expected resource');
|
|
239
|
+
}
|
|
240
|
+
if (ctx.resourceOwner !== undefined && issuerDid(root) !== ctx.resourceOwner) {
|
|
241
|
+
reasons.push('root issuer ≠ the resource owner (responsibleParty mismatch)');
|
|
242
|
+
}
|
|
243
|
+
return reasons;
|
|
244
|
+
}
|
|
245
|
+
/** Structurally validate a chain (CRISP + continuity), fail-closed. Signature + revocation
|
|
246
|
+
* are separate injected concerns (see {@link evaluateDelegationChain}). */
|
|
247
|
+
export function validateDelegationChain(chain, ctx = {}) {
|
|
248
|
+
const depth = chain.length;
|
|
249
|
+
const maxDepth = ctx.maxDepth ?? MAX_DELEGATION_DEPTH;
|
|
250
|
+
if (depth === 0) {
|
|
251
|
+
return { ok: false, reasons: ['empty delegation chain'], allowedAction: [], depth };
|
|
252
|
+
}
|
|
253
|
+
const root = chain[0];
|
|
254
|
+
const leaf = chain[depth - 1];
|
|
255
|
+
const reasons = [];
|
|
256
|
+
if (depth > maxDepth)
|
|
257
|
+
reasons.push(`delegation chain depth ${depth} exceeds the maximum of ${maxDepth}`);
|
|
258
|
+
reasons.push(...rootReasons(root, ctx));
|
|
259
|
+
for (let i = 1; i < depth; i += 1) {
|
|
260
|
+
reasons.push(...attenuates(chain[i - 1], chain[i]));
|
|
261
|
+
}
|
|
262
|
+
// Wall-clock gate: a chain can attenuate perfectly and still be fully EXPIRED. Default to real
|
|
263
|
+
// time so the gate is never silently skipped; deterministic callers inject `ctx.now`.
|
|
264
|
+
reasons.push(...expiryReasons(chain, (ctx.now ?? Date.now)()));
|
|
265
|
+
return {
|
|
266
|
+
ok: reasons.length === 0,
|
|
267
|
+
reasons,
|
|
268
|
+
responsibleParty: responsiblePartyOf(chain),
|
|
269
|
+
leafInvoker: leafInvokerOf(chain),
|
|
270
|
+
invocationTarget: leaf.credentialSubject.invocationTarget,
|
|
271
|
+
allowedAction: leaf.credentialSubject.allowedAction,
|
|
272
|
+
depth,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
/** Validate structure AND revocation: run {@link validateDelegationChain}, then (only if it passes —
|
|
276
|
+
* fail-closed) cascade the injected {@link RevocationChecker} root→leaf via
|
|
277
|
+
* {@link evaluateRevocationChain}. A revoked ancestor invalidates the subtree. */
|
|
278
|
+
export async function evaluateDelegationChain(chain, check, ctx = {}) {
|
|
279
|
+
const structural = validateDelegationChain(chain, ctx);
|
|
280
|
+
if (!structural.ok)
|
|
281
|
+
return { ...structural, fresh: false };
|
|
282
|
+
const entries = chain
|
|
283
|
+
.map(statusEntryOf)
|
|
284
|
+
.filter((entry) => entry !== undefined);
|
|
285
|
+
const revocation = await evaluateRevocationChain(entries, check);
|
|
286
|
+
return {
|
|
287
|
+
...structural,
|
|
288
|
+
ok: structural.ok && revocation.ok,
|
|
289
|
+
reasons: [...structural.reasons, ...revocation.reasons],
|
|
290
|
+
fresh: revocation.fresh,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
//# sourceMappingURL=delegation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegation.js","sourceRoot":"","sources":["../../src/card/delegation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,GAAG,EAAiC,MAAM,aAAa,CAAC;AACjE,OAAO,EACL,uBAAuB,GAGxB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,CAAC,MAAM,qBAAqB,GAAG,sCAAsC,CAAC,CAAC,yBAAyB;AACtG,MAAM,CAAC,MAAM,YAAY,GAAG,mCAAmC,CAAC,CAAC,6BAA6B;AAC9F,MAAM,CAAC,MAAM,yBAAyB,GAAG,qCAAqC,CAAC,CAAC,YAAY;AAC5F,MAAM,CAAC,MAAM,0BAA0B,GAAG,sBAAsB,CAAC,CAAC,wCAAwC;AAC1G,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC,CAAC,0BAA0B;AAElE;mGACmG;AACnG,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC;KAC1B,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,QAAQ,EAAE,CAAC,CAAC,MAAM,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xB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KYA-OS Entity Card — EMIT discovery surfaces.
|
|
3
|
+
*
|
|
4
|
+
* "Discover like everyone": one canonical `EntityCard` PROJECTED onto every rail the
|
|
5
|
+
* ecosystem already indexes. These are pure, deterministic projections (no I/O, no crypto)
|
|
6
|
+
* of a single card — each one references the SAME canonical `card.json` endpoint on the
|
|
7
|
+
* entity's `did:web` DID document, so a verifier always lands back on one source of truth:
|
|
8
|
+
*
|
|
9
|
+
* - `toDidServiceEntry` — the `KyaOsEntityCard` service entry that ANCHORS the card on
|
|
10
|
+
* the DID document (the canonical home);
|
|
11
|
+
* - `toServerCardMeta` — MCP `server.json` / catalog `_meta['org.kya-os/card']` (inline
|
|
12
|
+
* summary, or `{ byRef }` → a lazy-fetch `cardRef`);
|
|
13
|
+
* - `toCatalogEntry` — a `/.well-known/mcp/catalog.json` INDEX row (always by-ref);
|
|
14
|
+
* - `toA2AExtension` — an A2A `AgentCard.capabilities.extensions[]` entry (agents only,
|
|
15
|
+
* `required:false` IS the graceful-degradation contract);
|
|
16
|
+
* - `toAgentFacts` — a NANDA AgentFacts JSON-LD projection (we POPULATE `owner` from
|
|
17
|
+
* `responsibleParty`, never re-claim it; our axes live under the `kya:` context).
|
|
18
|
+
*
|
|
19
|
+
* The per-request holder-of-key proof is NEVER projected here — it rides per-request `_meta`.
|
|
20
|
+
* A stripped `_meta` degrades to a fetch, never a failure.
|
|
21
|
+
*/
|
|
22
|
+
import { KYA_OS_CARD_META_KEY } from './resolve.js';
|
|
23
|
+
import { type BitstringStatusListEntry, type EntityCard, type EntityType } from './schema.js';
|
|
24
|
+
/**
|
|
25
|
+
* Shared emit option: override the card.json URL the web-anchored projections point at. Lets a
|
|
26
|
+
* BARE `did:web` org root (which has no path-derived card path) publish via the shipped helpers,
|
|
27
|
+
* or point at a non-conventional home. Defaults to `didWebToCardUrl(card.id)` — the well-known
|
|
28
|
+
* path for a bare root, `/…/card.json` for a path-form DID.
|
|
29
|
+
*/
|
|
30
|
+
export interface CardUrlOverride {
|
|
31
|
+
serviceEndpoint?: string;
|
|
32
|
+
}
|
|
33
|
+
/** A2A extension URI for the entity-card surface (version pinned IN the URI). */
|
|
34
|
+
export declare const A2A_ENTITY_CARD_EXT_URI = "https://kya-os.org/a2a/ext/entity-card/v1";
|
|
35
|
+
/** Human-readable description carried on the A2A extension entry. */
|
|
36
|
+
export declare const A2A_ENTITY_CARD_EXT_DESCRIPTION = "KYA-OS typed DID-anchored holder-of-key identity";
|
|
37
|
+
/** JSON-LD `@context` namespace for the uniquely-ours AgentFacts axes. */
|
|
38
|
+
export declare const AGENTFACTS_KYA_CONTEXT = "https://kya-os.org/ns/agentfacts/v1#";
|
|
39
|
+
/** The per-request holder-of-key proof profile a card advertises (named, never inlined). */
|
|
40
|
+
export declare const PROOF_PROFILE = "org.kya-os/proof@1";
|
|
41
|
+
/** A W3C DID-document `service[]` entry anchoring the card. */
|
|
42
|
+
export interface DidServiceEntry {
|
|
43
|
+
id: string;
|
|
44
|
+
type: string;
|
|
45
|
+
serviceEndpoint: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Inline projection of a card for `_meta` indexing. Carries the identity axes AND the
|
|
49
|
+
* trust-bearing POINTERS — `delegationRef` (the proof for the `responsibleParty` claim) and
|
|
50
|
+
* `revocation` (the post-issuance kill switch) — so the projection stays self-verifiable and can
|
|
51
|
+
* never be mistaken for a clean card once a trust field is stripped. `resolveCard` DEREFERENCES
|
|
52
|
+
* the summary to the canonical `card.json` (the summary is an index, not the authority), but
|
|
53
|
+
* carrying these pointers keeps the index honest for any consumer that reads it directly:
|
|
54
|
+
* emitting the `responsibleParty` claim WITHOUT its `delegationRef` proof, or dropping
|
|
55
|
+
* `revocation`, is exactly the asymmetry that would let a revoked card look live.
|
|
56
|
+
*/
|
|
57
|
+
export interface EntityCardSummary {
|
|
58
|
+
id: string;
|
|
59
|
+
entityType: EntityType;
|
|
60
|
+
name: string;
|
|
61
|
+
capabilities?: string[];
|
|
62
|
+
responsibleParty?: string;
|
|
63
|
+
delegationRef?: string;
|
|
64
|
+
proofProfile?: string;
|
|
65
|
+
revocation?: BitstringStatusListEntry;
|
|
66
|
+
}
|
|
67
|
+
/** The lazy-fetch alternative to an inline summary inside `org.kya-os/card`. */
|
|
68
|
+
export type CardRefValue = {
|
|
69
|
+
'org.kya-os/cardRef': string;
|
|
70
|
+
};
|
|
71
|
+
/** The `_meta` fragment carrying the card on an MCP server.json / catalog surface. */
|
|
72
|
+
export type ServerCardMeta = Record<typeof KYA_OS_CARD_META_KEY, EntityCardSummary | CardRefValue>;
|
|
73
|
+
/** A catalog.json INDEX row (always by-ref for lazy fetch). */
|
|
74
|
+
export interface CatalogEntry {
|
|
75
|
+
name: string;
|
|
76
|
+
_meta: ServerCardMeta;
|
|
77
|
+
}
|
|
78
|
+
/** An A2A `AgentCard.capabilities.extensions[]` entry. */
|
|
79
|
+
export interface A2AExtension {
|
|
80
|
+
uri: string;
|
|
81
|
+
description: string;
|
|
82
|
+
required: boolean;
|
|
83
|
+
params: {
|
|
84
|
+
id: string;
|
|
85
|
+
entityType: 'agent';
|
|
86
|
+
cardUrl: string;
|
|
87
|
+
/** Emitted only when the card DECLARES a proof profile — consistent with the other rails. */
|
|
88
|
+
proofProfile?: typeof PROOF_PROFILE;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/** A NANDA AgentFacts JSON-LD projection. */
|
|
92
|
+
export interface AgentFacts {
|
|
93
|
+
'@context': {
|
|
94
|
+
kya: string;
|
|
95
|
+
};
|
|
96
|
+
id: string;
|
|
97
|
+
agent_name: string;
|
|
98
|
+
'kya:entityType': EntityType;
|
|
99
|
+
owner?: string;
|
|
100
|
+
capabilities?: string[];
|
|
101
|
+
'kya:conformanceLevel'?: string;
|
|
102
|
+
'kya:proofProfile'?: string;
|
|
103
|
+
'kya:delegationRef'?: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The `KyaOsEntityCard` DID-document service entry — the card's canonical home. `opts.serviceEndpoint`
|
|
107
|
+
* overrides the derived URL so a bare `did:web` org root (or a non-conventional home) can anchor its
|
|
108
|
+
* entry explicitly; otherwise it defaults to `didWebToCardUrl(card.id)`.
|
|
109
|
+
*/
|
|
110
|
+
export declare function toDidServiceEntry(card: EntityCard, opts?: CardUrlOverride): DidServiceEntry;
|
|
111
|
+
/** The MCP `server.json` / catalog `_meta['org.kya-os/card']` fragment (inline, or by-ref). */
|
|
112
|
+
export declare function toServerCardMeta(card: EntityCard, opts?: CardUrlOverride & {
|
|
113
|
+
byRef?: boolean;
|
|
114
|
+
}): ServerCardMeta;
|
|
115
|
+
/** A catalog.json INDEX row — by-ref so the index stays cheap and the card lazy-fetches. */
|
|
116
|
+
export declare function toCatalogEntry(card: EntityCard): CatalogEntry;
|
|
117
|
+
/**
|
|
118
|
+
* An A2A AgentExtension entry. Scoped to `entityType:'agent'` (the only A2A principal) and
|
|
119
|
+
* fail-closed otherwise. `required:false` (the default) IS the graceful-degradation contract:
|
|
120
|
+
* an unaware peer ignores the extension instead of rejecting the AgentCard. `proofProfile` is
|
|
121
|
+
* emitted ONLY when the card declares one — the same gate as `_meta` and AgentFacts, so all four
|
|
122
|
+
* projections advertise the proof posture consistently (never A2A-only).
|
|
123
|
+
*/
|
|
124
|
+
export declare function toA2AExtension(card: EntityCard, opts?: CardUrlOverride & {
|
|
125
|
+
required?: boolean;
|
|
126
|
+
}): A2AExtension;
|
|
127
|
+
/**
|
|
128
|
+
* A NANDA AgentFacts JSON-LD projection. We POPULATE NANDA's shipped `owner` slot from
|
|
129
|
+
* `responsibleParty` (we do not re-claim it); the uniquely-ours axes live under the `kya:`
|
|
130
|
+
* context. Optional fields are omitted when absent (claim-minimalism, deterministic output).
|
|
131
|
+
*/
|
|
132
|
+
export declare function toAgentFacts(card: EntityCard): AgentFacts;
|
|
133
|
+
//# sourceMappingURL=emit.d.ts.map
|
|
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B,IAAI,GAAE,eAAe,GAAG;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,GAClD,YAAY,CAkBd;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAazD"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KYA-OS Entity Card — EMIT discovery surfaces.
|
|
3
|
+
*
|
|
4
|
+
* "Discover like everyone": one canonical `EntityCard` PROJECTED onto every rail the
|
|
5
|
+
* ecosystem already indexes. These are pure, deterministic projections (no I/O, no crypto)
|
|
6
|
+
* of a single card — each one references the SAME canonical `card.json` endpoint on the
|
|
7
|
+
* entity's `did:web` DID document, so a verifier always lands back on one source of truth:
|
|
8
|
+
*
|
|
9
|
+
* - `toDidServiceEntry` — the `KyaOsEntityCard` service entry that ANCHORS the card on
|
|
10
|
+
* the DID document (the canonical home);
|
|
11
|
+
* - `toServerCardMeta` — MCP `server.json` / catalog `_meta['org.kya-os/card']` (inline
|
|
12
|
+
* summary, or `{ byRef }` → a lazy-fetch `cardRef`);
|
|
13
|
+
* - `toCatalogEntry` — a `/.well-known/mcp/catalog.json` INDEX row (always by-ref);
|
|
14
|
+
* - `toA2AExtension` — an A2A `AgentCard.capabilities.extensions[]` entry (agents only,
|
|
15
|
+
* `required:false` IS the graceful-degradation contract);
|
|
16
|
+
* - `toAgentFacts` — a NANDA AgentFacts JSON-LD projection (we POPULATE `owner` from
|
|
17
|
+
* `responsibleParty`, never re-claim it; our axes live under the `kya:` context).
|
|
18
|
+
*
|
|
19
|
+
* The per-request holder-of-key proof is NEVER projected here — it rides per-request `_meta`.
|
|
20
|
+
* A stripped `_meta` degrades to a fetch, never a failure.
|
|
21
|
+
*/
|
|
22
|
+
import { didWebToCardUrl, KYA_OS_CARD_META_KEY, KYA_OS_CARD_REF_KEY, KYA_OS_CARD_SERVICE_ID, KYA_OS_CARD_SERVICE_TYPE, } from './resolve.js';
|
|
23
|
+
import { capabilityNames, PROOF_PROFILE_ID, } from './schema.js';
|
|
24
|
+
/** A2A extension URI for the entity-card surface (version pinned IN the URI). */
|
|
25
|
+
export const A2A_ENTITY_CARD_EXT_URI = 'https://kya-os.org/a2a/ext/entity-card/v1';
|
|
26
|
+
/** Human-readable description carried on the A2A extension entry. */
|
|
27
|
+
export const A2A_ENTITY_CARD_EXT_DESCRIPTION = 'KYA-OS typed DID-anchored holder-of-key identity';
|
|
28
|
+
/** JSON-LD `@context` namespace for the uniquely-ours AgentFacts axes. */
|
|
29
|
+
export const AGENTFACTS_KYA_CONTEXT = 'https://kya-os.org/ns/agentfacts/v1#';
|
|
30
|
+
/** The per-request holder-of-key proof profile a card advertises (named, never inlined). */
|
|
31
|
+
export const PROOF_PROFILE = PROOF_PROFILE_ID;
|
|
32
|
+
// ── Projections ─────────────────────────────────────────────────────────────
|
|
33
|
+
/**
|
|
34
|
+
* The `KyaOsEntityCard` DID-document service entry — the card's canonical home. `opts.serviceEndpoint`
|
|
35
|
+
* overrides the derived URL so a bare `did:web` org root (or a non-conventional home) can anchor its
|
|
36
|
+
* entry explicitly; otherwise it defaults to `didWebToCardUrl(card.id)`.
|
|
37
|
+
*/
|
|
38
|
+
export function toDidServiceEntry(card, opts = {}) {
|
|
39
|
+
return {
|
|
40
|
+
id: KYA_OS_CARD_SERVICE_ID,
|
|
41
|
+
type: KYA_OS_CARD_SERVICE_TYPE,
|
|
42
|
+
serviceEndpoint: opts.serviceEndpoint ?? didWebToCardUrl(card.id),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** The MCP `server.json` / catalog `_meta['org.kya-os/card']` fragment (inline, or by-ref). */
|
|
46
|
+
export function toServerCardMeta(card, opts = {}) {
|
|
47
|
+
const value = opts.byRef
|
|
48
|
+
? { [KYA_OS_CARD_REF_KEY]: opts.serviceEndpoint ?? didWebToCardUrl(card.id) }
|
|
49
|
+
: cardSummary(card);
|
|
50
|
+
return { [KYA_OS_CARD_META_KEY]: value };
|
|
51
|
+
}
|
|
52
|
+
/** A catalog.json INDEX row — by-ref so the index stays cheap and the card lazy-fetches. */
|
|
53
|
+
export function toCatalogEntry(card) {
|
|
54
|
+
return { name: card.name, _meta: toServerCardMeta(card, { byRef: true }) };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* An A2A AgentExtension entry. Scoped to `entityType:'agent'` (the only A2A principal) and
|
|
58
|
+
* fail-closed otherwise. `required:false` (the default) IS the graceful-degradation contract:
|
|
59
|
+
* an unaware peer ignores the extension instead of rejecting the AgentCard. `proofProfile` is
|
|
60
|
+
* emitted ONLY when the card declares one — the same gate as `_meta` and AgentFacts, so all four
|
|
61
|
+
* projections advertise the proof posture consistently (never A2A-only).
|
|
62
|
+
*/
|
|
63
|
+
export function toA2AExtension(card, opts = {}) {
|
|
64
|
+
if (card.entityType !== 'agent') {
|
|
65
|
+
throw new Error(`toA2AExtension: the A2A AgentExtension is scoped to entityType "agent" (got "${card.entityType}")`);
|
|
66
|
+
}
|
|
67
|
+
const params = {
|
|
68
|
+
id: card.id,
|
|
69
|
+
entityType: 'agent',
|
|
70
|
+
cardUrl: opts.serviceEndpoint ?? didWebToCardUrl(card.id),
|
|
71
|
+
};
|
|
72
|
+
if (card.proofProfile !== undefined)
|
|
73
|
+
params.proofProfile = card.proofProfile;
|
|
74
|
+
return {
|
|
75
|
+
uri: A2A_ENTITY_CARD_EXT_URI,
|
|
76
|
+
description: A2A_ENTITY_CARD_EXT_DESCRIPTION,
|
|
77
|
+
required: opts.required ?? false,
|
|
78
|
+
params,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A NANDA AgentFacts JSON-LD projection. We POPULATE NANDA's shipped `owner` slot from
|
|
83
|
+
* `responsibleParty` (we do not re-claim it); the uniquely-ours axes live under the `kya:`
|
|
84
|
+
* context. Optional fields are omitted when absent (claim-minimalism, deterministic output).
|
|
85
|
+
*/
|
|
86
|
+
export function toAgentFacts(card) {
|
|
87
|
+
const facts = {
|
|
88
|
+
'@context': { kya: AGENTFACTS_KYA_CONTEXT },
|
|
89
|
+
id: card.id,
|
|
90
|
+
agent_name: card.name,
|
|
91
|
+
'kya:entityType': card.entityType,
|
|
92
|
+
};
|
|
93
|
+
if (card.responsibleParty !== undefined)
|
|
94
|
+
facts.owner = card.responsibleParty;
|
|
95
|
+
if (card.capabilities !== undefined)
|
|
96
|
+
facts.capabilities = capabilityNames(card.capabilities);
|
|
97
|
+
if (card.conformanceLevel !== undefined)
|
|
98
|
+
facts['kya:conformanceLevel'] = card.conformanceLevel;
|
|
99
|
+
if (card.proofProfile !== undefined)
|
|
100
|
+
facts['kya:proofProfile'] = card.proofProfile;
|
|
101
|
+
if (card.delegationRef !== undefined)
|
|
102
|
+
facts['kya:delegationRef'] = card.delegationRef;
|
|
103
|
+
return facts;
|
|
104
|
+
}
|
|
105
|
+
// ── Internals ───────────────────────────────────────────────────────────────
|
|
106
|
+
/**
|
|
107
|
+
* Inline summary: identity + type + capability names, PLUS the trust-bearing pointers
|
|
108
|
+
* (`delegationRef` proves the `responsibleParty` claim; `revocation` is the kill switch). Carrying
|
|
109
|
+
* both closes the claim-without-proof asymmetry so the projection is self-verifiable and never
|
|
110
|
+
* fails open on a revoked card. Still a valid card (all fields optional), but `resolveCard`
|
|
111
|
+
* dereferences it to the canonical `card.json` rather than trusting it.
|
|
112
|
+
*/
|
|
113
|
+
function cardSummary(card) {
|
|
114
|
+
const summary = { id: card.id, entityType: card.entityType, name: card.name };
|
|
115
|
+
if (card.capabilities !== undefined)
|
|
116
|
+
summary.capabilities = capabilityNames(card.capabilities);
|
|
117
|
+
if (card.responsibleParty !== undefined)
|
|
118
|
+
summary.responsibleParty = card.responsibleParty;
|
|
119
|
+
if (card.delegationRef !== undefined)
|
|
120
|
+
summary.delegationRef = card.delegationRef;
|
|
121
|
+
if (card.proofProfile !== undefined)
|
|
122
|
+
summary.proofProfile = card.proofProfile;
|
|
123
|
+
if (card.revocation !== undefined)
|
|
124
|
+
summary.revocation = card.revocation;
|
|
125
|
+
return summary;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=emit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit.js","sourceRoot":"","sources":["../../src/card/emit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,eAAe,EACf,gBAAgB,GAIjB,MAAM,aAAa,CAAC;AAYrB,iFAAiF;AACjF,MAAM,CAAC,MAAM,uBAAuB,GAAG,2CAA2C,CAAC;AACnF,qEAAqE;AACrE,MAAM,CAAC,MAAM,+BAA+B,GAAG,kDAAkD,CAAC;AAClG,0EAA0E;AAC1E,MAAM,CAAC,MAAM,sBAAsB,GAAG,sCAAsC,CAAC;AAC7E,4FAA4F;AAC5F,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,CAAC;AAuE9C,+EAA+E;AAE/E;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAgB,EAAE,OAAwB,EAAE;IAC5E,OAAO;QACL,EAAE,EAAE,sBAAsB;QAC1B,IAAI,EAAE,wBAAwB;QAC9B,eAAe,EAAE,IAAI,CAAC,eAAe,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;KAClE,CAAC;AACJ,CAAC;AAED,+FAA+F;AAC/F,MAAM,UAAU,gBAAgB,CAC9B,IAAgB,EAChB,OAA8C,EAAE;IAEhD,MAAM,KAAK,GAAqC,IAAI,CAAC,KAAK;QACxD,CAAC,CAAC,EAAE,CAAC,mBAAmB,CAAC,EAAE,IAAI,CAAC,eAAe,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;QAC7E,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACtB,OAAO,EAAE,CAAC,oBAA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"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KYA-OS Entity Card — v1.1 profile helpers
|
|
3
|
+
*
|
|
4
|
+
* Reference helpers for the typed, DID-anchored entity card. See
|
|
5
|
+
* `SPEC-ENTITY-CARD.md` and `schemas/kya-os-card.schema.json`. Three moves, each in a
|
|
6
|
+
* focused submodule re-exported here:
|
|
7
|
+
* - buildCard (./build): EMIT this entity's card from its identity + declared facts.
|
|
8
|
+
* - emit (./emit): PROJECT the card onto every discovery rail (DID service entry,
|
|
9
|
+
* MCP `_meta`, catalog, A2A extension, NANDA AgentFacts).
|
|
10
|
+
* - resolveCard (./resolve): DISCOVER another entity's card (multi-surface, via SafeFetch).
|
|
11
|
+
* - verifyCard (./verify): VERIFY the card's claims — RECOMPUTING the conformance
|
|
12
|
+
* level rather than trusting whatever the card declares.
|
|
13
|
+
* - cimd (./cimd): BIND the L1 CIMD on-ramp — `client_id` ⇄ `did:web`, DID-keyed
|
|
14
|
+
* JWKS, and the fail-closed origin/`alsoKnownAs` substitution graft.
|
|
15
|
+
* - proof (./proof): MINT + VERIFY the stateless per-request holder-of-key proof
|
|
16
|
+
* (`org.kya-os/proof@1`) — sender-constrained, fail-closed.
|
|
17
|
+
* - delegation (./delegation): VALIDATE the W3C VC 2.0 + ZCAP-LD delegation chain — CRISP
|
|
18
|
+
* attenuation + continuity, `responsibleParty`/leaf-invoker, fail-closed.
|
|
19
|
+
* - builder (./builder): the fluent `card()` chain — the 10-minute path to a valid card.
|
|
20
|
+
* - middleware (./middleware): `withKyaOsCard` (mount the discovery artifacts) + `requireProof`
|
|
21
|
+
* (the per-request holder-of-key guard, 401-shaped on fail).
|
|
22
|
+
*
|
|
23
|
+
* All cryptographic verification is injected via pluggable seams (the same pattern
|
|
24
|
+
* `validateLevel2` already uses for its `signatureVerifier`), so `@kya-os/mcp` stays
|
|
25
|
+
* free of any runtime (mcp-i-core) dependency. The conformance LEVEL is derived in
|
|
26
|
+
* `./verify`, never baked into a function name.
|
|
27
|
+
*
|
|
28
|
+
* The card shape is defined once as a zod schema in `./schema` (mirroring the
|
|
29
|
+
* published `schemas/kya-os-card.schema.json`); types are `z.infer`-derived.
|
|
30
|
+
*/
|
|
31
|
+
export * from './schema.js';
|
|
32
|
+
export * from './build.js';
|
|
33
|
+
export * from './emit.js';
|
|
34
|
+
export * from './resolve.js';
|
|
35
|
+
export * from './verify.js';
|
|
36
|
+
export * from './cimd.js';
|
|
37
|
+
export * from './proof/index.js';
|
|
38
|
+
export * from './delegation.js';
|
|
39
|
+
export * from './builder.js';
|
|
40
|
+
export * from './middleware.js';
|
|
41
|
+
export * from './revocation.js';
|
|
42
|
+
export { createSafeFetch, fetchTransport, isBlockedAddress, type SafeFetch, type SafeFetchOptions, type SafeFetchResponse, type SafeFetchTransport, type TransportInit, type DnsLookup, type DnsAddress, } from '../utils/safe-fetch.js';
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/card/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAKhC,OAAO,EACL,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,UAAU,GAChB,MAAM,wBAAwB,CAAC"}
|