@kya-os/consent 0.1.46 → 0.1.48

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 (112) hide show
  1. package/README.md +89 -0
  2. package/dist/bundle/index.d.ts +2 -0
  3. package/dist/bundle/index.d.ts.map +1 -1
  4. package/dist/bundle/index.js +1 -0
  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/capabilities/registry.d.ts.map +1 -1
  10. package/dist/capabilities/registry.js +5 -1
  11. package/dist/capabilities/registry.js.map +1 -1
  12. package/dist/cedar/compile.d.ts +67 -2
  13. package/dist/cedar/compile.d.ts.map +1 -1
  14. package/dist/cedar/compile.js +34 -5
  15. package/dist/cedar/compile.js.map +1 -1
  16. package/dist/cedar/index.d.ts +1 -0
  17. package/dist/cedar/index.d.ts.map +1 -1
  18. package/dist/cedar/index.js.map +1 -1
  19. package/dist/cjs/bundle/index.js +3 -1
  20. package/dist/cjs/bundle/index.js.map +1 -1
  21. package/dist/cjs/bundle/inline.js +4 -4
  22. package/dist/cjs/bundle/inline.js.map +1 -1
  23. package/dist/cjs/capabilities/registry.js +5 -1
  24. package/dist/cjs/capabilities/registry.js.map +1 -1
  25. package/dist/cjs/cedar/compile.js +34 -5
  26. package/dist/cjs/cedar/compile.js.map +1 -1
  27. package/dist/cjs/cedar/index.js.map +1 -1
  28. package/dist/cjs/components/consent-action-bar.js +16 -5
  29. package/dist/cjs/components/consent-action-bar.js.map +1 -1
  30. package/dist/cjs/components/consent-capabilities-screen.js +92 -37
  31. package/dist/cjs/components/consent-capabilities-screen.js.map +1 -1
  32. package/dist/cjs/components/consent-capability-card.js +35 -4
  33. package/dist/cjs/components/consent-capability-card.js.map +1 -1
  34. package/dist/cjs/components/mcp-consent.js +91 -25
  35. package/dist/cjs/components/mcp-consent.js.map +1 -1
  36. package/dist/cjs/constants/capabilities.js +10 -0
  37. package/dist/cjs/constants/capabilities.js.map +1 -0
  38. package/dist/cjs/constants/index.js +3 -1
  39. package/dist/cjs/constants/index.js.map +1 -1
  40. package/dist/cjs/mcp-app/inline.js +2 -2
  41. package/dist/cjs/mcp-app/inline.js.map +1 -1
  42. package/dist/cjs/resolution/credential-capabilities.js +16 -0
  43. package/dist/cjs/resolution/credential-capabilities.js.map +1 -1
  44. package/dist/cjs/resolution/selected-capabilities.js +73 -0
  45. package/dist/cjs/resolution/selected-capabilities.js.map +1 -0
  46. package/dist/cjs/schemas/capabilities.schemas.js +14 -2
  47. package/dist/cjs/schemas/capabilities.schemas.js.map +1 -1
  48. package/dist/cjs/security/identity-assertion.js +69 -0
  49. package/dist/cjs/security/identity-assertion.js.map +1 -0
  50. package/dist/cjs/security/index.js +1 -0
  51. package/dist/cjs/security/index.js.map +1 -1
  52. package/dist/cjs/types/capabilities.types.js +55 -0
  53. package/dist/cjs/types/capabilities.types.js.map +1 -1
  54. package/dist/components/consent-action-bar.d.ts +2 -0
  55. package/dist/components/consent-action-bar.d.ts.map +1 -1
  56. package/dist/components/consent-action-bar.js +16 -5
  57. package/dist/components/consent-action-bar.js.map +1 -1
  58. package/dist/components/consent-capabilities-screen.d.ts +18 -5
  59. package/dist/components/consent-capabilities-screen.d.ts.map +1 -1
  60. package/dist/components/consent-capabilities-screen.js +92 -37
  61. package/dist/components/consent-capabilities-screen.js.map +1 -1
  62. package/dist/components/consent-capability-card.d.ts +2 -0
  63. package/dist/components/consent-capability-card.d.ts.map +1 -1
  64. package/dist/components/consent-capability-card.js +35 -4
  65. package/dist/components/consent-capability-card.js.map +1 -1
  66. package/dist/components/mcp-consent.d.ts +30 -0
  67. package/dist/components/mcp-consent.d.ts.map +1 -1
  68. package/dist/components/mcp-consent.js +92 -26
  69. package/dist/components/mcp-consent.js.map +1 -1
  70. package/dist/consent.js +280 -48
  71. package/dist/consent.min.js +200 -153
  72. package/dist/constants/capabilities.d.ts +7 -0
  73. package/dist/constants/capabilities.d.ts.map +1 -0
  74. package/dist/constants/capabilities.js +7 -0
  75. package/dist/constants/capabilities.js.map +1 -0
  76. package/dist/constants/index.d.ts +1 -0
  77. package/dist/constants/index.d.ts.map +1 -1
  78. package/dist/constants/index.js +1 -0
  79. package/dist/constants/index.js.map +1 -1
  80. package/dist/mcp-app/inline.d.ts.map +1 -1
  81. package/dist/mcp-app/inline.js +2 -2
  82. package/dist/mcp-app/inline.js.map +1 -1
  83. package/dist/resolution/credential-capabilities.d.ts +15 -2
  84. package/dist/resolution/credential-capabilities.d.ts.map +1 -1
  85. package/dist/resolution/credential-capabilities.js +15 -0
  86. package/dist/resolution/credential-capabilities.js.map +1 -1
  87. package/dist/resolution/selected-capabilities.d.ts +26 -0
  88. package/dist/resolution/selected-capabilities.d.ts.map +1 -0
  89. package/dist/resolution/selected-capabilities.js +69 -0
  90. package/dist/resolution/selected-capabilities.js.map +1 -0
  91. package/dist/schemas/api.schemas.d.ts +88 -68
  92. package/dist/schemas/api.schemas.d.ts.map +1 -1
  93. package/dist/schemas/branding.schemas.d.ts +2 -2
  94. package/dist/schemas/capabilities.schemas.d.ts +58 -12
  95. package/dist/schemas/capabilities.schemas.d.ts.map +1 -1
  96. package/dist/schemas/capabilities.schemas.js +14 -2
  97. package/dist/schemas/capabilities.schemas.js.map +1 -1
  98. package/dist/schemas/config.schemas.d.ts +140 -100
  99. package/dist/schemas/config.schemas.d.ts.map +1 -1
  100. package/dist/security/identity-assertion.d.ts +49 -0
  101. package/dist/security/identity-assertion.d.ts.map +1 -0
  102. package/dist/security/identity-assertion.js +66 -0
  103. package/dist/security/identity-assertion.js.map +1 -0
  104. package/dist/security/index.d.ts +1 -0
  105. package/dist/security/index.d.ts.map +1 -1
  106. package/dist/security/index.js +1 -0
  107. package/dist/security/index.js.map +1 -1
  108. package/dist/types/capabilities.types.d.ts +69 -0
  109. package/dist/types/capabilities.types.d.ts.map +1 -1
  110. package/dist/types/capabilities.types.js +53 -1
  111. package/dist/types/capabilities.types.js.map +1 -1
  112. package/package.json +6 -4
@@ -1 +1 @@
1
- {"version":3,"file":"inline.js","sourceRoot":"","sources":["../../src/mcp-app/inline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,sEAAsE;AACtE,MAAM,CAAC,MAAM,oBAAoB,GAAW,+qlvBAA+qlvB,CAAC;AAE5tlvB,4CAA4C;AAC5C,MAAM,CAAC,MAAM,yBAAyB,GAAW,MAAM,CAAC"}
1
+ {"version":3,"file":"inline.js","sourceRoot":"","sources":["../../src/mcp-app/inline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,sEAAsE;AACtE,MAAM,CAAC,MAAM,oBAAoB,GAAW,mnxvBAAmnxvB,CAAC;AAEhqxvB,4CAA4C;AAC5C,MAAM,CAAC,MAAM,yBAAyB,GAAW,MAAM,CAAC"}
@@ -8,12 +8,25 @@ export declare function shouldRenderCapabilityScreen(mode: AuthMode, capabilityC
8
8
  */
9
9
  export declare function shouldSelectAllCapabilities(mode: AuthMode): boolean;
10
10
  export declare function areCredentialsComplete(formData: Record<string, string>): boolean;
11
+ /**
12
+ * Whether the legacy scope-selection checkboxes (`renderPermissions` /
13
+ * `<consent-permissions>`) should render as interactive. When a signed
14
+ * identity assertion is bound to the request, `handleApprove` always posts
15
+ * the full requested scope set - the assertion binds a hash of that full
16
+ * set, so a user-narrowed subset would fail the mint gate's hash check and
17
+ * 403 (see the comment on the `scopes` form-data append in mcp-consent.ts).
18
+ * Letting the user uncheck a scope that will be granted regardless is a
19
+ * consent-accuracy bug, so this path drops to display-only rows instead.
20
+ * Interactive narrowing returns once the deferred subset-binding follow-up
21
+ * ships.
22
+ */
23
+ export declare function shouldRenderScopesInteractive(identityAssertion: string | undefined): boolean;
11
24
  /**
12
25
  * Which capabilities count as selected. In disclosure mode every capability is
13
26
  * granted, so all ids are returned; otherwise the operator's `defaultOn` seeds
14
27
  * the initial selection.
15
28
  */
16
- export declare function capabilityIdsFor(capabilities: Capability[], disclosureMode: boolean): string[];
29
+ export declare function capabilityIdsFor(capabilities: ReadonlyArray<Pick<Capability, "id" | "defaultOn">>, disclosureMode: boolean): string[];
17
30
  /**
18
31
  * Identity of a seeding decision: the capability ids in order, plus the
19
32
  * all-selected flag. Lit compares properties by reference, so a parent that
@@ -21,5 +34,5 @@ export declare function capabilityIdsFor(capabilities: Capability[], disclosureM
21
34
  * wipe the user's toggles) on every keystroke. Seeding is keyed on this value
22
35
  * instead of array identity.
23
36
  */
24
- export declare function capabilitySeedKey(capabilities: Capability[], allSelected: boolean): string;
37
+ export declare function capabilitySeedKey(capabilities: ReadonlyArray<Pick<Capability, "id" | "defaultOn">>, allSelected: boolean): string;
25
38
  //# sourceMappingURL=credential-capabilities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"credential-capabilities.d.ts","sourceRoot":"","sources":["../../src/resolution/credential-capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAYjE,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,QAAQ,EACd,eAAe,EAAE,MAAM,GACtB,OAAO,CAET;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAEnE;AAED,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAKT;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,UAAU,EAAE,EAC1B,cAAc,EAAE,OAAO,GACtB,MAAM,EAAE,CAIV;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,UAAU,EAAE,EAC1B,WAAW,EAAE,OAAO,GACnB,MAAM,CAER"}
1
+ {"version":3,"file":"credential-capabilities.d.ts","sourceRoot":"","sources":["../../src/resolution/credential-capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAYjE,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,QAAQ,EACd,eAAe,EAAE,MAAM,GACtB,OAAO,CAET;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAEnE;AAED,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAKT;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,6BAA6B,CAC3C,iBAAiB,EAAE,MAAM,GAAG,SAAS,GACpC,OAAO,CAET;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,aAAa,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,GAAG,WAAW,CAAC,CAAC,EACjE,cAAc,EAAE,OAAO,GACtB,MAAM,EAAE,CAIV;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,aAAa,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,GAAG,WAAW,CAAC,CAAC,EACjE,WAAW,EAAE,OAAO,GACnB,MAAM,CAER"}
@@ -23,6 +23,21 @@ export function areCredentialsComplete(formData) {
23
23
  return ((formData.username?.trim().length ?? 0) > 0 &&
24
24
  (formData.password?.trim().length ?? 0) > 0);
25
25
  }
26
+ /**
27
+ * Whether the legacy scope-selection checkboxes (`renderPermissions` /
28
+ * `<consent-permissions>`) should render as interactive. When a signed
29
+ * identity assertion is bound to the request, `handleApprove` always posts
30
+ * the full requested scope set - the assertion binds a hash of that full
31
+ * set, so a user-narrowed subset would fail the mint gate's hash check and
32
+ * 403 (see the comment on the `scopes` form-data append in mcp-consent.ts).
33
+ * Letting the user uncheck a scope that will be granted regardless is a
34
+ * consent-accuracy bug, so this path drops to display-only rows instead.
35
+ * Interactive narrowing returns once the deferred subset-binding follow-up
36
+ * ships.
37
+ */
38
+ export function shouldRenderScopesInteractive(identityAssertion) {
39
+ return !identityAssertion;
40
+ }
26
41
  /**
27
42
  * Which capabilities count as selected. In disclosure mode every capability is
28
43
  * granted, so all ids are returned; otherwise the operator's `defaultOn` seeds
@@ -1 +1 @@
1
- {"version":3,"file":"credential-capabilities.js","sourceRoot":"","sources":["../../src/resolution/credential-capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAiB,MAAM,yBAAyB,CAAC;AAGpE;;;;GAIG;AACH,MAAM,uBAAuB,GAAwB;IACnD,UAAU,CAAC,YAAY;IACvB,UAAU,CAAC,WAAW;CACvB,CAAC;AAEF,MAAM,UAAU,4BAA4B,CAC1C,IAAc,EACd,eAAuB;IAEvB,OAAO,eAAe,GAAG,CAAC,IAAI,uBAAuB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACvE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CAAC,IAAc;IACxD,OAAO,IAAI,KAAK,UAAU,CAAC,WAAW,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,QAAgC;IAEhC,OAAO,CACL,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC;QAC3C,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,CAC5C,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,YAA0B,EAC1B,cAAuB;IAEvB,OAAO,YAAY;SAChB,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,cAAc,IAAI,UAAU,CAAC,SAAS,CAAC;SAC9D,GAAG,CAAC,CAAC,UAAU,EAAE,E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UAAU,gBAAgB,CAC9B,YAAiE,EACjE,cAAuB;IAEvB,OAAO,YAAY;SAChB,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,cAAc,IAAI,UAAU,CAAC,SAAS,CAAC;SAC9D,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,YAAiE,EACjE,WAAoB;IAEpB,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AAC7E,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { Capability } from "../types/capabilities.types.js";
2
+ type ScopeCapability = Pick<Capability, "id" | "scopes"> & {
3
+ cedar?: string;
4
+ };
5
+ export type RequestedCapabilities<T extends ScopeCapability> = {
6
+ ok: true;
7
+ capabilities: T[];
8
+ } | {
9
+ ok: false;
10
+ error: string;
11
+ };
12
+ type SelectionResult = {
13
+ ok: true;
14
+ scopes: string[];
15
+ } | {
16
+ ok: false;
17
+ error: string;
18
+ };
19
+ /** Project a registry or project catalog onto this request before disclosure.
20
+ * Never rewrite a broader Cedar template as if it were an exact grant policy. */
21
+ export declare function projectRequestedCapabilities<T extends ScopeCapability>(requestedScopes: string[], capabilities: T[]): RequestedCapabilities<T>;
22
+ /** Derive the posted scope set from the reviewed capability IDs, without aliases
23
+ * or implicit widening. An assertion-bound or credential grant is indivisible. */
24
+ export declare function resolveCapabilitySelection(requestedScopes: string[], capabilities: ScopeCapability[], detail: unknown, requireAll?: boolean): SelectionResult;
25
+ export {};
26
+ //# sourceMappingURL=selected-capabilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selected-capabilities.d.ts","sourceRoot":"","sources":["../../src/resolution/selected-capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAEjE,KAAK,eAAe,GAAG,IAAI,CAAC,UAAU,EAAE,IAAI,GAAG,QAAQ,CAAC,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAC9E,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,eAAe,IACvD;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,YAAY,EAAE,CAAC,EAAE,CAAA;CAAE,GAC/B;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AACjC,KAAK,eAAe,GAChB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,GAC9B;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAcjC;iFACiF;AACjF,wBAAgB,4BAA4B,CAAC,CAAC,SAAS,eAAe,EACpE,eAAe,EAAE,MAAM,EAAE,EACzB,YAAY,EAAE,CAAC,EAAE,GAChB,qBAAqB,CAAC,CAAC,CAAC,CA2B1B;AAED;kFACkF;AAClF,wBAAgB,0BAA0B,CACxC,eAAe,EAAE,MAAM,EAAE,EACzB,YAAY,EAAE,eAAe,EAAE,EAC/B,MAAM,EAAE,OAAO,EACf,UAAU,UAAQ,GACjB,eAAe,CA0BjB"}
@@ -0,0 +1,69 @@
1
+ const MAPPING_ERROR = "The displayed capability scopes do not match the requested permissions. Contact the service operator.";
2
+ const SELECTION_ERROR = "Select at least one listed permission.";
3
+ function strings(value) {
4
+ return Array.isArray(value) && value.every((item) => typeof item === "string" && item.length > 0);
5
+ }
6
+ function sameSet(left, right) {
7
+ return left.size === right.size && [...left].every((value) => right.has(value));
8
+ }
9
+ /** Project a registry or project catalog onto this request before disclosure.
10
+ * Never rewrite a broader Cedar template as if it were an exact grant policy. */
11
+ export function projectRequestedCapabilities(requestedScopes, capabilities) {
12
+ if (!strings(requestedScopes) || requestedScopes.length === 0 ||
13
+ capabilities.length === 0 || capabilities.some((capability) => !capability || typeof capability.id !== "string" || !capability.id ||
14
+ !strings(capability.scopes) || capability.scopes.length === 0)) {
15
+ return { ok: false, error: MAPPING_ERROR };
16
+ }
17
+ const knownIds = new Set(capabilities.map((capability) => capability.id));
18
+ const requested = new Set(requestedScopes);
19
+ const disclosed = new Set(capabilities.flatMap((capability) => capability.scopes));
20
+ // Credential session keys hash the requested array, including duplicates.
21
+ // Reject ambiguous requests instead of silently normalizing their key.
22
+ if (requested.size !== requestedScopes.length ||
23
+ knownIds.size !== capabilities.length || [...requested].some((scope) => !disclosed.has(scope))) {
24
+ return { ok: false, error: MAPPING_ERROR };
25
+ }
26
+ const projected = capabilities.flatMap((capability) => {
27
+ const scopes = requestedScopes.filter((scope) => capability.scopes.includes(scope));
28
+ if (scopes.length === 0)
29
+ return [];
30
+ return [{
31
+ ...capability,
32
+ scopes,
33
+ // Keep the operator's exact policy only when its full scope set applies.
34
+ cedar: scopes.length === new Set(capability.scopes).size ? capability.cedar : "",
35
+ }];
36
+ });
37
+ return { ok: true, capabilities: projected };
38
+ }
39
+ /** Derive the posted scope set from the reviewed capability IDs, without aliases
40
+ * or implicit widening. An assertion-bound or credential grant is indivisible. */
41
+ export function resolveCapabilitySelection(requestedScopes, capabilities, detail, requireAll = false) {
42
+ const projection = projectRequestedCapabilities(requestedScopes, capabilities);
43
+ if (!projection.ok)
44
+ return projection;
45
+ const requestedCapabilities = projection.capabilities;
46
+ const knownIds = new Set(requestedCapabilities.map((capability) => capability.id));
47
+ if (!detail || typeof detail !== "object" ||
48
+ !("selectedCapabilityIds" in detail) || !strings(detail.selectedCapabilityIds) ||
49
+ !("selectedScopes" in detail) || !strings(detail.selectedScopes)) {
50
+ return { ok: false, error: SELECTION_ERROR };
51
+ }
52
+ const selectedIds = new Set(detail.selectedCapabilityIds);
53
+ if (selectedIds.size === 0 || selectedIds.size !== detail.selectedCapabilityIds.length ||
54
+ [...selectedIds].some((id) => !knownIds.has(id))) {
55
+ return { ok: false, error: SELECTION_ERROR };
56
+ }
57
+ if (requireAll && selectedIds.size !== knownIds.size) {
58
+ return { ok: false, error: "This grant requires every listed permission. Select all permissions or deny the request." };
59
+ }
60
+ const selectedScopes = new Set(requestedCapabilities
61
+ .filter((capability) => selectedIds.has(capability.id))
62
+ .flatMap((capability) => capability.scopes));
63
+ if (!sameSet(selectedScopes, new Set(detail.selectedScopes))) {
64
+ return { ok: false, error: SELECTION_ERROR };
65
+ }
66
+ // Preserve the canonical request ordering used by credential session keys.
67
+ return { ok: true, scopes: requestedScopes.filter((scope) => selectedScopes.has(scope)) };
68
+ }
69
+ //# sourceMappingURL=selected-capabilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selected-capabilities.js","sourceRoot":"","sources":["../../src/resolution/selected-capabilities.ts"],"names":[],"mappings":"AAUA,MAAM,aAAa,GACjB,uGAAuG,CAAC;AAC1G,MAAM,eAAe,GAAG,wCAAwC,CAAC;AAEjE,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACpG,CAAC;AAED,SAAS,OAAO,CAAC,IAAiB,EAAE,KAAkB;IACpD,OAAO,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAClF,CAAC;AAED;iFACiF;AACjF,MAAM,UAAU,4BAA4B,CAC1C,eAAyB,EACzB,YAAiB;IAEjB,I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