settld 0.1.2 → 0.2.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/README.md +93 -3
- package/SETTLD_VERSION +1 -1
- package/bin/settld-mcp +2 -0
- package/bin/settld.js +71 -0
- package/conformance/kernel-v0/README.md +7 -0
- package/conformance/kernel-v0/run.mjs +292 -4
- package/docs/ACCESS.md +57 -0
- package/docs/ADOPTION_CHECKLIST.md +44 -0
- package/docs/ALERTS.md +198 -0
- package/docs/ARCHITECTURE.md +69 -0
- package/docs/ARCHITECTURE_FOUNDER_GUIDE.md +284 -0
- package/docs/ARTIFACTS.md +60 -0
- package/docs/CERTIFICATION_CHECKLIST.md +33 -0
- package/docs/CIRCLE_SANDBOX_E2E.md +152 -0
- package/docs/CONFIG.md +297 -0
- package/docs/CONTRACTS_APIS.md +23 -0
- package/docs/DEPRECATION.md +31 -0
- package/docs/DOMAIN_MODEL.md +92 -0
- package/docs/EVENT_ENVELOPE.md +53 -0
- package/docs/FINANCE_PACK_FORMAT.md +53 -0
- package/docs/INCIDENT_TAXONOMY.md +30 -0
- package/docs/JOB_STATE_MACHINE.md +66 -0
- package/docs/KERNEL_COMPATIBLE.md +60 -0
- package/docs/KERNEL_V0.md +40 -0
- package/docs/KEY_ROTATION.md +80 -0
- package/docs/LEDGER.md +82 -0
- package/docs/LIVENESS.md +76 -0
- package/docs/MVP_BUILD_ORDER.md +36 -0
- package/docs/ONCALL_PLAYBOOK.md +39 -0
- package/docs/OPERATIONS_SIGNING.md +20 -0
- package/docs/OVERVIEW.md +190 -0
- package/docs/PERF_BASELINE.md +85 -0
- package/docs/PRD.md +77 -0
- package/docs/QUICKSTART_KERNEL_V0.md +96 -0
- package/docs/QUICKSTART_MCP.md +377 -0
- package/docs/QUICKSTART_MCP_HOSTS.md +210 -0
- package/docs/QUICKSTART_POLICY_PACKS.md +65 -0
- package/docs/QUICKSTART_PRODUCE.md +61 -0
- package/docs/QUICKSTART_PROFILES.md +198 -0
- package/docs/QUICKSTART_RELEASE_VERIFY.md +39 -0
- package/docs/QUICKSTART_SDK.md +125 -0
- package/docs/QUICKSTART_SDK_PYTHON.md +111 -0
- package/docs/QUICKSTART_VERIFY.md +54 -0
- package/docs/QUICKSTART_X402_GATEWAY.md +317 -0
- package/docs/README.md +33 -0
- package/docs/RELEASE_CHECKLIST.md +182 -0
- package/docs/RELEASING.md +82 -0
- package/docs/REPO_SETTINGS.md +37 -0
- package/docs/RUNBOOK.md +86 -0
- package/docs/SKILLS.md +42 -0
- package/docs/SKILL_BUNDLE_FORMAT.md +48 -0
- package/docs/SLO.md +131 -0
- package/docs/SUMMARY.md +17 -0
- package/docs/SUPPORT.md +31 -0
- package/docs/THREAT_MODEL.md +36 -0
- package/docs/TRUST.md +59 -0
- package/docs/WORKFLOW.md +35 -0
- package/docs/X402_BATCH_SETTLEMENT.md +126 -0
- package/docs/blog/2026-02-14-your-ai-agent-just-spent-500-where-is-the-receipt.md +73 -0
- package/docs/examples/x402-provider-payout-registry.example.json +14 -0
- package/docs/gitbook/README.md +64 -0
- package/docs/gitbook/SETUP.md +25 -0
- package/docs/gitbook/SUMMARY.md +15 -0
- package/docs/gitbook/api-reference.md +73 -0
- package/docs/gitbook/closepacks.md +55 -0
- package/docs/gitbook/conformance.md +59 -0
- package/docs/gitbook/core-primitives.md +85 -0
- package/docs/gitbook/dispute-lifecycle.md +33 -0
- package/docs/gitbook/faq.md +21 -0
- package/docs/gitbook/guides.md +49 -0
- package/docs/gitbook/operations-runbook.md +36 -0
- package/docs/gitbook/quickstart.md +103 -0
- package/docs/gitbook/replay-and-audit.md +30 -0
- package/docs/gitbook/sdk-reference.md +35 -0
- package/docs/gitbook/security-model.md +58 -0
- package/docs/integrations/README.md +15 -0
- package/docs/integrations/github-actions-verify.yml +31 -0
- package/docs/integrations/github-actions.md +34 -0
- package/docs/integrations/openclaw/CLAWHUB_PUBLISH_CHECKLIST.md +65 -0
- package/docs/integrations/openclaw/PUBLIC_QUICKSTART.md +95 -0
- package/docs/integrations/openclaw/settld-mcp-skill/SKILL.md +69 -0
- package/docs/integrations/openclaw/settld-mcp-skill/mcp-server.example.json +12 -0
- package/docs/kernel-compatible/capabilities.json +36 -0
- package/docs/marketing/agent-commerce-substrate.md +78 -0
- package/docs/marketing/hn-repost-2026-02-17.md +102 -0
- package/docs/marketing/show-hn-post.md +45 -0
- package/docs/ops/ARTIFACT_VERIFICATION_STATUS.md +43 -0
- package/docs/ops/BILLING_WEBHOOK_REPLAY.md +105 -0
- package/docs/ops/CI_FLAKE_BUDGET.md +31 -0
- package/docs/ops/DISPUTE_FINANCE_RECONCILIATION_PACKET.md +56 -0
- package/docs/ops/GO_LIVE_GATE_S13.md +27 -0
- package/docs/ops/HOSTED_BASELINE_R2.md +129 -0
- package/docs/ops/KERNEL_V0_SHIP_GATE.md +69 -0
- package/docs/ops/LIGHTHOUSE_PRODUCTION_CLOSE.md +51 -0
- package/docs/ops/MCP_COMPATIBILITY_MATRIX.md +30 -0
- package/docs/ops/MINIMUM_PRODUCTION_TOPOLOGY.md +89 -0
- package/docs/ops/P0_BACKEND_PROGRESS.md +150 -0
- package/docs/ops/PAYMENTS_ALPHA_R5.md +105 -0
- package/docs/ops/PILOT_ONBOARDING_RUNBOOK.md +112 -0
- package/docs/ops/PRODUCTION_DEPLOYMENT_CHECKLIST.md +140 -0
- package/docs/ops/R1_SLOS.md +66 -0
- package/docs/ops/RELEASE_SIGNING_INCIDENT.md +58 -0
- package/docs/ops/SELF_SERVE_LAUNCH_AUTOMATION.md +89 -0
- package/docs/ops/THROUGHPUT_DRILL_10X.md +48 -0
- package/docs/ops/TRUST_CONFIG_WIZARD.md +60 -0
- package/docs/ops/X402_PILOT_WEEKLY_METRICS.md +76 -0
- package/docs/ops/tool-call-disputes-holdback.md +52 -0
- package/docs/pilot-kit/PILOT_PACKAGE_SCORECARD_X402.md +46 -0
- package/docs/pilot-kit/README.md +29 -0
- package/docs/pilot-kit/architecture-one-pager.md +48 -0
- package/docs/pilot-kit/buyer-email.txt +19 -0
- package/docs/pilot-kit/buyer-one-pager.md +31 -0
- package/docs/pilot-kit/gtm-pilot-playbook.md +182 -0
- package/docs/pilot-kit/offline-verify.md +33 -0
- package/docs/pilot-kit/procurement-one-pager.md +50 -0
- package/docs/pilot-kit/rfp-clause.md +46 -0
- package/docs/pilot-kit/roi-calculator-template.csv +2 -0
- package/docs/pilot-kit/security-qa.md +153 -0
- package/docs/pilot-kit/security-summary.md +35 -0
- package/docs/plans/2026-02-13-mcp-spike-design.md +113 -0
- package/docs/plans/2026-02-20-trust-os-v1-jira-backlog.md +348 -0
- package/docs/plans/2026-02-21-agent-economic-actor-operating-model.md +169 -0
- package/docs/plans/2026-02-21-trust-os-v1-strategy.md +241 -0
- package/docs/research/2026-02-21-agent-spend-host-landscape.md +57 -0
- package/docs/spec/AcceptanceCriteria.v1.md +17 -0
- package/docs/spec/AcceptanceEvaluation.v1.md +10 -0
- package/docs/spec/AgentEvent.v1.md +47 -0
- package/docs/spec/AgentIdentity.v1.md +62 -0
- package/docs/spec/AgentPassport.v1.md +95 -0
- package/docs/spec/AgentReputation.v1.md +59 -0
- package/docs/spec/AgentReputation.v2.md +52 -0
- package/docs/spec/AgentRun.v1.md +47 -0
- package/docs/spec/AgentRunSettlement.v1.md +52 -0
- package/docs/spec/AgentWallet.v1.md +43 -0
- package/docs/spec/AgreementDelegation.v1.md +109 -0
- package/docs/spec/ArbitrationCase.v1.md +67 -0
- package/docs/spec/ArbitrationOutcomeMapping.v1.md +62 -0
- package/docs/spec/ArbitrationVerdict.v1.md +60 -0
- package/docs/spec/BundleHeadAttestation.v1.md +32 -0
- package/docs/spec/CANONICAL_JSON.md +31 -0
- package/docs/spec/CRYPTOGRAPHY.md +61 -0
- package/docs/spec/ClosePack.v1.md +49 -0
- package/docs/spec/ClosePackManifest.v1.md +24 -0
- package/docs/spec/DelegationGrant.v1.md +90 -0
- package/docs/spec/DisputeCaseLifecycle.v1.md +51 -0
- package/docs/spec/DisputeOpenEnvelope.v1.md +43 -0
- package/docs/spec/ERRORS.md +76 -0
- package/docs/spec/ESCROW_NETTING_INVARIANTS.md +71 -0
- package/docs/spec/EvidenceIndex.v1.md +20 -0
- package/docs/spec/ExecutionIntent.v1.md +90 -0
- package/docs/spec/FinancePackBundleManifest.v1.md +24 -0
- package/docs/spec/FundingHold.v1.md +60 -0
- package/docs/spec/GovernancePolicy.v1.md +34 -0
- package/docs/spec/GovernancePolicy.v2.md +30 -0
- package/docs/spec/INVARIANTS.md +389 -0
- package/docs/spec/InteractionDirectionMatrix.v1.md +30 -0
- package/docs/spec/InvoiceBundleManifest.v1.md +24 -0
- package/docs/spec/InvoiceClaim.v1.md +11 -0
- package/docs/spec/MONEY_RAIL_STATE_MACHINE.md +58 -0
- package/docs/spec/MarketplaceAcceptance.v2.md +46 -0
- package/docs/spec/MarketplaceOffer.v2.md +54 -0
- package/docs/spec/MeteringReport.v1.md +18 -0
- package/docs/spec/OperatorAction.v1.md +90 -0
- package/docs/spec/PRODUCER_ERRORS.md +42 -0
- package/docs/spec/PolicyDecision.v1.md +83 -0
- package/docs/spec/PricingMatrix.v1.md +20 -0
- package/docs/spec/PricingMatrixSignatures.v1.md +30 -0
- package/docs/spec/PricingMatrixSignatures.v2.md +29 -0
- package/docs/spec/ProduceCliOutput.v1.md +46 -0
- package/docs/spec/ProofBundleManifest.v1.md +24 -0
- package/docs/spec/README.md +109 -0
- package/docs/spec/REFERENCE_IMPLEMENTATIONS.md +29 -0
- package/docs/spec/REFERENCE_VERIFIER_BEHAVIOR.md +68 -0
- package/docs/spec/REMOTE_SIGNER.md +66 -0
- package/docs/spec/ReleaseIndex.v1.md +32 -0
- package/docs/spec/ReleaseIndexSignatures.v1.md +17 -0
- package/docs/spec/ReleaseTrust.v1.md +13 -0
- package/docs/spec/ReleaseTrust.v2.md +26 -0
- package/docs/spec/RemoteSignerRequest.v1.md +21 -0
- package/docs/spec/RemoteSignerResponse.v1.md +16 -0
- package/docs/spec/ReputationEvent.v1.md +63 -0
- package/docs/spec/RevocationList.v1.md +28 -0
- package/docs/spec/SIGNER_PROVIDER_PLUGIN.md +32 -0
- package/docs/spec/STRICTNESS.md +68 -0
- package/docs/spec/SUPPLY_CHAIN.md +33 -0
- package/docs/spec/SettlementAdjustment.v1.md +45 -0
- package/docs/spec/SettlementDecisionRecord.v1.md +48 -0
- package/docs/spec/SettlementDecisionRecord.v2.md +53 -0
- package/docs/spec/SettlementDecisionReport.v1.md +44 -0
- package/docs/spec/SettlementKernel.v1.md +59 -0
- package/docs/spec/SettlementReceipt.v1.md +63 -0
- package/docs/spec/SlaDefinition.v1.md +24 -0
- package/docs/spec/SlaEvaluation.v1.md +12 -0
- package/docs/spec/THREAT_MODEL.md +113 -0
- package/docs/spec/TOOL_PROVENANCE.md +30 -0
- package/docs/spec/TRUST_ANCHORS.md +84 -0
- package/docs/spec/TenantSettings.v1.md +90 -0
- package/docs/spec/TenantSettings.v2.md +99 -0
- package/docs/spec/TimestampProof.v1.md +25 -0
- package/docs/spec/ToolCallAgreement.v1.md +34 -0
- package/docs/spec/ToolCallEvidence.v1.md +47 -0
- package/docs/spec/ToolManifest.v1.md +47 -0
- package/docs/spec/VERIFIER_ENVIRONMENT.md +38 -0
- package/docs/spec/VERSIONING.md +107 -0
- package/docs/spec/VerificationReport.v1.md +50 -0
- package/docs/spec/VerifyAboutOutput.v1.md +10 -0
- package/docs/spec/VerifyCliOutput.v1.md +28 -0
- package/docs/spec/WARNINGS.md +83 -0
- package/docs/spec/error-codes.v1.txt +285 -0
- package/docs/spec/examples/agreement_delegation_v1.example.json +21 -0
- package/docs/spec/examples/arbitration_case_v1.example.json +26 -0
- package/docs/spec/examples/arbitration_verdict_v1.example.json +32 -0
- package/docs/spec/examples/dispute_open_envelope_v1.example.json +18 -0
- package/docs/spec/examples/produce_cli_output_v1.example.json +32 -0
- package/docs/spec/examples/release_index_signature_v1.example.json +9 -0
- package/docs/spec/examples/release_index_signatures_v1.example.json +14 -0
- package/docs/spec/examples/release_index_v1.example.json +15 -0
- package/docs/spec/examples/release_trust_v1.example.json +7 -0
- package/docs/spec/examples/release_trust_v2.example.json +22 -0
- package/docs/spec/examples/remote_signer_request_v1.example.json +18 -0
- package/docs/spec/examples/remote_signer_response_v1.example.json +8 -0
- package/docs/spec/examples/reputation_event_v1.example.json +29 -0
- package/docs/spec/examples/verification_report_v1.example.json +24 -0
- package/docs/spec/examples/verify_about_output_v1.example.json +29 -0
- package/docs/spec/examples/verify_cli_output_v1.example.json +13 -0
- package/docs/spec/legacy/MarketplaceAcceptance.v1.md +48 -0
- package/docs/spec/legacy/MarketplaceOffer.v1.md +56 -0
- package/docs/spec/legacy/schemas/MarketplaceAcceptance.v1.schema.json +53 -0
- package/docs/spec/legacy/schemas/MarketplaceOffer.v1.schema.json +61 -0
- package/docs/spec/producer-error-codes.v1.txt +14 -0
- package/docs/spec/schemas/AcceptanceCriteria.v1.schema.json +24 -0
- package/docs/spec/schemas/AcceptanceEvaluation.v1.schema.json +26 -0
- package/docs/spec/schemas/AgentEvent.v1.schema.json +49 -0
- package/docs/spec/schemas/AgentIdentity.v1.schema.json +129 -0
- package/docs/spec/schemas/AgentPassport.v1.schema.json +112 -0
- package/docs/spec/schemas/AgentReputation.v1.schema.json +151 -0
- package/docs/spec/schemas/AgentReputation.v2.schema.json +120 -0
- package/docs/spec/schemas/AgentRun.v1.schema.json +71 -0
- package/docs/spec/schemas/AgentRunSettlement.v1.schema.json +75 -0
- package/docs/spec/schemas/AgentWallet.v1.schema.json +54 -0
- package/docs/spec/schemas/AgreementDelegation.v1.schema.json +50 -0
- package/docs/spec/schemas/ArbitrationCase.v1.schema.json +133 -0
- package/docs/spec/schemas/ArbitrationVerdict.v1.schema.json +149 -0
- package/docs/spec/schemas/BundleHeadAttestation.v1.schema.json +21 -0
- package/docs/spec/schemas/ClosePackManifest.v1.schema.json +38 -0
- package/docs/spec/schemas/DelegationGrant.v1.schema.json +102 -0
- package/docs/spec/schemas/DisputeOpenEnvelope.v1.schema.json +78 -0
- package/docs/spec/schemas/EvidenceIndex.v1.schema.json +41 -0
- package/docs/spec/schemas/ExecutionIntent.v1.schema.json +85 -0
- package/docs/spec/schemas/FinancePackBundleManifest.v1.schema.json +38 -0
- package/docs/spec/schemas/FundingHold.v1.schema.json +46 -0
- package/docs/spec/schemas/GovernancePolicy.v1.schema.json +45 -0
- package/docs/spec/schemas/GovernancePolicy.v2.schema.json +70 -0
- package/docs/spec/schemas/InteractionDirectionMatrix.v1.schema.json +43 -0
- package/docs/spec/schemas/InvoiceBundleManifest.v1.schema.json +38 -0
- package/docs/spec/schemas/InvoiceClaim.v1.schema.json +39 -0
- package/docs/spec/schemas/MarketplaceAcceptance.v2.schema.json +53 -0
- package/docs/spec/schemas/MarketplaceOffer.v2.schema.json +61 -0
- package/docs/spec/schemas/MeteringReport.v1.schema.json +45 -0
- package/docs/spec/schemas/OperatorAction.v1.schema.json +113 -0
- package/docs/spec/schemas/PolicyDecision.v1.schema.json +74 -0
- package/docs/spec/schemas/PricingMatrix.v1.schema.json +24 -0
- package/docs/spec/schemas/PricingMatrixSignatures.v1.schema.json +24 -0
- package/docs/spec/schemas/PricingMatrixSignatures.v2.schema.json +24 -0
- package/docs/spec/schemas/ProduceCliOutput.v1.schema.json +107 -0
- package/docs/spec/schemas/ProofBundleManifest.v1.schema.json +37 -0
- package/docs/spec/schemas/PublicKeys.v1.schema.json +33 -0
- package/docs/spec/schemas/ReleaseIndex.v1.schema.json +45 -0
- package/docs/spec/schemas/ReleaseIndexSignature.v1.schema.json +16 -0
- package/docs/spec/schemas/ReleaseIndexSignatures.v1.schema.json +16 -0
- package/docs/spec/schemas/ReleaseTrust.v1.schema.json +15 -0
- package/docs/spec/schemas/ReleaseTrust.v2.schema.json +37 -0
- package/docs/spec/schemas/RemoteSignerPublicKeyResponse.v1.schema.json +14 -0
- package/docs/spec/schemas/RemoteSignerRequest.v1.schema.json +24 -0
- package/docs/spec/schemas/RemoteSignerResponse.v1.schema.json +10 -0
- package/docs/spec/schemas/RemoteSignerSignRequest.v1.schema.json +27 -0
- package/docs/spec/schemas/RemoteSignerSignResponse.v1.schema.json +16 -0
- package/docs/spec/schemas/ReputationEvent.v1.schema.json +164 -0
- package/docs/spec/schemas/RevocationList.v1.schema.json +51 -0
- package/docs/spec/schemas/SettlementAdjustment.v1.schema.json +44 -0
- package/docs/spec/schemas/SettlementDecisionRecord.v1.schema.json +66 -0
- package/docs/spec/schemas/SettlementDecisionRecord.v2.schema.json +149 -0
- package/docs/spec/schemas/SettlementDecisionReport.v1.schema.json +61 -0
- package/docs/spec/schemas/SettlementReceipt.v1.schema.json +135 -0
- package/docs/spec/schemas/SlaDefinition.v1.schema.json +33 -0
- package/docs/spec/schemas/SlaEvaluation.v1.schema.json +26 -0
- package/docs/spec/schemas/TenantSettings.v1.schema.json +90 -0
- package/docs/spec/schemas/TenantSettings.v2.schema.json +161 -0
- package/docs/spec/schemas/TimestampProof.v1.schema.json +17 -0
- package/docs/spec/schemas/ToolCallAgreement.v1.schema.json +34 -0
- package/docs/spec/schemas/ToolCallEvidence.v1.schema.json +45 -0
- package/docs/spec/schemas/ToolManifest.v1.schema.json +54 -0
- package/docs/spec/schemas/VerificationReport.v1.schema.json +83 -0
- package/docs/spec/schemas/VerifyAboutOutput.v1.schema.json +54 -0
- package/docs/spec/schemas/VerifyCliOutput.v1.schema.json +75 -0
- package/docs/spec/schemas/VerifyReleaseOutput.v1.schema.json +47 -0
- package/docs/spec/x402-error-codes.v1.txt +35 -0
- package/docs/templates/buyer-email.txt +18 -0
- package/docs/templates/buyer-one-pager.md +24 -0
- package/package.json +53 -6
- package/scripts/acceptance/full-stack.mjs +734 -0
- package/scripts/acceptance/full-stack.sh +99 -0
- package/scripts/audit/build-audit-packet.mjs +242 -0
- package/scripts/backup-pg.sh +45 -0
- package/scripts/backup-restore/README.md +18 -0
- package/scripts/backup-restore/capture-state.mjs +130 -0
- package/scripts/backup-restore/client.mjs +97 -0
- package/scripts/backup-restore/seed-workload.mjs +235 -0
- package/scripts/backup-restore/verify-state.mjs +139 -0
- package/scripts/backup-restore-test.sh +217 -0
- package/scripts/chaos.js +221 -0
- package/scripts/ci/build-launch-cutover-packet.mjs +304 -0
- package/scripts/ci/build-self-serve-benchmark-report.mjs +122 -0
- package/scripts/ci/changelog-guard.mjs +145 -0
- package/scripts/ci/check-kernel-v0-launch-gate.mjs +233 -0
- package/scripts/ci/check-secret-hygiene.mjs +78 -0
- package/scripts/ci/check-version-consistency.mjs +42 -0
- package/scripts/ci/cli-pack-smoke.mjs +160 -0
- package/scripts/ci/flake-budget-guard.mjs +68 -0
- package/scripts/ci/generate-error-codes.mjs +54 -0
- package/scripts/ci/lib/lighthouse-tracker.mjs +90 -0
- package/scripts/ci/lib/self-serve-launch-gate.mjs +89 -0
- package/scripts/ci/npm-pack-smoke.mjs +454 -0
- package/scripts/ci/run-10x-throughput-drill.mjs +318 -0
- package/scripts/ci/run-10x-throughput-incident-rehearsal.mjs +368 -0
- package/scripts/ci/run-arbitration-workspace-browser-e2e.sh +22 -0
- package/scripts/ci/run-circle-sandbox-smoke.mjs +237 -0
- package/scripts/ci/run-go-live-gate.mjs +150 -0
- package/scripts/ci/run-kernel-v0-ship-gate.mjs +97 -0
- package/scripts/ci/run-mcp-host-cert-matrix.mjs +201 -0
- package/scripts/ci/run-mcp-host-smoke.mjs +473 -0
- package/scripts/ci/run-offline-verification-parity-gate.mjs +762 -0
- package/scripts/ci/run-onboarding-host-success-gate.mjs +516 -0
- package/scripts/ci/run-onboarding-policy-slo-gate.mjs +537 -0
- package/scripts/ci/run-production-cutover-gate.mjs +540 -0
- package/scripts/ci/run-public-openclaw-npx-smoke.mjs +148 -0
- package/scripts/ci/run-release-promotion-guard.mjs +756 -0
- package/scripts/ci/run-self-serve-launch-gate.mjs +56 -0
- package/scripts/ci/runtime-import-smoke.mjs +58 -0
- package/scripts/ci/update-lighthouse-tracker.mjs +112 -0
- package/scripts/closepack/lib.mjs +286 -0
- package/scripts/collect-debug.sh +263 -0
- package/scripts/demo/compositional-settlement-3hop.mjs +237 -0
- package/scripts/demo/delivery-robot/export-ui-fixture.mjs +188 -0
- package/scripts/demo/delivery-robot/generate.mjs +377 -0
- package/scripts/demo/kernel-agent-goes-shopping.mjs +202 -0
- package/scripts/demo/magic-link-first-green.mjs +118 -0
- package/scripts/demo/magic-link-kind-smoke.mjs +577 -0
- package/scripts/demo/mcp-paid-exa.mjs +1110 -0
- package/scripts/dev/billing-doctor.sh +145 -0
- package/scripts/dev/billing-smoke-prod.sh +219 -0
- package/scripts/dev/billing-webhook-replay.sh +161 -0
- package/scripts/dev/env.dev.example +29 -0
- package/scripts/dev/env.sh +37 -0
- package/scripts/dev/new-sdk-key.sh +81 -0
- package/scripts/dev/sdk-first-run.sh +21 -0
- package/scripts/dev/smoke-x402-gateway.sh +115 -0
- package/scripts/dev/start-api.sh +24 -0
- package/scripts/doctor/mcp-host.mjs +120 -0
- package/scripts/examples/produce-and-verify-jobproof.mjs +191 -0
- package/scripts/examples/sdk-first-paid-rfq.py +105 -0
- package/scripts/examples/sdk-first-verified-run.mjs +85 -0
- package/scripts/examples/sdk-first-verified-run.py +99 -0
- package/scripts/examples/sdk-tenant-analytics.mjs +103 -0
- package/scripts/examples/sdk-tenant-analytics.py +118 -0
- package/scripts/finance-pack/bundle.mjs +284 -0
- package/scripts/fixtures/generate-bundle-fixtures.mjs +877 -0
- package/scripts/governance/export.mjs +169 -0
- package/scripts/load/delivery-stress.k6.js +183 -0
- package/scripts/load/ingest-burst.k6.js +236 -0
- package/scripts/load/run-delivery-load.js +66 -0
- package/scripts/load/webhook-receiver.js +131 -0
- package/scripts/magic-link/migrate-run-records-to-db.mjs +35 -0
- package/scripts/mcp/probe.mjs +238 -0
- package/scripts/mcp/settld-mcp-http-gateway.mjs +178 -0
- package/scripts/mcp/settld-mcp-server.mjs +1511 -0
- package/scripts/openapi/write.mjs +13 -0
- package/scripts/ops/bootstrap-tenant-conformance.mjs +185 -0
- package/scripts/ops/build-x402-pilot-reliability-report.mjs +489 -0
- package/scripts/ops/check-x402-receipt-sample.mjs +181 -0
- package/scripts/ops/design-partner-run-packet.mjs +466 -0
- package/scripts/ops/dispute-finance-reconciliation-packet.mjs +313 -0
- package/scripts/ops/hosted-baseline-evidence.mjs +890 -0
- package/scripts/ops/money-rails-chargeback-evidence.mjs +509 -0
- package/scripts/ops/money-rails-reconcile-evidence.mjs +180 -0
- package/scripts/ops/p0-seed-money-rail-operation.mjs +432 -0
- package/scripts/ops/run-x402-hitl-smoke.mjs +607 -0
- package/scripts/pilot/finance-pack.mjs +495 -0
- package/scripts/pilot/fixtures/robot-keypair.json +4 -0
- package/scripts/pilot/fixtures/server-signer.json +4 -0
- package/scripts/policy/cli.mjs +600 -0
- package/scripts/profile/cli.mjs +1324 -0
- package/scripts/proof-bundle/job.mjs +109 -0
- package/scripts/proof-bundle/lib.mjs +92 -0
- package/scripts/proof-bundle/month.mjs +103 -0
- package/scripts/provider/conformance-run.mjs +159 -0
- package/scripts/provider/keys-generate.mjs +135 -0
- package/scripts/provider/publish.mjs +420 -0
- package/scripts/quickstart/x402.mjs +334 -0
- package/scripts/register-entity-secret.mjs +102 -0
- package/scripts/release/build-artifacts.mjs +181 -0
- package/scripts/release/generate-release-index.mjs +112 -0
- package/scripts/release/release-index-lib.mjs +232 -0
- package/scripts/release/sign-release-index.mjs +85 -0
- package/scripts/release/validate-release-assets.mjs +170 -0
- package/scripts/release/verify-release.mjs +261 -0
- package/scripts/restore-pg.sh +34 -0
- package/scripts/scaffold/create-settld-paid-tool.mjs +19 -0
- package/scripts/sdk/smoke-python.py +30 -0
- package/scripts/sdk/smoke.mjs +16 -0
- package/scripts/settlement/x402-batch-worker.mjs +1091 -0
- package/scripts/setup/circle-bootstrap.mjs +310 -0
- package/scripts/setup/host-config.mjs +617 -0
- package/scripts/setup/onboard.mjs +1337 -0
- package/scripts/setup/openclaw-onboard.mjs +423 -0
- package/scripts/setup/wizard.mjs +986 -0
- package/scripts/slo/check.mjs +239 -0
- package/scripts/smoke/k8s-smoke.mjs +214 -0
- package/scripts/spec/generate-protocol-vectors.mjs +1019 -0
- package/scripts/test/check-no-generated-artifacts.sh +12 -0
- package/scripts/test/run.sh +59 -0
- package/scripts/trust/validate-trust-file.mjs +57 -0
- package/scripts/trust-config/rotate-settld-pay.mjs +277 -0
- package/scripts/trust-config/wizard.mjs +161 -0
- package/scripts/vendor-contract-test-lib.mjs +182 -0
- package/scripts/vendor-contract-test.mjs +55 -0
- package/scripts/vercel/build-mkdocs.sh +9 -0
- package/scripts/vercel/ignore-mkdocs.sh +25 -0
- package/scripts/vercel/install-mkdocs.sh +6 -0
- package/scripts/verify-pg.js +217 -0
- package/scripts/x402/receipt-verify.mjs +289 -0
- package/services/finance-sink/src/dedupe-store.js +29 -6
- package/services/receiver/src/dedupe-store.js +29 -5
- package/services/x402-gateway/Dockerfile +13 -0
- package/services/x402-gateway/README.md +58 -0
- package/services/x402-gateway/examples/upstream-mock.js +337 -0
- package/services/x402-gateway/src/server.js +1058 -0
- package/src/api/app.js +34658 -16940
- package/src/api/maintenance.js +70 -0
- package/src/api/middleware/trust-kernel.js +114 -0
- package/src/api/openapi.js +1778 -70
- package/src/api/persistence.js +456 -0
- package/src/api/server.js +81 -5
- package/src/api/store.js +1581 -62
- package/src/api/workers/deliveries.js +99 -4
- package/src/api/workers/insolvency-sweep.js +159 -0
- package/src/core/agent-card.js +69 -0
- package/src/core/agent-wallets.js +231 -0
- package/src/core/agreement-delegation.js +549 -0
- package/src/core/billing-plans.js +40 -6
- package/src/core/circle-reserve-adapter.js +845 -0
- package/src/core/event-policy.js +21 -2
- package/src/core/maintenance-locks.js +1 -0
- package/src/core/operator-action.js +303 -0
- package/src/core/paid-tool-manifest.js +318 -0
- package/src/core/policy-decision.js +322 -0
- package/src/core/policy-packs.js +207 -0
- package/src/core/profile-fingerprint.js +27 -0
- package/src/core/profile-simulation-reasons.js +84 -0
- package/src/core/profile-templates.js +242 -0
- package/src/core/provider-publish-conformance.js +525 -0
- package/src/core/provider-publish-proof.js +396 -0
- package/src/core/provider-quote-signature.js +170 -0
- package/src/core/settld-keys.js +112 -0
- package/src/core/settld-pay-token.js +344 -0
- package/src/core/settlement-kernel.js +239 -2
- package/src/core/settlement-verifier.js +335 -0
- package/src/core/tool-call-agreement.js +112 -0
- package/src/core/tool-call-evidence.js +144 -0
- package/src/core/tool-provider-signature.js +98 -0
- package/src/core/wallet-assignment-resolver.js +129 -0
- package/src/core/wallet-provider-bootstrap.js +365 -0
- package/src/core/x402-escalation-override.js +258 -0
- package/src/core/x402-gate.js +118 -0
- package/src/core/x402-provider-refund-decision.js +220 -0
- package/src/core/x402-receipt-verifier.js +708 -0
- package/src/core/x402-reversal-command.js +251 -0
- package/src/core/x402-wallet-issuer-decision.js +252 -0
- package/src/core/zk-verifier.js +300 -0
- package/src/db/migrations/029_reputation_event_index.sql +54 -0
- package/src/db/migrations/030_artifacts_source_event_unique_job_only.sql +15 -0
- package/src/db/pg.js +18 -7
- package/src/db/store-pg.js +1508 -111
|
@@ -0,0 +1,877 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { canonicalJsonStringify } from "../../src/core/canonical-json.js";
|
|
5
|
+
import { sha256Hex, signHashHexEd25519 } from "../../src/core/crypto.js";
|
|
6
|
+
import { computeArtifactHash } from "../../src/core/artifacts.js";
|
|
7
|
+
import { createChainedEvent, appendChainedEvent } from "../../src/core/event-chain.js";
|
|
8
|
+
import { buildJobProofBundleV1, buildMonthProofBundleV1 } from "../../src/core/proof-bundle.js";
|
|
9
|
+
import { buildFinancePackBundleV1 } from "../../src/core/finance-pack-bundle.js";
|
|
10
|
+
import { buildInvoiceBundleV1 } from "../../src/core/invoice-bundle.js";
|
|
11
|
+
import { buildClosePackBundleV1 } from "../../src/core/close-pack-bundle.js";
|
|
12
|
+
import { GOVERNANCE_STREAM_ID } from "../../src/core/governance.js";
|
|
13
|
+
import { DEFAULT_TENANT_ID } from "../../src/core/tenancy.js";
|
|
14
|
+
import { buildGovernancePolicyV2Unsigned } from "../../src/core/governance-policy.js";
|
|
15
|
+
import { writeFilesToDir } from "../proof-bundle/lib.mjs";
|
|
16
|
+
|
|
17
|
+
function usage() {
|
|
18
|
+
// eslint-disable-next-line no-console
|
|
19
|
+
console.error("usage: node scripts/fixtures/generate-bundle-fixtures.mjs [--out <dir>]");
|
|
20
|
+
process.exit(2);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function bytes(text) {
|
|
24
|
+
return new TextEncoder().encode(text);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function ensureEmptyDir(dir) {
|
|
28
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
29
|
+
await fs.mkdir(dir, { recursive: true });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function prepareOutDir(outDir) {
|
|
33
|
+
await fs.mkdir(outDir, { recursive: true });
|
|
34
|
+
await ensureEmptyDir(path.join(outDir, "jobproof"));
|
|
35
|
+
await ensureEmptyDir(path.join(outDir, "monthproof"));
|
|
36
|
+
await ensureEmptyDir(path.join(outDir, "financepack"));
|
|
37
|
+
await ensureEmptyDir(path.join(outDir, "invoicebundle"));
|
|
38
|
+
await ensureEmptyDir(path.join(outDir, "closepack"));
|
|
39
|
+
await fs.rm(path.join(outDir, "trust.json"), { force: true });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function readFixtureKeypairs() {
|
|
43
|
+
const p = path.resolve(process.cwd(), "test", "fixtures", "keys", "fixture_keypairs.json");
|
|
44
|
+
const raw = await fs.readFile(p, "utf8");
|
|
45
|
+
return JSON.parse(raw);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function stripVerificationReportSig(report) {
|
|
49
|
+
const { reportHash: _h, signature: _sig, ...rest } = report ?? {};
|
|
50
|
+
return rest;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function resignVerificationReport({ report, signer }) {
|
|
54
|
+
const core = stripVerificationReportSig(report);
|
|
55
|
+
const reportHash = sha256Hex(canonicalJsonStringify(core));
|
|
56
|
+
const signature = signHashHexEd25519(reportHash, signer.privateKeyPem);
|
|
57
|
+
return { ...core, reportHash, signature };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function buildGovernanceEvents({ tenantId, serverKeys }) {
|
|
61
|
+
let governanceEvents = [];
|
|
62
|
+
governanceEvents = appendChainedEvent({
|
|
63
|
+
events: governanceEvents,
|
|
64
|
+
signer: serverKeys.signerA,
|
|
65
|
+
event: createChainedEvent({
|
|
66
|
+
id: "evt_gov_serverA_registered",
|
|
67
|
+
streamId: GOVERNANCE_STREAM_ID,
|
|
68
|
+
type: "SERVER_SIGNER_KEY_REGISTERED",
|
|
69
|
+
at: "2026-01-01T00:00:00.000Z",
|
|
70
|
+
actor: { type: "system", id: "proxy" },
|
|
71
|
+
payload: {
|
|
72
|
+
tenantId: DEFAULT_TENANT_ID,
|
|
73
|
+
keyId: serverKeys.serverA.keyId,
|
|
74
|
+
publicKeyPem: serverKeys.serverA.publicKeyPem,
|
|
75
|
+
registeredAt: "2026-01-01T00:00:00.000Z",
|
|
76
|
+
reason: "fixture"
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
});
|
|
80
|
+
return governanceEvents;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function governanceSnapshotFor(events) {
|
|
84
|
+
const last = events.at(-1) ?? null;
|
|
85
|
+
return { streamId: GOVERNANCE_STREAM_ID, lastChainHash: last?.chainHash ?? null, lastEventId: last?.id ?? null };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function buildJobProofBase({
|
|
89
|
+
tenantId,
|
|
90
|
+
jobId,
|
|
91
|
+
generatedAt,
|
|
92
|
+
serverKeys,
|
|
93
|
+
govSigner,
|
|
94
|
+
timeSigner,
|
|
95
|
+
governancePolicy,
|
|
96
|
+
revocationList,
|
|
97
|
+
includeTimestampProof,
|
|
98
|
+
toolVersion,
|
|
99
|
+
toolCommit
|
|
100
|
+
}) {
|
|
101
|
+
const governanceEvents = buildGovernanceEvents({ tenantId, serverKeys });
|
|
102
|
+
const governanceSnapshot = governanceSnapshotFor(governanceEvents);
|
|
103
|
+
|
|
104
|
+
let jobEvents = [];
|
|
105
|
+
jobEvents = appendChainedEvent({
|
|
106
|
+
events: jobEvents,
|
|
107
|
+
signer: serverKeys.signerA,
|
|
108
|
+
event: createChainedEvent({
|
|
109
|
+
id: "evt_job_created",
|
|
110
|
+
streamId: jobId,
|
|
111
|
+
type: "JOB_CREATED",
|
|
112
|
+
at: generatedAt,
|
|
113
|
+
actor: { type: "system", id: "proxy" },
|
|
114
|
+
payload: { jobId }
|
|
115
|
+
})
|
|
116
|
+
});
|
|
117
|
+
const jobSnapshot = { id: jobId, lastChainHash: jobEvents.at(-1)?.chainHash ?? null, lastEventId: jobEvents.at(-1)?.id ?? null };
|
|
118
|
+
|
|
119
|
+
const publicKeyByKeyId = new Map([
|
|
120
|
+
[serverKeys.serverA.keyId, serverKeys.serverA.publicKeyPem],
|
|
121
|
+
[serverKeys.serverB.keyId, serverKeys.serverB.publicKeyPem]
|
|
122
|
+
]);
|
|
123
|
+
|
|
124
|
+
const { files } = buildJobProofBundleV1({
|
|
125
|
+
tenantId,
|
|
126
|
+
jobId,
|
|
127
|
+
jobEvents,
|
|
128
|
+
jobSnapshot,
|
|
129
|
+
governanceEvents,
|
|
130
|
+
governanceSnapshot,
|
|
131
|
+
tenantGovernanceEvents: [],
|
|
132
|
+
tenantGovernanceSnapshot: { streamId: GOVERNANCE_STREAM_ID, lastChainHash: null, lastEventId: null },
|
|
133
|
+
governancePolicy: governancePolicy ?? null,
|
|
134
|
+
governancePolicySigner: govSigner,
|
|
135
|
+
revocationList: revocationList ?? null,
|
|
136
|
+
artifacts: [],
|
|
137
|
+
contractDocsByHash: new Map(),
|
|
138
|
+
publicKeyByKeyId,
|
|
139
|
+
signerKeys: [],
|
|
140
|
+
manifestSigner: serverKeys.signerA,
|
|
141
|
+
verificationReportSigner: serverKeys.signerA,
|
|
142
|
+
timestampAuthoritySigner: includeTimestampProof ? timeSigner : null,
|
|
143
|
+
toolVersion: toolVersion ?? null,
|
|
144
|
+
toolCommit: toolCommit ?? null,
|
|
145
|
+
requireHeadAttestation: true,
|
|
146
|
+
generatedAt
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
return files;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function buildMonthProofBase({
|
|
153
|
+
tenantId,
|
|
154
|
+
period,
|
|
155
|
+
basis,
|
|
156
|
+
generatedAt,
|
|
157
|
+
serverKeys,
|
|
158
|
+
govSigner,
|
|
159
|
+
timeSigner,
|
|
160
|
+
governancePolicy,
|
|
161
|
+
revocationList,
|
|
162
|
+
includeTimestampProof,
|
|
163
|
+
toolVersion,
|
|
164
|
+
toolCommit
|
|
165
|
+
}) {
|
|
166
|
+
const governanceEvents = buildGovernanceEvents({ tenantId, serverKeys });
|
|
167
|
+
const governanceSnapshot = governanceSnapshotFor(governanceEvents);
|
|
168
|
+
|
|
169
|
+
let monthEvents = [];
|
|
170
|
+
monthEvents = appendChainedEvent({
|
|
171
|
+
events: monthEvents,
|
|
172
|
+
signer: serverKeys.signerA,
|
|
173
|
+
event: createChainedEvent({
|
|
174
|
+
id: "evt_month_close_requested",
|
|
175
|
+
streamId: `month_${period}`,
|
|
176
|
+
type: "MONTH_CLOSE_REQUESTED",
|
|
177
|
+
at: generatedAt,
|
|
178
|
+
actor: { type: "system", id: "proxy" },
|
|
179
|
+
payload: { period, basis }
|
|
180
|
+
})
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const publicKeyByKeyId = new Map([
|
|
184
|
+
[serverKeys.serverA.keyId, serverKeys.serverA.publicKeyPem],
|
|
185
|
+
[serverKeys.serverB.keyId, serverKeys.serverB.publicKeyPem]
|
|
186
|
+
]);
|
|
187
|
+
|
|
188
|
+
const { files, bundle } = buildMonthProofBundleV1({
|
|
189
|
+
tenantId,
|
|
190
|
+
period,
|
|
191
|
+
basis,
|
|
192
|
+
monthEvents,
|
|
193
|
+
governanceEvents,
|
|
194
|
+
governanceSnapshot,
|
|
195
|
+
tenantGovernanceEvents: [],
|
|
196
|
+
tenantGovernanceSnapshot: { streamId: GOVERNANCE_STREAM_ID, lastChainHash: null, lastEventId: null },
|
|
197
|
+
governancePolicy: governancePolicy ?? null,
|
|
198
|
+
governancePolicySigner: govSigner,
|
|
199
|
+
revocationList: revocationList ?? null,
|
|
200
|
+
artifacts: [],
|
|
201
|
+
contractDocsByHash: new Map(),
|
|
202
|
+
publicKeyByKeyId,
|
|
203
|
+
signerKeys: [],
|
|
204
|
+
manifestSigner: serverKeys.signerA,
|
|
205
|
+
verificationReportSigner: serverKeys.signerA,
|
|
206
|
+
timestampAuthoritySigner: includeTimestampProof ? timeSigner : null,
|
|
207
|
+
toolVersion: toolVersion ?? null,
|
|
208
|
+
toolCommit: toolCommit ?? null,
|
|
209
|
+
requireHeadAttestation: true,
|
|
210
|
+
generatedAt
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
return { files, bundle };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function buildFinancePackBase({ tenantId, period, createdAt, serverKeys, govSigner, monthProof, toolCommit }) {
|
|
217
|
+
const glBatch = { artifactType: "GLBatch.v1", schemaVersion: "GLBatch.v1", artifactId: "gl_fixture", tenantId, period, basis: "settledAt", batch: { lines: [] } };
|
|
218
|
+
glBatch.artifactHash = computeArtifactHash(glBatch);
|
|
219
|
+
|
|
220
|
+
const csvText = "a,b\n1,2\n";
|
|
221
|
+
const csvSha256 = sha256Hex(bytes(csvText));
|
|
222
|
+
const journalCsv = {
|
|
223
|
+
artifactType: "JournalCsv.v1",
|
|
224
|
+
schemaVersion: "JournalCsv.v1",
|
|
225
|
+
artifactId: "csv_fixture",
|
|
226
|
+
tenantId,
|
|
227
|
+
period,
|
|
228
|
+
basis: "settledAt",
|
|
229
|
+
accountMapHash: "h_map_fixture",
|
|
230
|
+
csv: csvText,
|
|
231
|
+
csvSha256
|
|
232
|
+
};
|
|
233
|
+
journalCsv.artifactHash = computeArtifactHash(journalCsv);
|
|
234
|
+
|
|
235
|
+
const reconcile = { ok: true, period, basis: "settledAt", entryCount: 0, totalsKeys: 0 };
|
|
236
|
+
const reconcileBytes = bytes(`${canonicalJsonStringify(reconcile)}\n`);
|
|
237
|
+
|
|
238
|
+
const { files } = buildFinancePackBundleV1({
|
|
239
|
+
tenantId,
|
|
240
|
+
period,
|
|
241
|
+
protocol: "1.0",
|
|
242
|
+
createdAt,
|
|
243
|
+
governancePolicySigner: govSigner,
|
|
244
|
+
monthProofBundle: monthProof.bundle,
|
|
245
|
+
monthProofFiles: monthProof.files,
|
|
246
|
+
requireMonthProofAttestation: true,
|
|
247
|
+
requireHeadAttestation: true,
|
|
248
|
+
manifestSigner: serverKeys.signerA,
|
|
249
|
+
verificationReportSigner: serverKeys.signerA,
|
|
250
|
+
glBatchArtifact: glBatch,
|
|
251
|
+
journalCsvArtifact: journalCsv,
|
|
252
|
+
reconcileReport: reconcile,
|
|
253
|
+
reconcileReportBytes: reconcileBytes,
|
|
254
|
+
toolVersion: "0.0.0-fixture",
|
|
255
|
+
toolCommit: toolCommit ?? null
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
return files;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function buildInvoiceBundleBase({
|
|
262
|
+
tenantId,
|
|
263
|
+
invoiceId,
|
|
264
|
+
createdAt,
|
|
265
|
+
serverKeys,
|
|
266
|
+
govSigner,
|
|
267
|
+
jobProofFiles,
|
|
268
|
+
toolCommit,
|
|
269
|
+
pricingMatrix,
|
|
270
|
+
meteringReport,
|
|
271
|
+
invoiceClaim,
|
|
272
|
+
pricingMatrixSigners = null,
|
|
273
|
+
pricingMatrixSignaturesOverride = undefined
|
|
274
|
+
}) {
|
|
275
|
+
const jobManifest = JSON.parse(new TextDecoder().decode(jobProofFiles.get("manifest.json")));
|
|
276
|
+
const jobAtt = JSON.parse(new TextDecoder().decode(jobProofFiles.get("attestation/bundle_head_attestation.json")));
|
|
277
|
+
const jobProofBundle = { manifestHash: String(jobManifest?.manifestHash ?? "") };
|
|
278
|
+
|
|
279
|
+
const { files } = buildInvoiceBundleV1({
|
|
280
|
+
tenantId,
|
|
281
|
+
invoiceId,
|
|
282
|
+
protocol: "1.0",
|
|
283
|
+
createdAt,
|
|
284
|
+
governancePolicySigner: govSigner,
|
|
285
|
+
pricingMatrixSigners,
|
|
286
|
+
pricingMatrixSignaturesOverride,
|
|
287
|
+
jobProofBundle,
|
|
288
|
+
jobProofFiles,
|
|
289
|
+
requireJobProofAttestation: true,
|
|
290
|
+
requireHeadAttestation: true,
|
|
291
|
+
manifestSigner: serverKeys.signerA,
|
|
292
|
+
verificationReportSigner: serverKeys.signerA,
|
|
293
|
+
toolVersion: "0.0.0-fixture",
|
|
294
|
+
toolCommit: toolCommit ?? null,
|
|
295
|
+
pricingMatrix,
|
|
296
|
+
meteringReport,
|
|
297
|
+
invoiceClaim:
|
|
298
|
+
invoiceClaim ??
|
|
299
|
+
null
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
// Ensure caller can construct binding objects without re-parsing.
|
|
303
|
+
return { files, jobProof: { embeddedPath: "payload/job_proof_bundle", manifestHash: jobManifest.manifestHash, headAttestationHash: jobAtt.attestationHash } };
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
async function main() {
|
|
307
|
+
const argv = process.argv.slice(2);
|
|
308
|
+
let outDir = path.resolve(process.cwd(), "test", "fixtures", "bundles", "v1");
|
|
309
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
310
|
+
const a = argv[i];
|
|
311
|
+
if (a === "--out") {
|
|
312
|
+
outDir = path.resolve(process.cwd(), String(argv[i + 1] ?? ""));
|
|
313
|
+
if (!outDir) usage();
|
|
314
|
+
i += 1;
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
if (a === "--help" || a === "-h") usage();
|
|
318
|
+
usage();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const keypairs = await readFixtureKeypairs();
|
|
322
|
+
const govSigner = { keyId: keypairs.govRoot.keyId, privateKeyPem: keypairs.govRoot.privateKeyPem };
|
|
323
|
+
const timeSigner = { keyId: keypairs.timeAuthority.keyId, privateKeyPem: keypairs.timeAuthority.privateKeyPem };
|
|
324
|
+
const serverKeys = {
|
|
325
|
+
serverA: keypairs.serverA,
|
|
326
|
+
serverB: keypairs.serverB,
|
|
327
|
+
signerA: { keyId: keypairs.serverA.keyId, privateKeyPem: keypairs.serverA.privateKeyPem }
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
await prepareOutDir(outDir);
|
|
331
|
+
|
|
332
|
+
const tenantId = "tenant_fixture";
|
|
333
|
+
const generatedAt = "2026-02-02T00:00:00.000Z";
|
|
334
|
+
const toolVersion = "0.0.0-fixture";
|
|
335
|
+
const toolCommit = "0123456789abcdef0123456789abcdef01234567";
|
|
336
|
+
|
|
337
|
+
let jobProofStrictPass = null;
|
|
338
|
+
|
|
339
|
+
// JobProof fixtures
|
|
340
|
+
{
|
|
341
|
+
const base = buildJobProofBase({
|
|
342
|
+
tenantId,
|
|
343
|
+
jobId: "job_fixture_1",
|
|
344
|
+
generatedAt,
|
|
345
|
+
serverKeys: { ...serverKeys, signerA: serverKeys.signerA, signerB: { keyId: keypairs.serverB.keyId, privateKeyPem: keypairs.serverB.privateKeyPem } },
|
|
346
|
+
govSigner,
|
|
347
|
+
timeSigner,
|
|
348
|
+
includeTimestampProof: false,
|
|
349
|
+
toolVersion,
|
|
350
|
+
toolCommit
|
|
351
|
+
});
|
|
352
|
+
jobProofStrictPass = base;
|
|
353
|
+
const dir = path.join(outDir, "jobproof", "strict-pass");
|
|
354
|
+
await ensureEmptyDir(dir);
|
|
355
|
+
writeFilesToDir({ files: base, outDir: dir });
|
|
356
|
+
|
|
357
|
+
const missingReport = new Map(base);
|
|
358
|
+
missingReport.delete("verify/verification_report.json");
|
|
359
|
+
const dirMissingStrict = path.join(outDir, "jobproof", "strict-fail-missing-verification-report");
|
|
360
|
+
await ensureEmptyDir(dirMissingStrict);
|
|
361
|
+
writeFilesToDir({ files: missingReport, outDir: dirMissingStrict });
|
|
362
|
+
|
|
363
|
+
const dirMissingNonStrict = path.join(outDir, "jobproof", "nonstrict-pass-missing-verification-report");
|
|
364
|
+
await ensureEmptyDir(dirMissingNonStrict);
|
|
365
|
+
writeFilesToDir({ files: missingReport, outDir: dirMissingNonStrict });
|
|
366
|
+
|
|
367
|
+
const tamper = new Map(base);
|
|
368
|
+
const snap = new TextDecoder().decode(tamper.get("job/snapshot.json"));
|
|
369
|
+
tamper.set("job/snapshot.json", bytes(snap.replace("\"id\":\"job_fixture_1\"", "\"id\":\"job_fixture_1_tampered\"")));
|
|
370
|
+
const dirTamper = path.join(outDir, "jobproof", "strict-fail-manifest-tamper");
|
|
371
|
+
await ensureEmptyDir(dirTamper);
|
|
372
|
+
writeFilesToDir({ files: tamper, outDir: dirTamper });
|
|
373
|
+
|
|
374
|
+
const bindingMismatch = new Map(base);
|
|
375
|
+
const report = JSON.parse(new TextDecoder().decode(bindingMismatch.get("verify/verification_report.json")));
|
|
376
|
+
report.bundleHeadAttestation = { ...(report.bundleHeadAttestation ?? {}), attestationHash: "0".repeat(64) };
|
|
377
|
+
const resigned = resignVerificationReport({ report, signer: serverKeys.signerA });
|
|
378
|
+
bindingMismatch.set("verify/verification_report.json", bytes(`${canonicalJsonStringify(resigned)}\n`));
|
|
379
|
+
const dirBinding = path.join(outDir, "jobproof", "strict-fail-verification-report-binding-mismatch");
|
|
380
|
+
await ensureEmptyDir(dirBinding);
|
|
381
|
+
writeFilesToDir({ files: bindingMismatch, outDir: dirBinding });
|
|
382
|
+
|
|
383
|
+
const unauthorizedPolicy = buildGovernancePolicyV2Unsigned({
|
|
384
|
+
policyId: "governance_policy_fixture_deny_serverA",
|
|
385
|
+
generatedAt,
|
|
386
|
+
revocationList: { path: "governance/revocations.json", sha256: "0".repeat(64) },
|
|
387
|
+
verificationReportSigners: [
|
|
388
|
+
{
|
|
389
|
+
subjectType: "JobProofBundle.v1",
|
|
390
|
+
allowedScopes: ["global", "tenant"],
|
|
391
|
+
allowedKeyIds: [keypairs.serverA.keyId],
|
|
392
|
+
requireGoverned: true,
|
|
393
|
+
requiredPurpose: "server"
|
|
394
|
+
}
|
|
395
|
+
],
|
|
396
|
+
bundleHeadAttestationSigners: [
|
|
397
|
+
{
|
|
398
|
+
subjectType: "JobProofBundle.v1",
|
|
399
|
+
allowedScopes: ["global", "tenant"],
|
|
400
|
+
allowedKeyIds: [keypairs.serverB.keyId],
|
|
401
|
+
requireGoverned: true,
|
|
402
|
+
requiredPurpose: "server"
|
|
403
|
+
}
|
|
404
|
+
]
|
|
405
|
+
});
|
|
406
|
+
const unauthorized = buildJobProofBase({
|
|
407
|
+
tenantId,
|
|
408
|
+
jobId: "job_fixture_unauthorized",
|
|
409
|
+
generatedAt,
|
|
410
|
+
serverKeys: { ...serverKeys, signerA: serverKeys.signerA, signerB: { keyId: keypairs.serverB.keyId, privateKeyPem: keypairs.serverB.privateKeyPem } },
|
|
411
|
+
govSigner,
|
|
412
|
+
timeSigner,
|
|
413
|
+
governancePolicy: unauthorizedPolicy,
|
|
414
|
+
includeTimestampProof: false,
|
|
415
|
+
toolVersion,
|
|
416
|
+
toolCommit
|
|
417
|
+
});
|
|
418
|
+
const dirUnauthorized = path.join(outDir, "jobproof", "strict-fail-unauthorized-signer");
|
|
419
|
+
await ensureEmptyDir(dirUnauthorized);
|
|
420
|
+
writeFilesToDir({ files: unauthorized, outDir: dirUnauthorized });
|
|
421
|
+
|
|
422
|
+
const revokedAt = "2026-02-02T00:00:00.000Z";
|
|
423
|
+
const revokedList = {
|
|
424
|
+
schemaVersion: "RevocationList.v1",
|
|
425
|
+
listId: "revocations_fixture_v1",
|
|
426
|
+
generatedAt,
|
|
427
|
+
rotations: [],
|
|
428
|
+
revocations: [{ keyId: keypairs.serverA.keyId, revokedAt, reason: "fixture", scope: null }],
|
|
429
|
+
signerKeyId: null,
|
|
430
|
+
signedAt: null,
|
|
431
|
+
listHash: null,
|
|
432
|
+
signature: null
|
|
433
|
+
};
|
|
434
|
+
const revokedAfter = buildJobProofBase({
|
|
435
|
+
tenantId,
|
|
436
|
+
jobId: "job_fixture_revoked_after",
|
|
437
|
+
generatedAt: revokedAt,
|
|
438
|
+
serverKeys: { ...serverKeys, signerA: serverKeys.signerA, signerB: { keyId: keypairs.serverB.keyId, privateKeyPem: keypairs.serverB.privateKeyPem } },
|
|
439
|
+
govSigner,
|
|
440
|
+
timeSigner,
|
|
441
|
+
revocationList: revokedList,
|
|
442
|
+
includeTimestampProof: true,
|
|
443
|
+
toolVersion,
|
|
444
|
+
toolCommit
|
|
445
|
+
});
|
|
446
|
+
const dirRevokedAfter = path.join(outDir, "jobproof", "strict-fail-revoked-at-or-after-with-timeproof");
|
|
447
|
+
await ensureEmptyDir(dirRevokedAfter);
|
|
448
|
+
writeFilesToDir({ files: revokedAfter, outDir: dirRevokedAfter });
|
|
449
|
+
|
|
450
|
+
const revokedBeforeList = {
|
|
451
|
+
...revokedList,
|
|
452
|
+
revocations: [{ keyId: keypairs.serverA.keyId, revokedAt: "2026-02-02T00:00:10.000Z", reason: "fixture", scope: null }]
|
|
453
|
+
};
|
|
454
|
+
const revokedNoProof = buildJobProofBase({
|
|
455
|
+
tenantId,
|
|
456
|
+
jobId: "job_fixture_revoked_before_noproof",
|
|
457
|
+
generatedAt: "2026-02-02T00:00:01.000Z",
|
|
458
|
+
serverKeys: { ...serverKeys, signerA: serverKeys.signerA, signerB: { keyId: keypairs.serverB.keyId, privateKeyPem: keypairs.serverB.privateKeyPem } },
|
|
459
|
+
govSigner,
|
|
460
|
+
timeSigner,
|
|
461
|
+
revocationList: revokedBeforeList,
|
|
462
|
+
includeTimestampProof: false,
|
|
463
|
+
toolVersion,
|
|
464
|
+
toolCommit
|
|
465
|
+
});
|
|
466
|
+
const dirRevokedNoProof = path.join(outDir, "jobproof", "strict-fail-revoked-before-without-timeproof");
|
|
467
|
+
await ensureEmptyDir(dirRevokedNoProof);
|
|
468
|
+
writeFilesToDir({ files: revokedNoProof, outDir: dirRevokedNoProof });
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// MonthProof fixtures (standalone)
|
|
472
|
+
const monthProof = buildMonthProofBase({
|
|
473
|
+
tenantId,
|
|
474
|
+
period: "2026-01",
|
|
475
|
+
basis: "settledAt",
|
|
476
|
+
generatedAt,
|
|
477
|
+
serverKeys: { ...serverKeys, signerA: serverKeys.signerA, signerB: { keyId: keypairs.serverB.keyId, privateKeyPem: keypairs.serverB.privateKeyPem } },
|
|
478
|
+
govSigner,
|
|
479
|
+
timeSigner,
|
|
480
|
+
includeTimestampProof: false,
|
|
481
|
+
toolVersion,
|
|
482
|
+
toolCommit
|
|
483
|
+
});
|
|
484
|
+
{
|
|
485
|
+
const dir = path.join(outDir, "monthproof", "strict-pass");
|
|
486
|
+
await ensureEmptyDir(dir);
|
|
487
|
+
writeFilesToDir({ files: monthProof.files, outDir: dir });
|
|
488
|
+
|
|
489
|
+
const missingReport = new Map(monthProof.files);
|
|
490
|
+
missingReport.delete("verify/verification_report.json");
|
|
491
|
+
const dirMissingStrict = path.join(outDir, "monthproof", "strict-fail-missing-verification-report");
|
|
492
|
+
await ensureEmptyDir(dirMissingStrict);
|
|
493
|
+
writeFilesToDir({ files: missingReport, outDir: dirMissingStrict });
|
|
494
|
+
|
|
495
|
+
const dirMissingNonStrict = path.join(outDir, "monthproof", "nonstrict-pass-missing-verification-report");
|
|
496
|
+
await ensureEmptyDir(dirMissingNonStrict);
|
|
497
|
+
writeFilesToDir({ files: missingReport, outDir: dirMissingNonStrict });
|
|
498
|
+
|
|
499
|
+
const tamper = new Map(monthProof.files);
|
|
500
|
+
const eventsRaw = new TextDecoder().decode(tamper.get("events/events.jsonl"));
|
|
501
|
+
tamper.set("events/events.jsonl", bytes(`${eventsRaw}\n`));
|
|
502
|
+
const dirTamper = path.join(outDir, "monthproof", "strict-fail-manifest-tamper");
|
|
503
|
+
await ensureEmptyDir(dirTamper);
|
|
504
|
+
writeFilesToDir({ files: tamper, outDir: dirTamper });
|
|
505
|
+
|
|
506
|
+
const unauthorizedPolicy = buildGovernancePolicyV2Unsigned({
|
|
507
|
+
policyId: "governance_policy_fixture_deny_month_serverA",
|
|
508
|
+
generatedAt,
|
|
509
|
+
revocationList: { path: "governance/revocations.json", sha256: "0".repeat(64) },
|
|
510
|
+
verificationReportSigners: [
|
|
511
|
+
{
|
|
512
|
+
subjectType: "MonthProofBundle.v1",
|
|
513
|
+
allowedScopes: ["global", "tenant"],
|
|
514
|
+
allowedKeyIds: [keypairs.serverA.keyId],
|
|
515
|
+
requireGoverned: true,
|
|
516
|
+
requiredPurpose: "server"
|
|
517
|
+
}
|
|
518
|
+
],
|
|
519
|
+
bundleHeadAttestationSigners: [
|
|
520
|
+
{
|
|
521
|
+
subjectType: "MonthProofBundle.v1",
|
|
522
|
+
allowedScopes: ["global", "tenant"],
|
|
523
|
+
allowedKeyIds: [keypairs.serverB.keyId],
|
|
524
|
+
requireGoverned: true,
|
|
525
|
+
requiredPurpose: "server"
|
|
526
|
+
}
|
|
527
|
+
]
|
|
528
|
+
});
|
|
529
|
+
const monthUnauthorized = buildMonthProofBase({
|
|
530
|
+
tenantId,
|
|
531
|
+
period: "2026-01",
|
|
532
|
+
basis: "settledAt",
|
|
533
|
+
generatedAt,
|
|
534
|
+
serverKeys: { ...serverKeys, signerA: serverKeys.signerA, signerB: { keyId: keypairs.serverB.keyId, privateKeyPem: keypairs.serverB.privateKeyPem } },
|
|
535
|
+
govSigner,
|
|
536
|
+
timeSigner,
|
|
537
|
+
governancePolicy: unauthorizedPolicy,
|
|
538
|
+
includeTimestampProof: false,
|
|
539
|
+
toolVersion,
|
|
540
|
+
toolCommit
|
|
541
|
+
});
|
|
542
|
+
const dirUnauthorized = path.join(outDir, "monthproof", "strict-fail-unauthorized-signer");
|
|
543
|
+
await ensureEmptyDir(dirUnauthorized);
|
|
544
|
+
writeFilesToDir({ files: monthUnauthorized.files, outDir: dirUnauthorized });
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// FinancePack fixtures (with embedded MonthProof)
|
|
548
|
+
{
|
|
549
|
+
const finance = buildFinancePackBase({ tenantId, period: "2026-01", createdAt: generatedAt, serverKeys, govSigner, monthProof, toolCommit });
|
|
550
|
+
const dir = path.join(outDir, "financepack", "strict-pass");
|
|
551
|
+
await ensureEmptyDir(dir);
|
|
552
|
+
writeFilesToDir({ files: finance, outDir: dir });
|
|
553
|
+
|
|
554
|
+
const missingReport = new Map(finance);
|
|
555
|
+
missingReport.delete("verify/verification_report.json");
|
|
556
|
+
const dirMissingStrict = path.join(outDir, "financepack", "strict-fail-missing-verification-report");
|
|
557
|
+
await ensureEmptyDir(dirMissingStrict);
|
|
558
|
+
writeFilesToDir({ files: missingReport, outDir: dirMissingStrict });
|
|
559
|
+
|
|
560
|
+
const dirMissingNonStrict = path.join(outDir, "financepack", "nonstrict-pass-missing-verification-report");
|
|
561
|
+
await ensureEmptyDir(dirMissingNonStrict);
|
|
562
|
+
writeFilesToDir({ files: missingReport, outDir: dirMissingNonStrict });
|
|
563
|
+
|
|
564
|
+
const tamper = new Map(finance);
|
|
565
|
+
const reconcileRaw = new TextDecoder().decode(tamper.get("finance/reconcile.json"));
|
|
566
|
+
tamper.set("finance/reconcile.json", bytes(`${reconcileRaw}\n`));
|
|
567
|
+
const dirTamper = path.join(outDir, "financepack", "strict-fail-manifest-tamper");
|
|
568
|
+
await ensureEmptyDir(dirTamper);
|
|
569
|
+
writeFilesToDir({ files: tamper, outDir: dirTamper });
|
|
570
|
+
|
|
571
|
+
const financeToolUnknown = new Map(finance);
|
|
572
|
+
const report = JSON.parse(new TextDecoder().decode(financeToolUnknown.get("verify/verification_report.json")));
|
|
573
|
+
report.tool = { ...(report.tool ?? {}), version: null };
|
|
574
|
+
// Recompute hash/signature as if the producer couldn't resolve a version.
|
|
575
|
+
report.warnings = Array.isArray(report.warnings) ? [...report.warnings, { code: "TOOL_VERSION_UNKNOWN" }] : [{ code: "TOOL_VERSION_UNKNOWN" }];
|
|
576
|
+
const core = (() => {
|
|
577
|
+
const { reportHash: _h, signature: _sig, ...rest } = report;
|
|
578
|
+
return rest;
|
|
579
|
+
})();
|
|
580
|
+
const reportHash = sha256Hex(canonicalJsonStringify(core));
|
|
581
|
+
const signature = signHashHexEd25519(reportHash, serverKeys.serverA.privateKeyPem);
|
|
582
|
+
financeToolUnknown.set("verify/verification_report.json", bytes(`${canonicalJsonStringify({ ...core, reportHash, signature })}\n`));
|
|
583
|
+
const dirToolUnknown = path.join(outDir, "financepack", "pass-with-tool-version-unknown-warning");
|
|
584
|
+
await ensureEmptyDir(dirToolUnknown);
|
|
585
|
+
writeFilesToDir({ files: financeToolUnknown, outDir: dirToolUnknown });
|
|
586
|
+
|
|
587
|
+
const financeCommitUnknown = new Map(finance);
|
|
588
|
+
const commitUnknownReport = JSON.parse(new TextDecoder().decode(financeCommitUnknown.get("verify/verification_report.json")));
|
|
589
|
+
if (commitUnknownReport.tool && typeof commitUnknownReport.tool === "object") {
|
|
590
|
+
// Optional fields should be omitted when absent.
|
|
591
|
+
delete commitUnknownReport.tool.commit;
|
|
592
|
+
}
|
|
593
|
+
commitUnknownReport.warnings = Array.isArray(commitUnknownReport.warnings)
|
|
594
|
+
? [...commitUnknownReport.warnings, { code: "TOOL_COMMIT_UNKNOWN" }]
|
|
595
|
+
: [{ code: "TOOL_COMMIT_UNKNOWN" }];
|
|
596
|
+
const commitUnknownCore = (() => {
|
|
597
|
+
const { reportHash: _h, signature: _sig, ...rest } = commitUnknownReport;
|
|
598
|
+
return rest;
|
|
599
|
+
})();
|
|
600
|
+
const commitUnknownHash = sha256Hex(canonicalJsonStringify(commitUnknownCore));
|
|
601
|
+
const commitUnknownSig = signHashHexEd25519(commitUnknownHash, serverKeys.serverA.privateKeyPem);
|
|
602
|
+
financeCommitUnknown.set(
|
|
603
|
+
"verify/verification_report.json",
|
|
604
|
+
bytes(`${canonicalJsonStringify({ ...commitUnknownCore, reportHash: commitUnknownHash, signature: commitUnknownSig })}\n`)
|
|
605
|
+
);
|
|
606
|
+
const dirCommitUnknown = path.join(outDir, "financepack", "pass-with-tool-commit-unknown-warning");
|
|
607
|
+
await ensureEmptyDir(dirCommitUnknown);
|
|
608
|
+
writeFilesToDir({ files: financeCommitUnknown, outDir: dirCommitUnknown });
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// InvoiceBundle fixtures (with embedded JobProof)
|
|
612
|
+
{
|
|
613
|
+
if (!(jobProofStrictPass instanceof Map)) throw new Error("jobProofStrictPass not captured");
|
|
614
|
+
const invoiceId = "invoice_fixture_1";
|
|
615
|
+
const pricingMatrix = {
|
|
616
|
+
currency: "USD",
|
|
617
|
+
prices: [{ code: "WORK_MINUTES", unitPriceCents: "150" }]
|
|
618
|
+
};
|
|
619
|
+
const evidenceSha = sha256Hex(jobProofStrictPass.get("job/snapshot.json"));
|
|
620
|
+
const meteringReport = {
|
|
621
|
+
generatedAt,
|
|
622
|
+
items: [{ code: "WORK_MINUTES", quantity: "10" }],
|
|
623
|
+
evidenceRefs: [{ path: "job/snapshot.json", sha256: evidenceSha }]
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
const pass = buildInvoiceBundleBase({
|
|
627
|
+
tenantId,
|
|
628
|
+
invoiceId,
|
|
629
|
+
createdAt: generatedAt,
|
|
630
|
+
serverKeys,
|
|
631
|
+
govSigner,
|
|
632
|
+
jobProofFiles: jobProofStrictPass,
|
|
633
|
+
toolCommit,
|
|
634
|
+
pricingMatrix,
|
|
635
|
+
meteringReport
|
|
636
|
+
});
|
|
637
|
+
const dir = path.join(outDir, "invoicebundle", "strict-pass");
|
|
638
|
+
await ensureEmptyDir(dir);
|
|
639
|
+
writeFilesToDir({ files: pass.files, outDir: dir });
|
|
640
|
+
|
|
641
|
+
const missingReport = new Map(pass.files);
|
|
642
|
+
missingReport.delete("verify/verification_report.json");
|
|
643
|
+
const dirMissingStrict = path.join(outDir, "invoicebundle", "strict-fail-missing-verification-report");
|
|
644
|
+
await ensureEmptyDir(dirMissingStrict);
|
|
645
|
+
writeFilesToDir({ files: missingReport, outDir: dirMissingStrict });
|
|
646
|
+
const dirMissingNonStrict = path.join(outDir, "invoicebundle", "nonstrict-pass-missing-verification-report");
|
|
647
|
+
await ensureEmptyDir(dirMissingNonStrict);
|
|
648
|
+
writeFilesToDir({ files: missingReport, outDir: dirMissingNonStrict });
|
|
649
|
+
|
|
650
|
+
const wrongTotal = buildInvoiceBundleBase({
|
|
651
|
+
tenantId,
|
|
652
|
+
invoiceId: "invoice_fixture_wrong_total",
|
|
653
|
+
createdAt: generatedAt,
|
|
654
|
+
serverKeys,
|
|
655
|
+
govSigner,
|
|
656
|
+
jobProofFiles: jobProofStrictPass,
|
|
657
|
+
toolCommit,
|
|
658
|
+
pricingMatrix,
|
|
659
|
+
meteringReport,
|
|
660
|
+
invoiceClaim: {
|
|
661
|
+
schemaVersion: "InvoiceClaim.v1",
|
|
662
|
+
tenantId,
|
|
663
|
+
invoiceId: "invoice_fixture_wrong_total",
|
|
664
|
+
createdAt: generatedAt,
|
|
665
|
+
currency: "USD",
|
|
666
|
+
jobProof: pass.jobProof,
|
|
667
|
+
totalCents: "999999"
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
const dirWrongTotal = path.join(outDir, "invoicebundle", "strict-fail-invoice-total-mismatch");
|
|
671
|
+
await ensureEmptyDir(dirWrongTotal);
|
|
672
|
+
writeFilesToDir({ files: wrongTotal.files, outDir: dirWrongTotal });
|
|
673
|
+
|
|
674
|
+
const badEvidence = buildInvoiceBundleBase({
|
|
675
|
+
tenantId,
|
|
676
|
+
invoiceId: "invoice_fixture_bad_evidence",
|
|
677
|
+
createdAt: generatedAt,
|
|
678
|
+
serverKeys,
|
|
679
|
+
govSigner,
|
|
680
|
+
jobProofFiles: jobProofStrictPass,
|
|
681
|
+
toolCommit,
|
|
682
|
+
pricingMatrix,
|
|
683
|
+
meteringReport: { ...meteringReport, evidenceRefs: [{ path: "job/snapshot.json", sha256: "0".repeat(64) }] }
|
|
684
|
+
});
|
|
685
|
+
const dirBadEvidence = path.join(outDir, "invoicebundle", "strict-fail-evidence-sha-mismatch");
|
|
686
|
+
await ensureEmptyDir(dirBadEvidence);
|
|
687
|
+
writeFilesToDir({ files: badEvidence.files, outDir: dirBadEvidence });
|
|
688
|
+
|
|
689
|
+
const unknownPricing = buildInvoiceBundleBase({
|
|
690
|
+
tenantId,
|
|
691
|
+
invoiceId: "invoice_fixture_unknown_pricing",
|
|
692
|
+
createdAt: generatedAt,
|
|
693
|
+
serverKeys,
|
|
694
|
+
govSigner,
|
|
695
|
+
jobProofFiles: jobProofStrictPass,
|
|
696
|
+
toolCommit,
|
|
697
|
+
pricingMatrix,
|
|
698
|
+
meteringReport: { ...meteringReport, items: [{ code: "UNKNOWN_CODE", quantity: "1" }] },
|
|
699
|
+
invoiceClaim: {
|
|
700
|
+
schemaVersion: "InvoiceClaim.v1",
|
|
701
|
+
tenantId,
|
|
702
|
+
invoiceId: "invoice_fixture_unknown_pricing",
|
|
703
|
+
createdAt: generatedAt,
|
|
704
|
+
currency: "USD",
|
|
705
|
+
jobProof: pass.jobProof,
|
|
706
|
+
totalCents: "0"
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
const dirUnknownPricing = path.join(outDir, "invoicebundle", "strict-fail-pricing-code-unknown");
|
|
710
|
+
await ensureEmptyDir(dirUnknownPricing);
|
|
711
|
+
writeFilesToDir({ files: unknownPricing.files, outDir: dirUnknownPricing });
|
|
712
|
+
|
|
713
|
+
const unsigned = buildInvoiceBundleBase({
|
|
714
|
+
tenantId,
|
|
715
|
+
invoiceId: "invoice_fixture_unsigned_matrix",
|
|
716
|
+
createdAt: generatedAt,
|
|
717
|
+
serverKeys,
|
|
718
|
+
govSigner,
|
|
719
|
+
jobProofFiles: jobProofStrictPass,
|
|
720
|
+
toolCommit,
|
|
721
|
+
pricingMatrix,
|
|
722
|
+
meteringReport,
|
|
723
|
+
pricingMatrixSigners: []
|
|
724
|
+
});
|
|
725
|
+
const dirUnsignedStrict = path.join(outDir, "invoicebundle", "strict-fail-missing-pricing-matrix-signature");
|
|
726
|
+
await ensureEmptyDir(dirUnsignedStrict);
|
|
727
|
+
writeFilesToDir({ files: unsigned.files, outDir: dirUnsignedStrict });
|
|
728
|
+
const dirUnsignedNonStrict = path.join(outDir, "invoicebundle", "nonstrict-pass-unsigned-pricing-matrix-warning");
|
|
729
|
+
await ensureEmptyDir(dirUnsignedNonStrict);
|
|
730
|
+
writeFilesToDir({ files: unsigned.files, outDir: dirUnsignedNonStrict });
|
|
731
|
+
|
|
732
|
+
const invalidSig = buildInvoiceBundleBase({
|
|
733
|
+
tenantId,
|
|
734
|
+
invoiceId: "invoice_fixture_invalid_matrix_sig",
|
|
735
|
+
createdAt: generatedAt,
|
|
736
|
+
serverKeys,
|
|
737
|
+
govSigner,
|
|
738
|
+
jobProofFiles: jobProofStrictPass,
|
|
739
|
+
toolCommit,
|
|
740
|
+
pricingMatrix,
|
|
741
|
+
meteringReport,
|
|
742
|
+
pricingMatrixSigners: [
|
|
743
|
+
// Claim the buyer's keyId but sign with the wrong private key to force signature verification failure.
|
|
744
|
+
{ keyId: keypairs.govRoot.keyId, privateKeyPem: keypairs.serverA.privateKeyPem }
|
|
745
|
+
]
|
|
746
|
+
});
|
|
747
|
+
const dirInvalidSig = path.join(outDir, "invoicebundle", "strict-fail-invalid-pricing-matrix-signature");
|
|
748
|
+
await ensureEmptyDir(dirInvalidSig);
|
|
749
|
+
writeFilesToDir({ files: invalidSig.files, outDir: dirInvalidSig });
|
|
750
|
+
|
|
751
|
+
// PricingMatrix signature payload mismatch (integrity-valid): pricing matrix altered but signature surface binds to the old canonical hash.
|
|
752
|
+
const passPricingSig = JSON.parse(new TextDecoder().decode(pass.files.get("pricing/pricing_matrix_signatures.json")));
|
|
753
|
+
const pricingAltered = buildInvoiceBundleBase({
|
|
754
|
+
tenantId,
|
|
755
|
+
invoiceId: "invoice_fixture_pricing_altered",
|
|
756
|
+
createdAt: generatedAt,
|
|
757
|
+
serverKeys,
|
|
758
|
+
govSigner,
|
|
759
|
+
jobProofFiles: jobProofStrictPass,
|
|
760
|
+
toolCommit,
|
|
761
|
+
pricingMatrix: { currency: "USD", prices: [{ code: "WORK_MINUTES", unitPriceCents: "151" }] },
|
|
762
|
+
meteringReport,
|
|
763
|
+
pricingMatrixSigners: [],
|
|
764
|
+
pricingMatrixSignaturesOverride: passPricingSig
|
|
765
|
+
});
|
|
766
|
+
const dirPricingAltered = path.join(outDir, "invoicebundle", "strict-fail-pricing-altered");
|
|
767
|
+
await ensureEmptyDir(dirPricingAltered);
|
|
768
|
+
writeFilesToDir({ files: pricingAltered.files, outDir: dirPricingAltered });
|
|
769
|
+
|
|
770
|
+
// ClosePack fixtures (wrap InvoiceBundle)
|
|
771
|
+
{
|
|
772
|
+
const invoiceManifest = JSON.parse(new TextDecoder().decode(pass.files.get("manifest.json")));
|
|
773
|
+
const invoiceBundle = { manifestHash: String(invoiceManifest?.manifestHash ?? "") };
|
|
774
|
+
const closePack = buildClosePackBundleV1({
|
|
775
|
+
tenantId,
|
|
776
|
+
invoiceId,
|
|
777
|
+
protocol: "1.0",
|
|
778
|
+
createdAt: generatedAt,
|
|
779
|
+
governancePolicySigner: govSigner,
|
|
780
|
+
invoiceBundle,
|
|
781
|
+
invoiceBundleFiles: pass.files,
|
|
782
|
+
requireInvoiceAttestation: true,
|
|
783
|
+
requireHeadAttestation: true,
|
|
784
|
+
manifestSigner: serverKeys.signerA,
|
|
785
|
+
verificationReportSigner: serverKeys.signerA,
|
|
786
|
+
toolVersion,
|
|
787
|
+
toolCommit
|
|
788
|
+
});
|
|
789
|
+
|
|
790
|
+
const dirClosePass = path.join(outDir, "closepack", "strict-pass");
|
|
791
|
+
await ensureEmptyDir(dirClosePass);
|
|
792
|
+
writeFilesToDir({ files: closePack.files, outDir: dirClosePass });
|
|
793
|
+
|
|
794
|
+
const evidenceJson = JSON.parse(new TextDecoder().decode(closePack.files.get("evidence/evidence_index.json")));
|
|
795
|
+
const badEvidence = evidenceJson && typeof evidenceJson === "object" ? { ...evidenceJson } : { schemaVersion: "EvidenceIndex.v1", generatedAt, jobProof: {}, items: [] };
|
|
796
|
+
badEvidence.items = Array.isArray(badEvidence.items) ? badEvidence.items.map((x) => x) : [];
|
|
797
|
+
if (badEvidence.items.length) {
|
|
798
|
+
const first = badEvidence.items[0];
|
|
799
|
+
if (first && typeof first === "object") badEvidence.items[0] = { ...first, key: `${String(first.key ?? "")}_tampered` };
|
|
800
|
+
else badEvidence.items[0] = { key: "tampered", source: "metering_evidence_ref" };
|
|
801
|
+
} else {
|
|
802
|
+
badEvidence.items = [{ key: "tampered", source: "metering_evidence_ref" }];
|
|
803
|
+
}
|
|
804
|
+
const closePackEvidenceMismatch = buildClosePackBundleV1({
|
|
805
|
+
tenantId,
|
|
806
|
+
invoiceId,
|
|
807
|
+
protocol: "1.0",
|
|
808
|
+
createdAt: generatedAt,
|
|
809
|
+
governancePolicySigner: govSigner,
|
|
810
|
+
invoiceBundle,
|
|
811
|
+
invoiceBundleFiles: pass.files,
|
|
812
|
+
requireInvoiceAttestation: true,
|
|
813
|
+
requireHeadAttestation: true,
|
|
814
|
+
manifestSigner: serverKeys.signerA,
|
|
815
|
+
verificationReportSigner: serverKeys.signerA,
|
|
816
|
+
toolVersion,
|
|
817
|
+
toolCommit,
|
|
818
|
+
evidenceIndexOverride: badEvidence
|
|
819
|
+
});
|
|
820
|
+
const dirEvidenceMismatch = path.join(outDir, "closepack", "strict-fail-evidence-index-mismatch");
|
|
821
|
+
await ensureEmptyDir(dirEvidenceMismatch);
|
|
822
|
+
writeFilesToDir({ files: closePackEvidenceMismatch.files, outDir: dirEvidenceMismatch });
|
|
823
|
+
|
|
824
|
+
const invoiceFailManifest = JSON.parse(new TextDecoder().decode(wrongTotal.files.get("manifest.json")));
|
|
825
|
+
const invoiceFailBundle = { manifestHash: String(invoiceFailManifest?.manifestHash ?? "") };
|
|
826
|
+
const closeWithBadInvoice = buildClosePackBundleV1({
|
|
827
|
+
tenantId,
|
|
828
|
+
invoiceId: "invoice_fixture_wrong_total",
|
|
829
|
+
protocol: "1.0",
|
|
830
|
+
createdAt: generatedAt,
|
|
831
|
+
governancePolicySigner: govSigner,
|
|
832
|
+
invoiceBundle: invoiceFailBundle,
|
|
833
|
+
invoiceBundleFiles: wrongTotal.files,
|
|
834
|
+
requireInvoiceAttestation: true,
|
|
835
|
+
requireHeadAttestation: true,
|
|
836
|
+
manifestSigner: serverKeys.signerA,
|
|
837
|
+
verificationReportSigner: serverKeys.signerA,
|
|
838
|
+
toolVersion,
|
|
839
|
+
toolCommit
|
|
840
|
+
});
|
|
841
|
+
const dirBadInvoice = path.join(outDir, "closepack", "strict-fail-embedded-invoice-fails");
|
|
842
|
+
await ensureEmptyDir(dirBadInvoice);
|
|
843
|
+
writeFilesToDir({ files: closeWithBadInvoice.files, outDir: dirBadInvoice });
|
|
844
|
+
|
|
845
|
+
const closePackNoSlaAcceptance = buildClosePackBundleV1({
|
|
846
|
+
tenantId,
|
|
847
|
+
invoiceId,
|
|
848
|
+
protocol: "1.0",
|
|
849
|
+
createdAt: generatedAt,
|
|
850
|
+
governancePolicySigner: govSigner,
|
|
851
|
+
invoiceBundle,
|
|
852
|
+
invoiceBundleFiles: pass.files,
|
|
853
|
+
requireInvoiceAttestation: true,
|
|
854
|
+
requireHeadAttestation: true,
|
|
855
|
+
manifestSigner: serverKeys.signerA,
|
|
856
|
+
verificationReportSigner: serverKeys.signerA,
|
|
857
|
+
toolVersion,
|
|
858
|
+
toolCommit,
|
|
859
|
+
includeSlaSurfaces: false,
|
|
860
|
+
includeAcceptanceSurfaces: false
|
|
861
|
+
});
|
|
862
|
+
const dirMissingSlaAcceptance = path.join(outDir, "closepack", "nonstrict-pass-missing-sla-acceptance");
|
|
863
|
+
await ensureEmptyDir(dirMissingSlaAcceptance);
|
|
864
|
+
writeFilesToDir({ files: closePackNoSlaAcceptance.files, outDir: dirMissingSlaAcceptance });
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
// Trust anchors used by strict-mode fixture tests (out-of-band).
|
|
869
|
+
const trust = {
|
|
870
|
+
governanceRoots: { [keypairs.govRoot.keyId]: keypairs.govRoot.publicKeyPem },
|
|
871
|
+
pricingSigners: { [keypairs.govRoot.keyId]: keypairs.govRoot.publicKeyPem },
|
|
872
|
+
timeAuthorities: { [keypairs.timeAuthority.keyId]: keypairs.timeAuthority.publicKeyPem }
|
|
873
|
+
};
|
|
874
|
+
await fs.writeFile(path.join(outDir, "trust.json"), `${JSON.stringify(trust, null, 2)}\n`, "utf8");
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
await main();
|