@gvnrdao/dh-mcp 0.5.20 → 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 +612 -111
- package/dist/connector-embed.js +1329 -495
- package/dist/connector.js +2673 -927
- package/dist/index.js +632 -124
- package/package.json +14 -3
package/dist/connector-embed.js
CHANGED
|
@@ -40,6 +40,7 @@ __export(wc_transport_exports, {
|
|
|
40
40
|
WC_DAPP_METADATA: () => WC_DAPP_METADATA,
|
|
41
41
|
WC_SESSION_METHODS: () => WC_SESSION_METHODS,
|
|
42
42
|
WcTransport: () => WcTransport,
|
|
43
|
+
guardRelayFatal: () => guardRelayFatal,
|
|
43
44
|
newIsolatedCore: () => newIsolatedCore,
|
|
44
45
|
wcSessionNamespaces: () => wcSessionNamespaces,
|
|
45
46
|
withEip712DomainType: () => withEip712DomainType
|
|
@@ -73,7 +74,27 @@ function newIsolatedCore(cfg, label) {
|
|
|
73
74
|
});
|
|
74
75
|
return { core, scratch };
|
|
75
76
|
}
|
|
76
|
-
|
|
77
|
+
function guardRelayFatal(core, health, onFatal) {
|
|
78
|
+
const relayer = core.relayer;
|
|
79
|
+
const register = relayer.registerProviderListeners;
|
|
80
|
+
if (typeof register !== "function") {
|
|
81
|
+
throw new Error(
|
|
82
|
+
"@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."
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
const record = (e) => {
|
|
86
|
+
if (health.fatal !== null) return;
|
|
87
|
+
health.fatal = e.message;
|
|
88
|
+
console.error(`[dh-mcp] WalletConnect relay failed fatally: ${e.message}`);
|
|
89
|
+
onFatal(e.message);
|
|
90
|
+
};
|
|
91
|
+
relayer.on("relayer_error", record);
|
|
92
|
+
relayer.registerProviderListeners = () => {
|
|
93
|
+
register.call(relayer);
|
|
94
|
+
relayer.provider.on("error", record);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
var import_core, import_sign_client, os, path, import_node_fs, import_ethers, WC_SESSION_METHODS, WC_DAPP_METADATA, EVENTS, WcTransport;
|
|
77
98
|
var init_wc_transport = __esm({
|
|
78
99
|
"src/boundary/upstream/shared/external-bridge/wc-transport.ts"() {
|
|
79
100
|
"use strict";
|
|
@@ -82,6 +103,7 @@ var init_wc_transport = __esm({
|
|
|
82
103
|
os = __toESM(require("os"));
|
|
83
104
|
path = __toESM(require("path"));
|
|
84
105
|
import_node_fs = require("fs");
|
|
106
|
+
import_ethers = require("ethers");
|
|
85
107
|
WC_SESSION_METHODS = ["personal_sign", "eth_signTypedData_v4", "eth_sendTransaction"];
|
|
86
108
|
WC_DAPP_METADATA = {
|
|
87
109
|
name: "Diamond Hands MCP",
|
|
@@ -91,25 +113,50 @@ var init_wc_transport = __esm({
|
|
|
91
113
|
};
|
|
92
114
|
EVENTS = ["accountsChanged", "chainChanged"];
|
|
93
115
|
WcTransport = class _WcTransport {
|
|
94
|
-
constructor(client, cfg, scratch) {
|
|
116
|
+
constructor(client, cfg, scratch, health) {
|
|
95
117
|
this.client = client;
|
|
96
118
|
this.cfg = cfg;
|
|
97
119
|
this.scratch = scratch;
|
|
98
|
-
|
|
120
|
+
this.health = health;
|
|
121
|
+
client.on("session_delete", ({ topic }) => {
|
|
122
|
+
const pending = this.candidates.get(topic);
|
|
123
|
+
if (pending) pending.deleted = true;
|
|
124
|
+
if (this.session === null || this.session.topic !== topic) return;
|
|
99
125
|
this.session = null;
|
|
100
126
|
this.sessionListener?.(null);
|
|
101
127
|
});
|
|
102
128
|
}
|
|
103
129
|
session = null;
|
|
104
130
|
sessionListener = null;
|
|
131
|
+
/** Sessions announced but not yet adopted (awaiting a deferred verdict), by topic. */
|
|
132
|
+
candidates = /* @__PURE__ */ new Map();
|
|
105
133
|
static async create(cfg) {
|
|
106
134
|
const { core, scratch } = newIsolatedCore(cfg, "dh-wc-dapp");
|
|
135
|
+
const health = { fatal: null };
|
|
136
|
+
let transport = null;
|
|
137
|
+
guardRelayFatal(core, health, () => transport?.dropForFatal());
|
|
107
138
|
const client = await import_sign_client.default.init({
|
|
108
139
|
core,
|
|
109
140
|
projectId: cfg.projectId,
|
|
110
|
-
metadata: WC_DAPP_METADATA
|
|
141
|
+
metadata: cfg.metadata ?? WC_DAPP_METADATA
|
|
111
142
|
});
|
|
112
|
-
|
|
143
|
+
transport = new _WcTransport(client, cfg, scratch, health);
|
|
144
|
+
return transport;
|
|
145
|
+
}
|
|
146
|
+
/** The relay is gone for good: no adopted session may outlive it. Listeners hear a
|
|
147
|
+
* disconnect, exactly as if the wallet had left. */
|
|
148
|
+
dropForFatal() {
|
|
149
|
+
if (this.session === null) return;
|
|
150
|
+
this.session = null;
|
|
151
|
+
void this.sessionListener?.(null);
|
|
152
|
+
}
|
|
153
|
+
/** Refuse to start new work over a relay that has failed fatally — naming why. */
|
|
154
|
+
assertRelayHealthy() {
|
|
155
|
+
if (this.health.fatal !== null) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
`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`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
113
160
|
}
|
|
114
161
|
/** Wallet-session state changes (connect/disconnect) — the bridge mirrors them. */
|
|
115
162
|
onSession(cb) {
|
|
@@ -120,22 +167,59 @@ var init_wc_transport = __esm({
|
|
|
120
167
|
}
|
|
121
168
|
/** Create a pairing URI; resolves the session in the background when a wallet approves. */
|
|
122
169
|
async createPairing() {
|
|
170
|
+
this.assertRelayHealthy();
|
|
123
171
|
const { uri, approval } = await this.client.connect({
|
|
124
172
|
// sign-client 2.21 deprecates requiredNamespaces (auto-downgraded to optional).
|
|
125
173
|
optionalNamespaces: wcSessionNamespaces(this.cfg.chainId)
|
|
126
174
|
});
|
|
127
175
|
if (!uri) throw new Error("WalletConnect returned no pairing URI");
|
|
128
|
-
|
|
176
|
+
const pairingId = /^wc:([0-9a-f]+)@/i.exec(uri)?.[1];
|
|
177
|
+
if (!pairingId) throw new Error(`WalletConnect pairing URI has no recognisable topic: ${uri.slice(0, 12)}\u2026`);
|
|
178
|
+
let candidateTopic = null;
|
|
179
|
+
void approval().then(async (session) => {
|
|
129
180
|
const first = session.namespaces["eip155"]?.accounts[0];
|
|
130
181
|
if (!first) throw new Error("WalletConnect session carries no eip155 account");
|
|
131
182
|
const [, chainIdStr, account] = first.split(":");
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
183
|
+
candidateTopic = session.topic;
|
|
184
|
+
const candidate = { topic: session.topic, account, chainId: Number(chainIdStr) };
|
|
185
|
+
const prove = async (statement) => {
|
|
186
|
+
this.assertRelayHealthy();
|
|
187
|
+
return await this.client.request({
|
|
188
|
+
topic: candidate.topic,
|
|
189
|
+
chainId: `eip155:${candidate.chainId}`,
|
|
190
|
+
request: { method: "personal_sign", params: [import_ethers.ethers.hexlify(import_ethers.ethers.toUtf8Bytes(statement)), candidate.account] }
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
const state = { deleted: false };
|
|
194
|
+
const live = () => !state.deleted && this.health.fatal === null;
|
|
195
|
+
const previous = this.session;
|
|
196
|
+
this.session = candidate;
|
|
197
|
+
this.candidates.set(candidate.topic, state);
|
|
198
|
+
const verdict = this.sessionListener?.({ account: candidate.account, chainId: candidate.chainId, pairingId, prove, live });
|
|
199
|
+
let adopted;
|
|
200
|
+
if (verdict instanceof Promise) {
|
|
201
|
+
this.session = previous;
|
|
202
|
+
adopted = await verdict.finally(() => this.candidates.delete(candidate.topic)).then((v) => v !== false);
|
|
203
|
+
if (adopted) this.session = candidate;
|
|
204
|
+
} else {
|
|
205
|
+
this.candidates.delete(candidate.topic);
|
|
206
|
+
adopted = verdict !== false;
|
|
207
|
+
if (!adopted) this.session = previous;
|
|
208
|
+
}
|
|
209
|
+
if (!adopted) {
|
|
210
|
+
void this.client.disconnect({ topic: session.topic, reason: { code: 6e3, message: "session refused by the bridge" } }).catch(() => void 0);
|
|
211
|
+
}
|
|
212
|
+
}).catch((e) => {
|
|
213
|
+
console.error(`[dh-mcp] WalletConnect pairing failed: ${e.message}`);
|
|
214
|
+
if (candidateTopic !== null && this.session?.topic !== candidateTopic) {
|
|
215
|
+
void this.client.disconnect({ topic: candidateTopic, reason: { code: 6e3, message: "session not adopted" } }).catch(() => void 0);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
return { uri, pairingId };
|
|
136
219
|
}
|
|
137
220
|
/** Route one wallet request over the active session. Throws on user rejection. */
|
|
138
221
|
async request(method, params) {
|
|
222
|
+
this.assertRelayHealthy();
|
|
139
223
|
if (!this.session) throw new Error("no active WalletConnect session");
|
|
140
224
|
return this.client.request({
|
|
141
225
|
topic: this.session.topic,
|
|
@@ -173,7 +257,7 @@ function decodeSignable(data) {
|
|
|
173
257
|
function eqAddr(a, b) {
|
|
174
258
|
if (!a || !b) return false;
|
|
175
259
|
try {
|
|
176
|
-
return
|
|
260
|
+
return import_ethers5.ethers.getAddress(a) === import_ethers5.ethers.getAddress(b);
|
|
177
261
|
} catch {
|
|
178
262
|
return false;
|
|
179
263
|
}
|
|
@@ -220,7 +304,7 @@ function decode(data) {
|
|
|
220
304
|
}
|
|
221
305
|
function normalizePositionId(id) {
|
|
222
306
|
const hex = id.startsWith("0x") ? id : `0x${id}`;
|
|
223
|
-
return
|
|
307
|
+
return import_ethers5.ethers.zeroPadValue(hex, 32).toLowerCase();
|
|
224
308
|
}
|
|
225
309
|
function validateUnsignedTx(unsignedTx, expected, vctx) {
|
|
226
310
|
const txChainId = readChainId(unsignedTx);
|
|
@@ -378,11 +462,11 @@ function describeUnsignedTx(unsignedTx) {
|
|
|
378
462
|
}
|
|
379
463
|
return { to, fn, chainId };
|
|
380
464
|
}
|
|
381
|
-
var
|
|
465
|
+
var import_ethers5, SIGNABLE_FUNCTIONS, IFACE, TxValidationError;
|
|
382
466
|
var init_tx_validator = __esm({
|
|
383
467
|
"src/boundary/upstream/shared/tx-validator.ts"() {
|
|
384
468
|
"use strict";
|
|
385
|
-
|
|
469
|
+
import_ethers5 = require("ethers");
|
|
386
470
|
SIGNABLE_FUNCTIONS = [
|
|
387
471
|
"function mintUCD(bytes32 positionId, uint256 mintAmount, uint256 mintFee, uint256 newDebt, uint256 newCollateral, uint256 btcPrice, bytes32 authorizedSpendsHash, bytes32 ucdDebtHash, bytes32 contractHash, uint256 quantumTimestamp, bytes calldata mintValidatorSignature) external returns (bool)",
|
|
388
472
|
"function makePayment(bytes32 positionId, uint256 paymentAmount, uint256 quantumTimestamp, uint256 btcPrice, bytes calldata paymentValidatorSignature) external returns (bool)",
|
|
@@ -400,7 +484,7 @@ var init_tx_validator = __esm({
|
|
|
400
484
|
"function createPosition(bytes32 pkpId, bytes validatorSignature, string mainnetVaultAddress, string regtestVaultAddress, uint256 selectedTermMonths, uint256 validatorVersion, bytes pkpPublicKey) external returns (bytes32)",
|
|
401
485
|
"function addAddress(string btcAddress) external"
|
|
402
486
|
];
|
|
403
|
-
IFACE = new
|
|
487
|
+
IFACE = new import_ethers5.ethers.Interface(SIGNABLE_FUNCTIONS);
|
|
404
488
|
TxValidationError = class extends Error {
|
|
405
489
|
constructor(msg) {
|
|
406
490
|
super(`Refusing to sign server-returned transaction: ${msg}`);
|
|
@@ -13543,6 +13627,12 @@ var require_follow_redirects = __commonJS({
|
|
|
13543
13627
|
RedirectableRequest.prototype._sanitizeOptions = function(options) {
|
|
13544
13628
|
if (!options.headers) {
|
|
13545
13629
|
options.headers = {};
|
|
13630
|
+
} else if (Array.isArray(options.headers)) {
|
|
13631
|
+
var headerList = options.headers;
|
|
13632
|
+
options.headers = {};
|
|
13633
|
+
for (var i = 0; i < headerList.length; i += 2) {
|
|
13634
|
+
options.headers[headerList[i]] = headerList[i + 1];
|
|
13635
|
+
}
|
|
13546
13636
|
}
|
|
13547
13637
|
if (!isArray2(options.sensitiveHeaders)) {
|
|
13548
13638
|
options.sensitiveHeaders = [];
|
|
@@ -13817,7 +13907,7 @@ var require_follow_redirects = __commonJS({
|
|
|
13817
13907
|
return URL3 && value instanceof URL3;
|
|
13818
13908
|
}
|
|
13819
13909
|
function escapeRegex(regex) {
|
|
13820
|
-
return regex.replace(/[\]\\/()
|
|
13910
|
+
return regex.replace(/[[\]\\/()*+?.^$|]/g, "\\$&");
|
|
13821
13911
|
}
|
|
13822
13912
|
module2.exports = wrap({ http: http4, https: https2 });
|
|
13823
13913
|
module2.exports.wrap = wrap;
|
|
@@ -14809,6 +14899,32 @@ var require_pkg_src = __commonJS({
|
|
|
14809
14899
|
deployedAt: 1790246264563,
|
|
14810
14900
|
size: 69219,
|
|
14811
14901
|
hash: "bda048d8cd6b5a39c2774bcf1320e82d1eea935c2a521006fb8b887e13b6dd8d"
|
|
14902
|
+
},
|
|
14903
|
+
carryCollateralAttestation: {
|
|
14904
|
+
cid: "QmYWULmXD9S5AmTdQqWqoZ28ctsZQNcXkAgre9G2Xo9dh8",
|
|
14905
|
+
authorizedCidHex: cidToHex(
|
|
14906
|
+
"QmYWULmXD9S5AmTdQqWqoZ28ctsZQNcXkAgre9G2Xo9dh8"
|
|
14907
|
+
),
|
|
14908
|
+
name: "Carry Collateral Attestation",
|
|
14909
|
+
description: "LoanCarryVault collateral attestation (borrower, BTC vault, confirmed BTC)",
|
|
14910
|
+
version: "1.0.0",
|
|
14911
|
+
deployed: true,
|
|
14912
|
+
deployedAt: 1790927734070,
|
|
14913
|
+
size: 21156,
|
|
14914
|
+
hash: "05b177e0bb36b0483db4a42d33c1bbbf47eb9ef34ae278459397d51a7f8957ff"
|
|
14915
|
+
},
|
|
14916
|
+
carryFundingAttestation: {
|
|
14917
|
+
cid: "QmWhox3xUZMNR5NpPZ9WLSPC5GoW4ms88GanVRKr8uuS3W",
|
|
14918
|
+
authorizedCidHex: cidToHex(
|
|
14919
|
+
"QmWhox3xUZMNR5NpPZ9WLSPC5GoW4ms88GanVRKr8uuS3W"
|
|
14920
|
+
),
|
|
14921
|
+
name: "Carry Funding Attestation",
|
|
14922
|
+
description: "LoanCarryVault funding attestation (Hyperliquid BTC windowed hourly average)",
|
|
14923
|
+
version: "1.0.0",
|
|
14924
|
+
deployed: true,
|
|
14925
|
+
deployedAt: 1790925699980,
|
|
14926
|
+
size: 7193,
|
|
14927
|
+
hash: "4944ada61610cf64b32e33b5be62087088dcf5e821040c69e67942e643ce74c9"
|
|
14812
14928
|
}
|
|
14813
14929
|
};
|
|
14814
14930
|
function getDeploymentsForNetwork(network) {
|
|
@@ -15552,7 +15668,7 @@ ${errorReport}`);
|
|
|
15552
15668
|
}
|
|
15553
15669
|
init_debug_logger();
|
|
15554
15670
|
init_session_signature_cache();
|
|
15555
|
-
var
|
|
15671
|
+
var import_ethers57 = require("ethers");
|
|
15556
15672
|
var EXPIRED_LOAN_MIN_LIQUIDATION_THRESHOLD_BPS = 11e3;
|
|
15557
15673
|
var GRACE_PERIOD_DAYS = 30;
|
|
15558
15674
|
var SATOSHIS_PER_BITCOIN = 100000000n;
|
|
@@ -18548,12 +18664,12 @@ ${auth.clientId}`;
|
|
|
18548
18664
|
}
|
|
18549
18665
|
async function executeVaultSnapshot(params) {
|
|
18550
18666
|
global.ethers = {
|
|
18551
|
-
...
|
|
18667
|
+
...import_ethers57.ethers,
|
|
18552
18668
|
providers: {
|
|
18553
|
-
StaticJsonRpcProvider:
|
|
18669
|
+
StaticJsonRpcProvider: import_ethers57.ethers.JsonRpcProvider
|
|
18554
18670
|
},
|
|
18555
|
-
Contract:
|
|
18556
|
-
utils:
|
|
18671
|
+
Contract: import_ethers57.ethers.Contract,
|
|
18672
|
+
utils: import_ethers57.ethers
|
|
18557
18673
|
// v6 moved utils to top level
|
|
18558
18674
|
};
|
|
18559
18675
|
global.Lit = {
|
|
@@ -27433,7 +27549,7 @@ var require_lit_ops_module = __commonJS({
|
|
|
27433
27549
|
break;
|
|
27434
27550
|
case 11155111:
|
|
27435
27551
|
chain = "sepolia";
|
|
27436
|
-
bitcoinProviderUrl = process.env.BITCOIN_PROVIDER_URL || "https://
|
|
27552
|
+
bitcoinProviderUrl = process.env.BITCOIN_PROVIDER_URL || "https://regtest.diamondhands.credit/api/esplora";
|
|
27437
27553
|
break;
|
|
27438
27554
|
case 1337:
|
|
27439
27555
|
// Hardhat local testnet (actual deployment chainId)
|
|
@@ -27622,7 +27738,7 @@ var require_lit_ops_module = __commonJS({
|
|
|
27622
27738
|
break;
|
|
27623
27739
|
case 11155111:
|
|
27624
27740
|
chain = "sepolia";
|
|
27625
|
-
bitcoinProviderUrl = process.env.BITCOIN_PROVIDER_URL || "https://
|
|
27741
|
+
bitcoinProviderUrl = process.env.BITCOIN_PROVIDER_URL || "https://regtest.diamondhands.credit/api/esplora";
|
|
27626
27742
|
break;
|
|
27627
27743
|
case 1337:
|
|
27628
27744
|
// Hardhat local testnet (actual deployment chainId)
|
|
@@ -27813,7 +27929,7 @@ var require_lit_ops_module = __commonJS({
|
|
|
27813
27929
|
break;
|
|
27814
27930
|
case 11155111:
|
|
27815
27931
|
chain = "sepolia";
|
|
27816
|
-
bitcoinProviderUrl = process.env.BITCOIN_PROVIDER_URL || "https://
|
|
27932
|
+
bitcoinProviderUrl = process.env.BITCOIN_PROVIDER_URL || "https://regtest.diamondhands.credit/api/esplora";
|
|
27817
27933
|
break;
|
|
27818
27934
|
case 1337:
|
|
27819
27935
|
case 31337:
|
|
@@ -27961,7 +28077,7 @@ var require_lit_ops_module = __commonJS({
|
|
|
27961
28077
|
break;
|
|
27962
28078
|
case 11155111:
|
|
27963
28079
|
chain = "sepolia";
|
|
27964
|
-
bitcoinProviderUrl = process.env.BITCOIN_PROVIDER_URL || "https://
|
|
28080
|
+
bitcoinProviderUrl = process.env.BITCOIN_PROVIDER_URL || "https://regtest.diamondhands.credit/api/esplora";
|
|
27965
28081
|
break;
|
|
27966
28082
|
case 1337:
|
|
27967
28083
|
// Hardhat local testnet (actual deployment chainId)
|
|
@@ -28181,7 +28297,7 @@ var require_lit_ops_module = __commonJS({
|
|
|
28181
28297
|
bitcoinProviderUrl = process.env.BITCOIN_PROVIDER_URL || "https://mempool.space/api";
|
|
28182
28298
|
break;
|
|
28183
28299
|
case 11155111:
|
|
28184
|
-
bitcoinProviderUrl = process.env.BITCOIN_PROVIDER_URL || "https://
|
|
28300
|
+
bitcoinProviderUrl = process.env.BITCOIN_PROVIDER_URL || "https://regtest.diamondhands.credit/api/esplora";
|
|
28185
28301
|
break;
|
|
28186
28302
|
case 1337:
|
|
28187
28303
|
// Hardhat local testnet (actual deployment chainId)
|
|
@@ -28397,7 +28513,7 @@ var require_lit_ops_module = __commonJS({
|
|
|
28397
28513
|
async chipotleCreateWalletAndAddToGroup(accountApiKey) {
|
|
28398
28514
|
const baseUrl = _LitOps.LIT_CORE_API_BASE;
|
|
28399
28515
|
const createResp = await fetch(`${baseUrl}/create_wallet`, {
|
|
28400
|
-
method: "
|
|
28516
|
+
method: "POST",
|
|
28401
28517
|
headers: {
|
|
28402
28518
|
"X-Api-Key": accountApiKey
|
|
28403
28519
|
}
|
|
@@ -40822,7 +40938,7 @@ module.exports = __toCommonJS(connector_embed_exports);
|
|
|
40822
40938
|
|
|
40823
40939
|
// src/connector/service.ts
|
|
40824
40940
|
var import_node_http = require("http");
|
|
40825
|
-
var
|
|
40941
|
+
var import_node_crypto11 = require("crypto");
|
|
40826
40942
|
var import_express = __toESM(require("express"));
|
|
40827
40943
|
var import_streamableHttp = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
40828
40944
|
var import_router = require("@modelcontextprotocol/sdk/server/auth/router.js");
|
|
@@ -40830,7 +40946,7 @@ var import_types4 = require("@modelcontextprotocol/sdk/types.js");
|
|
|
40830
40946
|
|
|
40831
40947
|
// src/connector/auth-md.ts
|
|
40832
40948
|
var CHAIN_IDS = { mainnet: 1, sepolia: 11155111 };
|
|
40833
|
-
function renderAuthMd({ publicOrigin, networks: networks2, walletConnectEnabled }) {
|
|
40949
|
+
function renderAuthMd({ publicOrigin, networks: networks2, walletConnectEnabled, grants }) {
|
|
40834
40950
|
const origin2 = publicOrigin.replace(/\/+$/, "");
|
|
40835
40951
|
const launchNetwork = networks2[0];
|
|
40836
40952
|
if (launchNetwork === void 0) {
|
|
@@ -40843,6 +40959,7 @@ function renderAuthMd({ publicOrigin, networks: networks2, walletConnectEnabled
|
|
|
40843
40959
|
);
|
|
40844
40960
|
}
|
|
40845
40961
|
const isMainnet = launchNetwork === "mainnet";
|
|
40962
|
+
const grantsLine = (grants.durable ? "- Clients and grants are stored durably, so a service restart does not sign anyone\n out: your client refreshes. Access tokens, sign-in flows and codes stay in memory." : "- All authorization state is held **in memory**. A service restart ends every session\n and the user signs in again. Nothing is persisted at rest.") + (grants.accountApi ? "\n- The wallet owner can see and **revoke** every grant from the Diamond Hands web app\n (Connect \u2192 Connections). A revoked grant stops working within about 30 seconds and\n its refresh token is refused with that reason." : "");
|
|
40846
40963
|
const wcLine = walletConnectEnabled ? "" : " **Mobile WalletConnect sign-in is not enabled on this deployment** \u2014 browser extension or own-key only.";
|
|
40847
40964
|
const agentAuth = {
|
|
40848
40965
|
agent_auth: {
|
|
@@ -40931,9 +41048,11 @@ ${JSON.stringify(agentAuth, null, 2)}
|
|
|
40931
41048
|
|
|
40932
41049
|
### What the credential is, and is not
|
|
40933
41050
|
|
|
40934
|
-
The **wallet address is the account.** There are no passwords
|
|
40935
|
-
|
|
40936
|
-
|
|
41051
|
+
The **wallet address is the account.** There are no passwords and no email addresses.
|
|
41052
|
+
Registration creates an OAuth client, not a Diamond Hands account. No password or email
|
|
41053
|
+
address is collected. Each completed sign-in is a **grant** that is stored: the wallet
|
|
41054
|
+
address, the client's id and self-declared name, the redirect host, timestamps, and a
|
|
41055
|
+
SHA-256 of the refresh token \u2014 never a token itself.
|
|
40937
41056
|
|
|
40938
41057
|
The access token proves **session identity only**. It can read what that address could
|
|
40939
41058
|
already read, and it can *stage* a fund-moving operation \u2014 arm a mint, a repayment, a
|
|
@@ -40942,8 +41061,7 @@ signature over that specific operation, which the token cannot produce. So it is
|
|
|
40942
41061
|
read-only credential, and it is not a spending one either. A stolen token cannot spend.
|
|
40943
41062
|
|
|
40944
41063
|
- Access token: ~1 hour. Refresh token: rotating, expires after inactivity.
|
|
40945
|
-
|
|
40946
|
-
and the user signs in again. Nothing is persisted at rest.
|
|
41064
|
+
${grantsLine}
|
|
40947
41065
|
- \`scopes_supported\` is empty and tokens are minted with no scopes \u2014 this
|
|
40948
41066
|
authorization server does not implement scoped access. Do not request a scope; you
|
|
40949
41067
|
will not receive one.
|
|
@@ -41017,9 +41135,12 @@ source of truth.
|
|
|
41017
41135
|
`;
|
|
41018
41136
|
}
|
|
41019
41137
|
|
|
41020
|
-
// src/
|
|
41138
|
+
// src/util/brand-assets.ts
|
|
41021
41139
|
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>`;
|
|
41022
41140
|
var FAVICON_DATA_URI = `data:image/svg+xml,${encodeURIComponent(FAVICON_SVG).replace(/'/g, "%27")}`;
|
|
41141
|
+
var GVNR_PILL_LOGO_DATA_URI = "data:image/png;base64,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";
|
|
41142
|
+
|
|
41143
|
+
// src/connector/landing-page.ts
|
|
41023
41144
|
var BACKGROUND_IMAGE_ORIGIN = "https://images.gvnr.xyz";
|
|
41024
41145
|
var BACKGROUND_IMAGE_URL = `${BACKGROUND_IMAGE_ORIGIN}/images/layout/backgroundCorleoneb.jpg`;
|
|
41025
41146
|
var escapeHtml = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
@@ -41114,16 +41235,86 @@ function htmlPageSecurityHeaders(extra) {
|
|
|
41114
41235
|
}
|
|
41115
41236
|
|
|
41116
41237
|
// src/version.ts
|
|
41117
|
-
var SERVER_VERSION = "0.5.
|
|
41238
|
+
var SERVER_VERSION = "0.5.22";
|
|
41118
41239
|
|
|
41119
41240
|
// src/connector/siwe-oauth.ts
|
|
41120
|
-
var
|
|
41121
|
-
var
|
|
41241
|
+
var import_node_crypto3 = require("crypto");
|
|
41242
|
+
var import_ethers2 = require("ethers");
|
|
41122
41243
|
var import_errors = require("@modelcontextprotocol/sdk/server/auth/errors.js");
|
|
41123
41244
|
|
|
41245
|
+
// src/util/house-style.ts
|
|
41246
|
+
var APP_BACKGROUND_ORIGIN = "https://images.diamondhands.credit";
|
|
41247
|
+
var APP_BACKGROUND_URL = `${APP_BACKGROUND_ORIGIN}/bg-diamond-hands.png`;
|
|
41248
|
+
var FONT_ORIGIN = "https://images.gvnr.xyz";
|
|
41249
|
+
var MANROPE_BASE = `${FONT_ORIGIN}/fonts/manrope`;
|
|
41250
|
+
var HOUSE_CSP_EXTRA = {
|
|
41251
|
+
"img-src": [APP_BACKGROUND_ORIGIN, "data:"],
|
|
41252
|
+
"font-src": [FONT_ORIGIN]
|
|
41253
|
+
};
|
|
41254
|
+
var HOUSE_HEAD_LINKS = `<link rel="icon" type="image/svg+xml" href="${FAVICON_DATA_URI}">
|
|
41255
|
+
<link rel="apple-touch-icon" href="${FAVICON_DATA_URI}">`;
|
|
41256
|
+
var MANROPE_WEIGHTS = [
|
|
41257
|
+
[300, "Light"],
|
|
41258
|
+
[400, "Regular"],
|
|
41259
|
+
[500, "Medium"],
|
|
41260
|
+
[600, "SemiBold"],
|
|
41261
|
+
[700, "Bold"]
|
|
41262
|
+
];
|
|
41263
|
+
var HOUSE_BASE_CSS = `
|
|
41264
|
+
${MANROPE_WEIGHTS.map(([w, n]) => `@font-face { font-family: "Manrope"; font-weight: ${w}; font-display: swap; src: url("${MANROPE_BASE}/Manrope-${n}.ttf") format("truetype"); }`).join("\n")}
|
|
41265
|
+
* { box-sizing: border-box; }
|
|
41266
|
+
html { min-height: 100%; background: #000006; }
|
|
41267
|
+
body { margin: 0; min-height: 100vh; color: #fff; font: 14px/1.5 "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
|
|
41268
|
+
background: #000006 url("${APP_BACKGROUND_URL}") center / cover no-repeat fixed; }
|
|
41269
|
+
.house-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem; }
|
|
41270
|
+
@media (min-width: 768px) { .house-header { padding: 1rem 2.5rem; } }
|
|
41271
|
+
.house-header > img { height: 1.92rem; width: auto; display: block; flex: none; }
|
|
41272
|
+
/* Narrow viewports: the chip may shrink (its label ellipsises), and below 400px the label
|
|
41273
|
+
is dropped so logo + chip icon always fit a 320px phone with no horizontal page scroll. */
|
|
41274
|
+
.house-header .chip { min-width: 0; }
|
|
41275
|
+
.chip-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
41276
|
+
/* ".house-header .chip", not ".chip": the base .chip rule below declares padding too, and at
|
|
41277
|
+
equal specificity the LATER rule wins regardless of the media query; this selector outranks it. */
|
|
41278
|
+
@media (max-width: 400px) { .chip-label { display: none; } .house-header .chip { padding: 0.4rem 0.6rem; } }
|
|
41279
|
+
.chip { display: inline-flex; align-items: center; gap: 0.45rem; padding: 0.4rem 0.85rem; border-radius: 999px;
|
|
41280
|
+
background: rgba(0, 0, 0, 0.3); border: 1px solid rgba(255, 255, 255, 0.1); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
|
|
41281
|
+
font-size: 0.8rem; font-weight: 600; color: #dbff91; white-space: nowrap; }
|
|
41282
|
+
.chip img { height: 1rem; }
|
|
41283
|
+
main { max-width: 34rem; margin: 2.5rem auto 3rem; padding: 0 1rem; }
|
|
41284
|
+
.panel { background: #121212; border: 1px solid rgba(255, 255, 255, 0.06); border-radius: 12px; padding: 1rem;
|
|
41285
|
+
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05); }
|
|
41286
|
+
@media (min-width: 768px) { .panel { padding: 1.25rem; } }
|
|
41287
|
+
h1 { font-size: 1.25rem; font-weight: 600; line-height: 1.375; color: #fafafa; margin: 0 0 1rem; }
|
|
41288
|
+
@media (min-width: 768px) { h1 { font-size: 1.5rem; margin-bottom: 1.25rem; } }
|
|
41289
|
+
h2 { font-size: 1rem; font-weight: 600; line-height: 1.375; color: #fafafa; margin: 0 0 0.75rem; }
|
|
41290
|
+
p { margin: 0 0 1rem; color: #e5e5e5; font-size: 0.875rem; font-weight: 300; line-height: 1.5; }
|
|
41291
|
+
button { font: inherit; font-size: 0.875rem; cursor: pointer; border: 0; display: inline-flex; align-items: center; justify-content: center;
|
|
41292
|
+
min-height: 2.75rem; padding: 0.65rem 1.25rem; transition: opacity 0.2s, background-color 0.2s; }
|
|
41293
|
+
button:focus-visible { outline: 2px solid #84cc16; outline-offset: 2px; }
|
|
41294
|
+
button:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
41295
|
+
/* Primary = lime-700 (#4d7c0f): white 14px text on it is 4.99:1 (WCAG AA needs 4.5:1; the
|
|
41296
|
+
brighter #65a30d was 3.09:1). Hover = lime-800 (#3f6212), 7.08:1. A test recomputes both. */
|
|
41297
|
+
.btn-primary { background: #4d7c0f; color: #fff; font-weight: 700; letter-spacing: 0.025em; border-radius: 12px; box-shadow: 0 4px 18px rgba(74, 222, 128, 0.2); }
|
|
41298
|
+
.btn-primary:hover:not(:disabled) { background: #3f6212; }
|
|
41299
|
+
.btn-secondary { background: #34440e; color: #dbff91; font-weight: 500; border-radius: 20px; }
|
|
41300
|
+
.btn-secondary:hover:not(:disabled) { background: #3d5210; }
|
|
41301
|
+
.btn-danger { background: transparent; color: #fca5a5; font-weight: 600; border-radius: 12px; border: 1px solid rgba(248, 113, 113, 0.45); }
|
|
41302
|
+
.btn-danger:hover:not(:disabled) { background: rgba(220, 38, 38, 0.15); }
|
|
41303
|
+
/* A QR needs dark-on-light to scan: it keeps a white plate on the dark page. */
|
|
41304
|
+
.qr-plate { max-width: 16rem; margin-top: 1rem; background: #fff; border-radius: 12px; padding: 0.5rem; }
|
|
41305
|
+
.qr-plate svg { width: 100%; height: auto; display: block; }
|
|
41306
|
+
`;
|
|
41307
|
+
function houseHeader(label) {
|
|
41308
|
+
return `<header class="house-header">
|
|
41309
|
+
<img src="${GVNR_PILL_LOGO_DATA_URI}" alt="GVNR">
|
|
41310
|
+
<span class="chip"><img src="${FAVICON_DATA_URI}" alt=""><span class="chip-label">${label}</span></span>
|
|
41311
|
+
</header>`;
|
|
41312
|
+
}
|
|
41313
|
+
|
|
41124
41314
|
// src/connector/siwe-page.ts
|
|
41315
|
+
var SIWE_PAGE_CSP_EXTRA = HOUSE_CSP_EXTRA;
|
|
41125
41316
|
function renderSiwePage(opts) {
|
|
41126
|
-
const { flowId, redirectHost, nonce } = opts;
|
|
41317
|
+
const { flowId, redirectHost, nonce, walletConnectEnabled } = opts;
|
|
41127
41318
|
const clientName = clampClientName(opts.clientName);
|
|
41128
41319
|
return `<!DOCTYPE html>
|
|
41129
41320
|
<html>
|
|
@@ -41131,54 +41322,63 @@ function renderSiwePage(opts) {
|
|
|
41131
41322
|
<meta charset="utf-8">
|
|
41132
41323
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
41133
41324
|
<title>Diamond Hands \u2014 sign in with your wallet</title>
|
|
41325
|
+
${HOUSE_HEAD_LINKS}
|
|
41134
41326
|
<style>
|
|
41135
|
-
|
|
41136
|
-
|
|
41137
|
-
|
|
41138
|
-
#
|
|
41139
|
-
|
|
41140
|
-
|
|
41327
|
+
${HOUSE_BASE_CSS}
|
|
41328
|
+
/* \u2500\u2500 sign-in page only \u2500\u2500 */
|
|
41329
|
+
.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.25rem; }
|
|
41330
|
+
#qr:empty { display: none; }
|
|
41331
|
+
#status { margin-top: 1rem; color: #a1a1a1; font-size: 0.875rem; font-weight: 400; }
|
|
41332
|
+
#status:empty, #wc-uri:empty { display: none; }
|
|
41333
|
+
.err { color: #f87171; }
|
|
41334
|
+
.note { font-size: 0.75rem; color: #a1a1a1; margin: 1.25rem 0 0; padding-top: 1rem; border-top: 1px solid rgba(255, 255, 255, 0.06); }
|
|
41141
41335
|
/* "position: relative" is load-bearing, not cosmetic: it puts the consent box in its
|
|
41142
41336
|
own stacking context so it paints ABOVE the inline content of the paragraph before
|
|
41143
41337
|
it. Without it, a client name built from stacked combining marks overflows its line
|
|
41144
41338
|
box downward and paints over this text \u2014 the CSS painting order draws every block
|
|
41145
41339
|
background first, then all inline content in tree order. */
|
|
41146
|
-
.dest { background:
|
|
41340
|
+
.dest { background: rgba(245, 158, 11, 0.12); border-left: 3px solid #f59e0b; border-radius: 0 10px 10px 0; padding: 0.75rem 0.95rem; font-size: 0.875rem; font-weight: 400; color: #f5f5f5; position: relative; }
|
|
41147
41341
|
/* The destination must stay legible under a host the attacker chose the length of:
|
|
41148
41342
|
"overflow-wrap: anywhere" lets it wrap mid-label (a dot is not a break opportunity),
|
|
41149
41343
|
and the isolate keeps any bidi control inside from reordering the sentence around
|
|
41150
41344
|
it. splitRedirectHost has already bounded the length; this bounds the geometry. */
|
|
41151
|
-
.dest code { font-family: ui-monospace, monospace; font-size: 1rem; word-break: break-all; overflow-wrap: anywhere; unicode-bidi: isolate; }
|
|
41152
|
-
.dest .host-head { color: #
|
|
41153
|
-
.dest .host-tail { font-weight: 700; color: #
|
|
41345
|
+
.dest code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1rem; word-break: break-all; overflow-wrap: anywhere; unicode-bidi: isolate; }
|
|
41346
|
+
.dest .host-head { color: #a3a3a3; }
|
|
41347
|
+
.dest .host-tail { font-weight: 700; color: #fff; }
|
|
41154
41348
|
/* The elision is NOT decoration \u2014 it is the page admitting it withheld characters, so
|
|
41155
41349
|
it must be as visible as the text it replaced. */
|
|
41156
|
-
.dest .host-cut { color: #
|
|
41350
|
+
.dest .host-cut { color: #fbbf24; font-weight: 700; font-style: normal; }
|
|
41157
41351
|
/* The attacker-chosen name is clipped to a fixed box: bounded characters alone do not
|
|
41158
41352
|
bound HEIGHT (combining marks stack vertically), and an isolate stops an unpaired
|
|
41159
41353
|
RTL override inside the name from reversing the rest of the sentence. */
|
|
41160
|
-
.cname { display: inline-block; max-width: 100%; max-height: 4.5em; overflow: hidden; vertical-align: bottom; word-break: break-all; overflow-wrap: anywhere; unicode-bidi: isolate; font-weight:
|
|
41161
|
-
#
|
|
41162
|
-
#qr svg { width: 100%; height: auto; }
|
|
41163
|
-
#wc-uri { font-size: 0.7rem; word-break: break-all; color: #888; }
|
|
41354
|
+
.cname { display: inline-block; max-width: 100%; max-height: 4.5em; overflow: hidden; vertical-align: bottom; word-break: break-all; overflow-wrap: anywhere; unicode-bidi: isolate; font-weight: 600; color: #fafafa; }
|
|
41355
|
+
#wc-uri { font-size: 0.7rem; word-break: break-all; color: #a1a1a1; }
|
|
41164
41356
|
</style>
|
|
41165
41357
|
</head>
|
|
41166
41358
|
<body>
|
|
41359
|
+
${houseHeader("Diamond Hands \xB7 wallet sign-in")}
|
|
41360
|
+
<main>
|
|
41167
41361
|
<h1>Sign in to Diamond Hands</h1>
|
|
41362
|
+
<div class="panel">
|
|
41363
|
+
<h2>Connect your wallet</h2>
|
|
41168
41364
|
<p><span class="cname" dir="ltr">${escapeHtml2(clientName)}</span> is asking to connect. Signing in proves you own a wallet address \u2014 it authorizes nothing on-chain and can never move funds.</p>
|
|
41169
41365
|
<p class="dest">When you sign, this connection is handed to <code dir="ltr">${renderRedirectHost(redirectHost)}</code>. Anyone can register a client under any name, so read the host, not the name \u2014 and read it from the <b>bold end</b>, which is the part that decides who actually owns it. If you do not recognize it, close this page; nothing has happened yet.</p>
|
|
41170
|
-
<
|
|
41171
|
-
<button id="
|
|
41366
|
+
<div class="actions">
|
|
41367
|
+
<button id="connect" class="btn-primary">Browser wallet</button>
|
|
41368
|
+
${walletConnectEnabled ? `<button id="wc" class="btn-secondary">Mobile wallet (QR)</button>
|
|
41369
|
+
` : ""}</div>
|
|
41172
41370
|
<div id="status"></div>
|
|
41173
|
-
<div id="qr"></div>
|
|
41371
|
+
<div id="qr" class="qr-plate"></div>
|
|
41174
41372
|
<p id="wc-uri"></p>
|
|
41175
|
-
<p class="note">Every future operation that moves funds will still ask for its own approval in your wallet. Two ways in: a browser wallet extension on this device, or scan the QR with a mobile wallet (WalletConnect)
|
|
41373
|
+
<p class="note">Every future operation that moves funds will still ask for its own approval in your wallet. ${walletConnectEnabled ? "Two ways in: a browser wallet extension on this device, or scan the QR with a mobile wallet (WalletConnect)." : "Sign in with a browser wallet extension on this device."}</p>
|
|
41374
|
+
</div>
|
|
41375
|
+
</main>
|
|
41176
41376
|
<script nonce="${nonce}">
|
|
41177
41377
|
const FLOW = ${JSON.stringify(flowId)};
|
|
41178
41378
|
const statusEl = document.getElementById("status");
|
|
41179
41379
|
function show(text, isErr) { statusEl.textContent = text; statusEl.className = isErr ? "err" : ""; }
|
|
41180
41380
|
document.getElementById("connect").addEventListener("click", async () => {
|
|
41181
|
-
if (!window.ethereum) { show("No browser wallet found - install a wallet extension and reload, or use the mobile QR path.", true); return; }
|
|
41381
|
+
if (!window.ethereum) { show(${JSON.stringify(walletConnectEnabled ? "No browser wallet found - install a wallet extension and reload, or use the mobile QR path." : "No browser wallet found - install a wallet extension and reload.")}, true); return; }
|
|
41182
41382
|
try {
|
|
41183
41383
|
const accounts = await window.ethereum.request({ method: "eth_requestAccounts" });
|
|
41184
41384
|
const address = accounts[0];
|
|
@@ -41204,7 +41404,7 @@ document.getElementById("connect").addEventListener("click", async () => {
|
|
|
41204
41404
|
show(e && e.code === 4001 ? "You declined in the wallet - nothing was connected." : String(e && e.message || e), true);
|
|
41205
41405
|
}
|
|
41206
41406
|
});
|
|
41207
|
-
let wcPoll = null;
|
|
41407
|
+
${walletConnectEnabled ? `let wcPoll = null;
|
|
41208
41408
|
document.getElementById("wc").addEventListener("click", async () => {
|
|
41209
41409
|
try {
|
|
41210
41410
|
show("Creating a WalletConnect pairing\u2026");
|
|
@@ -41237,6 +41437,7 @@ document.getElementById("wc").addEventListener("click", async () => {
|
|
|
41237
41437
|
show(String(e && e.message || e), true);
|
|
41238
41438
|
}
|
|
41239
41439
|
});
|
|
41440
|
+
` : ""}
|
|
41240
41441
|
</script>
|
|
41241
41442
|
</body>
|
|
41242
41443
|
</html>`;
|
|
@@ -41264,51 +41465,138 @@ function renderRedirectHost(host) {
|
|
|
41264
41465
|
const cut = elided === 0 ? "" : `<span class="host-cut">\u2026+${elided} chars\u2026</span>`;
|
|
41265
41466
|
return `<span class="host-head">${escapeHtml2(head)}</span>${cut}<span class="host-tail">${escapeHtml2(tail)}</span>`;
|
|
41266
41467
|
}
|
|
41468
|
+
function redirectHostForStatement(host) {
|
|
41469
|
+
const { head, elided, tail } = splitRedirectHost(host);
|
|
41470
|
+
return elided === 0 ? `${head}${tail}` : `${head}\u2026+${elided} chars\u2026${tail}`;
|
|
41471
|
+
}
|
|
41267
41472
|
function clampClientName(name) {
|
|
41268
41473
|
const points = [...name];
|
|
41269
41474
|
if (points.length <= MAX_CLIENT_NAME_CHARS) return name;
|
|
41270
41475
|
return `${points.slice(0, MAX_CLIENT_NAME_CHARS - 1).join("")}\u2026`;
|
|
41271
41476
|
}
|
|
41272
41477
|
|
|
41478
|
+
// src/connector/oauth-store.ts
|
|
41479
|
+
var import_node_crypto2 = require("crypto");
|
|
41480
|
+
function hashToken(token) {
|
|
41481
|
+
return (0, import_node_crypto2.createHash)("sha256").update(token, "utf8").digest("hex");
|
|
41482
|
+
}
|
|
41483
|
+
var DEFAULT_MAX_CLIENTS = 1e3;
|
|
41484
|
+
function memoryOAuthStateStore(opts) {
|
|
41485
|
+
const maxClients = opts?.maxClients ?? DEFAULT_MAX_CLIENTS;
|
|
41486
|
+
const clients = /* @__PURE__ */ new Map();
|
|
41487
|
+
const grants = /* @__PURE__ */ new Map();
|
|
41488
|
+
return {
|
|
41489
|
+
async getClient(clientId, now) {
|
|
41490
|
+
const entry = clients.get(clientId);
|
|
41491
|
+
if (!entry) return null;
|
|
41492
|
+
if (entry.expireAt <= now) {
|
|
41493
|
+
clients.delete(clientId);
|
|
41494
|
+
return null;
|
|
41495
|
+
}
|
|
41496
|
+
return entry.client;
|
|
41497
|
+
},
|
|
41498
|
+
async putClient(client, _now, expireAt) {
|
|
41499
|
+
if (!clients.has(client.client_id)) {
|
|
41500
|
+
while (clients.size >= maxClients) {
|
|
41501
|
+
let victim;
|
|
41502
|
+
let earliest = Infinity;
|
|
41503
|
+
for (const [id, entry] of clients) {
|
|
41504
|
+
if (entry.expireAt < earliest) {
|
|
41505
|
+
victim = id;
|
|
41506
|
+
earliest = entry.expireAt;
|
|
41507
|
+
}
|
|
41508
|
+
}
|
|
41509
|
+
if (victim === void 0) break;
|
|
41510
|
+
clients.delete(victim);
|
|
41511
|
+
}
|
|
41512
|
+
}
|
|
41513
|
+
clients.set(client.client_id, { client, expireAt });
|
|
41514
|
+
},
|
|
41515
|
+
async extendClient(clientId, expireAt) {
|
|
41516
|
+
const entry = clients.get(clientId);
|
|
41517
|
+
if (entry && entry.expireAt < expireAt) entry.expireAt = expireAt;
|
|
41518
|
+
},
|
|
41519
|
+
async createGrant(grant) {
|
|
41520
|
+
grants.set(grant.grantId, { ...grant });
|
|
41521
|
+
},
|
|
41522
|
+
async getGrant(grantId) {
|
|
41523
|
+
const g = grants.get(grantId);
|
|
41524
|
+
return g ? { ...g } : null;
|
|
41525
|
+
},
|
|
41526
|
+
async findGrantByRefreshHash(refreshHash) {
|
|
41527
|
+
for (const g of grants.values()) if (g.refreshHash === refreshHash) return { ...g };
|
|
41528
|
+
return null;
|
|
41529
|
+
},
|
|
41530
|
+
async rotateGrant(grantId, expectedHash, next) {
|
|
41531
|
+
const g = grants.get(grantId);
|
|
41532
|
+
if (!g || g.revokedAt !== null || g.refreshHash !== expectedHash) return false;
|
|
41533
|
+
grants.set(grantId, { ...g, ...next });
|
|
41534
|
+
return true;
|
|
41535
|
+
},
|
|
41536
|
+
async revokeGrant(grantId, now) {
|
|
41537
|
+
const g = grants.get(grantId);
|
|
41538
|
+
if (g && g.revokedAt === null) grants.set(grantId, { ...g, revokedAt: now });
|
|
41539
|
+
},
|
|
41540
|
+
async listGrants(address) {
|
|
41541
|
+
const a = address.toLowerCase();
|
|
41542
|
+
return [...grants.values()].filter((g) => g.address === a).map((g) => ({ ...g }));
|
|
41543
|
+
},
|
|
41544
|
+
async sweep(now) {
|
|
41545
|
+
for (const [id, c] of clients) if (c.expireAt <= now) clients.delete(id);
|
|
41546
|
+
for (const [id, g] of grants) if (g.expireAt <= now) grants.delete(id);
|
|
41547
|
+
}
|
|
41548
|
+
};
|
|
41549
|
+
}
|
|
41550
|
+
|
|
41273
41551
|
// src/connector/siwe-oauth.ts
|
|
41274
41552
|
var FLOW_TTL_MS = 10 * 60 * 1e3;
|
|
41275
41553
|
var CODE_TTL_MS = 60 * 1e3;
|
|
41276
41554
|
var ACCESS_TTL_S = 3600;
|
|
41277
41555
|
var DEFAULT_REFRESH_IDLE_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
41278
|
-
var
|
|
41556
|
+
var UNCLAIMED_CLIENT_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
41557
|
+
var GRANT_RECHECK_MS = 30 * 1e3;
|
|
41558
|
+
var DEFAULT_WC_MAX_GLOBAL_PAIRINGS = 50;
|
|
41559
|
+
var DEFAULT_WC_MAX_PAIRINGS_PER_IP = 3;
|
|
41560
|
+
function resolveWcLimits(limits) {
|
|
41561
|
+
const maxGlobal = limits?.maxGlobal ?? DEFAULT_WC_MAX_GLOBAL_PAIRINGS;
|
|
41562
|
+
const maxPerIp = limits?.maxPerIp ?? DEFAULT_WC_MAX_PAIRINGS_PER_IP;
|
|
41563
|
+
for (const [name, v] of [["wcLimits.maxGlobal", maxGlobal], ["wcLimits.maxPerIp", maxPerIp]]) {
|
|
41564
|
+
if (!Number.isSafeInteger(v) || v < 1) throw new Error(`${name} must be a positive integer, got ${String(v)}`);
|
|
41565
|
+
}
|
|
41566
|
+
return { maxGlobal, maxPerIp };
|
|
41567
|
+
}
|
|
41279
41568
|
var SiweOAuthProvider = class {
|
|
41280
41569
|
constructor(opts) {
|
|
41281
41570
|
this.opts = opts;
|
|
41282
41571
|
this.clock = opts.clock ?? Date.now;
|
|
41283
|
-
this.maxClients = opts.bounds?.maxClients ?? DEFAULT_MAX_CLIENTS;
|
|
41284
41572
|
this.refreshIdleMs = opts.bounds?.refreshIdleMs ?? DEFAULT_REFRESH_IDLE_MS;
|
|
41573
|
+
const limits = resolveWcLimits(opts.wcLimits);
|
|
41574
|
+
this.wcMaxGlobal = limits.maxGlobal;
|
|
41575
|
+
this.wcMaxPerIp = limits.maxPerIp;
|
|
41576
|
+
this.store = opts.store ?? memoryOAuthStateStore(opts.bounds?.maxClients !== void 0 ? { maxClients: opts.bounds.maxClients } : void 0);
|
|
41285
41577
|
}
|
|
41286
|
-
clients = /* @__PURE__ */ new Map();
|
|
41287
41578
|
flows = /* @__PURE__ */ new Map();
|
|
41288
41579
|
codes = /* @__PURE__ */ new Map();
|
|
41289
41580
|
access = /* @__PURE__ */ new Map();
|
|
41290
|
-
|
|
41581
|
+
store;
|
|
41291
41582
|
clock;
|
|
41292
|
-
maxClients;
|
|
41293
41583
|
refreshIdleMs;
|
|
41584
|
+
wcMaxGlobal;
|
|
41585
|
+
wcMaxPerIp;
|
|
41294
41586
|
get clientsStore() {
|
|
41295
|
-
const
|
|
41296
|
-
const
|
|
41587
|
+
const store = this.store;
|
|
41588
|
+
const clock = this.clock;
|
|
41297
41589
|
return {
|
|
41298
|
-
getClient: (clientId) =>
|
|
41299
|
-
registerClient: (client) => {
|
|
41590
|
+
getClient: async (clientId) => await store.getClient(clientId, clock()) ?? void 0,
|
|
41591
|
+
registerClient: async (client) => {
|
|
41300
41592
|
const name = client.client_name;
|
|
41301
41593
|
if (name !== void 0 && [...name].length > MAX_CLIENT_NAME_CHARS) {
|
|
41302
41594
|
throw new import_errors.InvalidClientMetadataError(
|
|
41303
41595
|
`client_name is ${[...name].length} characters \u2014 this authorization server displays it on a consent screen and accepts at most ${MAX_CLIENT_NAME_CHARS}`
|
|
41304
41596
|
);
|
|
41305
41597
|
}
|
|
41306
|
-
|
|
41307
|
-
|
|
41308
|
-
if (oldest === void 0) break;
|
|
41309
|
-
clients.delete(oldest);
|
|
41310
|
-
}
|
|
41311
|
-
clients.set(client.client_id, client);
|
|
41598
|
+
const now = clock();
|
|
41599
|
+
await store.putClient(client, now, now + UNCLAIMED_CLIENT_TTL_MS);
|
|
41312
41600
|
return client;
|
|
41313
41601
|
}
|
|
41314
41602
|
};
|
|
@@ -41319,10 +41607,10 @@ var SiweOAuthProvider = class {
|
|
|
41319
41607
|
* response carries its own security headers, and the page names the redirect HOST —
|
|
41320
41608
|
* the consent fact that open registration makes `client_name` unable to carry. */
|
|
41321
41609
|
async authorize(client, params, res) {
|
|
41322
|
-
this.sweep();
|
|
41323
|
-
const flowId = (0,
|
|
41610
|
+
await this.sweep();
|
|
41611
|
+
const flowId = (0, import_node_crypto3.randomBytes)(16).toString("hex");
|
|
41324
41612
|
this.flows.set(flowId, { clientId: client.client_id, params, createdAt: this.clock() });
|
|
41325
|
-
const page = htmlPageSecurityHeaders();
|
|
41613
|
+
const page = htmlPageSecurityHeaders(SIWE_PAGE_CSP_EXTRA);
|
|
41326
41614
|
for (const [name, value] of Object.entries(page.headers)) res.setHeader(name, value);
|
|
41327
41615
|
res.setHeader(STRICT_TRANSPORT_SECURITY.name, STRICT_TRANSPORT_SECURITY.value);
|
|
41328
41616
|
res.status(200).type("html").send(
|
|
@@ -41333,7 +41621,8 @@ var SiweOAuthProvider = class {
|
|
|
41333
41621
|
// redirect_uri (SafeUrlSchema) and, for a request-supplied one, URL.canParse
|
|
41334
41622
|
// plus a registered-URI match — so this constructor cannot throw here.
|
|
41335
41623
|
redirectHost: new URL(params.redirectUri).host,
|
|
41336
|
-
nonce: page.nonce
|
|
41624
|
+
nonce: page.nonce,
|
|
41625
|
+
walletConnectEnabled: this.opts.wc !== void 0
|
|
41337
41626
|
})
|
|
41338
41627
|
);
|
|
41339
41628
|
}
|
|
@@ -41344,19 +41633,24 @@ var SiweOAuthProvider = class {
|
|
|
41344
41633
|
siweMessage(flowId, address) {
|
|
41345
41634
|
const flow = this.liveFlow(flowId);
|
|
41346
41635
|
if (!flow) return { ok: false, status: 404, reason: "unknown or expired sign-in flow \u2014 restart the connection from claude.ai" };
|
|
41347
|
-
if (!
|
|
41348
|
-
const checksummed =
|
|
41349
|
-
flow.siwe = { address: checksummed, message: this.mintSiweMessage(checksummed) };
|
|
41636
|
+
if (!import_ethers2.ethers.isAddress(address)) return { ok: false, status: 400, reason: "not a valid wallet address" };
|
|
41637
|
+
const checksummed = import_ethers2.ethers.getAddress(address);
|
|
41638
|
+
flow.siwe = { address: checksummed, message: this.mintSiweMessage(checksummed, flow) };
|
|
41350
41639
|
return { ok: true, message: flow.siwe.message };
|
|
41351
41640
|
}
|
|
41352
|
-
|
|
41641
|
+
/** S1-C — the statement carries the redirect HOST (bounded like the sign-in page bounds
|
|
41642
|
+
* it; never the attacker-chosen client name), because on the WalletConnect leg the phone
|
|
41643
|
+
* shows only this text and a relayed pairing QR would otherwise hide where the grant goes.
|
|
41644
|
+
* One line, no newline: EIP-4361 statements cannot contain one, and a URL host cannot. */
|
|
41645
|
+
mintSiweMessage(checksummedAddress, flow) {
|
|
41646
|
+
const redirectHost = redirectHostForStatement(new URL(flow.params.redirectUri).host);
|
|
41353
41647
|
const origin2 = this.opts.origin();
|
|
41354
41648
|
const domain = new URL(origin2).host;
|
|
41355
|
-
const nonce = (0,
|
|
41649
|
+
const nonce = (0, import_node_crypto3.randomBytes)(8).toString("hex");
|
|
41356
41650
|
return `${domain} wants you to sign in with your Ethereum account:
|
|
41357
41651
|
${checksummedAddress}
|
|
41358
41652
|
|
|
41359
|
-
Connect Diamond Hands to your AI assistant. This signature only proves you own this wallet - it authorizes nothing on-chain and can never move funds.
|
|
41653
|
+
Connect Diamond Hands to your AI assistant. After you sign, this connection is handed to ${redirectHost}. This signature only proves you own this wallet - it authorizes nothing on-chain and can never move funds.
|
|
41360
41654
|
|
|
41361
41655
|
URI: ${origin2}/authorize
|
|
41362
41656
|
Version: 1
|
|
@@ -41367,12 +41661,42 @@ Issued At: ${new Date(this.clock()).toISOString()}`;
|
|
|
41367
41661
|
/** Plan 17 A1 — start the mobile (WalletConnect) leg for a flow: one ISOLATED
|
|
41368
41662
|
* transport per flow, a fresh pairing URI + QR. A re-call replaces the flow's
|
|
41369
41663
|
* previous pairing (dispose first — no orphaned transports). */
|
|
41370
|
-
async wcPairing(flowId) {
|
|
41664
|
+
async wcPairing(flowId, requesterIp) {
|
|
41371
41665
|
const wcOpts = this.opts.wc;
|
|
41372
41666
|
if (!wcOpts) return { ok: false, status: 404, reason: "mobile wallet sign-in is not enabled on this deployment" };
|
|
41373
41667
|
const flow = this.liveFlow(flowId);
|
|
41374
41668
|
if (!flow) return { ok: false, status: 404, reason: "unknown or expired sign-in flow \u2014 restart the connection from claude.ai" };
|
|
41669
|
+
if (flow.wcSetupInFlight) {
|
|
41670
|
+
return { ok: false, status: 409, reason: "a mobile wallet pairing for this sign-in is already being set up - wait for it to finish" };
|
|
41671
|
+
}
|
|
41672
|
+
let global2 = 0;
|
|
41673
|
+
let perIp = 0;
|
|
41674
|
+
for (const f of this.flows.values()) {
|
|
41675
|
+
if (f === flow || f.wcSlotIp === void 0) continue;
|
|
41676
|
+
global2 += 1;
|
|
41677
|
+
if (f.wcSlotIp === requesterIp) perIp += 1;
|
|
41678
|
+
}
|
|
41679
|
+
if (global2 >= this.wcMaxGlobal) {
|
|
41680
|
+
return { ok: false, status: 429, reason: `mobile wallet sign-in is at capacity (${this.wcMaxGlobal} pairings open on this server) - try again in a few minutes, or sign in with a browser wallet` };
|
|
41681
|
+
}
|
|
41682
|
+
if (perIp >= this.wcMaxPerIp) {
|
|
41683
|
+
return { ok: false, status: 429, reason: `too many mobile wallet sign-ins are pending from your network address (at most ${this.wcMaxPerIp} at once) - finish one, or wait up to 10 minutes for it to expire` };
|
|
41684
|
+
}
|
|
41375
41685
|
if (flow.wc) this.disposeFlowTransport(flow);
|
|
41686
|
+
flow.wcSlotIp = requesterIp;
|
|
41687
|
+
flow.wcSetupInFlight = true;
|
|
41688
|
+
try {
|
|
41689
|
+
return await this.buildWcPairing(flowId, flow, wcOpts);
|
|
41690
|
+
} catch (e) {
|
|
41691
|
+
this.disposeFlowTransport(flow);
|
|
41692
|
+
throw e;
|
|
41693
|
+
} finally {
|
|
41694
|
+
delete flow.wcSetupInFlight;
|
|
41695
|
+
}
|
|
41696
|
+
}
|
|
41697
|
+
/** The setup steps of `wcPairing` — runs only under that method's slot reservation and
|
|
41698
|
+
* in-flight mark, which also own the failure cleanup. */
|
|
41699
|
+
async buildWcPairing(flowId, flow, wcOpts) {
|
|
41376
41700
|
const factory2 = wcOpts.transportFactory ?? (async (cfg) => {
|
|
41377
41701
|
const { WcTransport: WcTransport2 } = await Promise.resolve().then(() => (init_wc_transport(), wc_transport_exports));
|
|
41378
41702
|
return WcTransport2.create(cfg);
|
|
@@ -41380,8 +41704,21 @@ Issued At: ${new Date(this.clock()).toISOString()}`;
|
|
|
41380
41704
|
const transport = await factory2({
|
|
41381
41705
|
projectId: wcOpts.projectId,
|
|
41382
41706
|
chainId: this.opts.chainId,
|
|
41383
|
-
...wcOpts.relayUrl ? { relayUrl: wcOpts.relayUrl } : {}
|
|
41707
|
+
...wcOpts.relayUrl ? { relayUrl: wcOpts.relayUrl } : {},
|
|
41708
|
+
// L-2: the wallet is asked to sign an EIP-4361 message whose domain is THIS origin,
|
|
41709
|
+
// so the dapp it is told it is talking to must be this origin too — a mismatch makes
|
|
41710
|
+
// domain-binding wallets warn on every honest sign-in.
|
|
41711
|
+
metadata: {
|
|
41712
|
+
name: "Diamond Hands \u2014 sign in",
|
|
41713
|
+
description: "Sign in to the Diamond Hands connector \u2014 proves wallet ownership, moves no funds",
|
|
41714
|
+
url: this.opts.origin(),
|
|
41715
|
+
icons: []
|
|
41716
|
+
}
|
|
41384
41717
|
});
|
|
41718
|
+
if (this.flows.get(flowId) !== flow) {
|
|
41719
|
+
void transport.close().catch(() => void 0);
|
|
41720
|
+
return { ok: false, status: 404, reason: "unknown or expired sign-in flow \u2014 restart the connection from claude.ai" };
|
|
41721
|
+
}
|
|
41385
41722
|
const record = { transport, uri: "", state: "pairing" };
|
|
41386
41723
|
flow.wc = record;
|
|
41387
41724
|
transport.onSession((info) => {
|
|
@@ -41419,17 +41756,17 @@ Issued At: ${new Date(this.clock()).toISOString()}`;
|
|
|
41419
41756
|
true
|
|
41420
41757
|
);
|
|
41421
41758
|
};
|
|
41422
|
-
if (!
|
|
41759
|
+
if (!import_ethers2.ethers.isAddress(account)) {
|
|
41423
41760
|
fail(400, "the connected wallet reported an invalid address");
|
|
41424
41761
|
return;
|
|
41425
41762
|
}
|
|
41426
|
-
const checksummed =
|
|
41427
|
-
const message = this.mintSiweMessage(checksummed);
|
|
41763
|
+
const checksummed = import_ethers2.ethers.getAddress(account);
|
|
41764
|
+
const message = this.mintSiweMessage(checksummed, flow);
|
|
41428
41765
|
flow.siwe = { address: checksummed, message };
|
|
41429
41766
|
flow.wc.state = "awaiting-signature";
|
|
41430
41767
|
let signature;
|
|
41431
41768
|
try {
|
|
41432
|
-
signature = await transport.request("personal_sign", [
|
|
41769
|
+
signature = await transport.request("personal_sign", [import_ethers2.ethers.hexlify(import_ethers2.ethers.toUtf8Bytes(message)), checksummed]);
|
|
41433
41770
|
} catch (e) {
|
|
41434
41771
|
const msg = e instanceof Error ? e.message : String(e);
|
|
41435
41772
|
const declined = e.code === 4001 || /reject|declin|denied|cancel/i.test(msg);
|
|
@@ -41438,7 +41775,7 @@ Issued At: ${new Date(this.clock()).toISOString()}`;
|
|
|
41438
41775
|
}
|
|
41439
41776
|
let recovered;
|
|
41440
41777
|
try {
|
|
41441
|
-
recovered =
|
|
41778
|
+
recovered = import_ethers2.ethers.verifyMessage(message, signature);
|
|
41442
41779
|
} catch {
|
|
41443
41780
|
fail(400, "the signature is not a valid Ethereum signature");
|
|
41444
41781
|
return;
|
|
@@ -41451,11 +41788,12 @@ Issued At: ${new Date(this.clock()).toISOString()}`;
|
|
|
41451
41788
|
void transport.close().catch(() => void 0);
|
|
41452
41789
|
return;
|
|
41453
41790
|
}
|
|
41454
|
-
const code = (0,
|
|
41791
|
+
const code = (0, import_node_crypto3.randomBytes)(24).toString("hex");
|
|
41455
41792
|
this.codes.set(code, {
|
|
41456
41793
|
clientId: flow.clientId,
|
|
41457
41794
|
address: checksummed,
|
|
41458
41795
|
codeChallenge: flow.params.codeChallenge,
|
|
41796
|
+
redirectHost: new URL(flow.params.redirectUri).host,
|
|
41459
41797
|
createdAt: this.clock()
|
|
41460
41798
|
});
|
|
41461
41799
|
const redirect = new URL(flow.params.redirectUri);
|
|
@@ -41497,6 +41835,7 @@ Issued At: ${new Date(this.clock()).toISOString()}`;
|
|
|
41497
41835
|
/** Close a flow's WC transport (idempotent). `keepState` preserves the wc state
|
|
41498
41836
|
* machine for the page's poll — only the TRANSPORT is released. */
|
|
41499
41837
|
disposeFlowTransport(flow, keepState = false) {
|
|
41838
|
+
delete flow.wcSlotIp;
|
|
41500
41839
|
const wc = flow.wc;
|
|
41501
41840
|
if (!wc) return;
|
|
41502
41841
|
void wc.transport.close().catch(() => void 0);
|
|
@@ -41510,7 +41849,7 @@ Issued At: ${new Date(this.clock()).toISOString()}`;
|
|
|
41510
41849
|
if (!flow.siwe) return { ok: false, status: 400, reason: "no wallet address was reported for this flow yet" };
|
|
41511
41850
|
let recovered;
|
|
41512
41851
|
try {
|
|
41513
|
-
recovered =
|
|
41852
|
+
recovered = import_ethers2.ethers.verifyMessage(flow.siwe.message, signature);
|
|
41514
41853
|
} catch {
|
|
41515
41854
|
return { ok: false, status: 400, reason: "the signature is not a valid Ethereum signature" };
|
|
41516
41855
|
}
|
|
@@ -41518,11 +41857,12 @@ Issued At: ${new Date(this.clock()).toISOString()}`;
|
|
|
41518
41857
|
return { ok: false, status: 401, reason: "the signature does not match the connected wallet address" };
|
|
41519
41858
|
}
|
|
41520
41859
|
this.deleteFlow(flowId, flow);
|
|
41521
|
-
const code = (0,
|
|
41860
|
+
const code = (0, import_node_crypto3.randomBytes)(24).toString("hex");
|
|
41522
41861
|
this.codes.set(code, {
|
|
41523
41862
|
clientId: flow.clientId,
|
|
41524
41863
|
address: flow.siwe.address,
|
|
41525
41864
|
codeChallenge: flow.params.codeChallenge,
|
|
41865
|
+
redirectHost: new URL(flow.params.redirectUri).host,
|
|
41526
41866
|
createdAt: this.clock()
|
|
41527
41867
|
});
|
|
41528
41868
|
const redirect = new URL(flow.params.redirectUri);
|
|
@@ -41539,28 +41879,61 @@ Issued At: ${new Date(this.clock()).toISOString()}`;
|
|
|
41539
41879
|
const record = this.liveCode(authorizationCode);
|
|
41540
41880
|
if (!record || record.clientId !== client.client_id) throw new import_errors.InvalidGrantError("unknown, expired, or foreign authorization code");
|
|
41541
41881
|
this.codes.delete(authorizationCode);
|
|
41542
|
-
|
|
41882
|
+
const now = this.clock();
|
|
41883
|
+
const refreshToken = (0, import_node_crypto3.randomBytes)(32).toString("hex");
|
|
41884
|
+
const grant = {
|
|
41885
|
+
grantId: (0, import_node_crypto3.randomBytes)(16).toString("hex"),
|
|
41886
|
+
address: record.address.toLowerCase(),
|
|
41887
|
+
clientId: client.client_id,
|
|
41888
|
+
clientName: client.client_name ?? null,
|
|
41889
|
+
redirectHost: record.redirectHost,
|
|
41890
|
+
createdAt: now,
|
|
41891
|
+
lastUsedAt: now,
|
|
41892
|
+
refreshHash: hashToken(refreshToken),
|
|
41893
|
+
revokedAt: null,
|
|
41894
|
+
expireAt: now + this.refreshIdleMs
|
|
41895
|
+
};
|
|
41896
|
+
await this.store.createGrant(grant);
|
|
41897
|
+
await this.store.extendClient(client.client_id, grant.expireAt);
|
|
41898
|
+
return this.mintAccess(grant, refreshToken);
|
|
41543
41899
|
}
|
|
41544
41900
|
async exchangeRefreshToken(client, refreshToken) {
|
|
41545
|
-
const
|
|
41546
|
-
|
|
41547
|
-
if (
|
|
41548
|
-
|
|
41901
|
+
const oldHash = hashToken(refreshToken);
|
|
41902
|
+
const grant = await this.store.findGrantByRefreshHash(oldHash);
|
|
41903
|
+
if (!grant || grant.clientId !== client.client_id) throw new import_errors.InvalidGrantError("unknown or foreign refresh token");
|
|
41904
|
+
if (grant.revokedAt !== null) throw new import_errors.InvalidGrantError("this connection was revoked by the wallet owner \u2014 reconnect with a fresh wallet sign-in");
|
|
41905
|
+
const now = this.clock();
|
|
41906
|
+
if (now - grant.lastUsedAt > this.refreshIdleMs) {
|
|
41549
41907
|
throw new import_errors.InvalidGrantError("refresh token expired after inactivity \u2014 reconnect with a fresh wallet sign-in");
|
|
41550
41908
|
}
|
|
41551
|
-
|
|
41552
|
-
|
|
41909
|
+
const nextToken = (0, import_node_crypto3.randomBytes)(32).toString("hex");
|
|
41910
|
+
const next = { refreshHash: hashToken(nextToken), lastUsedAt: now, expireAt: now + this.refreshIdleMs };
|
|
41911
|
+
await this.store.extendClient(client.client_id, next.expireAt);
|
|
41912
|
+
if (!await this.store.rotateGrant(grant.grantId, oldHash, next)) {
|
|
41913
|
+
throw new import_errors.InvalidGrantError("refresh token already used or revoked \u2014 reconnect with a fresh wallet sign-in");
|
|
41914
|
+
}
|
|
41915
|
+
return this.mintAccess({ ...grant, ...next }, nextToken);
|
|
41553
41916
|
}
|
|
41554
41917
|
/** SDK contract: throws InvalidTokenError on anything not live. */
|
|
41555
41918
|
async verifyAccessToken(token) {
|
|
41556
|
-
const info = this.lookupAccessToken(token);
|
|
41919
|
+
const info = await this.lookupAccessToken(token);
|
|
41557
41920
|
if (!info) throw new import_errors.InvalidTokenError("unknown or expired access token");
|
|
41558
41921
|
return info;
|
|
41559
41922
|
}
|
|
41560
|
-
/** Non-throwing lookup for the connector's own request path (null = 401).
|
|
41561
|
-
|
|
41923
|
+
/** Non-throwing lookup for the connector's own request path (null = 401). The grant
|
|
41924
|
+
* behind the token is re-confirmed live when the last check is older than D6's bound. */
|
|
41925
|
+
async lookupAccessToken(token) {
|
|
41562
41926
|
const record = this.access.get(token);
|
|
41563
|
-
|
|
41927
|
+
const now = this.clock();
|
|
41928
|
+
if (!record || record.expiresAt * 1e3 <= now) return null;
|
|
41929
|
+
if (now - record.checkedAt > GRANT_RECHECK_MS) {
|
|
41930
|
+
const grant = await this.store.getGrant(record.grantId);
|
|
41931
|
+
if (!grant || !this.grantLive(grant, now)) {
|
|
41932
|
+
this.access.delete(token);
|
|
41933
|
+
return null;
|
|
41934
|
+
}
|
|
41935
|
+
record.checkedAt = now;
|
|
41936
|
+
}
|
|
41564
41937
|
return {
|
|
41565
41938
|
token,
|
|
41566
41939
|
clientId: record.clientId,
|
|
@@ -41572,14 +41945,46 @@ Issued At: ${new Date(this.clock()).toISOString()}`;
|
|
|
41572
41945
|
async revokeToken(client, request) {
|
|
41573
41946
|
const a = this.access.get(request.token);
|
|
41574
41947
|
if (a && a.clientId === client.client_id) this.access.delete(request.token);
|
|
41575
|
-
const
|
|
41576
|
-
if (
|
|
41577
|
-
}
|
|
41578
|
-
|
|
41579
|
-
|
|
41580
|
-
const
|
|
41581
|
-
this.
|
|
41582
|
-
|
|
41948
|
+
const grant = await this.store.findGrantByRefreshHash(hashToken(request.token));
|
|
41949
|
+
if (grant && grant.clientId === client.client_id) await this.revokeGrantRecord(grant.grantId);
|
|
41950
|
+
}
|
|
41951
|
+
/** Plan 18 — the account API's list: the address's LIVE grants, most recently used first. */
|
|
41952
|
+
async listGrants(address) {
|
|
41953
|
+
const now = this.clock();
|
|
41954
|
+
return (await this.store.listGrants(address.toLowerCase())).filter((g) => this.grantLive(g, now)).sort((x, y) => y.lastUsedAt - x.lastUsedAt).map((g) => ({
|
|
41955
|
+
id: g.grantId,
|
|
41956
|
+
clientId: g.clientId,
|
|
41957
|
+
clientName: g.clientName,
|
|
41958
|
+
redirectHost: g.redirectHost,
|
|
41959
|
+
createdAt: new Date(g.createdAt).toISOString(),
|
|
41960
|
+
lastUsedAt: new Date(g.lastUsedAt).toISOString()
|
|
41961
|
+
}));
|
|
41962
|
+
}
|
|
41963
|
+
/** Plan 18 — the wallet owner revokes one grant. False when the grant is unknown, not
|
|
41964
|
+
* live, or ANOTHER address's: the caller cannot tell those apart (no existence oracle). */
|
|
41965
|
+
async revokeGrantForAddress(address, grantId) {
|
|
41966
|
+
const grant = await this.store.getGrant(grantId);
|
|
41967
|
+
if (!grant || grant.address !== address.toLowerCase() || !this.grantLive(grant, this.clock())) return false;
|
|
41968
|
+
await this.revokeGrantRecord(grantId);
|
|
41969
|
+
return true;
|
|
41970
|
+
}
|
|
41971
|
+
async revokeGrantRecord(grantId) {
|
|
41972
|
+
await this.store.revokeGrant(grantId, this.clock());
|
|
41973
|
+
for (const [t, a] of this.access) if (a.grantId === grantId) this.access.delete(t);
|
|
41974
|
+
}
|
|
41975
|
+
grantLive(grant, now) {
|
|
41976
|
+
return grant.revokedAt === null && now - grant.lastUsedAt <= this.refreshIdleMs;
|
|
41977
|
+
}
|
|
41978
|
+
mintAccess(grant, refreshToken) {
|
|
41979
|
+
const accessToken = (0, import_node_crypto3.randomBytes)(32).toString("hex");
|
|
41980
|
+
const now = this.clock();
|
|
41981
|
+
this.access.set(accessToken, {
|
|
41982
|
+
address: grant.address,
|
|
41983
|
+
clientId: grant.clientId,
|
|
41984
|
+
grantId: grant.grantId,
|
|
41985
|
+
expiresAt: Math.floor(now / 1e3) + ACCESS_TTL_S,
|
|
41986
|
+
checkedAt: now
|
|
41987
|
+
});
|
|
41583
41988
|
return { access_token: accessToken, token_type: "bearer", expires_in: ACCESS_TTL_S, refresh_token: refreshToken };
|
|
41584
41989
|
}
|
|
41585
41990
|
liveFlow(flowId) {
|
|
@@ -41601,17 +42006,53 @@ Issued At: ${new Date(this.clock()).toISOString()}`;
|
|
|
41601
42006
|
return record;
|
|
41602
42007
|
}
|
|
41603
42008
|
/** Expired flows/codes/tokens are dropped opportunistically — no timers to leak. An
|
|
41604
|
-
* expired flow's WC transport is DISPOSED with it (M17-3);
|
|
41605
|
-
* here too (M17-9 — nothing grows forever). */
|
|
41606
|
-
sweep() {
|
|
42009
|
+
* expired flow's WC transport is DISPOSED with it (M17-3); expired clients and grants
|
|
42010
|
+
* leave the store here too (M17-9 — nothing grows forever). */
|
|
42011
|
+
async sweep() {
|
|
41607
42012
|
const now = this.clock();
|
|
41608
42013
|
for (const [id, f] of this.flows) if (now - f.createdAt > FLOW_TTL_MS) this.deleteFlow(id, f);
|
|
41609
42014
|
for (const [c, r] of this.codes) if (now - r.createdAt > CODE_TTL_MS) this.codes.delete(c);
|
|
41610
42015
|
for (const [t, a] of this.access) if (a.expiresAt * 1e3 <= now) this.access.delete(t);
|
|
41611
|
-
|
|
42016
|
+
await this.store.sweep(now);
|
|
41612
42017
|
}
|
|
41613
42018
|
};
|
|
41614
42019
|
|
|
42020
|
+
// src/connector/wc-min-version.ts
|
|
42021
|
+
var WC_MIN_SAFE_VERSION = "0.5.22";
|
|
42022
|
+
function parseVersion(label, v) {
|
|
42023
|
+
const m = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/.exec(v);
|
|
42024
|
+
if (!m) throw new Error(`${label} '${v}' is not a MAJOR.MINOR.PATCH[-prerelease] version`);
|
|
42025
|
+
return { core: [Number(m[1]), Number(m[2]), Number(m[3])], pre: m[4] ? m[4].split(".") : [] };
|
|
42026
|
+
}
|
|
42027
|
+
function compareVersions(a, b) {
|
|
42028
|
+
for (let i = 0; i < 3; i++) {
|
|
42029
|
+
const d = a.core[i] - b.core[i];
|
|
42030
|
+
if (d !== 0) return d;
|
|
42031
|
+
}
|
|
42032
|
+
if (a.pre.length === 0 || b.pre.length === 0) return b.pre.length - a.pre.length;
|
|
42033
|
+
for (let i = 0; i < Math.min(a.pre.length, b.pre.length); i++) {
|
|
42034
|
+
const x = a.pre[i];
|
|
42035
|
+
const y = b.pre[i];
|
|
42036
|
+
if (x === y) continue;
|
|
42037
|
+
const xNum = /^\d+$/.test(x);
|
|
42038
|
+
const yNum = /^\d+$/.test(y);
|
|
42039
|
+
if (xNum && yNum) return Number(x) - Number(y);
|
|
42040
|
+
if (xNum !== yNum) return xNum ? -1 : 1;
|
|
42041
|
+
return x < y ? -1 : 1;
|
|
42042
|
+
}
|
|
42043
|
+
return a.pre.length - b.pre.length;
|
|
42044
|
+
}
|
|
42045
|
+
function assertWcMinSafeVersion(version2, wcArmed) {
|
|
42046
|
+
if (!wcArmed) return;
|
|
42047
|
+
const have = parseVersion("connector version", version2);
|
|
42048
|
+
const need = parseVersion("WC_MIN_SAFE_VERSION", WC_MIN_SAFE_VERSION);
|
|
42049
|
+
if (compareVersions(have, need) < 0) {
|
|
42050
|
+
throw new Error(
|
|
42051
|
+
`refusing to boot: the WalletConnect leg is armed (DH_WC_PROJECT_ID) but this connector is v${version2}, below WC_MIN_SAFE_VERSION v${WC_MIN_SAFE_VERSION} \u2014 the first release carrying the plan-19 WalletConnect fixes. Roll forward, or unset DH_WC_PROJECT_ID.`
|
|
42052
|
+
);
|
|
42053
|
+
}
|
|
42054
|
+
}
|
|
42055
|
+
|
|
41615
42056
|
// src/boundary/errors.ts
|
|
41616
42057
|
function boundaryError(code, message, extra) {
|
|
41617
42058
|
return { code, message, ...extra?.source && { source: extra.source }, ...extra?.details && { details: extra.details } };
|
|
@@ -41835,13 +42276,14 @@ function resolveRealConfig(env) {
|
|
|
41835
42276
|
|
|
41836
42277
|
// src/boot.ts
|
|
41837
42278
|
var fs6 = __toESM(require("fs"));
|
|
41838
|
-
var
|
|
42279
|
+
var import_ethers54 = require("ethers");
|
|
41839
42280
|
|
|
41840
42281
|
// src/boundary/index.ts
|
|
41841
|
-
var
|
|
42282
|
+
var import_node_crypto10 = require("crypto");
|
|
41842
42283
|
var fs5 = __toESM(require("fs"));
|
|
41843
42284
|
var os2 = __toESM(require("os"));
|
|
41844
42285
|
var path4 = __toESM(require("path"));
|
|
42286
|
+
var import_ethers53 = require("ethers");
|
|
41845
42287
|
|
|
41846
42288
|
// src/boundary/envelope.ts
|
|
41847
42289
|
function okEnvelope(data, source, warnings = []) {
|
|
@@ -42904,11 +43346,11 @@ var DEFAULT_SEED = {
|
|
|
42904
43346
|
};
|
|
42905
43347
|
|
|
42906
43348
|
// src/boundary/upstream/mock/world.ts
|
|
42907
|
-
var
|
|
42908
|
-
var
|
|
43349
|
+
var import_node_crypto4 = require("crypto");
|
|
43350
|
+
var import_ethers4 = require("ethers");
|
|
42909
43351
|
|
|
42910
43352
|
// src/signer/safe.ts
|
|
42911
|
-
var
|
|
43353
|
+
var import_ethers3 = require("ethers");
|
|
42912
43354
|
var SAFE_TX_TYPES = {
|
|
42913
43355
|
SafeTx: [
|
|
42914
43356
|
{ name: "to", type: "address" },
|
|
@@ -42929,18 +43371,18 @@ var SAFE_MESSAGE_TYPES = {
|
|
|
42929
43371
|
var EXEC_TRANSACTION_ABI = [
|
|
42930
43372
|
"function execTransaction(address to,uint256 value,bytes data,uint8 operation,uint256 safeTxGas,uint256 baseGas,uint256 gasPrice,address gasToken,address refundReceiver,bytes signatures) returns (bool)"
|
|
42931
43373
|
];
|
|
42932
|
-
var execIface = new
|
|
43374
|
+
var execIface = new import_ethers3.ethers.Interface(EXEC_TRANSACTION_ABI);
|
|
42933
43375
|
function buildSafeTx(p) {
|
|
42934
43376
|
return {
|
|
42935
|
-
to:
|
|
43377
|
+
to: import_ethers3.ethers.getAddress(p.to),
|
|
42936
43378
|
value: 0n,
|
|
42937
43379
|
data: p.data,
|
|
42938
43380
|
operation: 0,
|
|
42939
43381
|
safeTxGas: 0n,
|
|
42940
43382
|
baseGas: 0n,
|
|
42941
43383
|
gasPrice: 0n,
|
|
42942
|
-
gasToken:
|
|
42943
|
-
refundReceiver:
|
|
43384
|
+
gasToken: import_ethers3.ethers.ZeroAddress,
|
|
43385
|
+
refundReceiver: import_ethers3.ethers.ZeroAddress,
|
|
42944
43386
|
nonce: p.nonce
|
|
42945
43387
|
};
|
|
42946
43388
|
}
|
|
@@ -42950,11 +43392,11 @@ function assertPinnedSafeTx(tx2) {
|
|
|
42950
43392
|
if (tx2.safeTxGas !== 0n) throw new Error(`SafeTx refused: non-zero safeTxGas ${tx2.safeTxGas}`);
|
|
42951
43393
|
if (tx2.baseGas !== 0n) throw new Error(`SafeTx refused: non-zero baseGas ${tx2.baseGas}`);
|
|
42952
43394
|
if (tx2.gasPrice !== 0n) throw new Error(`SafeTx refused: non-zero gasPrice ${tx2.gasPrice} \u2014 refund surface is closed`);
|
|
42953
|
-
if (tx2.gasToken !==
|
|
42954
|
-
if (tx2.refundReceiver !==
|
|
43395
|
+
if (tx2.gasToken !== import_ethers3.ethers.ZeroAddress) throw new Error(`SafeTx refused: non-zero gasToken ${tx2.gasToken}`);
|
|
43396
|
+
if (tx2.refundReceiver !== import_ethers3.ethers.ZeroAddress) throw new Error(`SafeTx refused: non-zero refundReceiver ${tx2.refundReceiver}`);
|
|
42955
43397
|
}
|
|
42956
43398
|
function domainOf(safe) {
|
|
42957
|
-
return { chainId: safe.chainId, verifyingContract:
|
|
43399
|
+
return { chainId: safe.chainId, verifyingContract: import_ethers3.ethers.getAddress(safe.address) };
|
|
42958
43400
|
}
|
|
42959
43401
|
function safeTxTypedData(safe, tx2) {
|
|
42960
43402
|
assertPinnedSafeTx(tx2);
|
|
@@ -42977,7 +43419,7 @@ function safeTxTypedData(safe, tx2) {
|
|
|
42977
43419
|
}
|
|
42978
43420
|
function safeTxHash(safe, tx2) {
|
|
42979
43421
|
const p = safeTxTypedData(safe, tx2);
|
|
42980
|
-
return
|
|
43422
|
+
return import_ethers3.ethers.TypedDataEncoder.hash(p.domain, p.types, p.message);
|
|
42981
43423
|
}
|
|
42982
43424
|
function safeMessageTypedData(safe, innerHash) {
|
|
42983
43425
|
if (!/^0x[0-9a-fA-F]{64}$/.test(innerHash)) {
|
|
@@ -42987,20 +43429,20 @@ function safeMessageTypedData(safe, innerHash) {
|
|
|
42987
43429
|
}
|
|
42988
43430
|
function safeMessageHash(safe, innerHash) {
|
|
42989
43431
|
const p = safeMessageTypedData(safe, innerHash);
|
|
42990
|
-
return
|
|
43432
|
+
return import_ethers3.ethers.TypedDataEncoder.hash(p.domain, p.types, p.message);
|
|
42991
43433
|
}
|
|
42992
43434
|
function aggregateSignatures(p) {
|
|
42993
43435
|
const ownerSet = new Set(p.owners.map((o) => o.toLowerCase()));
|
|
42994
43436
|
const entries = [];
|
|
42995
43437
|
for (const signature of p.signatures) {
|
|
42996
|
-
if (
|
|
42997
|
-
throw new Error(`signature aggregation refused: expected 65-byte ECDSA signature, got ${
|
|
43438
|
+
if (import_ethers3.ethers.dataLength(signature) !== 65) {
|
|
43439
|
+
throw new Error(`signature aggregation refused: expected 65-byte ECDSA signature, got ${import_ethers3.ethers.dataLength(signature)} bytes`);
|
|
42998
43440
|
}
|
|
42999
|
-
const v =
|
|
43441
|
+
const v = import_ethers3.ethers.dataSlice(signature, 64, 65);
|
|
43000
43442
|
if (v !== "0x1b" && v !== "0x1c") {
|
|
43001
43443
|
throw new Error(`signature aggregation refused: v=${v} is not a typed-data signature (v must be 27 or 28 \u2014 eth_sign and approved-hash encodings are forbidden)`);
|
|
43002
43444
|
}
|
|
43003
|
-
const signer =
|
|
43445
|
+
const signer = import_ethers3.ethers.recoverAddress(p.hash, signature);
|
|
43004
43446
|
if (!ownerSet.has(signer.toLowerCase())) {
|
|
43005
43447
|
throw new Error(`signature aggregation refused: ${signer} is not an owner of this Safe`);
|
|
43006
43448
|
}
|
|
@@ -43010,11 +43452,11 @@ function aggregateSignatures(p) {
|
|
|
43010
43452
|
entries.push({ signer, signature });
|
|
43011
43453
|
}
|
|
43012
43454
|
entries.sort((a, b) => BigInt(a.signer) < BigInt(b.signer) ? -1 : 1);
|
|
43013
|
-
return { signers: entries.map((e) => e.signer), blob:
|
|
43455
|
+
return { signers: entries.map((e) => e.signer), blob: import_ethers3.ethers.concat(entries.map((e) => e.signature)) };
|
|
43014
43456
|
}
|
|
43015
43457
|
function verifyThreshold(p) {
|
|
43016
43458
|
if (p.threshold < 1) return { ok: false, reason: `threshold ${p.threshold} is not positive` };
|
|
43017
|
-
const len =
|
|
43459
|
+
const len = import_ethers3.ethers.dataLength(p.blob);
|
|
43018
43460
|
if (len < p.threshold * 65) {
|
|
43019
43461
|
return { ok: false, reason: `signatures blob carries ${Math.floor(len / 65)} signature(s) \u2014 threshold is ${p.threshold}` };
|
|
43020
43462
|
}
|
|
@@ -43022,10 +43464,10 @@ function verifyThreshold(p) {
|
|
|
43022
43464
|
const signers = [];
|
|
43023
43465
|
let last = 0n;
|
|
43024
43466
|
for (let i = 0; i < p.threshold; i++) {
|
|
43025
|
-
const sig =
|
|
43467
|
+
const sig = import_ethers3.ethers.dataSlice(p.blob, i * 65, (i + 1) * 65);
|
|
43026
43468
|
let signer;
|
|
43027
43469
|
try {
|
|
43028
|
-
signer =
|
|
43470
|
+
signer = import_ethers3.ethers.recoverAddress(p.hash, sig);
|
|
43029
43471
|
} catch (e) {
|
|
43030
43472
|
return { ok: false, reason: `signature ${i + 1} does not recover: ${e.message}` };
|
|
43031
43473
|
}
|
|
@@ -43069,8 +43511,8 @@ function safeTxFromJson(j) {
|
|
|
43069
43511
|
}
|
|
43070
43512
|
|
|
43071
43513
|
// src/boundary/upstream/mock/world.ts
|
|
43072
|
-
var ethersIsAddress = (v) =>
|
|
43073
|
-
var toChecksum = (v) =>
|
|
43514
|
+
var ethersIsAddress = (v) => import_ethers4.ethers.isAddress(v);
|
|
43515
|
+
var toChecksum = (v) => import_ethers4.ethers.getAddress(v);
|
|
43074
43516
|
function termSeconds(months) {
|
|
43075
43517
|
return months === 12 ? 365 * 24 * 3600 : months * SECONDS_PER_TERM_MONTH;
|
|
43076
43518
|
}
|
|
@@ -43108,7 +43550,7 @@ var World = class {
|
|
|
43108
43550
|
nextId(prefix) {
|
|
43109
43551
|
this.state.counter += 1;
|
|
43110
43552
|
const n = this.state.counter;
|
|
43111
|
-
const hash = (0,
|
|
43553
|
+
const hash = (0, import_node_crypto4.createHash)("sha256").update(`${this.state.seed.namespace}:${prefix}:${n}`).digest("hex");
|
|
43112
43554
|
return { n, hash };
|
|
43113
43555
|
}
|
|
43114
43556
|
nextTxRef() {
|
|
@@ -44059,7 +44501,7 @@ var WorldStore = class {
|
|
|
44059
44501
|
};
|
|
44060
44502
|
|
|
44061
44503
|
// src/boundary/upstream/mock/signer.ts
|
|
44062
|
-
var
|
|
44504
|
+
var import_node_crypto5 = require("crypto");
|
|
44063
44505
|
function mockSign(op, borrower, stance) {
|
|
44064
44506
|
if (stance === "decline") {
|
|
44065
44507
|
return {
|
|
@@ -44074,7 +44516,7 @@ function mockSign(op, borrower, stance) {
|
|
|
44074
44516
|
signer: borrower,
|
|
44075
44517
|
action: op.action,
|
|
44076
44518
|
card: op.card,
|
|
44077
|
-
digest: (0,
|
|
44519
|
+
digest: (0, import_node_crypto5.createHash)("sha256").update(`${borrower}:${op.card}`).digest("hex")
|
|
44078
44520
|
}
|
|
44079
44521
|
};
|
|
44080
44522
|
}
|
|
@@ -44248,9 +44690,9 @@ var MockControl = class {
|
|
|
44248
44690
|
};
|
|
44249
44691
|
|
|
44250
44692
|
// src/boundary/upstream/mock/tx-builder.ts
|
|
44251
|
-
var
|
|
44693
|
+
var import_ethers6 = require("ethers");
|
|
44252
44694
|
init_tx_validator();
|
|
44253
|
-
var ZERO32 =
|
|
44695
|
+
var ZERO32 = import_ethers6.ethers.ZeroHash;
|
|
44254
44696
|
var EMPTY_SIG = "0x" + "00".repeat(65);
|
|
44255
44697
|
function tx(ctx, data) {
|
|
44256
44698
|
return { to: ctx.positionManager, data, value: "0x0", chainId: ctx.chainId };
|
|
@@ -44311,9 +44753,9 @@ function psmApprovalSteps(allowanceBefore, amountIn) {
|
|
|
44311
44753
|
}
|
|
44312
44754
|
|
|
44313
44755
|
// src/boundary/upstream/mock/sink-contracts.ts
|
|
44314
|
-
var
|
|
44756
|
+
var import_ethers7 = require("ethers");
|
|
44315
44757
|
function sinkAddress(label) {
|
|
44316
|
-
return
|
|
44758
|
+
return import_ethers7.ethers.getAddress("0x" + import_ethers7.ethers.keccak256(import_ethers7.ethers.toUtf8Bytes(`dh-mock-sink:${label}`)).slice(-40));
|
|
44317
44759
|
}
|
|
44318
44760
|
var SINK_CONTRACTS = {
|
|
44319
44761
|
PositionManager: sinkAddress("PositionManager"),
|
|
@@ -44327,7 +44769,7 @@ var SINK_CONTRACTS = {
|
|
|
44327
44769
|
|
|
44328
44770
|
// src/boundary/signer-manager.ts
|
|
44329
44771
|
var fs2 = __toESM(require("fs"));
|
|
44330
|
-
var
|
|
44772
|
+
var import_ethers8 = require("ethers");
|
|
44331
44773
|
function memorySignerPersistence() {
|
|
44332
44774
|
let state = null;
|
|
44333
44775
|
return {
|
|
@@ -44344,8 +44786,13 @@ var SignerManager = class {
|
|
|
44344
44786
|
mode: deps.initialMode,
|
|
44345
44787
|
borrower: deps.configuredBorrower ?? null
|
|
44346
44788
|
};
|
|
44789
|
+
if (deps.authenticatedBorrower) this.state = { ...this.state, borrower: deps.authenticatedBorrower };
|
|
44347
44790
|
}
|
|
44348
44791
|
state;
|
|
44792
|
+
/** True when the borrower is the signed-in identity and cannot be swapped. */
|
|
44793
|
+
identityPinned() {
|
|
44794
|
+
return this.deps.authenticatedBorrower !== void 0;
|
|
44795
|
+
}
|
|
44349
44796
|
mode() {
|
|
44350
44797
|
return this.state.mode;
|
|
44351
44798
|
}
|
|
@@ -44385,7 +44832,7 @@ var SignerManager = class {
|
|
|
44385
44832
|
this.deps.persistence.save(this.state);
|
|
44386
44833
|
}
|
|
44387
44834
|
resetBorrower() {
|
|
44388
|
-
this.state = { ...this.state, borrower: null };
|
|
44835
|
+
this.state = { ...this.state, borrower: this.deps.authenticatedBorrower ?? null };
|
|
44389
44836
|
this.deps.persistence.save(this.state);
|
|
44390
44837
|
}
|
|
44391
44838
|
async use(mode, opts) {
|
|
@@ -44405,7 +44852,7 @@ var SignerManager = class {
|
|
|
44405
44852
|
return { ok: false, reason: `mode '${mode}' needs the Safe's address \u2014 say for example: use ${mode} 0xYourSafeAddress` };
|
|
44406
44853
|
}
|
|
44407
44854
|
const truncated = `${String(addr).slice(0, 12)}\u2026`;
|
|
44408
|
-
if (!
|
|
44855
|
+
if (!import_ethers8.ethers.isAddress(addr)) return { ok: false, reason: `'${truncated}' is not a valid Safe address` };
|
|
44409
44856
|
if (!this.deps.safeInfo) return { ok: false, reason: "this boundary construction has no Safe discovery \u2014 mode 'safe' is unavailable here" };
|
|
44410
44857
|
const info = this.deps.safeInfo(addr);
|
|
44411
44858
|
if (!info) {
|
|
@@ -44418,7 +44865,7 @@ var SignerManager = class {
|
|
|
44418
44865
|
const role = mode === "safe-module" ? "the delegated AGENT key" : "owner-signer and executor";
|
|
44419
44866
|
return { ok: false, reason: `mode '${mode}' needs the keystore as ${role}: ${ready.reason}` };
|
|
44420
44867
|
}
|
|
44421
|
-
const checksummed =
|
|
44868
|
+
const checksummed = import_ethers8.ethers.getAddress(addr);
|
|
44422
44869
|
if (this.state.borrower && this.state.borrower.toLowerCase() !== checksummed.toLowerCase()) {
|
|
44423
44870
|
return {
|
|
44424
44871
|
ok: false,
|
|
@@ -44511,8 +44958,8 @@ var KeystoreProvider = class {
|
|
|
44511
44958
|
/** Runtime provisioning (bridge unlock page): decrypt pasted/on-disk material. */
|
|
44512
44959
|
async unlock(keystoreJson, password) {
|
|
44513
44960
|
try {
|
|
44514
|
-
const decrypted = await
|
|
44515
|
-
if (!(decrypted instanceof
|
|
44961
|
+
const decrypted = await import_ethers8.ethers.Wallet.fromEncryptedJson(keystoreJson, password);
|
|
44962
|
+
if (!(decrypted instanceof import_ethers8.ethers.Wallet)) return { ok: false, reason: "the keystore did not decrypt to an EOA wallet" };
|
|
44516
44963
|
this.wallet = decrypted;
|
|
44517
44964
|
return { ok: true, address: decrypted.address };
|
|
44518
44965
|
} catch {
|
|
@@ -44529,10 +44976,10 @@ var KeystoreProvider = class {
|
|
|
44529
44976
|
}
|
|
44530
44977
|
/** Generate a FRESH keystore encrypted with the page-provided password, save it, unlock it. */
|
|
44531
44978
|
async generateAndSave(password, savePath) {
|
|
44532
|
-
const wallet =
|
|
44533
|
-
const json = await new
|
|
44979
|
+
const wallet = import_ethers8.ethers.Wallet.createRandom();
|
|
44980
|
+
const json = await new import_ethers8.ethers.Wallet(wallet.privateKey).encrypt(password);
|
|
44534
44981
|
fs2.writeFileSync(savePath, json);
|
|
44535
|
-
this.wallet = new
|
|
44982
|
+
this.wallet = new import_ethers8.ethers.Wallet(wallet.privateKey);
|
|
44536
44983
|
return { ok: true, address: wallet.address, savedTo: savePath };
|
|
44537
44984
|
}
|
|
44538
44985
|
async ensureReady() {
|
|
@@ -45453,12 +45900,12 @@ var MockUpstreamPlugin = class {
|
|
|
45453
45900
|
};
|
|
45454
45901
|
|
|
45455
45902
|
// src/boundary/upstream/mock/external-ceremony.ts
|
|
45456
|
-
var
|
|
45903
|
+
var import_node_crypto6 = require("crypto");
|
|
45457
45904
|
var import_node_child_process = require("child_process");
|
|
45458
|
-
var
|
|
45905
|
+
var import_ethers11 = require("ethers");
|
|
45459
45906
|
|
|
45460
45907
|
// src/boundary/upstream/shared/external-bridge/card.ts
|
|
45461
|
-
var
|
|
45908
|
+
var import_ethers9 = require("ethers");
|
|
45462
45909
|
init_tx_validator();
|
|
45463
45910
|
|
|
45464
45911
|
// src/boundary/upstream/shared/external-bridge/card-escape.ts
|
|
@@ -45625,12 +46072,12 @@ function operationTypedData(p) {
|
|
|
45625
46072
|
detail: p.detail,
|
|
45626
46073
|
borrower: p.borrower,
|
|
45627
46074
|
issuedAt: p.issuedAtSec,
|
|
45628
|
-
nonce: "0x" + Buffer.from(
|
|
46075
|
+
nonce: "0x" + Buffer.from(import_ethers9.ethers.randomBytes(32)).toString("hex")
|
|
45629
46076
|
}
|
|
45630
46077
|
};
|
|
45631
46078
|
}
|
|
45632
46079
|
function recoverOperationSigner(payload, signature) {
|
|
45633
|
-
return
|
|
46080
|
+
return import_ethers9.ethers.verifyTypedData(
|
|
45634
46081
|
payload.domain,
|
|
45635
46082
|
payload.types,
|
|
45636
46083
|
payload.message,
|
|
@@ -45642,7 +46089,7 @@ function recoverOperationSigner(payload, signature) {
|
|
|
45642
46089
|
init_tx_validator();
|
|
45643
46090
|
|
|
45644
46091
|
// src/signer/keystore-signer.ts
|
|
45645
|
-
var
|
|
46092
|
+
var import_ethers10 = require("ethers");
|
|
45646
46093
|
var LOGIN_DOMAIN = (chainId) => ({ name: "Diamond Hands", version: "1", chainId });
|
|
45647
46094
|
var LOGIN_TYPES = {
|
|
45648
46095
|
DiamondHands: [
|
|
@@ -45667,14 +46114,14 @@ function buildLoginTypedData(chainId, address, audience) {
|
|
|
45667
46114
|
message: {
|
|
45668
46115
|
address,
|
|
45669
46116
|
issuedAt: Math.floor(Date.now() / 1e3),
|
|
45670
|
-
nonce: "0x" + Buffer.from(
|
|
46117
|
+
nonce: "0x" + Buffer.from(import_ethers10.ethers.randomBytes(32)).toString("hex"),
|
|
45671
46118
|
...audience ? { audience } : {}
|
|
45672
46119
|
}
|
|
45673
46120
|
};
|
|
45674
46121
|
}
|
|
45675
46122
|
function recoverLoginSigner(payload) {
|
|
45676
46123
|
const types = payload.message.audience ? LOGIN_TYPES_WITH_AUDIENCE : LOGIN_TYPES;
|
|
45677
|
-
return
|
|
46124
|
+
return import_ethers10.ethers.verifyTypedData(LOGIN_DOMAIN(payload.chainId), types, payload.message, payload.signature);
|
|
45678
46125
|
}
|
|
45679
46126
|
|
|
45680
46127
|
// src/boundary/upstream/mock/external-ceremony.ts
|
|
@@ -45700,7 +46147,7 @@ var ExternalCeremony = class {
|
|
|
45700
46147
|
validateUnsignedTx({ ...p.tx }, p.expected, this.deps.vctx);
|
|
45701
46148
|
const card = cardForTx(p.tx);
|
|
45702
46149
|
const outcome = await this.request({
|
|
45703
|
-
id: (0,
|
|
46150
|
+
id: (0, import_node_crypto6.randomUUID)(),
|
|
45704
46151
|
kind: "transaction",
|
|
45705
46152
|
action: p.action,
|
|
45706
46153
|
card,
|
|
@@ -45745,7 +46192,7 @@ var ExternalCeremony = class {
|
|
|
45745
46192
|
message
|
|
45746
46193
|
};
|
|
45747
46194
|
const outcome = await this.request({
|
|
45748
|
-
id: (0,
|
|
46195
|
+
id: (0, import_node_crypto6.randomUUID)(),
|
|
45749
46196
|
kind: "typed-data",
|
|
45750
46197
|
action: "login",
|
|
45751
46198
|
card: cardForTypedData("login", typedData),
|
|
@@ -45773,7 +46220,7 @@ var ExternalCeremony = class {
|
|
|
45773
46220
|
});
|
|
45774
46221
|
const card = cardForTypedData(p.action, typedData);
|
|
45775
46222
|
const outcome = await this.request({
|
|
45776
|
-
id: (0,
|
|
46223
|
+
id: (0, import_node_crypto6.randomUUID)(),
|
|
45777
46224
|
kind: "typed-data",
|
|
45778
46225
|
action: p.action,
|
|
45779
46226
|
card,
|
|
@@ -45811,7 +46258,7 @@ var ExternalCeremony = class {
|
|
|
45811
46258
|
* back, else fetched from the sink chain by hash (the MetaMask path). */
|
|
45812
46259
|
async readSignedTx(outcome) {
|
|
45813
46260
|
if (outcome.rawSignedTx) {
|
|
45814
|
-
const parsed =
|
|
46261
|
+
const parsed = import_ethers11.ethers.Transaction.from(outcome.rawSignedTx);
|
|
45815
46262
|
if (!parsed.from || !parsed.to || !parsed.hash) {
|
|
45816
46263
|
return this.refuse("rejected", "the returned raw transaction is unsigned or malformed");
|
|
45817
46264
|
}
|
|
@@ -45827,7 +46274,7 @@ var ExternalCeremony = class {
|
|
|
45827
46274
|
"the wallet broadcast a transaction but DH_MOCK_SINK_RPC is not set \u2014 the bridge cannot verify what was signed"
|
|
45828
46275
|
);
|
|
45829
46276
|
}
|
|
45830
|
-
const provider = new
|
|
46277
|
+
const provider = new import_ethers11.ethers.JsonRpcProvider(this.deps.sinkRpcUrl, this.deps.chainId, { staticNetwork: true });
|
|
45831
46278
|
let tx2 = null;
|
|
45832
46279
|
for (let i = 0; i < TX_FETCH_ATTEMPTS && tx2 === null; i++) {
|
|
45833
46280
|
tx2 = await provider.getTransaction(hash);
|
|
@@ -45873,7 +46320,7 @@ function openInBrowser(url2) {
|
|
|
45873
46320
|
}
|
|
45874
46321
|
|
|
45875
46322
|
// src/boundary/upstream/mock/keystore-ceremony.ts
|
|
45876
|
-
var
|
|
46323
|
+
var import_ethers12 = require("ethers");
|
|
45877
46324
|
init_tx_validator();
|
|
45878
46325
|
var SOURCE2 = "keystore-signer";
|
|
45879
46326
|
var KeystoreCeremony = class {
|
|
@@ -45905,7 +46352,7 @@ var KeystoreCeremony = class {
|
|
|
45905
46352
|
data: p.tx.data,
|
|
45906
46353
|
value: BigInt(p.tx.value)
|
|
45907
46354
|
});
|
|
45908
|
-
const parsed =
|
|
46355
|
+
const parsed = import_ethers12.ethers.Transaction.from(raw);
|
|
45909
46356
|
if (!parsed.from || parsed.from.toLowerCase() !== p.borrower.toLowerCase() || !parsed.hash) {
|
|
45910
46357
|
return this.refuse(`${p.action}: keystore signature did not recover to the borrower \u2014 refusing to apply state`);
|
|
45911
46358
|
}
|
|
@@ -45948,8 +46395,8 @@ var KeystoreCeremony = class {
|
|
|
45948
46395
|
};
|
|
45949
46396
|
|
|
45950
46397
|
// src/boundary/upstream/mock/safe-ceremony.ts
|
|
45951
|
-
var
|
|
45952
|
-
var
|
|
46398
|
+
var import_node_crypto7 = require("crypto");
|
|
46399
|
+
var import_ethers13 = require("ethers");
|
|
45953
46400
|
init_tx_validator();
|
|
45954
46401
|
|
|
45955
46402
|
// src/boundary/upstream/shared/quantum.ts
|
|
@@ -46013,7 +46460,7 @@ var SafeCeremony = class {
|
|
|
46013
46460
|
data: p.tx.data,
|
|
46014
46461
|
value: BigInt(p.tx.value)
|
|
46015
46462
|
});
|
|
46016
|
-
const parsed =
|
|
46463
|
+
const parsed = import_ethers13.ethers.Transaction.from(raw);
|
|
46017
46464
|
if (!parsed.from || parsed.from.toLowerCase() !== executor.address.toLowerCase() || !parsed.hash) {
|
|
46018
46465
|
return this.refuse(`${p.action}: executor signature did not recover \u2014 refusing to apply state`);
|
|
46019
46466
|
}
|
|
@@ -46049,7 +46496,7 @@ var SafeCeremony = class {
|
|
|
46049
46496
|
if (!auth.ok) return auth.refusal;
|
|
46050
46497
|
plane1Signers = auth.signers;
|
|
46051
46498
|
}
|
|
46052
|
-
const intentData =
|
|
46499
|
+
const intentData = import_ethers13.ethers.AbiCoder.defaultAbiCoder().encode(["string", "string"], [`dh-mock-${p.action}`, p.detail]);
|
|
46053
46500
|
const tx2 = buildSafeTx({ to: this.txContext().positionManager, data: intentData, nonce: BigInt(safe.nonce) });
|
|
46054
46501
|
const collected = await this.collectSafeTxBlob({ action: p.action, safe, tx: tx2 });
|
|
46055
46502
|
if (!collected.ok) return collected.refusal;
|
|
@@ -46167,7 +46614,7 @@ var SafeCeremony = class {
|
|
|
46167
46614
|
detail: p.detail,
|
|
46168
46615
|
issuedAtSec: p.issuedAtSec
|
|
46169
46616
|
});
|
|
46170
|
-
const envelopeHash =
|
|
46617
|
+
const envelopeHash = import_ethers13.ethers.TypedDataEncoder.hash(
|
|
46171
46618
|
envelope.domain,
|
|
46172
46619
|
envelope.types,
|
|
46173
46620
|
envelope.message
|
|
@@ -46247,7 +46694,7 @@ var SafeCeremony = class {
|
|
|
46247
46694
|
const primaryType = Object.keys(build.payload.types)[0];
|
|
46248
46695
|
const outcome = await bridge.requestSignatureCollection(
|
|
46249
46696
|
{
|
|
46250
|
-
id: (0,
|
|
46697
|
+
id: (0, import_node_crypto7.randomUUID)(),
|
|
46251
46698
|
kind: "typed-data",
|
|
46252
46699
|
action,
|
|
46253
46700
|
card: build.card,
|
|
@@ -46264,7 +46711,7 @@ var SafeCeremony = class {
|
|
|
46264
46711
|
onApproval: (_account, signature) => {
|
|
46265
46712
|
let signer;
|
|
46266
46713
|
try {
|
|
46267
|
-
signer =
|
|
46714
|
+
signer = import_ethers13.ethers.recoverAddress(build.hash, signature);
|
|
46268
46715
|
} catch {
|
|
46269
46716
|
return { verdict: "rejected", reason: `signature does not recover \u2014 wrong payload or wallet`, done: false, progress: progress() };
|
|
46270
46717
|
}
|
|
@@ -46334,7 +46781,7 @@ var SafeCeremony = class {
|
|
|
46334
46781
|
}
|
|
46335
46782
|
safeMessageHashOf(safe, innerHash) {
|
|
46336
46783
|
const payload = safeMessageTypedData({ address: safe.address, chainId: safe.chainId }, innerHash);
|
|
46337
|
-
return
|
|
46784
|
+
return import_ethers13.ethers.TypedDataEncoder.hash(payload.domain, payload.types, payload.message);
|
|
46338
46785
|
}
|
|
46339
46786
|
/** The card pierces every wrapper (M6-5): base decode + Safe context. */
|
|
46340
46787
|
safeCard(base, safe, extra) {
|
|
@@ -46355,7 +46802,7 @@ var SafeCeremony = class {
|
|
|
46355
46802
|
};
|
|
46356
46803
|
|
|
46357
46804
|
// src/boundary/upstream/mock/safe-module-ceremony.ts
|
|
46358
|
-
var
|
|
46805
|
+
var import_ethers14 = require("ethers");
|
|
46359
46806
|
init_tx_validator();
|
|
46360
46807
|
var SOURCE4 = "safe-module";
|
|
46361
46808
|
var SafeModuleCeremony = class {
|
|
@@ -46401,7 +46848,7 @@ var SafeModuleCeremony = class {
|
|
|
46401
46848
|
const innerCard = cardForTx(p.tx);
|
|
46402
46849
|
const mod = world.moduleInfo(safe);
|
|
46403
46850
|
if (!mod) return this.refuse(`${p.action}: module vanished mid-ceremony`);
|
|
46404
|
-
const outerData = new
|
|
46851
|
+
const outerData = new import_ethers14.ethers.Interface(["function execute(address target, bytes data)"]).encodeFunctionData("execute", [
|
|
46405
46852
|
p.tx.to,
|
|
46406
46853
|
p.tx.data
|
|
46407
46854
|
]);
|
|
@@ -46417,7 +46864,7 @@ var SafeModuleCeremony = class {
|
|
|
46417
46864
|
data: outerData,
|
|
46418
46865
|
value: 0n
|
|
46419
46866
|
});
|
|
46420
|
-
const parsed =
|
|
46867
|
+
const parsed = import_ethers14.ethers.Transaction.from(raw);
|
|
46421
46868
|
if (!parsed.from || parsed.from.toLowerCase() !== agent.address.toLowerCase() || !parsed.hash) {
|
|
46422
46869
|
return this.refuse(`${p.action}: agent signature did not recover \u2014 refusing to apply state`);
|
|
46423
46870
|
}
|
|
@@ -46450,7 +46897,7 @@ var SafeModuleCeremony = class {
|
|
|
46450
46897
|
issuedAtSec: world.nowSec()
|
|
46451
46898
|
});
|
|
46452
46899
|
const sig = await agent.signTypedData(envelope.domain, envelope.types, envelope.message);
|
|
46453
|
-
const recovered =
|
|
46900
|
+
const recovered = import_ethers14.ethers.verifyTypedData(envelope.domain, envelope.types, envelope.message, sig);
|
|
46454
46901
|
if (recovered.toLowerCase() !== agent.address.toLowerCase()) {
|
|
46455
46902
|
return this.refuse(`${p.action}: agent signature did not recover \u2014 refusing to apply state`);
|
|
46456
46903
|
}
|
|
@@ -46462,7 +46909,7 @@ var SafeModuleCeremony = class {
|
|
|
46462
46909
|
signer: agent.address,
|
|
46463
46910
|
action: p.action,
|
|
46464
46911
|
card: this.moduleCard(cardForTypedData(p.action, envelope), safe, mod?.moduleAddress ?? "?", agent.address),
|
|
46465
|
-
digest:
|
|
46912
|
+
digest: import_ethers14.ethers.TypedDataEncoder.hash(envelope.domain, envelope.types, envelope.message)
|
|
46466
46913
|
}
|
|
46467
46914
|
};
|
|
46468
46915
|
}
|
|
@@ -46486,7 +46933,7 @@ var SafeModuleCeremony = class {
|
|
|
46486
46933
|
`Submitted by agent ${agent.address} through AgentModule ${mod?.moduleAddress ?? "?"} (msg.sender = the Safe)`,
|
|
46487
46934
|
p.detail
|
|
46488
46935
|
].join("\n"),
|
|
46489
|
-
digest:
|
|
46936
|
+
digest: import_ethers14.ethers.id(`dh-module-withdraw:${safe}:${env.issuedAtSec}:${p.detail}`)
|
|
46490
46937
|
}
|
|
46491
46938
|
};
|
|
46492
46939
|
}
|
|
@@ -46518,10 +46965,9 @@ var SafeModuleCeremony = class {
|
|
|
46518
46965
|
};
|
|
46519
46966
|
|
|
46520
46967
|
// src/boundary/upstream/real/plugin.ts
|
|
46521
|
-
var
|
|
46968
|
+
var import_ethers51 = require("ethers");
|
|
46522
46969
|
|
|
46523
46970
|
// node_modules/@gvnrdao/dh-sdk/dist/index.mjs
|
|
46524
|
-
var import_ethers14 = require("ethers");
|
|
46525
46971
|
var import_ethers15 = require("ethers");
|
|
46526
46972
|
var import_ethers16 = require("ethers");
|
|
46527
46973
|
var import_ethers17 = require("ethers");
|
|
@@ -46531,6 +46977,7 @@ var import_ethers20 = require("ethers");
|
|
|
46531
46977
|
var import_ethers21 = require("ethers");
|
|
46532
46978
|
var import_ethers22 = require("ethers");
|
|
46533
46979
|
var import_ethers23 = require("ethers");
|
|
46980
|
+
var import_ethers24 = require("ethers");
|
|
46534
46981
|
|
|
46535
46982
|
// node_modules/@noble/hashes/esm/utils.js
|
|
46536
46983
|
function isBytes(a) {
|
|
@@ -46978,11 +47425,11 @@ var ripemd1602 = ripemd160;
|
|
|
46978
47425
|
// node_modules/@gvnrdao/dh-sdk/dist/index.mjs
|
|
46979
47426
|
var import_bech32 = __toESM(require_dist(), 1);
|
|
46980
47427
|
var import_bs58check = __toESM(require_bs58check(), 1);
|
|
46981
|
-
var import_ethers24 = require("ethers");
|
|
46982
47428
|
var import_ethers25 = require("ethers");
|
|
46983
47429
|
var import_ethers26 = require("ethers");
|
|
46984
47430
|
var import_ethers27 = require("ethers");
|
|
46985
47431
|
var import_ethers28 = require("ethers");
|
|
47432
|
+
var import_ethers29 = require("ethers");
|
|
46986
47433
|
|
|
46987
47434
|
// node_modules/axios/lib/helpers/bind.js
|
|
46988
47435
|
function bind(fn, thisArg) {
|
|
@@ -52607,15 +53054,15 @@ var {
|
|
|
52607
53054
|
} = axios_default;
|
|
52608
53055
|
|
|
52609
53056
|
// node_modules/@gvnrdao/dh-sdk/dist/index.mjs
|
|
52610
|
-
var import_ethers29 = require("ethers");
|
|
52611
53057
|
var import_ethers30 = require("ethers");
|
|
52612
53058
|
var import_ethers31 = require("ethers");
|
|
52613
53059
|
var import_ethers32 = require("ethers");
|
|
52614
53060
|
var import_ethers33 = require("ethers");
|
|
52615
53061
|
var import_ethers34 = require("ethers");
|
|
52616
|
-
var import_dh_lit_ops = __toESM(require_dist3(), 1);
|
|
52617
53062
|
var import_ethers35 = require("ethers");
|
|
53063
|
+
var import_dh_lit_ops = __toESM(require_dist3(), 1);
|
|
52618
53064
|
var import_ethers36 = require("ethers");
|
|
53065
|
+
var import_ethers37 = require("ethers");
|
|
52619
53066
|
var __create2 = Object.create;
|
|
52620
53067
|
var __defProp2 = Object.defineProperty;
|
|
52621
53068
|
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
@@ -52765,11 +53212,11 @@ var init_deployment_addresses = __esm2({
|
|
|
52765
53212
|
reason: "Shared upgrade script: AdminModule implementation update"
|
|
52766
53213
|
},
|
|
52767
53214
|
PositionManagerViews: {
|
|
52768
|
-
previousImplementation: "
|
|
52769
|
-
newImplementation: "
|
|
52770
|
-
upgradedAt: "2026-
|
|
52771
|
-
upgradedBy: "
|
|
52772
|
-
reason: "
|
|
53215
|
+
previousImplementation: "0xA455B542cFb36AF8451fc420dB89e590E5c87cef",
|
|
53216
|
+
newImplementation: "0x8cEB3F1c07fDB3301f55b96a5B9aDb33C8d36Da3",
|
|
53217
|
+
upgradedAt: "2026-10-02T17:04:25.853Z",
|
|
53218
|
+
upgradedBy: "0x0f8f23674cc90Ef7107930a4437341fD8B460362",
|
|
53219
|
+
reason: "1.1.2: getBackingVaults (PoR backing set) + implementation lock (constructor)"
|
|
52773
53220
|
},
|
|
52774
53221
|
TestPositionManager: {
|
|
52775
53222
|
previousImplementation: "0x0B46Ee1a9C6b42559758B7FF78294Cd867BB08f8",
|
|
@@ -54229,6 +54676,32 @@ var require_pkg_src2 = __commonJS2({
|
|
|
54229
54676
|
deployedAt: 1790246264563,
|
|
54230
54677
|
size: 69219,
|
|
54231
54678
|
hash: "bda048d8cd6b5a39c2774bcf1320e82d1eea935c2a521006fb8b887e13b6dd8d"
|
|
54679
|
+
},
|
|
54680
|
+
carryCollateralAttestation: {
|
|
54681
|
+
cid: "QmYWULmXD9S5AmTdQqWqoZ28ctsZQNcXkAgre9G2Xo9dh8",
|
|
54682
|
+
authorizedCidHex: cidToHex(
|
|
54683
|
+
"QmYWULmXD9S5AmTdQqWqoZ28ctsZQNcXkAgre9G2Xo9dh8"
|
|
54684
|
+
),
|
|
54685
|
+
name: "Carry Collateral Attestation",
|
|
54686
|
+
description: "LoanCarryVault collateral attestation (borrower, BTC vault, confirmed BTC)",
|
|
54687
|
+
version: "1.0.0",
|
|
54688
|
+
deployed: true,
|
|
54689
|
+
deployedAt: 1790927734070,
|
|
54690
|
+
size: 21156,
|
|
54691
|
+
hash: "05b177e0bb36b0483db4a42d33c1bbbf47eb9ef34ae278459397d51a7f8957ff"
|
|
54692
|
+
},
|
|
54693
|
+
carryFundingAttestation: {
|
|
54694
|
+
cid: "QmWhox3xUZMNR5NpPZ9WLSPC5GoW4ms88GanVRKr8uuS3W",
|
|
54695
|
+
authorizedCidHex: cidToHex(
|
|
54696
|
+
"QmWhox3xUZMNR5NpPZ9WLSPC5GoW4ms88GanVRKr8uuS3W"
|
|
54697
|
+
),
|
|
54698
|
+
name: "Carry Funding Attestation",
|
|
54699
|
+
description: "LoanCarryVault funding attestation (Hyperliquid BTC windowed hourly average)",
|
|
54700
|
+
version: "1.0.0",
|
|
54701
|
+
deployed: true,
|
|
54702
|
+
deployedAt: 1790925699980,
|
|
54703
|
+
size: 7193,
|
|
54704
|
+
hash: "4944ada61610cf64b32e33b5be62087088dcf5e821040c69e67942e643ce74c9"
|
|
54232
54705
|
}
|
|
54233
54706
|
};
|
|
54234
54707
|
function getDeploymentsForNetwork(network) {
|
|
@@ -58772,10 +59245,10 @@ var DEFAULT_FEE_CEILING = {
|
|
|
58772
59245
|
maxTxFeeWei: DEFAULT_MAX_TX_FEE_WEI
|
|
58773
59246
|
};
|
|
58774
59247
|
function fmtEth(wei) {
|
|
58775
|
-
return `${
|
|
59248
|
+
return `${import_ethers17.ethers.formatEther(wei)} ETH`;
|
|
58776
59249
|
}
|
|
58777
59250
|
function fmtGwei(wei) {
|
|
58778
|
-
return `${
|
|
59251
|
+
return `${import_ethers17.ethers.formatUnits(wei, "gwei")} gwei`;
|
|
58779
59252
|
}
|
|
58780
59253
|
function worstCaseFeeWei(gasLimit, maxFeePerGas) {
|
|
58781
59254
|
if (gasLimit == null || maxFeePerGas == null)
|
|
@@ -58824,12 +59297,12 @@ function parseFeeHistory(raw) {
|
|
|
58824
59297
|
`eth_feeHistory returned no reward percentiles \u2014 the RPC ignored the rewardPercentiles argument: ${JSON.stringify(raw)}`
|
|
58825
59298
|
);
|
|
58826
59299
|
}
|
|
58827
|
-
const nextBaseFee = (0,
|
|
59300
|
+
const nextBaseFee = (0, import_ethers16.getBigInt)(baseFeePerGas[baseFeePerGas.length - 1], "baseFeePerGas");
|
|
58828
59301
|
const tips = reward.map((perBlock, i) => {
|
|
58829
59302
|
if (!Array.isArray(perBlock) || perBlock.length === 0) {
|
|
58830
59303
|
throw new Error(`eth_feeHistory reward row ${i} is empty: ${JSON.stringify(raw)}`);
|
|
58831
59304
|
}
|
|
58832
|
-
return (0,
|
|
59305
|
+
return (0, import_ethers16.getBigInt)(perBlock[0], `reward[${i}]`);
|
|
58833
59306
|
});
|
|
58834
59307
|
return { nextBaseFee, tips };
|
|
58835
59308
|
}
|
|
@@ -58863,7 +59336,7 @@ async function resolveEip1559FeeFields(feeProvider) {
|
|
|
58863
59336
|
}
|
|
58864
59337
|
const history = parseFeeHistory(
|
|
58865
59338
|
await feeProvider.send("eth_feeHistory", [
|
|
58866
|
-
(0,
|
|
59339
|
+
(0, import_ethers16.toQuantity)(FEE_HISTORY_BLOCK_COUNT),
|
|
58867
59340
|
"latest",
|
|
58868
59341
|
[FEE_HISTORY_REWARD_PERCENTILE]
|
|
58869
59342
|
])
|
|
@@ -59276,7 +59749,7 @@ async function getPKPPublicKeyFromTokenId(pkpTokenId, provider, pkpNftContractAd
|
|
|
59276
59749
|
`pkpNftContractAddress is required for getPKPPublicKeyFromTokenId`
|
|
59277
59750
|
);
|
|
59278
59751
|
}
|
|
59279
|
-
const pkpNft = new
|
|
59752
|
+
const pkpNft = new import_ethers18.Contract(
|
|
59280
59753
|
pkpNftContractAddress,
|
|
59281
59754
|
PKP_NFT_ABI,
|
|
59282
59755
|
provider
|
|
@@ -59313,7 +59786,7 @@ async function generateBalanceConfirmationAuthorization(positionId, chainId, sig
|
|
|
59313
59786
|
const timestamp = calculateNextQuantumTimestamp();
|
|
59314
59787
|
const caller = await signer.getAddress();
|
|
59315
59788
|
const action = "confirm-balance";
|
|
59316
|
-
const actionHash = (0,
|
|
59789
|
+
const actionHash = (0, import_ethers18.keccak256)((0, import_ethers18.toUtf8Bytes)(action));
|
|
59317
59790
|
const types = [
|
|
59318
59791
|
"bytes32",
|
|
59319
59792
|
// positionId
|
|
@@ -59327,8 +59800,8 @@ async function generateBalanceConfirmationAuthorization(positionId, chainId, sig
|
|
|
59327
59800
|
// actionHash
|
|
59328
59801
|
];
|
|
59329
59802
|
const values = [positionId, timestamp, chainId, caller, actionHash];
|
|
59330
|
-
const messageHash = (0,
|
|
59331
|
-
const messageHashBytes = (0,
|
|
59803
|
+
const messageHash = (0, import_ethers18.solidityPackedKeccak256)(types, values);
|
|
59804
|
+
const messageHashBytes = (0, import_ethers18.getBytes)(messageHash);
|
|
59332
59805
|
const signature = await signer.signMessage(messageHashBytes);
|
|
59333
59806
|
return {
|
|
59334
59807
|
positionId,
|
|
@@ -59519,7 +59992,7 @@ async function buildSignedLoginPayload(signer, chainId, audience, reuse, withSta
|
|
|
59519
59992
|
...statement ? { statement } : {},
|
|
59520
59993
|
address,
|
|
59521
59994
|
issuedAt: reuse?.issuedAt ?? Math.floor(Date.now() / 1e3),
|
|
59522
|
-
nonce: reuse?.nonce ?? (0,
|
|
59995
|
+
nonce: reuse?.nonce ?? (0, import_ethers20.hexlify)((0, import_ethers20.randomBytes)(32)),
|
|
59523
59996
|
...audience ? { audience } : {}
|
|
59524
59997
|
};
|
|
59525
59998
|
const signature = await signer.signTypedData(
|
|
@@ -60142,13 +60615,13 @@ function decodeQuantumRevert(e) {
|
|
|
60142
60615
|
if (!name && selector && data) {
|
|
60143
60616
|
try {
|
|
60144
60617
|
if (selector === ERROR_STRING_SELECTOR) {
|
|
60145
|
-
const [message] =
|
|
60618
|
+
const [message] = import_ethers21.AbiCoder.defaultAbiCoder().decode(
|
|
60146
60619
|
["string"],
|
|
60147
60620
|
"0x" + data.slice(10)
|
|
60148
60621
|
);
|
|
60149
60622
|
name = `Error("${message}")`;
|
|
60150
60623
|
} else if (selector === PANIC_SELECTOR) {
|
|
60151
|
-
const [code] =
|
|
60624
|
+
const [code] = import_ethers21.AbiCoder.defaultAbiCoder().decode(
|
|
60152
60625
|
["uint256"],
|
|
60153
60626
|
"0x" + data.slice(10)
|
|
60154
60627
|
);
|
|
@@ -60396,12 +60869,12 @@ var RECOVERY_INVALIDATE_ACTION = "btc-utxo-invalidator";
|
|
|
60396
60869
|
var QUANTUM_SECONDS = 60;
|
|
60397
60870
|
var QUANTUM_SAFE_THRESHOLD = 40;
|
|
60398
60871
|
function buildInvalidateMessageHash(params) {
|
|
60399
|
-
const positionIdBytes32 = (0,
|
|
60872
|
+
const positionIdBytes32 = (0, import_ethers22.zeroPadValue)(
|
|
60400
60873
|
params.positionId.startsWith("0x") ? params.positionId : `0x${params.positionId}`,
|
|
60401
60874
|
32
|
|
60402
60875
|
);
|
|
60403
|
-
const actionHash = (0,
|
|
60404
|
-
return (0,
|
|
60876
|
+
const actionHash = (0, import_ethers22.keccak256)((0, import_ethers22.toUtf8Bytes)(RECOVERY_INVALIDATE_ACTION));
|
|
60877
|
+
return (0, import_ethers22.solidityPackedKeccak256)(
|
|
60405
60878
|
[
|
|
60406
60879
|
"bytes32",
|
|
60407
60880
|
// positionId
|
|
@@ -60447,7 +60920,7 @@ async function buildInvalidateStaleSpendEnvelope(params) {
|
|
|
60447
60920
|
utxoTxid,
|
|
60448
60921
|
utxoVout
|
|
60449
60922
|
});
|
|
60450
|
-
const signature = await signer.signMessage((0,
|
|
60923
|
+
const signature = await signer.signMessage((0, import_ethers22.getBytes)(messageHash));
|
|
60451
60924
|
const borrowerAddress = await signer.getAddress();
|
|
60452
60925
|
return {
|
|
60453
60926
|
positionId,
|
|
@@ -60490,7 +60963,7 @@ function hashBtcInputSet(utxos) {
|
|
|
60490
60963
|
seen.add(key);
|
|
60491
60964
|
}
|
|
60492
60965
|
const canonical = normalized.sort((a, b) => a.txid < b.txid ? -1 : a.txid > b.txid ? 1 : a.vout - b.vout).map((u) => `${u.txid}:${u.vout}:${u.value}`).join("|");
|
|
60493
|
-
return (0,
|
|
60966
|
+
return (0, import_ethers23.keccak256)((0, import_ethers23.toUtf8Bytes)(canonical));
|
|
60494
60967
|
}
|
|
60495
60968
|
async function buildBtcExecuteEnvelope(params) {
|
|
60496
60969
|
const {
|
|
@@ -60535,15 +61008,15 @@ async function buildBtcExecuteEnvelope(params) {
|
|
|
60535
61008
|
} else {
|
|
60536
61009
|
timestamp = currentQuantumStart;
|
|
60537
61010
|
}
|
|
60538
|
-
const actionHash = (0,
|
|
60539
|
-
(0,
|
|
61011
|
+
const actionHash = (0, import_ethers23.keccak256)(
|
|
61012
|
+
(0, import_ethers23.toUtf8Bytes)("execute-btc-withdrawal")
|
|
60540
61013
|
);
|
|
60541
61014
|
const utxoIdentifier = `${txid}:${vout}`;
|
|
60542
|
-
const positionIdBytes32 = (0,
|
|
61015
|
+
const positionIdBytes32 = (0, import_ethers23.zeroPadValue)(
|
|
60543
61016
|
positionId.startsWith("0x") ? positionId : `0x${positionId}`,
|
|
60544
61017
|
32
|
|
60545
61018
|
);
|
|
60546
|
-
const messageHash = (0,
|
|
61019
|
+
const messageHash = (0, import_ethers23.solidityPackedKeccak256)(
|
|
60547
61020
|
[
|
|
60548
61021
|
"bytes32",
|
|
60549
61022
|
// positionId
|
|
@@ -60576,7 +61049,7 @@ async function buildBtcExecuteEnvelope(params) {
|
|
|
60576
61049
|
actionHash
|
|
60577
61050
|
]
|
|
60578
61051
|
);
|
|
60579
|
-
const userSignature = await signer.signMessage((0,
|
|
61052
|
+
const userSignature = await signer.signMessage((0, import_ethers23.getBytes)(messageHash));
|
|
60580
61053
|
const borrowerAddress = await signer.getAddress();
|
|
60581
61054
|
return {
|
|
60582
61055
|
positionId,
|
|
@@ -60944,7 +61417,7 @@ function rowToStatus(row) {
|
|
|
60944
61417
|
return row;
|
|
60945
61418
|
}
|
|
60946
61419
|
async function fetchProtocolPauseStatus(provider, positionManagerAddress) {
|
|
60947
|
-
const iface = new
|
|
61420
|
+
const iface = new import_ethers25.Interface(GET_PROTOCOL_PAUSE_STATUS_ABI);
|
|
60948
61421
|
const data = iface.encodeFunctionData("getProtocolPauseStatus", []);
|
|
60949
61422
|
const raw = await provider.call({ to: positionManagerAddress, data });
|
|
60950
61423
|
const decoded = iface.decodeFunctionResult("getProtocolPauseStatus", raw);
|
|
@@ -61134,38 +61607,38 @@ var ContractManager = class {
|
|
|
61134
61607
|
}
|
|
61135
61608
|
const contractRunner = runner;
|
|
61136
61609
|
const contracts = {
|
|
61137
|
-
positionManager: new
|
|
61610
|
+
positionManager: new import_ethers26.Contract(
|
|
61138
61611
|
contractAddresses.positionManager,
|
|
61139
61612
|
POSITION_MANAGER_ABI,
|
|
61140
61613
|
contractRunner
|
|
61141
61614
|
),
|
|
61142
|
-
loanOperationsManager: new
|
|
61143
|
-
contractAddresses.loanOperationsManager ||
|
|
61615
|
+
loanOperationsManager: new import_ethers26.Contract(
|
|
61616
|
+
contractAddresses.loanOperationsManager || import_ethers26.ZeroAddress,
|
|
61144
61617
|
LOAN_OPS_ABI,
|
|
61145
61618
|
contractRunner
|
|
61146
61619
|
),
|
|
61147
|
-
ucdController: new
|
|
61620
|
+
ucdController: new import_ethers26.Contract(
|
|
61148
61621
|
contractAddresses.ucdToken,
|
|
61149
61622
|
UCD_CONTROLLER_ABI,
|
|
61150
61623
|
contractRunner
|
|
61151
61624
|
),
|
|
61152
|
-
termManager: new
|
|
61153
|
-
contractAddresses.termManager ||
|
|
61625
|
+
termManager: new import_ethers26.Contract(
|
|
61626
|
+
contractAddresses.termManager || import_ethers26.ZeroAddress,
|
|
61154
61627
|
TERM_MANAGER_ABI,
|
|
61155
61628
|
contractRunner
|
|
61156
61629
|
),
|
|
61157
|
-
circuitBreaker: new
|
|
61158
|
-
contractAddresses.circuitBreaker ||
|
|
61630
|
+
circuitBreaker: new import_ethers26.Contract(
|
|
61631
|
+
contractAddresses.circuitBreaker || import_ethers26.ZeroAddress,
|
|
61159
61632
|
CIRCUIT_BREAKER_ABI,
|
|
61160
61633
|
contractRunner
|
|
61161
61634
|
),
|
|
61162
|
-
liquidationManager: new
|
|
61163
|
-
contractAddresses.liquidationManager ||
|
|
61635
|
+
liquidationManager: new import_ethers26.Contract(
|
|
61636
|
+
contractAddresses.liquidationManager || import_ethers26.ZeroAddress,
|
|
61164
61637
|
LIQUIDATION_MANAGER_ABI,
|
|
61165
61638
|
contractRunner
|
|
61166
61639
|
),
|
|
61167
|
-
bitcoinWithdrawalAddressRegistry: new
|
|
61168
|
-
contractAddresses.bitcoinWithdrawalAddressRegistry ||
|
|
61640
|
+
bitcoinWithdrawalAddressRegistry: new import_ethers26.Contract(
|
|
61641
|
+
contractAddresses.bitcoinWithdrawalAddressRegistry || import_ethers26.ZeroAddress,
|
|
61169
61642
|
BITCOIN_WITHDRAWAL_ADDRESS_REGISTRY_ABI,
|
|
61170
61643
|
contractRunner
|
|
61171
61644
|
)
|
|
@@ -61214,13 +61687,13 @@ var ContractManager = class {
|
|
|
61214
61687
|
const address = addresses[key];
|
|
61215
61688
|
if (!address) {
|
|
61216
61689
|
missing.push(String(key));
|
|
61217
|
-
} else if (!(0,
|
|
61690
|
+
} else if (!(0, import_ethers26.isAddress)(address)) {
|
|
61218
61691
|
invalid.push(String(key));
|
|
61219
61692
|
}
|
|
61220
61693
|
}
|
|
61221
61694
|
for (const key of optionalAddresses) {
|
|
61222
61695
|
const address = addresses[key];
|
|
61223
|
-
if (address && !(0,
|
|
61696
|
+
if (address && !(0, import_ethers26.isAddress)(address)) {
|
|
61224
61697
|
invalid.push(String(key));
|
|
61225
61698
|
}
|
|
61226
61699
|
}
|
|
@@ -62535,11 +63008,11 @@ var LoanCreator = class {
|
|
|
62535
63008
|
try {
|
|
62536
63009
|
const mainnetVaultAddress = bitcoinAddresses.mainnet;
|
|
62537
63010
|
const regtestVaultAddress = bitcoinAddresses.regtest;
|
|
62538
|
-
const pkpIdBytes32 = (0,
|
|
62539
|
-
(0,
|
|
63011
|
+
const pkpIdBytes32 = (0, import_ethers27.zeroPadValue)(
|
|
63012
|
+
(0, import_ethers27.toBeHex)(BigInt(pkpData.tokenId)),
|
|
62540
63013
|
32
|
|
62541
63014
|
);
|
|
62542
|
-
const pkpPublicKeyUncompressed =
|
|
63015
|
+
const pkpPublicKeyUncompressed = import_ethers27.SigningKey.computePublicKey(
|
|
62543
63016
|
pkpData.publicKey,
|
|
62544
63017
|
false
|
|
62545
63018
|
);
|
|
@@ -62552,7 +63025,7 @@ var LoanCreator = class {
|
|
|
62552
63025
|
);
|
|
62553
63026
|
log.debug(`BigInt conversion: ${BigInt(pkpData.tokenId).toString()}`);
|
|
62554
63027
|
log.debug(
|
|
62555
|
-
`Hex from BigInt: ${(0,
|
|
63028
|
+
`Hex from BigInt: ${(0, import_ethers27.toBeHex)(BigInt(pkpData.tokenId))}`
|
|
62556
63029
|
);
|
|
62557
63030
|
log.debug(`Final bytes32 (zero-padded): ${pkpIdBytes32}`);
|
|
62558
63031
|
log.debug(
|
|
@@ -62724,8 +63197,8 @@ var LoanCreator = class {
|
|
|
62724
63197
|
}
|
|
62725
63198
|
}
|
|
62726
63199
|
if (this.config.debug) {
|
|
62727
|
-
const pkpIdBytes32Check = (0,
|
|
62728
|
-
(0,
|
|
63200
|
+
const pkpIdBytes32Check = (0, import_ethers27.zeroPadValue)(
|
|
63201
|
+
(0, import_ethers27.toBeHex)(BigInt(pkpData.tokenId)),
|
|
62729
63202
|
32
|
|
62730
63203
|
);
|
|
62731
63204
|
log.error("\u274C Loan creation transaction failed", {
|
|
@@ -62886,7 +63359,7 @@ var LoanCreator = class {
|
|
|
62886
63359
|
const coreAddress = this.config.contractManager.getContractAddresses().positionManagerCore;
|
|
62887
63360
|
if (coreAddress) {
|
|
62888
63361
|
try {
|
|
62889
|
-
const core = new
|
|
63362
|
+
const core = new import_ethers27.Contract(
|
|
62890
63363
|
coreAddress,
|
|
62891
63364
|
[
|
|
62892
63365
|
"function getPositionDetails(bytes32) view returns (tuple(bytes32 positionId, bytes32 pkpId, uint256 ucdDebt, string vaultAddress, address borrower, uint40 createdAt, uint40 lastUpdated, uint16 selectedTerm, uint40 expiryAt, uint8 status))"
|
|
@@ -62928,8 +63401,8 @@ var LoanCreator = class {
|
|
|
62928
63401
|
const newEventAbi = [
|
|
62929
63402
|
"event PositionCreated(bytes32 indexed positionId, bytes32 indexed pkpId, address indexed borrower, uint256 requestedCollateralRatio, uint256 selectedTerm, uint256 expiryAt)"
|
|
62930
63403
|
];
|
|
62931
|
-
const oldIface = new
|
|
62932
|
-
const newIface = new
|
|
63404
|
+
const oldIface = new import_ethers27.Interface(oldEventAbi);
|
|
63405
|
+
const newIface = new import_ethers27.Interface(newEventAbi);
|
|
62933
63406
|
let positionId;
|
|
62934
63407
|
if (this.config.debug) {
|
|
62935
63408
|
log.info("\u{1F50D} Parsing transaction receipt logs", {
|
|
@@ -63409,7 +63882,7 @@ var LoanQuery = class {
|
|
|
63409
63882
|
const isChipotlePkpId2 = typeof rawId === "string" && isNormalizedChipotlePkpId(rawId);
|
|
63410
63883
|
if (isChipotlePkpId2) {
|
|
63411
63884
|
if (this.config.positionManagerCoreAddress && this.config.provider) {
|
|
63412
|
-
const pmContract = new
|
|
63885
|
+
const pmContract = new import_ethers28.Contract(
|
|
63413
63886
|
this.config.positionManagerCoreAddress,
|
|
63414
63887
|
POSITION_CORE_ABI,
|
|
63415
63888
|
this.config.provider
|
|
@@ -63512,7 +63985,7 @@ var LoanQuery = class {
|
|
|
63512
63985
|
*/
|
|
63513
63986
|
async getBorrowerUcdDebtSummary(borrower) {
|
|
63514
63987
|
const trimmed = typeof borrower === "string" ? borrower.trim() : "";
|
|
63515
|
-
if (!(0,
|
|
63988
|
+
if (!(0, import_ethers28.isAddress)(trimmed)) {
|
|
63516
63989
|
return failure(
|
|
63517
63990
|
new SDKError({
|
|
63518
63991
|
message: `Borrower must be an EVM address for a UCD debt summary, got "${trimmed}"`,
|
|
@@ -63787,7 +64260,7 @@ var WithdrawalAddressModule = class {
|
|
|
63787
64260
|
if (!res.success)
|
|
63788
64261
|
return res;
|
|
63789
64262
|
const target = res.value.target;
|
|
63790
|
-
if (!target || target ===
|
|
64263
|
+
if (!target || target === import_ethers29.ZeroAddress) {
|
|
63791
64264
|
return failure(
|
|
63792
64265
|
new SDKError({
|
|
63793
64266
|
code: "SDK_WITHDRAWAL_REGISTRY_NOT_CONFIGURED",
|
|
@@ -63806,7 +64279,7 @@ var WithdrawalAddressModule = class {
|
|
|
63806
64279
|
}
|
|
63807
64280
|
/** keccak256 of the canonicalized address — matches the on-chain key. */
|
|
63808
64281
|
static addressHash(btcAddress2) {
|
|
63809
|
-
return (0,
|
|
64282
|
+
return (0, import_ethers29.keccak256)((0, import_ethers29.toUtf8Bytes)(normalizeBitcoinAddress(btcAddress2)));
|
|
63810
64283
|
}
|
|
63811
64284
|
/**
|
|
63812
64285
|
* Add a Bitcoin address to the caller's allowlist. It becomes usable only
|
|
@@ -69826,7 +70299,7 @@ var _abi = [
|
|
|
69826
70299
|
];
|
|
69827
70300
|
var _bytecode = "0x60a080604052346100ea57306080527ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460ff8160401c166100d9576002600160401b03196001600160401b03821601610073575b60405161485a90816100f0823960805181818161278e01526128870152f35b6001600160401b0319166001600160401b039081177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005581527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a13880610054565b63f92ee8a960e01b60005260046000fd5b600080fdfe6080604052600436101561001257600080fd5b6000803560e01c8062f7fce91461384657806301ffc9a7146137d5578063021d28931461377c5780630871b20614613743578063114249d214610f6157806311d954f81461371a57806313da3166146136e15780631d44a904146136385780631f77bf65146135ff578063248a9ca3146135e05780632b83cccd146131205780632f2ff15d146130ee57806334bac370146130b557806334e181251461307c57806336568abe14613037578063373c86b614612ffe5780633f4ba83a14612f375780634373b57214612f0e5780634451e89b14612b3a5780634ebd25a514612b015780634f1ef2861461280c5780635273b6f6146127e357806352d1902d1461277b578063568fafca146126ed57806359d5d02a146124205780635bc26aea146123eb5780635c975abb146123bb5780635ecc27081461229d5780638456cb59146121a257806385c15d9a1461216957806389d3ad00146120a25780638bff608e146120695780639010d07c1461201657806390ad8b4014611ffa57806391d1485414611fa15780639b759bf714611f5e5780639baf58d214611f415780639f1d0f59146118a8578063a217fddf1461188c578063a3246ad3146117cf578063ad3cb1cc14611788578063b492fc691461168e578063b9f637af14611463578063bf7d911914611424578063c4c5f62414611371578063c55f15ea1461134e578063ca15c87314611317578063ca2ce65d146112de578063cc1f8ffa146112ac578063cf46075e146111a2578063d21a74ff14611165578063d2f8253614611142578063d547741f14611107578063d5d3f78b14610f9a578063d66bd52414610f61578063e1f1c4a714610f44578063e1f3962c14610f18578063ec2f96fe14610ef4578063eda5a26a14610af7578063f1a1eb8414610ab4578063f385116d14610a7b578063f77c479114610a54578063f8c8765e14610661578063faaebd2114610628578063facdfb5e14610488578063fc99bd9a14610377578063fe32e7281461033e5763ffa1ad741461030857600080fd5b3461033b578060031936011261033b57610337610323613a68565b604051918291602083526020830190613a17565b0390f35b80fd5b503461033b57602036600319011261033b576020906040906001600160a01b0361036661392e565b168152601283522054604051908152f35b503461033b57604036600319011261033b5761039161392e565b6010546024359291906001600160a01b03163303610479576001600160a01b03168082526002602052604082205490929060ff16156104665780156104575782825260076020526040822054926103e88285613cb0565b848110610448576001600160ff1b0381116104395760008051602061482e833981519152604085968493846104369852600760205280838a205582519182526020820152a23090339061421c565b80f35b630700fcb360e11b8452600484fd5b63446c8cc960e01b8452600484fd5b63162908e360e11b8252600482fd5b506024916374ed46ad60e01b8252600452fd5b6349db3bd360e01b8252600482fd5b503461033b57602036600319011261033b576104a261392e565b6104aa613f12565b6010546001600160a01b03163303610479576001600160a01b03168082526002602052604082205460ff161561061657808252600760205260408220546040516370a0823160e01b8152306004820152602081602481865afa90811561060b5784916105d4575b50818111156105c5576105248282613b6c565b8215908115610570575b505060008051602061482e833981519152916040918486526007602052808387205582519182526020820152a260016000805160206147ce8339815191525580f35b61271081029080820461271014901517156105b157606484029184830460641417156105b157116105a257388061052e565b63a73af74d60e01b8452600484fd5b634e487b7160e01b86526011600452602486fd5b6105cf8183613b6c565b610524565b90506020813d602011610603575b816105ef602093836139c3565b810103126105fe575138610511565b600080fd5b3d91506105e2565b6040513d86823e3d90fd5b6374ed46ad60e01b8252600452602490fd5b503461033b57602036600319011261033b576020906040906001600160a01b0361065061392e565b168152600483522054604051908152f35b503461033b57608036600319011261033b5761067b61392e565b610683613944565b6044356001600160a01b03811690818103610a50576064356001600160a01b0381169390849003610a4c5760008051602061480e83398151915254604081901c60ff161595906001600160401b031680159081610a44575b6001149081610a3a575b159081610a31575b50610a225760008051602061480e83398151915280546001600160401b0319166001179055856109fd575b6001600160a01b03169081156109ee576001600160a01b03169081156109df5783156109d05761074661448a565b61074e61448a565b61075661448a565b61075e61448a565b60016000805160206147ce8339815191525561077861448a565b61078061448a565b86546001600160a01b0319908116919091178755600180549182168317905560405163313ce56760e01b8152909190602081600481855afa88918161099f575b506107d457633a24e95b60e11b8852600488fd5b6001600160a81b03199092161760a091821b60ff60a01b16176001819055901c60ff16601119810161098d575061080b8186614348565b80610965575b156109205761082e816000805160206147ee833981519152614348565b8061092f575b15610920576108519060008051602061470e833981519152614348565b90816108e9575b50156108da57806108af575b5061086c5780f35b60ff60401b1960008051602061480e833981519152541660008051602061480e833981519152556000805160206146ee833981519152602060405160018152a180f35b601080546001600160a01b031916821790558260008051602061474e8339815191528180a338610864565b63cf5a8e3360e01b8352600483fd5b6109199060008051602061470e83398151915286526000805160206146ae833981519152602052604086206144d0565b5038610858565b63cf5a8e3360e01b8552600485fd5b6000805160206147ee83398151915286526000805160206146ae83398151915260205261095f83604088206144d0565b50610834565b8580526000805160206146ae83398151915260205261098783604088206144d0565b50610811565b63167738cf60e21b8652600452602485fd5b6109c291925060203d6020116109c9575b6109ba81836139c3565b810190613ba9565b90386107c0565b503d6109b0565b630b5eba9f60e41b8752600487fd5b63c1ab6dc160e01b8752600487fd5b6336abb4df60e11b8752600487fd5b60008051602061480e833981519152805460ff60401b1916600160401b179055610718565b63f92ee8a960e01b8752600487fd5b905015386106ed565b303b1591506106e5565b8791506106db565b8580fd5b8480fd5b503461033b578060031936011261033b57546040516001600160a01b039091168152602090f35b503461033b57602036600319011261033b576020906040906001600160a01b03610aa361392e565b168152600a83522054604051908152f35b503461033b57604036600319011261033b576020906040906001600160a01b03610adc61392e565b16815260158352818120602435825283522054604051908152f35b503461033b5761016036600319011261033b57610b1261392e565b90606435604435602435610b24613a58565b9160a4359160c43560e43561010435916101243595610144359760018060a01b03601054163303610ee5576001600160a01b038c16808c52600260205260408c2054909a9060ff16610ed1578a15610ec2578615610eb3576127108811610e99576103e88111610e815760ff82169c60128e118e8115610e76575b50610e6257803b15610e4e578915610e3a578a15610e265782610bc191614260565b84151580610e1d575b610e065785151580610dfd575b610de6578b9c602460208d9e9d604051928380926370a0823160e01b82523060048301525afa9c8d15610dda579c610da6575b506001600160ff1b038c11610d97578a8d8f9760408f97838f918f8f8f8f90859f988f99879f9660008051602061476e8339815191529f978b9f988f8d6000805160206146ce8339815191529f988e8e610d4f9b60008051602061468e8339815191529f8f8f8487526002602052878720600160ff198254161790558487526003602052878720558386526004602052868620558285526006602052878686205582855260056020528585209060ff19825416179055818452600c6020528885852055818452600d6020528985852055818452600e6020528a85852055818452600f6020528b8585205581845260076020528484205582526012602052828220558d8152601360205220558a7f991d1ef1b5c0820d213328cba6682059e00a50e49c469a454eb3557e78eaf6668e80518b81528c6020820152a28c5198899889613cbd565b0390a28151908b82526020820152a28151908782526020820152a280610d73578280f35b604060008051602061482e833981519152918151908582526020820152a281808280f35b63556e7a8160e01b8e5260048efd5b909b506020813d602011610dd2575b81610dc2602093836139c3565b810103126105fe57519a38610c0a565b3d9150610db5565b604051903d90823e3d90fd5b60448c858863dd85772b60e01b8352600452602452fd5b50838610610bd7565b60448c8487637449915760e01b8352600452602452fd5b50828510610bca565b636835314760e11b8d52600160045260248dfd5b636835314760e11b8d5260048d905260248dfd5b63377e3f9960e21b8d5260048c905260248dfd5b63ca95039160e01b8d5260048e905260248dfd5b60069150108e610b9f565b631051834f60e11b8c526004526103e860245260448bfd5b63c1e9a14160e01b8c52600488905261271060245260448cfd5b63a2ec3a5560e01b8c5260048cfd5b63df407ac560e01b8c5260048cfd5b6317f4215b60e21b8c5260048b905260248cfd5b6349db3bd360e01b8b5260048bfd5b503461033b578060031936011261033b57602060ff60015460a01c16604051908152f35b503461033b57602036600319011261033b576020610f3c610f3761392e565b613df5565b604051908152f35b503461033b578060031936011261033b5760206040516127108152f35b503461033b57602036600319011261033b576020906040906001600160a01b03610f8961392e565b168152600783522054604051908152f35b503461033b57602036600319011261033b57610fb461392e565b6010546001600160a01b03163303610479576001600160a01b03168082526002602052604082205460ff16156106165780825260076020526040822054806110f1575080825260026020526040822060ff1981541690558082526003602052816040812055808252600460205281604081205580825260056020526040822060ff198154169055808252600c602052816040812055808252600d602052816040812055808252600e602052816040812055808252600f602052816040812055808252600660205281604081205580825260076020526040822054818352600760205282604081205560405190827f3302a1b37f04242bb55603f5449e7ecd690a35eef08ba1353c48c20e2aae9cda8580a2806110ce578380f35b8160409160008051602061482e8339815191529352846020820152a23880808380f35b604492916376bc059760e11b8352600452602452fd5b503461033b57604036600319011261033b5761113e600435611127613944565b9061113961113482613b79565b614088565b61411a565b5080f35b503461033b578060031936011261033b57602060ff600854166040519015158152f35b503461033b57602036600319011261033b5760209060ff906040906001600160a01b0361119061392e565b16815260058452205416604051908152f35b503461033b57602036600319011261033b576111bc61392e565b6111c4613f12565b6010546001600160a01b03163303610479576001600160a01b03168082526002602052604082205460ff161561061657808252600760205260408220546040516370a0823160e01b8152306004820152602081602481865afa90811561060b57849161126c575b5060008051602061482e833981519152916040918486526007602052808387205582519182526020820152a260016000805160206147ce8339815191525580f35b90506020813d6020116112a4575b81611287602093836139c3565b810103126105fe575160008051602061482e83398151915261122b565b3d915061127a565b503461033b57604036600319011261033b5760206112d46112cb61392e565b60243590613cf6565b6040519015158152f35b503461033b57602036600319011261033b576020906040906001600160a01b0361130661392e565b168152601383522054604051908152f35b503461033b57602036600319011261033b57604060209160043581526000805160206146ae83398151915283522054604051908152f35b503461033b578060031936011261033b576020604051670de0b6b3a76400008152f35b503461033b57604036600319011261033b5761138b61392e565b6010546024359291906001600160a01b03163303610479576001600160a01b031680825260076020526040822054929081841061140d578060008051602061482e8339815191526040866113e3866104369899613b6c565b84895260076020528289205583885260076020528188205482519182526020820152a2339061404c565b5091604492633cb8e07360e01b8352600452602452fd5b503461033b57602036600319011261033b5760209060ff906040906001600160a01b0361144f61392e565b168152600284522054166040519015158152f35b503461033b5761012036600319011261033b5761147e61392e565b6064359190604435602435611491613a58565b601054610104359660e4359260c4359260a43592906001600160a01b0316330361167f576001600160a01b038816808a52600260205260408a205490989060ff161561166b57861561165c576127108811611642576103e882116116285760ff83169060128211801561161e575b61160a578361150d91614260565b85151580611601575b6115ea578a1515806115e1575b6115ca579260008051602061468e83398151915297969592828c956115c4979460408e8e80825260036020528c8383205580825260046020528d838320558152600660205220558b8d52600560205260408d209060ff198254161790558a8c52600c6020528260408d20558a8c52600d6020528360408d20558a8c52600e6020528460408d20558a8c52600f6020528560408d205560405198899889613cbd565b0390a280f35b60448a868d63dd85772b60e01b8352600452602452fd5b50848b10611523565b60448a8588637449915760e01b8352600452602452fd5b50838610611516565b63ca95039160e01b8b52600482905260248bfd5b50600682106114ff565b631051834f60e11b8a5260048290526103e860245260448afd5b63c1e9a14160e01b8a52600488905261271060245260448afd5b63a2ec3a5560e01b8a5260048afd5b6374ed46ad60e01b8a52600489905260248afd5b6349db3bd360e01b8952600489fd5b503461033b57604036600319011261033b576116a861392e565b6001600160a01b0316808252600260205260408220546024359060ff16156117745780156117655761271061172a604085670de0b6b3a76400006117196117329688859a52600560205260ff85852054169080916012811061173f575b505088845260036020528484205490613a8b565b049581526004602052205484613a8b565b048092613b6c565b9082519182526020820152f35b61175e925060ff61175261175892613ad4565b16613ae5565b90613a8b565b3880611705565b63162908e360e11b8352600483fd5b6374ed46ad60e01b83526004829052602483fd5b503461033b578060031936011261033b5761033760408051906117ab81836139c3565b60058252640352e302e360dc1b602083015251918291602083526020830190613a17565b503461033b57602036600319011261033b5760043581526000805160206146ae83398151915260205260408120604051908160208254918281520190819285526020852090855b818110611876575050508261182c9103836139c3565b604051928392602084019060208552518091526040840192915b818110611854575050500390f35b82516001600160a01b0316845285945060209384019390920191600101611846565b8254845260209093019260019283019201611816565b503461033b578060031936011261033b57602090604051908152f35b503461033b576118b736613969565b9190926118c2613f12565b6118ca613f4e565b338152600960205260408120544303611f1f57338152600a602052600360408220541015611f1057338152600a602052604081206119088154613b9a565b90555b6001600160a01b0382168082526002602052604082205490929060ff16611e6f575b828252600260205260ff60408320541615610466578415610457578315611e6057828252600c60205260408220548510611e3b57828252600e60205260408220548015611e2c57808611611e155750846119869161415e565b6040516370a0823160e01b8152306004820152602081602481865afa908115611e0a578291611dd8575b506119bd8530338661421c565b6040516370a0823160e01b8152306004820152602081602481875afa908115611cef57908692918491611d9f575b50906119f691613b6c565b10611d905781815260076020526040812054611a128582613cb0565b818110611d81576001600160ff1b038111611d72576040849260008051602061482e833981519152928486526007602052808387205582519182526020820152a2818152600560205260ff604082205416849060128110611d11575b50611a8f670de0b6b3a7640000918484526003602052604084205490613a8b565b04908281526004602052612710611aaa604083205484613a8b565b0491611ab68382613b6c565b94808610611cfa57506001546040516318160ddd60e01b815290602090829060049082906001600160a01b03165afa908115611cef578391611cbd575b5082546001600160a01b0316803b15611ca45783809160846040518094819363ae494fa160e01b83523360048401528c60248401528b60448401528d60648401525af1801561060b57908491611ca8575b505083611c34575b6001546040516318160ddd60e01b81529190602090839060049082906001600160a01b03165afa801561060b578490611c00575b611b8a9250613b6c565b90808203611bea575050507fb3e2773606abfd36b5bd91394b3a54d1398336c65005baf7bf7a05efeffaf75b611bcd602095604051918291339588429285613bdd565b0390a360016000805160206147ce83398151915255604051908152f35b632d8562a360e11b835260045260245260449150fd5b506020823d602011611c2c575b81611c1a602093836139c3565b810103126105fe57611b8a9151611b80565b3d9150611c0d565b82546001600160a01b0316803b15611ca45783809160846040518094819363ae494fa160e01b83523060048401528a60248401528b60448401528160648401525af1801561060b57908491611c8b575b5050611b4c565b81611c95916139c3565b611ca0578238611c84565b8280fd5b8380fd5b81611cb2916139c3565b611ca0578238611b44565b90506020813d602011611ce7575b81611cd8602093836139c3565b810103126105fe575138611af3565b3d9150611ccb565b6040513d85823e3d90fd5b6371c4efed60e01b83526004869052602452604482fd5b611d21915061175260ff91613ad4565b8015611d5e5780600019048511611d4f57611a8f611d48670de0b6b3a76400009287613a8b565b9150611a6e565b63035fc53d60e41b8252600482fd5b634e487b7160e01b82526012600452602482fd5b630700fcb360e11b8352600483fd5b63446c8cc960e01b8352600483fd5b639bfa3c1760e01b8152600490fd5b919250506020813d602011611dd0575b81611dbc602093836139c3565b810103126105fe57518591906119f66119eb565b3d9150611daf565b90506020813d602011611e02575b81611df3602093836139c3565b810103126105fe5751386119b0565b3d9150611de6565b6040513d84823e3d90fd5b631d7f2ac360e01b83526004869052602452604482fd5b633b5db2f360e11b8352600483fd5b50908152600c6020526040812054630d54e9e160e01b82526004849052602452604490fd5b632cd84af360e01b8252600482fd5b60405163313ce56760e01b815291939291602081600481865afa859181611eef575b50611ea55763105482c760e21b8552600485fd5b93919293838352600560205260ff806040852054169116908103611ec9575061192d565b90506044928252600560205260ff604083205416631e43476360e11b8352600452602452fd5b611f0991925060203d6020116109c9576109ba81836139c3565b9038611e91565b63a74c1c5f60e01b8152600490fd5b3381526009602052436040822055338152600a6020526001604082205561190b565b503461033b578060031936011261033b5760206040516103e88152f35b503461033b57604036600319011261033b576020906040906001600160a01b03611f8661392e565b16815260148352818120602435825283522054604051908152f35b503461033b57604036600319011261033b576040611fbd613944565b91600435815260008051602061478e833981519152602052209060018060a01b0316600052602052602060ff604060002054166040519015158152f35b503461033b578060031936011261033b57602060405160648152f35b503461033b57604036600319011261033b5761205060209160043581526000805160206146ae8339815191528352604060243591206144b8565b905460405160039290921b1c6001600160a01b03168152f35b503461033b57602036600319011261033b576020906040906001600160a01b0361209161392e565b168152600983522054604051908152f35b503461033b57604036600319011261033b576120bc61392e565b60105460243591906001600160a01b0316330361215a576001600160a01b031690811561214b57604060008051602061476e8339815191529183855260136020528185205490848652601360205280838720558486526015602052828620438752602052828620548587526019602052838720558486526017602052438387205582519182526020820152a280f35b63df407ac560e01b8352600483fd5b6349db3bd360e01b8352600483fd5b503461033b57602036600319011261033b576020906040906001600160a01b0361219161392e565b168152600383522054604051908152f35b503461033b578060031936011261033b5760008051602061470e833981519152815260008051602061478e83398151915260209081526040808320336000908152925290205460ff1615612278576121f8613f4e565b600160ff196000805160206147ae8339815191525416176000805160206147ae833981519152557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a16040514281527f80170b5fcdd2bf1e0660ef4b8851f86685f64d41b1a19de1471947ece8725aac60203392a280f35b63e2517d3f60e01b81523360045260008051602061470e833981519152602452604490fd5b503461033b57602036600319011261033b576122b761392e565b60008051602061480e8339815191525460ff8160401c169081156123a3575b506123945760008051602061480e83398151915280546001600160481b0319166003600160401b0117905581805260008051602061478e83398151915260209081526040808420336000908152925290205460ff161561237c5761233990613c5e565b60ff60401b1960008051602061480e833981519152541660008051602061480e833981519152556000805160206146ee833981519152602060405160038152a180f35b63e2517d3f60e01b8252336004526024829052604482fd5b63f92ee8a960e01b8252600482fd5b60036001600160401b039190911610159050386122d6565b503461033b578060031936011261033b57602060ff6000805160206147ae83398151915254166040519015158152f35b503461033b57602036600319011261033b5761240561392e565b6010546001600160a01b031633036104795761043690613c5e565b503461033b57606036600319011261033b5761243a61392e565b612442613944565b60105490926044359290916001600160a01b0316330361047957612464613f4e565b6011546001600160a01b03169182156126de5760405163babcc53960e01b81526001600160a01b0386166004820181905293602090829060249082905afa908115611e0a57829161269f575b5015612690578215612681576001546001600160a01b03928316921682036125d1576040516370a0823160e01b8152306004820152602081602481865afa908115611e0a57829161259f575b50935b841561259057600019810361258a5750835b841561257b5780851161256357505061252d836020958361404c565b7f0bf519e4b3821615dbdd874fa1a5fbb4bb651b4e6beabedd4ac318e770233b2c604080518581524287820152a3604051908152f35b630555ed4f60e31b8252600485905260245260449150fd5b632e11316f60e11b8252600482fd5b93612511565b63f09872eb60e01b8252600482fd5b90506020813d6020116125c9575b816125ba602093836139c3565b810103126105fe5751386124fc565b3d91506125ad565b8181526002602052604081205460ff161561266f576040516370a0823160e01b8152306004820152602081602481865afa908115611e0a57829161263d575b5082825260076020526040822054808211156126355761262f91613b6c565b936124ff565b50508061262f565b90506020813d602011612667575b81612658602093836139c3565b810103126105fe575138612610565b3d915061264b565b60249163eef7849760e01b8252600452fd5b634e46966960e11b8152600490fd5b63133307bb60e21b8152600490fd5b90506020813d6020116126d6575b816126ba602093836139c3565b810103126126d2575180151581036126d257386124b0565b5080fd5b3d91506126ad565b630e048e7160e41b8152600490fd5b503461033b57602036600319011261033b5761270761392e565b6010546001600160a01b03163303610479576001600160a01b0316801561276c57601180546001600160a01b0319811683179091556001600160a01b03167f1e9c406f2707909cfd9f61e744f73bcab77e5997d063276f67883c5257d51cf08380a380f35b634e46966960e11b8252600482fd5b503461033b578060031936011261033b577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031630036127d457602060405160008051602061472e8339815191528152f35b63703e46dd60e11b8152600490fd5b503461033b578060031936011261033b576010546040516001600160a01b039091168152602090f35b50604036600319011261033b5761282161392e565b602435906001600160401b038211611ca05736602383011215611ca0578160040135908361284e836139fc565b9361285c60405195866139c3565b83855260208501933660248284010111611ca057806024602093018637850101526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016308114908115612ade575b50612acf576010546001600160a01b03163303612ac0576001600160a01b038116928315612ab157813b15612aa25760008051602061472e83398151915254846128fa613a68565b7f6ea8b34d59b2818d3f37a08dddaa06f5886b9c20c907b36f03ca6528e106e86f61293060405192604084526040840190613a17565b4260208401526001600160a01b038516929081900390a36040516352d1902d60e01b8152602081600481895afa879181612a6a575b5061297e57634c9c8ce360e01b87526004869052602487fd5b908160008051602061472e83398151915288979303612a585750833b15612a44576001600160a01b031916811760008051602061472e833981519152558491907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b8380a2805115612a295761113e9382915190845af43d15612a21573d91612a05836139fc565b92612a1360405194856139c3565b83523d85602085013e61460c565b60609161460c565b5050505034612a355780f35b63b398979f60e01b8152600490fd5b634c9c8ce360e01b86526004829052602486fd5b632a87526960e21b8752600452602486fd5b9091506020813d602011612a9a575b81612a86602093836139c3565b81010312612a9657519038612965565b8780fd5b3d9150612a79565b636f7c43f160e01b8552600485fd5b63e6c4247b60e01b8552600485fd5b6349db3bd360e01b8452600484fd5b63703e46dd60e11b8452600484fd5b60008051602061472e833981519152546001600160a01b031614159050386128b2565b503461033b57602036600319011261033b576020906040906001600160a01b03612b2961392e565b168152600e83522054604051908152f35b503461033b57606036600319011261033b57612b5461395a565b6024356001600160401b038111611ca057612b73903690600401613993565b916044356001600160401b038111610a5057612b93903690600401613993565b60008051602061480e8339815191529291925460ff8160401c16908115612ef6575b50612ee75760008051602061480e83398151915280546001600160481b0319166002600160401b011790556000805160206147ee833981519152865260008051602061478e83398151915260209081526040808820336000908152925290205460ff1615612ec257612c2561448a565b612c2d61448a565b60016000805160206147ce83398151915255600b549160ff8316612eb357818603612ea457612c5b86613bf9565b92612c6960405194856139c3565b868452601f19612c7888613bf9565b01366020860137875b878110612daf575060019060ff191617600b5515159460ff196008541660ff871617600855865b818110612d0c578760008051602061466e833981519152602089604051908152a160ff60401b1960008051602061480e833981519152541660008051602061480e833981519152556000805160206146ee833981519152602060405160028152a180f35b808860008051602061482e8339815191526040612d34612d2f600196888d613c10565b613c36565b612d3f85898c613c10565b357f8f955fa878b4aae8b1ac37b1ab715307470f2822ceff87e23d33ef1e044814a783612d6c888d613c4a565b5193898060a01b0316968793848252600660205280838320558482526007602052858383205582519182526020820152a28151908d82526020820152a201612ca8565b612dbd612d2f828a8a613c10565b612dc8828689613c10565b6001600160a01b03909116808b52600260205260408b20549091359060ff1615612e90576103e88111612e785750906020602492604051938480926370a0823160e01b82523060048301525afa8015612e6d578a90612e37575b60019250612e308288613c4a565b5201612c81565b509060203d8111612e66575b612e4d81836139c3565b6020826000928101031261033b57509060019151612e22565b503d612e43565b6040513d8c823e3d90fd5b631051834f60e11b8b526004526103e860245260448afd5b6351104c5960e01b8b52600482905260248bfd5b63512509d360e11b8752600487fd5b6324d0d1fd60e01b8752600487fd5b63e2517d3f60e01b8652336004526000805160206147ee833981519152602452604486fd5b63f92ee8a960e01b8652600486fd5b60026001600160401b03919091161015905038612bb5565b503461033b578060031936011261033b576011546040516001600160a01b039091168152602090f35b503461033b578060031936011261033b576010546001600160a01b03163303612fef576000805160206147ae8339815191525460ff811615612fe05760ff19166000805160206147ae833981519152557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a16040514281527f107553d8191d85b405879cf752997865edd48d94e20bda4dd27223c94b31a7cc60203392a280f35b638dfc202b60e01b8252600482fd5b6349db3bd360e01b8152600490fd5b503461033b57602036600319011261033b576020906040906001600160a01b0361302661392e565b168152601683522054604051908152f35b503461033b57604036600319011261033b57613051613944565b336001600160a01b0382160361306d5761113e9060043561411a565b63334bd91960e11b8252600482fd5b503461033b57602036600319011261033b576020906040906001600160a01b036130a461392e565b168152600c83522054604051908152f35b503461033b57602036600319011261033b576020906040906001600160a01b036130dd61392e565b168152601783522054604051908152f35b503461033b57604036600319011261033b5761113e60043561310e613944565b9061311b61113482613b79565b6140d2565b503461033b5761312f36613969565b91909261313a613f12565b613142613f4e565b3381526009602052604081205443036135be57338152600a602052600360408220541015611f1057338152600a602052604081206131808154613b9a565b90555b6001600160a01b0382168082526002602052604082205490929060ff16613543575b828252600260205260ff604083205416156104665760ff6008541615613534578415610457578315611e6057828252600d602052604082205480861061351d5750828252600f6020526040822054801561350e578086116134f857508461320b91613f78565b670de0b6b3a76400008402848104670de0b6b3a7640000036134e4578282526003602052604082205461323d91613ab4565b90828152600560205260ff604082205416601281106134c4575b50828152600660205261327c612710613274604084205485613a8b565b048093613b6c565b938085106134ac575082815260076020528360408220541061348857828152600760205260408120548481106134795760008051602061482e8339815191526040826132c9888895613b6c565b8486526007602052808387205582519182526020820152a26001546040516318160ddd60e01b815290602090829060049082906001600160a01b03165afa908115611e0a578291613447575b5081546001600160a01b0316803b15611ca057826040518092633a52b90760e11b82528183816133498d3360048401613bc2565b03925af18015611cef57613432575b506001546040516318160ddd60e01b81529190602090839060049082906001600160a01b03165afa908115611cef5783916133fc575b6133989250613b6c565b8581036133e45750507f8caf04742286d017f9ac3924388e188c73e6e5094311c5e59a61a7ef86dda8bf611bcd6020956133d386338761404c565b604051918291339588429285613bdd565b635ab6e2db60e01b8252600486905260245260449150fd5b90506020823d60201161342a575b81613417602093836139c3565b810103126105fe5761339891519061338e565b3d915061340a565b9161344081600493946139c3565b9190613358565b90506020813d602011613471575b81613462602093836139c3565b810103126126d2575138613315565b3d9150613455565b6308aed4ef60e31b8252600482fd5b82815260076020526040812054635960d22160e01b82526004526024849052604490fd5b6371c4efed60e01b8252600485905260245260449150fd5b916134d760ff6117526134dd9495613ad4565b90613ab4565b9038613257565b634e487b7160e01b82526011600452602482fd5b625502a360e91b83526004869052602452604482fd5b636c6ff70d60e11b8352600483fd5b6361767b8560e01b83526004869052602452604482fd5b630df65d9f60e01b8252600482fd5b60405163313ce56760e01b815291939291602081600481865afa85918161359d575b506135795763105482c760e21b8552600485fd5b93919293838352600560205260ff806040852054169116908103611ec957506131a5565b6135b791925060203d6020116109c9576109ba81836139c3565b9038613565565b3381526009602052436040822055338152600a60205260016040822055613183565b503461033b57602036600319011261033b576020610f3c600435613b79565b503461033b57602036600319011261033b576020906040906001600160a01b0361362761392e565b168152600f83522054604051908152f35b503461033b57604036600319011261033b5761365261392e565b60105460243591906001600160a01b0316330361215a576001600160a01b031690811561214b5760406000805160206146ce8339815191529183855260126020528185205490848652601260205280838720558486526014602052828620438752602052828620548587526018602052838720558486526016602052438387205582519182526020820152a280f35b503461033b57602036600319011261033b576020906040906001600160a01b0361370961392e565b168152600683522054604051908152f35b503461033b578060031936011261033b576001546040516001600160a01b039091168152602090f35b503461033b57602036600319011261033b576020906040906001600160a01b0361376b61392e565b168152600d83522054604051908152f35b503461033b57602036600319011261033b5761379661395a565b6010546001600160a01b0316330361047957602060008051602061466e83398151915291151560ff196008541660ff821617600855604051908152a180f35b503461033b57602036600319011261033b5760043563ffffffff60e01b81168091036126d257602090635a05180f60e01b811490811561381b575b506040519015158152f35b637965db0b60e01b811491508115613835575b5082613810565b6301ffc9a760e01b1490508261382e565b503461033b57604036600319011261033b5761386061392e565b6001600160a01b0316808252600260205260408220546024359060ff161561177457670de0b6b3a7640000810290808204670de0b6b3a7640000149015171561391a57916138bc60409383835260036020528483205490613ab4565b91808252600560205260ff8483205416601281106138f1575b5061172a84836127109361173295526006602052205484613a8b565b846117329361390f61271094966134d760ff61175261172a97613ad4565b9593509350506138d5565b634e487b7160e01b83526011600452602483fd5b600435906001600160a01b03821682036105fe57565b602435906001600160a01b03821682036105fe57565b6004359081151582036105fe57565b60609060031901126105fe576004356001600160a01b03811681036105fe57906024359060443590565b9181601f840112156105fe578235916001600160401b0383116105fe576020808501948460051b0101116105fe57565b601f909101601f19168101906001600160401b038211908210176139e657604052565b634e487b7160e01b600052604160045260246000fd5b6001600160401b0381116139e657601f01601f191660200190565b919082519283825260005b848110613a43575050826000602080949584010152601f8019910116010190565b80602080928401015182828601015201613a22565b6084359060ff821682036105fe57565b60405190613a776040836139c3565b6005825264322e332e3360d81b6020830152565b81810292918115918404141715613a9e57565b634e487b7160e01b600052601160045260246000fd5b8115613abe570490565b634e487b7160e01b600052601260045260246000fd5b60ff166012039060ff8211613a9e57565b8015613b665760009060208110600116604e821060011617613b5e57600a916001915b60018111613b35575082600019048211613b2157500290565b634e487b7160e01b81526011600452602490fd5b92806000190481116134e45760018416613b55575b80029260011c613b08565b80920291613b4a565b9050600a0a90565b50600190565b91908203918211613a9e57565b60005260008051602061478e83398151915260205260016040600020015490565b6000198114613a9e5760010190565b908160209103126105fe575160ff811681036105fe5790565b6001600160a01b039091168152602081019190915260400190565b9094939260609260808301968352602083015260408201520152565b6001600160401b0381116139e65760051b60200190565b9190811015613c205760051b0190565b634e487b7160e01b600052603260045260246000fd5b356001600160a01b03811681036105fe5790565b8051821015613c205760209160051b010190565b6001600160a01b03168015613c9f57601080546001600160a01b0319811683179091556001600160a01b031660008051602061474e833981519152600080a3565b63e6c4247b60e01b60005260046000fd5b91908201809211613a9e57565b94919360e0969360ff929a99989561010088019b885260208801526040870152166060850152608084015260a083015260c08201520152565b6001600160a01b03811660008181526002602052604090205490919060ff16158015613de8575b8015613de0575b613dce5781600052600f6020526040600020548015908115613dd6575b50613dce57613d66926040918251948592839262f7fce960e01b845260048401613bc2565b0381305afa918215613dc257600092613d8e575b506000526007602052604060002054101590565b9091506040813d604011613dba575b81613daa604093836139c3565b810103126105fe57519038613d7a565b3d9150613d9d565b6040513d6000823e3d90fd5b505050600090565b9050831138613d41565b508215613d24565b5060ff6008541615613d1d565b6001546001600160a01b0391821691168103613e6a576020602491604051928380926370a0823160e01b82523060048301525afa908115613dc257600091613e3b575090565b90506020813d602011613e62575b81613e56602093836139c3565b810103126105fe575190565b3d9150613e49565b80600052600260205260ff60406000205416613e865750600090565b6040516370a0823160e01b815230600482015290602082602481845afa918215613dc257600092613ede575b506000526007602052604060002054808211600014613ed757613ed491613b6c565b90565b5050600090565b90916020823d602011613f0a575b81613ef9602093836139c3565b8101031261033b5750519038613eb2565b3d9150613eec565b60026000805160206147ce8339815191525414613f3d5760026000805160206147ce83398151915255565b633ee5aeb560e01b60005260046000fd5b60ff6000805160206147ae8339815191525416613f6757565b63d93c066560e01b60005260046000fd5b6001600160a01b0316600081815260136020526040902054801561404757816000526015602052604060002043600052602052613fbb6040600020549384613cb0565b92831061403657808260005260176020524360406000205414614018575b8311613ffc57506000526015602052604060002043600052602052604060002055565b925063029359d560e41b60005260045260245260445260646000fd5b5081600052601960205261403160406000205482613cb0565b613fd9565b63446c8cc960e01b60005260046000fd5b505050565b614081614086939261407360405194859263a9059cbb60e01b602085015260248401613bc2565b03601f1981018452836139c3565b6142ed565b565b600081815260008051602061478e8339815191526020908152604080832033845290915290205460ff16156140ba5750565b63e2517d3f60e01b6000523360045260245260446000fd5b6140dc8282614348565b91826140e757505090565b60009182526000805160206146ae8339815191526020526040909120614116916001600160a01b0316906144d0565b5090565b61412482826143ea565b918261412f57505090565b60009182526000805160206146ae8339815191526020526040909120614116916001600160a01b031690614539565b6001600160a01b03166000818152601260205260409020548015614047578160005260146020526040600020436000526020526141a16040600020549384613cb0565b928310614036578082600052601660205243604060002054146141fe575b83116141e257506000526014602052604060002043600052602052604060002055565b92506319a4e2a760e01b60005260045260245260445260646000fd5b5081600052601860205261421760406000205482613cb0565b6141bf565b6040516323b872dd60e01b60208201526001600160a01b039283166024820152929091166044830152606480830193909352918152614086916140816084836139c3565b60405163313ce56760e01b81529190602090839060049082906001600160a01b03165afa600092816142cc575b506142a357631eecbb6560e01b60005260046000fd5b60ff91821691168082036142b5575050565b631e43476360e11b60005260045260245260446000fd5b6142e691935060203d6020116109c9576109ba81836139c3565b913861428d565b906000602091828151910182855af115613dc2576000513d61433f57506001600160a01b0381163b155b61431e5750565b635274afe760e01b60009081526001600160a01b0391909116600452602490fd5b60011415614317565b600081815260008051602061478e833981519152602090815260408083206001600160a01b038616845290915290205460ff16613ed757600081815260008051602061478e833981519152602090815260408083206001600160a01b0395909516808452949091528120805460ff19166001179055339291907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9080a4600190565b600081815260008051602061478e833981519152602090815260408083206001600160a01b038616845290915290205460ff1615613ed757600081815260008051602061478e833981519152602090815260408083206001600160a01b0395909516808452949091528120805460ff19169055339291907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9080a4600190565b60ff60008051602061480e8339815191525460401c16156144a757565b631afcd79f60e31b60005260046000fd5b8054821015613c205760005260206000200190600090565b6001810190826000528160205260406000205415600014613dce578054600160401b8110156139e65761452461450d8260018794018555846144b8565b819391549060031b91821b91600019901b19161790565b90555491600052602052604060002055600190565b9060018201918160005282602052604060002054801515600014614603576000198101818111613a9e578254600019810191908211613a9e578181036145cc575b505050805480156145b657600019019061459482826144b8565b8154906000199060031b1b191690555560005260205260006040812055600190565b634e487b7160e01b600052603160045260246000fd5b6145ec6145dc61450d93866144b8565b90549060031b1c928392866144b8565b90556000528360205260406000205538808061457a565b50505050600090565b90614632575080511561462157602081519101fd5b63d6bda27560e01b60005260046000fd5b81511580614664575b614643575090565b639996b31560e01b60009081526001600160a01b0391909116600452602490fd5b50803b1561463b56fe2c0a5f5ab0ba371221bb3612c2d2f90d36566279309f526000c5b354efd1b0658c67aaac7f77de07240e5a9b36dfdccb2a89c438635abbb27a73142d2aa0f629c1f6fe24621ce81ec5827caf0253cadb74709b061630e6b55e8237170593200048b07fab687f450848f1df8a96db08fef7840f53415f18fdc2ec8e9f810f0930c7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d275027301df982f5215b4963a854cf9c73219df80cb6acd8f098189c9480c7bbc360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc17dc5b1290f7495d7f8cc68476e6941aaf510598fa925d0d2720edc8805a846c4460507c21097c15f6883572ebd157a9ee4b1d989a312314e93afd9d2ecd494002dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800cd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033009b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00a49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775f0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a006d129bd71f2401cbe77f49f546d7d5f58992faecfca6e51ba06b50b261e83331a164736f6c6343000822000a";
|
|
69828
70301
|
var isSuperArgs = (xs) => xs.length > 1;
|
|
69829
|
-
var SimplePSMV2__factory = class extends
|
|
70302
|
+
var SimplePSMV2__factory = class extends import_ethers30.ContractFactory {
|
|
69830
70303
|
constructor(...args) {
|
|
69831
70304
|
if (isSuperArgs(args)) {
|
|
69832
70305
|
super(...args);
|
|
@@ -69846,10 +70319,10 @@ var SimplePSMV2__factory = class extends import_ethers29.ContractFactory {
|
|
|
69846
70319
|
static bytecode = _bytecode;
|
|
69847
70320
|
static abi = _abi;
|
|
69848
70321
|
static createInterface() {
|
|
69849
|
-
return new
|
|
70322
|
+
return new import_ethers30.Interface(_abi);
|
|
69850
70323
|
}
|
|
69851
70324
|
static connect(address, runner) {
|
|
69852
|
-
return new
|
|
70325
|
+
return new import_ethers30.Contract(address, _abi, runner);
|
|
69853
70326
|
}
|
|
69854
70327
|
};
|
|
69855
70328
|
var _abi2 = [
|
|
@@ -71544,7 +72017,7 @@ var _abi2 = [
|
|
|
71544
72017
|
];
|
|
71545
72018
|
var _bytecode2 = "0x60a080604052346100ea57306080527ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460ff8160401c166100d9576002600160401b03196001600160401b03821601610073575b60405161304c90816100f0823960805181818161114401526113290152f35b6001600160401b0319166001600160401b039081177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005581527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a13880610054565b63f92ee8a960e01b60005260046000fd5b600080fdfe608080604052600436101561001357600080fd5b60003560e01c90816301ffc9a714611ff7575080630d33f3c214611fd35780630f3f4a9414611f885780631459457a14611be257806318c38b8914611ad15780631d44454114611a005780632106764c146119d9578063248a9ca3146119b35780632ec22d4c146118f25780632f0647ce146118775780632f2ff15d14611846578063324207441461177257806336568abe1461172c578063392f1087146116f65780633f4ba83a146115fe5780633f5aadc91461158f5780634f1ef286146112ad57806352340363146111c45780635273b6f61461119b57806352d1902d14611131578063554c4f4b146110a1578063561b7f8a14610f755780635bc26aea14610ee85780635c975abb14610eb85780636289d18c14610e375780636711cc0b14610e1b5780636e852a7814610d1a5780637e35bf6e14610ce65780638343f67414610cb95780638456cb5914610bc35780638f33527f14610b895780639010d07c14610b3557806391d1485414610adb5780639b9d30c114610ab2578063a19af3f614610a01578063a217fddf146109e5578063a3246ad314610923578063a878086414610907578063ac3c0e30146107fa578063ad3cb1cc146107b3578063b3fad6381461070e578063c34e9c26146106f2578063c86deb31146106d6578063ca15c8731461069d578063d547741f14610665578063dd71d99a14610623578063e0922fa114610576578063efa9b4ae14610507578063f2f4eb26146104de578063f68e9553146104b5578063f94f67ab146103de578063fd437d391461029f5763ffa1ad741461026657600080fd5b3461029a57600036600319011261029a576102966102826121ed565b6040519182916020835260208301906121c8565b0390f35b600080fd5b3461029a57606036600319011261029a576102b861207a565b6102c0612064565b906102c961218f565b906102d2612795565b6001600160a01b0316338190036103ce5780600052600160205260406000209283549360ff8560e01c1660038110156103b8576001036103a75781600160209261033e877fc5d5c5bbf10444998e0ea6d4725e79027b574e1c14ec929279e8a9a95c6c6e919688612c43565b818060a01b038316828060a01b031982541617815561035d878261239f565b0180546001600160401b031916426001600160401b03908116919091179091556001600160a01b0391821660008181526002855260409081902087905551969091168652951693a4005b632437e77160e11b60005260046000fd5b634e487b7160e01b600052602160045260246000fd5b62fca64560e31b60005260046000fd5b3461029a57604036600319011261029a576004356103fa6120c9565b90610403612795565b63ffffffff600554169163ffffffff8116928084109081156104ac575b5061049b5760207f6b7727cc9c3df4a29acf0afe01594c1b7e845d20f40f4a14e4c292164a9ed8e191610452846127e0565b9161046a600863ffffffff845460a01c1617836122e3565b81546001600160e01b031660e09190911b6001600160e01b0319161790556040519485526001600160a01b031693a3005b634346c13160e01b60005260046000fd5b90501584610420565b3461029a57600036600319011261029a576020604051600080516020612fe08339815191528152f35b3461029a57600036600319011261029a576003546040516001600160a01b039091168152602090f35b3461029a57602036600319011261029a57600435610523612795565b61054561052f826127e0565b9190600163ffffffff825460a01c1617906122e3565b6001600160a01b0316907f812690e0a9dff5bf3add998111b8af5c8299608d859025bfe35662060ab4267d600080a3005b3461029a57602036600319011261029a576004356001600160401b0381169081810361029a576000546001600160a01b038116330361061257600160a01b600160e01b0319811660a092831b600160a01b600160e01b031617600055604080519190921c6001600160401b0316815260208101929092527f9c195448332abd01f716db873b329752ea02f19d33f7e311fb0daf082c4edd0391a1005b6349db3bd360e01b60005260046000fd5b3461029a57602036600319011261029a576001600160a01b0361064461207a565b166000526002602052602060018060a01b0360406000205416604051908152f35b3461029a57604036600319011261029a5761069b600435610684612064565b90610696610691826122c2565b6126bf565b612751565b005b3461029a57602036600319011261029a57600435600052600080516020612ee08339815191526020526020604060002054604051908152f35b3461029a57600036600319011261029a57602060405160088152f35b3461029a57600036600319011261029a57602060405160028152f35b3461029a57602036600319011261029a576000606060405161072f81612136565b828152826020820152826040820152015260043560005260046020526080604060002063ffffffff6040519161076483612136565b548160018060a01b038216938481528160208201818560a01c16815260606040840193838760c01c168552019460e01c8552604051968752511660208601525116604084015251166060820152f35b3461029a57600036600319011261029a5761029660408051906107d68183612151565b60058252640352e302e360dc1b6020830152519182916020835260208301906121c8565b3461029a57602036600319011261029a5761081361207a565b6000608060405161082381612105565b828152826020820152826040820152826060820152015260018060a01b03166000526001602052604060002060405161085b81612105565b81546001600160a01b038116825260a081901c6001600160401b03166020830190815292604083019160e01c60ff169060038210156103b857908252600101546001600160401b0380821660608501908152604092831c821660808601908152925194516001600160a01b03168552945116602084015290519260038410156103b857604083019390935291516001600160401b0390811660608301529151909116608082015260a090f35b3461029a57600036600319011261029a57602060405160018152f35b3461029a57602036600319011261029a57600435600052600080516020612ee083398151915260205260406000206040518060208354918281520190819360005260206000209060005b8181106109cf5750505081610983910382612151565b6040519182916020830190602084525180915260408301919060005b8181106109ad575050500390f35b82516001600160a01b031684528594506020938401939092019160010161099f565b825484526020909301926001928301920161096d565b3461029a57600036600319011261029a57602060405160008152f35b3461029a57604036600319011261029a57600435610a1d6120c9565b90610a26612795565b63ffffffff600554169163ffffffff811692808410908115610aa9575b5061049b5760207f1da95b87b4c773f68c1447ffc5644e41a8a8887d55065beb64852014cf7140be91610a96610a78856127e0565b9290610a91600463ffffffff835460a01c1617826122e3565b612210565b6040519485526001600160a01b031693a3005b90501584610a43565b3461029a57600036600319011261029a576020604051600080516020612f208339815191528152f35b3461029a57604036600319011261029a57610af4612064565b600435600052600080516020612fc083398151915260205260406000209060018060a01b0316600052602052602060ff604060002054166040519015158152f35b3461029a57604036600319011261029a57600435600052600080516020612ee08339815191526020526020610b706024356040600020612d0c565b905460405160039290921b1c6001600160a01b03168152f35b3461029a57602036600319011261029a576001600160a01b03610baa61207a565b1660005260026020526020604060002054604051908152f35b3461029a57600036600319011261029a573360009081527f0ac8cc3d209806126662940717264973110c39045b305f6ba49613325a615e09602052604090205460ff1615610c9257610c13612795565b600160ff19600080516020613000833981519152541617600080516020613000833981519152557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a16040514281527f80170b5fcdd2bf1e0660ef4b8851f86685f64d41b1a19de1471947ece8725aac60203392a2005b63e2517d3f60e01b60005233600452600080516020612f2083398151915260245260446000fd5b3461029a57600036600319011261029a5760005460405160a09190911c6001600160401b03168152602090f35b3461029a57604036600319011261029a57610d0a610d02612064565b60043561236c565b906102966040519283928361209a565b3461029a57604036600319011261029a57610d3361207a565b336000908152600080516020612f60833981519152602052604090205460ff161580610e08575b6103ce576001600160a01b03166000818152600160205260409020805460e01c60ff1660038110156103b8576001036103a757805460ff60e01b198116600160e11b1782556001919091018054600160401b600160801b03191642604090811b600160401b600160801b0316919091179091555160243581526001600160a01b0390911691907fc0499cc07ed9d734deec6857802d3f0fa8d5afaf79a7008beb8ba7bef62a271b90602090a3005b50336001600160a01b0382161415610d5a565b3461029a57600036600319011261029a57602060405160048152f35b3461029a57602036600319011261029a57610e506120b6565b6000546001600160a01b031633036106125763ffffffff8116908115610ea757600080516020612fa083398151915291610ea263ffffffff926005549284198416176005556040519384931683612233565b0390a1005b6338f3377360e21b60005260046000fd5b3461029a57600036600319011261029a57602060ff60008051602061300083398151915254166040519015158152f35b3461029a57602036600319011261029a57610f0161207a565b6000546001600160a01b0381169033829003610612576001600160a01b038316928315610f64573b15610f53576001600160a01b03191682176000908155600080516020612f808339815191529080a3005b636f7c43f160e01b60005260046000fd5b63e6c4247b60e01b60005260046000fd5b3461029a57606036600319011261029a57610f8e61207a565b610f96612064565b610f9e61218f565b91610fa7612795565b6001600160a01b031690338290036103ce57816000526001602052604060002060ff815460e01c1660038110156103b857600114611090578160209161100f867ff223dc085722c94c84dcf67427e225799be616382a2a484d378f8921c69a20339587612c43565b80546001600160a01b0319166001600160a01b038316178155611032868261239f565b6001810180546001600160801b031916426001600160401b0390811691909117909155815460ff60e01b1916600160e01b179091556001600160a01b03919091166000818152600284526040908190208690555195909116855293a3005b639d2c8fdf60e01b60005260046000fd5b3461029a57602036600319011261029a576001600160a01b036110c261207a565b166000526001602052604060002060ff60008051602061300083398151915254161580611115575b602091816110fe575b506040519015158152f35b5460a01c6001600160401b031642109050826110f3565b5060ff815460e01c169060038210156103b857906001146110ea565b3461029a57600036600319011261029a577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316300361118a576020604051600080516020612f408339815191528152f35b63703e46dd60e11b60005260046000fd5b3461029a57600036600319011261029a576000546040516001600160a01b039091168152602090f35b3461029a57602036600319011261029a57600435604060008281526004602052209081549160018060a01b03831692831590811561129e575b5061128d57336000908152600080516020612f60833981519152602052604090205460ff161580611283575b611272578061124563fffffffe61124b935460a01c16826122e3565b8261269b565b7fa5ffbdba01b15df97334e34ad816b9986b6057a5ddc97aba93b7e8ccd21759ed600080a3005b630a606ec360e11b60005260046000fd5b5082331415611229565b6360eb6c2360e01b60005260046000fd5b6001915060a01c1615846111fd565b604036600319011261029a576112c161207a565b602435906001600160401b03821161029a573660238301121561029a578160040135906112ed82612174565b916112fb6040519384612151565b8083526020830193366024838301011161029a57816000926024602093018737840101526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630811490811561156c575b5061118a576000546001600160a01b03163303610612576001600160a01b038116928315610f6457813b1561155b5730841461154c57600080516020612f4083398151915254846113a36121ed565b7f6ea8b34d59b2818d3f37a08dddaa06f5886b9c20c907b36f03ca6528e106e86f6113d9604051926040845260408401906121c8565b4260208401526001600160a01b038516929081900390a36040516352d1902d60e01b8152602081600481895afa60009181611518575b506114295785634c9c8ce360e01b60005260045260246000fd5b9081600080516020612f408339815191528793036115045750833b156114ef576001600160a01b0319168117600080516020612f40833981519152557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a28251156114d4576000809161069b945190845af43d156114cc573d916114af83612174565b926114bd6040519485612151565b83523d6000602085013e612e7e565b606091612e7e565b505050346114de57005b63b398979f60e01b60005260046000fd5b50634c9c8ce360e01b60005260045260246000fd5b632a87526960e21b60005260045260246000fd5b9091506020813d602011611544575b8161153460209383612151565b8101031261029a5751908761140f565b3d9150611527565b614e8d60eb1b60005260046000fd5b632e07c4bd60e11b60005260046000fd5b600080516020612f40833981519152546001600160a01b03161415905084611354565b3461029a57602036600319011261029a576004356115ab612795565b6115cd6115b7826127e0565b9190600263ffffffff825460a01c1617906122e3565b6001600160a01b0316907fc2713e691344add4705edc62a0ee5aede95ba66ad68f97316efef9cb50644edd600080a3005b3461029a57600036600319011261029a57336000908152600080516020612f60833981519152602052604090205460ff1615806116e1575b6116d0576000805160206130008339815191525460ff8116156116bf5760ff1916600080516020613000833981519152557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a16040514281527f107553d8191d85b405879cf752997865edd48d94e20bda4dd27223c94b31a7cc60203392a2005b638dfc202b60e01b60005260046000fd5b63659a07b360e11b60005260046000fd5b506000546001600160a01b0316331415611636565b3461029a57604036600319011261029a5761029661171d611715612064565b600435612306565b604093919351938493846120dc565b3461029a57604036600319011261029a57611745612064565b336001600160a01b038216036117615761069b90600435612751565b63334bd91960e11b60005260046000fd5b3461029a57602036600319011261029a57600435604060008281526004602052209081549160018060a01b038316928315908115611837575b5061128d57336000908152600080516020612f60833981519152602052604090205460ff16158061182d575b61127257806117f363fffffff7611806935460a01c16826122e3565b80546001600160e01b031681558261269b565b7f054490ec6650e07db9b97a06ea31d44cebd44b390c9975a380055e1b4d3cac21600080a3005b50823314156117d7565b6008915060a01c1615846117ab565b3461029a57604036600319011261029a5761069b600435611865612064565b90611872610691826122c2565b612709565b3461029a57602036600319011261029a576004356118c161189782612629565b91906118ad63fffffffb825460a01c16826122e3565b805463ffffffff60c01b191681558361269b565b6001600160a01b0316907f09cb4ec44cdef8489412844b9682f87f7900758fa2bd7e039113e9125e538e0f600080a3005b3461029a57602036600319011261029a57600435604060008281526004602052209081549160018060a01b0383169283159081156119a4575b5061128d57336000908152600080516020612f60833981519152602052604090205460ff16158061199a575b611272578061124563fffffffd611973935460a01c16826122e3565b7fb390ab029eab314bd18190ebe73d7e5c1c336beaa5c83ac22578378dc9ccc405600080a3005b5082331415611957565b6002915060a01c16158461192b565b3461029a57602036600319011261029a5760206119d16004356122c2565b604051908152f35b3461029a57604036600319011261029a5761029661171d6119f8612064565b60043561224a565b3461029a57604036600319011261029a57600435611a1c6120c9565b63ffffffff600554169063ffffffff811691808310908115611ac8575b5061049b57611a4783612629565b909263ffffffff845460c01c16809260018060a01b03163314159182611abd575b5050611aac57611a98827e8a218591d4362499c38c38eb1c12e7a7cc97a9068818d1fe6046a42ba4a5ba94612210565b611aa760405192839283612233565b0390a2005b634e80a40760e11b60005260046000fd5b111590508186611a68565b90501584611a39565b3461029a57602036600319011261029a57611aea6120b6565b6000805160206130208339815191525460ff8160401c16908115611bca575b50611bb957600080516020613020833981519152805460026001600160401b0319821681179092556000546001600160481b031990911690911791906001600160a01b031633036106125763ffffffff168015610ea757604081600080516020612fa08339815191529263ffffffff196005541617600555815190600082526020820152a160008051602061302083398151915255600080516020612f00833981519152602060405160028152a1005b63f92ee8a960e01b60005260046000fd5b60026001600160401b03919091161015905082611b09565b3461029a5760a036600319011261029a57611bfb61207a565b611c03612064565b906044356001600160a01b03811680820361029a576064356001600160a01b0381169182820361029a576084356001600160a01b038116949085900361029a5760008051602061302083398151915254604081901c60ff161596906001600160401b031680159081611f80575b6001149081611f76575b159081611f6d575b50611bb95760008051602061302083398151915280546001600160401b031916600117905586611f48575b611cb5612acc565b611cbd612acc565b611cc5612acc565b611ccd612acc565b6001600160a01b038116908115610f64578315610f64578515610f64576001600160a01b038916988915610f64573b15610f5357858414611f375762aa36a746148015611f2c575b8015611f21575b1580611f0f575b610f5357611d32906000612afa565b9081611ec8575b5015611e0d57611d5790600080516020612fe0833981519152612afa565b9081611e73575b5015611e0d57611d7c90600080516020612f20833981519152612afa565b9081611e1e575b5015611e0d57600080546001600160a01b031916841781556040519390600080516020612f808339815191528180a38015610f6457803b15610f5357600380546001600160a01b031916919091179055611dd957005b600080516020613020833981519152805460ff60401b1916905560018152600080516020612f0083398151915290602090a1005b63cf5a8e3360e01b60005260046000fd5b600080516020612f20833981519152600052600080516020612ee0833981519152602052611e6c907ffff5b43478fa6840382eb63777e0da6941d320b940e3f70f0ea4780feff95827612d3a565b5084611d83565b600080516020612fe0833981519152600052600080516020612ee0833981519152602052611ec1907f32d31393d541a265984ec379cddd8b1fcbe5f2b0eb8ad81dddfead454f135eaa612d3a565b5086611d5e565b60008052600080516020612ee0833981519152602052611f08907f615f0f9e84155bea8cc509fe18befeb1baf65611e38a6ba60964480fb29dfd44612d3a565b5088611d39565b50823b1580611d235750843b15611d23565b50617a694614611d1c565b506105394614611d15565b638135316560e01b60005260046000fd5b600080516020613020833981519152805460ff60401b1916600160401b179055611cad565b90501589611c82565b303b159150611c7a565b889150611c70565b3461029a57604036600319011261029a57610296611fbc611fa7612064565b600435600052600460205260406000206123c8565b611fc581612090565b60405191818392158361209a565b3461029a57600036600319011261029a57602063ffffffff60055416604051908152f35b3461029a57602036600319011261029a576004359063ffffffff60e01b821680920361029a57602091635a05180f60e01b8114908115612039575b5015158152f35b637965db0b60e01b811491508115612053575b5083612032565b6301ffc9a760e01b1490508361204c565b602435906001600160a01b038216820361029a57565b600435906001600160a01b038216820361029a57565b600811156103b857565b9015158152604081019291906020906120b283612090565b0152565b6004359063ffffffff8216820361029a57565b6024359063ffffffff8216820361029a57565b91604091949363ffffffff916060850196151585526120fa81612090565b602085015216910152565b60a081019081106001600160401b0382111761212057604052565b634e487b7160e01b600052604160045260246000fd5b608081019081106001600160401b0382111761212057604052565b601f909101601f19168101906001600160401b0382119082101761212057604052565b6001600160401b03811161212057601f01601f191660200190565b604435906001600160401b038216820361029a57565b60005b8381106121b85750506000910152565b81810151838201526020016121a8565b906020916121e1815180928185528580860191016121a5565b601f01601f1916010190565b604051906121fc604083612151565b60058252640322e312e360dc1b6020830152565b805463ffffffff60c01b191660c09290921b63ffffffff60c01b16919091179055565b63ffffffff91821681529116602082015260400190565b600052600460205261226160406000209182612485565b61226a81612090565b806122b857505460e01c63ffffffff60055416811580156122b0575b6122a35780821061229c57505b60019160009190565b9050612293565b5050600090600390600090565b508015612286565b6000929091508290565b600052600080516020612fc083398151915260205260016040600020015490565b805463ffffffff60a01b191660a09290921b63ffffffff60a01b16919091179055565b919091600052600460205261232060406000209283612511565b9161232a83612090565b826123625763ffffffff9192505460c01c1663ffffffff60055416811580156122b0576122a35780821061229c575060019160009190565b5060009190600090565b90612383916000526004602052604060002061259d565b61238c81612090565b8061239a5750600190600090565b600091565b8054600160a01b600160e01b03191660a09290921b600160a01b600160e01b0316919091179055565b60ff600080516020613000833981519152541661247e57546001600160a01b0381169081156124765760a01c6002161561246f5760005260016020526040600020549060ff8260e01c1660038110156103b857801561246757600214612460574260a083901c6001600160401b03161115612459576001600160a01b0390811691160361245457600090565b600790565b5050600690565b5050600590565b505050600490565b5050600390565b505050600290565b5050600190565b60ff600080516020613000833981519152541661247e57546001600160a01b0381169081156124765760a01c6008161561246f5760005260016020526040600020549060ff8260e01c1660038110156103b857801561246757600214612460574260a083901c6001600160401b03161115612459576001600160a01b0390811691160361245457600090565b60ff600080516020613000833981519152541661247e57546001600160a01b0381169081156124765760a01c6004161561246f5760005260016020526040600020549060ff8260e01c1660038110156103b857801561246757600214612460574260a083901c6001600160401b03161115612459576001600160a01b0390811691160361245457600090565b60ff600080516020613000833981519152541661247e57546001600160a01b0381169081156124765760a01c6001161561246f5760005260016020526040600020549060ff8260e01c1660038110156103b857801561246757600214612460574260a083901c6001600160401b03161115612459576001600160a01b0390811691160361245457600090565b6000908152600460205260409020805490916001600160a01b03821691821590811561268c575b5061128d57336000908152600080516020612f60833981519152602052604090205460ff161580612682575b61127257565b508133141561267c565b6004915060a01c161538612650565b905460a01c63ffffffff16156126ae5750565b600052600460205260006040812055565b6000818152600080516020612fc08339815191526020908152604080832033845290915290205460ff16156126f15750565b63e2517d3f60e01b6000523360045260245260446000fd5b6127138282612afa565b918261271e57505090565b6000918252600080516020612ee0833981519152602052604090912061274d916001600160a01b031690612d3a565b5090565b61275b8282612ba3565b918261276657505090565b6000918252600080516020612ee0833981519152602052604090912061274d916001600160a01b031690612dab565b60ff60008051602061300083398151915254166127ae57565b63d93c066560e01b60005260046000fd5b519064ffffffffff8216820361029a57565b519061ffff8216820361029a57565b8015612abb57600354604051638d34875560e01b8152600481018390529190600090839060249082906001600160a01b03165afa918215612aaf57600092612904575b5060808201516001600160a01b0316913383900361127257610120015161284981612090565b61285281612090565b600381149081156128ef575b81156128db575b506128ca5781600052600160205260ff60406000205460e01c1660038110156103b8576001036128b957600090815260046020526040902080546001600160a01b0319166001600160a01b03831617815591565b632e68d1d360e21b60005260046000fd5b63e9f6db8560e01b60005260046000fd5b600791506128e881612090565b1438612865565b90506128fa81612090565b600581149061285e565b90913d8082843e6129158184612151565b820191602081840312612a8f578051906001600160401b038211612a975701906101a082840312612a8c57604051926101a084016001600160401b03811185821017612a9b5760409081528351855260208085015190860152838101519085015260608301516001600160401b038111612a9757830181601f82011215612a97578051906129a282612174565b926129b06040519485612151565b82845260208383010111612a9357906129cf91602080850191016121a5565b606084015260808201516001600160a01b0381168103612a8f5760808401526129fa60a083016127bf565b60a0840152612a0b60c083016127bf565b60c0840152612a1c60e083016127d1565b60e0840152612a2e61010083016127bf565b610100840152610120820151906008821015612a8c5750612a7f9161018091610120850152612a6061014082016127bf565b610140850152612a7361016082016127d1565b610160850152016127bf565b6101808201529038612823565b80fd5b5080fd5b8380fd5b8280fd5b634e487b7160e01b83526041600452602483fd5b6040513d6000823e3d90fd5b637bb0b62160e01b60005260046000fd5b60ff6000805160206130208339815191525460401c1615612ae957565b631afcd79f60e31b60005260046000fd5b6000818152600080516020612fc0833981519152602090815260408083206001600160a01b038616845290915290205460ff16612b9c576000818152600080516020612fc0833981519152602090815260408083206001600160a01b0395909516808452949091528120805460ff19166001179055339291907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9080a4600190565b5050600090565b6000818152600080516020612fc0833981519152602090815260408083206001600160a01b038616845290915290205460ff1615612b9c576000818152600080516020612fc0833981519152602090815260408083206001600160a01b0395909516808452949091528120805460ff19169055339291907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9080a4600190565b158015612cfb575b610f64576001600160a01b0316600090815260026020526040902054612cea576001600160401b031642811115612cd95760005460a01c6001600160401b03168015159182612cae575b5050612c9d57565b63e774e7b560e01b60005260046000fd5b909150428103908111612cc357113880612c95565b634e487b7160e01b600052601160045260246000fd5b63efa7aefd60e01b60005260046000fd5b633b53f64f60e21b60005260046000fd5b506001600160a01b03811615612c4b565b8054821015612d245760005260206000200190600090565b634e487b7160e01b600052603260045260246000fd5b6001810190826000528160205260406000205415600014612da3578054600160401b81101561212057612d8e612d77826001879401855584612d0c565b819391549060031b91821b91600019901b19161790565b90555491600052602052604060002055600190565b505050600090565b9060018201918160005282602052604060002054801515600014612e75576000198101818111612cc3578254600019810191908211612cc357818103612e3e575b50505080548015612e28576000190190612e068282612d0c565b8154906000199060031b1b191690555560005260205260006040812055600190565b634e487b7160e01b600052603160045260246000fd5b612e5e612e4e612d779386612d0c565b90549060031b1c92839286612d0c565b905560005283602052604060002055388080612dec565b50505050600090565b90612ea45750805115612e9357602081519101fd5b63d6bda27560e01b60005260046000fd5b81511580612ed6575b612eb5575090565b639996b31560e01b60009081526001600160a01b0391909116600452602490fd5b50803b15612ead56fec1f6fe24621ce81ec5827caf0253cadb74709b061630e6b55e82371705932000c7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d275027301df982f5215b4963a854cf9c73219df80cb6acd8f098189c9480c7bbc360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc07966f2ab141347034724e9b2a472c2f77f5cd745aeba27cacba797b8fcb708617dc5b1290f7495d7f8cc68476e6941aaf510598fa925d0d2720edc8805a846cd37bc77615afefc793aa17d75d4249a9b517ba91b0e54a49c9c4a44b3d7e228302dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800edcc084d3dcd65a1f7f23c65c46722faca6953d28e43150a467cf43e5c309238cd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300f0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00a164736f6c6343000822000a";
|
|
71546
72019
|
var isSuperArgs2 = (xs) => xs.length > 1;
|
|
71547
|
-
var AgentDelegationRegistry__factory = class extends
|
|
72020
|
+
var AgentDelegationRegistry__factory = class extends import_ethers31.ContractFactory {
|
|
71548
72021
|
constructor(...args) {
|
|
71549
72022
|
if (isSuperArgs2(args)) {
|
|
71550
72023
|
super(...args);
|
|
@@ -71564,10 +72037,10 @@ var AgentDelegationRegistry__factory = class extends import_ethers30.ContractFac
|
|
|
71564
72037
|
static bytecode = _bytecode2;
|
|
71565
72038
|
static abi = _abi2;
|
|
71566
72039
|
static createInterface() {
|
|
71567
|
-
return new
|
|
72040
|
+
return new import_ethers31.Interface(_abi2);
|
|
71568
72041
|
}
|
|
71569
72042
|
static connect(address, runner) {
|
|
71570
|
-
return new
|
|
72043
|
+
return new import_ethers31.Contract(
|
|
71571
72044
|
address,
|
|
71572
72045
|
_abi2,
|
|
71573
72046
|
runner
|
|
@@ -71581,7 +72054,7 @@ var POSITION_DELEGATE_REGISTRY_ABI = [
|
|
|
71581
72054
|
"event PositionDelegateUpdated(bytes32 indexed positionId, address indexed oldDelegate, address indexed newDelegate)"
|
|
71582
72055
|
];
|
|
71583
72056
|
async function setPositionDelegate(positionId, delegate, signer, registryAddress) {
|
|
71584
|
-
const registry = new
|
|
72057
|
+
const registry = new import_ethers32.Contract(
|
|
71585
72058
|
registryAddress,
|
|
71586
72059
|
POSITION_DELEGATE_REGISTRY_ABI,
|
|
71587
72060
|
signer
|
|
@@ -71589,7 +72062,7 @@ async function setPositionDelegate(positionId, delegate, signer, registryAddress
|
|
|
71589
72062
|
return registry["setPositionDelegate"](positionId, delegate);
|
|
71590
72063
|
}
|
|
71591
72064
|
async function getPositionDelegate(positionId, provider, registryAddress) {
|
|
71592
|
-
const registry = new
|
|
72065
|
+
const registry = new import_ethers32.Contract(
|
|
71593
72066
|
registryAddress,
|
|
71594
72067
|
POSITION_DELEGATE_REGISTRY_ABI,
|
|
71595
72068
|
provider
|
|
@@ -71712,7 +72185,7 @@ var SIGNABLE_FUNCTIONS2 = [
|
|
|
71712
72185
|
// this too is client-only and never module-whitelisted.
|
|
71713
72186
|
"function addAddress(string btcAddress) external"
|
|
71714
72187
|
];
|
|
71715
|
-
var IFACE2 = new
|
|
72188
|
+
var IFACE2 = new import_ethers34.ethers.Interface(SIGNABLE_FUNCTIONS2);
|
|
71716
72189
|
function encodeSignable2(fn, args) {
|
|
71717
72190
|
return IFACE2.encodeFunctionData(fn, args);
|
|
71718
72191
|
}
|
|
@@ -71737,7 +72210,7 @@ function eqAddr2(a, b) {
|
|
|
71737
72210
|
if (!a || !b)
|
|
71738
72211
|
return false;
|
|
71739
72212
|
try {
|
|
71740
|
-
return
|
|
72213
|
+
return import_ethers35.ethers.getAddress(a) === import_ethers35.ethers.getAddress(b);
|
|
71741
72214
|
} catch {
|
|
71742
72215
|
return false;
|
|
71743
72216
|
}
|
|
@@ -71803,7 +72276,7 @@ function readValue2(tx2) {
|
|
|
71803
72276
|
}
|
|
71804
72277
|
function normalizePositionId2(id) {
|
|
71805
72278
|
const hex = id.startsWith("0x") ? id : `0x${id}`;
|
|
71806
|
-
return
|
|
72279
|
+
return import_ethers35.ethers.zeroPadValue(hex, 32).toLowerCase();
|
|
71807
72280
|
}
|
|
71808
72281
|
function requirePositionId(actual, expected) {
|
|
71809
72282
|
const txPositionId = String(actual).toLowerCase();
|
|
@@ -72095,18 +72568,18 @@ function buildPsmRedeemTx2(p) {
|
|
|
72095
72568
|
var PSM_READS_ABI = ["function supportedStablecoins(address) view returns (bool)"];
|
|
72096
72569
|
var ERC20_READS_ABI = ["function allowance(address owner, address spender) view returns (uint256)"];
|
|
72097
72570
|
function psmExchangeReadsFromProvider(provider, psmAddress) {
|
|
72098
|
-
const psm = new
|
|
72571
|
+
const psm = new import_ethers33.ethers.Contract(psmAddress, PSM_READS_ABI, provider);
|
|
72099
72572
|
return {
|
|
72100
72573
|
isStablecoinSupported: async (stablecoin) => await psm.getFunction("supportedStablecoins")(stablecoin),
|
|
72101
|
-
allowance: async (token, owner, spender) => await new
|
|
72574
|
+
allowance: async (token, owner, spender) => await new import_ethers33.ethers.Contract(token, ERC20_READS_ABI, provider).getFunction("allowance")(owner, spender)
|
|
72102
72575
|
};
|
|
72103
72576
|
}
|
|
72104
72577
|
var refuse = (direction, msg) => new TxValidationError2(msg, `PSM ${direction}`);
|
|
72105
72578
|
function requireAddress(direction, label, value) {
|
|
72106
|
-
if (!value || !
|
|
72579
|
+
if (!value || !import_ethers33.ethers.isAddress(value)) {
|
|
72107
72580
|
throw refuse(direction, `${label} address is missing or invalid (${String(value)})`);
|
|
72108
72581
|
}
|
|
72109
|
-
return
|
|
72582
|
+
return import_ethers33.ethers.getAddress(value);
|
|
72110
72583
|
}
|
|
72111
72584
|
async function planPsmExchange(params) {
|
|
72112
72585
|
const { direction, amountIn, minOut, vctx, reads } = params;
|
|
@@ -72671,7 +73144,7 @@ function contractErrorTable() {
|
|
|
72671
73144
|
if (TABLE)
|
|
72672
73145
|
return TABLE;
|
|
72673
73146
|
const table = /* @__PURE__ */ new Map();
|
|
72674
|
-
const iface = new
|
|
73147
|
+
const iface = new import_ethers36.Interface(CONTRACT_ERROR_FRAGMENTS.map((e) => e.fragment));
|
|
72675
73148
|
const contractsByName = new Map(
|
|
72676
73149
|
CONTRACT_ERROR_FRAGMENTS.map((e) => [e.fragment.slice("error ".length, e.fragment.indexOf("(")), e.contracts])
|
|
72677
73150
|
);
|
|
@@ -72764,7 +73237,7 @@ function decodeContractError(error) {
|
|
|
72764
73237
|
const contract = entry.contracts.join(" | ");
|
|
72765
73238
|
let args = [];
|
|
72766
73239
|
try {
|
|
72767
|
-
const decoded = new
|
|
73240
|
+
const decoded = new import_ethers36.Interface([entry.fragment]).decodeErrorResult(entry.fragment, errorData);
|
|
72768
73241
|
args = Array.from(decoded);
|
|
72769
73242
|
} catch {
|
|
72770
73243
|
args = [];
|
|
@@ -73323,7 +73796,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
73323
73796
|
*/
|
|
73324
73797
|
constructor(config) {
|
|
73325
73798
|
if (!config.provider && config.ethRpcUrl) {
|
|
73326
|
-
config.provider = new
|
|
73799
|
+
config.provider = new import_ethers15.JsonRpcProvider(config.ethRpcUrl);
|
|
73327
73800
|
}
|
|
73328
73801
|
this.config = config;
|
|
73329
73802
|
if (config.debug) {
|
|
@@ -73616,7 +74089,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
73616
74089
|
const network = await config.provider.getNetwork();
|
|
73617
74090
|
chainId = Number(network.chainId);
|
|
73618
74091
|
} else if (config.ethRpcUrl) {
|
|
73619
|
-
const tempProvider = new
|
|
74092
|
+
const tempProvider = new import_ethers15.JsonRpcProvider(
|
|
73620
74093
|
config.ethRpcUrl
|
|
73621
74094
|
);
|
|
73622
74095
|
const network = await tempProvider.getNetwork();
|
|
@@ -74162,7 +74635,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
74162
74635
|
}
|
|
74163
74636
|
const loanOps = this.loanOps();
|
|
74164
74637
|
const protocolConfig = await loanOps.getProtocolConfig();
|
|
74165
|
-
const requestAmountWei = (0,
|
|
74638
|
+
const requestAmountWei = (0, import_ethers15.parseEther)(
|
|
74166
74639
|
request.amount.toString()
|
|
74167
74640
|
);
|
|
74168
74641
|
const minLoanValueWei = BigInt(protocolConfig.minimumLoanValueWei);
|
|
@@ -74264,12 +74737,12 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
74264
74737
|
);
|
|
74265
74738
|
return {
|
|
74266
74739
|
success: false,
|
|
74267
|
-
error: `Amount ${request.amount} UCD plus the ${positionTerm.originationFeeBps / 100}% origination fee (${(0,
|
|
74740
|
+
error: `Amount ${request.amount} UCD plus the ${positionTerm.originationFeeBps / 100}% origination fee (${(0, import_ethers15.formatEther)(baseFeeWei)} UCD) would take this loan's debt to ${(0, import_ethers15.formatEther)(debtAfterWei)} UCD, above the protocol maximum of ${(0, import_ethers15.formatEther)(maxLoanValueWei)} UCD. The largest amount you can mint now is ${maxPrincipalUcd} UCD.`
|
|
74268
74741
|
};
|
|
74269
74742
|
}
|
|
74270
74743
|
if (this.config.debug) {
|
|
74271
74744
|
log.info(
|
|
74272
|
-
`\u2705 Fee-inclusive loan cap check passed: ${(0,
|
|
74745
|
+
`\u2705 Fee-inclusive loan cap check passed: ${(0, import_ethers15.formatEther)(currentDebtWei + requestAmountWei + baseFeeWei)} UCD <= ${(0, import_ethers15.formatEther)(maxLoanValueWei)} UCD`,
|
|
74273
74746
|
{}
|
|
74274
74747
|
);
|
|
74275
74748
|
}
|
|
@@ -74300,7 +74773,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
74300
74773
|
pkpNftAddress,
|
|
74301
74774
|
this.getChipotlePublicKeyFallback()
|
|
74302
74775
|
);
|
|
74303
|
-
pkpEthAddress = (0,
|
|
74776
|
+
pkpEthAddress = (0, import_ethers15.computeAddress)(pkpPublicKey);
|
|
74304
74777
|
pkpCache.set(request.positionId, {
|
|
74305
74778
|
publicKey: pkpPublicKey,
|
|
74306
74779
|
ethAddress: pkpEthAddress,
|
|
@@ -74643,8 +75116,8 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
74643
75116
|
throw new Error(`Position not found: ${request.positionId}`);
|
|
74644
75117
|
}
|
|
74645
75118
|
const currentDebt = position.ucdDebt.toString();
|
|
74646
|
-
const ucdDebtHash = (0,
|
|
74647
|
-
const contractHash = (0,
|
|
75119
|
+
const ucdDebtHash = (0, import_ethers15.keccak256)(import_ethers15.AbiCoder.defaultAbiCoder().encode(["uint256"], [currentDebt]));
|
|
75120
|
+
const contractHash = (0, import_ethers15.keccak256)(import_ethers15.AbiCoder.defaultAbiCoder().encode(
|
|
74648
75121
|
["address", "address", "address", "address"],
|
|
74649
75122
|
[
|
|
74650
75123
|
positionManagerAddress,
|
|
@@ -74713,7 +75186,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
74713
75186
|
const coreAbi = [
|
|
74714
75187
|
"function getPositionDetails(bytes32) view returns (tuple(bytes32 positionId, bytes32 pkpId, uint256 ucdDebt, string vaultAddress, address borrower, uint40 createdAt, uint40 lastUpdated, uint16 selectedTerm, uint40 expiryAt, uint8 status, uint40 previousExpiryAt, uint16 totalTerm))"
|
|
74715
75188
|
];
|
|
74716
|
-
const positionCore = new
|
|
75189
|
+
const positionCore = new import_ethers15.Contract(
|
|
74717
75190
|
coreAddress,
|
|
74718
75191
|
coreAbi,
|
|
74719
75192
|
this.getSignerOrThrow().provider
|
|
@@ -74721,8 +75194,8 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
74721
75194
|
const currentPosition = await positionCore["getPositionDetails"](
|
|
74722
75195
|
positionIdBytes32
|
|
74723
75196
|
);
|
|
74724
|
-
const currentDebtHash = (0,
|
|
74725
|
-
|
|
75197
|
+
const currentDebtHash = (0, import_ethers15.keccak256)(
|
|
75198
|
+
import_ethers15.AbiCoder.defaultAbiCoder().encode(
|
|
74726
75199
|
["uint256"],
|
|
74727
75200
|
[currentPosition.ucdDebt]
|
|
74728
75201
|
)
|
|
@@ -74769,7 +75242,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
74769
75242
|
"function getCurrentQuantum() view returns (uint256)",
|
|
74770
75243
|
"function isQuantumValid(bytes32,uint256) view returns (bool)"
|
|
74771
75244
|
];
|
|
74772
|
-
const registry = new
|
|
75245
|
+
const registry = new import_ethers15.Contract(
|
|
74773
75246
|
registryAddress,
|
|
74774
75247
|
registryAbi,
|
|
74775
75248
|
this.getSignerOrThrow().provider
|
|
@@ -74885,7 +75358,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
74885
75358
|
});
|
|
74886
75359
|
}
|
|
74887
75360
|
const signatureHexMint = finalSignature.startsWith("0x") ? finalSignature : "0x" + finalSignature;
|
|
74888
|
-
const mintIface = new
|
|
75361
|
+
const mintIface = new import_ethers15.Interface(positionManagerAbi);
|
|
74889
75362
|
const mintCalldata = mintIface.encodeFunctionData("mintUCD", [
|
|
74890
75363
|
positionIdBytes32,
|
|
74891
75364
|
validationResponse.mintAmount,
|
|
@@ -74921,7 +75394,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
74921
75394
|
if (viewsAddress) {
|
|
74922
75395
|
let diagnosis = null;
|
|
74923
75396
|
try {
|
|
74924
|
-
const views = new
|
|
75397
|
+
const views = new import_ethers15.Contract(
|
|
74925
75398
|
viewsAddress,
|
|
74926
75399
|
[
|
|
74927
75400
|
"function diagnoseMintUCD(bytes32,uint256,uint256,uint256,uint256,uint256,bytes32,bytes32,bytes32,uint256,bytes) view returns (string)"
|
|
@@ -74979,7 +75452,7 @@ MintGuardFailed(${guardCode}): ${guardMeaning}
|
|
|
74979
75452
|
Lit mintAmount: ${validationResponse.mintAmount}
|
|
74980
75453
|
Lit mintFee: ${validationResponse.mintFee}
|
|
74981
75454
|
Lit newDebt: ${validationResponse.newDebt}
|
|
74982
|
-
Protocol maximum: ${(0,
|
|
75455
|
+
Protocol maximum: ${(0, import_ethers15.formatEther)(maxLoanValueWei)} UCD (fee-inclusive)`;
|
|
74983
75456
|
}
|
|
74984
75457
|
const mintDebtDiagnostics = selector === "0xb9d419a7" || // DebtUpdateVerificationFailed()
|
|
74985
75458
|
selector === "0xc7e20553" || // DebtUpdateVerificationFailedDetailed(...)
|
|
@@ -75050,7 +75523,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
75050
75523
|
if (receipt.logs && receipt.logs.length > 0) {
|
|
75051
75524
|
for (const receiptLog of receipt.logs) {
|
|
75052
75525
|
if (receiptLog.topics && receiptLog.topics[0] === "0x08c379a0") {
|
|
75053
|
-
const iface = new
|
|
75526
|
+
const iface = new import_ethers15.Interface([
|
|
75054
75527
|
"error Error(string)"
|
|
75055
75528
|
]);
|
|
75056
75529
|
const decoded = iface.decodeErrorResult("Error", receiptLog.data);
|
|
@@ -75067,7 +75540,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
75067
75540
|
const minimalAbi = [
|
|
75068
75541
|
"event UCDMintedWithAuthorization(bytes32 indexed positionId, address indexed borrower, uint256 mintAmount, uint256 mintFee, uint256 newDebt, uint256 newCollateral, uint256 btcPrice, uint256 quantumTimestamp, bytes32 authorizedSpendsHash)"
|
|
75069
75542
|
];
|
|
75070
|
-
const iface = new
|
|
75543
|
+
const iface = new import_ethers15.Interface(minimalAbi);
|
|
75071
75544
|
for (const receiptLog of receipt.logs) {
|
|
75072
75545
|
const parsed = (() => {
|
|
75073
75546
|
const logIface = iface;
|
|
@@ -75235,7 +75708,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
75235
75708
|
pkpNftAddress,
|
|
75236
75709
|
this.getChipotlePublicKeyFallback()
|
|
75237
75710
|
);
|
|
75238
|
-
const pkpEthAddress = (0,
|
|
75711
|
+
const pkpEthAddress = (0, import_ethers15.computeAddress)(pkpPublicKey);
|
|
75239
75712
|
pkpData = {
|
|
75240
75713
|
publicKey: pkpPublicKey,
|
|
75241
75714
|
ethAddress: pkpEthAddress,
|
|
@@ -75633,7 +76106,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
75633
76106
|
}
|
|
75634
76107
|
const loanOpsForUcd = loanOpsForUcdResult.value;
|
|
75635
76108
|
const ucdTokenAddress = await loanOpsForUcd.ucdToken();
|
|
75636
|
-
const ucdToken = new
|
|
76109
|
+
const ucdToken = new import_ethers15.Contract(
|
|
75637
76110
|
ucdTokenAddress,
|
|
75638
76111
|
[
|
|
75639
76112
|
"function balanceOf(address) view returns (uint256)",
|
|
@@ -75649,9 +76122,9 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
75649
76122
|
if (ucdBalance < debtWei) {
|
|
75650
76123
|
return {
|
|
75651
76124
|
success: false,
|
|
75652
|
-
error: `Insufficient UCD balance for liquidation: ${(0,
|
|
76125
|
+
error: `Insufficient UCD balance for liquidation: ${(0, import_ethers15.formatEther)(
|
|
75653
76126
|
ucdBalance
|
|
75654
|
-
)} UCD (need ${(0,
|
|
76127
|
+
)} UCD (need ${(0, import_ethers15.formatEther)(debtWei)} UCD)`,
|
|
75655
76128
|
positionId: request.positionId,
|
|
75656
76129
|
wasLiquidated: false
|
|
75657
76130
|
};
|
|
@@ -75660,7 +76133,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
75660
76133
|
if (request.skipUcdApproval) {
|
|
75661
76134
|
return {
|
|
75662
76135
|
success: false,
|
|
75663
|
-
error: `Insufficient UCD allowance for UCDController: need at least ${(0,
|
|
76136
|
+
error: `Insufficient UCD allowance for UCDController: need at least ${(0, import_ethers15.formatEther)(
|
|
75664
76137
|
debtWei
|
|
75665
76138
|
)} UCD, or omit skipUcdApproval to let the SDK submit approve`,
|
|
75666
76139
|
positionId: request.positionId,
|
|
@@ -76190,7 +76663,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
76190
76663
|
if (typeof signatureBytes === "string" && signatureBytes.startsWith("{")) {
|
|
76191
76664
|
try {
|
|
76192
76665
|
const parsed = JSON.parse(signatureBytes);
|
|
76193
|
-
signatureBytes = parsed.signature ?? (parsed.r && parsed.s && parsed.v ?
|
|
76666
|
+
signatureBytes = parsed.signature ?? (parsed.r && parsed.s && parsed.v ? import_ethers15.Signature.from({
|
|
76194
76667
|
r: parsed.r,
|
|
76195
76668
|
s: parsed.s,
|
|
76196
76669
|
v: parsed.v
|
|
@@ -76201,7 +76674,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
76201
76674
|
if (!signatureBytes.startsWith("0x")) {
|
|
76202
76675
|
signatureBytes = "0x" + signatureBytes;
|
|
76203
76676
|
}
|
|
76204
|
-
const extendIface = new
|
|
76677
|
+
const extendIface = new import_ethers15.Interface([
|
|
76205
76678
|
"function extendPosition(bytes32 positionId, uint256 selectedTerm, uint256 quantumTimestamp, uint256 btcPrice, uint256 availableBTCBalance, uint256 proRataRenewalFee, bytes calldata extensionValidatorSignature) external returns (bool)"
|
|
76206
76679
|
]);
|
|
76207
76680
|
const extendCalldata = extendIface.encodeFunctionData("extendPosition", [
|
|
@@ -76756,7 +77229,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
76756
77229
|
` Converting payment amount: ${request.paymentAmount} (type: ${typeof request.paymentAmount})`
|
|
76757
77230
|
);
|
|
76758
77231
|
}
|
|
76759
|
-
const paymentAmountWei = (0,
|
|
77232
|
+
const paymentAmountWei = (0, import_ethers15.parseEther)(
|
|
76760
77233
|
request.paymentAmount.toString()
|
|
76761
77234
|
);
|
|
76762
77235
|
if (this.config.debug) {
|
|
@@ -76823,7 +77296,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
76823
77296
|
};
|
|
76824
77297
|
}
|
|
76825
77298
|
const ucdTokenAddress = await loanOps.ucdToken();
|
|
76826
|
-
const ucdToken = new
|
|
77299
|
+
const ucdToken = new import_ethers15.Contract(
|
|
76827
77300
|
ucdTokenAddress,
|
|
76828
77301
|
[
|
|
76829
77302
|
"function balanceOf(address) view returns (uint256)",
|
|
@@ -76847,14 +77320,14 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
76847
77320
|
]);
|
|
76848
77321
|
if (this.config.debug) {
|
|
76849
77322
|
log.info(` UCD funds source: ${fundsSource}${isSelfRepay ? " (self)" : " (borrower; agent submitting)"}`);
|
|
76850
|
-
log.info(` UCD Balance: ${(0,
|
|
76851
|
-
log.info(` UCD Allowance: ${(0,
|
|
77323
|
+
log.info(` UCD Balance: ${(0, import_ethers15.formatEther)(balance)} UCD`);
|
|
77324
|
+
log.info(` UCD Allowance: ${(0, import_ethers15.formatEther)(allowance)} UCD`);
|
|
76852
77325
|
log.info(` Required: ${request.paymentAmount} UCD`);
|
|
76853
77326
|
}
|
|
76854
77327
|
if (balance < paymentAmountWei) {
|
|
76855
77328
|
return {
|
|
76856
77329
|
success: false,
|
|
76857
|
-
error: `Insufficient UCD balance: ${(0,
|
|
77330
|
+
error: `Insufficient UCD balance: ${(0, import_ethers15.formatEther)(
|
|
76858
77331
|
balance
|
|
76859
77332
|
)} UCD (need ${request.paymentAmount} UCD)${isSelfRepay ? "" : ` \u2014 borrower ${fundsSource} lacks funds`}`
|
|
76860
77333
|
};
|
|
@@ -76863,7 +77336,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
76863
77336
|
if (!isSelfRepay) {
|
|
76864
77337
|
return {
|
|
76865
77338
|
success: false,
|
|
76866
|
-
error: `Borrower ${fundsSource} has insufficient UCD allowance to PositionManager (${(0,
|
|
77339
|
+
error: `Borrower ${fundsSource} has insufficient UCD allowance to PositionManager (${(0, import_ethers15.formatEther)(allowance)} UCD, need ${request.paymentAmount}). The borrower must approve PositionManager before a delegated agent can repay.`
|
|
76867
77340
|
};
|
|
76868
77341
|
}
|
|
76869
77342
|
if (this.config.debug) {
|
|
@@ -77132,7 +77605,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
77132
77605
|
const paymentSigner = this.getSignerOrThrow();
|
|
77133
77606
|
const paymentFrom = await paymentSigner.getAddress();
|
|
77134
77607
|
const paymentProvider = contractManager.getProvider();
|
|
77135
|
-
const paymentIface = new
|
|
77608
|
+
const paymentIface = new import_ethers15.Interface([
|
|
77136
77609
|
"function makePayment(bytes32 positionId, uint256 paymentAmount, uint256 quantumTimestamp, uint256 btcPrice, bytes calldata paymentValidatorSignature) external returns (bool)"
|
|
77137
77610
|
]);
|
|
77138
77611
|
const paymentCalldata = paymentIface.encodeFunctionData("makePayment", [
|
|
@@ -77481,7 +77954,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
77481
77954
|
const pkpId = position.pkpId;
|
|
77482
77955
|
if (litValidatorAddr && pkpId) {
|
|
77483
77956
|
try {
|
|
77484
|
-
const litValidator = new
|
|
77957
|
+
const litValidator = new import_ethers15.Contract(
|
|
77485
77958
|
litValidatorAddr,
|
|
77486
77959
|
["function pkpOwners(bytes32) view returns (address)"],
|
|
77487
77960
|
this.getProviderOrThrow()
|
|
@@ -77489,7 +77962,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
77489
77962
|
const owner = await litValidator.pkpOwners(
|
|
77490
77963
|
pkpId
|
|
77491
77964
|
);
|
|
77492
|
-
if (owner && owner !==
|
|
77965
|
+
if (owner && owner !== import_ethers15.ZeroAddress) {
|
|
77493
77966
|
controller = owner;
|
|
77494
77967
|
}
|
|
77495
77968
|
} catch {
|
|
@@ -77541,7 +78014,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
77541
78014
|
pkpNftAddress,
|
|
77542
78015
|
this.getChipotlePublicKeyFallback()
|
|
77543
78016
|
);
|
|
77544
|
-
pkpEthAddress = (0,
|
|
78017
|
+
pkpEthAddress = (0, import_ethers15.computeAddress)(pkpPublicKey);
|
|
77545
78018
|
pkpCache.set(positionId, {
|
|
77546
78019
|
publicKey: pkpPublicKey,
|
|
77547
78020
|
ethAddress: pkpEthAddress,
|
|
@@ -77914,7 +78387,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
77914
78387
|
utxoVout: withdrawalParams.utxoVout
|
|
77915
78388
|
});
|
|
77916
78389
|
}
|
|
77917
|
-
const withdrawIface = new
|
|
78390
|
+
const withdrawIface = new import_ethers15.Interface([
|
|
77918
78391
|
"function withdrawBTC((bytes32 positionId, bytes32 actionHash, bytes32 authorizedSpendsHash, bytes32 ucdDebtHash, bytes32 contractBundleHash, string withdrawalAddress, uint256 totalDeduction, uint256 newCollateral, uint256 quantumTimestamp, uint256 btcPrice, string utxoTxid, uint32 utxoVout) params, bytes withdrawalValidatorSignature, bytes btcSpendAuthSignature) external returns (bool)"
|
|
77919
78392
|
]);
|
|
77920
78393
|
const withdrawCalldata = withdrawIface.encodeFunctionData("withdrawBTC", [
|
|
@@ -78145,7 +78618,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
78145
78618
|
}
|
|
78146
78619
|
const pkpId = positionDetails.pkpId;
|
|
78147
78620
|
const vaultAddress = positionDetails.vaultAddress;
|
|
78148
|
-
if (!pkpId || pkpId ===
|
|
78621
|
+
if (!pkpId || pkpId === import_ethers15.ZeroHash) {
|
|
78149
78622
|
return { success: false, error: "Position has no PKP" };
|
|
78150
78623
|
}
|
|
78151
78624
|
if (!vaultAddress) {
|
|
@@ -78165,7 +78638,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
78165
78638
|
if (!publicKey) {
|
|
78166
78639
|
return { success: false, error: "Failed to resolve PKP public key" };
|
|
78167
78640
|
}
|
|
78168
|
-
const chipotlePkpAddress = (0,
|
|
78641
|
+
const chipotlePkpAddress = (0, import_ethers15.computeAddress)(publicKey);
|
|
78169
78642
|
const chainName = LIT_ACTION_CHAIN_NAMES[chainId];
|
|
78170
78643
|
if (!chainName) {
|
|
78171
78644
|
return {
|
|
@@ -78549,7 +79022,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
78549
79022
|
const btcSpendAuthorizerAbi = [
|
|
78550
79023
|
"function getAuthorizedSpends(bytes32) view returns (tuple(string txid, uint32 vout, uint256 satoshis, string targetAddress, uint256 targetAmount, uint256 authorizedAt)[])"
|
|
78551
79024
|
];
|
|
78552
|
-
const btcSpendAuthorizer = new
|
|
79025
|
+
const btcSpendAuthorizer = new import_ethers15.Contract(
|
|
78553
79026
|
btcSpendAuthorizerAddress,
|
|
78554
79027
|
btcSpendAuthorizerAbi,
|
|
78555
79028
|
this.getProviderOrThrow()
|
|
@@ -78635,7 +79108,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
78635
79108
|
const abi = [
|
|
78636
79109
|
"function getAuthorizedSpends(bytes32) view returns (tuple(string txid, uint32 vout, uint256 satoshis, string targetAddress, uint256 targetAmount, uint256 authorizedAt)[])"
|
|
78637
79110
|
];
|
|
78638
|
-
const contract = new
|
|
79111
|
+
const contract = new import_ethers15.Contract(
|
|
78639
79112
|
btcSpendAuthorizerAddress,
|
|
78640
79113
|
abi,
|
|
78641
79114
|
this.getProviderOrThrow()
|
|
@@ -78649,7 +79122,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
78649
79122
|
targetAddress: spend.targetAddress,
|
|
78650
79123
|
targetAmount: Number(spend.targetAmount),
|
|
78651
79124
|
authorizedAt: Number(spend.authorizedAt),
|
|
78652
|
-
utxoKey: (0,
|
|
79125
|
+
utxoKey: (0, import_ethers15.solidityPackedKeccak256)(
|
|
78653
79126
|
["string", "uint32"],
|
|
78654
79127
|
[spend.txid, Number(spend.vout)]
|
|
78655
79128
|
)
|
|
@@ -78855,7 +79328,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
78855
79328
|
error: attRes.error ?? attRes.reason ?? `LIT recovery attestation rejected${attRes.failedStep ? ` at step ${attRes.failedStep}` : ""}`
|
|
78856
79329
|
};
|
|
78857
79330
|
}
|
|
78858
|
-
const btcSpendAuthorizer = new
|
|
79331
|
+
const btcSpendAuthorizer = new import_ethers15.Contract(
|
|
78859
79332
|
btcSpendAuthorizerAddress,
|
|
78860
79333
|
[
|
|
78861
79334
|
"function cancelStaleSpendWithProof(bytes32 positionId, bytes32 utxoKey, uint256 authorizedAt, string calldata invalidatorTxid, uint256 attestationTimestamp, bytes calldata litSignature) external"
|
|
@@ -78952,7 +79425,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
78952
79425
|
const positionDetails = await this.getPositionDetailsView(
|
|
78953
79426
|
params.positionId
|
|
78954
79427
|
);
|
|
78955
|
-
if (!positionDetails?.pkpId || positionDetails.pkpId ===
|
|
79428
|
+
if (!positionDetails?.pkpId || positionDetails.pkpId === import_ethers15.ZeroHash) {
|
|
78956
79429
|
return { success: false, error: "Position has no PKP" };
|
|
78957
79430
|
}
|
|
78958
79431
|
const pkpCache = this.cacheManager.getCache("pkp-data", {
|
|
@@ -78969,7 +79442,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
78969
79442
|
if (!publicKey) {
|
|
78970
79443
|
return { success: false, error: "Failed to resolve PKP public key" };
|
|
78971
79444
|
}
|
|
78972
|
-
const chipotlePkpAddress = (0,
|
|
79445
|
+
const chipotlePkpAddress = (0, import_ethers15.computeAddress)(publicKey);
|
|
78973
79446
|
const dc = this.config.contractAddresses || {};
|
|
78974
79447
|
const chainName = chainId === 1 ? "ethereum" : chainId === 11155111 ? "sepolia" : chainId === 1337 || chainId === 31337 ? "hardhat" : void 0;
|
|
78975
79448
|
if (!chainName) {
|
|
@@ -79669,7 +80142,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
79669
80142
|
*
|
|
79670
80143
|
* Deliberately omits `minWithdrawRatioBps` — see {@link readLoanGrant}.
|
|
79671
80144
|
*/
|
|
79672
|
-
static LOAN_GRANT_PREFIX_IFACE = new
|
|
80145
|
+
static LOAN_GRANT_PREFIX_IFACE = new import_ethers15.Interface([
|
|
79673
80146
|
"function getLoanGrant(bytes32 positionId) view returns (address borrower, uint32 scopeBits, uint32 minCollateralRatioBps)"
|
|
79674
80147
|
]);
|
|
79675
80148
|
/**
|
|
@@ -79690,9 +80163,9 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
79690
80163
|
to: registryAddress,
|
|
79691
80164
|
data: iface.encodeFunctionData("getLoanGrant", [pid])
|
|
79692
80165
|
});
|
|
79693
|
-
if ((0,
|
|
80166
|
+
if ((0, import_ethers15.getBytes)(data).length < 96) {
|
|
79694
80167
|
throw new SDKError({
|
|
79695
|
-
message: `AgentDelegationRegistry at ${registryAddress} returned ${(0,
|
|
80168
|
+
message: `AgentDelegationRegistry at ${registryAddress} returned ${(0, import_ethers15.getBytes)(data).length} bytes for getLoanGrant(bytes32) \u2014 expected at least 96. Wrong address, or a registry version this SDK does not support.`,
|
|
79696
80169
|
category: "CONTRACT",
|
|
79697
80170
|
severity: "HIGH"
|
|
79698
80171
|
/* HIGH */
|
|
@@ -79702,10 +80175,10 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
79702
80175
|
"getLoanGrant",
|
|
79703
80176
|
data
|
|
79704
80177
|
);
|
|
79705
|
-
const raw = (0,
|
|
80178
|
+
const raw = (0, import_ethers15.getBytes)(data);
|
|
79706
80179
|
const withdrawScopeSupported = raw.length >= 128;
|
|
79707
80180
|
const minWithdrawRatioBps = withdrawScopeSupported ? Number(
|
|
79708
|
-
|
|
80181
|
+
import_ethers15.AbiCoder.defaultAbiCoder().decode(["uint32"], raw.slice(96, 128))[0]
|
|
79709
80182
|
) : 0;
|
|
79710
80183
|
return {
|
|
79711
80184
|
borrower,
|
|
@@ -79870,7 +80343,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
79870
80343
|
getPositionDelegate(pid, signer, pdrAddr),
|
|
79871
80344
|
registry.agentOf(user).then((a) => a.agent)
|
|
79872
80345
|
]);
|
|
79873
|
-
if (currentDelegate !==
|
|
80346
|
+
if (currentDelegate !== import_ethers15.ZeroAddress && currentDelegate.toLowerCase() === userAgent.toLowerCase()) {
|
|
79874
80347
|
const clearTx = await setPositionDelegate(
|
|
79875
80348
|
pid,
|
|
79876
80349
|
"0x0000000000000000000000000000000000000000",
|
|
@@ -80267,7 +80740,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
80267
80740
|
const maxUcdWhole = BigInt(result[3].toString());
|
|
80268
80741
|
return success({
|
|
80269
80742
|
liquidationThreshold: result[0].toString(),
|
|
80270
|
-
minimumLoanValueUcd: (0,
|
|
80743
|
+
minimumLoanValueUcd: (0, import_ethers15.formatUnits)(result[2], 18),
|
|
80271
80744
|
minimumLoanValueWei: result[2].toString(),
|
|
80272
80745
|
maxSingleLoanValueUcd: maxUcdWhole.toString(),
|
|
80273
80746
|
maxSingleLoanValueWei: (maxUcdWhole * 10n ** 18n).toString()
|
|
@@ -80304,7 +80777,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
80304
80777
|
const balanceWei = await provider.getBalance(address);
|
|
80305
80778
|
return success({
|
|
80306
80779
|
balanceWei: balanceWei.toString(),
|
|
80307
|
-
balanceEth: (0,
|
|
80780
|
+
balanceEth: (0, import_ethers15.formatEther)(balanceWei)
|
|
80308
80781
|
});
|
|
80309
80782
|
} catch (error) {
|
|
80310
80783
|
return failure(new SDKError({
|
|
@@ -80713,7 +81186,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
80713
81186
|
* Convert decimal position ID to bytes32 format
|
|
80714
81187
|
*/
|
|
80715
81188
|
toBytes32(value) {
|
|
80716
|
-
return (0,
|
|
81189
|
+
return (0, import_ethers15.zeroPadValue)((0, import_ethers15.toBeHex)(BigInt(value)), 32);
|
|
80717
81190
|
}
|
|
80718
81191
|
/**
|
|
80719
81192
|
* Check if an error indicates a technical failure vs business logic rejection
|
|
@@ -80754,7 +81227,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
80754
81227
|
const coreModuleAbi = [
|
|
80755
81228
|
"function getPositionDetails(bytes32) view returns (tuple(bytes32 positionId, bytes32 pkpId, uint256 ucdDebt, string vaultAddress, address borrower, uint40 createdAt, uint40 lastUpdated, uint16 selectedTerm, uint40 expiryAt, uint8 status, uint40 previousExpiryAt, uint16 totalTerm))"
|
|
80756
81229
|
];
|
|
80757
|
-
const coreModule = new
|
|
81230
|
+
const coreModule = new import_ethers15.Contract(
|
|
80758
81231
|
coreModuleAddress,
|
|
80759
81232
|
coreModuleAbi,
|
|
80760
81233
|
provider
|
|
@@ -80821,7 +81294,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
80821
81294
|
const corePositionAbi = [
|
|
80822
81295
|
"function getPositionDetails(bytes32) view returns (tuple(bytes32 positionId, bytes32 pkpId, uint256 ucdDebt, string vaultAddress, address borrower, uint40 createdAt, uint40 lastUpdated, uint16 selectedTerm, uint40 expiryAt, uint8 status, uint40 previousExpiryAt, uint16 totalTerm))"
|
|
80823
81296
|
];
|
|
80824
|
-
const corePositionContract = new
|
|
81297
|
+
const corePositionContract = new import_ethers15.Contract(
|
|
80825
81298
|
coreAddress,
|
|
80826
81299
|
corePositionAbi,
|
|
80827
81300
|
provider
|
|
@@ -80832,7 +81305,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
80832
81305
|
positionIdBytes32
|
|
80833
81306
|
);
|
|
80834
81307
|
const positionIdFromCore = corePosition?.positionId || corePosition?.[0] || null;
|
|
80835
|
-
if (positionIdFromCore && positionIdFromCore !==
|
|
81308
|
+
if (positionIdFromCore && positionIdFromCore !== import_ethers15.ZeroHash && positionIdFromCore !== "0x0000000000000000000000000000000000000000000000000000000000000000") {
|
|
80836
81309
|
if (this.config.debug) {
|
|
80837
81310
|
log.info("Position exists in core contract", {
|
|
80838
81311
|
positionId,
|
|
@@ -80900,7 +81373,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
80900
81373
|
throw new Error("loanOperationsManager address not configured");
|
|
80901
81374
|
}
|
|
80902
81375
|
const runner = this.config.contractSigner || this.getProviderOrThrow();
|
|
80903
|
-
const contract = new
|
|
81376
|
+
const contract = new import_ethers15.Contract(
|
|
80904
81377
|
addr.loanOperationsManager,
|
|
80905
81378
|
[
|
|
80906
81379
|
"function getProtocolConfig() external view returns (uint256 liquidationThreshold, uint256 minimumLoanValueUcd, uint256 minimumLoanValueWei, uint256 maxSingleLoanValueUcd)"
|
|
@@ -80913,7 +81386,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
80913
81386
|
const maxUcdWhole = BigInt(result[3].toString());
|
|
80914
81387
|
return {
|
|
80915
81388
|
liquidationThreshold: result[0].toString(),
|
|
80916
|
-
minimumLoanValueUcd: (0,
|
|
81389
|
+
minimumLoanValueUcd: (0, import_ethers15.formatUnits)(result[2], 18),
|
|
80917
81390
|
minimumLoanValueWei: result[2].toString(),
|
|
80918
81391
|
maxSingleLoanValueUcd: maxUcdWhole.toString(),
|
|
80919
81392
|
maxSingleLoanValueWei: (maxUcdWhole * 10n ** 18n).toString()
|
|
@@ -80931,8 +81404,8 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
80931
81404
|
const MIN_REVEAL_DELAY = 60;
|
|
80932
81405
|
const MAX_RANDOM_DELAY = 240;
|
|
80933
81406
|
const entropyInput = positionId + quantumTimestamp.toString();
|
|
80934
|
-
const hash = (0,
|
|
80935
|
-
(0,
|
|
81407
|
+
const hash = (0, import_ethers15.keccak256)(
|
|
81408
|
+
(0, import_ethers15.toUtf8Bytes)(entropyInput)
|
|
80936
81409
|
);
|
|
80937
81410
|
const randomValue = BigInt(hash);
|
|
80938
81411
|
const randomDelay = Number(randomValue % BigInt(MAX_RANDOM_DELAY));
|
|
@@ -80957,12 +81430,12 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
80957
81430
|
const rawPositionId = /^0x/i.test(params.positionId.trim()) ? params.positionId.trim().slice(2) : params.positionId.trim();
|
|
80958
81431
|
const canonicalPositionId = "0x" + rawPositionId.padStart(64, "0").toLowerCase();
|
|
80959
81432
|
const intentTimestamp = Math.floor(Date.now() / 1e3);
|
|
80960
|
-
const intentActionHash = (0,
|
|
80961
|
-
const intentHash = (0,
|
|
81433
|
+
const intentActionHash = (0, import_ethers15.keccak256)((0, import_ethers15.toUtf8Bytes)("liquidate-position"));
|
|
81434
|
+
const intentHash = (0, import_ethers15.solidityPackedKeccak256)(
|
|
80962
81435
|
["bytes32", "uint256", "uint256", "address", "bytes32"],
|
|
80963
81436
|
[canonicalPositionId, intentTimestamp, chainId, intentSigner, intentActionHash]
|
|
80964
81437
|
);
|
|
80965
|
-
const intentSignature = await signer.signMessage((0,
|
|
81438
|
+
const intentSignature = await signer.signMessage((0, import_ethers15.getBytes)(intentHash));
|
|
80966
81439
|
const response = await fetch(endpoint, {
|
|
80967
81440
|
method: "POST",
|
|
80968
81441
|
headers: { "Content-Type": "application/json" },
|
|
@@ -81014,7 +81487,7 @@ Message: ${causeMessage}${quantumContext}${loanCapDiagnostics}${mintDebtDiagnost
|
|
|
81014
81487
|
const vrfSeedRaw = await lmResult.value["vrfSeeds"](positionId);
|
|
81015
81488
|
const vrfSeed = BigInt(vrfSeedRaw.toString());
|
|
81016
81489
|
if (vrfSeed !== 0n) {
|
|
81017
|
-
const finalEntropy = (0,
|
|
81490
|
+
const finalEntropy = (0, import_ethers15.solidityPackedKeccak256)(
|
|
81018
81491
|
["uint256", "uint256", "bytes32"],
|
|
81019
81492
|
[vrfSeed, BigInt(quantumTimestamp.toString()), positionId]
|
|
81020
81493
|
);
|
|
@@ -81222,15 +81695,15 @@ var SUPPORTED_STABLECOINS = `
|
|
|
81222
81695
|
}`;
|
|
81223
81696
|
|
|
81224
81697
|
// src/boundary/upstream/real/psm-calls.ts
|
|
81225
|
-
var
|
|
81698
|
+
var import_ethers44 = require("ethers");
|
|
81226
81699
|
|
|
81227
81700
|
// node_modules/@gvnrdao/dh-sdk/dist/sign-guard.mjs
|
|
81228
|
-
var import_ethers37 = require("ethers");
|
|
81229
81701
|
var import_ethers38 = require("ethers");
|
|
81230
81702
|
var import_ethers39 = require("ethers");
|
|
81231
81703
|
var import_ethers40 = require("ethers");
|
|
81232
81704
|
var import_ethers41 = require("ethers");
|
|
81233
81705
|
var import_ethers42 = require("ethers");
|
|
81706
|
+
var import_ethers43 = require("ethers");
|
|
81234
81707
|
var TxValidationError3 = class extends Error {
|
|
81235
81708
|
/**
|
|
81236
81709
|
* @param subject What is being refused. Defaults to the server-returned transaction the
|
|
@@ -81277,7 +81750,7 @@ var SIGNABLE_FUNCTIONS3 = [
|
|
|
81277
81750
|
// this too is client-only and never module-whitelisted.
|
|
81278
81751
|
"function addAddress(string btcAddress) external"
|
|
81279
81752
|
];
|
|
81280
|
-
var IFACE3 = new
|
|
81753
|
+
var IFACE3 = new import_ethers38.ethers.Interface(SIGNABLE_FUNCTIONS3);
|
|
81281
81754
|
function encodeSignable3(fn, args) {
|
|
81282
81755
|
return IFACE3.encodeFunctionData(fn, args);
|
|
81283
81756
|
}
|
|
@@ -81307,10 +81780,10 @@ var DEFAULT_FEE_CEILING2 = {
|
|
|
81307
81780
|
maxTxFeeWei: DEFAULT_MAX_TX_FEE_WEI2
|
|
81308
81781
|
};
|
|
81309
81782
|
function fmtEth2(wei) {
|
|
81310
|
-
return `${
|
|
81783
|
+
return `${import_ethers39.ethers.formatEther(wei)} ETH`;
|
|
81311
81784
|
}
|
|
81312
81785
|
function fmtGwei2(wei) {
|
|
81313
|
-
return `${
|
|
81786
|
+
return `${import_ethers39.ethers.formatUnits(wei, "gwei")} gwei`;
|
|
81314
81787
|
}
|
|
81315
81788
|
function worstCaseFeeWei2(gasLimit, maxFeePerGas) {
|
|
81316
81789
|
if (gasLimit == null || maxFeePerGas == null)
|
|
@@ -81337,7 +81810,7 @@ function eqAddr3(a, b) {
|
|
|
81337
81810
|
if (!a || !b)
|
|
81338
81811
|
return false;
|
|
81339
81812
|
try {
|
|
81340
|
-
return
|
|
81813
|
+
return import_ethers40.ethers.getAddress(a) === import_ethers40.ethers.getAddress(b);
|
|
81341
81814
|
} catch {
|
|
81342
81815
|
return false;
|
|
81343
81816
|
}
|
|
@@ -81403,7 +81876,7 @@ function readValue3(tx2) {
|
|
|
81403
81876
|
}
|
|
81404
81877
|
function normalizePositionId3(id) {
|
|
81405
81878
|
const hex = id.startsWith("0x") ? id : `0x${id}`;
|
|
81406
|
-
return
|
|
81879
|
+
return import_ethers40.ethers.zeroPadValue(hex, 32).toLowerCase();
|
|
81407
81880
|
}
|
|
81408
81881
|
function requirePositionId2(actual, expected) {
|
|
81409
81882
|
const txPositionId = String(actual).toLowerCase();
|
|
@@ -81698,18 +82171,18 @@ function buildPsmRedeemTx3(p) {
|
|
|
81698
82171
|
var PSM_READS_ABI2 = ["function supportedStablecoins(address) view returns (bool)"];
|
|
81699
82172
|
var ERC20_READS_ABI2 = ["function allowance(address owner, address spender) view returns (uint256)"];
|
|
81700
82173
|
function psmExchangeReadsFromProvider2(provider, psmAddress) {
|
|
81701
|
-
const psm = new
|
|
82174
|
+
const psm = new import_ethers43.ethers.Contract(psmAddress, PSM_READS_ABI2, provider);
|
|
81702
82175
|
return {
|
|
81703
82176
|
isStablecoinSupported: async (stablecoin) => await psm.getFunction("supportedStablecoins")(stablecoin),
|
|
81704
|
-
allowance: async (token, owner, spender) => await new
|
|
82177
|
+
allowance: async (token, owner, spender) => await new import_ethers43.ethers.Contract(token, ERC20_READS_ABI2, provider).getFunction("allowance")(owner, spender)
|
|
81705
82178
|
};
|
|
81706
82179
|
}
|
|
81707
82180
|
var refuse2 = (direction, msg) => new TxValidationError3(msg, `PSM ${direction}`);
|
|
81708
82181
|
function requireAddress2(direction, label, value) {
|
|
81709
|
-
if (!value || !
|
|
82182
|
+
if (!value || !import_ethers43.ethers.isAddress(value)) {
|
|
81710
82183
|
throw refuse2(direction, `${label} address is missing or invalid (${String(value)})`);
|
|
81711
82184
|
}
|
|
81712
|
-
return
|
|
82185
|
+
return import_ethers43.ethers.getAddress(value);
|
|
81713
82186
|
}
|
|
81714
82187
|
async function planPsmExchange2(params) {
|
|
81715
82188
|
const { direction, amountIn, minOut, vctx, reads } = params;
|
|
@@ -81836,8 +82309,8 @@ var PsmCalls = class {
|
|
|
81836
82309
|
constructor(deps) {
|
|
81837
82310
|
this.deps = deps;
|
|
81838
82311
|
const abi = [...PSM_VIEW_FRAGMENTS, ...PSM_ERROR_FRAGMENTS];
|
|
81839
|
-
this.iface = new
|
|
81840
|
-
this.psm = new
|
|
82312
|
+
this.iface = new import_ethers44.ethers.Interface(abi);
|
|
82313
|
+
this.psm = new import_ethers44.ethers.Contract(deps.psmAddress, abi, deps.provider);
|
|
81841
82314
|
}
|
|
81842
82315
|
psm;
|
|
81843
82316
|
iface;
|
|
@@ -81866,8 +82339,8 @@ var PsmCalls = class {
|
|
|
81866
82339
|
});
|
|
81867
82340
|
}
|
|
81868
82341
|
return this.call(async () => {
|
|
81869
|
-
const ucd = new
|
|
81870
|
-
const stable = new
|
|
82342
|
+
const ucd = new import_ethers44.ethers.Contract(ucdToken, ERC20_FRAGMENTS, this.deps.provider);
|
|
82343
|
+
const stable = new import_ethers44.ethers.Contract(this.deps.stablecoinAddress, ERC20_FRAGMENTS, this.deps.provider);
|
|
81871
82344
|
const [ucdWei, stablecoinUnits] = await Promise.all([ucd["balanceOf"](holder), stable["balanceOf"](holder)]);
|
|
81872
82345
|
return { ucdWei: ucdWei.toString(), stablecoinUnits: stablecoinUnits.toString() };
|
|
81873
82346
|
});
|
|
@@ -81985,7 +82458,7 @@ var PsmCalls = class {
|
|
|
81985
82458
|
};
|
|
81986
82459
|
|
|
81987
82460
|
// src/boundary/upstream/real/session.ts
|
|
81988
|
-
var
|
|
82461
|
+
var import_ethers45 = require("ethers");
|
|
81989
82462
|
var REFRESH_LEEWAY_SEC = 30;
|
|
81990
82463
|
var LOGIN_TYPES_WITH_AUDIENCE3 = {
|
|
81991
82464
|
DiamondHands: [
|
|
@@ -82033,7 +82506,7 @@ var LitOpsSession = class {
|
|
|
82033
82506
|
const message = {
|
|
82034
82507
|
address: this.wallet.address,
|
|
82035
82508
|
issuedAt: Math.floor(Date.now() / 1e3),
|
|
82036
|
-
nonce: "0x" + Buffer.from(
|
|
82509
|
+
nonce: "0x" + Buffer.from(import_ethers45.ethers.randomBytes(32)).toString("hex"),
|
|
82037
82510
|
audience: this.serviceEndpoint
|
|
82038
82511
|
};
|
|
82039
82512
|
const signature = await this.wallet.signTypedData(
|
|
@@ -82075,7 +82548,7 @@ function decodeJwtExp(token) {
|
|
|
82075
82548
|
}
|
|
82076
82549
|
|
|
82077
82550
|
// src/boundary/upstream/real/write-ops.ts
|
|
82078
|
-
var
|
|
82551
|
+
var import_ethers47 = require("ethers");
|
|
82079
82552
|
|
|
82080
82553
|
// src/signer/types.ts
|
|
82081
82554
|
var OperationDeclined = class extends Error {
|
|
@@ -82085,7 +82558,7 @@ var OperationDeclined = class extends Error {
|
|
|
82085
82558
|
init_tx_validator();
|
|
82086
82559
|
|
|
82087
82560
|
// src/boundary/upstream/shared/external-bridge/page-crypto.ts
|
|
82088
|
-
var
|
|
82561
|
+
var import_ethers46 = require("ethers");
|
|
82089
82562
|
var PERSONAL_SIGN_LAYOUTS = {
|
|
82090
82563
|
"dh-op-envelope-v1": {
|
|
82091
82564
|
types: ["bytes32", "uint256", "uint256", "uint256", "bytes32"],
|
|
@@ -82106,9 +82579,9 @@ function hashForLayout(layout, fields) {
|
|
|
82106
82579
|
const values = def.fieldOrder.map((name) => {
|
|
82107
82580
|
const raw = fields[name];
|
|
82108
82581
|
if (raw === void 0) throw new Error(`page-crypto: layout "${layout}" missing field "${name}"`);
|
|
82109
|
-
return hashUtf8.has(name) ?
|
|
82582
|
+
return hashUtf8.has(name) ? import_ethers46.ethers.keccak256(import_ethers46.ethers.toUtf8Bytes(raw)) : raw;
|
|
82110
82583
|
});
|
|
82111
|
-
return
|
|
82584
|
+
return import_ethers46.ethers.solidityPackedKeccak256(def.types, values);
|
|
82112
82585
|
}
|
|
82113
82586
|
var PAGE_CRYPTO_JS = `"use strict";
|
|
82114
82587
|
(function () {
|
|
@@ -82351,7 +82824,7 @@ function mcpExpected(leg) {
|
|
|
82351
82824
|
}
|
|
82352
82825
|
var OP_LAYOUT = "dh-op-envelope-v1";
|
|
82353
82826
|
function randomNonceHex() {
|
|
82354
|
-
return "0x" + Buffer.from(
|
|
82827
|
+
return "0x" + Buffer.from(import_ethers47.ethers.randomBytes(16)).toString("hex");
|
|
82355
82828
|
}
|
|
82356
82829
|
async function postJson(url2, body, headers) {
|
|
82357
82830
|
const res = await fetch(url2, {
|
|
@@ -82412,7 +82885,7 @@ function buildWriteOps(deps) {
|
|
|
82412
82885
|
return {
|
|
82413
82886
|
to: String(tx2["to"] ?? ""),
|
|
82414
82887
|
data: String(tx2["data"] ?? "0x"),
|
|
82415
|
-
value: tx2["value"] != null ?
|
|
82888
|
+
value: tx2["value"] != null ? import_ethers47.ethers.toBeHex(BigInt(String(tx2["value"]))) : "0x0",
|
|
82416
82889
|
chainId: tx2["chainId"] != null ? Number(tx2["chainId"]) : chainId
|
|
82417
82890
|
};
|
|
82418
82891
|
}
|
|
@@ -82578,7 +83051,7 @@ function buildWriteOps(deps) {
|
|
|
82578
83051
|
mintedUcdWei: minted,
|
|
82579
83052
|
feeUcdWei: mintFee,
|
|
82580
83053
|
echoedAmountUcdWei: minted,
|
|
82581
|
-
authorization: auth(action, `mint ${
|
|
83054
|
+
authorization: auth(action, `mint ${import_ethers47.ethers.formatEther(amountWei)} UCD against ${p.positionId}`, r.value.digest)
|
|
82582
83055
|
},
|
|
82583
83056
|
{ id: SOURCE5, kind: "lit-ops", fetchedAt: (/* @__PURE__ */ new Date()).toISOString() }
|
|
82584
83057
|
);
|
|
@@ -82619,7 +83092,7 @@ function buildWriteOps(deps) {
|
|
|
82619
83092
|
txRef: { kind: "eth-tx", id: r.value.txHash },
|
|
82620
83093
|
paidUcdWei: paid,
|
|
82621
83094
|
echoedAmountUcdWei: paid,
|
|
82622
|
-
authorization: auth(action, `repay ${
|
|
83095
|
+
authorization: auth(action, `repay ${import_ethers47.ethers.formatEther(amountWei)} UCD on ${p.positionId}`, r.value.digest)
|
|
82623
83096
|
},
|
|
82624
83097
|
{ id: SOURCE5, kind: "lit-ops", fetchedAt: (/* @__PURE__ */ new Date()).toISOString() }
|
|
82625
83098
|
);
|
|
@@ -82882,7 +83355,7 @@ function buildWriteOps(deps) {
|
|
|
82882
83355
|
}
|
|
82883
83356
|
|
|
82884
83357
|
// src/signer/eoa-dh.ts
|
|
82885
|
-
var
|
|
83358
|
+
var import_ethers48 = require("ethers");
|
|
82886
83359
|
var EoaDHSigner = class {
|
|
82887
83360
|
constructor(wallet, broadcast, clock = Date.now) {
|
|
82888
83361
|
this.wallet = wallet;
|
|
@@ -82899,7 +83372,7 @@ var EoaDHSigner = class {
|
|
|
82899
83372
|
async signAuthorization(spec) {
|
|
82900
83373
|
const quantumTs = nextQuantumTimestamp(this.clock());
|
|
82901
83374
|
const { fields, hashHex } = spec.stamp(quantumTs);
|
|
82902
|
-
const signature = await this.wallet.signMessage(
|
|
83375
|
+
const signature = await this.wallet.signMessage(import_ethers48.ethers.getBytes(hashHex));
|
|
82903
83376
|
return { signature, quantumTs, fields };
|
|
82904
83377
|
}
|
|
82905
83378
|
async wrapInnerTx(innerTx) {
|
|
@@ -82916,11 +83389,11 @@ var EoaDHSigner = class {
|
|
|
82916
83389
|
};
|
|
82917
83390
|
|
|
82918
83391
|
// src/signer/external-eoa.ts
|
|
82919
|
-
var
|
|
82920
|
-
var
|
|
83392
|
+
var import_node_crypto8 = require("crypto");
|
|
83393
|
+
var import_ethers50 = require("ethers");
|
|
82921
83394
|
|
|
82922
83395
|
// src/boundary/upstream/shared/external-bridge/verify-landed-tx.ts
|
|
82923
|
-
var
|
|
83396
|
+
var import_ethers49 = require("ethers");
|
|
82924
83397
|
function eq2(a, b) {
|
|
82925
83398
|
return a.toLowerCase() === b.toLowerCase();
|
|
82926
83399
|
}
|
|
@@ -82943,7 +83416,7 @@ function compareLandedTx(landed, approved, borrower) {
|
|
|
82943
83416
|
return { status: "verified", from: landed.from, hash: landed.hash };
|
|
82944
83417
|
}
|
|
82945
83418
|
function verifyRawSignedTx(rawSignedTx, approved, borrower) {
|
|
82946
|
-
const parsed =
|
|
83419
|
+
const parsed = import_ethers49.ethers.Transaction.from(rawSignedTx);
|
|
82947
83420
|
if (!parsed.from || !parsed.to || !parsed.hash) {
|
|
82948
83421
|
return { status: "mismatch", hash: parsed.hash ?? "0x", reason: "the returned raw transaction is unsigned or malformed" };
|
|
82949
83422
|
}
|
|
@@ -82981,7 +83454,7 @@ async function gasHintAcrossBlocks(provider, from, tx2, action) {
|
|
|
82981
83454
|
for (let attempt = 0; attempt < 4; attempt++) {
|
|
82982
83455
|
try {
|
|
82983
83456
|
const est = await provider.estimateGas({ from, to: tx2.to, data: tx2.data, value: BigInt(tx2.value) });
|
|
82984
|
-
return
|
|
83457
|
+
return import_ethers50.ethers.toBeHex(est * 15n / 10n);
|
|
82985
83458
|
} catch (e) {
|
|
82986
83459
|
lastErr = e;
|
|
82987
83460
|
await new Promise((r) => setTimeout(r, 13e3));
|
|
@@ -83010,7 +83483,7 @@ var ExternalEoaDHSigner = class {
|
|
|
83010
83483
|
let used = { quantumTs: initialTs, fields: initial.fields };
|
|
83011
83484
|
const outcome = await this.deps.bridge.requestSignature(
|
|
83012
83485
|
{
|
|
83013
|
-
id: (0,
|
|
83486
|
+
id: (0, import_node_crypto8.randomUUID)(),
|
|
83014
83487
|
kind: "personal-sign",
|
|
83015
83488
|
action: spec.action,
|
|
83016
83489
|
card: initial.card,
|
|
@@ -83031,7 +83504,7 @@ var ExternalEoaDHSigner = class {
|
|
|
83031
83504
|
throw new OperationDeclined(`the ${spec.action} authorization was not signed: ${describeOutcome(outcome)}`);
|
|
83032
83505
|
}
|
|
83033
83506
|
const finalHash = spec.stamp(used.quantumTs).hashHex;
|
|
83034
|
-
const recovered =
|
|
83507
|
+
const recovered = import_ethers50.ethers.verifyMessage(import_ethers50.ethers.getBytes(finalHash), outcome.signature);
|
|
83035
83508
|
if (recovered.toLowerCase() !== this.deps.borrower.toLowerCase()) {
|
|
83036
83509
|
throw new Error(`the ${spec.action} authorization was signed by ${recovered}, not the borrower ${this.deps.borrower}`);
|
|
83037
83510
|
}
|
|
@@ -83042,9 +83515,9 @@ var ExternalEoaDHSigner = class {
|
|
|
83042
83515
|
}
|
|
83043
83516
|
async submitValidatedTx(outerTx, ctx) {
|
|
83044
83517
|
const approved = toApprovedTx(outerTx, this.deps.chainId);
|
|
83045
|
-
const gas = outerTx.gasLimit != null ?
|
|
83518
|
+
const gas = outerTx.gasLimit != null ? import_ethers50.ethers.toBeHex(BigInt(String(outerTx.gasLimit))) : await gasHintAcrossBlocks(this.deps.provider, this.deps.borrower, approved, ctx.action);
|
|
83046
83519
|
const outcome = await this.deps.bridge.requestSignature({
|
|
83047
|
-
id: (0,
|
|
83520
|
+
id: (0, import_node_crypto8.randomUUID)(),
|
|
83048
83521
|
kind: "transaction",
|
|
83049
83522
|
action: ctx.action,
|
|
83050
83523
|
card: ctx.card,
|
|
@@ -83076,7 +83549,7 @@ var ExternalEoaDHSigner = class {
|
|
|
83076
83549
|
return new BridgeEthersSigner(this.deps);
|
|
83077
83550
|
}
|
|
83078
83551
|
};
|
|
83079
|
-
var BridgeEthersSigner = class _BridgeEthersSigner extends
|
|
83552
|
+
var BridgeEthersSigner = class _BridgeEthersSigner extends import_ethers50.ethers.AbstractSigner {
|
|
83080
83553
|
constructor(deps) {
|
|
83081
83554
|
super(deps.provider);
|
|
83082
83555
|
this.deps = deps;
|
|
@@ -83087,18 +83560,18 @@ var BridgeEthersSigner = class _BridgeEthersSigner extends import_ethers49.ether
|
|
|
83087
83560
|
return this.deps.borrower;
|
|
83088
83561
|
}
|
|
83089
83562
|
async signMessage(message) {
|
|
83090
|
-
const bytes = typeof message === "string" ?
|
|
83563
|
+
const bytes = typeof message === "string" ? import_ethers50.ethers.toUtf8Bytes(message) : message;
|
|
83091
83564
|
if (bytes.length !== 32) {
|
|
83092
83565
|
throw new Error(
|
|
83093
83566
|
`external-wallet signMessage accepts only the SDK's bare 32-byte auth hashes (got ${bytes.length} bytes) \u2014 no other raw-message signing rides this path.`
|
|
83094
83567
|
);
|
|
83095
83568
|
}
|
|
83096
|
-
const hashHex =
|
|
83569
|
+
const hashHex = import_ethers50.ethers.hexlify(bytes).toLowerCase();
|
|
83097
83570
|
const nowMs = (this.deps.clock ?? Date.now)();
|
|
83098
83571
|
const expiresAtSec = nextQuantumTimestamp(nowMs);
|
|
83099
83572
|
const secondsLeft = Math.max(0, expiresAtSec - Math.floor(nowMs / 1e3));
|
|
83100
83573
|
const outcome = await this.deps.bridge.requestSignature({
|
|
83101
|
-
id: (0,
|
|
83574
|
+
id: (0, import_node_crypto8.randomUUID)(),
|
|
83102
83575
|
kind: "personal-sign",
|
|
83103
83576
|
action: "btc-withdrawal EXECUTE step (blind hash)",
|
|
83104
83577
|
card: [
|
|
@@ -83123,7 +83596,7 @@ var BridgeEthersSigner = class _BridgeEthersSigner extends import_ethers49.ether
|
|
|
83123
83596
|
if (outcome.status !== "approved" || !outcome.signature) {
|
|
83124
83597
|
throw new OperationDeclined(`the btc-withdrawal authorization was not signed: ${describeOutcome(outcome)}`);
|
|
83125
83598
|
}
|
|
83126
|
-
const recovered =
|
|
83599
|
+
const recovered = import_ethers50.ethers.verifyMessage(bytes, outcome.signature);
|
|
83127
83600
|
if (recovered.toLowerCase() !== this.deps.borrower.toLowerCase()) {
|
|
83128
83601
|
throw new Error(`the btc-withdrawal authorization was signed by ${recovered}, not the borrower ${this.deps.borrower}`);
|
|
83129
83602
|
}
|
|
@@ -83137,7 +83610,7 @@ var BridgeEthersSigner = class _BridgeEthersSigner extends import_ethers49.ether
|
|
|
83137
83610
|
message: value
|
|
83138
83611
|
};
|
|
83139
83612
|
const outcome = await this.deps.bridge.requestSignature({
|
|
83140
|
-
id: (0,
|
|
83613
|
+
id: (0, import_node_crypto8.randomUUID)(),
|
|
83141
83614
|
kind: "typed-data",
|
|
83142
83615
|
action: "login",
|
|
83143
83616
|
card: cardForTypedData("login", typedData),
|
|
@@ -83157,13 +83630,13 @@ var BridgeEthersSigner = class _BridgeEthersSigner extends import_ethers49.ether
|
|
|
83157
83630
|
const approved = {
|
|
83158
83631
|
to: tx2.to,
|
|
83159
83632
|
data: tx2.data,
|
|
83160
|
-
value: tx2.value != null ?
|
|
83633
|
+
value: tx2.value != null ? import_ethers50.ethers.toBeHex(BigInt(String(tx2.value))) : "0x0",
|
|
83161
83634
|
chainId: tx2.chainId != null ? Number(tx2.chainId) : this.deps.chainId
|
|
83162
83635
|
};
|
|
83163
83636
|
const card = cardForTx(approved);
|
|
83164
|
-
const gas = tx2.gasLimit != null ?
|
|
83637
|
+
const gas = tx2.gasLimit != null ? import_ethers50.ethers.toBeHex(BigInt(String(tx2.gasLimit))) : await gasHintAcrossBlocks(this.deps.provider, this.deps.borrower, approved, describeFn(approved.data));
|
|
83165
83638
|
const outcome = await this.deps.bridge.requestSignature({
|
|
83166
|
-
id: (0,
|
|
83639
|
+
id: (0, import_node_crypto8.randomUUID)(),
|
|
83167
83640
|
kind: "transaction",
|
|
83168
83641
|
action: describeFn(approved.data),
|
|
83169
83642
|
card,
|
|
@@ -83203,7 +83676,7 @@ function toApprovedTx(tx2, fallbackChainId) {
|
|
|
83203
83676
|
return {
|
|
83204
83677
|
to: tx2.to,
|
|
83205
83678
|
data: tx2.data,
|
|
83206
|
-
value: tx2.value != null ?
|
|
83679
|
+
value: tx2.value != null ? import_ethers50.ethers.toBeHex(BigInt(String(tx2.value))) : "0x0",
|
|
83207
83680
|
chainId: tx2.chainId != null ? Number(tx2.chainId) : fallbackChainId
|
|
83208
83681
|
};
|
|
83209
83682
|
}
|
|
@@ -83247,7 +83720,7 @@ var MIN_CONFIRMATIONS = { mainnet: 6, sepolia: 1 };
|
|
|
83247
83720
|
var RealUpstreamPlugin = class {
|
|
83248
83721
|
constructor(config, wallet, runtime) {
|
|
83249
83722
|
this.config = config;
|
|
83250
|
-
this.provider = new
|
|
83723
|
+
this.provider = new import_ethers51.ethers.JsonRpcProvider(config.rpcUrl, config.chainId);
|
|
83251
83724
|
this.wallet = wallet ?? null;
|
|
83252
83725
|
this.runtime = runtime ?? null;
|
|
83253
83726
|
this.session = wallet ? new LitOpsSession(wallet.connect(this.provider), config.serviceEndpoint, config.chainId) : null;
|
|
@@ -83554,14 +84027,14 @@ var RealUpstreamPlugin = class {
|
|
|
83554
84027
|
if (!pkpValidation) {
|
|
83555
84028
|
throw new Error(`the SDK's ${this.config.network} deployment table has no PKPValidation address \u2014 cannot verify validator version ${version2}.`);
|
|
83556
84029
|
}
|
|
83557
|
-
const registry = new
|
|
84030
|
+
const registry = new import_ethers51.ethers.Contract(pkpValidation, ["function validatorForVersion(uint256) view returns (address)"], this.provider);
|
|
83558
84031
|
let validator;
|
|
83559
84032
|
try {
|
|
83560
84033
|
validator = await registry.validatorForVersion(version2);
|
|
83561
84034
|
} catch (e) {
|
|
83562
84035
|
throw new Error(`could not verify validator version ${version2} on-chain (PKPValidation ${pkpValidation}): ${e.message}`);
|
|
83563
84036
|
}
|
|
83564
|
-
if (validator ===
|
|
84037
|
+
if (validator === import_ethers51.ethers.ZeroAddress) {
|
|
83565
84038
|
throw new Error(
|
|
83566
84039
|
`validator version ${version2} is NOT registered on ${this.config.network} (PKPValidation ${pkpValidation} returns the zero address) \u2014 the transaction would revert ValidatorNotConfigured. Set DH_VALIDATOR_VERSION to the network's registered generation.`
|
|
83567
84040
|
);
|
|
@@ -83639,7 +84112,7 @@ var RealUpstreamPlugin = class {
|
|
|
83639
84112
|
}
|
|
83640
84113
|
if (mode === "external") {
|
|
83641
84114
|
const borrower = await rt.manager.resolveBorrowerForWrite();
|
|
83642
|
-
if (!borrower) {
|
|
84115
|
+
if (!borrower || this.pinnedWalletUnreachable(borrower, { allowCachedLogin: false })) {
|
|
83643
84116
|
return {
|
|
83644
84117
|
ok: false,
|
|
83645
84118
|
failure: {
|
|
@@ -83689,6 +84162,20 @@ var RealUpstreamPlugin = class {
|
|
|
83689
84162
|
}
|
|
83690
84163
|
};
|
|
83691
84164
|
}
|
|
84165
|
+
/** Hosted tier: the SIWE borrower is bound from boot, so "bound" no longer implies a
|
|
84166
|
+
* wallet can sign. Refuse as "no wallet is connected" instead of starting a ceremony
|
|
84167
|
+
* nobody can answer.
|
|
84168
|
+
*
|
|
84169
|
+
* `allowCachedLogin` is for `connectExternal` ONLY: a still-valid lit-ops login lets it
|
|
84170
|
+
* succeed without a wallet (it signs nothing). A WRITE always needs a fresh wallet
|
|
84171
|
+
* signature (ExternalEoaDHSigner), so a cached JWT must not admit it — that would queue
|
|
84172
|
+
* an approval with no wallet attached to sign it. */
|
|
84173
|
+
pinnedWalletUnreachable(borrower, opts) {
|
|
84174
|
+
if (!this.runtime?.manager.identityPinned()) return false;
|
|
84175
|
+
if (this.runtime.bridge.walletState() !== null) return false;
|
|
84176
|
+
if (!opts.allowCachedLogin) return true;
|
|
84177
|
+
return !this.sessionCache.get(`external:${borrower.toLowerCase()}`)?.hasValidToken();
|
|
84178
|
+
}
|
|
83692
84179
|
/** The EXPLICIT login action (plan 10 OV-10 / A0.7): the ONLY path that may summon the
|
|
83693
84180
|
* wallet for a lit-ops login outside a write ceremony. Binds the borrower on success —
|
|
83694
84181
|
* the first verified ceremony fixes the identity. */
|
|
@@ -83699,7 +84186,7 @@ var RealUpstreamPlugin = class {
|
|
|
83699
84186
|
return { ok: false, reason: `the active mode is '${manager.mode()}' \u2014 run signer_setup action 'use' mode 'external' first` };
|
|
83700
84187
|
}
|
|
83701
84188
|
const borrower = manager.borrowerForWrite();
|
|
83702
|
-
if (!borrower) {
|
|
84189
|
+
if (!borrower || this.pinnedWalletUnreachable(borrower, { allowCachedLogin: true })) {
|
|
83703
84190
|
return { ok: false, reason: "no wallet is connected \u2014 open the approval page (signer_setup action 'status') and connect your wallet first" };
|
|
83704
84191
|
}
|
|
83705
84192
|
const key = `external:${borrower.toLowerCase()}`;
|
|
@@ -83837,7 +84324,7 @@ var RealUpstreamPlugin = class {
|
|
|
83837
84324
|
);
|
|
83838
84325
|
if (!r.ok) return r;
|
|
83839
84326
|
const raw = r.value.data.supportedStablecoins ?? [];
|
|
83840
|
-
const bad = raw.find((x) => !
|
|
84327
|
+
const bad = raw.find((x) => !import_ethers51.ethers.isAddress(String(x.address)) || !Number.isFinite(Number(x.decimals)));
|
|
83841
84328
|
if (bad) {
|
|
83842
84329
|
return {
|
|
83843
84330
|
ok: false,
|
|
@@ -83920,7 +84407,7 @@ var RealUpstreamPlugin = class {
|
|
|
83920
84407
|
};
|
|
83921
84408
|
}
|
|
83922
84409
|
const symbol = raw.toLowerCase();
|
|
83923
|
-
if (
|
|
84410
|
+
if (import_ethers51.ethers.isAddress(raw)) return this.psmCallsFor(symbol);
|
|
83924
84411
|
const verified = await this.verifiedStablecoins();
|
|
83925
84412
|
if (!verified.ok) return { ok: false, failure: verified.failure };
|
|
83926
84413
|
const hits = verified.rows.filter((r) => r.symbol.toLowerCase() === symbol);
|
|
@@ -83958,7 +84445,7 @@ var RealUpstreamPlugin = class {
|
|
|
83958
84445
|
* chain, then sign.
|
|
83959
84446
|
*/
|
|
83960
84447
|
async psmCallsFor(stablecoinAddress) {
|
|
83961
|
-
if (!
|
|
84448
|
+
if (!import_ethers51.ethers.isAddress(stablecoinAddress)) {
|
|
83962
84449
|
throw new Error(`psmCallsFor requires a resolved 0x address, got '${stablecoinAddress}' \u2014 resolve through psmCallsForChoice`);
|
|
83963
84450
|
}
|
|
83964
84451
|
const key = stablecoinAddress.toLowerCase();
|
|
@@ -83978,9 +84465,9 @@ var RealUpstreamPlugin = class {
|
|
|
83978
84465
|
let supported;
|
|
83979
84466
|
let symbol;
|
|
83980
84467
|
try {
|
|
83981
|
-
const psm = new
|
|
84468
|
+
const psm = new import_ethers51.ethers.Contract(psmAddress, ["function supportedStablecoins(address) view returns (bool)"], this.provider);
|
|
83982
84469
|
supported = await psm["supportedStablecoins"](key);
|
|
83983
|
-
const erc20 = new
|
|
84470
|
+
const erc20 = new import_ethers51.ethers.Contract(key, ["function symbol() view returns (string)"], this.provider);
|
|
83984
84471
|
symbol = await erc20["symbol"]();
|
|
83985
84472
|
} catch (e) {
|
|
83986
84473
|
return { ok: false, failure: { kind: "unavailable", source: "chain-rpc", message: `PSM stablecoin check failed for ${key}: ${e.message}` } };
|
|
@@ -84193,7 +84680,7 @@ var RealUpstreamPlugin = class {
|
|
|
84193
84680
|
const pm = this.contracts["PositionManager"];
|
|
84194
84681
|
if (!pm) return false;
|
|
84195
84682
|
try {
|
|
84196
|
-
const c = new
|
|
84683
|
+
const c = new import_ethers51.ethers.Contract(pm, PAUSABLE_ABI, this.provider);
|
|
84197
84684
|
return Boolean(await c["paused"]());
|
|
84198
84685
|
} catch {
|
|
84199
84686
|
return false;
|
|
@@ -84202,16 +84689,16 @@ var RealUpstreamPlugin = class {
|
|
|
84202
84689
|
async readPositionDetails(id) {
|
|
84203
84690
|
const core = this.contracts["PositionManagerCoreModule"] ?? this.contracts["PositionManager"];
|
|
84204
84691
|
if (!core) throw new Error(`no PositionManager address for network ${this.config.network}`);
|
|
84205
|
-
const c = new
|
|
84692
|
+
const c = new import_ethers51.ethers.Contract(core, POSITION_DETAILS_ABI, this.provider);
|
|
84206
84693
|
let d;
|
|
84207
84694
|
try {
|
|
84208
|
-
d = await c["getPositionDetails"](
|
|
84695
|
+
d = await c["getPositionDetails"](import_ethers51.ethers.zeroPadValue(id, 32));
|
|
84209
84696
|
} catch (e) {
|
|
84210
84697
|
if (e.code === "CALL_EXCEPTION") return null;
|
|
84211
84698
|
throw e;
|
|
84212
84699
|
}
|
|
84213
84700
|
const borrower = String(d["borrower"]);
|
|
84214
|
-
if (borrower ===
|
|
84701
|
+
if (borrower === import_ethers51.ethers.ZeroAddress) return null;
|
|
84215
84702
|
return {
|
|
84216
84703
|
positionId: String(d["positionId"]),
|
|
84217
84704
|
pkpId: String(d["pkpId"]),
|
|
@@ -84235,7 +84722,8 @@ var RealUpstreamPlugin = class {
|
|
|
84235
84722
|
// src/boundary/upstream/shared/external-bridge/bridge.ts
|
|
84236
84723
|
var fs4 = __toESM(require("fs"));
|
|
84237
84724
|
var http3 = __toESM(require("http"));
|
|
84238
|
-
var
|
|
84725
|
+
var import_node_crypto9 = require("crypto");
|
|
84726
|
+
var import_ethers52 = require("ethers");
|
|
84239
84727
|
|
|
84240
84728
|
// src/boundary/upstream/shared/external-bridge/approval-page.ts
|
|
84241
84729
|
function renderApprovalPage(sessionId, nonce) {
|
|
@@ -84245,47 +84733,48 @@ function renderApprovalPage(sessionId, nonce) {
|
|
|
84245
84733
|
<meta charset="utf-8">
|
|
84246
84734
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
84247
84735
|
<title>Diamond Hands \u2014 signature approval</title>
|
|
84736
|
+
${HOUSE_HEAD_LINKS}
|
|
84248
84737
|
<style>
|
|
84249
|
-
|
|
84250
|
-
|
|
84251
|
-
|
|
84252
|
-
|
|
84253
|
-
|
|
84254
|
-
|
|
84255
|
-
|
|
84256
|
-
|
|
84257
|
-
|
|
84258
|
-
.
|
|
84259
|
-
|
|
84260
|
-
|
|
84261
|
-
|
|
84262
|
-
|
|
84263
|
-
#
|
|
84264
|
-
#
|
|
84265
|
-
#wallet { font-family:ui-monospace,monospace; font-size:12px; color:var(--dim); margin-top:10px; }
|
|
84738
|
+
${HOUSE_BASE_CSS}
|
|
84739
|
+
/* \u2500\u2500 approval page only \u2500\u2500 */
|
|
84740
|
+
main { max-width: 36rem; }
|
|
84741
|
+
.status { color:#a1a1a1; font-size:0.875rem; }
|
|
84742
|
+
.action { text-transform:uppercase; letter-spacing:.08em; font-size:0.75rem; font-weight:600; color:#dbff91; margin-top:0.25rem; }
|
|
84743
|
+
/* The decoded card IS the operation (decode-equivalence): kept monospace and pre-wrapped
|
|
84744
|
+
exactly as the server rendered it, on an inset well darker than the panel. */
|
|
84745
|
+
.card { white-space:pre-wrap; font-family:ui-monospace,SFMono-Regular,Menlo,monospace; font-size:0.875rem; color:#fafafa;
|
|
84746
|
+
background:#0a0a0a; border:1px solid rgba(255,255,255,0.1); border-radius:10px; padding:14px; margin:0.75rem 0 1rem; }
|
|
84747
|
+
.actions { display:flex; flex-wrap:wrap; gap:0.75rem; }
|
|
84748
|
+
#deadline { margin-bottom:1rem; }
|
|
84749
|
+
#wallet { font-family:ui-monospace,SFMono-Regular,Menlo,monospace; font-size:0.75rem; color:#a1a1a1; margin-top:1rem; }
|
|
84750
|
+
#wallet:empty { display:none; }
|
|
84751
|
+
#wc { margin-top:1.25rem; border-top:1px solid rgba(255,255,255,0.06); padding-top:1rem; }
|
|
84752
|
+
#wc-uri { user-select:all; word-break:break-all; font-size:0.75rem; }
|
|
84753
|
+
#wc-hint { margin-top:0.75rem; }
|
|
84266
84754
|
.hidden { display:none; }
|
|
84267
84755
|
</style>
|
|
84268
84756
|
</head>
|
|
84269
84757
|
<body>
|
|
84758
|
+
${houseHeader("Diamond Hands \xB7 signature approval")}
|
|
84270
84759
|
<main>
|
|
84271
|
-
<h1
|
|
84760
|
+
<h1>Signature approval</h1>
|
|
84272
84761
|
<div class="panel">
|
|
84273
84762
|
<div id="status" class="status">Connecting to your wallet\u2026</div>
|
|
84274
84763
|
<div id="request" class="hidden">
|
|
84275
84764
|
<div id="action" class="action"></div>
|
|
84276
84765
|
<div id="card" class="card"></div>
|
|
84277
84766
|
<div id="deadline" class="status hidden"></div>
|
|
84278
|
-
<
|
|
84279
|
-
|
|
84767
|
+
<div class="actions">
|
|
84768
|
+
<button id="approve" class="btn-primary">Approve in wallet</button>
|
|
84769
|
+
<button id="reject" class="btn-danger">Reject</button>
|
|
84770
|
+
</div>
|
|
84280
84771
|
</div>
|
|
84281
84772
|
<div id="wallet"></div>
|
|
84282
|
-
<div id="wc"
|
|
84283
|
-
<button id="wc-connect"
|
|
84284
|
-
|
|
84285
|
-
|
|
84286
|
-
<div id="wc-
|
|
84287
|
-
<div id="wc-uri" class="card hidden" style="user-select:all; word-break:break-all; font-size:12px;"></div>
|
|
84288
|
-
<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>
|
|
84773
|
+
<div id="wc">
|
|
84774
|
+
<button id="wc-connect" class="btn-secondary">Use a mobile wallet instead (WalletConnect)</button>
|
|
84775
|
+
<div id="wc-qr" class="qr-plate hidden"></div>
|
|
84776
|
+
<div id="wc-uri" class="card hidden"></div>
|
|
84777
|
+
<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>
|
|
84289
84778
|
</div>
|
|
84290
84779
|
</div>
|
|
84291
84780
|
</main>
|
|
@@ -84359,21 +84848,63 @@ async function healChain() {
|
|
|
84359
84848
|
}).catch(() => undefined);
|
|
84360
84849
|
}
|
|
84361
84850
|
await readWallet();
|
|
84362
|
-
await
|
|
84851
|
+
await sayHello();
|
|
84363
84852
|
showWallet();
|
|
84364
84853
|
}
|
|
84365
84854
|
|
|
84855
|
+
function utf8Hex(text) {
|
|
84856
|
+
return "0x" + Array.from(new TextEncoder().encode(text)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
84857
|
+
}
|
|
84858
|
+
|
|
84859
|
+
// Presence proof: the bridge only believes a wallet is at this page once the wallet has
|
|
84860
|
+
// SIGNED a short statement naming this page's origin, the chain and a per-page nonce. Saying
|
|
84861
|
+
// an address proves nothing (it is public); signing proves the key is here. One prompt per
|
|
84862
|
+
// page session: once this account has proven itself the bridge accepts later hellos for it
|
|
84863
|
+
// (a chain switch) without asking the wallet again.
|
|
84864
|
+
let provenFor = null;
|
|
84865
|
+
async function sayHello() {
|
|
84866
|
+
let signature;
|
|
84867
|
+
if (provenFor === null || provenFor.toLowerCase() !== String(account).toLowerCase()) {
|
|
84868
|
+
const ch = await fetch(BASE + "challenge?s=" + SESSION + "&chainId=" + chainId).then((r) => r.json());
|
|
84869
|
+
showIdleStatus("Sign the short statement in your wallet to prove it is yours \u2014 it moves no funds.");
|
|
84870
|
+
signature = await window.ethereum.request({ method: "personal_sign", params: [utf8Hex(ch.statement), account] });
|
|
84871
|
+
}
|
|
84872
|
+
const r = await post(BASE + "hello", { account: account, chainId: chainId, signature: signature });
|
|
84873
|
+
if (!r.ok) {
|
|
84874
|
+
const b = await r.json().catch(() => ({}));
|
|
84875
|
+
showStatus("This wallet was not accepted: " + (b.error || "HTTP " + r.status));
|
|
84876
|
+
return false;
|
|
84877
|
+
}
|
|
84878
|
+
provenFor = account;
|
|
84879
|
+
return true;
|
|
84880
|
+
}
|
|
84881
|
+
|
|
84882
|
+
// The stream opens at load, so a card can be on screen BEFORE connect() finishes. The status
|
|
84883
|
+
// line then belongs to that card (its review / mobile-wallet guidance), and connection
|
|
84884
|
+
// progress must not overwrite it. Connection progress lines (idle / "sign the statement", whose
|
|
84885
|
+
// wallet popup is self-explanatory) go through here; failures (a refused hello, a lost
|
|
84886
|
+
// stream, a wrong network) still show unconditionally.
|
|
84887
|
+
function showIdleStatus(text) {
|
|
84888
|
+
if (current !== null) return;
|
|
84889
|
+
showStatus(text);
|
|
84890
|
+
}
|
|
84891
|
+
|
|
84366
84892
|
async function connect() {
|
|
84367
|
-
if (!window.ethereum) {
|
|
84893
|
+
if (!window.ethereum) {
|
|
84894
|
+
// The event stream is already open (see the bottom of this script) \u2014 a phone paired
|
|
84895
|
+
// below still mirrors its cards here.
|
|
84896
|
+
showIdleStatus("No browser wallet detected \u2014 use the mobile wallet option below, or install MetaMask (or open this page in a wallet browser).");
|
|
84897
|
+
return;
|
|
84898
|
+
}
|
|
84368
84899
|
await window.ethereum.request({ method: "eth_requestAccounts" });
|
|
84369
84900
|
await readWallet();
|
|
84370
|
-
|
|
84901
|
+
const accepted = await sayHello();
|
|
84371
84902
|
showWallet();
|
|
84372
84903
|
window.ethereum.on("accountsChanged", onAccountsChanged);
|
|
84373
84904
|
window.ethereum.on("chainChanged", onChainChanged);
|
|
84905
|
+
if (!accepted) return;
|
|
84374
84906
|
await healChain();
|
|
84375
|
-
|
|
84376
|
-
listen();
|
|
84907
|
+
showIdleStatus("Connected. Waiting for a signature request\u2026");
|
|
84377
84908
|
}
|
|
84378
84909
|
|
|
84379
84910
|
// Handlers trust the EVENT payloads \u2014 re-reading eth_accounts/eth_chainId here races the
|
|
@@ -84383,6 +84914,8 @@ async function onAccountsChanged(accounts) {
|
|
|
84383
84914
|
await post(BASE + "wallet-event", { account: account, chainId: chainId });
|
|
84384
84915
|
showWallet();
|
|
84385
84916
|
invalidatePageRequests("Wallet changed \u2014 pending request invalidated.");
|
|
84917
|
+
// The bridge adopts no account from an event alone \u2014 a different account proves itself.
|
|
84918
|
+
if (account) await sayHello();
|
|
84386
84919
|
}
|
|
84387
84920
|
|
|
84388
84921
|
async function onChainChanged(cid) {
|
|
@@ -84392,8 +84925,14 @@ async function onChainChanged(cid) {
|
|
|
84392
84925
|
invalidatePageRequests("Network changed \u2014 pending request invalidated.");
|
|
84393
84926
|
}
|
|
84394
84927
|
|
|
84928
|
+
// ONE stream per page, opened at load whatever wallet this browser has: a phone paired
|
|
84929
|
+
// through WalletConnect needs no injected wallet, and its read-only mirror arrives on this
|
|
84930
|
+
// stream. Opening it proves nothing \u2014 the bridge sends this page NOTHING until a person is
|
|
84931
|
+
// proven (a signed hello, or a pairing a phone answered).
|
|
84932
|
+
let es = null;
|
|
84395
84933
|
function listen() {
|
|
84396
|
-
|
|
84934
|
+
if (es !== null) return;
|
|
84935
|
+
es = new EventSource(BASE + "events?s=" + SESSION);
|
|
84397
84936
|
es.onmessage = (ev) => {
|
|
84398
84937
|
const next = JSON.parse(ev.data);
|
|
84399
84938
|
// A later frame for an id REPLACES the earlier one: driveWc re-stamps a personal-sign
|
|
@@ -84582,9 +85121,10 @@ document.getElementById("wc-connect").onclick = async () => {
|
|
|
84582
85121
|
qrEl.classList.remove("hidden");
|
|
84583
85122
|
}
|
|
84584
85123
|
document.getElementById("wc-hint").classList.remove("hidden");
|
|
84585
|
-
|
|
85124
|
+
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.");
|
|
84586
85125
|
};
|
|
84587
85126
|
|
|
85127
|
+
listen();
|
|
84588
85128
|
connect();
|
|
84589
85129
|
</script>
|
|
84590
85130
|
</body>
|
|
@@ -84665,6 +85205,22 @@ document.getElementById("generate").onclick = () => submit(true);
|
|
|
84665
85205
|
|
|
84666
85206
|
// src/boundary/upstream/shared/external-bridge/bridge.ts
|
|
84667
85207
|
var MAX_SESSIONS = 16;
|
|
85208
|
+
function presenceStatement(origin2, chainId, nonce) {
|
|
85209
|
+
return [
|
|
85210
|
+
"Diamond Hands approval page",
|
|
85211
|
+
"Sign to prove this wallet is yours. This moves no funds and approves no operation.",
|
|
85212
|
+
`Origin: ${origin2}`,
|
|
85213
|
+
`Chain ID: ${chainId}`,
|
|
85214
|
+
`Session nonce: ${nonce}`
|
|
85215
|
+
].join("\n");
|
|
85216
|
+
}
|
|
85217
|
+
function recoverPresenceSigner(statement, signature) {
|
|
85218
|
+
try {
|
|
85219
|
+
return import_ethers52.ethers.verifyMessage(statement, signature);
|
|
85220
|
+
} catch {
|
|
85221
|
+
return null;
|
|
85222
|
+
}
|
|
85223
|
+
}
|
|
84668
85224
|
var DEFAULT_EXPIRY_MS = 5 * 60 * 1e3;
|
|
84669
85225
|
var DEFAULT_ATTACH_GRACE_MS = 60 * 1e3;
|
|
84670
85226
|
var DEFAULT_HOSTED_ATTACH_GRACE_MS = 180 * 1e3;
|
|
@@ -84678,6 +85234,7 @@ function wcDeclineOrFault(e) {
|
|
|
84678
85234
|
}
|
|
84679
85235
|
var SignatureBridge = class {
|
|
84680
85236
|
clock;
|
|
85237
|
+
sweepIntervalMs;
|
|
84681
85238
|
/** Lowercased at construction so every comparison is case-flat — EIP-55 checksum casing
|
|
84682
85239
|
* differs between what SIWE signs and what a wallet reports for the SAME address. */
|
|
84683
85240
|
boundAccount;
|
|
@@ -84690,7 +85247,7 @@ var SignatureBridge = class {
|
|
|
84690
85247
|
/** Started state independent of the transport binding (mounted bridges own no server). */
|
|
84691
85248
|
started = false;
|
|
84692
85249
|
mount;
|
|
84693
|
-
token = (0,
|
|
85250
|
+
token = (0, import_node_crypto9.randomBytes)(24).toString("hex");
|
|
84694
85251
|
/** Hosted mounts: when the current page token was minted (rotation basis). */
|
|
84695
85252
|
tokenMintedAt = 0;
|
|
84696
85253
|
/** Ceremony-scoped link (plan 06 §1.5): the SAME URL is multi-visit and multi-owner —
|
|
@@ -84708,13 +85265,24 @@ var SignatureBridge = class {
|
|
|
84708
85265
|
wcTransport = null;
|
|
84709
85266
|
/** True while a WalletConnect session is THE wallet — ceremonies route over WC. */
|
|
84710
85267
|
wcActive = false;
|
|
84711
|
-
/**
|
|
84712
|
-
|
|
85268
|
+
/** Which page session asked for which pairing (pairing id → session id). The transport's
|
|
85269
|
+
* `onSession` says WHICH PAIRING a phone answered; this says whose it was. The previous
|
|
85270
|
+
* "most recent asker" guess let a second session claim the credit for a QR the user's
|
|
85271
|
+
* phone scanned (Sentinel 2 PoC-B). */
|
|
85272
|
+
pairingOwners = /* @__PURE__ */ new Map();
|
|
85273
|
+
/** The page session the ADMITTED WalletConnect session's proof was made for — the one page
|
|
85274
|
+
* credited with `wcPaired`. The credit lasts exactly as long as that session: it moves when
|
|
85275
|
+
* another proven session replaces it and ends when the wallet disconnects. */
|
|
85276
|
+
wcCreditedSession = null;
|
|
84713
85277
|
keystoreUnlock;
|
|
84714
85278
|
unlockToken = null;
|
|
84715
85279
|
unlockSession = null;
|
|
84716
85280
|
constructor(opts) {
|
|
84717
85281
|
this.clock = opts?.clock ?? Date.now;
|
|
85282
|
+
this.sweepIntervalMs = opts?.sweepIntervalMs ?? 1e3;
|
|
85283
|
+
if (!Number.isInteger(this.sweepIntervalMs) || this.sweepIntervalMs < 0) {
|
|
85284
|
+
throw new Error(`bridge sweepIntervalMs must be a non-negative integer (got ${String(opts?.sweepIntervalMs)})`);
|
|
85285
|
+
}
|
|
84718
85286
|
this.boundAccount = opts?.boundAccount?.toLowerCase();
|
|
84719
85287
|
this.expiryMs = opts?.expiryMs ?? DEFAULT_EXPIRY_MS;
|
|
84720
85288
|
this.maxPending = opts?.maxPending ?? null;
|
|
@@ -84730,7 +85298,7 @@ var SignatureBridge = class {
|
|
|
84730
85298
|
unlockUrl() {
|
|
84731
85299
|
if (!this.started) throw new Error("bridge is not started");
|
|
84732
85300
|
if (!this.keystoreUnlock) throw new Error("keystore unlock is not wired on this bridge");
|
|
84733
|
-
this.unlockToken = (0,
|
|
85301
|
+
this.unlockToken = (0, import_node_crypto9.randomBytes)(24).toString("hex");
|
|
84734
85302
|
return this.mount ? `${this.mount.baseUrl}/unlock?t=${this.unlockToken}` : `http://127.0.0.1:${this.port}/unlock?t=${this.unlockToken}`;
|
|
84735
85303
|
}
|
|
84736
85304
|
/** Idempotent — the bridge spawns on the first write that needs it (plan 04 §2).
|
|
@@ -84750,8 +85318,10 @@ var SignatureBridge = class {
|
|
|
84750
85318
|
this.server = server;
|
|
84751
85319
|
}
|
|
84752
85320
|
this.started = true;
|
|
84753
|
-
this.
|
|
84754
|
-
|
|
85321
|
+
if (this.sweepIntervalMs > 0) {
|
|
85322
|
+
this.sweepTimer = setInterval(() => this.sweep(), this.sweepIntervalMs);
|
|
85323
|
+
this.sweepTimer.unref();
|
|
85324
|
+
}
|
|
84755
85325
|
if (this.urlFile) fs4.writeFileSync(this.urlFile, this.url());
|
|
84756
85326
|
}
|
|
84757
85327
|
/** Plan 12 C1: the outer server's dispatch entry for a MOUNTED bridge — `req.url`
|
|
@@ -84771,7 +85341,7 @@ var SignatureBridge = class {
|
|
|
84771
85341
|
if (this.mount) {
|
|
84772
85342
|
const now = this.clock();
|
|
84773
85343
|
if (this.tokenMintedAt === 0 || now - this.tokenMintedAt > HOSTED_PAGE_TOKEN_TTL_MS) {
|
|
84774
|
-
this.token = (0,
|
|
85344
|
+
this.token = (0, import_node_crypto9.randomBytes)(24).toString("hex");
|
|
84775
85345
|
this.tokenMintedAt = now;
|
|
84776
85346
|
}
|
|
84777
85347
|
return `${this.mount.baseUrl}/?t=${this.token}`;
|
|
@@ -84811,6 +85381,16 @@ var SignatureBridge = class {
|
|
|
84811
85381
|
pendingCount() {
|
|
84812
85382
|
return this.pending.size;
|
|
84813
85383
|
}
|
|
85384
|
+
/** A request lives for the bridge's expiry OR until its payload dies, whichever is first.
|
|
85385
|
+
* The BTC-withdraw execute leg's payload dies inside a sub-minute quantum window; holding
|
|
85386
|
+
* the ceremony open for the full five minutes kept a dead card on screen and let the phone
|
|
85387
|
+
* be asked to sign something the protocol would refuse. */
|
|
85388
|
+
deadlineFor(request, nowMs) {
|
|
85389
|
+
const bridgeDeadline = nowMs + this.expiryMs;
|
|
85390
|
+
if (request.expiresAtSec === void 0) return bridgeDeadline;
|
|
85391
|
+
if (!Number.isFinite(request.expiresAtSec)) throw new Error(`request ${request.id} carries a non-finite expiresAtSec`);
|
|
85392
|
+
return Math.min(bridgeDeadline, request.expiresAtSec * 1e3);
|
|
85393
|
+
}
|
|
84814
85394
|
/**
|
|
84815
85395
|
* Enqueue a request and resolve on the human's decision (or expiry/invalidation).
|
|
84816
85396
|
* Chain-id mismatch with an already-connected wallet refuses BEFORE the wallet is asked.
|
|
@@ -84833,7 +85413,7 @@ var SignatureBridge = class {
|
|
|
84833
85413
|
const now = this.clock();
|
|
84834
85414
|
const entry = {
|
|
84835
85415
|
request,
|
|
84836
|
-
deadlineMs:
|
|
85416
|
+
deadlineMs: this.deadlineFor(request, now),
|
|
84837
85417
|
enqueuedMs: now,
|
|
84838
85418
|
resolve,
|
|
84839
85419
|
settled: false,
|
|
@@ -84864,7 +85444,7 @@ var SignatureBridge = class {
|
|
|
84864
85444
|
const now = this.clock();
|
|
84865
85445
|
const entry = {
|
|
84866
85446
|
request,
|
|
84867
|
-
deadlineMs:
|
|
85447
|
+
deadlineMs: this.deadlineFor(request, now),
|
|
84868
85448
|
enqueuedMs: now,
|
|
84869
85449
|
resolve,
|
|
84870
85450
|
settled: false,
|
|
@@ -84916,6 +85496,7 @@ var SignatureBridge = class {
|
|
|
84916
85496
|
return;
|
|
84917
85497
|
}
|
|
84918
85498
|
try {
|
|
85499
|
+
if (this.expireIfOverdue(entry)) return;
|
|
84919
85500
|
if (req.kind === "transaction") {
|
|
84920
85501
|
this.pushEntry(entry);
|
|
84921
85502
|
const tx2 = req.tx;
|
|
@@ -84927,15 +85508,23 @@ var SignatureBridge = class {
|
|
|
84927
85508
|
} else if (req.kind === "personal-sign") {
|
|
84928
85509
|
if (entry.finalize) {
|
|
84929
85510
|
const fresh = await entry.finalize();
|
|
85511
|
+
if (entry.settled) return;
|
|
85512
|
+
if (entry.owner !== "wc") return;
|
|
85513
|
+
const live = transport.active();
|
|
85514
|
+
if (!this.wcActive || !live || live.account.toLowerCase() !== account.toLowerCase()) {
|
|
85515
|
+
this.settle(entry, {
|
|
85516
|
+
status: "invalidated",
|
|
85517
|
+
reason: "the WalletConnect wallet changed while this payload was being prepared \u2014 the phone was not asked. Reconnect your wallet and retry the operation."
|
|
85518
|
+
});
|
|
85519
|
+
return;
|
|
85520
|
+
}
|
|
84930
85521
|
req.personalSign = fresh.personalSign;
|
|
84931
85522
|
req.card = fresh.card;
|
|
84932
85523
|
}
|
|
85524
|
+
if (this.expireIfOverdue(entry)) return;
|
|
84933
85525
|
const ps = req.personalSign;
|
|
84934
|
-
if (
|
|
84935
|
-
this.settle(entry, {
|
|
84936
|
-
status: "invalidated",
|
|
84937
|
-
reason: `this step signs a 32-byte hash your wallet cannot decode, and no approval page is open to show you what it authorizes \u2014 open ${this.url()} and re-run the withdrawal with loan_withdraw_retry (it re-signs with a fresh stamp; your coins stay in the vault meanwhile)`
|
|
84938
|
-
});
|
|
85526
|
+
if (!this.pageAttached()) {
|
|
85527
|
+
this.settle(entry, { status: "invalidated", reason: this.noPageReason(ps.layout === RAW_HASH_LAYOUT) });
|
|
84939
85528
|
return;
|
|
84940
85529
|
}
|
|
84941
85530
|
this.pushEntry(entry);
|
|
@@ -84960,6 +85549,16 @@ var SignatureBridge = class {
|
|
|
84960
85549
|
}
|
|
84961
85550
|
}
|
|
84962
85551
|
}
|
|
85552
|
+
/** Refusal for a WalletConnect personal_sign with no proven approval page attached.
|
|
85553
|
+
*
|
|
85554
|
+
* The remedy names BOTH halves, because opening the link alone does not fix it: a freshly
|
|
85555
|
+
* opened page is a stranger until a phone answers a pairing it showed (or its wallet signs
|
|
85556
|
+
* the presence statement), so it receives no card. Following "just reopen the URL" looped
|
|
85557
|
+
* (Sentinel 2 PoC-C). */
|
|
85558
|
+
noPageReason(blindHash) {
|
|
85559
|
+
const what = blindHash ? "this step signs a 32-byte hash your wallet cannot decode" : "this step asks your wallet to sign a message your phone shows only as a hash";
|
|
85560
|
+
return `${what}, and no approval page linked to your wallet is open to show you what it authorizes \u2014 open ${this.url()} in a browser AND, on that page, re-scan the WalletConnect QR with your phone (or reconnect your wallet there) so the page is tied to your wallet, then retry with loan_withdraw_retry for a withdrawal or re-run the operation (it re-signs with a fresh stamp; your coins stay in the vault meanwhile)`;
|
|
85561
|
+
}
|
|
84963
85562
|
/** A live attachment that could still decide a request: an open approval-page SSE
|
|
84964
85563
|
* stream (real page or headless driver) or an active WalletConnect session. PUBLIC
|
|
84965
85564
|
* (plan 17 E1): the connector's idle-eviction predicate reads it — a tenant world
|
|
@@ -85037,12 +85636,13 @@ var SignatureBridge = class {
|
|
|
85037
85636
|
this.server = null;
|
|
85038
85637
|
this.started = false;
|
|
85039
85638
|
this.wallet = null;
|
|
85040
|
-
this.token = (0,
|
|
85639
|
+
this.token = (0, import_node_crypto9.randomBytes)(24).toString("hex");
|
|
85041
85640
|
this.tokenMintedAt = 0;
|
|
85042
85641
|
if (this.urlFile) fs4.rmSync(this.urlFile, { force: true });
|
|
85043
85642
|
void this.wcTransport?.close().catch(() => void 0);
|
|
85044
85643
|
this.wcTransport = null;
|
|
85045
85644
|
this.wcActive = false;
|
|
85645
|
+
this.pairingOwners.clear();
|
|
85046
85646
|
}
|
|
85047
85647
|
// ---- HTTP plumbing ----
|
|
85048
85648
|
route(req, res) {
|
|
@@ -85050,6 +85650,7 @@ var SignatureBridge = class {
|
|
|
85050
85650
|
const url2 = new URL(req.url ?? "/", this.mount ? this.mount.origin : `http://127.0.0.1:${this.port}`);
|
|
85051
85651
|
if (req.method === "GET" && url2.pathname === "/") return this.servePage(url2, res);
|
|
85052
85652
|
if (req.method === "GET" && url2.pathname === "/config") return this.serveConfig(url2, res);
|
|
85653
|
+
if (req.method === "GET" && url2.pathname === "/challenge") return this.serveChallenge(url2, res);
|
|
85053
85654
|
if (req.method === "GET" && url2.pathname === "/wc-pairing") return void this.serveWcPairing(url2, res);
|
|
85054
85655
|
if (req.method === "GET" && url2.pathname === "/unlock") return this.serveUnlockPage(url2, res);
|
|
85055
85656
|
if (req.method === "POST" && url2.pathname === "/unlock-submit")
|
|
@@ -85108,9 +85709,17 @@ var SignatureBridge = class {
|
|
|
85108
85709
|
this.deny(res, 429, `too many open approval pages (${MAX_SESSIONS}) \u2014 close one and retry`);
|
|
85109
85710
|
return;
|
|
85110
85711
|
}
|
|
85111
|
-
const sessionId = (0,
|
|
85112
|
-
this.sessions.set(sessionId, {
|
|
85113
|
-
|
|
85712
|
+
const sessionId = (0, import_node_crypto9.randomBytes)(24).toString("hex");
|
|
85713
|
+
this.sessions.set(sessionId, {
|
|
85714
|
+
wallet: null,
|
|
85715
|
+
sse: null,
|
|
85716
|
+
refused: null,
|
|
85717
|
+
lastSeenMs: this.clock(),
|
|
85718
|
+
wcPaired: false,
|
|
85719
|
+
presenceNonce: (0, import_node_crypto9.randomBytes)(16).toString("hex"),
|
|
85720
|
+
provenAccount: null
|
|
85721
|
+
});
|
|
85722
|
+
const page = htmlPageSecurityHeaders(HOUSE_CSP_EXTRA);
|
|
85114
85723
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store", ...page.headers });
|
|
85115
85724
|
res.end(renderApprovalPage(sessionId, page.nonce));
|
|
85116
85725
|
}
|
|
@@ -85120,11 +85729,29 @@ var SignatureBridge = class {
|
|
|
85120
85729
|
res.writeHead(200, { "Content-Type": "application/json", "Cache-Control": "no-store" });
|
|
85121
85730
|
res.end(JSON.stringify({ network: this.network ?? null }));
|
|
85122
85731
|
}
|
|
85732
|
+
/** The origin this bridge is served from — what a presence statement names. */
|
|
85733
|
+
publicOrigin() {
|
|
85734
|
+
return this.mount ? this.mount.origin : `http://127.0.0.1:${this.port}`;
|
|
85735
|
+
}
|
|
85736
|
+
/** The presence statement for this session + chain (session-gated). The page signs exactly
|
|
85737
|
+
* this text in its wallet; the bridge rebuilds it on `hello` rather than trusting any text
|
|
85738
|
+
* the client sends back. */
|
|
85739
|
+
serveChallenge(url2, res) {
|
|
85740
|
+
const session = this.sessionOf(url2.searchParams.get("s"), res);
|
|
85741
|
+
if (!session) return;
|
|
85742
|
+
const chainId = Number(url2.searchParams.get("chainId"));
|
|
85743
|
+
if (!Number.isInteger(chainId)) {
|
|
85744
|
+
this.deny(res, 400, "challenge requires an integer chainId");
|
|
85745
|
+
return;
|
|
85746
|
+
}
|
|
85747
|
+
res.writeHead(200, { "Content-Type": "application/json", "Cache-Control": "no-store" });
|
|
85748
|
+
res.end(JSON.stringify({ statement: presenceStatement(this.publicOrigin(), chainId, session.presenceNonce) }));
|
|
85749
|
+
}
|
|
85123
85750
|
/** WalletConnect pairing (D2, session-gated): lazily boots the WC transport and serves a
|
|
85124
85751
|
* fresh pairing URI. A wallet approving the pairing becomes THE wallet. */
|
|
85125
85752
|
async serveWcPairing(url2, res) {
|
|
85126
85753
|
if (!this.checkSession(url2.searchParams.get("s"), res)) return;
|
|
85127
|
-
|
|
85754
|
+
const askingSession = url2.searchParams.get("s");
|
|
85128
85755
|
if (!this.wcConfig) {
|
|
85129
85756
|
this.deny(res, 404, "WalletConnect is not configured (set DH_WC_PROJECT_ID)");
|
|
85130
85757
|
return;
|
|
@@ -85135,36 +85762,17 @@ var SignatureBridge = class {
|
|
|
85135
85762
|
const { WcTransport: WcTransport2 } = await Promise.resolve().then(() => (init_wc_transport(), wc_transport_exports));
|
|
85136
85763
|
return WcTransport2.create(cfg);
|
|
85137
85764
|
});
|
|
85138
|
-
|
|
85139
|
-
this.wcTransport
|
|
85140
|
-
|
|
85141
|
-
|
|
85142
|
-
|
|
85143
|
-
|
|
85144
|
-
|
|
85145
|
-
|
|
85146
|
-
|
|
85147
|
-
|
|
85148
|
-
}
|
|
85149
|
-
this.wcActive = info !== null;
|
|
85150
|
-
this.wallet = info ? { account: info.account, chainId: info.chainId } : null;
|
|
85151
|
-
if (info && this.pairingSessionId) {
|
|
85152
|
-
const paired = this.sessions.get(this.pairingSessionId);
|
|
85153
|
-
if (paired) paired.wcPaired = true;
|
|
85154
|
-
}
|
|
85155
|
-
if (info === null) {
|
|
85156
|
-
for (const entry of this.pending.values()) {
|
|
85157
|
-
if (!entry.settled && !entry.collect) {
|
|
85158
|
-
this.settle(entry, {
|
|
85159
|
-
status: "invalidated",
|
|
85160
|
-
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"
|
|
85161
|
-
});
|
|
85162
|
-
}
|
|
85163
|
-
}
|
|
85164
|
-
}
|
|
85165
|
-
});
|
|
85765
|
+
const transport = await factory2(this.wcConfig);
|
|
85766
|
+
this.wcTransport = transport;
|
|
85767
|
+
transport.onSession((info) => info === null ? this.onWcDisconnect() : this.admitWcSession(info, transport));
|
|
85768
|
+
}
|
|
85769
|
+
const { uri, pairingId } = await this.wcTransport.createPairing();
|
|
85770
|
+
if (pairingId) {
|
|
85771
|
+
for (const [pending, owner] of this.pairingOwners) {
|
|
85772
|
+
if (owner === askingSession || !this.sessions.has(owner)) this.pairingOwners.delete(pending);
|
|
85773
|
+
}
|
|
85774
|
+
this.pairingOwners.set(pairingId, askingSession);
|
|
85166
85775
|
}
|
|
85167
|
-
const { uri } = await this.wcTransport.createPairing();
|
|
85168
85776
|
const { default: qrcode } = await import("qrcode-generator");
|
|
85169
85777
|
const qr = qrcode(0, "M");
|
|
85170
85778
|
qr.addData(uri);
|
|
@@ -85189,7 +85797,7 @@ var SignatureBridge = class {
|
|
|
85189
85797
|
return;
|
|
85190
85798
|
}
|
|
85191
85799
|
this.unlockToken = null;
|
|
85192
|
-
this.unlockSession = (0,
|
|
85800
|
+
this.unlockSession = (0, import_node_crypto9.randomBytes)(24).toString("hex");
|
|
85193
85801
|
const page = htmlPageSecurityHeaders();
|
|
85194
85802
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store", ...page.headers });
|
|
85195
85803
|
res.end(renderUnlockPage(this.unlockSession, page.nonce));
|
|
@@ -85252,6 +85860,29 @@ var SignatureBridge = class {
|
|
|
85252
85860
|
this.deny(res, 403, refusal);
|
|
85253
85861
|
return;
|
|
85254
85862
|
}
|
|
85863
|
+
const alreadyProven = session.provenAccount !== null && session.provenAccount.toLowerCase() === account.toLowerCase();
|
|
85864
|
+
if (!alreadyProven) {
|
|
85865
|
+
const signature = body["signature"];
|
|
85866
|
+
if (typeof signature !== "string" || signature === "") {
|
|
85867
|
+
this.deny(
|
|
85868
|
+
res,
|
|
85869
|
+
403,
|
|
85870
|
+
`hello requires a signature proving this page controls ${account} \u2014 an address alone proves nothing. Approve the short signing prompt in your wallet (the approval page asks for it on connect); reload the page if it did not appear.`
|
|
85871
|
+
);
|
|
85872
|
+
return;
|
|
85873
|
+
}
|
|
85874
|
+
const statement = presenceStatement(this.publicOrigin(), chainId, session.presenceNonce);
|
|
85875
|
+
const recovered = recoverPresenceSigner(statement, signature);
|
|
85876
|
+
if (recovered === null || recovered.toLowerCase() !== account.toLowerCase()) {
|
|
85877
|
+
this.deny(
|
|
85878
|
+
res,
|
|
85879
|
+
403,
|
|
85880
|
+
`the presence signature was not made by ${account} for this page's statement \u2014 sign the statement the approval page shows with that account (EOA wallets only; contract wallets cannot prove presence here).`
|
|
85881
|
+
);
|
|
85882
|
+
return;
|
|
85883
|
+
}
|
|
85884
|
+
session.provenAccount = account;
|
|
85885
|
+
}
|
|
85255
85886
|
session.wallet = { account, chainId };
|
|
85256
85887
|
this.wallet = { account, chainId };
|
|
85257
85888
|
this.replayPending(session);
|
|
@@ -85293,17 +85924,21 @@ var SignatureBridge = class {
|
|
|
85293
85924
|
if (refusedSwitch) {
|
|
85294
85925
|
this.quarantine(session, switchRefusal);
|
|
85295
85926
|
} else {
|
|
85296
|
-
session.
|
|
85927
|
+
const sameProven = offered !== null && session.provenAccount !== null && offered.account.toLowerCase() === session.provenAccount.toLowerCase();
|
|
85928
|
+
session.wallet = sameProven ? offered : null;
|
|
85297
85929
|
if (this.wallet !== null && prev !== null && this.wallet.account.toLowerCase() === prev.account.toLowerCase()) {
|
|
85298
85930
|
this.wallet = session.wallet;
|
|
85931
|
+
} else if (this.wallet === null && prev === null && session.wallet !== null) {
|
|
85932
|
+
this.wallet = session.wallet;
|
|
85299
85933
|
}
|
|
85300
85934
|
}
|
|
85301
|
-
const
|
|
85302
|
-
|
|
85935
|
+
const reported = refusedSwitch ? null : offered;
|
|
85936
|
+
const unchanged = prev !== null && reported !== null && prev.account.toLowerCase() === reported.account.toLowerCase() && prev.chainId === reported.chainId;
|
|
85937
|
+
if (unchanged || prev === null) {
|
|
85303
85938
|
this.ok(res);
|
|
85304
85939
|
return;
|
|
85305
85940
|
}
|
|
85306
|
-
const reason = refusedSwitch ? "the wallet switched to an account this session is not signed in as" : prev &&
|
|
85941
|
+
const reason = refusedSwitch ? "the wallet switched to an account this session is not signed in as" : prev && reported && prev.account.toLowerCase() !== reported.account.toLowerCase() ? "the wallet account changed while approval was pending" : prev && reported && prev.chainId !== reported.chainId ? "the wallet network changed while approval was pending" : "the wallet disconnected while approval was pending";
|
|
85307
85942
|
for (const entry of this.pending.values()) {
|
|
85308
85943
|
if (entry.settled || entry.collect) continue;
|
|
85309
85944
|
if (this.ownedByWc(entry)) continue;
|
|
@@ -85328,6 +85963,100 @@ var SignatureBridge = class {
|
|
|
85328
85963
|
* Those entries instead fail fast at the per-entry grace, since `attachedFor` now reads
|
|
85329
85964
|
* false for them, and `unattendedReason` says plainly that the phone may already have
|
|
85330
85965
|
* acted. */
|
|
85966
|
+
/**
|
|
85967
|
+
* C-47, the THIRD door: a wallet announced a WalletConnect session. `requestSignature`
|
|
85968
|
+
* PREFERS the WalletConnect wallet over the approval page (see the `wcActive` branch there),
|
|
85969
|
+
* so an account admitted here does not merely become the candidate — it becomes the SIGNER,
|
|
85970
|
+
* and the page that showed its QR becomes the page that sees every card.
|
|
85971
|
+
*
|
|
85972
|
+
* The account a WalletConnect session carries is the wallet's own UNSIGNED claim — the
|
|
85973
|
+
* protocol validates its format, never its ownership. Admitting on that claim let anyone
|
|
85974
|
+
* holding the approval link answer their own QR with a scripted wallet claiming the user's
|
|
85975
|
+
* public address: it took the signer seat, its page saw every card, and an extension-only
|
|
85976
|
+
* user's ceremonies were routed to it (Sentinel 2 PoC-D). So this door now asks for the same
|
|
85977
|
+
* proof `hello` does: the wallet signs the presence statement of the page whose QR it
|
|
85978
|
+
* answered, and the signature must recover to the account it claims.
|
|
85979
|
+
*
|
|
85980
|
+
* Resolves `false` to refuse — the transport then keeps what it held and drops the wallet. If
|
|
85981
|
+
* the wallet declines the proof (or the request fails) the promise rejects and the transport
|
|
85982
|
+
* ends the session unadopted; nothing here is adopted before the proof checks out.
|
|
85983
|
+
*/
|
|
85984
|
+
async admitWcSession(info, transport) {
|
|
85985
|
+
const refusal = this.accountRefusal(info.account);
|
|
85986
|
+
if (refusal) return this.refuseWcSession(refusal);
|
|
85987
|
+
const ownerId = info.pairingId ? this.pairingOwners.get(info.pairingId) : void 0;
|
|
85988
|
+
if (info.pairingId) this.pairingOwners.delete(info.pairingId);
|
|
85989
|
+
const owner = ownerId ? this.sessions.get(ownerId) : void 0;
|
|
85990
|
+
if (!ownerId || !owner) {
|
|
85991
|
+
return this.refuseWcSession(
|
|
85992
|
+
"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"
|
|
85993
|
+
);
|
|
85994
|
+
}
|
|
85995
|
+
if (!info.prove || !info.live) {
|
|
85996
|
+
return this.refuseWcSession(
|
|
85997
|
+
"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"
|
|
85998
|
+
);
|
|
85999
|
+
}
|
|
86000
|
+
const statement = presenceStatement(this.publicOrigin(), info.chainId, owner.presenceNonce);
|
|
86001
|
+
const signature = await info.prove(statement);
|
|
86002
|
+
const recovered = recoverPresenceSigner(statement, signature);
|
|
86003
|
+
if (recovered === null || recovered.toLowerCase() !== info.account.toLowerCase()) {
|
|
86004
|
+
return this.refuseWcSession(
|
|
86005
|
+
`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`
|
|
86006
|
+
);
|
|
86007
|
+
}
|
|
86008
|
+
if (this.wcTransport !== transport) {
|
|
86009
|
+
return this.refuseWcSession("the bridge's WalletConnect connection was replaced while the wallet was proving its account");
|
|
86010
|
+
}
|
|
86011
|
+
if (!info.live()) {
|
|
86012
|
+
return this.refuseWcSession("the wallet's WalletConnect session ended (or the relay failed) while it was proving its account \u2014 scan the QR again");
|
|
86013
|
+
}
|
|
86014
|
+
const lateRefusal = this.accountRefusal(info.account);
|
|
86015
|
+
if (lateRefusal) return this.refuseWcSession(lateRefusal);
|
|
86016
|
+
const page = this.sessions.get(ownerId);
|
|
86017
|
+
if (!page || page.refused) {
|
|
86018
|
+
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");
|
|
86019
|
+
}
|
|
86020
|
+
if (this.wcCreditedSession !== null && this.wcCreditedSession !== ownerId) {
|
|
86021
|
+
const previous = this.sessions.get(this.wcCreditedSession);
|
|
86022
|
+
if (previous) previous.wcPaired = false;
|
|
86023
|
+
}
|
|
86024
|
+
this.wcActive = true;
|
|
86025
|
+
this.wallet = { account: info.account, chainId: info.chainId };
|
|
86026
|
+
page.wcPaired = true;
|
|
86027
|
+
page.provenAccount = info.account;
|
|
86028
|
+
this.wcCreditedSession = ownerId;
|
|
86029
|
+
this.replayPending(page);
|
|
86030
|
+
return true;
|
|
86031
|
+
}
|
|
86032
|
+
/** Refuse a WalletConnect session — see `admitWcSession`. */
|
|
86033
|
+
refuseWcSession(reason) {
|
|
86034
|
+
if (!this.wcActive) {
|
|
86035
|
+
this.rebuildSharedWallet();
|
|
86036
|
+
this.demoteWcEntries();
|
|
86037
|
+
}
|
|
86038
|
+
process.stderr.write(`[bridge] WalletConnect session refused \u2014 ${reason}
|
|
86039
|
+
`);
|
|
86040
|
+
return false;
|
|
86041
|
+
}
|
|
86042
|
+
/** The admitted WalletConnect wallet went away. */
|
|
86043
|
+
onWcDisconnect() {
|
|
86044
|
+
this.wcActive = false;
|
|
86045
|
+
this.wallet = null;
|
|
86046
|
+
for (const entry of this.pending.values()) {
|
|
86047
|
+
if (!entry.settled && !entry.collect) {
|
|
86048
|
+
this.settle(entry, {
|
|
86049
|
+
status: "invalidated",
|
|
86050
|
+
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"
|
|
86051
|
+
});
|
|
86052
|
+
}
|
|
86053
|
+
}
|
|
86054
|
+
if (this.wcCreditedSession !== null) {
|
|
86055
|
+
const credited = this.sessions.get(this.wcCreditedSession);
|
|
86056
|
+
if (credited) credited.wcPaired = false;
|
|
86057
|
+
this.wcCreditedSession = null;
|
|
86058
|
+
}
|
|
86059
|
+
}
|
|
85331
86060
|
demoteWcEntries() {
|
|
85332
86061
|
for (const entry of this.pending.values()) {
|
|
85333
86062
|
if (entry.settled || entry.owner !== "wc" || entry.dispatched) continue;
|
|
@@ -85346,6 +86075,10 @@ var SignatureBridge = class {
|
|
|
85346
86075
|
this.deny(res, 404, "unknown or already-settled requestId");
|
|
85347
86076
|
return;
|
|
85348
86077
|
}
|
|
86078
|
+
if (this.expireIfOverdue(entry)) {
|
|
86079
|
+
this.deny(res, 410, "this request has expired \u2014 retry the operation");
|
|
86080
|
+
return;
|
|
86081
|
+
}
|
|
85349
86082
|
if (entry.request.kind !== "personal-sign") {
|
|
85350
86083
|
this.deny(res, 400, "finalize applies only to personal-sign requests");
|
|
85351
86084
|
return;
|
|
@@ -85372,6 +86105,10 @@ var SignatureBridge = class {
|
|
|
85372
86105
|
this.deny(res, 404, "request settled while finalizing");
|
|
85373
86106
|
return;
|
|
85374
86107
|
}
|
|
86108
|
+
if (this.expireIfOverdue(entry)) {
|
|
86109
|
+
this.deny(res, 410, "this request expired while its payload was being prepared \u2014 retry the operation");
|
|
86110
|
+
return;
|
|
86111
|
+
}
|
|
85375
86112
|
entry.request.personalSign = fresh.personalSign;
|
|
85376
86113
|
entry.request.card = fresh.card;
|
|
85377
86114
|
}
|
|
@@ -85385,6 +86122,10 @@ var SignatureBridge = class {
|
|
|
85385
86122
|
this.deny(res, 404, "unknown or already-settled requestId");
|
|
85386
86123
|
return;
|
|
85387
86124
|
}
|
|
86125
|
+
if (this.expireIfOverdue(entry)) {
|
|
86126
|
+
this.deny(res, 410, "this request has expired \u2014 retry the operation");
|
|
86127
|
+
return;
|
|
86128
|
+
}
|
|
85388
86129
|
if (body["approved"] !== true) {
|
|
85389
86130
|
if (this.ownedByWc(entry) && entry.request.kind === "transaction") {
|
|
85390
86131
|
this.settle(entry, {
|
|
@@ -85433,6 +86174,16 @@ var SignatureBridge = class {
|
|
|
85433
86174
|
this.ok(res);
|
|
85434
86175
|
}
|
|
85435
86176
|
// ---- helpers ----
|
|
86177
|
+
/** Accept-time deadline check. The 1 s sweep is only the backstop: between the deadline and
|
|
86178
|
+
* the next tick a late click on /finalize or /result — or a WalletConnect dispatch — would
|
|
86179
|
+
* otherwise still ask for or accept a signature over a payload the protocol will refuse.
|
|
86180
|
+
* Settles the entry `expired` (the same outcome the sweep gives) and reports it. */
|
|
86181
|
+
expireIfOverdue(entry) {
|
|
86182
|
+
if (entry.settled) return true;
|
|
86183
|
+
if (this.clock() < entry.deadlineMs) return false;
|
|
86184
|
+
this.settle(entry, { status: "expired" });
|
|
86185
|
+
return true;
|
|
86186
|
+
}
|
|
85436
86187
|
settle(entry, outcome) {
|
|
85437
86188
|
entry.settled = true;
|
|
85438
86189
|
this.pending.delete(entry.request.id);
|
|
@@ -85651,7 +86402,7 @@ function createBoundary(config, opts) {
|
|
|
85651
86402
|
"createBoundary(real) is async \u2014 use createRealBoundary() so the write SDK can be built."
|
|
85652
86403
|
);
|
|
85653
86404
|
}
|
|
85654
|
-
const configFingerprint = (0,
|
|
86405
|
+
const configFingerprint = (0, import_node_crypto10.createHash)("sha256").update(JSON.stringify({ adapter: config.adapter, latency: config.latency, db: config.mockDb, signer: config.signer ?? "auto" })).digest("hex").slice(0, 12);
|
|
85655
86406
|
if (opts?.ceremony) {
|
|
85656
86407
|
const plugin2 = new MockUpstreamPlugin(config, { ceremony: opts.ceremony });
|
|
85657
86408
|
const boundary2 = new BoundaryCore({
|
|
@@ -85814,6 +86565,7 @@ async function createRealBoundary(config, wallet, overrides) {
|
|
|
85814
86565
|
const manager = new SignerManager({
|
|
85815
86566
|
persistence: overrides?.signerPersistence?.(config.network) ?? fileSignerPersistence(stateFile),
|
|
85816
86567
|
initialMode,
|
|
86568
|
+
...overrides?.boundBorrower ? { authenticatedBorrower: import_ethers53.ethers.getAddress(overrides.boundBorrower) } : {},
|
|
85817
86569
|
candidate: () => bridge.walletState()?.account ?? null,
|
|
85818
86570
|
pendingCeremonies: () => bridge.pendingCount(),
|
|
85819
86571
|
keystore
|
|
@@ -85825,7 +86577,7 @@ async function createRealBoundary(config, wallet, overrides) {
|
|
|
85825
86577
|
}
|
|
85826
86578
|
const plugin = new RealUpstreamPlugin(config, wallet, { manager, bridge, keystore });
|
|
85827
86579
|
await plugin.initWriteSdk();
|
|
85828
|
-
const configFingerprint = (0,
|
|
86580
|
+
const configFingerprint = (0, import_node_crypto10.createHash)("sha256").update(JSON.stringify({ adapter: config.adapter, network: config.network, ops: config.serviceEndpoint })).digest("hex").slice(0, 12);
|
|
85829
86581
|
const capabilities = () => ({
|
|
85830
86582
|
reads: {
|
|
85831
86583
|
public: true,
|
|
@@ -85909,8 +86661,8 @@ async function buildBoundary(configResult, overrides) {
|
|
|
85909
86661
|
);
|
|
85910
86662
|
}
|
|
85911
86663
|
try {
|
|
85912
|
-
const decrypted = await
|
|
85913
|
-
if (!(decrypted instanceof
|
|
86664
|
+
const decrypted = await import_ethers54.ethers.Wallet.fromEncryptedJson(keystoreJson, config.keystorePassword);
|
|
86665
|
+
if (!(decrypted instanceof import_ethers54.ethers.Wallet)) {
|
|
85914
86666
|
return bootError("DH_KEYSTORE_PATH did not decrypt to an EOA wallet keystore.", ["DH_KEYSTORE_PATH"]);
|
|
85915
86667
|
}
|
|
85916
86668
|
wallet = decrypted;
|
|
@@ -86390,7 +87142,7 @@ on the real adapter and the mock.
|
|
|
86390
87142
|
**The walkthrough:**
|
|
86391
87143
|
1. \`signer_setup\` action \`use\`, mode \`external\`. The approval page auto-opens in the
|
|
86392
87144
|
desktop browser; ${approvalPageLocation(d)}
|
|
86393
|
-
2. On the page: connect the browser extension${d.walletConnect ? ", or \u2014 for a mobile wallet \u2014 scan the\n WalletConnect QR code or paste the pairing code. KEEP
|
|
87145
|
+
2. On the page: connect the browser extension${d.walletConnect ? ", or \u2014 for a mobile wallet \u2014 scan the\n WalletConnect QR code or paste the pairing code, then sign the short statement the wallet\n shows: it proves the wallet holds the address it reports, approves nothing and moves no\n funds, and without it the phone is not accepted. The proof needs an ordinary wallet account\n (EOA): a smart-contract or smart-account wallet cannot produce it, so it cannot connect\n here. KEEP THAT APPROVAL PAGE OPEN \u2014 the one\n whose QR you scanned: while a phone wallet is connected it is the READ-ONLY reader for\n every ceremony \u2014 it shows the full card, the phone shows only what a wallet can render,\n and you approve or decline in the phone. (Cancel still works from the page.) With no\n such page open, the phone is NOT asked to sign the opaque 32-byte hashes (loan and withdrawal\n envelopes) \u2014 those refuse, because a wallet shows them as a bare hash. Plain transactions and\n typed-data are not gated: the wallet decodes those itself." : ". " + phoneWalletOffer(d) + "."}
|
|
86394
87146
|
3. For authenticated reads before any write: \`signer_setup\` action \`connect\` runs the
|
|
86395
87147
|
login ceremony explicitly (one typed-data signature in the wallet).
|
|
86396
87148
|
4. The FIRST verified signature binds that wallet address as the borrower \u2014 it persists
|
|
@@ -86778,7 +87530,9 @@ plus one lit-ops login signature (read access). After that, every operation that
|
|
|
86778
87530
|
funds asks for its OWN approval in the user's wallet, every time \u2014 and reads never pop
|
|
86779
87531
|
the wallet. The login session lives ONLY in the server's memory: a server restart, or
|
|
86780
87532
|
an idle spell long enough that the tenant's world is evicted, means signing in again.
|
|
86781
|
-
That is the flip side of
|
|
87533
|
+
That is the flip side of never storing a login session at rest \u2014 a re-login is normal,
|
|
87534
|
+
not a fault. (The connector's own sign-in is a separate grant; /auth.md states whether
|
|
87535
|
+
this deployment keeps it across restarts.)
|
|
86782
87536
|
|
|
86783
87537
|
**What the hosted server IS trusted with** (the six residual trusts \u2014 state them
|
|
86784
87538
|
honestly when asked "is this safe"):
|
|
@@ -87047,7 +87801,7 @@ var import_mcp2 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
|
87047
87801
|
|
|
87048
87802
|
// src/tools/loan.ts
|
|
87049
87803
|
var import_zod = require("zod");
|
|
87050
|
-
var
|
|
87804
|
+
var import_ethers55 = require("ethers");
|
|
87051
87805
|
|
|
87052
87806
|
// src/util/format.ts
|
|
87053
87807
|
function bigintReplacer(_key, value) {
|
|
@@ -87235,7 +87989,7 @@ function registerLoanTools(server, getB, adapter2 = "real") {
|
|
|
87235
87989
|
const b = getB();
|
|
87236
87990
|
if (!b.ok) return renderError(b.error);
|
|
87237
87991
|
return renderEnvelope(
|
|
87238
|
-
await b.boundary.mintUcd({ positionId, amountUcdWei: (0,
|
|
87992
|
+
await b.boundary.mintUcd({ positionId, amountUcdWei: (0, import_ethers55.parseEther)(amountUcd.toString()).toString() })
|
|
87239
87993
|
);
|
|
87240
87994
|
})
|
|
87241
87995
|
);
|
|
@@ -87273,7 +88027,7 @@ function registerLoanTools(server, getB, adapter2 = "real") {
|
|
|
87273
88027
|
if (BigInt(detail.data.debtUcdWei) === 0n) return validationFailed("the position has no outstanding debt");
|
|
87274
88028
|
amountUcdWei = detail.data.debtUcdWei;
|
|
87275
88029
|
} else {
|
|
87276
|
-
amountUcdWei = (0,
|
|
88030
|
+
amountUcdWei = (0, import_ethers55.parseEther)(amountUcd.toString()).toString();
|
|
87277
88031
|
}
|
|
87278
88032
|
return renderEnvelope(await b.boundary.repayUcd({ positionId, amountUcdWei }));
|
|
87279
88033
|
})
|
|
@@ -87876,7 +88630,7 @@ function registerMockControlTool(server, control, chainId = 1337) {
|
|
|
87876
88630
|
|
|
87877
88631
|
// src/tools/signer.ts
|
|
87878
88632
|
var import_zod6 = require("zod");
|
|
87879
|
-
var
|
|
88633
|
+
var import_ethers56 = require("ethers");
|
|
87880
88634
|
var MODES = ["external", "keystore", "safe", "safe-module", "mock-simulated"];
|
|
87881
88635
|
var ACTIONS2 = ["status", "use", "reset-borrower", "unlock-keystore", "connect", "disconnect"];
|
|
87882
88636
|
var EXTERNAL_ONLY_MODES = ["external"];
|
|
@@ -87918,7 +88672,7 @@ function registerSignerTool(server, getRuntime, opts) {
|
|
|
87918
88672
|
if (mode !== void 0 && !offeredModes.includes(mode)) {
|
|
87919
88673
|
return validationFailed(looksSecretShaped(mode) ? SECRET_REFUSAL : `mode '${mode}' is not one of: ${offeredModes.join(" | ")}`);
|
|
87920
88674
|
}
|
|
87921
|
-
if (safeAddress !== void 0 && !
|
|
88675
|
+
if (safeAddress !== void 0 && !import_ethers56.ethers.isAddress(safeAddress)) {
|
|
87922
88676
|
return validationFailed(looksSecretShaped(safeAddress) ? SECRET_REFUSAL : `'${safeAddress}' is not a valid Safe address`);
|
|
87923
88677
|
}
|
|
87924
88678
|
if (action === "status") {
|
|
@@ -87929,9 +88683,9 @@ function registerSignerTool(server, getRuntime, opts) {
|
|
|
87929
88683
|
// Plan 16 A3 — provenance honesty: the assistant must never guess HOW an
|
|
87930
88684
|
// identity is known. borrower = a persisted binding; candidate = a live
|
|
87931
88685
|
// wallet connection in THIS process only.
|
|
87932
|
-
identityProvenance: s.borrower !== null ? `borrower ${s.borrower} is a PERSISTED binding (survives restarts until 'disconnect' or 'reset-borrower')` + (s.candidate !== null ? `; candidate ${s.candidate} is a LIVE wallet connection (approval page / WalletConnect, this process only)` : "") : s.candidate !== null ? `no borrower is bound; candidate ${s.candidate} is a LIVE wallet connection (approval page / WalletConnect, this process only) \u2014 the first verified signature binds it` : "no borrower is bound and no wallet is connected",
|
|
88686
|
+
identityProvenance: manager.identityPinned() ? `borrower ${s.borrower} is the wallet that signed this connector's login \u2014 it is your borrowing identity for this session and cannot be swapped, and only this wallet can approve writes` + (s.candidate !== null ? `; candidate ${s.candidate} is a LIVE wallet connection (approval page / WalletConnect, this process only)` : "") : s.borrower !== null ? `borrower ${s.borrower} is a PERSISTED binding (survives restarts until 'disconnect' or 'reset-borrower')` + (s.candidate !== null ? `; candidate ${s.candidate} is a LIVE wallet connection (approval page / WalletConnect, this process only)` : "") : s.candidate !== null ? `no borrower is bound; candidate ${s.candidate} is a LIVE wallet connection (approval page / WalletConnect, this process only) \u2014 the first verified signature binds it` : "no borrower is bound and no wallet is connected",
|
|
87933
88687
|
approvalPageUrl: bridge.url(),
|
|
87934
|
-
hint: s.mode === "none" ? manager.invitation() + (s.keystoreConfigured ? " Note: keystore material IS already configured \u2014 choosing 'keystore' (or 'safe') unlocks it automatically; the unlock page is only for NEW material." : "") : s.mode === "external" && !s.borrower && !s.candidate ? "External mode: open the approval page URL above and connect your wallet \u2014 it becomes your borrowing identity." : !s.keystoreUnlocked && s.keystoreConfigured ? `Active mode: ${s.mode}. Keystore material is configured \u2014 'use keystore' unlocks it automatically; the unlock page is only for NEW material.` : `Active mode: ${s.mode}. Writes still require confirmed:true, always.`
|
|
88688
|
+
hint: s.mode === "none" ? manager.invitation() + (s.keystoreConfigured ? " Note: keystore material IS already configured \u2014 choosing 'keystore' (or 'safe') unlocks it automatically; the unlock page is only for NEW material." : "") : s.mode === "external" && !s.borrower && !s.candidate ? "External mode: open the approval page URL above and connect your wallet \u2014 it becomes your borrowing identity." : s.mode === "external" && manager.identityPinned() && !s.candidate ? `Signed in as ${s.borrower}. Chain reads work now (position_status by id, protocol_status, btc_price). Listing positions (position_list borrower=${s.borrower}) goes through the authenticated indexer proxy and needs a lit-ops login: open the approval page URL above, connect THIS wallet (any other is refused), then run signer_setup 'connect' \u2014 one login signature that moves nothing. The same connected wallet approves writes.` : !s.keystoreUnlocked && s.keystoreConfigured ? `Active mode: ${s.mode}. Keystore material is configured \u2014 'use keystore' unlocks it automatically; the unlock page is only for NEW material.` : `Active mode: ${s.mode}. Writes still require confirmed:true, always.`
|
|
87935
88689
|
});
|
|
87936
88690
|
}
|
|
87937
88691
|
if (action === "use") {
|
|
@@ -88008,6 +88762,11 @@ function registerSignerTool(server, getRuntime, opts) {
|
|
|
88008
88762
|
});
|
|
88009
88763
|
}
|
|
88010
88764
|
if (action === "reset-borrower") {
|
|
88765
|
+
if (manager.identityPinned()) {
|
|
88766
|
+
return validationFailed(
|
|
88767
|
+
`the borrowing identity is ${manager.boundBorrower()} \u2014 the wallet that signed this connector's login \u2014 and cannot be swapped here. To act as a different wallet, sign in to the connector again with that wallet.`
|
|
88768
|
+
);
|
|
88769
|
+
}
|
|
88011
88770
|
manager.resetBorrower();
|
|
88012
88771
|
return ok({
|
|
88013
88772
|
reset: true,
|
|
@@ -88403,8 +89162,16 @@ function requireSafeCount(value, fallback, name, min) {
|
|
|
88403
89162
|
return value;
|
|
88404
89163
|
}
|
|
88405
89164
|
var RATE_WINDOW_MS = 60 * 1e3;
|
|
89165
|
+
function assertWcLegComposable(opts) {
|
|
89166
|
+
assertWcMinSafeVersion(
|
|
89167
|
+
opts.serverVersion ?? SERVER_VERSION,
|
|
89168
|
+
opts.siweWc !== void 0 || resolvedWcProjectId(opts.env) !== void 0
|
|
89169
|
+
);
|
|
89170
|
+
resolveWcLimits(opts.siweWcLimits);
|
|
89171
|
+
}
|
|
88406
89172
|
function composeConnector(opts, rawPublicOrigin) {
|
|
88407
89173
|
const publicOrigin = normalizePublicOrigin(rawPublicOrigin);
|
|
89174
|
+
assertWcLegComposable(opts);
|
|
88408
89175
|
const allowedNetworks = opts.allowedNetworks ?? ["sepolia"];
|
|
88409
89176
|
if (allowedNetworks.length === 0) throw new Error("connector service: allowedNetworks must name at least one network");
|
|
88410
89177
|
const launchNetwork = allowedNetworks[0];
|
|
@@ -88446,7 +89213,7 @@ function composeConnector(opts, rawPublicOrigin) {
|
|
|
88446
89213
|
}
|
|
88447
89214
|
async function buildWorld(tenantKey) {
|
|
88448
89215
|
const stores = /* @__PURE__ */ new Map();
|
|
88449
|
-
const mountId = (0,
|
|
89216
|
+
const mountId = (0, import_node_crypto11.randomUUID)().replaceAll("-", "");
|
|
88450
89217
|
const overrides = {
|
|
88451
89218
|
externalOnly: true,
|
|
88452
89219
|
allowedNetworks,
|
|
@@ -88725,7 +89492,7 @@ function composeConnector(opts, rawPublicOrigin) {
|
|
|
88725
89492
|
}
|
|
88726
89493
|
const mcp = createServer2(world.deps, CONNECTOR_INSTRUCTIONS);
|
|
88727
89494
|
const transport = new import_streamableHttp.StreamableHTTPServerTransport({
|
|
88728
|
-
sessionIdGenerator: () => (0,
|
|
89495
|
+
sessionIdGenerator: () => (0, import_node_crypto11.randomUUID)(),
|
|
88729
89496
|
onsessioninitialized: (sessionId) => {
|
|
88730
89497
|
evictExcessSessions(tenantKey);
|
|
88731
89498
|
sessions.set(sessionId, { transport, tenant: tenantKey, lastSeen: clock() });
|
|
@@ -88769,7 +89536,7 @@ function composeConnector(opts, rawPublicOrigin) {
|
|
|
88769
89536
|
return;
|
|
88770
89537
|
}
|
|
88771
89538
|
const p = (req.originalUrl ?? req.url).split("?")[0].toLowerCase();
|
|
88772
|
-
const sensitive = ["/mcp", "/token", "/register", "/revoke", "/authorize"].some(
|
|
89539
|
+
const sensitive = ["/mcp", "/token", "/register", "/revoke", "/authorize", "/account"].some(
|
|
88773
89540
|
(r) => p === r || p.startsWith(`${r}/`)
|
|
88774
89541
|
);
|
|
88775
89542
|
if (!sensitive) {
|
|
@@ -88805,9 +89572,12 @@ function composeConnector(opts, rawPublicOrigin) {
|
|
|
88805
89572
|
origin: () => publicOrigin,
|
|
88806
89573
|
chainId: launchNetwork === "mainnet" ? 1 : 11155111,
|
|
88807
89574
|
...wcLeg ? { wc: wcLeg } : {},
|
|
89575
|
+
...opts.siweWcLimits ? { wcLimits: opts.siweWcLimits } : {},
|
|
89576
|
+
...opts.oauthStore ? { store: opts.oauthStore } : {},
|
|
88808
89577
|
...opts.clock ? { clock: opts.clock } : {}
|
|
88809
89578
|
});
|
|
88810
89579
|
siweRef = siwe;
|
|
89580
|
+
mountAccountApi(app, siwe, opts.account);
|
|
88811
89581
|
app.post("/authorize/siwe-message", import_express.default.json(), (req, res) => {
|
|
88812
89582
|
const b = req.body;
|
|
88813
89583
|
const r = siwe.siweMessage(String(b.flowId ?? ""), String(b.address ?? ""));
|
|
@@ -88828,7 +89598,12 @@ function composeConnector(opts, rawPublicOrigin) {
|
|
|
88828
89598
|
});
|
|
88829
89599
|
app.post("/authorize/wc-pairing", import_express.default.json(), (req, res) => {
|
|
88830
89600
|
const b = req.body;
|
|
88831
|
-
|
|
89601
|
+
const ip = req.ip;
|
|
89602
|
+
if (ip === void 0) {
|
|
89603
|
+
res.status(400).json({ reason: "cannot determine the requesting network address - mobile wallet sign-in refused" });
|
|
89604
|
+
return;
|
|
89605
|
+
}
|
|
89606
|
+
void siwe.wcPairing(String(b.flowId ?? ""), ip).then((r) => {
|
|
88832
89607
|
if (!r.ok) res.status(r.status).json({ reason: r.reason });
|
|
88833
89608
|
else res.json({ uri: r.uri, qrSvg: r.qrSvg });
|
|
88834
89609
|
}).catch((e) => {
|
|
@@ -88842,7 +89617,8 @@ function composeConnector(opts, rawPublicOrigin) {
|
|
|
88842
89617
|
const authMd = renderAuthMd({
|
|
88843
89618
|
publicOrigin,
|
|
88844
89619
|
networks: allowedNetworks,
|
|
88845
|
-
walletConnectEnabled: wcLeg !== void 0
|
|
89620
|
+
walletConnectEnabled: wcLeg !== void 0,
|
|
89621
|
+
grants: { durable: opts.oauthStore !== void 0, accountApi: opts.account !== void 0 }
|
|
88846
89622
|
});
|
|
88847
89623
|
app.get("/auth.md", (_req, res) => {
|
|
88848
89624
|
res.setHeader("X-Content-Type-Options", "nosniff");
|
|
@@ -88872,10 +89648,10 @@ function composeConnector(opts, rawPublicOrigin) {
|
|
|
88872
89648
|
})
|
|
88873
89649
|
);
|
|
88874
89650
|
authImpl = {
|
|
88875
|
-
tenant(req) {
|
|
89651
|
+
async tenant(req) {
|
|
88876
89652
|
const header = req.headers.authorization;
|
|
88877
89653
|
if (typeof header !== "string" || !header.startsWith("Bearer ")) return null;
|
|
88878
|
-
const info = siwe.lookupAccessToken(header.slice("Bearer ".length));
|
|
89654
|
+
const info = await siwe.lookupAccessToken(header.slice("Bearer ".length));
|
|
88879
89655
|
const address = info?.extra?.["address"];
|
|
88880
89656
|
return typeof address === "string" ? { address } : null;
|
|
88881
89657
|
}
|
|
@@ -88916,6 +89692,64 @@ function composeConnector(opts, rawPublicOrigin) {
|
|
|
88916
89692
|
}
|
|
88917
89693
|
};
|
|
88918
89694
|
}
|
|
89695
|
+
function mountAccountApi(app, siwe, account) {
|
|
89696
|
+
const allowed = new Set(account?.appOrigins ?? []);
|
|
89697
|
+
app.use("/account", (req, res, next) => {
|
|
89698
|
+
const origin2 = req.headers.origin;
|
|
89699
|
+
if (typeof origin2 === "string" && allowed.has(origin2)) {
|
|
89700
|
+
res.setHeader("Access-Control-Allow-Origin", origin2);
|
|
89701
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
89702
|
+
res.setHeader("Access-Control-Allow-Headers", "Authorization, Content-Type");
|
|
89703
|
+
res.setHeader("Access-Control-Max-Age", "600");
|
|
89704
|
+
}
|
|
89705
|
+
res.setHeader("Vary", "Origin");
|
|
89706
|
+
res.setHeader("Cache-Control", "no-store");
|
|
89707
|
+
if (req.method === "OPTIONS") {
|
|
89708
|
+
res.status(204).end();
|
|
89709
|
+
return;
|
|
89710
|
+
}
|
|
89711
|
+
next();
|
|
89712
|
+
});
|
|
89713
|
+
const fail = (res, status, error, reason) => {
|
|
89714
|
+
res.status(status).json({ error, reason });
|
|
89715
|
+
};
|
|
89716
|
+
const identify = async (req, res) => {
|
|
89717
|
+
if (!account) {
|
|
89718
|
+
fail(res, 501, "not_configured", "the account API is not configured on this deployment (no app identity verifier)");
|
|
89719
|
+
return null;
|
|
89720
|
+
}
|
|
89721
|
+
const header = req.headers.authorization;
|
|
89722
|
+
if (typeof header !== "string" || !header.startsWith("Bearer ") || header.length === "Bearer ".length) {
|
|
89723
|
+
fail(res, 401, "unauthorized", "missing app session \u2014 send the app's Firebase ID token as 'Authorization: Bearer <token>'");
|
|
89724
|
+
return null;
|
|
89725
|
+
}
|
|
89726
|
+
const who = await account.verifier.verify(header.slice("Bearer ".length));
|
|
89727
|
+
if (!who.ok) {
|
|
89728
|
+
fail(res, 401, "unauthorized", who.reason);
|
|
89729
|
+
return null;
|
|
89730
|
+
}
|
|
89731
|
+
return who.address;
|
|
89732
|
+
};
|
|
89733
|
+
app.get("/account/grants", (req, res) => {
|
|
89734
|
+
void (async () => {
|
|
89735
|
+
const address = await identify(req, res);
|
|
89736
|
+
if (address === null) return;
|
|
89737
|
+
res.json({ address, grants: await siwe.listGrants(address) });
|
|
89738
|
+
})().catch((e) => fail(res, 503, "store_error", `the connection store failed: ${e instanceof Error ? e.message : String(e)}`));
|
|
89739
|
+
});
|
|
89740
|
+
app.post("/account/grants/:id/revoke", (req, res) => {
|
|
89741
|
+
void (async () => {
|
|
89742
|
+
const address = await identify(req, res);
|
|
89743
|
+
if (address === null) return;
|
|
89744
|
+
const id = String(req.params["id"]);
|
|
89745
|
+
if (!await siwe.revokeGrantForAddress(address, id)) {
|
|
89746
|
+
fail(res, 404, "not_found", `no live connection '${id}' belongs to ${address}`);
|
|
89747
|
+
return;
|
|
89748
|
+
}
|
|
89749
|
+
res.json({ revoked: true, id });
|
|
89750
|
+
})().catch((e) => fail(res, 503, "store_error", `the connection store failed: ${e instanceof Error ? e.message : String(e)}`));
|
|
89751
|
+
});
|
|
89752
|
+
}
|
|
88919
89753
|
var CONNECTOR_PATH_PREFIXES = [
|
|
88920
89754
|
"/mcp",
|
|
88921
89755
|
"/approval/",
|