@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/action-escrow-state.js
CHANGED
|
@@ -1,397 +1,4 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
* A portable, operator-signed statement over one exact durable Action Escrow
|
|
6
|
-
* snapshot. The signature authenticates an operator statement; it does not
|
|
7
|
-
* prove the operator's database was complete or that a custodian moved money.
|
|
8
|
-
*/
|
|
9
|
-
import crypto from 'node:crypto';
|
|
10
|
-
import { canonicalize, hashCanonical } from './execution-binding.js';
|
|
11
|
-
import { ACTION_ESCROW_EVIDENCE_STAGES } from './action-escrow-evidence.js';
|
|
12
|
-
|
|
13
|
-
export const ACTION_ESCROW_STATE_STATEMENT_VERSION = 'EP-ACTION-ESCROW-STATE-STATEMENT-v1';
|
|
14
|
-
export const ACTION_ESCROW_STATE_STATEMENT_DOMAIN = `${ACTION_ESCROW_STATE_STATEMENT_VERSION}\0`;
|
|
15
|
-
|
|
16
|
-
const HASH = /^sha256:[0-9a-f]{64}$/;
|
|
17
|
-
const ID = /^[A-Za-z0-9][A-Za-z0-9._:/#@+-]{0,255}$/;
|
|
18
|
-
const BASE64URL = /^[A-Za-z0-9_-]+$/;
|
|
19
|
-
const TOP_KEYS = new Set(['version', 'issuer', 'payload', 'statement_digest', 'signature']);
|
|
20
|
-
const ISSUER_KEYS = new Set(['operator_id', 'key_id']);
|
|
21
|
-
const PAYLOAD_KEYS = new Set([
|
|
22
|
-
'statement_id',
|
|
23
|
-
'agreement_id',
|
|
24
|
-
'binding_digest',
|
|
25
|
-
'action_digest',
|
|
26
|
-
'profile_digest',
|
|
27
|
-
'state',
|
|
28
|
-
'revision',
|
|
29
|
-
'amendment_digests',
|
|
30
|
-
'state_record_digest',
|
|
31
|
-
'previous_statement_digest',
|
|
32
|
-
'occurred_at',
|
|
33
|
-
]);
|
|
34
|
-
const SIGNATURE_KEYS = new Set(['algorithm', 'signature_b64u']);
|
|
35
|
-
|
|
36
|
-
function isRecord(value) {
|
|
37
|
-
return value !== null
|
|
38
|
-
&& typeof value === 'object'
|
|
39
|
-
&& !Array.isArray(value)
|
|
40
|
-
&& (Object.getPrototypeOf(value) === Object.prototype
|
|
41
|
-
|| Object.getPrototypeOf(value) === null);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function exactKeys(value, keys) {
|
|
45
|
-
return isRecord(value)
|
|
46
|
-
&& Object.keys(value).length === keys.size
|
|
47
|
-
&& Object.keys(value).every((key) => keys.has(key));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function strictInstant(value) {
|
|
51
|
-
if (typeof value !== 'string') return NaN;
|
|
52
|
-
const match = value.match(
|
|
53
|
-
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d{1,9})?Z$/,
|
|
54
|
-
);
|
|
55
|
-
if (!match) return NaN;
|
|
56
|
-
const [, year, month, day, hour, minute, second] = match;
|
|
57
|
-
const calendar = new Date(0);
|
|
58
|
-
calendar.setUTCFullYear(Number(year), Number(month) - 1, Number(day));
|
|
59
|
-
calendar.setUTCHours(Number(hour), Number(minute), Number(second), 0);
|
|
60
|
-
if (calendar.toISOString().slice(0, 19)
|
|
61
|
-
!== `${year}-${month}-${day}T${hour}:${minute}:${second}`) return NaN;
|
|
62
|
-
const parsed = Date.parse(value);
|
|
63
|
-
return Number.isFinite(parsed) ? parsed : NaN;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function boundedCanonicalCopy(value) {
|
|
67
|
-
let nodes = 0;
|
|
68
|
-
let bytes = 0;
|
|
69
|
-
const seen = new WeakSet();
|
|
70
|
-
|
|
71
|
-
function copy(current, depth) {
|
|
72
|
-
nodes += 1;
|
|
73
|
-
if (nodes > 50_000 || depth > 64) throw new TypeError('state statement exceeds resource limits');
|
|
74
|
-
if (current === null || typeof current === 'boolean') return current;
|
|
75
|
-
if (typeof current === 'string') {
|
|
76
|
-
bytes += Buffer.byteLength(current, 'utf8');
|
|
77
|
-
if (bytes > 4 * 1024 * 1024) throw new TypeError('state statement exceeds string limit');
|
|
78
|
-
return current;
|
|
79
|
-
}
|
|
80
|
-
if (typeof current === 'number') {
|
|
81
|
-
if (!Number.isSafeInteger(current) || Object.is(current, -0)) {
|
|
82
|
-
throw new TypeError('state statement contains a non-canonical number');
|
|
83
|
-
}
|
|
84
|
-
return current;
|
|
85
|
-
}
|
|
86
|
-
if (!isRecord(current) && !Array.isArray(current)) {
|
|
87
|
-
throw new TypeError('state statement is not canonical JSON');
|
|
88
|
-
}
|
|
89
|
-
if (seen.has(current)) throw new TypeError('state statement contains an alias or cycle');
|
|
90
|
-
seen.add(current);
|
|
91
|
-
if (Array.isArray(current)) return current.map((entry) => copy(entry, depth + 1));
|
|
92
|
-
return Object.fromEntries(
|
|
93
|
-
Object.entries(current).map(([key, entry]) => [key, copy(entry, depth + 1)]),
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return copy(value, 0);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function canonicalHash(value) {
|
|
101
|
-
return `sha256:${hashCanonical(value)}`;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function signingBody(statement) {
|
|
105
|
-
return {
|
|
106
|
-
version: statement.version,
|
|
107
|
-
issuer: statement.issuer,
|
|
108
|
-
payload: statement.payload,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function stateSigningBytes(statement) {
|
|
113
|
-
const body = boundedCanonicalCopy(signingBody(statement));
|
|
114
|
-
return Buffer.from(
|
|
115
|
-
ACTION_ESCROW_STATE_STATEMENT_DOMAIN + canonicalize(body),
|
|
116
|
-
'utf8',
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function deepFreeze(value) {
|
|
121
|
-
if (!value || typeof value !== 'object' || Object.isFrozen(value)) return value;
|
|
122
|
-
Object.freeze(value);
|
|
123
|
-
for (const child of Object.values(value)) deepFreeze(child);
|
|
124
|
-
return value;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function strictBase64url(value, length) {
|
|
128
|
-
if (typeof value !== 'string' || !BASE64URL.test(value) || value.length % 4 === 1) return null;
|
|
129
|
-
const bytes = Buffer.from(value, 'base64url');
|
|
130
|
-
if (bytes.toString('base64url') !== value || (length !== undefined && bytes.length !== length)) return null;
|
|
131
|
-
return bytes;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function validDigestList(value) {
|
|
135
|
-
return Array.isArray(value)
|
|
136
|
-
&& value.length <= 1024
|
|
137
|
-
&& value.every((entry) => typeof entry === 'string' && HASH.test(entry))
|
|
138
|
-
&& new Set(value).size === value.length;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function payloadValid(payload) {
|
|
142
|
-
return exactKeys(payload, PAYLOAD_KEYS)
|
|
143
|
-
&& typeof payload.statement_id === 'string' && ID.test(payload.statement_id)
|
|
144
|
-
&& typeof payload.agreement_id === 'string' && ID.test(payload.agreement_id)
|
|
145
|
-
&& HASH.test(payload.binding_digest)
|
|
146
|
-
&& HASH.test(payload.action_digest)
|
|
147
|
-
&& HASH.test(payload.profile_digest)
|
|
148
|
-
&& ACTION_ESCROW_EVIDENCE_STAGES.includes(payload.state)
|
|
149
|
-
&& Number.isSafeInteger(payload.revision) && payload.revision >= 0
|
|
150
|
-
&& validDigestList(payload.amendment_digests)
|
|
151
|
-
&& HASH.test(payload.state_record_digest)
|
|
152
|
-
&& (payload.previous_statement_digest === null || HASH.test(payload.previous_statement_digest))
|
|
153
|
-
&& Number.isFinite(strictInstant(payload.occurred_at));
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function refuse(reason, checks) {
|
|
157
|
-
return {
|
|
158
|
-
valid: false,
|
|
159
|
-
reason,
|
|
160
|
-
checks,
|
|
161
|
-
statement_digest: null,
|
|
162
|
-
agreement_id: null,
|
|
163
|
-
binding_digest: null,
|
|
164
|
-
action_digest: null,
|
|
165
|
-
profile_digest: null,
|
|
166
|
-
state: null,
|
|
167
|
-
revision: null,
|
|
168
|
-
amendment_digests: [],
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Sign one exact state snapshot. Issuance may throw on invalid local input;
|
|
174
|
-
* verification below never throws.
|
|
175
|
-
*/
|
|
176
|
-
export function signActionEscrowStateStatement({
|
|
177
|
-
statementId,
|
|
178
|
-
agreementId,
|
|
179
|
-
bindingDigest,
|
|
180
|
-
actionDigest,
|
|
181
|
-
profileDigest,
|
|
182
|
-
state,
|
|
183
|
-
revision,
|
|
184
|
-
amendmentDigests = [],
|
|
185
|
-
stateRecord,
|
|
186
|
-
previousStatementDigest = null,
|
|
187
|
-
occurredAt,
|
|
188
|
-
} = {}, {
|
|
189
|
-
operatorId,
|
|
190
|
-
keyId,
|
|
191
|
-
privateKey,
|
|
192
|
-
} = {}) {
|
|
193
|
-
const stateRecordCopy = boundedCanonicalCopy(stateRecord);
|
|
194
|
-
const statement = {
|
|
195
|
-
version: ACTION_ESCROW_STATE_STATEMENT_VERSION,
|
|
196
|
-
issuer: {
|
|
197
|
-
operator_id: operatorId,
|
|
198
|
-
key_id: keyId,
|
|
199
|
-
},
|
|
200
|
-
payload: {
|
|
201
|
-
statement_id: statementId,
|
|
202
|
-
agreement_id: agreementId,
|
|
203
|
-
binding_digest: bindingDigest,
|
|
204
|
-
action_digest: actionDigest,
|
|
205
|
-
profile_digest: profileDigest,
|
|
206
|
-
state,
|
|
207
|
-
revision,
|
|
208
|
-
amendment_digests: boundedCanonicalCopy(amendmentDigests),
|
|
209
|
-
state_record_digest: canonicalHash(stateRecordCopy),
|
|
210
|
-
previous_statement_digest: previousStatementDigest,
|
|
211
|
-
occurred_at: occurredAt,
|
|
212
|
-
},
|
|
213
|
-
};
|
|
214
|
-
if (!exactKeys(statement.issuer, ISSUER_KEYS)
|
|
215
|
-
|| typeof operatorId !== 'string' || !ID.test(operatorId)
|
|
216
|
-
|| typeof keyId !== 'string' || !ID.test(keyId)
|
|
217
|
-
|| !payloadValid(statement.payload)) {
|
|
218
|
-
throw new TypeError('action-escrow state statement input is invalid');
|
|
219
|
-
}
|
|
220
|
-
const key = privateKey instanceof crypto.KeyObject ? privateKey : crypto.createPrivateKey(privateKey);
|
|
221
|
-
if (key.asymmetricKeyType !== 'ed25519') {
|
|
222
|
-
throw new TypeError('action-escrow state statement key must be Ed25519');
|
|
223
|
-
}
|
|
224
|
-
const bytes = stateSigningBytes(statement);
|
|
225
|
-
const statementDigest = `sha256:${crypto.createHash('sha256').update(bytes).digest('hex')}`;
|
|
226
|
-
return deepFreeze({
|
|
227
|
-
...statement,
|
|
228
|
-
statement_digest: statementDigest,
|
|
229
|
-
signature: {
|
|
230
|
-
algorithm: 'Ed25519',
|
|
231
|
-
signature_b64u: crypto.sign(null, bytes, key).toString('base64url'),
|
|
232
|
-
},
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Verify one state statement against an exact snapshot and relying-party pins.
|
|
238
|
-
*/
|
|
239
|
-
export function verifyActionEscrowStateStatement(statement, {
|
|
240
|
-
trustedKeys,
|
|
241
|
-
stateRecord,
|
|
242
|
-
expectedAgreementId,
|
|
243
|
-
expectedBindingDigest,
|
|
244
|
-
expectedActionDigest,
|
|
245
|
-
expectedProfileDigest,
|
|
246
|
-
expectedState,
|
|
247
|
-
expectedRevision,
|
|
248
|
-
expectedAmendmentDigests,
|
|
249
|
-
expectedPreviousStatementDigest,
|
|
250
|
-
now,
|
|
251
|
-
} = {}) {
|
|
252
|
-
const checks = {
|
|
253
|
-
structure: false,
|
|
254
|
-
payload: false,
|
|
255
|
-
issuer_pin: false,
|
|
256
|
-
signature: false,
|
|
257
|
-
statement_digest: false,
|
|
258
|
-
state_record: false,
|
|
259
|
-
expected_bindings: false,
|
|
260
|
-
time: false,
|
|
261
|
-
};
|
|
262
|
-
try {
|
|
263
|
-
checks.structure = exactKeys(statement, TOP_KEYS)
|
|
264
|
-
&& statement.version === ACTION_ESCROW_STATE_STATEMENT_VERSION
|
|
265
|
-
&& exactKeys(statement.issuer, ISSUER_KEYS)
|
|
266
|
-
&& exactKeys(statement.signature, SIGNATURE_KEYS);
|
|
267
|
-
if (!checks.structure) return refuse('malformed_state_statement', checks);
|
|
268
|
-
|
|
269
|
-
checks.payload = payloadValid(statement.payload);
|
|
270
|
-
if (!checks.payload) return refuse('invalid_state_payload', checks);
|
|
271
|
-
|
|
272
|
-
const pin = isRecord(trustedKeys) && Object.hasOwn(trustedKeys, statement.issuer.key_id)
|
|
273
|
-
? trustedKeys[statement.issuer.key_id]
|
|
274
|
-
: null;
|
|
275
|
-
checks.issuer_pin = exactKeys(pin, new Set(['operator_id', 'public_key']))
|
|
276
|
-
&& pin.operator_id === statement.issuer.operator_id
|
|
277
|
-
&& typeof pin.public_key === 'string';
|
|
278
|
-
if (!checks.issuer_pin) return refuse('operator_key_not_pinned', checks);
|
|
279
|
-
|
|
280
|
-
const publicBytes = strictBase64url(pin.public_key);
|
|
281
|
-
const signatureBytes = strictBase64url(statement.signature.signature_b64u, 64);
|
|
282
|
-
let publicKey = null;
|
|
283
|
-
try {
|
|
284
|
-
publicKey = crypto.createPublicKey({ key: publicBytes, format: 'der', type: 'spki' });
|
|
285
|
-
} catch {
|
|
286
|
-
publicKey = null;
|
|
287
|
-
}
|
|
288
|
-
const bytes = stateSigningBytes(statement);
|
|
289
|
-
checks.signature = statement.signature.algorithm === 'Ed25519'
|
|
290
|
-
&& publicBytes !== null
|
|
291
|
-
&& signatureBytes !== null
|
|
292
|
-
&& publicKey?.asymmetricKeyType === 'ed25519'
|
|
293
|
-
&& crypto.verify(null, bytes, publicKey, signatureBytes);
|
|
294
|
-
if (!checks.signature) return refuse('state_signature_invalid', checks);
|
|
295
|
-
|
|
296
|
-
const digest = `sha256:${crypto.createHash('sha256').update(bytes).digest('hex')}`;
|
|
297
|
-
checks.statement_digest = statement.statement_digest === digest;
|
|
298
|
-
if (!checks.statement_digest) return refuse('state_statement_digest_mismatch', checks);
|
|
299
|
-
|
|
300
|
-
checks.state_record = canonicalHash(boundedCanonicalCopy(stateRecord))
|
|
301
|
-
=== statement.payload.state_record_digest;
|
|
302
|
-
if (!checks.state_record) return refuse('state_record_digest_mismatch', checks);
|
|
303
|
-
|
|
304
|
-
const amendments = expectedAmendmentDigests;
|
|
305
|
-
checks.expected_bindings = typeof expectedAgreementId === 'string'
|
|
306
|
-
&& statement.payload.agreement_id === expectedAgreementId
|
|
307
|
-
&& statement.payload.binding_digest === expectedBindingDigest
|
|
308
|
-
&& statement.payload.action_digest === expectedActionDigest
|
|
309
|
-
&& statement.payload.profile_digest === expectedProfileDigest
|
|
310
|
-
&& statement.payload.state === expectedState
|
|
311
|
-
&& statement.payload.revision === expectedRevision
|
|
312
|
-
&& Array.isArray(amendments)
|
|
313
|
-
&& statement.payload.amendment_digests.length === amendments.length
|
|
314
|
-
&& statement.payload.amendment_digests.every((entry, index) => entry === amendments[index])
|
|
315
|
-
&& statement.payload.previous_statement_digest === expectedPreviousStatementDigest;
|
|
316
|
-
if (!checks.expected_bindings) return refuse('state_expected_binding_mismatch', checks);
|
|
317
|
-
|
|
318
|
-
const evaluation = now instanceof Date
|
|
319
|
-
? now.getTime()
|
|
320
|
-
: typeof now === 'number' ? now : strictInstant(now);
|
|
321
|
-
checks.time = Number.isFinite(evaluation)
|
|
322
|
-
&& strictInstant(statement.payload.occurred_at) <= evaluation;
|
|
323
|
-
if (!checks.time) return refuse('state_statement_from_future', checks);
|
|
324
|
-
|
|
325
|
-
return {
|
|
326
|
-
valid: true,
|
|
327
|
-
reason: 'verified',
|
|
328
|
-
checks,
|
|
329
|
-
statement_digest: digest,
|
|
330
|
-
agreement_id: statement.payload.agreement_id,
|
|
331
|
-
binding_digest: statement.payload.binding_digest,
|
|
332
|
-
action_digest: statement.payload.action_digest,
|
|
333
|
-
profile_digest: statement.payload.profile_digest,
|
|
334
|
-
state: statement.payload.state,
|
|
335
|
-
revision: statement.payload.revision,
|
|
336
|
-
amendment_digests: [...statement.payload.amendment_digests],
|
|
337
|
-
};
|
|
338
|
-
} catch {
|
|
339
|
-
return refuse('malformed_state_statement', checks);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* Build the callback expected by verifyActionEscrowEvidencePackage. The
|
|
345
|
-
* package carries both the exact durable snapshot and the signed statement
|
|
346
|
-
* over it; trust keys and time remain verifier configuration.
|
|
347
|
-
*/
|
|
348
|
-
export function createActionEscrowStatePackageVerifier({
|
|
349
|
-
trustedKeys,
|
|
350
|
-
now,
|
|
351
|
-
minimumRevision = 0,
|
|
352
|
-
} = {}) {
|
|
353
|
-
if (!Number.isSafeInteger(minimumRevision) || minimumRevision < 0) {
|
|
354
|
-
throw new TypeError('minimumRevision must be a non-negative safe integer');
|
|
355
|
-
}
|
|
356
|
-
const pinnedKeys = boundedCanonicalCopy(trustedKeys);
|
|
357
|
-
return async function verifyPackagedState(packaged, expected = {}) {
|
|
358
|
-
if (!exactKeys(packaged, new Set(['snapshot', 'statement']))
|
|
359
|
-
|| !isRecord(packaged.statement?.payload)
|
|
360
|
-
|| !isRecord(packaged.snapshot)
|
|
361
|
-
|| packaged.statement.payload.state !== packaged.snapshot.state
|
|
362
|
-
|| packaged.statement.payload.revision !== packaged.snapshot.revision
|
|
363
|
-
|| packaged.statement.payload.revision < minimumRevision) {
|
|
364
|
-
return refuse('malformed_packaged_state', {
|
|
365
|
-
structure: false,
|
|
366
|
-
payload: false,
|
|
367
|
-
issuer_pin: false,
|
|
368
|
-
signature: false,
|
|
369
|
-
statement_digest: false,
|
|
370
|
-
state_record: false,
|
|
371
|
-
expected_bindings: false,
|
|
372
|
-
time: false,
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
return verifyActionEscrowStateStatement(packaged.statement, {
|
|
376
|
-
trustedKeys: pinnedKeys,
|
|
377
|
-
stateRecord: packaged.snapshot,
|
|
378
|
-
expectedAgreementId: expected.agreementId,
|
|
379
|
-
expectedBindingDigest: expected.bindingDigest,
|
|
380
|
-
expectedActionDigest: expected.actionDigest,
|
|
381
|
-
expectedProfileDigest: expected.profileDigest,
|
|
382
|
-
expectedState: expected.stage,
|
|
383
|
-
expectedRevision: packaged.statement.payload.revision,
|
|
384
|
-
expectedAmendmentDigests: expected.amendmentDigests,
|
|
385
|
-
expectedPreviousStatementDigest: packaged.statement.payload.previous_statement_digest,
|
|
386
|
-
now,
|
|
387
|
-
});
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
export default {
|
|
392
|
-
ACTION_ESCROW_STATE_STATEMENT_VERSION,
|
|
393
|
-
ACTION_ESCROW_STATE_STATEMENT_DOMAIN,
|
|
394
|
-
signActionEscrowStateStatement,
|
|
395
|
-
verifyActionEscrowStateStatement,
|
|
396
|
-
createActionEscrowStatePackageVerifier,
|
|
397
|
-
};
|
|
2
|
+
// Compatibility entry point for the TypeScript action-escrow-state module.
|
|
3
|
+
export * from './dist/action-escrow-state.js';
|
|
4
|
+
export { default } from './dist/action-escrow-state.js';
|