@gvnrdao/dh-mcp 0.5.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.
package/README.md CHANGED
@@ -11,13 +11,13 @@ so there is **nothing to install first** (no Node, no npm):
11
11
 
12
12
  | You are on | Install path |
13
13
  |---|---|
14
- | **Claude Desktop (macOS / Windows)** | Download the bundle and open it (double-click / drag into Settings → Extensions): `https://assets.gvnr.xyz/dh-mcp/v0.5.0/dh-mcp-0.5.0.mcpb` — Claude Desktop runs it on its own embedded runtime; network and optional keystore are configured in the extension's settings UI (the password is held by the OS credential store, never written to a config file). |
15
- | **Linux — including Claude Desktop builds on Linux — or any other MCP host** | One line, no sudo: `curl -fsSL https://assets.gvnr.xyz/dh-mcp/install.sh \| sh` — installs a self-contained binary (its own Node runtime inside) to `~/.dh-mcp/bin/dh-mcp`, verifies its SHA-256, and prints the exact `mcpServers` snippet. **Then wire the host:** Claude Code: `claude mcp add diamond-hands -- $HOME/.dh-mcp/bin/dh-mcp` (new session); Claude Desktop (Linux builds): the snippet in `~/.config/Claude/claude_desktop_config.json`, full quit + relaunch; other hosts: the snippet in their MCP config. Pin a version: `curl -fsSL https://assets.gvnr.xyz/dh-mcp/install.sh \| DH_VERSION=0.5.0 sh` |
14
+ | **Claude Desktop (macOS / Windows)** | Download the bundle and open it (double-click / drag into Settings → Extensions): `https://assets.gvnr.xyz/dh-mcp/v0.5.2/dh-mcp-0.5.2.mcpb` — Claude Desktop runs it on its own embedded runtime; network and optional keystore are configured in the extension's settings UI (the password is held by the OS credential store, never written to a config file). |
15
+ | **Linux — including Claude Desktop builds on Linux — or any other MCP host** | One line, no sudo: `curl -fsSL https://assets.gvnr.xyz/dh-mcp/install.sh \| sh` — installs a self-contained binary (its own Node runtime inside) to `~/.dh-mcp/bin/dh-mcp`, verifies its SHA-256, and prints the exact `mcpServers` snippet. **Then wire the host:** Claude Code: `claude mcp add diamond-hands -- $HOME/.dh-mcp/bin/dh-mcp` (new session); Claude Desktop (Linux builds): the snippet in `~/.config/Claude/claude_desktop_config.json`, full quit + relaunch; other hosts: the snippet in their MCP config. Pin a version: `curl -fsSL https://assets.gvnr.xyz/dh-mcp/install.sh \| DH_VERSION=0.5.2 sh` |
16
16
  | **Developers** (requires **Node ≥ 18 on PATH** — this path does NOT work on a bare machine) | Claude Code: `claude mcp add diamond-hands -- npx -y @gvnrdao/dh-mcp` · any host JSON: `{ "mcpServers": { "diamond-hands": { "command": "npx", "args": ["-y", "@gvnrdao/dh-mcp"] } } }` |
17
17
 
18
18
  Downloads landing page (which file is for which system, checksums, security notes):
19
19
  **https://assets.gvnr.xyz/dh-mcp/** — all artifacts and `SHA256SUMS` live under it
20
- (`latest/` and `v<version>/` — e.g. `v0.5.0/`).
20
+ (`latest/` and `v<version>/` — e.g. `v0.5.2/`).
21
21
 
22
22
  Local installs serve local MCP hosts only — **claude.ai web / mobile / Cowork cannot
23
23
  reach them** (a hosted remote connector is a separate, upcoming tier).
package/dist/boundary.js CHANGED
@@ -88203,6 +88203,22 @@ async function verifyBroadcastTxByHash(provider, hash, approved, borrower, budge
88203
88203
 
88204
88204
  // src/signer/external-eoa.ts
88205
88205
  var DEFAULT_BUDGET = { attempts: 30, delayMs: 3e3 };
88206
+ async function gasHintAcrossBlocks(provider, from, tx2, action) {
88207
+ if (typeof provider.estimateGas !== "function") return null;
88208
+ let lastErr = null;
88209
+ for (let attempt = 0; attempt < 4; attempt++) {
88210
+ try {
88211
+ const est = await provider.estimateGas({ from, to: tx2.to, data: tx2.data, value: BigInt(tx2.value) });
88212
+ return import_ethers36.ethers.toBeHex(est * 15n / 10n);
88213
+ } catch (e) {
88214
+ lastErr = e;
88215
+ await new Promise((r) => setTimeout(r, 13e3));
88216
+ }
88217
+ }
88218
+ throw new Error(
88219
+ `the ${action} transaction kept reverting in gas estimation across blocks \u2014 refusing to hand it to the wallet (it would fail on-chain; a wallet-side estimate would fall back to an absurd fee and block confirmation): ${(lastErr?.message ?? "unknown estimation failure").slice(0, 200)}`
88220
+ );
88221
+ }
88206
88222
  var ExternalEoaDHSigner = class {
88207
88223
  constructor(deps) {
88208
88224
  this.deps = deps;
@@ -88254,6 +88270,7 @@ var ExternalEoaDHSigner = class {
88254
88270
  }
88255
88271
  async submitValidatedTx(outerTx, ctx) {
88256
88272
  const approved = toApprovedTx(outerTx, this.deps.chainId);
88273
+ const gas = outerTx.gasLimit != null ? import_ethers36.ethers.toBeHex(BigInt(String(outerTx.gasLimit))) : await gasHintAcrossBlocks(this.deps.provider, this.deps.borrower, approved, ctx.action);
88257
88274
  const outcome = await this.deps.bridge.requestSignature({
88258
88275
  id: (0, import_node_crypto5.randomUUID)(),
88259
88276
  kind: "transaction",
@@ -88261,7 +88278,7 @@ var ExternalEoaDHSigner = class {
88261
88278
  card: ctx.card,
88262
88279
  expectedSigner: this.deps.borrower,
88263
88280
  chainId: this.deps.chainId,
88264
- tx: approved
88281
+ tx: { ...approved, ...gas ? { gas } : {}, txType: 2 }
88265
88282
  });
88266
88283
  if (outcome.status !== "approved") {
88267
88284
  throw new OperationDeclined(`the ${ctx.action} transaction was not approved: ${describeOutcome(outcome)}`);
@@ -88361,6 +88378,7 @@ var BridgeEthersSigner = class _BridgeEthersSigner extends import_ethers36.ether
88361
88378
  chainId: tx2.chainId != null ? Number(tx2.chainId) : this.deps.chainId
88362
88379
  };
88363
88380
  const card = cardForTx(approved);
88381
+ const gas = tx2.gasLimit != null ? import_ethers36.ethers.toBeHex(BigInt(String(tx2.gasLimit))) : await gasHintAcrossBlocks(this.deps.provider, this.deps.borrower, approved, describeFn(approved.data));
88364
88382
  const outcome = await this.deps.bridge.requestSignature({
88365
88383
  id: (0, import_node_crypto5.randomUUID)(),
88366
88384
  kind: "transaction",
@@ -88368,7 +88386,7 @@ var BridgeEthersSigner = class _BridgeEthersSigner extends import_ethers36.ether
88368
88386
  card,
88369
88387
  expectedSigner: this.deps.borrower,
88370
88388
  chainId: approved.chainId,
88371
- tx: { ...approved, ...tx2.gasLimit != null ? { gas: import_ethers36.ethers.toBeHex(BigInt(String(tx2.gasLimit))) } : {}, txType: 2 }
88389
+ tx: { ...approved, ...gas ? { gas } : {}, txType: 2 }
88372
88390
  });
88373
88391
  if (outcome.status !== "approved") {
88374
88392
  throw new OperationDeclined(`the transaction was not approved: ${describeOutcome(outcome)}`);
@@ -89516,10 +89534,15 @@ document.getElementById("generate").onclick = () => submit(true);
89516
89534
  // src/boundary/upstream/shared/external-bridge/bridge.ts
89517
89535
  var MAX_SESSIONS = 16;
89518
89536
  var DEFAULT_EXPIRY_MS = 5 * 60 * 1e3;
89537
+ var DEFAULT_ATTACH_GRACE_MS = 60 * 1e3;
89519
89538
  var JSON_LIMIT_BYTES = 64 * 1024;
89520
89539
  var SignatureBridge = class {
89521
89540
  clock;
89522
89541
  expiryMs;
89542
+ attachGraceMs;
89543
+ /** Last sweep tick that saw a live attachment — the unattended grace measures from
89544
+ * max(enqueue, this), so a page closed mid-wait gets the same grace as never-opened. */
89545
+ lastAttachedMs = 0;
89523
89546
  server = null;
89524
89547
  port = 0;
89525
89548
  token = (0, import_node_crypto6.randomBytes)(24).toString("hex");
@@ -89544,6 +89567,7 @@ var SignatureBridge = class {
89544
89567
  constructor(opts) {
89545
89568
  this.clock = opts?.clock ?? Date.now;
89546
89569
  this.expiryMs = opts?.expiryMs ?? DEFAULT_EXPIRY_MS;
89570
+ this.attachGraceMs = opts?.attachGraceMs ?? DEFAULT_ATTACH_GRACE_MS;
89547
89571
  this.urlFile = opts?.urlFile;
89548
89572
  this.network = opts?.network;
89549
89573
  this.wcConfig = opts?.wc;
@@ -89618,9 +89642,11 @@ var SignatureBridge = class {
89618
89642
  });
89619
89643
  }
89620
89644
  return new Promise((resolve) => {
89645
+ const now = this.clock();
89621
89646
  const entry = {
89622
89647
  request,
89623
- deadlineMs: this.clock() + this.expiryMs,
89648
+ deadlineMs: now + this.expiryMs,
89649
+ enqueuedMs: now,
89624
89650
  resolve,
89625
89651
  settled: false,
89626
89652
  ...handlers?.finalize ? { finalize: handlers.finalize } : {}
@@ -89643,9 +89669,11 @@ var SignatureBridge = class {
89643
89669
  requestSignatureCollection(request, collect) {
89644
89670
  if (!this.server) return Promise.resolve({ status: "invalidated", reason: "bridge is not started" });
89645
89671
  return new Promise((resolve) => {
89672
+ const now = this.clock();
89646
89673
  const entry = {
89647
89674
  request,
89648
- deadlineMs: this.clock() + this.expiryMs,
89675
+ deadlineMs: now + this.expiryMs,
89676
+ enqueuedMs: now,
89649
89677
  resolve,
89650
89678
  settled: false,
89651
89679
  collect
@@ -89715,12 +89743,32 @@ var SignatureBridge = class {
89715
89743
  }
89716
89744
  }
89717
89745
  }
89718
- /** Expire overdue requests. Runs on a real-time interval; tests call it directly with the
89719
- * injected clock advanced. */
89746
+ /** A live attachment that could still decide a request: an open approval-page SSE
89747
+ * stream (real page or headless driver) or an active WalletConnect session. */
89748
+ attachedNow() {
89749
+ if (this.wcActive) return true;
89750
+ for (const s of this.sessions.values()) if (s.sse) return true;
89751
+ return false;
89752
+ }
89753
+ /** Expire overdue requests; fail UNATTENDED requests fast. Runs on a real-time
89754
+ * interval; tests call it directly with the injected clock advanced. Order matters:
89755
+ * the deadline is checked first so expiry semantics stay pinned (T-EXT-03). */
89720
89756
  sweep() {
89721
89757
  const now = this.clock();
89758
+ const attached = this.attachedNow();
89759
+ if (attached) this.lastAttachedMs = now;
89722
89760
  for (const entry of this.pending.values()) {
89723
- if (!entry.settled && now >= entry.deadlineMs) this.settle(entry, { status: "expired" });
89761
+ if (entry.settled) continue;
89762
+ if (now >= entry.deadlineMs) {
89763
+ this.settle(entry, { status: "expired" });
89764
+ continue;
89765
+ }
89766
+ if (!attached && now - Math.max(entry.enqueuedMs, this.lastAttachedMs) >= this.attachGraceMs) {
89767
+ this.settle(entry, {
89768
+ status: "invalidated",
89769
+ reason: `no wallet approval page is attached to this bridge (it may have been closed) \u2014 open ${this.url()} in the browser, connect the wallet, and retry the operation`
89770
+ });
89771
+ }
89724
89772
  }
89725
89773
  }
89726
89774
  close() {
package/dist/index.js CHANGED
@@ -88405,6 +88405,22 @@ async function verifyBroadcastTxByHash(provider, hash, approved, borrower, budge
88405
88405
 
88406
88406
  // src/signer/external-eoa.ts
88407
88407
  var DEFAULT_BUDGET = { attempts: 30, delayMs: 3e3 };
88408
+ async function gasHintAcrossBlocks(provider, from, tx2, action) {
88409
+ if (typeof provider.estimateGas !== "function") return null;
88410
+ let lastErr = null;
88411
+ for (let attempt = 0; attempt < 4; attempt++) {
88412
+ try {
88413
+ const est = await provider.estimateGas({ from, to: tx2.to, data: tx2.data, value: BigInt(tx2.value) });
88414
+ return import_ethers36.ethers.toBeHex(est * 15n / 10n);
88415
+ } catch (e) {
88416
+ lastErr = e;
88417
+ await new Promise((r) => setTimeout(r, 13e3));
88418
+ }
88419
+ }
88420
+ throw new Error(
88421
+ `the ${action} transaction kept reverting in gas estimation across blocks \u2014 refusing to hand it to the wallet (it would fail on-chain; a wallet-side estimate would fall back to an absurd fee and block confirmation): ${(lastErr?.message ?? "unknown estimation failure").slice(0, 200)}`
88422
+ );
88423
+ }
88408
88424
  var ExternalEoaDHSigner = class {
88409
88425
  constructor(deps) {
88410
88426
  this.deps = deps;
@@ -88456,6 +88472,7 @@ var ExternalEoaDHSigner = class {
88456
88472
  }
88457
88473
  async submitValidatedTx(outerTx, ctx) {
88458
88474
  const approved = toApprovedTx(outerTx, this.deps.chainId);
88475
+ const gas = outerTx.gasLimit != null ? import_ethers36.ethers.toBeHex(BigInt(String(outerTx.gasLimit))) : await gasHintAcrossBlocks(this.deps.provider, this.deps.borrower, approved, ctx.action);
88459
88476
  const outcome = await this.deps.bridge.requestSignature({
88460
88477
  id: (0, import_node_crypto5.randomUUID)(),
88461
88478
  kind: "transaction",
@@ -88463,7 +88480,7 @@ var ExternalEoaDHSigner = class {
88463
88480
  card: ctx.card,
88464
88481
  expectedSigner: this.deps.borrower,
88465
88482
  chainId: this.deps.chainId,
88466
- tx: approved
88483
+ tx: { ...approved, ...gas ? { gas } : {}, txType: 2 }
88467
88484
  });
88468
88485
  if (outcome.status !== "approved") {
88469
88486
  throw new OperationDeclined(`the ${ctx.action} transaction was not approved: ${describeOutcome(outcome)}`);
@@ -88563,6 +88580,7 @@ var BridgeEthersSigner = class _BridgeEthersSigner extends import_ethers36.ether
88563
88580
  chainId: tx2.chainId != null ? Number(tx2.chainId) : this.deps.chainId
88564
88581
  };
88565
88582
  const card = cardForTx(approved);
88583
+ const gas = tx2.gasLimit != null ? import_ethers36.ethers.toBeHex(BigInt(String(tx2.gasLimit))) : await gasHintAcrossBlocks(this.deps.provider, this.deps.borrower, approved, describeFn(approved.data));
88566
88584
  const outcome = await this.deps.bridge.requestSignature({
88567
88585
  id: (0, import_node_crypto5.randomUUID)(),
88568
88586
  kind: "transaction",
@@ -88570,7 +88588,7 @@ var BridgeEthersSigner = class _BridgeEthersSigner extends import_ethers36.ether
88570
88588
  card,
88571
88589
  expectedSigner: this.deps.borrower,
88572
88590
  chainId: approved.chainId,
88573
- tx: { ...approved, ...tx2.gasLimit != null ? { gas: import_ethers36.ethers.toBeHex(BigInt(String(tx2.gasLimit))) } : {}, txType: 2 }
88591
+ tx: { ...approved, ...gas ? { gas } : {}, txType: 2 }
88574
88592
  });
88575
88593
  if (outcome.status !== "approved") {
88576
88594
  throw new OperationDeclined(`the transaction was not approved: ${describeOutcome(outcome)}`);
@@ -89718,10 +89736,15 @@ document.getElementById("generate").onclick = () => submit(true);
89718
89736
  // src/boundary/upstream/shared/external-bridge/bridge.ts
89719
89737
  var MAX_SESSIONS = 16;
89720
89738
  var DEFAULT_EXPIRY_MS = 5 * 60 * 1e3;
89739
+ var DEFAULT_ATTACH_GRACE_MS = 60 * 1e3;
89721
89740
  var JSON_LIMIT_BYTES = 64 * 1024;
89722
89741
  var SignatureBridge = class {
89723
89742
  clock;
89724
89743
  expiryMs;
89744
+ attachGraceMs;
89745
+ /** Last sweep tick that saw a live attachment — the unattended grace measures from
89746
+ * max(enqueue, this), so a page closed mid-wait gets the same grace as never-opened. */
89747
+ lastAttachedMs = 0;
89725
89748
  server = null;
89726
89749
  port = 0;
89727
89750
  token = (0, import_node_crypto6.randomBytes)(24).toString("hex");
@@ -89746,6 +89769,7 @@ var SignatureBridge = class {
89746
89769
  constructor(opts) {
89747
89770
  this.clock = opts?.clock ?? Date.now;
89748
89771
  this.expiryMs = opts?.expiryMs ?? DEFAULT_EXPIRY_MS;
89772
+ this.attachGraceMs = opts?.attachGraceMs ?? DEFAULT_ATTACH_GRACE_MS;
89749
89773
  this.urlFile = opts?.urlFile;
89750
89774
  this.network = opts?.network;
89751
89775
  this.wcConfig = opts?.wc;
@@ -89820,9 +89844,11 @@ var SignatureBridge = class {
89820
89844
  });
89821
89845
  }
89822
89846
  return new Promise((resolve) => {
89847
+ const now = this.clock();
89823
89848
  const entry = {
89824
89849
  request,
89825
- deadlineMs: this.clock() + this.expiryMs,
89850
+ deadlineMs: now + this.expiryMs,
89851
+ enqueuedMs: now,
89826
89852
  resolve,
89827
89853
  settled: false,
89828
89854
  ...handlers?.finalize ? { finalize: handlers.finalize } : {}
@@ -89845,9 +89871,11 @@ var SignatureBridge = class {
89845
89871
  requestSignatureCollection(request, collect) {
89846
89872
  if (!this.server) return Promise.resolve({ status: "invalidated", reason: "bridge is not started" });
89847
89873
  return new Promise((resolve) => {
89874
+ const now = this.clock();
89848
89875
  const entry = {
89849
89876
  request,
89850
- deadlineMs: this.clock() + this.expiryMs,
89877
+ deadlineMs: now + this.expiryMs,
89878
+ enqueuedMs: now,
89851
89879
  resolve,
89852
89880
  settled: false,
89853
89881
  collect
@@ -89917,12 +89945,32 @@ var SignatureBridge = class {
89917
89945
  }
89918
89946
  }
89919
89947
  }
89920
- /** Expire overdue requests. Runs on a real-time interval; tests call it directly with the
89921
- * injected clock advanced. */
89948
+ /** A live attachment that could still decide a request: an open approval-page SSE
89949
+ * stream (real page or headless driver) or an active WalletConnect session. */
89950
+ attachedNow() {
89951
+ if (this.wcActive) return true;
89952
+ for (const s of this.sessions.values()) if (s.sse) return true;
89953
+ return false;
89954
+ }
89955
+ /** Expire overdue requests; fail UNATTENDED requests fast. Runs on a real-time
89956
+ * interval; tests call it directly with the injected clock advanced. Order matters:
89957
+ * the deadline is checked first so expiry semantics stay pinned (T-EXT-03). */
89922
89958
  sweep() {
89923
89959
  const now = this.clock();
89960
+ const attached = this.attachedNow();
89961
+ if (attached) this.lastAttachedMs = now;
89924
89962
  for (const entry of this.pending.values()) {
89925
- if (!entry.settled && now >= entry.deadlineMs) this.settle(entry, { status: "expired" });
89963
+ if (entry.settled) continue;
89964
+ if (now >= entry.deadlineMs) {
89965
+ this.settle(entry, { status: "expired" });
89966
+ continue;
89967
+ }
89968
+ if (!attached && now - Math.max(entry.enqueuedMs, this.lastAttachedMs) >= this.attachGraceMs) {
89969
+ this.settle(entry, {
89970
+ status: "invalidated",
89971
+ reason: `no wallet approval page is attached to this bridge (it may have been closed) \u2014 open ${this.url()} in the browser, connect the wallet, and retry the operation`
89972
+ });
89973
+ }
89926
89974
  }
89927
89975
  }
89928
89976
  close() {
@@ -92229,7 +92277,7 @@ function registerBoundaryInfoResource(server, getB) {
92229
92277
  }
92230
92278
 
92231
92279
  // src/server.ts
92232
- var SERVER_VERSION = "0.5.0";
92280
+ var SERVER_VERSION = "0.5.2";
92233
92281
  var SERVER_INSTRUCTIONS = "Diamond Hands MCP \u2014 Bitcoin-collateralized borrowing. Before promising ANY flow, read the boundary://info resource and honor its `capabilities` block: it states which network this server is on, whether money is real (practiceWorld), whether writes are enabled (and the true reason when they are not), and which signer modes this build actually offers \u2014 never describe a flow outside it. State the network and whether funds are real when the user first acts. Authorization is chosen by conversation via the signer_setup tool (when listed); writes always require confirmed:true after showing the human-readable card. For walkthroughs consult the guide tool / guide:// resources instead of inventing steps; when a tool refuses, relay its stated reason and remedy \u2014 do not improvise alternatives. When a network_switch tool is listed, the network can change mid-session \u2014 after ANY switch, re-read boundary://info and state the new network and money reality to the user before doing anything else.";
92234
92282
  function createServer2(deps) {
92235
92283
  const server = new import_mcp2.McpServer(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gvnrdao/dh-mcp",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "MCP server for the Diamond Hands protocol — Bitcoin-collateralized UCD lending with human-approved signing (sepolia practice by default; mainnet fully enabled)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {