@gvnrdao/dh-mcp 0.5.21 → 0.5.23

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/dist/boundary.js CHANGED
@@ -15463,7 +15463,7 @@ ${errorReport}`);
15463
15463
  }
15464
15464
  init_debug_logger();
15465
15465
  init_session_signature_cache();
15466
- var import_ethers52 = require("ethers");
15466
+ var import_ethers53 = require("ethers");
15467
15467
  var EXPIRED_LOAN_MIN_LIQUIDATION_THRESHOLD_BPS = 11e3;
15468
15468
  var GRACE_PERIOD_DAYS = 30;
15469
15469
  var SATOSHIS_PER_BITCOIN = 100000000n;
@@ -18459,12 +18459,12 @@ ${auth.clientId}`;
18459
18459
  }
18460
18460
  async function executeVaultSnapshot(params) {
18461
18461
  global.ethers = {
18462
- ...import_ethers52.ethers,
18462
+ ...import_ethers53.ethers,
18463
18463
  providers: {
18464
- StaticJsonRpcProvider: import_ethers52.ethers.JsonRpcProvider
18464
+ StaticJsonRpcProvider: import_ethers53.ethers.JsonRpcProvider
18465
18465
  },
18466
- Contract: import_ethers52.ethers.Contract,
18467
- utils: import_ethers52.ethers
18466
+ Contract: import_ethers53.ethers.Contract,
18467
+ utils: import_ethers53.ethers
18468
18468
  // v6 moved utils to top level
18469
18469
  };
18470
18470
  global.Lit = {
@@ -27397,7 +27397,7 @@ var require_lit_ops_module = __commonJS({
27397
27397
  litActionParams.rpcUrl = request.rpcUrl;
27398
27398
  litActionParams.customRpcUrl = request.rpcUrl;
27399
27399
  if (this.config.debug) {
27400
- console.log(" RPC URL override:", request.rpcUrl);
27400
+ console.log(" RPC URL override host:", new URL(request.rpcUrl).host);
27401
27401
  }
27402
27402
  }
27403
27403
  if (this.config.network === "chipotle") {
@@ -27573,7 +27573,7 @@ var require_lit_ops_module = __commonJS({
27573
27573
  litActionParams.rpcUrl = request.rpcUrl;
27574
27574
  litActionParams.customRpcUrl = request.rpcUrl;
27575
27575
  if (this.config.debug) {
27576
- console.log(" RPC URL override:", request.rpcUrl);
27576
+ console.log(" RPC URL override host:", new URL(request.rpcUrl).host);
27577
27577
  }
27578
27578
  }
27579
27579
  if (this.config.network === "chipotle") {
@@ -27911,7 +27911,7 @@ var require_lit_ops_module = __commonJS({
27911
27911
  litActionParams.rpcUrl = request.rpcUrl;
27912
27912
  litActionParams.customRpcUrl = request.rpcUrl;
27913
27913
  if (this.config.debug) {
27914
- console.log(" RPC URL override:", request.rpcUrl);
27914
+ console.log(" RPC URL override host:", new URL(request.rpcUrl).host);
27915
27915
  }
27916
27916
  }
27917
27917
  if (this.config.network === "chipotle") {
@@ -28127,7 +28127,7 @@ var require_lit_ops_module = __commonJS({
28127
28127
  litActionParams.rpcUrl = request.rpcUrl;
28128
28128
  litActionParams.customRpcUrl = request.rpcUrl;
28129
28129
  if (this.config.debug) {
28130
- console.log(" EVM RPC URL override:", request.rpcUrl);
28130
+ console.log(" EVM RPC URL override host:", new URL(request.rpcUrl).host);
28131
28131
  }
28132
28132
  }
28133
28133
  if (this.config.debug) {
@@ -28257,7 +28257,12 @@ var require_lit_ops_module = __commonJS({
28257
28257
  if (!moduleAddress || !provisionerPk || !baseRpc) {
28258
28258
  throw new Error("LIT_VAULT_PROVISION_MODE=module requires LIT_ONCHAIN_VAULT_MODULE_ADDRESS, LIT_ONCHAIN_PROVISIONER_PRIVATE_KEY, BASE_RPC_URL");
28259
28259
  }
28260
- const provider = new ethers_1.JsonRpcProvider(baseRpc);
28260
+ const baseRequest = new ethers_1.FetchRequest(baseRpc);
28261
+ const drpcKey = process.env.DRPC_API_KEY;
28262
+ if (drpcKey && /(^|\.)drpc\.(org|live)$/.test(new URL(baseRpc).hostname)) {
28263
+ baseRequest.setHeader("Drpc-Key", drpcKey);
28264
+ }
28265
+ const provider = new ethers_1.JsonRpcProvider(baseRequest);
28261
28266
  const signer = new ethers_1.Wallet(provisionerPk, provider);
28262
28267
  const chainId = Number(process.env.BASE_CHAIN_ID || "8453");
28263
28268
  const issuedAt = Math.floor(Date.now() / 1e3);
@@ -28308,7 +28313,7 @@ var require_lit_ops_module = __commonJS({
28308
28313
  async chipotleCreateWalletAndAddToGroup(accountApiKey) {
28309
28314
  const baseUrl = _LitOps.LIT_CORE_API_BASE;
28310
28315
  const createResp = await fetch(`${baseUrl}/create_wallet`, {
28311
- method: "GET",
28316
+ method: "POST",
28312
28317
  headers: {
28313
28318
  "X-Api-Key": accountApiKey
28314
28319
  }
@@ -40728,6 +40733,7 @@ __export(wc_transport_exports, {
40728
40733
  WC_DAPP_METADATA: () => WC_DAPP_METADATA,
40729
40734
  WC_SESSION_METHODS: () => WC_SESSION_METHODS,
40730
40735
  WcTransport: () => WcTransport,
40736
+ guardRelayFatal: () => guardRelayFatal,
40731
40737
  newIsolatedCore: () => newIsolatedCore,
40732
40738
  wcSessionNamespaces: () => wcSessionNamespaces,
40733
40739
  withEip712DomainType: () => withEip712DomainType
@@ -40761,7 +40767,27 @@ function newIsolatedCore(cfg, label) {
40761
40767
  });
40762
40768
  return { core, scratch };
40763
40769
  }
40764
- var import_core, import_sign_client, os, path3, import_node_fs, WC_SESSION_METHODS, WC_DAPP_METADATA, EVENTS, WcTransport;
40770
+ function guardRelayFatal(core, health, onFatal) {
40771
+ const relayer = core.relayer;
40772
+ const register = relayer.registerProviderListeners;
40773
+ if (typeof register !== "function") {
40774
+ throw new Error(
40775
+ "@walletconnect/core no longer exposes relayer.registerProviderListeners \u2014 the fatal-close guard (D-4) cannot be installed. Re-verify the relay error path for this WalletConnect version before shipping it."
40776
+ );
40777
+ }
40778
+ const record = (e) => {
40779
+ if (health.fatal !== null) return;
40780
+ health.fatal = e.message;
40781
+ console.error(`[dh-mcp] WalletConnect relay failed fatally: ${e.message}`);
40782
+ onFatal(e.message);
40783
+ };
40784
+ relayer.on("relayer_error", record);
40785
+ relayer.registerProviderListeners = () => {
40786
+ register.call(relayer);
40787
+ relayer.provider.on("error", record);
40788
+ };
40789
+ }
40790
+ var import_core, import_sign_client, os, path3, import_node_fs, import_ethers50, WC_SESSION_METHODS, WC_DAPP_METADATA, EVENTS, WcTransport;
40765
40791
  var init_wc_transport = __esm({
40766
40792
  "src/boundary/upstream/shared/external-bridge/wc-transport.ts"() {
40767
40793
  "use strict";
@@ -40770,6 +40796,7 @@ var init_wc_transport = __esm({
40770
40796
  os = __toESM(require("os"));
40771
40797
  path3 = __toESM(require("path"));
40772
40798
  import_node_fs = require("fs");
40799
+ import_ethers50 = require("ethers");
40773
40800
  WC_SESSION_METHODS = ["personal_sign", "eth_signTypedData_v4", "eth_sendTransaction"];
40774
40801
  WC_DAPP_METADATA = {
40775
40802
  name: "Diamond Hands MCP",
@@ -40779,11 +40806,14 @@ var init_wc_transport = __esm({
40779
40806
  };
40780
40807
  EVENTS = ["accountsChanged", "chainChanged"];
40781
40808
  WcTransport = class _WcTransport {
40782
- constructor(client, cfg, scratch) {
40809
+ constructor(client, cfg, scratch, health) {
40783
40810
  this.client = client;
40784
40811
  this.cfg = cfg;
40785
40812
  this.scratch = scratch;
40813
+ this.health = health;
40786
40814
  client.on("session_delete", ({ topic }) => {
40815
+ const pending = this.candidates.get(topic);
40816
+ if (pending) pending.deleted = true;
40787
40817
  if (this.session === null || this.session.topic !== topic) return;
40788
40818
  this.session = null;
40789
40819
  this.sessionListener?.(null);
@@ -40791,14 +40821,35 @@ var init_wc_transport = __esm({
40791
40821
  }
40792
40822
  session = null;
40793
40823
  sessionListener = null;
40824
+ /** Sessions announced but not yet adopted (awaiting a deferred verdict), by topic. */
40825
+ candidates = /* @__PURE__ */ new Map();
40794
40826
  static async create(cfg) {
40795
40827
  const { core, scratch } = newIsolatedCore(cfg, "dh-wc-dapp");
40828
+ const health = { fatal: null };
40829
+ let transport = null;
40830
+ guardRelayFatal(core, health, () => transport?.dropForFatal());
40796
40831
  const client = await import_sign_client.default.init({
40797
40832
  core,
40798
40833
  projectId: cfg.projectId,
40799
40834
  metadata: cfg.metadata ?? WC_DAPP_METADATA
40800
40835
  });
40801
- return new _WcTransport(client, cfg, scratch);
40836
+ transport = new _WcTransport(client, cfg, scratch, health);
40837
+ return transport;
40838
+ }
40839
+ /** The relay is gone for good: no adopted session may outlive it. Listeners hear a
40840
+ * disconnect, exactly as if the wallet had left. */
40841
+ dropForFatal() {
40842
+ if (this.session === null) return;
40843
+ this.session = null;
40844
+ void this.sessionListener?.(null);
40845
+ }
40846
+ /** Refuse to start new work over a relay that has failed fatally — naming why. */
40847
+ assertRelayHealthy() {
40848
+ if (this.health.fatal !== null) {
40849
+ throw new Error(
40850
+ `the WalletConnect relay refused this connector (${this.health.fatal}) \u2014 mobile-wallet signing is unavailable until the relay accepts its project id (DH_WC_PROJECT_ID); use the browser-wallet approval page instead`
40851
+ );
40852
+ }
40802
40853
  }
40803
40854
  /** Wallet-session state changes (connect/disconnect) — the bridge mirrors them. */
40804
40855
  onSession(cb) {
@@ -40809,6 +40860,7 @@ var init_wc_transport = __esm({
40809
40860
  }
40810
40861
  /** Create a pairing URI; resolves the session in the background when a wallet approves. */
40811
40862
  async createPairing() {
40863
+ this.assertRelayHealthy();
40812
40864
  const { uri, approval } = await this.client.connect({
40813
40865
  // sign-client 2.21 deprecates requiredNamespaces (auto-downgraded to optional).
40814
40866
  optionalNamespaces: wcSessionNamespaces(this.cfg.chainId)
@@ -40816,22 +40868,51 @@ var init_wc_transport = __esm({
40816
40868
  if (!uri) throw new Error("WalletConnect returned no pairing URI");
40817
40869
  const pairingId = /^wc:([0-9a-f]+)@/i.exec(uri)?.[1];
40818
40870
  if (!pairingId) throw new Error(`WalletConnect pairing URI has no recognisable topic: ${uri.slice(0, 12)}\u2026`);
40819
- void approval().then((session) => {
40871
+ let candidateTopic = null;
40872
+ void approval().then(async (session) => {
40820
40873
  const first = session.namespaces["eip155"]?.accounts[0];
40821
40874
  if (!first) throw new Error("WalletConnect session carries no eip155 account");
40822
40875
  const [, chainIdStr, account] = first.split(":");
40876
+ candidateTopic = session.topic;
40877
+ const candidate = { topic: session.topic, account, chainId: Number(chainIdStr) };
40878
+ const prove = async (statement) => {
40879
+ this.assertRelayHealthy();
40880
+ return await this.client.request({
40881
+ topic: candidate.topic,
40882
+ chainId: `eip155:${candidate.chainId}`,
40883
+ request: { method: "personal_sign", params: [import_ethers50.ethers.hexlify(import_ethers50.ethers.toUtf8Bytes(statement)), candidate.account] }
40884
+ });
40885
+ };
40886
+ const state = { deleted: false };
40887
+ const live = () => !state.deleted && this.health.fatal === null;
40823
40888
  const previous = this.session;
40824
- this.session = { topic: session.topic, account, chainId: Number(chainIdStr) };
40825
- const verdict = this.sessionListener?.({ ...this.active(), pairingId });
40826
- if (verdict === false) {
40889
+ this.session = candidate;
40890
+ this.candidates.set(candidate.topic, state);
40891
+ const verdict = this.sessionListener?.({ account: candidate.account, chainId: candidate.chainId, pairingId, prove, live });
40892
+ let adopted;
40893
+ if (verdict instanceof Promise) {
40827
40894
  this.session = previous;
40895
+ adopted = await verdict.finally(() => this.candidates.delete(candidate.topic)).then((v) => v !== false);
40896
+ if (adopted) this.session = candidate;
40897
+ } else {
40898
+ this.candidates.delete(candidate.topic);
40899
+ adopted = verdict !== false;
40900
+ if (!adopted) this.session = previous;
40901
+ }
40902
+ if (!adopted) {
40828
40903
  void this.client.disconnect({ topic: session.topic, reason: { code: 6e3, message: "session refused by the bridge" } }).catch(() => void 0);
40829
40904
  }
40830
- }).catch((e) => console.error(`[dh-mcp] WalletConnect pairing failed: ${e.message}`));
40905
+ }).catch((e) => {
40906
+ console.error(`[dh-mcp] WalletConnect pairing failed: ${e.message}`);
40907
+ if (candidateTopic !== null && this.session?.topic !== candidateTopic) {
40908
+ void this.client.disconnect({ topic: candidateTopic, reason: { code: 6e3, message: "session not adopted" } }).catch(() => void 0);
40909
+ }
40910
+ });
40831
40911
  return { uri, pairingId };
40832
40912
  }
40833
40913
  /** Route one wallet request over the active session. Throws on user rejection. */
40834
40914
  async request(method, params) {
40915
+ this.assertRelayHealthy();
40835
40916
  if (!this.session) throw new Error("no active WalletConnect session");
40836
40917
  return this.client.request({
40837
40918
  topic: this.session.topic,
@@ -40863,7 +40944,232 @@ var import_node_crypto8 = require("crypto");
40863
40944
  var fs5 = __toESM(require("fs"));
40864
40945
  var os2 = __toESM(require("os"));
40865
40946
  var path4 = __toESM(require("path"));
40866
- var import_ethers51 = require("ethers");
40947
+ var import_ethers52 = require("ethers");
40948
+
40949
+ // src/boundary/errors.ts
40950
+ function boundaryError(code, message, extra) {
40951
+ return { code, message, ...extra?.source && { source: extra.source }, ...extra?.details && { details: extra.details } };
40952
+ }
40953
+
40954
+ // src/boundary/config.ts
40955
+ var NETWORKS = { sepolia: 11155111, mainnet: 1 };
40956
+ var ADAPTERS = ["mock", "real"];
40957
+ var LATENCIES = ["zero", "realistic"];
40958
+ var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
40959
+ var WC_DISABLED = "off";
40960
+ function resolveWcProjectId(raw, problems) {
40961
+ if (raw === void 0 || raw === "" || raw === WC_DISABLED) return void 0;
40962
+ if (!/^[0-9a-f]{32}$/.test(raw)) {
40963
+ problems.push(`DH_WC_PROJECT_ID must be a 32-char hex WalletConnect project id, or '${WC_DISABLED}' to disable WalletConnect.`);
40964
+ return void 0;
40965
+ }
40966
+ return raw;
40967
+ }
40968
+ var RPC_PROXY_ORIGIN = "https://api.gvnr.xyz";
40969
+ var rpcProxy = (chainId) => `${RPC_PROXY_ORIGIN}/v1/proxy/rpc/${chainId}`;
40970
+ var publicRpcUrl = rpcProxy;
40971
+ var DRPC_ENDPOINT = {
40972
+ mainnet: "https://lb.drpc.live/ethereum",
40973
+ sepolia: "https://lb.drpc.live/sepolia"
40974
+ };
40975
+ var NETWORK_DEFAULTS = {
40976
+ sepolia: {
40977
+ rpcUrl: rpcProxy(11155111),
40978
+ serviceEndpoint: "https://ops-test.gvnr.xyz",
40979
+ litNetwork: "chipotle",
40980
+ validatorVersion: 3
40981
+ // on-chain validator generation, sepolia (2026-07-30)
40982
+ },
40983
+ mainnet: {
40984
+ rpcUrl: rpcProxy(1),
40985
+ // Cutover 2026-09-08 — see sdk/src/constants/chunks/network-configs.ts for the full
40986
+ // reasoning. Widening, not a rename: ops.gvnr.xyz serves the same broker and cannot be
40987
+ // retired while installed copies call it. The sepolia entry above deliberately stays on
40988
+ // ops-test.gvnr.xyz — there is no ops-test.diamondhands.credit twin (open decision 2).
40989
+ serviceEndpoint: "https://ops.diamondhands.credit",
40990
+ litNetwork: "chipotle",
40991
+ // On-chain PKPValidation generation, mainnet (validatorForVersion(3) is the ONLY
40992
+ // registered validator — verified live 2026-08-05). Without this the SDK defaults
40993
+ // to 1 and createPosition reverts ValidatorNotConfigured in wallet simulation.
40994
+ validatorVersion: 3
40995
+ }
40996
+ };
40997
+ function resolveBoundaryConfig(env) {
40998
+ const adapter2 = env["DH_ADAPTER"] === void 0 || env["DH_ADAPTER"] === "" ? "real" : env["DH_ADAPTER"];
40999
+ if (!ADAPTERS.includes(adapter2)) {
41000
+ return {
41001
+ ok: false,
41002
+ error: boundaryError(
41003
+ "CONFIG_MISSING",
41004
+ `DH_ADAPTER='${adapter2}' is not a valid adapter. Allowed: ${ADAPTERS.join(" | ")}.`,
41005
+ { details: { invalid: ["DH_ADAPTER"] } }
41006
+ )
41007
+ };
41008
+ }
41009
+ if (adapter2 === "real") return resolveRealConfig(env);
41010
+ const problems = [];
41011
+ const missing = [];
41012
+ const mockDb = env["DH_MOCK_DB"];
41013
+ if (!mockDb) {
41014
+ missing.push("DH_MOCK_DB");
41015
+ problems.push("DH_MOCK_DB is not set (path of the mock world DB file).");
41016
+ }
41017
+ const latency = env["DH_MOCK_LATENCY"];
41018
+ if (!latency) {
41019
+ missing.push("DH_MOCK_LATENCY");
41020
+ problems.push(`DH_MOCK_LATENCY is not set. Allowed: ${LATENCIES.join(" | ")}.`);
41021
+ } else if (!LATENCIES.includes(latency)) {
41022
+ problems.push(`DH_MOCK_LATENCY='${latency}' is invalid. Allowed: ${LATENCIES.join(" | ")}.`);
41023
+ }
41024
+ const borrower = env["DH_MOCK_BORROWER"];
41025
+ if (borrower !== void 0 && borrower !== "" && !ADDRESS_RE.test(borrower)) {
41026
+ problems.push(`DH_MOCK_BORROWER='${borrower}' is not a valid 0x address.`);
41027
+ }
41028
+ const SIGNER_MODES = ["external", "keystore", "mock-simulated"];
41029
+ const signer = env["DH_SIGNER"];
41030
+ if (signer !== void 0 && signer !== "" && !SIGNER_MODES.includes(signer)) {
41031
+ problems.push(`DH_SIGNER='${signer}' is not supported for the mock adapter. Allowed: ${SIGNER_MODES.join(" | ")} (or unset).`);
41032
+ }
41033
+ let chainId;
41034
+ const chainRaw = env["DH_MOCK_CHAIN_ID"];
41035
+ if (chainRaw !== void 0 && chainRaw !== "") {
41036
+ const n = Number(chainRaw);
41037
+ if (!Number.isInteger(n) || n <= 0) {
41038
+ problems.push(`DH_MOCK_CHAIN_ID='${chainRaw}' must be a positive integer.`);
41039
+ } else {
41040
+ chainId = n;
41041
+ }
41042
+ }
41043
+ const sinkRpcUrl = env["DH_MOCK_SINK_RPC"];
41044
+ if (sinkRpcUrl !== void 0 && sinkRpcUrl !== "" && !/^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?/.test(sinkRpcUrl)) {
41045
+ problems.push(`DH_MOCK_SINK_RPC='${sinkRpcUrl}' must be a loopback http:// URL (the sink chain never leaves this machine).`);
41046
+ }
41047
+ const bridgeUrlFile = env["DH_BRIDGE_URL_FILE"];
41048
+ const bridgeOpenRaw = env["DH_BRIDGE_OPEN"];
41049
+ const wcProjectId = resolveWcProjectId(env["DH_WC_PROJECT_ID"], problems);
41050
+ let bridgeOpenBrowser;
41051
+ if (bridgeOpenRaw !== void 0 && bridgeOpenRaw !== "") {
41052
+ if (bridgeOpenRaw !== "0" && bridgeOpenRaw !== "1") {
41053
+ problems.push(`DH_BRIDGE_OPEN='${bridgeOpenRaw}' must be 0 or 1.`);
41054
+ } else {
41055
+ bridgeOpenBrowser = bridgeOpenRaw === "1";
41056
+ }
41057
+ }
41058
+ const keystorePath = env["DH_KEYSTORE_PATH"];
41059
+ const keystorePassword = env["DH_KEYSTORE_PASSWORD"];
41060
+ if (keystorePath && !keystorePassword || !keystorePath && keystorePassword) {
41061
+ problems.push("DH_KEYSTORE_PATH and DH_KEYSTORE_PASSWORD must be set together (or neither).");
41062
+ }
41063
+ if (problems.length > 0) {
41064
+ return {
41065
+ ok: false,
41066
+ error: boundaryError("CONFIG_MISSING", `Mock boundary configuration is incomplete:
41067
+ - ${problems.join("\n- ")}`, {
41068
+ details: { missing }
41069
+ })
41070
+ };
41071
+ }
41072
+ return {
41073
+ ok: true,
41074
+ config: {
41075
+ adapter: "mock",
41076
+ mockDb,
41077
+ latency,
41078
+ ...borrower ? { borrower } : {},
41079
+ ...signer ? { signer } : {},
41080
+ chainId: chainId ?? 1337,
41081
+ ...sinkRpcUrl ? { sinkRpcUrl } : {},
41082
+ ...bridgeUrlFile ? { bridgeUrlFile } : {},
41083
+ ...bridgeOpenBrowser !== void 0 ? { bridgeOpenBrowser } : {},
41084
+ ...wcProjectId ? { wcProjectId } : {},
41085
+ ...keystorePath && keystorePassword ? { keystorePath, keystorePassword } : {}
41086
+ }
41087
+ };
41088
+ }
41089
+ function resolveRealConfig(env) {
41090
+ const problems = [];
41091
+ const missing = [];
41092
+ const signer = env["DH_SIGNER"];
41093
+ if (signer !== void 0 && signer !== "") {
41094
+ if (signer === "mock-simulated") {
41095
+ problems.push(
41096
+ "DH_SIGNER='mock-simulated' is the test-world stand-in ceremony and cannot authorize real-protocol operations. On the real adapter use 'external' (your own wallet) or 'keystore', or DH_ADAPTER=mock."
41097
+ );
41098
+ } else if (signer !== "external" && signer !== "keystore") {
41099
+ problems.push(`DH_SIGNER='${signer}' is not supported for the real adapter. Allowed: external | keystore (or unset).`);
41100
+ }
41101
+ }
41102
+ const network = env["DH_NETWORK"] === void 0 || env["DH_NETWORK"] === "" ? "mainnet" : env["DH_NETWORK"];
41103
+ if (NETWORKS[network] === void 0) {
41104
+ problems.push(`DH_NETWORK='${network}' is not supported. Allowed: ${Object.keys(NETWORKS).join(" | ")}.`);
41105
+ }
41106
+ const defaults2 = NETWORK_DEFAULTS[network] ?? NETWORK_DEFAULTS.mainnet;
41107
+ const rpcDrpcKey = env["DRPC_API_KEY"] || void 0;
41108
+ if (rpcDrpcKey !== void 0 && env["ETH_RPC_URL"]) {
41109
+ problems.push("DRPC_API_KEY and ETH_RPC_URL are both set \u2014 set one: DRPC_API_KEY (dRPC, key sent as a header) or ETH_RPC_URL (your own endpoint).");
41110
+ }
41111
+ const rpcUrl = rpcDrpcKey !== void 0 ? DRPC_ENDPOINT[network] ?? DRPC_ENDPOINT.mainnet : env["ETH_RPC_URL"] || defaults2.rpcUrl;
41112
+ const serviceEndpoint = env["DH_SERVICE_ENDPOINT"] || defaults2.serviceEndpoint;
41113
+ if (!/^https:\/\//.test(serviceEndpoint) && !/^http:\/\/(localhost|127\.0\.0\.1)/.test(serviceEndpoint)) {
41114
+ problems.push(`DH_SERVICE_ENDPOINT='${serviceEndpoint}' must be https:// (or http:// on loopback).`);
41115
+ }
41116
+ const litNetwork = env["DH_LIT_NETWORK"] || defaults2.litNetwork;
41117
+ const keystorePath = env["DH_KEYSTORE_PATH"];
41118
+ const keystorePassword = env["DH_KEYSTORE_PASSWORD"];
41119
+ if (keystorePath && !keystorePassword || !keystorePath && keystorePassword) {
41120
+ problems.push("DH_KEYSTORE_PATH and DH_KEYSTORE_PASSWORD must be set together (or neither).");
41121
+ }
41122
+ const stateDir = env["DH_STATE_DIR"];
41123
+ const bridgeUrlFile = env["DH_BRIDGE_URL_FILE"];
41124
+ const bridgeOpenRaw = env["DH_BRIDGE_OPEN"];
41125
+ const wcProjectId = resolveWcProjectId(env["DH_WC_PROJECT_ID"], problems);
41126
+ let bridgeOpenBrowser;
41127
+ if (bridgeOpenRaw !== void 0 && bridgeOpenRaw !== "") {
41128
+ if (bridgeOpenRaw !== "0" && bridgeOpenRaw !== "1") {
41129
+ problems.push(`DH_BRIDGE_OPEN='${bridgeOpenRaw}' must be 0 or 1.`);
41130
+ } else {
41131
+ bridgeOpenBrowser = bridgeOpenRaw === "1";
41132
+ }
41133
+ }
41134
+ const validatorRaw = env["DH_VALIDATOR_VERSION"];
41135
+ let validatorVersion = defaults2.validatorVersion;
41136
+ if (validatorRaw !== void 0 && validatorRaw !== "") {
41137
+ const n = Number(validatorRaw);
41138
+ if (!Number.isInteger(n) || n <= 0) {
41139
+ problems.push(`DH_VALIDATOR_VERSION='${validatorRaw}' must be a positive integer.`);
41140
+ } else {
41141
+ validatorVersion = n;
41142
+ }
41143
+ }
41144
+ if (problems.length > 0) {
41145
+ return {
41146
+ ok: false,
41147
+ error: boundaryError("CONFIG_MISSING", `Real boundary configuration is incomplete:
41148
+ - ${problems.join("\n- ")}`, {
41149
+ details: { missing }
41150
+ })
41151
+ };
41152
+ }
41153
+ return {
41154
+ ok: true,
41155
+ config: {
41156
+ adapter: "real",
41157
+ network,
41158
+ chainId: NETWORKS[network],
41159
+ rpcUrl,
41160
+ ...rpcDrpcKey !== void 0 ? { rpcDrpcKey } : {},
41161
+ serviceEndpoint,
41162
+ litNetwork,
41163
+ ...keystorePath && keystorePassword ? { keystorePath, keystorePassword } : {},
41164
+ ...signer === "external" || signer === "keystore" ? { signer } : {},
41165
+ ...stateDir ? { stateDir } : {},
41166
+ ...bridgeUrlFile ? { bridgeUrlFile } : {},
41167
+ ...bridgeOpenBrowser !== void 0 ? { bridgeOpenBrowser } : {},
41168
+ ...wcProjectId ? { wcProjectId } : {},
41169
+ ...validatorVersion !== void 0 ? { validatorVersion } : {}
41170
+ }
41171
+ };
41172
+ }
40867
41173
 
40868
41174
  // src/boundary/envelope.ts
40869
41175
  function okEnvelope(data, source, warnings = []) {
@@ -40873,11 +41179,6 @@ function errEnvelope(error) {
40873
41179
  return { ok: false, error };
40874
41180
  }
40875
41181
 
40876
- // src/boundary/errors.ts
40877
- function boundaryError(code, message, extra) {
40878
- return { code, message, ...extra?.source && { source: extra.source }, ...extra?.details && { details: extra.details } };
40879
- }
40880
-
40881
41182
  // src/boundary/reading-notes.ts
40882
41183
  var STATE_FLOW_LINE = "PENDING_DEPOSIT \u2192 ACTIVE (after the first mint) \u2192 REPAID \u2192 CLOSED (after the collateral leaves). EXPIRED/LIQUIDATABLE exist for overdue/undercollateralized positions";
40883
41184
  function positionReadingNotes(d) {
@@ -40927,6 +41228,16 @@ function checkBtcAddress(addr, expected) {
40927
41228
  }
40928
41229
  }
40929
41230
 
41231
+ // src/util/redact-url.ts
41232
+ var URL_PATTERN = /\b((?:https?|wss?):\/\/)([^\s/?#"'`<>\\]+)([^\s"'`<>\\]*)/gi;
41233
+ function redactUrls(text) {
41234
+ return text.replace(URL_PATTERN, (_whole, scheme, authority, rest) => {
41235
+ const host = authority.includes("@") ? authority.slice(authority.lastIndexOf("@") + 1) : authority;
41236
+ const cut = rest.length > 0 || host !== authority;
41237
+ return `${scheme}${host}${cut ? "/\u2026" : ""}`;
41238
+ });
41239
+ }
41240
+
40930
41241
  // src/boundary/math.ts
40931
41242
  function collateralValueUcdWei(sats, priceUsd8) {
40932
41243
  return sats * priceUsd8 * 100n;
@@ -40959,10 +41270,11 @@ function stablecoinKindFor(network, stablecoinAddress) {
40959
41270
  }
40960
41271
  function failureToError(f) {
40961
41272
  const code = f.kind === "signer-missing" ? "SIGNER_UNAVAILABLE" : f.kind === "unavailable" ? "UPSTREAM_UNAVAILABLE" : f.kind === "unsupported" ? "NOT_IMPLEMENTED" : f.kind === "not-found" ? "NOT_FOUND" : "UPSTREAM_REJECTED";
40962
- const message = f.kind === "malformed" ? `${f.message} (upstream response failed integrity checks)` : f.message;
41273
+ const text = redactUrls(f.message);
41274
+ const message = f.kind === "malformed" ? `${text} (upstream response failed integrity checks)` : text;
40963
41275
  return boundaryError(code, message, {
40964
41276
  source: f.source,
40965
- ...f.raw ? { details: { upstreamMessage: f.raw } } : {}
41277
+ ...f.raw ? { details: { upstreamMessage: redactUrls(f.raw) } } : {}
40966
41278
  });
40967
41279
  }
40968
41280
  var BoundaryCore = class {
@@ -82296,7 +82608,9 @@ var MIN_CONFIRMATIONS = { mainnet: 6, sepolia: 1 };
82296
82608
  var RealUpstreamPlugin = class {
82297
82609
  constructor(config, wallet, runtime) {
82298
82610
  this.config = config;
82299
- this.provider = new import_ethers49.ethers.JsonRpcProvider(config.rpcUrl, config.chainId);
82611
+ const rpc = new import_ethers49.ethers.FetchRequest(config.rpcUrl);
82612
+ if (config.rpcDrpcKey !== void 0) rpc.setHeader("Drpc-Key", config.rpcDrpcKey);
82613
+ this.provider = new import_ethers49.ethers.JsonRpcProvider(rpc, config.chainId);
82300
82614
  this.wallet = wallet ?? null;
82301
82615
  this.runtime = runtime ?? null;
82302
82616
  this.session = wallet ? new LitOpsSession(wallet.connect(this.provider), config.serviceEndpoint, config.chainId) : null;
@@ -83237,8 +83551,9 @@ var RealUpstreamPlugin = class {
83237
83551
  }
83238
83552
  /** Chain read → mapped value, failures typed. F-PUB-5 (protocol 106): the SPECIFIC
83239
83553
  * thrown cause is rendered — a blanket rewrite to a generic message masked the
83240
- * deliberate `readPendingWithdrawals` gap as an RPC outage. No secrets transit here
83241
- * (provider errors carry method/params, never keys). */
83554
+ * deliberate `readPendingWithdrawals` gap as an RPC outage. Provider errors DO carry
83555
+ * the request URL (ethers' `info.requestUrl`); the server's URL holds no key (it is in
83556
+ * the `Drpc-Key` header) and failureToError redacts every URL regardless. */
83242
83557
  async chainRead(fn) {
83243
83558
  try {
83244
83559
  return upOk(await fn(), this.src("chain-rpc"));
@@ -83299,7 +83614,7 @@ var RealUpstreamPlugin = class {
83299
83614
  var fs4 = __toESM(require("fs"));
83300
83615
  var http3 = __toESM(require("http"));
83301
83616
  var import_node_crypto7 = require("crypto");
83302
- var import_ethers50 = require("ethers");
83617
+ var import_ethers51 = require("ethers");
83303
83618
 
83304
83619
  // src/util/brand-assets.ts
83305
83620
  var FAVICON_SVG = `<svg width="512" height="512" viewBox="-6 -11 88 88" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Diamond Hands"><path d="M1.08325 20.7041L37.9038 64.4967L74.2886 20.7041L61.8699 0.877686H13.502L1.08325 20.7041Z" fill="#C9F284" stroke="#34440E" stroke-width="1.75559"/><path d="M13.9385 0.877441L37.9045 64.2785" stroke="#34440E" stroke-width="1.75559"/><path d="M61.6553 0.877441L37.9071 64.4964" stroke="#34440E" stroke-width="1.75559"/><path d="M1.08276 20.7029H74.2882" stroke="#34440E" stroke-width="1.75559"/></svg>`;
@@ -83424,7 +83739,7 @@ ${houseHeader("Diamond Hands \xB7 signature approval")}
83424
83739
  <button id="wc-connect" class="btn-secondary">Use a mobile wallet instead (WalletConnect)</button>
83425
83740
  <div id="wc-qr" class="qr-plate hidden"></div>
83426
83741
  <div id="wc-uri" class="card hidden"></div>
83427
- <div id="wc-hint" class="status hidden">Scan the QR with your wallet app (or open the app \u2192 WalletConnect \u2192 paste the pairing code). Approvals then happen on your phone.</div>
83742
+ <div id="wc-hint" class="status hidden">Scan the QR with your wallet app (or open the app \u2192 WalletConnect \u2192 paste the pairing code). Your wallet first asks you to sign a short statement proving the wallet is yours \u2014 it moves no funds. Approvals then happen on your phone.</div>
83428
83743
  </div>
83429
83744
  </div>
83430
83745
  </main>
@@ -83771,7 +84086,7 @@ document.getElementById("wc-connect").onclick = async () => {
83771
84086
  qrEl.classList.remove("hidden");
83772
84087
  }
83773
84088
  document.getElementById("wc-hint").classList.remove("hidden");
83774
- showStatus("Scan the QR (or paste the code) in your mobile wallet \u2014 it becomes the signing wallet.");
84089
+ showIdleStatus("Scan the QR (or paste the code) in your mobile wallet, then sign the short statement it shows (it proves the wallet is yours and moves no funds) \u2014 it then becomes the signing wallet.");
83775
84090
  };
83776
84091
 
83777
84092
  listen();
@@ -83883,7 +84198,6 @@ function htmlPageSecurityHeaders(extra) {
83883
84198
 
83884
84199
  // src/boundary/upstream/shared/external-bridge/bridge.ts
83885
84200
  var MAX_SESSIONS = 16;
83886
- var MAX_PENDING_PAIRINGS = 64;
83887
84201
  function presenceStatement(origin2, chainId, nonce) {
83888
84202
  return [
83889
84203
  "Diamond Hands approval page",
@@ -83893,6 +84207,13 @@ function presenceStatement(origin2, chainId, nonce) {
83893
84207
  `Session nonce: ${nonce}`
83894
84208
  ].join("\n");
83895
84209
  }
84210
+ function recoverPresenceSigner(statement, signature) {
84211
+ try {
84212
+ return import_ethers51.ethers.verifyMessage(statement, signature);
84213
+ } catch {
84214
+ return null;
84215
+ }
84216
+ }
83896
84217
  var DEFAULT_EXPIRY_MS = 5 * 60 * 1e3;
83897
84218
  var DEFAULT_ATTACH_GRACE_MS = 60 * 1e3;
83898
84219
  var DEFAULT_HOSTED_ATTACH_GRACE_MS = 180 * 1e3;
@@ -83942,6 +84263,10 @@ var SignatureBridge = class {
83942
84263
  * "most recent asker" guess let a second session claim the credit for a QR the user's
83943
84264
  * phone scanned (Sentinel 2 PoC-B). */
83944
84265
  pairingOwners = /* @__PURE__ */ new Map();
84266
+ /** The page session the ADMITTED WalletConnect session's proof was made for — the one page
84267
+ * credited with `wcPaired`. The credit lasts exactly as long as that session: it moves when
84268
+ * another proven session replaces it and ends when the wallet disconnects. */
84269
+ wcCreditedSession = null;
83945
84270
  keystoreUnlock;
83946
84271
  unlockToken = null;
83947
84272
  unlockSession = null;
@@ -84430,46 +84755,16 @@ var SignatureBridge = class {
84430
84755
  const { WcTransport: WcTransport2 } = await Promise.resolve().then(() => (init_wc_transport(), wc_transport_exports));
84431
84756
  return WcTransport2.create(cfg);
84432
84757
  });
84433
- this.wcTransport = await factory2(this.wcConfig);
84434
- this.wcTransport.onSession((info) => {
84435
- const refusal = info ? this.accountRefusal(info.account) : null;
84436
- if (info && refusal) {
84437
- if (!this.wcActive) {
84438
- this.rebuildSharedWallet();
84439
- this.demoteWcEntries();
84440
- }
84441
- process.stderr.write(`[bridge] WalletConnect session refused \u2014 ${refusal}
84442
- `);
84443
- return false;
84444
- }
84445
- this.wcActive = info !== null;
84446
- this.wallet = info ? { account: info.account, chainId: info.chainId } : null;
84447
- if (info?.pairingId) {
84448
- const owner = this.pairingOwners.get(info.pairingId);
84449
- this.pairingOwners.delete(info.pairingId);
84450
- const paired = owner ? this.sessions.get(owner) : void 0;
84451
- if (paired) paired.wcPaired = true;
84452
- }
84453
- if (info === null) {
84454
- for (const entry of this.pending.values()) {
84455
- if (!entry.settled && !entry.collect) {
84456
- this.settle(entry, {
84457
- status: "invalidated",
84458
- reason: entry.dispatched && entry.request.kind === "transaction" ? "the WalletConnect session disconnected after being asked to send this transaction \u2014 it may have broadcast. Check the chain (or your wallet's activity) before retrying, or you may pay twice." : "the WalletConnect session disconnected"
84459
- });
84460
- }
84461
- }
84462
- }
84463
- });
84758
+ const transport = await factory2(this.wcConfig);
84759
+ this.wcTransport = transport;
84760
+ transport.onSession((info) => info === null ? this.onWcDisconnect() : this.admitWcSession(info, transport));
84464
84761
  }
84465
84762
  const { uri, pairingId } = await this.wcTransport.createPairing();
84466
84763
  if (pairingId) {
84467
- this.pairingOwners.set(pairingId, askingSession);
84468
- while (this.pairingOwners.size > MAX_PENDING_PAIRINGS) {
84469
- const oldest = this.pairingOwners.keys().next();
84470
- if (oldest.done) break;
84471
- this.pairingOwners.delete(oldest.value);
84764
+ for (const [pending, owner] of this.pairingOwners) {
84765
+ if (owner === askingSession || !this.sessions.has(owner)) this.pairingOwners.delete(pending);
84472
84766
  }
84767
+ this.pairingOwners.set(pairingId, askingSession);
84473
84768
  }
84474
84769
  const { default: qrcode } = await import("qrcode-generator");
84475
84770
  const qr = qrcode(0, "M");
@@ -84570,12 +84865,7 @@ var SignatureBridge = class {
84570
84865
  return;
84571
84866
  }
84572
84867
  const statement = presenceStatement(this.publicOrigin(), chainId, session.presenceNonce);
84573
- let recovered = null;
84574
- try {
84575
- recovered = import_ethers50.ethers.verifyMessage(statement, signature);
84576
- } catch {
84577
- recovered = null;
84578
- }
84868
+ const recovered = recoverPresenceSigner(statement, signature);
84579
84869
  if (recovered === null || recovered.toLowerCase() !== account.toLowerCase()) {
84580
84870
  this.deny(
84581
84871
  res,
@@ -84666,6 +84956,100 @@ var SignatureBridge = class {
84666
84956
  * Those entries instead fail fast at the per-entry grace, since `attachedFor` now reads
84667
84957
  * false for them, and `unattendedReason` says plainly that the phone may already have
84668
84958
  * acted. */
84959
+ /**
84960
+ * C-47, the THIRD door: a wallet announced a WalletConnect session. `requestSignature`
84961
+ * PREFERS the WalletConnect wallet over the approval page (see the `wcActive` branch there),
84962
+ * so an account admitted here does not merely become the candidate — it becomes the SIGNER,
84963
+ * and the page that showed its QR becomes the page that sees every card.
84964
+ *
84965
+ * The account a WalletConnect session carries is the wallet's own UNSIGNED claim — the
84966
+ * protocol validates its format, never its ownership. Admitting on that claim let anyone
84967
+ * holding the approval link answer their own QR with a scripted wallet claiming the user's
84968
+ * public address: it took the signer seat, its page saw every card, and an extension-only
84969
+ * user's ceremonies were routed to it (Sentinel 2 PoC-D). So this door now asks for the same
84970
+ * proof `hello` does: the wallet signs the presence statement of the page whose QR it
84971
+ * answered, and the signature must recover to the account it claims.
84972
+ *
84973
+ * Resolves `false` to refuse — the transport then keeps what it held and drops the wallet. If
84974
+ * the wallet declines the proof (or the request fails) the promise rejects and the transport
84975
+ * ends the session unadopted; nothing here is adopted before the proof checks out.
84976
+ */
84977
+ async admitWcSession(info, transport) {
84978
+ const refusal = this.accountRefusal(info.account);
84979
+ if (refusal) return this.refuseWcSession(refusal);
84980
+ const ownerId = info.pairingId ? this.pairingOwners.get(info.pairingId) : void 0;
84981
+ if (info.pairingId) this.pairingOwners.delete(info.pairingId);
84982
+ const owner = ownerId ? this.sessions.get(ownerId) : void 0;
84983
+ if (!ownerId || !owner) {
84984
+ return this.refuseWcSession(
84985
+ "the wallet answered no QR code that an open approval page of this bridge showed \u2014 open the approval page and scan the QR code it shows"
84986
+ );
84987
+ }
84988
+ if (!info.prove || !info.live) {
84989
+ return this.refuseWcSession(
84990
+ "this WalletConnect transport cannot ask the wallet to prove its account (or report whether its session is still live), so no session can be admitted"
84991
+ );
84992
+ }
84993
+ const statement = presenceStatement(this.publicOrigin(), info.chainId, owner.presenceNonce);
84994
+ const signature = await info.prove(statement);
84995
+ const recovered = recoverPresenceSigner(statement, signature);
84996
+ if (recovered === null || recovered.toLowerCase() !== info.account.toLowerCase()) {
84997
+ return this.refuseWcSession(
84998
+ `the wallet claimed ${info.account} but ${recovered === null ? "returned no valid signature" : `signed with ${recovered}`} for the approval page's presence statement \u2014 an address alone proves nothing`
84999
+ );
85000
+ }
85001
+ if (this.wcTransport !== transport) {
85002
+ return this.refuseWcSession("the bridge's WalletConnect connection was replaced while the wallet was proving its account");
85003
+ }
85004
+ if (!info.live()) {
85005
+ return this.refuseWcSession("the wallet's WalletConnect session ended (or the relay failed) while it was proving its account \u2014 scan the QR again");
85006
+ }
85007
+ const lateRefusal = this.accountRefusal(info.account);
85008
+ if (lateRefusal) return this.refuseWcSession(lateRefusal);
85009
+ const page = this.sessions.get(ownerId);
85010
+ if (!page || page.refused) {
85011
+ return this.refuseWcSession("the approval page that showed this QR code closed while the wallet was proving its account \u2014 reopen it and scan again");
85012
+ }
85013
+ if (this.wcCreditedSession !== null && this.wcCreditedSession !== ownerId) {
85014
+ const previous = this.sessions.get(this.wcCreditedSession);
85015
+ if (previous) previous.wcPaired = false;
85016
+ }
85017
+ this.wcActive = true;
85018
+ this.wallet = { account: info.account, chainId: info.chainId };
85019
+ page.wcPaired = true;
85020
+ page.provenAccount = info.account;
85021
+ this.wcCreditedSession = ownerId;
85022
+ this.replayPending(page);
85023
+ return true;
85024
+ }
85025
+ /** Refuse a WalletConnect session — see `admitWcSession`. */
85026
+ refuseWcSession(reason) {
85027
+ if (!this.wcActive) {
85028
+ this.rebuildSharedWallet();
85029
+ this.demoteWcEntries();
85030
+ }
85031
+ process.stderr.write(`[bridge] WalletConnect session refused \u2014 ${reason}
85032
+ `);
85033
+ return false;
85034
+ }
85035
+ /** The admitted WalletConnect wallet went away. */
85036
+ onWcDisconnect() {
85037
+ this.wcActive = false;
85038
+ this.wallet = null;
85039
+ for (const entry of this.pending.values()) {
85040
+ if (!entry.settled && !entry.collect) {
85041
+ this.settle(entry, {
85042
+ status: "invalidated",
85043
+ reason: entry.dispatched && entry.request.kind === "transaction" ? "the WalletConnect session disconnected after being asked to send this transaction \u2014 it may have broadcast. Check the chain (or your wallet's activity) before retrying, or you may pay twice." : "the WalletConnect session disconnected"
85044
+ });
85045
+ }
85046
+ }
85047
+ if (this.wcCreditedSession !== null) {
85048
+ const credited = this.sessions.get(this.wcCreditedSession);
85049
+ if (credited) credited.wcPaired = false;
85050
+ this.wcCreditedSession = null;
85051
+ }
85052
+ }
84669
85053
  demoteWcEntries() {
84670
85054
  for (const entry of this.pending.values()) {
84671
85055
  if (entry.settled || entry.owner !== "wc" || entry.dispatched) continue;
@@ -84992,216 +85376,6 @@ data: ${JSON.stringify(payload)}
84992
85376
  }
84993
85377
  };
84994
85378
 
84995
- // src/boundary/config.ts
84996
- var NETWORKS = { sepolia: 11155111, mainnet: 1 };
84997
- var ADAPTERS = ["mock", "real"];
84998
- var LATENCIES = ["zero", "realistic"];
84999
- var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
85000
- var WC_DISABLED = "off";
85001
- function resolveWcProjectId(raw, problems) {
85002
- if (raw === void 0 || raw === "" || raw === WC_DISABLED) return void 0;
85003
- if (!/^[0-9a-f]{32}$/.test(raw)) {
85004
- problems.push(`DH_WC_PROJECT_ID must be a 32-char hex WalletConnect project id, or '${WC_DISABLED}' to disable WalletConnect.`);
85005
- return void 0;
85006
- }
85007
- return raw;
85008
- }
85009
- var RPC_PROXY_ORIGIN = "https://api.gvnr.xyz";
85010
- var rpcProxy = (chainId) => `${RPC_PROXY_ORIGIN}/v1/proxy/rpc/${chainId}`;
85011
- var NETWORK_DEFAULTS = {
85012
- sepolia: {
85013
- rpcUrl: rpcProxy(11155111),
85014
- serviceEndpoint: "https://ops-test.gvnr.xyz",
85015
- litNetwork: "chipotle",
85016
- validatorVersion: 3
85017
- // on-chain validator generation, sepolia (2026-07-30)
85018
- },
85019
- mainnet: {
85020
- rpcUrl: rpcProxy(1),
85021
- // Cutover 2026-09-08 — see sdk/src/constants/chunks/network-configs.ts for the full
85022
- // reasoning. Widening, not a rename: ops.gvnr.xyz serves the same broker and cannot be
85023
- // retired while installed copies call it. The sepolia entry above deliberately stays on
85024
- // ops-test.gvnr.xyz — there is no ops-test.diamondhands.credit twin (open decision 2).
85025
- serviceEndpoint: "https://ops.diamondhands.credit",
85026
- litNetwork: "chipotle",
85027
- // On-chain PKPValidation generation, mainnet (validatorForVersion(3) is the ONLY
85028
- // registered validator — verified live 2026-08-05). Without this the SDK defaults
85029
- // to 1 and createPosition reverts ValidatorNotConfigured in wallet simulation.
85030
- validatorVersion: 3
85031
- }
85032
- };
85033
- function resolveBoundaryConfig(env) {
85034
- const adapter2 = env["DH_ADAPTER"] === void 0 || env["DH_ADAPTER"] === "" ? "real" : env["DH_ADAPTER"];
85035
- if (!ADAPTERS.includes(adapter2)) {
85036
- return {
85037
- ok: false,
85038
- error: boundaryError(
85039
- "CONFIG_MISSING",
85040
- `DH_ADAPTER='${adapter2}' is not a valid adapter. Allowed: ${ADAPTERS.join(" | ")}.`,
85041
- { details: { invalid: ["DH_ADAPTER"] } }
85042
- )
85043
- };
85044
- }
85045
- if (adapter2 === "real") return resolveRealConfig(env);
85046
- const problems = [];
85047
- const missing = [];
85048
- const mockDb = env["DH_MOCK_DB"];
85049
- if (!mockDb) {
85050
- missing.push("DH_MOCK_DB");
85051
- problems.push("DH_MOCK_DB is not set (path of the mock world DB file).");
85052
- }
85053
- const latency = env["DH_MOCK_LATENCY"];
85054
- if (!latency) {
85055
- missing.push("DH_MOCK_LATENCY");
85056
- problems.push(`DH_MOCK_LATENCY is not set. Allowed: ${LATENCIES.join(" | ")}.`);
85057
- } else if (!LATENCIES.includes(latency)) {
85058
- problems.push(`DH_MOCK_LATENCY='${latency}' is invalid. Allowed: ${LATENCIES.join(" | ")}.`);
85059
- }
85060
- const borrower = env["DH_MOCK_BORROWER"];
85061
- if (borrower !== void 0 && borrower !== "" && !ADDRESS_RE.test(borrower)) {
85062
- problems.push(`DH_MOCK_BORROWER='${borrower}' is not a valid 0x address.`);
85063
- }
85064
- const SIGNER_MODES = ["external", "keystore", "mock-simulated"];
85065
- const signer = env["DH_SIGNER"];
85066
- if (signer !== void 0 && signer !== "" && !SIGNER_MODES.includes(signer)) {
85067
- problems.push(`DH_SIGNER='${signer}' is not supported for the mock adapter. Allowed: ${SIGNER_MODES.join(" | ")} (or unset).`);
85068
- }
85069
- let chainId;
85070
- const chainRaw = env["DH_MOCK_CHAIN_ID"];
85071
- if (chainRaw !== void 0 && chainRaw !== "") {
85072
- const n = Number(chainRaw);
85073
- if (!Number.isInteger(n) || n <= 0) {
85074
- problems.push(`DH_MOCK_CHAIN_ID='${chainRaw}' must be a positive integer.`);
85075
- } else {
85076
- chainId = n;
85077
- }
85078
- }
85079
- const sinkRpcUrl = env["DH_MOCK_SINK_RPC"];
85080
- if (sinkRpcUrl !== void 0 && sinkRpcUrl !== "" && !/^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?/.test(sinkRpcUrl)) {
85081
- problems.push(`DH_MOCK_SINK_RPC='${sinkRpcUrl}' must be a loopback http:// URL (the sink chain never leaves this machine).`);
85082
- }
85083
- const bridgeUrlFile = env["DH_BRIDGE_URL_FILE"];
85084
- const bridgeOpenRaw = env["DH_BRIDGE_OPEN"];
85085
- const wcProjectId = resolveWcProjectId(env["DH_WC_PROJECT_ID"], problems);
85086
- let bridgeOpenBrowser;
85087
- if (bridgeOpenRaw !== void 0 && bridgeOpenRaw !== "") {
85088
- if (bridgeOpenRaw !== "0" && bridgeOpenRaw !== "1") {
85089
- problems.push(`DH_BRIDGE_OPEN='${bridgeOpenRaw}' must be 0 or 1.`);
85090
- } else {
85091
- bridgeOpenBrowser = bridgeOpenRaw === "1";
85092
- }
85093
- }
85094
- const keystorePath = env["DH_KEYSTORE_PATH"];
85095
- const keystorePassword = env["DH_KEYSTORE_PASSWORD"];
85096
- if (keystorePath && !keystorePassword || !keystorePath && keystorePassword) {
85097
- problems.push("DH_KEYSTORE_PATH and DH_KEYSTORE_PASSWORD must be set together (or neither).");
85098
- }
85099
- if (problems.length > 0) {
85100
- return {
85101
- ok: false,
85102
- error: boundaryError("CONFIG_MISSING", `Mock boundary configuration is incomplete:
85103
- - ${problems.join("\n- ")}`, {
85104
- details: { missing }
85105
- })
85106
- };
85107
- }
85108
- return {
85109
- ok: true,
85110
- config: {
85111
- adapter: "mock",
85112
- mockDb,
85113
- latency,
85114
- ...borrower ? { borrower } : {},
85115
- ...signer ? { signer } : {},
85116
- chainId: chainId ?? 1337,
85117
- ...sinkRpcUrl ? { sinkRpcUrl } : {},
85118
- ...bridgeUrlFile ? { bridgeUrlFile } : {},
85119
- ...bridgeOpenBrowser !== void 0 ? { bridgeOpenBrowser } : {},
85120
- ...wcProjectId ? { wcProjectId } : {},
85121
- ...keystorePath && keystorePassword ? { keystorePath, keystorePassword } : {}
85122
- }
85123
- };
85124
- }
85125
- function resolveRealConfig(env) {
85126
- const problems = [];
85127
- const missing = [];
85128
- const signer = env["DH_SIGNER"];
85129
- if (signer !== void 0 && signer !== "") {
85130
- if (signer === "mock-simulated") {
85131
- problems.push(
85132
- "DH_SIGNER='mock-simulated' is the test-world stand-in ceremony and cannot authorize real-protocol operations. On the real adapter use 'external' (your own wallet) or 'keystore', or DH_ADAPTER=mock."
85133
- );
85134
- } else if (signer !== "external" && signer !== "keystore") {
85135
- problems.push(`DH_SIGNER='${signer}' is not supported for the real adapter. Allowed: external | keystore (or unset).`);
85136
- }
85137
- }
85138
- const network = env["DH_NETWORK"] === void 0 || env["DH_NETWORK"] === "" ? "mainnet" : env["DH_NETWORK"];
85139
- if (NETWORKS[network] === void 0) {
85140
- problems.push(`DH_NETWORK='${network}' is not supported. Allowed: ${Object.keys(NETWORKS).join(" | ")}.`);
85141
- }
85142
- const defaults2 = NETWORK_DEFAULTS[network] ?? NETWORK_DEFAULTS.mainnet;
85143
- const rpcUrl = env["ETH_RPC_URL"] || defaults2.rpcUrl;
85144
- const serviceEndpoint = env["DH_SERVICE_ENDPOINT"] || defaults2.serviceEndpoint;
85145
- if (!/^https:\/\//.test(serviceEndpoint) && !/^http:\/\/(localhost|127\.0\.0\.1)/.test(serviceEndpoint)) {
85146
- problems.push(`DH_SERVICE_ENDPOINT='${serviceEndpoint}' must be https:// (or http:// on loopback).`);
85147
- }
85148
- const litNetwork = env["DH_LIT_NETWORK"] || defaults2.litNetwork;
85149
- const keystorePath = env["DH_KEYSTORE_PATH"];
85150
- const keystorePassword = env["DH_KEYSTORE_PASSWORD"];
85151
- if (keystorePath && !keystorePassword || !keystorePath && keystorePassword) {
85152
- problems.push("DH_KEYSTORE_PATH and DH_KEYSTORE_PASSWORD must be set together (or neither).");
85153
- }
85154
- const stateDir = env["DH_STATE_DIR"];
85155
- const bridgeUrlFile = env["DH_BRIDGE_URL_FILE"];
85156
- const bridgeOpenRaw = env["DH_BRIDGE_OPEN"];
85157
- const wcProjectId = resolveWcProjectId(env["DH_WC_PROJECT_ID"], problems);
85158
- let bridgeOpenBrowser;
85159
- if (bridgeOpenRaw !== void 0 && bridgeOpenRaw !== "") {
85160
- if (bridgeOpenRaw !== "0" && bridgeOpenRaw !== "1") {
85161
- problems.push(`DH_BRIDGE_OPEN='${bridgeOpenRaw}' must be 0 or 1.`);
85162
- } else {
85163
- bridgeOpenBrowser = bridgeOpenRaw === "1";
85164
- }
85165
- }
85166
- const validatorRaw = env["DH_VALIDATOR_VERSION"];
85167
- let validatorVersion = defaults2.validatorVersion;
85168
- if (validatorRaw !== void 0 && validatorRaw !== "") {
85169
- const n = Number(validatorRaw);
85170
- if (!Number.isInteger(n) || n <= 0) {
85171
- problems.push(`DH_VALIDATOR_VERSION='${validatorRaw}' must be a positive integer.`);
85172
- } else {
85173
- validatorVersion = n;
85174
- }
85175
- }
85176
- if (problems.length > 0) {
85177
- return {
85178
- ok: false,
85179
- error: boundaryError("CONFIG_MISSING", `Real boundary configuration is incomplete:
85180
- - ${problems.join("\n- ")}`, {
85181
- details: { missing }
85182
- })
85183
- };
85184
- }
85185
- return {
85186
- ok: true,
85187
- config: {
85188
- adapter: "real",
85189
- network,
85190
- chainId: NETWORKS[network],
85191
- rpcUrl,
85192
- serviceEndpoint,
85193
- litNetwork,
85194
- ...keystorePath && keystorePassword ? { keystorePath, keystorePassword } : {},
85195
- ...signer === "external" || signer === "keystore" ? { signer } : {},
85196
- ...stateDir ? { stateDir } : {},
85197
- ...bridgeUrlFile ? { bridgeUrlFile } : {},
85198
- ...bridgeOpenBrowser !== void 0 ? { bridgeOpenBrowser } : {},
85199
- ...wcProjectId ? { wcProjectId } : {},
85200
- ...validatorVersion !== void 0 ? { validatorVersion } : {}
85201
- }
85202
- };
85203
- }
85204
-
85205
85379
  // src/boundary/index.ts
85206
85380
  function fileSignerPersistence(filePath) {
85207
85381
  return {
@@ -85359,7 +85533,10 @@ async function createRealBoundary(config, wallet, overrides) {
85359
85533
  const chainName = config.network === "mainnet" ? "Ethereum Mainnet" : "Sepolia";
85360
85534
  const bridge = new SignatureBridge({
85361
85535
  ...config.bridgeUrlFile ? { urlFile: config.bridgeUrlFile } : {},
85362
- network: { chainId: config.chainId, chainName, rpcUrl: config.rpcUrl },
85536
+ // The page's wallet_addEthereumChain gets the PUBLIC proxy, never config.rpcUrl: the
85537
+ // server's endpoint is a server credential, and the page would save it into the
85538
+ // user's wallet.
85539
+ network: { chainId: config.chainId, chainName, rpcUrl: publicRpcUrl(config.chainId) },
85363
85540
  ...config.wcProjectId ? { wc: { projectId: config.wcProjectId, chainId: config.chainId } } : {},
85364
85541
  // Plan 17 E2 (SVC-OPS-08): the HOSTED tier caps ceremonies at concurrent-1 per
85365
85542
  // tenant — one bridge per tenant world, so the bridge cap IS the tenant cap. The
@@ -85384,7 +85561,7 @@ async function createRealBoundary(config, wallet, overrides) {
85384
85561
  const manager = new SignerManager({
85385
85562
  persistence: overrides?.signerPersistence?.(config.network) ?? fileSignerPersistence(stateFile),
85386
85563
  initialMode,
85387
- ...overrides?.boundBorrower ? { authenticatedBorrower: import_ethers51.ethers.getAddress(overrides.boundBorrower) } : {},
85564
+ ...overrides?.boundBorrower ? { authenticatedBorrower: import_ethers52.ethers.getAddress(overrides.boundBorrower) } : {},
85388
85565
  candidate: () => bridge.walletState()?.account ?? null,
85389
85566
  pendingCeremonies: () => bridge.pendingCount(),
85390
85567
  keystore