@gvnrdao/dh-mcp 0.5.21 → 0.5.22
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 +207 -62
- package/dist/connector-embed.js +474 -329
- package/dist/connector.js +474 -329
- package/dist/index.js +217 -72
- package/package.json +2 -2
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
|
|
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
|
-
...
|
|
18462
|
+
...import_ethers53.ethers,
|
|
18463
18463
|
providers: {
|
|
18464
|
-
StaticJsonRpcProvider:
|
|
18464
|
+
StaticJsonRpcProvider: import_ethers53.ethers.JsonRpcProvider
|
|
18465
18465
|
},
|
|
18466
|
-
Contract:
|
|
18467
|
-
utils:
|
|
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 = {
|
|
@@ -28308,7 +28308,7 @@ var require_lit_ops_module = __commonJS({
|
|
|
28308
28308
|
async chipotleCreateWalletAndAddToGroup(accountApiKey) {
|
|
28309
28309
|
const baseUrl = _LitOps.LIT_CORE_API_BASE;
|
|
28310
28310
|
const createResp = await fetch(`${baseUrl}/create_wallet`, {
|
|
28311
|
-
method: "
|
|
28311
|
+
method: "POST",
|
|
28312
28312
|
headers: {
|
|
28313
28313
|
"X-Api-Key": accountApiKey
|
|
28314
28314
|
}
|
|
@@ -40728,6 +40728,7 @@ __export(wc_transport_exports, {
|
|
|
40728
40728
|
WC_DAPP_METADATA: () => WC_DAPP_METADATA,
|
|
40729
40729
|
WC_SESSION_METHODS: () => WC_SESSION_METHODS,
|
|
40730
40730
|
WcTransport: () => WcTransport,
|
|
40731
|
+
guardRelayFatal: () => guardRelayFatal,
|
|
40731
40732
|
newIsolatedCore: () => newIsolatedCore,
|
|
40732
40733
|
wcSessionNamespaces: () => wcSessionNamespaces,
|
|
40733
40734
|
withEip712DomainType: () => withEip712DomainType
|
|
@@ -40761,7 +40762,27 @@ function newIsolatedCore(cfg, label) {
|
|
|
40761
40762
|
});
|
|
40762
40763
|
return { core, scratch };
|
|
40763
40764
|
}
|
|
40764
|
-
|
|
40765
|
+
function guardRelayFatal(core, health, onFatal) {
|
|
40766
|
+
const relayer = core.relayer;
|
|
40767
|
+
const register = relayer.registerProviderListeners;
|
|
40768
|
+
if (typeof register !== "function") {
|
|
40769
|
+
throw new Error(
|
|
40770
|
+
"@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."
|
|
40771
|
+
);
|
|
40772
|
+
}
|
|
40773
|
+
const record = (e) => {
|
|
40774
|
+
if (health.fatal !== null) return;
|
|
40775
|
+
health.fatal = e.message;
|
|
40776
|
+
console.error(`[dh-mcp] WalletConnect relay failed fatally: ${e.message}`);
|
|
40777
|
+
onFatal(e.message);
|
|
40778
|
+
};
|
|
40779
|
+
relayer.on("relayer_error", record);
|
|
40780
|
+
relayer.registerProviderListeners = () => {
|
|
40781
|
+
register.call(relayer);
|
|
40782
|
+
relayer.provider.on("error", record);
|
|
40783
|
+
};
|
|
40784
|
+
}
|
|
40785
|
+
var import_core, import_sign_client, os, path3, import_node_fs, import_ethers50, WC_SESSION_METHODS, WC_DAPP_METADATA, EVENTS, WcTransport;
|
|
40765
40786
|
var init_wc_transport = __esm({
|
|
40766
40787
|
"src/boundary/upstream/shared/external-bridge/wc-transport.ts"() {
|
|
40767
40788
|
"use strict";
|
|
@@ -40770,6 +40791,7 @@ var init_wc_transport = __esm({
|
|
|
40770
40791
|
os = __toESM(require("os"));
|
|
40771
40792
|
path3 = __toESM(require("path"));
|
|
40772
40793
|
import_node_fs = require("fs");
|
|
40794
|
+
import_ethers50 = require("ethers");
|
|
40773
40795
|
WC_SESSION_METHODS = ["personal_sign", "eth_signTypedData_v4", "eth_sendTransaction"];
|
|
40774
40796
|
WC_DAPP_METADATA = {
|
|
40775
40797
|
name: "Diamond Hands MCP",
|
|
@@ -40779,11 +40801,14 @@ var init_wc_transport = __esm({
|
|
|
40779
40801
|
};
|
|
40780
40802
|
EVENTS = ["accountsChanged", "chainChanged"];
|
|
40781
40803
|
WcTransport = class _WcTransport {
|
|
40782
|
-
constructor(client, cfg, scratch) {
|
|
40804
|
+
constructor(client, cfg, scratch, health) {
|
|
40783
40805
|
this.client = client;
|
|
40784
40806
|
this.cfg = cfg;
|
|
40785
40807
|
this.scratch = scratch;
|
|
40808
|
+
this.health = health;
|
|
40786
40809
|
client.on("session_delete", ({ topic }) => {
|
|
40810
|
+
const pending = this.candidates.get(topic);
|
|
40811
|
+
if (pending) pending.deleted = true;
|
|
40787
40812
|
if (this.session === null || this.session.topic !== topic) return;
|
|
40788
40813
|
this.session = null;
|
|
40789
40814
|
this.sessionListener?.(null);
|
|
@@ -40791,14 +40816,35 @@ var init_wc_transport = __esm({
|
|
|
40791
40816
|
}
|
|
40792
40817
|
session = null;
|
|
40793
40818
|
sessionListener = null;
|
|
40819
|
+
/** Sessions announced but not yet adopted (awaiting a deferred verdict), by topic. */
|
|
40820
|
+
candidates = /* @__PURE__ */ new Map();
|
|
40794
40821
|
static async create(cfg) {
|
|
40795
40822
|
const { core, scratch } = newIsolatedCore(cfg, "dh-wc-dapp");
|
|
40823
|
+
const health = { fatal: null };
|
|
40824
|
+
let transport = null;
|
|
40825
|
+
guardRelayFatal(core, health, () => transport?.dropForFatal());
|
|
40796
40826
|
const client = await import_sign_client.default.init({
|
|
40797
40827
|
core,
|
|
40798
40828
|
projectId: cfg.projectId,
|
|
40799
40829
|
metadata: cfg.metadata ?? WC_DAPP_METADATA
|
|
40800
40830
|
});
|
|
40801
|
-
|
|
40831
|
+
transport = new _WcTransport(client, cfg, scratch, health);
|
|
40832
|
+
return transport;
|
|
40833
|
+
}
|
|
40834
|
+
/** The relay is gone for good: no adopted session may outlive it. Listeners hear a
|
|
40835
|
+
* disconnect, exactly as if the wallet had left. */
|
|
40836
|
+
dropForFatal() {
|
|
40837
|
+
if (this.session === null) return;
|
|
40838
|
+
this.session = null;
|
|
40839
|
+
void this.sessionListener?.(null);
|
|
40840
|
+
}
|
|
40841
|
+
/** Refuse to start new work over a relay that has failed fatally — naming why. */
|
|
40842
|
+
assertRelayHealthy() {
|
|
40843
|
+
if (this.health.fatal !== null) {
|
|
40844
|
+
throw new Error(
|
|
40845
|
+
`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`
|
|
40846
|
+
);
|
|
40847
|
+
}
|
|
40802
40848
|
}
|
|
40803
40849
|
/** Wallet-session state changes (connect/disconnect) — the bridge mirrors them. */
|
|
40804
40850
|
onSession(cb) {
|
|
@@ -40809,6 +40855,7 @@ var init_wc_transport = __esm({
|
|
|
40809
40855
|
}
|
|
40810
40856
|
/** Create a pairing URI; resolves the session in the background when a wallet approves. */
|
|
40811
40857
|
async createPairing() {
|
|
40858
|
+
this.assertRelayHealthy();
|
|
40812
40859
|
const { uri, approval } = await this.client.connect({
|
|
40813
40860
|
// sign-client 2.21 deprecates requiredNamespaces (auto-downgraded to optional).
|
|
40814
40861
|
optionalNamespaces: wcSessionNamespaces(this.cfg.chainId)
|
|
@@ -40816,22 +40863,51 @@ var init_wc_transport = __esm({
|
|
|
40816
40863
|
if (!uri) throw new Error("WalletConnect returned no pairing URI");
|
|
40817
40864
|
const pairingId = /^wc:([0-9a-f]+)@/i.exec(uri)?.[1];
|
|
40818
40865
|
if (!pairingId) throw new Error(`WalletConnect pairing URI has no recognisable topic: ${uri.slice(0, 12)}\u2026`);
|
|
40819
|
-
|
|
40866
|
+
let candidateTopic = null;
|
|
40867
|
+
void approval().then(async (session) => {
|
|
40820
40868
|
const first = session.namespaces["eip155"]?.accounts[0];
|
|
40821
40869
|
if (!first) throw new Error("WalletConnect session carries no eip155 account");
|
|
40822
40870
|
const [, chainIdStr, account] = first.split(":");
|
|
40871
|
+
candidateTopic = session.topic;
|
|
40872
|
+
const candidate = { topic: session.topic, account, chainId: Number(chainIdStr) };
|
|
40873
|
+
const prove = async (statement) => {
|
|
40874
|
+
this.assertRelayHealthy();
|
|
40875
|
+
return await this.client.request({
|
|
40876
|
+
topic: candidate.topic,
|
|
40877
|
+
chainId: `eip155:${candidate.chainId}`,
|
|
40878
|
+
request: { method: "personal_sign", params: [import_ethers50.ethers.hexlify(import_ethers50.ethers.toUtf8Bytes(statement)), candidate.account] }
|
|
40879
|
+
});
|
|
40880
|
+
};
|
|
40881
|
+
const state = { deleted: false };
|
|
40882
|
+
const live = () => !state.deleted && this.health.fatal === null;
|
|
40823
40883
|
const previous = this.session;
|
|
40824
|
-
this.session =
|
|
40825
|
-
|
|
40826
|
-
|
|
40884
|
+
this.session = candidate;
|
|
40885
|
+
this.candidates.set(candidate.topic, state);
|
|
40886
|
+
const verdict = this.sessionListener?.({ account: candidate.account, chainId: candidate.chainId, pairingId, prove, live });
|
|
40887
|
+
let adopted;
|
|
40888
|
+
if (verdict instanceof Promise) {
|
|
40827
40889
|
this.session = previous;
|
|
40890
|
+
adopted = await verdict.finally(() => this.candidates.delete(candidate.topic)).then((v) => v !== false);
|
|
40891
|
+
if (adopted) this.session = candidate;
|
|
40892
|
+
} else {
|
|
40893
|
+
this.candidates.delete(candidate.topic);
|
|
40894
|
+
adopted = verdict !== false;
|
|
40895
|
+
if (!adopted) this.session = previous;
|
|
40896
|
+
}
|
|
40897
|
+
if (!adopted) {
|
|
40828
40898
|
void this.client.disconnect({ topic: session.topic, reason: { code: 6e3, message: "session refused by the bridge" } }).catch(() => void 0);
|
|
40829
40899
|
}
|
|
40830
|
-
}).catch((e) =>
|
|
40900
|
+
}).catch((e) => {
|
|
40901
|
+
console.error(`[dh-mcp] WalletConnect pairing failed: ${e.message}`);
|
|
40902
|
+
if (candidateTopic !== null && this.session?.topic !== candidateTopic) {
|
|
40903
|
+
void this.client.disconnect({ topic: candidateTopic, reason: { code: 6e3, message: "session not adopted" } }).catch(() => void 0);
|
|
40904
|
+
}
|
|
40905
|
+
});
|
|
40831
40906
|
return { uri, pairingId };
|
|
40832
40907
|
}
|
|
40833
40908
|
/** Route one wallet request over the active session. Throws on user rejection. */
|
|
40834
40909
|
async request(method, params) {
|
|
40910
|
+
this.assertRelayHealthy();
|
|
40835
40911
|
if (!this.session) throw new Error("no active WalletConnect session");
|
|
40836
40912
|
return this.client.request({
|
|
40837
40913
|
topic: this.session.topic,
|
|
@@ -40863,7 +40939,7 @@ var import_node_crypto8 = require("crypto");
|
|
|
40863
40939
|
var fs5 = __toESM(require("fs"));
|
|
40864
40940
|
var os2 = __toESM(require("os"));
|
|
40865
40941
|
var path4 = __toESM(require("path"));
|
|
40866
|
-
var
|
|
40942
|
+
var import_ethers52 = require("ethers");
|
|
40867
40943
|
|
|
40868
40944
|
// src/boundary/envelope.ts
|
|
40869
40945
|
function okEnvelope(data, source, warnings = []) {
|
|
@@ -83299,7 +83375,7 @@ var RealUpstreamPlugin = class {
|
|
|
83299
83375
|
var fs4 = __toESM(require("fs"));
|
|
83300
83376
|
var http3 = __toESM(require("http"));
|
|
83301
83377
|
var import_node_crypto7 = require("crypto");
|
|
83302
|
-
var
|
|
83378
|
+
var import_ethers51 = require("ethers");
|
|
83303
83379
|
|
|
83304
83380
|
// src/util/brand-assets.ts
|
|
83305
83381
|
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 +83500,7 @@ ${houseHeader("Diamond Hands \xB7 signature approval")}
|
|
|
83424
83500
|
<button id="wc-connect" class="btn-secondary">Use a mobile wallet instead (WalletConnect)</button>
|
|
83425
83501
|
<div id="wc-qr" class="qr-plate hidden"></div>
|
|
83426
83502
|
<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>
|
|
83503
|
+
<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
83504
|
</div>
|
|
83429
83505
|
</div>
|
|
83430
83506
|
</main>
|
|
@@ -83771,7 +83847,7 @@ document.getElementById("wc-connect").onclick = async () => {
|
|
|
83771
83847
|
qrEl.classList.remove("hidden");
|
|
83772
83848
|
}
|
|
83773
83849
|
document.getElementById("wc-hint").classList.remove("hidden");
|
|
83774
|
-
|
|
83850
|
+
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
83851
|
};
|
|
83776
83852
|
|
|
83777
83853
|
listen();
|
|
@@ -83883,7 +83959,6 @@ function htmlPageSecurityHeaders(extra) {
|
|
|
83883
83959
|
|
|
83884
83960
|
// src/boundary/upstream/shared/external-bridge/bridge.ts
|
|
83885
83961
|
var MAX_SESSIONS = 16;
|
|
83886
|
-
var MAX_PENDING_PAIRINGS = 64;
|
|
83887
83962
|
function presenceStatement(origin2, chainId, nonce) {
|
|
83888
83963
|
return [
|
|
83889
83964
|
"Diamond Hands approval page",
|
|
@@ -83893,6 +83968,13 @@ function presenceStatement(origin2, chainId, nonce) {
|
|
|
83893
83968
|
`Session nonce: ${nonce}`
|
|
83894
83969
|
].join("\n");
|
|
83895
83970
|
}
|
|
83971
|
+
function recoverPresenceSigner(statement, signature) {
|
|
83972
|
+
try {
|
|
83973
|
+
return import_ethers51.ethers.verifyMessage(statement, signature);
|
|
83974
|
+
} catch {
|
|
83975
|
+
return null;
|
|
83976
|
+
}
|
|
83977
|
+
}
|
|
83896
83978
|
var DEFAULT_EXPIRY_MS = 5 * 60 * 1e3;
|
|
83897
83979
|
var DEFAULT_ATTACH_GRACE_MS = 60 * 1e3;
|
|
83898
83980
|
var DEFAULT_HOSTED_ATTACH_GRACE_MS = 180 * 1e3;
|
|
@@ -83942,6 +84024,10 @@ var SignatureBridge = class {
|
|
|
83942
84024
|
* "most recent asker" guess let a second session claim the credit for a QR the user's
|
|
83943
84025
|
* phone scanned (Sentinel 2 PoC-B). */
|
|
83944
84026
|
pairingOwners = /* @__PURE__ */ new Map();
|
|
84027
|
+
/** The page session the ADMITTED WalletConnect session's proof was made for — the one page
|
|
84028
|
+
* credited with `wcPaired`. The credit lasts exactly as long as that session: it moves when
|
|
84029
|
+
* another proven session replaces it and ends when the wallet disconnects. */
|
|
84030
|
+
wcCreditedSession = null;
|
|
83945
84031
|
keystoreUnlock;
|
|
83946
84032
|
unlockToken = null;
|
|
83947
84033
|
unlockSession = null;
|
|
@@ -84430,46 +84516,16 @@ var SignatureBridge = class {
|
|
|
84430
84516
|
const { WcTransport: WcTransport2 } = await Promise.resolve().then(() => (init_wc_transport(), wc_transport_exports));
|
|
84431
84517
|
return WcTransport2.create(cfg);
|
|
84432
84518
|
});
|
|
84433
|
-
|
|
84434
|
-
this.wcTransport
|
|
84435
|
-
|
|
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
|
-
});
|
|
84519
|
+
const transport = await factory2(this.wcConfig);
|
|
84520
|
+
this.wcTransport = transport;
|
|
84521
|
+
transport.onSession((info) => info === null ? this.onWcDisconnect() : this.admitWcSession(info, transport));
|
|
84464
84522
|
}
|
|
84465
84523
|
const { uri, pairingId } = await this.wcTransport.createPairing();
|
|
84466
84524
|
if (pairingId) {
|
|
84467
|
-
this.pairingOwners
|
|
84468
|
-
|
|
84469
|
-
const oldest = this.pairingOwners.keys().next();
|
|
84470
|
-
if (oldest.done) break;
|
|
84471
|
-
this.pairingOwners.delete(oldest.value);
|
|
84525
|
+
for (const [pending, owner] of this.pairingOwners) {
|
|
84526
|
+
if (owner === askingSession || !this.sessions.has(owner)) this.pairingOwners.delete(pending);
|
|
84472
84527
|
}
|
|
84528
|
+
this.pairingOwners.set(pairingId, askingSession);
|
|
84473
84529
|
}
|
|
84474
84530
|
const { default: qrcode } = await import("qrcode-generator");
|
|
84475
84531
|
const qr = qrcode(0, "M");
|
|
@@ -84570,12 +84626,7 @@ var SignatureBridge = class {
|
|
|
84570
84626
|
return;
|
|
84571
84627
|
}
|
|
84572
84628
|
const statement = presenceStatement(this.publicOrigin(), chainId, session.presenceNonce);
|
|
84573
|
-
|
|
84574
|
-
try {
|
|
84575
|
-
recovered = import_ethers50.ethers.verifyMessage(statement, signature);
|
|
84576
|
-
} catch {
|
|
84577
|
-
recovered = null;
|
|
84578
|
-
}
|
|
84629
|
+
const recovered = recoverPresenceSigner(statement, signature);
|
|
84579
84630
|
if (recovered === null || recovered.toLowerCase() !== account.toLowerCase()) {
|
|
84580
84631
|
this.deny(
|
|
84581
84632
|
res,
|
|
@@ -84666,6 +84717,100 @@ var SignatureBridge = class {
|
|
|
84666
84717
|
* Those entries instead fail fast at the per-entry grace, since `attachedFor` now reads
|
|
84667
84718
|
* false for them, and `unattendedReason` says plainly that the phone may already have
|
|
84668
84719
|
* acted. */
|
|
84720
|
+
/**
|
|
84721
|
+
* C-47, the THIRD door: a wallet announced a WalletConnect session. `requestSignature`
|
|
84722
|
+
* PREFERS the WalletConnect wallet over the approval page (see the `wcActive` branch there),
|
|
84723
|
+
* so an account admitted here does not merely become the candidate — it becomes the SIGNER,
|
|
84724
|
+
* and the page that showed its QR becomes the page that sees every card.
|
|
84725
|
+
*
|
|
84726
|
+
* The account a WalletConnect session carries is the wallet's own UNSIGNED claim — the
|
|
84727
|
+
* protocol validates its format, never its ownership. Admitting on that claim let anyone
|
|
84728
|
+
* holding the approval link answer their own QR with a scripted wallet claiming the user's
|
|
84729
|
+
* public address: it took the signer seat, its page saw every card, and an extension-only
|
|
84730
|
+
* user's ceremonies were routed to it (Sentinel 2 PoC-D). So this door now asks for the same
|
|
84731
|
+
* proof `hello` does: the wallet signs the presence statement of the page whose QR it
|
|
84732
|
+
* answered, and the signature must recover to the account it claims.
|
|
84733
|
+
*
|
|
84734
|
+
* Resolves `false` to refuse — the transport then keeps what it held and drops the wallet. If
|
|
84735
|
+
* the wallet declines the proof (or the request fails) the promise rejects and the transport
|
|
84736
|
+
* ends the session unadopted; nothing here is adopted before the proof checks out.
|
|
84737
|
+
*/
|
|
84738
|
+
async admitWcSession(info, transport) {
|
|
84739
|
+
const refusal = this.accountRefusal(info.account);
|
|
84740
|
+
if (refusal) return this.refuseWcSession(refusal);
|
|
84741
|
+
const ownerId = info.pairingId ? this.pairingOwners.get(info.pairingId) : void 0;
|
|
84742
|
+
if (info.pairingId) this.pairingOwners.delete(info.pairingId);
|
|
84743
|
+
const owner = ownerId ? this.sessions.get(ownerId) : void 0;
|
|
84744
|
+
if (!ownerId || !owner) {
|
|
84745
|
+
return this.refuseWcSession(
|
|
84746
|
+
"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"
|
|
84747
|
+
);
|
|
84748
|
+
}
|
|
84749
|
+
if (!info.prove || !info.live) {
|
|
84750
|
+
return this.refuseWcSession(
|
|
84751
|
+
"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"
|
|
84752
|
+
);
|
|
84753
|
+
}
|
|
84754
|
+
const statement = presenceStatement(this.publicOrigin(), info.chainId, owner.presenceNonce);
|
|
84755
|
+
const signature = await info.prove(statement);
|
|
84756
|
+
const recovered = recoverPresenceSigner(statement, signature);
|
|
84757
|
+
if (recovered === null || recovered.toLowerCase() !== info.account.toLowerCase()) {
|
|
84758
|
+
return this.refuseWcSession(
|
|
84759
|
+
`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`
|
|
84760
|
+
);
|
|
84761
|
+
}
|
|
84762
|
+
if (this.wcTransport !== transport) {
|
|
84763
|
+
return this.refuseWcSession("the bridge's WalletConnect connection was replaced while the wallet was proving its account");
|
|
84764
|
+
}
|
|
84765
|
+
if (!info.live()) {
|
|
84766
|
+
return this.refuseWcSession("the wallet's WalletConnect session ended (or the relay failed) while it was proving its account \u2014 scan the QR again");
|
|
84767
|
+
}
|
|
84768
|
+
const lateRefusal = this.accountRefusal(info.account);
|
|
84769
|
+
if (lateRefusal) return this.refuseWcSession(lateRefusal);
|
|
84770
|
+
const page = this.sessions.get(ownerId);
|
|
84771
|
+
if (!page || page.refused) {
|
|
84772
|
+
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");
|
|
84773
|
+
}
|
|
84774
|
+
if (this.wcCreditedSession !== null && this.wcCreditedSession !== ownerId) {
|
|
84775
|
+
const previous = this.sessions.get(this.wcCreditedSession);
|
|
84776
|
+
if (previous) previous.wcPaired = false;
|
|
84777
|
+
}
|
|
84778
|
+
this.wcActive = true;
|
|
84779
|
+
this.wallet = { account: info.account, chainId: info.chainId };
|
|
84780
|
+
page.wcPaired = true;
|
|
84781
|
+
page.provenAccount = info.account;
|
|
84782
|
+
this.wcCreditedSession = ownerId;
|
|
84783
|
+
this.replayPending(page);
|
|
84784
|
+
return true;
|
|
84785
|
+
}
|
|
84786
|
+
/** Refuse a WalletConnect session — see `admitWcSession`. */
|
|
84787
|
+
refuseWcSession(reason) {
|
|
84788
|
+
if (!this.wcActive) {
|
|
84789
|
+
this.rebuildSharedWallet();
|
|
84790
|
+
this.demoteWcEntries();
|
|
84791
|
+
}
|
|
84792
|
+
process.stderr.write(`[bridge] WalletConnect session refused \u2014 ${reason}
|
|
84793
|
+
`);
|
|
84794
|
+
return false;
|
|
84795
|
+
}
|
|
84796
|
+
/** The admitted WalletConnect wallet went away. */
|
|
84797
|
+
onWcDisconnect() {
|
|
84798
|
+
this.wcActive = false;
|
|
84799
|
+
this.wallet = null;
|
|
84800
|
+
for (const entry of this.pending.values()) {
|
|
84801
|
+
if (!entry.settled && !entry.collect) {
|
|
84802
|
+
this.settle(entry, {
|
|
84803
|
+
status: "invalidated",
|
|
84804
|
+
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"
|
|
84805
|
+
});
|
|
84806
|
+
}
|
|
84807
|
+
}
|
|
84808
|
+
if (this.wcCreditedSession !== null) {
|
|
84809
|
+
const credited = this.sessions.get(this.wcCreditedSession);
|
|
84810
|
+
if (credited) credited.wcPaired = false;
|
|
84811
|
+
this.wcCreditedSession = null;
|
|
84812
|
+
}
|
|
84813
|
+
}
|
|
84669
84814
|
demoteWcEntries() {
|
|
84670
84815
|
for (const entry of this.pending.values()) {
|
|
84671
84816
|
if (entry.settled || entry.owner !== "wc" || entry.dispatched) continue;
|
|
@@ -85384,7 +85529,7 @@ async function createRealBoundary(config, wallet, overrides) {
|
|
|
85384
85529
|
const manager = new SignerManager({
|
|
85385
85530
|
persistence: overrides?.signerPersistence?.(config.network) ?? fileSignerPersistence(stateFile),
|
|
85386
85531
|
initialMode,
|
|
85387
|
-
...overrides?.boundBorrower ? { authenticatedBorrower:
|
|
85532
|
+
...overrides?.boundBorrower ? { authenticatedBorrower: import_ethers52.ethers.getAddress(overrides.boundBorrower) } : {},
|
|
85388
85533
|
candidate: () => bridge.walletState()?.account ?? null,
|
|
85389
85534
|
pendingCeremonies: () => bridge.pendingCount(),
|
|
85390
85535
|
keystore
|