@flop-labs/sdk 0.4.0 → 0.5.2

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.
Files changed (149) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/README.md +152 -101
  3. package/dist/a2a/agent-card.d.ts +51 -1
  4. package/dist/a2a/agent-card.d.ts.map +1 -1
  5. package/dist/a2a/agent-card.js +20 -0
  6. package/dist/a2a/agent-card.js.map +1 -1
  7. package/dist/a2a/index.d.ts +1 -1
  8. package/dist/a2a/index.d.ts.map +1 -1
  9. package/dist/a2a/index.js +1 -1
  10. package/dist/a2a/index.js.map +1 -1
  11. package/dist/a2a-cjs/agent-card.js +22 -0
  12. package/dist/a2a-cjs/agent-card.js.map +1 -1
  13. package/dist/a2a-cjs/index.js +3 -1
  14. package/dist/a2a-cjs/index.js.map +1 -1
  15. package/dist/agent/task-delegation.d.ts +1 -1
  16. package/dist/agent/task-delegation.d.ts.map +1 -1
  17. package/dist/agent/task-delegation.js +17 -48
  18. package/dist/agent/task-delegation.js.map +1 -1
  19. package/dist/agent-wallet.d.ts.map +1 -1
  20. package/dist/agent-wallet.js +1 -18
  21. package/dist/agent-wallet.js.map +1 -1
  22. package/dist/bundle/index.esm.js +1 -1
  23. package/dist/bundle/index.esm.js.map +1 -1
  24. package/dist/bundle/index.umd.cjs +1 -1
  25. package/dist/bundle/index.umd.cjs.map +1 -1
  26. package/dist/chain-text.d.ts +3 -0
  27. package/dist/chain-text.d.ts.map +1 -0
  28. package/dist/chain-text.js +27 -0
  29. package/dist/chain-text.js.map +1 -0
  30. package/dist/client.d.ts +16 -4
  31. package/dist/client.d.ts.map +1 -1
  32. package/dist/client.js +76 -69
  33. package/dist/client.js.map +1 -1
  34. package/dist/compute-channel/agent-driver.d.ts.map +1 -1
  35. package/dist/compute-channel/agent-driver.js +3 -16
  36. package/dist/compute-channel/agent-driver.js.map +1 -1
  37. package/dist/compute-channel/direct-session-chain.d.ts.map +1 -1
  38. package/dist/compute-channel/direct-session-chain.js +63 -37
  39. package/dist/compute-channel/direct-session-chain.js.map +1 -1
  40. package/dist/compute-channel/direct-session.d.ts +1 -1
  41. package/dist/compute-channel/direct-session.d.ts.map +1 -1
  42. package/dist/compute-channel/direct-session.js +39 -6
  43. package/dist/compute-channel/direct-session.js.map +1 -1
  44. package/dist/compute-channel/fcu-admission.d.ts +37 -0
  45. package/dist/compute-channel/fcu-admission.d.ts.map +1 -0
  46. package/dist/compute-channel/fcu-admission.js +53 -0
  47. package/dist/compute-channel/fcu-admission.js.map +1 -0
  48. package/dist/compute-channel/fcu-agent.d.ts +27 -0
  49. package/dist/compute-channel/fcu-agent.d.ts.map +1 -0
  50. package/dist/compute-channel/fcu-agent.js +35 -0
  51. package/dist/compute-channel/fcu-agent.js.map +1 -0
  52. package/dist/compute-channel/fcu-policy.d.ts +67 -0
  53. package/dist/compute-channel/fcu-policy.d.ts.map +1 -0
  54. package/dist/compute-channel/fcu-policy.js +121 -0
  55. package/dist/compute-channel/fcu-policy.js.map +1 -0
  56. package/dist/compute-channel/fcu-profile.d.ts +56 -0
  57. package/dist/compute-channel/fcu-profile.d.ts.map +1 -0
  58. package/dist/compute-channel/fcu-profile.js +100 -0
  59. package/dist/compute-channel/fcu-profile.js.map +1 -0
  60. package/dist/compute-channel/fcu-serving.d.ts +146 -0
  61. package/dist/compute-channel/fcu-serving.d.ts.map +1 -0
  62. package/dist/compute-channel/fcu-serving.js +350 -0
  63. package/dist/compute-channel/fcu-serving.js.map +1 -0
  64. package/dist/compute-channel/fcu-sla.d.ts +88 -0
  65. package/dist/compute-channel/fcu-sla.d.ts.map +1 -0
  66. package/dist/compute-channel/fcu-sla.js +154 -0
  67. package/dist/compute-channel/fcu-sla.js.map +1 -0
  68. package/dist/compute-channel/fcu-store-node.d.ts +10 -0
  69. package/dist/compute-channel/fcu-store-node.d.ts.map +1 -0
  70. package/dist/compute-channel/fcu-store-node.js +98 -0
  71. package/dist/compute-channel/fcu-store-node.js.map +1 -0
  72. package/dist/compute-channel/fcu-timing.d.ts +34 -0
  73. package/dist/compute-channel/fcu-timing.d.ts.map +1 -0
  74. package/dist/compute-channel/fcu-timing.js +79 -0
  75. package/dist/compute-channel/fcu-timing.js.map +1 -0
  76. package/dist/compute-channel/flop-submitter.d.ts +1 -1
  77. package/dist/compute-channel/flop-submitter.d.ts.map +1 -1
  78. package/dist/compute-channel/flop-submitter.js +10 -20
  79. package/dist/compute-channel/flop-submitter.js.map +1 -1
  80. package/dist/compute-channel/index.d.ts +8 -0
  81. package/dist/compute-channel/index.d.ts.map +1 -1
  82. package/dist/compute-channel/index.js +8 -0
  83. package/dist/compute-channel/index.js.map +1 -1
  84. package/dist/compute-channel/peer-info.d.ts +15 -0
  85. package/dist/compute-channel/peer-info.d.ts.map +1 -0
  86. package/dist/compute-channel/peer-info.js +33 -0
  87. package/dist/compute-channel/peer-info.js.map +1 -0
  88. package/dist/compute-channel/transport-http.d.ts +18 -4
  89. package/dist/compute-channel/transport-http.d.ts.map +1 -1
  90. package/dist/compute-channel/transport-http.js +69 -18
  91. package/dist/compute-channel/transport-http.js.map +1 -1
  92. package/dist/connect.d.ts +4 -0
  93. package/dist/connect.d.ts.map +1 -0
  94. package/dist/connect.js +24 -0
  95. package/dist/connect.js.map +1 -0
  96. package/dist/coordination.d.ts.map +1 -1
  97. package/dist/coordination.js +5 -3
  98. package/dist/coordination.js.map +1 -1
  99. package/dist/discovery/discovery-service.d.ts.map +1 -1
  100. package/dist/discovery/discovery-service.js +19 -28
  101. package/dist/discovery/discovery-service.js.map +1 -1
  102. package/dist/faucet.d.ts +7 -2
  103. package/dist/faucet.d.ts.map +1 -1
  104. package/dist/faucet.js +39 -51
  105. package/dist/faucet.js.map +1 -1
  106. package/dist/htlc-appraisal.d.ts +4 -0
  107. package/dist/htlc-appraisal.d.ts.map +1 -0
  108. package/dist/htlc-appraisal.js +25 -0
  109. package/dist/htlc-appraisal.js.map +1 -0
  110. package/dist/index.d.ts +6 -1
  111. package/dist/index.d.ts.map +1 -1
  112. package/dist/index.js +5 -1
  113. package/dist/index.js.map +1 -1
  114. package/dist/inference-purchase.d.ts +40 -0
  115. package/dist/inference-purchase.d.ts.map +1 -0
  116. package/dist/inference-purchase.js +43 -0
  117. package/dist/inference-purchase.js.map +1 -0
  118. package/dist/miner-admission.d.ts +124 -0
  119. package/dist/miner-admission.d.ts.map +1 -0
  120. package/dist/miner-admission.js +259 -0
  121. package/dist/miner-admission.js.map +1 -0
  122. package/dist/model-loader/image-stream.d.ts +29 -0
  123. package/dist/model-loader/image-stream.d.ts.map +1 -0
  124. package/dist/model-loader/image-stream.js +71 -0
  125. package/dist/model-loader/image-stream.js.map +1 -0
  126. package/dist/model-loader/index.d.ts +1 -0
  127. package/dist/model-loader/index.d.ts.map +1 -1
  128. package/dist/model-loader/index.js +1 -0
  129. package/dist/model-loader/index.js.map +1 -1
  130. package/dist/model-loader/registry.d.ts.map +1 -1
  131. package/dist/model-loader/registry.js +2 -8
  132. package/dist/model-loader/registry.js.map +1 -1
  133. package/dist/runtime-compatibility.d.ts +1 -1
  134. package/dist/runtime-compatibility.d.ts.map +1 -1
  135. package/dist/runtime-compatibility.js +5 -2
  136. package/dist/runtime-compatibility.js.map +1 -1
  137. package/dist/submit-tx.d.ts +1 -1
  138. package/dist/submit-tx.d.ts.map +1 -1
  139. package/dist/submit-tx.js +5 -13
  140. package/dist/submit-tx.js.map +1 -1
  141. package/dist/watch-transaction.d.ts +26 -0
  142. package/dist/watch-transaction.d.ts.map +1 -0
  143. package/dist/watch-transaction.js +91 -0
  144. package/dist/watch-transaction.js.map +1 -0
  145. package/dist/x402.d.ts +3 -1
  146. package/dist/x402.d.ts.map +1 -1
  147. package/dist/x402.js +16 -4
  148. package/dist/x402.js.map +1 -1
  149. package/package.json +10 -3
@@ -0,0 +1,350 @@
1
+ import { assertFcuRegistry, assertFcuRequestWindow, FCU_ACCEPTANCE_BUDGET_MS } from "./fcu-policy.js";
2
+ import { assessFcuCompletion, assessFcuTimingBounds, fcuCompletionBinding } from "./fcu-timing.js";
3
+ /** Durable coordination preparation; no default store, chain authority or live activation. */
4
+ import { blake2_256 } from "./transcript.js";
5
+ import { verify } from "./crypto.js";
6
+ import { fcuDecisionMessage, fcuRequestMessage, signFcuDecision, validateFcuRequest, verifyFcuDecision } from "./fcu-admission.js";
7
+ import { fcuDomainMessage, fcuHash, fcuHex, fcuProfileHash, fcuUnsigned, validateFcuBooking } from "./fcu-profile.js";
8
+ export function fcuServingBinding(profile, terms, minerKey) {
9
+ fcuHash(fcuHex(minerKey));
10
+ fcuHash(terms.qualificationHash);
11
+ fcuUnsigned(terms.maxDeliveredEntries, BigInt(Number.MAX_SAFE_INTEGER));
12
+ if (terms.booking.quantityGn > terms.maxDeliveredEntries) {
13
+ throw new Error("FCU journal capacity cannot cover every permitted delivery; qualification required");
14
+ }
15
+ return fcuHex(blake2_256(fcuDomainMessage("flop-fcu-serving-binding-v1", [terms.genesisHash,
16
+ terms.channelId, fcuProfileHash(profile), terms.purchasedAtUtcMs.toString(),
17
+ terms.booking.quantityGn.toString(), terms.booking.deliveryStartUtcMs.toString(),
18
+ terms.booking.deliveryEndUtcMs.toString(), terms.qualificationHash,
19
+ terms.maxDeliveredEntries.toString(), fcuHex(minerKey)])));
20
+ }
21
+ export class FcuServingCoordinator {
22
+ miner;
23
+ store;
24
+ authority;
25
+ profile;
26
+ terms;
27
+ binding;
28
+ constructor(profile, terms, miner, store, authority) {
29
+ this.miner = miner;
30
+ this.store = store;
31
+ this.authority = authority;
32
+ if (profile.acceptanceBudgetMs !== FCU_ACCEPTANCE_BUDGET_MS)
33
+ throw new Error("FCU ratified 100ms acceptance budget required");
34
+ this.profile = Object.freeze({ ...profile });
35
+ this.terms = Object.freeze({ ...terms, booking: Object.freeze({ ...terms.booking }) });
36
+ fcuHash(terms.genesisHash);
37
+ fcuHash(terms.channelId);
38
+ validateFcuBooking(profile, terms.booking, terms.purchasedAtUtcMs);
39
+ this.binding = fcuServingBinding(profile, terms, miner.publicKey);
40
+ fcuUnsigned(store.maxDeliveredEntries, BigInt(Number.MAX_SAFE_INTEGER));
41
+ // Actual verified work may be smaller than minChunkGn. One positive G_n per
42
+ // delivery is the only guaranteed lower bound; refusals/retries add no history.
43
+ if (terms.maxDeliveredEntries > store.maxDeliveredEntries) {
44
+ throw new Error("FCU journal capacity cannot cover every permitted delivery; qualification required");
45
+ }
46
+ }
47
+ checkQualification(observation) {
48
+ assertFcuRegistry(this.profile, observation.registry, "execute");
49
+ if (observation.registry.qualificationHash !== this.terms.qualificationHash
50
+ || observation.maxDeliveredEntries !== this.terms.maxDeliveredEntries) {
51
+ throw new Error("FCU sold journal qualification mismatch");
52
+ }
53
+ }
54
+ async initialize() {
55
+ const existing = await this.store.load(this.terms.channelId);
56
+ if (existing) {
57
+ this.checkState(existing);
58
+ return;
59
+ }
60
+ const observation = await this.authority.observe();
61
+ fcuHash(observation.finalizedBlockHash);
62
+ if (observation.fundingBindingHash !== this.binding)
63
+ throw new Error("FCU funding binding mismatch");
64
+ if (observation.genesisHash !== this.terms.genesisHash)
65
+ throw new Error("FCU authority chain mismatch");
66
+ this.checkQualification(observation);
67
+ const coordinatorKey = observation.coordinatorKey;
68
+ fcuHash(coordinatorKey);
69
+ fcuUnsigned(observation.recordedConsumedGn, (1n << 128n) - 1n, false);
70
+ if (observation.recordedConsumedGn !== 0n)
71
+ throw new Error("FCU non-virgin consumption requires reconciliation");
72
+ const grant = await this.authority.claimVirginStart(this.binding, observation.finalizedBlockHash);
73
+ if (!grant || grant.bindingHash !== this.binding || grant.finalizedBlockHash !== observation.finalizedBlockHash
74
+ || grant.recordedConsumedGn !== 0n) {
75
+ throw new Error("FCU journal missing or initialization grant invalid; reconciliation required");
76
+ }
77
+ await this.write(null, { revision: 0n, binding: this.binding, coordinatorKey,
78
+ nextSequence: 0n, consumedGn: 0n, pending: [], admissionsPaused: true });
79
+ }
80
+ async snapshot() {
81
+ const state = await this.store.load(this.terms.channelId);
82
+ if (!state)
83
+ throw new Error("FCU serving journal not initialized");
84
+ this.checkState(state);
85
+ return structuredClone(state);
86
+ }
87
+ checkState(s) {
88
+ fcuUnsigned(s.revision, (1n << 64n) - 1n, false);
89
+ fcuUnsigned(s.nextSequence, (1n << 64n) - 1n, false);
90
+ fcuUnsigned(s.consumedGn, (1n << 128n) - 1n, false);
91
+ fcuHash(s.coordinatorKey);
92
+ if (s.binding !== this.binding || s.pending.length > this.profile.maxConcurrency
93
+ || s.consumedGn + this.reserved(s) > this.terms.booking.quantityGn) {
94
+ throw new Error("FCU serving journal binding or capacity mismatch");
95
+ }
96
+ if (s.lastDecision) {
97
+ verifyFcuDecision(this.profile, s.lastDecision, this.miner.publicKey);
98
+ if (s.lastDecision.decision.request.sequence + 1n !== s.nextSequence) {
99
+ throw new Error("FCU invalid last decision sequence");
100
+ }
101
+ }
102
+ if (s.receiptCheckpoint) {
103
+ fcuHash(s.receiptCheckpoint.root);
104
+ fcuUnsigned(s.receiptCheckpoint.aggregateGn);
105
+ if (s.receiptCheckpoint.aggregateGn !== s.consumedGn)
106
+ throw new Error("FCU receipt checkpoint consumption mismatch");
107
+ }
108
+ if (s.timingFindings && Object.keys(s.timingFindings).length) {
109
+ throw new Error("FCU pre-ratification pending timing journal requires explicit reconciliation");
110
+ }
111
+ const entries = Object.entries(s.delivered ?? {});
112
+ if (BigInt(entries.length) > this.terms.maxDeliveredEntries)
113
+ throw new Error("FCU journal exceeds sold qualification");
114
+ let delivered = 0n;
115
+ for (const [sequence, item] of entries) {
116
+ verifyFcuDecision(this.profile, item.accepted, this.miner.publicKey);
117
+ fcuHash(item.outputHash);
118
+ fcuUnsigned(item.verifiedWorkGn);
119
+ if (item.accepted.decision.request.sequence.toString() !== sequence
120
+ || item.accepted.decision.request.channelId !== this.terms.channelId
121
+ || item.accepted.decision.request.genesisHash !== this.terms.genesisHash
122
+ || item.accepted.decision.outcome !== "accepted"
123
+ || item.verifiedWorkGn > item.accepted.decision.request.workGn
124
+ || s.pending.some((p) => p.decision.request.sequence.toString() === sequence)
125
+ || (item.timing && item.timing.bindingHash !== fcuCompletionBinding(item.accepted, item.outputHash))) {
126
+ throw new Error("FCU delivered journal identity mismatch");
127
+ }
128
+ if (item.timing) {
129
+ const t = item.timing;
130
+ const expected = assessFcuTimingBounds(item.accepted.decision.decidedAtMs, t);
131
+ if (t.lowerLatencyMs !== expected.lowerLatencyMs || t.upperLatencyMs !== expected.upperLatencyMs
132
+ || t.status !== expected.status || t.remedy !== expected.remedy) {
133
+ throw new Error("FCU invalid saved timing bounds");
134
+ }
135
+ }
136
+ if (item.accepted.decision.request.sequence >= s.nextSequence)
137
+ throw new Error("FCU invalid delivered sequence");
138
+ delivered += item.verifiedWorkGn;
139
+ }
140
+ if (delivered !== s.consumedGn)
141
+ throw new Error("FCU delivered journal requires consumption reconciliation");
142
+ if (s.admissionsPaused !== undefined && typeof s.admissionsPaused !== "boolean") {
143
+ throw new Error("FCU invalid admission pause state");
144
+ }
145
+ const sequences = new Set();
146
+ for (const entry of s.pending) {
147
+ verifyFcuDecision(this.profile, entry, this.miner.publicKey);
148
+ const r = entry.decision.request;
149
+ fcuUnsigned(r.workGn);
150
+ if (r.workGn < this.profile.minChunkGn || r.workGn > this.profile.maxChunkGn) {
151
+ throw new Error("FCU pending work outside pinned profile");
152
+ }
153
+ if (r.genesisHash !== this.terms.genesisHash || r.channelId !== this.terms.channelId
154
+ || r.profileHash !== this.terms.booking.profileHash || entry.decision.outcome !== "accepted"
155
+ || r.sequence >= s.nextSequence || sequences.has(r.sequence.toString())
156
+ || !verify(this.miner.publicKey, fcuDecisionMessage(entry.decision), entry.signature)) {
157
+ throw new Error("FCU serving journal contains invalid pending work");
158
+ }
159
+ sequences.add(r.sequence.toString());
160
+ }
161
+ }
162
+ reserved(s) {
163
+ return s.pending.reduce((sum, p) => sum + p.decision.request.workGn, 0n);
164
+ }
165
+ async write(previous, next) {
166
+ this.checkState(next);
167
+ if (!await this.store.compareAndSwap(this.terms.channelId, previous?.revision ?? null, structuredClone(next))) {
168
+ throw new Error("FCU journal changed; retry against current sequence");
169
+ }
170
+ }
171
+ async admit(input, receivedAtMs, decidedAtMs) {
172
+ const signed = structuredClone(input);
173
+ validateFcuRequest(this.profile, this.terms.booking, signed);
174
+ const r = signed.request;
175
+ if (r.genesisHash !== this.terms.genesisHash || r.channelId !== this.terms.channelId) {
176
+ throw new Error("FCU chain or channel mismatch");
177
+ }
178
+ const s = await this.snapshot();
179
+ // A lookup of a previously reserved request grants no new work or capacity.
180
+ const cached = s.pending.find((p) => p.decision.request.sequence === r.sequence) ?? s.lastDecision;
181
+ if (cached && fcuHex(fcuRequestMessage(r)) === fcuHex(fcuRequestMessage(cached.decision.request))) {
182
+ return structuredClone(cached);
183
+ }
184
+ const observation = await this.authority.observe(r.holderKey);
185
+ fcuHash(observation.finalizedBlockHash);
186
+ if (observation.fundingBindingHash !== this.binding)
187
+ throw new Error("FCU funding binding mismatch");
188
+ if (observation.genesisHash !== this.terms.genesisHash)
189
+ throw new Error("FCU authority chain mismatch");
190
+ this.checkQualification(observation);
191
+ if (observation.servingEligibility !== "eligible")
192
+ throw new Error("FCU serving eligibility unavailable or paused");
193
+ fcuUnsigned(observation.recordedConsumedGn, (1n << 128n) - 1n, false);
194
+ if (observation.recordedConsumedGn > s.consumedGn)
195
+ throw new Error("FCU journal behind finalized consumption; reconciliation required");
196
+ if (s.consumedGn > 0n && !s.receiptCheckpoint)
197
+ throw new Error("FCU receipt reconciliation required");
198
+ if (r.sequence !== s.nextSequence || r.sequence === (1n << 64n) - 1n)
199
+ throw new Error("FCU stale request sequence");
200
+ if (s.coordinatorKey !== observation.coordinatorKey)
201
+ throw new Error("FCU coordinator handoff required");
202
+ if (!observation.isHolder)
203
+ throw new Error("FCU requester is not a current holder");
204
+ if (receivedAtMs < this.terms.booking.deliveryStartUtcMs
205
+ || decidedAtMs >= this.terms.booking.deliveryEndUtcMs)
206
+ throw new Error("FCU outside delivery window");
207
+ if (decidedAtMs - receivedAtMs > this.profile.acceptanceBudgetMs)
208
+ throw new Error("FCU acceptance budget exceeded");
209
+ await this.authority.verifyWorkload(structuredClone(signed));
210
+ const clock = await this.authority.verifyAdmission(structuredClone(signed), receivedAtMs, decidedAtMs);
211
+ if (clock.blockHash !== observation.finalizedBlockHash)
212
+ throw new Error("FCU admission observations differ");
213
+ assertFcuRequestWindow(this.terms.booking, clock, this.terms.genesisHash, receivedAtMs, decidedAtMs);
214
+ const paused = s.admissionsPaused !== false;
215
+ const accepted = !paused && s.pending.length < this.profile.maxConcurrency
216
+ && s.consumedGn + this.reserved(s) + r.workGn <= this.terms.booking.quantityGn;
217
+ const result = signFcuDecision({ request: r, authorityBlockHash: observation.finalizedBlockHash, receivedAtMs, decidedAtMs,
218
+ outcome: accepted ? "accepted" : "refused", reason: accepted ? "accepted" : paused ? "paused" : "capacity" }, this.miner);
219
+ await this.write(s, { ...s, revision: s.revision + 1n, nextSequence: s.nextSequence + 1n,
220
+ pending: accepted ? [...s.pending, result] : s.pending, lastDecision: result });
221
+ return structuredClone(result);
222
+ }
223
+ /** Correct available work consumes once independently of timing. Missing timing creates no success verdict. */
224
+ async recordExecution(sequence, evidence, execution) {
225
+ const s = await this.snapshot();
226
+ const old = s.delivered?.[sequence.toString()];
227
+ if (old) {
228
+ if (old.outputHash !== evidence.outputHash)
229
+ throw new Error("FCU conflicting completion binding");
230
+ return;
231
+ }
232
+ await this.commitExecution(s, sequence, evidence, execution, null);
233
+ }
234
+ async commitExecution(s, sequence, evidence, execution, timing) {
235
+ const accepted = s.pending.find((p) => p.decision.request.sequence === sequence);
236
+ if (!accepted)
237
+ throw new Error("FCU pending request not found");
238
+ fcuHash(evidence.outputHash);
239
+ const verified = await execution.verify(structuredClone(accepted), evidence.outputHash, evidence.executionReceipt.slice());
240
+ fcuUnsigned(verified.workGn);
241
+ fcuHash(verified.receiptRoot);
242
+ fcuUnsigned(verified.cumulativeGn);
243
+ if (verified.outputHash !== evidence.outputHash || verified.workGn > accepted.decision.request.workGn
244
+ || verified.cumulativeGn !== s.consumedGn + verified.workGn)
245
+ throw new Error("FCU execution output mismatch, exceeds reserved work or invalid cumulative binding");
246
+ await this.write(s, { ...s, revision: s.revision + 1n, consumedGn: verified.cumulativeGn,
247
+ receiptCheckpoint: { root: verified.receiptRoot, aggregateGn: verified.cumulativeGn },
248
+ pending: s.pending.filter((p) => p.decision.request.sequence !== sequence),
249
+ delivered: { ...s.delivered, [sequence.toString()]: { accepted, outputHash: evidence.outputHash,
250
+ verifiedWorkGn: verified.workGn, timing } } });
251
+ }
252
+ async recordDelivery(sequence, evidence, verification) {
253
+ const s = await this.snapshot();
254
+ const old = s.delivered?.[sequence.toString()];
255
+ const accepted = old?.accepted ?? s.pending.find((p) => p.decision.request.sequence === sequence);
256
+ if (!accepted)
257
+ throw new Error("FCU pending request not found");
258
+ const binding = fcuCompletionBinding(accepted, evidence.outputHash);
259
+ if (old && old.outputHash !== evidence.outputHash)
260
+ throw new Error("FCU conflicting completion binding");
261
+ if (old?.timing?.status === "late" || old?.timing?.status === "on-time")
262
+ return structuredClone(old.timing);
263
+ const assessment = await assessFcuCompletion(this.profile, structuredClone(accepted), this.miner.publicKey, evidence.outputHash, evidence.timingEvidence, verification.timing);
264
+ const prior = old?.timing;
265
+ if (prior && (assessment.lowerLatencyMs < prior.lowerLatencyMs || assessment.upperLatencyMs > prior.upperLatencyMs
266
+ || assessment.acceptedEarliestMs < prior.acceptedEarliestMs || assessment.acceptedLatestMs > prior.acceptedLatestMs
267
+ || assessment.completedEarliestMs < prior.completedEarliestMs || assessment.completedLatestMs > prior.completedLatestMs)) {
268
+ throw new Error("FCU conflicting timing evidence; adjudication required");
269
+ }
270
+ if (old) {
271
+ if (assessment.bindingHash !== binding)
272
+ throw new Error("FCU completion binding mismatch");
273
+ await this.write(s, { ...s, revision: s.revision + 1n,
274
+ delivered: { ...s.delivered, [sequence.toString()]: { ...old, timing: assessment } } });
275
+ }
276
+ else
277
+ await this.commitExecution(s, sequence, evidence, verification.execution, assessment);
278
+ return assessment;
279
+ }
280
+ async admissionControlMessage(paused) {
281
+ const s = await this.snapshot();
282
+ return fcuDomainMessage("flop-fcu-admission-control-v1", [this.binding, s.revision.toString(), paused]);
283
+ }
284
+ /** Serving pause only: funded obligations, reservations, claims and sold terms remain. */
285
+ async setAdmissionPaused(paused, minerSignature) {
286
+ const s = await this.snapshot();
287
+ if (typeof paused !== "boolean")
288
+ throw new Error("FCU invalid pause control");
289
+ const message = fcuDomainMessage("flop-fcu-admission-control-v1", [this.binding, s.revision.toString(), paused]);
290
+ if (!verify(this.miner.publicKey, message, minerSignature))
291
+ throw new Error("FCU miner admission-control signature invalid");
292
+ if (!paused) {
293
+ const observation = await this.authority.observe();
294
+ fcuHash(observation.finalizedBlockHash);
295
+ if (observation.genesisHash !== this.terms.genesisHash || observation.fundingBindingHash !== this.binding) {
296
+ throw new Error("FCU admission authority binding mismatch");
297
+ }
298
+ this.checkQualification(observation);
299
+ if (observation.servingEligibility !== "eligible")
300
+ throw new Error("FCU serving eligibility unavailable or paused");
301
+ fcuUnsigned(observation.recordedConsumedGn, (1n << 128n) - 1n, false);
302
+ if (observation.recordedConsumedGn > s.consumedGn)
303
+ throw new Error("FCU reconciliation required before admission");
304
+ }
305
+ await this.write(s, { ...s, revision: s.revision + 1n, admissionsPaused: paused });
306
+ }
307
+ async telemetry() {
308
+ const s = await this.snapshot();
309
+ const reservedGn = this.reserved(s);
310
+ return { source: "offchain-serving-journal", revision: s.revision, profileHash: this.terms.booking.profileHash,
311
+ admissionsPaused: s.admissionsPaused !== false, consumedGn: s.consumedGn, reservedGn,
312
+ unallocatedGn: this.terms.booking.quantityGn - s.consumedGn - reservedGn,
313
+ receiptCheckpoint: s.receiptCheckpoint ? { ...s.receiptCheckpoint } : null, receiptConfirmation: "not-assessed",
314
+ pendingChunks: s.pending.length, pendingRemedies: Object.values(s.delivered ?? {}).filter((d) => d.timing?.status !== "on-time").length,
315
+ unverifiedPendingChunks: s.pending.length,
316
+ authorityBlockHashes: [...new Set([...s.pending, ...Object.values(s.delivered ?? {}).map((d) => d.accepted)].map((p) => p.decision.authorityBlockHash))],
317
+ deliveryStartUtcMs: this.terms.booking.deliveryStartUtcMs, deliveryEndUtcMs: this.terms.booking.deliveryEndUtcMs };
318
+ }
319
+ async handoffMessage(nextKey) {
320
+ fcuHash(nextKey);
321
+ const s = await this.snapshot();
322
+ return fcuDomainMessage("flop-fcu-handoff-v1", [this.binding, s.revision.toString(), s.coordinatorKey, nextKey]);
323
+ }
324
+ async handoff(nextKey, oldSignature, newSignature) {
325
+ const s = await this.snapshot();
326
+ const observation = await this.authority.observe();
327
+ fcuHash(observation.finalizedBlockHash);
328
+ if (observation.fundingBindingHash !== this.binding)
329
+ throw new Error("FCU funding binding mismatch");
330
+ if (observation.genesisHash !== this.terms.genesisHash)
331
+ throw new Error("FCU authority chain mismatch");
332
+ if (s.pending.length || nextKey !== observation.coordinatorKey) {
333
+ throw new Error("FCU handoff requires drained pending work and finalized assignment");
334
+ }
335
+ fcuUnsigned(observation.recordedConsumedGn, (1n << 128n) - 1n, false);
336
+ if (observation.recordedConsumedGn !== s.consumedGn || (s.consumedGn > 0n
337
+ && (!s.receiptCheckpoint || !observation.confirmedReceipt
338
+ || observation.confirmedReceipt.aggregateGn !== s.receiptCheckpoint.aggregateGn
339
+ || observation.confirmedReceipt.root !== s.receiptCheckpoint.root))) {
340
+ throw new Error("FCU pending receipt settlement; reconciliation required before handoff");
341
+ }
342
+ const msg = fcuDomainMessage("flop-fcu-handoff-v1", [this.binding, s.revision.toString(), s.coordinatorKey, nextKey]);
343
+ const keyBytes = (k) => { fcuHash(k); return Uint8Array.from(k.slice(2).match(/../g), (b) => parseInt(b, 16)); };
344
+ if (!verify(keyBytes(s.coordinatorKey), msg, oldSignature) || !verify(keyBytes(nextKey), msg, newSignature)) {
345
+ throw new Error("FCU handoff countersignatures invalid");
346
+ }
347
+ await this.write(s, { ...s, revision: s.revision + 1n, coordinatorKey: nextKey });
348
+ }
349
+ }
350
+ //#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AE,CAAC,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;QACtH,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAE,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1H,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,EAAE,CAAC;YAC5G,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC3D,CAAC;QACD,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,GAAG,EAAE,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC,CAAC;IACpF,CAAC;CACF"}
@@ -0,0 +1,88 @@
1
+ export declare const FCU_TIMING_PROOF_GRACE_MS = 60000n;
2
+ export declare const FCU_SLA_CHALLENGE_MS = 86400000n;
3
+ export type FcuSlaClaimStatus = "awaiting-proof" | "provisional" | "contested" | "cleared" | "final";
4
+ export interface FcuVerifiedDelivery {
5
+ executionId: string;
6
+ outputHash: string;
7
+ receiptRoot: string;
8
+ beneficiarySnapshot: string;
9
+ workGn: bigint;
10
+ acceptedAtMs: bigint;
11
+ timing: "on-time" | "late" | "inconclusive" | "missing";
12
+ }
13
+ export interface FcuSlaClaim extends FcuVerifiedDelivery {
14
+ status: FcuSlaClaimStatus;
15
+ cause: "none" | "late" | "evidence-failure";
16
+ credit: bigint;
17
+ }
18
+ export interface FcuSlaState {
19
+ revision: bigint;
20
+ bindingHash: string;
21
+ quotaGn: bigint;
22
+ originalPrepayment: bigint;
23
+ deliveryEndUtcMs: bigint;
24
+ existingDisputeDaCutoffMs: bigint;
25
+ deliveredGn: bigint;
26
+ finalizedGn: bigint;
27
+ credits: bigint;
28
+ reserveReleased: bigint;
29
+ lastFinalizedOrdinal: bigint;
30
+ claims: FcuSlaClaim[];
31
+ }
32
+ export interface FcuSlaCredit {
33
+ beneficiarySnapshot: string;
34
+ amount: bigint;
35
+ executionId: string;
36
+ }
37
+ export interface FcuSlaStore {
38
+ load(bindingHash: string): Promise<FcuSlaState>;
39
+ /** False writes nothing. True atomically commits state and native FLOP credits/releases.
40
+ * Use one canonical non-rollback finalized history; a local file alone is insufficient. */
41
+ commit(bindingHash: string, revision: bigint, next: FcuSlaState, credit: FcuSlaCredit | null, providerRelease: bigint): Promise<boolean>;
42
+ }
43
+ export interface FcuSlaAuthority {
44
+ verifyDelivery(bindingHash: string, evidence: Uint8Array): Promise<{
45
+ delivery: FcuVerifiedDelivery;
46
+ nowUtcMs: bigint;
47
+ }>;
48
+ /** Authenticates UTC, chain/finality, eligibility and the original claim identity.
49
+ * previousOrdinal authenticates the prior reservation finalization, so no claim can skip its prefix.
50
+ * Contested claims require the existing authorized adjudicator's final verdict. */
51
+ verifyFinalization(bindingHash: string, executionId: string, evidence: Uint8Array): Promise<{
52
+ bindingHash: string;
53
+ executionId: string;
54
+ finalizedBlockHash: string;
55
+ ordinal: bigint;
56
+ previousOrdinal: bigint;
57
+ nowUtcMs: bigint;
58
+ verdict: "upheld" | "cleared";
59
+ }>;
60
+ verifyChallenge(bindingHash: string, executionId: string, evidence: Uint8Array): Promise<{
61
+ bindingHash: string;
62
+ executionId: string;
63
+ nowUtcMs: bigint;
64
+ cause: "late" | "evidence-failure";
65
+ }>;
66
+ /** Authenticates cutoff closure, no further ordinary claims, drained physical work/receipts and fences. */
67
+ verifyReserveRelease(bindingHash: string, evidence: Uint8Array): Promise<{
68
+ bindingHash: string;
69
+ nowUtcMs: bigint;
70
+ }>;
71
+ }
72
+ export declare function fcuSlaChallengeUntil(s: FcuSlaState): bigint;
73
+ export declare function fcuSlaEncumbered(s: FcuSlaState): bigint;
74
+ export declare function assertFcuSlaState(s: FcuSlaState): void;
75
+ export declare class FcuSlaLedger {
76
+ private readonly bindingHash;
77
+ private readonly store;
78
+ private readonly authority;
79
+ constructor(bindingHash: string, store: FcuSlaStore, authority: FcuSlaAuthority);
80
+ snapshot(): Promise<FcuSlaState>;
81
+ private write;
82
+ recordDelivery(evidence: Uint8Array): Promise<void>;
83
+ /** Call after authenticating a timely challenge through the existing dispute authority. */
84
+ contest(executionId: string, evidence: Uint8Array): Promise<void>;
85
+ finalize(executionId: string, evidence: Uint8Array): Promise<bigint>;
86
+ releaseReserve(evidence: Uint8Array): Promise<bigint>;
87
+ }
88
+ //# sourceMappingURL=fcu-sla.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fcu-sla.d.ts","sourceRoot":"","sources":["../../src/compute-channel/fcu-sla.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,yBAAyB,SAAU,CAAC;AACjD,eAAO,MAAM,oBAAoB,YAAc,CAAC;AAEhD,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,GAAG,aAAa,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;AACrG,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,SAAS,GAAG,MAAM,GAAG,cAAc,GAAG,SAAS,CAAC;CACzD;AACD,MAAM,WAAW,WAAY,SAAQ,mBAAmB;IACtD,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,EAAE,MAAM,GAAG,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AAO,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAUtE;IACK,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBzE;IACK,cAAc,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAQ1D;CACF"}
@@ -0,0 +1,154 @@
1
+ /** D-0538 finalized-only claims. Not a payment authority: settlement requires an atomic native-FLOP adapter. */
2
+ import { fcuHash, fcuUnsigned, FCU_ACCEPTED_CHUNK_MAX_MS } from "./fcu-profile.js";
3
+ export const FCU_TIMING_PROOF_GRACE_MS = 60000n;
4
+ export const FCU_SLA_CHALLENGE_MS = 86400000n;
5
+ export function fcuSlaChallengeUntil(s) {
6
+ const minimum = s.deliveryEndUtcMs + FCU_SLA_CHALLENGE_MS;
7
+ return minimum > s.existingDisputeDaCutoffMs ? minimum : s.existingDisputeDaCutoffMs;
8
+ }
9
+ const proofDue = (c) => c.acceptedAtMs + FCU_ACCEPTED_CHUNK_MAX_MS + FCU_TIMING_PROOF_GRACE_MS;
10
+ const pending = (s) => s.claims.filter((c) => !["cleared", "final"].includes(c.status))
11
+ .reduce((n, c) => n + c.workGn, 0n);
12
+ export function fcuSlaEncumbered(s) {
13
+ return s.originalPrepayment * (s.finalizedGn + pending(s)) / s.quotaGn - s.credits;
14
+ }
15
+ export function assertFcuSlaState(s) {
16
+ fcuHash(s.bindingHash);
17
+ fcuUnsigned(s.quotaGn);
18
+ fcuUnsigned(s.originalPrepayment);
19
+ for (const n of [s.revision, s.deliveryEndUtcMs, s.existingDisputeDaCutoffMs,
20
+ s.deliveredGn, s.finalizedGn, s.credits, s.reserveReleased, s.lastFinalizedOrdinal])
21
+ fcuUnsigned(n, (1n << 128n) - 1n, false);
22
+ let delivered = 0n, final = 0n, credited = 0n;
23
+ const ids = new Set();
24
+ for (const c of s.claims) {
25
+ [c.executionId, c.outputHash, c.receiptRoot, c.beneficiarySnapshot].forEach(fcuHash);
26
+ fcuUnsigned(c.workGn);
27
+ fcuUnsigned(c.acceptedAtMs, (1n << 64n) - 1n, false);
28
+ fcuUnsigned(c.credit, (1n << 128n) - 1n, false);
29
+ if (ids.has(c.executionId) || !["awaiting-proof", "provisional", "contested", "cleared", "final"].includes(c.status)
30
+ || !["on-time", "late", "inconclusive", "missing"].includes(c.timing)
31
+ || !["none", "late", "evidence-failure"].includes(c.cause)
32
+ || (c.status !== "final" && c.credit !== 0n)
33
+ || (c.status === "final" && c.cause === "none"))
34
+ throw new Error("FCU invalid/duplicate SLA claim");
35
+ ids.add(c.executionId);
36
+ delivered += c.workGn;
37
+ credited += c.credit;
38
+ if (c.status === "final")
39
+ final += c.workGn;
40
+ }
41
+ if (delivered !== s.deliveredGn || final !== s.finalizedGn || credited !== s.credits
42
+ || s.deliveredGn > s.quotaGn || s.finalizedGn + pending(s) > s.deliveredGn
43
+ || s.credits !== s.originalPrepayment * s.finalizedGn / s.quotaGn
44
+ || s.credits + s.reserveReleased + fcuSlaEncumbered(s) > s.originalPrepayment) {
45
+ throw new Error("FCU SLA conservation or reserve invariant failed");
46
+ }
47
+ }
48
+ export class FcuSlaLedger {
49
+ bindingHash;
50
+ store;
51
+ authority;
52
+ constructor(bindingHash, store, authority) {
53
+ this.bindingHash = bindingHash;
54
+ this.store = store;
55
+ this.authority = authority;
56
+ fcuHash(bindingHash);
57
+ }
58
+ async snapshot() {
59
+ const s = structuredClone(await this.store.load(this.bindingHash));
60
+ assertFcuSlaState(s);
61
+ if (s.bindingHash !== this.bindingHash)
62
+ throw new Error("FCU SLA binding mismatch");
63
+ return s;
64
+ }
65
+ async write(s, next, credit = null, release = 0n) {
66
+ next.revision = s.revision + 1n;
67
+ assertFcuSlaState(next);
68
+ if (!await this.store.commit(this.bindingHash, s.revision, structuredClone(next), credit, release)) {
69
+ throw new Error("FCU SLA transaction changed or payment failed; reconcile before retry");
70
+ }
71
+ }
72
+ async recordDelivery(evidence) {
73
+ const s = await this.snapshot();
74
+ const verified = await this.authority.verifyDelivery(this.bindingHash, evidence.slice());
75
+ const { nowUtcMs } = verified;
76
+ fcuUnsigned(nowUtcMs, (1n << 64n) - 1n, false);
77
+ if (s.reserveReleased !== 0n || nowUtcMs >= fcuSlaChallengeUntil(s))
78
+ throw new Error("FCU SLA submissions closed");
79
+ const delivery = structuredClone(verified.delivery);
80
+ const old = s.claims.find((c) => c.executionId === delivery.executionId);
81
+ if (old) {
82
+ if (["outputHash", "receiptRoot", "beneficiarySnapshot", "workGn", "acceptedAtMs"].some((k) => old[k] !== delivery[k]))
83
+ throw new Error("FCU conflicting delivery identity");
84
+ if (["final", "cleared"].includes(old.status)) {
85
+ if (delivery.timing !== old.timing)
86
+ throw new Error("FCU final timing cannot be replaced");
87
+ return;
88
+ }
89
+ if (old.status === "contested")
90
+ throw new Error("FCU contested claim requires final adjudication");
91
+ if (old.timing === "late" && delivery.timing !== "late")
92
+ throw new Error("FCU conflicting late evidence requires adjudication");
93
+ }
94
+ const claim = { ...delivery, credit: 0n, cause: delivery.timing === "late" ? "late"
95
+ : delivery.timing === "on-time" ? "none" : "evidence-failure",
96
+ status: delivery.timing === "on-time" ? "cleared" : "provisional" };
97
+ if (["missing", "inconclusive"].includes(delivery.timing) && nowUtcMs < proofDue(claim))
98
+ claim.status = "awaiting-proof";
99
+ if (delivery.acceptedAtMs > nowUtcMs)
100
+ throw new Error("FCU delivery precedes acceptance");
101
+ await this.write(s, { ...s, deliveredGn: s.deliveredGn + (old ? 0n : claim.workGn),
102
+ claims: old ? s.claims.map((c) => c.executionId === claim.executionId ? claim : c) : [...s.claims, claim] });
103
+ }
104
+ /** Call after authenticating a timely challenge through the existing dispute authority. */
105
+ async contest(executionId, evidence) {
106
+ const s = await this.snapshot();
107
+ const claim = s.claims.find((c) => c.executionId === executionId);
108
+ if (!claim || !["awaiting-proof", "provisional", "cleared"].includes(claim.status))
109
+ throw new Error("FCU claim not challengeable");
110
+ const challenge = await this.authority.verifyChallenge(this.bindingHash, executionId, evidence.slice());
111
+ const { nowUtcMs } = challenge;
112
+ if (challenge.bindingHash !== this.bindingHash || challenge.executionId !== executionId
113
+ || !["late", "evidence-failure"].includes(challenge.cause))
114
+ throw new Error("FCU challenge identity mismatch");
115
+ fcuUnsigned(nowUtcMs, (1n << 64n) - 1n, false);
116
+ if (nowUtcMs >= fcuSlaChallengeUntil(s))
117
+ throw new Error("FCU challenge cutoff passed");
118
+ await this.write(s, { ...s, claims: s.claims.map((c) => c.executionId === executionId ? { ...c, status: "contested", cause: challenge.cause } : c) });
119
+ }
120
+ async finalize(executionId, evidence) {
121
+ const s = await this.snapshot();
122
+ const claim = s.claims.find((c) => c.executionId === executionId);
123
+ if (!claim || ["cleared", "final"].includes(claim.status))
124
+ throw new Error("FCU claim not eligible to finalize");
125
+ const v = await this.authority.verifyFinalization(this.bindingHash, executionId, evidence.slice());
126
+ fcuHash(v.finalizedBlockHash);
127
+ fcuUnsigned(v.ordinal);
128
+ fcuUnsigned(v.previousOrdinal, (1n << 128n) - 1n, false);
129
+ fcuUnsigned(v.nowUtcMs, (1n << 64n) - 1n, false);
130
+ if (v.bindingHash !== this.bindingHash || v.executionId !== executionId || v.ordinal <= s.lastFinalizedOrdinal || v.previousOrdinal !== s.lastFinalizedOrdinal
131
+ || v.nowUtcMs < fcuSlaChallengeUntil(s) || v.nowUtcMs < proofDue(claim)
132
+ || !["upheld", "cleared"].includes(v.verdict))
133
+ throw new Error("FCU invalid finalized claim authority or cutoff");
134
+ const g = v.verdict === "upheld" ? claim.workGn : 0n;
135
+ const total = s.originalPrepayment * (s.finalizedGn + g) / s.quotaGn;
136
+ const delta = total - s.credits;
137
+ const next = { ...s, lastFinalizedOrdinal: v.ordinal, finalizedGn: s.finalizedGn + g, credits: total,
138
+ claims: s.claims.map((c) => c.executionId === executionId ? { ...c,
139
+ status: v.verdict === "upheld" ? "final" : "cleared", credit: delta } : c) };
140
+ await this.write(s, next, delta === 0n ? null : { amount: delta, executionId, beneficiarySnapshot: claim.beneficiarySnapshot });
141
+ return delta;
142
+ }
143
+ async releaseReserve(evidence) {
144
+ const s = await this.snapshot();
145
+ const v = await this.authority.verifyReserveRelease(this.bindingHash, evidence.slice());
146
+ fcuUnsigned(v.nowUtcMs, (1n << 64n) - 1n, false);
147
+ if (v.bindingHash !== this.bindingHash || v.nowUtcMs < fcuSlaChallengeUntil(s))
148
+ throw new Error("FCU reserve cutoff or binding invalid");
149
+ const release = s.originalPrepayment - s.credits - fcuSlaEncumbered(s) - s.reserveReleased;
150
+ await this.write(s, { ...s, reserveReleased: s.reserveReleased + release }, null, release);
151
+ return release;
152
+ }
153
+ }
154
+ //# sourceMappingURL=fcu-sla.js.map