@mysten-incubation/suipay-mcp 0.3.0-dev.16 → 0.3.0-dev.18
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/README.md
CHANGED
|
@@ -5,7 +5,7 @@ buyer-funded spend account. The buyer owns the account. The agent holds the
|
|
|
5
5
|
delegate key and can spend only under the on-chain grant (recipient bind,
|
|
6
6
|
per-payment cap, budget).
|
|
7
7
|
|
|
8
|
-
Pin `@mysten-incubation/suipay-mcp@0.3.0-dev.
|
|
8
|
+
Pin `@mysten-incubation/suipay-mcp@0.3.0-dev.18` in MCP config for the `latest` dist-tag.
|
|
9
9
|
`npx -y @mysten-incubation/suipay-mcp@dev` tracks the `dev` prerelease line.
|
|
10
10
|
`1.0.1` remains on the registry as a historical release; do not install it
|
|
11
11
|
for new agents.
|
|
@@ -13,7 +13,7 @@ for new agents.
|
|
|
13
13
|
## Install
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
claude mcp add --scope user suipay -- npx -y @mysten-incubation/suipay-mcp@0.3.0-dev.
|
|
16
|
+
claude mcp add --scope user suipay -- npx -y @mysten-incubation/suipay-mcp@0.3.0-dev.18
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
`@dev` installs the Railway-dev gateway/console defaults. A workspace
|
|
@@ -155,10 +155,10 @@ Default is Railway **suipay-dev**. `--local` / `target: "local"` is laptop-only.
|
|
|
155
155
|
|
|
156
156
|
```bash
|
|
157
157
|
# Railway suipay-dev (default)
|
|
158
|
-
npx @mysten-incubation/suipay-mcp@0.3.0-dev.
|
|
158
|
+
npx @mysten-incubation/suipay-mcp@0.3.0-dev.18
|
|
159
159
|
|
|
160
160
|
# Laptop stack
|
|
161
|
-
npx @mysten-incubation/suipay-mcp@0.3.0-dev.
|
|
161
|
+
npx @mysten-incubation/suipay-mcp@0.3.0-dev.18 --local
|
|
162
162
|
```
|
|
163
163
|
|
|
164
164
|
`SUIPAY_MCP_TARGET=local|dev` selects the same preset. Explicit
|
package/dist/bin/suipay.js
CHANGED
|
@@ -1759,12 +1759,6 @@ import { fromBase64 as fromBase644, toBase64 as toBase643 } from "@mysten/sui/ut
|
|
|
1759
1759
|
|
|
1760
1760
|
// ../sdk/dist/protocol/auth-params.js
|
|
1761
1761
|
var TOKEN = /^[A-Za-z0-9!#$%&'*+\-.^_`|~]+$/;
|
|
1762
|
-
function formatAuthParams(params) {
|
|
1763
|
-
return Object.entries(params).map(([k, v]) => `${k}=${TOKEN.test(v) ? v : quote(v)}`).join(", ");
|
|
1764
|
-
}
|
|
1765
|
-
function quote(value) {
|
|
1766
|
-
return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
1767
|
-
}
|
|
1768
1762
|
function parseAuthHeader(header) {
|
|
1769
1763
|
const trimmed = header.trim();
|
|
1770
1764
|
const firstSpace = trimmed.indexOf(" ");
|
|
@@ -1843,6 +1837,19 @@ function bytesToBase64Url(bytes) {
|
|
|
1843
1837
|
const base64 = typeof globalThis.btoa === "function" ? globalThis.btoa(binary) : Buffer.from(bytes).toString("base64");
|
|
1844
1838
|
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
1845
1839
|
}
|
|
1840
|
+
function bytesFromBase64Url(s) {
|
|
1841
|
+
const normalized = s.replace(/-/g, "+").replace(/_/g, "/");
|
|
1842
|
+
const pad = (4 - normalized.length % 4) % 4;
|
|
1843
|
+
const base64 = normalized + "=".repeat(pad);
|
|
1844
|
+
if (typeof globalThis.atob === "function") {
|
|
1845
|
+
const binary = globalThis.atob(base64);
|
|
1846
|
+
const out = new Uint8Array(binary.length);
|
|
1847
|
+
for (let i = 0; i < binary.length; i++)
|
|
1848
|
+
out[i] = binary.charCodeAt(i);
|
|
1849
|
+
return out;
|
|
1850
|
+
}
|
|
1851
|
+
return Uint8Array.from(Buffer.from(base64, "base64"));
|
|
1852
|
+
}
|
|
1846
1853
|
|
|
1847
1854
|
// ../sdk/dist/protocol/challenge.js
|
|
1848
1855
|
import { Ed25519PublicKey } from "@mysten/sui/keypairs/ed25519";
|
|
@@ -2187,9 +2194,220 @@ function offerToBase64Url(offer) {
|
|
|
2187
2194
|
}
|
|
2188
2195
|
var MPP_SCHEME = "Payment";
|
|
2189
2196
|
var MPP_METHOD = "sui.charge";
|
|
2197
|
+
var MPP_SUI_METHOD = "sui";
|
|
2198
|
+
var MPP_CHARGE_INTENT = "charge";
|
|
2199
|
+
var MPP_RECEIPT_STATUS = "success";
|
|
2200
|
+
var LEGACY_RECEIPT_STATUS = "settled";
|
|
2190
2201
|
var MPP_CHALLENGE_HEADER = "WWW-Authenticate";
|
|
2191
2202
|
var MPP_CREDENTIAL_HEADER = "Authorization";
|
|
2192
2203
|
var MPP_RECEIPT_HEADER = "Payment-Receipt";
|
|
2204
|
+
var HEADER_TEXT_REPLACEMENTS = {
|
|
2205
|
+
"\u2264": "<=",
|
|
2206
|
+
// ≤ less-than-or-equal
|
|
2207
|
+
"\u2265": ">=",
|
|
2208
|
+
// ≥ greater-than-or-equal
|
|
2209
|
+
"\u2014": "-",
|
|
2210
|
+
// — em dash
|
|
2211
|
+
"\u2013": "-",
|
|
2212
|
+
// – en dash
|
|
2213
|
+
"\u2018": "'",
|
|
2214
|
+
// ' left single quote
|
|
2215
|
+
"\u2019": "'",
|
|
2216
|
+
// ' right single quote
|
|
2217
|
+
"\u201C": '"',
|
|
2218
|
+
// " left double quote
|
|
2219
|
+
"\u201D": '"'
|
|
2220
|
+
// " right double quote
|
|
2221
|
+
};
|
|
2222
|
+
function latin1HeaderText(value) {
|
|
2223
|
+
let out = "";
|
|
2224
|
+
for (const ch of value) {
|
|
2225
|
+
const mapped = HEADER_TEXT_REPLACEMENTS[ch];
|
|
2226
|
+
if (mapped !== void 0)
|
|
2227
|
+
out += mapped;
|
|
2228
|
+
else if (ch.codePointAt(0) > 255)
|
|
2229
|
+
out += "?";
|
|
2230
|
+
else
|
|
2231
|
+
out += ch;
|
|
2232
|
+
}
|
|
2233
|
+
return out;
|
|
2234
|
+
}
|
|
2235
|
+
var DAY_MS = 864e5;
|
|
2236
|
+
function billingPeriod(periodMs) {
|
|
2237
|
+
if (!Number.isInteger(periodMs) || periodMs < DAY_MS || periodMs % DAY_MS !== 0)
|
|
2238
|
+
return null;
|
|
2239
|
+
const days = periodMs / DAY_MS;
|
|
2240
|
+
if (days % 7 === 0)
|
|
2241
|
+
return { periodCount: String(days / 7), periodUnit: "week" };
|
|
2242
|
+
return { periodCount: String(days), periodUnit: "day" };
|
|
2243
|
+
}
|
|
2244
|
+
function billingPeriodMs(unit, count) {
|
|
2245
|
+
if (!Number.isInteger(count) || count <= 0)
|
|
2246
|
+
return null;
|
|
2247
|
+
if (unit === "day")
|
|
2248
|
+
return count * DAY_MS;
|
|
2249
|
+
if (unit === "week")
|
|
2250
|
+
return count * 7 * DAY_MS;
|
|
2251
|
+
return null;
|
|
2252
|
+
}
|
|
2253
|
+
function expiresWire(offer) {
|
|
2254
|
+
if (typeof offer.expiresAt !== "number" || !Number.isFinite(offer.expiresAt))
|
|
2255
|
+
return void 0;
|
|
2256
|
+
return new Date(offer.expiresAt).toISOString();
|
|
2257
|
+
}
|
|
2258
|
+
function flatParams(offer) {
|
|
2259
|
+
const params = {
|
|
2260
|
+
amount: offer.amount,
|
|
2261
|
+
asset: offer.asset,
|
|
2262
|
+
network: offer.network,
|
|
2263
|
+
recipient: offer.payTo,
|
|
2264
|
+
package: offer.packageId,
|
|
2265
|
+
resource: offer.resource,
|
|
2266
|
+
digest: offer.digest
|
|
2267
|
+
};
|
|
2268
|
+
if (typeof offer.decimals === "number")
|
|
2269
|
+
params.decimals = String(offer.decimals);
|
|
2270
|
+
if (typeof offer.description === "string") {
|
|
2271
|
+
params.description = latin1HeaderText(offer.description);
|
|
2272
|
+
}
|
|
2273
|
+
if (typeof offer.issuedAt === "number" && Number.isFinite(offer.issuedAt)) {
|
|
2274
|
+
params.issued = new Date(offer.issuedAt).toISOString();
|
|
2275
|
+
}
|
|
2276
|
+
if (typeof offer.expiresAt === "number" && Number.isFinite(offer.expiresAt)) {
|
|
2277
|
+
params.expires = new Date(offer.expiresAt).toISOString();
|
|
2278
|
+
}
|
|
2279
|
+
if (offer.netAmount !== void 0)
|
|
2280
|
+
params.net_amount = offer.netAmount;
|
|
2281
|
+
if (offer.platformFee !== void 0)
|
|
2282
|
+
params.platform_fee = offer.platformFee;
|
|
2283
|
+
if (offer.digestVersion !== void 0)
|
|
2284
|
+
params.digest_version = String(offer.digestVersion);
|
|
2285
|
+
if (offer.settlementRail !== void 0)
|
|
2286
|
+
params.settlement_rail = offer.settlementRail;
|
|
2287
|
+
if (offer.serviceId !== void 0)
|
|
2288
|
+
params.service_id = offer.serviceId;
|
|
2289
|
+
if (offer.serviceRevision !== void 0) {
|
|
2290
|
+
params.service_revision = String(offer.serviceRevision);
|
|
2291
|
+
}
|
|
2292
|
+
if (offer.targetHash !== void 0)
|
|
2293
|
+
params.target_hash = offer.targetHash;
|
|
2294
|
+
if (offer.authorizationEpoch !== void 0) {
|
|
2295
|
+
params.authorization_epoch = String(offer.authorizationEpoch);
|
|
2296
|
+
}
|
|
2297
|
+
if (offer.method !== void 0)
|
|
2298
|
+
params.http_method = offer.method;
|
|
2299
|
+
if (offer.path !== void 0)
|
|
2300
|
+
params.http_path = offer.path;
|
|
2301
|
+
if (offer.bodyHash !== void 0)
|
|
2302
|
+
params.body_hash = offer.bodyHash;
|
|
2303
|
+
if (offer.contentType !== void 0)
|
|
2304
|
+
params.content_type = offer.contentType;
|
|
2305
|
+
if (offer.intent !== void 0)
|
|
2306
|
+
params.intent = offer.intent;
|
|
2307
|
+
if (offer.periodMs !== void 0)
|
|
2308
|
+
params.period_ms = String(offer.periodMs);
|
|
2309
|
+
if (offer.periodCount !== void 0)
|
|
2310
|
+
params.period_count = String(offer.periodCount);
|
|
2311
|
+
if (offer.refundable !== void 0)
|
|
2312
|
+
params.refundable = offer.refundable ? "true" : "false";
|
|
2313
|
+
if (offer.refundWindowMs !== void 0) {
|
|
2314
|
+
params.refund_window_ms = String(offer.refundWindowMs);
|
|
2315
|
+
}
|
|
2316
|
+
if (offer.decideWindowMs !== void 0) {
|
|
2317
|
+
params.decide_window_ms = String(offer.decideWindowMs);
|
|
2318
|
+
}
|
|
2319
|
+
if (offer.chainId !== void 0)
|
|
2320
|
+
params.chain_id = String(offer.chainId);
|
|
2321
|
+
if (offer.paymentSalt !== void 0)
|
|
2322
|
+
params.payment_salt = offer.paymentSalt;
|
|
2323
|
+
if (offer.refundConfigId !== void 0)
|
|
2324
|
+
params.refund_config_id = offer.refundConfigId;
|
|
2325
|
+
if (offer.refundTo !== void 0)
|
|
2326
|
+
params.refund_to = offer.refundTo;
|
|
2327
|
+
if (offer.sponsorGasOwner !== void 0) {
|
|
2328
|
+
params.sponsor_gas_owner = offer.sponsorGasOwner;
|
|
2329
|
+
}
|
|
2330
|
+
if (offer.sponsorGasBudget !== void 0) {
|
|
2331
|
+
params.sponsor_gas_budget = offer.sponsorGasBudget;
|
|
2332
|
+
}
|
|
2333
|
+
if (offer.sponsorGasPrice !== void 0) {
|
|
2334
|
+
params.sponsor_gas_price = offer.sponsorGasPrice;
|
|
2335
|
+
}
|
|
2336
|
+
if (offer.sponsorGasPayment !== void 0) {
|
|
2337
|
+
params.sponsor_gas_payment = offer.sponsorGasPayment;
|
|
2338
|
+
}
|
|
2339
|
+
if (offer.acceptedRails !== void 0) {
|
|
2340
|
+
params.accepted_rails = offer.acceptedRails.join(",");
|
|
2341
|
+
}
|
|
2342
|
+
if (offer.exclusionProtocolVersion !== void 0) {
|
|
2343
|
+
params.exclusion_protocol_version = String(offer.exclusionProtocolVersion);
|
|
2344
|
+
}
|
|
2345
|
+
if (offer.registryIdentity !== void 0) {
|
|
2346
|
+
params.registry_identity = offer.registryIdentity;
|
|
2347
|
+
}
|
|
2348
|
+
if (offer.sig !== void 0)
|
|
2349
|
+
params.sig = offer.sig;
|
|
2350
|
+
if (offer.sigKid !== void 0)
|
|
2351
|
+
params.sig_kid = offer.sigKid;
|
|
2352
|
+
return params;
|
|
2353
|
+
}
|
|
2354
|
+
function legacyRequestBlob(offer, copies = false) {
|
|
2355
|
+
const params = flatParams(offer);
|
|
2356
|
+
if (copies) {
|
|
2357
|
+
params.method = MPP_SUI_METHOD;
|
|
2358
|
+
params.realm = "suipay";
|
|
2359
|
+
params.challenge = offer.challengeId;
|
|
2360
|
+
if (typeof offer.mimeType === "string")
|
|
2361
|
+
params.type = offer.mimeType;
|
|
2362
|
+
}
|
|
2363
|
+
return bytesToBase64Url(new TextEncoder().encode(canonicalJson(params)));
|
|
2364
|
+
}
|
|
2365
|
+
function requestBlob(offer) {
|
|
2366
|
+
const flat = flatParams(offer);
|
|
2367
|
+
const details = { ...flat };
|
|
2368
|
+
delete details.amount;
|
|
2369
|
+
delete details.asset;
|
|
2370
|
+
delete details.recipient;
|
|
2371
|
+
delete details.description;
|
|
2372
|
+
delete details.expires;
|
|
2373
|
+
const body = {
|
|
2374
|
+
amount: flat.amount,
|
|
2375
|
+
currency: flat.asset,
|
|
2376
|
+
methodDetails: details
|
|
2377
|
+
};
|
|
2378
|
+
if (flat.recipient !== void 0)
|
|
2379
|
+
body.recipient = flat.recipient;
|
|
2380
|
+
if (flat.description !== void 0)
|
|
2381
|
+
body.description = flat.description;
|
|
2382
|
+
if (wireIntent(offer) === "subscription") {
|
|
2383
|
+
delete details.period_ms;
|
|
2384
|
+
const periodMs = offer.periodMs;
|
|
2385
|
+
const billing = typeof periodMs === "number" ? billingPeriod(periodMs) : null;
|
|
2386
|
+
if (!billing) {
|
|
2387
|
+
throw new Error("subscription periodMs is not an exact number of days");
|
|
2388
|
+
}
|
|
2389
|
+
body.periodCount = billing.periodCount;
|
|
2390
|
+
body.periodUnit = billing.periodUnit;
|
|
2391
|
+
const periodCount = offer.periodCount;
|
|
2392
|
+
const issuedAt = offer.issuedAt;
|
|
2393
|
+
if (typeof periodMs === "number" && typeof periodCount === "number" && typeof issuedAt === "number" && Number.isSafeInteger(periodMs) && Number.isSafeInteger(periodCount) && Number.isSafeInteger(issuedAt) && Number.isSafeInteger(periodMs * periodCount)) {
|
|
2394
|
+
const end = issuedAt + periodMs * periodCount;
|
|
2395
|
+
if (Number.isSafeInteger(end))
|
|
2396
|
+
body.subscriptionExpires = new Date(end).toISOString();
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
return bytesToBase64Url(new TextEncoder().encode(canonicalJsonValue(body)));
|
|
2400
|
+
}
|
|
2401
|
+
function issuedRequestBlob(offer) {
|
|
2402
|
+
return requestBlob(offer);
|
|
2403
|
+
}
|
|
2404
|
+
function echoedRequestBlob(offer) {
|
|
2405
|
+
try {
|
|
2406
|
+
return issuedRequestBlob(offer);
|
|
2407
|
+
} catch {
|
|
2408
|
+
return legacyRequestBlob(offer);
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2193
2411
|
function splitChallenges(header) {
|
|
2194
2412
|
const scheme = `${MPP_SCHEME} `;
|
|
2195
2413
|
const value = header.trim();
|
|
@@ -2249,11 +2467,120 @@ function decodeChallenge(header, opts) {
|
|
|
2249
2467
|
}
|
|
2250
2468
|
return null;
|
|
2251
2469
|
}
|
|
2470
|
+
function canonicalJson(fields) {
|
|
2471
|
+
const keys = Object.keys(fields).sort();
|
|
2472
|
+
return `{${keys.map((key) => `${JSON.stringify(key)}:${JSON.stringify(fields[key])}`).join(",")}}`;
|
|
2473
|
+
}
|
|
2474
|
+
function canonicalJsonValue(value) {
|
|
2475
|
+
if (value === null || typeof value !== "object")
|
|
2476
|
+
return JSON.stringify(value);
|
|
2477
|
+
if (Array.isArray(value))
|
|
2478
|
+
return `[${value.map(canonicalJsonValue).join(",")}]`;
|
|
2479
|
+
const fields = value;
|
|
2480
|
+
const keys = Object.keys(fields).sort();
|
|
2481
|
+
return `{${keys.map((key) => `${JSON.stringify(key)}:${canonicalJsonValue(fields[key])}`).join(",")}}`;
|
|
2482
|
+
}
|
|
2483
|
+
function wireIntent(offer) {
|
|
2484
|
+
return offer.intent === "subscription" ? "subscription" : MPP_CHARGE_INTENT;
|
|
2485
|
+
}
|
|
2486
|
+
var REQUEST_TOP_LEVEL = /* @__PURE__ */ new Set([
|
|
2487
|
+
"amount",
|
|
2488
|
+
"asset",
|
|
2489
|
+
"currency",
|
|
2490
|
+
"description",
|
|
2491
|
+
"externalId",
|
|
2492
|
+
"recipient",
|
|
2493
|
+
"subscriptionExpires"
|
|
2494
|
+
]);
|
|
2495
|
+
function takeStrings(source, into) {
|
|
2496
|
+
for (const [key, value] of Object.entries(source)) {
|
|
2497
|
+
if (typeof value !== "string")
|
|
2498
|
+
return false;
|
|
2499
|
+
into[key] = value;
|
|
2500
|
+
}
|
|
2501
|
+
return true;
|
|
2502
|
+
}
|
|
2503
|
+
function officialParams(params) {
|
|
2504
|
+
if (params.method !== MPP_SUI_METHOD || !params.request)
|
|
2505
|
+
return null;
|
|
2506
|
+
if (params.intent !== MPP_CHARGE_INTENT && params.intent !== "subscription")
|
|
2507
|
+
return null;
|
|
2508
|
+
let body;
|
|
2509
|
+
try {
|
|
2510
|
+
body = JSON.parse(new TextDecoder().decode(bytesFromBase64Url(params.request)));
|
|
2511
|
+
} catch {
|
|
2512
|
+
return null;
|
|
2513
|
+
}
|
|
2514
|
+
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
2515
|
+
return null;
|
|
2516
|
+
const record = body;
|
|
2517
|
+
const fields = {};
|
|
2518
|
+
const details = record.methodDetails;
|
|
2519
|
+
if (details !== void 0) {
|
|
2520
|
+
if (!details || typeof details !== "object" || Array.isArray(details))
|
|
2521
|
+
return null;
|
|
2522
|
+
if (!takeStrings(details, fields))
|
|
2523
|
+
return null;
|
|
2524
|
+
for (const [key, value] of Object.entries(record)) {
|
|
2525
|
+
if (key === "methodDetails" || key === "periodCount" || key === "periodUnit")
|
|
2526
|
+
continue;
|
|
2527
|
+
if (typeof value !== "string" || !REQUEST_TOP_LEVEL.has(key))
|
|
2528
|
+
return null;
|
|
2529
|
+
if (fields[key] !== void 0 && fields[key] !== value)
|
|
2530
|
+
return null;
|
|
2531
|
+
fields[key] = value;
|
|
2532
|
+
}
|
|
2533
|
+
const periodCount = record.periodCount;
|
|
2534
|
+
const periodUnit = record.periodUnit;
|
|
2535
|
+
if (periodCount !== void 0 || periodUnit !== void 0) {
|
|
2536
|
+
if (typeof periodCount !== "string" || typeof periodUnit !== "string")
|
|
2537
|
+
return null;
|
|
2538
|
+
if (!/^[1-9]\d*$/.test(periodCount))
|
|
2539
|
+
return null;
|
|
2540
|
+
const ms = billingPeriodMs(periodUnit, Number(periodCount));
|
|
2541
|
+
if (ms === null)
|
|
2542
|
+
return null;
|
|
2543
|
+
if (fields.period_ms !== void 0 && fields.period_ms !== String(ms))
|
|
2544
|
+
return null;
|
|
2545
|
+
fields.period_ms = String(ms);
|
|
2546
|
+
}
|
|
2547
|
+
if (params.intent === "subscription" && fields.period_ms === void 0)
|
|
2548
|
+
return null;
|
|
2549
|
+
} else if (!takeStrings(record, fields)) {
|
|
2550
|
+
return null;
|
|
2551
|
+
}
|
|
2552
|
+
if (fields.currency !== void 0) {
|
|
2553
|
+
if (fields.asset !== void 0 && fields.asset !== fields.currency)
|
|
2554
|
+
return null;
|
|
2555
|
+
fields.asset = fields.currency;
|
|
2556
|
+
}
|
|
2557
|
+
if (params.expires !== void 0) {
|
|
2558
|
+
if (fields.expires !== void 0 && fields.expires !== params.expires)
|
|
2559
|
+
return null;
|
|
2560
|
+
if (fields.expires === void 0)
|
|
2561
|
+
fields.expires = params.expires;
|
|
2562
|
+
}
|
|
2563
|
+
if (!fields.challenge && params.id)
|
|
2564
|
+
fields.challenge = params.id;
|
|
2565
|
+
if (fields.method === void 0)
|
|
2566
|
+
fields.method = MPP_SUI_METHOD;
|
|
2567
|
+
if (fields.method !== MPP_METHOD && fields.method !== MPP_SUI_METHOD)
|
|
2568
|
+
return null;
|
|
2569
|
+
if (fields.intent !== void 0 && fields.intent !== params.intent)
|
|
2570
|
+
return null;
|
|
2571
|
+
if (fields.intent === void 0 && params.intent === "subscription")
|
|
2572
|
+
return null;
|
|
2573
|
+
fields.method = MPP_METHOD;
|
|
2574
|
+
return fields;
|
|
2575
|
+
}
|
|
2252
2576
|
function decodeSingleChallenge(header) {
|
|
2253
2577
|
const parsed = parseAuthHeader(header);
|
|
2254
2578
|
if (!parsed || parsed.scheme !== MPP_SCHEME)
|
|
2255
2579
|
return null;
|
|
2256
|
-
const
|
|
2580
|
+
const pinned = officialParams(parsed.params);
|
|
2581
|
+
const p = { ...pinned ?? parsed.params };
|
|
2582
|
+
if (p.method === MPP_SUI_METHOD)
|
|
2583
|
+
p.method = MPP_METHOD;
|
|
2257
2584
|
if (p.method !== MPP_METHOD)
|
|
2258
2585
|
return null;
|
|
2259
2586
|
const required = [
|
|
@@ -2338,13 +2665,15 @@ function decodeSingleChallenge(header) {
|
|
|
2338
2665
|
offer.intent = p.intent;
|
|
2339
2666
|
if (p.period_ms !== void 0) {
|
|
2340
2667
|
const ms = Number(p.period_ms);
|
|
2341
|
-
if (Number.
|
|
2342
|
-
|
|
2668
|
+
if (!Number.isSafeInteger(ms) || ms <= 0)
|
|
2669
|
+
return null;
|
|
2670
|
+
offer.periodMs = ms;
|
|
2343
2671
|
}
|
|
2344
2672
|
if (p.period_count !== void 0) {
|
|
2345
2673
|
const count = Number(p.period_count);
|
|
2346
|
-
if (Number.
|
|
2347
|
-
|
|
2674
|
+
if (!Number.isSafeInteger(count) || count <= 0)
|
|
2675
|
+
return null;
|
|
2676
|
+
offer.periodCount = count;
|
|
2348
2677
|
}
|
|
2349
2678
|
if (p.refundable === "true")
|
|
2350
2679
|
offer.refundable = true;
|
|
@@ -2404,25 +2733,46 @@ function decodeSingleChallenge(header) {
|
|
|
2404
2733
|
offer.sigKid = p.sig_kid;
|
|
2405
2734
|
return offer;
|
|
2406
2735
|
}
|
|
2736
|
+
function echoedChallenge(offer, challengeId) {
|
|
2737
|
+
const challenge = {
|
|
2738
|
+
id: challengeId,
|
|
2739
|
+
realm: "suipay",
|
|
2740
|
+
method: MPP_SUI_METHOD,
|
|
2741
|
+
intent: wireIntent(offer),
|
|
2742
|
+
// Section 5.2 echoes the original challenge, including its request.
|
|
2743
|
+
request: echoedRequestBlob(offer)
|
|
2744
|
+
};
|
|
2745
|
+
const expires = expiresWire(offer);
|
|
2746
|
+
if (expires !== void 0)
|
|
2747
|
+
challenge.expires = expires;
|
|
2748
|
+
return challenge;
|
|
2749
|
+
}
|
|
2750
|
+
function encodeOfficialMessage(body) {
|
|
2751
|
+
return `${MPP_SCHEME} ${bytesToBase64Url(new TextEncoder().encode(canonicalJsonValue(body)))}`;
|
|
2752
|
+
}
|
|
2407
2753
|
function encodeProof(proof) {
|
|
2408
|
-
return
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2754
|
+
return encodeOfficialMessage({
|
|
2755
|
+
challenge: echoedChallenge(proof.offer, proof.challengeId),
|
|
2756
|
+
payload: {
|
|
2757
|
+
payer: proof.payer,
|
|
2758
|
+
offer: offerToBase64Url(proof.offer),
|
|
2759
|
+
digest: proof.txDigest
|
|
2760
|
+
}
|
|
2761
|
+
});
|
|
2415
2762
|
}
|
|
2416
|
-
function
|
|
2417
|
-
|
|
2418
|
-
if (!parsed)
|
|
2763
|
+
function receiptFromParams(p) {
|
|
2764
|
+
if (p.method !== MPP_METHOD && p.method !== MPP_SUI_METHOD)
|
|
2419
2765
|
return null;
|
|
2420
|
-
|
|
2421
|
-
|
|
2766
|
+
if (p.status !== MPP_RECEIPT_STATUS && p.status !== LEGACY_RECEIPT_STATUS)
|
|
2767
|
+
return null;
|
|
2768
|
+
if (p.tx_digest && p.reference && p.tx_digest !== p.reference)
|
|
2769
|
+
return null;
|
|
2770
|
+
const txDigest = p.tx_digest || p.reference;
|
|
2771
|
+
if (!p.challenge || !txDigest || !p.payer || !p.amount || !p.asset || !p.network)
|
|
2422
2772
|
return null;
|
|
2423
2773
|
const receipt = {
|
|
2424
2774
|
challengeId: p.challenge,
|
|
2425
|
-
txDigest
|
|
2775
|
+
txDigest,
|
|
2426
2776
|
network: p.network,
|
|
2427
2777
|
payer: p.payer,
|
|
2428
2778
|
amount: p.amount,
|
|
@@ -2443,6 +2793,34 @@ function decodeReceipt(header) {
|
|
|
2443
2793
|
receipt.periodIndex = p.period_index;
|
|
2444
2794
|
return receipt;
|
|
2445
2795
|
}
|
|
2796
|
+
function decodeOfficialReceipt(header) {
|
|
2797
|
+
const token = header.trim();
|
|
2798
|
+
if (!/^[A-Za-z0-9_-]+$/.test(token))
|
|
2799
|
+
return null;
|
|
2800
|
+
let body;
|
|
2801
|
+
try {
|
|
2802
|
+
body = JSON.parse(new TextDecoder().decode(bytesFromBase64Url(token)));
|
|
2803
|
+
} catch {
|
|
2804
|
+
return null;
|
|
2805
|
+
}
|
|
2806
|
+
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
2807
|
+
return null;
|
|
2808
|
+
const fields = {};
|
|
2809
|
+
for (const [key, value] of Object.entries(body)) {
|
|
2810
|
+
if (typeof value !== "string")
|
|
2811
|
+
return null;
|
|
2812
|
+
fields[key] = value;
|
|
2813
|
+
}
|
|
2814
|
+
return receiptFromParams(fields);
|
|
2815
|
+
}
|
|
2816
|
+
function decodeReceipt(header) {
|
|
2817
|
+
if (/^[A-Za-z0-9_-]+$/.test(header.trim()))
|
|
2818
|
+
return decodeOfficialReceipt(header);
|
|
2819
|
+
const parsed = parseAuthHeader(`X ${header}`);
|
|
2820
|
+
if (!parsed)
|
|
2821
|
+
return null;
|
|
2822
|
+
return receiptFromParams(parsed.params);
|
|
2823
|
+
}
|
|
2446
2824
|
|
|
2447
2825
|
// ../sdk/dist/protocol/x402.js
|
|
2448
2826
|
import { fromBase64 as fromBase643, toBase64 as toBase642 } from "@mysten/sui/utils";
|
|
@@ -5364,8 +5742,8 @@ function redactSecrets(text2) {
|
|
|
5364
5742
|
out = out.replace(KEY_VALUE_PATTERN, (match, prefix, value) => {
|
|
5365
5743
|
if (COUNTER_KEY_PATTERN.test(prefix.replace(/\s*[:=]\s*$/, "")))
|
|
5366
5744
|
return match;
|
|
5367
|
-
const
|
|
5368
|
-
return `${prefix}${
|
|
5745
|
+
const quote2 = value[0] === '"' || value[0] === "'" ? value[0] : "";
|
|
5746
|
+
return `${prefix}${quote2}${REDACTED}${quote2}`;
|
|
5369
5747
|
});
|
|
5370
5748
|
return out;
|
|
5371
5749
|
}
|
|
@@ -5430,7 +5808,7 @@ function redactOAuthAuthorizationCodes(text2) {
|
|
|
5430
5808
|
if (!OAUTH_HINT.test(text2))
|
|
5431
5809
|
return text2;
|
|
5432
5810
|
let out = text2.replace(OAUTH_FORM_CODE, `$1code=${REDACTED}`);
|
|
5433
|
-
out = out.replace(OAUTH_INSPECT_CODE, (match2, prefix,
|
|
5811
|
+
out = out.replace(OAUTH_INSPECT_CODE, (match2, prefix, quote2, value) => isSystemErrorCode(value) ? match2 : `${prefix}code: ${quote2}${REDACTED}${quote2}`);
|
|
5434
5812
|
OAUTH_JSON_CODE_KEY.lastIndex = 0;
|
|
5435
5813
|
let last = 0;
|
|
5436
5814
|
let rebuilt = "";
|
|
@@ -5454,8 +5832,8 @@ function redactOAuthAuthorizationCodes(text2) {
|
|
|
5454
5832
|
}
|
|
5455
5833
|
function scanQuotedString(text2, i) {
|
|
5456
5834
|
const escapedOpen = text2[i] === "\\" && (text2[i + 1] === '"' || text2[i + 1] === "'") ? 1 : 0;
|
|
5457
|
-
const
|
|
5458
|
-
if (
|
|
5835
|
+
const quote2 = text2[i + escapedOpen];
|
|
5836
|
+
if (quote2 !== '"' && quote2 !== "'")
|
|
5459
5837
|
return { end: i, open: "", close: "" };
|
|
5460
5838
|
const open2 = text2.slice(i, i + escapedOpen + 1);
|
|
5461
5839
|
if (escapedOpen === 1) {
|
|
@@ -5478,7 +5856,7 @@ function scanQuotedString(text2, i) {
|
|
|
5478
5856
|
innerEscaped = true;
|
|
5479
5857
|
continue;
|
|
5480
5858
|
}
|
|
5481
|
-
if (decoded ===
|
|
5859
|
+
if (decoded === quote2)
|
|
5482
5860
|
return { end: k2, open: open2, close: open2 };
|
|
5483
5861
|
}
|
|
5484
5862
|
return { end: text2.length, open: open2, close: "" };
|
|
@@ -5489,8 +5867,8 @@ function scanQuotedString(text2, i) {
|
|
|
5489
5867
|
k += 2;
|
|
5490
5868
|
continue;
|
|
5491
5869
|
}
|
|
5492
|
-
if (text2[k] ===
|
|
5493
|
-
return { end: k + 1, open: open2, close:
|
|
5870
|
+
if (text2[k] === quote2)
|
|
5871
|
+
return { end: k + 1, open: open2, close: quote2 };
|
|
5494
5872
|
k += 1;
|
|
5495
5873
|
}
|
|
5496
5874
|
return { end: text2.length, open: open2, close: "" };
|
|
@@ -5831,6 +6209,8 @@ var CONTEXT_ALLOWLIST = /* @__PURE__ */ new Set([
|
|
|
5831
6209
|
"seedId",
|
|
5832
6210
|
"grantId",
|
|
5833
6211
|
"grantObjectId",
|
|
6212
|
+
"policyId",
|
|
6213
|
+
"onChainPolicyId",
|
|
5834
6214
|
"sameGrantObjectId",
|
|
5835
6215
|
"verifiedGrant",
|
|
5836
6216
|
"poolObjectId",
|
|
@@ -6329,7 +6709,7 @@ function normalizePaidHttpRequest(input) {
|
|
|
6329
6709
|
bodyHash: hashRequestBody(body)
|
|
6330
6710
|
});
|
|
6331
6711
|
}
|
|
6332
|
-
function
|
|
6712
|
+
function canonicalJson2(value, seen = /* @__PURE__ */ new Set()) {
|
|
6333
6713
|
if (value === null)
|
|
6334
6714
|
return "null";
|
|
6335
6715
|
const type = typeof value;
|
|
@@ -6356,10 +6736,10 @@ function canonicalJson(value, seen = /* @__PURE__ */ new Set()) {
|
|
|
6356
6736
|
seen.add(object);
|
|
6357
6737
|
try {
|
|
6358
6738
|
if (Array.isArray(object)) {
|
|
6359
|
-
return `[${object.map((item) =>
|
|
6739
|
+
return `[${object.map((item) => canonicalJson2(item, seen)).join(",")}]`;
|
|
6360
6740
|
}
|
|
6361
6741
|
const entries = Object.entries(object).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
6362
|
-
return `{${entries.map(([key, item]) => `${JSON.stringify(key)}:${
|
|
6742
|
+
return `{${entries.map(([key, item]) => `${JSON.stringify(key)}:${canonicalJson2(item, seen)}`).join(",")}}`;
|
|
6363
6743
|
} finally {
|
|
6364
6744
|
seen.delete(object);
|
|
6365
6745
|
}
|
|
@@ -6381,7 +6761,7 @@ function normalizeMcpPaidHttpRequest(input) {
|
|
|
6381
6761
|
return normalizePaidHttpRequest({
|
|
6382
6762
|
url: input.url,
|
|
6383
6763
|
method,
|
|
6384
|
-
body:
|
|
6764
|
+
body: canonicalJson2(input.json),
|
|
6385
6765
|
contentType: MCP_JSON_CONTENT_TYPE
|
|
6386
6766
|
});
|
|
6387
6767
|
}
|
|
@@ -10896,6 +11276,22 @@ async function settlePreparedMcpPayment(args) {
|
|
|
10896
11276
|
});
|
|
10897
11277
|
}
|
|
10898
11278
|
|
|
11279
|
+
// src/mcp-client-header.ts
|
|
11280
|
+
var MCP_CLIENT_HEADER = "x-suipay-client";
|
|
11281
|
+
var MCP_CLIENT_HEADER_VALUE = "mcp";
|
|
11282
|
+
function withMcpClientFetch(base = fetch) {
|
|
11283
|
+
return (input, init) => {
|
|
11284
|
+
const headers = new Headers(input instanceof Request ? input.headers : void 0);
|
|
11285
|
+
if (init?.headers) {
|
|
11286
|
+
new Headers(init.headers).forEach((value, key) => headers.set(key, value));
|
|
11287
|
+
}
|
|
11288
|
+
if (!headers.has(MCP_CLIENT_HEADER)) {
|
|
11289
|
+
headers.set(MCP_CLIENT_HEADER, MCP_CLIENT_HEADER_VALUE);
|
|
11290
|
+
}
|
|
11291
|
+
return base(input, { ...init, headers });
|
|
11292
|
+
};
|
|
11293
|
+
}
|
|
11294
|
+
|
|
10899
11295
|
// ../sdk/dist/agent-sdk/delegate-agent.js
|
|
10900
11296
|
import { normalizeSuiAddress as normalizeSuiAddress12 } from "@mysten/sui/utils";
|
|
10901
11297
|
|
|
@@ -12701,7 +13097,7 @@ async function prepareSpendAccountPayment(args) {
|
|
|
12701
13097
|
...refundConfigInitialSharedVersion ? { refundConfigInitialSharedVersion } : {}
|
|
12702
13098
|
});
|
|
12703
13099
|
};
|
|
12704
|
-
const rawFetch = deps.fetchImpl ?? fetch;
|
|
13100
|
+
const rawFetch = withMcpClientFetch(deps.fetchImpl ?? fetch);
|
|
12705
13101
|
const wrappedFetch = (input, init) => {
|
|
12706
13102
|
const probeUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
12707
13103
|
if (probeUrl === request.url || probeUrl === args.url) {
|
|
@@ -13627,7 +14023,7 @@ async function delegateProofHeaders(resourceUrl, method, key, fetchImpl) {
|
|
|
13627
14023
|
[DELEGATE_PROOF_HEADER]: signature
|
|
13628
14024
|
};
|
|
13629
14025
|
}
|
|
13630
|
-
async function
|
|
14026
|
+
async function quote(resourceUrl, probeBody, options = {}) {
|
|
13631
14027
|
const doFetch = options.fetchImpl ?? fetch;
|
|
13632
14028
|
const remedy = options.remedy ?? "Supply them and quote again.";
|
|
13633
14029
|
const method = liveHttpMethod(options.method);
|
|
@@ -13896,7 +14292,7 @@ async function pay(args, cfg, deps = {}) {
|
|
|
13896
14292
|
cfg,
|
|
13897
14293
|
...intent.dialect ? { preferredDialect: intent.dialect } : {},
|
|
13898
14294
|
deps: {
|
|
13899
|
-
|
|
14295
|
+
fetchImpl: withMcpClientFetch(deps.fetchImpl ?? fetch),
|
|
13900
14296
|
...trace ? { trace } : {},
|
|
13901
14297
|
...deps.resolveExclusionRegistry ? { resolveExclusionRegistry: deps.resolveExclusionRegistry } : {},
|
|
13902
14298
|
...deps.buildPayKind ? { buildPayKind: deps.buildPayKind } : liveKindBuilder ? {
|
|
@@ -13948,7 +14344,9 @@ async function pay(args, cfg, deps = {}) {
|
|
|
13948
14344
|
cfg: { gatewayUrl: cfg.gatewayUrl },
|
|
13949
14345
|
deps: {
|
|
13950
14346
|
...deps.agentHeld.payerDeps,
|
|
13951
|
-
|
|
14347
|
+
fetchImpl: withMcpClientFetch(
|
|
14348
|
+
deps.agentHeld.payerDeps.fetchImpl ?? deps.fetchImpl ?? fetch
|
|
14349
|
+
)
|
|
13952
14350
|
}
|
|
13953
14351
|
});
|
|
13954
14352
|
return renderSettled(settled);
|
|
@@ -14073,7 +14471,7 @@ async function payStdioWithLocalKey(args) {
|
|
|
14073
14471
|
async function openGrantQuote(request, maxAmount, coinType, deps) {
|
|
14074
14472
|
let quoted;
|
|
14075
14473
|
try {
|
|
14076
|
-
quoted = await
|
|
14474
|
+
quoted = await quote(new URL(request.url), new TextDecoder().decode(request.body), {
|
|
14077
14475
|
...deps.fetchImpl ? { fetchImpl: deps.fetchImpl } : {},
|
|
14078
14476
|
method: request.method,
|
|
14079
14477
|
rail: "delegate"
|
|
@@ -14175,7 +14573,7 @@ async function stdioPayerAndReader(cfg, deps) {
|
|
|
14175
14573
|
gatewayUrl,
|
|
14176
14574
|
keypair,
|
|
14177
14575
|
...select ? { select } : {},
|
|
14178
|
-
|
|
14576
|
+
fetchImpl: withMcpClientFetch(deps.fetchImpl ?? fetch),
|
|
14179
14577
|
...cfg.rpcUrl ? { fullnodeUrl: cfg.rpcUrl } : {}
|
|
14180
14578
|
});
|
|
14181
14579
|
if (!built.ok) {
|
package/dist/http.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
loadBootProfile,
|
|
3
3
|
main
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-4HWODHQ4.js";
|
|
5
5
|
import {
|
|
6
6
|
MCP_TARGET_PRESETS,
|
|
7
7
|
PACKAGE_NAME,
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
settlePreparedMcpPayment,
|
|
27
27
|
traceMcpHttpRequest,
|
|
28
28
|
verifySpendAccountPayReconstructs
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-JHBXXJ6X.js";
|
|
30
30
|
export {
|
|
31
31
|
MCP_TARGET_PRESETS,
|
|
32
32
|
PACKAGE_NAME,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mysten-incubation/suipay-mcp",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "SuiPay MCP — pay MPP-gated APIs from a spend-account grant with an agent-held delegate key.",
|
|
6
6
|
"repository": {
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"tsup": "^8.0.0",
|
|
43
43
|
"typescript": "^6.0.3",
|
|
44
44
|
"vitest": "^4.1.10",
|
|
45
|
-
"@cmdoss/suipay-
|
|
46
|
-
"@cmdoss/suipay-
|
|
45
|
+
"@cmdoss/suipay-sdk": "0.1.0",
|
|
46
|
+
"@cmdoss/suipay-core": "0.1.0"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsup",
|