@agenticprimitives/admission 0.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Agentic Trust Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # @agenticprimitives/admission
2
+
3
+ Admission contracts for the Agentic Primitives Edge — the boundary between external agent intentions
4
+ and internal agent capabilities.
5
+
6
+ **Architect-of-record:** [spec 339](https://github.com/agentictrustlabs/agenticprimitives/blob/master/specs/339-agentic-primitives-edge-https-admission.md) ·
7
+ [ADR-0057](https://github.com/agentictrustlabs/agenticprimitives/blob/master/docs/architecture/decisions/0057-a2a-over-https-admission-mtls-optional.md)
8
+
9
+ ```text
10
+ HTTPS is required.
11
+ mTLS is optional.
12
+ Application-level identity resolution and Admission are always required.
13
+ ```
14
+
15
+ ## What it is
16
+
17
+ Four questions that must stay separate, in four shapes that cannot substitute for one another:
18
+
19
+ | Question | Shape |
20
+ | --- | --- |
21
+ | What did the transport prove? | `OptionalTransportEvidence` — never sufficient alone |
22
+ | What authenticated the caller? | `OAuthEvidence` / `RequestProofEvidence` |
23
+ | Who is the caller, canonically? | `CanonicalActorContext` — resolved, never claimed |
24
+ | What may they do? | `AdmissionRequest` → `AdmissionDecision` → `AdmissionGrant` |
25
+
26
+ Plus `ExactMcpInvocationRequest` for the private gateway, where a grant is re-checked against exact
27
+ arguments and live delegation.
28
+
29
+ ## Why the invariants are code
30
+
31
+ The architecture's claims are all "X is not Y" — a certificate is not an owner, a SPIFFE ID is not an
32
+ agent, a grant is not a tool permission. Those survive review and then die in implementation, because
33
+ the mistake never looks like one:
34
+
35
+ ```ts
36
+ if (req.transport.mtls) { /* trusted peer */ } // a real handshake; a wrong conclusion
37
+ ```
38
+
39
+ A type cannot catch that — `mtls: true` is a perfectly good boolean. So:
40
+
41
+ ```ts
42
+ import { checkAdmissionInvariants } from '@agenticprimitives/admission';
43
+
44
+ const violations = checkAdmissionInvariants(request);
45
+ // mTLS-only, no token → OAUTH_TOKEN_REQUIRED
46
+ // "a TLS connection, mutual or not, authenticates no principal"
47
+ ```
48
+
49
+ `[]` means the request is coherent enough to evaluate. It does **not** mean admit — relationship,
50
+ delegation, capability, entitlement and policy are all still ahead of it, and none of them live here.
51
+
52
+ ## Zero runtime dependencies
53
+
54
+ No viem, no provider SDK, no SPIFFE, no transport. Anything needing I/O is a port, not an import.
55
+ Enforced by `pnpm check:optional-package-boundaries`.
56
+
57
+ ## Install
58
+
59
+ ```bash
60
+ pnpm add @agenticprimitives/admission
61
+ ```
62
+
63
+ MIT.
@@ -0,0 +1,46 @@
1
+ import type { AdmissionGrant, AdmissionPolicyContribution, AdmissionRequest, CanonicalActorContext } from './types.js';
2
+ /** `sha256:<hex>` over canonical JSON. The one hashing convention this package uses. */
3
+ export declare function digestOf(body: unknown): Promise<string>;
4
+ /**
5
+ * WHAT AUTHENTICATED THE CALLER.
6
+ *
7
+ * Carries the token digest, never the token; the proof digest, never the proof. `mtls` and
8
+ * `transportAssurance` are included because an otherwise-identical request over a stronger transport
9
+ * is a different authentication event and should not collide.
10
+ */
11
+ export declare function authenticationEvidenceDigest(req: AdmissionRequest): Promise<string>;
12
+ /**
13
+ * WHO WE DECIDED THE CALLER IS.
14
+ *
15
+ * Includes the binding ids, so "resolved via this workload binding" and "resolved via that one" are
16
+ * distinguishable after the fact — which is what you need during an incident, when the question is
17
+ * whether a revoked binding was still being honoured.
18
+ */
19
+ export declare function identityResolutionDigest(actor: CanonicalActorContext): Promise<string>;
20
+ /**
21
+ * WHAT AUTHORITY WAS CITED.
22
+ *
23
+ * References only — the live documents are re-read at invocation. Sorted so the digest is stable
24
+ * under caller reordering; a set of authorities is a set, and two orderings of it are the same claim.
25
+ */
26
+ export declare function authorityEvidenceDigest(req: AdmissionRequest): Promise<string>;
27
+ /**
28
+ * WHICH RULES DECIDED.
29
+ *
30
+ * Keyed by contributor and policy version, with the effect and reason codes. This is the field that
31
+ * answers "policy changed last Tuesday — which decisions used the old rules?", which is otherwise
32
+ * unanswerable once the policy store has moved on.
33
+ */
34
+ export declare function policySnapshotDigest(contributions: readonly AdmissionPolicyContribution[]): Promise<string>;
35
+ /**
36
+ * The body an `AdmissionGrant`'s signature covers.
37
+ *
38
+ * `signature` is excluded (it is the output). EVERYTHING else is included, including the four digests
39
+ * — so a grant cannot be re-filed under different evidence, a longer expiry, or a wider capability set
40
+ * without invalidating it. That is the same discipline spec 338 applies to resolution grants, for the
41
+ * same reason: a signature that does not cover the scope is a signature over a wish.
42
+ */
43
+ export declare function admissionGrantBody(grant: Omit<AdmissionGrant, 'signature'>): Record<string, unknown>;
44
+ /** The digest a boundary signs to issue a grant, and a consumer recomputes to verify one. */
45
+ export declare function admissionGrantDigest(grant: Omit<AdmissionGrant, 'signature'>): Promise<string>;
46
+ //# sourceMappingURL=digests.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"digests.d.ts","sourceRoot":"","sources":["../src/digests.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,cAAc,EACd,2BAA2B,EAC3B,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAUpB,wFAAwF;AACxF,wBAAsB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAE7D;AAED;;;;;;GAMG;AACH,wBAAsB,4BAA4B,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CA6BzF;AAED;;;;;;GAMG;AACH,wBAAsB,wBAAwB,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CAe5F;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAOpF;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,aAAa,EAAE,SAAS,2BAA2B,EAAE,GACpD,OAAO,CAAC,MAAM,CAAC,CAYjB;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,IAAI,CAAC,cAAc,EAAE,WAAW,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA8BpG;AAED,6FAA6F;AAC7F,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,IAAI,CAAC,cAAc,EAAE,WAAW,CAAC,GACvC,OAAO,CAAC,MAAM,CAAC,CAEjB"}
@@ -0,0 +1,164 @@
1
+ // Canonical digests (closes AD-2 in AUDIT.md).
2
+ //
3
+ // `AdmissionGrant` carries four digests — authentication evidence, identity resolution, authority
4
+ // evidence, policy snapshot — and until now they were typed `string` with no stated derivation. That
5
+ // is worse than it looks. A grant's signature covers those fields, so two implementations that derive
6
+ // them differently produce signatures that verify against nothing, and the failure surfaces as
7
+ // "signature invalid" rather than "we disagree about what we signed".
8
+ //
9
+ // So each has exactly one derivation here, over a canonical body with the fields named explicitly.
10
+ //
11
+ // WHAT GOES IN AND WHAT DOES NOT. Every body below is deliberately made of DIGESTS AND IDENTIFIERS,
12
+ // never payloads: no bearer token, no certificate bytes, no delegation document, no request body. A
13
+ // grant is a durable, forwardable, logged object. If deriving it required holding the material it was
14
+ // derived from, every audit store would become a credential store — and the digests exist precisely so
15
+ // that an auditor can prove WHICH evidence produced a decision without ever holding that evidence.
16
+ import { canonicalizeJson } from '@agenticprimitives/types';
17
+ const enc = new TextEncoder();
18
+ /** Lowercase hex of a SHA-256 over a UTF-8 string. */
19
+ async function sha256Hex(s) {
20
+ const d = await crypto.subtle.digest('SHA-256', enc.encode(s));
21
+ return [...new Uint8Array(d)].map((b) => b.toString(16).padStart(2, '0')).join('');
22
+ }
23
+ /** `sha256:<hex>` over canonical JSON. The one hashing convention this package uses. */
24
+ export async function digestOf(body) {
25
+ return `sha256:${await sha256Hex(canonicalizeJson(body))}`;
26
+ }
27
+ /**
28
+ * WHAT AUTHENTICATED THE CALLER.
29
+ *
30
+ * Carries the token digest, never the token; the proof digest, never the proof. `mtls` and
31
+ * `transportAssurance` are included because an otherwise-identical request over a stronger transport
32
+ * is a different authentication event and should not collide.
33
+ */
34
+ export async function authenticationEvidenceDigest(req) {
35
+ const a = req.authentication;
36
+ return digestOf({
37
+ v: 1,
38
+ oauth: a.oauth
39
+ ? {
40
+ issuer: a.oauth.issuer,
41
+ subject: a.oauth.subject,
42
+ audience: [...a.oauth.audience].sort(),
43
+ clientId: a.oauth.clientId,
44
+ scopes: [...a.oauth.scopes].sort(),
45
+ tokenDigest: a.oauth.tokenDigest,
46
+ expiresAt: a.oauth.expiresAt,
47
+ }
48
+ : null,
49
+ requestProof: a.requestProof
50
+ ? {
51
+ keyId: a.requestProof.keyId,
52
+ proofDigest: a.requestProof.proofDigest,
53
+ replayId: a.requestProof.replayId,
54
+ expiresAt: a.requestProof.expiresAt,
55
+ }
56
+ : null,
57
+ transport: {
58
+ mtls: req.transport.mtls,
59
+ assurance: req.transport.assurance,
60
+ clientCertificateSha256: req.transport.clientCertificateSha256 ?? null,
61
+ },
62
+ });
63
+ }
64
+ /**
65
+ * WHO WE DECIDED THE CALLER IS.
66
+ *
67
+ * Includes the binding ids, so "resolved via this workload binding" and "resolved via that one" are
68
+ * distinguishable after the fact — which is what you need during an incident, when the question is
69
+ * whether a revoked binding was still being honoured.
70
+ */
71
+ export async function identityResolutionDigest(actor) {
72
+ return digestOf({
73
+ v: 1,
74
+ principalAgentId: actor.principalAgentId,
75
+ actingAgentId: actor.actingAgentId,
76
+ runtimeId: actor.runtimeId,
77
+ ownerAgentId: actor.ownerAgentId ?? null,
78
+ operatorAgentId: actor.operatorAgentId ?? null,
79
+ organizationAgentId: actor.organizationAgentId ?? null,
80
+ applicationIdentityBindingId: actor.applicationIdentityBindingId ?? null,
81
+ workloadIdentityBindingId: actor.workloadIdentityBindingId ?? null,
82
+ signingKeyBindingId: actor.signingKeyBindingId ?? null,
83
+ authenticationMethods: [...actor.authenticationMethods].sort(),
84
+ resolvedAt: actor.resolvedAt,
85
+ });
86
+ }
87
+ /**
88
+ * WHAT AUTHORITY WAS CITED.
89
+ *
90
+ * References only — the live documents are re-read at invocation. Sorted so the digest is stable
91
+ * under caller reordering; a set of authorities is a set, and two orderings of it are the same claim.
92
+ */
93
+ export async function authorityEvidenceDigest(req) {
94
+ return digestOf({
95
+ v: 1,
96
+ relationshipRefs: [...req.relationshipRefs].sort(),
97
+ delegationRefs: [...req.delegationRefs].sort(),
98
+ entitlementRefs: [...req.entitlementRefs].sort(),
99
+ });
100
+ }
101
+ /**
102
+ * WHICH RULES DECIDED.
103
+ *
104
+ * Keyed by contributor and policy version, with the effect and reason codes. This is the field that
105
+ * answers "policy changed last Tuesday — which decisions used the old rules?", which is otherwise
106
+ * unanswerable once the policy store has moved on.
107
+ */
108
+ export async function policySnapshotDigest(contributions) {
109
+ return digestOf({
110
+ v: 1,
111
+ contributions: [...contributions]
112
+ .map((c) => ({
113
+ contributorId: c.contributorId,
114
+ policyVersion: c.policyVersion,
115
+ effect: c.effect,
116
+ reasonCodes: [...c.reasonCodes].sort(),
117
+ }))
118
+ .sort((a, b) => a.contributorId.localeCompare(b.contributorId)),
119
+ });
120
+ }
121
+ /**
122
+ * The body an `AdmissionGrant`'s signature covers.
123
+ *
124
+ * `signature` is excluded (it is the output). EVERYTHING else is included, including the four digests
125
+ * — so a grant cannot be re-filed under different evidence, a longer expiry, or a wider capability set
126
+ * without invalidating it. That is the same discipline spec 338 applies to resolution grants, for the
127
+ * same reason: a signature that does not cover the scope is a signature over a wish.
128
+ */
129
+ export function admissionGrantBody(grant) {
130
+ return {
131
+ schemaVersion: grant.schemaVersion,
132
+ grantId: grant.grantId,
133
+ principalAgentId: grant.principalAgentId,
134
+ actingAgentId: grant.actingAgentId,
135
+ runtimeId: grant.runtimeId,
136
+ targetAgentId: grant.targetAgentId,
137
+ targetRuntimeId: grant.targetRuntimeId,
138
+ boundaryId: grant.boundaryId,
139
+ audience: grant.audience,
140
+ protocol: grant.protocol,
141
+ protocolVersion: grant.protocolVersion,
142
+ protocolBinding: grant.protocolBinding,
143
+ operations: [...grant.operations].sort(),
144
+ permittedCapabilityIds: [...grant.permittedCapabilityIds].sort(),
145
+ taskId: grant.taskId ?? null,
146
+ contextId: grant.contextId ?? null,
147
+ constraints: grant.constraints,
148
+ obligations: grant.obligations,
149
+ transportAssurance: grant.transportAssurance,
150
+ authenticationEvidenceDigest: grant.authenticationEvidenceDigest,
151
+ identityResolutionDigest: grant.identityResolutionDigest,
152
+ authorityEvidenceDigest: grant.authorityEvidenceDigest,
153
+ policySnapshotDigest: grant.policySnapshotDigest,
154
+ issuedAt: grant.issuedAt,
155
+ expiresAt: grant.expiresAt,
156
+ replayId: grant.replayId,
157
+ issuerBoundaryId: grant.issuerBoundaryId,
158
+ };
159
+ }
160
+ /** The digest a boundary signs to issue a grant, and a consumer recomputes to verify one. */
161
+ export async function admissionGrantDigest(grant) {
162
+ return digestOf(admissionGrantBody(grant));
163
+ }
164
+ //# sourceMappingURL=digests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"digests.js","sourceRoot":"","sources":["../src/digests.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,EAAE;AACF,kGAAkG;AAClG,qGAAqG;AACrG,sGAAsG;AACtG,+FAA+F;AAC/F,sEAAsE;AACtE,EAAE;AACF,mGAAmG;AACnG,EAAE;AACF,oGAAoG;AACpG,oGAAoG;AACpG,sGAAsG;AACtG,uGAAuG;AACvG,mGAAmG;AAEnG,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAQ5D,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;AAE9B,sDAAsD;AACtD,KAAK,UAAU,SAAS,CAAC,CAAS;IAChC,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAA2B,CAAC,CAAC;IACzF,OAAO,CAAC,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACrF,CAAC;AAED,wFAAwF;AACxF,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAa;IAC1C,OAAO,UAAU,MAAM,SAAS,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;AAC7D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAAC,GAAqB;IACtE,MAAM,CAAC,GAAG,GAAG,CAAC,cAAc,CAAC;IAC7B,OAAO,QAAQ,CAAC;QACd,CAAC,EAAE,CAAC;QAC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,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;KACzC,CAAC;AACJ,CAAC;AAED,6FAA6F;AAC7F,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,KAAwC;IAExC,OAAO,QAAQ,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,51 @@
1
+ import type { AdmissionEngine, AdmissionPolicyEvaluator, FailHardAuditSink } from './ports.js';
2
+ import type { AdmissionEffect, AdmissionGrant } from './types.js';
3
+ export interface AdmissionEngineOptions {
4
+ boundaryId: string;
5
+ /** Ordered, but all are evaluated — a later DENY is not short-circuited away by an earlier ALLOW. */
6
+ evaluators: readonly AdmissionPolicyEvaluator[];
7
+ audit: FailHardAuditSink;
8
+ /** Signs `admissionGrantDigest`. The boundary's own key. */
9
+ sign: (digest: string) => Promise<string>;
10
+ /** Grant lifetime. Short by default: a grant is re-obtainable, so a long one only widens exposure. */
11
+ grantTtlSeconds?: number;
12
+ now?: () => Date;
13
+ newId?: () => string;
14
+ /** Local-only diagnostics. Reason codes are internal (§26.2). */
15
+ observe?: (o: {
16
+ effect: AdmissionEffect;
17
+ reasonCodes: string[];
18
+ }) => void;
19
+ }
20
+ /**
21
+ * Build the admission engine.
22
+ *
23
+ * `evaluate` never throws. Every failure — a broken evaluator, an unreachable audit sink — resolves to
24
+ * a DENY carrying a reason code, because a decision function that can throw has a third outcome the
25
+ * caller must remember to handle, and that outcome is where fail-open lives.
26
+ */
27
+ export declare function createAdmissionEngine(opts: AdmissionEngineOptions): AdmissionEngine;
28
+ export interface VerifyGrantInput {
29
+ grant: AdmissionGrant;
30
+ /** The boundary the consumer expects. A grant for another boundary is a confused-deputy attempt. */
31
+ expectedBoundaryId: string;
32
+ verifySignature: (args: {
33
+ digest: string;
34
+ signature: string;
35
+ }) => Promise<boolean>;
36
+ now?: Date;
37
+ }
38
+ export type VerifyGrantResult = {
39
+ ok: true;
40
+ } | {
41
+ ok: false;
42
+ reason: string;
43
+ };
44
+ /**
45
+ * Verify a presented grant — what an agent runtime or MCP gateway does before honouring one.
46
+ *
47
+ * Recomputes the digest from the grant's own fields rather than trusting any carried digest, so an
48
+ * edited grant fails here rather than being honoured with the editor's chosen scope.
49
+ */
50
+ export declare function verifyAdmissionGrant(input: VerifyGrantInput): Promise<VerifyGrantResult>;
51
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAAE,eAAe,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/F,OAAO,KAAK,EAGV,eAAe,EACf,cAAc,EAIf,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,qGAAqG;IACrG,UAAU,EAAE,SAAS,wBAAwB,EAAE,CAAC;IAChD,KAAK,EAAE,iBAAiB,CAAC;IACzB,4DAA4D;IAC5D,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1C,sGAAsG;IACtG,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC;IACrB,iEAAiE;IACjE,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE;QAAE,MAAM,EAAE,eAAe,CAAC;QAAC,WAAW,EAAE,MAAM,EAAE,CAAA;KAAE,KAAK,IAAI,CAAC;CAC3E;AAoBD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,sBAAsB,GAAG,eAAe,CAuKnF;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,cAAc,CAAC;IACtB,oGAAoG;IACpG,kBAAkB,EAAE,MAAM,CAAC;IAC3B,eAAe,EAAE,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACnF,GAAG,CAAC,EAAE,IAAI,CAAC;CACZ;AAED,MAAM,MAAM,iBAAiB,GAAG;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7E;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAuB9F"}
package/dist/engine.js ADDED
@@ -0,0 +1,224 @@
1
+ // The admission engine (spec 339 §17–§18, §25 — Phase 2).
2
+ //
3
+ // Composes independent evaluator opinions into one decision, records it, and signs any grant. The
4
+ // evaluators are ports: relationship, delegation, capability, entitlement and situational policy all
5
+ // live in packages that know how to read chains and vaults. This file knows only how to COMBINE them,
6
+ // which is why it can stay dependency-free — and why the combination rules are worth stating precisely,
7
+ // because every one of them is a way fail-closed gets lost.
8
+ //
9
+ // THE COMPOSITION RULES, and what each prevents:
10
+ //
11
+ // any DENY → DENY one veto is enough; permissive-override would make the
12
+ // weakest evaluator the effective policy
13
+ // any INDETERMINATE → DENY "could not decide" is not "allow". An evaluator whose vault
14
+ // was unreachable must not abstain INTO admission
15
+ // no contributions → DENY zero evaluators is a misconfiguration, and the failure mode
16
+ // of treating it as unanimous consent is total
17
+ // an evaluator throws → DENY a crash is not a vote
18
+ // any CHALLENGE → CHALLENGE only once nothing denied — "not yet, here's how" outranks
19
+ // ALLOW but never outranks DENY
20
+ // all ALLOW → ADMIT ADMIT_CONSTRAINED when constraints or obligations attach
21
+ //
22
+ // AUDIT IS A PRECONDITION, NOT A SIDE EFFECT. If the sink rejects, the decision is DENY. An admission
23
+ // that could not be recorded did not happen — and the tempting alternative ("admit, log later") means
24
+ // the one incident where logging is broken is also the one with no evidence.
25
+ import { admissionGrantDigest, authenticationEvidenceDigest, authorityEvidenceDigest, identityResolutionDigest, policySnapshotDigest, } from './digests.js';
26
+ import { checkAdmissionInvariants } from './invariants.js';
27
+ const DEFAULT_TTL_SECONDS = 300;
28
+ /** The union of every constraint the evaluators attached. Union, because each one narrows. */
29
+ function mergeConstraints(cs) {
30
+ return cs.flatMap((c) => c.constraints ?? []);
31
+ }
32
+ function mergeObligations(cs) {
33
+ const seen = new Set();
34
+ const out = [];
35
+ for (const o of cs.flatMap((c) => c.obligations ?? [])) {
36
+ if (seen.has(o.obligationId))
37
+ continue;
38
+ seen.add(o.obligationId);
39
+ out.push(o);
40
+ }
41
+ return out;
42
+ }
43
+ /**
44
+ * Build the admission engine.
45
+ *
46
+ * `evaluate` never throws. Every failure — a broken evaluator, an unreachable audit sink — resolves to
47
+ * a DENY carrying a reason code, because a decision function that can throw has a third outcome the
48
+ * caller must remember to handle, and that outcome is where fail-open lives.
49
+ */
50
+ export function createAdmissionEngine(opts) {
51
+ const now = opts.now ?? (() => new Date());
52
+ const newId = opts.newId ?? (() => globalThis.crypto.randomUUID());
53
+ const ttl = opts.grantTtlSeconds ?? DEFAULT_TTL_SECONDS;
54
+ return {
55
+ async evaluate(request) {
56
+ const at = now();
57
+ const evaluatedAt = at.toISOString();
58
+ const decisionId = newId();
59
+ /** Record first, then answer. A decision the sink refused is not a decision. */
60
+ const settle = async (effect, reasonCodes, contributions, grant) => {
61
+ let receiptRef;
62
+ try {
63
+ const r = await opts.audit.append({
64
+ kind: 'admission.decision',
65
+ decisionId,
66
+ requestId: request.requestId,
67
+ boundaryId: opts.boundaryId,
68
+ principalAgentId: request.actor.principalAgentId,
69
+ actingAgentId: request.actor.actingAgentId,
70
+ targetAgentId: request.targetAgentId,
71
+ effect,
72
+ reasonCodes,
73
+ grantId: grant?.grantId,
74
+ evaluatedAt,
75
+ });
76
+ receiptRef = r.receiptRef;
77
+ }
78
+ catch {
79
+ // The sink is down. We cannot admit — but we can still refuse, and we say why.
80
+ opts.observe?.({ effect: 'DENY', reasonCodes: ['AUDIT_SINK_UNAVAILABLE'] });
81
+ return {
82
+ decisionId,
83
+ effect: 'DENY',
84
+ reasonCodes: ['AUDIT_SINK_UNAVAILABLE'],
85
+ contributions,
86
+ receiptRef: '',
87
+ evaluatedAt,
88
+ };
89
+ }
90
+ opts.observe?.({ effect, reasonCodes });
91
+ return { decisionId, effect, reasonCodes, grant, contributions, receiptRef, evaluatedAt };
92
+ };
93
+ // ── Stage 1: structural coherence, before any evaluator does work ────
94
+ const violations = checkAdmissionInvariants(request);
95
+ if (violations.length > 0) {
96
+ return settle('DENY', violations.map((v) => v.code), []);
97
+ }
98
+ // ── Stages 4–8: the evaluators ───────────────────────────────────────
99
+ // All of them run. Short-circuiting on the first DENY would make the decision depend on
100
+ // evaluator ORDER, and would hide from the audit record which other checks also failed.
101
+ const contributions = [];
102
+ for (const ev of opts.evaluators) {
103
+ try {
104
+ contributions.push(await ev.evaluate(request));
105
+ }
106
+ catch {
107
+ // A crash is not a vote. Synthesize the fail-closed one it did not cast.
108
+ contributions.push({
109
+ contributorId: ev.contributorId,
110
+ policyVersion: 'unknown',
111
+ effect: 'INDETERMINATE',
112
+ reasonCodes: ['POLICY_DEPENDENCY_UNAVAILABLE'],
113
+ evaluatedAt,
114
+ });
115
+ }
116
+ }
117
+ if (contributions.length === 0) {
118
+ // Zero evaluators is a misconfiguration. Reading it as unanimous consent is how a boundary
119
+ // ships with its policy engine unwired and nobody notices until the audit.
120
+ return settle('DENY', ['POLICY_DEPENDENCY_UNAVAILABLE'], contributions);
121
+ }
122
+ const reasonCodes = [...new Set(contributions.flatMap((c) => c.reasonCodes))];
123
+ const denied = contributions.filter((c) => c.effect === 'DENY');
124
+ if (denied.length > 0) {
125
+ return settle('DENY', [...new Set(denied.flatMap((c) => c.reasonCodes))], contributions);
126
+ }
127
+ const indeterminate = contributions.filter((c) => c.effect === 'INDETERMINATE');
128
+ if (indeterminate.length > 0) {
129
+ return settle('DENY', [...new Set([...indeterminate.flatMap((c) => c.reasonCodes), 'POLICY_DEPENDENCY_UNAVAILABLE'])], contributions);
130
+ }
131
+ const challenged = contributions.filter((c) => c.effect === 'CHALLENGE');
132
+ if (challenged.length > 0) {
133
+ const decision = await settle('CHALLENGE', [...new Set(challenged.flatMap((c) => c.reasonCodes))], contributions);
134
+ return {
135
+ ...decision,
136
+ challenge: {
137
+ challengeId: newId(),
138
+ audience: opts.boundaryId,
139
+ requiredEvidenceKinds: [...new Set(challenged.flatMap((c) => c.reasonCodes))],
140
+ requiredAuthorityKinds: [],
141
+ expiresAt: new Date(at.getTime() + 300_000).toISOString(),
142
+ },
143
+ };
144
+ }
145
+ // ── Stage 9: everyone allowed — build and sign the grant ─────────────
146
+ const constraints = mergeConstraints(contributions);
147
+ const obligations = mergeObligations(contributions);
148
+ const unsigned = {
149
+ schemaVersion: '1',
150
+ grantId: newId(),
151
+ principalAgentId: request.actor.principalAgentId,
152
+ actingAgentId: request.actor.actingAgentId,
153
+ runtimeId: request.actor.runtimeId,
154
+ targetAgentId: request.targetAgentId,
155
+ targetRuntimeId: request.targetRuntimeId,
156
+ boundaryId: opts.boundaryId,
157
+ audience: opts.boundaryId,
158
+ protocol: 'A2A',
159
+ protocolVersion: request.a2a.protocolVersion,
160
+ protocolBinding: request.a2a.protocolBinding,
161
+ operations: [request.a2a.operation],
162
+ // The ceiling is what was ASKED FOR, never a wildcard. A grant that permitted everything the
163
+ // policy did not explicitly forbid would invert the fail-closed default.
164
+ permittedCapabilityIds: request.a2a.requestedCapabilityId ? [request.a2a.requestedCapabilityId] : [],
165
+ taskId: request.a2a.taskId,
166
+ contextId: request.a2a.contextId,
167
+ constraints,
168
+ obligations,
169
+ transportAssurance: request.transport.assurance,
170
+ authenticationEvidenceDigest: await authenticationEvidenceDigest(request),
171
+ identityResolutionDigest: await identityResolutionDigest(request.actor),
172
+ authorityEvidenceDigest: await authorityEvidenceDigest(request),
173
+ policySnapshotDigest: await policySnapshotDigest(contributions),
174
+ issuedAt: evaluatedAt,
175
+ expiresAt: new Date(at.getTime() + ttl * 1000).toISOString(),
176
+ replayId: newId(),
177
+ issuerBoundaryId: opts.boundaryId,
178
+ };
179
+ let signature;
180
+ try {
181
+ signature = await opts.sign(await admissionGrantDigest(unsigned));
182
+ }
183
+ catch {
184
+ // An unsigned grant is not a grant. Refuse rather than emit one nobody can verify.
185
+ return settle('DENY', ['POLICY_DEPENDENCY_UNAVAILABLE'], contributions);
186
+ }
187
+ const grant = { ...unsigned, signature };
188
+ const effect = constraints.length > 0 || obligations.length > 0 ? 'ADMIT_CONSTRAINED' : 'ADMIT';
189
+ return settle(effect, reasonCodes, contributions, grant);
190
+ },
191
+ };
192
+ }
193
+ /**
194
+ * Verify a presented grant — what an agent runtime or MCP gateway does before honouring one.
195
+ *
196
+ * Recomputes the digest from the grant's own fields rather than trusting any carried digest, so an
197
+ * edited grant fails here rather than being honoured with the editor's chosen scope.
198
+ */
199
+ export async function verifyAdmissionGrant(input) {
200
+ const g = input.grant;
201
+ const nowMs = (input.now ?? new Date()).getTime();
202
+ if (g.schemaVersion !== '1')
203
+ return { ok: false, reason: 'unknown grant schema version' };
204
+ if (g.audience !== input.expectedBoundaryId) {
205
+ return { ok: false, reason: 'grant is addressed to a different boundary' };
206
+ }
207
+ if (Date.parse(g.expiresAt) <= nowMs)
208
+ return { ok: false, reason: 'grant has expired' };
209
+ if (Date.parse(g.issuedAt) > nowMs + 60_000) {
210
+ return { ok: false, reason: 'grant is issued in the future' };
211
+ }
212
+ const { signature, ...unsigned } = g;
213
+ let valid = false;
214
+ try {
215
+ valid = await input.verifySignature({ digest: await admissionGrantDigest(unsigned), signature });
216
+ }
217
+ catch {
218
+ valid = false;
219
+ }
220
+ if (!valid)
221
+ return { ok: false, reason: 'grant signature did not verify' };
222
+ return { ok: true };
223
+ }
224
+ //# sourceMappingURL=engine.js.map
@@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