@mysten-incubation/suipay-mcp 0.3.0-dev.20 → 0.3.0-dev.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -5
- package/dist/bin/suipay.js +2 -2
- package/dist/{chunk-4HWODHQ4.js → chunk-7L7CQYBL.js} +1 -1
- package/dist/{chunk-JHBXXJ6X.js → chunk-DZUVYB76.js} +204 -146
- package/dist/http.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -2
- package/package.json +1 -1
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.22` 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.22
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
`@dev` installs the Railway-dev gateway/console defaults. A workspace
|
|
@@ -87,7 +87,13 @@ maxAmount: 50000
|
|
|
87
87
|
To store local bytes (Walrus), do not paste base64. Name the file and field.
|
|
88
88
|
Set `SUIPAY_MCP_FILE_ROOT` to an absolute directory; `file` must resolve inside
|
|
89
89
|
it (unset disables attach). Paths under `~/.suipay` are refused even if that
|
|
90
|
-
directory falls inside the root.
|
|
90
|
+
directory falls inside the root. Files with multiple hard links are also refused
|
|
91
|
+
(`request.file_forbidden`), because an allowed path can share a private file's
|
|
92
|
+
bytes. Use a regular file with a single hard link for attachments.
|
|
93
|
+
|
|
94
|
+
This checks current links, not where the bytes came from. A pre-existing hard
|
|
95
|
+
link can pass after the private original is deleted or atomically replaced,
|
|
96
|
+
leaving one link. Do not place hard links to private files in the attachment root.
|
|
91
97
|
|
|
92
98
|
```
|
|
93
99
|
Pay this SuiPay resource with the suipay MCP `pay` tool. Do not write SDK code.
|
|
@@ -155,10 +161,10 @@ Default is Railway **suipay-dev**. `--local` / `target: "local"` is laptop-only.
|
|
|
155
161
|
|
|
156
162
|
```bash
|
|
157
163
|
# Railway suipay-dev (default)
|
|
158
|
-
npx @mysten-incubation/suipay-mcp@0.3.0-dev.
|
|
164
|
+
npx @mysten-incubation/suipay-mcp@0.3.0-dev.22
|
|
159
165
|
|
|
160
166
|
# Laptop stack
|
|
161
|
-
npx @mysten-incubation/suipay-mcp@0.3.0-dev.
|
|
167
|
+
npx @mysten-incubation/suipay-mcp@0.3.0-dev.22 --local
|
|
162
168
|
```
|
|
163
169
|
|
|
164
170
|
`SUIPAY_MCP_TARGET=local|dev` selects the same preset. Explicit
|
package/dist/bin/suipay.js
CHANGED
|
@@ -66,8 +66,8 @@ async function retryRetryable(fn, options = {}) {
|
|
|
66
66
|
throw last;
|
|
67
67
|
}
|
|
68
68
|
function endpointRetrySleep(retryIndex) {
|
|
69
|
-
return new Promise((
|
|
70
|
-
setTimeout(
|
|
69
|
+
return new Promise((resolve2) => {
|
|
70
|
+
setTimeout(resolve2, 40 * 2 ** retryIndex);
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
function createFailoverGrpcClient(options) {
|
|
@@ -8105,8 +8105,8 @@ var X402_EXPIRATION_EPOCHS = 32n;
|
|
|
8105
8105
|
var X402_PRESENT_ATTEMPTS = 10;
|
|
8106
8106
|
var X402_PRESENT_DELAY_MS = 1e3;
|
|
8107
8107
|
function delay(ms) {
|
|
8108
|
-
return new Promise((
|
|
8109
|
-
setTimeout(
|
|
8108
|
+
return new Promise((resolve2) => {
|
|
8109
|
+
setTimeout(resolve2, ms);
|
|
8110
8110
|
});
|
|
8111
8111
|
}
|
|
8112
8112
|
var SUI_CLOCK2 = "0x6";
|
|
@@ -10194,19 +10194,19 @@ async function verifyPreparedSettlementKind(input) {
|
|
|
10194
10194
|
}
|
|
10195
10195
|
const args = cmd.MoveCall.arguments ?? [];
|
|
10196
10196
|
const inputs = data.inputs ?? [];
|
|
10197
|
-
const
|
|
10197
|
+
const resolve2 = (argIdx) => {
|
|
10198
10198
|
const idx = preparedInputIndex(args[argIdx]);
|
|
10199
10199
|
if (idx === null || idx < 0 || idx >= inputs.length)
|
|
10200
10200
|
return void 0;
|
|
10201
10201
|
return inputs[idx];
|
|
10202
10202
|
};
|
|
10203
|
-
const poolObjectId = preparedSharedObjectId(
|
|
10203
|
+
const poolObjectId = preparedSharedObjectId(resolve2(2));
|
|
10204
10204
|
if (input.expected.poolObjectId) {
|
|
10205
10205
|
if (!poolObjectId || !sameAddress2(poolObjectId, input.expected.poolObjectId)) {
|
|
10206
10206
|
throw new Error(`prepared pool ${poolObjectId ?? "(missing)"} does not match expected pool ${input.expected.poolObjectId}`);
|
|
10207
10207
|
}
|
|
10208
10208
|
}
|
|
10209
|
-
const grantObjectId = preparedSharedObjectId(
|
|
10209
|
+
const grantObjectId = preparedSharedObjectId(resolve2(3));
|
|
10210
10210
|
if (!grantObjectId) {
|
|
10211
10211
|
throw new Error("prepared transaction does not name a grant object");
|
|
10212
10212
|
}
|
|
@@ -10214,11 +10214,11 @@ async function verifyPreparedSettlementKind(input) {
|
|
|
10214
10214
|
throw new Error(`prepared grant ${grantObjectId} does not match expected grant ${input.expected.grantObjectId}`);
|
|
10215
10215
|
}
|
|
10216
10216
|
if (accessMode === "open") {
|
|
10217
|
-
const recipient = preparedPureAddress(
|
|
10217
|
+
const recipient = preparedPureAddress(resolve2(4));
|
|
10218
10218
|
if (!recipient || !sameAddress2(recipient, input.expected.recipient)) {
|
|
10219
10219
|
throw new Error(`prepared recipient ${recipient ?? "(missing)"} does not match the requested recipient`);
|
|
10220
10220
|
}
|
|
10221
|
-
const amount = preparedPureU64(
|
|
10221
|
+
const amount = preparedPureU64(resolve2(5));
|
|
10222
10222
|
let expectedAmount;
|
|
10223
10223
|
try {
|
|
10224
10224
|
expectedAmount = BigInt(input.expected.amount);
|
|
@@ -10230,20 +10230,20 @@ async function verifyPreparedSettlementKind(input) {
|
|
|
10230
10230
|
}
|
|
10231
10231
|
} else {
|
|
10232
10232
|
if (input.expected.onChainPolicyId !== void 0) {
|
|
10233
|
-
const policyId = preparedPureU64(
|
|
10233
|
+
const policyId = preparedPureU64(resolve2(4));
|
|
10234
10234
|
const expectedPolicyId = BigInt(input.expected.onChainPolicyId);
|
|
10235
10235
|
if (policyId !== expectedPolicyId) {
|
|
10236
10236
|
throw new Error(`prepared policy_id ${policyId ?? "(missing)"} does not match expected onChainPolicyId`);
|
|
10237
10237
|
}
|
|
10238
10238
|
}
|
|
10239
10239
|
if (input.expected.targetHash) {
|
|
10240
|
-
const targetHash = preparedPureVectorU8(
|
|
10240
|
+
const targetHash = preparedPureVectorU8(resolve2(5));
|
|
10241
10241
|
const expectedBytes = toTargetHashBytes(input.expected.targetHash);
|
|
10242
10242
|
if (!targetHash || !sameBytes(targetHash, expectedBytes)) {
|
|
10243
10243
|
throw new Error("prepared target_hash does not match expected targetHash");
|
|
10244
10244
|
}
|
|
10245
10245
|
}
|
|
10246
|
-
const amount = preparedPureU64(
|
|
10246
|
+
const amount = preparedPureU64(resolve2(6));
|
|
10247
10247
|
let expectedAmount;
|
|
10248
10248
|
try {
|
|
10249
10249
|
expectedAmount = BigInt(input.expected.amount);
|
|
@@ -10254,14 +10254,14 @@ async function verifyPreparedSettlementKind(input) {
|
|
|
10254
10254
|
throw new Error(`prepared amount ${amount ?? "(missing)"} does not match the requested amount`);
|
|
10255
10255
|
}
|
|
10256
10256
|
if (input.expected.paymentIdHash) {
|
|
10257
|
-
const paymentIdHash2 = preparedPureVectorU8(
|
|
10257
|
+
const paymentIdHash2 = preparedPureVectorU8(resolve2(7));
|
|
10258
10258
|
const expectedBytes = toHashBytes(input.expected.paymentIdHash);
|
|
10259
10259
|
if (!paymentIdHash2 || !sameBytes(paymentIdHash2, expectedBytes)) {
|
|
10260
10260
|
throw new Error("prepared payment_id_hash does not match expected paymentIdHash");
|
|
10261
10261
|
}
|
|
10262
10262
|
}
|
|
10263
10263
|
if (input.expected.termsHash) {
|
|
10264
|
-
const termsHash2 = preparedPureVectorU8(
|
|
10264
|
+
const termsHash2 = preparedPureVectorU8(resolve2(8));
|
|
10265
10265
|
const expectedBytes = toHashBytes(input.expected.termsHash);
|
|
10266
10266
|
if (!termsHash2 || !sameBytes(termsHash2, expectedBytes)) {
|
|
10267
10267
|
throw new Error("prepared terms_hash does not match expected termsHash");
|
|
@@ -10272,23 +10272,23 @@ async function verifyPreparedSettlementKind(input) {
|
|
|
10272
10272
|
if (!vault.refundConfigId || vault.chainId === void 0 || vault.decideWindowMs === void 0 || vault.refundWindowMs === void 0 || !vault.paymentSalt) {
|
|
10273
10273
|
throw new Error("refundable prepared settlement is missing vault inputs");
|
|
10274
10274
|
}
|
|
10275
|
-
const chainId = preparedPureU64(
|
|
10275
|
+
const chainId = preparedPureU64(resolve2(11));
|
|
10276
10276
|
if (chainId !== BigInt(vault.chainId)) {
|
|
10277
10277
|
throw new Error("prepared chainId does not match the offer");
|
|
10278
10278
|
}
|
|
10279
|
-
const configId = preparedSharedObjectId(
|
|
10279
|
+
const configId = preparedSharedObjectId(resolve2(12));
|
|
10280
10280
|
if (!configId || !sameAddress2(configId, vault.refundConfigId)) {
|
|
10281
10281
|
throw new Error("prepared refund config does not match the offer");
|
|
10282
10282
|
}
|
|
10283
|
-
const decide = preparedPureU64(
|
|
10283
|
+
const decide = preparedPureU64(resolve2(13));
|
|
10284
10284
|
if (decide !== BigInt(vault.decideWindowMs)) {
|
|
10285
10285
|
throw new Error("prepared decideWindowMs does not match the offer");
|
|
10286
10286
|
}
|
|
10287
|
-
const refundWindow = preparedPureU64(
|
|
10287
|
+
const refundWindow = preparedPureU64(resolve2(14));
|
|
10288
10288
|
if (refundWindow !== BigInt(vault.refundWindowMs)) {
|
|
10289
10289
|
throw new Error("prepared refundWindowMs does not match the offer");
|
|
10290
10290
|
}
|
|
10291
|
-
const salt = preparedPureVectorU8(
|
|
10291
|
+
const salt = preparedPureVectorU8(resolve2(15));
|
|
10292
10292
|
const expectedSalt = new TextEncoder().encode(vault.paymentSalt);
|
|
10293
10293
|
if (!salt || !sameBytes(salt, expectedSalt)) {
|
|
10294
10294
|
throw new Error("prepared paymentSalt does not match the offer");
|
|
@@ -12429,8 +12429,8 @@ async function createPayer(options) {
|
|
|
12429
12429
|
// directory id was configured, so such an offer fails closed (BUILD_FAILED)
|
|
12430
12430
|
// rather than building an unguarded settle. Unguarded offers never call it.
|
|
12431
12431
|
...(() => {
|
|
12432
|
-
const
|
|
12433
|
-
return
|
|
12432
|
+
const resolve2 = createExclusionRegistryResolver(chain.client, exclusionDirectoryObjectId);
|
|
12433
|
+
return resolve2 ? { resolveExclusionRegistry: resolve2 } : {};
|
|
12434
12434
|
})(),
|
|
12435
12435
|
// x402 bounds the transaction's expiration by the current epoch, read from
|
|
12436
12436
|
// the same client as every other chain read here.
|
|
@@ -12494,6 +12494,77 @@ async function createPayer(options) {
|
|
|
12494
12494
|
import { createServer } from "http";
|
|
12495
12495
|
import { randomBytes as randomBytes2, timingSafeEqual } from "crypto";
|
|
12496
12496
|
import open from "open";
|
|
12497
|
+
|
|
12498
|
+
// ../sdk/dist/sponsor/delegate-control.js
|
|
12499
|
+
import { bcs as bcs7 } from "@mysten/sui/bcs";
|
|
12500
|
+
import { verifyPersonalMessageSignature as verifyPersonalMessageSignature3 } from "@mysten/sui/verify";
|
|
12501
|
+
import { normalizeSuiAddress as normalizeSuiAddress13 } from "@mysten/sui/utils";
|
|
12502
|
+
var DELEGATE_CONTROL_DOMAIN = "suipay:delegate-control:v1";
|
|
12503
|
+
var DELEGATE_CONTROL_TTL_MS = 6e4;
|
|
12504
|
+
function canonicalDelegateControlRequest(method, url) {
|
|
12505
|
+
const normalized = method.trim().toUpperCase();
|
|
12506
|
+
if (normalized !== "GET" && normalized !== "POST") {
|
|
12507
|
+
throw new Error("pay-prepare method must be GET or POST");
|
|
12508
|
+
}
|
|
12509
|
+
let parsed;
|
|
12510
|
+
try {
|
|
12511
|
+
parsed = new URL(url);
|
|
12512
|
+
} catch {
|
|
12513
|
+
throw new Error("pay-prepare url must be absolute");
|
|
12514
|
+
}
|
|
12515
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
12516
|
+
throw new Error("pay-prepare url must be http or https");
|
|
12517
|
+
}
|
|
12518
|
+
parsed.search = "";
|
|
12519
|
+
parsed.hash = "";
|
|
12520
|
+
parsed.username = "";
|
|
12521
|
+
parsed.password = "";
|
|
12522
|
+
return { method: normalized, url: parsed.origin + parsed.pathname };
|
|
12523
|
+
}
|
|
12524
|
+
function isDelegateControlPurpose(value) {
|
|
12525
|
+
return value === "register" || value === "pay-prepare";
|
|
12526
|
+
}
|
|
12527
|
+
function encodeDelegateControlPayload(payload) {
|
|
12528
|
+
if (payload.domain !== DELEGATE_CONTROL_DOMAIN) {
|
|
12529
|
+
throw new Error(`domain must be ${DELEGATE_CONTROL_DOMAIN}`);
|
|
12530
|
+
}
|
|
12531
|
+
if (!isDelegateControlPurpose(payload.purpose)) {
|
|
12532
|
+
throw new Error("purpose must be register or pay-prepare");
|
|
12533
|
+
}
|
|
12534
|
+
if (!payload.nonce.trim())
|
|
12535
|
+
throw new Error("nonce is required");
|
|
12536
|
+
if (!Number.isFinite(payload.expiryMs) || payload.expiryMs <= 0) {
|
|
12537
|
+
throw new Error("expiryMs must be a positive finite number");
|
|
12538
|
+
}
|
|
12539
|
+
if (payload.purpose === "register" && !payload.owner.trim()) {
|
|
12540
|
+
throw new Error("register proof binds an owner address");
|
|
12541
|
+
}
|
|
12542
|
+
const request = payload.purpose === "pay-prepare" ? canonicalDelegateControlRequest(payload.method, payload.url) : null;
|
|
12543
|
+
const parts = [];
|
|
12544
|
+
const push = (bytes) => parts.push(bytes);
|
|
12545
|
+
const utf8 = (value) => bcs7.vector(bcs7.u8()).serialize([...new TextEncoder().encode(value)]).toBytes();
|
|
12546
|
+
push(utf8(payload.domain));
|
|
12547
|
+
push(utf8(payload.purpose));
|
|
12548
|
+
push(utf8(payload.nonce));
|
|
12549
|
+
push(bcs7.u64().serialize(BigInt(payload.expiryMs)).toBytes());
|
|
12550
|
+
push(bcs7.Address.serialize(normalizeSuiAddress13(payload.delegate)).toBytes());
|
|
12551
|
+
if (payload.purpose === "register") {
|
|
12552
|
+
push(bcs7.Address.serialize(normalizeSuiAddress13(payload.owner)).toBytes());
|
|
12553
|
+
} else if (request) {
|
|
12554
|
+
push(utf8(request.method));
|
|
12555
|
+
push(utf8(request.url));
|
|
12556
|
+
}
|
|
12557
|
+
const total = parts.reduce((sum, part) => sum + part.length, 0);
|
|
12558
|
+
const out = new Uint8Array(total);
|
|
12559
|
+
let offset = 0;
|
|
12560
|
+
for (const part of parts) {
|
|
12561
|
+
out.set(part, offset);
|
|
12562
|
+
offset += part.length;
|
|
12563
|
+
}
|
|
12564
|
+
return out;
|
|
12565
|
+
}
|
|
12566
|
+
|
|
12567
|
+
// src/stdio-login.ts
|
|
12497
12568
|
var HEX642 = /^[0-9a-f]{64}$/;
|
|
12498
12569
|
var PUBHEX = /^[0-9a-fA-F]{64}$/;
|
|
12499
12570
|
function isPreflight(obj) {
|
|
@@ -12542,7 +12613,7 @@ function normalizeUrl(url) {
|
|
|
12542
12613
|
return url.replace(/\/+$/, "");
|
|
12543
12614
|
}
|
|
12544
12615
|
function readBody2(req, maxBytes = 16 * 1024) {
|
|
12545
|
-
return new Promise((
|
|
12616
|
+
return new Promise((resolve2, reject2) => {
|
|
12546
12617
|
const chunks = [];
|
|
12547
12618
|
let len = 0;
|
|
12548
12619
|
req.on("data", (c) => {
|
|
@@ -12554,7 +12625,7 @@ function readBody2(req, maxBytes = 16 * 1024) {
|
|
|
12554
12625
|
}
|
|
12555
12626
|
chunks.push(c);
|
|
12556
12627
|
});
|
|
12557
|
-
req.on("end", () =>
|
|
12628
|
+
req.on("end", () => resolve2(Buffer.concat(chunks).toString("utf8")));
|
|
12558
12629
|
req.on("error", reject2);
|
|
12559
12630
|
});
|
|
12560
12631
|
}
|
|
@@ -12580,7 +12651,7 @@ async function startStdioLogin(opts) {
|
|
|
12580
12651
|
server.requestTimeout = 1e4;
|
|
12581
12652
|
server.headersTimeout = 1e4;
|
|
12582
12653
|
server.keepAliveTimeout = 5e3;
|
|
12583
|
-
await new Promise((
|
|
12654
|
+
await new Promise((resolve2) => server.listen(0, "127.0.0.1", resolve2));
|
|
12584
12655
|
const port = server.address().port;
|
|
12585
12656
|
const allowedHosts = /* @__PURE__ */ new Set([`127.0.0.1:${port}`, `localhost:${port}`]);
|
|
12586
12657
|
const base = opts.consoleUrl.replace(/\/+$/, "");
|
|
@@ -12590,14 +12661,15 @@ async function startStdioLogin(opts) {
|
|
|
12590
12661
|
} catch {
|
|
12591
12662
|
}
|
|
12592
12663
|
let preflightVerified = false;
|
|
12664
|
+
let proofOwner = null;
|
|
12593
12665
|
let completed = false;
|
|
12594
12666
|
let error = null;
|
|
12595
|
-
const done = new Promise((
|
|
12667
|
+
const done = new Promise((resolve2) => {
|
|
12596
12668
|
const timer = setTimeout(() => {
|
|
12597
12669
|
if (!completed) {
|
|
12598
12670
|
error = new Error(`login timed out after ${timeoutMs}ms`);
|
|
12599
12671
|
server.close();
|
|
12600
|
-
|
|
12672
|
+
resolve2();
|
|
12601
12673
|
}
|
|
12602
12674
|
}, timeoutMs);
|
|
12603
12675
|
timer.unref?.();
|
|
@@ -12625,7 +12697,7 @@ async function startStdioLogin(opts) {
|
|
|
12625
12697
|
res.writeHead(code, { "content-type": type, ...SECURITY_HEADERS, ...extra });
|
|
12626
12698
|
res.end(body);
|
|
12627
12699
|
};
|
|
12628
|
-
const okPath = url.pathname === "/preflight" || url.pathname === "/callback";
|
|
12700
|
+
const okPath = url.pathname === "/preflight" || url.pathname === "/callback" || url.pathname === "/control-proof";
|
|
12629
12701
|
if (req.method === "OPTIONS") {
|
|
12630
12702
|
const extra = { ...cors };
|
|
12631
12703
|
if (okHost && okOrigin && okPath && req.headers["access-control-request-private-network"] === "true") {
|
|
@@ -12664,13 +12736,8 @@ async function startStdioLogin(opts) {
|
|
|
12664
12736
|
res.end(JSON.stringify({ ok: false, error: "invalid preflight payload" }));
|
|
12665
12737
|
return;
|
|
12666
12738
|
}
|
|
12667
|
-
const derived = deriveSuiAddress(
|
|
12668
|
-
|
|
12669
|
-
);
|
|
12670
|
-
const valid = stateEquals(parsed.state, connectState) && stateEquals(
|
|
12671
|
-
parsed.publicKey.toLowerCase(),
|
|
12672
|
-
opts.identity.publicKeyHex.toLowerCase()
|
|
12673
|
-
) && parsed.delegateAddress.toLowerCase() === opts.identity.delegateAddress.toLowerCase() && derived.toLowerCase() === opts.identity.delegateAddress.toLowerCase() && normalizeUrl(parsed.gateway) === expectedGateway;
|
|
12739
|
+
const derived = deriveSuiAddress(Uint8Array.from(Buffer.from(parsed.publicKey, "hex")));
|
|
12740
|
+
const valid = stateEquals(parsed.state, connectState) && stateEquals(parsed.publicKey.toLowerCase(), opts.identity.publicKeyHex.toLowerCase()) && parsed.delegateAddress.toLowerCase() === opts.identity.delegateAddress.toLowerCase() && derived.toLowerCase() === opts.identity.delegateAddress.toLowerCase() && normalizeUrl(parsed.gateway) === expectedGateway;
|
|
12674
12741
|
if (!valid) {
|
|
12675
12742
|
res.writeHead(403, {
|
|
12676
12743
|
"content-type": "application/json",
|
|
@@ -12702,8 +12769,37 @@ async function startStdioLogin(opts) {
|
|
|
12702
12769
|
...cors,
|
|
12703
12770
|
...SECURITY_HEADERS
|
|
12704
12771
|
});
|
|
12705
|
-
res.end(
|
|
12706
|
-
|
|
12772
|
+
res.end(failHtml("Local MCP bridge verification is required before the callback."));
|
|
12773
|
+
return;
|
|
12774
|
+
}
|
|
12775
|
+
if (url.pathname === "/control-proof") {
|
|
12776
|
+
const body = parsed;
|
|
12777
|
+
const challenge = body?.challenge;
|
|
12778
|
+
const expiryMs = challenge?.expiryMs;
|
|
12779
|
+
if (typeof body?.state !== "string" || !stateEquals(body.state, connectState) || !challenge || challenge.domain !== DELEGATE_CONTROL_DOMAIN || challenge.purpose !== "register" || typeof challenge.nonce !== "string" || !challenge.nonce.trim() || typeof challenge.owner !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(challenge.owner) || proofOwner !== null && challenge.owner.toLowerCase() !== proofOwner || typeof challenge.delegate !== "string" || challenge.delegate.toLowerCase() !== opts.identity.delegateAddress.toLowerCase() || typeof expiryMs !== "number" || !Number.isSafeInteger(expiryMs) || expiryMs <= Date.now() || expiryMs > Date.now() + DELEGATE_CONTROL_TTL_MS) {
|
|
12780
|
+
send(403, "Invalid delegate control challenge", "text/plain", cors);
|
|
12781
|
+
return;
|
|
12782
|
+
}
|
|
12783
|
+
if (!opts.signPersonalMessage) {
|
|
12784
|
+
send(503, "Delegate signing is unavailable", "text/plain", cors);
|
|
12785
|
+
return;
|
|
12786
|
+
}
|
|
12787
|
+
proofOwner = challenge.owner.toLowerCase();
|
|
12788
|
+
const signature = await opts.signPersonalMessage(
|
|
12789
|
+
encodeDelegateControlPayload({
|
|
12790
|
+
domain: DELEGATE_CONTROL_DOMAIN,
|
|
12791
|
+
purpose: "register",
|
|
12792
|
+
nonce: challenge.nonce,
|
|
12793
|
+
expiryMs,
|
|
12794
|
+
delegate: opts.identity.delegateAddress,
|
|
12795
|
+
owner: challenge.owner
|
|
12796
|
+
})
|
|
12797
|
+
);
|
|
12798
|
+
send(
|
|
12799
|
+
200,
|
|
12800
|
+
JSON.stringify({ nonce: challenge.nonce, signature }),
|
|
12801
|
+
"application/json",
|
|
12802
|
+
cors
|
|
12707
12803
|
);
|
|
12708
12804
|
return;
|
|
12709
12805
|
}
|
|
@@ -12744,7 +12840,7 @@ async function startStdioLogin(opts) {
|
|
|
12744
12840
|
});
|
|
12745
12841
|
res.end(SUCCESS_HTML);
|
|
12746
12842
|
setTimeout(() => server.close(), 100);
|
|
12747
|
-
|
|
12843
|
+
resolve2();
|
|
12748
12844
|
} catch (err) {
|
|
12749
12845
|
error = err instanceof Error ? err : new Error(String(err));
|
|
12750
12846
|
res.writeHead(500, {
|
|
@@ -12754,7 +12850,7 @@ async function startStdioLogin(opts) {
|
|
|
12754
12850
|
});
|
|
12755
12851
|
res.end(failHtml("Internal error parsing callback."));
|
|
12756
12852
|
setTimeout(() => server.close(), 100);
|
|
12757
|
-
|
|
12853
|
+
resolve2();
|
|
12758
12854
|
}
|
|
12759
12855
|
});
|
|
12760
12856
|
});
|
|
@@ -12779,15 +12875,15 @@ async function startStdioLogin(opts) {
|
|
|
12779
12875
|
|
|
12780
12876
|
// src/spend-account-pay.ts
|
|
12781
12877
|
import { Transaction as Transaction8 } from "@mysten/sui/transactions";
|
|
12782
|
-
import { fromBase64 as fromBase6411, normalizeSuiAddress as
|
|
12878
|
+
import { fromBase64 as fromBase6411, normalizeSuiAddress as normalizeSuiAddress16, toBase64 as toBase647 } from "@mysten/sui/utils";
|
|
12783
12879
|
|
|
12784
12880
|
// ../sdk/dist/pay-operation/verify-x402-offer.js
|
|
12785
|
-
import { normalizeStructTag as normalizeStructTag8, normalizeSuiAddress as
|
|
12881
|
+
import { normalizeStructTag as normalizeStructTag8, normalizeSuiAddress as normalizeSuiAddress14 } from "@mysten/sui/utils";
|
|
12786
12882
|
|
|
12787
12883
|
// ../sdk/dist/pay-operation/verify-direct-tx.js
|
|
12788
12884
|
import { Transaction as Transaction6 } from "@mysten/sui/transactions";
|
|
12789
|
-
import { bcs as
|
|
12790
|
-
import { fromBase64 as fromBase649, normalizeStructTag as normalizeStructTag9, normalizeSuiAddress as
|
|
12885
|
+
import { bcs as bcs8 } from "@mysten/sui/bcs";
|
|
12886
|
+
import { fromBase64 as fromBase649, normalizeStructTag as normalizeStructTag9, normalizeSuiAddress as normalizeSuiAddress15 } from "@mysten/sui/utils";
|
|
12791
12887
|
|
|
12792
12888
|
// ../sdk/dist/pay-operation/resolve-grant-x402.js
|
|
12793
12889
|
import { Transaction as Transaction7 } from "@mysten/sui/transactions";
|
|
@@ -12959,19 +13055,19 @@ function verifySpendAccountPayReconstructs(bytes, expected) {
|
|
|
12959
13055
|
} catch {
|
|
12960
13056
|
throw new Error("sponsored transaction is not valid Sui transaction bytes");
|
|
12961
13057
|
}
|
|
12962
|
-
if (!data.sender ||
|
|
13058
|
+
if (!data.sender || normalizeSuiAddress16(data.sender) !== normalizeSuiAddress16(expected.delegate)) {
|
|
12963
13059
|
throw new Error("sponsored transaction sender does not match delegate");
|
|
12964
13060
|
}
|
|
12965
13061
|
if (!data.commands || data.commands.length !== 1) {
|
|
12966
13062
|
throw new Error("sponsored transaction must contain exactly one command");
|
|
12967
13063
|
}
|
|
12968
13064
|
const auth = defaultAuthorityForRail("delegate", expected.packageId);
|
|
12969
|
-
const wanted = `${
|
|
13065
|
+
const wanted = `${normalizeSuiAddress16(auth.packageId)}::${auth.module}::${auth.payFunction}`;
|
|
12970
13066
|
const cmd = data.commands[0];
|
|
12971
13067
|
if (cmd.$kind !== "MoveCall" || !cmd.MoveCall) {
|
|
12972
13068
|
throw new Error("sponsored transaction is not a MoveCall");
|
|
12973
13069
|
}
|
|
12974
|
-
const got = `${
|
|
13070
|
+
const got = `${normalizeSuiAddress16(String(cmd.MoveCall.package))}::${cmd.MoveCall.module}::${cmd.MoveCall.function}`;
|
|
12975
13071
|
if (got !== wanted) {
|
|
12976
13072
|
throw new Error(`sponsored transaction does not reconstruct ${wanted}`);
|
|
12977
13073
|
}
|
|
@@ -13192,7 +13288,7 @@ async function prepareSpendAccountPayment(args) {
|
|
|
13192
13288
|
const signingRequest = {
|
|
13193
13289
|
unsignedKindBytes: kindBytes,
|
|
13194
13290
|
delegateAddress: resolved.delegateAddress,
|
|
13195
|
-
packageId:
|
|
13291
|
+
packageId: normalizeSuiAddress16(authority.packageId),
|
|
13196
13292
|
poolObjectId: resolved.poolObjectId,
|
|
13197
13293
|
grantObjectId: resolved.grantObjectId,
|
|
13198
13294
|
policyId: resolved.onChainPolicyId,
|
|
@@ -13674,8 +13770,11 @@ function failureFieldsOf(result) {
|
|
|
13674
13770
|
}
|
|
13675
13771
|
|
|
13676
13772
|
// src/pay-file.ts
|
|
13677
|
-
import { isAbsolute, dirname as dirname4, sep } from "path";
|
|
13773
|
+
import { isAbsolute, dirname as dirname4, join as join5, resolve, sep } from "path";
|
|
13774
|
+
import { homedir as homedir2 } from "os";
|
|
13678
13775
|
import {
|
|
13776
|
+
statSync,
|
|
13777
|
+
readdirSync,
|
|
13679
13778
|
openSync as openSync2,
|
|
13680
13779
|
closeSync as closeSync2,
|
|
13681
13780
|
fstatSync,
|
|
@@ -13747,10 +13846,7 @@ function resolveContainedPath(raw) {
|
|
|
13747
13846
|
);
|
|
13748
13847
|
}
|
|
13749
13848
|
if (!isAbsolute(rootRaw) || rootRaw.includes("://")) {
|
|
13750
|
-
return fail2(
|
|
13751
|
-
"FILE_ROOT_UNSET",
|
|
13752
|
-
"SUIPAY_MCP_FILE_ROOT must be an absolute filesystem path"
|
|
13753
|
-
);
|
|
13849
|
+
return fail2("FILE_ROOT_UNSET", "SUIPAY_MCP_FILE_ROOT must be an absolute filesystem path");
|
|
13754
13850
|
}
|
|
13755
13851
|
let rootReal;
|
|
13756
13852
|
let fileReal;
|
|
@@ -13769,22 +13865,59 @@ function resolveContainedPath(raw) {
|
|
|
13769
13865
|
if (code === "EACCES") {
|
|
13770
13866
|
return fail2("FILE_EACCES", "file is not readable");
|
|
13771
13867
|
}
|
|
13772
|
-
return fail2(
|
|
13773
|
-
"INVALID_FILE",
|
|
13774
|
-
`file could not be read (${code ?? "unknown error"})`
|
|
13775
|
-
);
|
|
13868
|
+
return fail2("INVALID_FILE", `file could not be read (${code ?? "unknown error"})`);
|
|
13776
13869
|
}
|
|
13777
13870
|
if (!inside(rootReal, fileReal)) {
|
|
13778
13871
|
return fail2("FILE_OUTSIDE_ROOT", "file must be under SUIPAY_MCP_FILE_ROOT");
|
|
13779
13872
|
}
|
|
13780
|
-
const
|
|
13781
|
-
|
|
13873
|
+
const home = process.env.HOME ?? process.env.USERPROFILE ?? homedir2();
|
|
13874
|
+
const privateDirs = [
|
|
13875
|
+
join5(home, ".suipay"),
|
|
13876
|
+
join5(home, ".suipay", "credentials.json"),
|
|
13877
|
+
dirname4(mcpCredentialsPath()),
|
|
13878
|
+
mcpCredentialsPath()
|
|
13879
|
+
];
|
|
13880
|
+
const profiles = join5(home, ".suipay", "profiles");
|
|
13881
|
+
privateDirs.push(profiles);
|
|
13782
13882
|
try {
|
|
13783
|
-
|
|
13883
|
+
for (const name of readdirSync(profiles)) {
|
|
13884
|
+
privateDirs.push(join5(profiles, name), join5(profiles, name, "credentials.json"));
|
|
13885
|
+
}
|
|
13784
13886
|
} catch {
|
|
13887
|
+
try {
|
|
13888
|
+
realpathSync(profiles);
|
|
13889
|
+
return fail2("FILE_FORBIDDEN", "credential storage could not be inspected");
|
|
13890
|
+
} catch {
|
|
13891
|
+
}
|
|
13785
13892
|
}
|
|
13786
|
-
|
|
13787
|
-
|
|
13893
|
+
for (const dir of privateDirs) {
|
|
13894
|
+
let realDir = resolve(dir);
|
|
13895
|
+
try {
|
|
13896
|
+
realDir = realpathSync(dir);
|
|
13897
|
+
} catch {
|
|
13898
|
+
}
|
|
13899
|
+
let privateIdentity;
|
|
13900
|
+
try {
|
|
13901
|
+
privateIdentity = statSync(realDir);
|
|
13902
|
+
} catch {
|
|
13903
|
+
}
|
|
13904
|
+
let ancestor = fileReal;
|
|
13905
|
+
while (privateIdentity?.ino) {
|
|
13906
|
+
try {
|
|
13907
|
+
const current = statSync(ancestor);
|
|
13908
|
+
if (current.dev === privateIdentity.dev && current.ino === privateIdentity.ino) {
|
|
13909
|
+
return fail2("FILE_FORBIDDEN", "file must not be under ~/.suipay");
|
|
13910
|
+
}
|
|
13911
|
+
} catch {
|
|
13912
|
+
return fail2("FILE_FORBIDDEN", "file ancestry could not be inspected");
|
|
13913
|
+
}
|
|
13914
|
+
const parent = dirname4(ancestor);
|
|
13915
|
+
if (parent === ancestor) break;
|
|
13916
|
+
ancestor = parent;
|
|
13917
|
+
}
|
|
13918
|
+
if (inside(resolve(dir), resolve(raw)) || inside(realDir, fileReal)) {
|
|
13919
|
+
return fail2("FILE_FORBIDDEN", "file must not be under ~/.suipay");
|
|
13920
|
+
}
|
|
13788
13921
|
}
|
|
13789
13922
|
return fileReal;
|
|
13790
13923
|
}
|
|
@@ -13800,6 +13933,9 @@ function readRegularFile(path) {
|
|
|
13800
13933
|
if (!st.isFile()) {
|
|
13801
13934
|
return fail2("INVALID_FILE", "file must be a regular file");
|
|
13802
13935
|
}
|
|
13936
|
+
if (st.nlink > 1) {
|
|
13937
|
+
return fail2("FILE_FORBIDDEN", "file must have only one hard link");
|
|
13938
|
+
}
|
|
13803
13939
|
if (st.size > MCP_MAX_FILE_FIELD_BYTES) {
|
|
13804
13940
|
return fail2(
|
|
13805
13941
|
"FILE_TOO_LARGE",
|
|
@@ -13826,10 +13962,7 @@ function readRegularFile(path) {
|
|
|
13826
13962
|
return fail2("INVALID_FILE", "file must be a regular file");
|
|
13827
13963
|
}
|
|
13828
13964
|
if (code === "EACCES") return fail2("FILE_EACCES", "file is not readable");
|
|
13829
|
-
return fail2(
|
|
13830
|
-
"INVALID_FILE",
|
|
13831
|
-
`file could not be read (${code ?? "unknown error"})`
|
|
13832
|
-
);
|
|
13965
|
+
return fail2("INVALID_FILE", `file could not be read (${code ?? "unknown error"})`);
|
|
13833
13966
|
} finally {
|
|
13834
13967
|
if (fd !== void 0) {
|
|
13835
13968
|
try {
|
|
@@ -13848,10 +13981,7 @@ function jsonWithLocalFile(input) {
|
|
|
13848
13981
|
if (!hasFile && !hasField) return { json: input.json };
|
|
13849
13982
|
if (hasFile !== hasField) {
|
|
13850
13983
|
return {
|
|
13851
|
-
error: fail2(
|
|
13852
|
-
"INVALID_FILE_ARGS",
|
|
13853
|
-
"file and fileField are required together"
|
|
13854
|
-
)
|
|
13984
|
+
error: fail2("INVALID_FILE_ARGS", "file and fileField are required together")
|
|
13855
13985
|
};
|
|
13856
13986
|
}
|
|
13857
13987
|
const method = parseMethod(input.method);
|
|
@@ -13871,12 +14001,9 @@ function jsonWithLocalFile(input) {
|
|
|
13871
14001
|
} else {
|
|
13872
14002
|
return { error: fail2("MALFORMED_REQUEST", "POST requires json object") };
|
|
13873
14003
|
}
|
|
13874
|
-
if (Object.
|
|
14004
|
+
if (Object.hasOwn(json, field)) {
|
|
13875
14005
|
return {
|
|
13876
|
-
error: fail2(
|
|
13877
|
-
"FILE_FIELD_EXISTS",
|
|
13878
|
-
"json already has fileField; refuse to overwrite"
|
|
13879
|
-
)
|
|
14006
|
+
error: fail2("FILE_FIELD_EXISTS", "json already has fileField; refuse to overwrite")
|
|
13880
14007
|
};
|
|
13881
14008
|
}
|
|
13882
14009
|
const contained = resolveContainedPath(path);
|
|
@@ -13889,76 +14016,6 @@ function jsonWithLocalFile(input) {
|
|
|
13889
14016
|
|
|
13890
14017
|
// ../sdk/dist/pay-flow.js
|
|
13891
14018
|
import { normalizeStructTag as normalizeStructTag11, normalizeSuiAddress as normalizeSuiAddress17 } from "@mysten/sui/utils";
|
|
13892
|
-
|
|
13893
|
-
// ../sdk/dist/sponsor/delegate-control.js
|
|
13894
|
-
import { bcs as bcs8 } from "@mysten/sui/bcs";
|
|
13895
|
-
import { verifyPersonalMessageSignature as verifyPersonalMessageSignature3 } from "@mysten/sui/verify";
|
|
13896
|
-
import { normalizeSuiAddress as normalizeSuiAddress16 } from "@mysten/sui/utils";
|
|
13897
|
-
var DELEGATE_CONTROL_DOMAIN = "suipay:delegate-control:v1";
|
|
13898
|
-
function canonicalDelegateControlRequest(method, url) {
|
|
13899
|
-
const normalized = method.trim().toUpperCase();
|
|
13900
|
-
if (normalized !== "GET" && normalized !== "POST") {
|
|
13901
|
-
throw new Error("pay-prepare method must be GET or POST");
|
|
13902
|
-
}
|
|
13903
|
-
let parsed;
|
|
13904
|
-
try {
|
|
13905
|
-
parsed = new URL(url);
|
|
13906
|
-
} catch {
|
|
13907
|
-
throw new Error("pay-prepare url must be absolute");
|
|
13908
|
-
}
|
|
13909
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
13910
|
-
throw new Error("pay-prepare url must be http or https");
|
|
13911
|
-
}
|
|
13912
|
-
parsed.search = "";
|
|
13913
|
-
parsed.hash = "";
|
|
13914
|
-
parsed.username = "";
|
|
13915
|
-
parsed.password = "";
|
|
13916
|
-
return { method: normalized, url: parsed.origin + parsed.pathname };
|
|
13917
|
-
}
|
|
13918
|
-
function isDelegateControlPurpose(value) {
|
|
13919
|
-
return value === "register" || value === "pay-prepare";
|
|
13920
|
-
}
|
|
13921
|
-
function encodeDelegateControlPayload(payload) {
|
|
13922
|
-
if (payload.domain !== DELEGATE_CONTROL_DOMAIN) {
|
|
13923
|
-
throw new Error(`domain must be ${DELEGATE_CONTROL_DOMAIN}`);
|
|
13924
|
-
}
|
|
13925
|
-
if (!isDelegateControlPurpose(payload.purpose)) {
|
|
13926
|
-
throw new Error("purpose must be register or pay-prepare");
|
|
13927
|
-
}
|
|
13928
|
-
if (!payload.nonce.trim())
|
|
13929
|
-
throw new Error("nonce is required");
|
|
13930
|
-
if (!Number.isFinite(payload.expiryMs) || payload.expiryMs <= 0) {
|
|
13931
|
-
throw new Error("expiryMs must be a positive finite number");
|
|
13932
|
-
}
|
|
13933
|
-
if (payload.purpose === "register" && !payload.owner.trim()) {
|
|
13934
|
-
throw new Error("register proof binds an owner address");
|
|
13935
|
-
}
|
|
13936
|
-
const request = payload.purpose === "pay-prepare" ? canonicalDelegateControlRequest(payload.method, payload.url) : null;
|
|
13937
|
-
const parts = [];
|
|
13938
|
-
const push = (bytes) => parts.push(bytes);
|
|
13939
|
-
const utf8 = (value) => bcs8.vector(bcs8.u8()).serialize([...new TextEncoder().encode(value)]).toBytes();
|
|
13940
|
-
push(utf8(payload.domain));
|
|
13941
|
-
push(utf8(payload.purpose));
|
|
13942
|
-
push(utf8(payload.nonce));
|
|
13943
|
-
push(bcs8.u64().serialize(BigInt(payload.expiryMs)).toBytes());
|
|
13944
|
-
push(bcs8.Address.serialize(normalizeSuiAddress16(payload.delegate)).toBytes());
|
|
13945
|
-
if (payload.purpose === "register") {
|
|
13946
|
-
push(bcs8.Address.serialize(normalizeSuiAddress16(payload.owner)).toBytes());
|
|
13947
|
-
} else if (request) {
|
|
13948
|
-
push(utf8(request.method));
|
|
13949
|
-
push(utf8(request.url));
|
|
13950
|
-
}
|
|
13951
|
-
const total = parts.reduce((sum, part) => sum + part.length, 0);
|
|
13952
|
-
const out = new Uint8Array(total);
|
|
13953
|
-
let offset = 0;
|
|
13954
|
-
for (const part of parts) {
|
|
13955
|
-
out.set(part, offset);
|
|
13956
|
-
offset += part.length;
|
|
13957
|
-
}
|
|
13958
|
-
return out;
|
|
13959
|
-
}
|
|
13960
|
-
|
|
13961
|
-
// ../sdk/dist/pay-flow.js
|
|
13962
14019
|
function refuse(code, detail) {
|
|
13963
14020
|
return SuiPayError.of(code, "not_charged", { detail });
|
|
13964
14021
|
}
|
|
@@ -14856,6 +14913,7 @@ async function suipayLogin(args, cfg, deps = {}) {
|
|
|
14856
14913
|
consoleUrl: endpoints.consoleUrl,
|
|
14857
14914
|
gatewayUrl: endpoints.gatewayUrl,
|
|
14858
14915
|
identity,
|
|
14916
|
+
signPersonalMessage: local?.signPersonalMessage,
|
|
14859
14917
|
label,
|
|
14860
14918
|
timeoutMs: LOGIN_BG_TIMEOUT_MS,
|
|
14861
14919
|
openBrowser: true,
|
|
@@ -14909,7 +14967,7 @@ function safeRetryDetail(rawDetail) {
|
|
|
14909
14967
|
if (!rawDetail) {
|
|
14910
14968
|
return "Grant status could not be verified on chain. Retry shortly.";
|
|
14911
14969
|
}
|
|
14912
|
-
|
|
14970
|
+
const stripped = rawDetail.replace(/https?:\/\/[^\s"'<>]+/gi, "[redacted]");
|
|
14913
14971
|
if (stripped.includes("ECONNREFUSED") || stripped.includes("ETIMEDOUT") || stripped.includes("fetch failed")) {
|
|
14914
14972
|
return "Network connection to gateway or chain node failed. Retry shortly.";
|
|
14915
14973
|
}
|
|
@@ -15687,8 +15745,8 @@ async function withDeadline(work, ms) {
|
|
|
15687
15745
|
try {
|
|
15688
15746
|
return await Promise.race([
|
|
15689
15747
|
work,
|
|
15690
|
-
new Promise((
|
|
15691
|
-
timer = setTimeout(() =>
|
|
15748
|
+
new Promise((resolve2) => {
|
|
15749
|
+
timer = setTimeout(() => resolve2(null), ms);
|
|
15692
15750
|
timer.unref?.();
|
|
15693
15751
|
})
|
|
15694
15752
|
]);
|
package/dist/http.js
CHANGED
package/dist/index.d.ts
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-7L7CQYBL.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-DZUVYB76.js";
|
|
30
30
|
export {
|
|
31
31
|
MCP_TARGET_PRESETS,
|
|
32
32
|
PACKAGE_NAME,
|
package/package.json
CHANGED