@mysten-incubation/suipay-mcp 0.3.0-dev.21 → 0.3.0-dev.23
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-JHBXXJ6X.js → chunk-H7ET3HU2.js} +252 -150
- package/dist/{chunk-4HWODHQ4.js → chunk-Y4VKD3RV.js} +1 -1
- 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.23` 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.23
|
|
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.23
|
|
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.23 --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) {
|
|
@@ -1484,13 +1484,18 @@ var GUARDED_DELEGATE_ARG_LAYOUT = {
|
|
|
1484
1484
|
recipient: null,
|
|
1485
1485
|
amount: 6,
|
|
1486
1486
|
paymentIdHash: 7,
|
|
1487
|
-
expiresAtMs: 9
|
|
1487
|
+
expiresAtMs: 9,
|
|
1488
|
+
// After clock (10): chain id, refund config, decide window, refund window.
|
|
1489
|
+
decideWindowMs: 13,
|
|
1490
|
+
refundWindowMs: 14
|
|
1488
1491
|
},
|
|
1489
1492
|
settle_any_recipient_to_refund_vault: {
|
|
1490
1493
|
recipient: 4,
|
|
1491
1494
|
amount: 5,
|
|
1492
1495
|
paymentIdHash: 6,
|
|
1493
|
-
expiresAtMs: 9
|
|
1496
|
+
expiresAtMs: 9,
|
|
1497
|
+
decideWindowMs: 13,
|
|
1498
|
+
refundWindowMs: 14
|
|
1494
1499
|
}
|
|
1495
1500
|
};
|
|
1496
1501
|
function pureBytesOf(data, arg) {
|
|
@@ -1570,11 +1575,48 @@ function recoverGuardedDelegateCalls(finalized) {
|
|
|
1570
1575
|
paymentIdHash: readPureVectorU8Hex(data, args[layout.paymentIdHash]),
|
|
1571
1576
|
amount: readPureU64(data, args[layout.amount]),
|
|
1572
1577
|
recipient: layout.recipient === null ? null : readPureAddress(data, args[layout.recipient]),
|
|
1573
|
-
expiresAtMs: readPureU64(data, args[layout.expiresAtMs])
|
|
1578
|
+
expiresAtMs: readPureU64(data, args[layout.expiresAtMs]),
|
|
1579
|
+
..."decideWindowMs" in layout ? {
|
|
1580
|
+
decideWindowMs: readPureU64(data, args[layout.decideWindowMs]),
|
|
1581
|
+
refundWindowMs: readPureU64(data, args[layout.refundWindowMs])
|
|
1582
|
+
} : {}
|
|
1574
1583
|
});
|
|
1575
1584
|
}
|
|
1576
1585
|
return calls;
|
|
1577
1586
|
}
|
|
1587
|
+
var VAULT_SETTLEMENT_TS_TIMEOUT_MS = 1e4;
|
|
1588
|
+
function withTimeout(work, ms, label) {
|
|
1589
|
+
return new Promise((resolve2, reject2) => {
|
|
1590
|
+
const timer = setTimeout(() => reject2(new Error(`${label} timed out after ${ms}ms`)), ms);
|
|
1591
|
+
Promise.resolve(work).then((value) => {
|
|
1592
|
+
clearTimeout(timer);
|
|
1593
|
+
resolve2(value);
|
|
1594
|
+
}, (err) => {
|
|
1595
|
+
clearTimeout(timer);
|
|
1596
|
+
reject2(err);
|
|
1597
|
+
});
|
|
1598
|
+
});
|
|
1599
|
+
}
|
|
1600
|
+
async function readVaultSettlementMs(client, digest) {
|
|
1601
|
+
const ledger = client.ledgerService;
|
|
1602
|
+
if (!ledger?.getTransaction)
|
|
1603
|
+
return void 0;
|
|
1604
|
+
try {
|
|
1605
|
+
const call = await withTimeout(ledger.getTransaction({
|
|
1606
|
+
digest,
|
|
1607
|
+
readMask: { paths: ["timestamp"] }
|
|
1608
|
+
}), VAULT_SETTLEMENT_TS_TIMEOUT_MS, "vault settlement timestamp read");
|
|
1609
|
+
const ts = call.response.transaction?.timestamp;
|
|
1610
|
+
if (!ts || ts.seconds === void 0)
|
|
1611
|
+
return void 0;
|
|
1612
|
+
const seconds = Number(ts.seconds);
|
|
1613
|
+
if (!Number.isFinite(seconds))
|
|
1614
|
+
return void 0;
|
|
1615
|
+
return seconds * 1e3 + Math.floor((ts.nanos ?? 0) / 1e6);
|
|
1616
|
+
} catch {
|
|
1617
|
+
return void 0;
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1578
1620
|
function createSpendAccountSettledTxReader(options) {
|
|
1579
1621
|
const network = toGrpcNetwork(options.network);
|
|
1580
1622
|
const client = options.client ?? createFailoverGrpcClient({
|
|
@@ -1629,6 +1671,7 @@ function createSpendAccountSettledTxReader(options) {
|
|
|
1629
1671
|
kind: e.eventType.split("::").pop() ?? e.eventType
|
|
1630
1672
|
}));
|
|
1631
1673
|
const guardedDelegateCalls = recoverGuardedDelegateCalls(finalized);
|
|
1674
|
+
const timestampMs = events.some((event) => event.kind === "VaultOpened") ? await readVaultSettlementMs(client, digest) : void 0;
|
|
1632
1675
|
return {
|
|
1633
1676
|
status: "success",
|
|
1634
1677
|
txDigest: digest,
|
|
@@ -1636,7 +1679,8 @@ function createSpendAccountSettledTxReader(options) {
|
|
|
1636
1679
|
moveCalls,
|
|
1637
1680
|
objectIds,
|
|
1638
1681
|
events,
|
|
1639
|
-
guardedDelegateCalls
|
|
1682
|
+
guardedDelegateCalls,
|
|
1683
|
+
...timestampMs !== void 0 ? { timestampMs } : {}
|
|
1640
1684
|
};
|
|
1641
1685
|
}
|
|
1642
1686
|
};
|
|
@@ -8105,8 +8149,8 @@ var X402_EXPIRATION_EPOCHS = 32n;
|
|
|
8105
8149
|
var X402_PRESENT_ATTEMPTS = 10;
|
|
8106
8150
|
var X402_PRESENT_DELAY_MS = 1e3;
|
|
8107
8151
|
function delay(ms) {
|
|
8108
|
-
return new Promise((
|
|
8109
|
-
setTimeout(
|
|
8152
|
+
return new Promise((resolve2) => {
|
|
8153
|
+
setTimeout(resolve2, ms);
|
|
8110
8154
|
});
|
|
8111
8155
|
}
|
|
8112
8156
|
var SUI_CLOCK2 = "0x6";
|
|
@@ -10194,19 +10238,19 @@ async function verifyPreparedSettlementKind(input) {
|
|
|
10194
10238
|
}
|
|
10195
10239
|
const args = cmd.MoveCall.arguments ?? [];
|
|
10196
10240
|
const inputs = data.inputs ?? [];
|
|
10197
|
-
const
|
|
10241
|
+
const resolve2 = (argIdx) => {
|
|
10198
10242
|
const idx = preparedInputIndex(args[argIdx]);
|
|
10199
10243
|
if (idx === null || idx < 0 || idx >= inputs.length)
|
|
10200
10244
|
return void 0;
|
|
10201
10245
|
return inputs[idx];
|
|
10202
10246
|
};
|
|
10203
|
-
const poolObjectId = preparedSharedObjectId(
|
|
10247
|
+
const poolObjectId = preparedSharedObjectId(resolve2(2));
|
|
10204
10248
|
if (input.expected.poolObjectId) {
|
|
10205
10249
|
if (!poolObjectId || !sameAddress2(poolObjectId, input.expected.poolObjectId)) {
|
|
10206
10250
|
throw new Error(`prepared pool ${poolObjectId ?? "(missing)"} does not match expected pool ${input.expected.poolObjectId}`);
|
|
10207
10251
|
}
|
|
10208
10252
|
}
|
|
10209
|
-
const grantObjectId = preparedSharedObjectId(
|
|
10253
|
+
const grantObjectId = preparedSharedObjectId(resolve2(3));
|
|
10210
10254
|
if (!grantObjectId) {
|
|
10211
10255
|
throw new Error("prepared transaction does not name a grant object");
|
|
10212
10256
|
}
|
|
@@ -10214,11 +10258,11 @@ async function verifyPreparedSettlementKind(input) {
|
|
|
10214
10258
|
throw new Error(`prepared grant ${grantObjectId} does not match expected grant ${input.expected.grantObjectId}`);
|
|
10215
10259
|
}
|
|
10216
10260
|
if (accessMode === "open") {
|
|
10217
|
-
const recipient = preparedPureAddress(
|
|
10261
|
+
const recipient = preparedPureAddress(resolve2(4));
|
|
10218
10262
|
if (!recipient || !sameAddress2(recipient, input.expected.recipient)) {
|
|
10219
10263
|
throw new Error(`prepared recipient ${recipient ?? "(missing)"} does not match the requested recipient`);
|
|
10220
10264
|
}
|
|
10221
|
-
const amount = preparedPureU64(
|
|
10265
|
+
const amount = preparedPureU64(resolve2(5));
|
|
10222
10266
|
let expectedAmount;
|
|
10223
10267
|
try {
|
|
10224
10268
|
expectedAmount = BigInt(input.expected.amount);
|
|
@@ -10230,20 +10274,20 @@ async function verifyPreparedSettlementKind(input) {
|
|
|
10230
10274
|
}
|
|
10231
10275
|
} else {
|
|
10232
10276
|
if (input.expected.onChainPolicyId !== void 0) {
|
|
10233
|
-
const policyId = preparedPureU64(
|
|
10277
|
+
const policyId = preparedPureU64(resolve2(4));
|
|
10234
10278
|
const expectedPolicyId = BigInt(input.expected.onChainPolicyId);
|
|
10235
10279
|
if (policyId !== expectedPolicyId) {
|
|
10236
10280
|
throw new Error(`prepared policy_id ${policyId ?? "(missing)"} does not match expected onChainPolicyId`);
|
|
10237
10281
|
}
|
|
10238
10282
|
}
|
|
10239
10283
|
if (input.expected.targetHash) {
|
|
10240
|
-
const targetHash = preparedPureVectorU8(
|
|
10284
|
+
const targetHash = preparedPureVectorU8(resolve2(5));
|
|
10241
10285
|
const expectedBytes = toTargetHashBytes(input.expected.targetHash);
|
|
10242
10286
|
if (!targetHash || !sameBytes(targetHash, expectedBytes)) {
|
|
10243
10287
|
throw new Error("prepared target_hash does not match expected targetHash");
|
|
10244
10288
|
}
|
|
10245
10289
|
}
|
|
10246
|
-
const amount = preparedPureU64(
|
|
10290
|
+
const amount = preparedPureU64(resolve2(6));
|
|
10247
10291
|
let expectedAmount;
|
|
10248
10292
|
try {
|
|
10249
10293
|
expectedAmount = BigInt(input.expected.amount);
|
|
@@ -10254,14 +10298,14 @@ async function verifyPreparedSettlementKind(input) {
|
|
|
10254
10298
|
throw new Error(`prepared amount ${amount ?? "(missing)"} does not match the requested amount`);
|
|
10255
10299
|
}
|
|
10256
10300
|
if (input.expected.paymentIdHash) {
|
|
10257
|
-
const paymentIdHash2 = preparedPureVectorU8(
|
|
10301
|
+
const paymentIdHash2 = preparedPureVectorU8(resolve2(7));
|
|
10258
10302
|
const expectedBytes = toHashBytes(input.expected.paymentIdHash);
|
|
10259
10303
|
if (!paymentIdHash2 || !sameBytes(paymentIdHash2, expectedBytes)) {
|
|
10260
10304
|
throw new Error("prepared payment_id_hash does not match expected paymentIdHash");
|
|
10261
10305
|
}
|
|
10262
10306
|
}
|
|
10263
10307
|
if (input.expected.termsHash) {
|
|
10264
|
-
const termsHash2 = preparedPureVectorU8(
|
|
10308
|
+
const termsHash2 = preparedPureVectorU8(resolve2(8));
|
|
10265
10309
|
const expectedBytes = toHashBytes(input.expected.termsHash);
|
|
10266
10310
|
if (!termsHash2 || !sameBytes(termsHash2, expectedBytes)) {
|
|
10267
10311
|
throw new Error("prepared terms_hash does not match expected termsHash");
|
|
@@ -10272,23 +10316,23 @@ async function verifyPreparedSettlementKind(input) {
|
|
|
10272
10316
|
if (!vault.refundConfigId || vault.chainId === void 0 || vault.decideWindowMs === void 0 || vault.refundWindowMs === void 0 || !vault.paymentSalt) {
|
|
10273
10317
|
throw new Error("refundable prepared settlement is missing vault inputs");
|
|
10274
10318
|
}
|
|
10275
|
-
const chainId = preparedPureU64(
|
|
10319
|
+
const chainId = preparedPureU64(resolve2(11));
|
|
10276
10320
|
if (chainId !== BigInt(vault.chainId)) {
|
|
10277
10321
|
throw new Error("prepared chainId does not match the offer");
|
|
10278
10322
|
}
|
|
10279
|
-
const configId = preparedSharedObjectId(
|
|
10323
|
+
const configId = preparedSharedObjectId(resolve2(12));
|
|
10280
10324
|
if (!configId || !sameAddress2(configId, vault.refundConfigId)) {
|
|
10281
10325
|
throw new Error("prepared refund config does not match the offer");
|
|
10282
10326
|
}
|
|
10283
|
-
const decide = preparedPureU64(
|
|
10327
|
+
const decide = preparedPureU64(resolve2(13));
|
|
10284
10328
|
if (decide !== BigInt(vault.decideWindowMs)) {
|
|
10285
10329
|
throw new Error("prepared decideWindowMs does not match the offer");
|
|
10286
10330
|
}
|
|
10287
|
-
const refundWindow = preparedPureU64(
|
|
10331
|
+
const refundWindow = preparedPureU64(resolve2(14));
|
|
10288
10332
|
if (refundWindow !== BigInt(vault.refundWindowMs)) {
|
|
10289
10333
|
throw new Error("prepared refundWindowMs does not match the offer");
|
|
10290
10334
|
}
|
|
10291
|
-
const salt = preparedPureVectorU8(
|
|
10335
|
+
const salt = preparedPureVectorU8(resolve2(15));
|
|
10292
10336
|
const expectedSalt = new TextEncoder().encode(vault.paymentSalt);
|
|
10293
10337
|
if (!salt || !sameBytes(salt, expectedSalt)) {
|
|
10294
10338
|
throw new Error("prepared paymentSalt does not match the offer");
|
|
@@ -12429,8 +12473,8 @@ async function createPayer(options) {
|
|
|
12429
12473
|
// directory id was configured, so such an offer fails closed (BUILD_FAILED)
|
|
12430
12474
|
// rather than building an unguarded settle. Unguarded offers never call it.
|
|
12431
12475
|
...(() => {
|
|
12432
|
-
const
|
|
12433
|
-
return
|
|
12476
|
+
const resolve2 = createExclusionRegistryResolver(chain.client, exclusionDirectoryObjectId);
|
|
12477
|
+
return resolve2 ? { resolveExclusionRegistry: resolve2 } : {};
|
|
12434
12478
|
})(),
|
|
12435
12479
|
// x402 bounds the transaction's expiration by the current epoch, read from
|
|
12436
12480
|
// the same client as every other chain read here.
|
|
@@ -12494,6 +12538,77 @@ async function createPayer(options) {
|
|
|
12494
12538
|
import { createServer } from "http";
|
|
12495
12539
|
import { randomBytes as randomBytes2, timingSafeEqual } from "crypto";
|
|
12496
12540
|
import open from "open";
|
|
12541
|
+
|
|
12542
|
+
// ../sdk/dist/sponsor/delegate-control.js
|
|
12543
|
+
import { bcs as bcs7 } from "@mysten/sui/bcs";
|
|
12544
|
+
import { verifyPersonalMessageSignature as verifyPersonalMessageSignature3 } from "@mysten/sui/verify";
|
|
12545
|
+
import { normalizeSuiAddress as normalizeSuiAddress13 } from "@mysten/sui/utils";
|
|
12546
|
+
var DELEGATE_CONTROL_DOMAIN = "suipay:delegate-control:v1";
|
|
12547
|
+
var DELEGATE_CONTROL_TTL_MS = 6e4;
|
|
12548
|
+
function canonicalDelegateControlRequest(method, url) {
|
|
12549
|
+
const normalized = method.trim().toUpperCase();
|
|
12550
|
+
if (normalized !== "GET" && normalized !== "POST") {
|
|
12551
|
+
throw new Error("pay-prepare method must be GET or POST");
|
|
12552
|
+
}
|
|
12553
|
+
let parsed;
|
|
12554
|
+
try {
|
|
12555
|
+
parsed = new URL(url);
|
|
12556
|
+
} catch {
|
|
12557
|
+
throw new Error("pay-prepare url must be absolute");
|
|
12558
|
+
}
|
|
12559
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
12560
|
+
throw new Error("pay-prepare url must be http or https");
|
|
12561
|
+
}
|
|
12562
|
+
parsed.search = "";
|
|
12563
|
+
parsed.hash = "";
|
|
12564
|
+
parsed.username = "";
|
|
12565
|
+
parsed.password = "";
|
|
12566
|
+
return { method: normalized, url: parsed.origin + parsed.pathname };
|
|
12567
|
+
}
|
|
12568
|
+
function isDelegateControlPurpose(value) {
|
|
12569
|
+
return value === "register" || value === "pay-prepare";
|
|
12570
|
+
}
|
|
12571
|
+
function encodeDelegateControlPayload(payload) {
|
|
12572
|
+
if (payload.domain !== DELEGATE_CONTROL_DOMAIN) {
|
|
12573
|
+
throw new Error(`domain must be ${DELEGATE_CONTROL_DOMAIN}`);
|
|
12574
|
+
}
|
|
12575
|
+
if (!isDelegateControlPurpose(payload.purpose)) {
|
|
12576
|
+
throw new Error("purpose must be register or pay-prepare");
|
|
12577
|
+
}
|
|
12578
|
+
if (!payload.nonce.trim())
|
|
12579
|
+
throw new Error("nonce is required");
|
|
12580
|
+
if (!Number.isFinite(payload.expiryMs) || payload.expiryMs <= 0) {
|
|
12581
|
+
throw new Error("expiryMs must be a positive finite number");
|
|
12582
|
+
}
|
|
12583
|
+
if (payload.purpose === "register" && !payload.owner.trim()) {
|
|
12584
|
+
throw new Error("register proof binds an owner address");
|
|
12585
|
+
}
|
|
12586
|
+
const request = payload.purpose === "pay-prepare" ? canonicalDelegateControlRequest(payload.method, payload.url) : null;
|
|
12587
|
+
const parts = [];
|
|
12588
|
+
const push = (bytes) => parts.push(bytes);
|
|
12589
|
+
const utf8 = (value) => bcs7.vector(bcs7.u8()).serialize([...new TextEncoder().encode(value)]).toBytes();
|
|
12590
|
+
push(utf8(payload.domain));
|
|
12591
|
+
push(utf8(payload.purpose));
|
|
12592
|
+
push(utf8(payload.nonce));
|
|
12593
|
+
push(bcs7.u64().serialize(BigInt(payload.expiryMs)).toBytes());
|
|
12594
|
+
push(bcs7.Address.serialize(normalizeSuiAddress13(payload.delegate)).toBytes());
|
|
12595
|
+
if (payload.purpose === "register") {
|
|
12596
|
+
push(bcs7.Address.serialize(normalizeSuiAddress13(payload.owner)).toBytes());
|
|
12597
|
+
} else if (request) {
|
|
12598
|
+
push(utf8(request.method));
|
|
12599
|
+
push(utf8(request.url));
|
|
12600
|
+
}
|
|
12601
|
+
const total = parts.reduce((sum, part) => sum + part.length, 0);
|
|
12602
|
+
const out = new Uint8Array(total);
|
|
12603
|
+
let offset = 0;
|
|
12604
|
+
for (const part of parts) {
|
|
12605
|
+
out.set(part, offset);
|
|
12606
|
+
offset += part.length;
|
|
12607
|
+
}
|
|
12608
|
+
return out;
|
|
12609
|
+
}
|
|
12610
|
+
|
|
12611
|
+
// src/stdio-login.ts
|
|
12497
12612
|
var HEX642 = /^[0-9a-f]{64}$/;
|
|
12498
12613
|
var PUBHEX = /^[0-9a-fA-F]{64}$/;
|
|
12499
12614
|
function isPreflight(obj) {
|
|
@@ -12542,7 +12657,7 @@ function normalizeUrl(url) {
|
|
|
12542
12657
|
return url.replace(/\/+$/, "");
|
|
12543
12658
|
}
|
|
12544
12659
|
function readBody2(req, maxBytes = 16 * 1024) {
|
|
12545
|
-
return new Promise((
|
|
12660
|
+
return new Promise((resolve2, reject2) => {
|
|
12546
12661
|
const chunks = [];
|
|
12547
12662
|
let len = 0;
|
|
12548
12663
|
req.on("data", (c) => {
|
|
@@ -12554,7 +12669,7 @@ function readBody2(req, maxBytes = 16 * 1024) {
|
|
|
12554
12669
|
}
|
|
12555
12670
|
chunks.push(c);
|
|
12556
12671
|
});
|
|
12557
|
-
req.on("end", () =>
|
|
12672
|
+
req.on("end", () => resolve2(Buffer.concat(chunks).toString("utf8")));
|
|
12558
12673
|
req.on("error", reject2);
|
|
12559
12674
|
});
|
|
12560
12675
|
}
|
|
@@ -12580,7 +12695,7 @@ async function startStdioLogin(opts) {
|
|
|
12580
12695
|
server.requestTimeout = 1e4;
|
|
12581
12696
|
server.headersTimeout = 1e4;
|
|
12582
12697
|
server.keepAliveTimeout = 5e3;
|
|
12583
|
-
await new Promise((
|
|
12698
|
+
await new Promise((resolve2) => server.listen(0, "127.0.0.1", resolve2));
|
|
12584
12699
|
const port = server.address().port;
|
|
12585
12700
|
const allowedHosts = /* @__PURE__ */ new Set([`127.0.0.1:${port}`, `localhost:${port}`]);
|
|
12586
12701
|
const base = opts.consoleUrl.replace(/\/+$/, "");
|
|
@@ -12590,14 +12705,15 @@ async function startStdioLogin(opts) {
|
|
|
12590
12705
|
} catch {
|
|
12591
12706
|
}
|
|
12592
12707
|
let preflightVerified = false;
|
|
12708
|
+
let proofOwner = null;
|
|
12593
12709
|
let completed = false;
|
|
12594
12710
|
let error = null;
|
|
12595
|
-
const done = new Promise((
|
|
12711
|
+
const done = new Promise((resolve2) => {
|
|
12596
12712
|
const timer = setTimeout(() => {
|
|
12597
12713
|
if (!completed) {
|
|
12598
12714
|
error = new Error(`login timed out after ${timeoutMs}ms`);
|
|
12599
12715
|
server.close();
|
|
12600
|
-
|
|
12716
|
+
resolve2();
|
|
12601
12717
|
}
|
|
12602
12718
|
}, timeoutMs);
|
|
12603
12719
|
timer.unref?.();
|
|
@@ -12625,7 +12741,7 @@ async function startStdioLogin(opts) {
|
|
|
12625
12741
|
res.writeHead(code, { "content-type": type, ...SECURITY_HEADERS, ...extra });
|
|
12626
12742
|
res.end(body);
|
|
12627
12743
|
};
|
|
12628
|
-
const okPath = url.pathname === "/preflight" || url.pathname === "/callback";
|
|
12744
|
+
const okPath = url.pathname === "/preflight" || url.pathname === "/callback" || url.pathname === "/control-proof";
|
|
12629
12745
|
if (req.method === "OPTIONS") {
|
|
12630
12746
|
const extra = { ...cors };
|
|
12631
12747
|
if (okHost && okOrigin && okPath && req.headers["access-control-request-private-network"] === "true") {
|
|
@@ -12664,13 +12780,8 @@ async function startStdioLogin(opts) {
|
|
|
12664
12780
|
res.end(JSON.stringify({ ok: false, error: "invalid preflight payload" }));
|
|
12665
12781
|
return;
|
|
12666
12782
|
}
|
|
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;
|
|
12783
|
+
const derived = deriveSuiAddress(Uint8Array.from(Buffer.from(parsed.publicKey, "hex")));
|
|
12784
|
+
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
12785
|
if (!valid) {
|
|
12675
12786
|
res.writeHead(403, {
|
|
12676
12787
|
"content-type": "application/json",
|
|
@@ -12702,8 +12813,37 @@ async function startStdioLogin(opts) {
|
|
|
12702
12813
|
...cors,
|
|
12703
12814
|
...SECURITY_HEADERS
|
|
12704
12815
|
});
|
|
12705
|
-
res.end(
|
|
12706
|
-
|
|
12816
|
+
res.end(failHtml("Local MCP bridge verification is required before the callback."));
|
|
12817
|
+
return;
|
|
12818
|
+
}
|
|
12819
|
+
if (url.pathname === "/control-proof") {
|
|
12820
|
+
const body = parsed;
|
|
12821
|
+
const challenge = body?.challenge;
|
|
12822
|
+
const expiryMs = challenge?.expiryMs;
|
|
12823
|
+
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) {
|
|
12824
|
+
send(403, "Invalid delegate control challenge", "text/plain", cors);
|
|
12825
|
+
return;
|
|
12826
|
+
}
|
|
12827
|
+
if (!opts.signPersonalMessage) {
|
|
12828
|
+
send(503, "Delegate signing is unavailable", "text/plain", cors);
|
|
12829
|
+
return;
|
|
12830
|
+
}
|
|
12831
|
+
proofOwner = challenge.owner.toLowerCase();
|
|
12832
|
+
const signature = await opts.signPersonalMessage(
|
|
12833
|
+
encodeDelegateControlPayload({
|
|
12834
|
+
domain: DELEGATE_CONTROL_DOMAIN,
|
|
12835
|
+
purpose: "register",
|
|
12836
|
+
nonce: challenge.nonce,
|
|
12837
|
+
expiryMs,
|
|
12838
|
+
delegate: opts.identity.delegateAddress,
|
|
12839
|
+
owner: challenge.owner
|
|
12840
|
+
})
|
|
12841
|
+
);
|
|
12842
|
+
send(
|
|
12843
|
+
200,
|
|
12844
|
+
JSON.stringify({ nonce: challenge.nonce, signature }),
|
|
12845
|
+
"application/json",
|
|
12846
|
+
cors
|
|
12707
12847
|
);
|
|
12708
12848
|
return;
|
|
12709
12849
|
}
|
|
@@ -12744,7 +12884,7 @@ async function startStdioLogin(opts) {
|
|
|
12744
12884
|
});
|
|
12745
12885
|
res.end(SUCCESS_HTML);
|
|
12746
12886
|
setTimeout(() => server.close(), 100);
|
|
12747
|
-
|
|
12887
|
+
resolve2();
|
|
12748
12888
|
} catch (err) {
|
|
12749
12889
|
error = err instanceof Error ? err : new Error(String(err));
|
|
12750
12890
|
res.writeHead(500, {
|
|
@@ -12754,7 +12894,7 @@ async function startStdioLogin(opts) {
|
|
|
12754
12894
|
});
|
|
12755
12895
|
res.end(failHtml("Internal error parsing callback."));
|
|
12756
12896
|
setTimeout(() => server.close(), 100);
|
|
12757
|
-
|
|
12897
|
+
resolve2();
|
|
12758
12898
|
}
|
|
12759
12899
|
});
|
|
12760
12900
|
});
|
|
@@ -12779,15 +12919,15 @@ async function startStdioLogin(opts) {
|
|
|
12779
12919
|
|
|
12780
12920
|
// src/spend-account-pay.ts
|
|
12781
12921
|
import { Transaction as Transaction8 } from "@mysten/sui/transactions";
|
|
12782
|
-
import { fromBase64 as fromBase6411, normalizeSuiAddress as
|
|
12922
|
+
import { fromBase64 as fromBase6411, normalizeSuiAddress as normalizeSuiAddress16, toBase64 as toBase647 } from "@mysten/sui/utils";
|
|
12783
12923
|
|
|
12784
12924
|
// ../sdk/dist/pay-operation/verify-x402-offer.js
|
|
12785
|
-
import { normalizeStructTag as normalizeStructTag8, normalizeSuiAddress as
|
|
12925
|
+
import { normalizeStructTag as normalizeStructTag8, normalizeSuiAddress as normalizeSuiAddress14 } from "@mysten/sui/utils";
|
|
12786
12926
|
|
|
12787
12927
|
// ../sdk/dist/pay-operation/verify-direct-tx.js
|
|
12788
12928
|
import { Transaction as Transaction6 } from "@mysten/sui/transactions";
|
|
12789
|
-
import { bcs as
|
|
12790
|
-
import { fromBase64 as fromBase649, normalizeStructTag as normalizeStructTag9, normalizeSuiAddress as
|
|
12929
|
+
import { bcs as bcs8 } from "@mysten/sui/bcs";
|
|
12930
|
+
import { fromBase64 as fromBase649, normalizeStructTag as normalizeStructTag9, normalizeSuiAddress as normalizeSuiAddress15 } from "@mysten/sui/utils";
|
|
12791
12931
|
|
|
12792
12932
|
// ../sdk/dist/pay-operation/resolve-grant-x402.js
|
|
12793
12933
|
import { Transaction as Transaction7 } from "@mysten/sui/transactions";
|
|
@@ -12959,19 +13099,19 @@ function verifySpendAccountPayReconstructs(bytes, expected) {
|
|
|
12959
13099
|
} catch {
|
|
12960
13100
|
throw new Error("sponsored transaction is not valid Sui transaction bytes");
|
|
12961
13101
|
}
|
|
12962
|
-
if (!data.sender ||
|
|
13102
|
+
if (!data.sender || normalizeSuiAddress16(data.sender) !== normalizeSuiAddress16(expected.delegate)) {
|
|
12963
13103
|
throw new Error("sponsored transaction sender does not match delegate");
|
|
12964
13104
|
}
|
|
12965
13105
|
if (!data.commands || data.commands.length !== 1) {
|
|
12966
13106
|
throw new Error("sponsored transaction must contain exactly one command");
|
|
12967
13107
|
}
|
|
12968
13108
|
const auth = defaultAuthorityForRail("delegate", expected.packageId);
|
|
12969
|
-
const wanted = `${
|
|
13109
|
+
const wanted = `${normalizeSuiAddress16(auth.packageId)}::${auth.module}::${auth.payFunction}`;
|
|
12970
13110
|
const cmd = data.commands[0];
|
|
12971
13111
|
if (cmd.$kind !== "MoveCall" || !cmd.MoveCall) {
|
|
12972
13112
|
throw new Error("sponsored transaction is not a MoveCall");
|
|
12973
13113
|
}
|
|
12974
|
-
const got = `${
|
|
13114
|
+
const got = `${normalizeSuiAddress16(String(cmd.MoveCall.package))}::${cmd.MoveCall.module}::${cmd.MoveCall.function}`;
|
|
12975
13115
|
if (got !== wanted) {
|
|
12976
13116
|
throw new Error(`sponsored transaction does not reconstruct ${wanted}`);
|
|
12977
13117
|
}
|
|
@@ -13192,7 +13332,7 @@ async function prepareSpendAccountPayment(args) {
|
|
|
13192
13332
|
const signingRequest = {
|
|
13193
13333
|
unsignedKindBytes: kindBytes,
|
|
13194
13334
|
delegateAddress: resolved.delegateAddress,
|
|
13195
|
-
packageId:
|
|
13335
|
+
packageId: normalizeSuiAddress16(authority.packageId),
|
|
13196
13336
|
poolObjectId: resolved.poolObjectId,
|
|
13197
13337
|
grantObjectId: resolved.grantObjectId,
|
|
13198
13338
|
policyId: resolved.onChainPolicyId,
|
|
@@ -13674,8 +13814,11 @@ function failureFieldsOf(result) {
|
|
|
13674
13814
|
}
|
|
13675
13815
|
|
|
13676
13816
|
// src/pay-file.ts
|
|
13677
|
-
import { isAbsolute, dirname as dirname4, sep } from "path";
|
|
13817
|
+
import { isAbsolute, dirname as dirname4, join as join5, resolve, sep } from "path";
|
|
13818
|
+
import { homedir as homedir2 } from "os";
|
|
13678
13819
|
import {
|
|
13820
|
+
statSync,
|
|
13821
|
+
readdirSync,
|
|
13679
13822
|
openSync as openSync2,
|
|
13680
13823
|
closeSync as closeSync2,
|
|
13681
13824
|
fstatSync,
|
|
@@ -13747,10 +13890,7 @@ function resolveContainedPath(raw) {
|
|
|
13747
13890
|
);
|
|
13748
13891
|
}
|
|
13749
13892
|
if (!isAbsolute(rootRaw) || rootRaw.includes("://")) {
|
|
13750
|
-
return fail2(
|
|
13751
|
-
"FILE_ROOT_UNSET",
|
|
13752
|
-
"SUIPAY_MCP_FILE_ROOT must be an absolute filesystem path"
|
|
13753
|
-
);
|
|
13893
|
+
return fail2("FILE_ROOT_UNSET", "SUIPAY_MCP_FILE_ROOT must be an absolute filesystem path");
|
|
13754
13894
|
}
|
|
13755
13895
|
let rootReal;
|
|
13756
13896
|
let fileReal;
|
|
@@ -13769,22 +13909,59 @@ function resolveContainedPath(raw) {
|
|
|
13769
13909
|
if (code === "EACCES") {
|
|
13770
13910
|
return fail2("FILE_EACCES", "file is not readable");
|
|
13771
13911
|
}
|
|
13772
|
-
return fail2(
|
|
13773
|
-
"INVALID_FILE",
|
|
13774
|
-
`file could not be read (${code ?? "unknown error"})`
|
|
13775
|
-
);
|
|
13912
|
+
return fail2("INVALID_FILE", `file could not be read (${code ?? "unknown error"})`);
|
|
13776
13913
|
}
|
|
13777
13914
|
if (!inside(rootReal, fileReal)) {
|
|
13778
13915
|
return fail2("FILE_OUTSIDE_ROOT", "file must be under SUIPAY_MCP_FILE_ROOT");
|
|
13779
13916
|
}
|
|
13780
|
-
const
|
|
13781
|
-
|
|
13917
|
+
const home = process.env.HOME ?? process.env.USERPROFILE ?? homedir2();
|
|
13918
|
+
const privateDirs = [
|
|
13919
|
+
join5(home, ".suipay"),
|
|
13920
|
+
join5(home, ".suipay", "credentials.json"),
|
|
13921
|
+
dirname4(mcpCredentialsPath()),
|
|
13922
|
+
mcpCredentialsPath()
|
|
13923
|
+
];
|
|
13924
|
+
const profiles = join5(home, ".suipay", "profiles");
|
|
13925
|
+
privateDirs.push(profiles);
|
|
13782
13926
|
try {
|
|
13783
|
-
|
|
13927
|
+
for (const name of readdirSync(profiles)) {
|
|
13928
|
+
privateDirs.push(join5(profiles, name), join5(profiles, name, "credentials.json"));
|
|
13929
|
+
}
|
|
13784
13930
|
} catch {
|
|
13931
|
+
try {
|
|
13932
|
+
realpathSync(profiles);
|
|
13933
|
+
return fail2("FILE_FORBIDDEN", "credential storage could not be inspected");
|
|
13934
|
+
} catch {
|
|
13935
|
+
}
|
|
13785
13936
|
}
|
|
13786
|
-
|
|
13787
|
-
|
|
13937
|
+
for (const dir of privateDirs) {
|
|
13938
|
+
let realDir = resolve(dir);
|
|
13939
|
+
try {
|
|
13940
|
+
realDir = realpathSync(dir);
|
|
13941
|
+
} catch {
|
|
13942
|
+
}
|
|
13943
|
+
let privateIdentity;
|
|
13944
|
+
try {
|
|
13945
|
+
privateIdentity = statSync(realDir);
|
|
13946
|
+
} catch {
|
|
13947
|
+
}
|
|
13948
|
+
let ancestor = fileReal;
|
|
13949
|
+
while (privateIdentity?.ino) {
|
|
13950
|
+
try {
|
|
13951
|
+
const current = statSync(ancestor);
|
|
13952
|
+
if (current.dev === privateIdentity.dev && current.ino === privateIdentity.ino) {
|
|
13953
|
+
return fail2("FILE_FORBIDDEN", "file must not be under ~/.suipay");
|
|
13954
|
+
}
|
|
13955
|
+
} catch {
|
|
13956
|
+
return fail2("FILE_FORBIDDEN", "file ancestry could not be inspected");
|
|
13957
|
+
}
|
|
13958
|
+
const parent = dirname4(ancestor);
|
|
13959
|
+
if (parent === ancestor) break;
|
|
13960
|
+
ancestor = parent;
|
|
13961
|
+
}
|
|
13962
|
+
if (inside(resolve(dir), resolve(raw)) || inside(realDir, fileReal)) {
|
|
13963
|
+
return fail2("FILE_FORBIDDEN", "file must not be under ~/.suipay");
|
|
13964
|
+
}
|
|
13788
13965
|
}
|
|
13789
13966
|
return fileReal;
|
|
13790
13967
|
}
|
|
@@ -13800,6 +13977,9 @@ function readRegularFile(path) {
|
|
|
13800
13977
|
if (!st.isFile()) {
|
|
13801
13978
|
return fail2("INVALID_FILE", "file must be a regular file");
|
|
13802
13979
|
}
|
|
13980
|
+
if (st.nlink > 1) {
|
|
13981
|
+
return fail2("FILE_FORBIDDEN", "file must have only one hard link");
|
|
13982
|
+
}
|
|
13803
13983
|
if (st.size > MCP_MAX_FILE_FIELD_BYTES) {
|
|
13804
13984
|
return fail2(
|
|
13805
13985
|
"FILE_TOO_LARGE",
|
|
@@ -13826,10 +14006,7 @@ function readRegularFile(path) {
|
|
|
13826
14006
|
return fail2("INVALID_FILE", "file must be a regular file");
|
|
13827
14007
|
}
|
|
13828
14008
|
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
|
-
);
|
|
14009
|
+
return fail2("INVALID_FILE", `file could not be read (${code ?? "unknown error"})`);
|
|
13833
14010
|
} finally {
|
|
13834
14011
|
if (fd !== void 0) {
|
|
13835
14012
|
try {
|
|
@@ -13848,10 +14025,7 @@ function jsonWithLocalFile(input) {
|
|
|
13848
14025
|
if (!hasFile && !hasField) return { json: input.json };
|
|
13849
14026
|
if (hasFile !== hasField) {
|
|
13850
14027
|
return {
|
|
13851
|
-
error: fail2(
|
|
13852
|
-
"INVALID_FILE_ARGS",
|
|
13853
|
-
"file and fileField are required together"
|
|
13854
|
-
)
|
|
14028
|
+
error: fail2("INVALID_FILE_ARGS", "file and fileField are required together")
|
|
13855
14029
|
};
|
|
13856
14030
|
}
|
|
13857
14031
|
const method = parseMethod(input.method);
|
|
@@ -13871,12 +14045,9 @@ function jsonWithLocalFile(input) {
|
|
|
13871
14045
|
} else {
|
|
13872
14046
|
return { error: fail2("MALFORMED_REQUEST", "POST requires json object") };
|
|
13873
14047
|
}
|
|
13874
|
-
if (Object.
|
|
14048
|
+
if (Object.hasOwn(json, field)) {
|
|
13875
14049
|
return {
|
|
13876
|
-
error: fail2(
|
|
13877
|
-
"FILE_FIELD_EXISTS",
|
|
13878
|
-
"json already has fileField; refuse to overwrite"
|
|
13879
|
-
)
|
|
14050
|
+
error: fail2("FILE_FIELD_EXISTS", "json already has fileField; refuse to overwrite")
|
|
13880
14051
|
};
|
|
13881
14052
|
}
|
|
13882
14053
|
const contained = resolveContainedPath(path);
|
|
@@ -13889,76 +14060,6 @@ function jsonWithLocalFile(input) {
|
|
|
13889
14060
|
|
|
13890
14061
|
// ../sdk/dist/pay-flow.js
|
|
13891
14062
|
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
14063
|
function refuse(code, detail) {
|
|
13963
14064
|
return SuiPayError.of(code, "not_charged", { detail });
|
|
13964
14065
|
}
|
|
@@ -14856,6 +14957,7 @@ async function suipayLogin(args, cfg, deps = {}) {
|
|
|
14856
14957
|
consoleUrl: endpoints.consoleUrl,
|
|
14857
14958
|
gatewayUrl: endpoints.gatewayUrl,
|
|
14858
14959
|
identity,
|
|
14960
|
+
signPersonalMessage: local?.signPersonalMessage,
|
|
14859
14961
|
label,
|
|
14860
14962
|
timeoutMs: LOGIN_BG_TIMEOUT_MS,
|
|
14861
14963
|
openBrowser: true,
|
|
@@ -14909,7 +15011,7 @@ function safeRetryDetail(rawDetail) {
|
|
|
14909
15011
|
if (!rawDetail) {
|
|
14910
15012
|
return "Grant status could not be verified on chain. Retry shortly.";
|
|
14911
15013
|
}
|
|
14912
|
-
|
|
15014
|
+
const stripped = rawDetail.replace(/https?:\/\/[^\s"'<>]+/gi, "[redacted]");
|
|
14913
15015
|
if (stripped.includes("ECONNREFUSED") || stripped.includes("ETIMEDOUT") || stripped.includes("fetch failed")) {
|
|
14914
15016
|
return "Network connection to gateway or chain node failed. Retry shortly.";
|
|
14915
15017
|
}
|
|
@@ -15687,8 +15789,8 @@ async function withDeadline(work, ms) {
|
|
|
15687
15789
|
try {
|
|
15688
15790
|
return await Promise.race([
|
|
15689
15791
|
work,
|
|
15690
|
-
new Promise((
|
|
15691
|
-
timer = setTimeout(() =>
|
|
15792
|
+
new Promise((resolve2) => {
|
|
15793
|
+
timer = setTimeout(() => resolve2(null), ms);
|
|
15692
15794
|
timer.unref?.();
|
|
15693
15795
|
})
|
|
15694
15796
|
]);
|
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-Y4VKD3RV.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-H7ET3HU2.js";
|
|
30
30
|
export {
|
|
31
31
|
MCP_TARGET_PRESETS,
|
|
32
32
|
PACKAGE_NAME,
|
package/package.json
CHANGED