@prismnetwork/mcp 0.8.3 → 0.9.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.
Files changed (4) hide show
  1. package/README.md +22 -38
  2. package/package.json +9 -11
  3. package/server.mjs +228 -194
  4. package/budget.mjs +0 -257
package/README.md CHANGED
@@ -13,20 +13,19 @@ claude mcp add prism -- npx -y @prismnetwork/mcp
13
13
  Then ask what you can rent. `prism_list_gpus` answers from live capacity with
14
14
  real prices. Leasing spends money, so those tools ask for a wallet and say so.
15
15
 
16
- Packaged for Claude Code and Codex as the [Prism plugin](https://plugins.prismnetwork.tech),
17
- which wires this server up and prompts for the wallet at install time.
18
-
19
16
  ## Tools
20
17
 
21
18
  | Tool | Wallet |
22
19
  | --- | --- |
23
- | `prism_budget` | no |
24
20
  | `prism_list_gpus` | no |
25
21
  | `prism_price_index` | no |
26
22
  | `prism_receipts` | no |
27
23
  | `prism_wallet` | yes |
28
24
  | `prism_leases` | yes |
29
25
  | `prism_infer` | yes |
26
+ | `prism_infer_batch` | yes |
27
+ | `prism_confidential_infer` | yes |
28
+ | `prism_verify_attestation` | no |
30
29
  | `prism_lease_and_run` | yes |
31
30
  | `prism_lease` | yes |
32
31
  | `prism_run` | yes |
@@ -38,8 +37,6 @@ which wires this server up and prompts for the wallet at install time.
38
37
  | `prism_vault_delete` | yes |
39
38
  | `prism_vault_release` | yes |
40
39
 
41
- - `prism_budget`: the spending limits in force and what has already been spent
42
- today, with the recent charges.
43
40
  - `prism_wallet`: the agent's address and USDG/ETH balances.
44
41
  - `prism_list_gpus`: GPUs available to lease, with price per second and per hour.
45
42
  - `prism_price_index`: sourced and settled pricing per GPU model, for cost estimates.
@@ -50,6 +47,23 @@ which wires this server up and prompts for the wallet at install time.
50
47
  paying the quoted USDG price from this wallet (about 0.01 USDG). Waits
51
48
  through a cold start; an unconsumed payment is kept and reused on the next
52
49
  call instead of paying twice.
50
+ - `prism_infer_batch`: buy many generations in one paid call, at the
51
+ single-generation price times the number of prompts. Each prompt runs whole on
52
+ a rented GPU and they are spread across every GPU the endpoint holds, so a
53
+ list of prompts finishes far sooner than the same prompts sent one at a time.
54
+ Returns every answer in order with a Merkle receipt naming the leases that did
55
+ the work.
56
+ - `prism_confidential_infer`: buy one generation that runs inside a GPU TEE.
57
+ The message contents are encrypted to a key the enclave's own attestation
58
+ commits to, so this server's relay carries ciphertext and cannot read the
59
+ prompt or the answer. Returns the answer, the cost and a receipt id the
60
+ workload signed over the exact bytes of the exchange.
61
+ - `prism_verify_attestation`: check one of those generations against its
62
+ receipt and the hardware behind it. The server remembers the digests of the
63
+ last few confidential calls, so the verdict is bound to the bytes it actually
64
+ sent and received. Every check is reported with its result, including the two
65
+ that cannot be established today: private-key custody, and where TLS
66
+ terminates.
53
67
  - `prism_lease_and_run`: lease a GPU, run a command, return the output (one shot).
54
68
  - `prism_lease`: lease a GPU and keep it; returns a `lease_id` and SSH access.
55
69
  - `prism_run`: run a command on an existing lease.
@@ -63,29 +77,6 @@ which wires this server up and prompts for the wallet at install time.
63
77
  - `prism_vault_delete`: permanently delete an item.
64
78
  - `prism_vault_release`: authorize an item into a lease that clears its trust floor.
65
79
 
66
- ## Spending limits
67
-
68
- Two ceilings bound what this server can spend, and a refusal quotes both.
69
-
70
- | Variable | Default | What it bounds |
71
- | --- | --- | --- |
72
- | `PRISM_MAX_USDG` | 1 | Any single lease or generation. `max_usdg` on a call may lower it, never raise it past this. |
73
- | `PRISM_DAILY_BUDGET_USDG` | 5 | Everything in a rolling 24 hours. `0` removes the ceiling. |
74
- | `PRISM_LEDGER_PATH` | `~/.prism/spend.json` | Where the spend is recorded. |
75
-
76
- Spend is written before the money moves, so a crash between funding an escrow
77
- and answering is counted rather than forgiven, and a restart does not hand back
78
- a fresh day's allowance. Only an attempt that provably never reached the chain
79
- is reverted. Two clients pointed at one wallet share one ceiling, because they
80
- share the ledger file.
81
-
82
- None of this is the real limit. Fund a dedicated wallet with what you are
83
- willing to lose: that balance is what survives a bug in everything above.
84
-
85
- Tools that spend are annotated `destructiveHint` and carry
86
- `anthropic/requiresUserInteraction`, so Claude Code asks before every one of
87
- them even in modes that otherwise approve tools automatically.
88
-
89
80
  ## Vault
90
81
 
91
82
  An agent that handles a card, an identity document or a credential should not
@@ -111,8 +102,7 @@ Point your MCP client (Claude Desktop / Code) at the published server:
111
102
  "args": ["-y", "@prismnetwork/mcp"],
112
103
  "env": {
113
104
  "PRISM_AGENT_KEY": "0x<agent wallet private key>",
114
- "PRISM_MAX_USDG": "1",
115
- "PRISM_DAILY_BUDGET_USDG": "5"
105
+ "PRISM_ESCROW": "0x62C042265991bEa17B07229322A01850974626dA"
116
106
  }
117
107
  }
118
108
  }
@@ -125,17 +115,11 @@ Or add it to Claude Code in one line:
125
115
 
126
116
  ```sh
127
117
  claude mcp add prism \
118
+ --env PRISM_ESCROW=0x62C042265991bEa17B07229322A01850974626dA \
128
119
  --env PRISM_AGENT_KEY=0x<agent wallet private key> \
129
- --env PRISM_DAILY_BUDGET_USDG=5 \
130
120
  -- npx -y @prismnetwork/mcp
131
121
  ```
132
122
 
133
- Codex takes the same server:
134
-
135
- ```sh
136
- codex mcp add prism --env PRISM_AGENT_KEY=0x<agent wallet private key> -- npx -y @prismnetwork/mcp
137
- ```
138
-
139
123
  ## Timing
140
124
 
141
125
  `prism_lease` and `prism_lease_and_run` block while a GPU provisions (usually one to four minutes, occasionally longer on a slow host). Configure your MCP client to allow long tool calls.
package/package.json CHANGED
@@ -1,15 +1,14 @@
1
1
  {
2
2
  "name": "@prismnetwork/mcp",
3
- "version": "0.8.3",
3
+ "version": "0.9.0",
4
4
  "description": "MCP server for leasing and running on Prism Network GPUs.",
5
- "mcpName": "tech.prismnetwork/mcp",
5
+ "mcpName": "io.github.prismnetwork-tech/mcp",
6
6
  "type": "module",
7
7
  "bin": {
8
8
  "prism-mcp": "server.mjs"
9
9
  },
10
10
  "files": [
11
11
  "server.mjs",
12
- "budget.mjs",
13
12
  "README.md"
14
13
  ],
15
14
  "engines": {
@@ -17,19 +16,18 @@
17
16
  },
18
17
  "dependencies": {
19
18
  "@modelcontextprotocol/sdk": "^1.0.0",
20
- "@prismnetwork/agent-sdk": "^0.6.1",
19
+ "@phala/dcap-qvl": "^0.6.1",
20
+ "@prismnetwork/agent-sdk": "^0.7.0",
21
+ "jose": "^6",
21
22
  "viem": "^2"
22
23
  },
23
24
  "keywords": [
25
+ "prism",
26
+ "mcp",
27
+ "gpu",
24
28
  "agent",
25
29
  "claude",
26
- "codex",
27
- "compute",
28
- "gpu",
29
- "gpu-rental",
30
- "mcp",
31
- "prism",
32
- "x402"
30
+ "compute"
33
31
  ],
34
32
  "homepage": "https://prismnetwork.tech",
35
33
  "repository": {
package/server.mjs CHANGED
@@ -2,13 +2,17 @@
2
2
  // Prism Network MCP server: lets an MCP client (Claude, agents) see and lease
3
3
  // real GPUs. Looking is free and needs no configuration. Leasing spends money,
4
4
  // so it needs a wallet: PRISM_AGENT_KEY, PRISM_ESCROW.
5
+ import { createHash } from "node:crypto";
5
6
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
6
7
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
7
8
  import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
8
- import { DEFAULT_IMAGE, DEFAULT_TRUST_FLOOR, PrismAgent, TRUST_CLASSES } from "@prismnetwork/agent-sdk";
9
- import { BudgetError, SpendLedger, readBudget, stripUnexpanded } from "./budget.mjs";
10
-
11
- stripUnexpanded(process.env);
9
+ import {
10
+ DEFAULT_IMAGE,
11
+ DEFAULT_TRUST_FLOOR,
12
+ PrismAgent,
13
+ TRUST_CLASSES,
14
+ verifyConfidential,
15
+ } from "@prismnetwork/agent-sdk";
12
16
 
13
17
  const IMAGE = process.env.PRISM_DEFAULT_IMAGE ?? DEFAULT_IMAGE;
14
18
 
@@ -44,18 +48,6 @@ if (!agent) {
44
48
  );
45
49
  }
46
50
 
47
- // A budget the operator got wrong must stop spending, not fall back to none.
48
- // Reading capacity and prices is unaffected, so a typo is discoverable rather
49
- // than fatal.
50
- let ledger = null;
51
- let budgetProblem = null;
52
- try {
53
- ledger = new SpendLedger(readBudget());
54
- } catch (err) {
55
- budgetProblem = err?.message ?? String(err);
56
- console.error(`prism mcp: ${budgetProblem}`);
57
- }
58
-
59
51
  function requireWallet(tool, reason = "spends money") {
60
52
  if (!agent) {
61
53
  throw new Error(
@@ -65,43 +57,6 @@ function requireWallet(tool, reason = "spends money") {
65
57
  return agent;
66
58
  }
67
59
 
68
- function requireLedger(tool) {
69
- if (!ledger) {
70
- throw new Error(`${tool} needs the spend limits, and they are unusable: ${budgetProblem}`);
71
- }
72
- return ledger;
73
- }
74
-
75
- // Records the spend before the money moves, then reconciles. An attempt that
76
- // never reached the chain is reverted; anything that funded an escrow keeps its
77
- // entry and gains the transaction that proves it, because a ledger that forgets
78
- // a funded lease is worse than no ledger at all.
79
- async function spending(tool, micros, run) {
80
- const book = requireLedger(tool);
81
- const id = book.commit({ tool, micros });
82
- // Reconciling is bookkeeping and must never be the reason a caller loses a
83
- // machine it paid for, or the reason a failure is reported as the wrong
84
- // failure. A ledger that cannot be written says so on stderr and the
85
- // committed figure stands, which errs towards counting the spend.
86
- const reconcile = (action, ...args) => {
87
- try {
88
- book[action](id, ...args);
89
- } catch (err) {
90
- console.error(`prism mcp: could not ${action} the ledger entry for ${tool}: ${err?.message ?? err}`);
91
- }
92
- };
93
- try {
94
- const { value, settledMicros, reference } = await run();
95
- reconcile("settle", { micros: settledMicros, reference });
96
- return value;
97
- } catch (err) {
98
- const funded = err?.body?.funding_hash;
99
- if (funded) reconcile("settle", { reference: funded });
100
- else reconcile("revert");
101
- throw err;
102
- }
103
- }
104
-
105
60
  function requireCommand(value) {
106
61
  if (typeof value !== "string" || value.trim() === "") {
107
62
  throw new Error("command is required: the shell command to run on the GPU, e.g. 'nvidia-smi'.");
@@ -112,12 +67,8 @@ function requireCommand(value) {
112
67
  return value;
113
68
  }
114
69
 
115
- // The per-call ceiling is the operator's, not the model's: an omitted max_usdg
116
- // takes the configured cap rather than a hardcoded one, and a stated max_usdg
117
- // above it is refused when the ledger checks the commit.
118
- function maxDeposit(tool, args) {
119
- if (args.max_usdg === undefined) return requireLedger(tool).maxPerCallMicros;
120
- const cap = args.max_usdg;
70
+ function maxDeposit(args) {
71
+ const cap = args.max_usdg ?? 1;
121
72
  if (typeof cap !== "number" || !Number.isFinite(cap) || cap <= 0) {
122
73
  throw new Error("max_usdg must be a positive number of USDG.");
123
74
  }
@@ -138,13 +89,56 @@ async function publicJson(url, what) {
138
89
  }
139
90
 
140
91
  const leases = new Map();
141
- // Unconsumed inference payments, keyed by endpoint and price, so a failed
142
- // generation is retried with the same paid header instead of paying again.
143
- const pendingInference = new Map();
144
92
  // null in, null out: a missing price must never render as 0.000000 USDG.
145
93
  const usdg = (micros) =>
146
94
  micros == null || !Number.isFinite(Number(micros)) ? null : `${(Number(micros) / 1e6).toFixed(6)} USDG`;
147
95
 
96
+ /// The SDK pays once and keeps the payment until the endpoint actually serves,
97
+ /// so a generation that never happened is retried with the payment already made.
98
+ async function payAndPost({ base, path, price, payTo, body, tool }) {
99
+ const served = await agent.payAndPost({ base, path, price, payTo, body, caller: tool });
100
+ return { ...JSON.parse(served.bytes.toString("utf8")), paid: usdg(price), payment_tx: served.tx };
101
+ }
102
+
103
+ // What the last few confidential calls sent and received, as digests only, so
104
+ // prism_verify_attestation binds its verdict to the real bytes of a call
105
+ // without keeping anyone's prompt in memory.
106
+ const confidentialCalls = new Map();
107
+ const CONFIDENTIAL_HISTORY = 16;
108
+
109
+ const sha256Prefixed = (bytes) => `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
110
+
111
+ function rememberConfidentialCall(receiptId, record) {
112
+ if (!receiptId) return;
113
+ confidentialCalls.set(receiptId, record);
114
+ while (confidentialCalls.size > CONFIDENTIAL_HISTORY) {
115
+ confidentialCalls.delete(confidentialCalls.keys().next().value);
116
+ }
117
+ }
118
+
119
+ const inferenceBase = () =>
120
+ (process.env.PRISM_INFERENCE_URL ?? "https://api.prismnetwork.tech/inference").replace(/\/$/, "");
121
+
122
+ /// What the endpoint currently offers, and the model this call should use.
123
+ async function inferenceOffer(base, requested) {
124
+ const offer = await publicJson(`${base}/v1/models`, "inference endpoint");
125
+ const model = requested ?? offer.models?.[0];
126
+ if (!model || (Array.isArray(offer.models) && !offer.models.includes(model))) {
127
+ throw new Error(`model must be one of ${offer.models?.join(", ") ?? "(endpoint offered none)"}`);
128
+ }
129
+ return { offer, model, unit: BigInt(offer.price_micros ?? 0) };
130
+ }
131
+
132
+ function withinCap(price, maxUsdg, fallback, what) {
133
+ const cap = maxUsdg ?? fallback;
134
+ if (typeof cap !== "number" || !Number.isFinite(cap) || cap <= 0) {
135
+ throw new Error("max_usdg must be a positive number of USDG.");
136
+ }
137
+ if (price <= 0n || price > BigInt(Math.round(cap * 1e6))) {
138
+ throw new Error(`the endpoint quotes ${usdg(price)} ${what}, past the ${cap} USDG cap.`);
139
+ }
140
+ }
141
+
148
142
  function sweepExpiredLeases() {
149
143
  const now = Date.now();
150
144
  for (const [id, lease] of leases) {
@@ -162,28 +156,11 @@ function leaseId(value) {
162
156
  return id;
163
157
  }
164
158
 
165
- // Hints a client uses to decide what it may run unattended. `reads` is anything
166
- // that cannot change state or move money; `spends` is anything that can, and it
167
- // carries the Claude Code marker that forces a confirmation prompt on every call
168
- // even in modes that otherwise auto-approve.
169
- const reads = { readOnlyHint: true, openWorldHint: true };
170
- const spends = {
171
- annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true },
172
- _meta: { "anthropic/requiresUserInteraction": true },
173
- };
174
-
175
159
  const TOOLS = [
176
- {
177
- name: "prism_budget",
178
- description: "Show the spending limits this server enforces and what it has already spent in the last 24 hours, with the recent charges. Needs no wallet. Check this before a long job; a lease refused for budget says the same numbers.",
179
- inputSchema: { type: "object", properties: {} },
180
- annotations: { title: "Spending limits", readOnlyHint: true, openWorldHint: false },
181
- },
182
160
  {
183
161
  name: "prism_wallet",
184
162
  description: "Show the agent's wallet address and on-chain balances (USDG and ETH for gas) on Robinhood Chain. Check this before leasing to confirm the wallet can pay.",
185
163
  inputSchema: { type: "object", properties: {} },
186
- annotations: { title: "Wallet balances", ...reads },
187
164
  },
188
165
  {
189
166
  name: "prism_list_gpus",
@@ -198,13 +175,11 @@ const TOOLS = [
198
175
  },
199
176
  },
200
177
  },
201
- annotations: { title: "Available GPUs", ...reads },
202
178
  },
203
179
  {
204
180
  name: "prism_price_index",
205
181
  description: "Current GPU pricing on Prism Network by model: sourced low/median/high and settled mean, in USDG per hour. Needs no wallet. Use it to estimate what an analysis job will cost before leasing.",
206
182
  inputSchema: { type: "object", properties: {} },
207
- annotations: { title: "GPU price index", ...reads },
208
183
  },
209
184
  {
210
185
  name: "prism_receipts",
@@ -215,13 +190,11 @@ const TOOLS = [
215
190
  limit: { type: "integer", description: "Max receipts to return (default 10, max 50)." },
216
191
  },
217
192
  },
218
- annotations: { title: "Settled receipts", ...reads },
219
193
  },
220
194
  {
221
195
  name: "prism_leases",
222
196
  description: "List this wallet's leases on Prism Network with their current state.",
223
197
  inputSchema: { type: "object", properties: {} },
224
- annotations: { title: "Your leases", ...reads },
225
198
  },
226
199
  {
227
200
  name: "prism_batch_run",
@@ -236,8 +209,6 @@ const TOOLS = [
236
209
  },
237
210
  required: ["command"],
238
211
  },
239
- ...spends,
240
- annotations: { title: "Rent a GPU for one command", ...spends.annotations },
241
212
  },
242
213
  {
243
214
  name: "prism_batch_result",
@@ -249,7 +220,6 @@ const TOOLS = [
249
220
  },
250
221
  required: ["lease_id"],
251
222
  },
252
- annotations: { title: "Batch result", ...reads },
253
223
  },
254
224
  {
255
225
  name: "prism_infer",
@@ -263,8 +233,52 @@ const TOOLS = [
263
233
  },
264
234
  required: ["prompt"],
265
235
  },
266
- ...spends,
267
- annotations: { title: "Buy one LLM generation", ...spends.annotations },
236
+ },
237
+ {
238
+ name: "prism_infer_batch",
239
+ description: "Buy many LLM generations from Prism's managed inference endpoint in one paid call. Every prompt runs whole on a rented GPU, spread across every GPU the endpoint holds, so a list of prompts finishes far sooner than the same prompts sent one at a time. Costs the single-generation price times the number of prompts. Returns every answer in order plus a Merkle receipt naming the leases that did the work. Use it for evals, dataset passes, rollouts, or anything with more than a handful of independent prompts.",
240
+ inputSchema: {
241
+ type: "object",
242
+ properties: {
243
+ prompts: {
244
+ type: "array",
245
+ items: { type: "string" },
246
+ minItems: 1,
247
+ maxItems: 64,
248
+ description: "Independent prompts, answered in the order given (each max 32 KiB).",
249
+ },
250
+ model: { type: "string", description: "Model to use; defaults to the endpoint's first offered model." },
251
+ max_usdg: { type: "number", description: "Refuse if the quoted total exceeds this (default 0.5)." },
252
+ },
253
+ required: ["prompts"],
254
+ },
255
+ },
256
+ {
257
+ name: "prism_confidential_infer",
258
+ description: "Buy one LLM generation that runs inside a GPU TEE, with the message contents encrypted end to end to a key the enclave's own attestation commits to, so Prism's relay in between carries ciphertext and cannot read the prompt or the answer. Costs a little more than prism_infer. Returns the answer, the cost, and a receipt id the workload signed over the exact bytes of the exchange; pass that id to prism_verify_attestation to check the whole chain. Use it for anything the operator of an ordinary endpoint should not be able to read.",
259
+ inputSchema: {
260
+ type: "object",
261
+ properties: {
262
+ prompt: { type: "string", description: "The prompt to generate from." },
263
+ model: { type: "string", description: "Confidential model to use; defaults to the endpoint's first." },
264
+ max_tokens: { type: "integer", description: "Cap on generated tokens (default 512). The price is quoted against this cap." },
265
+ max_usdg: { type: "number", description: "Refuse if the quoted price exceeds this (default 0.25)." },
266
+ e2ee: { type: "boolean", description: "Encrypt message contents to the attested enclave key (default true). Turn it off only when the relay is allowed to read the prompt." },
267
+ },
268
+ required: ["prompt"],
269
+ },
270
+ },
271
+ {
272
+ name: "prism_verify_attestation",
273
+ description: "Check a confidential generation against its signed receipt and the hardware behind it: the TDX quote verifies to Intel's root and commits to the key set that signed the receipt, the boot log replays to the measurement in that quote, the receipt covers the exact bytes of this call, the upstream that ran the model was itself verified, and the GPU is attested by NVIDIA. Returns every check with its result, including the ones that cannot be established today. Needs no wallet.",
274
+ inputSchema: {
275
+ type: "object",
276
+ properties: {
277
+ receipt_id: { type: "string", description: "The receipt_id from prism_confidential_infer." },
278
+ model: { type: "string", description: "Model to fetch GPU evidence for; defaults to the one recorded for this receipt." },
279
+ },
280
+ required: ["receipt_id"],
281
+ },
268
282
  },
269
283
  {
270
284
  name: "prism_lease_and_run",
@@ -284,8 +298,6 @@ const TOOLS = [
284
298
  },
285
299
  required: ["command"],
286
300
  },
287
- ...spends,
288
- annotations: { title: "Rent a GPU and run a command", ...spends.annotations },
289
301
  },
290
302
  {
291
303
  name: "prism_lease",
@@ -303,8 +315,6 @@ const TOOLS = [
303
315
  max_usdg: { type: "number", description: "Hard cap on the USDG this lease may cost (default 1). Raise it deliberately for longer leases." },
304
316
  },
305
317
  },
306
- ...spends,
307
- annotations: { title: "Rent a GPU", ...spends.annotations },
308
318
  },
309
319
  {
310
320
  name: "prism_run",
@@ -318,7 +328,6 @@ const TOOLS = [
318
328
  },
319
329
  required: ["lease_id", "command"],
320
330
  },
321
- annotations: { title: "Run a command on a lease", readOnlyHint: false, destructiveHint: true, openWorldHint: true },
322
331
  },
323
332
  {
324
333
  name: "prism_end_lease",
@@ -328,7 +337,6 @@ const TOOLS = [
328
337
  properties: { lease_id: { type: "integer" } },
329
338
  required: ["lease_id"],
330
339
  },
331
- annotations: { title: "Release a lease", readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
332
340
  },
333
341
  {
334
342
  name: "prism_vault_store",
@@ -346,13 +354,11 @@ const TOOLS = [
346
354
  },
347
355
  required: ["value"],
348
356
  },
349
- annotations: { title: "Seal a secret", readOnlyHint: false, destructiveHint: false, openWorldHint: true },
350
357
  },
351
358
  {
352
359
  name: "prism_vault_list",
353
360
  description: "List the agent's sealed vault items: item_id, label, version and trust floor. Values are not returned and are not readable by Prism.",
354
361
  inputSchema: { type: "object", properties: {} },
355
- annotations: { title: "List sealed items", ...reads },
356
362
  },
357
363
  {
358
364
  name: "prism_vault_read",
@@ -362,8 +368,6 @@ const TOOLS = [
362
368
  properties: { item_id: { type: "string", description: "The item_id from prism_vault_store or prism_vault_list." } },
363
369
  required: ["item_id"],
364
370
  },
365
- _meta: { "anthropic/requiresUserInteraction": true },
366
- annotations: { title: "Decrypt one sealed item", readOnlyHint: true, openWorldHint: true },
367
371
  },
368
372
  {
369
373
  name: "prism_vault_delete",
@@ -373,8 +377,6 @@ const TOOLS = [
373
377
  properties: { item_id: { type: "string" } },
374
378
  required: ["item_id"],
375
379
  },
376
- ...spends,
377
- annotations: { title: "Delete a sealed item", ...spends.annotations },
378
380
  },
379
381
  {
380
382
  name: "prism_vault_release",
@@ -387,13 +389,10 @@ const TOOLS = [
387
389
  },
388
390
  required: ["item_id", "lease_id"],
389
391
  },
390
- ...spends,
391
- annotations: { title: "Release a secret into a lease", ...spends.annotations },
392
392
  },
393
393
  ];
394
394
 
395
395
  async function handle(name, args) {
396
- if (name === "prism_budget") return requireLedger(name).status();
397
396
  if (name === "prism_wallet") {
398
397
  const b = await requireWallet("prism_wallet").balances();
399
398
  return { address: b.address, usdg: usdg(b.usdg), eth_wei: b.eth };
@@ -484,27 +483,22 @@ async function handle(name, args) {
484
483
  if (name === "prism_batch_run") {
485
484
  requireCommand(args.command);
486
485
  requireWallet(name);
487
- const cap = maxDeposit(name, args);
488
- return spending(name, cap, async () => {
489
- const batch = await agent.lease({
490
- image: IMAGE,
491
- durationSeconds: args.duration_seconds ?? 900,
492
- minVramMib: args.min_vram_mib ?? 16000,
493
- maxDeposit: cap,
494
- command: args.command,
495
- });
496
- return {
497
- reference: batch.fundingHash,
498
- value: {
499
- lease_id: batch.leaseId,
500
- funding_tx: batch.fundingHash,
501
- exit_code: batch.result?.exit_code,
502
- stdout: batch.result?.stdout,
503
- stderr: batch.result?.stderr,
504
- truncated: batch.result?.truncated ?? false,
505
- },
506
- };
486
+ const cap = maxDeposit(args);
487
+ const batch = await agent.lease({
488
+ image: IMAGE,
489
+ durationSeconds: args.duration_seconds ?? 900,
490
+ minVramMib: args.min_vram_mib ?? 16000,
491
+ maxDeposit: cap,
492
+ command: args.command,
507
493
  });
494
+ return {
495
+ lease_id: batch.leaseId,
496
+ funding_tx: batch.fundingHash,
497
+ exit_code: batch.result?.exit_code,
498
+ stdout: batch.result?.stdout,
499
+ stderr: batch.result?.stderr,
500
+ truncated: batch.result?.truncated ?? false,
501
+ };
508
502
  }
509
503
  if (name === "prism_batch_result") {
510
504
  requireWallet(name, "reads this wallet's leases");
@@ -516,83 +510,126 @@ async function handle(name, args) {
516
510
  throw new Error("prompt is required.");
517
511
  }
518
512
  requireWallet(name);
519
- const base = (process.env.PRISM_INFERENCE_URL ?? "https://api.prismnetwork.tech/inference").replace(/\/$/, "");
520
- const offer = await publicJson(`${base}/v1/models`, "inference endpoint");
521
- const model = args.model ?? offer.models?.[0];
522
- if (!model || (Array.isArray(offer.models) && !offer.models.includes(model))) {
523
- throw new Error(`model must be one of ${offer.models?.join(", ") ?? "(endpoint offered none)"}`);
513
+ const base = inferenceBase();
514
+ const { offer, model, unit } = await inferenceOffer(base, args.model);
515
+ withinCap(unit, args.max_usdg, 0.05, "per generation");
516
+ return payAndPost({
517
+ base,
518
+ path: "/v1/inference",
519
+ price: unit,
520
+ payTo: offer.pay_to,
521
+ body: { model, prompt: args.prompt },
522
+ tool: "prism_infer",
523
+ });
524
+ }
525
+ if (name === "prism_infer_batch") {
526
+ const prompts = args.prompts;
527
+ if (!Array.isArray(prompts) || !prompts.length) {
528
+ throw new Error("prompts must be a non-empty array of strings.");
524
529
  }
525
- const price = BigInt(offer.price_micros ?? 0);
526
- const cap = args.max_usdg ?? 0.05;
527
- if (typeof cap !== "number" || !Number.isFinite(cap) || cap <= 0) {
528
- throw new Error("max_usdg must be a positive number of USDG.");
530
+ if (prompts.some((p) => typeof p !== "string" || p.trim() === "")) {
531
+ throw new Error("every prompt must be a non-empty string.");
529
532
  }
530
- if (price <= 0n || price > BigInt(Math.round(cap * 1e6))) {
531
- throw new Error(`the endpoint quotes ${usdg(price)} per generation, past the ${cap} USDG cap.`);
533
+ if (prompts.length > 64) {
534
+ throw new Error(`a batch takes at most 64 prompts; ${prompts.length} were given.`);
532
535
  }
533
- const pendingKey = `${base}:${price}`;
534
- let pending = pendingInference.get(pendingKey);
535
- // A kept payment was already charged and already counted. Only a new
536
- // transfer touches the ledger, or a retry would bill the day twice for one
537
- // generation.
538
- if (!pending) {
539
- pending = await spending(name, Number(price), async () => {
540
- const paymentTx = await agent.transferUsdg(offer.pay_to, price);
541
- const signature = await agent.account.signMessage({ message: paymentTx });
542
- return {
543
- reference: paymentTx,
544
- value: {
545
- tx: paymentTx,
546
- header: Buffer.from(JSON.stringify({ txHash: paymentTx, signature })).toString("base64"),
547
- },
548
- };
549
- });
550
- pendingInference.set(pendingKey, pending);
536
+ requireWallet(name);
537
+ const base = inferenceBase();
538
+ const { offer, model, unit } = await inferenceOffer(base, args.model);
539
+ const price = unit * BigInt(prompts.length);
540
+ withinCap(price, args.max_usdg, 0.5, `for ${prompts.length} generations`);
541
+ return payAndPost({
542
+ base,
543
+ path: "/v1/batch",
544
+ price,
545
+ payTo: offer.pay_to,
546
+ body: { model, prompts },
547
+ tool: "prism_infer_batch",
548
+ });
549
+ }
550
+ if (name === "prism_confidential_infer") {
551
+ if (typeof args.prompt !== "string" || args.prompt.trim() === "") {
552
+ throw new Error("prompt is required.");
551
553
  }
552
- // A cold endpoint holds the request through provisioning; when it answers
553
- // 503 instead, the payment is not consumed and the same header retries.
554
- const deadline = Date.now() + 600_000;
555
- for (;;) {
556
- const res = await fetch(`${base}/v1/inference`, {
557
- method: "POST",
558
- headers: { "content-type": "application/json", "x-payment": pending.header },
559
- body: JSON.stringify({ model, prompt: args.prompt }),
560
- signal: AbortSignal.timeout(620_000),
561
- });
562
- const body = await res.json().catch(() => null);
563
- if (res.status === 200 && body) {
564
- pendingInference.delete(pendingKey);
565
- return { ...body, paid: usdg(price), payment_tx: pending.tx };
566
- }
567
- const last = body?.detail ?? body?.error ?? `status ${res.status}`;
568
- // 503 means the box is warming; a 402 for a payment that is merely too
569
- // young (confirmations still landing, receipt not yet visible) heals by
570
- // itself. Everything else is final.
571
- const retryable =
572
- res.status === 503 ||
573
- (res.status === 402 && ["insufficient_confirmations", "tx_not_found"].includes(body?.error));
574
- if (!retryable || Date.now() > deadline) {
575
- throw new Error(
576
- `inference failed: ${last}. The payment (tx ${pending.tx}) was not consumed and is kept; the next prism_infer call retries with it instead of paying again.`,
577
- );
578
- }
579
- await new Promise((r) => setTimeout(r, 15_000));
554
+ requireWallet(name);
555
+ const base = inferenceBase();
556
+ const run = await agent.confidentialInfer({
557
+ prompt: args.prompt,
558
+ model: args.model,
559
+ maxTokens: args.max_tokens ?? 512,
560
+ maxUsdg: args.max_usdg ?? 0.25,
561
+ e2ee: args.e2ee ?? true,
562
+ endpoint: base,
563
+ });
564
+ rememberConfidentialCall(run.receiptId, {
565
+ base,
566
+ model: run.model,
567
+ e2ee: run.e2ee,
568
+ keysetDigest: run.keysetDigest,
569
+ responseHash: sha256Prefixed(run.bytes.response),
570
+ requestHash: sha256Prefixed(run.bytes.request),
571
+ restoredRequestHash: run.bytes.restoredRequest ? sha256Prefixed(run.bytes.restoredRequest) : null,
572
+ });
573
+ return {
574
+ model: run.model,
575
+ content: run.content,
576
+ usage: run.usage,
577
+ receipt_id: run.receiptId,
578
+ paid: usdg(run.priceMicros),
579
+ payment_tx: run.tx,
580
+ e2ee: run.e2ee
581
+ ? "on: the prompt and the answer were encrypted to the enclave's attested key, and the relay carried ciphertext"
582
+ : "off: the relay could read this prompt",
583
+ next: `prism_verify_attestation with receipt_id ${run.receiptId} checks the hardware, the receipt and the GPU behind this answer`,
584
+ };
585
+ }
586
+ if (name === "prism_verify_attestation") {
587
+ if (typeof args.receipt_id !== "string" || args.receipt_id.trim() === "") {
588
+ throw new Error("receipt_id is required: the id prism_confidential_infer returned.");
580
589
  }
590
+ // Without the bytes of the call, a receipt still proves what the workload
591
+ // signed, but not that it signed this exchange. That is `incomplete`, and it
592
+ // is a different thing to tell an agent than a failure.
593
+ const remembered = confidentialCalls.get(args.receipt_id) ?? {};
594
+ const bound = remembered.responseHash != null;
595
+ const result = await verifyConfidential({
596
+ base: remembered.base ?? inferenceBase(),
597
+ receiptId: args.receipt_id,
598
+ model: args.model ?? remembered.model,
599
+ e2ee: Boolean(remembered.e2ee),
600
+ requestHash: remembered.requestHash ?? null,
601
+ responseHash: remembered.responseHash ?? null,
602
+ restoredRequestHash: remembered.restoredRequestHash ?? null,
603
+ expectedKeysetDigest: remembered.keysetDigest ?? null,
604
+ });
605
+ const mark = { pass: "ok", fail: "FAIL", skip: "skip" };
606
+ return {
607
+ receipt_id: args.receipt_id,
608
+ verdict: result.verdict,
609
+ verdict_means: {
610
+ verified: "every check that ran passed, and the only skips are the documented ones",
611
+ incomplete: "nothing failed, and evidence some check needed was not available here",
612
+ failed: "a check failed",
613
+ }[result.verdict],
614
+ bound_to_this_session: bound,
615
+ ...(bound
616
+ ? {}
617
+ : { unbound_because: "this server has no record of that call, so the request and response checks could not run" }),
618
+ measured_source: result.provenance,
619
+ checks: result.checks.map((c) => `${mark[c.status]} ${c.title}${c.detail ? `: ${c.detail}` : ""}`),
620
+ };
581
621
  }
582
622
  if (name === "prism_lease_and_run" || name === "prism_lease") {
583
623
  if (name === "prism_lease_and_run") requireCommand(args.command);
584
624
  requireWallet(name);
585
- const cap = maxDeposit(name, args);
625
+ const cap = maxDeposit(args);
586
626
  sweepExpiredLeases();
587
- const lease = await spending(name, cap, async () => {
588
- const funded = await agent.lease({
589
- image: IMAGE,
590
- durationSeconds: args.duration_seconds ?? 900,
591
- minVramMib: args.min_vram_mib ?? 16000,
592
- maxDeposit: cap,
593
- minTrustClass: args.min_trust_class ?? "open",
594
- });
595
- return { value: funded, reference: funded.fundingHash };
627
+ const lease = await agent.lease({
628
+ image: IMAGE,
629
+ durationSeconds: args.duration_seconds ?? 900,
630
+ minVramMib: args.min_vram_mib ?? 16000,
631
+ maxDeposit: cap,
632
+ minTrustClass: args.min_trust_class ?? "open",
596
633
  });
597
634
  leases.set(lease.leaseId, lease);
598
635
  const summary = {
@@ -690,16 +727,13 @@ async function handleVault(name, args) {
690
727
  throw new Error(`unknown tool ${name}`);
691
728
  }
692
729
 
693
- const server = new Server({ name: "prism", version: "0.8.3" }, { capabilities: { tools: {} } });
730
+ const server = new Server({ name: "prism", version: "0.9.0" }, { capabilities: { tools: {} } });
694
731
  server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS }));
695
732
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
696
733
  try {
697
734
  const result = await handle(request.params.name, request.params.arguments ?? {});
698
735
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
699
736
  } catch (err) {
700
- if (err instanceof BudgetError) {
701
- return { isError: true, content: [{ type: "text", text: `${err.message} See prism_budget.` }] };
702
- }
703
737
  const body = err?.body ?? {};
704
738
  const detail = [
705
739
  body.cause,
package/budget.mjs DELETED
@@ -1,257 +0,0 @@
1
- // What stands between a model deciding to rent a GPU and a wallet paying for it.
2
- // The real ceiling is the balance; fund the agent wallet with what you are
3
- // willing to lose. This is the second line, and it exists because `max_usdg`
4
- // never was one: it bounds a single lease and says nothing about the fortieth in
5
- // a row, which is what an unattended agent actually does.
6
- //
7
- // Spend is written before the money moves and reverted only when the attempt
8
- // provably cost nothing, so a crash between funding and reply is counted rather
9
- // than forgiven. The file is shared across clients on purpose: one wallet gets
10
- // one daily ceiling whoever is holding it.
11
- import { mkdirSync, readFileSync, renameSync, writeFileSync, openSync, closeSync, unlinkSync, statSync } from "node:fs";
12
- import { homedir } from "node:os";
13
- import { dirname, join } from "node:path";
14
-
15
- const MICROS = 1_000_000;
16
- const DAY_MS = 86_400_000;
17
- // Entries older than this are dropped on write. Two days covers the rolling
18
- // window with room for a clock that stepped backwards.
19
- const MEMORY_MS = 2 * DAY_MS;
20
- const LOCK_STALE_MS = 15_000;
21
- const LOCK_WAIT_MS = 5_000;
22
-
23
- export class BudgetError extends Error {
24
- constructor(message, detail = {}) {
25
- super(message);
26
- this.name = "BudgetError";
27
- this.detail = detail;
28
- }
29
- }
30
-
31
- export const usdg = (micros) => `${(Number(micros) / MICROS).toFixed(6)} USDG`;
32
-
33
- function positiveNumber(raw, fallback, name) {
34
- if (raw === undefined || raw === null || String(raw).trim() === "") return fallback;
35
- const value = Number(raw);
36
- if (!Number.isFinite(value) || value < 0) {
37
- throw new BudgetError(`${name} must be a non-negative number of USDG, got ${JSON.stringify(raw)}`);
38
- }
39
- return value;
40
- }
41
-
42
- // One .mcp.json serves every client, and they disagree about templates: Claude
43
- // Code expands ${user_config.x} before launch, Codex passes it through. Reading
44
- // the literal template as a value would turn "no wallet configured" into
45
- // "wallet configured and broken", so an unexpanded placeholder is nothing.
46
- export function stripUnexpanded(env = process.env) {
47
- for (const [key, value] of Object.entries(env)) {
48
- if (key.startsWith("PRISM_") && /^\$\{[^}]*\}$/.test(String(value ?? "").trim())) delete env[key];
49
- }
50
- return env;
51
- }
52
-
53
- export function defaultLedgerPath(env = process.env) {
54
- if (env.PRISM_LEDGER_PATH) return env.PRISM_LEDGER_PATH;
55
- return join(env.HOME || homedir(), ".prism", "spend.json");
56
- }
57
-
58
- // A missing budget is not an unlimited one. The default is deliberately small:
59
- // enough for a handful of real leases, cheap enough that discovering the plugin
60
- // spends money costs about the price of a coffee rather than a rent cheque.
61
- export function readBudget(env = process.env) {
62
- const maxPerCall = positiveNumber(env.PRISM_MAX_USDG, 1, "PRISM_MAX_USDG");
63
- const daily = positiveNumber(env.PRISM_DAILY_BUDGET_USDG, 5, "PRISM_DAILY_BUDGET_USDG");
64
- if (maxPerCall <= 0) throw new BudgetError("PRISM_MAX_USDG must be above zero");
65
- // A per-call cap above the day's allowance is a cap in name only, and the
66
- // mismatch is always a configuration mistake rather than an intention.
67
- if (daily > 0 && maxPerCall > daily) {
68
- throw new BudgetError(
69
- `PRISM_MAX_USDG (${maxPerCall}) cannot exceed PRISM_DAILY_BUDGET_USDG (${daily}); lower the per-call cap or raise the daily one`,
70
- );
71
- }
72
- return {
73
- maxPerCallMicros: Math.round(maxPerCall * MICROS),
74
- // Zero means the operator explicitly removed the daily ceiling. It is not
75
- // the default and it is not what a missing variable produces.
76
- dailyMicros: Math.round(daily * MICROS),
77
- ledgerPath: defaultLedgerPath(env),
78
- };
79
- }
80
-
81
- // A lock rather than last-write-wins, because two clients sharing one wallet is
82
- // the case this file exists for. A lock older than LOCK_STALE_MS belonged to a
83
- // process that died; breaking it is safe and not breaking it wedges the wallet.
84
- function withLock(path, fn, waitMs = LOCK_WAIT_MS) {
85
- const lock = `${path}.lock`;
86
- mkdirSync(dirname(path), { recursive: true });
87
- const deadline = Date.now() + waitMs;
88
- for (;;) {
89
- let fd;
90
- try {
91
- fd = openSync(lock, "wx");
92
- } catch (err) {
93
- if (err?.code !== "EEXIST") throw err;
94
- let age = 0;
95
- try {
96
- age = Date.now() - statSync(lock).mtimeMs;
97
- } catch {
98
- continue; // it vanished between the open and the stat; retry immediately
99
- }
100
- if (age > LOCK_STALE_MS) {
101
- try {
102
- unlinkSync(lock);
103
- } catch {
104
- /* another process broke it first, which is the outcome we wanted */
105
- }
106
- continue;
107
- }
108
- if (Date.now() > deadline) {
109
- throw new BudgetError(
110
- `the spend ledger at ${path} is locked by another Prism process; nothing was charged. Retry in a moment.`,
111
- );
112
- }
113
- // Busy-wait deliberately: this holds for milliseconds and the alternative
114
- // is making every caller of a synchronous ledger asynchronous.
115
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 25);
116
- continue;
117
- }
118
- try {
119
- closeSync(fd);
120
- return fn();
121
- } finally {
122
- try {
123
- unlinkSync(lock);
124
- } catch {
125
- /* already gone */
126
- }
127
- }
128
- }
129
- }
130
-
131
- function readState(path) {
132
- try {
133
- const parsed = JSON.parse(readFileSync(path, "utf8"));
134
- if (!parsed || !Array.isArray(parsed.entries)) return { entries: [] };
135
- return { entries: parsed.entries.filter((e) => e && Number.isFinite(e.at) && Number.isFinite(e.micros)) };
136
- } catch (err) {
137
- if (err?.code === "ENOENT") return { entries: [] };
138
- // A corrupt ledger must not read as an empty one: that would hand the
139
- // caller a fresh day's budget every time the file got truncated.
140
- throw new BudgetError(
141
- `the spend ledger at ${path} is unreadable (${err?.message ?? err}), so spending is refused. Move or repair the file.`,
142
- );
143
- }
144
- }
145
-
146
- function writeState(path, state, now) {
147
- const entries = state.entries.filter((e) => now - e.at < MEMORY_MS);
148
- const tmp = `${path}.${process.pid}.tmp`;
149
- writeFileSync(tmp, `${JSON.stringify({ version: 1, entries }, null, 2)}\n`, { mode: 0o600 });
150
- renameSync(tmp, path);
151
- }
152
-
153
- export function spentInWindow(entries, now) {
154
- return entries.reduce((total, e) => (now - e.at < DAY_MS ? total + e.micros : total), 0);
155
- }
156
-
157
- export class SpendLedger {
158
- constructor({ ledgerPath, dailyMicros, maxPerCallMicros, lockWaitMs = LOCK_WAIT_MS }) {
159
- this.path = ledgerPath;
160
- this.dailyMicros = dailyMicros;
161
- this.maxPerCallMicros = maxPerCallMicros;
162
- this.lockWaitMs = lockWaitMs;
163
- }
164
-
165
- // What is left of today, for the caller to show before it asks to spend.
166
- remaining(now = Date.now()) {
167
- if (this.dailyMicros <= 0) return null;
168
- const { entries } = readState(this.path);
169
- return Math.max(0, this.dailyMicros - spentInWindow(entries, now));
170
- }
171
-
172
- status(now = Date.now()) {
173
- const { entries } = readState(this.path);
174
- const spent = spentInWindow(entries, now);
175
- return {
176
- daily_budget: this.dailyMicros > 0 ? usdg(this.dailyMicros) : "unlimited (PRISM_DAILY_BUDGET_USDG=0)",
177
- spent_last_24h: usdg(spent),
178
- remaining_today: this.dailyMicros > 0 ? usdg(Math.max(0, this.dailyMicros - spent)) : "unlimited",
179
- max_per_call: usdg(this.maxPerCallMicros),
180
- ledger: this.path,
181
- charges_last_24h: entries
182
- .filter((e) => now - e.at < DAY_MS)
183
- .sort((a, b) => b.at - a.at)
184
- .slice(0, 20)
185
- .map((e) => ({
186
- at: new Date(e.at).toISOString(),
187
- tool: e.tool,
188
- amount: usdg(e.micros),
189
- ...(e.reference ? { reference: e.reference } : {}),
190
- })),
191
- };
192
- }
193
-
194
- // Records the spend before the money moves. Returns a handle the caller
195
- // reverts only when it can prove nothing was charged.
196
- commit({ tool, micros, now = Date.now() }) {
197
- if (!Number.isFinite(micros) || micros <= 0) {
198
- throw new BudgetError("a spend must be a positive number of micros");
199
- }
200
- if (micros > this.maxPerCallMicros) {
201
- throw new BudgetError(
202
- `${tool} would commit up to ${usdg(micros)}, past the ${usdg(this.maxPerCallMicros)} per-call cap. ` +
203
- `Lower max_usdg for this call, or raise PRISM_MAX_USDG.`,
204
- { required: micros, cap: this.maxPerCallMicros },
205
- );
206
- }
207
- return withLock(
208
- this.path,
209
- () => {
210
- const state = readState(this.path);
211
- const spent = spentInWindow(state.entries, now);
212
- if (this.dailyMicros > 0 && spent + micros > this.dailyMicros) {
213
- throw new BudgetError(
214
- `${tool} would take today's Prism spend to ${usdg(spent + micros)}, past the ${usdg(this.dailyMicros)} ` +
215
- `daily cap (${usdg(spent)} already spent). Nothing was charged. Raise PRISM_DAILY_BUDGET_USDG to continue.`,
216
- { spent, requested: micros, cap: this.dailyMicros },
217
- );
218
- }
219
- const id = `${now.toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
220
- state.entries.push({ id, at: now, tool, micros });
221
- writeState(this.path, state, now);
222
- return id;
223
- },
224
- this.lockWaitMs,
225
- );
226
- }
227
-
228
- // Only for an attempt that provably cost nothing. A funded lease whose command
229
- // failed is not one of those.
230
- revert(id) {
231
- if (!id) return false;
232
- return withLock(this.path, () => {
233
- const state = readState(this.path);
234
- const before = state.entries.length;
235
- state.entries = state.entries.filter((e) => e.id !== id);
236
- if (state.entries.length === before) return false;
237
- writeState(this.path, state, Date.now());
238
- return true;
239
- }, this.lockWaitMs);
240
- }
241
-
242
- // Replaces the reserved figure with what was actually committed on-chain and
243
- // pins the receipt to it, so the ledger reads like a statement rather than a
244
- // list of intentions.
245
- settle(id, { micros, reference } = {}) {
246
- if (!id) return false;
247
- return withLock(this.path, () => {
248
- const state = readState(this.path);
249
- const entry = state.entries.find((e) => e.id === id);
250
- if (!entry) return false;
251
- if (Number.isFinite(micros) && micros >= 0) entry.micros = micros;
252
- if (reference) entry.reference = reference;
253
- writeState(this.path, state, Date.now());
254
- return true;
255
- }, this.lockWaitMs);
256
- }
257
- }