@emilia-protocol/gate 0.9.5 → 0.10.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 (74) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/LICENSE +190 -0
  3. package/README.md +75 -16
  4. package/action-control-manifest.js +26 -0
  5. package/adapters/_kit.js +47 -5
  6. package/adapters/aws.js +15 -4
  7. package/adapters/github-demo.mjs +25 -22
  8. package/adapters/github.js +1 -1
  9. package/adapters/jira.js +1 -0
  10. package/adapters/linear.js +1 -0
  11. package/adapters/salesforce.js +1 -0
  12. package/adapters/stripe.js +1 -1
  13. package/adapters/supabase.js +26 -4
  14. package/adapters/vercel.js +33 -4
  15. package/aec-execution.js +1 -3
  16. package/breakglass.js +285 -51
  17. package/control-plane.js +341 -0
  18. package/coverage.js +722 -0
  19. package/custody-demo.mjs +13 -3
  20. package/demo.mjs +9 -3
  21. package/deploy/helm/README.md +16 -8
  22. package/deploy/helm/emilia-gate/Chart.yaml +3 -1
  23. package/deploy/helm/emilia-gate/templates/NOTES.txt +3 -2
  24. package/deploy/helm/emilia-gate/templates/deployment.yaml +55 -1
  25. package/deploy/helm/emilia-gate/values.yaml +18 -2
  26. package/deploy/helm/emilia-gate-service/Chart.yaml +11 -0
  27. package/deploy/helm/emilia-gate-service/README.md +81 -0
  28. package/deploy/helm/emilia-gate-service/templates/NOTES.txt +12 -0
  29. package/deploy/helm/emilia-gate-service/templates/_helpers.tpl +83 -0
  30. package/deploy/helm/emilia-gate-service/templates/deployment.yaml +153 -0
  31. package/deploy/helm/emilia-gate-service/templates/migration-job.yaml +73 -0
  32. package/deploy/helm/emilia-gate-service/templates/networkpolicy.yaml +113 -0
  33. package/deploy/helm/emilia-gate-service/templates/pdb.yaml +14 -0
  34. package/deploy/helm/emilia-gate-service/templates/service.yaml +20 -0
  35. package/deploy/helm/emilia-gate-service/templates/serviceaccount.yaml +8 -0
  36. package/deploy/helm/emilia-gate-service/tests/fixtures/001_gate.sql +26 -0
  37. package/deploy/helm/emilia-gate-service/tests/fixtures/002_runtime_access.sql +32 -0
  38. package/deploy/helm/emilia-gate-service/tests/fixtures/gate.config.mjs +29 -0
  39. package/deploy/helm/emilia-gate-service/tests/render-check.sh +145 -0
  40. package/deploy/helm/emilia-gate-service/values.schema.json +145 -0
  41. package/deploy/helm/emilia-gate-service/values.yaml +166 -0
  42. package/deploy/sql/001-runtime.sql +707 -0
  43. package/deploy/terraform/README.md +24 -14
  44. package/deploy/terraform/main.tf +59 -0
  45. package/deploy/terraform/service/README.md +81 -0
  46. package/deploy/terraform/service/main.tf +718 -0
  47. package/deploy/terraform/service/outputs.tf +19 -0
  48. package/deploy/terraform/service/tests/validate.sh +24 -0
  49. package/deploy/terraform/service/tests/validation.tftest.hcl +168 -0
  50. package/deploy/terraform/service/variables.tf +459 -0
  51. package/deploy/terraform/service/versions.tf +10 -0
  52. package/deploy/terraform/variables.tf +95 -2
  53. package/deployment-attestation.js +248 -0
  54. package/eg1-conformance.js +46 -12
  55. package/enterprise.js +6 -2
  56. package/ep-assure.mjs +3 -2
  57. package/evidence-postgres.js +357 -0
  58. package/evidence.js +10 -3
  59. package/execution-binding.js +141 -26
  60. package/index.js +556 -115
  61. package/key-registry.js +51 -19
  62. package/mcp.js +4 -2
  63. package/network-witness.js +500 -0
  64. package/package.json +25 -5
  65. package/reliance-kernel.js +5 -6
  66. package/reliance-packet.js +43 -10
  67. package/reports/assurance-package.js +45 -19
  68. package/reports/reperform.js +78 -18
  69. package/reports/underwriter.js +1 -1
  70. package/settlement.js +300 -0
  71. package/store-postgres.js +14 -0
  72. package/store.js +26 -5
  73. package/strict-json.js +86 -0
  74. package/witness-postgres.js +97 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,70 @@
1
+ <!-- SPDX-License-Identifier: Apache-2.0 -->
2
+ # Changelog
3
+
4
+ All notable changes to `@emilia-protocol/gate` are documented here.
5
+ This package follows [Semantic Versioning](https://semver.org/).
6
+
7
+ ## 0.10.0 (2026-07-16)
8
+
9
+ ### Added
10
+
11
+ - The EMILIA Gate consequence-control plane, including action coverage,
12
+ settlement, metering, deployment-attestation, network-witness, SIEM, and
13
+ control-plane modules.
14
+ - A BYOC GitHub repository-deletion service with complete mediation, strict
15
+ receipt ingress, durable Postgres action/consumption/evidence state,
16
+ authenticated evidence reads, bounded readiness, graceful shutdown, and
17
+ fail-closed recovery of interrupted effects.
18
+ - Helm, Terraform, Docker Compose, and SQL deployment assets for the BYOC
19
+ service. Production assets require explicit non-latest images, separate
20
+ runtime and migration credentials, and operator-owned trust configuration.
21
+
22
+ ### Security
23
+
24
+ - Pinned issuer, approver, policy, actuator, meter, attestation, and
25
+ network-witness trust roots are kept outside presenter-controlled evidence.
26
+ - Signed negative human decisions remain durable evidence but cannot satisfy
27
+ authorization, signer, assurance, authority, quorum, or action-material
28
+ predicates.
29
+ - Mobile approval and denial evidence is bound to the exact action, profile,
30
+ presentation, app, device enrollment, RP, origin, and single-use challenge.
31
+ - A same-sequence network-witness conflict permanently poisons that exact
32
+ witness/capture-point stream. Higher sequence numbers cannot restore trust;
33
+ recovery requires an explicitly provisioned replacement stream identity.
34
+ - Ambiguous external effects burn their receipt and become `indeterminate`;
35
+ Gate never retries a consequential effect whose outcome is unknown.
36
+
37
+ ### Distribution
38
+
39
+ - Gate now declares the exact `@emilia-protocol/require-receipt` and
40
+ `@emilia-protocol/verify` release bytes it imports. The verifier floor is
41
+ `3.10.1`, which includes the signed-denial authorization fix.
42
+ - The npm package now carries this changelog and the Apache-2.0 license text.
43
+
44
+ ## 0.9.2 (2026-07-06)
45
+
46
+ ### Added
47
+ `EP-EXTERNAL-VERIFICATION-STATEMENT-v1` (`./reports/external-verification`): the
48
+ artifact a non-EMILIA verifier signs after checking EP evidence. It records a
49
+ procedure, inputs, result, and limitations under the verifier's own Ed25519 key,
50
+ and is accepted only by a relying party pinning that key together with the
51
+ verifier identity out of band. It does not authorize an action or certify
52
+ correctness. A turnkey harness for issuing one over a conformance run lives in
53
+ `examples/external-verification/`.
54
+
55
+ ### Fixed
56
+ `./reports/external-verification` imported `canonicalize` from outside the
57
+ package root, which made the published tarball unloadable
58
+ (`ERR_MODULE_NOT_FOUND`) for every consumer, including the package main entry.
59
+ It now imports the byte-identical in-package `canonicalize`. A new
60
+ `package-boundary` test fails closed if any shipped module ever again resolves a
61
+ relative import outside the package root.
62
+
63
+ ### Security
64
+ Verification hardening (fail-closed): a pin must name the `verifier_id` it
65
+ vouches for, so a pinned key can never validate a different claimed identity
66
+ (`pin_missing_or_mismatched_verifier_id`); `key_id` is derived from the carried
67
+ public key and a mismatched envelope `key_id` is refused (`key_id_mismatch`),
68
+ since the envelope is outside the signed bytes. Default statement limitations now
69
+ disclose that a statement carries no expiry and no consumer binding, is
70
+ replayable verbatim, and that `generated_at` is signer-asserted, not verified.
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2024–2026 EMILIA Protocol, Inc. and contributors
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @emilia-protocol/gate — EMILIA Gate
2
2
 
3
- **The Trusted Action Firewall.** Deny-by-default enforcement for consequential machine actions.
3
+ **The Consequence Firewall.** Deny-by-default enforcement for consequential machine actions.
4
4
 
5
5
  > If an agent cannot produce a valid receipt, it cannot change money, code, permissions, data,
6
6
  > infrastructure, energy, or physical state.
@@ -32,6 +32,7 @@ import { createTrustedActionFirewall } from '@emilia-protocol/gate';
32
32
 
33
33
  const gate = createTrustedActionFirewall({
34
34
  trustedKeys: [ISSUER_PUBKEY_B64U], // pin the issuers you trust
35
+ store: sharedConsumptionStore, // durable + ownership-fenced + permanent
35
36
  maxAgeSec: 900,
36
37
  });
37
38
 
@@ -58,6 +59,48 @@ if (!out.ok) throw out.body; // 428 Receipt Required
58
59
  console.log(out.packet.verdict); // "rely"
59
60
  ```
60
61
 
62
+ ## Three-plane deployment
63
+
64
+ High-consequence infrastructure separates three jobs instead of asking one
65
+ vendor or appliance to prove its own work:
66
+
67
+ 1. **Enforcement plane** — an executor-side Gate returns 428 and does not call
68
+ the actuator until the pinned authorization profile is satisfied.
69
+ 2. **Witness plane** — an independently pinned TAP, packet broker, or sensor
70
+ signs privacy-minimized observations. Observation never establishes that an
71
+ action was authorized, blocked, executed, or physically completed.
72
+ 3. **Control plane** — a relying party pins the coverage inventory and
73
+ settlement profile, joins signed evidence by exact action digest, reports
74
+ `gated`, `witness_only`, `ungated`, `stale`, or `unknown`, and meters only
75
+ protected actions.
76
+
77
+ ```js
78
+ import { evaluateGateControlPlane } from '@emilia-protocol/gate/control-plane';
79
+
80
+ const report = await evaluateGateControlPlane({
81
+ coverage: { deployments, probes, witnesses }, // presenter evidence only
82
+ settlements: [{ bundle }],
83
+ }, {
84
+ coverageInventory, // relying-party pinned
85
+ settlementProfile, // relying-party pinned
86
+ expectedProbeNonces, // current RP challenges, keyed by surface
87
+ attestationVerifiers,
88
+ pinnedProbes,
89
+ pinnedWitnesses,
90
+ witnessSequenceStore, // durable atomic stream checkpoint store
91
+ verifyAuthorization,
92
+ verifyExecution,
93
+ verifyOutcome,
94
+ });
95
+ ```
96
+
97
+ The reference demonstration is `node examples/gate-control-plane/demo.mjs`.
98
+ It shows a complete view becoming `witness_only` and settlement-ineligible when
99
+ the Gate is removed while the network witness remains healthy.
100
+ Witness-dependent production decisions fail closed unless `witnessSequenceStore`
101
+ is durable or the relying party supplies a previously accepted durable witness
102
+ result through the explicit trusted-acceptance option.
103
+
61
104
  ## Default action packs
62
105
 
63
106
  `createTrustedActionFirewall()` ships with high-risk defaults. These are category-based, not just
@@ -95,21 +138,21 @@ Use your own manifest when you need custom policy:
95
138
  ```js
96
139
  import { createGate } from '@emilia-protocol/gate';
97
140
 
98
- const gate = createGate({ manifest, trustedKeys: [ISSUER_PUBKEY_B64U] });
141
+ const gate = createGate({ manifest, trustedKeys: [ISSUER_PUBKEY_B64U], store: sharedConsumptionStore });
99
142
  ```
100
143
 
101
144
  ## Framework adapters
102
145
 
103
146
  ```js
104
- // 1) Express / Connect middleware
105
- app.post(
106
- '/payments',
107
- gate.middleware({
147
+ // 1) Express / Connect route wrapper. The handler is the effect callback;
148
+ // Gate owns reservation, execution, consumption, and evidence as one lifecycle.
149
+ app.post('/payments', gate.route(
150
+ async (req, res) => res.json(await releasePayment(req.paymentFromSystemOfRecord)),
151
+ {
108
152
  selector: { protocol: 'http', method: 'POST', path: '/payments' },
109
153
  observedAction: (req) => req.paymentFromSystemOfRecord,
110
- }),
111
- handler,
112
- );
154
+ },
155
+ ));
113
156
 
114
157
  // 2) Wrap any function
115
158
  const release = gate.guard(reallyRelease, {
@@ -125,6 +168,11 @@ const release = gate.guard(reallyRelease, {
125
168
  });
126
169
  ```
127
170
 
171
+ `gate.middleware()` is intentionally deprecated and always refuses: middleware
172
+ cannot prove that code after `next()` executed, so consuming a one-time receipt
173
+ there would create an authorization-without-effect ambiguity. Use
174
+ `gate.route()`, `gate.guard()`, or `gate.run()` for mutations.
175
+
128
176
  ## MCP drop-in
129
177
 
130
178
  Agents live at the MCP tool-call boundary. One wrapper turns a dangerous tool into a
@@ -134,7 +182,7 @@ receipt-required one:
134
182
  import { createTrustedActionFirewall } from '@emilia-protocol/gate';
135
183
  import { gateMcpTool } from '@emilia-protocol/gate/mcp';
136
184
 
137
- const gate = createTrustedActionFirewall({ trustedKeys: [ISSUER_PUBKEY_B64U] });
185
+ const gate = createTrustedActionFirewall({ trustedKeys: [ISSUER_PUBKEY_B64U], store: sharedConsumptionStore });
138
186
 
139
187
  server.tool('release_payment', gateMcpTool(
140
188
  gate,
@@ -156,7 +204,7 @@ mutating B). All share one fail-closed contract (`adapters/_kit.js`).
156
204
  import { createGate } from '@emilia-protocol/gate';
157
205
  import { createGithubManifest, guardGithubMutation } from '@emilia-protocol/gate/adapters/github';
158
206
 
159
- const gate = createGate({ manifest: createGithubManifest(), trustedKeys: [ISSUER_PUBKEY_B64U] });
207
+ const gate = createGate({ manifest: createGithubManifest(), trustedKeys: [ISSUER_PUBKEY_B64U], store: sharedConsumptionStore });
160
208
  await guardGithubMutation(gate, octokit, {
161
209
  op: 'repo.delete', // | 'permission.change' | 'branch_protection.remove'
162
210
  params: { owner: 'acme', repo: 'prod' },
@@ -173,7 +221,7 @@ await guardGithubMutation(gate, octokit, {
173
221
 
174
222
  ```js
175
223
  import { createStripeManifest, guardStripeMutation } from '@emilia-protocol/gate/adapters/stripe';
176
- const gate = createGate({ manifest: createStripeManifest(), trustedKeys: [ISSUER_PUBKEY_B64U] });
224
+ const gate = createGate({ manifest: createStripeManifest(), trustedKeys: [ISSUER_PUBKEY_B64U], store: sharedConsumptionStore });
177
225
  await guardStripeMutation(gate, stripe, { op: 'payout.create', params: { amount: 40000, currency: 'usd', destination: 'acct_x' }, receipt });
178
226
  // Supabase: guardSupabaseMutation(gate, db, { op: 'sql.destructive', params: { sql }, receipt }) // binds the exact statement
179
227
  // AWS: guardAwsMutation(gate, client, { op: 'iam.attach_policy', params: { user, policy_arn }, receipt })
@@ -203,7 +251,13 @@ if it demonstrably passes all eight checks:
203
251
  import { createTrustedActionFirewall, createEg1Harness, gateConformance } from '@emilia-protocol/gate';
204
252
 
205
253
  const harness = createEg1Harness();
206
- const gate = createTrustedActionFirewall({ trustedKeys: [harness.publicKey] });
254
+ const gate = createTrustedActionFirewall({
255
+ trustedKeys: [harness.publicKey],
256
+ approverKeys: harness.approverKeys,
257
+ rpId: harness.rpId,
258
+ allowedOrigins: harness.allowedOrigins,
259
+ allowEphemeralStore: true, // conformance fixture only
260
+ });
207
261
  const report = await gateConformance({ gate, harness });
208
262
  // report.passed === true; report.badge === 'EG-1 Enforced'
209
263
  ```
@@ -216,7 +270,7 @@ into a crisp claim: *"this PR makes `delete_row` earn EG-1."*
216
270
  ## What it adds over a bare verifier
217
271
 
218
272
  `@emilia-protocol/require-receipt` already does manifest matching, offline verification, and the 428
219
- challenge. The Gate composes that and adds the three things a firewall needs:
273
+ challenge. The Gate composes that and adds the lifecycle controls a firewall needs:
220
274
 
221
275
  - **Assurance tiers** — `software` < `class_a` (device signoff) < `quorum` (m-of-n). A `critical`
222
276
  action can demand `class_a` or `quorum`; a lower-assurance receipt is refused (`assurance_too_low`).
@@ -225,7 +279,9 @@ challenge. The Gate composes that and adds the three things a firewall needs:
225
279
  of every embedded device/quorum signature, use the EP §6.2 trust-receipt
226
280
  verifier in `@emilia-protocol/verify`.
227
281
  - **One-time consumption** — a receipt authorizes one action, once. Replays are refused
228
- (`replay_refused`). Default store is in-memory; swap in Redis/DB for a fleet.
282
+ (`replay_refused`). Gate construction requires a durable, ownership-fenced, permanent store.
283
+ The process-local store is available only through explicit `allowEphemeralStore:true` for tests
284
+ and reference demos.
229
285
  - **Evidence log** — the local logger hash-chains decisions and detects alteration when given its
230
286
  complete process history. It is not a fleet ledger: a sink cannot prevent restart-from-genesis or
231
287
  cross-replica forks. Safety-critical deployments use `createAtomicEvidenceLog()` over a durable
@@ -235,6 +291,9 @@ challenge. The Gate composes that and adds the three things a firewall needs:
235
291
  closes "approved harmless X, executed dangerous Y."
236
292
  - **Reliance packet** — `gate.reliancePacket()` turns the decision, execution receipt, field binding,
237
293
  and evidence head into the compact artifact an auditor, insurer, or investigator can review.
294
+ - **Independent coverage evidence** — deployment attestation plus a separately pinned active probe
295
+ can establish a declared surface as `gated`; a passive network witness alone is always
296
+ `witness_only`. Inventory completeness remains an explicit relying-party assumption.
238
297
 
239
298
  ## Production custody
240
299
 
@@ -265,7 +324,7 @@ const registry = createKeyRegistry([
265
324
  { kid: 'issuer-1', key: KEY1 },
266
325
  { kid: 'issuer-2', key: KEY2, not_before: '2026-07-01T00:00:00Z' }, // rotation window
267
326
  ]);
268
- const gate = createGate({ manifest, keyRegistry: registry });
327
+ const gate = createGate({ manifest, keyRegistry: registry, store: sharedConsumptionStore });
269
328
  registry.revoke('issuer-1'); // compromised — refused immediately, live, no redeploy
270
329
  ```
271
330
 
@@ -119,6 +119,9 @@ export function toActionControl(action) {
119
119
  },
120
120
  };
121
121
  if (action.quorum) out.quorum = cloneJson(action.quorum);
122
+ if (action.business_authorization || action.businessAuthorization) {
123
+ out.business_authorization = cloneJson(action.business_authorization || action.businessAuthorization);
124
+ }
122
125
  return out;
123
126
  }
124
127
 
@@ -224,6 +227,29 @@ export function validateActionControlManifest(manifest) {
224
227
  if (control.evidence_output?.execution_attestation !== true) errors.push(`${prefix}.control.evidence_output.execution_attestation must be true`);
225
228
  if (control.evidence_output?.reliance_packet !== true) errors.push(`${prefix}.control.evidence_output.reliance_packet must be true`);
226
229
  if (action.conformance?.level !== ACTION_CONTROL_CONFORMANCE_LEVEL) errors.push(`${prefix}.conformance.level must be ${ACTION_CONTROL_CONFORMANCE_LEVEL}`);
230
+ if (action.business_authorization !== undefined) {
231
+ const business = action.business_authorization;
232
+ const policy = business?.policy;
233
+ const approvers = business?.allowed_approvers;
234
+ if (!business || typeof business !== 'object' || Array.isArray(business)) {
235
+ errors.push(`${prefix}.business_authorization must be an object`);
236
+ } else {
237
+ if (!policy || typeof policy !== 'object' || Array.isArray(policy)
238
+ || typeof policy.id !== 'string' || !policy.id
239
+ || typeof policy.hash !== 'string' || !policy.hash) {
240
+ errors.push(`${prefix}.business_authorization.policy must pin non-empty id and hash`);
241
+ }
242
+ if (typeof business.tenant_id !== 'string' || !business.tenant_id) {
243
+ errors.push(`${prefix}.business_authorization.tenant_id must be a non-empty string`);
244
+ }
245
+ if (!Array.isArray(approvers) || approvers.length === 0
246
+ || approvers.some((entry) => !entry || typeof entry !== 'object'
247
+ || typeof entry.subject !== 'string' || !entry.subject
248
+ || typeof entry.role !== 'string' || !entry.role)) {
249
+ errors.push(`${prefix}.business_authorization.allowed_approvers must name subject and role`);
250
+ }
251
+ }
252
+ }
227
253
  }
228
254
  }
229
255
  return { ok: errors.length === 0, errors };
package/adapters/_kit.js CHANGED
@@ -6,15 +6,29 @@
6
6
  * gate.run(), and FAIL CLOSED — if the gate refuses, the real client call is
7
7
  * never made and we throw EMILIA_RECEIPT_REQUIRED.
8
8
  *
9
- * An op spec is: { selector, observed(params) -> {fields...}, perform(client, params) -> result }.
9
+ * An op spec is: { selector, observed(params) -> {fields...},
10
+ * actuator?(params, observed) -> {fields...}, perform(client, actuator) -> result }.
10
11
  * `observed` must return the same material fields the action pack binds, drawn
11
12
  * from the call params (the system-of-record facts), so a receipt for resource A
12
13
  * cannot authorize a mutation of resource B.
13
14
  */
14
- import { hashCanonical } from '../execution-binding.js';
15
+ import { canonicalize, hashCanonical } from '../execution-binding.js';
15
16
 
16
17
  export { hashCanonical };
17
18
 
19
+ function deepFreeze(value) {
20
+ if (value && typeof value === 'object' && !Object.isFrozen(value)) {
21
+ for (const child of Object.values(value)) deepFreeze(child);
22
+ Object.freeze(value);
23
+ }
24
+ return value;
25
+ }
26
+
27
+ /** Canonical plain-data snapshot used at the actuator boundary. */
28
+ export function canonicalActuatorObject(value) {
29
+ return deepFreeze(JSON.parse(canonicalize(value)));
30
+ }
31
+
18
32
  /** Build an EP-ACTION-RISK-MANIFEST-v0.1 from a frozen action pack (deep-copied). */
19
33
  export function manifestFromPack(pack, extraActions = []) {
20
34
  return {
@@ -26,6 +40,9 @@ export function manifestFromPack(pack, extraActions = []) {
26
40
  execution_binding: a.execution_binding
27
41
  ? { ...a.execution_binding, required_fields: [...a.execution_binding.required_fields] }
28
42
  : undefined,
43
+ ...(a.business_authorization
44
+ ? { business_authorization: canonicalActuatorObject(a.business_authorization) }
45
+ : {}),
29
46
  })),
30
47
  ...extraActions,
31
48
  ],
@@ -44,8 +61,33 @@ export function createAdapter({ system, ops }) {
44
61
  if (!gate || typeof gate.run !== 'function') throw new Error(`${system} adapter requires an EMILIA Gate (with .run)`);
45
62
  const spec = ops[op];
46
63
  if (!spec) throw new Error(`${system} adapter: unknown op "${op}" (expected one of: ${OPS.join(', ')})`);
47
- const observedAction = spec.observed(params);
48
- const out = await gate.run({ selector: spec.selector, receipt, observedAction }, () => spec.perform(client, params));
64
+ if (!receipt) {
65
+ const refused = await gate.run(
66
+ { selector: spec.selector, receipt: null, observedAction: null },
67
+ () => { throw new Error('unreachable_adapter_effect'); },
68
+ );
69
+ const e = new Error(`EMILIA Gate refused ${system}:${op} — ${refused.authorization.reason}`);
70
+ e.code = 'EMILIA_RECEIPT_REQUIRED';
71
+ e.status = refused.status;
72
+ e.gate = refused.authorization;
73
+ e.challenge = refused.body;
74
+ throw e;
75
+ }
76
+ // Snapshot before any asynchronous verification. Caller-owned params may be
77
+ // mutated while gate.run() awaits evidence/storage; neither the observation
78
+ // nor the eventual provider call may follow that mutable reference.
79
+ const input = canonicalActuatorObject(params);
80
+ const observedAction = canonicalActuatorObject(spec.observed(input));
81
+ // Default to the verified fields only. Operations that need a preimage for a
82
+ // bound digest (SQL, RLS, secret values, queries) must opt in with an explicit
83
+ // actuator() constructor. The unrestricted caller object is never passed.
84
+ const actuator = canonicalActuatorObject(
85
+ typeof spec.actuator === 'function' ? spec.actuator(input, observedAction) : observedAction,
86
+ );
87
+ const out = await gate.run(
88
+ { selector: spec.selector, receipt, observedAction },
89
+ () => spec.perform(client, actuator),
90
+ );
49
91
  if (!out.ok) {
50
92
  const e = new Error(`EMILIA Gate refused ${system}:${op} — ${out.authorization.reason}`);
51
93
  e.code = 'EMILIA_RECEIPT_REQUIRED';
@@ -60,4 +102,4 @@ export function createAdapter({ system, ops }) {
60
102
  return { ops, OPS, guard };
61
103
  }
62
104
 
63
- export default { createAdapter, manifestFromPack, hashCanonical };
105
+ export default { createAdapter, manifestFromPack, hashCanonical, canonicalActuatorObject };
package/adapters/aws.js CHANGED
@@ -13,7 +13,7 @@
13
13
  * import { createGate } from '@emilia-protocol/gate';
14
14
  * import { createAwsManifest, guardAwsMutation } from '@emilia-protocol/gate/adapters/aws';
15
15
  *
16
- * const gate = createGate({ manifest: createAwsManifest(), trustedKeys: [ISSUER] });
16
+ * const gate = createGate({ manifest: createAwsManifest(), trustedKeys: [ISSUER], store: sharedConsumptionStore });
17
17
  * // client: { iam: { attachUserPolicy, createAccessKey, deleteUser }, ec2: { authorizeSecurityGroupIngress } }
18
18
  * await guardAwsMutation(gate, client, {
19
19
  * op: 'iam.attach_policy', params: { user: 'svc-bot', policy_arn: 'arn:aws:iam::aws:policy/AdministratorAccess' }, receipt,
@@ -48,7 +48,7 @@ export const AWS_ACTION_PACK = Object.freeze([
48
48
  risk: 'critical', receipt_required: true, assurance_class: 'quorum',
49
49
  match: { protocol: 'aws', tool: 'authorize_security_group_ingress' },
50
50
  why: 'Opens the network. Bind group/CIDR/port so 0.0.0.0/0:22 cannot slip through.',
51
- execution_binding: { required_fields: ['action_type', 'group_id', 'cidr', 'from_port'] },
51
+ execution_binding: { required_fields: ['action_type', 'group_id', 'cidr', 'protocol', 'from_port', 'to_port'] },
52
52
  }),
53
53
  ]);
54
54
 
@@ -70,9 +70,20 @@ const OPS = {
70
70
  },
71
71
  'ec2.authorize_ingress': {
72
72
  selector: { protocol: 'aws', tool: 'authorize_security_group_ingress' },
73
- observed: (p) => ({ action_type: 'aws.ec2.authorize_ingress', group_id: p.group_id, cidr: p.cidr, from_port: p.from_port }),
73
+ observed: (p) => ({
74
+ action_type: 'aws.ec2.authorize_ingress',
75
+ group_id: p.group_id,
76
+ cidr: p.cidr,
77
+ protocol: p.protocol ?? 'tcp',
78
+ from_port: p.from_port,
79
+ to_port: p.to_port ?? p.from_port,
80
+ }),
74
81
  perform: (client, p) => client.ec2.authorizeSecurityGroupIngress({
75
- GroupId: p.group_id, CidrIp: p.cidr, FromPort: p.from_port, ToPort: p.to_port ?? p.from_port, IpProtocol: p.protocol ?? 'tcp',
82
+ GroupId: p.group_id,
83
+ CidrIp: p.cidr,
84
+ FromPort: p.from_port,
85
+ ToPort: p.to_port,
86
+ IpProtocol: p.protocol,
76
87
  }),
77
88
  },
78
89
  };