@t2000/sdk 9.2.0 → 9.3.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.
@@ -1,4 +1,4 @@
1
- export { B as BalanceResponse, C as CLOCK_ID, a as COIN_REGISTRY, b as ClassifyBalanceChange, c as ClassifyResult, d as CoinMeta, D as DEFAULT_NETWORK, e as DepositInfo, E as ETH_TYPE, f as ExtractedTransfer, G as GAS_RESERVE_MIN, I as IKA_TYPE, K as KNOWN_TARGETS, g as KeypairSigner, L as LABEL_PATTERNS, h as LOFI_TYPE, M as MANIFEST_TYPE, i as MIST_PER_SUI, N as NAVX_TYPE, O as OVERLAY_FEE_RATE, j as OverlayFeeConfig, P as PREFLIGHT_MAX_AMOUNT, k as PREFLIGHT_OK, l as PayOptions, m as PayResult, n as PreflightResult, S as STABLE_ASSETS, o as SUI_DECIMALS, p as SUI_TYPE, q as SUPPORTED_ASSETS, r as SendResult, s as SimulationResult, t as StableAsset, u as SuiHolding, v as SuiRpcTxBlock, w as SupportedAsset, x as SwapRouteResult, T as T2000Error, y as T2000ErrorCode, z as T2000ErrorData, A as T2000_OVERLAY_FEE_WALLET, F as TOKEN_MAP, H as TransactionLeg, J as TransactionRecord, Q as TransactionSigner, R as TxDirection, U as USDC_DECIMALS, V as USDC_TYPE, W as USDE_TYPE, X as USDSUI_TYPE, Y as USDT_TYPE, Z as WAL_TYPE, _ as WBTC_TYPE, $ as ZkLoginProof, a0 as ZkLoginSigner, a1 as buildSendTx, a2 as buildSwapTx, a3 as checkPositiveAmount, a4 as checkSuiAddress, a5 as classifyAction, a6 as classifyLabel, a7 as classifyTransaction, a8 as executeTx, a9 as extractAllUserLegs, aa as extractTransferDetails, ab as extractTxCommands, ac as extractTxSender, ad as fallbackLabel, ae as findSwapRoute, af as formatAssetAmount, ag as formatSui, ah as formatUsd, ai as getDecimals, aj as getDecimalsForCoinType, ak as mapMoveAbortCode, al as mapWalletError, am as mistToSui, an as parseSuiRpcTx, ao as payWithMpp, ap as preflightFail, aq as preflightPay, ar as preflightSend, as as preflightSwap, at as rawToStable, au as rawToUsdc, av as refineLendingLabel, aw as resolveSymbol, ax as resolveTokenType, ay as stableToRaw, az as suiToMist, aA as truncateAddress, aB as usdcToRaw, aC as validateAddress } from './send-CUUOLK_H.cjs';
1
+ export { B as BalanceResponse, C as CLOCK_ID, a as COIN_REGISTRY, b as ClassifyBalanceChange, c as ClassifyResult, d as CoinMeta, D as DEFAULT_NETWORK, e as DepositInfo, E as ETH_TYPE, f as ExtractedTransfer, G as GAS_RESERVE_MIN, I as IKA_TYPE, K as KNOWN_TARGETS, g as KeypairSigner, L as LABEL_PATTERNS, h as LOFI_TYPE, M as MANIFEST_TYPE, i as MIST_PER_SUI, N as NAVX_TYPE, O as OVERLAY_FEE_RATE, j as OverlayFeeConfig, P as PREFLIGHT_MAX_AMOUNT, k as PREFLIGHT_OK, l as PayOptions, m as PayResult, n as PreflightResult, S as STABLE_ASSETS, o as SUI_DECIMALS, p as SUI_TYPE, q as SUPPORTED_ASSETS, r as SendResult, s as SimulationResult, t as StableAsset, u as SuiHolding, v as SuiRpcTxBlock, w as SupportedAsset, x as SwapRouteResult, T as T2000Error, y as T2000ErrorCode, z as T2000ErrorData, A as T2000_OVERLAY_FEE_WALLET, F as TOKEN_MAP, H as TransactionLeg, J as TransactionRecord, Q as TransactionSigner, R as TxDirection, U as USDC_DECIMALS, V as USDC_TYPE, W as USDE_TYPE, X as USDSUI_TYPE, Y as USDT_TYPE, Z as WAL_TYPE, _ as WBTC_TYPE, $ as ZkLoginProof, a0 as ZkLoginSigner, a1 as buildSendTx, a2 as buildSwapTx, a3 as checkPositiveAmount, a4 as checkSuiAddress, a5 as classifyAction, a6 as classifyLabel, a7 as classifyTransaction, a8 as executeTx, a9 as extractAllUserLegs, aa as extractTransferDetails, ab as extractTxCommands, ac as extractTxSender, ad as fallbackLabel, ae as findSwapRoute, af as formatAssetAmount, ag as formatSui, ah as formatUsd, ai as getDecimals, aj as getDecimalsForCoinType, ak as mapMoveAbortCode, al as mapWalletError, am as mistToSui, an as parseMppSuiChallenge, ao as parseSuiRpcTx, ap as payWithMpp, aq as preflightFail, ar as preflightPay, as as preflightSend, at as preflightSwap, au as rawToStable, av as rawToUsdc, aw as refineLendingLabel, ax as resolveSymbol, ay as resolveTokenType, az as stableToRaw, aA as suiToMist, aB as truncateAddress, aC as usdcToRaw, aD as validateAddress } from './send-DEK6aOGe.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 { B as BalanceResponse, C as CLOCK_ID, a as COIN_REGISTRY, b as ClassifyBalanceChange, c as ClassifyResult, d as CoinMeta, D as DEFAULT_NETWORK, e as DepositInfo, E as ETH_TYPE, f as ExtractedTransfer, G as GAS_RESERVE_MIN, I as IKA_TYPE, K as KNOWN_TARGETS, g as KeypairSigner, L as LABEL_PATTERNS, h as LOFI_TYPE, M as MANIFEST_TYPE, i as MIST_PER_SUI, N as NAVX_TYPE, O as OVERLAY_FEE_RATE, j as OverlayFeeConfig, P as PREFLIGHT_MAX_AMOUNT, k as PREFLIGHT_OK, l as PayOptions, m as PayResult, n as PreflightResult, S as STABLE_ASSETS, o as SUI_DECIMALS, p as SUI_TYPE, q as SUPPORTED_ASSETS, r as SendResult, s as SimulationResult, t as StableAsset, u as SuiHolding, v as SuiRpcTxBlock, w as SupportedAsset, x as SwapRouteResult, T as T2000Error, y as T2000ErrorCode, z as T2000ErrorData, A as T2000_OVERLAY_FEE_WALLET, F as TOKEN_MAP, H as TransactionLeg, J as TransactionRecord, Q as TransactionSigner, R as TxDirection, U as USDC_DECIMALS, V as USDC_TYPE, W as USDE_TYPE, X as USDSUI_TYPE, Y as USDT_TYPE, Z as WAL_TYPE, _ as WBTC_TYPE, $ as ZkLoginProof, a0 as ZkLoginSigner, a1 as buildSendTx, a2 as buildSwapTx, a3 as checkPositiveAmount, a4 as checkSuiAddress, a5 as classifyAction, a6 as classifyLabel, a7 as classifyTransaction, a8 as executeTx, a9 as extractAllUserLegs, aa as extractTransferDetails, ab as extractTxCommands, ac as extractTxSender, ad as fallbackLabel, ae as findSwapRoute, af as formatAssetAmount, ag as formatSui, ah as formatUsd, ai as getDecimals, aj as getDecimalsForCoinType, ak as mapMoveAbortCode, al as mapWalletError, am as mistToSui, an as parseSuiRpcTx, ao as payWithMpp, ap as preflightFail, aq as preflightPay, ar as preflightSend, as as preflightSwap, at as rawToStable, au as rawToUsdc, av as refineLendingLabel, aw as resolveSymbol, ax as resolveTokenType, ay as stableToRaw, az as suiToMist, aA as truncateAddress, aB as usdcToRaw, aC as validateAddress } from './send-CUUOLK_H.js';
1
+ export { B as BalanceResponse, C as CLOCK_ID, a as COIN_REGISTRY, b as ClassifyBalanceChange, c as ClassifyResult, d as CoinMeta, D as DEFAULT_NETWORK, e as DepositInfo, E as ETH_TYPE, f as ExtractedTransfer, G as GAS_RESERVE_MIN, I as IKA_TYPE, K as KNOWN_TARGETS, g as KeypairSigner, L as LABEL_PATTERNS, h as LOFI_TYPE, M as MANIFEST_TYPE, i as MIST_PER_SUI, N as NAVX_TYPE, O as OVERLAY_FEE_RATE, j as OverlayFeeConfig, P as PREFLIGHT_MAX_AMOUNT, k as PREFLIGHT_OK, l as PayOptions, m as PayResult, n as PreflightResult, S as STABLE_ASSETS, o as SUI_DECIMALS, p as SUI_TYPE, q as SUPPORTED_ASSETS, r as SendResult, s as SimulationResult, t as StableAsset, u as SuiHolding, v as SuiRpcTxBlock, w as SupportedAsset, x as SwapRouteResult, T as T2000Error, y as T2000ErrorCode, z as T2000ErrorData, A as T2000_OVERLAY_FEE_WALLET, F as TOKEN_MAP, H as TransactionLeg, J as TransactionRecord, Q as TransactionSigner, R as TxDirection, U as USDC_DECIMALS, V as USDC_TYPE, W as USDE_TYPE, X as USDSUI_TYPE, Y as USDT_TYPE, Z as WAL_TYPE, _ as WBTC_TYPE, $ as ZkLoginProof, a0 as ZkLoginSigner, a1 as buildSendTx, a2 as buildSwapTx, a3 as checkPositiveAmount, a4 as checkSuiAddress, a5 as classifyAction, a6 as classifyLabel, a7 as classifyTransaction, a8 as executeTx, a9 as extractAllUserLegs, aa as extractTransferDetails, ab as extractTxCommands, ac as extractTxSender, ad as fallbackLabel, ae as findSwapRoute, af as formatAssetAmount, ag as formatSui, ah as formatUsd, ai as getDecimals, aj as getDecimalsForCoinType, ak as mapMoveAbortCode, al as mapWalletError, am as mistToSui, an as parseMppSuiChallenge, ao as parseSuiRpcTx, ap as payWithMpp, aq as preflightFail, ar as preflightPay, as as preflightSend, at as preflightSwap, au as rawToStable, av as rawToUsdc, aw as refineLendingLabel, ax as resolveSymbol, ay as resolveTokenType, az as stableToRaw, aA as suiToMist, aB as truncateAddress, aC as usdcToRaw, aD as validateAddress } from './send-DEK6aOGe.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
@@ -445,6 +445,13 @@ var ZkLoginSigner = class {
445
445
  // src/wallet/pay.ts
446
446
  init_errors();
447
447
 
448
+ // src/mpp-cost.ts
449
+ function parseChallengeAmount(challenge) {
450
+ const raw = challenge?.request?.amount;
451
+ const n = typeof raw === "string" ? Number(raw) : typeof raw === "number" ? raw : Number.NaN;
452
+ return Number.isFinite(n) ? n : void 0;
453
+ }
454
+
448
455
  // src/wallet/executeTx.ts
449
456
  async function executeTx(client, signer, buildTx, options = {}) {
450
457
  const tx = await buildTx();
@@ -457,7 +464,11 @@ async function executeTx(client, signer, buildTx, options = {}) {
457
464
  include: { effects: true }
458
465
  });
459
466
  const txn = result.$kind === "Transaction" ? result.Transaction : result.FailedTransaction;
460
- await client.core.waitForTransaction({ digest: txn.digest });
467
+ try {
468
+ await client.core.waitForTransaction({ digest: txn.digest });
469
+ } catch (err) {
470
+ if (!txn.effects) throw err;
471
+ }
461
472
  const effects = txn.effects ?? void 0;
462
473
  const gasUsed = effects?.gasUsed;
463
474
  let gasCostSui = 0;
@@ -518,11 +529,18 @@ function preflightPay(input) {
518
529
  return PREFLIGHT_OK;
519
530
  }
520
531
  async function payWithMpp(args) {
521
- const { signer, client, options } = args;
532
+ const { signer, client } = args;
533
+ let options = args.options;
522
534
  const pf = preflightPay({ url: options.url, maxPrice: options.maxPrice });
523
535
  if (!pf.valid) throw new T2000Error(pf.code, pf.error);
524
536
  const method = (options.method ?? "GET").toUpperCase();
525
537
  const canHaveBody = method !== "GET" && method !== "HEAD";
538
+ if (canHaveBody && typeof options.body === "string" && isJsonText(options.body) && !hasContentType(options.headers)) {
539
+ options = {
540
+ ...options,
541
+ headers: { ...options.headers ?? {}, "content-type": "application/json" }
542
+ };
543
+ }
526
544
  const reqInit = {
527
545
  method,
528
546
  headers: options.headers,
@@ -533,13 +551,35 @@ async function payWithMpp(args) {
533
551
  return finalize(probe, { paid: false });
534
552
  }
535
553
  const requirements = await pickSuiExactRequirements(probe, client.network);
536
- if (!requirements) {
537
- throw new T2000Error(
538
- "FACILITATOR_REJECTION",
539
- `Endpoint returned 402 without an x402 'exact' / sui:${client.network} payment requirement. This SDK only speaks the x402 dialect.`
540
- );
554
+ if (requirements) {
555
+ return payViaX402({ signer, client, options, reqInit, requirements });
556
+ }
557
+ const headerChallenge = await parseMppSuiChallenge(probe);
558
+ if (headerChallenge) {
559
+ return payViaMppHeader({ signer, client, options });
560
+ }
561
+ throw new T2000Error(
562
+ "FACILITATOR_REJECTION",
563
+ `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.`
564
+ );
565
+ }
566
+ async function parseMppSuiChallenge(response) {
567
+ try {
568
+ const { Challenge } = await import('mppx');
569
+ const challenges = Challenge.fromResponseList(response);
570
+ const suiChallenge = challenges.find((c) => c.method === "sui" && c.intent === "charge");
571
+ if (!suiChallenge) return void 0;
572
+ const req = suiChallenge.request;
573
+ if (typeof req?.amount !== "string" || typeof req?.recipient !== "string") return void 0;
574
+ return {
575
+ amount: req.amount,
576
+ currency: typeof req.currency === "string" ? req.currency : "",
577
+ recipient: req.recipient,
578
+ description: suiChallenge.description
579
+ };
580
+ } catch {
581
+ return void 0;
541
582
  }
542
- return payViaX402({ signer, client, options, reqInit, requirements });
543
583
  }
544
584
  async function pickSuiExactRequirements(response, network) {
545
585
  try {
@@ -554,6 +594,7 @@ async function payViaX402(args) {
554
594
  const { signer, client, options, reqInit, requirements } = args;
555
595
  const { buildX402SignedPayment, X402_PAYMENT_HEADER, X402_PAYMENT_RESPONSE_HEADER } = await import('@suimpp/mpp/x402');
556
596
  const amountRaw = BigInt(requirements.maxAmountRequired);
597
+ assertWithinMaxPrice(atomicToHuman(amountRaw, await assetDecimals(requirements.asset)), options.maxPrice);
557
598
  const migrationGasSui = await ensureAddressBalanceCovers({
558
599
  signer,
559
600
  client,
@@ -589,6 +630,70 @@ async function payViaX402(args) {
589
630
  receipt: digest ? { reference: digest, timestamp: (/* @__PURE__ */ new Date()).toISOString() } : result.receipt
590
631
  };
591
632
  }
633
+ async function payViaMppHeader(args) {
634
+ const { signer, client, options } = args;
635
+ const { Mppx } = await import('mppx/client');
636
+ const { sui, USDC, USDC_TESTNET } = await import('@suimpp/mpp/client');
637
+ const signerAddress = signer.getAddress();
638
+ const network = client.network === "testnet" ? "testnet" : "mainnet";
639
+ const grpcClient = await makeGrpcBuildClient(client);
640
+ let paymentDigest;
641
+ let gasCostSui = 0;
642
+ let chargedAmount;
643
+ const mppx = Mppx.create({
644
+ polyfill: false,
645
+ onChallenge: async (challenge) => {
646
+ const parsed = parseChallengeAmount(challenge);
647
+ if (parsed !== void 0) {
648
+ chargedAmount = parsed;
649
+ assertWithinMaxPrice(parsed, options.maxPrice);
650
+ }
651
+ return void 0;
652
+ },
653
+ methods: [
654
+ sui({
655
+ client,
656
+ currency: network === "testnet" ? USDC_TESTNET : USDC,
657
+ signer: {
658
+ toSuiAddress: () => signerAddress,
659
+ signPersonalMessage: (bytes) => signer.signPersonalMessage(bytes)
660
+ },
661
+ execute: async (tx) => {
662
+ const result2 = await executeTx(client, signer, () => tx, { buildClient: grpcClient });
663
+ paymentDigest = result2.digest;
664
+ gasCostSui = result2.gasCostSui;
665
+ return { digest: result2.digest };
666
+ }
667
+ })
668
+ ]
669
+ });
670
+ const method = (options.method ?? "GET").toUpperCase();
671
+ const canHaveBody = method !== "GET" && method !== "HEAD";
672
+ const response = await mppx.fetch(options.url, {
673
+ method,
674
+ headers: options.headers,
675
+ body: canHaveBody ? options.body : void 0
676
+ });
677
+ const paid = !!paymentDigest;
678
+ const result = await finalize(response, { paid });
679
+ if (!paid) return { ...result, dialect: "legacy" };
680
+ return {
681
+ ...result,
682
+ dialect: "legacy",
683
+ cost: chargedAmount ?? options.maxPrice ?? void 0,
684
+ gasCostSui,
685
+ receipt: paymentDigest ? { reference: paymentDigest, timestamp: (/* @__PURE__ */ new Date()).toISOString() } : void 0
686
+ };
687
+ }
688
+ function assertWithinMaxPrice(price, maxPrice) {
689
+ if (maxPrice !== void 0 && price > maxPrice) {
690
+ throw new T2000Error(
691
+ "PRICE_EXCEEDS_LIMIT",
692
+ `Service price $${price} exceeds maxPrice ceiling $${maxPrice}`,
693
+ { price, maxPrice }
694
+ );
695
+ }
696
+ }
592
697
  async function ensureAddressBalanceCovers(args) {
593
698
  const { signer, client, asset, amountRaw } = args;
594
699
  const owner = signer.getAddress();
@@ -622,6 +727,18 @@ async function ensureAddressBalanceCovers(args) {
622
727
  const migration = await executeTx(client, signer, () => tx, { buildClient: grpcClient });
623
728
  return migration.gasCostSui;
624
729
  }
730
+ function isJsonText(text) {
731
+ try {
732
+ JSON.parse(text);
733
+ return true;
734
+ } catch {
735
+ return false;
736
+ }
737
+ }
738
+ function hasContentType(headers) {
739
+ if (!headers) return false;
740
+ return Object.keys(headers).some((k) => k.toLowerCase() === "content-type");
741
+ }
625
742
  async function finalize(response, opts) {
626
743
  const contentType = response.headers.get("content-type") ?? "";
627
744
  let body;
@@ -1170,6 +1287,6 @@ async function buildSendTx({
1170
1287
  // src/browser.ts
1171
1288
  init_token_registry();
1172
1289
 
1173
- export { CLOCK_ID, COIN_REGISTRY, DEFAULT_NETWORK, ETH_TYPE, GAS_RESERVE_MIN, IKA_TYPE, KNOWN_TARGETS, KeypairSigner, LABEL_PATTERNS, LOFI_TYPE, MANIFEST_TYPE, 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, buildSendTx, buildSwapTx, checkPositiveAmount, checkSuiAddress, classifyAction, classifyLabel, classifyTransaction, executeTx, extractAllUserLegs, extractTransferDetails, extractTxCommands, extractTxSender, fallbackLabel, findSwapRoute, formatAssetAmount, formatSui, formatUsd, fromBase642 as fromBase64, getDecimals, getDecimalsForCoinType, mapMoveAbortCode, mapWalletError, mistToSui, parseSuiRpcTx, payWithMpp, preflightFail, preflightPay, preflightSend, preflightSwap, rawToStable, rawToUsdc, refineLendingLabel, resolveSymbol, resolveTokenType, stableToRaw, suiToMist, toBase64, truncateAddress, usdcToRaw, validateAddress };
1290
+ export { CLOCK_ID, COIN_REGISTRY, DEFAULT_NETWORK, ETH_TYPE, GAS_RESERVE_MIN, IKA_TYPE, KNOWN_TARGETS, KeypairSigner, LABEL_PATTERNS, LOFI_TYPE, MANIFEST_TYPE, 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, buildSendTx, buildSwapTx, checkPositiveAmount, checkSuiAddress, classifyAction, classifyLabel, classifyTransaction, executeTx, extractAllUserLegs, extractTransferDetails, extractTxCommands, extractTxSender, fallbackLabel, findSwapRoute, formatAssetAmount, formatSui, formatUsd, fromBase642 as fromBase64, getDecimals, getDecimalsForCoinType, mapMoveAbortCode, mapWalletError, mistToSui, parseMppSuiChallenge, parseSuiRpcTx, payWithMpp, preflightFail, preflightPay, preflightSend, preflightSwap, rawToStable, rawToUsdc, refineLendingLabel, resolveSymbol, resolveTokenType, stableToRaw, suiToMist, toBase64, truncateAddress, usdcToRaw, validateAddress };
1174
1291
  //# sourceMappingURL=browser.js.map
1175
1292
  //# sourceMappingURL=browser.js.map