@emilia-protocol/gate 0.11.0 → 0.14.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.
- package/CHANGELOG.md +80 -0
- package/README.md +310 -0
- package/action-control-manifest.js +3 -268
- package/action-escrow-custodian.js +3 -394
- package/action-escrow-evidence.js +3 -858
- package/action-escrow-package.js +3 -1668
- package/action-escrow-postgres.js +3 -337
- package/action-escrow-state.js +3 -396
- package/action-escrow-verifiers.js +3 -331
- package/action-escrow.js +3 -2447
- package/action-packs.js +3 -140
- package/adapters/_kit.js +3 -104
- package/adapters/aws.js +3 -108
- package/adapters/cloudflare.js +3 -54
- package/adapters/gcp.js +3 -70
- package/adapters/github.js +3 -109
- package/adapters/jira.js +3 -55
- package/adapters/k8s.js +3 -70
- package/adapters/linear.js +3 -55
- package/adapters/salesforce.js +3 -55
- package/adapters/stripe.js +3 -81
- package/adapters/supabase.js +3 -121
- package/adapters/terraform.js +3 -59
- package/adapters/vercel.js +3 -84
- package/aec-execution.js +3 -312
- package/breakglass.js +3 -582
- package/capability-receipt.js +4 -0
- package/cf1-conformance.js +3 -106
- package/challenge-store.js +3 -69
- package/control-plane.js +3 -340
- package/coverage.js +3 -721
- package/demo.mjs +1 -1
- package/deployment-attestation.js +3 -247
- package/dist/action-control-manifest.d.ts +82 -0
- package/dist/action-control-manifest.d.ts.map +1 -0
- package/dist/action-control-manifest.js +422 -0
- package/dist/action-control-manifest.js.map +1 -0
- package/dist/action-escrow-custodian.d.ts +74 -0
- package/dist/action-escrow-custodian.d.ts.map +1 -0
- package/dist/action-escrow-custodian.js +363 -0
- package/dist/action-escrow-custodian.js.map +1 -0
- package/dist/action-escrow-evidence.d.ts +130 -0
- package/dist/action-escrow-evidence.d.ts.map +1 -0
- package/dist/action-escrow-evidence.js +1012 -0
- package/dist/action-escrow-evidence.js.map +1 -0
- package/dist/action-escrow-package.d.ts +10 -0
- package/dist/action-escrow-package.d.ts.map +1 -0
- package/dist/action-escrow-package.js +1583 -0
- package/dist/action-escrow-package.js.map +1 -0
- package/dist/action-escrow-postgres.d.ts +62 -0
- package/dist/action-escrow-postgres.d.ts.map +1 -0
- package/dist/action-escrow-postgres.js +339 -0
- package/dist/action-escrow-postgres.js.map +1 -0
- package/dist/action-escrow-state.d.ts +141 -0
- package/dist/action-escrow-state.d.ts.map +1 -0
- package/dist/action-escrow-state.js +413 -0
- package/dist/action-escrow-state.js.map +1 -0
- package/dist/action-escrow-verifiers.d.ts +65 -0
- package/dist/action-escrow-verifiers.d.ts.map +1 -0
- package/dist/action-escrow-verifiers.js +421 -0
- package/dist/action-escrow-verifiers.js.map +1 -0
- package/dist/action-escrow.d.ts +112 -0
- package/dist/action-escrow.d.ts.map +1 -0
- package/dist/action-escrow.js +2661 -0
- package/dist/action-escrow.js.map +1 -0
- package/dist/action-packs.d.ts +54 -0
- package/dist/action-packs.d.ts.map +1 -0
- package/dist/action-packs.js +143 -0
- package/dist/action-packs.js.map +1 -0
- package/dist/adapters/_kit.d.ts +50 -0
- package/dist/adapters/_kit.d.ts.map +1 -0
- package/dist/adapters/_kit.js +98 -0
- package/dist/adapters/_kit.js.map +1 -0
- package/dist/adapters/aws.d.ts +158 -0
- package/dist/adapters/aws.d.ts.map +1 -0
- package/dist/adapters/aws.js +136 -0
- package/dist/adapters/aws.js.map +1 -0
- package/dist/adapters/cloudflare.d.ts +116 -0
- package/dist/adapters/cloudflare.d.ts.map +1 -0
- package/dist/adapters/cloudflare.js +75 -0
- package/dist/adapters/cloudflare.js.map +1 -0
- package/dist/adapters/gcp.d.ts +139 -0
- package/dist/adapters/gcp.d.ts.map +1 -0
- package/dist/adapters/gcp.js +69 -0
- package/dist/adapters/gcp.js.map +1 -0
- package/dist/adapters/github.d.ts +123 -0
- package/dist/adapters/github.d.ts.map +1 -0
- package/dist/adapters/github.js +105 -0
- package/dist/adapters/github.js.map +1 -0
- package/dist/adapters/jira.d.ts +109 -0
- package/dist/adapters/jira.d.ts.map +1 -0
- package/dist/adapters/jira.js +54 -0
- package/dist/adapters/jira.js.map +1 -0
- package/dist/adapters/k8s.d.ts +139 -0
- package/dist/adapters/k8s.d.ts.map +1 -0
- package/dist/adapters/k8s.js +69 -0
- package/dist/adapters/k8s.js.map +1 -0
- package/dist/adapters/linear.d.ts +109 -0
- package/dist/adapters/linear.d.ts.map +1 -0
- package/dist/adapters/linear.js +54 -0
- package/dist/adapters/linear.js.map +1 -0
- package/dist/adapters/salesforce.d.ts +109 -0
- package/dist/adapters/salesforce.d.ts.map +1 -0
- package/dist/adapters/salesforce.js +54 -0
- package/dist/adapters/salesforce.js.map +1 -0
- package/dist/adapters/stripe.d.ts +116 -0
- package/dist/adapters/stripe.d.ts.map +1 -0
- package/dist/adapters/stripe.js +77 -0
- package/dist/adapters/stripe.js.map +1 -0
- package/dist/adapters/supabase.d.ts +127 -0
- package/dist/adapters/supabase.d.ts.map +1 -0
- package/dist/adapters/supabase.js +112 -0
- package/dist/adapters/supabase.js.map +1 -0
- package/dist/adapters/terraform.d.ts +109 -0
- package/dist/adapters/terraform.d.ts.map +1 -0
- package/dist/adapters/terraform.js +58 -0
- package/dist/adapters/terraform.js.map +1 -0
- package/dist/adapters/vercel.d.ts +114 -0
- package/dist/adapters/vercel.d.ts.map +1 -0
- package/dist/adapters/vercel.js +81 -0
- package/dist/adapters/vercel.js.map +1 -0
- package/dist/aec-execution.d.ts +107 -0
- package/dist/aec-execution.d.ts.map +1 -0
- package/dist/aec-execution.js +334 -0
- package/dist/aec-execution.js.map +1 -0
- package/dist/breakglass.d.ts +205 -0
- package/dist/breakglass.d.ts.map +1 -0
- package/dist/breakglass.js +627 -0
- package/dist/breakglass.js.map +1 -0
- package/dist/capability-receipt.d.ts +601 -0
- package/dist/capability-receipt.d.ts.map +1 -0
- package/dist/capability-receipt.js +1177 -0
- package/dist/capability-receipt.js.map +1 -0
- package/dist/cf1-conformance.d.ts +83 -0
- package/dist/cf1-conformance.d.ts.map +1 -0
- package/dist/cf1-conformance.js +94 -0
- package/dist/cf1-conformance.js.map +1 -0
- package/dist/challenge-store.d.ts +20 -0
- package/dist/challenge-store.d.ts.map +1 -0
- package/dist/challenge-store.js +62 -0
- package/dist/challenge-store.js.map +1 -0
- package/dist/control-plane.d.ts +136 -0
- package/dist/control-plane.d.ts.map +1 -0
- package/dist/control-plane.js +349 -0
- package/dist/control-plane.js.map +1 -0
- package/dist/coverage.d.ts +156 -0
- package/dist/coverage.d.ts.map +1 -0
- package/dist/coverage.js +768 -0
- package/dist/coverage.js.map +1 -0
- package/dist/deployment-attestation.d.ts +93 -0
- package/dist/deployment-attestation.d.ts.map +1 -0
- package/dist/deployment-attestation.js +262 -0
- package/dist/deployment-attestation.js.map +1 -0
- package/dist/eg1-conformance.d.ts +286 -0
- package/dist/eg1-conformance.d.ts.map +1 -0
- package/dist/eg1-conformance.js +379 -0
- package/dist/eg1-conformance.js.map +1 -0
- package/dist/enterprise.d.ts +88 -0
- package/dist/enterprise.d.ts.map +1 -0
- package/dist/enterprise.js +194 -0
- package/dist/enterprise.js.map +1 -0
- package/dist/evidence-postgres.d.ts +123 -0
- package/dist/evidence-postgres.d.ts.map +1 -0
- package/dist/evidence-postgres.js +343 -0
- package/dist/evidence-postgres.js.map +1 -0
- package/dist/evidence.d.ts +113 -0
- package/dist/evidence.d.ts.map +1 -0
- package/dist/evidence.js +369 -0
- package/dist/evidence.js.map +1 -0
- package/dist/execution-binding.d.ts +49 -0
- package/dist/execution-binding.d.ts.map +1 -0
- package/dist/execution-binding.js +243 -0
- package/dist/execution-binding.js.map +1 -0
- package/dist/formal-runtime-map.d.ts +42 -0
- package/dist/formal-runtime-map.d.ts.map +1 -0
- package/dist/formal-runtime-map.js +23 -0
- package/dist/formal-runtime-map.js.map +1 -0
- package/dist/index.d.ts +1003 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1737 -0
- package/dist/index.js.map +1 -0
- package/dist/key-registry.d.ts +60 -0
- package/dist/key-registry.d.ts.map +1 -0
- package/dist/key-registry.js +144 -0
- package/dist/key-registry.js.map +1 -0
- package/dist/mcp.d.ts +53 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +112 -0
- package/dist/mcp.js.map +1 -0
- package/dist/metering.d.ts +80 -0
- package/dist/metering.d.ts.map +1 -0
- package/dist/metering.js +227 -0
- package/dist/metering.js.map +1 -0
- package/dist/metrics.d.ts +68 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +242 -0
- package/dist/metrics.js.map +1 -0
- package/dist/network-witness.d.ts +167 -0
- package/dist/network-witness.d.ts.map +1 -0
- package/dist/network-witness.js +520 -0
- package/dist/network-witness.js.map +1 -0
- package/dist/proposal-to-effect.d.ts +146 -0
- package/dist/proposal-to-effect.d.ts.map +1 -0
- package/dist/proposal-to-effect.js +427 -0
- package/dist/proposal-to-effect.js.map +1 -0
- package/dist/protocol-state.d.ts +141 -0
- package/dist/protocol-state.d.ts.map +1 -0
- package/dist/protocol-state.js +106 -0
- package/dist/protocol-state.js.map +1 -0
- package/dist/receipt-program.d.ts +59 -0
- package/dist/receipt-program.d.ts.map +1 -0
- package/dist/receipt-program.js +1053 -0
- package/dist/receipt-program.js.map +1 -0
- package/dist/reliance-kernel.d.ts +66 -0
- package/dist/reliance-kernel.d.ts.map +1 -0
- package/dist/reliance-kernel.js +103 -0
- package/dist/reliance-kernel.js.map +1 -0
- package/dist/reliance-packet.d.ts +67 -0
- package/dist/reliance-packet.d.ts.map +1 -0
- package/dist/reliance-packet.js +176 -0
- package/dist/reliance-packet.js.map +1 -0
- package/dist/remedy-program-postgres.d.ts +37 -0
- package/dist/remedy-program-postgres.d.ts.map +1 -0
- package/dist/remedy-program-postgres.js +291 -0
- package/dist/remedy-program-postgres.js.map +1 -0
- package/dist/remedy-program-receipt.d.ts +97 -0
- package/dist/remedy-program-receipt.d.ts.map +1 -0
- package/dist/remedy-program-receipt.js +817 -0
- package/dist/remedy-program-receipt.js.map +1 -0
- package/dist/remedy-program.d.ts +76 -0
- package/dist/remedy-program.d.ts.map +1 -0
- package/dist/remedy-program.js +1346 -0
- package/dist/remedy-program.js.map +1 -0
- package/dist/reports/art14.d.ts +101 -0
- package/dist/reports/art14.d.ts.map +1 -0
- package/dist/reports/art14.js +340 -0
- package/dist/reports/art14.js.map +1 -0
- package/dist/reports/assurance-package.d.ts +197 -0
- package/dist/reports/assurance-package.d.ts.map +1 -0
- package/dist/reports/assurance-package.js +313 -0
- package/dist/reports/assurance-package.js.map +1 -0
- package/dist/reports/auditor-workpaper.d.ts +194 -0
- package/dist/reports/auditor-workpaper.d.ts.map +1 -0
- package/dist/reports/auditor-workpaper.js +545 -0
- package/dist/reports/auditor-workpaper.js.map +1 -0
- package/dist/reports/external-verification.d.ts +76 -0
- package/dist/reports/external-verification.d.ts.map +1 -0
- package/dist/reports/external-verification.js +209 -0
- package/dist/reports/external-verification.js.map +1 -0
- package/dist/reports/reperform.d.ts +122 -0
- package/dist/reports/reperform.d.ts.map +1 -0
- package/dist/reports/reperform.js +432 -0
- package/dist/reports/reperform.js.map +1 -0
- package/dist/reports/underwriter.d.ts +127 -0
- package/dist/reports/underwriter.d.ts.map +1 -0
- package/dist/reports/underwriter.js +348 -0
- package/dist/reports/underwriter.js.map +1 -0
- package/dist/retention.d.ts +88 -0
- package/dist/retention.d.ts.map +1 -0
- package/dist/retention.js +90 -0
- package/dist/retention.js.map +1 -0
- package/dist/roster.d.ts +113 -0
- package/dist/roster.d.ts.map +1 -0
- package/dist/roster.js +261 -0
- package/dist/roster.js.map +1 -0
- package/dist/runtime-monitor.d.ts +132 -0
- package/dist/runtime-monitor.d.ts.map +1 -0
- package/dist/runtime-monitor.js +197 -0
- package/dist/runtime-monitor.js.map +1 -0
- package/dist/settlement.d.ts +68 -0
- package/dist/settlement.d.ts.map +1 -0
- package/dist/settlement.js +306 -0
- package/dist/settlement.js.map +1 -0
- package/dist/siem.d.ts +261 -0
- package/dist/siem.d.ts.map +1 -0
- package/dist/siem.js +247 -0
- package/dist/siem.js.map +1 -0
- package/dist/store-postgres.d.ts +107 -0
- package/dist/store-postgres.d.ts.map +1 -0
- package/dist/store-postgres.js +152 -0
- package/dist/store-postgres.js.map +1 -0
- package/dist/store.d.ts +95 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +202 -0
- package/dist/store.js.map +1 -0
- package/dist/strict-json.d.ts +14 -0
- package/dist/strict-json.d.ts.map +1 -0
- package/dist/strict-json.js +132 -0
- package/dist/strict-json.js.map +1 -0
- package/dist/trust-program-adapters.d.ts +122 -0
- package/dist/trust-program-adapters.d.ts.map +1 -0
- package/dist/trust-program-adapters.js +802 -0
- package/dist/trust-program-adapters.js.map +1 -0
- package/dist/trust-program-postgres.d.ts +41 -0
- package/dist/trust-program-postgres.d.ts.map +1 -0
- package/dist/trust-program-postgres.js +346 -0
- package/dist/trust-program-postgres.js.map +1 -0
- package/dist/trust-program-revocation.d.ts +206 -0
- package/dist/trust-program-revocation.d.ts.map +1 -0
- package/dist/trust-program-revocation.js +600 -0
- package/dist/trust-program-revocation.js.map +1 -0
- package/dist/trust-program.d.ts +197 -0
- package/dist/trust-program.d.ts.map +1 -0
- package/dist/trust-program.js +1351 -0
- package/dist/trust-program.js.map +1 -0
- package/dist/witness-postgres.d.ts +43 -0
- package/dist/witness-postgres.d.ts.map +1 -0
- package/dist/witness-postgres.js +92 -0
- package/dist/witness-postgres.js.map +1 -0
- package/dist/zk-range-proof.d.ts +78 -0
- package/dist/zk-range-proof.d.ts.map +1 -0
- package/dist/zk-range-proof.js +228 -0
- package/dist/zk-range-proof.js.map +1 -0
- package/eg1-conformance.js +3 -404
- package/enterprise.js +3 -180
- package/ep-assure.mjs +1 -0
- package/evidence-postgres.js +3 -356
- package/evidence.js +4 -360
- package/execution-binding.js +3 -212
- package/formal-runtime-map.js +4 -0
- package/index.js +4 -1249
- package/key-registry.js +3 -134
- package/mcp.js +3 -109
- package/metering.js +3 -226
- package/metrics.js +3 -231
- package/network-witness.js +3 -499
- package/package.json +35 -4
- package/proposal-to-effect.js +4 -0
- package/receipt-program.js +4 -0
- package/reliance-kernel.js +3 -112
- package/reliance-packet.js +3 -175
- package/remedy-program-postgres.js +4 -0
- package/remedy-program-receipt.js +4 -0
- package/remedy-program.js +4 -0
- package/reports/art14.js +0 -0
- package/reports/assurance-package.js +2 -312
- package/reports/auditor-workpaper.js +3 -537
- package/reports/external-verification.js +3 -222
- package/reports/reperform.js +3 -424
- package/reports/underwriter.js +3 -339
- package/retention.js +3 -84
- package/roster.js +3 -264
- package/runtime-monitor.js +4 -0
- package/settlement.js +3 -299
- package/siem.js +3 -235
- package/src/action-control-manifest.ts +424 -0
- package/src/action-escrow-custodian.ts +427 -0
- package/src/action-escrow-evidence.ts +1178 -0
- package/src/action-escrow-package.ts +1821 -0
- package/src/action-escrow-postgres.ts +366 -0
- package/src/action-escrow-state.ts +498 -0
- package/src/action-escrow-verifiers.ts +484 -0
- package/src/action-escrow.ts +3039 -0
- package/src/action-packs.ts +170 -0
- package/src/adapters/_kit.ts +117 -0
- package/src/adapters/aws.ts +142 -0
- package/src/adapters/cloudflare.ts +78 -0
- package/src/adapters/gcp.ts +71 -0
- package/src/adapters/github.ts +110 -0
- package/src/adapters/jira.ts +56 -0
- package/src/adapters/k8s.ts +71 -0
- package/src/adapters/linear.ts +56 -0
- package/src/adapters/salesforce.ts +56 -0
- package/src/adapters/stripe.ts +82 -0
- package/src/adapters/supabase.ts +122 -0
- package/src/adapters/terraform.ts +60 -0
- package/src/adapters/vercel.ts +85 -0
- package/src/aec-execution.ts +354 -0
- package/src/breakglass.ts +647 -0
- package/src/capability-receipt.ts +1258 -0
- package/src/cf1-conformance.ts +120 -0
- package/src/challenge-store.ts +70 -0
- package/src/control-plane.ts +374 -0
- package/src/coverage.ts +832 -0
- package/src/deployment-attestation.ts +259 -0
- package/src/eg1-conformance.ts +471 -0
- package/src/enterprise.ts +195 -0
- package/src/evidence-postgres.ts +374 -0
- package/src/evidence.ts +367 -0
- package/src/execution-binding.ts +236 -0
- package/src/formal-runtime-map.ts +24 -0
- package/src/index.ts +2127 -0
- package/src/key-registry.ts +150 -0
- package/src/mcp.ts +120 -0
- package/src/metering.ts +237 -0
- package/src/metrics.ts +232 -0
- package/src/network-witness.ts +585 -0
- package/src/proposal-to-effect.ts +571 -0
- package/src/protocol-state.ts +143 -0
- package/src/protocol-state.typecheck.ts +94 -0
- package/src/receipt-program.ts +1105 -0
- package/src/reliance-kernel.ts +119 -0
- package/src/reliance-packet.ts +206 -0
- package/src/remedy-program-postgres.ts +367 -0
- package/src/remedy-program-receipt.ts +891 -0
- package/src/remedy-program.ts +1388 -0
- package/src/reports/art14.ts +361 -0
- package/src/reports/assurance-package.ts +330 -0
- package/src/reports/auditor-workpaper.ts +558 -0
- package/src/reports/external-verification.ts +232 -0
- package/src/reports/reperform.ts +441 -0
- package/src/reports/underwriter.ts +356 -0
- package/src/retention.ts +100 -0
- package/src/roster.ts +273 -0
- package/src/runtime-monitor.ts +217 -0
- package/src/settlement.ts +313 -0
- package/src/siem.ts +247 -0
- package/src/store-postgres.ts +167 -0
- package/src/store.ts +214 -0
- package/src/strict-json.ts +115 -0
- package/src/trust-program-adapters.ts +847 -0
- package/src/trust-program-postgres.ts +429 -0
- package/src/trust-program-revocation.ts +751 -0
- package/src/trust-program.ts +1460 -0
- package/src/witness-postgres.ts +106 -0
- package/src/zk-range-proof.ts +250 -0
- package/store-postgres.js +3 -161
- package/store.js +4 -198
- package/strict-json.js +3 -102
- package/trust-program-adapters.js +4 -0
- package/trust-program-postgres.js +4 -0
- package/trust-program-revocation.js +4 -0
- package/trust-program.js +4 -0
- package/witness-postgres.js +3 -96
- package/zk-range-proof.js +4 -0
package/aec-execution.js
CHANGED
|
@@ -1,313 +1,4 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
* verifyAuthorizationChain is a pure evidence-composition decision. This
|
|
6
|
-
* wrapper adds the stateful properties an executor needs: independently bound
|
|
7
|
-
* action bytes, a mandatory human-assurance floor, atomic one-time reservation,
|
|
8
|
-
* tamper-evident decision records, and conservative crash semantics.
|
|
9
|
-
*/
|
|
10
|
-
import { createEvidenceLog, verifyEvidenceRecord } from './evidence.js';
|
|
11
|
-
import { MemoryConsumptionStore } from './store.js';
|
|
12
|
-
import { verifyAuthorizationChain } from '@emilia-protocol/verify/evidence-chain';
|
|
13
|
-
|
|
14
|
-
const HUMAN_FLOORS = new Set(['class_a', 'quorum', 'class_a_or_quorum']);
|
|
15
|
-
const HEX_256 = /^[0-9a-f]{64}$/;
|
|
16
|
-
const COMPONENT_TYPE = /^[A-Za-z0-9_.:-]+$/;
|
|
17
|
-
const RESERVED_COMPONENT_TYPES = new Set(['ep-receipt', 'ep-quorum']);
|
|
18
|
-
const own = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
19
|
-
|
|
20
|
-
function deepFreeze(value) {
|
|
21
|
-
if (!value || typeof value !== 'object') return value;
|
|
22
|
-
const stack = [value];
|
|
23
|
-
const seen = new WeakSet();
|
|
24
|
-
while (stack.length) {
|
|
25
|
-
const current = stack.pop();
|
|
26
|
-
if (!current || typeof current !== 'object' || seen.has(current)) continue;
|
|
27
|
-
seen.add(current);
|
|
28
|
-
for (const child of Object.values(current)) stack.push(child);
|
|
29
|
-
Object.freeze(current);
|
|
30
|
-
}
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function validLogRecord(record, atomicRequired, expectedEntry) {
|
|
35
|
-
return verifyEvidenceRecord(record, { atomicRequired, expectedEntry });
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function validComponent(result, type) {
|
|
39
|
-
return Array.isArray(result?.components)
|
|
40
|
-
&& result.components.some((component) => component.type === type && component.valid === true && component.bound === true);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function humanFloorSatisfied(result, floor) {
|
|
44
|
-
const classA = validComponent(result, 'ep-receipt');
|
|
45
|
-
const quorum = validComponent(result, 'ep-quorum');
|
|
46
|
-
if (floor === 'class_a') return classA;
|
|
47
|
-
if (floor === 'quorum') return quorum;
|
|
48
|
-
return classA || quorum;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function evidenceSatisfied(result) {
|
|
52
|
-
try {
|
|
53
|
-
if (!result || typeof result !== 'object') return false;
|
|
54
|
-
// New verifiers expose the evidence-layer term. Older supported 3.x
|
|
55
|
-
// verifiers expose the equivalent `allow` result only. If `satisfied` is
|
|
56
|
-
// present, it is authoritative so a conflicting compatibility alias can
|
|
57
|
-
// never upgrade a refusal.
|
|
58
|
-
return own(result, 'satisfied') ? result.satisfied === true : result.allow === true;
|
|
59
|
-
} catch {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function consumptionKey(result) {
|
|
65
|
-
// Consume the executor-owned action instance, not a presenter-selected
|
|
66
|
-
// component identifier. Otherwise an invalid decoy component or an alternate
|
|
67
|
-
// valid human proof can create a fresh key for the same physical effect.
|
|
68
|
-
// Repeated intended effects therefore need a unique nonce/id inside the
|
|
69
|
-
// canonical action before authorization is collected.
|
|
70
|
-
return HEX_256.test(result?.action_digest)
|
|
71
|
-
? `aec:action:${result.action_digest}`
|
|
72
|
-
: null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function instant(now) {
|
|
76
|
-
try {
|
|
77
|
-
const value = typeof now === 'function' ? now() : now;
|
|
78
|
-
const date = value instanceof Date ? value : new Date(value);
|
|
79
|
-
return Number.isFinite(date.getTime()) ? date.toISOString() : null;
|
|
80
|
-
} catch {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* @param {object} config
|
|
87
|
-
* @param {string} config.requirement relying-party AEC requirement
|
|
88
|
-
* @param {object} config.policiesByType relying-party human acceptance profiles
|
|
89
|
-
* @param {object} [config.verifiers] relying-party-pinned custom component verifiers
|
|
90
|
-
* @param {object} [config.keysByType] relying-party-pinned custom verifier keys
|
|
91
|
-
* @param {'class_a'|'quorum'|'class_a_or_quorum'} config.humanFloor
|
|
92
|
-
* @param {object} [config.store] ownership-fenced consumption store
|
|
93
|
-
* @param {object} [config.log] tamper-evident evidence log
|
|
94
|
-
* @param {boolean} [config.allowEphemeralState=false] test/demo opt-in only
|
|
95
|
-
* @param {Function|number|Date} [config.now=Date.now]
|
|
96
|
-
*/
|
|
97
|
-
export function createAECExecutionGate({
|
|
98
|
-
requirement,
|
|
99
|
-
policiesByType,
|
|
100
|
-
verifiers = {},
|
|
101
|
-
keysByType = {},
|
|
102
|
-
humanFloor,
|
|
103
|
-
store,
|
|
104
|
-
log,
|
|
105
|
-
allowEphemeralState = false,
|
|
106
|
-
now = Date.now,
|
|
107
|
-
} = {}) {
|
|
108
|
-
if (typeof requirement !== 'string' || !requirement.trim()) {
|
|
109
|
-
throw new Error('AEC execution gate requires a relying-party requirement');
|
|
110
|
-
}
|
|
111
|
-
if (!policiesByType || typeof policiesByType !== 'object' || Array.isArray(policiesByType)) {
|
|
112
|
-
throw new Error('AEC execution gate requires relying-party policiesByType');
|
|
113
|
-
}
|
|
114
|
-
let pinnedPolicies;
|
|
115
|
-
try { pinnedPolicies = deepFreeze(structuredClone(policiesByType)); }
|
|
116
|
-
catch { throw new Error('AEC execution gate policiesByType must be cloneable canonical data'); }
|
|
117
|
-
if (!verifiers || typeof verifiers !== 'object' || Array.isArray(verifiers)) {
|
|
118
|
-
throw new Error('AEC execution gate verifiers must be a relying-party-owned object');
|
|
119
|
-
}
|
|
120
|
-
const pinnedVerifiers = Object.create(null);
|
|
121
|
-
try {
|
|
122
|
-
for (const [type, verifier] of Object.entries(verifiers)) {
|
|
123
|
-
if (!COMPONENT_TYPE.test(type) || type.length > 128 || RESERVED_COMPONENT_TYPES.has(type)
|
|
124
|
-
|| typeof verifier !== 'function') {
|
|
125
|
-
throw new Error('invalid verifier registry member');
|
|
126
|
-
}
|
|
127
|
-
pinnedVerifiers[type] = verifier;
|
|
128
|
-
}
|
|
129
|
-
Object.freeze(pinnedVerifiers);
|
|
130
|
-
} catch {
|
|
131
|
-
throw new Error('AEC execution gate verifiers must contain only named custom verifier functions');
|
|
132
|
-
}
|
|
133
|
-
if (!keysByType || typeof keysByType !== 'object' || Array.isArray(keysByType)) {
|
|
134
|
-
throw new Error('AEC execution gate keysByType must be a relying-party-owned object');
|
|
135
|
-
}
|
|
136
|
-
let pinnedKeysByType;
|
|
137
|
-
try { pinnedKeysByType = deepFreeze(structuredClone(keysByType)); }
|
|
138
|
-
catch { throw new Error('AEC execution gate keysByType must be cloneable canonical data'); }
|
|
139
|
-
if (!HUMAN_FLOORS.has(humanFloor)) {
|
|
140
|
-
throw new Error('AEC execution gate requires humanFloor class_a, quorum, or class_a_or_quorum');
|
|
141
|
-
}
|
|
142
|
-
if (!store && !allowEphemeralState) {
|
|
143
|
-
throw new Error('AEC execution gate requires a durable consumption store');
|
|
144
|
-
}
|
|
145
|
-
if (!log && !allowEphemeralState) {
|
|
146
|
-
throw new Error('AEC execution gate requires a durable strict evidence log');
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const consumption = store || new MemoryConsumptionStore();
|
|
150
|
-
const evidence = log || createEvidenceLog({ strict: true });
|
|
151
|
-
if (!allowEphemeralState && (consumption.durable !== true || consumption.ownershipFenced !== true
|
|
152
|
-
|| consumption.permanentConsumption !== true)) {
|
|
153
|
-
throw new Error('AEC execution gate requires a capability-marked, ownership-fenced durable store with non-expiring committed keys');
|
|
154
|
-
}
|
|
155
|
-
if (!allowEphemeralState && (evidence.durable !== true || evidence.strict !== true
|
|
156
|
-
|| evidence.forkAware !== true || evidence.atomicAppend !== true)) {
|
|
157
|
-
throw new Error('AEC execution gate requires a durable strict evidence log with atomic shared-head append and fork detection');
|
|
158
|
-
}
|
|
159
|
-
for (const method of ['reserve', 'commit']) {
|
|
160
|
-
if (typeof consumption?.[method] !== 'function') {
|
|
161
|
-
throw new Error(`AEC execution gate consumption store requires ${method}()`);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
if (typeof evidence?.record !== 'function') {
|
|
165
|
-
throw new Error('AEC execution gate evidence log requires record()');
|
|
166
|
-
}
|
|
167
|
-
// Capture the methods that passed construction checks. Callers may retain the
|
|
168
|
-
// objects for observability, but replacing a method later must not rewrite the
|
|
169
|
-
// gate's replay or evidence semantics.
|
|
170
|
-
const reserveConsumption = consumption.reserve.bind(consumption);
|
|
171
|
-
const commitConsumption = consumption.commit.bind(consumption);
|
|
172
|
-
const releaseConsumption = typeof consumption.release === 'function'
|
|
173
|
-
? consumption.release.bind(consumption) : null;
|
|
174
|
-
const recordEvidence = evidence.record.bind(evidence);
|
|
175
|
-
|
|
176
|
-
async function deny(reason, result = null, extra = {}) {
|
|
177
|
-
let decision = null;
|
|
178
|
-
try {
|
|
179
|
-
const entry = {
|
|
180
|
-
type: 'aec.execution.decision',
|
|
181
|
-
at: instant(now),
|
|
182
|
-
allow: false,
|
|
183
|
-
reason,
|
|
184
|
-
action_digest: result?.action_digest ?? null,
|
|
185
|
-
requirement,
|
|
186
|
-
human_floor: humanFloor,
|
|
187
|
-
...extra,
|
|
188
|
-
};
|
|
189
|
-
decision = await recordEvidence(entry);
|
|
190
|
-
if (!validLogRecord(decision, !allowEphemeralState, entry)) throw new Error('malformed evidence record');
|
|
191
|
-
} catch {
|
|
192
|
-
return { ok: false, allow: false, reason: 'evidence_log_failed', result, decision: null };
|
|
193
|
-
}
|
|
194
|
-
return { ok: false, allow: false, reason, result, decision };
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
async function run(request = {}, effect) {
|
|
198
|
-
if (typeof effect !== 'function') throw new Error('AEC execution gate run() requires an effect function');
|
|
199
|
-
let chain;
|
|
200
|
-
let expectedAction;
|
|
201
|
-
try {
|
|
202
|
-
if (!request || typeof request !== 'object' || Array.isArray(request)) {
|
|
203
|
-
return deny('invalid_execution_request');
|
|
204
|
-
}
|
|
205
|
-
// Trust configuration belongs to the relying party at gate construction.
|
|
206
|
-
// Accepting verifier code or trust keys beside presenter evidence lets the
|
|
207
|
-
// presenter define the proof that its own evidence must pass.
|
|
208
|
-
if (own(request, 'verifiers') || own(request, 'keysByType') || own(request, 'policiesByType')) {
|
|
209
|
-
return deny('runtime_trust_configuration_refused');
|
|
210
|
-
}
|
|
211
|
-
chain = request.chain;
|
|
212
|
-
expectedAction = request.expectedAction;
|
|
213
|
-
} catch {
|
|
214
|
-
return deny('invalid_execution_request');
|
|
215
|
-
}
|
|
216
|
-
const verificationTime = instant(now);
|
|
217
|
-
if (!verificationTime) return deny('invalid_verification_time');
|
|
218
|
-
let actionSnapshot;
|
|
219
|
-
try { actionSnapshot = deepFreeze(structuredClone(expectedAction)); }
|
|
220
|
-
catch { return deny('invalid_expected_action'); }
|
|
221
|
-
|
|
222
|
-
const result = verifyAuthorizationChain(chain, {
|
|
223
|
-
verifiers: pinnedVerifiers,
|
|
224
|
-
keysByType: pinnedKeysByType,
|
|
225
|
-
policiesByType: pinnedPolicies,
|
|
226
|
-
requirement,
|
|
227
|
-
expectedAction: actionSnapshot,
|
|
228
|
-
verificationTime,
|
|
229
|
-
});
|
|
230
|
-
if (!evidenceSatisfied(result)) return deny('aec_refused', result, { reasons: result.reasons });
|
|
231
|
-
if (!humanFloorSatisfied(result, humanFloor)) return deny('human_floor_unsatisfied', result);
|
|
232
|
-
|
|
233
|
-
const key = consumptionKey(result);
|
|
234
|
-
if (!key) return deny('missing_stable_consumption_key', result);
|
|
235
|
-
|
|
236
|
-
let reserved;
|
|
237
|
-
try { reserved = (await reserveConsumption(key)) === true; }
|
|
238
|
-
catch { return deny('consumption_store_unavailable', result, { consumption_key: key }); }
|
|
239
|
-
if (!reserved) return deny('replay_refused', result, { consumption_key: key });
|
|
240
|
-
|
|
241
|
-
let authorization;
|
|
242
|
-
try {
|
|
243
|
-
const entry = {
|
|
244
|
-
type: 'aec.execution.decision',
|
|
245
|
-
at: verificationTime,
|
|
246
|
-
allow: true,
|
|
247
|
-
reason: 'allow',
|
|
248
|
-
action_digest: result.action_digest,
|
|
249
|
-
requirement,
|
|
250
|
-
human_floor: humanFloor,
|
|
251
|
-
consumption_key: key,
|
|
252
|
-
};
|
|
253
|
-
authorization = await recordEvidence(entry);
|
|
254
|
-
if (!validLogRecord(authorization, !allowEphemeralState, entry)) throw new Error('malformed evidence record');
|
|
255
|
-
} catch {
|
|
256
|
-
try { if (releaseConsumption) await releaseConsumption(key); } catch { /* frozen is safe */ }
|
|
257
|
-
return { ok: false, allow: false, reason: 'evidence_log_failed', result, decision: null };
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
let effectStarted = false;
|
|
261
|
-
let committed = false;
|
|
262
|
-
try {
|
|
263
|
-
effectStarted = true;
|
|
264
|
-
const value = await effect({ action: actionSnapshot, result, authorization });
|
|
265
|
-
if ((await commitConsumption(key)) !== true) throw new Error('consumption_store_commit_refused');
|
|
266
|
-
committed = true;
|
|
267
|
-
const executionEntry = {
|
|
268
|
-
type: 'aec.execution.outcome',
|
|
269
|
-
at: instant(now),
|
|
270
|
-
outcome: 'executed',
|
|
271
|
-
authorizes_decision: authorization.hash,
|
|
272
|
-
action_digest: result.action_digest,
|
|
273
|
-
consumption_key: key,
|
|
274
|
-
};
|
|
275
|
-
const execution = await recordEvidence(executionEntry);
|
|
276
|
-
if (!validLogRecord(execution, !allowEphemeralState, executionEntry)) throw new Error('malformed evidence record');
|
|
277
|
-
return { ok: true, allow: true, value, result, authorization, execution };
|
|
278
|
-
} catch (error) {
|
|
279
|
-
if (effectStarted && !committed) {
|
|
280
|
-
try { committed = (await commitConsumption(key)) === true; } catch { /* reservation remains fail-closed */ }
|
|
281
|
-
}
|
|
282
|
-
try {
|
|
283
|
-
const indeterminateEntry = {
|
|
284
|
-
type: 'aec.execution.outcome',
|
|
285
|
-
at: instant(now),
|
|
286
|
-
outcome: 'indeterminate',
|
|
287
|
-
authorizes_decision: authorization.hash,
|
|
288
|
-
action_digest: result.action_digest,
|
|
289
|
-
consumption_key: key,
|
|
290
|
-
};
|
|
291
|
-
const indeterminate = await recordEvidence(indeterminateEntry);
|
|
292
|
-
if (!validLogRecord(indeterminate, !allowEphemeralState, indeterminateEntry)) {
|
|
293
|
-
throw new Error('malformed evidence record');
|
|
294
|
-
}
|
|
295
|
-
} catch { /* the original failure remains primary; replay is still blocked */ }
|
|
296
|
-
throw error;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
return { run, evidence, store: consumption };
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
export const __aecExecutionSecurityInternals = Object.freeze({
|
|
304
|
-
deepFreeze,
|
|
305
|
-
validLogRecord,
|
|
306
|
-
validComponent,
|
|
307
|
-
humanFloorSatisfied,
|
|
308
|
-
evidenceSatisfied,
|
|
309
|
-
consumptionKey,
|
|
310
|
-
instant,
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
export default { createAECExecutionGate };
|
|
2
|
+
// Compatibility entry point for the TypeScript aec-execution module.
|
|
3
|
+
export * from './dist/aec-execution.js';
|
|
4
|
+
export { default } from './dist/aec-execution.js';
|