@gvnrdao/dh-mcp 0.5.9 → 0.5.11

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
@@ -21,9 +21,11 @@ Downloads landing page (which file is for which system, checksums, security note
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 (paste-a-URL, wallet-only: OAuth 2.1 + Sign-In-
24
- with-Ethereum, external-wallet signing, no keystore mode in that build) is IMPLEMENTED
25
- but **not yet publicly served** — it goes live only after its security audit and rollout
26
- gates, and will appear here with its URL when it does.
24
+ with-Ethereum, external-wallet signing, no keystore mode in that build) is IMPLEMENTED;
25
+ whether it is publicly served, and on which networks, is the operator's rollout decision
26
+ (security audit first) and is stated by the running deployment itself — its `guide
27
+ connector` topic and `boundary://info` capabilities. This file cannot know: if you have
28
+ not been given a URL, use the install paths above.
27
29
 
28
30
  Unsigned-binary honesty: the macOS and Windows binaries are **not yet code-signed** —
29
31
  macOS Gatekeeper may quarantine the download (right-click → Open, or
@@ -24,6 +24,29 @@ export interface EmbeddedConnectorOptions {
24
24
  allowedNetworks?: readonly ("sepolia" | "mainnet")[];
25
25
  /** Idle windows (ms): `sessionMs` MCP-session expiry, `worldMs` tenant-world eviction. */
26
26
  idle?: { sessionMs?: number; worldMs?: number };
27
+ /** Maximum tenant worlds held at once (default 200). A world is a full boundary per
28
+ * distinct wallet, so this is the memory ceiling of the whole service. Reaching it
29
+ * first RECLAIMS the least-recently-active world that has no session, no attached
30
+ * approval page and no pending signature; only when no slot is reclaimable does it
31
+ * refuse the newcomer with a 503. A tenant who is using the service is never evicted
32
+ * to admit a stranger. */
33
+ maxTenants?: number;
34
+ /** Maximum MCP sessions held for ONE tenant (default 16). Each holds an McpServer and
35
+ * a transport and outlives its client by the session idle window; reaching the cap
36
+ * closes that tenant's least-recently-seen session (its client re-initializes on the
37
+ * 404) rather than refusing. Keyed by tenant, so it can only ever cost the identity
38
+ * that asked for the new session. */
39
+ maxSessionsPerTenant?: number;
40
+ /** Maximum bytes in a single /mcp request body (default 1 MiB), enforced on every
41
+ * POST — the initialize and the established-session legs alike, since the MCP SDK
42
+ * applies no limit of its own. Over the cap is a 413 naming the limit, with the
43
+ * connection closed rather than the upload drained. */
44
+ maxBodyBytes?: number;
45
+ /** Proxy hops in front of the HOST's listener (default 1). Decides what `req.ip`
46
+ * resolves to and therefore what every per-IP rate limit keys on: set 0 when nothing
47
+ * fronts the process, because trusting an absent hop lets a caller forge
48
+ * X-Forwarded-For and mint unlimited limiter keys. Never `true`. */
49
+ trustProxyHops?: number;
27
50
  /** Request caps with truthful 429s: per-tenant on /mcp, global on the whole surface. */
28
51
  rateLimits?: { tenantPerMin?: number; globalPerMin?: number };
29
52
  }
package/dist/boundary.js CHANGED
@@ -498,7 +498,7 @@ var require_utils = __commonJS({
498
498
  exports2.createHasher = createHasher2;
499
499
  exports2.createOptHasher = createOptHasher;
500
500
  exports2.createXOFer = createXOFer;
501
- exports2.randomBytes = randomBytes3;
501
+ exports2.randomBytes = randomBytes4;
502
502
  var crypto_1 = require_cryptoNode();
503
503
  function isBytes2(a) {
504
504
  return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
@@ -696,7 +696,7 @@ var require_utils = __commonJS({
696
696
  exports2.wrapConstructor = createHasher2;
697
697
  exports2.wrapConstructorWithOpts = createOptHasher;
698
698
  exports2.wrapXOFConstructorWithOpts = createXOFer;
699
- function randomBytes3(bytesLength = 32) {
699
+ function randomBytes4(bytesLength = 32) {
700
700
  if (crypto_1.crypto && typeof crypto_1.crypto.getRandomValues === "function") {
701
701
  return crypto_1.crypto.getRandomValues(new Uint8Array(bytesLength));
702
702
  }
@@ -40622,7 +40622,7 @@ __export(boundary_exports, {
40622
40622
  resolveBoundaryConfig: () => resolveBoundaryConfig
40623
40623
  });
40624
40624
  module.exports = __toCommonJS(boundary_exports);
40625
- var import_node_crypto7 = require("crypto");
40625
+ var import_node_crypto8 = require("crypto");
40626
40626
  var fs5 = __toESM(require("fs"));
40627
40627
  var os2 = __toESM(require("os"));
40628
40628
  var path4 = __toESM(require("path"));
@@ -42135,11 +42135,10 @@ var World = class {
42135
42135
  const spend = BigInt(p.amountSats);
42136
42136
  const fee = BigInt(p.networkFeeSats);
42137
42137
  const available = this.availableSats(p.positionId);
42138
- if (spend + fee > available) {
42139
- const maxSpend = available > fee ? available - fee : 0n;
42138
+ if (spend > available) {
42140
42139
  return {
42141
42140
  ok: false,
42142
- reason: `withdrawal of ${spend.toString()} sats leaves no room for the ${fee.toString()}-sat network fee (TargetMustLeaveFeeRoom) \u2014 max amountSats now is ${maxSpend.toString()} (destination then receives ${(maxSpend > fee ? maxSpend - fee : 0n).toString()} after the fee)`
42141
+ reason: `withdrawal of ${spend.toString()} sats exceeds the ${available.toString()} sats available (TargetExceedsInputValue) \u2014 max amountSats now is ${available.toString()} (destination then receives ${(available > fee ? available - fee : 0n).toString()} after the fee)`
42143
42142
  };
42144
42143
  }
42145
42144
  const debt = BigInt(pos.debtUcdWei);
@@ -51311,9 +51310,9 @@ var init_deployment_addresses = __esm2({
51311
51310
  reason: "Shared upgrade script: LiquidationManagerModule implementation update"
51312
51311
  },
51313
51312
  BTCSpendAuthorizer: {
51314
- previousImplementation: "0x8775a520cAA18c03Cc3f51ee254cAB830960f80E",
51315
- newImplementation: "0xdd3DFaEc50d6214d57eA64e8b76ff318b501607b",
51316
- upgradedAt: "2026-07-03T20:09:36.466Z",
51313
+ previousImplementation: "0xdd3DFaEc50d6214d57eA64e8b76ff318b501607b",
51314
+ newImplementation: "0xf3282B5A1AE6428ee1b08cfaAF4EB4e198877484",
51315
+ upgradedAt: "2026-09-06T15:03:13.627Z",
51317
51316
  upgradedBy: "0xF20986F02420EF443AE9BE5092FB8A4975cF3aA6",
51318
51317
  reason: "Shared upgrade script: BTCSpendAuthorizer implementation update"
51319
51318
  },
@@ -51379,6 +51378,13 @@ var init_deployment_addresses = __esm2({
51379
51378
  upgradedAt: "2026-07-07T16:56:49.844Z",
51380
51379
  upgradedBy: "0xF20986F02420EF443AE9BE5092FB8A4975cF3aA6",
51381
51380
  reason: "Shared upgrade script: BitcoinWithdrawalAddressRegistry implementation update"
51381
+ },
51382
+ AgentDelegationRegistry: {
51383
+ previousImplementation: "0xE931E4b9ceF2A48Ac7D57192da4B523756cFC310",
51384
+ newImplementation: "0xE931E4b9ceF2A48Ac7D57192da4B523756cFC310",
51385
+ upgradedAt: "2026-09-06T15:06:02.814Z",
51386
+ upgradedBy: "0xF20986F02420EF443AE9BE5092FB8A4975cF3aA6",
51387
+ reason: "Reconciled implementation from chain"
51382
51388
  }
51383
51389
  },
51384
51390
  history: {
@@ -51464,7 +51470,7 @@ var init_deployment_addresses = __esm2({
51464
51470
  LIQUIDATION_MANAGER_MODULE: "0xC4AB00f39e7ceD812F5C67058C9fa44e15d40e76",
51465
51471
  LIQUIDATION_MANAGER_MODULE_IMPL: "0xCe7587C47094BBb3dCa13D7a2299Ec9beA6cd759",
51466
51472
  BTC_SPEND_AUTHORIZER: "0xd7E9Eb5eE53f1d9ee55Dc162bBC7486bE437B6bD",
51467
- BTC_SPEND_AUTHORIZER_IMPL: "0xdd3DFaEc50d6214d57eA64e8b76ff318b501607b",
51473
+ BTC_SPEND_AUTHORIZER_IMPL: "0xf3282B5A1AE6428ee1b08cfaAF4EB4e198877484",
51468
51474
  UPGRADE_VALIDATOR: "0x592e650edD9bA26ecc407989fdd6F9cdcDeC27A6",
51469
51475
  UPGRADE_VALIDATOR_IMPL: "0x9E70e1D07AB11ac9dD37B67AA091Efe97d7Ed84b",
51470
51476
  BITCOIN_PROVIDER_REGISTRY: "0xbfA0c48B070D0a9A9CD27469AeacFD2d4261cEE2",
@@ -58582,12 +58588,12 @@ async function reconcileAuthorizedSpend(spend, esploraBaseUrl, httpGetJson = def
58582
58588
  { txid: spend.txid, vout: spend.vout }
58583
58589
  );
58584
58590
  }
58585
- if (spend.targetAmount >= spend.satoshis) {
58591
+ if (spend.targetAmount > spend.satoshis) {
58586
58592
  return {
58587
58593
  spend,
58588
58594
  status: "CORRUPT",
58589
58595
  onChainOutputValue,
58590
- reason: `Authorized targetAmount ${spend.targetAmount} sats is not below the ${spend.satoshis}-sat aggregate input value \u2014 the contract could never have authorized this`
58596
+ reason: `Authorized targetAmount ${spend.targetAmount} sats exceeds the ${spend.satoshis}-sat aggregate input value \u2014 the contract could never have authorized this`
58591
58597
  };
58592
58598
  }
58593
58599
  const outspendRes = await httpGetJson(
@@ -79532,13 +79538,20 @@ var BridgeEthersSigner = class _BridgeEthersSigner extends import_ethers37.ether
79532
79538
  const outcome = await this.deps.bridge.requestSignature({
79533
79539
  id: (0, import_node_crypto5.randomUUID)(),
79534
79540
  kind: "personal-sign",
79535
- action: "btc-withdrawal authorization (blind hash)",
79541
+ action: "btc-withdrawal EXECUTE step (blind hash)",
79536
79542
  card: [
79537
- "BLIND SIGNATURE \u2014 BTC withdrawal authorization step",
79543
+ "BLIND SIGNATURE \u2014 BTC withdrawal, EXECUTE step",
79538
79544
  `hash: ${hashHex}`,
79539
79545
  "This hash is built inside the SDK and its contents CANNOT be decoded or verified by this page",
79540
79546
  "(identical to how diamondhands.credit signs withdrawals).",
79541
- "Approve ONLY if you initiated this exact BTC withdrawal in the conversation."
79547
+ "Approve ONLY if you initiated this exact BTC withdrawal in the conversation.",
79548
+ "",
79549
+ "SIGN NOW \u2014 this one is on a clock. The payload was stamped before this card was",
79550
+ `raised and is only valid inside a single ${QUANTUM_WINDOW_SECONDS}-second window, so the time left is`,
79551
+ "under a minute and often nearer twenty seconds \u2014 far less than the approval page",
79552
+ "itself allows. If it expires the signature is refused, the withdrawal does not",
79553
+ "complete, and the reserved coins stay reserved until that is cleared. Decline and",
79554
+ "start again rather than signing something you have not finished reading."
79542
79555
  ],
79543
79556
  expectedSigner: this.deps.borrower,
79544
79557
  chainId: this.deps.chainId,
@@ -80471,10 +80484,10 @@ var RealUpstreamPlugin = class {
80471
80484
  // src/boundary/upstream/shared/external-bridge/bridge.ts
80472
80485
  var fs4 = __toESM(require("fs"));
80473
80486
  var http3 = __toESM(require("http"));
80474
- var import_node_crypto6 = require("crypto");
80487
+ var import_node_crypto7 = require("crypto");
80475
80488
 
80476
80489
  // src/boundary/upstream/shared/external-bridge/approval-page.ts
80477
- function renderApprovalPage(sessionId) {
80490
+ function renderApprovalPage(sessionId, nonce) {
80478
80491
  return `<!doctype html>
80479
80492
  <html lang="en">
80480
80493
  <head>
@@ -80524,15 +80537,17 @@ function renderApprovalPage(sessionId) {
80524
80537
  </div>
80525
80538
  </div>
80526
80539
  </main>
80527
- <script>
80540
+ <script nonce="${nonce}">
80528
80541
  ${PAGE_CRYPTO_JS}
80529
80542
  </script>
80530
- <script>
80543
+ <script nonce="${nonce}">
80531
80544
  "use strict";
80532
80545
  const SESSION = ${JSON.stringify(sessionId)};
80533
80546
  // One-time token leaves the address bar (and history) immediately.
80534
80547
  // Plan 12 C1: endpoints resolve relative to the page DIRECTORY, so the same page works
80535
80548
  // at loopback root ("/") and under a hosted tenant mount ("/approval/<id>/").
80549
+ // EVERY endpoint reference goes through BASE \u2014 an origin-absolute "/x" resolves to the
80550
+ // ORIGIN root, which on a mount is the host, not the bridge, and 404s silently.
80536
80551
  const BASE = location.pathname.replace(/[^/]*$/, "");
80537
80552
  history.replaceState(null, "", location.pathname);
80538
80553
 
@@ -80604,14 +80619,14 @@ async function connect() {
80604
80619
  // wallet's own state transition and can report the stale value.
80605
80620
  async function onAccountsChanged(accounts) {
80606
80621
  account = (accounts && accounts[0]) || null;
80607
- await post("/wallet-event", { account: account, chainId: chainId });
80622
+ await post(BASE + "wallet-event", { account: account, chainId: chainId });
80608
80623
  showWallet();
80609
80624
  clearRequest("Wallet changed \u2014 pending request invalidated.");
80610
80625
  }
80611
80626
 
80612
80627
  async function onChainChanged(cid) {
80613
80628
  chainId = typeof cid === "string" ? parseInt(cid, 16) : Number(cid);
80614
- await post("/wallet-event", { account: account, chainId: chainId });
80629
+ await post(BASE + "wallet-event", { account: account, chainId: chainId });
80615
80630
  showWallet();
80616
80631
  clearRequest("Network changed \u2014 pending request invalidated.");
80617
80632
  }
@@ -80719,7 +80734,7 @@ connect();
80719
80734
  </body>
80720
80735
  </html>`;
80721
80736
  }
80722
- function renderUnlockPage(sessionId) {
80737
+ function renderUnlockPage(sessionId, nonce) {
80723
80738
  return `<!doctype html>
80724
80739
  <html lang="en">
80725
80740
  <head>
@@ -80761,7 +80776,7 @@ function renderUnlockPage(sessionId) {
80761
80776
  <div id="status" class="status"></div>
80762
80777
  </div>
80763
80778
  </main>
80764
- <script>
80779
+ <script nonce="${nonce}">
80765
80780
  "use strict";
80766
80781
  const SESSION = ${JSON.stringify(sessionId)};
80767
80782
  // Plan 12 C1: endpoints resolve relative to the page DIRECTORY, so the same page works
@@ -80792,6 +80807,21 @@ document.getElementById("generate").onclick = () => submit(true);
80792
80807
  </html>`;
80793
80808
  }
80794
80809
 
80810
+ // src/util/page-headers.ts
80811
+ var import_node_crypto6 = require("crypto");
80812
+ function htmlPageSecurityHeaders() {
80813
+ const nonce = (0, import_node_crypto6.randomBytes)(16).toString("base64");
80814
+ return {
80815
+ nonce,
80816
+ headers: {
80817
+ "Content-Security-Policy": `default-src 'none'; script-src 'nonce-${nonce}'; style-src 'unsafe-inline'; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'`,
80818
+ "X-Frame-Options": "DENY",
80819
+ "Referrer-Policy": "no-referrer",
80820
+ "X-Content-Type-Options": "nosniff"
80821
+ }
80822
+ };
80823
+ }
80824
+
80795
80825
  // src/boundary/upstream/shared/external-bridge/bridge.ts
80796
80826
  var MAX_SESSIONS = 16;
80797
80827
  var DEFAULT_EXPIRY_MS = 5 * 60 * 1e3;
@@ -80819,7 +80849,7 @@ var SignatureBridge = class {
80819
80849
  /** Started state independent of the transport binding (mounted bridges own no server). */
80820
80850
  started = false;
80821
80851
  mount;
80822
- token = (0, import_node_crypto6.randomBytes)(24).toString("hex");
80852
+ token = (0, import_node_crypto7.randomBytes)(24).toString("hex");
80823
80853
  /** Hosted mounts: when the current page token was minted (rotation basis). */
80824
80854
  tokenMintedAt = 0;
80825
80855
  /** Ceremony-scoped link (plan 06 §1.5): the SAME URL is multi-visit and multi-owner —
@@ -80856,7 +80886,7 @@ var SignatureBridge = class {
80856
80886
  unlockUrl() {
80857
80887
  if (!this.started) throw new Error("bridge is not started");
80858
80888
  if (!this.keystoreUnlock) throw new Error("keystore unlock is not wired on this bridge");
80859
- this.unlockToken = (0, import_node_crypto6.randomBytes)(24).toString("hex");
80889
+ this.unlockToken = (0, import_node_crypto7.randomBytes)(24).toString("hex");
80860
80890
  return this.mount ? `${this.mount.baseUrl}/unlock?t=${this.unlockToken}` : `http://127.0.0.1:${this.port}/unlock?t=${this.unlockToken}`;
80861
80891
  }
80862
80892
  /** Idempotent — the bridge spawns on the first write that needs it (plan 04 §2).
@@ -80897,7 +80927,7 @@ var SignatureBridge = class {
80897
80927
  if (this.mount) {
80898
80928
  const now = this.clock();
80899
80929
  if (this.tokenMintedAt === 0 || now - this.tokenMintedAt > HOSTED_PAGE_TOKEN_TTL_MS) {
80900
- this.token = (0, import_node_crypto6.randomBytes)(24).toString("hex");
80930
+ this.token = (0, import_node_crypto7.randomBytes)(24).toString("hex");
80901
80931
  this.tokenMintedAt = now;
80902
80932
  }
80903
80933
  return `${this.mount.baseUrl}/?t=${this.token}`;
@@ -81113,7 +81143,7 @@ var SignatureBridge = class {
81113
81143
  this.server = null;
81114
81144
  this.started = false;
81115
81145
  this.wallet = null;
81116
- this.token = (0, import_node_crypto6.randomBytes)(24).toString("hex");
81146
+ this.token = (0, import_node_crypto7.randomBytes)(24).toString("hex");
81117
81147
  this.tokenMintedAt = 0;
81118
81148
  if (this.urlFile) fs4.rmSync(this.urlFile, { force: true });
81119
81149
  void this.wcTransport?.close().catch(() => void 0);
@@ -81183,10 +81213,11 @@ var SignatureBridge = class {
81183
81213
  this.deny(res, 429, `too many open approval pages (${MAX_SESSIONS}) \u2014 close one and retry`);
81184
81214
  return;
81185
81215
  }
81186
- const sessionId = (0, import_node_crypto6.randomBytes)(24).toString("hex");
81216
+ const sessionId = (0, import_node_crypto7.randomBytes)(24).toString("hex");
81187
81217
  this.sessions.set(sessionId, { wallet: null, sse: null });
81188
- res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store" });
81189
- res.end(renderApprovalPage(sessionId));
81218
+ const page = htmlPageSecurityHeaders();
81219
+ res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store", ...page.headers });
81220
+ res.end(renderApprovalPage(sessionId, page.nonce));
81190
81221
  }
81191
81222
  /** Target-network hints for the page's chain self-heal (session-gated). */
81192
81223
  serveConfig(url2, res) {
@@ -81246,9 +81277,10 @@ var SignatureBridge = class {
81246
81277
  return;
81247
81278
  }
81248
81279
  this.unlockToken = null;
81249
- this.unlockSession = (0, import_node_crypto6.randomBytes)(24).toString("hex");
81250
- res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store" });
81251
- res.end(renderUnlockPage(this.unlockSession));
81280
+ this.unlockSession = (0, import_node_crypto7.randomBytes)(24).toString("hex");
81281
+ const page = htmlPageSecurityHeaders();
81282
+ res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store", ...page.headers });
81283
+ res.end(renderUnlockPage(this.unlockSession, page.nonce));
81252
81284
  }
81253
81285
  async onUnlockSubmit(body, res) {
81254
81286
  if (!this.keystoreUnlock) {
@@ -81695,7 +81727,7 @@ function createBoundary(config, opts) {
81695
81727
  "createBoundary(real) is async \u2014 use createRealBoundary() so the write SDK can be built."
81696
81728
  );
81697
81729
  }
81698
- const configFingerprint = (0, import_node_crypto7.createHash)("sha256").update(JSON.stringify({ adapter: config.adapter, latency: config.latency, db: config.mockDb, signer: config.signer ?? "auto" })).digest("hex").slice(0, 12);
81730
+ const configFingerprint = (0, import_node_crypto8.createHash)("sha256").update(JSON.stringify({ adapter: config.adapter, latency: config.latency, db: config.mockDb, signer: config.signer ?? "auto" })).digest("hex").slice(0, 12);
81699
81731
  if (opts?.ceremony) {
81700
81732
  const plugin2 = new MockUpstreamPlugin(config, { ceremony: opts.ceremony });
81701
81733
  const boundary2 = new BoundaryCore({
@@ -81864,7 +81896,7 @@ async function createRealBoundary(config, wallet, overrides) {
81864
81896
  }
81865
81897
  const plugin = new RealUpstreamPlugin(config, wallet, { manager, bridge, keystore });
81866
81898
  await plugin.initWriteSdk();
81867
- const configFingerprint = (0, import_node_crypto7.createHash)("sha256").update(JSON.stringify({ adapter: config.adapter, network: config.network, ops: config.serviceEndpoint })).digest("hex").slice(0, 12);
81899
+ const configFingerprint = (0, import_node_crypto8.createHash)("sha256").update(JSON.stringify({ adapter: config.adapter, network: config.network, ops: config.serviceEndpoint })).digest("hex").slice(0, 12);
81868
81900
  const capabilities = () => ({
81869
81901
  reads: {
81870
81902
  public: true,