@t2000/sdk 10.20.2 → 10.21.1
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 +44 -91
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +43 -91
- package/dist/browser.js.map +1 -1
- package/dist/{commerce-BkSSPS1w.d.cts → commerce-CS4wgrg5.d.cts} +42 -29
- package/dist/{commerce-BkSSPS1w.d.ts → commerce-CS4wgrg5.d.ts} +42 -29
- package/dist/index.cjs +44 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +43 -91
- package/dist/index.js.map +1 -1
- package/package.json +2 -4
package/dist/browser.cjs
CHANGED
|
@@ -449,11 +449,23 @@ var ZkLoginSigner = class {
|
|
|
449
449
|
// src/wallet/pay.ts
|
|
450
450
|
init_errors();
|
|
451
451
|
|
|
452
|
-
// src/
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
452
|
+
// src/wallet/activity-report.ts
|
|
453
|
+
var DEFAULT_ACTIVITY_REPORT_URL = "https://t2000.ai/api/activity/x402";
|
|
454
|
+
function resolveActivityReportUrl(override) {
|
|
455
|
+
if (override) return override;
|
|
456
|
+
const env = typeof process !== "undefined" && process.env ? process.env.T2000_ACTIVITY_REPORT_URL?.trim() : void 0;
|
|
457
|
+
return env && env.length > 0 ? env : DEFAULT_ACTIVITY_REPORT_URL;
|
|
458
|
+
}
|
|
459
|
+
function reportX402Activity(payload, url) {
|
|
460
|
+
try {
|
|
461
|
+
void fetch(resolveActivityReportUrl(url), {
|
|
462
|
+
method: "POST",
|
|
463
|
+
headers: { "content-type": "application/json" },
|
|
464
|
+
body: JSON.stringify(payload),
|
|
465
|
+
signal: AbortSignal.timeout(1500)
|
|
466
|
+
}).catch(() => void 0);
|
|
467
|
+
} catch {
|
|
468
|
+
}
|
|
457
469
|
}
|
|
458
470
|
|
|
459
471
|
// src/wallet/executeTx.ts
|
|
@@ -574,18 +586,12 @@ async function payWithMpp(args) {
|
|
|
574
586
|
const result = await payViaX402({ signer, client, options, reqInit, requirements });
|
|
575
587
|
return result;
|
|
576
588
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
{ dialect: "mpp-header", signerKind: "zklogin" }
|
|
584
|
-
);
|
|
585
|
-
}
|
|
586
|
-
assertNotSelfPayment(signer.getAddress(), headerChallenge.recipient);
|
|
587
|
-
const result = await payViaMppHeader({ signer, client, options });
|
|
588
|
-
return result;
|
|
589
|
+
if (hasPaymentAuthenticateHeader(probe)) {
|
|
590
|
+
throw new exports.T2000Error(
|
|
591
|
+
"DIALECT_UNSUPPORTED",
|
|
592
|
+
"This seller answered a header-only 402 (WWW-Authenticate: Payment) with no payable x402 accepts[] envelope. The MPP header dialect is no longer supported \u2014 it charged before the seller proved it could deliver. No payment was made. The seller must offer x402 (e.g. @t2000/serve emits it).",
|
|
593
|
+
{ dialect: "mpp-header", reason: "header-only-402-unsupported" }
|
|
594
|
+
);
|
|
589
595
|
}
|
|
590
596
|
if (pick.kind === "incomplete") {
|
|
591
597
|
throw new exports.T2000Error(
|
|
@@ -599,24 +605,6 @@ async function payWithMpp(args) {
|
|
|
599
605
|
`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.`
|
|
600
606
|
);
|
|
601
607
|
}
|
|
602
|
-
async function parseMppSuiChallenge(response) {
|
|
603
|
-
try {
|
|
604
|
-
const { Challenge } = await import('mppx');
|
|
605
|
-
const challenges = Challenge.fromResponseList(response);
|
|
606
|
-
const suiChallenge = challenges.find((c) => c.method === "sui" && c.intent === "charge");
|
|
607
|
-
if (!suiChallenge) return void 0;
|
|
608
|
-
const req = suiChallenge.request;
|
|
609
|
-
if (typeof req?.amount !== "string" || typeof req?.recipient !== "string") return void 0;
|
|
610
|
-
return {
|
|
611
|
-
amount: req.amount,
|
|
612
|
-
currency: typeof req.currency === "string" ? req.currency : "",
|
|
613
|
-
recipient: req.recipient,
|
|
614
|
-
description: suiChallenge.description
|
|
615
|
-
};
|
|
616
|
-
} catch {
|
|
617
|
-
return void 0;
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
608
|
function hasCompleteSuimppChallenge(entry) {
|
|
621
609
|
const s = entry.extra?.suimpp;
|
|
622
610
|
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";
|
|
@@ -675,6 +663,21 @@ async function payViaX402(args) {
|
|
|
675
663
|
}
|
|
676
664
|
const result = await finalize(res, { paid });
|
|
677
665
|
if (!paid) return { ...result, dialect: "x402" };
|
|
666
|
+
if (digest && options.activityReport !== false) {
|
|
667
|
+
const report = options.activityReport || {};
|
|
668
|
+
reportX402Activity(
|
|
669
|
+
{
|
|
670
|
+
digest,
|
|
671
|
+
payTo: requirements.payTo,
|
|
672
|
+
payer: signer.getAddress(),
|
|
673
|
+
amountMicroUsdc: Number(amountRaw),
|
|
674
|
+
network: requirements.network,
|
|
675
|
+
route: options.url,
|
|
676
|
+
source: report.source ?? "pay"
|
|
677
|
+
},
|
|
678
|
+
report.url
|
|
679
|
+
);
|
|
680
|
+
}
|
|
678
681
|
return {
|
|
679
682
|
...result,
|
|
680
683
|
dialect: "x402",
|
|
@@ -683,61 +686,6 @@ async function payViaX402(args) {
|
|
|
683
686
|
receipt: digest ? { reference: digest, timestamp: (/* @__PURE__ */ new Date()).toISOString() } : result.receipt
|
|
684
687
|
};
|
|
685
688
|
}
|
|
686
|
-
async function payViaMppHeader(args) {
|
|
687
|
-
const { signer, client, options } = args;
|
|
688
|
-
const { Mppx } = await import('mppx/client');
|
|
689
|
-
const { sui, USDC, USDC_TESTNET } = await import('@suimpp/mpp/client');
|
|
690
|
-
const signerAddress = signer.getAddress();
|
|
691
|
-
const network = client.network === "testnet" ? "testnet" : "mainnet";
|
|
692
|
-
const grpcClient = await makeGrpcBuildClient(client);
|
|
693
|
-
let paymentDigest;
|
|
694
|
-
let gasCostSui = 0;
|
|
695
|
-
let chargedAmount;
|
|
696
|
-
const mppx = Mppx.create({
|
|
697
|
-
polyfill: false,
|
|
698
|
-
onChallenge: async (challenge) => {
|
|
699
|
-
const parsed = parseChallengeAmount(challenge);
|
|
700
|
-
if (parsed !== void 0) {
|
|
701
|
-
chargedAmount = parsed;
|
|
702
|
-
assertWithinMaxPrice(parsed, options.maxPrice);
|
|
703
|
-
}
|
|
704
|
-
return void 0;
|
|
705
|
-
},
|
|
706
|
-
methods: [
|
|
707
|
-
sui({
|
|
708
|
-
client,
|
|
709
|
-
currency: network === "testnet" ? USDC_TESTNET : USDC,
|
|
710
|
-
signer: {
|
|
711
|
-
toSuiAddress: () => signerAddress,
|
|
712
|
-
signPersonalMessage: (bytes) => signer.signPersonalMessage(bytes)
|
|
713
|
-
},
|
|
714
|
-
execute: async (tx) => {
|
|
715
|
-
const result2 = await executeTx(client, signer, () => tx, { buildClient: grpcClient });
|
|
716
|
-
paymentDigest = result2.digest;
|
|
717
|
-
gasCostSui = result2.gasCostSui;
|
|
718
|
-
return { digest: result2.digest };
|
|
719
|
-
}
|
|
720
|
-
})
|
|
721
|
-
]
|
|
722
|
-
});
|
|
723
|
-
const method = (options.method ?? "GET").toUpperCase();
|
|
724
|
-
const canHaveBody = method !== "GET" && method !== "HEAD";
|
|
725
|
-
const response = await mppx.fetch(options.url, {
|
|
726
|
-
method,
|
|
727
|
-
headers: options.headers,
|
|
728
|
-
body: canHaveBody ? options.body : void 0
|
|
729
|
-
});
|
|
730
|
-
const paid = !!paymentDigest;
|
|
731
|
-
const result = await finalize(response, { paid });
|
|
732
|
-
if (!paid) return { ...result, dialect: "legacy" };
|
|
733
|
-
return {
|
|
734
|
-
...result,
|
|
735
|
-
dialect: "legacy",
|
|
736
|
-
cost: chargedAmount ?? options.maxPrice ?? void 0,
|
|
737
|
-
gasCostSui,
|
|
738
|
-
receipt: paymentDigest ? { reference: paymentDigest, timestamp: (/* @__PURE__ */ new Date()).toISOString() } : void 0
|
|
739
|
-
};
|
|
740
|
-
}
|
|
741
689
|
function assertNotSelfPayment(payer, payTo) {
|
|
742
690
|
if (utils.normalizeSuiAddress(payer) === utils.normalizeSuiAddress(payTo)) {
|
|
743
691
|
throw new exports.T2000Error(
|
|
@@ -789,6 +737,10 @@ async function ensureAddressBalanceCovers(args) {
|
|
|
789
737
|
const migration = await executeTx(client, signer, () => tx, { buildClient: grpcClient });
|
|
790
738
|
return migration.gasCostSui;
|
|
791
739
|
}
|
|
740
|
+
function hasPaymentAuthenticateHeader(response) {
|
|
741
|
+
const header = response.headers.get("www-authenticate") ?? "";
|
|
742
|
+
return /(^|,)\s*Payment[\s,]/i.test(`${header},`);
|
|
743
|
+
}
|
|
792
744
|
function isJsonText(text) {
|
|
793
745
|
try {
|
|
794
746
|
JSON.parse(text);
|
|
@@ -1667,6 +1619,7 @@ init_token_registry();
|
|
|
1667
1619
|
exports.A2A_ESCROW_FEE_CONFIG_ID = A2A_ESCROW_FEE_CONFIG_ID;
|
|
1668
1620
|
exports.A2A_ESCROW_PACKAGE_ID = A2A_ESCROW_PACKAGE_ID;
|
|
1669
1621
|
exports.CLOCK_ID = CLOCK_ID;
|
|
1622
|
+
exports.DEFAULT_ACTIVITY_REPORT_URL = DEFAULT_ACTIVITY_REPORT_URL;
|
|
1670
1623
|
exports.DEFAULT_COMMERCE_API_BASE = DEFAULT_COMMERCE_API_BASE;
|
|
1671
1624
|
exports.DEFAULT_NETWORK = DEFAULT_NETWORK;
|
|
1672
1625
|
exports.GAS_RESERVE_MIN = GAS_RESERVE_MIN;
|
|
@@ -1720,7 +1673,6 @@ exports.listServices = listServices;
|
|
|
1720
1673
|
exports.mapMoveAbortCode = mapMoveAbortCode;
|
|
1721
1674
|
exports.mapWalletError = mapWalletError;
|
|
1722
1675
|
exports.mistToSui = mistToSui;
|
|
1723
|
-
exports.parseMppSuiChallenge = parseMppSuiChallenge;
|
|
1724
1676
|
exports.parseSuiRpcTx = parseSuiRpcTx;
|
|
1725
1677
|
exports.payWithMpp = payWithMpp;
|
|
1726
1678
|
exports.preflightCreateJob = preflightCreateJob;
|
|
@@ -1732,6 +1684,7 @@ exports.putJobSpec = putJobSpec;
|
|
|
1732
1684
|
exports.rawToStable = rawToStable;
|
|
1733
1685
|
exports.rawToUsdc = rawToUsdc;
|
|
1734
1686
|
exports.refineLendingLabel = refineLendingLabel;
|
|
1687
|
+
exports.reportX402Activity = reportX402Activity;
|
|
1735
1688
|
exports.resolveSymbol = resolveSymbol;
|
|
1736
1689
|
exports.resolveTokenType = resolveTokenType;
|
|
1737
1690
|
exports.stableToRaw = stableToRaw;
|