@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.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as A2A_ESCROW_FEE_CONFIG_ID, a as A2A_ESCROW_PACKAGE_ID, B as BalanceResponse, C as CLOCK_ID,
|
|
1
|
+
export { A as A2A_ESCROW_FEE_CONFIG_ID, a as A2A_ESCROW_PACKAGE_ID, b as ActivityReportConfig, B as BalanceResponse, C as CLOCK_ID, c as COIN_REGISTRY, d as ClassifyBalanceChange, e as ClassifyResult, f as CoinMeta, D as DEFAULT_ACTIVITY_REPORT_URL, g as DEFAULT_COMMERCE_API_BASE, h as DEFAULT_NETWORK, i as DepositInfo, E as ETH_TYPE, j as ExtractedTransfer, G as GAS_RESERVE_MIN, I as IKA_TYPE, J as JOB_STATES, k as Job, l as JobState, m as JobTerms, n as JobVerification, K as KNOWN_TARGETS, o as KeypairSigner, L as LABEL_PATTERNS, p as LOFI_TYPE, M as MANIFEST_TYPE, q as MAX_DELIVER_HORIZON_MS, r as MAX_JOB_USDC, s as MAX_REVIEW_WINDOW_MS, t as MIST_PER_SUI, N as NAVX_TYPE, O as OVERLAY_FEE_RATE, u as OverlayFeeConfig, P as PREFLIGHT_MAX_AMOUNT, v as PREFLIGHT_OK, w as PayOptions, x as PayResult, y as PreflightResult, S as STABLE_ASSETS, z as SUI_DECIMALS, F as SUI_TYPE, H as SUPPORTED_ASSETS, Q as SendResult, R as ServiceListing, T as SimulationResult, U as StableAsset, V as SuiHolding, W as SuiRpcTxBlock, X as SupportedAsset, Y as SwapRouteResult, Z as T2000Error, _ as T2000ErrorCode, $ as T2000ErrorData, a0 as T2000_OVERLAY_FEE_WALLET, a1 as TOKEN_MAP, a2 as TransactionLeg, a3 as TransactionRecord, a4 as TransactionSigner, a5 as TxDirection, a6 as USDC_DECIMALS, a7 as USDC_TYPE, a8 as USDE_TYPE, a9 as USDSUI_TYPE, aa as USDT_TYPE, ab as WAL_TYPE, ac as WBTC_TYPE, ad as X402ActivityPayload, ae as ZkLoginProof, af as ZkLoginSigner, ag as buildCreateJobTx, ah as buildDeliverJobTx, ai as buildRefundJobTx, aj as buildRejectJobTx, ak as buildReleaseJobTx, al as buildSendTx, am as buildSwapTx, an as checkPositiveAmount, ao as checkSuiAddress, ap as classifyAction, aq as classifyLabel, ar as classifyTransaction, as as executeTx, at as extractAllUserLegs, au as extractTransferDetails, av as extractTxCommands, aw as extractTxSender, ax as fallbackLabel, ay as fetchService, az as findSwapRoute, aA as formatAssetAmount, aB as formatSui, aC as formatUsd, aD as getDecimals, aE as getDecimalsForCoinType, aF as getJob, aG as getJobSpec, aH as jobActionsFor, aI as listServices, aJ as mapMoveAbortCode, aK as mapWalletError, aL as mistToSui, aM as parseSuiRpcTx, aN as payWithMpp, aO as preflightCreateJob, aP as preflightFail, aQ as preflightPay, aR as preflightSend, aS as preflightSwap, aT as putJobSpec, aU as rawToStable, aV as rawToUsdc, aW as refineLendingLabel, aX as reportX402Activity, aY as resolveSymbol, aZ as resolveTokenType, a_ as stableToRaw, a$ as suiToMist, b0 as truncateAddress, b1 as usdcToRaw, b2 as validateAddress, b3 as verifyJobForSeller } from './commerce-CS4wgrg5.cjs';
|
|
2
2
|
import '@mysten/sui/keypairs/ed25519';
|
|
3
3
|
import '@mysten/sui/grpc';
|
|
4
4
|
import '@mysten/sui/client';
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as A2A_ESCROW_FEE_CONFIG_ID, a as A2A_ESCROW_PACKAGE_ID, B as BalanceResponse, C as CLOCK_ID,
|
|
1
|
+
export { A as A2A_ESCROW_FEE_CONFIG_ID, a as A2A_ESCROW_PACKAGE_ID, b as ActivityReportConfig, B as BalanceResponse, C as CLOCK_ID, c as COIN_REGISTRY, d as ClassifyBalanceChange, e as ClassifyResult, f as CoinMeta, D as DEFAULT_ACTIVITY_REPORT_URL, g as DEFAULT_COMMERCE_API_BASE, h as DEFAULT_NETWORK, i as DepositInfo, E as ETH_TYPE, j as ExtractedTransfer, G as GAS_RESERVE_MIN, I as IKA_TYPE, J as JOB_STATES, k as Job, l as JobState, m as JobTerms, n as JobVerification, K as KNOWN_TARGETS, o as KeypairSigner, L as LABEL_PATTERNS, p as LOFI_TYPE, M as MANIFEST_TYPE, q as MAX_DELIVER_HORIZON_MS, r as MAX_JOB_USDC, s as MAX_REVIEW_WINDOW_MS, t as MIST_PER_SUI, N as NAVX_TYPE, O as OVERLAY_FEE_RATE, u as OverlayFeeConfig, P as PREFLIGHT_MAX_AMOUNT, v as PREFLIGHT_OK, w as PayOptions, x as PayResult, y as PreflightResult, S as STABLE_ASSETS, z as SUI_DECIMALS, F as SUI_TYPE, H as SUPPORTED_ASSETS, Q as SendResult, R as ServiceListing, T as SimulationResult, U as StableAsset, V as SuiHolding, W as SuiRpcTxBlock, X as SupportedAsset, Y as SwapRouteResult, Z as T2000Error, _ as T2000ErrorCode, $ as T2000ErrorData, a0 as T2000_OVERLAY_FEE_WALLET, a1 as TOKEN_MAP, a2 as TransactionLeg, a3 as TransactionRecord, a4 as TransactionSigner, a5 as TxDirection, a6 as USDC_DECIMALS, a7 as USDC_TYPE, a8 as USDE_TYPE, a9 as USDSUI_TYPE, aa as USDT_TYPE, ab as WAL_TYPE, ac as WBTC_TYPE, ad as X402ActivityPayload, ae as ZkLoginProof, af as ZkLoginSigner, ag as buildCreateJobTx, ah as buildDeliverJobTx, ai as buildRefundJobTx, aj as buildRejectJobTx, ak as buildReleaseJobTx, al as buildSendTx, am as buildSwapTx, an as checkPositiveAmount, ao as checkSuiAddress, ap as classifyAction, aq as classifyLabel, ar as classifyTransaction, as as executeTx, at as extractAllUserLegs, au as extractTransferDetails, av as extractTxCommands, aw as extractTxSender, ax as fallbackLabel, ay as fetchService, az as findSwapRoute, aA as formatAssetAmount, aB as formatSui, aC as formatUsd, aD as getDecimals, aE as getDecimalsForCoinType, aF as getJob, aG as getJobSpec, aH as jobActionsFor, aI as listServices, aJ as mapMoveAbortCode, aK as mapWalletError, aL as mistToSui, aM as parseSuiRpcTx, aN as payWithMpp, aO as preflightCreateJob, aP as preflightFail, aQ as preflightPay, aR as preflightSend, aS as preflightSwap, aT as putJobSpec, aU as rawToStable, aV as rawToUsdc, aW as refineLendingLabel, aX as reportX402Activity, aY as resolveSymbol, aZ as resolveTokenType, a_ as stableToRaw, a$ as suiToMist, b0 as truncateAddress, b1 as usdcToRaw, b2 as validateAddress, b3 as verifyJobForSeller } from './commerce-CS4wgrg5.js';
|
|
2
2
|
import '@mysten/sui/keypairs/ed25519';
|
|
3
3
|
import '@mysten/sui/grpc';
|
|
4
4
|
import '@mysten/sui/client';
|
package/dist/browser.js
CHANGED
|
@@ -447,11 +447,23 @@ var ZkLoginSigner = class {
|
|
|
447
447
|
// src/wallet/pay.ts
|
|
448
448
|
init_errors();
|
|
449
449
|
|
|
450
|
-
// src/
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
450
|
+
// src/wallet/activity-report.ts
|
|
451
|
+
var DEFAULT_ACTIVITY_REPORT_URL = "https://t2000.ai/api/activity/x402";
|
|
452
|
+
function resolveActivityReportUrl(override) {
|
|
453
|
+
if (override) return override;
|
|
454
|
+
const env = typeof process !== "undefined" && process.env ? process.env.T2000_ACTIVITY_REPORT_URL?.trim() : void 0;
|
|
455
|
+
return env && env.length > 0 ? env : DEFAULT_ACTIVITY_REPORT_URL;
|
|
456
|
+
}
|
|
457
|
+
function reportX402Activity(payload, url) {
|
|
458
|
+
try {
|
|
459
|
+
void fetch(resolveActivityReportUrl(url), {
|
|
460
|
+
method: "POST",
|
|
461
|
+
headers: { "content-type": "application/json" },
|
|
462
|
+
body: JSON.stringify(payload),
|
|
463
|
+
signal: AbortSignal.timeout(1500)
|
|
464
|
+
}).catch(() => void 0);
|
|
465
|
+
} catch {
|
|
466
|
+
}
|
|
455
467
|
}
|
|
456
468
|
|
|
457
469
|
// src/wallet/executeTx.ts
|
|
@@ -572,18 +584,12 @@ async function payWithMpp(args) {
|
|
|
572
584
|
const result = await payViaX402({ signer, client, options, reqInit, requirements });
|
|
573
585
|
return result;
|
|
574
586
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
{ dialect: "mpp-header", signerKind: "zklogin" }
|
|
582
|
-
);
|
|
583
|
-
}
|
|
584
|
-
assertNotSelfPayment(signer.getAddress(), headerChallenge.recipient);
|
|
585
|
-
const result = await payViaMppHeader({ signer, client, options });
|
|
586
|
-
return result;
|
|
587
|
+
if (hasPaymentAuthenticateHeader(probe)) {
|
|
588
|
+
throw new T2000Error(
|
|
589
|
+
"DIALECT_UNSUPPORTED",
|
|
590
|
+
"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).",
|
|
591
|
+
{ dialect: "mpp-header", reason: "header-only-402-unsupported" }
|
|
592
|
+
);
|
|
587
593
|
}
|
|
588
594
|
if (pick.kind === "incomplete") {
|
|
589
595
|
throw new T2000Error(
|
|
@@ -597,24 +603,6 @@ async function payWithMpp(args) {
|
|
|
597
603
|
`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.`
|
|
598
604
|
);
|
|
599
605
|
}
|
|
600
|
-
async function parseMppSuiChallenge(response) {
|
|
601
|
-
try {
|
|
602
|
-
const { Challenge } = await import('mppx');
|
|
603
|
-
const challenges = Challenge.fromResponseList(response);
|
|
604
|
-
const suiChallenge = challenges.find((c) => c.method === "sui" && c.intent === "charge");
|
|
605
|
-
if (!suiChallenge) return void 0;
|
|
606
|
-
const req = suiChallenge.request;
|
|
607
|
-
if (typeof req?.amount !== "string" || typeof req?.recipient !== "string") return void 0;
|
|
608
|
-
return {
|
|
609
|
-
amount: req.amount,
|
|
610
|
-
currency: typeof req.currency === "string" ? req.currency : "",
|
|
611
|
-
recipient: req.recipient,
|
|
612
|
-
description: suiChallenge.description
|
|
613
|
-
};
|
|
614
|
-
} catch {
|
|
615
|
-
return void 0;
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
606
|
function hasCompleteSuimppChallenge(entry) {
|
|
619
607
|
const s = entry.extra?.suimpp;
|
|
620
608
|
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";
|
|
@@ -673,6 +661,21 @@ async function payViaX402(args) {
|
|
|
673
661
|
}
|
|
674
662
|
const result = await finalize(res, { paid });
|
|
675
663
|
if (!paid) return { ...result, dialect: "x402" };
|
|
664
|
+
if (digest && options.activityReport !== false) {
|
|
665
|
+
const report = options.activityReport || {};
|
|
666
|
+
reportX402Activity(
|
|
667
|
+
{
|
|
668
|
+
digest,
|
|
669
|
+
payTo: requirements.payTo,
|
|
670
|
+
payer: signer.getAddress(),
|
|
671
|
+
amountMicroUsdc: Number(amountRaw),
|
|
672
|
+
network: requirements.network,
|
|
673
|
+
route: options.url,
|
|
674
|
+
source: report.source ?? "pay"
|
|
675
|
+
},
|
|
676
|
+
report.url
|
|
677
|
+
);
|
|
678
|
+
}
|
|
676
679
|
return {
|
|
677
680
|
...result,
|
|
678
681
|
dialect: "x402",
|
|
@@ -681,61 +684,6 @@ async function payViaX402(args) {
|
|
|
681
684
|
receipt: digest ? { reference: digest, timestamp: (/* @__PURE__ */ new Date()).toISOString() } : result.receipt
|
|
682
685
|
};
|
|
683
686
|
}
|
|
684
|
-
async function payViaMppHeader(args) {
|
|
685
|
-
const { signer, client, options } = args;
|
|
686
|
-
const { Mppx } = await import('mppx/client');
|
|
687
|
-
const { sui, USDC, USDC_TESTNET } = await import('@suimpp/mpp/client');
|
|
688
|
-
const signerAddress = signer.getAddress();
|
|
689
|
-
const network = client.network === "testnet" ? "testnet" : "mainnet";
|
|
690
|
-
const grpcClient = await makeGrpcBuildClient(client);
|
|
691
|
-
let paymentDigest;
|
|
692
|
-
let gasCostSui = 0;
|
|
693
|
-
let chargedAmount;
|
|
694
|
-
const mppx = Mppx.create({
|
|
695
|
-
polyfill: false,
|
|
696
|
-
onChallenge: async (challenge) => {
|
|
697
|
-
const parsed = parseChallengeAmount(challenge);
|
|
698
|
-
if (parsed !== void 0) {
|
|
699
|
-
chargedAmount = parsed;
|
|
700
|
-
assertWithinMaxPrice(parsed, options.maxPrice);
|
|
701
|
-
}
|
|
702
|
-
return void 0;
|
|
703
|
-
},
|
|
704
|
-
methods: [
|
|
705
|
-
sui({
|
|
706
|
-
client,
|
|
707
|
-
currency: network === "testnet" ? USDC_TESTNET : USDC,
|
|
708
|
-
signer: {
|
|
709
|
-
toSuiAddress: () => signerAddress,
|
|
710
|
-
signPersonalMessage: (bytes) => signer.signPersonalMessage(bytes)
|
|
711
|
-
},
|
|
712
|
-
execute: async (tx) => {
|
|
713
|
-
const result2 = await executeTx(client, signer, () => tx, { buildClient: grpcClient });
|
|
714
|
-
paymentDigest = result2.digest;
|
|
715
|
-
gasCostSui = result2.gasCostSui;
|
|
716
|
-
return { digest: result2.digest };
|
|
717
|
-
}
|
|
718
|
-
})
|
|
719
|
-
]
|
|
720
|
-
});
|
|
721
|
-
const method = (options.method ?? "GET").toUpperCase();
|
|
722
|
-
const canHaveBody = method !== "GET" && method !== "HEAD";
|
|
723
|
-
const response = await mppx.fetch(options.url, {
|
|
724
|
-
method,
|
|
725
|
-
headers: options.headers,
|
|
726
|
-
body: canHaveBody ? options.body : void 0
|
|
727
|
-
});
|
|
728
|
-
const paid = !!paymentDigest;
|
|
729
|
-
const result = await finalize(response, { paid });
|
|
730
|
-
if (!paid) return { ...result, dialect: "legacy" };
|
|
731
|
-
return {
|
|
732
|
-
...result,
|
|
733
|
-
dialect: "legacy",
|
|
734
|
-
cost: chargedAmount ?? options.maxPrice ?? void 0,
|
|
735
|
-
gasCostSui,
|
|
736
|
-
receipt: paymentDigest ? { reference: paymentDigest, timestamp: (/* @__PURE__ */ new Date()).toISOString() } : void 0
|
|
737
|
-
};
|
|
738
|
-
}
|
|
739
687
|
function assertNotSelfPayment(payer, payTo) {
|
|
740
688
|
if (normalizeSuiAddress(payer) === normalizeSuiAddress(payTo)) {
|
|
741
689
|
throw new T2000Error(
|
|
@@ -787,6 +735,10 @@ async function ensureAddressBalanceCovers(args) {
|
|
|
787
735
|
const migration = await executeTx(client, signer, () => tx, { buildClient: grpcClient });
|
|
788
736
|
return migration.gasCostSui;
|
|
789
737
|
}
|
|
738
|
+
function hasPaymentAuthenticateHeader(response) {
|
|
739
|
+
const header = response.headers.get("www-authenticate") ?? "";
|
|
740
|
+
return /(^|,)\s*Payment[\s,]/i.test(`${header},`);
|
|
741
|
+
}
|
|
790
742
|
function isJsonText(text) {
|
|
791
743
|
try {
|
|
792
744
|
JSON.parse(text);
|
|
@@ -1662,6 +1614,6 @@ async function getJobSpec(base, hash) {
|
|
|
1662
1614
|
// src/browser.ts
|
|
1663
1615
|
init_token_registry();
|
|
1664
1616
|
|
|
1665
|
-
export { A2A_ESCROW_FEE_CONFIG_ID, A2A_ESCROW_PACKAGE_ID, CLOCK_ID, COIN_REGISTRY, DEFAULT_COMMERCE_API_BASE, DEFAULT_NETWORK, ETH_TYPE, GAS_RESERVE_MIN, IKA_TYPE, JOB_STATES, KNOWN_TARGETS, KeypairSigner, LABEL_PATTERNS, LOFI_TYPE, MANIFEST_TYPE, MAX_DELIVER_HORIZON_MS, MAX_JOB_USDC, MAX_REVIEW_WINDOW_MS, MIST_PER_SUI, NAVX_TYPE, OVERLAY_FEE_RATE, PREFLIGHT_MAX_AMOUNT, PREFLIGHT_OK, STABLE_ASSETS, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, T2000Error, T2000_OVERLAY_FEE_WALLET, TOKEN_MAP, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, WAL_TYPE, WBTC_TYPE, ZkLoginSigner, buildCreateJobTx, buildDeliverJobTx, buildRefundJobTx, buildRejectJobTx, buildReleaseJobTx, buildSendTx, buildSwapTx, checkPositiveAmount, checkSuiAddress, classifyAction, classifyLabel, classifyTransaction, executeTx, extractAllUserLegs, extractTransferDetails, extractTxCommands, extractTxSender, fallbackLabel, fetchService, findSwapRoute, formatAssetAmount, formatSui, formatUsd, fromBase642 as fromBase64, getDecimals, getDecimalsForCoinType, getJob, getJobSpec, jobActionsFor, listServices, mapMoveAbortCode, mapWalletError, mistToSui,
|
|
1617
|
+
export { A2A_ESCROW_FEE_CONFIG_ID, A2A_ESCROW_PACKAGE_ID, CLOCK_ID, COIN_REGISTRY, DEFAULT_ACTIVITY_REPORT_URL, DEFAULT_COMMERCE_API_BASE, DEFAULT_NETWORK, ETH_TYPE, GAS_RESERVE_MIN, IKA_TYPE, JOB_STATES, KNOWN_TARGETS, KeypairSigner, LABEL_PATTERNS, LOFI_TYPE, MANIFEST_TYPE, MAX_DELIVER_HORIZON_MS, MAX_JOB_USDC, MAX_REVIEW_WINDOW_MS, MIST_PER_SUI, NAVX_TYPE, OVERLAY_FEE_RATE, PREFLIGHT_MAX_AMOUNT, PREFLIGHT_OK, STABLE_ASSETS, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, T2000Error, T2000_OVERLAY_FEE_WALLET, TOKEN_MAP, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, WAL_TYPE, WBTC_TYPE, ZkLoginSigner, buildCreateJobTx, buildDeliverJobTx, buildRefundJobTx, buildRejectJobTx, buildReleaseJobTx, buildSendTx, buildSwapTx, checkPositiveAmount, checkSuiAddress, classifyAction, classifyLabel, classifyTransaction, executeTx, extractAllUserLegs, extractTransferDetails, extractTxCommands, extractTxSender, fallbackLabel, fetchService, findSwapRoute, formatAssetAmount, formatSui, formatUsd, fromBase642 as fromBase64, getDecimals, getDecimalsForCoinType, getJob, getJobSpec, jobActionsFor, listServices, mapMoveAbortCode, mapWalletError, mistToSui, parseSuiRpcTx, payWithMpp, preflightCreateJob, preflightFail, preflightPay, preflightSend, preflightSwap, putJobSpec, rawToStable, rawToUsdc, refineLendingLabel, reportX402Activity, resolveSymbol, resolveTokenType, stableToRaw, suiToMist, toBase64, truncateAddress, usdcToRaw, validateAddress, verifyJobForSeller };
|
|
1666
1618
|
//# sourceMappingURL=browser.js.map
|
|
1667
1619
|
//# sourceMappingURL=browser.js.map
|