@gvnrdao/dh-mcp 0.5.12 → 0.5.14
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 +311 -24
- package/dist/connector-embed.js +432 -61
- package/dist/connector.js +432 -61
- package/dist/index.js +426 -61
- package/package.json +2 -2
package/dist/connector.js
CHANGED
|
@@ -41030,7 +41030,7 @@ function htmlPageSecurityHeaders(extra) {
|
|
|
41030
41030
|
}
|
|
41031
41031
|
|
|
41032
41032
|
// src/version.ts
|
|
41033
|
-
var SERVER_VERSION = "0.5.
|
|
41033
|
+
var SERVER_VERSION = "0.5.14";
|
|
41034
41034
|
|
|
41035
41035
|
// src/connector/siwe-oauth.ts
|
|
41036
41036
|
var import_node_crypto2 = require("crypto");
|
|
@@ -42483,6 +42483,22 @@ var BoundaryCore = class {
|
|
|
42483
42483
|
if (!r.ok) return errEnvelope(failureToError(r.failure));
|
|
42484
42484
|
return okEnvelope({ releasedSats: r.value.releasedSats }, r.source);
|
|
42485
42485
|
}
|
|
42486
|
+
/** C-46. Unlike `recoverStaleSpend` this is NOT permissionless: re-running phase 2 signs
|
|
42487
|
+
* for the vault, so it takes the same borrower gate every fund-moving op takes. */
|
|
42488
|
+
async retryWithdrawExecute(p) {
|
|
42489
|
+
const auth = await this.requireBorrower();
|
|
42490
|
+
if (!auth.ok) return errEnvelope(auth.error);
|
|
42491
|
+
const r = await this.deps.plugin.ops.retryWithdrawExecute({
|
|
42492
|
+
positionId: p.positionId,
|
|
42493
|
+
networkFeeSats: p.networkFeeSats,
|
|
42494
|
+
borrower: auth.borrower
|
|
42495
|
+
});
|
|
42496
|
+
if (!r.ok) return errEnvelope(failureToError(r.failure));
|
|
42497
|
+
return okEnvelope(
|
|
42498
|
+
{ attempted: r.value.attempted, transfers: r.value.transfers, ...r.value.authorization ? { authorization: r.value.authorization } : {} },
|
|
42499
|
+
r.source
|
|
42500
|
+
);
|
|
42501
|
+
}
|
|
42486
42502
|
// ---- meta ----
|
|
42487
42503
|
world() {
|
|
42488
42504
|
return {
|
|
@@ -43306,6 +43322,78 @@ var World = class {
|
|
|
43306
43322
|
c.authorizedSpends.splice(idx, 1);
|
|
43307
43323
|
return { ok: true, value: { releasedSats: spend.satoshis } };
|
|
43308
43324
|
}
|
|
43325
|
+
/**
|
|
43326
|
+
* C-46: re-run the withdrawal EXECUTE leg for reservations whose coins have not been
|
|
43327
|
+
* observed moving (`consumed === null`). This is the stranded shape: phase 1 committed
|
|
43328
|
+
* the reservation, phase 2's quantum-stamped signature expired, and the outpoint was
|
|
43329
|
+
* never spent.
|
|
43330
|
+
*
|
|
43331
|
+
* The retry BROADCASTS; it does not observe. `consumed` therefore stays null — that flag
|
|
43332
|
+
* means "seen consumed on Bitcoin", and only MockControl.confirmSpendConsumed (standing
|
|
43333
|
+
* in for the chain) may set it. Conflating the two would let a retry release collateral
|
|
43334
|
+
* against a transaction no one has confirmed, which is the mistake the whole
|
|
43335
|
+
* proof-of-consumption design exists to prevent. So a retry leaves the reservation
|
|
43336
|
+
* holding its balance exactly as before; what it produces is the txid that can LATER
|
|
43337
|
+
* become the invalidator — the proof the stranded state could never generate for itself.
|
|
43338
|
+
*/
|
|
43339
|
+
retryWithdrawExecute(p) {
|
|
43340
|
+
const paused = this.pausedReason();
|
|
43341
|
+
if (paused) return { ok: false, reason: paused };
|
|
43342
|
+
const pos = this.state.positions[p.positionId];
|
|
43343
|
+
if (!pos) return { ok: false, reason: `position ${p.positionId} does not exist` };
|
|
43344
|
+
if (pos.borrower.toLowerCase() !== p.borrower.toLowerCase()) {
|
|
43345
|
+
return { ok: false, reason: `caller ${p.borrower} is not the borrower of this position` };
|
|
43346
|
+
}
|
|
43347
|
+
const fee = BigInt(p.networkFeeSats);
|
|
43348
|
+
const transfers = this.pendingSpends(p.positionId).map((spend) => {
|
|
43349
|
+
const utxoIdentifier = `${spend.txid}:${spend.vout}`;
|
|
43350
|
+
const refusal = this.retryFeeRefusal(spend, p.networkFeeSats);
|
|
43351
|
+
if (refusal) return { utxoIdentifier, ok: false, error: refusal };
|
|
43352
|
+
const { hash: txid } = this.nextId("btc-withdraw-retry");
|
|
43353
|
+
return {
|
|
43354
|
+
utxoIdentifier,
|
|
43355
|
+
ok: true,
|
|
43356
|
+
txid,
|
|
43357
|
+
// NET of the fee: what the destination actually receives. The fee is carved OUT of
|
|
43358
|
+
// the authorized amount, never added on top — the same semantics `withdraw` above
|
|
43359
|
+
// models and `IBTCSpendAuthorizer` enforces (the recipient receives
|
|
43360
|
+
// targetAmount − networkFee). Reporting the gross figure as "sent" would hide
|
|
43361
|
+
// whether the fee was honoured at all.
|
|
43362
|
+
amountSentSats: (BigInt(spend.satoshis) - fee).toString(),
|
|
43363
|
+
destination: spend.targetAddress
|
|
43364
|
+
};
|
|
43365
|
+
});
|
|
43366
|
+
return { ok: true, value: { attempted: transfers.length, transfers } };
|
|
43367
|
+
}
|
|
43368
|
+
/** Reservations whose coins have not been observed moving — the set phase 2 re-executes. */
|
|
43369
|
+
pendingSpends(positionId) {
|
|
43370
|
+
return (this.state.collateral[positionId]?.authorizedSpends ?? []).filter((s) => s.consumed === null);
|
|
43371
|
+
}
|
|
43372
|
+
/**
|
|
43373
|
+
* The fee cap the SDK applies to a reservation BEFORE it signs anything
|
|
43374
|
+
* (`diamond-hands-sdk.ts` `executeBTCWithdrawal`, above `buildBtcExecuteEnvelope`):
|
|
43375
|
+
*
|
|
43376
|
+
* if (request.networkFee * 2 >= request.targetAmount) { … refuse … }
|
|
43377
|
+
*
|
|
43378
|
+
* — audit M-E, a griefing cap, deliberately far tighter than "leaves something to send".
|
|
43379
|
+
* A reservation's `satoshis` here IS the authorized `targetAmount`, so the same arithmetic
|
|
43380
|
+
* applies per reservation. Returns the refusal, or null when phase 2 would proceed.
|
|
43381
|
+
*/
|
|
43382
|
+
retryFeeRefusal(spend, networkFeeSats) {
|
|
43383
|
+
const target = BigInt(spend.satoshis);
|
|
43384
|
+
if (BigInt(networkFeeSats) * 2n >= target) {
|
|
43385
|
+
return `network fee ${networkFeeSats} sats is \u2265 50% of the ${target.toString()}-sat authorized amount on ${spend.txid}:${spend.vout} \u2014 the fee comes OUT of the authorized amount, and the protocol refuses to broadcast above that cap (real Bitcoin fees are typically <1% of value)`;
|
|
43386
|
+
}
|
|
43387
|
+
return null;
|
|
43388
|
+
}
|
|
43389
|
+
/**
|
|
43390
|
+
* How many of this position's outstanding reservations phase 2 would actually attempt at
|
|
43391
|
+
* this fee. Zero means the SDK never reaches `executeBTCWithdrawal`'s signing step, so the
|
|
43392
|
+
* wallet is never opened — which is what the mock's ceremony gate reads.
|
|
43393
|
+
*/
|
|
43394
|
+
retryExecutableCount(positionId, networkFeeSats) {
|
|
43395
|
+
return this.pendingSpends(positionId).filter((s) => this.retryFeeRefusal(s, networkFeeSats) === null).length;
|
|
43396
|
+
}
|
|
43309
43397
|
// ---- Mock Safes (plan 06): REAL verification semantics, no fakes (M6-21/27) ----
|
|
43310
43398
|
safesMap() {
|
|
43311
43399
|
return this.state.safes;
|
|
@@ -44500,7 +44588,8 @@ var MockUpstreamPlugin = class {
|
|
|
44500
44588
|
const r = this.world.recoverStaleSpend(p);
|
|
44501
44589
|
if (!r.ok) return this.rejected("recoverStaleSpend", r.reason);
|
|
44502
44590
|
return upOk({ txRef: this.world.nextTxRef(), releasedSats: r.value.releasedSats }, this.src("mock-ops"));
|
|
44503
|
-
})
|
|
44591
|
+
}),
|
|
44592
|
+
retryWithdrawExecute: (p) => this.opRetryWithdrawExecute(p)
|
|
44504
44593
|
};
|
|
44505
44594
|
}
|
|
44506
44595
|
indexer;
|
|
@@ -44775,6 +44864,46 @@ var MockUpstreamPlugin = class {
|
|
|
44775
44864
|
);
|
|
44776
44865
|
});
|
|
44777
44866
|
}
|
|
44867
|
+
/**
|
|
44868
|
+
* C-46 retry, and it takes the SAME ceremony `opWithdraw` takes.
|
|
44869
|
+
*
|
|
44870
|
+
* The first version of this op skipped all three gates: no `noneRefusal`, no wallet
|
|
44871
|
+
* ceremony, no `applyAuthorized`. It moved mock BTC on nothing but `confirmed: true`, so a
|
|
44872
|
+
* user who DECLINED in their wallet still saw the retry succeed. The real adapter does sign
|
|
44873
|
+
* — the SDK's phase 2 raises the blind-hash card before it broadcasts — so the mock was
|
|
44874
|
+
* passing requests the real protocol would refuse, which is the one thing a practice world
|
|
44875
|
+
* must never do.
|
|
44876
|
+
*
|
|
44877
|
+
* The ceremony is nonetheless PREFLIGHTED, because the SDK signs strictly less often than
|
|
44878
|
+
* "once per call": `executePendingBtcTransfers` reads the authorizer and `return []`s on an
|
|
44879
|
+
* empty set without entering `executeBTCWithdrawal` at all, and `executeBTCWithdrawal`'s own
|
|
44880
|
+
* fee cap refuses above `buildBtcExecuteEnvelope` — the only thing that touches the signer.
|
|
44881
|
+
* So a retry with nothing executable opens NO wallet on the real adapter, and a mock that
|
|
44882
|
+
* raised a ceremony there would teach a user to approve a popup the protocol never shows.
|
|
44883
|
+
*/
|
|
44884
|
+
async opRetryWithdrawExecute(p) {
|
|
44885
|
+
const none = this.noneRefusal();
|
|
44886
|
+
if (none) return none;
|
|
44887
|
+
const executable = this.world.retryExecutableCount(p.positionId, p.networkFeeSats);
|
|
44888
|
+
const card = `re-run the BTC withdrawal EXECUTE step for ${executable} outstanding reservation(s) on ${p.positionId}`;
|
|
44889
|
+
const cer = executable > 0 ? this.ceremonyNow() : null;
|
|
44890
|
+
const auth = cer ? await cer.authorizeTypedData({ action: "withdraw", borrower: p.borrower, detail: card }) : null;
|
|
44891
|
+
if (auth && !auth.ok) return auth.failure;
|
|
44892
|
+
if (auth?.ok) this.bindIfDiscovering(auth.authorization);
|
|
44893
|
+
return this.write("retryWithdrawExecute", () => {
|
|
44894
|
+
const sig = executable === 0 ? null : auth ?? this.sign("withdraw", p.borrower, card);
|
|
44895
|
+
if (sig && !sig.ok) return sig.failure;
|
|
44896
|
+
const r = this.applyAuthorized(
|
|
44897
|
+
sig ? sig.authorization : void 0,
|
|
44898
|
+
() => this.world.retryWithdrawExecute({ positionId: p.positionId, networkFeeSats: p.networkFeeSats, borrower: p.borrower })
|
|
44899
|
+
);
|
|
44900
|
+
if (!r.ok) return this.rejected("retryWithdrawExecute", r.reason);
|
|
44901
|
+
return upOk(
|
|
44902
|
+
{ attempted: r.value.attempted, transfers: r.value.transfers, ...sig ? { authorization: sig.authorization } : {} },
|
|
44903
|
+
this.src("mock-ops")
|
|
44904
|
+
);
|
|
44905
|
+
});
|
|
44906
|
+
}
|
|
44778
44907
|
/** BWAR mirror ceremony (plan 06 E3): a SAFE borrower allowlists a BTC destination via
|
|
44779
44908
|
* a Safe transaction (owner signatures, durable — async collection is honest here). On
|
|
44780
44909
|
* mock, EOA borrowers have no allowlist gate; refusing beats faking success. */
|
|
@@ -52739,13 +52868,13 @@ var init_deployment_addresses = __esm2({
|
|
|
52739
52868
|
block: 25472956
|
|
52740
52869
|
},
|
|
52741
52870
|
BTCSpendAuthorizer: {
|
|
52742
|
-
previousImplementation: "
|
|
52743
|
-
newImplementation: "
|
|
52744
|
-
upgradedAt: "2026-
|
|
52745
|
-
upgradedBy: "AdminModule
|
|
52746
|
-
reason: "
|
|
52747
|
-
executeTx: "
|
|
52748
|
-
block:
|
|
52871
|
+
previousImplementation: "0x40c9e8C46C65E0A57BB63da5368868A9E8Df81A5",
|
|
52872
|
+
newImplementation: "0x00D7a47798E8ff169104b748131703B78f23390C",
|
|
52873
|
+
upgradedAt: "2026-09-09T12:05:35.000Z",
|
|
52874
|
+
upgradedBy: "AdminModule generic op 0xc0214ff38bb454864a34f6482dcd03570b3fd04171c84be2c20184afb1a2e161 (bsa-1-7-0 ceremony: proposed by seat 0x3030C0414B6d95aA9d5A57269E51a347fCBaB472 2026-09-08T11:35:23Z, 3/3 seat signatures, 24h timelock); executeGenericAdminOperation sent by 0xF20986F02420EF443AE9BE5092FB8A4975cF3aA6 in tx 0x77cd231966c546177bd8f1a07bd4e705afd5c2dfbd110b096836401679c0c69c (block 25939703)",
|
|
52875
|
+
reason: "BTCSpendAuthorizer 1.6.0 -> 1.7.0: allow a full-vault sweep (targetAmount == satoshis); TargetMustLeaveFeeRoom -> TargetExceedsInputValue (PR #849; mainnet incidents 2026-09-04 and 2026-09-07). Impl deployed by 0xEba7BfAeB35ee18408b424Ee0BB45AdDf776589f at nonce 430 from source 0a7c535a1 (contracts/src identical to main 99b335f77). Cross-ref onchain-auth/.safe-batches/mainnet-bsa-1-7-0-{propose,sign,execute}.json and docs/mainnet-bsa-1-7-0-ceremony-2026-09-08.md",
|
|
52876
|
+
executeTx: "0x77cd231966c546177bd8f1a07bd4e705afd5c2dfbd110b096836401679c0c69c",
|
|
52877
|
+
block: 25939703
|
|
52749
52878
|
},
|
|
52750
52879
|
PositionManager: {
|
|
52751
52880
|
previousImplementation: "0x600Dc0D1C2c0F94882B6Bc09172f8650047Ad5B1",
|
|
@@ -52848,7 +52977,7 @@ var init_deployment_addresses = __esm2({
|
|
|
52848
52977
|
ADMIN_MODULE: "0x0023B71B586795eE5fa4E83E384345C1EC8Bb946",
|
|
52849
52978
|
ADMIN_MODULE_IMPL: "0xb4C5C7E051A1e672F014B25CB5D55B225Aa0D512",
|
|
52850
52979
|
BTC_SPEND_AUTHORIZER: "0xfBbF108486fa07F1B06a811C5b66ed68DD9c508a",
|
|
52851
|
-
BTC_SPEND_AUTHORIZER_IMPL: "
|
|
52980
|
+
BTC_SPEND_AUTHORIZER_IMPL: "0x00D7a47798E8ff169104b748131703B78f23390C",
|
|
52852
52981
|
POSITION_MANAGER_VIEWS: "0x8B57954eA338c6A6bfF1457f71080e25baFF3937",
|
|
52853
52982
|
POSITION_MANAGER_VIEWS_IMPL: "0xE68DC096A65Ecddbc6A9b5c6e5f878e2CE143Bfe",
|
|
52854
52983
|
POSITION_MANAGER: "0x12A1836e56139ccaD8722B89519d84233efc224B",
|
|
@@ -58918,9 +59047,27 @@ var LOGIN_TYPES_WITH_AUDIENCE2 = {
|
|
|
58918
59047
|
{ name: "audience", type: "string" }
|
|
58919
59048
|
]
|
|
58920
59049
|
};
|
|
58921
|
-
|
|
59050
|
+
var LOGIN_TYPES_WITH_STATEMENT = {
|
|
59051
|
+
DiamondHands: [
|
|
59052
|
+
{ name: "statement", type: "string" },
|
|
59053
|
+
{ name: "address", type: "address" },
|
|
59054
|
+
{ name: "issuedAt", type: "uint256" },
|
|
59055
|
+
{ name: "nonce", type: "bytes32" },
|
|
59056
|
+
{ name: "audience", type: "string" }
|
|
59057
|
+
]
|
|
59058
|
+
};
|
|
59059
|
+
var LOGIN_STATEMENT_TEMPLATE = "{host} is verifying you own this wallet. Signing proves control of the address so we can show your loans and positions. It authorizes no transaction, moves no funds, and costs no gas.";
|
|
59060
|
+
function canonicalLoginStatement(audience) {
|
|
59061
|
+
const host = /^https?:\/\/([^/?#]+)/i.exec(audience)?.[1];
|
|
59062
|
+
if (!host)
|
|
59063
|
+
return null;
|
|
59064
|
+
return LOGIN_STATEMENT_TEMPLATE.replace("{host}", host);
|
|
59065
|
+
}
|
|
59066
|
+
async function buildSignedLoginPayload(signer, chainId, audience, reuse, withStatement = false) {
|
|
58922
59067
|
const address = await signer.getAddress();
|
|
59068
|
+
const statement = withStatement && audience ? canonicalLoginStatement(audience) : null;
|
|
58923
59069
|
const message = {
|
|
59070
|
+
...statement ? { statement } : {},
|
|
58924
59071
|
address,
|
|
58925
59072
|
issuedAt: reuse?.issuedAt ?? Math.floor(Date.now() / 1e3),
|
|
58926
59073
|
nonce: reuse?.nonce ?? (0, import_ethers18.hexlify)((0, import_ethers18.randomBytes)(32)),
|
|
@@ -58928,7 +59075,7 @@ async function buildSignedLoginPayload(signer, chainId, audience, reuse) {
|
|
|
58928
59075
|
};
|
|
58929
59076
|
const signature = await signer.signTypedData(
|
|
58930
59077
|
buildLoginDomain(chainId),
|
|
58931
|
-
audience ? LOGIN_TYPES_WITH_AUDIENCE2 : LOGIN_TYPES2,
|
|
59078
|
+
statement ? LOGIN_TYPES_WITH_STATEMENT : audience ? LOGIN_TYPES_WITH_AUDIENCE2 : LOGIN_TYPES2,
|
|
58932
59079
|
message
|
|
58933
59080
|
);
|
|
58934
59081
|
return { chainId, message, signature };
|
|
@@ -59097,6 +59244,8 @@ var ServerSession = class {
|
|
|
59097
59244
|
signer;
|
|
59098
59245
|
serviceEndpoint;
|
|
59099
59246
|
loginAudience;
|
|
59247
|
+
/** Whether this session's login carries the human-readable statement. */
|
|
59248
|
+
withStatement;
|
|
59100
59249
|
chainId;
|
|
59101
59250
|
store;
|
|
59102
59251
|
onSignaturePrompt;
|
|
@@ -59138,6 +59287,13 @@ var ServerSession = class {
|
|
|
59138
59287
|
/\/+$/,
|
|
59139
59288
|
""
|
|
59140
59289
|
);
|
|
59290
|
+
const explicitAudience = typeof opts.loginAudience === "string" && opts.loginAudience.length > 0;
|
|
59291
|
+
this.withStatement = opts.withStatement === true && explicitAudience;
|
|
59292
|
+
if (opts.withStatement === true && !explicitAudience) {
|
|
59293
|
+
console.warn(
|
|
59294
|
+
"[dh-sdk] withStatement ignored: it requires an explicit loginAudience, since the servers rebuild the expected sentence from the audience host"
|
|
59295
|
+
);
|
|
59296
|
+
}
|
|
59141
59297
|
this.chainId = opts.chainId;
|
|
59142
59298
|
this.store = opts.persistSession === false ? null : opts.sessionStore ?? createDefaultSessionStore();
|
|
59143
59299
|
this.onSignaturePrompt = opts.onSignaturePrompt;
|
|
@@ -59391,12 +59547,16 @@ var ServerSession = class {
|
|
|
59391
59547
|
this.signer,
|
|
59392
59548
|
this.chainId,
|
|
59393
59549
|
this.loginAudience,
|
|
59394
|
-
reuse
|
|
59550
|
+
reuse,
|
|
59551
|
+
reuse ? reuse.withStatement === true : this.withStatement
|
|
59395
59552
|
);
|
|
59396
59553
|
if (storeKey && !reuse) {
|
|
59397
59554
|
store.savePending?.(storeKey, {
|
|
59398
59555
|
issuedAt: payload.message.issuedAt,
|
|
59399
|
-
nonce: payload.message.nonce
|
|
59556
|
+
nonce: payload.message.nonce,
|
|
59557
|
+
// Recorded so a resume reproduces this digest even if the
|
|
59558
|
+
// capability flag changes before the owners finish signing.
|
|
59559
|
+
withStatement: this.withStatement
|
|
59400
59560
|
});
|
|
59401
59561
|
}
|
|
59402
59562
|
session = await this.login(payload);
|
|
@@ -71607,6 +71767,9 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
71607
71767
|
signer: config.authSigner ?? config.contractSigner,
|
|
71608
71768
|
serviceEndpoint: config.serviceEndpoint,
|
|
71609
71769
|
loginAudience: config.loginAudience,
|
|
71770
|
+
// Only meaningful alongside an audience; the servers derive the expected
|
|
71771
|
+
// sentence from its host. Defaults off so Node callers are untouched.
|
|
71772
|
+
withStatement: config.loginStatement === true,
|
|
71610
71773
|
chainId: config.chainId,
|
|
71611
71774
|
persistSession: config.sessionPersistence?.enabled,
|
|
71612
71775
|
sessionStore: config.sessionPersistence?.store,
|
|
@@ -80452,7 +80615,33 @@ function buildWriteOps(deps) {
|
|
|
80452
80615
|
kind: "unavailable",
|
|
80453
80616
|
source: SOURCE5,
|
|
80454
80617
|
message: "recoverStaleSpend is not wired in this delivery (permissionless recovery \u2014 planned follow-up)."
|
|
80455
|
-
})
|
|
80618
|
+
}),
|
|
80619
|
+
retryWithdrawExecute: async (p) => {
|
|
80620
|
+
const sdk = deps.getWriteSdk();
|
|
80621
|
+
if (!sdk) return upFail({ kind: "unavailable", source: SOURCE5, message: "write SDK is not initialized (its boot-time construction failed)" });
|
|
80622
|
+
let rows;
|
|
80623
|
+
try {
|
|
80624
|
+
rows = await sdk.executePendingBtcTransfers(p.positionId, p.networkFeeSats);
|
|
80625
|
+
} catch (e) {
|
|
80626
|
+
return failed("retryWithdrawExecute", e);
|
|
80627
|
+
}
|
|
80628
|
+
const gate = rows.find((r) => !r.success && !r.utxoIdentifier);
|
|
80629
|
+
if (gate) return declined("retryWithdrawExecute", gate.error ?? "pending-transfer execution refused before any reservation was attempted");
|
|
80630
|
+
return upOk(
|
|
80631
|
+
{
|
|
80632
|
+
attempted: rows.length,
|
|
80633
|
+
transfers: rows.map((r) => ({
|
|
80634
|
+
utxoIdentifier: r.utxoIdentifier ?? "",
|
|
80635
|
+
ok: r.success,
|
|
80636
|
+
...r.txid ? { txid: r.txid } : {},
|
|
80637
|
+
...r.amountSent !== void 0 ? { amountSentSats: String(r.amountSent) } : {},
|
|
80638
|
+
...r.destination ? { destination: r.destination } : {},
|
|
80639
|
+
...r.error ? { error: r.error } : {}
|
|
80640
|
+
}))
|
|
80641
|
+
},
|
|
80642
|
+
{ id: SOURCE5, kind: "lit-ops", fetchedAt: (/* @__PURE__ */ new Date()).toISOString() }
|
|
80643
|
+
);
|
|
80644
|
+
}
|
|
80456
80645
|
};
|
|
80457
80646
|
}
|
|
80458
80647
|
|
|
@@ -80977,7 +81166,8 @@ var RealUpstreamPlugin = class {
|
|
|
80977
81166
|
message: "no signer configured \u2014 psmSwap signs two on-chain transactions (exact-amount approve, then swap/redeem) with the keystore signer. Set DH_KEYSTORE_PATH and DH_KEYSTORE_PASSWORD to enable it."
|
|
80978
81167
|
})
|
|
80979
81168
|
),
|
|
80980
|
-
recoverStaleSpend: () => readOnly("recoverStaleSpend")
|
|
81169
|
+
recoverStaleSpend: () => readOnly("recoverStaleSpend"),
|
|
81170
|
+
retryWithdrawExecute: () => readOnly("retryWithdrawExecute")
|
|
80981
81171
|
};
|
|
80982
81172
|
}
|
|
80983
81173
|
}
|
|
@@ -81145,7 +81335,8 @@ var RealUpstreamPlugin = class {
|
|
|
81145
81335
|
psmSwap: call("psmSwap"),
|
|
81146
81336
|
delegationSetup: call("delegationSetup"),
|
|
81147
81337
|
delegationGrant: call("delegationGrant"),
|
|
81148
|
-
recoverStaleSpend: call("recoverStaleSpend")
|
|
81338
|
+
recoverStaleSpend: call("recoverStaleSpend"),
|
|
81339
|
+
retryWithdrawExecute: call("retryWithdrawExecute")
|
|
81149
81340
|
};
|
|
81150
81341
|
}
|
|
81151
81342
|
async resolveOpsGateway() {
|
|
@@ -81956,6 +82147,9 @@ function wcDeclineOrFault(e) {
|
|
|
81956
82147
|
}
|
|
81957
82148
|
var SignatureBridge = class {
|
|
81958
82149
|
clock;
|
|
82150
|
+
/** Lowercased at construction so every comparison is case-flat — EIP-55 checksum casing
|
|
82151
|
+
* differs between what SIWE signs and what a wallet reports for the SAME address. */
|
|
82152
|
+
boundAccount;
|
|
81959
82153
|
expiryMs;
|
|
81960
82154
|
/** Plan 17 E2: single-decision concurrency cap (null = unbounded, the loopback tier). */
|
|
81961
82155
|
maxPending;
|
|
@@ -81991,6 +82185,7 @@ var SignatureBridge = class {
|
|
|
81991
82185
|
unlockSession = null;
|
|
81992
82186
|
constructor(opts) {
|
|
81993
82187
|
this.clock = opts?.clock ?? Date.now;
|
|
82188
|
+
this.boundAccount = opts?.boundAccount?.toLowerCase();
|
|
81994
82189
|
this.expiryMs = opts?.expiryMs ?? DEFAULT_EXPIRY_MS;
|
|
81995
82190
|
this.maxPending = opts?.maxPending ?? null;
|
|
81996
82191
|
this.attachGraceMs = opts?.attachGraceMs ?? (opts?.mount ? DEFAULT_HOSTED_ATTACH_GRACE_MS : DEFAULT_ATTACH_GRACE_MS);
|
|
@@ -82072,7 +82267,7 @@ var SignatureBridge = class {
|
|
|
82072
82267
|
connectedAccounts() {
|
|
82073
82268
|
const seen = /* @__PURE__ */ new Map();
|
|
82074
82269
|
for (const s of this.sessions.values()) {
|
|
82075
|
-
if (s.wallet) seen.set(s.wallet.account.toLowerCase(), s.wallet.account);
|
|
82270
|
+
if (!s.refused && s.wallet) seen.set(s.wallet.account.toLowerCase(), s.wallet.account);
|
|
82076
82271
|
}
|
|
82077
82272
|
if (this.wcActive && this.wallet) seen.set(this.wallet.account.toLowerCase(), this.wallet.account);
|
|
82078
82273
|
return [...seen.values()];
|
|
@@ -82333,7 +82528,7 @@ var SignatureBridge = class {
|
|
|
82333
82528
|
return;
|
|
82334
82529
|
}
|
|
82335
82530
|
const sessionId = (0, import_node_crypto8.randomBytes)(24).toString("hex");
|
|
82336
|
-
this.sessions.set(sessionId, { wallet: null, sse: null });
|
|
82531
|
+
this.sessions.set(sessionId, { wallet: null, sse: null, refused: null });
|
|
82337
82532
|
const page = htmlPageSecurityHeaders();
|
|
82338
82533
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store", ...page.headers });
|
|
82339
82534
|
res.end(renderApprovalPage(sessionId, page.nonce));
|
|
@@ -82360,6 +82555,14 @@ var SignatureBridge = class {
|
|
|
82360
82555
|
});
|
|
82361
82556
|
this.wcTransport = await factory2(this.wcConfig);
|
|
82362
82557
|
this.wcTransport.onSession((info) => {
|
|
82558
|
+
const refusal = info ? this.accountRefusal(info.account) : null;
|
|
82559
|
+
if (info && refusal) {
|
|
82560
|
+
this.wcActive = false;
|
|
82561
|
+
this.rebuildSharedWallet();
|
|
82562
|
+
process.stderr.write(`[bridge] WalletConnect session refused \u2014 ${refusal}
|
|
82563
|
+
`);
|
|
82564
|
+
return;
|
|
82565
|
+
}
|
|
82363
82566
|
this.wcActive = info !== null;
|
|
82364
82567
|
this.wallet = info ? { account: info.account, chainId: info.chainId } : null;
|
|
82365
82568
|
if (info === null) {
|
|
@@ -82457,10 +82660,37 @@ var SignatureBridge = class {
|
|
|
82457
82660
|
this.deny(res, 400, "hello requires account (0x address) and integer chainId");
|
|
82458
82661
|
return;
|
|
82459
82662
|
}
|
|
82663
|
+
const refusal = this.accountRefusal(account);
|
|
82664
|
+
if (refusal) {
|
|
82665
|
+
this.quarantine(session, refusal);
|
|
82666
|
+
this.deny(res, 403, refusal);
|
|
82667
|
+
return;
|
|
82668
|
+
}
|
|
82460
82669
|
session.wallet = { account, chainId };
|
|
82461
82670
|
this.wallet = { account, chainId };
|
|
82462
82671
|
this.ok(res);
|
|
82463
82672
|
}
|
|
82673
|
+
/** C-47: the single predicate every wallet account is admitted through. There are THREE
|
|
82674
|
+
* doors into the account this bridge will sign with — `hello`, `accountsChanged`, and the
|
|
82675
|
+
* WalletConnect `onSession` callback — and all three call this. The first version of this
|
|
82676
|
+
* fix guarded only the first two while this docstring already claimed to be "the single
|
|
82677
|
+
* place", which is how the WC door survived a green suite: the claim was in prose, not in a
|
|
82678
|
+
* test. T-EXT-BIND-01/02/04 now pin one door each, so adding a fourth writer of
|
|
82679
|
+
* `this.wallet` without coming through here fails a test rather than a review.
|
|
82680
|
+
*
|
|
82681
|
+
* Returns the refusal reason, or
|
|
82682
|
+
* null when the account may be adopted.
|
|
82683
|
+
*
|
|
82684
|
+
* Both addresses are named because the pre-fix failure surfaced much later as an opaque
|
|
82685
|
+
* signature-recovery error (`external-eoa.ts:230-233`) that named neither and read as a
|
|
82686
|
+
* wallet fault. A user with several accounts in one wallet extension hits this by
|
|
82687
|
+
* accident far more often than any attacker does, and "wrong account" is only actionable
|
|
82688
|
+
* if it says WHICH. */
|
|
82689
|
+
accountRefusal(account) {
|
|
82690
|
+
if (!this.boundAccount) return null;
|
|
82691
|
+
if (account.toLowerCase() === this.boundAccount) return null;
|
|
82692
|
+
return `this session is signed in as ${this.boundAccount} but the wallet offered ${account.toLowerCase()} \u2014 the account that signs must be the account that signed in. Switch your wallet to the signed-in account, or start a new session with this one.`;
|
|
82693
|
+
}
|
|
82464
82694
|
/** accountsChanged / chainChanged: a wallet-state CHANGE mid-request invalidates every
|
|
82465
82695
|
* pending request — what the human saw approved is no longer what would sign. Wallets
|
|
82466
82696
|
* also deliver late no-op echoes of these events; an unchanged state invalidates nothing. */
|
|
@@ -82470,16 +82700,23 @@ var SignatureBridge = class {
|
|
|
82470
82700
|
const account = String(body["account"] ?? "");
|
|
82471
82701
|
const chainId = Number(body["chainId"]);
|
|
82472
82702
|
const prev = session.wallet;
|
|
82473
|
-
|
|
82474
|
-
|
|
82475
|
-
|
|
82703
|
+
const offered = /^0x[0-9a-fA-F]{40}$/.test(account) && Number.isInteger(chainId) ? { account, chainId } : null;
|
|
82704
|
+
const switchRefusal = offered !== null ? this.accountRefusal(offered.account) : null;
|
|
82705
|
+
const refusedSwitch = switchRefusal !== null;
|
|
82706
|
+
if (refusedSwitch) {
|
|
82707
|
+
this.quarantine(session, switchRefusal);
|
|
82708
|
+
} else {
|
|
82709
|
+
session.wallet = offered;
|
|
82710
|
+
if (this.wallet !== null && prev !== null && this.wallet.account.toLowerCase() === prev.account.toLowerCase()) {
|
|
82711
|
+
this.wallet = session.wallet;
|
|
82712
|
+
}
|
|
82476
82713
|
}
|
|
82477
82714
|
const unchanged = prev !== null && session.wallet !== null && prev.account.toLowerCase() === session.wallet.account.toLowerCase() && prev.chainId === session.wallet.chainId;
|
|
82478
82715
|
if (unchanged) {
|
|
82479
82716
|
this.ok(res);
|
|
82480
82717
|
return;
|
|
82481
82718
|
}
|
|
82482
|
-
const reason = prev && session.wallet && prev.account.toLowerCase() !== session.wallet.account.toLowerCase() ? "the wallet account changed while approval was pending" : prev && session.wallet && prev.chainId !== session.wallet.chainId ? "the wallet network changed while approval was pending" : "the wallet disconnected while approval was pending";
|
|
82719
|
+
const reason = refusedSwitch ? "the wallet switched to an account this session is not signed in as" : prev && session.wallet && prev.account.toLowerCase() !== session.wallet.account.toLowerCase() ? "the wallet account changed while approval was pending" : prev && session.wallet && prev.chainId !== session.wallet.chainId ? "the wallet network changed while approval was pending" : "the wallet disconnected while approval was pending";
|
|
82483
82720
|
for (const entry of this.pending.values()) {
|
|
82484
82721
|
if (!entry.settled && !entry.collect) this.settle(entry, { status: "invalidated", reason });
|
|
82485
82722
|
}
|
|
@@ -82569,7 +82806,7 @@ var SignatureBridge = class {
|
|
|
82569
82806
|
const data = `data: ${JSON.stringify(request)}
|
|
82570
82807
|
|
|
82571
82808
|
`;
|
|
82572
|
-
for (const s of this.sessions.values()) s.sse?.write(data);
|
|
82809
|
+
for (const s of this.sessions.values()) if (!s.refused) s.sse?.write(data);
|
|
82573
82810
|
}
|
|
82574
82811
|
/** Progress goes out as a NAMED event so `es.onmessage` request handling never sees it. */
|
|
82575
82812
|
pushProgress(payload) {
|
|
@@ -82577,7 +82814,48 @@ var SignatureBridge = class {
|
|
|
82577
82814
|
data: ${JSON.stringify(payload)}
|
|
82578
82815
|
|
|
82579
82816
|
`;
|
|
82580
|
-
for (const s of this.sessions.values()) s.sse?.write(data);
|
|
82817
|
+
for (const s of this.sessions.values()) if (!s.refused) s.sse?.write(data);
|
|
82818
|
+
}
|
|
82819
|
+
/**
|
|
82820
|
+
* C-47: `this.wallet` is DERIVED, never guessed.
|
|
82821
|
+
*
|
|
82822
|
+
* It is the shared last-wallet view `candidate()` reads, and an earlier fix decided its
|
|
82823
|
+
* ownership from the `wcActive` flag — "while that is true the wallet came from
|
|
82824
|
+
* WalletConnect". That is false: an approval page can say hello AFTER a WC session is
|
|
82825
|
+
* live, so the page owned the wallet while the flag still said WC did. A refused pairing
|
|
82826
|
+
* then blanked a perfectly good page session, turning someone scanning the QR with the
|
|
82827
|
+
* wrong account into a disconnect for the legitimate user.
|
|
82828
|
+
*
|
|
82829
|
+
* Deriving it from live state removes the guess. Preference order matches
|
|
82830
|
+
* `requestSignature`, which routes to WalletConnect ahead of the page.
|
|
82831
|
+
*/
|
|
82832
|
+
rebuildSharedWallet() {
|
|
82833
|
+
if (this.wcActive && this.wcTransport) {
|
|
82834
|
+
const wc = this.wcTransport.active();
|
|
82835
|
+
if (wc && !this.accountRefusal(wc.account)) {
|
|
82836
|
+
this.wallet = { account: wc.account, chainId: wc.chainId };
|
|
82837
|
+
return;
|
|
82838
|
+
}
|
|
82839
|
+
}
|
|
82840
|
+
let latest = null;
|
|
82841
|
+
for (const s of this.sessions.values()) if (!s.refused && s.wallet) latest = s.wallet;
|
|
82842
|
+
this.wallet = latest;
|
|
82843
|
+
}
|
|
82844
|
+
/**
|
|
82845
|
+
* C-47: the ONE way a page session is refused. Setting `refused` alone was not enough —
|
|
82846
|
+
* an ALREADY-ADMITTED session that later offers a wrong account kept its `wallet`, so it
|
|
82847
|
+
* still answered `connectedAccounts()` for quorum and could still be the shared candidate.
|
|
82848
|
+
* Quarantine therefore does all four things together: mark it, drop its wallet, close its
|
|
82849
|
+
* stream, and re-derive the shared view without it.
|
|
82850
|
+
*/
|
|
82851
|
+
quarantine(session, reason) {
|
|
82852
|
+
session.refused = reason;
|
|
82853
|
+
session.wallet = null;
|
|
82854
|
+
if (session.sse) {
|
|
82855
|
+
session.sse.end();
|
|
82856
|
+
session.sse = null;
|
|
82857
|
+
}
|
|
82858
|
+
this.rebuildSharedWallet();
|
|
82581
82859
|
}
|
|
82582
82860
|
sessionOf(candidate, res) {
|
|
82583
82861
|
const session = typeof candidate === "string" ? this.sessions.get(candidate) ?? null : null;
|
|
@@ -82585,6 +82863,10 @@ data: ${JSON.stringify(payload)}
|
|
|
82585
82863
|
this.deny(res, 403, "missing or wrong session");
|
|
82586
82864
|
return null;
|
|
82587
82865
|
}
|
|
82866
|
+
if (session.refused) {
|
|
82867
|
+
this.deny(res, 403, session.refused);
|
|
82868
|
+
return null;
|
|
82869
|
+
}
|
|
82588
82870
|
return session;
|
|
82589
82871
|
}
|
|
82590
82872
|
checkSession(candidate, res) {
|
|
@@ -82789,6 +83071,11 @@ async function createRealBoundary(config, wallet, overrides) {
|
|
|
82789
83071
|
// tenant — one bridge per tenant world, so the bridge cap IS the tenant cap. The
|
|
82790
83072
|
// loopback tier keeps its unbounded pending (multi-owner Safe pages need it).
|
|
82791
83073
|
...overrides?.bridgeMount ? { mount: overrides.bridgeMount(config.network), maxPending: 1 } : {},
|
|
83074
|
+
// C-47: the authenticated identity governs the write path. Passed separately from
|
|
83075
|
+
// `bridgeMount` although the hosted tier sets both — they answer different questions
|
|
83076
|
+
// ("where does the page live" vs "whose wallet may sign"), and fusing them would make
|
|
83077
|
+
// an unbound hosted bridge impossible to express in a test.
|
|
83078
|
+
...overrides?.boundBorrower ? { boundAccount: overrides.boundBorrower } : {},
|
|
82792
83079
|
// M12-12: no unlock closures without a provider — the unlock endpoints answer with
|
|
82793
83080
|
// their loud not-wired refusal instead of ever touching key material.
|
|
82794
83081
|
...keystore ? {
|
|
@@ -83065,6 +83352,32 @@ function offers(d, mode) {
|
|
|
83065
83352
|
function signerModeSourceClause(d) {
|
|
83066
83353
|
return offers(d, "keystore") ? "the set `signer_setup` offers. `boundary://info` reports the NARROWER set the active adapter actually constructs under `capabilities.writes.signerModes` (the real adapter builds `external` + `keystore`; the practice ceremonies are mock-adapter only) \u2014 when the two differ, `boundary://info` is authoritative" : "the same set `signer_setup` offers and `boundary://info` reports under `capabilities.writes.signerModes`";
|
|
83067
83354
|
}
|
|
83355
|
+
function phoneWalletOffer(d) {
|
|
83356
|
+
return d.walletConnect ? "or scan the WalletConnect QR (or paste the pairing code) to approve on a phone wallet" : "This deployment does NOT offer the WalletConnect phone-wallet leg \u2014 there is no QR to scan and `/wc-pairing` answers 404; a browser-extension wallet is the only path here";
|
|
83357
|
+
}
|
|
83358
|
+
function moneyTruth(d) {
|
|
83359
|
+
const practice = offers(d, "mock-simulated");
|
|
83360
|
+
const sepolia = d.networks.includes("sepolia");
|
|
83361
|
+
const mainnet = d.networks.includes("mainnet");
|
|
83362
|
+
const cases = [];
|
|
83363
|
+
if (practice) cases.push("- Adapter `mock` \u2014 a PRACTICE sandbox. No real money anywhere.");
|
|
83364
|
+
if (sepolia) {
|
|
83365
|
+
cases.push(
|
|
83366
|
+
"- Adapter `real` on SEPOLIA (the zero-config default) \u2014 the REAL protocol contracts on\n the test network: real ceremonies and signatures, PRACTICE money (test funds)."
|
|
83367
|
+
);
|
|
83368
|
+
}
|
|
83369
|
+
if (mainnet) cases.push("- Adapter `real` on MAINNET \u2014 REAL MONEY.");
|
|
83370
|
+
const gate = "Writes are enabled on every build; what stops one is having no signing identity connected\nyet \u2014 `signer_setup` is how that is fixed, and every fund movement still needs the user's\nown wallet signature AND `confirmed: true`.";
|
|
83371
|
+
if (cases.length === 1) {
|
|
83372
|
+
const only = mainnet && !sepolia && !practice ? "This deployment serves MAINNET ONLY \u2014 every fund-moving operation here spends REAL MONEY,\nand there is no practice network on it to fall back to." : `This deployment serves exactly one world:
|
|
83373
|
+
${cases[0]}`;
|
|
83374
|
+
return `${only}
|
|
83375
|
+
${gate}`;
|
|
83376
|
+
}
|
|
83377
|
+
return `The money truth on this deployment has ${cases.length === 2 ? "TWO" : "THREE"} cases:
|
|
83378
|
+
${cases.join("\n")}
|
|
83379
|
+
${gate}`;
|
|
83380
|
+
}
|
|
83068
83381
|
var LOCAL_GUIDE_DEPLOYMENT = {
|
|
83069
83382
|
tier: "local",
|
|
83070
83383
|
networks: ["sepolia", "mainnet"],
|
|
@@ -83072,7 +83385,13 @@ var LOCAL_GUIDE_DEPLOYMENT = {
|
|
|
83072
83385
|
// external+keystore and the mock sandbox adds the practice ceremonies, so the guide may
|
|
83073
83386
|
// speak the full vocabulary and let the existing adapter prose ("PRACTICE-ONLY today —
|
|
83074
83387
|
// on the real adapter these modes refuse") carry the narrower adapter axis.
|
|
83075
|
-
signerModes: GUIDE_SIGNER_MODES
|
|
83388
|
+
signerModes: GUIDE_SIGNER_MODES,
|
|
83389
|
+
// FALSE, because `DH_WC_PROJECT_ID` is unset in a default install and the WalletConnect
|
|
83390
|
+
// leg genuinely is not there until an operator configures it. The first draft of this line
|
|
83391
|
+
// said `true` "to keep the walkthrough complete", which is exactly the overclaim C-44 is
|
|
83392
|
+
// about — the default rendering would have promised a QR that most installs cannot show.
|
|
83393
|
+
// A live boot derives this from env either way (network-switch.ts).
|
|
83394
|
+
walletConnect: false
|
|
83076
83395
|
};
|
|
83077
83396
|
function servedNetworks(d) {
|
|
83078
83397
|
if (d.networks.length === 0) throw new Error("guide: a deployment must serve at least one network");
|
|
@@ -83244,7 +83563,7 @@ function keystoreAbsenceBullet() {
|
|
|
83244
83563
|
never ask for a password.`;
|
|
83245
83564
|
}
|
|
83246
83565
|
var GUIDE_TOPIC_SOURCES = {
|
|
83247
|
-
"getting-started": `# Diamond Hands \u2014 what this is
|
|
83566
|
+
"getting-started": (d) => `# Diamond Hands \u2014 what this is
|
|
83248
83567
|
|
|
83249
83568
|
Diamond Hands lets you BORROW a dollar-pegged token (UCD) against your own BITCOIN,
|
|
83250
83569
|
without selling it. Your BTC sits in a custody vault tied to your position; you mint UCD
|
|
@@ -83252,14 +83571,9 @@ against it, pay it back whenever you like, and take your BTC out again.
|
|
|
83252
83571
|
|
|
83253
83572
|
**Agent instructions:** answer in the USER'S language, map their words via the \`glossary\`
|
|
83254
83573
|
topic, and always say plainly whether this session is PRACTICE or REAL MONEY. Read the
|
|
83255
|
-
\`capabilities\` block in \`boundary://info\` FIRST \u2014 it states the network,
|
|
83256
|
-
|
|
83257
|
-
|
|
83258
|
-
- Adapter \`mock\` \u2014 a PRACTICE sandbox. No real money anywhere.
|
|
83259
|
-
- Adapter \`real\` on SEPOLIA (the zero-config default) \u2014 the REAL protocol contracts on
|
|
83260
|
-
the test network: real ceremonies and signatures, PRACTICE money (test funds).
|
|
83261
|
-
- Adapter \`real\` on MAINNET \u2014 REAL MONEY. Writes are disabled unless the operator
|
|
83262
|
-
explicitly arms them; the capabilities block states which applies.
|
|
83574
|
+
\`capabilities\` block in \`boundary://info\` FIRST \u2014 it states the network, which signer
|
|
83575
|
+
modes this build offers, and which mode is active; never promise a capability it does not
|
|
83576
|
+
list. ${moneyTruth(d)}
|
|
83263
83577
|
SAY THIS EARLY AND UNPROMPTED \u2014 users must never wonder whether money is real.
|
|
83264
83578
|
|
|
83265
83579
|
A first conversation usually goes: explain this page \u2192 \`guide first-setup\` (choose how to
|
|
@@ -83284,8 +83598,8 @@ signer modes exist; current terms (\`protocol_terms\`).
|
|
|
83284
83598
|
**2. Choose HOW to authorize operations** (the user's choice, made by talking):
|
|
83285
83599
|
- **"Use my own wallet"** \u2192 call \`signer_setup\` action \`use\`, mode \`external\` \u2014 works
|
|
83286
83600
|
on the real adapter and the mock. The approval page auto-opens in the browser (its URL
|
|
83287
|
-
is ALSO in the tool result); the user connects MetaMask \u2014
|
|
83288
|
-
|
|
83601
|
+
is ALSO in the tool result); the user connects MetaMask \u2014 ${phoneWalletOffer(d)} \u2014 and
|
|
83602
|
+
then APPROVES EACH OPERATION in
|
|
83289
83603
|
their own wallet. The first verified signature binds their wallet address as the
|
|
83290
83604
|
borrower. Full walkthrough: \`guide connect-wallet\`.
|
|
83291
83605
|
${offers(d, "keystore") ? `- **"Sign automatically / no popups"** \u2192 mode \`keystore\`. A local encrypted keystore
|
|
@@ -83316,14 +83630,13 @@ The user can switch authorization modes at ANY time by saying so \u2014 repeat s
|
|
|
83316
83630
|
"connect-wallet": (d) => `# Connect your wallet \u2014 the external-signer walkthrough
|
|
83317
83631
|
|
|
83318
83632
|
External mode means the user approves every operation in their OWN wallet \u2014 a browser
|
|
83319
|
-
extension (MetaMask) or a WalletConnect mobile wallet. It works
|
|
83320
|
-
the mock.
|
|
83633
|
+
extension (MetaMask)${d.walletConnect ? " or a WalletConnect mobile wallet" : ""}. It works
|
|
83634
|
+
on the real adapter and the mock.
|
|
83321
83635
|
|
|
83322
83636
|
**The walkthrough:**
|
|
83323
83637
|
1. \`signer_setup\` action \`use\`, mode \`external\`. The approval page auto-opens in the
|
|
83324
83638
|
desktop browser; ${approvalPageLocation(d)}
|
|
83325
|
-
2. On the page: connect the browser extension, or \u2014 for a mobile wallet \u2014 scan the
|
|
83326
|
-
WalletConnect QR code or paste the pairing code.
|
|
83639
|
+
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." : ". " + phoneWalletOffer(d) + "."}
|
|
83327
83640
|
3. For authenticated reads before any write: \`signer_setup\` action \`connect\` runs the
|
|
83328
83641
|
login ceremony explicitly (one typed-data signature in the wallet).
|
|
83329
83642
|
4. The FIRST verified signature binds that wallet address as the borrower \u2014 it persists
|
|
@@ -83368,7 +83681,11 @@ the mock.
|
|
|
83368
83681
|
attempts, each a FRESH typed-data card. So a slow approval does not fail; it comes
|
|
83369
83682
|
back. Warn the user: a second or third identical card is the retry, NOT a duplicate
|
|
83370
83683
|
charge and NOT an attack \u2014 but they should still read it, and each attempt is a new
|
|
83371
|
-
signature. The
|
|
83684
|
+
signature. The EXECUTE popup comes once PER ATTEMPT too, and \`loan_withdraw_retry\` raises
|
|
83685
|
+
it again \u2014 re-signing with a fresh stamp is the whole of what a retry does. What that popup
|
|
83686
|
+
LOOKS like depends on the adapter: on the real adapter it is the blind 32-byte hash above;
|
|
83687
|
+
in a practice world (adapter \`mock\`) every ceremony, retries included, is a readable
|
|
83688
|
+
typed-data card. Promise the unreadable one only where it is real.
|
|
83372
83689
|
- **The allowlist delay is read LIVE from the chain.** A new BTC withdrawal destination
|
|
83373
83690
|
(\`loan_allowlist_destination\`) becomes usable only after the chain's own delay \u2014 24
|
|
83374
83691
|
hours on mainnet, so allowlisting and withdrawing happen on DIFFERENT DAYS there. The
|
|
@@ -83404,6 +83721,21 @@ Connections / Connected sites).`,
|
|
|
83404
83721
|
6. **Withdraw BTC** \u2014 \`loan_withdraw {positionId, btcAddress, amountSats, confirmed:true}\`.
|
|
83405
83722
|
BTC sends are IRREVERSIBLE \u2014 read the address back to the user before confirming.
|
|
83406
83723
|
amountSats is gross (fee comes out of it) and may be the whole available balance.
|
|
83724
|
+
The SECOND wallet popup is on a clock of well under a minute; if the user misses it the
|
|
83725
|
+
withdrawal fails with the reservation already committed and their coins still in the
|
|
83726
|
+
vault. That does NOT clear itself and it is not a stale spend \u2014 \`loan_recover_stale_spend\`
|
|
83727
|
+
needs the coins to have MOVED, which is exactly what did not happen. The way out is
|
|
83728
|
+
\`loan_withdraw_retry {positionId, confirmed:true}\`, which re-runs that second step with a
|
|
83729
|
+
fresh stamp using the destination and amount the CHAIN already holds. Check
|
|
83730
|
+
\`position_pending_withdrawals\` first, and tell the user it re-sends real BTC.
|
|
83731
|
+
WARN THEM WHAT THEY WILL SEE: the retry raises the SAME popup the original attempt's
|
|
83732
|
+
execute step raised, on the same sub-minute clock \u2014 on the real adapter that is the opaque
|
|
83733
|
+
32-byte hash the wallet cannot decode; in a practice world it is a readable typed-data card.
|
|
83734
|
+
Say which one before they open the page, not after the popup surprises them.
|
|
83735
|
+
A retry with nothing outstanding pops NO wallet at all: both adapters look the
|
|
83736
|
+
reservations up first and answer \`attempted: 0\` without ever asking for a signature.
|
|
83737
|
+
The fee is taken OUT of the already-authorized amount, so a retry can never send more than
|
|
83738
|
+
the original withdrawal authorized.
|
|
83407
83739
|
7. **Watch it** \u2014 \`position_status\` (one), \`position_list\` (all),
|
|
83408
83740
|
\`position_events\` (history), \`btc_price\`, \`protocol_status\`.
|
|
83409
83741
|
|
|
@@ -83666,8 +83998,7 @@ ${connectorStatusTruth(d)}
|
|
|
83666
83998
|
**What it is:** instead of installing anything, the user adds Diamond Hands to
|
|
83667
83999
|
claude.ai as a connector (paste a URL \u2014 zero install, zero Node, zero config files).
|
|
83668
84000
|
Sign-in IS the wallet: one Sign-In-with-Ethereum signature proves address ownership \u2014
|
|
83669
|
-
no password, no email, no account beyond the wallet address. The sign-in
|
|
83670
|
-
WalletConnect QR too, so a phone wallet works without any browser extension.
|
|
84001
|
+
no password, no email, no account beyond the wallet address.${d.walletConnect ? " The sign-in\npage offers a WalletConnect QR too, so a phone wallet works without any browser extension." : "\n" + phoneWalletOffer(d) + "."}
|
|
83671
84002
|
|
|
83672
84003
|
**Signature cadence, plainly:** the FIRST connect costs one SIWE signature (sign-in)
|
|
83673
84004
|
plus one lit-ops login signature (read access). After that, every operation that moves
|
|
@@ -83688,17 +84019,19 @@ honestly when asked "is this safe"):
|
|
|
83688
84019
|
is never written to disk. A breach here is privacy-class, never money-class.
|
|
83689
84020
|
3. **What the assistant narrates.** Tool results shape what the assistant tells you \u2014
|
|
83690
84021
|
a security concern is filed and audited for exactly this channel.
|
|
83691
|
-
4. **Tenant separation
|
|
83692
|
-
gets its own world: its own boundary, its own signer state, its own
|
|
83693
|
-
mount, keyed by that address.
|
|
83694
|
-
|
|
83695
|
-
|
|
83696
|
-
|
|
83697
|
-
|
|
83698
|
-
|
|
83699
|
-
|
|
83700
|
-
|
|
83701
|
-
|
|
84022
|
+
4. **Tenant separation, and what the mount binding does and does not cover.** Each
|
|
84023
|
+
signed-in wallet gets its own world: its own boundary, its own signer state, its own
|
|
84024
|
+
approval-page mount, keyed by that address. The wallet that connects at the mount
|
|
84025
|
+
must BE that address \u2014 a wallet offering any other account is refused at connect
|
|
84026
|
+
time, and switching accounts afterwards is refused the same way rather than silently
|
|
84027
|
+
becoming the new signer. So the account that signs is the account that signed in.
|
|
84028
|
+
None of that makes the mount link safe to pass around: whoever holds it can still
|
|
84029
|
+
load the page and observe or disrupt a pending ceremony, so treat the link as a
|
|
84030
|
+
secret \u2014 it is freshly random per world and travels only in the user's own tool
|
|
84031
|
+
result. What the binding does mean is that a holder cannot become this session's
|
|
84032
|
+
signer. Alongside that,
|
|
84033
|
+
EVERY fund movement still verifies the signature against the bound borrower, and no
|
|
84034
|
+
key material exists server-side.
|
|
83702
84035
|
5. **Availability and deploy honesty.** Hosted code changes under you: deploys are
|
|
83703
84036
|
version-pinned, the page bundle is open-source, and \`boundary://info\` capabilities
|
|
83704
84037
|
reports the exact server version.
|
|
@@ -83885,11 +84218,17 @@ function createNetworkSwitchRuntime(opts) {
|
|
|
83885
84218
|
}
|
|
83886
84219
|
};
|
|
83887
84220
|
}
|
|
83888
|
-
function guideDeployment(overrides) {
|
|
84221
|
+
function guideDeployment(overrides, env) {
|
|
83889
84222
|
return {
|
|
83890
84223
|
tier: overrides?.bridgeMount ? "hosted" : "local",
|
|
83891
84224
|
networks: overrides?.allowedNetworks ?? LOCAL_GUIDE_DEPLOYMENT.networks,
|
|
83892
|
-
signerModes: overrides?.externalOnly ? EXTERNAL_ONLY_SIGNER_MODES : LOCAL_GUIDE_DEPLOYMENT.signerModes
|
|
84225
|
+
signerModes: overrides?.externalOnly ? EXTERNAL_ONLY_SIGNER_MODES : LOCAL_GUIDE_DEPLOYMENT.signerModes,
|
|
84226
|
+
// C-44 F8, the fourth derivation. Read from the SAME env var the bridge reads
|
|
84227
|
+
// (boundary/config.ts `DH_WC_PROJECT_ID` → BridgeOptions.wc), so the guide cannot promise
|
|
84228
|
+
// a phone-wallet QR that `/wc-pairing` would answer 404 for. Deriving it rather than
|
|
84229
|
+
// hard-coding a tier default is what keeps the guide and `/auth.md` from disagreeing
|
|
84230
|
+
// about the same server, which is exactly what they did before this line existed.
|
|
84231
|
+
walletConnect: Boolean(env?.["DH_WC_PROJECT_ID"])
|
|
83893
84232
|
};
|
|
83894
84233
|
}
|
|
83895
84234
|
function assembleWorld(opts) {
|
|
@@ -83899,7 +84238,7 @@ function assembleWorld(opts) {
|
|
|
83899
84238
|
...boot.mockControl ? { mockControl: boot.mockControl } : {},
|
|
83900
84239
|
...boot.signer ? { signer: boot.signer } : {},
|
|
83901
84240
|
...opts.overrides?.externalOnly ? { externalOnly: true } : {},
|
|
83902
|
-
deployment: guideDeployment(opts.overrides),
|
|
84241
|
+
deployment: guideDeployment(opts.overrides, opts.env),
|
|
83903
84242
|
...opts.configResult.ok && opts.configResult.config.adapter === "mock" && opts.configResult.config.chainId ? { chainId: opts.configResult.config.chainId } : {}
|
|
83904
84243
|
};
|
|
83905
84244
|
if ((opts.env["DH_ADAPTER"] ?? "real") !== "mock") {
|
|
@@ -84211,6 +84550,32 @@ function registerLoanTools(server, getB, adapter2 = "real") {
|
|
|
84211
84550
|
return renderEnvelope(await b.boundary.withdrawBtc({ positionId, btcAddress: btcAddress2, amountSats, networkFeeSats }));
|
|
84212
84551
|
})
|
|
84213
84552
|
);
|
|
84553
|
+
registerBoundaryTool(
|
|
84554
|
+
server,
|
|
84555
|
+
"loan_withdraw_retry",
|
|
84556
|
+
{
|
|
84557
|
+
title: "Re-run a stalled BTC withdrawal's execute step",
|
|
84558
|
+
description: `Finish a withdrawal that authorized but never broadcast. loan_withdraw has two steps: the first commits the reservation on-chain, the second signs a time-stamped hash whose window is under a minute \u2014 often nearer twenty seconds. If that second signature is not given in time the withdrawal fails with the reservation ALREADY committed and the coins still in the vault, and it does not clear itself: loan_recover_stale_spend needs the coins to have MOVED, which is exactly what did not happen. This re-runs the second step alone with a fresh stamp. Destination and amount come from the on-chain record, not from you \u2014 the only figure you supply is the network fee, which is taken OUT of the already-authorized amount and cannot increase what leaves the vault. Use position_pending_withdrawals to see what is outstanding first. Sends real BTC. ${LATENCY_NOTE} Requires human confirmation (confirmed: true).`,
|
|
84559
|
+
inputSchema: {
|
|
84560
|
+
positionId: positionIdSchema,
|
|
84561
|
+
networkFeeSats: import_zod.z.number().int().positive().default(1e3).describe("BTC network fee in sats (declared default 1000); taken FROM the authorized amount, not added on top"),
|
|
84562
|
+
confirmed: confirmedSchema
|
|
84563
|
+
},
|
|
84564
|
+
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
84565
|
+
},
|
|
84566
|
+
async ({ positionId, networkFeeSats, confirmed }) => guardedWrite(getB, async () => {
|
|
84567
|
+
const gate = requireConfirmation(
|
|
84568
|
+
confirmed,
|
|
84569
|
+
`re-run the execute step for every outstanding BTC withdrawal reservation on position ${positionId} (this BROADCASTS real BTC to the destination each reservation already authorizes)`
|
|
84570
|
+
);
|
|
84571
|
+
if (gate) return gate;
|
|
84572
|
+
const problem = checkPositionIdHex(positionId) ?? checkSatsAmount(networkFeeSats, "Network fee");
|
|
84573
|
+
if (problem) return validationFailed(problem);
|
|
84574
|
+
const b = getB();
|
|
84575
|
+
if (!b.ok) return renderError(b.error);
|
|
84576
|
+
return renderEnvelope(await b.boundary.retryWithdrawExecute({ positionId, networkFeeSats }));
|
|
84577
|
+
})
|
|
84578
|
+
);
|
|
84214
84579
|
registerBoundaryTool(
|
|
84215
84580
|
server,
|
|
84216
84581
|
"loan_allowlist_destination",
|
|
@@ -84236,7 +84601,7 @@ function registerLoanTools(server, getB, adapter2 = "real") {
|
|
|
84236
84601
|
"loan_delegation_setup",
|
|
84237
84602
|
{
|
|
84238
84603
|
title: "Install delegation on the Safe (one owner ceremony)",
|
|
84239
|
-
description: `The ONE-TIME Safe delegation batch (signer mode 'safe-module'): your owners sign a single durable Safe transaction \u2014 at their leisure, no time window \u2014 that enables the Safe's AgentModule, binds the agent key, registers it in the delegation registry, and pre-approves the given BTC withdrawal destinations. After it, day-to-day operations (create/mint/pay/extend) run agent-solo; withdrawals always still need the owners' short signing burst, and only to destinations approved here (or later via loan_allowlist_destination \u2014 also owners-only). A revoked agent address burns FOREVER (AR-1) \u2014 rotation means a fresh key. Requires human confirmation (confirmed: true).`,
|
|
84604
|
+
description: `NOT AVAILABLE on the real protocol in this build \u2014 the real adapter answers UPSTREAM_UNAVAILABLE ('not wired in this delivery'). It runs on the practice (mock) adapter only. Say so before a user plans around it. The ONE-TIME Safe delegation batch (signer mode 'safe-module'): your owners sign a single durable Safe transaction \u2014 at their leisure, no time window \u2014 that enables the Safe's AgentModule, binds the agent key, registers it in the delegation registry, and pre-approves the given BTC withdrawal destinations. After it, day-to-day operations (create/mint/pay/extend) run agent-solo; withdrawals always still need the owners' short signing burst, and only to destinations approved here (or later via loan_allowlist_destination \u2014 also owners-only). A revoked agent address burns FOREVER (AR-1) \u2014 rotation means a fresh key. Requires human confirmation (confirmed: true).`,
|
|
84240
84605
|
inputSchema: {
|
|
84241
84606
|
btcAddresses: import_zod.z.array(import_zod.z.string().min(1)).describe("BTC withdrawal destinations to pre-approve in the same ceremony (avoids a second owner gathering before the first withdrawal)"),
|
|
84242
84607
|
confirmed: confirmedSchema
|
|
@@ -84256,7 +84621,7 @@ function registerLoanTools(server, getB, adapter2 = "real") {
|
|
|
84256
84621
|
"loan_delegation_grant",
|
|
84257
84622
|
{
|
|
84258
84623
|
title: "Grant the agent per-position scopes (owners sign)",
|
|
84259
|
-
description: `Set what the delegated agent may do on ONE position \u2014 RENEW (extend), REPAY (pay down), MINT (borrow, only while the post-mint collateral ratio stays at or above mintFloorBps \u2014 required for MINT, it is the owners' risk bound). Grants are user-only expansion: for a Safe this is a QUORUM signature (durable Safe transaction, owners sign at leisure) \u2014 the agent can never widen its own powers. Omitting a scope leaves it un-granted; a grant with no scopes clears the position's grant. Requires human confirmation (confirmed: true).`,
|
|
84624
|
+
description: `NOT AVAILABLE on the real protocol in this build \u2014 the real adapter answers UPSTREAM_UNAVAILABLE ('not wired in this delivery'). It runs on the practice (mock) adapter only. Say so before a user plans around it. Set what the delegated agent may do on ONE position \u2014 RENEW (extend), REPAY (pay down), MINT (borrow, only while the post-mint collateral ratio stays at or above mintFloorBps \u2014 required for MINT, it is the owners' risk bound). Grants are user-only expansion: for a Safe this is a QUORUM signature (durable Safe transaction, owners sign at leisure) \u2014 the agent can never widen its own powers. Omitting a scope leaves it un-granted; a grant with no scopes clears the position's grant. Requires human confirmation (confirmed: true).`,
|
|
84260
84625
|
inputSchema: {
|
|
84261
84626
|
positionId: positionIdSchema,
|
|
84262
84627
|
renew: import_zod.z.boolean().optional().describe("Allow the agent to extend/renew this position"),
|
|
@@ -84286,7 +84651,7 @@ function registerLoanTools(server, getB, adapter2 = "real") {
|
|
|
84286
84651
|
"loan_recover_stale_spend",
|
|
84287
84652
|
{
|
|
84288
84653
|
title: "Recover a stale BTC reservation via LIT-attested proof",
|
|
84289
|
-
description: "Clear a stale authorized BTC spend on BTCSpendAuthorizer using a LIT-attested StaleSpendRecovery attestation. The original UTXO must already be consumed on Bitcoin with \u22656 confirmations. `invalidatorTxid` is either the borrower's authorized broadcast (after confirmations) or a PKP self-spend that invalidated the reservation. Permissionless on-chain.",
|
|
84654
|
+
description: "NOT AVAILABLE on the real protocol in this build \u2014 the real adapter answers UPSTREAM_UNAVAILABLE ('not wired in this delivery'); it runs on the practice (mock) adapter only. For a withdrawal that authorized but never broadcast, loan_withdraw_retry is the working path. Clear a stale authorized BTC spend on BTCSpendAuthorizer using a LIT-attested StaleSpendRecovery attestation. The original UTXO must already be consumed on Bitcoin with \u22656 confirmations. `invalidatorTxid` is either the borrower's authorized broadcast (after confirmations) or a PKP self-spend that invalidated the reservation. Permissionless on-chain.",
|
|
84290
84655
|
inputSchema: {
|
|
84291
84656
|
positionId: positionIdSchema,
|
|
84292
84657
|
utxoTxid: import_zod.z.string().describe("The original authorized UTXO's txid"),
|
|
@@ -85285,6 +85650,12 @@ function composeConnector(opts, rawPublicOrigin) {
|
|
|
85285
85650
|
const overrides = {
|
|
85286
85651
|
externalOnly: true,
|
|
85287
85652
|
allowedNetworks,
|
|
85653
|
+
// C-47: `tenantKey` IS the lowercased SIWE address (see the `authImpl.tenant` call
|
|
85654
|
+
// site). Until this line it was a map key and an error string and nothing else, so a
|
|
85655
|
+
// session authenticated as A could write as B by connecting B to the approval page.
|
|
85656
|
+
// The mount is a bearer capability that transits the LLM transcript by design
|
|
85657
|
+
// (C-45), which is what made that reachable rather than merely untidy.
|
|
85658
|
+
boundBorrower: tenantKey,
|
|
85288
85659
|
bridgeMount: () => ({ baseUrl: `${publicOrigin}/approval/${mountId}`, origin: publicOrigin }),
|
|
85289
85660
|
signerPersistence: (network) => {
|
|
85290
85661
|
let s = stores.get(network);
|