@t2000/sdk 10.13.2 → 10.13.3
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/browser.cjs +29 -4
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +29 -4
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +29 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -552,8 +552,9 @@ async function payWithMpp(args) {
|
|
|
552
552
|
if (probe.status !== 402) {
|
|
553
553
|
return finalize(probe, { paid: false });
|
|
554
554
|
}
|
|
555
|
-
const
|
|
556
|
-
if (
|
|
555
|
+
const pick = await pickSuiExactRequirements(probe, client.network);
|
|
556
|
+
if (pick.kind === "payable") {
|
|
557
|
+
const requirements = pick.requirements;
|
|
557
558
|
const { isX402EscrowRequirements } = await import('@suimpp/mpp/x402');
|
|
558
559
|
if (isX402EscrowRequirements(requirements)) {
|
|
559
560
|
const escrow = requirements.extra.escrow;
|
|
@@ -586,6 +587,13 @@ async function payWithMpp(args) {
|
|
|
586
587
|
await reportDirectPayment(result, options.url);
|
|
587
588
|
return result;
|
|
588
589
|
}
|
|
590
|
+
if (pick.kind === "incomplete") {
|
|
591
|
+
throw new T2000Error(
|
|
592
|
+
"FACILITATOR_REJECTION",
|
|
593
|
+
"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.",
|
|
594
|
+
{ reason: "incomplete-x402-accepts" }
|
|
595
|
+
);
|
|
596
|
+
}
|
|
589
597
|
throw new T2000Error(
|
|
590
598
|
"FACILITATOR_REJECTION",
|
|
591
599
|
`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.`
|
|
@@ -624,17 +632,34 @@ async function parseMppSuiChallenge(response) {
|
|
|
624
632
|
return void 0;
|
|
625
633
|
}
|
|
626
634
|
}
|
|
635
|
+
function hasCompleteSuimppChallenge(entry) {
|
|
636
|
+
const s = entry.extra?.suimpp;
|
|
637
|
+
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";
|
|
638
|
+
}
|
|
627
639
|
async function pickSuiExactRequirements(response, network) {
|
|
628
640
|
try {
|
|
629
641
|
const body = await response.clone().json();
|
|
630
642
|
const want = `sui:${network === "testnet" ? "testnet" : "mainnet"}`;
|
|
631
|
-
|
|
643
|
+
const entry = body.accepts?.find((a) => a.scheme === "exact" && a.network === want);
|
|
644
|
+
if (!entry) return { kind: "none" };
|
|
645
|
+
const { isX402EscrowRequirements } = await import('@suimpp/mpp/x402');
|
|
646
|
+
if (hasCompleteSuimppChallenge(entry) || isX402EscrowRequirements(entry)) {
|
|
647
|
+
return { kind: "payable", requirements: entry };
|
|
648
|
+
}
|
|
649
|
+
return { kind: "incomplete" };
|
|
632
650
|
} catch {
|
|
633
|
-
return
|
|
651
|
+
return { kind: "none" };
|
|
634
652
|
}
|
|
635
653
|
}
|
|
636
654
|
async function payViaX402(args) {
|
|
637
655
|
const { signer, client, options, reqInit, requirements } = args;
|
|
656
|
+
if (!hasCompleteSuimppChallenge(requirements)) {
|
|
657
|
+
throw new T2000Error(
|
|
658
|
+
"FACILITATOR_REJECTION",
|
|
659
|
+
"Seller's x402 challenge is incomplete (missing extra.suimpp) \u2014 nothing was paid.",
|
|
660
|
+
{ reason: "incomplete-x402-accepts" }
|
|
661
|
+
);
|
|
662
|
+
}
|
|
638
663
|
const { buildX402SignedPayment, X402_PAYMENT_HEADER, X402_PAYMENT_RESPONSE_HEADER } = await import('@suimpp/mpp/x402');
|
|
639
664
|
const amountRaw = BigInt(requirements.maxAmountRequired);
|
|
640
665
|
assertWithinMaxPrice(atomicToHuman(amountRaw, await assetDecimals(requirements.asset)), options.maxPrice);
|