@emilia-protocol/gate 0.11.0 → 0.13.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 +58 -0
- package/README.md +252 -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 +1002 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1736 -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/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 +31 -2
- 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 +2122 -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/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
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { MemoryConsumptionStore } from './store.js';
|
|
2
|
+
type Obj = Record<string, any>;
|
|
3
|
+
type ConsumptionStore = {
|
|
4
|
+
durable?: boolean;
|
|
5
|
+
ownershipFenced?: boolean;
|
|
6
|
+
permanentConsumption?: boolean;
|
|
7
|
+
reserve?: (key: string) => Promise<boolean> | boolean;
|
|
8
|
+
commit?: (key: string) => Promise<boolean> | boolean;
|
|
9
|
+
release?: (key: string) => Promise<void> | void;
|
|
10
|
+
};
|
|
11
|
+
type ExecutionEvidenceLog = {
|
|
12
|
+
durable?: boolean;
|
|
13
|
+
strict?: boolean;
|
|
14
|
+
forkAware?: boolean;
|
|
15
|
+
atomicAppend?: boolean;
|
|
16
|
+
record?: (entry: Obj) => Promise<Obj> | Obj;
|
|
17
|
+
};
|
|
18
|
+
declare function deepFreeze(value: any): any;
|
|
19
|
+
declare function validLogRecord(record: any, atomicRequired: any, expectedEntry: any): boolean;
|
|
20
|
+
declare function validComponent(result: any, type: any): any;
|
|
21
|
+
declare function humanFloorSatisfied(result: any, floor: any): any;
|
|
22
|
+
declare function evidenceSatisfied(result: any): boolean;
|
|
23
|
+
declare function consumptionKey(result: any): string | null;
|
|
24
|
+
declare function instant(now: any): string | null;
|
|
25
|
+
/**
|
|
26
|
+
* @param {object} [config]
|
|
27
|
+
* @param {string} [config.requirement] relying-party AEC requirement (required at runtime)
|
|
28
|
+
* @param {object} [config.policiesByType] relying-party human acceptance profiles (required at runtime)
|
|
29
|
+
* @param {object} [config.verifiers] relying-party-pinned custom component verifiers
|
|
30
|
+
* @param {object} [config.keysByType] relying-party-pinned custom verifier keys
|
|
31
|
+
* @param {'class_a'|'quorum'|'class_a_or_quorum'} [config.humanFloor] (required at runtime)
|
|
32
|
+
* @param {object} [config.store] ownership-fenced consumption store
|
|
33
|
+
* @param {object} [config.log] tamper-evident evidence log
|
|
34
|
+
* @param {boolean} [config.allowEphemeralState=false] test/demo opt-in only
|
|
35
|
+
* @param {Function|number|Date} [config.now=Date.now]
|
|
36
|
+
*/
|
|
37
|
+
export declare function createAECExecutionGate({ requirement, policiesByType, verifiers, keysByType, humanFloor, store, log, allowEphemeralState, now, }?: {
|
|
38
|
+
requirement?: string;
|
|
39
|
+
policiesByType?: Obj;
|
|
40
|
+
verifiers?: Record<string, Function>;
|
|
41
|
+
keysByType?: Obj;
|
|
42
|
+
humanFloor?: 'class_a' | 'quorum' | 'class_a_or_quorum';
|
|
43
|
+
store?: ConsumptionStore;
|
|
44
|
+
log?: ExecutionEvidenceLog;
|
|
45
|
+
allowEphemeralState?: boolean;
|
|
46
|
+
now?: (() => number) | number | Date;
|
|
47
|
+
}): {
|
|
48
|
+
run: (request: Obj | undefined, effect: (input: {
|
|
49
|
+
action: any;
|
|
50
|
+
result: any;
|
|
51
|
+
authorization: any;
|
|
52
|
+
}) => any) => Promise<{
|
|
53
|
+
ok: false;
|
|
54
|
+
allow: false;
|
|
55
|
+
reason: string;
|
|
56
|
+
result: Obj | null;
|
|
57
|
+
decision: any;
|
|
58
|
+
value?: undefined;
|
|
59
|
+
authorization?: undefined;
|
|
60
|
+
execution?: undefined;
|
|
61
|
+
} | {
|
|
62
|
+
ok: true;
|
|
63
|
+
allow: true;
|
|
64
|
+
value: any;
|
|
65
|
+
result: any;
|
|
66
|
+
authorization: any;
|
|
67
|
+
execution: any;
|
|
68
|
+
reason?: undefined;
|
|
69
|
+
}>;
|
|
70
|
+
evidence: {
|
|
71
|
+
durable: boolean;
|
|
72
|
+
persisted: boolean;
|
|
73
|
+
strict: boolean;
|
|
74
|
+
forkAware: boolean;
|
|
75
|
+
atomicAppend: boolean;
|
|
76
|
+
record(entry: any): Promise<any>;
|
|
77
|
+
all(): Record<string, any>[];
|
|
78
|
+
verify(): {
|
|
79
|
+
ok: boolean;
|
|
80
|
+
at: any;
|
|
81
|
+
reason: string;
|
|
82
|
+
length?: undefined;
|
|
83
|
+
head?: undefined;
|
|
84
|
+
} | {
|
|
85
|
+
ok: boolean;
|
|
86
|
+
length: number;
|
|
87
|
+
head: string | null;
|
|
88
|
+
at?: undefined;
|
|
89
|
+
reason?: undefined;
|
|
90
|
+
};
|
|
91
|
+
} | ExecutionEvidenceLog;
|
|
92
|
+
store: MemoryConsumptionStore | ConsumptionStore;
|
|
93
|
+
};
|
|
94
|
+
export declare const __aecExecutionSecurityInternals: Readonly<{
|
|
95
|
+
deepFreeze: typeof deepFreeze;
|
|
96
|
+
validLogRecord: typeof validLogRecord;
|
|
97
|
+
validComponent: typeof validComponent;
|
|
98
|
+
humanFloorSatisfied: typeof humanFloorSatisfied;
|
|
99
|
+
evidenceSatisfied: typeof evidenceSatisfied;
|
|
100
|
+
consumptionKey: typeof consumptionKey;
|
|
101
|
+
instant: typeof instant;
|
|
102
|
+
}>;
|
|
103
|
+
declare const _default: {
|
|
104
|
+
createAECExecutionGate: typeof createAECExecutionGate;
|
|
105
|
+
};
|
|
106
|
+
export default _default;
|
|
107
|
+
//# sourceMappingURL=aec-execution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aec-execution.d.ts","sourceRoot":"","sources":["../src/aec-execution.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE/B,KAAK,gBAAgB,GAAG;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IACtD,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IACrD,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACjD,CAAC;AAEF,KAAK,oBAAoB,GAAG;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;CAC7C,CAAC;AAQF,iBAAS,UAAU,CAAC,KAAK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GAAG,GAAG,IAAI,CAAC;QAAC,QAAQ,EAAE,GAAG,CAAC;QAAC,KAAK,CAAC,EAAE,SAAS,CAAC;QAAC,aAAa,CAAC,EAAE,SAAS,CAAC;QAAC,SAAS,CAAC,EAAE,SAAS,CAAA;KAAE,GACnJ;QAAE,EAAE,EAAE,IAAI,CAAC;QAAC,KAAK,EAAE,IAAI,CAAC;QAAC,KAAK,EAAE,GAAG,CAAC;QAAC,MAAM,EAAE,GAAG,CAAC;QAAC,aAAa,EAAE,GAAG,CAAC;QAAC,SAAS,EAAE,GAAG,CAAC;QAAC,MAAM,CAAC,EAAE,SAAS,CAAA;KAAE,CAC7G;;;;;;;;;;;;;;;;;;;;;;;;EAwGF;AAED,eAAO,MAAM,+BAA+B;;;;;;;;EAQ1C,CAAC;;;;AAEH,wBAA0C"}
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/**
|
|
4
|
+
* Stateful execution boundary for EP-AEC.
|
|
5
|
+
*
|
|
6
|
+
* verifyAuthorizationChain is a pure evidence-composition decision. This
|
|
7
|
+
* wrapper adds the stateful properties an executor needs: independently bound
|
|
8
|
+
* action bytes, a mandatory human-assurance floor, atomic one-time reservation,
|
|
9
|
+
* tamper-evident decision records, and conservative crash semantics.
|
|
10
|
+
*/
|
|
11
|
+
import { createEvidenceLog, verifyEvidenceRecord } from './evidence.js';
|
|
12
|
+
import { MemoryConsumptionStore } from './store.js';
|
|
13
|
+
import { verifyAuthorizationChain } from '@emilia-protocol/verify/evidence-chain';
|
|
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
|
+
function deepFreeze(value) {
|
|
20
|
+
if (!value || typeof value !== 'object')
|
|
21
|
+
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))
|
|
27
|
+
continue;
|
|
28
|
+
seen.add(current);
|
|
29
|
+
for (const child of Object.values(current))
|
|
30
|
+
stack.push(child);
|
|
31
|
+
Object.freeze(current);
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
function validLogRecord(record, atomicRequired, expectedEntry) {
|
|
36
|
+
return verifyEvidenceRecord(record, { atomicRequired, expectedEntry });
|
|
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
|
+
function humanFloorSatisfied(result, floor) {
|
|
43
|
+
const classA = validComponent(result, 'ep-receipt');
|
|
44
|
+
const quorum = validComponent(result, 'ep-quorum');
|
|
45
|
+
if (floor === 'class_a')
|
|
46
|
+
return classA;
|
|
47
|
+
if (floor === 'quorum')
|
|
48
|
+
return quorum;
|
|
49
|
+
return classA || quorum;
|
|
50
|
+
}
|
|
51
|
+
function evidenceSatisfied(result) {
|
|
52
|
+
try {
|
|
53
|
+
if (!result || typeof result !== 'object')
|
|
54
|
+
return false;
|
|
55
|
+
// New verifiers expose the evidence-layer term. Older supported 3.x
|
|
56
|
+
// verifiers expose the equivalent `allow` result only. If `satisfied` is
|
|
57
|
+
// present, it is authoritative so a conflicting compatibility alias can
|
|
58
|
+
// never upgrade a refusal.
|
|
59
|
+
return own(result, 'satisfied') ? result.satisfied === true : result.allow === true;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function consumptionKey(result) {
|
|
66
|
+
// Consume the executor-owned action instance, not a presenter-selected
|
|
67
|
+
// component identifier. Otherwise an invalid decoy component or an alternate
|
|
68
|
+
// valid human proof can create a fresh key for the same physical effect.
|
|
69
|
+
// Repeated intended effects therefore need a unique nonce/id inside the
|
|
70
|
+
// canonical action before authorization is collected.
|
|
71
|
+
return HEX_256.test(result?.action_digest)
|
|
72
|
+
? `aec:action:${result.action_digest}`
|
|
73
|
+
: null;
|
|
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
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @param {object} [config]
|
|
87
|
+
* @param {string} [config.requirement] relying-party AEC requirement (required at runtime)
|
|
88
|
+
* @param {object} [config.policiesByType] relying-party human acceptance profiles (required at runtime)
|
|
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] (required at runtime)
|
|
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({ requirement, policiesByType, verifiers = {}, keysByType = {}, humanFloor, store, log, allowEphemeralState = false, now = Date.now, } = {}) {
|
|
98
|
+
if (typeof requirement !== 'string' || !requirement.trim()) {
|
|
99
|
+
throw new Error('AEC execution gate requires a relying-party requirement');
|
|
100
|
+
}
|
|
101
|
+
if (!policiesByType || typeof policiesByType !== 'object' || Array.isArray(policiesByType)) {
|
|
102
|
+
throw new Error('AEC execution gate requires relying-party policiesByType');
|
|
103
|
+
}
|
|
104
|
+
let pinnedPolicies;
|
|
105
|
+
try {
|
|
106
|
+
pinnedPolicies = deepFreeze(structuredClone(policiesByType));
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
throw new Error('AEC execution gate policiesByType must be cloneable canonical data');
|
|
110
|
+
}
|
|
111
|
+
if (!verifiers || typeof verifiers !== 'object' || Array.isArray(verifiers)) {
|
|
112
|
+
throw new Error('AEC execution gate verifiers must be a relying-party-owned object');
|
|
113
|
+
}
|
|
114
|
+
const pinnedVerifiers = Object.create(null);
|
|
115
|
+
try {
|
|
116
|
+
for (const [type, verifier] of Object.entries(verifiers)) {
|
|
117
|
+
if (!COMPONENT_TYPE.test(type) || type.length > 128 || RESERVED_COMPONENT_TYPES.has(type)
|
|
118
|
+
|| typeof verifier !== 'function') {
|
|
119
|
+
throw new Error('invalid verifier registry member');
|
|
120
|
+
}
|
|
121
|
+
pinnedVerifiers[type] = verifier;
|
|
122
|
+
}
|
|
123
|
+
Object.freeze(pinnedVerifiers);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
throw new Error('AEC execution gate verifiers must contain only named custom verifier functions');
|
|
127
|
+
}
|
|
128
|
+
if (!keysByType || typeof keysByType !== 'object' || Array.isArray(keysByType)) {
|
|
129
|
+
throw new Error('AEC execution gate keysByType must be a relying-party-owned object');
|
|
130
|
+
}
|
|
131
|
+
let pinnedKeysByType;
|
|
132
|
+
try {
|
|
133
|
+
pinnedKeysByType = deepFreeze(structuredClone(keysByType));
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
throw new Error('AEC execution gate keysByType must be cloneable canonical data');
|
|
137
|
+
}
|
|
138
|
+
if (!HUMAN_FLOORS.has(humanFloor)) {
|
|
139
|
+
throw new Error('AEC execution gate requires humanFloor class_a, quorum, or class_a_or_quorum');
|
|
140
|
+
}
|
|
141
|
+
if (!store && !allowEphemeralState) {
|
|
142
|
+
throw new Error('AEC execution gate requires a durable consumption store');
|
|
143
|
+
}
|
|
144
|
+
if (!log && !allowEphemeralState) {
|
|
145
|
+
throw new Error('AEC execution gate requires a durable strict evidence log');
|
|
146
|
+
}
|
|
147
|
+
const consumption = store || new MemoryConsumptionStore();
|
|
148
|
+
const evidence = log || createEvidenceLog({ strict: true });
|
|
149
|
+
if (!allowEphemeralState && (consumption.durable !== true || consumption.ownershipFenced !== true
|
|
150
|
+
|| consumption.permanentConsumption !== true)) {
|
|
151
|
+
throw new Error('AEC execution gate requires a capability-marked, ownership-fenced durable store with non-expiring committed keys');
|
|
152
|
+
}
|
|
153
|
+
if (!allowEphemeralState && (evidence.durable !== true || evidence.strict !== true
|
|
154
|
+
|| evidence.forkAware !== true || evidence.atomicAppend !== true)) {
|
|
155
|
+
throw new Error('AEC execution gate requires a durable strict evidence log with atomic shared-head append and fork detection');
|
|
156
|
+
}
|
|
157
|
+
for (const method of ['reserve', 'commit']) {
|
|
158
|
+
if (typeof consumption?.[method] !== 'function') {
|
|
159
|
+
throw new Error(`AEC execution gate consumption store requires ${method}()`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (typeof evidence?.record !== 'function') {
|
|
163
|
+
throw new Error('AEC execution gate evidence log requires record()');
|
|
164
|
+
}
|
|
165
|
+
// Capture the methods that passed construction checks. Callers may retain the
|
|
166
|
+
// objects for observability, but replacing a method later must not rewrite the
|
|
167
|
+
// gate's replay or evidence semantics.
|
|
168
|
+
// The loop above already proves reserve/commit are functions; TS can't track
|
|
169
|
+
// narrowing through a dynamic (computed) property key, hence the assertions.
|
|
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
|
+
async function deny(reason, result = null, extra = {}) {
|
|
176
|
+
let decision = null;
|
|
177
|
+
try {
|
|
178
|
+
const entry = {
|
|
179
|
+
type: 'aec.execution.decision',
|
|
180
|
+
at: instant(now),
|
|
181
|
+
allow: false,
|
|
182
|
+
reason,
|
|
183
|
+
action_digest: result?.action_digest ?? null,
|
|
184
|
+
requirement,
|
|
185
|
+
human_floor: humanFloor,
|
|
186
|
+
...extra,
|
|
187
|
+
};
|
|
188
|
+
decision = await recordEvidence(entry);
|
|
189
|
+
if (!validLogRecord(decision, !allowEphemeralState, entry))
|
|
190
|
+
throw new Error('malformed evidence record');
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
return { ok: false, allow: false, reason: 'evidence_log_failed', result, decision: null };
|
|
194
|
+
}
|
|
195
|
+
return { ok: false, allow: false, reason, result, decision };
|
|
196
|
+
}
|
|
197
|
+
async function run(request = {}, effect) {
|
|
198
|
+
if (typeof effect !== 'function')
|
|
199
|
+
throw new Error('AEC execution gate run() requires an effect function');
|
|
200
|
+
let chain;
|
|
201
|
+
let expectedAction;
|
|
202
|
+
try {
|
|
203
|
+
if (!request || typeof request !== 'object' || Array.isArray(request)) {
|
|
204
|
+
return deny('invalid_execution_request');
|
|
205
|
+
}
|
|
206
|
+
// Trust configuration belongs to the relying party at gate construction.
|
|
207
|
+
// Accepting verifier code or trust keys beside presenter evidence lets the
|
|
208
|
+
// presenter define the proof that its own evidence must pass.
|
|
209
|
+
if (own(request, 'verifiers') || own(request, 'keysByType') || own(request, 'policiesByType')) {
|
|
210
|
+
return deny('runtime_trust_configuration_refused');
|
|
211
|
+
}
|
|
212
|
+
chain = request.chain;
|
|
213
|
+
expectedAction = request.expectedAction;
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
return deny('invalid_execution_request');
|
|
217
|
+
}
|
|
218
|
+
const verificationTime = instant(now);
|
|
219
|
+
if (!verificationTime)
|
|
220
|
+
return deny('invalid_verification_time');
|
|
221
|
+
let actionSnapshot;
|
|
222
|
+
try {
|
|
223
|
+
actionSnapshot = deepFreeze(structuredClone(expectedAction));
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
return deny('invalid_expected_action');
|
|
227
|
+
}
|
|
228
|
+
const result = verifyAuthorizationChain(chain, {
|
|
229
|
+
verifiers: pinnedVerifiers,
|
|
230
|
+
keysByType: pinnedKeysByType,
|
|
231
|
+
policiesByType: pinnedPolicies,
|
|
232
|
+
requirement,
|
|
233
|
+
expectedAction: actionSnapshot,
|
|
234
|
+
verificationTime,
|
|
235
|
+
});
|
|
236
|
+
if (!evidenceSatisfied(result))
|
|
237
|
+
return deny('aec_refused', result, { reasons: result.reasons });
|
|
238
|
+
if (!humanFloorSatisfied(result, humanFloor))
|
|
239
|
+
return deny('human_floor_unsatisfied', result);
|
|
240
|
+
const key = consumptionKey(result);
|
|
241
|
+
if (!key)
|
|
242
|
+
return deny('missing_stable_consumption_key', result);
|
|
243
|
+
let reserved;
|
|
244
|
+
try {
|
|
245
|
+
reserved = (await reserveConsumption(key)) === true;
|
|
246
|
+
}
|
|
247
|
+
catch {
|
|
248
|
+
return deny('consumption_store_unavailable', result, { consumption_key: key });
|
|
249
|
+
}
|
|
250
|
+
if (!reserved)
|
|
251
|
+
return deny('replay_refused', result, { consumption_key: key });
|
|
252
|
+
let authorization;
|
|
253
|
+
try {
|
|
254
|
+
const entry = {
|
|
255
|
+
type: 'aec.execution.decision',
|
|
256
|
+
at: verificationTime,
|
|
257
|
+
allow: true,
|
|
258
|
+
reason: 'allow',
|
|
259
|
+
action_digest: result.action_digest,
|
|
260
|
+
requirement,
|
|
261
|
+
human_floor: humanFloor,
|
|
262
|
+
consumption_key: key,
|
|
263
|
+
};
|
|
264
|
+
authorization = await recordEvidence(entry);
|
|
265
|
+
if (!validLogRecord(authorization, !allowEphemeralState, entry))
|
|
266
|
+
throw new Error('malformed evidence record');
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
try {
|
|
270
|
+
if (releaseConsumption)
|
|
271
|
+
await releaseConsumption(key);
|
|
272
|
+
}
|
|
273
|
+
catch { /* frozen is safe */ }
|
|
274
|
+
return { ok: false, allow: false, reason: 'evidence_log_failed', result, decision: null };
|
|
275
|
+
}
|
|
276
|
+
let effectStarted = false;
|
|
277
|
+
let committed = false;
|
|
278
|
+
try {
|
|
279
|
+
effectStarted = true;
|
|
280
|
+
const value = await effect({ action: actionSnapshot, result, authorization });
|
|
281
|
+
if ((await commitConsumption(key)) !== true)
|
|
282
|
+
throw new Error('consumption_store_commit_refused');
|
|
283
|
+
committed = true;
|
|
284
|
+
const executionEntry = {
|
|
285
|
+
type: 'aec.execution.outcome',
|
|
286
|
+
at: instant(now),
|
|
287
|
+
outcome: 'executed',
|
|
288
|
+
authorizes_decision: authorization.hash,
|
|
289
|
+
action_digest: result.action_digest,
|
|
290
|
+
consumption_key: key,
|
|
291
|
+
};
|
|
292
|
+
const execution = await recordEvidence(executionEntry);
|
|
293
|
+
if (!validLogRecord(execution, !allowEphemeralState, executionEntry))
|
|
294
|
+
throw new Error('malformed evidence record');
|
|
295
|
+
return { ok: true, allow: true, value, result, authorization, execution };
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
if (effectStarted && !committed) {
|
|
299
|
+
try {
|
|
300
|
+
committed = (await commitConsumption(key)) === true;
|
|
301
|
+
}
|
|
302
|
+
catch { /* reservation remains fail-closed */ }
|
|
303
|
+
}
|
|
304
|
+
try {
|
|
305
|
+
const indeterminateEntry = {
|
|
306
|
+
type: 'aec.execution.outcome',
|
|
307
|
+
at: instant(now),
|
|
308
|
+
outcome: 'indeterminate',
|
|
309
|
+
authorizes_decision: authorization.hash,
|
|
310
|
+
action_digest: result.action_digest,
|
|
311
|
+
consumption_key: key,
|
|
312
|
+
};
|
|
313
|
+
const indeterminate = await recordEvidence(indeterminateEntry);
|
|
314
|
+
if (!validLogRecord(indeterminate, !allowEphemeralState, indeterminateEntry)) {
|
|
315
|
+
throw new Error('malformed evidence record');
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
catch { /* the original failure remains primary; replay is still blocked */ }
|
|
319
|
+
throw error;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return { run, evidence, store: consumption };
|
|
323
|
+
}
|
|
324
|
+
export const __aecExecutionSecurityInternals = Object.freeze({
|
|
325
|
+
deepFreeze,
|
|
326
|
+
validLogRecord,
|
|
327
|
+
validComponent,
|
|
328
|
+
humanFloorSatisfied,
|
|
329
|
+
evidenceSatisfied,
|
|
330
|
+
consumptionKey,
|
|
331
|
+
instant,
|
|
332
|
+
});
|
|
333
|
+
export default { createAECExecutionGate };
|
|
334
|
+
//# sourceMappingURL=aec-execution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aec-execution.js","sourceRoot":"","sources":["../src/aec-execution.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC;;;;;;;GAOG;AACH,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAqBlF,MAAM,YAAY,GAA4B,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,mBAAmB,CAAC,CAAC,CAAC;AAClG,MAAM,OAAO,GAAG,gBAAgB,CAAC;AACjC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAC5C,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC;AACtE,MAAM,GAAG,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAE7E,SAAS,UAAU,CAAC,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|
|
4
|
+
/** Relying-party break-glass trust policy: pinned roster + minimum threshold. */
|
|
5
|
+
type BreakGlassPolicy = {
|
|
6
|
+
minimum_threshold: number;
|
|
7
|
+
roster: Array<{
|
|
8
|
+
kid: string;
|
|
9
|
+
principal_id: string;
|
|
10
|
+
key?: string;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
/** Optional pinned keys when roster entries omit their own `key`. */
|
|
14
|
+
type IssuerKeys = Record<string, string> | Array<{
|
|
15
|
+
kid: string;
|
|
16
|
+
key: string;
|
|
17
|
+
}>;
|
|
18
|
+
/** Injected clock: fixed ms/ISO value, or a () => ms function (default Date.now). */
|
|
19
|
+
type BreakGlassClock = number | string | (() => number);
|
|
20
|
+
/**
|
|
21
|
+
* Mint a break-glass authorization: every signer signs the canonical JSON of
|
|
22
|
+
* the SAME grant payload. Throws on invalid fields — a malformed grant must
|
|
23
|
+
* never be issued, only refused. Signer kids must already be distinct at mint
|
|
24
|
+
* time: one key can never pre-fill two threshold slots. Relying-party principal
|
|
25
|
+
* uniqueness is enforced at verification through the pinned policy roster.
|
|
26
|
+
*
|
|
27
|
+
* grant_id is CONTENT-DERIVED (sha-256 of the canonical grant fields), so the
|
|
28
|
+
* id is deterministic and re-minting the identical grant yields the identical
|
|
29
|
+
* single-use consumption key — the same emergency authorization cannot be
|
|
30
|
+
* "refreshed" into extra uses by minting it twice.
|
|
31
|
+
*
|
|
32
|
+
* @param {Array<{ privateKey: crypto.KeyObject, kid: string }>} signers
|
|
33
|
+
* @param {object} fields { scope: { action_types: string[] }, window: { not_before, expires_at }, reason, incident_ref, threshold }
|
|
34
|
+
* @returns {{ '@version': string, payload: object, signatures: Array<{ kid: string, algorithm: 'Ed25519', value: string }> }}
|
|
35
|
+
*/
|
|
36
|
+
export declare function mintBreakGlassAuthorization(signers: any, { scope, window: win, reason, incident_ref, threshold, }?: {
|
|
37
|
+
scope?: {
|
|
38
|
+
action_types: string[];
|
|
39
|
+
};
|
|
40
|
+
window?: {
|
|
41
|
+
not_before: number | string;
|
|
42
|
+
expires_at: number | string;
|
|
43
|
+
};
|
|
44
|
+
reason?: string;
|
|
45
|
+
incident_ref?: string;
|
|
46
|
+
threshold?: number;
|
|
47
|
+
}): {
|
|
48
|
+
'@version': string;
|
|
49
|
+
payload: {
|
|
50
|
+
scope: {
|
|
51
|
+
action_types: string[];
|
|
52
|
+
};
|
|
53
|
+
window: {
|
|
54
|
+
not_before: string | number;
|
|
55
|
+
expires_at: string | number;
|
|
56
|
+
};
|
|
57
|
+
reason: string | undefined;
|
|
58
|
+
incident_ref: string | undefined;
|
|
59
|
+
threshold: number;
|
|
60
|
+
grant_id: string;
|
|
61
|
+
};
|
|
62
|
+
signatures: {
|
|
63
|
+
kid: any;
|
|
64
|
+
algorithm: string;
|
|
65
|
+
value: string;
|
|
66
|
+
}[];
|
|
67
|
+
};
|
|
68
|
+
export declare function verifyBreakGlass(grantJson: any, options?: {}): {
|
|
69
|
+
valid: boolean;
|
|
70
|
+
reason: any;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* SINGLE-USE consumption via the consumption-store contract (store.js):
|
|
74
|
+
* `consume(key)` returns true the FIRST time, false on every replay, and marks
|
|
75
|
+
* the key seen BEFORE the caller acts — consumption is committed before use.
|
|
76
|
+
* If the process crashes after consume() and before the override, the grant is
|
|
77
|
+
* burned, not replayable: the fail direction is unusable, never reusable.
|
|
78
|
+
*
|
|
79
|
+
* Accepts the grant document ({ payload: { grant_id } }) or a verified result
|
|
80
|
+
* ({ grant_id }). NEVER throws — a missing store, missing grant_id, or a store
|
|
81
|
+
* error all refuse with a machine-readable reason. This is a low-level primitive;
|
|
82
|
+
* only runBreakGlass also enforces store capabilities, evidence, and execution order.
|
|
83
|
+
*
|
|
84
|
+
* @param {object} grant break-glass grant document or verifyBreakGlass result
|
|
85
|
+
* @param {{ consume(key: string): Promise<boolean> }} store consumption store (store.js contract)
|
|
86
|
+
* @returns {Promise<{ consumed: boolean, reason: string, key?: string }>}
|
|
87
|
+
*/
|
|
88
|
+
export declare function consumeBreakGlass(grant: any, store: any): Promise<{
|
|
89
|
+
consumed: boolean;
|
|
90
|
+
reason: string;
|
|
91
|
+
key?: undefined;
|
|
92
|
+
} | {
|
|
93
|
+
consumed: boolean;
|
|
94
|
+
reason: string;
|
|
95
|
+
key: string;
|
|
96
|
+
}>;
|
|
97
|
+
export declare function buildBreakGlassEvidence(grant: any, decision: any, options?: {}): {
|
|
98
|
+
kind: string;
|
|
99
|
+
'@version': string;
|
|
100
|
+
at: string;
|
|
101
|
+
grant_id: any;
|
|
102
|
+
incident_ref: any;
|
|
103
|
+
grant_reason: any;
|
|
104
|
+
scope: any;
|
|
105
|
+
threshold: any;
|
|
106
|
+
policy_minimum_threshold: any;
|
|
107
|
+
required_threshold: any;
|
|
108
|
+
signer_kids: any;
|
|
109
|
+
signer_principal_ids: any;
|
|
110
|
+
signer_spki_fingerprints: any;
|
|
111
|
+
grant_hash: string | null;
|
|
112
|
+
decision: {
|
|
113
|
+
allow: boolean;
|
|
114
|
+
reason: any;
|
|
115
|
+
action_type: any;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* The sole high-level break-glass execution path. It snapshots the presented
|
|
120
|
+
* artifact, verifies it against relying-party policy, atomically consumes the
|
|
121
|
+
* grant in a capability-marked permanent store, validates a strict evidence
|
|
122
|
+
* acknowledgement, and only then invokes `effect`.
|
|
123
|
+
*
|
|
124
|
+
* @param {object} [args]
|
|
125
|
+
* @param {object|string} [args.grant] the presented break-glass artifact
|
|
126
|
+
* @param {{minimum_threshold:number,roster:Array<{kid:string,principal_id:string,key?:string}>}} [args.policy]
|
|
127
|
+
* @param {object|Array<{kid:string,key:string}>} [args.issuerKeys]
|
|
128
|
+
* @param {string} [args.actionType]
|
|
129
|
+
* @param {{ consume(key: string): Promise<boolean> }} [args.store]
|
|
130
|
+
* @param {{ strict?: boolean, atomicAppend?: boolean, record?: Function }} [args.evidence]
|
|
131
|
+
* @param {number|string|function} [args.now=Date.now]
|
|
132
|
+
* @param {Function} [effect] required at runtime; a missing effect throws
|
|
133
|
+
*/
|
|
134
|
+
export declare function runBreakGlass({ grant, policy, issuerKeys, actionType, store, evidence, now, }: {
|
|
135
|
+
grant?: Obj | string;
|
|
136
|
+
policy?: BreakGlassPolicy;
|
|
137
|
+
issuerKeys?: IssuerKeys;
|
|
138
|
+
actionType?: string;
|
|
139
|
+
store?: {
|
|
140
|
+
consume(key: string): Promise<boolean>;
|
|
141
|
+
};
|
|
142
|
+
evidence?: {
|
|
143
|
+
strict?: boolean;
|
|
144
|
+
atomicAppend?: boolean;
|
|
145
|
+
record?: (entry: Obj) => any;
|
|
146
|
+
};
|
|
147
|
+
now?: BreakGlassClock;
|
|
148
|
+
} | undefined, effect: any): Promise<{
|
|
149
|
+
ok: boolean;
|
|
150
|
+
reason: any;
|
|
151
|
+
verification: {
|
|
152
|
+
valid: boolean;
|
|
153
|
+
reason: any;
|
|
154
|
+
};
|
|
155
|
+
consumption: null;
|
|
156
|
+
evidence: null;
|
|
157
|
+
result?: undefined;
|
|
158
|
+
} | {
|
|
159
|
+
ok: boolean;
|
|
160
|
+
reason: string;
|
|
161
|
+
verification: {
|
|
162
|
+
valid: boolean;
|
|
163
|
+
reason: any;
|
|
164
|
+
};
|
|
165
|
+
consumption: {
|
|
166
|
+
consumed: boolean;
|
|
167
|
+
reason: string;
|
|
168
|
+
key?: undefined;
|
|
169
|
+
} | {
|
|
170
|
+
consumed: boolean;
|
|
171
|
+
reason: string;
|
|
172
|
+
key: string;
|
|
173
|
+
};
|
|
174
|
+
evidence: null;
|
|
175
|
+
result?: undefined;
|
|
176
|
+
} | {
|
|
177
|
+
ok: boolean;
|
|
178
|
+
reason: string;
|
|
179
|
+
result: any;
|
|
180
|
+
verification: {
|
|
181
|
+
valid: boolean;
|
|
182
|
+
reason: any;
|
|
183
|
+
};
|
|
184
|
+
consumption: {
|
|
185
|
+
consumed: boolean;
|
|
186
|
+
reason: string;
|
|
187
|
+
key?: undefined;
|
|
188
|
+
} | {
|
|
189
|
+
consumed: boolean;
|
|
190
|
+
reason: string;
|
|
191
|
+
key: string;
|
|
192
|
+
};
|
|
193
|
+
evidence: any;
|
|
194
|
+
}>;
|
|
195
|
+
declare const _default: {
|
|
196
|
+
mintBreakGlassAuthorization: typeof mintBreakGlassAuthorization;
|
|
197
|
+
verifyBreakGlass: typeof verifyBreakGlass;
|
|
198
|
+
consumeBreakGlass: typeof consumeBreakGlass;
|
|
199
|
+
buildBreakGlassEvidence: typeof buildBreakGlassEvidence;
|
|
200
|
+
runBreakGlass: typeof runBreakGlass;
|
|
201
|
+
BREAKGLASS_VERSION: string;
|
|
202
|
+
BREAKGLASS_EVIDENCE_KIND: string;
|
|
203
|
+
};
|
|
204
|
+
export default _default;
|
|
205
|
+
//# sourceMappingURL=breakglass.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"breakglass.d.ts","sourceRoot":"","sources":["../src/breakglass.ts"],"names":[],"mappings":"AAgDA,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAC1D,eAAO,MAAM,wBAAwB,eAAe,CAAC;AAErD,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE/B,iFAAiF;AACjF,KAAK,gBAAgB,GAAG;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACpE,CAAC;AAEF,qEAAqE;AACrE,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE/E,qFAAqF;AACrF,KAAK,eAAe,GAAG,M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