@t2000/sdk 10.13.2 → 10.13.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1145,8 +1145,9 @@ async function payWithMpp(args) {
1145
1145
  if (probe.status !== 402) {
1146
1146
  return finalize(probe, { paid: false });
1147
1147
  }
1148
- const requirements = await pickSuiExactRequirements(probe, client.network);
1149
- if (requirements) {
1148
+ const pick = await pickSuiExactRequirements(probe, client.network);
1149
+ if (pick.kind === "payable") {
1150
+ const requirements = pick.requirements;
1150
1151
  const { isX402EscrowRequirements } = await import('@suimpp/mpp/x402');
1151
1152
  if (isX402EscrowRequirements(requirements)) {
1152
1153
  const escrow = requirements.extra.escrow;
@@ -1179,6 +1180,13 @@ async function payWithMpp(args) {
1179
1180
  await reportDirectPayment(result, options.url);
1180
1181
  return result;
1181
1182
  }
1183
+ if (pick.kind === "incomplete") {
1184
+ throw new T2000Error(
1185
+ "FACILITATOR_REJECTION",
1186
+ "Seller's x402 challenge is incomplete (missing extra.suimpp) \u2014 nothing was paid. The 402 advertises an exact/sui entry but carries no settlement challenge to bind a payment to; the seller must emit the createX402Requirements shape to be x402-payable.",
1187
+ { reason: "incomplete-x402-accepts" }
1188
+ );
1189
+ }
1182
1190
  throw new T2000Error(
1183
1191
  "FACILITATOR_REJECTION",
1184
1192
  `Endpoint returned 402 without an x402 'exact' / sui:${client.network} requirement in the body or an MPP 'sui' challenge in WWW-Authenticate. Nothing this SDK can pay.`
@@ -1217,17 +1225,34 @@ async function parseMppSuiChallenge(response) {
1217
1225
  return void 0;
1218
1226
  }
1219
1227
  }
1228
+ function hasCompleteSuimppChallenge(entry) {
1229
+ const s = entry.extra?.suimpp;
1230
+ return !!s && typeof s.challengeId === "string" && s.challengeId.length > 0 && typeof s.nonce === "number" && typeof s.chain === "string" && s.chain.length > 0 && typeof s.minEpoch === "string" && typeof s.maxEpoch === "string";
1231
+ }
1220
1232
  async function pickSuiExactRequirements(response, network) {
1221
1233
  try {
1222
1234
  const body2 = await response.clone().json();
1223
1235
  const want = `sui:${network === "testnet" ? "testnet" : "mainnet"}`;
1224
- return body2.accepts?.find((a) => a.scheme === "exact" && a.network === want);
1236
+ const entry = body2.accepts?.find((a) => a.scheme === "exact" && a.network === want);
1237
+ if (!entry) return { kind: "none" };
1238
+ const { isX402EscrowRequirements } = await import('@suimpp/mpp/x402');
1239
+ if (hasCompleteSuimppChallenge(entry) || isX402EscrowRequirements(entry)) {
1240
+ return { kind: "payable", requirements: entry };
1241
+ }
1242
+ return { kind: "incomplete" };
1225
1243
  } catch {
1226
- return void 0;
1244
+ return { kind: "none" };
1227
1245
  }
1228
1246
  }
1229
1247
  async function payViaX402(args) {
1230
1248
  const { signer, client, options, reqInit, requirements } = args;
1249
+ if (!hasCompleteSuimppChallenge(requirements)) {
1250
+ throw new T2000Error(
1251
+ "FACILITATOR_REJECTION",
1252
+ "Seller's x402 challenge is incomplete (missing extra.suimpp) \u2014 nothing was paid.",
1253
+ { reason: "incomplete-x402-accepts" }
1254
+ );
1255
+ }
1231
1256
  const { buildX402SignedPayment, X402_PAYMENT_HEADER, X402_PAYMENT_RESPONSE_HEADER } = await import('@suimpp/mpp/x402');
1232
1257
  const amountRaw = BigInt(requirements.maxAmountRequired);
1233
1258
  assertWithinMaxPrice(atomicToHuman(amountRaw, await assetDecimals(requirements.asset)), options.maxPrice);