agent-passport-system 4.1.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/README.md +37 -34
  2. package/dist/src/adapters/oauth-id-jag/import-v1.d.ts +74 -0
  3. package/dist/src/adapters/oauth-id-jag/import-v1.d.ts.map +1 -0
  4. package/dist/src/adapters/oauth-id-jag/import-v1.js +243 -0
  5. package/dist/src/adapters/oauth-id-jag/import-v1.js.map +1 -0
  6. package/dist/src/index.d.ts +3 -0
  7. package/dist/src/index.d.ts.map +1 -1
  8. package/dist/src/index.js +6 -0
  9. package/dist/src/index.js.map +1 -1
  10. package/dist/src/profiles/a2a/identity-v1.d.ts +44 -0
  11. package/dist/src/profiles/a2a/identity-v1.d.ts.map +1 -0
  12. package/dist/src/profiles/a2a/identity-v1.js +208 -0
  13. package/dist/src/profiles/a2a/identity-v1.js.map +1 -0
  14. package/dist/src/profiles/a2a/index.d.ts +2 -0
  15. package/dist/src/profiles/a2a/index.d.ts.map +1 -0
  16. package/dist/src/profiles/a2a/index.js +2 -0
  17. package/dist/src/profiles/a2a/index.js.map +1 -0
  18. package/dist/src/profiles/mcp/authorization-v1.d.ts +88 -0
  19. package/dist/src/profiles/mcp/authorization-v1.d.ts.map +1 -0
  20. package/dist/src/profiles/mcp/authorization-v1.js +215 -0
  21. package/dist/src/profiles/mcp/authorization-v1.js.map +1 -0
  22. package/dist/src/profiles/mcp/index.d.ts +2 -0
  23. package/dist/src/profiles/mcp/index.d.ts.map +1 -0
  24. package/dist/src/profiles/mcp/index.js +2 -0
  25. package/dist/src/profiles/mcp/index.js.map +1 -0
  26. package/dist/src/v2/action-reference/index.d.ts +2 -0
  27. package/dist/src/v2/action-reference/index.d.ts.map +1 -0
  28. package/dist/src/v2/action-reference/index.js +2 -0
  29. package/dist/src/v2/action-reference/index.js.map +1 -0
  30. package/dist/src/v2/action-reference/v2.d.ts +23 -0
  31. package/dist/src/v2/action-reference/v2.d.ts.map +1 -0
  32. package/dist/src/v2/action-reference/v2.js +57 -0
  33. package/dist/src/v2/action-reference/v2.js.map +1 -0
  34. package/dist/src/v2/authority-delegation/budget.d.ts +20 -0
  35. package/dist/src/v2/authority-delegation/budget.d.ts.map +1 -0
  36. package/dist/src/v2/authority-delegation/budget.js +141 -0
  37. package/dist/src/v2/authority-delegation/budget.js.map +1 -0
  38. package/dist/src/v2/authority-delegation/canonical.d.ts +12 -0
  39. package/dist/src/v2/authority-delegation/canonical.d.ts.map +1 -0
  40. package/dist/src/v2/authority-delegation/canonical.js +33 -0
  41. package/dist/src/v2/authority-delegation/canonical.js.map +1 -0
  42. package/dist/src/v2/authority-delegation/compare.d.ts +4 -0
  43. package/dist/src/v2/authority-delegation/compare.d.ts.map +1 -0
  44. package/dist/src/v2/authority-delegation/compare.js +67 -0
  45. package/dist/src/v2/authority-delegation/compare.js.map +1 -0
  46. package/dist/src/v2/authority-delegation/index.d.ts +10 -0
  47. package/dist/src/v2/authority-delegation/index.d.ts.map +1 -0
  48. package/dist/src/v2/authority-delegation/index.js +12 -0
  49. package/dist/src/v2/authority-delegation/index.js.map +1 -0
  50. package/dist/src/v2/authority-delegation/issue.d.ts +10 -0
  51. package/dist/src/v2/authority-delegation/issue.d.ts.map +1 -0
  52. package/dist/src/v2/authority-delegation/issue.js +52 -0
  53. package/dist/src/v2/authority-delegation/issue.js.map +1 -0
  54. package/dist/src/v2/authority-delegation/parse.d.ts +4 -0
  55. package/dist/src/v2/authority-delegation/parse.d.ts.map +1 -0
  56. package/dist/src/v2/authority-delegation/parse.js +96 -0
  57. package/dist/src/v2/authority-delegation/parse.js.map +1 -0
  58. package/dist/src/v2/authority-delegation/schema.d.ts +7 -0
  59. package/dist/src/v2/authority-delegation/schema.d.ts.map +1 -0
  60. package/dist/src/v2/authority-delegation/schema.js +177 -0
  61. package/dist/src/v2/authority-delegation/schema.js.map +1 -0
  62. package/dist/src/v2/authority-delegation/scope.d.ts +6 -0
  63. package/dist/src/v2/authority-delegation/scope.d.ts.map +1 -0
  64. package/dist/src/v2/authority-delegation/scope.js +50 -0
  65. package/dist/src/v2/authority-delegation/scope.js.map +1 -0
  66. package/dist/src/v2/authority-delegation/types.d.ts +98 -0
  67. package/dist/src/v2/authority-delegation/types.d.ts.map +1 -0
  68. package/dist/src/v2/authority-delegation/types.js +10 -0
  69. package/dist/src/v2/authority-delegation/types.js.map +1 -0
  70. package/dist/src/v2/authority-delegation/verify.d.ts +5 -0
  71. package/dist/src/v2/authority-delegation/verify.d.ts.map +1 -0
  72. package/dist/src/v2/authority-delegation/verify.js +124 -0
  73. package/dist/src/v2/authority-delegation/verify.js.map +1 -0
  74. package/dist/src/v2/identity-binding/did-aps.d.ts +12 -0
  75. package/dist/src/v2/identity-binding/did-aps.d.ts.map +1 -0
  76. package/dist/src/v2/identity-binding/did-aps.js +53 -0
  77. package/dist/src/v2/identity-binding/did-aps.js.map +1 -0
  78. package/dist/src/v2/identity-binding/index.d.ts +6 -0
  79. package/dist/src/v2/identity-binding/index.d.ts.map +1 -0
  80. package/dist/src/v2/identity-binding/index.js +6 -0
  81. package/dist/src/v2/identity-binding/index.js.map +1 -0
  82. package/dist/src/v2/identity-binding/passport.d.ts +18 -0
  83. package/dist/src/v2/identity-binding/passport.d.ts.map +1 -0
  84. package/dist/src/v2/identity-binding/passport.js +144 -0
  85. package/dist/src/v2/identity-binding/passport.js.map +1 -0
  86. package/dist/src/v2/identity-binding/principal-binding.d.ts +20 -0
  87. package/dist/src/v2/identity-binding/principal-binding.d.ts.map +1 -0
  88. package/dist/src/v2/identity-binding/principal-binding.js +128 -0
  89. package/dist/src/v2/identity-binding/principal-binding.js.map +1 -0
  90. package/dist/src/v2/identity-binding/revocation.d.ts +12 -0
  91. package/dist/src/v2/identity-binding/revocation.d.ts.map +1 -0
  92. package/dist/src/v2/identity-binding/revocation.js +97 -0
  93. package/dist/src/v2/identity-binding/revocation.js.map +1 -0
  94. package/dist/src/v2/identity-binding/types.d.ts +72 -0
  95. package/dist/src/v2/identity-binding/types.d.ts.map +1 -0
  96. package/dist/src/v2/identity-binding/types.js +4 -0
  97. package/dist/src/v2/identity-binding/types.js.map +1 -0
  98. package/dist/src/v2/identity-binding/validation.d.ts +9 -0
  99. package/dist/src/v2/identity-binding/validation.d.ts.map +1 -0
  100. package/dist/src/v2/identity-binding/validation.js +104 -0
  101. package/dist/src/v2/identity-binding/validation.js.map +1 -0
  102. package/dist/src/v2/receipt-core/decision-ref.d.ts +23 -0
  103. package/dist/src/v2/receipt-core/decision-ref.d.ts.map +1 -0
  104. package/dist/src/v2/receipt-core/decision-ref.js +75 -0
  105. package/dist/src/v2/receipt-core/decision-ref.js.map +1 -0
  106. package/dist/src/v2/receipt-core/jcs.d.ts +15 -0
  107. package/dist/src/v2/receipt-core/jcs.d.ts.map +1 -0
  108. package/dist/src/v2/receipt-core/jcs.js +198 -0
  109. package/dist/src/v2/receipt-core/jcs.js.map +1 -0
  110. package/dist/src/v2/receipt-core/receipt.d.ts +21 -0
  111. package/dist/src/v2/receipt-core/receipt.d.ts.map +1 -0
  112. package/dist/src/v2/receipt-core/receipt.js +132 -0
  113. package/dist/src/v2/receipt-core/receipt.js.map +1 -0
  114. package/dist/src/v2/receipt-core/supporting-record.d.ts +55 -0
  115. package/dist/src/v2/receipt-core/supporting-record.d.ts.map +1 -0
  116. package/dist/src/v2/receipt-core/supporting-record.js +243 -0
  117. package/dist/src/v2/receipt-core/supporting-record.js.map +1 -0
  118. package/dist/src/v2/receipt-core/types.d.ts +94 -0
  119. package/dist/src/v2/receipt-core/types.d.ts.map +1 -0
  120. package/dist/src/v2/receipt-core/types.js +4 -0
  121. package/dist/src/v2/receipt-core/types.js.map +1 -0
  122. package/package.json +6 -6
@@ -0,0 +1,67 @@
1
+ // Copyright (c) 2026 Tymofii Pidlisnyi
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { scopeNarrows } from './scope.js';
4
+ const REVERSIBILITY_RANK = {
5
+ tentative: 0,
6
+ compensable: 1,
7
+ irreversible: 2,
8
+ };
9
+ function fail(failures, code, facet, message) {
10
+ failures.push({ code, facet, message });
11
+ }
12
+ /** Compare a child against its immediate parent in the seven-facet partial order. */
13
+ export function compareAuthority(parent, child) {
14
+ const failures = [];
15
+ if (child.scope.profile !== parent.scope.profile) {
16
+ fail(failures, 'UNSUPPORTED_PROFILE', 'scope', 'scope profile changes are incomparable');
17
+ }
18
+ else if (!scopeNarrows(parent.scope.grants, child.scope.grants)) {
19
+ fail(failures, 'SCOPE_WIDENING', 'scope', 'child scope is not covered by parent scope');
20
+ }
21
+ if (parent.spend.mode === 'bounded') {
22
+ if (child.spend.mode === 'unbounded') {
23
+ fail(failures, 'SPEND_WIDENING', 'spend', 'bounded parent cannot produce unbounded child');
24
+ }
25
+ else if (child.spend.unit !== parent.spend.unit) {
26
+ fail(failures, 'SPEND_UNIT_CHANGE', 'spend', 'bounded spend unit must remain exact');
27
+ }
28
+ else if (BigInt(child.spend.per_action) > BigInt(parent.spend.per_action) ||
29
+ BigInt(child.spend.cumulative) > BigInt(parent.spend.cumulative)) {
30
+ fail(failures, 'SPEND_WIDENING', 'spend', 'child spend limits exceed parent limits');
31
+ }
32
+ }
33
+ if (parent.depth.remaining === 0) {
34
+ fail(failures, 'DEPTH_EXHAUSTED', 'depth', 'parent has no remaining delegation hop');
35
+ }
36
+ else if (child.depth.remaining > parent.depth.remaining - 1) {
37
+ fail(failures, 'DEPTH_WIDENING', 'depth', 'child remaining depth must consume at least one hop');
38
+ }
39
+ if (Date.parse(child.time.not_before) < Date.parse(parent.time.not_before) ||
40
+ Date.parse(child.time.not_after) > Date.parse(parent.time.not_after)) {
41
+ fail(failures, 'TIME_WIDENING', 'time', 'child validity window is not contained in parent window');
42
+ }
43
+ if (child.reputation.profile !== parent.reputation.profile) {
44
+ fail(failures, 'UNSUPPORTED_PROFILE', 'reputation', 'reputation profile changes are incomparable');
45
+ }
46
+ else if (child.reputation.ceiling > parent.reputation.ceiling) {
47
+ fail(failures, 'REPUTATION_WIDENING', 'reputation', 'child reputation ceiling exceeds parent');
48
+ }
49
+ if (child.values.profile !== parent.values.profile) {
50
+ fail(failures, 'UNSUPPORTED_PROFILE', 'values', 'values profile changes are incomparable');
51
+ }
52
+ else {
53
+ const childRequired = new Set(child.values.required);
54
+ if (parent.values.required.some(identifier => !childRequired.has(identifier))) {
55
+ fail(failures, 'VALUES_WEAKENING', 'values', 'child removed an ancestor-required value identifier');
56
+ }
57
+ }
58
+ if (child.reversibility.profile !== parent.reversibility.profile) {
59
+ fail(failures, 'UNSUPPORTED_PROFILE', 'reversibility', 'reversibility profile changes are incomparable');
60
+ }
61
+ else if (REVERSIBILITY_RANK[child.reversibility.ceiling] >
62
+ REVERSIBILITY_RANK[parent.reversibility.ceiling]) {
63
+ fail(failures, 'REVERSIBILITY_WIDENING', 'reversibility', 'child reversibility ceiling exceeds parent');
64
+ }
65
+ return failures;
66
+ }
67
+ //# sourceMappingURL=compare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare.js","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/compare.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,sCAAsC;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAGzC,MAAM,kBAAkB,GAAyC;IAC/D,SAAS,EAAE,CAAC;IACZ,WAAW,EAAE,CAAC;IACd,YAAY,EAAE,CAAC;CAChB,CAAA;AAED,SAAS,IAAI,CACX,QAA4B,EAC5B,IAA8B,EAC9B,KAA8B,EAC9B,OAAe;IAEf,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAA;AACzC,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,gBAAgB,CAC9B,MAAyB,EACzB,KAAwB;IAExB,MAAM,QAAQ,GAAuB,EAAE,CAAA;IAEvC,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,KAAK,MAAM,CAAC,KAAK,CAAC,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I,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;YAC9E,IAAI,CAAC,QAAQ,EAAE,kBAAkB,EAAE,QAAQ,EAAE,qDAAqD,CAAC,CAAA;QACrG,CAAC;IACH,CAAC;IAED,IAAI,KAAK,CAAC,aAAa,CAAC,OAAO,KAAK,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;QACjE,IAAI,CAAC,QAAQ,EAAE,qBAAqB,EAAE,eAAe,EAAE,gDAAgD,CAAC,CAAA;IAC1G,CAAC;SAAM,IAAI,kBAAkB,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC;QAC/C,kBAAkB,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5D,IAAI,CAAC,QAAQ,EAAE,wBAAwB,EAAE,eAAe,EAAE,4CAA4C,CAAC,CAAA;IACzG,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC"}
@@ -0,0 +1,10 @@
1
+ export * from './types.js';
2
+ export * from './schema.js';
3
+ export * from './scope.js';
4
+ export * from './canonical.js';
5
+ export * from './compare.js';
6
+ export * from './issue.js';
7
+ export * from './parse.js';
8
+ export * from './verify.js';
9
+ export * from './budget.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/index.ts"],"names":[],"mappings":"AAGA,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
@@ -0,0 +1,12 @@
1
+ // Copyright (c) 2026 Tymofii Pidlisnyi
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export * from './types.js';
4
+ export * from './schema.js';
5
+ export * from './scope.js';
6
+ export * from './canonical.js';
7
+ export * from './compare.js';
8
+ export * from './issue.js';
9
+ export * from './parse.js';
10
+ export * from './verify.js';
11
+ export * from './budget.js';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,sCAAsC;AAEtC,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
@@ -0,0 +1,10 @@
1
+ import type { AuthorityDelegationBodyV1, AuthorityDelegationV1 } from './types.js';
2
+ /** Create a deterministic v1 record from explicit body fields and an Ed25519 key. */
3
+ export declare function issueAuthorityDelegation(body: AuthorityDelegationBodyV1, privateKey: string): AuthorityDelegationV1;
4
+ /**
5
+ * Issue a child after immediate-parent attenuation checks. The caller must first
6
+ * validate the complete parent chain and revocation state; this pure primitive
7
+ * cannot establish live ancestor status by itself.
8
+ */
9
+ export declare function issueSubAuthorityDelegation(parent: AuthorityDelegationV1, body: AuthorityDelegationBodyV1, privateKey: string): AuthorityDelegationV1;
10
+ //# sourceMappingURL=issue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issue.d.ts","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/issue.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAclF,qFAAqF;AACrF,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,yBAAyB,EAC/B,UAAU,EAAE,MAAM,GACjB,qBAAqB,CAKvB;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,qBAAqB,EAC7B,IAAI,EAAE,yBAAyB,EAC/B,UAAU,EAAE,MAAM,GACjB,qBAAqB,CAsBvB"}
@@ -0,0 +1,52 @@
1
+ // Copyright (c) 2026 Tymofii Pidlisnyi
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { computeAuthorityDelegationId, signAuthorityDelegation, } from './canonical.js';
4
+ import { compareAuthority } from './compare.js';
5
+ import { validateAuthorityDelegationShape } from './schema.js';
6
+ function assertBody(body) {
7
+ const probe = {
8
+ ...body,
9
+ delegation_id: `sha256:${'0'.repeat(64)}`,
10
+ signature: '0'.repeat(128),
11
+ };
12
+ const failures = validateAuthorityDelegationShape(probe);
13
+ if (failures.length > 0) {
14
+ throw new Error(`authority delegation body invalid: ${failures.map(item => `${item.code}: ${item.message}`).join('; ')}`);
15
+ }
16
+ }
17
+ /** Create a deterministic v1 record from explicit body fields and an Ed25519 key. */
18
+ export function issueAuthorityDelegation(body, privateKey) {
19
+ assertBody(body);
20
+ const delegation_id = computeAuthorityDelegationId(body);
21
+ const unsigned = { ...body, delegation_id };
22
+ return { ...unsigned, signature: signAuthorityDelegation(unsigned, privateKey) };
23
+ }
24
+ /**
25
+ * Issue a child after immediate-parent attenuation checks. The caller must first
26
+ * validate the complete parent chain and revocation state; this pure primitive
27
+ * cannot establish live ancestor status by itself.
28
+ */
29
+ export function issueSubAuthorityDelegation(parent, body, privateKey) {
30
+ const parentFailures = validateAuthorityDelegationShape(parent);
31
+ if (parentFailures.length > 0) {
32
+ throw new Error(`authority delegation parent invalid: ${parentFailures.map(item => item.code).join(', ')}`);
33
+ }
34
+ assertBody(body);
35
+ if (body.parent_delegation_id !== parent.delegation_id) {
36
+ throw new Error('authority delegation parent mismatch');
37
+ }
38
+ if (body.issuer !== parent.subject) {
39
+ throw new Error('authority delegation chain continuity failure');
40
+ }
41
+ const issued = Date.parse(body.issued_at);
42
+ if (issued < Date.parse(parent.authority.time.not_before) ||
43
+ issued >= Date.parse(parent.authority.time.not_after)) {
44
+ throw new Error('authority delegation issued_at is outside parent validity');
45
+ }
46
+ const failures = compareAuthority(parent.authority, body.authority);
47
+ if (failures.length > 0) {
48
+ throw new Error(`authority delegation does not narrow: ${failures.map(item => item.code).join(', ')}`);
49
+ }
50
+ return issueAuthorityDelegation(body, privateKey);
51
+ }
52
+ //# sourceMappingURL=issue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issue.js","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/issue.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,sCAAsC;AAEtC,OAAO,EACL,4BAA4B,EAC5B,uBAAuB,GACxB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,gCAAgC,EAAE,MAAM,aAAa,CAAA;AAG9D,SAAS,UAAU,CAAC,IAA+B;IACjD,MAAM,KAAK,GAA0B;QACnC,GAAG,IAAI;QACP,aAAa,EAAE,UAAU,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;QACzC,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC;KAC3B,CAAA;IACD,MAAM,QAAQ,GAAG,gCAAgC,CAAC,KAAK,CAAC,CAAA;IACxD,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,sCAAsC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAC3H,CAAC;AACH,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,wBAAwB,CACtC,IAA+B,EAC/B,UAAkB;IAElB,UAAU,CAAC,IAAI,CAAC,CAAA;IAChB,MAAM,a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AAM,QAAQ,GAAG,gBAAgB,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;IACnE,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,yCAAyC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACxG,CAAC;IACD,OAAO,wBAAwB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;AACnD,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { AuthorityDelegationV1 } from './types.js';
2
+ /** Strict untrusted-wire entry point: valid JSON, I-JSON names, and closed v1 schema. */
3
+ export declare function parseAuthorityDelegationJson(source: string): AuthorityDelegationV1;
4
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/parse.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAsEvD,yFAAyF;AACzF,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,MAAM,GAAG,qBAAqB,CAWlF"}
@@ -0,0 +1,96 @@
1
+ // Copyright (c) 2026 Tymofii Pidlisnyi
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { validateAuthorityDelegationShape } from './schema.js';
4
+ const MAX_WIRE_BYTES = 1_048_576;
5
+ /**
6
+ * JSON.parse silently keeps the last occurrence of a duplicate member. RFC
7
+ * 8785 operates on I-JSON, so scan the already-syntax-checked source and reject
8
+ * repeated names at every object depth before accepting a signed record.
9
+ */
10
+ function rejectDuplicateMembers(source) {
11
+ let cursor = 0;
12
+ const skipWhitespace = () => {
13
+ while (cursor < source.length && /[\u0009\u000a\u000d\u0020]/.test(source[cursor]))
14
+ cursor++;
15
+ };
16
+ const readString = () => {
17
+ const start = cursor;
18
+ cursor++; // opening quote; whole-document JSON.parse already proved syntax
19
+ while (cursor < source.length) {
20
+ if (source[cursor] === '\\') {
21
+ cursor += 2;
22
+ }
23
+ else if (source[cursor++] === '"') {
24
+ return JSON.parse(source.slice(start, cursor));
25
+ }
26
+ }
27
+ throw new SyntaxError('unterminated JSON string');
28
+ };
29
+ const value = () => {
30
+ skipWhitespace();
31
+ const first = source[cursor];
32
+ if (first === '{') {
33
+ cursor++;
34
+ skipWhitespace();
35
+ const names = new Set();
36
+ if (source[cursor] === '}') {
37
+ cursor++;
38
+ return;
39
+ }
40
+ while (cursor < source.length) {
41
+ const name = readString();
42
+ if (names.has(name))
43
+ throw new SyntaxError('duplicate JSON object member');
44
+ names.add(name);
45
+ skipWhitespace();
46
+ cursor++; // colon
47
+ value();
48
+ skipWhitespace();
49
+ if (source[cursor++] === '}')
50
+ return;
51
+ skipWhitespace(); // comma was consumed
52
+ }
53
+ }
54
+ else if (first === '[') {
55
+ cursor++;
56
+ skipWhitespace();
57
+ if (source[cursor] === ']') {
58
+ cursor++;
59
+ return;
60
+ }
61
+ while (cursor < source.length) {
62
+ value();
63
+ skipWhitespace();
64
+ if (source[cursor++] === ']')
65
+ return;
66
+ }
67
+ }
68
+ else if (first === '"') {
69
+ readString();
70
+ }
71
+ else {
72
+ const start = cursor;
73
+ while (cursor < source.length && !/[\u0009\u000a\u000d\u0020,}\]]/.test(source[cursor]))
74
+ cursor++;
75
+ const token = source.slice(start, cursor);
76
+ if (/^[-0-9]/.test(token) && !/^-?(0|[1-9][0-9]*)$/.test(token)) {
77
+ throw new SyntaxError('non-integer JSON numbers are not permitted');
78
+ }
79
+ }
80
+ };
81
+ value();
82
+ }
83
+ /** Strict untrusted-wire entry point: valid JSON, I-JSON names, and closed v1 schema. */
84
+ export function parseAuthorityDelegationJson(source) {
85
+ if (typeof source !== 'string' || Buffer.byteLength(source, 'utf8') > MAX_WIRE_BYTES) {
86
+ throw new TypeError('authority delegation JSON must be a string no larger than 1 MiB');
87
+ }
88
+ const decoded = JSON.parse(source);
89
+ rejectDuplicateMembers(source);
90
+ const failures = validateAuthorityDelegationShape(decoded);
91
+ if (failures.length > 0) {
92
+ throw new TypeError(`authority delegation wire invalid: ${failures.map(item => item.code).join(', ')}`);
93
+ }
94
+ return decoded;
95
+ }
96
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/parse.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,sCAAsC;AAEtC,OAAO,EAAE,gCAAgC,EAAE,MAAM,aAAa,CAAA;AAG9D,MAAM,cAAc,GAAG,SAAS,CAAA;AAEhC;;;;GAIG;AACH,SAAS,sBAAsB,CAAC,MAAc;IAC5C,IAAI,MAAM,GAAG,CAAC,CAAA;IAEd,MAAM,cAAc,GAAG,GAAS,EAAE;QAChC,OAAO,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,4BAA4B,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAAE,MAAM,EAAE,CAAA;IAC9F,CAAC,CAAA;IACD,MAAM,UAAU,GAAG,GAAW,EAAE;QAC9B,MAAM,KAAK,GAAG,MAAM,CAAA;QACpB,MAAM,EAAE,CAAA,CAAC,iEAAiE;QAC1E,OAAO,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;YAC9B,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC5B,MAAM,IAAI,CAAC,CAAA;YACb,CAAC;iBAAM,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,GAAG,EAAE,CAAC;gBACpC,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAW,CAAA;YAC1D,CAAC;QACH,CAAC;QACD,MAAM,IAAI,WAAW,CAAC,0BAA0B,CAAC,CAAA;IACnD,C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OAAO,OAAgC,CAAA;AACzC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { AuthorityDelegationV1, AuthorityFailure } from './types.js';
2
+ export declare function isCanonicalTimestamp(value: unknown): value is string;
3
+ export declare function isCanonicalQuantity(value: unknown): value is string;
4
+ /** Closed-schema and canonical-value validation for an in-memory decoded record. */
5
+ export declare function validateAuthorityDelegationShape(value: unknown): AuthorityFailure[];
6
+ export declare function isAuthorityDelegationV1(value: unknown): value is AuthorityDelegationV1;
7
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/schema.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAmCzE,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAIpE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAGnE;AAMD,oFAAoF;AACpF,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,EAAE,CA4GnF;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,qBAAqB,CAEtF"}
@@ -0,0 +1,177 @@
1
+ // Copyright (c) 2026 Tymofii Pidlisnyi
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { grantsAreCanonical } from './scope.js';
4
+ import { AUTHORITY_DELEGATION_RECORD_TYPE, AUTHORITY_DELEGATION_VERSION, REPUTATION_PROFILE_V1, REVERSIBILITY_PROFILE_V1, SCOPE_PROFILE_V1, VALUES_PROFILE_V1, } from './types.js';
5
+ const ID = /^sha256:[0-9a-f]{64}$/;
6
+ const HEX_32 = /^[0-9a-f]{32}$/;
7
+ const HEX_128 = /^[0-9a-f]{128}$/;
8
+ const DECIMAL = /^(0|[1-9][0-9]*)$/;
9
+ const IDENTIFIER = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
10
+ const MAX_QUANTITY = 9223372036854775807n;
11
+ const MILLIS_UTC = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
12
+ function record(value) {
13
+ return value !== null && typeof value === 'object' && !Array.isArray(value)
14
+ ? value
15
+ : null;
16
+ }
17
+ function exactKeys(value, expected) {
18
+ const actual = Object.keys(value).sort();
19
+ const wanted = [...expected].sort();
20
+ return actual.length === wanted.length && actual.every((key, i) => key === wanted[i]);
21
+ }
22
+ function wellFormedUnicode(value) {
23
+ for (let i = 0; i < value.length; i++) {
24
+ const unit = value.charCodeAt(i);
25
+ if (unit >= 0xd800 && unit <= 0xdbff) {
26
+ const next = value.charCodeAt(++i);
27
+ if (!(next >= 0xdc00 && next <= 0xdfff))
28
+ return false;
29
+ }
30
+ else if (unit >= 0xdc00 && unit <= 0xdfff) {
31
+ return false;
32
+ }
33
+ }
34
+ return true;
35
+ }
36
+ export function isCanonicalTimestamp(value) {
37
+ if (typeof value !== 'string' || !MILLIS_UTC.test(value) || value.startsWith('0000-'))
38
+ return false;
39
+ const parsed = new Date(value);
40
+ return Number.isFinite(parsed.getTime()) && parsed.toISOString() === value;
41
+ }
42
+ export function isCanonicalQuantity(value) {
43
+ if (typeof value !== 'string' || !DECIMAL.test(value))
44
+ return false;
45
+ try {
46
+ return BigInt(value) <= MAX_QUANTITY;
47
+ }
48
+ catch {
49
+ return false;
50
+ }
51
+ }
52
+ function failure(code, message) {
53
+ return { code, message };
54
+ }
55
+ /** Closed-schema and canonical-value validation for an in-memory decoded record. */
56
+ export function validateAuthorityDelegationShape(value) {
57
+ const failures = [];
58
+ const top = record(value);
59
+ if (!top || !exactKeys(top, [
60
+ 'record_type', 'version', 'delegation_id', 'parent_delegation_id', 'issuer',
61
+ 'subject', 'verification_method', 'issued_at', 'nonce', 'authority', 'signature',
62
+ ]))
63
+ return [failure('SCHEMA_INVALID', 'delegation must be an exact closed v1 object')];
64
+ if (top.record_type !== AUTHORITY_DELEGATION_RECORD_TYPE || top.version !== AUTHORITY_DELEGATION_VERSION) {
65
+ failures.push(failure('UNSUPPORTED_VERSION', 'unsupported authority-delegation record_type or version'));
66
+ }
67
+ if (typeof top.delegation_id !== 'string' || !ID.test(top.delegation_id)) {
68
+ failures.push(failure('SCHEMA_INVALID', 'delegation_id must be sha256:<64 lowercase hex>'));
69
+ }
70
+ if (top.parent_delegation_id !== null &&
71
+ (typeof top.parent_delegation_id !== 'string' || !ID.test(top.parent_delegation_id))) {
72
+ failures.push(failure('SCHEMA_INVALID', 'parent_delegation_id must be null or a delegation digest'));
73
+ }
74
+ for (const key of ['issuer', 'subject', 'verification_method']) {
75
+ const item = top[key];
76
+ if (typeof item !== 'string' || item.length === 0 || Buffer.byteLength(item, 'utf8') > 1024 || !wellFormedUnicode(item)) {
77
+ failures.push(failure('SCHEMA_INVALID', `${key} must be a non-empty well-formed Unicode string`));
78
+ }
79
+ }
80
+ if (!isCanonicalTimestamp(top.issued_at))
81
+ failures.push(failure('NONCANONICAL_VALUE', 'issued_at must be canonical UTC milliseconds'));
82
+ if (typeof top.nonce !== 'string' || !HEX_32.test(top.nonce))
83
+ failures.push(failure('NONCANONICAL_VALUE', 'nonce must be 32 lowercase hex characters'));
84
+ if (typeof top.signature !== 'string' || !HEX_128.test(top.signature))
85
+ failures.push(failure('SCHEMA_INVALID', 'signature must be 128 lowercase hex characters'));
86
+ const authority = record(top.authority);
87
+ if (!authority || !exactKeys(authority, ['scope', 'spend', 'depth', 'time', 'reputation', 'values', 'reversibility'])) {
88
+ failures.push(failure('SCHEMA_INVALID', 'authority must carry exactly all seven facets'));
89
+ return failures;
90
+ }
91
+ const scope = record(authority.scope);
92
+ if (!scope || !exactKeys(scope, ['profile', 'grants']) || typeof scope.profile !== 'string' ||
93
+ !IDENTIFIER.test(scope.profile) || !Array.isArray(scope.grants) ||
94
+ !scope.grants.every(item => typeof item === 'string')) {
95
+ failures.push(failure('SCHEMA_INVALID', 'scope must contain profile and grants'));
96
+ }
97
+ else {
98
+ if (scope.profile !== SCOPE_PROFILE_V1)
99
+ failures.push(failure('UNSUPPORTED_PROFILE', 'unsupported scope profile'));
100
+ if (!grantsAreCanonical(scope.grants))
101
+ failures.push(failure('NONCANONICAL_VALUE', 'scope grants must be valid, sorted, unique, and irredundant'));
102
+ }
103
+ const spend = record(authority.spend);
104
+ if (!spend || typeof spend.mode !== 'string') {
105
+ failures.push(failure('SCHEMA_INVALID', 'spend must be a tagged object'));
106
+ }
107
+ else if (spend.mode === 'unbounded') {
108
+ if (!exactKeys(spend, ['mode']))
109
+ failures.push(failure('SCHEMA_INVALID', 'unbounded spend has no other fields'));
110
+ }
111
+ else if (spend.mode === 'bounded') {
112
+ if (!exactKeys(spend, ['mode', 'unit', 'per_action', 'cumulative']) ||
113
+ typeof spend.unit !== 'string' || !IDENTIFIER.test(spend.unit) ||
114
+ !isCanonicalQuantity(spend.per_action) || !isCanonicalQuantity(spend.cumulative)) {
115
+ failures.push(failure('NONCANONICAL_VALUE', 'bounded spend fields are malformed'));
116
+ }
117
+ else if (BigInt(spend.per_action) > BigInt(spend.cumulative)) {
118
+ failures.push(failure('SCHEMA_INVALID', 'spend per_action cannot exceed cumulative'));
119
+ }
120
+ }
121
+ else
122
+ failures.push(failure('SCHEMA_INVALID', 'unknown spend mode'));
123
+ const depth = record(authority.depth);
124
+ if (!depth || !exactKeys(depth, ['remaining']) || !Number.isInteger(depth.remaining) ||
125
+ depth.remaining < 0 || depth.remaining > 255) {
126
+ failures.push(failure('SCHEMA_INVALID', 'depth.remaining must be an integer from 0 through 255'));
127
+ }
128
+ const time = record(authority.time);
129
+ if (!time || !exactKeys(time, ['not_before', 'not_after']) ||
130
+ !isCanonicalTimestamp(time.not_before) || !isCanonicalTimestamp(time.not_after)) {
131
+ failures.push(failure('NONCANONICAL_VALUE', 'time bounds must be canonical UTC milliseconds'));
132
+ }
133
+ else if (Date.parse(time.not_before) >= Date.parse(time.not_after)) {
134
+ failures.push(failure('SCHEMA_INVALID', 'time window must be non-empty'));
135
+ }
136
+ else if (isCanonicalTimestamp(top.issued_at) && Date.parse(time.not_before) < Date.parse(top.issued_at)) {
137
+ failures.push(failure('SCHEMA_INVALID', 'time.not_before cannot predate issued_at'));
138
+ }
139
+ const reputation = record(authority.reputation);
140
+ if (!reputation || !exactKeys(reputation, ['profile', 'ceiling']) ||
141
+ typeof reputation.profile !== 'string' || !IDENTIFIER.test(reputation.profile) ||
142
+ !Number.isInteger(reputation.ceiling) || reputation.ceiling < 0 ||
143
+ reputation.ceiling > 100) {
144
+ failures.push(failure('SCHEMA_INVALID', 'reputation ceiling must be an integer from 0 through 100'));
145
+ }
146
+ else if (reputation.profile !== REPUTATION_PROFILE_V1) {
147
+ failures.push(failure('UNSUPPORTED_PROFILE', 'unsupported reputation profile'));
148
+ }
149
+ const values = record(authority.values);
150
+ if (!values || !exactKeys(values, ['profile', 'required']) || typeof values.profile !== 'string' ||
151
+ !IDENTIFIER.test(values.profile) || !Array.isArray(values.required) ||
152
+ !values.required.every(item => typeof item === 'string' && IDENTIFIER.test(item))) {
153
+ failures.push(failure('SCHEMA_INVALID', 'values.required must contain valid identifiers'));
154
+ }
155
+ else {
156
+ if (values.profile !== VALUES_PROFILE_V1)
157
+ failures.push(failure('UNSUPPORTED_PROFILE', 'unsupported values profile'));
158
+ const required = values.required;
159
+ if (required.some((item, i) => i > 0 && required[i - 1] >= item)) {
160
+ failures.push(failure('NONCANONICAL_VALUE', 'values.required must be sorted and unique'));
161
+ }
162
+ }
163
+ const reversibility = record(authority.reversibility);
164
+ if (!reversibility || !exactKeys(reversibility, ['profile', 'ceiling']) ||
165
+ typeof reversibility.profile !== 'string' || !IDENTIFIER.test(reversibility.profile) ||
166
+ !['tentative', 'compensable', 'irreversible'].includes(String(reversibility.ceiling))) {
167
+ failures.push(failure('SCHEMA_INVALID', 'reversibility facet is malformed'));
168
+ }
169
+ else if (reversibility.profile !== REVERSIBILITY_PROFILE_V1) {
170
+ failures.push(failure('UNSUPPORTED_PROFILE', 'unsupported reversibility profile'));
171
+ }
172
+ return failures;
173
+ }
174
+ export function isAuthorityDelegationV1(value) {
175
+ return validateAuthorityDelegationShape(value).length === 0;
176
+ }
177
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/schema.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,sCAAsC;AAEtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EACL,gCAAgC,EAChC,4BAA4B,EAC5B,qBAAqB,EACrB,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,YAAY,CAAA;AAGnB,MAAM,EAAE,GAAG,uBAAuB,CAAA;AAClC,MAAM,MAAM,GAAG,gBAAgB,CAAA;AAC/B,MAAM,OAAO,GAAG,iBAAiB,CAAA;AACjC,MAAM,OAAO,GAAG,mBAAmB,CAAA;AACnC,MAAM,UAAU,GAAG,qCAAqC,CAAA;AACxD,MAAM,YAAY,GAAG,oBAAoB,CAAA;AACzC,MAAM,UAAU,GAAG,+CAA+C,CAAA;AAElE,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACzE,CAAC,CAAC,KAAgC;QAClC,CAAC,CAAC,IAAI,CAAA;AACV,CAAC;AAED,SAAS,SAAS,CAAC,KAA8B,EAAE,QAA2B;IAC5E,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAA;IACxC,MAAM,MAAM,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAA;IACnC,OAAO,MAAM,CAAC,MAAM,KAAK,MAAM,CA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ean;
2
+ /** Exact grants cover only themselves. A terminal :* grant covers its prefix and descendants. */
3
+ export declare function scopeGrantCovers(parent: string, child: string): boolean;
4
+ export declare function grantsAreCanonical(grants: readonly string[]): boolean;
5
+ export declare function scopeNarrows(parent: readonly string[], child: readonly string[]): boolean;
6
+ //# sourceMappingURL=scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/scope.ts"],"names":[],"mappings":"AAKA,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CASxD;AAED,iGAAiG;AACjG,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAQvE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAYrE;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAEzF"}
@@ -0,0 +1,50 @@
1
+ // Copyright (c) 2026 Tymofii Pidlisnyi
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ const SEGMENT = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
4
+ export function isValidScopeGrant(grant) {
5
+ if (grant === '*')
6
+ return true;
7
+ if (typeof grant !== 'string' || grant.length === 0 || grant.length > 255)
8
+ return false;
9
+ const parts = grant.split(':');
10
+ if (parts.length > 16)
11
+ return false;
12
+ const wildcard = parts.at(-1) === '*';
13
+ if (wildcard)
14
+ parts.pop();
15
+ if (parts.length === 0 || parts.some(part => !SEGMENT.test(part)))
16
+ return false;
17
+ return !parts.includes('*');
18
+ }
19
+ /** Exact grants cover only themselves. A terminal :* grant covers its prefix and descendants. */
20
+ export function scopeGrantCovers(parent, child) {
21
+ if (parent === '*')
22
+ return true;
23
+ if (parent.endsWith(':*')) {
24
+ const prefix = parent.slice(0, -2);
25
+ const childPrefix = child.endsWith(':*') ? child.slice(0, -2) : child;
26
+ return childPrefix === prefix || childPrefix.startsWith(prefix + ':');
27
+ }
28
+ return parent === child;
29
+ }
30
+ export function grantsAreCanonical(grants) {
31
+ if (!Array.isArray(grants))
32
+ return false;
33
+ for (let i = 0; i < grants.length; i++) {
34
+ const grant = grants[i];
35
+ if (!isValidScopeGrant(grant))
36
+ return false;
37
+ if (i > 0 && grants[i - 1] >= grant)
38
+ return false;
39
+ // A canonical set is an antichain: no entry is redundant under another entry.
40
+ for (let j = 0; j < grants.length; j++) {
41
+ if (i !== j && scopeGrantCovers(grants[j], grant))
42
+ return false;
43
+ }
44
+ }
45
+ return true;
46
+ }
47
+ export function scopeNarrows(parent, child) {
48
+ return child.every(grant => parent.some(parentGrant => scopeGrantCovers(parentGrant, grant)));
49
+ }
50
+ //# sourceMappingURL=scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/scope.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,sCAAsC;AAEtC,MAAM,OAAO,GAAG,mCAAmC,CAAA;AAEnD,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,IAAI,KAAK,KAAK,GAAG;QAAE,OAAO,IAAI,CAAA;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,GAAG;QAAE,OAAO,KAAK,CAAA;IACvF,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC9B,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE;QAAE,OAAO,KAAK,CAAA;IACnC,MAAM,QAAQ,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAA;IACrC,IAAI,QAAQ;QAAE,KAAK,CAAC,GAAG,EAAE,CAAA;IACzB,IAAI,K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