@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
package/network-witness.js
CHANGED
|
@@ -1,500 +1,4 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
* A network witness is deliberately NOT an enforcement point. It can prove a
|
|
6
|
-
* pinned sensor observed bytes associated with an action digest at a named
|
|
7
|
-
* capture point. It cannot prove the action was authorized, blocked, executed,
|
|
8
|
-
* or physically completed. Keeping that boundary in the artifact prevents a
|
|
9
|
-
* passive TAP from being marketed as a firewall.
|
|
10
|
-
*/
|
|
11
|
-
import crypto from 'node:crypto';
|
|
12
|
-
import { canonicalize } from './execution-binding.js';
|
|
13
|
-
import { strictJsonGate } from './strict-json.js';
|
|
14
|
-
|
|
15
|
-
export const NETWORK_WITNESS_VERSION = 'EP-GATE-NETWORK-WITNESS-v1';
|
|
16
|
-
export const NETWORK_WITNESS_ACCEPTANCE_VERSION = 'EP-GATE-NETWORK-WITNESS-ACCEPTANCE-v1';
|
|
17
|
-
export const NETWORK_WITNESS_DOMAIN = `${NETWORK_WITNESS_VERSION}\0`;
|
|
18
|
-
export const NETWORK_WITNESS_EVENTS = Object.freeze([
|
|
19
|
-
'request_observed',
|
|
20
|
-
'response_observed',
|
|
21
|
-
'effect_observed',
|
|
22
|
-
]);
|
|
23
|
-
|
|
24
|
-
const DIGEST_RE = /^sha256:[0-9a-f]{64}$/;
|
|
25
|
-
const DIRECTIONS = new Set(['ingress', 'egress', 'internal']);
|
|
26
|
-
const RFC3339 = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?Z$/;
|
|
27
|
-
|
|
28
|
-
function strictInstantMs(value) {
|
|
29
|
-
if (typeof value !== 'string') return NaN;
|
|
30
|
-
const match = value.match(RFC3339);
|
|
31
|
-
if (!match) return NaN;
|
|
32
|
-
const [, year, month, day, hour, minute, second] = match;
|
|
33
|
-
const base = new Date(0);
|
|
34
|
-
base.setUTCFullYear(Number(year), Number(month) - 1, Number(day));
|
|
35
|
-
base.setUTCHours(Number(hour), Number(minute), Number(second), 0);
|
|
36
|
-
if (base.toISOString().slice(0, 19) !== `${year}-${month}-${day}T${hour}:${minute}:${second}`) return NaN;
|
|
37
|
-
const parsed = Date.parse(value);
|
|
38
|
-
return Number.isFinite(parsed) ? parsed : NaN;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function isPlainObject(value) {
|
|
42
|
-
if (value === null || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
43
|
-
const prototype = Object.getPrototypeOf(value);
|
|
44
|
-
return prototype === Object.prototype || prototype === null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function exactKeys(value, allowed) {
|
|
48
|
-
return isPlainObject(value) && Object.keys(value).every((key) => allowed.has(key));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function nonEmptyString(value, max = 256) {
|
|
52
|
-
return typeof value === 'string' && value.length > 0 && value.length <= max && !/[\u0000-\u001f\u007f]/.test(value);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function digest(value) {
|
|
56
|
-
return typeof value === 'string' && DIGEST_RE.test(value);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function sha256(bytes) {
|
|
60
|
-
return crypto.createHash('sha256').update(bytes).digest('hex');
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function decodeBase64Url(value, maxBytes) {
|
|
64
|
-
if (typeof value !== 'string' || value.length === 0 || !/^[A-Za-z0-9_-]+$/.test(value)) return null;
|
|
65
|
-
try {
|
|
66
|
-
const bytes = Buffer.from(value, 'base64url');
|
|
67
|
-
if (bytes.length === 0 || bytes.length > maxBytes || bytes.toString('base64url') !== value) return null;
|
|
68
|
-
return bytes;
|
|
69
|
-
} catch { return null; }
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function keyIdFor(key) {
|
|
73
|
-
const der = crypto.createPublicKey(key).export({ type: 'spki', format: 'der' });
|
|
74
|
-
return `ep:witness-key:sha256:${sha256(der).slice(0, 16)}`;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function signingBytes(body) {
|
|
78
|
-
return Buffer.from(NETWORK_WITNESS_DOMAIN + canonicalize(body), 'utf8');
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function unsigned(statement) {
|
|
82
|
-
if (!isPlainObject(statement)) throw new TypeError('network witness statement must be an object');
|
|
83
|
-
const { signature: _signature, ...body } = statement;
|
|
84
|
-
return body;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function networkWitnessDigest(statement) {
|
|
88
|
-
return `sha256:${sha256(signingBytes(unsigned(statement)))}`;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/** Duplicate-key-safe parser for an untrusted serialized witness artifact. */
|
|
92
|
-
export function parseNetworkWitnessStatement(raw, { maxBytes = 64 * 1024 } = {}) {
|
|
93
|
-
if (typeof raw !== 'string' || !Number.isSafeInteger(maxBytes) || maxBytes < 1
|
|
94
|
-
|| Buffer.byteLength(raw, 'utf8') > maxBytes) return null;
|
|
95
|
-
const gated = strictJsonGate(raw);
|
|
96
|
-
if (!gated.ok) return null;
|
|
97
|
-
try {
|
|
98
|
-
const parsed = JSON.parse(raw);
|
|
99
|
-
return isPlainObject(parsed) ? parsed : null;
|
|
100
|
-
} catch { return null; }
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function validateBody(body) {
|
|
104
|
-
if (!exactKeys(body, new Set(['@version', 'witness', 'observation', 'deployment', 'privacy', 'limitations']))) {
|
|
105
|
-
return 'statement_shape_invalid';
|
|
106
|
-
}
|
|
107
|
-
if (body['@version'] !== NETWORK_WITNESS_VERSION) return 'version_invalid';
|
|
108
|
-
if (!exactKeys(body.witness, new Set(['id', 'key_id', 'capture_point_id']))) return 'witness_shape_invalid';
|
|
109
|
-
if (!nonEmptyString(body.witness.id) || !nonEmptyString(body.witness.key_id)
|
|
110
|
-
|| !nonEmptyString(body.witness.capture_point_id)) return 'witness_identity_invalid';
|
|
111
|
-
if (!exactKeys(body.observation, new Set([
|
|
112
|
-
'sequence', 'observed_at', 'event', 'direction', 'action_digest', 'flow_digest', 'byte_count',
|
|
113
|
-
]))) return 'observation_shape_invalid';
|
|
114
|
-
if (!Number.isSafeInteger(body.observation.sequence) || body.observation.sequence < 0) return 'sequence_invalid';
|
|
115
|
-
if (!Number.isFinite(strictInstantMs(body.observation.observed_at))) return 'observed_at_invalid';
|
|
116
|
-
if (!NETWORK_WITNESS_EVENTS.includes(body.observation.event)) return 'event_invalid';
|
|
117
|
-
if (!DIRECTIONS.has(body.observation.direction)) return 'direction_invalid';
|
|
118
|
-
if (!digest(body.observation.action_digest)) return 'action_digest_invalid';
|
|
119
|
-
if (body.observation.flow_digest !== undefined && !digest(body.observation.flow_digest)) return 'flow_digest_invalid';
|
|
120
|
-
if (body.observation.byte_count !== undefined
|
|
121
|
-
&& (!Number.isSafeInteger(body.observation.byte_count) || body.observation.byte_count < 0)) return 'byte_count_invalid';
|
|
122
|
-
if (!exactKeys(body.deployment, new Set(['config_digest', 'attestation_ref']))) return 'deployment_shape_invalid';
|
|
123
|
-
if (!digest(body.deployment.config_digest)) return 'config_digest_invalid';
|
|
124
|
-
if (body.deployment.attestation_ref !== undefined && !digest(body.deployment.attestation_ref)) {
|
|
125
|
-
return 'attestation_ref_invalid';
|
|
126
|
-
}
|
|
127
|
-
if (!exactKeys(body.privacy, new Set(['payload_captured']))) return 'privacy_shape_invalid';
|
|
128
|
-
if (body.privacy.payload_captured !== false) return 'payload_capture_forbidden';
|
|
129
|
-
if (!Array.isArray(body.limitations) || body.limitations.length < 2 || body.limitations.length > 8
|
|
130
|
-
|| body.limitations.some((item) => !nonEmptyString(item, 512))) return 'limitations_invalid';
|
|
131
|
-
try { canonicalize(body); } catch { return 'canonical_body_invalid'; }
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/** Create a signed observation. The public key is intentionally not embedded. */
|
|
136
|
-
export function signNetworkWitnessStatement(input, privateKey) {
|
|
137
|
-
if (!privateKey) throw new TypeError('privateKey is required');
|
|
138
|
-
const keyId = input?.key_id ?? keyIdFor(privateKey);
|
|
139
|
-
const body = {
|
|
140
|
-
'@version': NETWORK_WITNESS_VERSION,
|
|
141
|
-
witness: {
|
|
142
|
-
id: input?.witness_id,
|
|
143
|
-
key_id: keyId,
|
|
144
|
-
capture_point_id: input?.capture_point_id,
|
|
145
|
-
},
|
|
146
|
-
observation: {
|
|
147
|
-
sequence: input?.sequence,
|
|
148
|
-
observed_at: input?.observed_at,
|
|
149
|
-
event: input?.event,
|
|
150
|
-
direction: input?.direction,
|
|
151
|
-
action_digest: input?.action_digest,
|
|
152
|
-
...(input?.flow_digest !== undefined ? { flow_digest: input.flow_digest } : {}),
|
|
153
|
-
...(input?.byte_count !== undefined ? { byte_count: input.byte_count } : {}),
|
|
154
|
-
},
|
|
155
|
-
deployment: {
|
|
156
|
-
config_digest: input?.config_digest,
|
|
157
|
-
...(input?.attestation_ref !== undefined ? { attestation_ref: input.attestation_ref } : {}),
|
|
158
|
-
},
|
|
159
|
-
privacy: { payload_captured: false },
|
|
160
|
-
limitations: [
|
|
161
|
-
'This artifact proves only that a pinned witness key signed an observation at a named capture point.',
|
|
162
|
-
'A passive network witness does not authorize, block, execute, or prove the physical outcome of an action.',
|
|
163
|
-
'Coverage and completeness depend on the relying party pinning the capture topology and expected witness set.',
|
|
164
|
-
'Rollback detection begins at a relying-party-pinned stream checkpoint; first-seen sequence numbers are not self-authenticating history.',
|
|
165
|
-
],
|
|
166
|
-
};
|
|
167
|
-
const invalid = validateBody(body);
|
|
168
|
-
if (invalid) throw new TypeError(invalid);
|
|
169
|
-
const statementDigest = networkWitnessDigest(body);
|
|
170
|
-
return Object.freeze({
|
|
171
|
-
...body,
|
|
172
|
-
signature: Object.freeze({
|
|
173
|
-
algorithm: 'Ed25519',
|
|
174
|
-
key_id: keyId,
|
|
175
|
-
statement_digest: statementDigest,
|
|
176
|
-
signature_b64u: crypto.sign(null, signingBytes(body), privateKey).toString('base64url'),
|
|
177
|
-
}),
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function findPin(pins, witness) {
|
|
182
|
-
if (!Array.isArray(pins)) return null;
|
|
183
|
-
return pins.find((pin) => isPlainObject(pin)
|
|
184
|
-
&& pin.witness_id === witness.id
|
|
185
|
-
&& pin.key_id === witness.key_id
|
|
186
|
-
&& Array.isArray(pin.capture_point_ids)
|
|
187
|
-
&& pin.capture_point_ids.includes(witness.capture_point_id)) ?? null;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Offline signature and context verification. This function never throws on a
|
|
192
|
-
* presenter-controlled statement. Sequence consumption is a separate online
|
|
193
|
-
* operation performed by acceptNetworkWitnessStatement.
|
|
194
|
-
*/
|
|
195
|
-
export function verifyNetworkWitnessStatement(statement, options = {}) {
|
|
196
|
-
const fail = (reason, checks = {}) => ({
|
|
197
|
-
verified: false,
|
|
198
|
-
accepted: false,
|
|
199
|
-
reason,
|
|
200
|
-
checks: {
|
|
201
|
-
shape: false,
|
|
202
|
-
pin: false,
|
|
203
|
-
signature: false,
|
|
204
|
-
action_binding: false,
|
|
205
|
-
freshness: false,
|
|
206
|
-
config_binding: false,
|
|
207
|
-
...checks,
|
|
208
|
-
},
|
|
209
|
-
});
|
|
210
|
-
try {
|
|
211
|
-
if (!isPlainObject(statement)
|
|
212
|
-
|| !exactKeys(statement, new Set(['@version', 'witness', 'observation', 'deployment', 'privacy', 'limitations', 'signature']))) {
|
|
213
|
-
return fail('statement_shape_invalid');
|
|
214
|
-
}
|
|
215
|
-
const body = unsigned(statement);
|
|
216
|
-
const invalid = validateBody(body);
|
|
217
|
-
if (invalid) return fail(invalid);
|
|
218
|
-
if (!exactKeys(statement.signature, new Set(['algorithm', 'key_id', 'statement_digest', 'signature_b64u']))) {
|
|
219
|
-
return fail('signature_shape_invalid', { shape: true });
|
|
220
|
-
}
|
|
221
|
-
if (statement.signature.algorithm !== 'Ed25519'
|
|
222
|
-
|| statement.signature.key_id !== body.witness.key_id
|
|
223
|
-
|| !digest(statement.signature.statement_digest)
|
|
224
|
-
|| !nonEmptyString(statement.signature.signature_b64u, 512)) {
|
|
225
|
-
return fail('signature_envelope_invalid', { shape: true });
|
|
226
|
-
}
|
|
227
|
-
const pin = findPin(options.pinnedWitnesses, body.witness);
|
|
228
|
-
if (!pin || !nonEmptyString(pin.public_key, 4096)) return fail('witness_key_unpinned', { shape: true });
|
|
229
|
-
if (!Array.isArray(pin.config_digests) || pin.config_digests.length === 0
|
|
230
|
-
|| !pin.config_digests.includes(body.deployment.config_digest)) {
|
|
231
|
-
return fail('witness_config_unpinned', { shape: true, pin: true });
|
|
232
|
-
}
|
|
233
|
-
if (options.expectedActionDigest !== undefined
|
|
234
|
-
&& body.observation.action_digest !== options.expectedActionDigest) {
|
|
235
|
-
return fail('action_digest_mismatch', { shape: true, pin: true, config_binding: true });
|
|
236
|
-
}
|
|
237
|
-
if (options.expectedEvent !== undefined && body.observation.event !== options.expectedEvent) {
|
|
238
|
-
return fail('event_mismatch', { shape: true, pin: true, config_binding: true });
|
|
239
|
-
}
|
|
240
|
-
const now = options.now === undefined ? Date.now() : Number(options.now);
|
|
241
|
-
const maxAgeSec = options.maxAgeSec === undefined ? 300 : options.maxAgeSec;
|
|
242
|
-
const maxFutureSkewSec = options.maxFutureSkewSec === undefined ? 30 : options.maxFutureSkewSec;
|
|
243
|
-
if (!Number.isFinite(now) || !Number.isSafeInteger(maxAgeSec) || maxAgeSec < 0
|
|
244
|
-
|| !Number.isSafeInteger(maxFutureSkewSec) || maxFutureSkewSec < 0) {
|
|
245
|
-
return fail('verification_profile_invalid', { shape: true, pin: true, config_binding: true });
|
|
246
|
-
}
|
|
247
|
-
const observedMs = strictInstantMs(body.observation.observed_at);
|
|
248
|
-
if (observedMs > now + (maxFutureSkewSec * 1000)) {
|
|
249
|
-
return fail('observation_from_future', { shape: true, pin: true, action_binding: true, config_binding: true });
|
|
250
|
-
}
|
|
251
|
-
if (now - observedMs > maxAgeSec * 1000) {
|
|
252
|
-
return fail('observation_stale', { shape: true, pin: true, action_binding: true, config_binding: true });
|
|
253
|
-
}
|
|
254
|
-
const computedDigest = networkWitnessDigest(body);
|
|
255
|
-
if (computedDigest !== statement.signature.statement_digest) {
|
|
256
|
-
return fail('statement_digest_mismatch', {
|
|
257
|
-
shape: true, pin: true, action_binding: true, freshness: true, config_binding: true,
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
let publicKey;
|
|
261
|
-
try {
|
|
262
|
-
const keyBytes = decodeBase64Url(pin.public_key, 4096);
|
|
263
|
-
if (!keyBytes) throw new TypeError('invalid base64url key');
|
|
264
|
-
publicKey = crypto.createPublicKey({
|
|
265
|
-
key: keyBytes,
|
|
266
|
-
type: 'spki',
|
|
267
|
-
format: 'der',
|
|
268
|
-
});
|
|
269
|
-
if (publicKey.asymmetricKeyType !== 'ed25519') throw new TypeError('witness key must be Ed25519');
|
|
270
|
-
} catch {
|
|
271
|
-
return fail('pinned_key_invalid', {
|
|
272
|
-
shape: true, pin: true, action_binding: true, freshness: true, config_binding: true,
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
const signature = decodeBase64Url(statement.signature.signature_b64u, 64);
|
|
276
|
-
if (!signature || signature.length !== 64) {
|
|
277
|
-
return fail('signature_invalid', {
|
|
278
|
-
shape: true, pin: true, action_binding: true, freshness: true, config_binding: true,
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
if (!crypto.verify(null, signingBytes(body), publicKey, signature)) {
|
|
282
|
-
return fail('signature_invalid', {
|
|
283
|
-
shape: true, pin: true, action_binding: true, freshness: true, config_binding: true,
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
return {
|
|
287
|
-
verified: true,
|
|
288
|
-
accepted: true,
|
|
289
|
-
reason: null,
|
|
290
|
-
statement_digest: computedDigest,
|
|
291
|
-
stream_id: `${body.witness.id}\0${body.witness.capture_point_id}`,
|
|
292
|
-
sequence: body.observation.sequence,
|
|
293
|
-
action_digest: body.observation.action_digest,
|
|
294
|
-
event: body.observation.event,
|
|
295
|
-
observed_at: body.observation.observed_at,
|
|
296
|
-
witness_id: body.witness.id,
|
|
297
|
-
capture_point_id: body.witness.capture_point_id,
|
|
298
|
-
checks: {
|
|
299
|
-
shape: true,
|
|
300
|
-
pin: true,
|
|
301
|
-
signature: true,
|
|
302
|
-
action_binding: true,
|
|
303
|
-
freshness: true,
|
|
304
|
-
config_binding: true,
|
|
305
|
-
},
|
|
306
|
-
limitation: 'Observation is not authorization, enforcement, execution, or physical truth.',
|
|
307
|
-
};
|
|
308
|
-
} catch {
|
|
309
|
-
return fail('hostile_input_refused');
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
export function createMemoryWitnessSequenceStore() {
|
|
314
|
-
const streams = new Map();
|
|
315
|
-
return {
|
|
316
|
-
durable: false,
|
|
317
|
-
async advance(streamId, sequence, statementDigest) {
|
|
318
|
-
const previous = streams.get(streamId);
|
|
319
|
-
if (previous) {
|
|
320
|
-
if (previous.equivocated === true) {
|
|
321
|
-
return { accepted: false, reason: 'sequence_equivocation' };
|
|
322
|
-
}
|
|
323
|
-
if (sequence < previous.sequence) return { accepted: false, reason: 'sequence_rollback' };
|
|
324
|
-
if (sequence === previous.sequence) {
|
|
325
|
-
if (previous.digest === statementDigest) {
|
|
326
|
-
return { accepted: false, reason: 'statement_replay' };
|
|
327
|
-
}
|
|
328
|
-
streams.set(streamId, { ...previous, equivocated: true });
|
|
329
|
-
return { accepted: false, reason: 'sequence_equivocation' };
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
streams.set(streamId, { sequence, digest: statementDigest, equivocated: false });
|
|
333
|
-
return { accepted: true, reason: null };
|
|
334
|
-
},
|
|
335
|
-
snapshot() { return [...streams.entries()].map(([stream_id, value]) => ({ stream_id, ...value })); },
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
function acceptanceResult(verified, {
|
|
340
|
-
accepted,
|
|
341
|
-
consumed,
|
|
342
|
-
reason,
|
|
343
|
-
sequenceStoreDurable,
|
|
344
|
-
}) {
|
|
345
|
-
return Object.freeze({
|
|
346
|
-
...verified,
|
|
347
|
-
acceptance_version: NETWORK_WITNESS_ACCEPTANCE_VERSION,
|
|
348
|
-
accepted,
|
|
349
|
-
consumed,
|
|
350
|
-
reason,
|
|
351
|
-
sequence_store_durable: sequenceStoreDurable === true,
|
|
352
|
-
...(isPlainObject(verified.checks) ? { checks: Object.freeze({ ...verified.checks }) } : {}),
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* Validate an ingestion result supplied through a relying-party-trusted option.
|
|
358
|
-
* This does not authenticate presenter-controlled JSON; callers must never move
|
|
359
|
-
* an untrusted bundle field into this trust channel.
|
|
360
|
-
*/
|
|
361
|
-
export function validateTrustedNetworkWitnessAcceptance(result, options = {}) {
|
|
362
|
-
const fail = (reason, fields = {}, statementVerified = false) => ({
|
|
363
|
-
verified: statementVerified === true,
|
|
364
|
-
accepted: false,
|
|
365
|
-
consumed: false,
|
|
366
|
-
reason,
|
|
367
|
-
...fields,
|
|
368
|
-
});
|
|
369
|
-
try {
|
|
370
|
-
if (!isPlainObject(result)
|
|
371
|
-
|| result.acceptance_version !== NETWORK_WITNESS_ACCEPTANCE_VERSION) {
|
|
372
|
-
return fail('trusted_witness_acceptance_invalid');
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
const common = {
|
|
376
|
-
acceptance_version: NETWORK_WITNESS_ACCEPTANCE_VERSION,
|
|
377
|
-
statement_digest: result.statement_digest,
|
|
378
|
-
stream_id: result.stream_id,
|
|
379
|
-
sequence: result.sequence,
|
|
380
|
-
action_digest: result.action_digest,
|
|
381
|
-
event: result.event,
|
|
382
|
-
observed_at: result.observed_at,
|
|
383
|
-
witness_id: result.witness_id,
|
|
384
|
-
capture_point_id: result.capture_point_id,
|
|
385
|
-
sequence_store_durable: result.sequence_store_durable === true,
|
|
386
|
-
};
|
|
387
|
-
const statementVerified = result.verified === true
|
|
388
|
-
&& digest(common.statement_digest) && digest(common.action_digest)
|
|
389
|
-
&& Number.isSafeInteger(common.sequence) && common.sequence >= 0
|
|
390
|
-
&& nonEmptyString(common.witness_id) && nonEmptyString(common.capture_point_id)
|
|
391
|
-
&& common.stream_id === `${common.witness_id}\0${common.capture_point_id}`
|
|
392
|
-
&& NETWORK_WITNESS_EVENTS.includes(common.event)
|
|
393
|
-
&& Number.isFinite(strictInstantMs(common.observed_at));
|
|
394
|
-
if (result.accepted !== true || result.consumed !== true) {
|
|
395
|
-
return fail(
|
|
396
|
-
nonEmptyString(result.reason) ? result.reason : 'trusted_witness_acceptance_rejected',
|
|
397
|
-
common,
|
|
398
|
-
statementVerified,
|
|
399
|
-
);
|
|
400
|
-
}
|
|
401
|
-
if (!statementVerified || result.reason !== null) {
|
|
402
|
-
return fail('trusted_witness_acceptance_invalid');
|
|
403
|
-
}
|
|
404
|
-
if (!common.sequence_store_durable && options.allowEphemeralStore !== true) {
|
|
405
|
-
return fail('durable_sequence_store_required', common);
|
|
406
|
-
}
|
|
407
|
-
if (options.expectedStatementDigest !== undefined) {
|
|
408
|
-
if (!digest(options.expectedStatementDigest)) return fail('verification_profile_invalid', common);
|
|
409
|
-
if (common.statement_digest !== options.expectedStatementDigest) {
|
|
410
|
-
return fail('witness_acceptance_digest_mismatch', common);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
if (options.expectedActionDigest !== undefined
|
|
414
|
-
&& common.action_digest !== options.expectedActionDigest) {
|
|
415
|
-
return fail('action_digest_mismatch', common);
|
|
416
|
-
}
|
|
417
|
-
if (options.expectedEvent !== undefined && common.event !== options.expectedEvent) {
|
|
418
|
-
return fail('event_mismatch', common);
|
|
419
|
-
}
|
|
420
|
-
const now = options.now === undefined ? Date.now() : Number(options.now);
|
|
421
|
-
const maxAgeSec = options.maxAgeSec === undefined ? 300 : options.maxAgeSec;
|
|
422
|
-
const maxFutureSkewSec = options.maxFutureSkewSec === undefined ? 30 : options.maxFutureSkewSec;
|
|
423
|
-
if (!Number.isFinite(now) || !Number.isSafeInteger(maxAgeSec) || maxAgeSec < 0
|
|
424
|
-
|| !Number.isSafeInteger(maxFutureSkewSec) || maxFutureSkewSec < 0) {
|
|
425
|
-
return fail('verification_profile_invalid', common);
|
|
426
|
-
}
|
|
427
|
-
const observedMs = strictInstantMs(common.observed_at);
|
|
428
|
-
if (observedMs > now + (maxFutureSkewSec * 1000)) return fail('observation_from_future', common);
|
|
429
|
-
if (now - observedMs > maxAgeSec * 1000) return fail('observation_stale', common);
|
|
430
|
-
return {
|
|
431
|
-
...common,
|
|
432
|
-
verified: true,
|
|
433
|
-
accepted: true,
|
|
434
|
-
consumed: true,
|
|
435
|
-
reason: null,
|
|
436
|
-
};
|
|
437
|
-
} catch {
|
|
438
|
-
return fail('trusted_witness_acceptance_invalid');
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
/** Verify and atomically advance a witness stream for online ingestion. */
|
|
443
|
-
export async function acceptNetworkWitnessStatement(statement, options = {}) {
|
|
444
|
-
const verified = verifyNetworkWitnessStatement(statement, options);
|
|
445
|
-
if (!verified.accepted) {
|
|
446
|
-
return acceptanceResult(verified, {
|
|
447
|
-
accepted: false,
|
|
448
|
-
consumed: false,
|
|
449
|
-
reason: verified.reason,
|
|
450
|
-
sequenceStoreDurable: false,
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
const store = options.sequenceStore;
|
|
454
|
-
if (!store || typeof store.advance !== 'function'
|
|
455
|
-
|| (store.durable !== true && options.allowEphemeralStore !== true)) {
|
|
456
|
-
return acceptanceResult(verified, {
|
|
457
|
-
accepted: false,
|
|
458
|
-
consumed: false,
|
|
459
|
-
reason: 'durable_sequence_store_required',
|
|
460
|
-
sequenceStoreDurable: false,
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
try {
|
|
464
|
-
const advanced = await store.advance(verified.stream_id, verified.sequence, verified.statement_digest);
|
|
465
|
-
if (!isPlainObject(advanced) || advanced.accepted !== true || advanced.reason !== null) {
|
|
466
|
-
return acceptanceResult(verified, {
|
|
467
|
-
accepted: false,
|
|
468
|
-
consumed: false,
|
|
469
|
-
reason: nonEmptyString(advanced?.reason) ? advanced.reason : 'sequence_store_refused',
|
|
470
|
-
sequenceStoreDurable: store.durable === true,
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
return acceptanceResult(verified, {
|
|
474
|
-
accepted: true,
|
|
475
|
-
consumed: true,
|
|
476
|
-
reason: null,
|
|
477
|
-
sequenceStoreDurable: store.durable === true,
|
|
478
|
-
});
|
|
479
|
-
} catch {
|
|
480
|
-
return acceptanceResult(verified, {
|
|
481
|
-
accepted: false,
|
|
482
|
-
consumed: false,
|
|
483
|
-
reason: 'sequence_store_unavailable',
|
|
484
|
-
sequenceStoreDurable: store.durable === true,
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
export default {
|
|
490
|
-
NETWORK_WITNESS_VERSION,
|
|
491
|
-
NETWORK_WITNESS_ACCEPTANCE_VERSION,
|
|
492
|
-
NETWORK_WITNESS_EVENTS,
|
|
493
|
-
parseNetworkWitnessStatement,
|
|
494
|
-
networkWitnessDigest,
|
|
495
|
-
signNetworkWitnessStatement,
|
|
496
|
-
verifyNetworkWitnessStatement,
|
|
497
|
-
acceptNetworkWitnessStatement,
|
|
498
|
-
validateTrustedNetworkWitnessAcceptance,
|
|
499
|
-
createMemoryWitnessSequenceStore,
|
|
500
|
-
};
|
|
2
|
+
// Compatibility entry point for the TypeScript network-witness module.
|
|
3
|
+
export * from './dist/network-witness.js';
|
|
4
|
+
export { default } from './dist/network-witness.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emilia-protocol/gate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/emiliaprotocol/emilia-protocol.git",
|
|
@@ -59,13 +59,27 @@
|
|
|
59
59
|
"./reports/external-verification": "./reports/external-verification.js",
|
|
60
60
|
"./reports/assurance-package": "./reports/assurance-package.js",
|
|
61
61
|
"./reliance-kernel": "./reliance-kernel.js",
|
|
62
|
-
"./aec-execution": "./aec-execution.js"
|
|
62
|
+
"./aec-execution": "./aec-execution.js",
|
|
63
|
+
"./runtime-monitor": "./runtime-monitor.js",
|
|
64
|
+
"./formal-runtime-map": "./formal-runtime-map.js",
|
|
65
|
+
"./capability-receipt": "./capability-receipt.js",
|
|
66
|
+
"./receipt-program": "./receipt-program.js",
|
|
67
|
+
"./trust-program": "./trust-program.js",
|
|
68
|
+
"./trust-program-adapters": "./trust-program-adapters.js",
|
|
69
|
+
"./trust-program-postgres": "./trust-program-postgres.js",
|
|
70
|
+
"./trust-program-revocation": "./trust-program-revocation.js",
|
|
71
|
+
"./remedy-program": "./remedy-program.js",
|
|
72
|
+
"./remedy-program-receipt": "./remedy-program-receipt.js",
|
|
73
|
+
"./remedy-program-postgres": "./remedy-program-postgres.js",
|
|
74
|
+
"./zk-range-proof": "./zk-range-proof.js"
|
|
63
75
|
},
|
|
64
76
|
"bin": {
|
|
65
77
|
"ep-assure": "./ep-assure.mjs"
|
|
66
78
|
},
|
|
67
79
|
"files": [
|
|
68
80
|
"index.js",
|
|
81
|
+
"dist",
|
|
82
|
+
"src",
|
|
69
83
|
"strict-json.js",
|
|
70
84
|
"store.js",
|
|
71
85
|
"challenge-store.js",
|
|
@@ -86,6 +100,18 @@
|
|
|
86
100
|
"reliance-packet.js",
|
|
87
101
|
"reliance-kernel.js",
|
|
88
102
|
"aec-execution.js",
|
|
103
|
+
"runtime-monitor.js",
|
|
104
|
+
"formal-runtime-map.js",
|
|
105
|
+
"capability-receipt.js",
|
|
106
|
+
"receipt-program.js",
|
|
107
|
+
"trust-program.js",
|
|
108
|
+
"trust-program-adapters.js",
|
|
109
|
+
"trust-program-postgres.js",
|
|
110
|
+
"trust-program-revocation.js",
|
|
111
|
+
"remedy-program.js",
|
|
112
|
+
"remedy-program-receipt.js",
|
|
113
|
+
"remedy-program-postgres.js",
|
|
114
|
+
"zk-range-proof.js",
|
|
89
115
|
"reports/assurance-package.js",
|
|
90
116
|
"ep-assure.mjs",
|
|
91
117
|
"key-registry.js",
|
|
@@ -148,12 +174,15 @@
|
|
|
148
174
|
"reports/external-verification.js"
|
|
149
175
|
],
|
|
150
176
|
"scripts": {
|
|
177
|
+
"build": "tsc -p tsconfig.json && node postbuild-ts-nocheck.mjs",
|
|
178
|
+
"pretest": "npm run build",
|
|
151
179
|
"test": "node --test",
|
|
152
180
|
"demo": "node demo.mjs",
|
|
153
181
|
"eg1": "node eg1.mjs",
|
|
154
182
|
"cf1": "node cf1.mjs"
|
|
155
183
|
},
|
|
156
184
|
"dependencies": {
|
|
185
|
+
"@noble/curves": "2.2.0",
|
|
157
186
|
"@emilia-protocol/require-receipt": "0.6.1",
|
|
158
187
|
"@emilia-protocol/verify": "3.11.0"
|
|
159
188
|
},
|