@kya-os/consent 0.2.1 → 0.2.3

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 (132) hide show
  1. package/README.md +128 -0
  2. package/dist/bundle/index.d.ts +38 -36
  3. package/dist/bundle/index.d.ts.map +1 -1
  4. package/dist/bundle/index.js +35 -33
  5. package/dist/bundle/index.js.map +1 -1
  6. package/dist/bundle/inline.d.ts.map +1 -1
  7. package/dist/bundle/inline.js +4 -4
  8. package/dist/bundle/inline.js.map +1 -1
  9. package/dist/bundle/shell.d.ts +7 -0
  10. package/dist/bundle/shell.d.ts.map +1 -1
  11. package/dist/bundle/shell.js +5 -0
  12. package/dist/bundle/shell.js.map +1 -1
  13. package/dist/cjs/bundle/index.js +4 -1
  14. package/dist/cjs/bundle/index.js.map +1 -1
  15. package/dist/cjs/bundle/inline.js +4 -4
  16. package/dist/cjs/bundle/inline.js.map +1 -1
  17. package/dist/cjs/bundle/shell.js +5 -0
  18. package/dist/cjs/bundle/shell.js.map +1 -1
  19. package/dist/cjs/components/consent-agent-header.js +15 -9
  20. package/dist/cjs/components/consent-agent-header.js.map +1 -1
  21. package/dist/cjs/components/consent-capabilities-screen.js +40 -78
  22. package/dist/cjs/components/consent-capabilities-screen.js.map +1 -1
  23. package/dist/cjs/components/consent-headline.js +138 -0
  24. package/dist/cjs/components/consent-headline.js.map +1 -0
  25. package/dist/cjs/components/consent-otp-input.js +35 -18
  26. package/dist/cjs/components/consent-otp-input.js.map +1 -1
  27. package/dist/cjs/components/index.js +3 -1
  28. package/dist/cjs/components/index.js.map +1 -1
  29. package/dist/cjs/components/mcp-consent.js +42 -1
  30. package/dist/cjs/components/mcp-consent.js.map +1 -1
  31. package/dist/cjs/copy/tokens.js +16 -1
  32. package/dist/cjs/copy/tokens.js.map +1 -1
  33. package/dist/cjs/identity/agent-identity.js +314 -0
  34. package/dist/cjs/identity/agent-identity.js.map +1 -0
  35. package/dist/cjs/identity/documents.js +212 -0
  36. package/dist/cjs/identity/documents.js.map +1 -0
  37. package/dist/cjs/identity/entity-card.js +128 -0
  38. package/dist/cjs/identity/entity-card.js.map +1 -0
  39. package/dist/cjs/identity/index.js +31 -0
  40. package/dist/cjs/identity/index.js.map +1 -0
  41. package/dist/cjs/identity/resolve.js +122 -0
  42. package/dist/cjs/identity/resolve.js.map +1 -0
  43. package/dist/cjs/identity/schemas.js +88 -0
  44. package/dist/cjs/identity/schemas.js.map +1 -0
  45. package/dist/cjs/index.js +3 -1
  46. package/dist/cjs/index.js.map +1 -1
  47. package/dist/cjs/mcp-app/inline.js +2 -2
  48. package/dist/cjs/mcp-app/inline.js.map +1 -1
  49. package/dist/cjs/mcp-app/types.js +1 -1
  50. package/dist/cjs/popup/launcher.js +3 -3
  51. package/dist/cjs/react/index.js +141 -25
  52. package/dist/cjs/react/index.js.map +1 -1
  53. package/dist/cjs/templates/index.js +1 -1
  54. package/dist/cjs/types/index.js +1 -1
  55. package/dist/components/consent-agent-header.d.ts +3 -1
  56. package/dist/components/consent-agent-header.d.ts.map +1 -1
  57. package/dist/components/consent-agent-header.js +15 -9
  58. package/dist/components/consent-agent-header.js.map +1 -1
  59. package/dist/components/consent-capabilities-screen.d.ts +13 -3
  60. package/dist/components/consent-capabilities-screen.d.ts.map +1 -1
  61. package/dist/components/consent-capabilities-screen.js +40 -78
  62. package/dist/components/consent-capabilities-screen.js.map +1 -1
  63. package/dist/components/consent-headline.d.ts +42 -0
  64. package/dist/components/consent-headline.d.ts.map +1 -0
  65. package/dist/components/consent-headline.js +135 -0
  66. package/dist/components/consent-headline.js.map +1 -0
  67. package/dist/components/consent-otp-input.d.ts +7 -2
  68. package/dist/components/consent-otp-input.d.ts.map +1 -1
  69. package/dist/components/consent-otp-input.js +35 -18
  70. package/dist/components/consent-otp-input.js.map +1 -1
  71. package/dist/components/index.d.ts +18 -17
  72. package/dist/components/index.d.ts.map +1 -1
  73. package/dist/components/index.js +18 -17
  74. package/dist/components/index.js.map +1 -1
  75. package/dist/components/mcp-consent.d.ts +16 -0
  76. package/dist/components/mcp-consent.d.ts.map +1 -1
  77. package/dist/components/mcp-consent.js +42 -1
  78. package/dist/components/mcp-consent.js.map +1 -1
  79. package/dist/consent.js +493 -100
  80. package/dist/consent.min.js +244 -232
  81. package/dist/copy/tokens.d.ts +16 -1
  82. package/dist/copy/tokens.d.ts.map +1 -1
  83. package/dist/copy/tokens.js +16 -1
  84. package/dist/copy/tokens.js.map +1 -1
  85. package/dist/identity/agent-identity.d.ts +199 -0
  86. package/dist/identity/agent-identity.d.ts.map +1 -0
  87. package/dist/identity/agent-identity.js +305 -0
  88. package/dist/identity/agent-identity.js.map +1 -0
  89. package/dist/identity/documents.d.ts +63 -0
  90. package/dist/identity/documents.d.ts.map +1 -0
  91. package/dist/identity/documents.js +206 -0
  92. package/dist/identity/documents.js.map +1 -0
  93. package/dist/identity/entity-card.d.ts +80 -0
  94. package/dist/identity/entity-card.d.ts.map +1 -0
  95. package/dist/identity/entity-card.js +119 -0
  96. package/dist/identity/entity-card.js.map +1 -0
  97. package/dist/identity/index.d.ts +15 -0
  98. package/dist/identity/index.d.ts.map +1 -0
  99. package/dist/identity/index.js +15 -0
  100. package/dist/identity/index.js.map +1 -0
  101. package/dist/identity/resolve.d.ts +31 -0
  102. package/dist/identity/resolve.d.ts.map +1 -0
  103. package/dist/identity/resolve.js +119 -0
  104. package/dist/identity/resolve.js.map +1 -0
  105. package/dist/identity/schemas.d.ts +404 -0
  106. package/dist/identity/schemas.d.ts.map +1 -0
  107. package/dist/identity/schemas.js +84 -0
  108. package/dist/identity/schemas.js.map +1 -0
  109. package/dist/index.d.ts +2 -1
  110. package/dist/index.d.ts.map +1 -1
  111. package/dist/index.js +3 -1
  112. package/dist/index.js.map +1 -1
  113. package/dist/kya-os/index.d.ts +55 -0
  114. package/dist/kya-os/index.d.ts.map +1 -0
  115. package/dist/kya-os/index.js +235 -0
  116. package/dist/kya-os/index.js.map +1 -0
  117. package/dist/mcp-app/inline.d.ts.map +1 -1
  118. package/dist/mcp-app/inline.js +2 -2
  119. package/dist/mcp-app/inline.js.map +1 -1
  120. package/dist/mcp-app/types.d.ts +1 -1
  121. package/dist/mcp-app/types.js +1 -1
  122. package/dist/popup/launcher.d.ts +3 -3
  123. package/dist/popup/launcher.js +3 -3
  124. package/dist/react/index.d.ts +108 -22
  125. package/dist/react/index.d.ts.map +1 -1
  126. package/dist/react/index.js +151 -35
  127. package/dist/react/index.js.map +1 -1
  128. package/dist/templates/index.d.ts +1 -1
  129. package/dist/templates/index.js +1 -1
  130. package/dist/types/index.d.ts +1 -1
  131. package/dist/types/index.js +1 -1
  132. package/package.json +41 -6
@@ -0,0 +1,206 @@
1
+ /**
2
+ * Read the documents agents already publish into the Entity Card shape.
3
+ *
4
+ * Four kinds are recognized:
5
+ *
6
+ * - a KYA-OS Entity Card;
7
+ * - CIMD client metadata (the OAuth `client_id` document), read the way
8
+ * `cardFromClientMetadata` in `@kya-os/mcp/card` reads it;
9
+ * - an A2A AgentCard carrying the KYA-OS entity-card extension, or that
10
+ * extension on its own;
11
+ * - a NANDA AgentFacts document whose `id` is a DID.
12
+ *
13
+ * Reading is not verifying. The card that comes back is what the document
14
+ * claims; `ref` says where a verifier finds the canonical card, the same
15
+ * reference forms `resolveCard` in `@kya-os/mcp/card` takes.
16
+ *
17
+ * @module identity/documents
18
+ */
19
+ import { ConsentEntityCardSchema } from "./schemas.js";
20
+ import { ENTITY_DID_PATTERN, ENTITY_TYPES, didWebHost, httpsHost, } from "./entity-card.js";
21
+ /** The URI of the KYA-OS entity-card extension on an A2A AgentCard. */
22
+ export const A2A_ENTITY_CARD_EXTENSION_URI = "https://kya-os.org/a2a/ext/entity-card/v1";
23
+ /** The JSON-LD context KYA-OS terms use inside a NANDA AgentFacts document. */
24
+ export const AGENTFACTS_KYA_CONTEXT = "https://kya-os.org/ns/agentfacts/v1#";
25
+ /** The `_meta` key a CIMD document declares its DID under. */
26
+ export const KYA_OS_DID_META_KEY = "org.kya-os/did";
27
+ /** Thrown when a document can't be read into an Entity Card. */
28
+ export class AgentDocumentError extends Error {
29
+ constructor(code, message) {
30
+ super(message);
31
+ this.name = "AgentDocumentError";
32
+ this.code = code;
33
+ }
34
+ }
35
+ /**
36
+ * Read an agent document into the Entity Card shape.
37
+ *
38
+ * @throws {AgentDocumentError} `unrecognized` for anything that isn't one of
39
+ * the four kinds, `no_did` for a document that names no DID (an A2A
40
+ * AgentCard without the KYA-OS extension, AgentFacts whose `id` isn't a
41
+ * DID), and `invalid` for one that breaks its own rules.
42
+ */
43
+ export function readAgentDocument(doc) {
44
+ if (!isRecord(doc)) {
45
+ throw new AgentDocumentError("unrecognized", "An agent document is a JSON object");
46
+ }
47
+ if (typeof doc.client_id === "string")
48
+ return fromClientMetadata(doc);
49
+ if (typeof doc.agent_name === "string")
50
+ return fromAgentFacts(doc);
51
+ if (typeof doc.entityType === "string")
52
+ return fromEntityCard(doc);
53
+ if (doc.uri === A2A_ENTITY_CARD_EXTENSION_URI) {
54
+ return fromA2AExtension(doc, undefined);
55
+ }
56
+ if (isA2AAgentCard(doc))
57
+ return fromA2AAgentCard(doc);
58
+ throw new AgentDocumentError("unrecognized", "Not an Entity Card, CIMD client metadata, an A2A AgentCard or NANDA AgentFacts");
59
+ }
60
+ /** The `did:web` an `https:` CIMD `client_id` names, as `@kya-os/mcp` mints it. */
61
+ export function didFromClientId(clientId) {
62
+ let url;
63
+ try {
64
+ url = new URL(clientId);
65
+ }
66
+ catch {
67
+ throw new AgentDocumentError("invalid", `client_id is not a URL: "${clientId}"`);
68
+ }
69
+ if (url.protocol !== "https:") {
70
+ throw new AgentDocumentError("invalid", `client_id must be https: "${clientId}"`);
71
+ }
72
+ const authority = encodeURIComponent(url.host);
73
+ const segments = url.pathname
74
+ .split("/")
75
+ .filter((segment) => segment.length > 0)
76
+ .map(encodeURIComponent);
77
+ return `did:web:${[authority, ...segments].join(":")}`;
78
+ }
79
+ /* ------------------------------------------------------------ the kinds */
80
+ function fromEntityCard(doc) {
81
+ const card = parseCard(doc, "Entity Card");
82
+ return { kind: "entity-card", card, ...refFor(card.id) };
83
+ }
84
+ function fromClientMetadata(doc) {
85
+ const clientId = doc.client_id;
86
+ // Minting first checks the client_id is an https URL, which CIMD requires
87
+ // whatever DID the document declares.
88
+ const minted = didFromClientId(clientId);
89
+ const did = declaredClientDid(doc, clientId) ?? minted;
90
+ // A blank name names nothing: show the DID, as for a missing one.
91
+ const name = typeof doc.client_name === "string" && doc.client_name.trim().length > 0
92
+ ? doc.client_name
93
+ : did;
94
+ const card = { id: did, entityType: "client", name };
95
+ if (typeof doc.jwks_uri === "string") {
96
+ card.cimd = { clientId, jwksUri: doc.jwks_uri };
97
+ }
98
+ const parsed = parseCard(card, "CIMD client metadata");
99
+ return { kind: "cimd", card: parsed, ...refFor(parsed.id) };
100
+ }
101
+ /**
102
+ * A DID the CIMD document declares in `_meta`. A document is served from its
103
+ * `client_id`, so it can only speak for a `did:web` on that same host.
104
+ */
105
+ function declaredClientDid(doc, clientId) {
106
+ const meta = isRecord(doc._meta) ? doc._meta : undefined;
107
+ const declared = meta?.[KYA_OS_DID_META_KEY];
108
+ if (declared === undefined)
109
+ return undefined;
110
+ if (typeof declared !== "string" || !ENTITY_DID_PATTERN.test(declared)) {
111
+ throw new AgentDocumentError("invalid", `_meta["${KYA_OS_DID_META_KEY}"] must be a did:key or did:web DID`);
112
+ }
113
+ if (declared.startsWith("did:web:")) {
114
+ const declaredHost = didWebHost(declared);
115
+ if (declaredHost === null || declaredHost !== httpsHost(clientId)) {
116
+ throw new AgentDocumentError("invalid", `${declared} is not on the host of client_id "${clientId}": a CIMD document can only speak for its own host`);
117
+ }
118
+ }
119
+ return declared;
120
+ }
121
+ function fromAgentFacts(doc) {
122
+ const id = doc.id;
123
+ if (typeof id !== "string" || !ENTITY_DID_PATTERN.test(id)) {
124
+ throw new AgentDocumentError("no_did", "This AgentFacts document's id is not a did:key or did:web DID, so no Entity Card stands behind it");
125
+ }
126
+ const card = {
127
+ id,
128
+ entityType: entityTypeOr(doc["kya:entityType"], "agent"),
129
+ name: doc.agent_name,
130
+ };
131
+ if (typeof doc.owner === "string" && ENTITY_DID_PATTERN.test(doc.owner)) {
132
+ card.responsibleParty = doc.owner;
133
+ }
134
+ // KYA-OS projects capability names; NANDA's own `capabilities` object
135
+ // (modalities, streaming, authentication) has no Entity Card equivalent.
136
+ if (Array.isArray(doc.capabilities) &&
137
+ doc.capabilities.every((name) => typeof name === "string" && name.length > 0)) {
138
+ card.capabilities = doc.capabilities;
139
+ }
140
+ if (typeof doc["kya:delegationRef"] === "string") {
141
+ card.delegationRef = doc["kya:delegationRef"];
142
+ }
143
+ const parsed = parseCard(card, "AgentFacts");
144
+ return { kind: "agentfacts", card: parsed, ...refFor(parsed.id) };
145
+ }
146
+ function isA2AAgentCard(doc) {
147
+ return (typeof doc.name === "string" &&
148
+ (isRecord(doc.capabilities) ||
149
+ Array.isArray(doc.skills) ||
150
+ typeof doc.protocolVersion === "string"));
151
+ }
152
+ function fromA2AAgentCard(doc) {
153
+ const capabilities = isRecord(doc.capabilities) ? doc.capabilities : {};
154
+ const extensions = Array.isArray(capabilities.extensions)
155
+ ? capabilities.extensions
156
+ : [];
157
+ const extension = extensions.find((entry) => isRecord(entry) && entry.uri === A2A_ENTITY_CARD_EXTENSION_URI);
158
+ if (!isRecord(extension)) {
159
+ throw new AgentDocumentError("no_did", "This A2A AgentCard has no KYA-OS entity-card extension, so it names no DID");
160
+ }
161
+ return fromA2AExtension(extension, doc.name);
162
+ }
163
+ function fromA2AExtension(extension, agentName) {
164
+ const params = isRecord(extension.params) ? extension.params : {};
165
+ const id = params.id;
166
+ if (typeof id !== "string" || !ENTITY_DID_PATTERN.test(id)) {
167
+ throw new AgentDocumentError("no_did", "The A2A entity-card extension's params.id is not a did:key or did:web DID");
168
+ }
169
+ // The A2A projection exists only for agents.
170
+ if (params.entityType !== undefined && params.entityType !== "agent") {
171
+ throw new AgentDocumentError("invalid", `The A2A entity-card extension is for agents, not "${String(params.entityType)}"`);
172
+ }
173
+ const card = parseCard({ id, entityType: "agent", name: agentName || id }, "A2A entity-card extension");
174
+ // A did:web resolves through its own DID document, which binds the card to
175
+ // the DID; the card URL is the way in only when there is no DID home.
176
+ if (id.startsWith("did:web:"))
177
+ return { kind: "a2a", card, ref: { did: id } };
178
+ const cardUrl = params.cardUrl;
179
+ if (typeof cardUrl === "string" && httpsHost(cardUrl) !== null) {
180
+ return { kind: "a2a", card, ref: { cardUrl } };
181
+ }
182
+ return { kind: "a2a", card };
183
+ }
184
+ /* ------------------------------------------------------------ helpers */
185
+ function parseCard(value, source) {
186
+ const parsed = ConsentEntityCardSchema.safeParse(value);
187
+ if (!parsed.success) {
188
+ const issue = parsed.error.issues[0];
189
+ const where = issue?.path.length ? `${issue.path.join(".")}: ` : "";
190
+ throw new AgentDocumentError("invalid", `${source}: ${where}${issue?.message ?? "not an Entity Card"}`);
191
+ }
192
+ return parsed.data;
193
+ }
194
+ function refFor(did) {
195
+ return did.startsWith("did:web:") ? { ref: { did } } : {};
196
+ }
197
+ function entityTypeOr(value, fallback) {
198
+ return typeof value === "string" &&
199
+ ENTITY_TYPES.includes(value)
200
+ ? value
201
+ : fallback;
202
+ }
203
+ function isRecord(value) {
204
+ return typeof value === "object" && value !== null && !Array.isArray(value);
205
+ }
206
+ //# sourceMappingURL=documents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documents.js","sourceRoot":"","sources":["../../src/identity/documents.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,SAAS,GAGV,MAAM,kBAAkB,CAAC;AAE1B,uEAAuE;AACvE,MAAM,CAAC,MAAM,6BAA6B,GACxC,2CAA2C,CAAC;AAE9C,+EAA+E;AAC/E,MAAM,CAAC,MAAM,sBAAsB,GAAG,sCAAsC,CAAC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BAAuB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACxD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACrC,MAAM,KAAK,GAAG,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACpE,MAAM,IAAI,kBAAkB,CAC1B,SAAS,EACT,GAAG,MAAM,KAAK,KAAK,GAAG,KAAK,EAAE,OAAO,IAAI,oBAAoB,EAAE,CAC/D,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC,IAAyB,CAAC;AAC1C,CAAC;AAED,SAAS,MAAM,CAAC,GAAW;IACzB,OAAO,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5D,CAAC;AAED,SAAS,YAAY,CACnB,KAAc,EACd,QAA2B;IAE3B,OAAO,OAAO,KAAK,KAAK,QAAQ;QAC7B,YAAkC,CAAC,QAAQ,CAAC,KAAK,CAAC;QACnD,CAAC,CAAE,KAA2B;QAC9B,CAAC,CAAC,QAAQ,CAAC;AACf,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * The KYA-OS Entity Card, as the consent screen reads it.
3
+ *
4
+ * An Entity Card (KYA-OS Entity Card profile, `@kya-os/mcp/card`) is a
5
+ * DID-anchored description of an agent, MCP server, client, verifier or
6
+ * human. The consent screen reads the fields it shows and the fields that
7
+ * bind a domain to the card; it keeps the rest and never trusts a card's
8
+ * self-declared `conformanceLevel`.
9
+ *
10
+ * A full `EntityCard` from `@kya-os/mcp/card` passes as a `ConsentEntityCard`
11
+ * unchanged, so a KYA-OS deployment hands its cards straight to the screen.
12
+ *
13
+ * No zod here: the components import this module, and the browser bundle
14
+ * stays free of it. The schemas are in `./schemas.ts`.
15
+ *
16
+ * @module identity/entity-card
17
+ */
18
+ /** The entity types an Entity Card names. */
19
+ export declare const ENTITY_TYPES: readonly ["mcp", "agent", "client", "verifier", "human"];
20
+ export type ConsentEntityType = (typeof ENTITY_TYPES)[number];
21
+ /** A DID an Entity Card can be anchored on: `did:key` or `did:web`. */
22
+ export declare const ENTITY_DID_PATTERN: RegExp;
23
+ /**
24
+ * The Entity Card fields the consent screen reads. Every other field a card
25
+ * carries is kept as is and ignored.
26
+ */
27
+ export interface ConsentEntityCard {
28
+ /** The entity's DID, `did:key` or `did:web`. */
29
+ id: string;
30
+ entityType: ConsentEntityType;
31
+ /** Display name. A claim until a verifier says otherwise. */
32
+ name: string;
33
+ /** The DID accountable for the entity (NANDA AgentFacts' `owner`). */
34
+ responsibleParty?: string;
35
+ /** The DID the entity acts for. */
36
+ principal?: string;
37
+ /** Capability names, bare or with an attestation. */
38
+ capabilities?: Array<string | {
39
+ name: string;
40
+ }>;
41
+ /** Reference to the delegation that proves `responsibleParty`. */
42
+ delegationRef?: string;
43
+ /** CIMD coordinates: the OAuth `client_id` and the `jwks_uri` keyed to the DID. */
44
+ cimd?: {
45
+ clientId: string;
46
+ jwksUri: string;
47
+ };
48
+ }
49
+ /** The capability names a card declares, attested or not. */
50
+ export declare function cardCapabilityNames(card: ConsentEntityCard): string[];
51
+ /**
52
+ * The `https:` host (with any port) a `did:web` lives on, lowercased:
53
+ * `did:web:chatgpt.com:x` is `chatgpt.com`, `did:web:localhost%3A8443` is
54
+ * `localhost:8443`. Null for any other DID, or a `did:web` with no host.
55
+ */
56
+ export declare function didWebHost(did: string): string | null;
57
+ /** The lowercased host (with any port) of an `https:` URL, or null. */
58
+ export declare function httpsHost(url: string): string | null;
59
+ /**
60
+ * Whether two DIDs are the same DID. A `did:web`'s host is case-insensitive
61
+ * and its segments may be percent-encoded differently, so both are compared
62
+ * in canonical form, the way `resolveCard` in `@kya-os/mcp/card` binds a
63
+ * card to its DID. Any other DID compares verbatim.
64
+ */
65
+ export declare function sameDid(a: string, b: string): boolean;
66
+ /**
67
+ * A DID in canonical form: a `did:web` with its host lowercased and every
68
+ * segment percent-encoded one way, so a decoded `:` (a port, say) never turns
69
+ * into a segment separator. Any other DID, or a `did:web` that doesn't
70
+ * decode, as it is.
71
+ */
72
+ export declare function canonicalDid(did: string): string;
73
+ /**
74
+ * The one domain a card can be bound to: its CIMD `client_id`'s host when it
75
+ * has CIMD coordinates, else its `did:web` host. A card whose `client_id` and
76
+ * `did:web` name different hosts has none, and neither does a `did:key` card
77
+ * with no CIMD coordinates.
78
+ */
79
+ export declare function cardDomain(card: ConsentEntityCard): string | null;
80
+ //# sourceMappingURL=entity-card.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-card.d.ts","sourceRoot":"","sources":["../../src/identity/entity-card.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,6CAA6C;AAC7C,eAAO,MAAM,YAAY,0DAMf,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9D,uEAAuE;AACvE,eAAO,MAAM,kBAAkB,QAAuB,CAAC;AAIvD;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,gDAAgD;IAChD,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,iBAAiB,CAAC;IAC9B,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,sEAAsE;IACtE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mCAAmC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,YAAY,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAChD,kEAAkE;IAClE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mFAAmF;IACnF,IAAI,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAC9C;AAED,6DAA6D;AAC7D,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,EAAE,CAIrE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAarD;AAED,uEAAuE;AACvE,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEpD;AAcD;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAWhD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CAOjE"}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * The KYA-OS Entity Card, as the consent screen reads it.
3
+ *
4
+ * An Entity Card (KYA-OS Entity Card profile, `@kya-os/mcp/card`) is a
5
+ * DID-anchored description of an agent, MCP server, client, verifier or
6
+ * human. The consent screen reads the fields it shows and the fields that
7
+ * bind a domain to the card; it keeps the rest and never trusts a card's
8
+ * self-declared `conformanceLevel`.
9
+ *
10
+ * A full `EntityCard` from `@kya-os/mcp/card` passes as a `ConsentEntityCard`
11
+ * unchanged, so a KYA-OS deployment hands its cards straight to the screen.
12
+ *
13
+ * No zod here: the components import this module, and the browser bundle
14
+ * stays free of it. The schemas are in `./schemas.ts`.
15
+ *
16
+ * @module identity/entity-card
17
+ */
18
+ /** The entity types an Entity Card names. */
19
+ export const ENTITY_TYPES = [
20
+ "mcp",
21
+ "agent",
22
+ "client",
23
+ "verifier",
24
+ "human",
25
+ ];
26
+ /** A DID an Entity Card can be anchored on: `did:key` or `did:web`. */
27
+ export const ENTITY_DID_PATTERN = /^did:(key|web):.+$/;
28
+ const DID_WEB_PREFIX = "did:web:";
29
+ /** The capability names a card declares, attested or not. */
30
+ export function cardCapabilityNames(card) {
31
+ return (card.capabilities ?? []).map((capability) => typeof capability === "string" ? capability : capability.name);
32
+ }
33
+ /**
34
+ * The `https:` host (with any port) a `did:web` lives on, lowercased:
35
+ * `did:web:chatgpt.com:x` is `chatgpt.com`, `did:web:localhost%3A8443` is
36
+ * `localhost:8443`. Null for any other DID, or a `did:web` with no host.
37
+ */
38
+ export function didWebHost(did) {
39
+ if (!did.startsWith(DID_WEB_PREFIX))
40
+ return null;
41
+ const authority = did.slice(DID_WEB_PREFIX.length).split(":")[0] ?? "";
42
+ let host;
43
+ try {
44
+ host = decodeURIComponent(authority);
45
+ }
46
+ catch {
47
+ return null;
48
+ }
49
+ // The authority is a host and an optional port, nothing that would move
50
+ // the URL somewhere else once decoded.
51
+ if (!host || /[/?#@\\\s]/.test(host))
52
+ return null;
53
+ return hostOf(`https://${host}`);
54
+ }
55
+ /** The lowercased host (with any port) of an `https:` URL, or null. */
56
+ export function httpsHost(url) {
57
+ return hostOf(url);
58
+ }
59
+ function hostOf(url) {
60
+ let parsed;
61
+ try {
62
+ parsed = new URL(url);
63
+ }
64
+ catch {
65
+ return null;
66
+ }
67
+ if (parsed.protocol !== "https:" || !parsed.host)
68
+ return null;
69
+ if (parsed.username || parsed.password)
70
+ return null;
71
+ return parsed.host.toLowerCase();
72
+ }
73
+ /**
74
+ * Whether two DIDs are the same DID. A `did:web`'s host is case-insensitive
75
+ * and its segments may be percent-encoded differently, so both are compared
76
+ * in canonical form, the way `resolveCard` in `@kya-os/mcp/card` binds a
77
+ * card to its DID. Any other DID compares verbatim.
78
+ */
79
+ export function sameDid(a, b) {
80
+ return a === b || canonicalDid(a) === canonicalDid(b);
81
+ }
82
+ /**
83
+ * A DID in canonical form: a `did:web` with its host lowercased and every
84
+ * segment percent-encoded one way, so a decoded `:` (a port, say) never turns
85
+ * into a segment separator. Any other DID, or a `did:web` that doesn't
86
+ * decode, as it is.
87
+ */
88
+ export function canonicalDid(did) {
89
+ if (!did.startsWith(DID_WEB_PREFIX))
90
+ return did;
91
+ try {
92
+ const [host = "", ...path] = did
93
+ .slice(DID_WEB_PREFIX.length)
94
+ .split(":")
95
+ .map(decodeURIComponent);
96
+ return `${DID_WEB_PREFIX}${[host.toLowerCase(), ...path].map(encodeURIComponent).join(":")}`;
97
+ }
98
+ catch {
99
+ return did;
100
+ }
101
+ }
102
+ /**
103
+ * The one domain a card can be bound to: its CIMD `client_id`'s host when it
104
+ * has CIMD coordinates, else its `did:web` host. A card whose `client_id` and
105
+ * `did:web` name different hosts has none, and neither does a `did:key` card
106
+ * with no CIMD coordinates.
107
+ */
108
+ export function cardDomain(card) {
109
+ const didHost = didWebHost(card.id);
110
+ if (!card.cimd)
111
+ return didHost;
112
+ const clientHost = httpsHost(card.cimd.clientId);
113
+ if (!clientHost)
114
+ return null;
115
+ if (didHost !== null && didHost !== clientHost)
116
+ return null;
117
+ return clientHost;
118
+ }
119
+ //# sourceMappingURL=entity-card.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-card.js","sourceRoot":"","sources":["../../src/identity/entity-card.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,6CAA6C;AAC7C,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,KAAK;IACL,OAAO;IACP,QAAQ;IACR,UAAU;IACV,OAAO;CACC,CAAC;AAIX,uEAAuE;AACvE,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAC;AAEvD,MAAM,cAAc,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AAI,CAAC;IAC7B,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,UAAU;QAAE,OAAO,IAAI,CAAC;IAC5D,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Agent identity in the KYA-OS Entity Card shape.
3
+ *
4
+ * Read what an agent publishes (an Entity Card, CIMD client metadata, an A2A
5
+ * AgentCard with the KYA-OS extension, NANDA AgentFacts) into one card shape,
6
+ * verify it in the host, and hand the screen the result.
7
+ *
8
+ * @module @kya-os/consent/identity
9
+ */
10
+ export * from "./entity-card.js";
11
+ export * from "./documents.js";
12
+ export * from "./agent-identity.js";
13
+ export * from "./schemas.js";
14
+ export * from "./resolve.js";
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Agent identity in the KYA-OS Entity Card shape.
3
+ *
4
+ * Read what an agent publishes (an Entity Card, CIMD client metadata, an A2A
5
+ * AgentCard with the KYA-OS extension, NANDA AgentFacts) into one card shape,
6
+ * verify it in the host, and hand the screen the result.
7
+ *
8
+ * @module @kya-os/consent/identity
9
+ */
10
+ export * from "./entity-card.js";
11
+ export * from "./documents.js";
12
+ export * from "./agent-identity.js";
13
+ export * from "./schemas.js";
14
+ export * from "./resolve.js";
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Turn an agent's document into the identity the consent screen takes:
3
+ * read it, run the host's verifier, bind the result to the card, validate.
4
+ *
5
+ * Host side. Uses zod (through `./schemas.ts`), so the components never
6
+ * import this module.
7
+ *
8
+ * @module identity/resolve
9
+ */
10
+ import { type AgentIdentity, type AgentIdentityVerifier, type AgentVerificationContext } from "./agent-identity.js";
11
+ export interface ResolveAgentIdentityOptions {
12
+ /** Checks the document. Without one, the identity is unverified. */
13
+ verifier?: AgentIdentityVerifier;
14
+ /** The request the document came with. */
15
+ context?: AgentVerificationContext;
16
+ vendor?: string;
17
+ surfaceLabel?: string;
18
+ logoUrl?: string;
19
+ connectedAt?: string;
20
+ }
21
+ /**
22
+ * Read an agent document, run the verifier on it, and return the identity
23
+ * the consent screen takes. A verifier that throws or returns something
24
+ * malformed leaves the identity unverified, never verified, and so does a
25
+ * `verified` result without a valid card for the document's DID.
26
+ *
27
+ * @throws {AgentDocumentError} when the document can't be read.
28
+ * @throws {AgentIdentityError} when a display option doesn't validate.
29
+ */
30
+ export declare function resolveAgentIdentity(document: unknown, options?: ResolveAgentIdentityOptions): Promise<AgentIdentity>;
31
+ //# sourceMappingURL=resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/identity/resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAGL,KAAK,aAAa,EAElB,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAE9B,MAAM,qBAAqB,CAAC;AAS7B,MAAM,WAAW,2BAA2B;IAC1C,oEAAoE;IACpE,QAAQ,CAAC,EAAE,qBAAqB,CAAC;IACjC,0CAA0C;IAC1C,OAAO,CAAC,EAAE,wBAAwB,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,OAAO,EACjB,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,aAAa,CAAC,CAexB"}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Turn an agent's document into the identity the consent screen takes:
3
+ * read it, run the host's verifier, bind the result to the card, validate.
4
+ *
5
+ * Host side. Uses zod (through `./schemas.ts`), so the components never
6
+ * import this module.
7
+ *
8
+ * @module identity/resolve
9
+ */
10
+ import { bindVerification, limitReason, } from "./agent-identity.js";
11
+ import { readAgentDocument } from "./documents.js";
12
+ import { sameDid } from "./entity-card.js";
13
+ import { AgentIdentityVerificationSchema, ConsentEntityCardSchema, parseAgentIdentity, } from "./schemas.js";
14
+ /**
15
+ * Read an agent document, run the verifier on it, and return the identity
16
+ * the consent screen takes. A verifier that throws or returns something
17
+ * malformed leaves the identity unverified, never verified, and so does a
18
+ * `verified` result without a valid card for the document's DID.
19
+ *
20
+ * @throws {AgentDocumentError} when the document can't be read.
21
+ * @throws {AgentIdentityError} when a display option doesn't validate.
22
+ */
23
+ export async function resolveAgentIdentity(document, options = {}) {
24
+ const read = readAgentDocument(document);
25
+ const { card, verification } = await runVerifier(read, options);
26
+ const identity = {
27
+ card,
28
+ verification: bindVerification(card, verification),
29
+ };
30
+ if (options.vendor !== undefined)
31
+ identity.vendor = options.vendor;
32
+ if (options.surfaceLabel !== undefined)
33
+ identity.surfaceLabel = options.surfaceLabel;
34
+ if (options.logoUrl !== undefined)
35
+ identity.logoUrl = options.logoUrl;
36
+ if (options.connectedAt !== undefined)
37
+ identity.connectedAt = options.connectedAt;
38
+ parseAgentIdentity(identity);
39
+ return identity;
40
+ }
41
+ function isRecord(value) {
42
+ return typeof value === "object" && value !== null && !Array.isArray(value);
43
+ }
44
+ async function runVerifier(read, options) {
45
+ if (options.verifier === undefined) {
46
+ return {
47
+ card: read.card,
48
+ verification: { status: "unverified", reason: "no verifier" },
49
+ };
50
+ }
51
+ let result;
52
+ try {
53
+ result = await options.verifier.verify(read, options.context ?? {});
54
+ }
55
+ catch (error) {
56
+ const message = error instanceof Error ? error.message : String(error);
57
+ return {
58
+ card: read.card,
59
+ verification: {
60
+ status: "unverified",
61
+ reason: limitReason(`verifier threw: ${message}`),
62
+ },
63
+ };
64
+ }
65
+ // A long reason is cut to fit rather than failing the whole result.
66
+ const returned = result?.verification;
67
+ const verification = AgentIdentityVerificationSchema.safeParse(isRecord(returned) &&
68
+ returned.status === "unverified" &&
69
+ typeof returned.reason === "string"
70
+ ? { ...returned, reason: limitReason(returned.reason) }
71
+ : returned);
72
+ if (!verification.success) {
73
+ return {
74
+ card: read.card,
75
+ verification: {
76
+ status: "unverified",
77
+ reason: "the verifier returned no valid result",
78
+ },
79
+ };
80
+ }
81
+ const stated = verification.data;
82
+ const canonical = ConsentEntityCardSchema.safeParse(result.card);
83
+ if (canonical.success && sameDid(canonical.data.id, read.card.id)) {
84
+ return { card: canonical.data, verification: stated };
85
+ }
86
+ if (stated.status !== "verified") {
87
+ return { card: read.card, verification: stated };
88
+ }
89
+ // Verified vouches for a card. Without the verifier's own card for this
90
+ // DID, the screen would show the presented document's name next to
91
+ // Verified, and that name is one nobody checked.
92
+ const { verifier, checkedAt } = stated;
93
+ return {
94
+ card: read.card,
95
+ verification: {
96
+ status: "unverified",
97
+ reason: limitReason(whyNotVouched(result.card, canonical, read.card.id)),
98
+ ...(verifier === undefined ? {} : { verifier }),
99
+ ...(checkedAt === undefined ? {} : { checkedAt }),
100
+ },
101
+ };
102
+ }
103
+ /** Why the card a `verified` result came with can't be shown. */
104
+ function whyNotVouched(card, canonical, did) {
105
+ if (card === undefined) {
106
+ return "the verifier said verified but returned no card";
107
+ }
108
+ if (!canonical.success) {
109
+ const issue = canonical.error.issues[0];
110
+ const detail = issue === undefined
111
+ ? "invalid"
112
+ : issue.path.length > 0
113
+ ? `${issue.path.join(".")}: ${issue.message}`
114
+ : issue.message;
115
+ return `the card the verifier vouched for doesn't validate (${detail})`;
116
+ }
117
+ return `the verifier vouched for a card for ${canonical.data.id}, not ${did}`;
118
+ }
119
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/identity/resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,gBAAgB,EAChB,WAAW,GAMZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAsB,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,OAAO,EAA0B,MAAM,kBAAkB,CAAC;AACnE,OAAO,EACL,+BAA+B,EAC/B,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AAatB;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,QAAiB,EACjB,UAAuC,EAAE;IAEzC,MAAM,IAAI,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IACzC,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,MAAM,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAChE,MAAM,QAAQ,GAAkB;QAC9B,IAAI;QACJ,YAAY,EAAE,gBAAgB,CAAC,IAAI,EAAE,YAAY,CAAC;KACnD,CAAC;IACF,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS;QAAE,QAAQ,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IACnE,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS;QACpC,QAAQ,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC/C,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS;QAAE,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACtE,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS;QAC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