@flop-labs/sdk 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +315 -0
- package/LICENSE +238 -0
- package/README.md +622 -2
- package/dist/a2a/agent-card.d.ts +56 -0
- package/dist/a2a/agent-card.d.ts.map +1 -0
- package/dist/a2a/agent-card.js +111 -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 +115 -0
- package/dist/a2a-cjs/agent-card.js.map +1 -0
- package/dist/a2a-cjs/index.js +21 -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 +444 -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 +408 -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.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 +356 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +863 -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 +364 -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 +245 -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 +208 -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/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 +134 -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 +47 -0
- package/dist/compute-channel/index.d.ts.map +1 -0
- package/dist/compute-channel/index.js +48 -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/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 +217 -0
- package/dist/compute-channel/transport-http.d.ts.map +1 -0
- package/dist/compute-channel/transport-http.js +625 -0
- package/dist/compute-channel/transport-http.js.map +1 -0
- package/dist/coordination.d.ts +341 -0
- package/dist/coordination.d.ts.map +1 -0
- package/dist/coordination.js +481 -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 +1005 -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 +141 -0
- package/dist/faucet.d.ts.map +1 -0
- package/dist/faucet.js +312 -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/index.d.ts +109 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +140 -0
- package/dist/index.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 +105 -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 +20 -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 +33 -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/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 +111 -0
- package/dist/x402.d.ts.map +1 -0
- package/dist/x402.js +206 -0
- package/dist/x402.js.map +1 -0
- package/package.json +165 -3
|
@@ -0,0 +1,1038 @@
|
|
|
1
|
+
/** Owner-only, pre-funded UNRATIFIED (E.54) paid-memory client. */
|
|
2
|
+
import { decodePaidStorageRecord, encodePaidStorageRecord, paidStorageSigningPreimage } from "../paid-storage-wire.js";
|
|
3
|
+
import { cryptoWaitReady, sr25519Verify } from "@polkadot/util-crypto";
|
|
4
|
+
import { concat, equal, hash, hex, integer, json, unhex, utf8 } from "./bytes.js";
|
|
5
|
+
import { bindingBytes, decryptObject, encryptObject, opaqueIdentifier, unwrapObjectKey, wrapObjectKey } from "./crypto.js";
|
|
6
|
+
import { encodeShards, reconstructShards } from "./codec.js";
|
|
7
|
+
import { checkProfile, cryptoProfileId, SHARD_PREFIX } from "./profile.js";
|
|
8
|
+
import { encodePlan, encodeShardRequest, PaidShardTransportError, placementPayload, requestEnvelope, responseWorkBytes, signShardRequest, verifyPlacement } from "./transport.js";
|
|
9
|
+
import { VoucherManager } from "./vouchers.js";
|
|
10
|
+
const storedPlan = (p) => ({ genesis: hex(p.genesis), reservation: p.reservation.toString(), generation: p.assignmentGeneration, namespace: hex(p.namespace), object: hex(p.object), version: p.version.toString(), nonce: hex(p.nonce), shards: p.shards.map((s) => ({ provider: hex(s.provider), position: s.position, commitment: hex(s.commitment), length: s.encodedLength.toString() })) });
|
|
11
|
+
const loadPlan = (p) => ({ genesis: unhex(p.genesis, 32), reservation: BigInt(p.reservation), assignmentGeneration: p.generation, namespace: unhex(p.namespace, 32), object: unhex(p.object, 32), version: BigInt(p.version), nonce: unhex(p.nonce, 32), shards: p.shards.map((s) => ({ provider: unhex(s.provider, 32), position: s.position, commitment: unhex(s.commitment, 32), encodedLength: BigInt(s.length) })) });
|
|
12
|
+
const binding = (p) => ({ genesis: p.genesis, reservation: p.reservation, namespace: p.namespace, object: p.object, version: p.version });
|
|
13
|
+
const buffer = (bytes) => Uint8Array.from(bytes).buffer;
|
|
14
|
+
const randomNonce = () => globalThis.crypto.getRandomValues(new Uint8Array(32));
|
|
15
|
+
const referenceCommitment = (object, commitment, lanes) => hex(hash(json([object.plan, object.ciphertextCommitment, commitment, ...(object.ranges ? [object.ranges] : []), ...(lanes ? [lanes] : [])])));
|
|
16
|
+
const loadAuthority = (bytes) => JSON.parse(bytes, (_name, value) => {
|
|
17
|
+
if (!value || typeof value !== "object" || Object.keys(value).length !== 1)
|
|
18
|
+
return value;
|
|
19
|
+
if ("bigint" in value) {
|
|
20
|
+
if (typeof value.bigint !== "string" || !/^[0-9]+$/.test(value.bigint))
|
|
21
|
+
throw new Error("Paid-memory admission tag invalid.");
|
|
22
|
+
return BigInt(value.bigint);
|
|
23
|
+
}
|
|
24
|
+
if ("bytes" in value) {
|
|
25
|
+
if (typeof value.bytes !== "string")
|
|
26
|
+
throw new Error("Paid-memory admission tag invalid.");
|
|
27
|
+
return unhex(value.bytes);
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
});
|
|
31
|
+
const loadAdmission = (bytes) => loadAuthority(bytes);
|
|
32
|
+
const serializeAuthority = (value) => JSON.stringify(value, (_name, entry) => typeof entry === "bigint" ? { bigint: entry.toString() } : entry instanceof Uint8Array ? { bytes: hex(entry) } : entry);
|
|
33
|
+
const capsuleCommitment = (saved) => hex(hash(json([saved.encoded, saved.signature, saved.voucher, saved.at, saved.namespaceEpoch, saved.objectEpoch])));
|
|
34
|
+
class OperationCompleted extends Error {
|
|
35
|
+
}
|
|
36
|
+
class InvalidRangeResponse extends Error {
|
|
37
|
+
}
|
|
38
|
+
function compact(operation, pending) {
|
|
39
|
+
operation.shards = [];
|
|
40
|
+
operation.requests = {};
|
|
41
|
+
operation.attestations = {};
|
|
42
|
+
delete operation.head;
|
|
43
|
+
if (pending.length === 0)
|
|
44
|
+
operation.ranges = {};
|
|
45
|
+
}
|
|
46
|
+
export class PaidMemoryClient {
|
|
47
|
+
options;
|
|
48
|
+
async putAuthentication(operation, key, recovery = false, mint = false) {
|
|
49
|
+
if (operation.kind !== "put" || !operation.lanes || (recovery && !operation.casRecovery))
|
|
50
|
+
throw new Error("Paid-memory CAS recovery authority unavailable.");
|
|
51
|
+
const domain = recovery ? "cas-proof-recovery" : "put-authority", plan = loadPlan(operation.object.plan);
|
|
52
|
+
const context = concat(unhex(this.identity, 32), bindingBytes(binding(plan)), unhex(operation.object.profileId, 32));
|
|
53
|
+
const material = await crypto.subtle.importKey("raw", buffer(key), "HKDF", false, ["deriveKey"]);
|
|
54
|
+
const derived = await crypto.subtle.deriveKey({ name: "HKDF", hash: "SHA-256", salt: new Uint8Array(32), info: buffer(concat(utf8(`flop/paid-storage/${domain}-key/v1`), context)) }, material, { name: "HMAC", hash: "SHA-256", length: 256 }, false, ["sign", "verify"]);
|
|
55
|
+
const payload = buffer(concat(utf8(`flop/paid-storage/${domain}/v1`), context, json([operation.prepared.reference.operationId, operation.identity, operation.inputCommitment, operation.namespace, operation.maxCost, operation.kind,
|
|
56
|
+
operation.scopeNamespace, operation.scopeObject, operation.previous, operation.nonce, operation.prepared, operation.lanes, operation.object,
|
|
57
|
+
...(recovery ? [operation.casRecovery.admission, operation.casRecovery.attestations] : [])])));
|
|
58
|
+
if (mint) {
|
|
59
|
+
const tag = hex(new Uint8Array(await crypto.subtle.sign("HMAC", derived, payload)));
|
|
60
|
+
if (recovery)
|
|
61
|
+
operation.casRecovery.tag = tag;
|
|
62
|
+
else
|
|
63
|
+
operation.putAuthority = tag;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const tag = recovery ? operation.casRecovery.tag : operation.putAuthority;
|
|
67
|
+
if (!tag || !await crypto.subtle.verify("HMAC", derived, buffer(unhex(tag, 32)), payload))
|
|
68
|
+
throw new Error("Paid-memory CAS recovery authentication failed.");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async replayAuthentication(operation, key, record, mint = false) {
|
|
72
|
+
if (!operation.lanes || (record && !record.saved.replay))
|
|
73
|
+
throw new Error("Paid-memory replay capsule unavailable.");
|
|
74
|
+
const domain = record ? "request-capsule" : "replay-authority", plan = loadPlan(operation.object.plan);
|
|
75
|
+
const context = concat(unhex(this.identity, 32), bindingBytes(binding(plan)), unhex(operation.object.profileId, 32));
|
|
76
|
+
const material = await crypto.subtle.importKey("raw", buffer(key), "HKDF", false, ["deriveKey"]);
|
|
77
|
+
const derived = await crypto.subtle.deriveKey({ name: "HKDF", hash: "SHA-256", salt: new Uint8Array(32), info: buffer(concat(utf8(`flop/paid-storage/${domain}-key/v1`), context)) }, material, { name: "HMAC", hash: "SHA-256", length: 256 }, false, ["sign", "verify"]);
|
|
78
|
+
const replay = record?.saved.replay;
|
|
79
|
+
const payload = buffer(concat(utf8(`flop/paid-storage/${domain}/v1`), context, json([operation.prepared.reference.operationId, operation.identity, operation.inputCommitment, operation.namespace, operation.maxCost, operation.kind,
|
|
80
|
+
operation.scopeNamespace, operation.scopeObject, operation.nonce, operation.prepared, operation.lanes, hex(hash(encodePlan(plan))), operation.object.ciphertextCommitment, operation.object.privateManifest, operation.object.rangeTag,
|
|
81
|
+
...(record ? [record.requestKey, record.saved.encoded, record.saved.signature, record.saved.voucher, record.saved.at, record.saved.namespaceEpoch, record.saved.objectEpoch, replay.provider, replay.lane, replay.scopeNamespace, replay.scopeObject, replay.end] : operation.originalRead === undefined ? [] : [operation.originalRead])])));
|
|
82
|
+
if (mint) {
|
|
83
|
+
const tag = hex(new Uint8Array(await crypto.subtle.sign("HMAC", derived, payload)));
|
|
84
|
+
if (replay)
|
|
85
|
+
replay.tag = tag;
|
|
86
|
+
else
|
|
87
|
+
operation.replayAuthority = tag;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const tag = replay?.tag ?? operation.replayAuthority;
|
|
91
|
+
if (!tag || !await crypto.subtle.verify("HMAC", derived, buffer(unhex(tag, 32)), payload))
|
|
92
|
+
throw new Error("Paid-memory replay capsule authentication failed.");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async operationAuthentication(operation, key) {
|
|
96
|
+
switch (operation.kind) {
|
|
97
|
+
case "get":
|
|
98
|
+
await this.replayAuthentication(operation, key);
|
|
99
|
+
return;
|
|
100
|
+
case "put":
|
|
101
|
+
await this.putAuthentication(operation, key);
|
|
102
|
+
return;
|
|
103
|
+
default: throw new Error("Paid-memory operation kind authentication unavailable.");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async readAuthentication(operation, key, domain, mint = false) {
|
|
107
|
+
if (operation.originalRead === undefined || !operation.readHistory || operation.readHistory.version !== 1 || (domain === "read-result" && !operation.result))
|
|
108
|
+
throw new Error("Paid-memory original read state unavailable.");
|
|
109
|
+
const context = concat(unhex(this.identity, 32), bindingBytes(binding(loadPlan(operation.object.plan))), unhex(operation.object.profileId, 32));
|
|
110
|
+
const material = await crypto.subtle.importKey("raw", buffer(key), "HKDF", false, ["deriveKey"]);
|
|
111
|
+
const derived = await crypto.subtle.deriveKey({ name: "HKDF", hash: "SHA-256", salt: new Uint8Array(32), info: buffer(concat(utf8(`flop/paid-storage/${domain}-key/v1`), context)) }, material, { name: "HMAC", hash: "SHA-256", length: 256 }, false, ["sign", "verify"]);
|
|
112
|
+
const payload = buffer(concat(utf8(`flop/paid-storage/${domain}/v1`), context, json([operation.prepared, operation.replayAuthority,
|
|
113
|
+
domain === "read-history" ? operation.readHistory.issued : [operation.readHistory, operation.result, operation.retired === true]])));
|
|
114
|
+
const tag = domain === "read-history" ? operation.readHistory.tag : operation.resultTag;
|
|
115
|
+
if (mint) {
|
|
116
|
+
const signed = hex(new Uint8Array(await crypto.subtle.sign("HMAC", derived, payload)));
|
|
117
|
+
if (domain === "read-history")
|
|
118
|
+
operation.readHistory.tag = signed;
|
|
119
|
+
else
|
|
120
|
+
operation.resultTag = signed;
|
|
121
|
+
}
|
|
122
|
+
else if (!tag || !await crypto.subtle.verify("HMAC", derived, buffer(unhex(tag, 32)), payload))
|
|
123
|
+
throw new Error("Paid-memory original read authentication failed.");
|
|
124
|
+
}
|
|
125
|
+
originalRead(operation) {
|
|
126
|
+
if (!operation.originalRead || operation.originalRead.version !== 1 || typeof operation.originalRead.snapshot !== "string")
|
|
127
|
+
throw new Error("Paid-memory original read snapshot unavailable.");
|
|
128
|
+
const snapshot = loadAuthority(operation.originalRead.snapshot);
|
|
129
|
+
const { admission, head } = snapshot, plan = loadPlan(operation.object.plan);
|
|
130
|
+
if (!admission || !head || typeof head.headVersion !== "bigint" || typeof head.objectVersion !== "bigint" || !(head.object instanceof Uint8Array) || !(head.planCommitment instanceof Uint8Array) || !(head.privateManifest instanceof Uint8Array)
|
|
131
|
+
|| !head.evidence || typeof head.evidence !== "object" || Array.isArray(head.evidence) || !Number.isSafeInteger(admission.at) || !Number.isSafeInteger(admission.assignmentGeneration))
|
|
132
|
+
throw new Error("Paid-memory original read type changed.");
|
|
133
|
+
if (!(admission.genesis instanceof Uint8Array) || admission.genesis.length !== 32 || !(admission.payer instanceof Uint8Array) || admission.payer.length !== 32
|
|
134
|
+
|| typeof admission.reservation !== "bigint" || typeof admission.maxAttempts !== "bigint" || !Number.isSafeInteger(admission.epochLengthBlocks) || admission.epochLengthBlocks <= 0
|
|
135
|
+
|| !Number.isSafeInteger(admission.requestLifetimeBlocks) || admission.requestLifetimeBlocks <= 0 || !Array.isArray(admission.providers)
|
|
136
|
+
|| typeof admission.profile?.maxCiphertextBytes !== "bigint" || typeof admission.profile.maxStoreBytes !== "bigint" || !(admission.profile.codecId instanceof Uint8Array)
|
|
137
|
+
|| typeof admission.policy?.namespace_epoch !== "bigint" || typeof admission.policy.object_epoch !== "bigint")
|
|
138
|
+
throw new Error("Paid-memory original read type changed.");
|
|
139
|
+
integer(admission.at, 4);
|
|
140
|
+
integer(admission.assignmentGeneration, 4);
|
|
141
|
+
integer(admission.reservation, 8);
|
|
142
|
+
integer(admission.maxAttempts, 8);
|
|
143
|
+
for (const provider of admission.providers) {
|
|
144
|
+
const lane = provider.lane;
|
|
145
|
+
if (!(provider.publicKey instanceof Uint8Array) || provider.publicKey.length !== 32 || typeof provider.reservedBytes !== "bigint" || !lane
|
|
146
|
+
|| [lane.id, lane.payer, lane.provider].some((bytes) => !(bytes instanceof Uint8Array) || bytes.length !== 32) || typeof lane.reservation !== "bigint")
|
|
147
|
+
throw new Error("Paid-memory original lane type changed.");
|
|
148
|
+
integer(provider.reservedBytes, 8);
|
|
149
|
+
integer(lane.reservation, 8);
|
|
150
|
+
for (const field of ["setupFee", "retrievalNum", "retrievalDen", "requestFee", "budget"]) {
|
|
151
|
+
if (typeof lane[field] !== "bigint")
|
|
152
|
+
throw new Error("Paid-memory original lane type changed.");
|
|
153
|
+
integer(lane[field], 16);
|
|
154
|
+
}
|
|
155
|
+
for (const field of ["sequence", "writes", "bytes", "requests", "amount"]) {
|
|
156
|
+
const value = lane.counters?.[field];
|
|
157
|
+
if (typeof value !== "string" || !/^[0-9]+$/.test(value))
|
|
158
|
+
throw new Error("Paid-memory original counter type changed.");
|
|
159
|
+
integer(BigInt(value), field === "amount" ? 16 : 8);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
this.checkAdmission(admission, unhex(operation.scopeNamespace, 32), unhex(operation.scopeObject, 32), plan);
|
|
163
|
+
integer(head.headVersion, 8);
|
|
164
|
+
integer(head.objectVersion, 8);
|
|
165
|
+
if (!equal(plan.genesis, admission.genesis) || plan.reservation !== admission.reservation || head.headVersion.toString() !== operation.previous || head.objectVersion !== plan.version || !equal(head.object, plan.object) || !equal(head.planCommitment, hash(encodePlan(plan))) || hex(head.privateManifest) !== operation.object.privateManifest
|
|
166
|
+
|| operation.object.profileId !== hex(cryptoProfileId(admission.profile)) || !equal(json(operation.lanes), json(admission.providers.map((provider) => hex(provider.lane.id)))) || !operation.object.ranges || operation.object.ranges.chunkBytes > admission.readChunkBytes)
|
|
167
|
+
throw new Error("Paid-memory original read binding changed.");
|
|
168
|
+
return snapshot;
|
|
169
|
+
}
|
|
170
|
+
async readState(tx, operation, key) {
|
|
171
|
+
await this.replayAuthentication(operation, key);
|
|
172
|
+
await this.readAuthentication(operation, key, "read-history");
|
|
173
|
+
if (operation.result)
|
|
174
|
+
await this.readAuthentication(operation, key, "read-result");
|
|
175
|
+
const { admission } = this.originalRead(operation), plan = loadPlan(operation.object.plan), id = operation.prepared.reference.operationId;
|
|
176
|
+
for (const slice of operation.object.ranges.slices) {
|
|
177
|
+
const suffix = slice.provider + ":" + slice.start;
|
|
178
|
+
if (!operation.readHistory.issued[suffix] && (operation.requests[suffix] !== undefined || await tx.get("voucher:" + id + ":" + suffix) !== undefined || await tx.get("signed-request:" + id + ":" + suffix) !== undefined))
|
|
179
|
+
throw new Error("Paid-memory original issuance history incomplete.");
|
|
180
|
+
}
|
|
181
|
+
const issued = [];
|
|
182
|
+
for (const [suffix, entry] of Object.entries(operation.readHistory.issued)) {
|
|
183
|
+
const slice = operation.object.ranges.slices.find((part) => suffix === part.provider + ":" + part.start);
|
|
184
|
+
const provider = admission.providers.find((provider) => hex(provider.lane.id) === entry.lane);
|
|
185
|
+
if (!slice || !provider || slice.provider !== hex(provider.publicKey) || typeof entry.acknowledged !== "boolean")
|
|
186
|
+
throw new Error("Paid-memory original issuance changed.");
|
|
187
|
+
const requestKey = id + ":" + suffix, context = await tx.get("request-context:" + requestKey);
|
|
188
|
+
if (!context || !Number.isSafeInteger(context.at) || typeof context.namespaceEpoch !== "string" || typeof context.objectEpoch !== "string" || context.end !== (BigInt(slice.start) + BigInt(slice.length)).toString())
|
|
189
|
+
throw new Error("Paid-memory issued read context unavailable.");
|
|
190
|
+
const nonce = hash(concat(unhex(operation.nonce, 32), provider.publicKey, integer(BigInt(slice.start), 8)));
|
|
191
|
+
const request = { at: context.at, lane: provider.lane.id, policy: { ...admission.policy, namespace_epoch: BigInt(context.namespaceEpoch), object_epoch: BigInt(context.objectEpoch) }, operation: { get: { plan, position: slice.position, nonce, start: BigInt(slice.start), end: BigInt(context.end) } } };
|
|
192
|
+
const rangeCommitment = hash(encodeShardRequest(request)), voucher = entry.voucher, c = voucher.counters;
|
|
193
|
+
const fields = decodePaidStorageRecord("ServiceVoucher", unhex(voucher.bytes));
|
|
194
|
+
const expected = encodePaidStorageRecord("ServiceVoucher", { version: 0, suite: 0, genesis_hash: admission.genesis, lane: provider.lane.id, sequence: BigInt(c.sequence), object: plan.object, object_version: plan.version, request_nonce: nonce, range_commitment: rangeCommitment,
|
|
195
|
+
cumulative_activated_writes: BigInt(c.writes), cumulative_deduplicated_bytes: BigInt(c.bytes), cumulative_requests: BigInt(c.requests), cumulative_amount: BigInt(c.amount), payer: admission.payer, signer: admission.payer, signature: fields.signature });
|
|
196
|
+
if (!equal(expected, unhex(voucher.bytes)) || !sr25519Verify(paidStorageSigningPreimage("ServiceVoucher", fields), fields.signature, admission.payer))
|
|
197
|
+
throw new Error("Paid-memory issued voucher authentication failed.");
|
|
198
|
+
const saved = await tx.get("signed-request:" + requestKey);
|
|
199
|
+
if (entry.capsule === undefined ? saved !== undefined || entry.acknowledged : !saved || capsuleCommitment(saved) !== entry.capsule || saved.voucher !== voucher.bytes || saved.encoded !== hex(encodeShardRequest(request))
|
|
200
|
+
|| !sr25519Verify(concat(utf8("flop/paid-storage/owner-request/v0"), encodeShardRequest(request)), unhex(saved.signature, 64), admission.payer))
|
|
201
|
+
throw new Error("Paid-memory issued request capsule unavailable.");
|
|
202
|
+
if (saved && !entry.acknowledged)
|
|
203
|
+
await this.replayAuthentication(operation, key, { requestKey, saved });
|
|
204
|
+
const cached = operation.requests[suffix];
|
|
205
|
+
if (cached && (!saved || cached.at !== saved.at || cached.signature !== saved.signature || cached.voucher !== saved.voucher))
|
|
206
|
+
throw new Error("Paid-memory issued request cache changed.");
|
|
207
|
+
if (saved && entry.acknowledged && saved.replay !== undefined)
|
|
208
|
+
throw new Error("Paid-memory read acknowledgement changed.");
|
|
209
|
+
if (entry.acknowledged && !operation.result && operation.ranges[suffix] === undefined)
|
|
210
|
+
throw new Error("Paid-memory retained read unavailable.");
|
|
211
|
+
if (!entry.acknowledged && operation.ranges[suffix] !== undefined)
|
|
212
|
+
throw new Error("Paid-memory read acknowledgement changed.");
|
|
213
|
+
issued.push({ requestKey, lane: provider.lane, object: plan.object, version: plan.version, nonce, rangeCommitment, deliveredBytes: BigInt(slice.length), voucher, acknowledged: entry.acknowledged });
|
|
214
|
+
}
|
|
215
|
+
for (const [suffix, bytes] of Object.entries(operation.ranges)) {
|
|
216
|
+
const slice = operation.object.ranges.slices.find((part) => suffix === part.provider + ":" + part.start);
|
|
217
|
+
if (!slice || !operation.readHistory.issued[suffix]?.acknowledged)
|
|
218
|
+
throw new Error("Paid-memory retained read authority unavailable.");
|
|
219
|
+
this.checkRangeBytes(slice, unhex(bytes));
|
|
220
|
+
}
|
|
221
|
+
const cost = await this.vouchers.readCostIn(tx, id, BigInt(operation.maxCost), issued);
|
|
222
|
+
const pending = await this.vouchers.unresolvedIn(tx, id, operation.lanes);
|
|
223
|
+
if (!equal(json(pending), json(issued.filter((entry) => !entry.acknowledged).map((entry) => entry.requestKey).sort())) || (operation.result && (operation.result.cost !== cost.toString() || !equal(json(operation.result.evidence.unresolvedRequestIds), json(pending)))))
|
|
224
|
+
throw new Error("Paid-memory original read exposure changed.");
|
|
225
|
+
return { cost, pending };
|
|
226
|
+
}
|
|
227
|
+
async clearReplayCapsule(tx, requestKey) {
|
|
228
|
+
const saved = await tx.get("signed-request:" + requestKey);
|
|
229
|
+
if (saved?.replay) {
|
|
230
|
+
delete saved.replay;
|
|
231
|
+
await tx.put("signed-request:" + requestKey, saved);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
async rangeAuthentication(object, key, mint = false) {
|
|
235
|
+
const ranges = object.ranges, plan = loadPlan(object.plan);
|
|
236
|
+
if (!ranges || !Number.isSafeInteger(ranges.chunkBytes) || ranges.chunkBytes <= 0)
|
|
237
|
+
throw new Error("Paid-memory range metadata unavailable.");
|
|
238
|
+
const context = concat(unhex(this.identity, 32), bindingBytes(binding(plan)), unhex(object.profileId, 32));
|
|
239
|
+
const tuples = [];
|
|
240
|
+
let index = 0;
|
|
241
|
+
for (const shard of plan.shards) {
|
|
242
|
+
for (let start = 0n; start < shard.encodedLength; start += BigInt(ranges.chunkBytes)) {
|
|
243
|
+
const slice = ranges.slices[index++];
|
|
244
|
+
const remaining = shard.encodedLength - start;
|
|
245
|
+
const length = remaining < BigInt(ranges.chunkBytes) ? Number(remaining) : ranges.chunkBytes;
|
|
246
|
+
if (!slice || slice.provider !== hex(shard.provider) || slice.position !== shard.position || slice.start !== start.toString() || slice.length !== length)
|
|
247
|
+
throw new Error("Paid-memory range metadata changed.");
|
|
248
|
+
tuples.push(concat(unhex(slice.provider, 32), integer(slice.position, 4), integer(start, 8), integer(slice.length, 8), unhex(slice.commitment, 32)));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (index !== ranges.slices.length)
|
|
252
|
+
throw new Error("Paid-memory range metadata changed.");
|
|
253
|
+
const material = await crypto.subtle.importKey("raw", buffer(key), "HKDF", false, ["deriveKey"]);
|
|
254
|
+
const derived = await crypto.subtle.deriveKey({ name: "HKDF", hash: "SHA-256", salt: new Uint8Array(32), info: buffer(concat(utf8("flop/paid-storage/range-metadata-key/v1"), context)) }, material, { name: "HMAC", hash: "SHA-256", length: 256 }, false, ["sign", "verify"]);
|
|
255
|
+
const payload = buffer(concat(utf8("flop/paid-storage/range-metadata/v1"), context, hash(encodePlan(plan)), unhex(object.ciphertextCommitment, 32), unhex(object.privateManifest, 32), integer(ranges.chunkBytes, 8), integer(index, 4), ...tuples));
|
|
256
|
+
if (mint)
|
|
257
|
+
object.rangeTag = hex(new Uint8Array(await crypto.subtle.sign("HMAC", derived, payload)));
|
|
258
|
+
else if (!object.rangeTag || !await crypto.subtle.verify("HMAC", derived, buffer(unhex(object.rangeTag, 32)), payload))
|
|
259
|
+
throw new Error("Paid-memory range metadata authentication failed.");
|
|
260
|
+
}
|
|
261
|
+
/** The host has durably retained the canonical result; no retired operation is repurchased. */
|
|
262
|
+
async retire(input) {
|
|
263
|
+
const operation = await this.options.store.transaction((tx) => tx.get("operation:" + input.operationId));
|
|
264
|
+
this.checkOperation(operation, input);
|
|
265
|
+
const key = await unwrapObjectKey(this.options.kek, operation.object.wrappedKey, binding(loadPlan(operation.object.plan)), this.options.keyGeneration);
|
|
266
|
+
return this.options.store.transaction(async (tx) => {
|
|
267
|
+
const current = await tx.get("operation:" + input.operationId);
|
|
268
|
+
this.checkOperation(current, input);
|
|
269
|
+
await this.operationAuthentication(current, key);
|
|
270
|
+
if (current.retired)
|
|
271
|
+
return true;
|
|
272
|
+
if (current.kind === "get") {
|
|
273
|
+
if (current.originalRead !== undefined)
|
|
274
|
+
await this.readState(tx, current, key);
|
|
275
|
+
}
|
|
276
|
+
if (!current.result || !current.lanes || (await this.vouchers.unresolvedIn(tx, input.operationId, current.lanes)).length > 0)
|
|
277
|
+
return false;
|
|
278
|
+
compact(current, []);
|
|
279
|
+
current.retired = true;
|
|
280
|
+
current.result = { cost: current.result.cost, evidence: { signedExposureAtomic: current.result.cost, unresolvedRequestIds: [] } };
|
|
281
|
+
if (current.originalRead !== undefined)
|
|
282
|
+
await this.readAuthentication(current, key, "read-result", true);
|
|
283
|
+
await tx.put("operation:" + input.operationId, current);
|
|
284
|
+
return true;
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
checkOperation(operation, input) {
|
|
288
|
+
if (!operation || operation.identity !== this.identity || operation.namespace !== input.namespace || operation.maxCost !== input.maxCostAtomic.toString()
|
|
289
|
+
|| JSON.stringify(operation.prepared) !== JSON.stringify(input.prepared)
|
|
290
|
+
|| operation.prepared.reference.commitment !== referenceCommitment(operation.object, operation.inputCommitment, operation.lanes))
|
|
291
|
+
throw new Error("Paid-memory immutable operation mismatch.");
|
|
292
|
+
}
|
|
293
|
+
expectedRange(object, provider, position, start, end) {
|
|
294
|
+
const expected = object.ranges?.slices.find((slice) => slice.provider === hex(provider) && slice.position === position && slice.start === start.toString());
|
|
295
|
+
if (!expected || BigInt(expected.length) !== end - start)
|
|
296
|
+
throw new Error("Paid-memory range authentication failed.");
|
|
297
|
+
return expected;
|
|
298
|
+
}
|
|
299
|
+
checkRangeBytes(expected, bytes) {
|
|
300
|
+
if (bytes.length !== expected.length || hex(hash(bytes)) !== expected.commitment)
|
|
301
|
+
throw new InvalidRangeResponse("Paid-memory range authentication failed.");
|
|
302
|
+
}
|
|
303
|
+
checkRange(object, provider, position, start, end, bytes) {
|
|
304
|
+
this.checkRangeBytes(this.expectedRange(object, provider, position, start, end), bytes);
|
|
305
|
+
}
|
|
306
|
+
async refreshCompleted(tx, id, operation, key) {
|
|
307
|
+
if (!operation.result || operation.retired || !operation.lanes)
|
|
308
|
+
return;
|
|
309
|
+
const pending = await this.vouchers.unresolvedIn(tx, id, operation.lanes);
|
|
310
|
+
operation.result.evidence = { ...operation.result.evidence, unresolvedRequestIds: pending };
|
|
311
|
+
compact(operation, pending);
|
|
312
|
+
if (operation.originalRead !== undefined) {
|
|
313
|
+
if (!key)
|
|
314
|
+
throw new Error("Paid-memory original result key unavailable.");
|
|
315
|
+
await this.readAuthentication(operation, key, "read-result", true);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
waitForCheckpoint(signal, finalizedBlockHash) {
|
|
319
|
+
return this.options.chain.waitForFinalized(signal, finalizedBlockHash === undefined ? undefined : unhex(finalizedBlockHash, 32));
|
|
320
|
+
}
|
|
321
|
+
/** Resolve only previously signed uncertain reads; never issue replacement paid work. */
|
|
322
|
+
async reconcile(input, signal) {
|
|
323
|
+
signal?.throwIfAborted();
|
|
324
|
+
const operation = await this.options.store.transaction((tx) => tx.get("operation:" + input.operationId));
|
|
325
|
+
this.checkOperation(operation, input);
|
|
326
|
+
if (operation.kind !== "get" || operation.retired)
|
|
327
|
+
throw new Error("Paid-memory reconciliation preparation mismatch.");
|
|
328
|
+
const plan = loadPlan(operation.object.plan);
|
|
329
|
+
const key = await unwrapObjectKey(this.options.kek, operation.object.wrappedKey, binding(plan), this.options.keyGeneration);
|
|
330
|
+
if (operation.object.ranges)
|
|
331
|
+
await this.rangeAuthentication(operation.object, key);
|
|
332
|
+
await this.replayAuthentication(operation, key);
|
|
333
|
+
if (operation.originalRead !== undefined)
|
|
334
|
+
await this.options.store.transaction((tx) => this.readState(tx, operation, key));
|
|
335
|
+
const originalPending = await this.options.store.transaction((tx) => this.vouchers.unresolvedIn(tx, input.operationId, operation.lanes));
|
|
336
|
+
if (!operation.result && originalPending.length === 0 && Object.keys(operation.ranges).length === 0)
|
|
337
|
+
throw new Error("Paid-memory original replay capsule unavailable.");
|
|
338
|
+
for (const requestKey of originalPending) {
|
|
339
|
+
const suffix = requestKey.slice(input.operationId.length + 1), [providerHex, startText] = suffix.split(":");
|
|
340
|
+
const saved = await this.options.store.transaction((tx) => tx.get("signed-request:" + requestKey));
|
|
341
|
+
if (!saved?.replay || !/^\d+$/.test(startText))
|
|
342
|
+
throw new Error("Paid-memory original replay capsule unavailable.");
|
|
343
|
+
await this.replayAuthentication(operation, key, { requestKey, saved });
|
|
344
|
+
const capsule = saved.replay, provider = unhex(capsule.provider, 32), lane = unhex(capsule.lane, 32);
|
|
345
|
+
const start = BigInt(startText), end = BigInt(capsule.end), shard = plan.shards.find((s) => equal(s.provider, provider));
|
|
346
|
+
if (!shard || providerHex !== capsule.provider || !operation.lanes.includes(capsule.lane))
|
|
347
|
+
throw new Error("Paid-memory original request unavailable.");
|
|
348
|
+
const request = { at: saved.at, lane, policy: { scope: { namespace: Array.from(unhex(capsule.scopeNamespace)), object: Array.from(unhex(capsule.scopeObject)) }, namespace_epoch: BigInt(saved.namespaceEpoch), object_epoch: BigInt(saved.objectEpoch) }, operation: { get: { plan, position: shard.position, nonce: hash(concat(unhex(operation.nonce, 32), provider, integer(start, 8))), start, end } } };
|
|
349
|
+
if (hex(encodeShardRequest(request)) !== saved.encoded)
|
|
350
|
+
throw new Error("Paid-memory original request changed.");
|
|
351
|
+
const expected = this.expectedRange(operation.object, provider, shard.position, start, end);
|
|
352
|
+
signal?.throwIfAborted();
|
|
353
|
+
let bytes;
|
|
354
|
+
try {
|
|
355
|
+
bytes = await this.options.transport.get(provider, { request, signature: saved.signature, voucher: saved.voucher }, Number(end - start), signal);
|
|
356
|
+
signal?.throwIfAborted();
|
|
357
|
+
this.checkRangeBytes(expected, bytes);
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
signal?.throwIfAborted();
|
|
361
|
+
if (error instanceof Error && error.name === "AbortError")
|
|
362
|
+
throw error;
|
|
363
|
+
if (!(error instanceof PaidShardTransportError || error instanceof InvalidRangeResponse))
|
|
364
|
+
throw error;
|
|
365
|
+
// Failed original capsules keep their signed authority and lane exposure.
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
signal?.throwIfAborted();
|
|
369
|
+
await this.vouchers.acknowledge(lane, requestKey, saved.voucher, async (tx) => {
|
|
370
|
+
const current = await tx.get("operation:" + input.operationId);
|
|
371
|
+
this.checkOperation(current, input);
|
|
372
|
+
if (current.retired)
|
|
373
|
+
throw new Error("Paid-memory operation retired.");
|
|
374
|
+
await this.replayAuthentication(current, key);
|
|
375
|
+
if (current.originalRead !== undefined) {
|
|
376
|
+
// The fence is already released within this transaction; verify sealed state before changing it.
|
|
377
|
+
await this.readAuthentication(current, key, "read-history");
|
|
378
|
+
if (current.result)
|
|
379
|
+
await this.readAuthentication(current, key, "read-result");
|
|
380
|
+
const entry = current.readHistory.issued[suffix];
|
|
381
|
+
if (!entry || entry.capsule !== capsuleCommitment(saved) || entry.acknowledged)
|
|
382
|
+
throw new Error("Paid-memory original acknowledgement changed.");
|
|
383
|
+
entry.acknowledged = true;
|
|
384
|
+
await this.readAuthentication(current, key, "read-history", true);
|
|
385
|
+
}
|
|
386
|
+
signal?.throwIfAborted();
|
|
387
|
+
if (!current.result)
|
|
388
|
+
current.ranges[suffix] = hex(bytes);
|
|
389
|
+
await this.clearReplayCapsule(tx, requestKey);
|
|
390
|
+
await this.refreshCompleted(tx, input.operationId, current, key);
|
|
391
|
+
if (current.originalRead !== undefined)
|
|
392
|
+
await this.readState(tx, current, key);
|
|
393
|
+
await tx.put("operation:" + input.operationId, current);
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
signal?.throwIfAborted();
|
|
397
|
+
return this.options.store.transaction(async (tx) => {
|
|
398
|
+
const current = await tx.get("operation:" + input.operationId);
|
|
399
|
+
this.checkOperation(current, input);
|
|
400
|
+
if (current.retired)
|
|
401
|
+
return [];
|
|
402
|
+
await this.replayAuthentication(current, key);
|
|
403
|
+
if (current.originalRead !== undefined)
|
|
404
|
+
await this.readState(tx, current, key);
|
|
405
|
+
const pending = await this.vouchers.unresolvedIn(tx, input.operationId, current.lanes);
|
|
406
|
+
if (current.result) {
|
|
407
|
+
current.result.evidence.unresolvedRequestIds = pending;
|
|
408
|
+
compact(current, pending);
|
|
409
|
+
if (current.originalRead !== undefined)
|
|
410
|
+
await this.readAuthentication(current, key, "read-result", true);
|
|
411
|
+
}
|
|
412
|
+
signal?.throwIfAborted();
|
|
413
|
+
await tx.put("operation:" + input.operationId, current);
|
|
414
|
+
return pending;
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
identity;
|
|
418
|
+
vouchers;
|
|
419
|
+
constructor(options) {
|
|
420
|
+
this.options = options;
|
|
421
|
+
if (!options.keyGeneration || options.kek.length !== 32 || options.owner.publicKey.length !== 32)
|
|
422
|
+
throw new Error("Paid-memory client key identity required.");
|
|
423
|
+
integer(options.reservation, 8);
|
|
424
|
+
integer(options.aggregateBudgetAtomic, 16);
|
|
425
|
+
this.identity = hex(hash(json(["flop/paid-storage/client/v1", hex(options.genesis), options.reservation.toString(), hex(options.owner.publicKey), options.keyGeneration])));
|
|
426
|
+
this.vouchers = new VoucherManager(options.store, options.owner, options.genesis, options.aggregateBudgetAtomic);
|
|
427
|
+
}
|
|
428
|
+
async scopes(namespaceName, name) {
|
|
429
|
+
const namespace = await opaqueIdentifier(this.options.kek, "namespace", [this.identity, namespaceName]);
|
|
430
|
+
return { namespace, object: await opaqueIdentifier(this.options.kek, "object", [hex(namespace), name]) };
|
|
431
|
+
}
|
|
432
|
+
/** Safe opaque inputs for explicit owner policy provisioning; no chain writes or payments. */
|
|
433
|
+
async policyScope(namespace, name) {
|
|
434
|
+
if (!namespace || !name)
|
|
435
|
+
throw new Error("Paid-memory scope identity required.");
|
|
436
|
+
return this.scopes(namespace, name);
|
|
437
|
+
}
|
|
438
|
+
checkAdmission(admission, scopeNamespace, scopeObject, plan) {
|
|
439
|
+
checkProfile(admission.profile, admission.providers.length);
|
|
440
|
+
const { options } = this;
|
|
441
|
+
if (!equal(admission.genesis, options.genesis) || admission.reservation !== options.reservation || !equal(admission.payer, options.owner.publicKey)
|
|
442
|
+
|| !equal(Uint8Array.from(admission.policy.scope.namespace), scopeNamespace) || !equal(Uint8Array.from(admission.policy.scope.object ?? []), scopeObject)
|
|
443
|
+
|| admission.policy.namespace_epoch <= 0n || admission.policy.object_epoch === null || admission.policy.object_epoch <= 0n
|
|
444
|
+
|| !Number.isSafeInteger(admission.readChunkBytes) || admission.readChunkBytes <= 0
|
|
445
|
+
|| new Set(admission.providers.map((p) => hex(p.publicKey))).size !== admission.providers.length)
|
|
446
|
+
throw new Error("Paid-memory admission denied.");
|
|
447
|
+
for (const provider of admission.providers)
|
|
448
|
+
if (!equal(provider.lane.provider, provider.publicKey) || !equal(provider.lane.payer, options.owner.publicKey) || provider.lane.reservation !== options.reservation)
|
|
449
|
+
throw new Error("Paid-memory lane authority denied.");
|
|
450
|
+
if (plan && (plan.assignmentGeneration !== admission.assignmentGeneration || !equal(plan.namespace, hash(scopeNamespace)) || !equal(plan.object, hash(scopeObject))
|
|
451
|
+
|| plan.shards.length !== admission.providers.length || plan.shards.some((s) => !admission.providers.some((p) => equal(p.publicKey, s.provider) && s.encodedLength <= p.reservedBytes))))
|
|
452
|
+
throw new Error("Paid-memory assignment changed.");
|
|
453
|
+
}
|
|
454
|
+
checkReadWork(admission, plan, chunkBytes) {
|
|
455
|
+
const work = admission.readWork;
|
|
456
|
+
if (!work || typeof work.diskReadBytes !== "bigint" || typeof work.egressBytes !== "bigint")
|
|
457
|
+
throw new Error("Paid-memory finalized read work unavailable; unsupported legacy admission.");
|
|
458
|
+
integer(work.diskReadBytes, 8);
|
|
459
|
+
integer(work.egressBytes, 8);
|
|
460
|
+
if (chunkBytes > admission.readChunkBytes)
|
|
461
|
+
throw new Error("Paid-memory authenticated range profile unavailable.");
|
|
462
|
+
for (const shard of plan.shards) {
|
|
463
|
+
const count = shard.encodedLength < BigInt(chunkBytes) ? shard.encodedLength : BigInt(chunkBytes);
|
|
464
|
+
if (shard.encodedLength > work.diskReadBytes || responseWorkBytes(count) > work.egressBytes)
|
|
465
|
+
throw new Error("Paid-memory read work exceeds finalized limits.");
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
checkWriteWork(admission, plan, requests = admission.providers.map((provider) => ({ at: admission.at, lane: provider.lane.id, policy: admission.policy, operation: { put: plan } }))) {
|
|
469
|
+
if (!requests.length)
|
|
470
|
+
return;
|
|
471
|
+
const work = admission.writeWork;
|
|
472
|
+
if (!work)
|
|
473
|
+
throw new Error("Paid-memory finalized write work unavailable; unsupported legacy admission.");
|
|
474
|
+
for (const field of ["envelopeBytes", "signatureAttempts", "ingressBytes", "diskReadBytes", "diskWriteBytes", "cpuUnits", "egressBytes", "retries"]) {
|
|
475
|
+
if (typeof work[field] !== "bigint" || work[field] <= 0n)
|
|
476
|
+
throw new Error("Paid-memory finalized write work invalid.");
|
|
477
|
+
integer(work[field], 8);
|
|
478
|
+
}
|
|
479
|
+
// Both signatures and vouchers have fixed widths in the canonical codec.
|
|
480
|
+
const zero = new Uint8Array(32), signature = new Uint8Array(64);
|
|
481
|
+
const voucher = hex(encodePaidStorageRecord("ServiceVoucher", { version: 0, suite: 0, genesis_hash: zero, lane: zero, sequence: 0n,
|
|
482
|
+
object: zero, object_version: 0n, request_nonce: zero, range_commitment: zero, cumulative_activated_writes: 0n,
|
|
483
|
+
cumulative_deduplicated_bytes: 0n, cumulative_requests: 0n, cumulative_amount: 0n, payer: zero, signer: zero, signature }));
|
|
484
|
+
for (const request of requests) {
|
|
485
|
+
const provider = admission.providers.find((provider) => equal(provider.lane.id, request.lane));
|
|
486
|
+
const shard = plan.shards.find((shard) => equal(shard.provider, provider.publicKey));
|
|
487
|
+
const envelopeBytes = BigInt(utf8(requestEnvelope({ request, signature: hex(signature), voucher })).length) + BigInt(SHARD_PREFIX.length);
|
|
488
|
+
integer(envelopeBytes, 8);
|
|
489
|
+
integer(shard.encodedLength, 8);
|
|
490
|
+
const payloadBytes = BigInt(placementPayload(plan, shard.provider).length), attestationBytes = payloadBytes + 64n;
|
|
491
|
+
const diskWriteBytes = shard.encodedLength + payloadBytes + attestationBytes;
|
|
492
|
+
integer(attestationBytes, 8);
|
|
493
|
+
integer(diskWriteBytes, 8);
|
|
494
|
+
// Native owner auth charges the header and two signatures before placement charges its prefix and signature.
|
|
495
|
+
// Auth can replenish before reservation; the fresh attempt must still hold S + 2V + 5I, each coefficient positive.
|
|
496
|
+
if (work.cpuUnits < 8n || envelopeBytes > work.envelopeBytes || 3n > work.signatureAttempts
|
|
497
|
+
|| shard.encodedLength > work.ingressBytes || shard.encodedLength > work.diskReadBytes
|
|
498
|
+
|| diskWriteBytes > work.diskWriteBytes || responseWorkBytes(attestationBytes) > work.egressBytes)
|
|
499
|
+
throw new Error("Paid-memory write work exceeds finalized limits.");
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
async prepare(request, kind, signal) {
|
|
503
|
+
await cryptoWaitReady();
|
|
504
|
+
if (!request.operationId || !request.namespace || !request.name || request.maxCostAtomic <= 0n)
|
|
505
|
+
throw new Error("Invalid paid-memory preparation.");
|
|
506
|
+
const commitment = hex(hash(json([kind, request.operationId, request.namespace, request.name, request.content ? hex(hash(request.content)) : null, request.maxCostAtomic.toString(), this.identity])));
|
|
507
|
+
const existing = await this.options.store.transaction((tx) => tx.get("operation:" + request.operationId));
|
|
508
|
+
if (existing) {
|
|
509
|
+
if (existing.inputCommitment !== commitment || existing.identity !== this.identity)
|
|
510
|
+
throw new Error("Paid-memory preparation changed.");
|
|
511
|
+
if (existing.prepared.reference.commitment !== referenceCommitment(existing.object, existing.inputCommitment, existing.lanes))
|
|
512
|
+
throw new Error("Paid-memory range metadata changed.");
|
|
513
|
+
const key = await unwrapObjectKey(this.options.kek, existing.object.wrappedKey, binding(loadPlan(existing.object.plan)), this.options.keyGeneration);
|
|
514
|
+
if (existing.object.ranges)
|
|
515
|
+
await this.rangeAuthentication(existing.object, key);
|
|
516
|
+
return existing.prepared;
|
|
517
|
+
}
|
|
518
|
+
const scopes = await this.scopes(request.namespace, request.name), admission = await this.options.chain.admission(scopes.namespace, scopes.object, signal);
|
|
519
|
+
this.checkAdmission(admission, scopes.namespace, scopes.object);
|
|
520
|
+
const key = hash(scopes.object), head = await this.options.heads.get(admission, key, signal), nonce = randomNonce();
|
|
521
|
+
let object, shards = [];
|
|
522
|
+
if (kind === "put") {
|
|
523
|
+
const version = await this.options.store.transaction(async (tx) => {
|
|
524
|
+
const allocationKey = "version-allocation:" + request.operationId;
|
|
525
|
+
const allocation = await tx.get(allocationKey);
|
|
526
|
+
if (allocation) {
|
|
527
|
+
if (allocation.commitment !== commitment)
|
|
528
|
+
throw new Error("Paid-memory version preparation changed.");
|
|
529
|
+
return BigInt(allocation.version);
|
|
530
|
+
}
|
|
531
|
+
const key = "object-version:" + hex(scopes.object);
|
|
532
|
+
const local = BigInt(await tx.get(key) ?? "0"), remote = head?.objectVersion ?? 0n;
|
|
533
|
+
const next = (local > remote ? local : remote) + 1n;
|
|
534
|
+
integer(next, 8);
|
|
535
|
+
await tx.put(key, next.toString());
|
|
536
|
+
await tx.put(allocationKey, { commitment, version: next.toString() });
|
|
537
|
+
return next;
|
|
538
|
+
});
|
|
539
|
+
const base = { genesis: admission.genesis, reservation: admission.reservation, namespace: hash(scopes.namespace), object: hash(scopes.object), version };
|
|
540
|
+
const encrypted = await encryptObject(base, request.name, request.content, admission.profile);
|
|
541
|
+
const encoded = encodeShards(encrypted.bytes, admission.providers.length, admission.profile);
|
|
542
|
+
const plan = { ...base, assignmentGeneration: admission.assignmentGeneration, nonce, shards: admission.providers.map((p, i) => ({ provider: p.publicKey, position: i, commitment: hash(encoded[i]), encodedLength: BigInt(encoded[i].length) })) };
|
|
543
|
+
this.checkAdmission(admission, scopes.namespace, scopes.object, plan);
|
|
544
|
+
this.checkReadWork(admission, plan, admission.readChunkBytes);
|
|
545
|
+
this.checkWriteWork(admission, plan);
|
|
546
|
+
const manifestLength = Number(new DataView(encrypted.bytes.buffer, encrypted.bytes.byteOffset + 166, 4).getUint32(0, true));
|
|
547
|
+
object = { plan: storedPlan(plan), profileId: hex(cryptoProfileId(admission.profile)), wrappedKey: await wrapObjectKey(this.options.kek, encrypted.key, base, this.options.keyGeneration),
|
|
548
|
+
ciphertextCommitment: hex(hash(encrypted.bytes)), privateManifest: hex(hash(encrypted.bytes.slice(166, 166 + 4 + manifestLength + 16))) };
|
|
549
|
+
object.ranges = { chunkBytes: admission.readChunkBytes, slices: encoded.flatMap((bytes, position) => {
|
|
550
|
+
const slices = [];
|
|
551
|
+
for (let start = 0; start < bytes.length; start += admission.readChunkBytes) {
|
|
552
|
+
const part = bytes.slice(start, start + admission.readChunkBytes);
|
|
553
|
+
slices.push({ provider: hex(plan.shards[position].provider), position, start: String(start), length: part.length, commitment: hex(hash(part)) });
|
|
554
|
+
}
|
|
555
|
+
return slices;
|
|
556
|
+
}) };
|
|
557
|
+
await this.rangeAuthentication(object, encrypted.key, true);
|
|
558
|
+
shards = encoded.map(hex);
|
|
559
|
+
}
|
|
560
|
+
else {
|
|
561
|
+
if (!head)
|
|
562
|
+
throw new Error("Paid-memory head is absent.");
|
|
563
|
+
const found = await this.options.store.transaction((tx) => tx.get("object:" + hex(head.object) + ":" + head.objectVersion));
|
|
564
|
+
if (!found || !equal(hash(encodePlan(loadPlan(found.plan))), head.planCommitment) || found.privateManifest !== hex(head.privateManifest))
|
|
565
|
+
throw new Error("Paid-memory immutable key/reference unavailable.");
|
|
566
|
+
object = found;
|
|
567
|
+
await this.rangeAuthentication(object, await unwrapObjectKey(this.options.kek, object.wrappedKey, binding(loadPlan(object.plan)), this.options.keyGeneration));
|
|
568
|
+
if (!object.ranges || object.ranges.chunkBytes > admission.readChunkBytes)
|
|
569
|
+
throw new Error("Paid-memory authenticated range profile unavailable.");
|
|
570
|
+
this.checkAdmission(admission, scopes.namespace, scopes.object, loadPlan(object.plan));
|
|
571
|
+
this.checkReadWork(admission, loadPlan(object.plan), object.ranges.chunkBytes);
|
|
572
|
+
if (object.profileId !== hex(cryptoProfileId(admission.profile)))
|
|
573
|
+
throw new Error("Paid-memory crypto profile changed.");
|
|
574
|
+
}
|
|
575
|
+
const lanes = admission.providers.map((p) => hex(p.lane.id));
|
|
576
|
+
const prepared = { version: object.plan.version, reference: { operationId: request.operationId, identity: this.identity, commitment: referenceCommitment(object, commitment, lanes) } };
|
|
577
|
+
const operation = { identity: this.identity, inputCommitment: commitment, namespace: request.namespace, maxCost: request.maxCostAtomic.toString(), kind, scopeNamespace: hex(scopes.namespace), scopeObject: hex(scopes.object), previous: (head?.headVersion ?? 0n).toString(), nonce: hex(nonce), object, prepared, lanes, shards, requests: {}, attestations: {}, ranges: {}, ...(head ? { head: { headVersion: head.headVersion.toString(), evidence: head.evidence } } : {}) };
|
|
578
|
+
if (kind === "get") {
|
|
579
|
+
operation.originalRead = { version: 1, snapshot: serializeAuthority({ admission, head }) };
|
|
580
|
+
operation.readHistory = { version: 1, issued: {}, tag: "" };
|
|
581
|
+
const key = await unwrapObjectKey(this.options.kek, object.wrappedKey, binding(loadPlan(object.plan)), this.options.keyGeneration);
|
|
582
|
+
await this.replayAuthentication(operation, key, undefined, true);
|
|
583
|
+
await this.readAuthentication(operation, key, "read-history", true);
|
|
584
|
+
}
|
|
585
|
+
else
|
|
586
|
+
await this.putAuthentication(operation, await unwrapObjectKey(this.options.kek, object.wrappedKey, binding(loadPlan(object.plan)), this.options.keyGeneration), false, true);
|
|
587
|
+
return this.options.store.transaction(async (tx) => {
|
|
588
|
+
const winner = await tx.get("operation:" + request.operationId);
|
|
589
|
+
if (winner) {
|
|
590
|
+
if (winner.inputCommitment !== commitment || winner.identity !== this.identity)
|
|
591
|
+
throw new Error("Paid-memory concurrent preparation changed.");
|
|
592
|
+
return winner.prepared;
|
|
593
|
+
}
|
|
594
|
+
await tx.put("operation:" + request.operationId, operation);
|
|
595
|
+
if (kind === "put") {
|
|
596
|
+
const objectKey = "object:" + object.plan.object + ":" + object.plan.version;
|
|
597
|
+
const prior = await tx.get(objectKey);
|
|
598
|
+
if (prior && JSON.stringify(prior) !== JSON.stringify(object))
|
|
599
|
+
throw new Error("Paid-memory immutable object collision.");
|
|
600
|
+
await tx.put(objectKey, object);
|
|
601
|
+
}
|
|
602
|
+
return prepared;
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
preparePut(input, signal) { return this.prepare(input, "put", signal); }
|
|
606
|
+
prepareGet(input, signal) { return this.prepare(input, "get", signal); }
|
|
607
|
+
async update(id, change) {
|
|
608
|
+
await this.options.store.transaction(async (tx) => { const current = await tx.get("operation:" + id); if (!current)
|
|
609
|
+
throw new Error("Paid-memory operation state unavailable."); change(current); await tx.put("operation:" + id, current); });
|
|
610
|
+
}
|
|
611
|
+
async completeOriginalRead(input, key, signal) {
|
|
612
|
+
return this.options.store.transaction(async (tx) => {
|
|
613
|
+
const operation = await tx.get("operation:" + input.operationId);
|
|
614
|
+
this.checkOperation(operation, input);
|
|
615
|
+
await this.operationAuthentication(operation, key);
|
|
616
|
+
if (operation.retired)
|
|
617
|
+
throw new Error("Paid-memory operation retired.");
|
|
618
|
+
const { cost, pending } = await this.readState(tx, operation, key);
|
|
619
|
+
if (operation.result)
|
|
620
|
+
return true;
|
|
621
|
+
const { admission, head } = this.originalRead(operation), plan = loadPlan(operation.object.plan), shards = [];
|
|
622
|
+
for (const shard of plan.shards) {
|
|
623
|
+
const slices = operation.object.ranges.slices.filter((slice) => slice.provider === hex(shard.provider));
|
|
624
|
+
if (slices.some((slice) => operation.ranges[slice.provider + ":" + slice.start] === undefined))
|
|
625
|
+
continue;
|
|
626
|
+
const bytes = concat(...slices.map((slice) => unhex(operation.ranges[slice.provider + ":" + slice.start])));
|
|
627
|
+
if (!equal(hash(bytes), shard.commitment))
|
|
628
|
+
throw new Error("Paid-memory retained shard commitment mismatch.");
|
|
629
|
+
shards.push({ position: shard.position, bytes });
|
|
630
|
+
}
|
|
631
|
+
signal?.throwIfAborted();
|
|
632
|
+
if (shards.length < admission.profile.reconstructionThreshold)
|
|
633
|
+
return false;
|
|
634
|
+
const ciphertext = reconstructShards(shards, plan.shards.length, admission.profile);
|
|
635
|
+
if (hex(hash(ciphertext)) !== operation.object.ciphertextCommitment || ciphertext.length < 170)
|
|
636
|
+
throw new Error("Paid-memory ciphertext commitment mismatch.");
|
|
637
|
+
const manifestLength = new DataView(ciphertext.buffer, ciphertext.byteOffset + 166, 4).getUint32(0, true);
|
|
638
|
+
if (hex(hash(ciphertext.slice(166, 166 + 4 + manifestLength + 16))) !== operation.object.privateManifest)
|
|
639
|
+
throw new Error("Paid-memory private manifest commitment mismatch.");
|
|
640
|
+
const content = (await decryptObject(binding(plan), ciphertext, key, admission.profile)).content;
|
|
641
|
+
signal?.throwIfAborted();
|
|
642
|
+
operation.result = { cost: cost.toString(), content: hex(content), evidence: { head: head.evidence, headVersion: head.headVersion.toString(), planCommitment: hex(head.planCommitment), ciphertextCommitment: operation.object.ciphertextCommitment,
|
|
643
|
+
version: plan.version.toString(), receivedShardPositions: shards.map((shard) => shard.position), signedExposureAtomic: cost.toString(), unresolvedRequestIds: pending } };
|
|
644
|
+
compact(operation, pending);
|
|
645
|
+
await this.readAuthentication(operation, key, "read-result", true);
|
|
646
|
+
await tx.put("operation:" + input.operationId, operation);
|
|
647
|
+
return true;
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
async execute(input, signal) {
|
|
651
|
+
signal?.throwIfAborted();
|
|
652
|
+
await cryptoWaitReady();
|
|
653
|
+
const stored = await this.options.store.transaction((tx) => tx.get("operation:" + input.operationId));
|
|
654
|
+
this.checkOperation(stored, input);
|
|
655
|
+
let operation = stored;
|
|
656
|
+
if (operation.retired)
|
|
657
|
+
throw new Error("Paid-memory operation retired.");
|
|
658
|
+
const objectKey = await unwrapObjectKey(this.options.kek, operation.object.wrappedKey, binding(loadPlan(operation.object.plan)), this.options.keyGeneration);
|
|
659
|
+
if (operation.object.ranges)
|
|
660
|
+
await this.rangeAuthentication(operation.object, objectKey);
|
|
661
|
+
await this.operationAuthentication(operation, objectKey);
|
|
662
|
+
if (operation.originalRead !== undefined) {
|
|
663
|
+
await this.options.store.transaction(async (tx) => {
|
|
664
|
+
const current = await tx.get("operation:" + input.operationId);
|
|
665
|
+
this.checkOperation(current, input);
|
|
666
|
+
if (current.retired)
|
|
667
|
+
throw new Error("Paid-memory operation retired.");
|
|
668
|
+
await this.readState(tx, current, objectKey);
|
|
669
|
+
signal?.throwIfAborted();
|
|
670
|
+
operation = current;
|
|
671
|
+
});
|
|
672
|
+
if (!operation.result && await this.completeOriginalRead(input, objectKey, signal))
|
|
673
|
+
return this.execute(input, signal);
|
|
674
|
+
}
|
|
675
|
+
signal?.throwIfAborted();
|
|
676
|
+
if (operation.result)
|
|
677
|
+
return { operationId: input.operationId, namespace: input.namespace, version: operation.prepared.version, costAtomic: BigInt(operation.result.cost), signedExposureAtomic: BigInt(operation.result.cost), unresolvedRequestIds: operation.result.evidence.unresolvedRequestIds, evidence: operation.result.evidence, ...(operation.result.content !== undefined ? { content: unhex(operation.result.content) } : {}) };
|
|
678
|
+
if (operation.kind === "put" && operation.casRecovery && this.options.heads.recoverAccepted) {
|
|
679
|
+
await this.putAuthentication(operation, objectKey, true);
|
|
680
|
+
// Parse historical authority only after authenticating its exact producer bytes.
|
|
681
|
+
const pinned = loadAdmission(operation.casRecovery.admission);
|
|
682
|
+
const plan = loadPlan(operation.object.plan), receipts = operation.casRecovery.attestations.map((bytes) => unhex(bytes));
|
|
683
|
+
this.checkAdmission(pinned, unhex(operation.scopeNamespace, 32), unhex(operation.scopeObject, 32), plan);
|
|
684
|
+
if (operation.object.profileId !== hex(cryptoProfileId(pinned.profile)) || !equal(json(operation.lanes), json(pinned.providers.map((provider) => hex(provider.lane.id)))))
|
|
685
|
+
throw new Error("Paid-memory CAS recovery context changed.");
|
|
686
|
+
receipts.forEach((receipt, position) => verifyPlacement(plan, plan.shards[position].provider, receipt));
|
|
687
|
+
const head = await this.options.heads.recoverAccepted(pinned, { key: plan.object, previous: BigInt(operation.previous), plan, privateManifest: unhex(operation.object.privateManifest, 32), attestations: receipts }, signal);
|
|
688
|
+
if (head) {
|
|
689
|
+
if (head.headVersion !== BigInt(operation.previous) + 1n || head.objectVersion !== plan.version || !equal(head.object, plan.object) || !equal(head.planCommitment, hash(encodePlan(plan))) || !equal(head.privateManifest, unhex(operation.object.privateManifest, 32)))
|
|
690
|
+
throw new Error("Paid-memory head receipt mismatch.");
|
|
691
|
+
await this.options.store.transaction(async (tx) => {
|
|
692
|
+
const current = await tx.get("operation:" + input.operationId);
|
|
693
|
+
this.checkOperation(current, input);
|
|
694
|
+
if (current.result || current.retired)
|
|
695
|
+
return;
|
|
696
|
+
await this.putAuthentication(current, objectKey);
|
|
697
|
+
await this.putAuthentication(current, objectKey, true);
|
|
698
|
+
if (current.casRecovery.admission !== operation.casRecovery.admission || !equal(json(current.casRecovery.attestations), json(operation.casRecovery.attestations)))
|
|
699
|
+
throw new Error("Paid-memory CAS recovery context changed.");
|
|
700
|
+
const cost = await this.vouchers.completedPutCostIn(tx, input.operationId, input.maxCostAtomic, pinned.providers.map((provider) => provider.lane), plan.shards.map((shard) => input.operationId + ":" + hex(shard.provider) + ":put"));
|
|
701
|
+
current.result = { cost: cost.toString(), evidence: { head: head.evidence, placements: operation.casRecovery.attestations, planCommitment: hex(head.planCommitment), signedExposureAtomic: cost.toString(), unresolvedRequestIds: [] } };
|
|
702
|
+
compact(current, []);
|
|
703
|
+
delete current.casRecovery;
|
|
704
|
+
await tx.put("operation:" + input.operationId, current);
|
|
705
|
+
});
|
|
706
|
+
return this.execute(input, signal);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
const scopeNamespace = unhex(operation.scopeNamespace, 32), scopeObject = unhex(operation.scopeObject, 32);
|
|
710
|
+
const admission = await this.options.chain.admission(scopeNamespace, scopeObject, signal), plan = loadPlan(operation.object.plan);
|
|
711
|
+
this.checkAdmission(admission, scopeNamespace, scopeObject, plan);
|
|
712
|
+
if (operation.lanes && !equal(json(operation.lanes), json(admission.providers.map((provider) => hex(provider.lane.id)))))
|
|
713
|
+
throw new Error("Paid-memory lane assignment changed.");
|
|
714
|
+
if (operation.object.profileId !== hex(cryptoProfileId(admission.profile)))
|
|
715
|
+
throw new Error("Paid-memory crypto profile changed.");
|
|
716
|
+
if (operation.kind === "get" && (!operation.object.ranges || operation.object.ranges.chunkBytes > admission.readChunkBytes))
|
|
717
|
+
throw new Error("Paid-memory authenticated range profile unavailable.");
|
|
718
|
+
const freshWork = await this.options.store.transaction(async (tx) => {
|
|
719
|
+
let replayShards = 0;
|
|
720
|
+
const reads = [];
|
|
721
|
+
for (const shard of plan.shards) {
|
|
722
|
+
const provider = hex(shard.provider);
|
|
723
|
+
if (operation.kind === "put") {
|
|
724
|
+
if (!operation.attestations[provider] && !await tx.get("signed-request:" + input.operationId + ":" + provider + ":put")) {
|
|
725
|
+
if (!operation.object.ranges)
|
|
726
|
+
throw new Error("Paid-memory authenticated range profile unavailable.");
|
|
727
|
+
const requestKey = input.operationId + ":" + provider + ":put";
|
|
728
|
+
const paid = operation.requests[provider + ":put"] || await tx.get("voucher:" + requestKey);
|
|
729
|
+
const saved = paid ? await tx.get("request-context:" + requestKey) : undefined;
|
|
730
|
+
if (paid && !saved)
|
|
731
|
+
throw new Error("Paid-memory paid request context unavailable.");
|
|
732
|
+
const lane = admission.providers.find((p) => equal(p.publicKey, shard.provider)).lane.id;
|
|
733
|
+
const request = { at: saved?.at ?? admission.at, lane, policy: saved ? { ...admission.policy, namespace_epoch: BigInt(saved.namespaceEpoch), object_epoch: BigInt(saved.objectEpoch) } : admission.policy, operation: { put: plan } };
|
|
734
|
+
reads.push({ plan: { ...plan, shards: [shard] }, chunkBytes: operation.object.ranges.chunkBytes, request });
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
else {
|
|
738
|
+
let chunkBytes = 0;
|
|
739
|
+
for (const slice of operation.object.ranges.slices.filter((range) => range.provider === provider)) {
|
|
740
|
+
const suffix = provider + ":" + slice.start;
|
|
741
|
+
if (!operation.ranges[suffix] && !await tx.get("signed-request:" + input.operationId + ":" + suffix))
|
|
742
|
+
chunkBytes = Math.max(chunkBytes, slice.length);
|
|
743
|
+
}
|
|
744
|
+
if (!chunkBytes)
|
|
745
|
+
replayShards++;
|
|
746
|
+
else
|
|
747
|
+
reads.push({ plan: { ...plan, shards: [shard] }, chunkBytes });
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
// Unsigned fallback shards cannot block a threshold of original signed authority.
|
|
751
|
+
return operation.kind === "put" || replayShards < admission.profile.reconstructionThreshold ? reads : [];
|
|
752
|
+
});
|
|
753
|
+
for (const work of freshWork) {
|
|
754
|
+
this.checkReadWork(admission, work.plan, work.chunkBytes);
|
|
755
|
+
if (operation.kind === "put")
|
|
756
|
+
this.checkWriteWork(admission, plan, [work.request]);
|
|
757
|
+
}
|
|
758
|
+
await this.vouchers.reconcile(input.operationId, input.maxCostAtomic, admission.providers.map((p) => p.lane));
|
|
759
|
+
const active = async (tx) => {
|
|
760
|
+
const current = await tx.get("operation:" + input.operationId);
|
|
761
|
+
this.checkOperation(current, input);
|
|
762
|
+
if (current.result || current.retired)
|
|
763
|
+
throw new OperationCompleted();
|
|
764
|
+
};
|
|
765
|
+
try {
|
|
766
|
+
const requestFor = async (provider, position, start, end) => {
|
|
767
|
+
const suffix = hex(provider.publicKey) + (start === undefined ? ":put" : ":" + start), requestKey = input.operationId + ":" + suffix;
|
|
768
|
+
const prior = operation.requests[suffix];
|
|
769
|
+
const nonce = start === undefined ? plan.nonce : hash(concat(unhex(operation.nonce, 32), provider.publicKey, integer(start, 8)));
|
|
770
|
+
const request = { at: prior?.at ?? admission.at, lane: provider.lane.id, policy: admission.policy, operation: start === undefined ? { put: plan } : { get: { plan, position, nonce, start, end: end } } };
|
|
771
|
+
// Once signed, all request inputs including finalized policy epochs remain pinned.
|
|
772
|
+
const pinnedKey = "signed-request:" + requestKey;
|
|
773
|
+
const contextKey = "request-context:" + requestKey;
|
|
774
|
+
const applyContext = (context) => {
|
|
775
|
+
request.at = context.at;
|
|
776
|
+
request.policy = { ...request.policy, namespace_epoch: BigInt(context.namespaceEpoch), object_epoch: BigInt(context.objectEpoch) };
|
|
777
|
+
if ("get" in request.operation) {
|
|
778
|
+
if (context.end === null || BigInt(context.end) !== end)
|
|
779
|
+
throw new Error("Paid-memory range profile changed.");
|
|
780
|
+
request.operation.get.end = BigInt(context.end);
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
const signingLifetime = () => {
|
|
784
|
+
if (!Number.isSafeInteger(request.at) || !Number.isSafeInteger(admission.at) || !Number.isSafeInteger(admission.requestLifetimeBlocks) || admission.requestLifetimeBlocks <= 0)
|
|
785
|
+
throw new Error("Paid-memory request signing lifetime unavailable.");
|
|
786
|
+
const expires = BigInt(request.at) + BigInt(admission.requestLifetimeBlocks);
|
|
787
|
+
integer(expires, 4);
|
|
788
|
+
if (request.at > admission.at || BigInt(admission.at) >= expires)
|
|
789
|
+
throw new Error("Paid-memory unsigned request context expired.");
|
|
790
|
+
if (request.policy.namespace_epoch !== admission.policy.namespace_epoch || request.policy.object_epoch !== admission.policy.object_epoch)
|
|
791
|
+
throw new Error("Paid-memory unsigned request authority changed.");
|
|
792
|
+
};
|
|
793
|
+
const persisted = await this.options.store.transaction((tx) => tx.get(pinnedKey));
|
|
794
|
+
if (persisted) {
|
|
795
|
+
if (start !== undefined)
|
|
796
|
+
await this.replayAuthentication(operation, objectKey, { requestKey, saved: persisted });
|
|
797
|
+
request.at = persisted.at;
|
|
798
|
+
request.policy = { ...request.policy, namespace_epoch: BigInt(persisted.namespaceEpoch), object_epoch: BigInt(persisted.objectEpoch) };
|
|
799
|
+
if (hex(encodeShardRequest(request)) !== persisted.encoded)
|
|
800
|
+
throw new Error("Paid-memory request reconciliation changed.");
|
|
801
|
+
return { request, signature: persisted.signature, voucher: persisted.voucher };
|
|
802
|
+
}
|
|
803
|
+
// Stored owner signatures retain their original authority; new exposure needs current work limits.
|
|
804
|
+
if (!operation.object.ranges)
|
|
805
|
+
throw new Error("Paid-memory authenticated range profile unavailable.");
|
|
806
|
+
this.checkReadWork(admission, start === undefined ? plan : { ...plan, shards: [plan.shards.find((shard) => equal(shard.provider, provider.publicKey))] }, start === undefined ? operation.object.ranges.chunkBytes : Number(end - start));
|
|
807
|
+
if (start === undefined) {
|
|
808
|
+
const savedContext = await this.options.store.transaction(async (tx) => {
|
|
809
|
+
const paid = await tx.get("voucher:" + requestKey) || prior || operation.attestations[hex(provider.publicKey)];
|
|
810
|
+
const saved = paid ? await tx.get(contextKey) : undefined;
|
|
811
|
+
if (paid && !saved)
|
|
812
|
+
throw new Error("Paid-memory paid request context unavailable.");
|
|
813
|
+
return saved;
|
|
814
|
+
});
|
|
815
|
+
if (savedContext)
|
|
816
|
+
applyContext(savedContext);
|
|
817
|
+
signingLifetime();
|
|
818
|
+
this.checkWriteWork(admission, plan, [request]);
|
|
819
|
+
}
|
|
820
|
+
const rangeCommitment = start === undefined ? hash(placementPayload(plan, provider.publicKey)) : hash(encodeShardRequest(request));
|
|
821
|
+
const voucher = await this.vouchers.issue({ operationId: input.operationId, requestKey, lane: provider.lane, object: plan.object, version: plan.version, nonce, rangeCommitment,
|
|
822
|
+
write: start === undefined, deliveredBytes: start === undefined ? 0n : end - start, maxCostAtomic: input.maxCostAtomic, beforeSign: async (tx, existingVoucher) => {
|
|
823
|
+
await active(tx);
|
|
824
|
+
const current = (await tx.get("operation:" + input.operationId));
|
|
825
|
+
if (current.originalRead !== undefined)
|
|
826
|
+
await this.readState(tx, current, objectKey);
|
|
827
|
+
const signed = await tx.get(pinnedKey);
|
|
828
|
+
const saved = await tx.get(contextKey);
|
|
829
|
+
if (existingVoucher || signed || current.requests[suffix] || current.attestations[hex(provider.publicKey)]) {
|
|
830
|
+
if (!saved)
|
|
831
|
+
throw new Error("Paid-memory paid request context unavailable.");
|
|
832
|
+
applyContext(saved);
|
|
833
|
+
}
|
|
834
|
+
else {
|
|
835
|
+
const fresh = { at: admission.at, namespaceEpoch: admission.policy.namespace_epoch.toString(), objectEpoch: admission.policy.object_epoch.toString(), end: end?.toString() ?? null };
|
|
836
|
+
applyContext(fresh);
|
|
837
|
+
await tx.put(contextKey, fresh);
|
|
838
|
+
}
|
|
839
|
+
if (!signed) {
|
|
840
|
+
signingLifetime();
|
|
841
|
+
if (start === undefined)
|
|
842
|
+
this.checkWriteWork(admission, plan, [request]);
|
|
843
|
+
}
|
|
844
|
+
return start === undefined ? hash(placementPayload(plan, provider.publicKey)) : hash(encodeShardRequest(request));
|
|
845
|
+
}, ...(operation.originalRead === undefined ? {} : { persistIssued: async (tx, issued) => {
|
|
846
|
+
const current = (await tx.get("operation:" + input.operationId));
|
|
847
|
+
this.checkOperation(current, input);
|
|
848
|
+
await this.replayAuthentication(current, objectKey);
|
|
849
|
+
await this.readAuthentication(current, objectKey, "read-history");
|
|
850
|
+
const prior = current.readHistory.issued[suffix];
|
|
851
|
+
if (prior) {
|
|
852
|
+
if (prior.lane !== hex(provider.lane.id) || !equal(json(prior.voucher), json(issued)))
|
|
853
|
+
throw new Error("Paid-memory original issuance changed.");
|
|
854
|
+
}
|
|
855
|
+
else
|
|
856
|
+
current.readHistory.issued[suffix] = { lane: hex(provider.lane.id), voucher: issued, acknowledged: false };
|
|
857
|
+
await this.readAuthentication(current, objectKey, "read-history", true);
|
|
858
|
+
await this.readState(tx, current, objectKey);
|
|
859
|
+
await tx.put("operation:" + input.operationId, current);
|
|
860
|
+
} }) });
|
|
861
|
+
await this.options.store.transaction(async (tx) => {
|
|
862
|
+
const existing = await tx.get(pinnedKey);
|
|
863
|
+
if (existing) {
|
|
864
|
+
if (existing.encoded !== hex(encodeShardRequest(request)) || existing.voucher !== voucher.bytes)
|
|
865
|
+
throw new Error("Paid-memory concurrent request changed.");
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
await active(tx);
|
|
869
|
+
signingLifetime();
|
|
870
|
+
const current = (await tx.get("operation:" + input.operationId));
|
|
871
|
+
if (current.originalRead !== undefined)
|
|
872
|
+
await this.readState(tx, current, objectKey);
|
|
873
|
+
const signed = await signShardRequest(request, voucher.bytes, this.options.owner);
|
|
874
|
+
const pinned = { encoded: hex(encodeShardRequest(request)), signature: signed.signature, voucher: signed.voucher, at: request.at, namespaceEpoch: request.policy.namespace_epoch.toString(), objectEpoch: request.policy.object_epoch.toString() };
|
|
875
|
+
if (start !== undefined) {
|
|
876
|
+
await this.replayAuthentication(operation, objectKey);
|
|
877
|
+
pinned.replay = { provider: hex(provider.publicKey), lane: hex(provider.lane.id), scopeNamespace: hex(Uint8Array.from(request.policy.scope.namespace)), scopeObject: hex(Uint8Array.from(request.policy.scope.object)), end: end.toString(), tag: "" };
|
|
878
|
+
await this.replayAuthentication(operation, objectKey, { requestKey, saved: pinned }, true);
|
|
879
|
+
}
|
|
880
|
+
await tx.put(pinnedKey, pinned);
|
|
881
|
+
if (current.originalRead !== undefined) {
|
|
882
|
+
const entry = current.readHistory.issued[suffix];
|
|
883
|
+
if (!entry || entry.capsule !== undefined || entry.acknowledged || entry.voucher.bytes !== pinned.voucher)
|
|
884
|
+
throw new Error("Paid-memory original signing state changed.");
|
|
885
|
+
entry.capsule = capsuleCommitment(pinned);
|
|
886
|
+
await this.readAuthentication(current, objectKey, "read-history", true);
|
|
887
|
+
await this.readState(tx, current, objectKey);
|
|
888
|
+
await tx.put("operation:" + input.operationId, current);
|
|
889
|
+
}
|
|
890
|
+
});
|
|
891
|
+
const saved = await this.options.store.transaction((tx) => tx.get(pinnedKey));
|
|
892
|
+
await this.update(input.operationId, (op) => { if (!op.result && !op.retired)
|
|
893
|
+
op.requests[suffix] = { at: request.at, signature: saved.signature, voucher: saved.voucher }; });
|
|
894
|
+
return { request, signature: saved.signature, voucher: saved.voucher };
|
|
895
|
+
};
|
|
896
|
+
let content, evidence;
|
|
897
|
+
if (operation.kind === "put") {
|
|
898
|
+
const receipts = [];
|
|
899
|
+
for (const shard of plan.shards) {
|
|
900
|
+
const provider = admission.providers.find((p) => equal(p.publicKey, shard.provider));
|
|
901
|
+
let receipt = operation.attestations[hex(shard.provider)] ? unhex(operation.attestations[hex(shard.provider)]) : undefined;
|
|
902
|
+
if (!receipt) {
|
|
903
|
+
const request = await requestFor(provider, shard.position);
|
|
904
|
+
receipt = await this.options.transport.put(shard.provider, request, unhex(operation.shards[shard.position]), signal);
|
|
905
|
+
verifyPlacement(plan, shard.provider, receipt);
|
|
906
|
+
await this.vouchers.acknowledge(provider.lane.id, input.operationId + ":" + hex(provider.publicKey) + ":put", request.voucher, async (tx) => {
|
|
907
|
+
const op = await tx.get("operation:" + input.operationId);
|
|
908
|
+
if (!op)
|
|
909
|
+
throw new Error("Paid-memory operation state unavailable.");
|
|
910
|
+
if (!op.result && !op.retired)
|
|
911
|
+
op.attestations[hex(shard.provider)] = hex(receipt);
|
|
912
|
+
await this.refreshCompleted(tx, input.operationId, op);
|
|
913
|
+
await tx.put("operation:" + input.operationId, op);
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
verifyPlacement(plan, shard.provider, receipt);
|
|
917
|
+
receipts.push(receipt);
|
|
918
|
+
}
|
|
919
|
+
const sealed = operation.putAuthority ? await this.options.store.transaction(async (tx) => {
|
|
920
|
+
await active(tx);
|
|
921
|
+
const current = (await tx.get("operation:" + input.operationId));
|
|
922
|
+
this.checkOperation(current, input);
|
|
923
|
+
await this.putAuthentication(current, objectKey);
|
|
924
|
+
if (current.casRecovery) {
|
|
925
|
+
await this.putAuthentication(current, objectKey, true);
|
|
926
|
+
if (!equal(json(current.casRecovery.attestations), json(receipts.map(hex))))
|
|
927
|
+
throw new Error("Paid-memory CAS recovery placements changed.");
|
|
928
|
+
}
|
|
929
|
+
else {
|
|
930
|
+
current.casRecovery = { admission: JSON.stringify(admission, (_name, value) => typeof value === "bigint" ? { bigint: value.toString() } : value instanceof Uint8Array ? { bytes: hex(value) } : value), attestations: receipts.map(hex), tag: "" };
|
|
931
|
+
await this.putAuthentication(current, objectKey, true, true);
|
|
932
|
+
await tx.put("operation:" + input.operationId, current);
|
|
933
|
+
}
|
|
934
|
+
return current.casRecovery.admission;
|
|
935
|
+
}) : undefined;
|
|
936
|
+
const head = await this.options.heads.cas(admission, { key: plan.object, previous: BigInt(operation.previous), plan, privateManifest: unhex(operation.object.privateManifest, 32), attestations: receipts, ...(sealed === undefined ? {} : { pinnedAdmission: loadAdmission(sealed) }) }, signal);
|
|
937
|
+
if (head.headVersion !== BigInt(operation.previous) + 1n || head.objectVersion !== plan.version || !equal(head.object, plan.object) || !equal(head.planCommitment, hash(encodePlan(plan))))
|
|
938
|
+
throw new Error("Paid-memory head receipt mismatch.");
|
|
939
|
+
evidence = { head: head.evidence, placements: receipts.map(hex), planCommitment: hex(head.planCommitment) };
|
|
940
|
+
}
|
|
941
|
+
else {
|
|
942
|
+
const shards = [];
|
|
943
|
+
for (const shard of plan.shards) {
|
|
944
|
+
if (shards.length === admission.profile.reconstructionThreshold)
|
|
945
|
+
break;
|
|
946
|
+
try {
|
|
947
|
+
const provider = admission.providers.find((p) => equal(p.publicKey, shard.provider));
|
|
948
|
+
const parts = [];
|
|
949
|
+
const chunkBytes = operation.object.ranges.chunkBytes;
|
|
950
|
+
for (let start = 0n; start < shard.encodedLength; start += BigInt(chunkBytes)) {
|
|
951
|
+
const end = start + BigInt(chunkBytes) > shard.encodedLength ? shard.encodedLength : start + BigInt(chunkBytes);
|
|
952
|
+
const key = hex(shard.provider) + ":" + start;
|
|
953
|
+
let part = operation.ranges[key] ? unhex(operation.ranges[key]) : undefined;
|
|
954
|
+
if (!part) {
|
|
955
|
+
const request = await requestFor(provider, shard.position, start, end);
|
|
956
|
+
part = await this.options.transport.get(shard.provider, request, Number(end - start), signal);
|
|
957
|
+
this.checkRange(operation.object, shard.provider, shard.position, start, end, part);
|
|
958
|
+
await this.vouchers.acknowledge(provider.lane.id, input.operationId + ":" + hex(provider.publicKey) + ":" + start, request.voucher, async (tx) => {
|
|
959
|
+
const op = await tx.get("operation:" + input.operationId);
|
|
960
|
+
if (!op)
|
|
961
|
+
throw new Error("Paid-memory operation state unavailable.");
|
|
962
|
+
if (op.originalRead !== undefined) {
|
|
963
|
+
this.checkOperation(op, input);
|
|
964
|
+
if (op.retired)
|
|
965
|
+
throw new Error("Paid-memory operation retired.");
|
|
966
|
+
await this.replayAuthentication(op, objectKey);
|
|
967
|
+
await this.readAuthentication(op, objectKey, "read-history");
|
|
968
|
+
if (op.result)
|
|
969
|
+
await this.readAuthentication(op, objectKey, "read-result");
|
|
970
|
+
const entry = op.readHistory.issued[key];
|
|
971
|
+
const saved = await tx.get("signed-request:" + input.operationId + ":" + key);
|
|
972
|
+
if (!entry || !saved || entry.capsule !== capsuleCommitment(saved) || entry.acknowledged)
|
|
973
|
+
throw new Error("Paid-memory original acknowledgement changed.");
|
|
974
|
+
signal?.throwIfAborted();
|
|
975
|
+
entry.acknowledged = true;
|
|
976
|
+
await this.readAuthentication(op, objectKey, "read-history", true);
|
|
977
|
+
}
|
|
978
|
+
if (!op.result && !op.retired)
|
|
979
|
+
op.ranges[key] = hex(part);
|
|
980
|
+
await this.clearReplayCapsule(tx, input.operationId + ":" + hex(provider.publicKey) + ":" + start);
|
|
981
|
+
await this.refreshCompleted(tx, input.operationId, op, objectKey);
|
|
982
|
+
if (op.originalRead !== undefined)
|
|
983
|
+
await this.readState(tx, op, objectKey);
|
|
984
|
+
await tx.put("operation:" + input.operationId, op);
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
this.checkRange(operation.object, shard.provider, shard.position, start, end, part);
|
|
988
|
+
parts.push(part);
|
|
989
|
+
}
|
|
990
|
+
const bytes = concat(...parts);
|
|
991
|
+
if (!equal(hash(bytes), shard.commitment))
|
|
992
|
+
throw new Error("Paid-memory shard commitment mismatch.");
|
|
993
|
+
shards.push({ position: shard.position, bytes });
|
|
994
|
+
}
|
|
995
|
+
catch (error) {
|
|
996
|
+
if (error instanceof OperationCompleted)
|
|
997
|
+
throw error;
|
|
998
|
+
signal?.throwIfAborted();
|
|
999
|
+
// Other assigned shards may reconstruct; signed uncertain exposure remains reserved.
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
const ciphertext = reconstructShards(shards, plan.shards.length, admission.profile);
|
|
1003
|
+
if (hex(hash(ciphertext)) !== operation.object.ciphertextCommitment)
|
|
1004
|
+
throw new Error("Paid-memory ciphertext commitment mismatch.");
|
|
1005
|
+
content = (await decryptObject(binding(plan), ciphertext, objectKey, admission.profile)).content;
|
|
1006
|
+
if (!operation.head)
|
|
1007
|
+
throw new Error("Paid-memory prepared head witness unavailable.");
|
|
1008
|
+
evidence = { head: operation.head.evidence, headVersion: operation.head.headVersion, planCommitment: hex(hash(encodePlan(plan))), ciphertextCommitment: operation.object.ciphertextCommitment, version: plan.version.toString(), receivedShardPositions: shards.map((s) => s.position) };
|
|
1009
|
+
}
|
|
1010
|
+
await this.options.store.transaction(async (tx) => {
|
|
1011
|
+
const current = await tx.get("operation:" + input.operationId);
|
|
1012
|
+
this.checkOperation(current, input);
|
|
1013
|
+
await this.operationAuthentication(current, objectKey);
|
|
1014
|
+
if (current.result || current.retired)
|
|
1015
|
+
return;
|
|
1016
|
+
signal?.throwIfAborted();
|
|
1017
|
+
const cost = current.originalRead === undefined ? await this.vouchers.operationCostIn(tx, input.operationId) : (await this.readState(tx, current, objectKey)).cost;
|
|
1018
|
+
const pending = await this.vouchers.unresolvedIn(tx, input.operationId, current.lanes ?? admission.providers.map((p) => hex(p.lane.id)));
|
|
1019
|
+
if (cost > input.maxCostAtomic)
|
|
1020
|
+
throw new Error("Paid-memory final budget exceeded.");
|
|
1021
|
+
current.result = { cost: cost.toString(), evidence: { ...evidence, signedExposureAtomic: cost.toString(), unresolvedRequestIds: pending }, ...(content ? { content: hex(content) } : {}) };
|
|
1022
|
+
compact(current, pending);
|
|
1023
|
+
delete current.casRecovery;
|
|
1024
|
+
if (current.originalRead !== undefined)
|
|
1025
|
+
await this.readAuthentication(current, objectKey, "read-result", true);
|
|
1026
|
+
await tx.put("operation:" + input.operationId, current);
|
|
1027
|
+
});
|
|
1028
|
+
return this.execute(input, signal);
|
|
1029
|
+
}
|
|
1030
|
+
catch (error) {
|
|
1031
|
+
if (error instanceof OperationCompleted)
|
|
1032
|
+
return this.execute(input, signal);
|
|
1033
|
+
throw error;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
export const createPaidMemoryClient = (options) => new PaidMemoryClient(options);
|
|
1038
|
+
//# sourceMappingURL=client.js.map
|