@gvnrdao/dh-mcp 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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.4.0/dh-mcp-0.4.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.4.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.1/dh-mcp-0.5.1.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.1 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.4.0/`).
20
+ (`latest/` and `v<version>/` — e.g. `v0.5.1/`).
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).
@@ -56,7 +56,7 @@ paste-code) or a local encrypted keystore. Safe smart-account and delegation mod
56
56
 
57
57
  | Network | Reads (public) | Reads (authenticated) | Writes |
58
58
  |---|---|---|---|
59
- | **sepolia** (default — the real protocol, practice money) | always, no setup | after a login: keystore env pair, or "connect my wallet" (`signer_setup`) | signer modes **keystore** and **external** (your own wallet). External-mode BTC withdrawal is not shipped yet — it refuses with that true reason; keystore withdrawal works |
59
+ | **sepolia** (default — the real protocol, practice money) | always, no setup | after a login: keystore env pair, or "connect my wallet" (`signer_setup`) | signer modes **keystore** and **external** (your own wallet). External-mode BTC withdrawal signs the SDK's bare auth hashes **blind** — same as the web app; the approval page says so loudly |
60
60
  | **mainnet** (real money) | always (indexer gaps are reported honestly) | after a login (the broker throttles logins per address) | signer modes **keystore** and **external**, same as sepolia — every operation moves REAL funds behind your confirmation + signature; PSM writes refuse (sepolia-only) |
61
61
  | **mock** (`DH_ADAPTER=mock` — offline practice sandbox) | always | always | all modes, including the simulated Safe and delegation planes |
62
62
 
@@ -153,8 +153,9 @@ diagrams, data contracts, scenario catalog) live in the repository:
153
153
  (missing config, uncollateralized operations, source divergence, upstream outages).
154
154
  - Current stage: **real adapter (sepolia AND mainnet, reads and writes) + mock
155
155
  simulator**, all behind the same boundary contract and the same scenario suites.
156
- External-wallet signing runs on the real adapter; external-mode BTC withdrawal is the
157
- one remaining refusal (its true reason is stated; keystore withdrawal works).
156
+ External-wallet signing runs on the real adapter, including BTC withdrawal (blind
157
+ hash signatures, site-parity — the approval card states the contents are not
158
+ decodable; keystore withdrawal signs locally).
158
159
  - Reads are unrestricted, with indexer gaps reported honestly.
159
160
 
160
161
  ## Security model
package/dist/boundary.js CHANGED
@@ -87369,7 +87369,13 @@ var PERSONAL_SIGN_LAYOUTS = {
87369
87369
  hashUtf8Fields: ["action"]
87370
87370
  }
87371
87371
  };
87372
+ var RAW_HASH_LAYOUT = "dh-raw-hash-v1";
87372
87373
  function hashForLayout(layout, fields) {
87374
+ if (layout === RAW_HASH_LAYOUT) {
87375
+ const raw = fields["hash"];
87376
+ if (!/^0x[0-9a-fA-F]{64}$/.test(raw ?? "")) throw new Error(`page-crypto: layout "${layout}" needs a 32-byte 0x-hex "hash" field`);
87377
+ return raw.toLowerCase();
87378
+ }
87373
87379
  const def = PERSONAL_SIGN_LAYOUTS[layout];
87374
87380
  if (!def) throw new Error(`page-crypto: unknown layout "${layout}"`);
87375
87381
  const hashUtf8 = new Set(def.hashUtf8Fields);
@@ -87537,6 +87543,15 @@ var PAGE_CRYPTO_JS = `"use strict";
87537
87543
  var PERSONAL_SIGN_LAYOUTS = ${JSON.stringify(PERSONAL_SIGN_LAYOUTS)};
87538
87544
 
87539
87545
  function packAndHash(layout, fields) {
87546
+ // SITE-PARITY blind-sign layout: identity \u2014 the hash field IS the hash (see the
87547
+ // RAW_HASH_LAYOUT note in page-crypto.ts; both sides special-case identically).
87548
+ if (layout === "dh-raw-hash-v1") {
87549
+ var rawHash = fields ? fields.hash : undefined;
87550
+ if (!rawHash || !/^0x[0-9a-fA-F]{64}$/.test(rawHash)) {
87551
+ throw new Error("dhPageCrypto: layout \\"dh-raw-hash-v1\\" needs a 32-byte 0x-hex hash field");
87552
+ }
87553
+ return rawHash.toLowerCase();
87554
+ }
87540
87555
  var def = PERSONAL_SIGN_LAYOUTS[layout];
87541
87556
  if (!def) {
87542
87557
  throw new Error("dhPageCrypto: unknown layout \\"" + layout + "\\"");
@@ -87755,6 +87770,11 @@ function buildWriteOps(deps) {
87755
87770
  createPosition: async (p) => {
87756
87771
  const sdk = deps.getWriteSdk();
87757
87772
  if (!sdk) return upFail({ kind: "unavailable", source: SOURCE5, message: "write SDK is not initialized (its boot-time construction failed)" });
87773
+ try {
87774
+ await deps.assertValidatorConfigured();
87775
+ } catch (e) {
87776
+ return upFail({ kind: "rejected", source: SOURCE5, message: `createPosition preflight: ${e.message}` });
87777
+ }
87758
87778
  let result;
87759
87779
  try {
87760
87780
  result = await sdk.createLoan({ selectedTerm: p.selectedTerm });
@@ -88183,6 +88203,22 @@ async function verifyBroadcastTxByHash(provider, hash, approved, borrower, budge
88183
88203
 
88184
88204
  // src/signer/external-eoa.ts
88185
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
+ }
88186
88222
  var ExternalEoaDHSigner = class {
88187
88223
  constructor(deps) {
88188
88224
  this.deps = deps;
@@ -88234,6 +88270,7 @@ var ExternalEoaDHSigner = class {
88234
88270
  }
88235
88271
  async submitValidatedTx(outerTx, ctx) {
88236
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);
88237
88274
  const outcome = await this.deps.bridge.requestSignature({
88238
88275
  id: (0, import_node_crypto5.randomUUID)(),
88239
88276
  kind: "transaction",
@@ -88241,7 +88278,7 @@ var ExternalEoaDHSigner = class {
88241
88278
  card: ctx.card,
88242
88279
  expectedSigner: this.deps.borrower,
88243
88280
  chainId: this.deps.chainId,
88244
- tx: approved
88281
+ tx: { ...approved, ...gas ? { gas } : {}, txType: 2 }
88245
88282
  });
88246
88283
  if (outcome.status !== "approved") {
88247
88284
  throw new OperationDeclined(`the ${ctx.action} transaction was not approved: ${describeOutcome(outcome)}`);
@@ -88277,10 +88314,37 @@ var BridgeEthersSigner = class _BridgeEthersSigner extends import_ethers36.ether
88277
88314
  async getAddress() {
88278
88315
  return this.deps.borrower;
88279
88316
  }
88280
- async signMessage(_message) {
88281
- throw new Error(
88282
- "external-wallet mode cannot sign this operation yet: it needs a raw message signature whose fields are built inside the SDK (BTC withdrawal). That is the plan-10 Phase A-2 signing-context seam \u2014 use the keystore signer for this operation until it lands."
88283
- );
88317
+ async signMessage(message) {
88318
+ const bytes = typeof message === "string" ? import_ethers36.ethers.toUtf8Bytes(message) : message;
88319
+ if (bytes.length !== 32) {
88320
+ throw new Error(
88321
+ `external-wallet signMessage accepts only the SDK's bare 32-byte auth hashes (got ${bytes.length} bytes) \u2014 no other raw-message signing rides this path.`
88322
+ );
88323
+ }
88324
+ const hashHex = import_ethers36.ethers.hexlify(bytes).toLowerCase();
88325
+ const outcome = await this.deps.bridge.requestSignature({
88326
+ id: (0, import_node_crypto5.randomUUID)(),
88327
+ kind: "personal-sign",
88328
+ action: "btc-withdrawal authorization (blind hash)",
88329
+ card: [
88330
+ "BLIND SIGNATURE \u2014 BTC withdrawal authorization step",
88331
+ `hash: ${hashHex}`,
88332
+ "This hash is built inside the SDK and its contents CANNOT be decoded or verified by this page",
88333
+ "(identical to how diamondhands.credit signs withdrawals).",
88334
+ "Approve ONLY if you initiated this exact BTC withdrawal in the conversation."
88335
+ ],
88336
+ expectedSigner: this.deps.borrower,
88337
+ chainId: this.deps.chainId,
88338
+ personalSign: { layout: RAW_HASH_LAYOUT, fields: { hash: hashHex }, hashHex }
88339
+ });
88340
+ if (outcome.status !== "approved" || !outcome.signature) {
88341
+ throw new OperationDeclined(`the btc-withdrawal authorization was not signed: ${describeOutcome(outcome)}`);
88342
+ }
88343
+ const recovered = import_ethers36.ethers.verifyMessage(bytes, outcome.signature);
88344
+ if (recovered.toLowerCase() !== this.deps.borrower.toLowerCase()) {
88345
+ throw new Error(`the btc-withdrawal authorization was signed by ${recovered}, not the borrower ${this.deps.borrower}`);
88346
+ }
88347
+ return outcome.signature;
88284
88348
  }
88285
88349
  async signTypedData(domain, types, value) {
88286
88350
  const typedData = {
@@ -88314,6 +88378,7 @@ var BridgeEthersSigner = class _BridgeEthersSigner extends import_ethers36.ether
88314
88378
  chainId: tx2.chainId != null ? Number(tx2.chainId) : this.deps.chainId
88315
88379
  };
88316
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));
88317
88382
  const outcome = await this.deps.bridge.requestSignature({
88318
88383
  id: (0, import_node_crypto5.randomUUID)(),
88319
88384
  kind: "transaction",
@@ -88321,7 +88386,7 @@ var BridgeEthersSigner = class _BridgeEthersSigner extends import_ethers36.ether
88321
88386
  card,
88322
88387
  expectedSigner: this.deps.borrower,
88323
88388
  chainId: approved.chainId,
88324
- tx: { ...approved, ...tx2.gasLimit != null ? { gas: import_ethers36.ethers.toBeHex(BigInt(String(tx2.gasLimit))) } : {}, txType: 2 }
88389
+ tx: { ...approved, ...gas ? { gas } : {}, txType: 2 }
88325
88390
  });
88326
88391
  if (outcome.status !== "approved") {
88327
88392
  throw new OperationDeclined(`the transaction was not approved: ${describeOutcome(outcome)}`);
@@ -88668,9 +88733,33 @@ var RealUpstreamPlugin = class {
88668
88733
  session,
88669
88734
  getWriteSdk: () => this.sdkCache.get(key) ?? null,
88670
88735
  readDetails: (id) => this.readPositionDetails(id),
88671
- psm: () => this.psmCalls()
88736
+ psm: () => this.psmCalls(),
88737
+ assertValidatorConfigured: () => this.assertValidatorConfigured()
88672
88738
  });
88673
88739
  }
88740
+ /** Live preflight (field bug, 2026-08-05): the configured validator generation must be
88741
+ * registered on-chain — on mainnet only version 3 exists, and a wrong version makes
88742
+ * createPosition revert ValidatorNotConfigured, which the user's wallet can only show
88743
+ * as an illegible "likely to fail". One eth_call turns that into a legible refusal. */
88744
+ async assertValidatorConfigured() {
88745
+ const version2 = this.config.validatorVersion ?? 1;
88746
+ const pkpValidation = this.contracts["PKPValidation"];
88747
+ if (!pkpValidation) {
88748
+ throw new Error(`the SDK's ${this.config.network} deployment table has no PKPValidation address \u2014 cannot verify validator version ${version2}.`);
88749
+ }
88750
+ const registry = new import_ethers37.ethers.Contract(pkpValidation, ["function validatorForVersion(uint256) view returns (address)"], this.provider);
88751
+ let validator;
88752
+ try {
88753
+ validator = await registry.validatorForVersion(version2);
88754
+ } catch (e) {
88755
+ throw new Error(`could not verify validator version ${version2} on-chain (PKPValidation ${pkpValidation}): ${e.message}`);
88756
+ }
88757
+ if (validator === import_ethers37.ethers.ZeroAddress) {
88758
+ throw new Error(
88759
+ `validator version ${version2} is NOT registered on ${this.config.network} (PKPValidation ${pkpValidation} returns the zero address) \u2014 the transaction would revert ValidatorNotConfigured. Set DH_VALIDATOR_VERSION to the network's registered generation.`
88760
+ );
88761
+ }
88762
+ }
88674
88763
  sessionFor(key, signer) {
88675
88764
  let s = this.sessionCache.get(key);
88676
88765
  if (!s) {
@@ -88777,7 +88866,8 @@ var RealUpstreamPlugin = class {
88777
88866
  session,
88778
88867
  getWriteSdk: () => this.sdkCache.get(key) ?? null,
88779
88868
  readDetails: (id) => this.readPositionDetails(id),
88780
- psm: () => this.psmCalls()
88869
+ psm: () => this.psmCalls(),
88870
+ assertValidatorConfigured: () => this.assertValidatorConfigured()
88781
88871
  });
88782
88872
  this.opsGatewayCache.set(key, gateway);
88783
88873
  }
@@ -90018,7 +90108,11 @@ var NETWORK_DEFAULTS = {
90018
90108
  mainnet: {
90019
90109
  rpcUrl: "https://ethereum-rpc.publicnode.com",
90020
90110
  serviceEndpoint: "https://ops.gvnr.xyz",
90021
- litNetwork: "chipotle"
90111
+ litNetwork: "chipotle",
90112
+ // On-chain PKPValidation generation, mainnet (validatorForVersion(3) is the ONLY
90113
+ // registered validator — verified live 2026-08-05). Without this the SDK defaults
90114
+ // to 1 and createPosition reverts ValidatorNotConfigured in wallet simulation.
90115
+ validatorVersion: 3
90022
90116
  }
90023
90117
  };
90024
90118
  function resolveBoundaryConfig(env) {
package/dist/index.js CHANGED
@@ -52072,7 +52072,11 @@ var NETWORK_DEFAULTS = {
52072
52072
  mainnet: {
52073
52073
  rpcUrl: "https://ethereum-rpc.publicnode.com",
52074
52074
  serviceEndpoint: "https://ops.gvnr.xyz",
52075
- litNetwork: "chipotle"
52075
+ litNetwork: "chipotle",
52076
+ // On-chain PKPValidation generation, mainnet (validatorForVersion(3) is the ONLY
52077
+ // registered validator — verified live 2026-08-05). Without this the SDK defaults
52078
+ // to 1 and createPosition reverts ValidatorNotConfigured in wallet simulation.
52079
+ validatorVersion: 3
52076
52080
  }
52077
52081
  };
52078
52082
  function resolveBoundaryConfig(env) {
@@ -87567,7 +87571,13 @@ var PERSONAL_SIGN_LAYOUTS = {
87567
87571
  hashUtf8Fields: ["action"]
87568
87572
  }
87569
87573
  };
87574
+ var RAW_HASH_LAYOUT = "dh-raw-hash-v1";
87570
87575
  function hashForLayout(layout, fields) {
87576
+ if (layout === RAW_HASH_LAYOUT) {
87577
+ const raw = fields["hash"];
87578
+ if (!/^0x[0-9a-fA-F]{64}$/.test(raw ?? "")) throw new Error(`page-crypto: layout "${layout}" needs a 32-byte 0x-hex "hash" field`);
87579
+ return raw.toLowerCase();
87580
+ }
87571
87581
  const def = PERSONAL_SIGN_LAYOUTS[layout];
87572
87582
  if (!def) throw new Error(`page-crypto: unknown layout "${layout}"`);
87573
87583
  const hashUtf8 = new Set(def.hashUtf8Fields);
@@ -87735,6 +87745,15 @@ var PAGE_CRYPTO_JS = `"use strict";
87735
87745
  var PERSONAL_SIGN_LAYOUTS = ${JSON.stringify(PERSONAL_SIGN_LAYOUTS)};
87736
87746
 
87737
87747
  function packAndHash(layout, fields) {
87748
+ // SITE-PARITY blind-sign layout: identity \u2014 the hash field IS the hash (see the
87749
+ // RAW_HASH_LAYOUT note in page-crypto.ts; both sides special-case identically).
87750
+ if (layout === "dh-raw-hash-v1") {
87751
+ var rawHash = fields ? fields.hash : undefined;
87752
+ if (!rawHash || !/^0x[0-9a-fA-F]{64}$/.test(rawHash)) {
87753
+ throw new Error("dhPageCrypto: layout \\"dh-raw-hash-v1\\" needs a 32-byte 0x-hex hash field");
87754
+ }
87755
+ return rawHash.toLowerCase();
87756
+ }
87738
87757
  var def = PERSONAL_SIGN_LAYOUTS[layout];
87739
87758
  if (!def) {
87740
87759
  throw new Error("dhPageCrypto: unknown layout \\"" + layout + "\\"");
@@ -87953,6 +87972,11 @@ function buildWriteOps(deps) {
87953
87972
  createPosition: async (p) => {
87954
87973
  const sdk = deps.getWriteSdk();
87955
87974
  if (!sdk) return upFail({ kind: "unavailable", source: SOURCE5, message: "write SDK is not initialized (its boot-time construction failed)" });
87975
+ try {
87976
+ await deps.assertValidatorConfigured();
87977
+ } catch (e) {
87978
+ return upFail({ kind: "rejected", source: SOURCE5, message: `createPosition preflight: ${e.message}` });
87979
+ }
87956
87980
  let result;
87957
87981
  try {
87958
87982
  result = await sdk.createLoan({ selectedTerm: p.selectedTerm });
@@ -88381,6 +88405,22 @@ async function verifyBroadcastTxByHash(provider, hash, approved, borrower, budge
88381
88405
 
88382
88406
  // src/signer/external-eoa.ts
88383
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
+ }
88384
88424
  var ExternalEoaDHSigner = class {
88385
88425
  constructor(deps) {
88386
88426
  this.deps = deps;
@@ -88432,6 +88472,7 @@ var ExternalEoaDHSigner = class {
88432
88472
  }
88433
88473
  async submitValidatedTx(outerTx, ctx) {
88434
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);
88435
88476
  const outcome = await this.deps.bridge.requestSignature({
88436
88477
  id: (0, import_node_crypto5.randomUUID)(),
88437
88478
  kind: "transaction",
@@ -88439,7 +88480,7 @@ var ExternalEoaDHSigner = class {
88439
88480
  card: ctx.card,
88440
88481
  expectedSigner: this.deps.borrower,
88441
88482
  chainId: this.deps.chainId,
88442
- tx: approved
88483
+ tx: { ...approved, ...gas ? { gas } : {}, txType: 2 }
88443
88484
  });
88444
88485
  if (outcome.status !== "approved") {
88445
88486
  throw new OperationDeclined(`the ${ctx.action} transaction was not approved: ${describeOutcome(outcome)}`);
@@ -88475,10 +88516,37 @@ var BridgeEthersSigner = class _BridgeEthersSigner extends import_ethers36.ether
88475
88516
  async getAddress() {
88476
88517
  return this.deps.borrower;
88477
88518
  }
88478
- async signMessage(_message) {
88479
- throw new Error(
88480
- "external-wallet mode cannot sign this operation yet: it needs a raw message signature whose fields are built inside the SDK (BTC withdrawal). That is the plan-10 Phase A-2 signing-context seam \u2014 use the keystore signer for this operation until it lands."
88481
- );
88519
+ async signMessage(message) {
88520
+ const bytes = typeof message === "string" ? import_ethers36.ethers.toUtf8Bytes(message) : message;
88521
+ if (bytes.length !== 32) {
88522
+ throw new Error(
88523
+ `external-wallet signMessage accepts only the SDK's bare 32-byte auth hashes (got ${bytes.length} bytes) \u2014 no other raw-message signing rides this path.`
88524
+ );
88525
+ }
88526
+ const hashHex = import_ethers36.ethers.hexlify(bytes).toLowerCase();
88527
+ const outcome = await this.deps.bridge.requestSignature({
88528
+ id: (0, import_node_crypto5.randomUUID)(),
88529
+ kind: "personal-sign",
88530
+ action: "btc-withdrawal authorization (blind hash)",
88531
+ card: [
88532
+ "BLIND SIGNATURE \u2014 BTC withdrawal authorization step",
88533
+ `hash: ${hashHex}`,
88534
+ "This hash is built inside the SDK and its contents CANNOT be decoded or verified by this page",
88535
+ "(identical to how diamondhands.credit signs withdrawals).",
88536
+ "Approve ONLY if you initiated this exact BTC withdrawal in the conversation."
88537
+ ],
88538
+ expectedSigner: this.deps.borrower,
88539
+ chainId: this.deps.chainId,
88540
+ personalSign: { layout: RAW_HASH_LAYOUT, fields: { hash: hashHex }, hashHex }
88541
+ });
88542
+ if (outcome.status !== "approved" || !outcome.signature) {
88543
+ throw new OperationDeclined(`the btc-withdrawal authorization was not signed: ${describeOutcome(outcome)}`);
88544
+ }
88545
+ const recovered = import_ethers36.ethers.verifyMessage(bytes, outcome.signature);
88546
+ if (recovered.toLowerCase() !== this.deps.borrower.toLowerCase()) {
88547
+ throw new Error(`the btc-withdrawal authorization was signed by ${recovered}, not the borrower ${this.deps.borrower}`);
88548
+ }
88549
+ return outcome.signature;
88482
88550
  }
88483
88551
  async signTypedData(domain, types, value) {
88484
88552
  const typedData = {
@@ -88512,6 +88580,7 @@ var BridgeEthersSigner = class _BridgeEthersSigner extends import_ethers36.ether
88512
88580
  chainId: tx2.chainId != null ? Number(tx2.chainId) : this.deps.chainId
88513
88581
  };
88514
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));
88515
88584
  const outcome = await this.deps.bridge.requestSignature({
88516
88585
  id: (0, import_node_crypto5.randomUUID)(),
88517
88586
  kind: "transaction",
@@ -88519,7 +88588,7 @@ var BridgeEthersSigner = class _BridgeEthersSigner extends import_ethers36.ether
88519
88588
  card,
88520
88589
  expectedSigner: this.deps.borrower,
88521
88590
  chainId: approved.chainId,
88522
- tx: { ...approved, ...tx2.gasLimit != null ? { gas: import_ethers36.ethers.toBeHex(BigInt(String(tx2.gasLimit))) } : {}, txType: 2 }
88591
+ tx: { ...approved, ...gas ? { gas } : {}, txType: 2 }
88523
88592
  });
88524
88593
  if (outcome.status !== "approved") {
88525
88594
  throw new OperationDeclined(`the transaction was not approved: ${describeOutcome(outcome)}`);
@@ -88866,9 +88935,33 @@ var RealUpstreamPlugin = class {
88866
88935
  session,
88867
88936
  getWriteSdk: () => this.sdkCache.get(key) ?? null,
88868
88937
  readDetails: (id) => this.readPositionDetails(id),
88869
- psm: () => this.psmCalls()
88938
+ psm: () => this.psmCalls(),
88939
+ assertValidatorConfigured: () => this.assertValidatorConfigured()
88870
88940
  });
88871
88941
  }
88942
+ /** Live preflight (field bug, 2026-08-05): the configured validator generation must be
88943
+ * registered on-chain — on mainnet only version 3 exists, and a wrong version makes
88944
+ * createPosition revert ValidatorNotConfigured, which the user's wallet can only show
88945
+ * as an illegible "likely to fail". One eth_call turns that into a legible refusal. */
88946
+ async assertValidatorConfigured() {
88947
+ const version2 = this.config.validatorVersion ?? 1;
88948
+ const pkpValidation = this.contracts["PKPValidation"];
88949
+ if (!pkpValidation) {
88950
+ throw new Error(`the SDK's ${this.config.network} deployment table has no PKPValidation address \u2014 cannot verify validator version ${version2}.`);
88951
+ }
88952
+ const registry = new import_ethers37.ethers.Contract(pkpValidation, ["function validatorForVersion(uint256) view returns (address)"], this.provider);
88953
+ let validator;
88954
+ try {
88955
+ validator = await registry.validatorForVersion(version2);
88956
+ } catch (e) {
88957
+ throw new Error(`could not verify validator version ${version2} on-chain (PKPValidation ${pkpValidation}): ${e.message}`);
88958
+ }
88959
+ if (validator === import_ethers37.ethers.ZeroAddress) {
88960
+ throw new Error(
88961
+ `validator version ${version2} is NOT registered on ${this.config.network} (PKPValidation ${pkpValidation} returns the zero address) \u2014 the transaction would revert ValidatorNotConfigured. Set DH_VALIDATOR_VERSION to the network's registered generation.`
88962
+ );
88963
+ }
88964
+ }
88872
88965
  sessionFor(key, signer) {
88873
88966
  let s = this.sessionCache.get(key);
88874
88967
  if (!s) {
@@ -88975,7 +89068,8 @@ var RealUpstreamPlugin = class {
88975
89068
  session,
88976
89069
  getWriteSdk: () => this.sdkCache.get(key) ?? null,
88977
89070
  readDetails: (id) => this.readPositionDetails(id),
88978
- psm: () => this.psmCalls()
89071
+ psm: () => this.psmCalls(),
89072
+ assertValidatorConfigured: () => this.assertValidatorConfigured()
88979
89073
  });
88980
89074
  this.opsGatewayCache.set(key, gateway);
88981
89075
  }
@@ -91539,14 +91633,16 @@ the mock.
91539
91633
  authenticated call refuses with the same remedy \u2014 an explicit reconnect, never a
91540
91634
  surprise popup. On mainnet the broker also throttles logins per address \u2014 a throttled
91541
91635
  login means "wait and retry", not a wallet failure.
91542
- - **Withdraw-BTC under external mode is not shipped yet** (the SDK signing-context seam
91543
- is pending) \u2014 it refuses with that true reason; keystore-mode withdraw works.
91636
+ - **Withdraw-BTC under external mode is a BLIND signature** \u2014 the SDK builds the two
91637
+ withdrawal auth hashes internally, so the approval page shows the bare hash and says
91638
+ plainly it cannot decode the contents (the production web app signs the same way).
91639
+ Tell the user this before the popups: two hash signatures, then the BTC moves.
91544
91640
  - **The allowlist delay is read LIVE from the chain.** A new BTC withdrawal destination
91545
91641
  (\`loan_allowlist_destination\`) becomes usable only after the chain's own delay \u2014 24
91546
91642
  hours on mainnet, so allowlisting and withdrawing happen on DIFFERENT DAYS there. The
91547
91643
  card states the live figure.
91548
- - **Mainnet:** writes are disabled unless the operator explicitly arms them, and the
91549
- minimum mint is 10 UCD.`,
91644
+ - **Mainnet:** every fund-moving operation spends REAL money, and the minimum mint is
91645
+ 10 UCD.`,
91550
91646
  lifecycle: `# The full lifecycle \u2014 exact calls
91551
91647
 
91552
91648
  1. **Create** \u2014 \`loan_create {selectedTerm, confirmed:true}\` \u2192 position id, vault address.
@@ -91802,8 +91898,9 @@ reality in your next message. The user must never have to ask which world they a
91802
91898
  - **"Wrong network" / wants mainnet or sepolia** \u2014 real adapter: \`network_switch\`
91803
91899
  (human-confirmed card; nothing carries across networks). Mock: the world is pinned by
91804
91900
  config \u2014 no switch exists there.
91805
- - **External-mode withdraw refused** \u2014 withdraw-BTC under external mode is not shipped
91806
- yet (the SDK signing-context seam is pending); keystore-mode withdraw works.
91901
+ - **External-mode withdraw shows a bare hash** \u2014 that is by design (site parity): the
91902
+ SDK builds the withdrawal auth hashes internally, so the page cannot decode them.
91903
+ Two blind hash signatures per withdrawal; warn the user before triggering them.
91807
91904
  - **Login throttled (mainnet)** \u2014 the broker limits logins per address; wait and retry.
91808
91905
  That is the broker throttle, not a wallet failure.
91809
91906
  - **VALIDATION_FAILED** \u2014 the input itself is off (bad address format, too many decimals,
@@ -92150,7 +92247,7 @@ function registerBoundaryInfoResource(server, getB) {
92150
92247
  }
92151
92248
 
92152
92249
  // src/server.ts
92153
- var SERVER_VERSION = "0.4.0";
92250
+ var SERVER_VERSION = "0.5.1";
92154
92251
  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.";
92155
92252
  function createServer2(deps) {
92156
92253
  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.4.0",
3
+ "version": "0.5.1",
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": {