@toon-protocol/client-mcp 0.16.0 → 0.17.0
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/{chunk-XFUZJ4XF.js → chunk-6Q3RYIEE.js} +99 -45
- package/dist/chunk-6Q3RYIEE.js.map +1 -0
- package/dist/{chunk-P7YF72JB.js → chunk-UDHZEABQ.js} +303 -663
- package/dist/chunk-UDHZEABQ.js.map +1 -0
- package/dist/{chunk-N7MWQMBC.js → chunk-ZPXVGXGV.js} +2 -2
- package/dist/daemon.js +2 -2
- package/dist/index.d.ts +62 -1
- package/dist/index.js +3 -3
- package/dist/mcp.js +2 -2
- package/package.json +6 -6
- package/dist/chunk-P7YF72JB.js.map +0 -1
- package/dist/chunk-XFUZJ4XF.js.map +0 -1
- /package/dist/{chunk-N7MWQMBC.js.map → chunk-ZPXVGXGV.js.map} +0 -0
|
@@ -14,9 +14,10 @@ import {
|
|
|
14
14
|
fundWallet,
|
|
15
15
|
generateKeystore,
|
|
16
16
|
isEventExpired,
|
|
17
|
+
mintExecutionCondition,
|
|
17
18
|
parseIlpPeerInfo,
|
|
18
19
|
readConfigFile
|
|
19
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-UDHZEABQ.js";
|
|
20
21
|
import {
|
|
21
22
|
__require
|
|
22
23
|
} from "./chunk-F22GNSF6.js";
|
|
@@ -360,8 +361,10 @@ import { readFile, stat } from "fs/promises";
|
|
|
360
361
|
import { resolve, sep } from "path";
|
|
361
362
|
import { generateSecretKey as generateSecretKey2 } from "nostr-tools/pure";
|
|
362
363
|
|
|
363
|
-
// ../../node_modules/.pnpm/@toon-protocol+core@
|
|
364
|
+
// ../../node_modules/.pnpm/@toon-protocol+core@2.0.1_typescript@5.9.3/node_modules/@toon-protocol/core/dist/nip34/index.js
|
|
364
365
|
var REPOSITORY_ANNOUNCEMENT_KIND = 30617;
|
|
366
|
+
var PATCH_KIND = 1617;
|
|
367
|
+
var ISSUE_KIND = 1621;
|
|
365
368
|
var STATUS_OPEN_KIND = 1630;
|
|
366
369
|
var STATUS_APPLIED_KIND = 1631;
|
|
367
370
|
var STATUS_CLOSED_KIND = 1632;
|
|
@@ -371,11 +374,6 @@ var STATUS_DRAFT_KIND = 1633;
|
|
|
371
374
|
var MAX_OBJECT_SIZE = 95 * 1024;
|
|
372
375
|
var EMPTY_BLOB_SHA = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391";
|
|
373
376
|
|
|
374
|
-
// ../../node_modules/.pnpm/@toon-protocol+core@2.0.1_typescript@5.9.3/node_modules/@toon-protocol/core/dist/nip34/index.js
|
|
375
|
-
var REPOSITORY_ANNOUNCEMENT_KIND2 = 30617;
|
|
376
|
-
var PATCH_KIND = 1617;
|
|
377
|
-
var ISSUE_KIND = 1621;
|
|
378
|
-
|
|
379
377
|
// ../rig/dist/chunk-3HRFDH7H.js
|
|
380
378
|
import { decode as decodeToon } from "@toon-format/toon";
|
|
381
379
|
var REPOSITORY_STATE_KIND = 30618;
|
|
@@ -416,7 +414,7 @@ function buildRepoAnnouncement(repoId, name, description, maintainers = []) {
|
|
|
416
414
|
tags.push([MAINTAINERS_TAG, ...declared]);
|
|
417
415
|
}
|
|
418
416
|
return {
|
|
419
|
-
kind:
|
|
417
|
+
kind: REPOSITORY_ANNOUNCEMENT_KIND,
|
|
420
418
|
content: "",
|
|
421
419
|
tags,
|
|
422
420
|
created_at: Math.floor(Date.now() / 1e3)
|
|
@@ -443,7 +441,7 @@ function buildRepoRefs(repoId, refs, arweaveMap = {}) {
|
|
|
443
441
|
}
|
|
444
442
|
function buildIssue(repoOwnerPubkey, repoId, title, body, labels = []) {
|
|
445
443
|
const tags = [
|
|
446
|
-
["a", `${
|
|
444
|
+
["a", `${REPOSITORY_ANNOUNCEMENT_KIND}:${repoOwnerPubkey}:${repoId}`],
|
|
447
445
|
["p", repoOwnerPubkey],
|
|
448
446
|
["subject", title],
|
|
449
447
|
...labels.map((label) => ["t", label])
|
|
@@ -460,7 +458,7 @@ function buildComment(repoOwnerPubkey, repoId, issueOrPrEventId, authorPubkey, b
|
|
|
460
458
|
kind: COMMENT_KIND,
|
|
461
459
|
content: body,
|
|
462
460
|
tags: [
|
|
463
|
-
["a", `${
|
|
461
|
+
["a", `${REPOSITORY_ANNOUNCEMENT_KIND}:${repoOwnerPubkey}:${repoId}`],
|
|
464
462
|
["e", issueOrPrEventId, "", marker],
|
|
465
463
|
["p", authorPubkey]
|
|
466
464
|
],
|
|
@@ -469,7 +467,7 @@ function buildComment(repoOwnerPubkey, repoId, issueOrPrEventId, authorPubkey, b
|
|
|
469
467
|
}
|
|
470
468
|
function buildPatch(repoOwnerPubkey, repoId, title, commits, branchTag, content = "", description) {
|
|
471
469
|
const tags = [
|
|
472
|
-
["a", `${
|
|
470
|
+
["a", `${REPOSITORY_ANNOUNCEMENT_KIND}:${repoOwnerPubkey}:${repoId}`],
|
|
473
471
|
["p", repoOwnerPubkey],
|
|
474
472
|
["subject", title]
|
|
475
473
|
];
|
|
@@ -739,7 +737,7 @@ async function fetchRemoteState(options) {
|
|
|
739
737
|
throw new Error("fetchRemoteState: repoId is required");
|
|
740
738
|
}
|
|
741
739
|
const filter = {
|
|
742
|
-
kinds: [
|
|
740
|
+
kinds: [REPOSITORY_ANNOUNCEMENT_KIND, REPOSITORY_STATE_KIND],
|
|
743
741
|
authors: [ownerPubkey],
|
|
744
742
|
"#d": [repoId]
|
|
745
743
|
};
|
|
@@ -771,7 +769,7 @@ async function fetchRemoteState(options) {
|
|
|
771
769
|
events.filter((e) => e.kind === REPOSITORY_STATE_KIND)
|
|
772
770
|
);
|
|
773
771
|
const announceEvent = latestReplaceable(
|
|
774
|
-
events.filter((e) => e.kind ===
|
|
772
|
+
events.filter((e) => e.kind === REPOSITORY_ANNOUNCEMENT_KIND)
|
|
775
773
|
);
|
|
776
774
|
const { refs, headSymref, shaToTxId } = refsEvent ? parseRefsEvent(refsEvent) : {
|
|
777
775
|
refs: /* @__PURE__ */ new Map(),
|
|
@@ -1474,7 +1472,7 @@ async function executePush(options) {
|
|
|
1474
1472
|
};
|
|
1475
1473
|
}
|
|
1476
1474
|
|
|
1477
|
-
// ../../node_modules/.pnpm/@toon-protocol+sdk@0.
|
|
1475
|
+
// ../../node_modules/.pnpm/@toon-protocol+sdk@2.0.1_mina-signer@3.1.0_typescript@5.9.3/node_modules/@toon-protocol/sdk/dist/chunk-UP2VWCW5.js
|
|
1478
1476
|
var __require2 = /* @__PURE__ */ ((x) => typeof __require !== "undefined" ? __require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
1479
1477
|
get: (a, b) => (typeof __require !== "undefined" ? __require : a)[b]
|
|
1480
1478
|
}) : x)(function(x) {
|
|
@@ -1482,7 +1480,7 @@ var __require2 = /* @__PURE__ */ ((x) => typeof __require !== "undefined" ? __re
|
|
|
1482
1480
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
1483
1481
|
});
|
|
1484
1482
|
|
|
1485
|
-
// ../../node_modules/.pnpm/@toon-protocol+sdk@0.
|
|
1483
|
+
// ../../node_modules/.pnpm/@toon-protocol+sdk@2.0.1_mina-signer@3.1.0_typescript@5.9.3/node_modules/@toon-protocol/sdk/dist/chunk-Z6S56VPV.js
|
|
1486
1484
|
import { getPublicKey } from "nostr-tools/pure";
|
|
1487
1485
|
import { generateSecretKey, getPublicKey as getPublicKey2 } from "nostr-tools/pure";
|
|
1488
1486
|
import { createRumor, createSeal, createWrap } from "nostr-tools/nip59";
|
|
@@ -1813,9 +1811,9 @@ function decodeFulfillMetadata(data, chain) {
|
|
|
1813
1811
|
if (typeof recipient === "string" && recipient.length > 0) {
|
|
1814
1812
|
result.recipient = recipient;
|
|
1815
1813
|
}
|
|
1816
|
-
const
|
|
1817
|
-
if (typeof
|
|
1818
|
-
result.
|
|
1814
|
+
const swapSignerAddress = obj["swapSignerAddress"];
|
|
1815
|
+
if (typeof swapSignerAddress === "string" && (!chain || validateChainAddress(swapSignerAddress, chain, "address"))) {
|
|
1816
|
+
result.swapSignerAddress = swapSignerAddress;
|
|
1819
1817
|
}
|
|
1820
1818
|
return result;
|
|
1821
1819
|
}
|
|
@@ -1898,10 +1896,10 @@ function validateParams(params) {
|
|
|
1898
1896
|
"senderSecretKey must be a 32-byte Uint8Array"
|
|
1899
1897
|
);
|
|
1900
1898
|
}
|
|
1901
|
-
if (typeof params.
|
|
1899
|
+
if (typeof params.swapPubkey !== "string" || !HEX64_REGEX.test(params.swapPubkey)) {
|
|
1902
1900
|
throw new StreamSwapError(
|
|
1903
1901
|
"INVALID_STATE",
|
|
1904
|
-
"
|
|
1902
|
+
"swapPubkey must be a 64-char lowercase hex string"
|
|
1905
1903
|
);
|
|
1906
1904
|
}
|
|
1907
1905
|
if (!params.pair || typeof params.pair !== "object") {
|
|
@@ -2083,8 +2081,8 @@ async function runLoop(params, pair, schedule, senderPubkey, logger, getState, s
|
|
|
2083
2081
|
const wrapped = wrapSwapPacketToToon({
|
|
2084
2082
|
rumor,
|
|
2085
2083
|
senderSecretKey: params.senderSecretKey,
|
|
2086
|
-
recipientPubkey: params.
|
|
2087
|
-
destination: params.
|
|
2084
|
+
recipientPubkey: params.swapPubkey,
|
|
2085
|
+
destination: params.swapIlpAddress,
|
|
2088
2086
|
amount: sourceAmount
|
|
2089
2087
|
});
|
|
2090
2088
|
toonData = new Uint8Array(Buffer.from(wrapped.ilpPrepare.data, "base64"));
|
|
@@ -2103,7 +2101,7 @@ async function runLoop(params, pair, schedule, senderPubkey, logger, getState, s
|
|
|
2103
2101
|
let sendResult;
|
|
2104
2102
|
try {
|
|
2105
2103
|
sendResult = await params.client.sendSwapPacket({
|
|
2106
|
-
destination: params.
|
|
2104
|
+
destination: params.swapIlpAddress,
|
|
2107
2105
|
amount: sourceAmount,
|
|
2108
2106
|
toonData,
|
|
2109
2107
|
timeout: params.packetTimeoutMs ?? 3e4,
|
|
@@ -2161,8 +2159,8 @@ async function runLoop(params, pair, schedule, senderPubkey, logger, getState, s
|
|
|
2161
2159
|
rejections.push({
|
|
2162
2160
|
packetIndex,
|
|
2163
2161
|
sourceAmount,
|
|
2164
|
-
code: "
|
|
2165
|
-
message: `
|
|
2162
|
+
code: "SWAP_RECIPIENT_MISMATCH",
|
|
2163
|
+
message: `Swap echoed recipient ${metadata.recipient} but sender expected ${params.chainRecipient}`
|
|
2166
2164
|
});
|
|
2167
2165
|
continue;
|
|
2168
2166
|
}
|
|
@@ -2223,7 +2221,7 @@ async function runLoop(params, pair, schedule, senderPubkey, logger, getState, s
|
|
|
2223
2221
|
sourceAmount,
|
|
2224
2222
|
targetAmount,
|
|
2225
2223
|
claimBytes,
|
|
2226
|
-
|
|
2224
|
+
swapEphemeralPubkey: metadata.ephemeralPubkey,
|
|
2227
2225
|
pair,
|
|
2228
2226
|
receivedAt: Date.now()
|
|
2229
2227
|
};
|
|
@@ -2235,8 +2233,8 @@ async function runLoop(params, pair, schedule, senderPubkey, logger, getState, s
|
|
|
2235
2233
|
accumulated.cumulativeAmount = metadata.cumulativeAmount;
|
|
2236
2234
|
if (metadata.recipient !== void 0)
|
|
2237
2235
|
accumulated.recipient = metadata.recipient;
|
|
2238
|
-
if (metadata.
|
|
2239
|
-
accumulated.
|
|
2236
|
+
if (metadata.swapSignerAddress !== void 0)
|
|
2237
|
+
accumulated.swapSignerAddress = metadata.swapSignerAddress;
|
|
2240
2238
|
claims.push(accumulated);
|
|
2241
2239
|
logger.debug({
|
|
2242
2240
|
event: "stream_swap.packet_accepted",
|
|
@@ -3465,15 +3463,36 @@ var ClientRunner = class {
|
|
|
3465
3463
|
}
|
|
3466
3464
|
throw new Error(`Channel "${channelId}" is not tracked by any apex.`);
|
|
3467
3465
|
}
|
|
3468
|
-
/**
|
|
3466
|
+
/**
|
|
3467
|
+
* Swap source→target asset against a swap peer via the selected apex.
|
|
3468
|
+
*
|
|
3469
|
+
* sdk ≥2.0.0 (the `mill`→`swap` vocabulary rename, toon commit `af4cd24`):
|
|
3470
|
+
* `streamSwap` takes `swapPubkey`/`swapIlpAddress` and accumulated claims
|
|
3471
|
+
* carry `swapSignerAddress`. The rename has NO wire back-compat — a
|
|
3472
|
+
* pre-rename (sdk ≤1.x) swap peer still emits `millSignerAddress` in its
|
|
3473
|
+
* FULFILL settlement metadata, which `decodeFulfillMetadata` silently drops
|
|
3474
|
+
* as an unknown field. That skew would otherwise surface only much later as
|
|
3475
|
+
* `MISSING_SETTLEMENT_METADATA` in `buildSettlementTx`, so we detect it
|
|
3476
|
+
* here (accepted claims with no `swapSignerAddress`) and surface a loud
|
|
3477
|
+
* `warning` on the response at swap time (#349).
|
|
3478
|
+
*
|
|
3479
|
+
* With `req.senderConditions` set, every swap packet is sent with a FRESH
|
|
3480
|
+
* sender-minted execution condition (`C_i = sha256(P_i)`, one per packet —
|
|
3481
|
+
* toon-client#350, rolling-swap spec §3 R1/R2) and the transport verifies
|
|
3482
|
+
* each FULFILL's preimage; a mismatch counts the packet failed. This
|
|
3483
|
+
* requires a maker/connector implementing the sender-chosen fulfillment
|
|
3484
|
+
* contract (connector#309) — the deployed claim-issuing mill cannot satisfy
|
|
3485
|
+
* it — so it is opt-in and the default stays the legacy zero condition.
|
|
3486
|
+
*/
|
|
3469
3487
|
async swap(req) {
|
|
3470
3488
|
const apex = this.selectApex(req.btpUrl);
|
|
3471
3489
|
this.assertApexReady(apex);
|
|
3472
3490
|
const senderSecretKey = generateSecretKey2();
|
|
3491
|
+
const swapClient = req.senderConditions ? this.withSenderConditions(apex.client) : apex.client;
|
|
3473
3492
|
const result = await streamSwap({
|
|
3474
|
-
client:
|
|
3475
|
-
|
|
3476
|
-
|
|
3493
|
+
client: swapClient,
|
|
3494
|
+
swapPubkey: req.swapPubkey,
|
|
3495
|
+
swapIlpAddress: req.destination,
|
|
3477
3496
|
pair: req.pair,
|
|
3478
3497
|
senderSecretKey,
|
|
3479
3498
|
chainRecipient: req.chainRecipient,
|
|
@@ -3481,25 +3500,60 @@ var ClientRunner = class {
|
|
|
3481
3500
|
packetCount: req.packetCount ?? 1
|
|
3482
3501
|
});
|
|
3483
3502
|
const firstReject = result.rejections[0];
|
|
3503
|
+
const claims = result.claims.map((c) => ({
|
|
3504
|
+
sourceAmount: c.sourceAmount.toString(),
|
|
3505
|
+
targetAmount: c.targetAmount.toString(),
|
|
3506
|
+
claim: Buffer.from(c.claimBytes).toString("base64"),
|
|
3507
|
+
...c.channelId ? { channelId: c.channelId } : {},
|
|
3508
|
+
...c.recipient ? { recipient: c.recipient } : {},
|
|
3509
|
+
...c.swapSignerAddress ? { swapSignerAddress: c.swapSignerAddress } : {},
|
|
3510
|
+
...c.claimId ? { claimId: c.claimId } : {},
|
|
3511
|
+
...c.nonce ? { nonce: c.nonce } : {},
|
|
3512
|
+
...c.cumulativeAmount ? { cumulativeAmount: c.cumulativeAmount } : {}
|
|
3513
|
+
}));
|
|
3514
|
+
const missingSettlementSigner = claims.length > 0 && claims.every((c) => !c.swapSignerAddress);
|
|
3515
|
+
if (missingSettlementSigner) {
|
|
3516
|
+
this.log(
|
|
3517
|
+
"[runner] swap: accepted claims are missing swapSignerAddress settlement metadata \u2014 swap peer is likely pre-rename (sdk <2.0.0)"
|
|
3518
|
+
);
|
|
3519
|
+
}
|
|
3484
3520
|
return {
|
|
3485
3521
|
accepted: result.claims.length > 0,
|
|
3486
3522
|
packetsAccepted: result.claims.length,
|
|
3487
|
-
claims
|
|
3488
|
-
sourceAmount: c.sourceAmount.toString(),
|
|
3489
|
-
targetAmount: c.targetAmount.toString(),
|
|
3490
|
-
claim: Buffer.from(c.claimBytes).toString("base64"),
|
|
3491
|
-
...c.channelId ? { channelId: c.channelId } : {},
|
|
3492
|
-
...c.recipient ? { recipient: c.recipient } : {},
|
|
3493
|
-
...c.millSignerAddress ? { swapSignerAddress: c.millSignerAddress } : {},
|
|
3494
|
-
...c.claimId ? { claimId: c.claimId } : {},
|
|
3495
|
-
...c.nonce ? { nonce: c.nonce } : {},
|
|
3496
|
-
...c.cumulativeAmount ? { cumulativeAmount: c.cumulativeAmount } : {}
|
|
3497
|
-
})),
|
|
3523
|
+
claims,
|
|
3498
3524
|
cumulativeSource: result.cumulativeSource.toString(),
|
|
3499
3525
|
cumulativeTarget: result.cumulativeTarget.toString(),
|
|
3500
3526
|
state: result.state,
|
|
3501
|
-
...firstReject ? { code: firstReject.code, message: firstReject.message } : {}
|
|
3527
|
+
...firstReject ? { code: firstReject.code, message: firstReject.message } : {},
|
|
3528
|
+
...missingSettlementSigner ? {
|
|
3529
|
+
warning: "Accepted claims are missing `swapSignerAddress` settlement metadata, so settling them will fail with MISSING_SETTLEMENT_METADATA. The swap peer is likely running a pre-rename SDK (<2.0.0, emits `millSignerAddress`, which sdk \u22652 silently drops). Upgrade the swap peer before settling."
|
|
3530
|
+
} : {}
|
|
3531
|
+
};
|
|
3532
|
+
}
|
|
3533
|
+
/**
|
|
3534
|
+
* Wrap an apex client so each `sendSwapPacket` call carries a freshly
|
|
3535
|
+
* minted sender-chosen execution condition (one preimage per packet, spec
|
|
3536
|
+
* R1 — reuse would let an observer of packet *i* fulfill packet *i+1*).
|
|
3537
|
+
* `streamSwap` calls `sendSwapPacket` once per packet, so minting here
|
|
3538
|
+
* yields exactly one condition per packet. The transports verify each
|
|
3539
|
+
* FULFILL's preimage against the condition and fail the packet on mismatch.
|
|
3540
|
+
*
|
|
3541
|
+
* NOTE: the minted preimage is intentionally NOT retained yet — leg-B
|
|
3542
|
+
* receive-side ingestion (where the sender reveals `P_i`) is a separate
|
|
3543
|
+
* rolling-swap workstream (toon-meta docs/rolling-swap.md §3.2). Until a
|
|
3544
|
+
* maker implements the connector#309 contract end-to-end, packets sent with
|
|
3545
|
+
* conditions will fail closed rather than settle unverified.
|
|
3546
|
+
*/
|
|
3547
|
+
withSenderConditions(client) {
|
|
3548
|
+
const wrapped = Object.create(client);
|
|
3549
|
+
wrapped.sendSwapPacket = (params) => {
|
|
3550
|
+
const { condition } = mintExecutionCondition();
|
|
3551
|
+
return client.sendSwapPacket({
|
|
3552
|
+
...params,
|
|
3553
|
+
executionCondition: condition
|
|
3554
|
+
});
|
|
3502
3555
|
};
|
|
3556
|
+
return wrapped;
|
|
3503
3557
|
}
|
|
3504
3558
|
/**
|
|
3505
3559
|
* Payment-aware HTTP fetch through an apex's client. The client issues the
|
|
@@ -4376,4 +4430,4 @@ export {
|
|
|
4376
4430
|
PublishRejectedError,
|
|
4377
4431
|
registerRoutes
|
|
4378
4432
|
};
|
|
4379
|
-
//# sourceMappingURL=chunk-
|
|
4433
|
+
//# sourceMappingURL=chunk-6Q3RYIEE.js.map
|