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