@flop-labs/sdk 0.0.0-stage → 0.5.1
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 +391 -0
- package/LICENSE +238 -0
- package/README.md +673 -2
- package/dist/a2a/agent-card.d.ts +106 -0
- package/dist/a2a/agent-card.d.ts.map +1 -0
- package/dist/a2a/agent-card.js +131 -0
- package/dist/a2a/agent-card.js.map +1 -0
- package/dist/a2a/index.d.ts +11 -0
- package/dist/a2a/index.d.ts.map +1 -0
- package/dist/a2a/index.js +11 -0
- package/dist/a2a/index.js.map +1 -0
- package/dist/a2a/task-lifecycle.d.ts +41 -0
- package/dist/a2a/task-lifecycle.d.ts.map +1 -0
- package/dist/a2a/task-lifecycle.js +60 -0
- package/dist/a2a/task-lifecycle.js.map +1 -0
- package/dist/a2a/types.d.ts +96 -0
- package/dist/a2a/types.d.ts.map +1 -0
- package/dist/a2a/types.js +23 -0
- package/dist/a2a/types.js.map +1 -0
- package/dist/a2a-cjs/agent-card.js +137 -0
- package/dist/a2a-cjs/agent-card.js.map +1 -0
- package/dist/a2a-cjs/index.js +23 -0
- package/dist/a2a-cjs/index.js.map +1 -0
- package/dist/a2a-cjs/package.json +1 -0
- package/dist/a2a-cjs/task-lifecycle.js +64 -0
- package/dist/a2a-cjs/task-lifecycle.js.map +1 -0
- package/dist/a2a-cjs/types.js +26 -0
- package/dist/a2a-cjs/types.js.map +1 -0
- package/dist/adaptor.d.ts +39 -0
- package/dist/adaptor.d.ts.map +1 -0
- package/dist/adaptor.js +130 -0
- package/dist/adaptor.js.map +1 -0
- package/dist/agent/errors.d.ts +95 -0
- package/dist/agent/errors.d.ts.map +1 -0
- package/dist/agent/errors.js +132 -0
- package/dist/agent/errors.js.map +1 -0
- package/dist/agent/task-delegation.d.ts +283 -0
- package/dist/agent/task-delegation.d.ts.map +1 -0
- package/dist/agent/task-delegation.js +413 -0
- package/dist/agent/task-delegation.js.map +1 -0
- package/dist/agent/types.d.ts +19 -0
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent/types.js +7 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/agent-wallet.d.ts +197 -0
- package/dist/agent-wallet.d.ts.map +1 -0
- package/dist/agent-wallet.js +391 -0
- package/dist/agent-wallet.js.map +1 -0
- package/dist/amhl.d.ts +61 -0
- package/dist/amhl.d.ts.map +1 -0
- package/dist/amhl.js +161 -0
- package/dist/amhl.js.map +1 -0
- package/dist/attestation.d.ts +126 -0
- package/dist/attestation.d.ts.map +1 -0
- package/dist/attestation.js +287 -0
- package/dist/attestation.js.map +1 -0
- package/dist/bip340-adaptor.d.ts +8 -0
- package/dist/bip340-adaptor.d.ts.map +1 -0
- package/dist/bip340-adaptor.js +129 -0
- package/dist/bip340-adaptor.js.map +1 -0
- package/dist/btc-relayer.d.ts +42 -0
- package/dist/btc-relayer.d.ts.map +1 -0
- package/dist/btc-relayer.js +40 -0
- package/dist/btc-relayer.js.map +1 -0
- package/dist/bundle/index.esm.js +2 -0
- package/dist/bundle/index.esm.js.map +1 -0
- package/dist/bundle/index.umd.cjs +2 -0
- package/dist/bundle/index.umd.cjs.map +1 -0
- package/dist/capability-claim-sink.d.ts +5 -0
- package/dist/capability-claim-sink.d.ts.map +1 -0
- package/dist/capability-claim-sink.js +6 -0
- package/dist/capability-claim-sink.js.map +1 -0
- package/dist/chain-text.d.ts +3 -0
- package/dist/chain-text.d.ts.map +1 -0
- package/dist/chain-text.js +27 -0
- package/dist/chain-text.js.map +1 -0
- package/dist/chain.d.ts +63 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +100 -0
- package/dist/chain.js.map +1 -0
- package/dist/client.d.ts +368 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +870 -0
- package/dist/client.js.map +1 -0
- package/dist/compute-channel/adaptor-settlement.d.ts +19 -0
- package/dist/compute-channel/adaptor-settlement.d.ts.map +1 -0
- package/dist/compute-channel/adaptor-settlement.js +40 -0
- package/dist/compute-channel/adaptor-settlement.js.map +1 -0
- package/dist/compute-channel/agent-client.d.ts +141 -0
- package/dist/compute-channel/agent-client.d.ts.map +1 -0
- package/dist/compute-channel/agent-client.js +265 -0
- package/dist/compute-channel/agent-client.js.map +1 -0
- package/dist/compute-channel/agent-driver.d.ts +59 -0
- package/dist/compute-channel/agent-driver.d.ts.map +1 -0
- package/dist/compute-channel/agent-driver.js +351 -0
- package/dist/compute-channel/agent-driver.js.map +1 -0
- package/dist/compute-channel/chain.d.ts +245 -0
- package/dist/compute-channel/chain.d.ts.map +1 -0
- package/dist/compute-channel/chain.js +490 -0
- package/dist/compute-channel/chain.js.map +1 -0
- package/dist/compute-channel/chat-render.d.ts +21 -0
- package/dist/compute-channel/chat-render.d.ts.map +1 -0
- package/dist/compute-channel/chat-render.js +87 -0
- package/dist/compute-channel/chat-render.js.map +1 -0
- package/dist/compute-channel/crypto.d.ts +19 -0
- package/dist/compute-channel/crypto.d.ts.map +1 -0
- package/dist/compute-channel/crypto.js +52 -0
- package/dist/compute-channel/crypto.js.map +1 -0
- package/dist/compute-channel/da.d.ts +111 -0
- package/dist/compute-channel/da.d.ts.map +1 -0
- package/dist/compute-channel/da.js +320 -0
- package/dist/compute-channel/da.js.map +1 -0
- package/dist/compute-channel/deepseek-v41.d.ts +56 -0
- package/dist/compute-channel/deepseek-v41.d.ts.map +1 -0
- package/dist/compute-channel/deepseek-v41.js +267 -0
- package/dist/compute-channel/deepseek-v41.js.map +1 -0
- package/dist/compute-channel/direct-session-chain.d.ts +3 -0
- package/dist/compute-channel/direct-session-chain.d.ts.map +1 -0
- package/dist/compute-channel/direct-session-chain.js +271 -0
- package/dist/compute-channel/direct-session-chain.js.map +1 -0
- package/dist/compute-channel/direct-session.d.ts +78 -0
- package/dist/compute-channel/direct-session.d.ts.map +1 -0
- package/dist/compute-channel/direct-session.js +241 -0
- package/dist/compute-channel/direct-session.js.map +1 -0
- package/dist/compute-channel/dispute.d.ts +103 -0
- package/dist/compute-channel/dispute.d.ts.map +1 -0
- package/dist/compute-channel/dispute.js +314 -0
- package/dist/compute-channel/dispute.js.map +1 -0
- package/dist/compute-channel/fcu-admission.d.ts +37 -0
- package/dist/compute-channel/fcu-admission.d.ts.map +1 -0
- package/dist/compute-channel/fcu-admission.js +53 -0
- package/dist/compute-channel/fcu-admission.js.map +1 -0
- package/dist/compute-channel/fcu-agent.d.ts +27 -0
- package/dist/compute-channel/fcu-agent.d.ts.map +1 -0
- package/dist/compute-channel/fcu-agent.js +35 -0
- package/dist/compute-channel/fcu-agent.js.map +1 -0
- package/dist/compute-channel/fcu-policy.d.ts +67 -0
- package/dist/compute-channel/fcu-policy.d.ts.map +1 -0
- package/dist/compute-channel/fcu-policy.js +121 -0
- package/dist/compute-channel/fcu-policy.js.map +1 -0
- package/dist/compute-channel/fcu-profile.d.ts +56 -0
- package/dist/compute-channel/fcu-profile.d.ts.map +1 -0
- package/dist/compute-channel/fcu-profile.js +100 -0
- package/dist/compute-channel/fcu-profile.js.map +1 -0
- package/dist/compute-channel/fcu-serving.d.ts +146 -0
- package/dist/compute-channel/fcu-serving.d.ts.map +1 -0
- package/dist/compute-channel/fcu-serving.js +350 -0
- package/dist/compute-channel/fcu-serving.js.map +1 -0
- package/dist/compute-channel/fcu-sla.d.ts +88 -0
- package/dist/compute-channel/fcu-sla.d.ts.map +1 -0
- package/dist/compute-channel/fcu-sla.js +154 -0
- package/dist/compute-channel/fcu-sla.js.map +1 -0
- package/dist/compute-channel/fcu-store-node.d.ts +10 -0
- package/dist/compute-channel/fcu-store-node.d.ts.map +1 -0
- package/dist/compute-channel/fcu-store-node.js +98 -0
- package/dist/compute-channel/fcu-store-node.js.map +1 -0
- package/dist/compute-channel/fcu-timing.d.ts +34 -0
- package/dist/compute-channel/fcu-timing.d.ts.map +1 -0
- package/dist/compute-channel/fcu-timing.js +79 -0
- package/dist/compute-channel/fcu-timing.js.map +1 -0
- package/dist/compute-channel/flop-meter.d.ts +96 -0
- package/dist/compute-channel/flop-meter.d.ts.map +1 -0
- package/dist/compute-channel/flop-meter.js +210 -0
- package/dist/compute-channel/flop-meter.js.map +1 -0
- package/dist/compute-channel/flop-submitter.d.ts +40 -0
- package/dist/compute-channel/flop-submitter.d.ts.map +1 -0
- package/dist/compute-channel/flop-submitter.js +124 -0
- package/dist/compute-channel/flop-submitter.js.map +1 -0
- package/dist/compute-channel/hybrid-candidate.d.ts +22 -0
- package/dist/compute-channel/hybrid-candidate.d.ts.map +1 -0
- package/dist/compute-channel/hybrid-candidate.js +155 -0
- package/dist/compute-channel/hybrid-candidate.js.map +1 -0
- package/dist/compute-channel/hybrid-metering.d.ts +36 -0
- package/dist/compute-channel/hybrid-metering.d.ts.map +1 -0
- package/dist/compute-channel/hybrid-metering.js +69 -0
- package/dist/compute-channel/hybrid-metering.js.map +1 -0
- package/dist/compute-channel/hybrid.d.ts +16 -0
- package/dist/compute-channel/hybrid.d.ts.map +1 -0
- package/dist/compute-channel/hybrid.js +98 -0
- package/dist/compute-channel/hybrid.js.map +1 -0
- package/dist/compute-channel/index.d.ts +55 -0
- package/dist/compute-channel/index.d.ts.map +1 -0
- package/dist/compute-channel/index.js +56 -0
- package/dist/compute-channel/index.js.map +1 -0
- package/dist/compute-channel/lane-producer.d.ts +92 -0
- package/dist/compute-channel/lane-producer.d.ts.map +1 -0
- package/dist/compute-channel/lane-producer.js +265 -0
- package/dist/compute-channel/lane-producer.js.map +1 -0
- package/dist/compute-channel/layered.d.ts +77 -0
- package/dist/compute-channel/layered.d.ts.map +1 -0
- package/dist/compute-channel/layered.js +220 -0
- package/dist/compute-channel/layered.js.map +1 -0
- package/dist/compute-channel/lineage.d.ts +19 -0
- package/dist/compute-channel/lineage.d.ts.map +1 -0
- package/dist/compute-channel/lineage.js +28 -0
- package/dist/compute-channel/lineage.js.map +1 -0
- package/dist/compute-channel/miner-host.d.ts +329 -0
- package/dist/compute-channel/miner-host.d.ts.map +1 -0
- package/dist/compute-channel/miner-host.js +880 -0
- package/dist/compute-channel/miner-host.js.map +1 -0
- package/dist/compute-channel/model-config.d.ts +87 -0
- package/dist/compute-channel/model-config.d.ts.map +1 -0
- package/dist/compute-channel/model-config.js +697 -0
- package/dist/compute-channel/model-config.js.map +1 -0
- package/dist/compute-channel/offers.d.ts +57 -0
- package/dist/compute-channel/offers.d.ts.map +1 -0
- package/dist/compute-channel/offers.js +182 -0
- package/dist/compute-channel/offers.js.map +1 -0
- package/dist/compute-channel/peer-info.d.ts +15 -0
- package/dist/compute-channel/peer-info.d.ts.map +1 -0
- package/dist/compute-channel/peer-info.js +33 -0
- package/dist/compute-channel/peer-info.js.map +1 -0
- package/dist/compute-channel/point-claim-sink.d.ts +5 -0
- package/dist/compute-channel/point-claim-sink.d.ts.map +1 -0
- package/dist/compute-channel/point-claim-sink.js +6 -0
- package/dist/compute-channel/point-claim-sink.js.map +1 -0
- package/dist/compute-channel/protocol.d.ts +243 -0
- package/dist/compute-channel/protocol.d.ts.map +1 -0
- package/dist/compute-channel/protocol.js +249 -0
- package/dist/compute-channel/protocol.js.map +1 -0
- package/dist/compute-channel/runtime-storage.d.ts +6 -0
- package/dist/compute-channel/runtime-storage.d.ts.map +1 -0
- package/dist/compute-channel/runtime-storage.js +11 -0
- package/dist/compute-channel/runtime-storage.js.map +1 -0
- package/dist/compute-channel/sampled-audit.d.ts +24 -0
- package/dist/compute-channel/sampled-audit.d.ts.map +1 -0
- package/dist/compute-channel/sampled-audit.js +97 -0
- package/dist/compute-channel/sampled-audit.js.map +1 -0
- package/dist/compute-channel/session-auth.d.ts +6 -0
- package/dist/compute-channel/session-auth.d.ts.map +1 -0
- package/dist/compute-channel/session-auth.js +23 -0
- package/dist/compute-channel/session-auth.js.map +1 -0
- package/dist/compute-channel/session-estimate.d.ts +103 -0
- package/dist/compute-channel/session-estimate.d.ts.map +1 -0
- package/dist/compute-channel/session-estimate.js +140 -0
- package/dist/compute-channel/session-estimate.js.map +1 -0
- package/dist/compute-channel/session-prior-bank.d.ts +61 -0
- package/dist/compute-channel/session-prior-bank.d.ts.map +1 -0
- package/dist/compute-channel/session-prior-bank.js +74 -0
- package/dist/compute-channel/session-prior-bank.js.map +1 -0
- package/dist/compute-channel/session-prior.d.ts +145 -0
- package/dist/compute-channel/session-prior.d.ts.map +1 -0
- package/dist/compute-channel/session-prior.js +325 -0
- package/dist/compute-channel/session-prior.js.map +1 -0
- package/dist/compute-channel/session-store.d.ts +51 -0
- package/dist/compute-channel/session-store.d.ts.map +1 -0
- package/dist/compute-channel/session-store.js +186 -0
- package/dist/compute-channel/session-store.js.map +1 -0
- package/dist/compute-channel/session.d.ts +120 -0
- package/dist/compute-channel/session.d.ts.map +1 -0
- package/dist/compute-channel/session.js +232 -0
- package/dist/compute-channel/session.js.map +1 -0
- package/dist/compute-channel/toploc-checker.d.ts +384 -0
- package/dist/compute-channel/toploc-checker.d.ts.map +1 -0
- package/dist/compute-channel/toploc-checker.js +794 -0
- package/dist/compute-channel/toploc-checker.js.map +1 -0
- package/dist/compute-channel/toploc-completion-rpc.d.ts +26 -0
- package/dist/compute-channel/toploc-completion-rpc.d.ts.map +1 -0
- package/dist/compute-channel/toploc-completion-rpc.js +391 -0
- package/dist/compute-channel/toploc-completion-rpc.js.map +1 -0
- package/dist/compute-channel/toploc-completion.d.ts +109 -0
- package/dist/compute-channel/toploc-completion.d.ts.map +1 -0
- package/dist/compute-channel/toploc-completion.js +301 -0
- package/dist/compute-channel/toploc-completion.js.map +1 -0
- package/dist/compute-channel/toploc-evidence.d.ts +185 -0
- package/dist/compute-channel/toploc-evidence.d.ts.map +1 -0
- package/dist/compute-channel/toploc-evidence.js +299 -0
- package/dist/compute-channel/toploc-evidence.js.map +1 -0
- package/dist/compute-channel/toploc-gumbel.d.ts +149 -0
- package/dist/compute-channel/toploc-gumbel.d.ts.map +1 -0
- package/dist/compute-channel/toploc-gumbel.js +245 -0
- package/dist/compute-channel/toploc-gumbel.js.map +1 -0
- package/dist/compute-channel/toploc.d.ts +63 -0
- package/dist/compute-channel/toploc.d.ts.map +1 -0
- package/dist/compute-channel/toploc.js +197 -0
- package/dist/compute-channel/toploc.js.map +1 -0
- package/dist/compute-channel/transcript.d.ts +127 -0
- package/dist/compute-channel/transcript.d.ts.map +1 -0
- package/dist/compute-channel/transcript.js +279 -0
- package/dist/compute-channel/transcript.js.map +1 -0
- package/dist/compute-channel/transport-http.d.ts +223 -0
- package/dist/compute-channel/transport-http.d.ts.map +1 -0
- package/dist/compute-channel/transport-http.js +661 -0
- package/dist/compute-channel/transport-http.js.map +1 -0
- package/dist/connect.d.ts +4 -0
- package/dist/connect.d.ts.map +1 -0
- package/dist/connect.js +24 -0
- package/dist/connect.js.map +1 -0
- package/dist/coordination.d.ts +341 -0
- package/dist/coordination.d.ts.map +1 -0
- package/dist/coordination.js +483 -0
- package/dist/coordination.js.map +1 -0
- package/dist/da-client.d.ts +124 -0
- package/dist/da-client.d.ts.map +1 -0
- package/dist/da-client.js +127 -0
- package/dist/da-client.js.map +1 -0
- package/dist/discovery/capabilities.d.ts +129 -0
- package/dist/discovery/capabilities.d.ts.map +1 -0
- package/dist/discovery/capabilities.js +398 -0
- package/dist/discovery/capabilities.js.map +1 -0
- package/dist/discovery/discovery-service.d.ts +476 -0
- package/dist/discovery/discovery-service.d.ts.map +1 -0
- package/dist/discovery/discovery-service.js +996 -0
- package/dist/discovery/discovery-service.js.map +1 -0
- package/dist/discovery/examples.d.ts +50 -0
- package/dist/discovery/examples.d.ts.map +1 -0
- package/dist/discovery/examples.js +163 -0
- package/dist/discovery/examples.js.map +1 -0
- package/dist/discovery/fee-estimation.d.ts +550 -0
- package/dist/discovery/fee-estimation.d.ts.map +1 -0
- package/dist/discovery/fee-estimation.js +921 -0
- package/dist/discovery/fee-estimation.js.map +1 -0
- package/dist/discovery/index.d.ts +38 -0
- package/dist/discovery/index.d.ts.map +1 -0
- package/dist/discovery/index.js +32 -0
- package/dist/discovery/index.js.map +1 -0
- package/dist/discovery/metered-pricing.d.ts +100 -0
- package/dist/discovery/metered-pricing.d.ts.map +1 -0
- package/dist/discovery/metered-pricing.js +150 -0
- package/dist/discovery/metered-pricing.js.map +1 -0
- package/dist/discovery/priority.d.ts +16 -0
- package/dist/discovery/priority.d.ts.map +1 -0
- package/dist/discovery/priority.js +17 -0
- package/dist/discovery/priority.js.map +1 -0
- package/dist/discovery/scoring.d.ts +231 -0
- package/dist/discovery/scoring.d.ts.map +1 -0
- package/dist/discovery/scoring.js +354 -0
- package/dist/discovery/scoring.js.map +1 -0
- package/dist/ecdsa-adaptor.d.ts +72 -0
- package/dist/ecdsa-adaptor.d.ts.map +1 -0
- package/dist/ecdsa-adaptor.js +351 -0
- package/dist/ecdsa-adaptor.js.map +1 -0
- package/dist/errors.d.ts +98 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +190 -0
- package/dist/errors.js.map +1 -0
- package/dist/escrow.d.ts +116 -0
- package/dist/escrow.d.ts.map +1 -0
- package/dist/escrow.js +172 -0
- package/dist/escrow.js.map +1 -0
- package/dist/evm-relayer.d.ts +12 -0
- package/dist/evm-relayer.d.ts.map +1 -0
- package/dist/evm-relayer.js +25 -0
- package/dist/evm-relayer.js.map +1 -0
- package/dist/experimental.d.ts +3 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +3 -0
- package/dist/experimental.js.map +1 -0
- package/dist/faucet.d.ts +146 -0
- package/dist/faucet.d.ts.map +1 -0
- package/dist/faucet.js +300 -0
- package/dist/faucet.js.map +1 -0
- package/dist/finality-status.d.ts +21 -0
- package/dist/finality-status.d.ts.map +1 -0
- package/dist/finality-status.js +10 -0
- package/dist/finality-status.js.map +1 -0
- package/dist/generated-client/capabilities.d.ts +83 -0
- package/dist/generated-client/capabilities.d.ts.map +1 -0
- package/dist/generated-client/capabilities.js +87 -0
- package/dist/generated-client/capabilities.js.map +1 -0
- package/dist/generated-client/cli.d.ts +3 -0
- package/dist/generated-client/cli.d.ts.map +1 -0
- package/dist/generated-client/cli.js +33 -0
- package/dist/generated-client/cli.js.map +1 -0
- package/dist/generated-client/errors.d.ts +13 -0
- package/dist/generated-client/errors.d.ts.map +1 -0
- package/dist/generated-client/errors.js +23 -0
- package/dist/generated-client/errors.js.map +1 -0
- package/dist/generated-client/factory.d.ts +28 -0
- package/dist/generated-client/factory.d.ts.map +1 -0
- package/dist/generated-client/factory.js +182 -0
- package/dist/generated-client/factory.js.map +1 -0
- package/dist/generated-client/generator.d.ts +9 -0
- package/dist/generated-client/generator.d.ts.map +1 -0
- package/dist/generated-client/generator.js +80 -0
- package/dist/generated-client/generator.js.map +1 -0
- package/dist/generated-client/index.d.ts +11 -0
- package/dist/generated-client/index.d.ts.map +1 -0
- package/dist/generated-client/index.js +6 -0
- package/dist/generated-client/index.js.map +1 -0
- package/dist/generated-client/profile.d.ts +166 -0
- package/dist/generated-client/profile.d.ts.map +1 -0
- package/dist/generated-client/profile.js +158 -0
- package/dist/generated-client/profile.js.map +1 -0
- package/dist/generated-client/templates/agent-chat.d.ts +16 -0
- package/dist/generated-client/templates/agent-chat.d.ts.map +1 -0
- package/dist/generated-client/templates/agent-chat.js +12 -0
- package/dist/generated-client/templates/agent-chat.js.map +1 -0
- package/dist/generated-client/templates/index.d.ts +4 -0
- package/dist/generated-client/templates/index.d.ts.map +1 -0
- package/dist/generated-client/templates/index.js +4 -0
- package/dist/generated-client/templates/index.js.map +1 -0
- package/dist/generated-client/templates/miner-operator.d.ts +16 -0
- package/dist/generated-client/templates/miner-operator.d.ts.map +1 -0
- package/dist/generated-client/templates/miner-operator.js +12 -0
- package/dist/generated-client/templates/miner-operator.js.map +1 -0
- package/dist/generated-client/templates/model-publisher.d.ts +21 -0
- package/dist/generated-client/templates/model-publisher.d.ts.map +1 -0
- package/dist/generated-client/templates/model-publisher.js +13 -0
- package/dist/generated-client/templates/model-publisher.js.map +1 -0
- package/dist/hardware.d.ts +68 -0
- package/dist/hardware.d.ts.map +1 -0
- package/dist/hardware.js +222 -0
- package/dist/hardware.js.map +1 -0
- package/dist/htlc-appraisal.d.ts +4 -0
- package/dist/htlc-appraisal.d.ts.map +1 -0
- package/dist/htlc-appraisal.js +25 -0
- package/dist/htlc-appraisal.js.map +1 -0
- package/dist/index.d.ts +114 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +144 -0
- package/dist/index.js.map +1 -0
- package/dist/inference-purchase.d.ts +40 -0
- package/dist/inference-purchase.d.ts.map +1 -0
- package/dist/inference-purchase.js +43 -0
- package/dist/inference-purchase.js.map +1 -0
- package/dist/miner-admission.d.ts +124 -0
- package/dist/miner-admission.d.ts.map +1 -0
- package/dist/miner-admission.js +259 -0
- package/dist/miner-admission.js.map +1 -0
- package/dist/model-loader/canonical.d.ts +79 -0
- package/dist/model-loader/canonical.d.ts.map +1 -0
- package/dist/model-loader/canonical.js +116 -0
- package/dist/model-loader/canonical.js.map +1 -0
- package/dist/model-loader/dir.d.ts +26 -0
- package/dist/model-loader/dir.d.ts.map +1 -0
- package/dist/model-loader/dir.js +109 -0
- package/dist/model-loader/dir.js.map +1 -0
- package/dist/model-loader/dmverity.d.ts +78 -0
- package/dist/model-loader/dmverity.d.ts.map +1 -0
- package/dist/model-loader/dmverity.js +141 -0
- package/dist/model-loader/dmverity.js.map +1 -0
- package/dist/model-loader/download-state.d.ts +24 -0
- package/dist/model-loader/download-state.d.ts.map +1 -0
- package/dist/model-loader/download-state.js +99 -0
- package/dist/model-loader/download-state.js.map +1 -0
- package/dist/model-loader/fetch.d.ts +51 -0
- package/dist/model-loader/fetch.d.ts.map +1 -0
- package/dist/model-loader/fetch.js +410 -0
- package/dist/model-loader/fetch.js.map +1 -0
- package/dist/model-loader/file-table.d.ts +38 -0
- package/dist/model-loader/file-table.d.ts.map +1 -0
- package/dist/model-loader/file-table.js +106 -0
- package/dist/model-loader/file-table.js.map +1 -0
- package/dist/model-loader/hf-preflight.d.ts +65 -0
- package/dist/model-loader/hf-preflight.d.ts.map +1 -0
- package/dist/model-loader/hf-preflight.js +179 -0
- package/dist/model-loader/hf-preflight.js.map +1 -0
- package/dist/model-loader/index.d.ts +27 -0
- package/dist/model-loader/index.d.ts.map +1 -0
- package/dist/model-loader/index.js +21 -0
- package/dist/model-loader/index.js.map +1 -0
- package/dist/model-loader/registry.d.ts +24 -0
- package/dist/model-loader/registry.d.ts.map +1 -0
- package/dist/model-loader/registry.js +99 -0
- package/dist/model-loader/registry.js.map +1 -0
- package/dist/model-loader/types.d.ts +101 -0
- package/dist/model-loader/types.d.ts.map +1 -0
- package/dist/model-loader/types.js +13 -0
- package/dist/model-loader/types.js.map +1 -0
- package/dist/model-loader/verify.d.ts +83 -0
- package/dist/model-loader/verify.d.ts.map +1 -0
- package/dist/model-loader/verify.js +138 -0
- package/dist/model-loader/verify.js.map +1 -0
- package/dist/model-qualification.d.ts +79 -0
- package/dist/model-qualification.d.ts.map +1 -0
- package/dist/model-qualification.js +135 -0
- package/dist/model-qualification.js.map +1 -0
- package/dist/near-relayer.d.ts +30 -0
- package/dist/near-relayer.d.ts.map +1 -0
- package/dist/near-relayer.js +81 -0
- package/dist/near-relayer.js.map +1 -0
- package/dist/paid-storage/bytes.d.ts +21 -0
- package/dist/paid-storage/bytes.d.ts.map +1 -0
- package/dist/paid-storage/bytes.js +71 -0
- package/dist/paid-storage/bytes.js.map +1 -0
- package/dist/paid-storage/chain.d.ts +20 -0
- package/dist/paid-storage/chain.d.ts.map +1 -0
- package/dist/paid-storage/chain.js +182 -0
- package/dist/paid-storage/chain.js.map +1 -0
- package/dist/paid-storage/client.d.ts +161 -0
- package/dist/paid-storage/client.d.ts.map +1 -0
- package/dist/paid-storage/client.js +1038 -0
- package/dist/paid-storage/client.js.map +1 -0
- package/dist/paid-storage/cloudflare.d.ts +4 -0
- package/dist/paid-storage/cloudflare.d.ts.map +1 -0
- package/dist/paid-storage/cloudflare.js +9 -0
- package/dist/paid-storage/cloudflare.js.map +1 -0
- package/dist/paid-storage/codec.d.ts +8 -0
- package/dist/paid-storage/codec.d.ts.map +1 -0
- package/dist/paid-storage/codec.js +92 -0
- package/dist/paid-storage/codec.js.map +1 -0
- package/dist/paid-storage/crypto.d.ts +27 -0
- package/dist/paid-storage/crypto.d.ts.map +1 -0
- package/dist/paid-storage/crypto.js +91 -0
- package/dist/paid-storage/crypto.js.map +1 -0
- package/dist/paid-storage/heads.d.ts +26 -0
- package/dist/paid-storage/heads.d.ts.map +1 -0
- package/dist/paid-storage/heads.js +208 -0
- package/dist/paid-storage/heads.js.map +1 -0
- package/dist/paid-storage/index.d.ts +14 -0
- package/dist/paid-storage/index.d.ts.map +1 -0
- package/dist/paid-storage/index.js +7 -0
- package/dist/paid-storage/index.js.map +1 -0
- package/dist/paid-storage/memory-wire.d.ts +85 -0
- package/dist/paid-storage/memory-wire.d.ts.map +1 -0
- package/dist/paid-storage/memory-wire.js +147 -0
- package/dist/paid-storage/memory-wire.js.map +1 -0
- package/dist/paid-storage/node-store.d.ts +9 -0
- package/dist/paid-storage/node-store.d.ts.map +1 -0
- package/dist/paid-storage/node-store.js +34 -0
- package/dist/paid-storage/node-store.js.map +1 -0
- package/dist/paid-storage/profile.d.ts +21 -0
- package/dist/paid-storage/profile.d.ts.map +1 -0
- package/dist/paid-storage/profile.js +22 -0
- package/dist/paid-storage/profile.js.map +1 -0
- package/dist/paid-storage/store.d.ts +18 -0
- package/dist/paid-storage/store.d.ts.map +1 -0
- package/dist/paid-storage/store.js +32 -0
- package/dist/paid-storage/store.js.map +1 -0
- package/dist/paid-storage/transport.d.ts +70 -0
- package/dist/paid-storage/transport.d.ts.map +1 -0
- package/dist/paid-storage/transport.js +140 -0
- package/dist/paid-storage/transport.js.map +1 -0
- package/dist/paid-storage/vouchers.d.ts +75 -0
- package/dist/paid-storage/vouchers.d.ts.map +1 -0
- package/dist/paid-storage/vouchers.js +239 -0
- package/dist/paid-storage/vouchers.js.map +1 -0
- package/dist/paid-storage-wire.d.ts +11 -0
- package/dist/paid-storage-wire.d.ts.map +1 -0
- package/dist/paid-storage-wire.js +184 -0
- package/dist/paid-storage-wire.js.map +1 -0
- package/dist/point-claims.d.ts +40 -0
- package/dist/point-claims.d.ts.map +1 -0
- package/dist/point-claims.js +98 -0
- package/dist/point-claims.js.map +1 -0
- package/dist/quickstart.d.ts +307 -0
- package/dist/quickstart.d.ts.map +1 -0
- package/dist/quickstart.js +536 -0
- package/dist/quickstart.js.map +1 -0
- package/dist/react/context.d.ts +10 -0
- package/dist/react/context.d.ts.map +1 -0
- package/dist/react/context.js +16 -0
- package/dist/react/context.js.map +1 -0
- package/dist/react/hooks.d.ts +206 -0
- package/dist/react/hooks.d.ts.map +1 -0
- package/dist/react/hooks.js +560 -0
- package/dist/react/hooks.js.map +1 -0
- package/dist/react/index.d.ts +4 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +4 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/provider.d.ts +18 -0
- package/dist/react/provider.d.ts.map +1 -0
- package/dist/react/provider.js +17 -0
- package/dist/react/provider.js.map +1 -0
- package/dist/relayer.d.ts +122 -0
- package/dist/relayer.d.ts.map +1 -0
- package/dist/relayer.js +203 -0
- package/dist/relayer.js.map +1 -0
- package/dist/runtime-compatibility.d.ts +8 -0
- package/dist/runtime-compatibility.d.ts.map +1 -0
- package/dist/runtime-compatibility.js +23 -0
- package/dist/runtime-compatibility.js.map +1 -0
- package/dist/session-manager.d.ts +197 -0
- package/dist/session-manager.d.ts.map +1 -0
- package/dist/session-manager.js +429 -0
- package/dist/session-manager.js.map +1 -0
- package/dist/solana-ptlc.d.ts +64 -0
- package/dist/solana-ptlc.d.ts.map +1 -0
- package/dist/solana-ptlc.js +137 -0
- package/dist/solana-ptlc.js.map +1 -0
- package/dist/staking-client.d.ts +103 -0
- package/dist/staking-client.d.ts.map +1 -0
- package/dist/staking-client.js +308 -0
- package/dist/staking-client.js.map +1 -0
- package/dist/staking-types.d.ts +203 -0
- package/dist/staking-types.d.ts.map +1 -0
- package/dist/staking-types.js +16 -0
- package/dist/staking-types.js.map +1 -0
- package/dist/submit-tx.d.ts +14 -0
- package/dist/submit-tx.d.ts.map +1 -0
- package/dist/submit-tx.js +25 -0
- package/dist/submit-tx.js.map +1 -0
- package/dist/templates/index.d.ts +52 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +123 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/ton/index.d.ts +52 -0
- package/dist/ton/index.d.ts.map +1 -0
- package/dist/ton/index.js +163 -0
- package/dist/ton/index.js.map +1 -0
- package/dist/ton-relayer.d.ts +26 -0
- package/dist/ton-relayer.d.ts.map +1 -0
- package/dist/ton-relayer.js +22 -0
- package/dist/ton-relayer.js.map +1 -0
- package/dist/tracing.d.ts +48 -0
- package/dist/tracing.d.ts.map +1 -0
- package/dist/tracing.js +108 -0
- package/dist/tracing.js.map +1 -0
- package/dist/transaction-signer.d.ts +13 -0
- package/dist/transaction-signer.d.ts.map +1 -0
- package/dist/transaction-signer.js +13 -0
- package/dist/transaction-signer.js.map +1 -0
- package/dist/trust-root.d.ts +56 -0
- package/dist/trust-root.d.ts.map +1 -0
- package/dist/trust-root.js +28 -0
- package/dist/trust-root.js.map +1 -0
- package/dist/types.d.ts +201 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/validator-staking-client.d.ts +87 -0
- package/dist/validator-staking-client.d.ts.map +1 -0
- package/dist/validator-staking-client.js +226 -0
- package/dist/validator-staking-client.js.map +1 -0
- package/dist/virtuals-acp.d.ts +149 -0
- package/dist/virtuals-acp.d.ts.map +1 -0
- package/dist/virtuals-acp.js +418 -0
- package/dist/virtuals-acp.js.map +1 -0
- package/dist/wallet-manager.d.ts +199 -0
- package/dist/wallet-manager.d.ts.map +1 -0
- package/dist/wallet-manager.js +425 -0
- package/dist/wallet-manager.js.map +1 -0
- package/dist/wallets/burner.d.ts +45 -0
- package/dist/wallets/burner.d.ts.map +1 -0
- package/dist/wallets/burner.js +58 -0
- package/dist/wallets/burner.js.map +1 -0
- package/dist/wallets/index.d.ts +26 -0
- package/dist/wallets/index.d.ts.map +1 -0
- package/dist/wallets/index.js +20 -0
- package/dist/wallets/index.js.map +1 -0
- package/dist/wallets/injected.d.ts +22 -0
- package/dist/wallets/injected.d.ts.map +1 -0
- package/dist/wallets/injected.js +45 -0
- package/dist/wallets/injected.js.map +1 -0
- package/dist/wallets/ledger.d.ts +76 -0
- package/dist/wallets/ledger.d.ts.map +1 -0
- package/dist/wallets/ledger.js +106 -0
- package/dist/wallets/ledger.js.map +1 -0
- package/dist/wallets/near.d.ts +69 -0
- package/dist/wallets/near.d.ts.map +1 -0
- package/dist/wallets/near.js +101 -0
- package/dist/wallets/near.js.map +1 -0
- package/dist/wallets/types.d.ts +42 -0
- package/dist/wallets/types.d.ts.map +1 -0
- package/dist/wallets/types.js +31 -0
- package/dist/wallets/types.js.map +1 -0
- package/dist/wallets/walletconnect.d.ts +38 -0
- package/dist/wallets/walletconnect.d.ts.map +1 -0
- package/dist/wallets/walletconnect.js +94 -0
- package/dist/wallets/walletconnect.js.map +1 -0
- package/dist/watch-transaction.d.ts +26 -0
- package/dist/watch-transaction.d.ts.map +1 -0
- package/dist/watch-transaction.js +91 -0
- package/dist/watch-transaction.js.map +1 -0
- package/dist/weak-subjectivity.d.ts +213 -0
- package/dist/weak-subjectivity.d.ts.map +1 -0
- package/dist/weak-subjectivity.js +389 -0
- package/dist/weak-subjectivity.js.map +1 -0
- package/dist/x402-types/channel-types.d.ts +78 -0
- package/dist/x402-types/channel-types.d.ts.map +1 -0
- package/dist/x402-types/channel-types.js +5 -0
- package/dist/x402-types/channel-types.js.map +1 -0
- package/dist/x402-types/exact-flop.d.ts +29 -0
- package/dist/x402-types/exact-flop.d.ts.map +1 -0
- package/dist/x402-types/exact-flop.js +64 -0
- package/dist/x402-types/exact-flop.js.map +1 -0
- package/dist/x402-types/index.d.ts +65 -0
- package/dist/x402-types/index.d.ts.map +1 -0
- package/dist/x402-types/index.js +26 -0
- package/dist/x402-types/index.js.map +1 -0
- package/dist/x402.d.ts +113 -0
- package/dist/x402.d.ts.map +1 -0
- package/dist/x402.js +218 -0
- package/dist/x402.js.map +1 -0
- package/package.json +172 -3
|
@@ -0,0 +1,880 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Miner-side session host (runs inside the TEE).
|
|
3
|
+
* @module sdk/typescript/compute-channel/miner-host
|
|
4
|
+
*
|
|
5
|
+
* Per turn: hash input, run inference, derive G_n, sign the canonical leaf with
|
|
6
|
+
* the enclave key bound at `open_channel`, fold into the running accumulator,
|
|
7
|
+
* return a signed {@link TurnReceipt}. At session end: publish the transcript to
|
|
8
|
+
* validator DA and build the settlement.
|
|
9
|
+
*
|
|
10
|
+
* Receipt fence ({@link maxUnackedGn}): the host tracks Σ G_n of turns without a
|
|
11
|
+
* verified agent ack and refuses further turns once that sum would leave
|
|
12
|
+
* `unacked_gn > maxUnackedGn` (session-migration-semantics invariant 5). Default
|
|
13
|
+
* `maxUnackedGn = 0` is single-turn credit — never unlimited.
|
|
14
|
+
*/
|
|
15
|
+
import { performance } from "perf_hooks";
|
|
16
|
+
import { SessionKey } from "./crypto.js";
|
|
17
|
+
import { TranscriptBlob, } from "./da.js";
|
|
18
|
+
import { u8aEq, verifyReceipt, verifyTurnAck, } from "./protocol.js";
|
|
19
|
+
import { LLAMA3_8B } from "./flop-meter.js";
|
|
20
|
+
import { isDenseGdnArch, meteredReferenceGn } from "./model-config.js";
|
|
21
|
+
import { DENSE_GDN_PROFILE_SHA256 } from "./hybrid.js";
|
|
22
|
+
import { encodeToplocActivationCommitment, toplocCommitmentHash, } from "./toploc.js";
|
|
23
|
+
import { activationsRoot, daRefReusable, DEFAULT_TOPLOC_SAMPLE_POLICY, encodeToplocActivationBatch, evaluateToplocEvidenceSettlement, isToplocTurnSelected, publishEphemeralWithRetry, ToplocEvidenceSettlementAction, ToplocPublishMetrics, } from "./toploc-evidence.js";
|
|
24
|
+
import { buildVerifiedTurns } from "./dispute.js";
|
|
25
|
+
import { blake2_256, gnFromMeasuredGn, hIds as computeHIds, leafVersionFromFields, MerkleAccumulator, reconstructLeafVersioned, turnEvidenceHash, transcriptLeafV2, transcriptLeafV3, } from "./transcript.js";
|
|
26
|
+
const ZERO_HASH = new Uint8Array(32);
|
|
27
|
+
function sameModelIdentity(a, b) {
|
|
28
|
+
return a.requestedSlug === b.requestedSlug &&
|
|
29
|
+
a.registryModel === b.registryModel &&
|
|
30
|
+
a.registryVersion === b.registryVersion &&
|
|
31
|
+
u8aEq(a.modelHash, b.modelHash) &&
|
|
32
|
+
a.precision === b.precision &&
|
|
33
|
+
u8aEq(a.decodePolicyHash, b.decodePolicyHash) &&
|
|
34
|
+
u8aEq(a.measuredRoot, b.measuredRoot) &&
|
|
35
|
+
a.backendModelName === b.backendModelName;
|
|
36
|
+
}
|
|
37
|
+
function cloneModelIdentity(identity) {
|
|
38
|
+
return {
|
|
39
|
+
...identity,
|
|
40
|
+
modelHash: identity.modelHash.slice(),
|
|
41
|
+
decodePolicyHash: identity.decodePolicyHash.slice(),
|
|
42
|
+
measuredRoot: identity.measuredRoot.slice(),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Reconstruct the explicit leaf version persisted in the turn record.
|
|
47
|
+
*/
|
|
48
|
+
function reconstructTurnLeaf(channelId, t) {
|
|
49
|
+
return reconstructLeafVersioned(t.leafVersion, channelId, t.turnIndex, t.hIn, t.hOut, t.gN, t.decodePolicyHash ?? ZERO_HASH, t.hIds ?? ZERO_HASH, t.toplocCommitmentHash ?? ZERO_HASH, t.minerRecvMs, t.minerDoneMs, t.latencyMs);
|
|
50
|
+
}
|
|
51
|
+
// perf_hooks.performance is explicitly monotonic in all supported Node versions,
|
|
52
|
+
// preventing spurious MinerClockReversed errors from NTP wall-clock corrections.
|
|
53
|
+
function defaultNowMs() {
|
|
54
|
+
return BigInt(Math.floor(performance.now()));
|
|
55
|
+
}
|
|
56
|
+
export var FenceErrorKind;
|
|
57
|
+
(function (FenceErrorKind) {
|
|
58
|
+
/** `unacked_gn > maxUnackedGn` — host will not serve until agent re-acks. */
|
|
59
|
+
FenceErrorKind["MaxUnackedGnExceeded"] = "MaxUnackedGnExceeded";
|
|
60
|
+
})(FenceErrorKind || (FenceErrorKind = {}));
|
|
61
|
+
/** Typed fence-breach error: host stopped serving; re-ack to resume. */
|
|
62
|
+
export class FenceBreachError extends Error {
|
|
63
|
+
unackedGn;
|
|
64
|
+
maxUnackedGn;
|
|
65
|
+
lastCosignedCheckpoint;
|
|
66
|
+
kind = FenceErrorKind.MaxUnackedGnExceeded;
|
|
67
|
+
constructor(unackedGn, maxUnackedGn,
|
|
68
|
+
/** Last agent co-signed cumulative receipt, if any (for force_settle). */
|
|
69
|
+
lastCosignedCheckpoint, message) {
|
|
70
|
+
super(message ??
|
|
71
|
+
`MaxUnackedGn fence breached: unacked_gn=${unackedGn} > maxUnackedGn=${maxUnackedGn}`);
|
|
72
|
+
this.unackedGn = unackedGn;
|
|
73
|
+
this.maxUnackedGn = maxUnackedGn;
|
|
74
|
+
this.lastCosignedCheckpoint = lastCosignedCheckpoint;
|
|
75
|
+
this.name = "FenceBreachError";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Default fence: single-turn credit. With maxUnackedGn=0 the host serves one
|
|
80
|
+
* turn, then refuses until that turn is acked (`unacked_gn > 0`).
|
|
81
|
+
*/
|
|
82
|
+
export const DEFAULT_MAX_UNACKED_GN = 0n;
|
|
83
|
+
export class MinerSessionHost {
|
|
84
|
+
channelId;
|
|
85
|
+
enclave;
|
|
86
|
+
arch;
|
|
87
|
+
reattestEvery;
|
|
88
|
+
agentKey;
|
|
89
|
+
nowMs;
|
|
90
|
+
toploc;
|
|
91
|
+
decodePolicyHash;
|
|
92
|
+
maxUnackedGn;
|
|
93
|
+
modelIdentity;
|
|
94
|
+
accumulator = new MerkleAccumulator();
|
|
95
|
+
turns = [];
|
|
96
|
+
toplocCommitments = [];
|
|
97
|
+
/** Per-turn running root right after the turn was folded (checkpoint bind). */
|
|
98
|
+
turnCheckpointRoots = new Map();
|
|
99
|
+
/** Idempotent DA refs for published TOPLOC activations (turn → binding). */
|
|
100
|
+
toplocPublished = new Map();
|
|
101
|
+
toplocBatchRef = null;
|
|
102
|
+
aggregate = 0n;
|
|
103
|
+
lastGnSource = null;
|
|
104
|
+
/** Σ G_n of turns lacking a verified agent ack. */
|
|
105
|
+
unacked = 0n;
|
|
106
|
+
fenceBreached = false;
|
|
107
|
+
lastCheckpoint = null;
|
|
108
|
+
/** Production TOPLOC DA sink (optional; set for auto-publish after turns). */
|
|
109
|
+
daSink = null;
|
|
110
|
+
/** Durable crash-safe store (optional; persists checkpoint + prefix leaves). */
|
|
111
|
+
sessionStore = null;
|
|
112
|
+
turnEvidenceStore = null;
|
|
113
|
+
/** In-flight persist writes (off the ack/checkpoint path; awaited by settle). */
|
|
114
|
+
pendingPersists = new Set();
|
|
115
|
+
/** Exact checkpoint confirmed durable; equal turn indices can carry different receipts. */
|
|
116
|
+
durableCheckpoint = null;
|
|
117
|
+
persistQueue = Promise.resolve();
|
|
118
|
+
/** Last durable-save failure; surfaced by flushPersists so durability isn't faked. */
|
|
119
|
+
lastPersistError = null;
|
|
120
|
+
/** True for a host rebuilt via {@link restore}: settle-only, cannot serve turns. */
|
|
121
|
+
restored = false;
|
|
122
|
+
/** In-flight serve-time DA publishes (off the turn path; see serveTurn). */
|
|
123
|
+
pendingToplocPublishes = new Set();
|
|
124
|
+
toplocMetrics = new ToplocPublishMetrics();
|
|
125
|
+
constructor(channelId, enclave,
|
|
126
|
+
/** Architecture of the served model (bound at `open_channel`). */
|
|
127
|
+
arch, reattestEvery,
|
|
128
|
+
/** Agent receipt-signing public key committed at `open_channel`. Used to
|
|
129
|
+
* verify turn-ack signatures before persisting them so a miner cannot
|
|
130
|
+
* inject fabricated timestamps into the DA transcript. */
|
|
131
|
+
agentKey, nowMs = defaultNowMs, toploc, decodePolicyHash = new Uint8Array(32),
|
|
132
|
+
/**
|
|
133
|
+
* Max Σ G_n of turns without a verified agent ack. Default
|
|
134
|
+
* {@link DEFAULT_MAX_UNACKED_GN} (0) = single-turn credit. Absent/omitted
|
|
135
|
+
* never means unlimited.
|
|
136
|
+
*/
|
|
137
|
+
maxUnackedGn = DEFAULT_MAX_UNACKED_GN,
|
|
138
|
+
/** Provider-grade sessions require every backend result to echo this tuple. */
|
|
139
|
+
modelIdentity) {
|
|
140
|
+
this.channelId = channelId;
|
|
141
|
+
this.enclave = enclave;
|
|
142
|
+
this.arch = arch;
|
|
143
|
+
this.reattestEvery = reattestEvery;
|
|
144
|
+
this.agentKey = agentKey;
|
|
145
|
+
this.nowMs = nowMs;
|
|
146
|
+
this.toploc = toploc;
|
|
147
|
+
this.decodePolicyHash = decodePolicyHash;
|
|
148
|
+
this.maxUnackedGn = maxUnackedGn;
|
|
149
|
+
this.modelIdentity = modelIdentity;
|
|
150
|
+
}
|
|
151
|
+
/** Attach neutral-validator DA for production TOPLOC publication. */
|
|
152
|
+
setDaSink(da) {
|
|
153
|
+
this.daSink = da;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Attach a durable {@link SessionStore}. Once set, the host persists a snapshot
|
|
157
|
+
* (last co-signed checkpoint + its prefix leaves) after every
|
|
158
|
+
* {@link recordCheckpoint} — the settle-critical datum — so a post-crash
|
|
159
|
+
* {@link restore} can still `force_settle` the acked prefix.
|
|
160
|
+
*/
|
|
161
|
+
setSessionStore(store) {
|
|
162
|
+
this.sessionStore = store;
|
|
163
|
+
}
|
|
164
|
+
setTurnEvidenceStore(store) {
|
|
165
|
+
if (!this.modelIdentity || !this.toploc) {
|
|
166
|
+
throw new Error("private audit handoff requires a verified model identity and TOPLOC");
|
|
167
|
+
}
|
|
168
|
+
this.turnEvidenceStore = store;
|
|
169
|
+
}
|
|
170
|
+
toplocSamplePolicy() {
|
|
171
|
+
return this.toploc?.samplePolicy ?? DEFAULT_TOPLOC_SAMPLE_POLICY;
|
|
172
|
+
}
|
|
173
|
+
/** True when TOPLOC is configured and evidence is required at settlement. */
|
|
174
|
+
toplocRequiredForSettlement() {
|
|
175
|
+
if (!this.toploc)
|
|
176
|
+
return false;
|
|
177
|
+
return this.toploc.requiredForSettlement !== false;
|
|
178
|
+
}
|
|
179
|
+
/** SLA fence advertised at handshake / echoed in session info. */
|
|
180
|
+
maxUnackedGnLimit() {
|
|
181
|
+
return this.maxUnackedGn;
|
|
182
|
+
}
|
|
183
|
+
/** Current unpaid-tail exposure (turns without verified agent ack). */
|
|
184
|
+
unackedGn() {
|
|
185
|
+
return this.unacked;
|
|
186
|
+
}
|
|
187
|
+
/** True after a serve was refused (or would be) until acks bring exposure under the fence. */
|
|
188
|
+
isFenceBreached() {
|
|
189
|
+
return this.fenceBreached || this.unacked > this.maxUnackedGn;
|
|
190
|
+
}
|
|
191
|
+
/** Last co-signed cumulative receipt (for unilateral force_settle). */
|
|
192
|
+
lastCosignedCheckpoint() {
|
|
193
|
+
return this.lastCheckpoint
|
|
194
|
+
? {
|
|
195
|
+
finalRoot: this.lastCheckpoint.finalRoot.slice(),
|
|
196
|
+
aggregateGn: this.lastCheckpoint.aggregateGn,
|
|
197
|
+
payable: this.lastCheckpoint.payable,
|
|
198
|
+
throughTurn: this.lastCheckpoint.throughTurn,
|
|
199
|
+
agentReceiptSig: this.lastCheckpoint.agentReceiptSig.slice(),
|
|
200
|
+
}
|
|
201
|
+
: null;
|
|
202
|
+
}
|
|
203
|
+
/** The enclave public key (the value committed at `open_channel`). */
|
|
204
|
+
enclaveKey() {
|
|
205
|
+
return this.enclave.publicKey;
|
|
206
|
+
}
|
|
207
|
+
/** Process one turn: hash, infer, sign the leaf, fold it in. */
|
|
208
|
+
async serveTurn(backend, request) {
|
|
209
|
+
// A restored host is settle-only: the enclave signing key is gone after a TEE
|
|
210
|
+
// restart, so it can never produce new authentic leaves. Fail closed.
|
|
211
|
+
if (this.restored) {
|
|
212
|
+
throw new Error("restored host is settle-only: the enclave key is gone after a TEE restart; " +
|
|
213
|
+
"it cannot serve new turns (use buildForceSettleFromLastCheckpoint)");
|
|
214
|
+
}
|
|
215
|
+
// Fail closed before spending compute once the unpaid tail already exceeds the fence.
|
|
216
|
+
if (this.unacked > this.maxUnackedGn) {
|
|
217
|
+
this.fenceBreached = true;
|
|
218
|
+
throw new FenceBreachError(this.unacked, this.maxUnackedGn, this.lastCosignedCheckpoint());
|
|
219
|
+
}
|
|
220
|
+
const turnIndex = this.turns.length;
|
|
221
|
+
if (isDenseGdnArch(this.arch) && (!this.turnEvidenceStore || !this.modelIdentity ||
|
|
222
|
+
!this.toploc || this.toplocSamplePolicy().mode !== "all" ||
|
|
223
|
+
this.toploc.precision !== 2 || !u8aEq(this.toploc.modelHash, this.modelIdentity.modelHash) ||
|
|
224
|
+
!u8aEq(this.decodePolicyHash, this.modelIdentity.decodePolicyHash))) {
|
|
225
|
+
throw new Error("hybrid sessions require durable native witnesses and every-turn BF16 TOPLOC binding");
|
|
226
|
+
}
|
|
227
|
+
const replayInput = this.turnEvidenceStore ? request.input.slice() : undefined;
|
|
228
|
+
const hIn = blake2_256(request.input);
|
|
229
|
+
const minerRecvMs = this.nowMs();
|
|
230
|
+
const result = await backend.infer(request.input);
|
|
231
|
+
const minerDoneMs = this.nowMs();
|
|
232
|
+
const latencyMs = minerDoneMs >= minerRecvMs ? minerDoneMs - minerRecvMs : 0n;
|
|
233
|
+
if (result.promptTokens < 0n || result.generatedTokens < 0n) {
|
|
234
|
+
throw new Error("backend token counts must be non-negative");
|
|
235
|
+
}
|
|
236
|
+
if (isDenseGdnArch(this.arch)) {
|
|
237
|
+
const e = result.hybridExecution;
|
|
238
|
+
const decode = result.generatedTokens > 0n ? result.generatedTokens - 1n : 0n;
|
|
239
|
+
if (!this.modelIdentity || !result.promptIds || !result.generatedIds || !result.toplocLanes?.length ||
|
|
240
|
+
!e || e.profileSha256 !== DENSE_GDN_PROFILE_SHA256 || e.coldStart !== true ||
|
|
241
|
+
!Number.isSafeInteger(e.prefillTokens) || !Number.isSafeInteger(e.decodeForwards) ||
|
|
242
|
+
BigInt(e.prefillTokens) !== result.promptTokens || BigInt(e.decodeForwards) !== decode ||
|
|
243
|
+
e.linearLayers !== this.arch.arch.layers.filter(t => t === 0).length) {
|
|
244
|
+
throw new Error("hybrid engine reset/full-forward evidence required");
|
|
245
|
+
}
|
|
246
|
+
for (const ids of [result.promptIds, result.generatedIds]) {
|
|
247
|
+
for (const id of ids) {
|
|
248
|
+
if (!Number.isInteger(id) || id < 0 || BigInt(id) >= this.arch.arch.dimensions[2]) {
|
|
249
|
+
throw new Error("invalid hybrid native token ID");
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
let hOut;
|
|
255
|
+
if (this.modelIdentity) {
|
|
256
|
+
if (!result.modelIdentity || !sameModelIdentity(result.modelIdentity, this.modelIdentity)) {
|
|
257
|
+
throw new Error("backend model identity does not match the gated session identity");
|
|
258
|
+
}
|
|
259
|
+
if (!result.finishReason)
|
|
260
|
+
throw new Error("backend finish reason is required");
|
|
261
|
+
hOut = turnEvidenceHash(result.output, result.promptTokens, result.generatedTokens, result.finishReason, result.modelIdentity);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
hOut = blake2_256(result.output);
|
|
265
|
+
}
|
|
266
|
+
const toplocCommitment = this.toploc && result.toplocLanes
|
|
267
|
+
? {
|
|
268
|
+
taskHash: this.channelId,
|
|
269
|
+
modelHash: this.toploc.modelHash,
|
|
270
|
+
turnIndex,
|
|
271
|
+
layerIndex: this.toploc.layerIndex,
|
|
272
|
+
seed: this.toploc.seed,
|
|
273
|
+
lanes: result.toplocLanes.slice(),
|
|
274
|
+
}
|
|
275
|
+
: undefined;
|
|
276
|
+
// Measure g_n in-enclave from the real token counts + the model arch —
|
|
277
|
+
// never trust a caller-supplied value (Q4; leaf format unchanged).
|
|
278
|
+
const gn = gnFromMeasuredGn(meteredReferenceGn(this.arch, result.promptTokens, result.generatedTokens));
|
|
279
|
+
const aggregate = this.aggregate + gn.value;
|
|
280
|
+
const unacked = this.unacked + gn.value;
|
|
281
|
+
if (aggregate > (1n << 128n) - 1n || unacked > (1n << 128n) - 1n) {
|
|
282
|
+
throw new RangeError("session reference work exceeds u128 width");
|
|
283
|
+
}
|
|
284
|
+
this.lastGnSource = gn.source;
|
|
285
|
+
// #871: when the backend commits token-id sequences, sign a V3 leaf binding
|
|
286
|
+
// `h_ids` (the metering-cert witness) + the per-turn TOPLOC commitment hash.
|
|
287
|
+
// V2 is permitted only without a TOPLOC commitment. TEE-optional: the
|
|
288
|
+
// session key covers the commitment so accounting integrity does not rest
|
|
289
|
+
// on trusting the signer.
|
|
290
|
+
let turnHIds;
|
|
291
|
+
let turnToplocHash;
|
|
292
|
+
let leaf;
|
|
293
|
+
if (result.promptIds !== undefined && result.generatedIds !== undefined) {
|
|
294
|
+
// Fail closed: the committed id counts are the billed counts, so a mismatch
|
|
295
|
+
// between the id-sequence lengths and the measured token counts is fraud.
|
|
296
|
+
if (BigInt(result.promptIds.length) !== result.promptTokens ||
|
|
297
|
+
BigInt(result.generatedIds.length) !== result.generatedTokens) {
|
|
298
|
+
throw new Error("V3 leaf: committed token-id sequence length != measured token count");
|
|
299
|
+
}
|
|
300
|
+
turnHIds = computeHIds(result.promptIds, result.generatedIds);
|
|
301
|
+
// TOPLOC binding: zero-hash only when the turn is not sampled; when it IS
|
|
302
|
+
// sampled the real commitment hash MUST be bound (never a silent default).
|
|
303
|
+
const sampled = !!this.toploc && isToplocTurnSelected(turnIndex, this.toplocSamplePolicy());
|
|
304
|
+
if (sampled && !result.toplocLanes) {
|
|
305
|
+
throw new Error("V3 leaf: turn is TOPLOC-sampled but no activation lanes to bind (fail closed)");
|
|
306
|
+
}
|
|
307
|
+
turnToplocHash = sampled && toplocCommitment
|
|
308
|
+
? toplocCommitmentHash(encodeToplocActivationCommitment(toplocCommitment))
|
|
309
|
+
: ZERO_HASH;
|
|
310
|
+
leaf = transcriptLeafV3(this.channelId, turnIndex, hIn, hOut, gn.value, this.decodePolicyHash, turnHIds, turnToplocHash, minerRecvMs, minerDoneMs, latencyMs);
|
|
311
|
+
}
|
|
312
|
+
else if (result.promptIds !== undefined ||
|
|
313
|
+
result.generatedIds !== undefined) {
|
|
314
|
+
// Only one side committed: a malformed metering result. Fail closed
|
|
315
|
+
// instead of silently downgrading to V2 and dropping the V3 checks.
|
|
316
|
+
throw new Error("V3 leaf: only one of promptIds/generatedIds was committed (fail closed)");
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
if (toplocCommitment) {
|
|
320
|
+
throw new Error("V2 leaf cannot bind a TOPLOC activation commitment (fail closed)");
|
|
321
|
+
}
|
|
322
|
+
leaf = transcriptLeafV2(this.channelId, turnIndex, hIn, hOut, gn.value, this.decodePolicyHash, minerRecvMs, minerDoneMs, latencyMs);
|
|
323
|
+
}
|
|
324
|
+
const enclaveSig = this.enclave.sign(leaf);
|
|
325
|
+
const turn = {
|
|
326
|
+
leafVersion: leafVersionFromFields(this.decodePolicyHash, turnHIds),
|
|
327
|
+
turnIndex,
|
|
328
|
+
hIn,
|
|
329
|
+
hOut,
|
|
330
|
+
gN: gn.value,
|
|
331
|
+
decodePolicyHash: this.decodePolicyHash,
|
|
332
|
+
hIds: turnHIds,
|
|
333
|
+
toplocCommitmentHash: turnToplocHash,
|
|
334
|
+
minerRecvMs,
|
|
335
|
+
minerDoneMs,
|
|
336
|
+
latencyMs,
|
|
337
|
+
enclaveSig,
|
|
338
|
+
};
|
|
339
|
+
if (this.turnEvidenceStore) {
|
|
340
|
+
if (!toplocCommitment)
|
|
341
|
+
throw new Error("private audit handoff requires captured TOPLOC evidence");
|
|
342
|
+
await this.turnEvidenceStore.saveTurn({
|
|
343
|
+
channelId: this.channelId,
|
|
344
|
+
enclaveKey: this.enclave.publicKey,
|
|
345
|
+
agentKey: this.agentKey,
|
|
346
|
+
modelIdentity: this.modelIdentity,
|
|
347
|
+
input: replayInput,
|
|
348
|
+
turn,
|
|
349
|
+
commitment: toplocCommitment,
|
|
350
|
+
...(isDenseGdnArch(this.arch) ? { hybrid: {
|
|
351
|
+
descriptor: { ...this.arch, configSha256: this.arch.configSha256.slice(),
|
|
352
|
+
arch: { ...this.arch.arch, dimensions: [...this.arch.arch.dimensions], layers: [...this.arch.arch.layers] } },
|
|
353
|
+
witness: { input: replayInput, output: result.output.slice(),
|
|
354
|
+
promptIds: result.promptIds.slice(), generatedIds: result.generatedIds.slice(),
|
|
355
|
+
finishReason: result.finishReason, toplocCommitmentHash: turnToplocHash.slice(),
|
|
356
|
+
minerRecvMs, minerDoneMs, latencyMs },
|
|
357
|
+
} } : {}),
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
if (toplocCommitment)
|
|
361
|
+
this.toplocCommitments.push(toplocCommitment);
|
|
362
|
+
const runningRoot = this.accumulator.push(leaf);
|
|
363
|
+
this.turnCheckpointRoots.set(turnIndex, runningRoot.slice());
|
|
364
|
+
this.turns.push(turn);
|
|
365
|
+
this.aggregate = aggregate;
|
|
366
|
+
this.unacked = unacked;
|
|
367
|
+
// Doc rule: stop streaming once unacked_gn > MaxUnackedGn (next serve refuses).
|
|
368
|
+
if (this.unacked > this.maxUnackedGn) {
|
|
369
|
+
this.fenceBreached = true;
|
|
370
|
+
}
|
|
371
|
+
// Production caller: policy-selected TOPLOC → neutral validator DA (idempotent).
|
|
372
|
+
// Best-effort at serve time: the turn is already folded, fence state updated,
|
|
373
|
+
// and its receipt is about to be returned. A DA outage must NOT throw out of
|
|
374
|
+
// serveTurn — that would leave the turn committed + counted against the fence
|
|
375
|
+
// while the agent never received a receipt to ack, wedging the session under
|
|
376
|
+
// maxUnackedGn=0. Publish failures are recorded in toplocMetrics.failures;
|
|
377
|
+
// evidence stays unpublished so settlement still fails closed
|
|
378
|
+
// (assertToplocEvidenceForSettlement), and can be retried later via
|
|
379
|
+
// publishSelectedToplocActivations.
|
|
380
|
+
//
|
|
381
|
+
// Fire-and-forget: the publish is NOT awaited — a DA round-trip on the turn
|
|
382
|
+
// path would add its latency to every sampled turn's receipt (default policy
|
|
383
|
+
// samples every turn). Settlement/tests await completion via
|
|
384
|
+
// flushToplocPublishes(); publishToplocActivation is idempotent.
|
|
385
|
+
if (this.daSink &&
|
|
386
|
+
this.toploc &&
|
|
387
|
+
result.toplocLanes &&
|
|
388
|
+
isToplocTurnSelected(turnIndex, this.toplocSamplePolicy())) {
|
|
389
|
+
const inflight = this.publishToplocActivation(this.daSink, turnIndex)
|
|
390
|
+
.catch(() => {
|
|
391
|
+
// Swallowed by design (see above): never wedge the live session on a
|
|
392
|
+
// transient DA failure; the money path fails closed at settlement.
|
|
393
|
+
})
|
|
394
|
+
.finally(() => {
|
|
395
|
+
this.pendingToplocPublishes.delete(inflight);
|
|
396
|
+
});
|
|
397
|
+
this.pendingToplocPublishes.add(inflight);
|
|
398
|
+
}
|
|
399
|
+
return {
|
|
400
|
+
leafVersion: leafVersionFromFields(this.decodePolicyHash, turnHIds),
|
|
401
|
+
turnIndex,
|
|
402
|
+
hIn,
|
|
403
|
+
hOut,
|
|
404
|
+
output: result.output,
|
|
405
|
+
promptTokens: this.modelIdentity ? result.promptTokens : undefined,
|
|
406
|
+
completionTokens: this.modelIdentity ? result.generatedTokens : undefined,
|
|
407
|
+
finishReason: this.modelIdentity ? result.finishReason : undefined,
|
|
408
|
+
modelIdentity: this.modelIdentity ? cloneModelIdentity(this.modelIdentity) : undefined,
|
|
409
|
+
gN: gn.value,
|
|
410
|
+
decodePolicyHash: this.decodePolicyHash,
|
|
411
|
+
// #871: surface the V3 fields the leaf was signed over so the agent can
|
|
412
|
+
// reconstruct the same V3 leaf when verifying + folding the receipt.
|
|
413
|
+
hIds: turnHIds,
|
|
414
|
+
toplocCommitmentHash: turnToplocHash,
|
|
415
|
+
minerRecvMs,
|
|
416
|
+
minerDoneMs,
|
|
417
|
+
latencyMs,
|
|
418
|
+
enclaveSig,
|
|
419
|
+
runningRoot,
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
recordAck(ack) {
|
|
423
|
+
const turn = this.turns[ack.turnIndex];
|
|
424
|
+
if (!turn)
|
|
425
|
+
throw new Error("ack for unknown turn");
|
|
426
|
+
const leaf = reconstructTurnLeaf(this.channelId, turn);
|
|
427
|
+
if (!u8aEq(leaf, ack.leafHash))
|
|
428
|
+
throw new Error("ack leaf mismatch");
|
|
429
|
+
// Verify the agent's signature before persisting. Without this check a miner
|
|
430
|
+
// could inject fabricated timestamps into the DA transcript, making latency
|
|
431
|
+
// scorers/auditors treat attacker-chosen values as co-signed.
|
|
432
|
+
if (!verifyTurnAck(this.agentKey, this.channelId, ack.turnIndex, ack.leafHash, ack.agentSendMs, ack.agentRecvMs, ack.agentSig)) {
|
|
433
|
+
throw new Error("ack signature did not verify under the committed agent key");
|
|
434
|
+
}
|
|
435
|
+
if (turn.agentAck &&
|
|
436
|
+
(turn.agentAck.agentSendMs !== ack.agentSendMs ||
|
|
437
|
+
turn.agentAck.agentRecvMs !== ack.agentRecvMs ||
|
|
438
|
+
!u8aEq(turn.agentAck.agentSig, ack.agentSig))) {
|
|
439
|
+
throw new Error("conflicting ack for turn");
|
|
440
|
+
}
|
|
441
|
+
const wasUnacked = !turn.agentAck;
|
|
442
|
+
turn.agentAck = {
|
|
443
|
+
agentSendMs: ack.agentSendMs,
|
|
444
|
+
agentRecvMs: ack.agentRecvMs,
|
|
445
|
+
agentSig: ack.agentSig.slice(),
|
|
446
|
+
};
|
|
447
|
+
if (wasUnacked) {
|
|
448
|
+
this.unacked -= turn.gN;
|
|
449
|
+
if (this.unacked < 0n)
|
|
450
|
+
this.unacked = 0n;
|
|
451
|
+
}
|
|
452
|
+
// Honest laggy agent re-acks → under fence again → resume serving.
|
|
453
|
+
if (this.unacked <= this.maxUnackedGn) {
|
|
454
|
+
this.fenceBreached = false;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Persist a co-signed cumulative receipt (agent signed over root ‖ aggregate G_n
|
|
459
|
+
* for the acked prefix). Highest-throughTurn wins; used for force_settle after
|
|
460
|
+
* fence breach / agent disappearance.
|
|
461
|
+
*/
|
|
462
|
+
recordCheckpoint(checkpoint) {
|
|
463
|
+
if (!verifyReceipt(this.agentKey, this.channelId, checkpoint.finalRoot, checkpoint.aggregateGn, checkpoint.payable, checkpoint.agentReceiptSig)) {
|
|
464
|
+
throw new Error("checkpoint receipt signature did not verify under the committed agent key");
|
|
465
|
+
}
|
|
466
|
+
if (this.lastCheckpoint &&
|
|
467
|
+
checkpoint.throughTurn < this.lastCheckpoint.throughTurn) {
|
|
468
|
+
return; // stale lower receipt — keep highest
|
|
469
|
+
}
|
|
470
|
+
this.lastCheckpoint = {
|
|
471
|
+
finalRoot: checkpoint.finalRoot.slice(),
|
|
472
|
+
aggregateGn: checkpoint.aggregateGn,
|
|
473
|
+
payable: checkpoint.payable,
|
|
474
|
+
throughTurn: checkpoint.throughTurn,
|
|
475
|
+
agentReceiptSig: checkpoint.agentReceiptSig.slice(),
|
|
476
|
+
};
|
|
477
|
+
// Persist the new settle-critical datum (best-effort, off the hot path; a
|
|
478
|
+
// caller awaits durability via flushPersists() before relying on it).
|
|
479
|
+
this.persist();
|
|
480
|
+
}
|
|
481
|
+
/** Snapshot the settle-critical prefix (checkpoint + turns ≤ throughTurn). */
|
|
482
|
+
snapshot() {
|
|
483
|
+
const cp = this.lastCheckpoint;
|
|
484
|
+
return {
|
|
485
|
+
channelId: this.channelId.slice(),
|
|
486
|
+
checkpoint: {
|
|
487
|
+
finalRoot: cp.finalRoot.slice(),
|
|
488
|
+
aggregateGn: cp.aggregateGn,
|
|
489
|
+
payable: cp.payable,
|
|
490
|
+
throughTurn: cp.throughTurn,
|
|
491
|
+
agentReceiptSig: cp.agentReceiptSig.slice(),
|
|
492
|
+
},
|
|
493
|
+
turns: this.transcriptBlob().turns.filter((t) => t.turnIndex <= cp.throughTurn),
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
/** Fire-and-forget durable save of the current snapshot (tracked for flush). */
|
|
497
|
+
persist() {
|
|
498
|
+
if (!this.sessionStore || !this.lastCheckpoint)
|
|
499
|
+
return;
|
|
500
|
+
const snapshot = this.snapshot();
|
|
501
|
+
const store = this.sessionStore;
|
|
502
|
+
const p = this.persistQueue
|
|
503
|
+
.then(() => store.save(this.channelId, snapshot))
|
|
504
|
+
.then(() => {
|
|
505
|
+
this.durableCheckpoint = snapshot.checkpoint;
|
|
506
|
+
})
|
|
507
|
+
.catch((err) => {
|
|
508
|
+
// A store outage must not throw out of recordCheckpoint (that would wedge the
|
|
509
|
+
// live fence path). Record it so flushPersists() can surface the durability gap
|
|
510
|
+
// instead of silently converting the failure into success.
|
|
511
|
+
this.lastPersistError = err instanceof Error ? err : new Error(String(err));
|
|
512
|
+
})
|
|
513
|
+
.finally(() => this.pendingPersists.delete(p));
|
|
514
|
+
this.pendingPersists.add(p);
|
|
515
|
+
this.persistQueue = p;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Await all in-flight persists (call before relying on durability, e.g. tests).
|
|
519
|
+
*
|
|
520
|
+
* Throws if the latest co-signed checkpoint never reached the store: a swallowed save
|
|
521
|
+
* failure (disk full / DB down) must not masquerade as durable, or the host could ack
|
|
522
|
+
* the checkpoint and continue, then be unable to restore / force-settle that co-signed
|
|
523
|
+
* work after a crash. Callers that await durability get a real failure, not a false ok.
|
|
524
|
+
*/
|
|
525
|
+
async flushPersists() {
|
|
526
|
+
while (this.pendingPersists.size > 0) {
|
|
527
|
+
await Promise.all([...this.pendingPersists]);
|
|
528
|
+
}
|
|
529
|
+
if (this.sessionStore &&
|
|
530
|
+
this.lastCheckpoint &&
|
|
531
|
+
(!this.durableCheckpoint
|
|
532
|
+
|| this.durableCheckpoint.throughTurn !== this.lastCheckpoint.throughTurn
|
|
533
|
+
|| this.durableCheckpoint.aggregateGn !== this.lastCheckpoint.aggregateGn
|
|
534
|
+
|| this.durableCheckpoint.payable !== this.lastCheckpoint.payable
|
|
535
|
+
|| !u8aEq(this.durableCheckpoint.finalRoot, this.lastCheckpoint.finalRoot)
|
|
536
|
+
|| !u8aEq(this.durableCheckpoint.agentReceiptSig, this.lastCheckpoint.agentReceiptSig))) {
|
|
537
|
+
throw (this.lastPersistError ??
|
|
538
|
+
new Error("durable checkpoint save did not complete — checkpoint is not recoverable"));
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Rebuild a **settle-only** host from a persisted snapshot after a crash.
|
|
543
|
+
*
|
|
544
|
+
* Verifies integrity first (fail closed): the accumulator root rebuilt from the
|
|
545
|
+
* persisted leaves MUST equal the persisted checkpoint root — a tampered/torn
|
|
546
|
+
* snapshot is refused. The returned host can produce the identical
|
|
547
|
+
* `force_settle` claim for the co-signed prefix (via
|
|
548
|
+
* {@link buildForceSettleFromLastCheckpoint}) but CANNOT serve new turns: the
|
|
549
|
+
* enclave signing key is not persisted (gone after a real TEE restart), so
|
|
550
|
+
* {@link serveTurn} throws. The goal is settle-ability, not continuation.
|
|
551
|
+
*/
|
|
552
|
+
static async restore(channelId, store) {
|
|
553
|
+
const snap = await store.load(channelId);
|
|
554
|
+
if (!snap)
|
|
555
|
+
throw new Error("restore: no persisted session for channel");
|
|
556
|
+
// Integrity: the persisted leaves must rebuild the co-signed checkpoint root.
|
|
557
|
+
const acc = new MerkleAccumulator();
|
|
558
|
+
for (const t of snap.turns)
|
|
559
|
+
acc.push(reconstructTurnLeaf(snap.channelId, t));
|
|
560
|
+
if (!u8aEq(acc.root(), snap.checkpoint.finalRoot)) {
|
|
561
|
+
throw new Error("restore refused: persisted leaves do not rebuild the checkpoint root " +
|
|
562
|
+
"(tampered or corrupt snapshot) — fail closed");
|
|
563
|
+
}
|
|
564
|
+
// Placeholder enclave/agent key + arch: never used on the settle-only path
|
|
565
|
+
// (buildForceSettleFromLastCheckpoint signs nothing and the enclave sigs are
|
|
566
|
+
// already in the persisted leaves). serveTurn is guarded by `restored`.
|
|
567
|
+
const host = new MinerSessionHost(snap.channelId, SessionKey.generate(), LLAMA3_8B, 0, new Uint8Array(32));
|
|
568
|
+
host.restored = true;
|
|
569
|
+
host.turns = snap.turns;
|
|
570
|
+
host.accumulator = acc;
|
|
571
|
+
host.aggregate = snap.checkpoint.aggregateGn;
|
|
572
|
+
host.lastCheckpoint = snap.checkpoint;
|
|
573
|
+
return host;
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Build a unilateral force_settle claim from the last co-signed checkpoint.
|
|
577
|
+
* Returns null if the agent never co-signed a cumulative receipt.
|
|
578
|
+
*/
|
|
579
|
+
buildForceSettleFromLastCheckpoint(claimedMeasuredRoot, transcriptRef) {
|
|
580
|
+
const cp = this.lastCheckpoint;
|
|
581
|
+
if (!cp)
|
|
582
|
+
return null;
|
|
583
|
+
// Build the proof bundle over the co-signed prefix (turns ≤ cp.throughTurn),
|
|
584
|
+
// NOT the full transcript. The pallet reconstructs every verified turn's
|
|
585
|
+
// Merkle path against the claim's `final_root` (= the prefix root) and
|
|
586
|
+
// requires Σ g_n == aggregate_gn (the prefix aggregate). Including the
|
|
587
|
+
// unacked tail would build paths against the full-tree root and over-count
|
|
588
|
+
// g_n, so force_settle would reject (LeafNotInRoot / AggregateGnMismatch) the
|
|
589
|
+
// moment there is an unacked tail — defeating the fence's force-settle path.
|
|
590
|
+
const prefix = new TranscriptBlob(this.channelId, this.transcriptBlob().turns.filter((t) => t.turnIndex <= cp.throughTurn));
|
|
591
|
+
return {
|
|
592
|
+
channelId: this.channelId,
|
|
593
|
+
finalRoot: cp.finalRoot.slice(),
|
|
594
|
+
aggregateGn: cp.aggregateGn,
|
|
595
|
+
payable: cp.payable,
|
|
596
|
+
claimedMeasuredRoot,
|
|
597
|
+
agentReceiptSig: cp.agentReceiptSig.slice(),
|
|
598
|
+
transcriptRef,
|
|
599
|
+
verifiedTurns: buildVerifiedTurns(prefix),
|
|
600
|
+
cooperative: false,
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
/** Whether a re-attestation is due (§4 blast-radius bound). */
|
|
604
|
+
reattestationDue() {
|
|
605
|
+
return this.reattestEvery !== 0 && this.turns.length % this.reattestEvery === 0;
|
|
606
|
+
}
|
|
607
|
+
finalRoot() {
|
|
608
|
+
return this.accumulator.root();
|
|
609
|
+
}
|
|
610
|
+
aggregateGn() {
|
|
611
|
+
return this.aggregate;
|
|
612
|
+
}
|
|
613
|
+
/** Whether a real agent receipt-signing key was committed at `open_channel`
|
|
614
|
+
* (vs the all-zero placeholder used when the caller omits one). */
|
|
615
|
+
hasAgentKey() {
|
|
616
|
+
return this.agentKey.some((byte) => byte !== 0);
|
|
617
|
+
}
|
|
618
|
+
/** Verify a cooperative-close receipt signature under the committed agent key.
|
|
619
|
+
* Mirrors the pallet's `verify_receipt` over `(channelId ‖ finalRoot ‖ gn ‖ payable)`
|
|
620
|
+
* so a bad co-signature is rejected before the miner submits (and pays for) a
|
|
621
|
+
* settle tx the pallet would reject. */
|
|
622
|
+
verifyCooperativeReceipt(agentReceiptSig, payable) {
|
|
623
|
+
return verifyReceipt(this.agentKey, this.channelId, this.finalRoot(), this.aggregate, payable, agentReceiptSig);
|
|
624
|
+
}
|
|
625
|
+
gnSource() {
|
|
626
|
+
return this.lastGnSource;
|
|
627
|
+
}
|
|
628
|
+
transcriptBlob() {
|
|
629
|
+
// Deep-copy so a caller (e.g. a challenger building a tampered blob) can't
|
|
630
|
+
// mutate the host's committed state through shared references.
|
|
631
|
+
const turns = this.turns.map((t) => ({
|
|
632
|
+
leafVersion: t.leafVersion,
|
|
633
|
+
turnIndex: t.turnIndex,
|
|
634
|
+
hIn: t.hIn.slice(),
|
|
635
|
+
hOut: t.hOut.slice(),
|
|
636
|
+
gN: t.gN,
|
|
637
|
+
decodePolicyHash: t.decodePolicyHash?.slice(),
|
|
638
|
+
hIds: t.hIds?.slice(),
|
|
639
|
+
toplocCommitmentHash: t.toplocCommitmentHash?.slice(),
|
|
640
|
+
minerRecvMs: t.minerRecvMs,
|
|
641
|
+
minerDoneMs: t.minerDoneMs,
|
|
642
|
+
latencyMs: t.latencyMs,
|
|
643
|
+
enclaveSig: t.enclaveSig.slice(),
|
|
644
|
+
agentAck: t.agentAck
|
|
645
|
+
? {
|
|
646
|
+
agentSendMs: t.agentAck.agentSendMs,
|
|
647
|
+
agentRecvMs: t.agentAck.agentRecvMs,
|
|
648
|
+
agentSig: t.agentAck.agentSig.slice(),
|
|
649
|
+
}
|
|
650
|
+
: undefined,
|
|
651
|
+
}));
|
|
652
|
+
return new TranscriptBlob(this.channelId, turns);
|
|
653
|
+
}
|
|
654
|
+
toplocActivationCommitment(turnIndex) {
|
|
655
|
+
return this.toplocCommitments.find((c) => c.turnIndex === turnIndex) ?? null;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* D-0431 settlement-gate marker (#753/#900): the non-zero commitment ref the miner
|
|
659
|
+
* submits via `submit_toploc_evidence` before settling. When TOPLOC capture is on it
|
|
660
|
+
* is the activations root over the locally-committed turns (what validators verify on
|
|
661
|
+
* the reactive path); otherwise the transcript `finalRoot` — a deterministic non-zero
|
|
662
|
+
* marker for sessions with no TOPLOC lanes (mock / metering-only), which the
|
|
663
|
+
* presence-only gate accepts. Never zero (guaranteed by a non-empty transcript).
|
|
664
|
+
*/
|
|
665
|
+
toplocEvidenceRef() {
|
|
666
|
+
const hashes = this.toplocCommitments.map((c) => toplocCommitmentHash(encodeToplocActivationCommitment(c)));
|
|
667
|
+
if (hashes.length > 0)
|
|
668
|
+
return activationsRoot(hashes);
|
|
669
|
+
return this.finalRoot().slice();
|
|
670
|
+
}
|
|
671
|
+
/** Published TOPLOC binding for a turn, if any. */
|
|
672
|
+
toplocPublishedBinding(turnIndex) {
|
|
673
|
+
return this.toplocPublished.get(turnIndex) ?? null;
|
|
674
|
+
}
|
|
675
|
+
/** All published TOPLOC bindings (session evidence activations). */
|
|
676
|
+
toplocPublishedBindings() {
|
|
677
|
+
return [...this.toplocPublished.values()].sort((a, b) => a.turnIndex - b.turnIndex);
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Turn indices that have a local commitment and are selected by the sample policy.
|
|
681
|
+
* These must be published when TOPLOC is required for settlement.
|
|
682
|
+
*/
|
|
683
|
+
toplocSelectedTurns() {
|
|
684
|
+
const policy = this.toplocSamplePolicy();
|
|
685
|
+
return this.toplocCommitments
|
|
686
|
+
.map((c) => c.turnIndex)
|
|
687
|
+
.filter((t) => isToplocTurnSelected(t, policy))
|
|
688
|
+
.sort((a, b) => a - b);
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Publish one captured TOPLOC activation commitment Ephemerally to validator DA.
|
|
692
|
+
* Idempotent: re-publishing the same turn returns the existing DataRef.
|
|
693
|
+
* Binds the ref into host session evidence (turn + checkpoint + model/precision).
|
|
694
|
+
*/
|
|
695
|
+
async publishToplocActivation(da, turnIndex) {
|
|
696
|
+
const commitment = this.toplocActivationCommitment(turnIndex);
|
|
697
|
+
if (!commitment)
|
|
698
|
+
return null;
|
|
699
|
+
if (!isToplocTurnSelected(turnIndex, this.toplocSamplePolicy())) {
|
|
700
|
+
return this.toplocPublished.get(turnIndex)?.dataRef ?? null;
|
|
701
|
+
}
|
|
702
|
+
const existing = this.toplocPublished.get(turnIndex);
|
|
703
|
+
const bytes = encodeToplocActivationCommitment(commitment);
|
|
704
|
+
const actHash = toplocCommitmentHash(bytes);
|
|
705
|
+
const dataRef = await publishEphemeralWithRetry(da, bytes, {
|
|
706
|
+
metrics: this.toplocMetrics,
|
|
707
|
+
existing: existing?.dataRef ?? null,
|
|
708
|
+
// Reuse the ref only when the blob is content-matched AND still retrievable;
|
|
709
|
+
// a dropped/expired blob must re-publish so validators can fetch evidence.
|
|
710
|
+
sameAsExisting: (ref, b) => daRefReusable(da, ref, b),
|
|
711
|
+
});
|
|
712
|
+
const checkpointRoot = this.turnCheckpointRoots.get(turnIndex)?.slice() ?? this.finalRoot().slice();
|
|
713
|
+
const binding = {
|
|
714
|
+
channelId: this.channelId.slice(),
|
|
715
|
+
turnIndex,
|
|
716
|
+
checkpointRoot: checkpointRoot,
|
|
717
|
+
modelHash: (this.toploc?.modelHash.slice() ?? commitment.modelHash.slice()),
|
|
718
|
+
precision: this.toploc?.precision ?? 0,
|
|
719
|
+
layerIndex: commitment.layerIndex,
|
|
720
|
+
seed: commitment.seed.slice(),
|
|
721
|
+
activationHash: actHash,
|
|
722
|
+
dataRef,
|
|
723
|
+
};
|
|
724
|
+
this.toplocPublished.set(turnIndex, binding);
|
|
725
|
+
return dataRef;
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Await all in-flight serve-time TOPLOC DA publishes (fire-and-forget in
|
|
729
|
+
* serveTurn). Call before building/asserting settlement evidence, or in tests
|
|
730
|
+
* that assert publication right after a serve. Publish failures were already
|
|
731
|
+
* swallowed on the turn path; settlement still fails closed on missing refs.
|
|
732
|
+
*/
|
|
733
|
+
async flushToplocPublishes() {
|
|
734
|
+
while (this.pendingToplocPublishes.size > 0) {
|
|
735
|
+
await Promise.all([...this.pendingToplocPublishes]);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* Publish all policy-selected TOPLOC commitments. Use `batch` mode to fold
|
|
740
|
+
* many turns into one ephemeral blob (cost) with a shared activations root.
|
|
741
|
+
*/
|
|
742
|
+
async publishSelectedToplocActivations(da, opts = {}) {
|
|
743
|
+
const mode = opts.mode ?? "per_turn";
|
|
744
|
+
const selected = this.toplocSelectedTurns();
|
|
745
|
+
if (selected.length === 0)
|
|
746
|
+
return [];
|
|
747
|
+
if (mode === "per_turn") {
|
|
748
|
+
for (const t of selected) {
|
|
749
|
+
await this.publishToplocActivation(da, t);
|
|
750
|
+
}
|
|
751
|
+
return this.toplocPublishedBindings().filter((b) => selected.includes(b.turnIndex));
|
|
752
|
+
}
|
|
753
|
+
// Batch: single DA publish for all selected turns still missing a ref
|
|
754
|
+
// (or always rebuild for a clean batch root when none published yet).
|
|
755
|
+
const items = [];
|
|
756
|
+
const hashes = [];
|
|
757
|
+
for (const t of selected) {
|
|
758
|
+
const c = this.toplocActivationCommitment(t);
|
|
759
|
+
if (!c)
|
|
760
|
+
continue;
|
|
761
|
+
const commitmentBytes = encodeToplocActivationCommitment(c);
|
|
762
|
+
items.push({ turnIndex: t, commitmentBytes });
|
|
763
|
+
hashes.push(toplocCommitmentHash(commitmentBytes));
|
|
764
|
+
}
|
|
765
|
+
if (items.length === 0)
|
|
766
|
+
return [];
|
|
767
|
+
const batchBytes = encodeToplocActivationBatch(this.channelId, items);
|
|
768
|
+
const dataRef = await publishEphemeralWithRetry(da, batchBytes, {
|
|
769
|
+
maxRetries: opts.maxRetries,
|
|
770
|
+
metrics: this.toplocMetrics,
|
|
771
|
+
existing: this.toplocBatchRef,
|
|
772
|
+
// Same availability-aware reuse as per-turn: never return a stale batch ref.
|
|
773
|
+
sameAsExisting: (ref, b) => daRefReusable(da, ref, b),
|
|
774
|
+
});
|
|
775
|
+
this.toplocBatchRef = dataRef;
|
|
776
|
+
this.toplocMetrics.batches += 1;
|
|
777
|
+
const precision = this.toploc?.precision ?? 0;
|
|
778
|
+
for (let i = 0; i < items.length; i++) {
|
|
779
|
+
const t = items[i].turnIndex;
|
|
780
|
+
const checkpointRoot = this.turnCheckpointRoots.get(t)?.slice() ?? this.finalRoot().slice();
|
|
781
|
+
const c = this.toplocActivationCommitment(t);
|
|
782
|
+
this.toplocPublished.set(t, {
|
|
783
|
+
channelId: this.channelId.slice(),
|
|
784
|
+
turnIndex: t,
|
|
785
|
+
checkpointRoot: checkpointRoot,
|
|
786
|
+
modelHash: (this.toploc?.modelHash.slice() ?? c.modelHash.slice()),
|
|
787
|
+
precision,
|
|
788
|
+
layerIndex: c.layerIndex,
|
|
789
|
+
seed: c.seed.slice(),
|
|
790
|
+
activationHash: hashes[i],
|
|
791
|
+
dataRef,
|
|
792
|
+
batchIndex: i,
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
return this.toplocPublishedBindings().filter((b) => selected.includes(b.turnIndex));
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Build session evidence binding each TOPLOC DataRef to session/turn/
|
|
799
|
+
* transcript/checkpoint and model/precision profile.
|
|
800
|
+
*/
|
|
801
|
+
buildToplocSessionEvidence(transcriptRef = null, publishMode = "per_turn") {
|
|
802
|
+
const activations = this.toplocPublishedBindings();
|
|
803
|
+
const root = activationsRoot(activations.map((a) => a.activationHash));
|
|
804
|
+
return {
|
|
805
|
+
channelId: this.channelId.slice(),
|
|
806
|
+
modelHash: (this.toploc?.modelHash.slice() ?? new Uint8Array(32)),
|
|
807
|
+
precision: this.toploc?.precision ?? 0,
|
|
808
|
+
samplePolicy: this.toplocSamplePolicy(),
|
|
809
|
+
publishMode,
|
|
810
|
+
transcriptRef,
|
|
811
|
+
checkpointRoot: this.finalRoot().slice(),
|
|
812
|
+
activations,
|
|
813
|
+
batchRef: this.toplocBatchRef,
|
|
814
|
+
activationsRoot: root,
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* Fail-closed gate before settlement: when TOPLOC evidence is required, every
|
|
819
|
+
* policy-selected turn with a local commitment must have a DA DataRef.
|
|
820
|
+
* Throws if evidence is missing/withheld (never silent accept).
|
|
821
|
+
*/
|
|
822
|
+
assertToplocEvidenceForSettlement() {
|
|
823
|
+
if (!this.toplocRequiredForSettlement())
|
|
824
|
+
return;
|
|
825
|
+
const selected = this.toplocSelectedTurns();
|
|
826
|
+
const published = this.toplocPublishedBindings().map((b) => b.turnIndex);
|
|
827
|
+
const action = evaluateToplocEvidenceSettlement({
|
|
828
|
+
required: true,
|
|
829
|
+
selectedTurns: selected,
|
|
830
|
+
publishedTurns: published,
|
|
831
|
+
daStatus: "available",
|
|
832
|
+
});
|
|
833
|
+
if (action !== ToplocEvidenceSettlementAction.Accept) {
|
|
834
|
+
throw new Error(`TOPLOC evidence required for settlement but incomplete ` +
|
|
835
|
+
`(selected=[${selected.join(",")}] published=[${published.join(",")}]) ` +
|
|
836
|
+
`→ ${action} (refund/freeze, never silent accept)`);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
/**
|
|
840
|
+
* Drop host-side published bindings (after challenge window). Does not delete
|
|
841
|
+
* neutral-DA blobs — validators retain Ephemeral data until W expires.
|
|
842
|
+
*/
|
|
843
|
+
pruneToplocPublished(turnIndices) {
|
|
844
|
+
let n = 0;
|
|
845
|
+
if (!turnIndices) {
|
|
846
|
+
n = this.toplocPublished.size;
|
|
847
|
+
this.toplocPublished.clear();
|
|
848
|
+
this.toplocBatchRef = null;
|
|
849
|
+
}
|
|
850
|
+
else {
|
|
851
|
+
for (const t of turnIndices) {
|
|
852
|
+
if (this.toplocPublished.delete(t))
|
|
853
|
+
n += 1;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
this.toplocMetrics.pruned += n;
|
|
857
|
+
return n;
|
|
858
|
+
}
|
|
859
|
+
/** Publish the transcript Ephemerally to validator DA. */
|
|
860
|
+
async publishTranscript(da) {
|
|
861
|
+
return da.publishEphemeral(this.transcriptBlob().encode());
|
|
862
|
+
}
|
|
863
|
+
/** Build a settlement claim (`settle` if cooperative, else `force_settle`). */
|
|
864
|
+
buildSettlement(claimedMeasuredRoot, agentReceiptSig, payable, transcriptRef, cooperative) {
|
|
865
|
+
// Fail closed: required TOPLOC evidence must be on neutral DA before settle.
|
|
866
|
+
this.assertToplocEvidenceForSettlement();
|
|
867
|
+
return {
|
|
868
|
+
channelId: this.channelId,
|
|
869
|
+
finalRoot: this.finalRoot(),
|
|
870
|
+
aggregateGn: this.aggregate,
|
|
871
|
+
payable,
|
|
872
|
+
claimedMeasuredRoot,
|
|
873
|
+
agentReceiptSig,
|
|
874
|
+
transcriptRef,
|
|
875
|
+
verifiedTurns: buildVerifiedTurns(this.transcriptBlob()),
|
|
876
|
+
cooperative,
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
//# sourceMappingURL=miner-host.js.map
|