@t2000/sdk 10.25.0 → 10.26.0
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 +18 -9
- 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 +18 -9
- package/dist/browser.js.map +1 -1
- package/dist/{commerce-B_eH6fvR.d.cts → commerce-DOKu1FYI.d.cts} +45 -1
- package/dist/{commerce-B_eH6fvR.d.ts → commerce-DOKu1FYI.d.ts} +45 -1
- package/dist/index.cjs +100 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -3
- package/dist/index.d.ts +19 -3
- package/dist/index.js +99 -15
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -938,6 +938,50 @@ declare function preflightPay(input: {
|
|
|
938
938
|
url: string;
|
|
939
939
|
maxPrice?: number;
|
|
940
940
|
}): PreflightResult;
|
|
941
|
+
/**
|
|
942
|
+
* What a paid call WOULD cost, without paying (S.919). Every branch mirrors
|
|
943
|
+
* a `payWithX402` outcome so the probe can never promise something the pay
|
|
944
|
+
* path then refuses — one dialect story, not two.
|
|
945
|
+
*/
|
|
946
|
+
type X402Probe = {
|
|
947
|
+
kind: 'free';
|
|
948
|
+
status: number;
|
|
949
|
+
note: string;
|
|
950
|
+
} | {
|
|
951
|
+
kind: 'payable';
|
|
952
|
+
priceUsdc: number;
|
|
953
|
+
asset: string;
|
|
954
|
+
payTo: string;
|
|
955
|
+
network: string;
|
|
956
|
+
} | {
|
|
957
|
+
kind: 'escrow';
|
|
958
|
+
priceUsdc: number;
|
|
959
|
+
payTo: string;
|
|
960
|
+
note: string;
|
|
961
|
+
} | {
|
|
962
|
+
kind: 'unsupported';
|
|
963
|
+
reason: string;
|
|
964
|
+
note: string;
|
|
965
|
+
} | {
|
|
966
|
+
kind: 'incomplete';
|
|
967
|
+
reason: string;
|
|
968
|
+
note: string;
|
|
969
|
+
} | {
|
|
970
|
+
kind: 'not-x402';
|
|
971
|
+
status: number;
|
|
972
|
+
note: string;
|
|
973
|
+
};
|
|
974
|
+
/**
|
|
975
|
+
* READ-ONLY x402 probe: issue the same request `pay()` would, read the 402,
|
|
976
|
+
* and report the terms. Never signs, never spends, never throws on a
|
|
977
|
+
* non-payable answer — an unpayable endpoint is information, not a failure.
|
|
978
|
+
* (Invalid input still throws, exactly as `pay()` would, so a caller can't
|
|
979
|
+
* probe a URL that could never be paid.)
|
|
980
|
+
*/
|
|
981
|
+
declare function probeX402(args: {
|
|
982
|
+
network: string;
|
|
983
|
+
options: PayOptions;
|
|
984
|
+
}): Promise<X402Probe>;
|
|
941
985
|
declare function payWithX402(args: {
|
|
942
986
|
signer: TransactionSigner;
|
|
943
987
|
client: SuiGrpcClient;
|
|
@@ -1556,4 +1600,4 @@ declare function putJobSpec(base: string, content: string): Promise<string>;
|
|
|
1556
1600
|
* the store is untrusted; the chain hash is the authority). */
|
|
1557
1601
|
declare function getJobSpec(base: string, hash: string): Promise<string>;
|
|
1558
1602
|
|
|
1559
|
-
export { type T2000ErrorData as $, A2A_ESCROW_FEE_CONFIG_ID as A, type BalanceResponse as B, CLOCK_ID as C, DEFAULT_ACTIVITY_REPORT_URL as D, ETH_TYPE as E, SUI_TYPE as F, GAS_RESERVE_MIN as G, SUPPORTED_ASSETS as H, IKA_TYPE as I, JOB_STATES as J, KNOWN_TARGETS as K, LABEL_PATTERNS as L, MANIFEST_TYPE as M, NAVX_TYPE as N, OVERLAY_FEE_RATE as O, PREFLIGHT_MAX_AMOUNT as P, type SendResult as Q, type ServiceListing as R, STABLE_ASSETS as S, type SimulationResult as T, type StableAsset as U, type SuiHolding as V, type SuiRpcTxBlock as W, type SupportedAsset as X, type SwapRouteResult as Y, T2000Error as Z, type T2000ErrorCode as _, A2A_ESCROW_PACKAGE_ID as a, suiToMist as a$, T2000_OVERLAY_FEE_WALLET as a0, TOKEN_MAP as a1, type TransactionLeg as a2, type TransactionRecord as a3, type TransactionSigner as a4, type TxDirection as a5, USDC_DECIMALS as a6, USDC_TYPE as a7, USDE_TYPE as a8, USDSUI_TYPE as a9, formatAssetAmount as aA, formatSui as aB, formatUsd as aC, getDecimals as aD, getDecimalsForCoinType as aE, getJob as aF, getJobSpec as aG, jobActionsFor as aH, listServices as aI, mapMoveAbortCode as aJ, mapWalletError as aK, mistToSui as aL, parseSuiRpcTx as aM, payWithX402 as aN, preflightCreateJob as aO, preflightFail as aP, preflightPay as aQ, preflightSend as aR, preflightSwap as aS, putJobSpec as aT, rawToStable as aU, rawToUsdc as aV, refineLendingLabel as aW, reportX402Activity as aX, resolveSymbol as aY, resolveTokenType as aZ, stableToRaw as a_, USDT_TYPE as aa, WAL_TYPE as ab, WBTC_TYPE as ac, type X402ActivityPayload as ad, type ZkLoginProof as ae, ZkLoginSigner as af, buildCreateJobTx as ag, buildDeliverJobTx as ah, buildRefundJobTx as ai, buildRejectJobTx as aj, buildReleaseJobTx as ak, buildSendTx as al, buildSwapTx as am, checkPositiveAmount as an, checkSuiAddress as ao, classifyAction as ap, classifyLabel as aq, classifyTransaction as ar, executeTx as as, extractAllUserLegs as at, extractTransferDetails as au, extractTxCommands as av, extractTxSender as aw, fallbackLabel as ax, fetchService as ay, findSwapRoute as az, type ActivityReportConfig as b, truncateAddress as b0, usdcToRaw as b1, validateAddress as b2, verifyJobForSeller as b3, type T2000Options as b4, type
|
|
1603
|
+
export { type T2000ErrorData as $, A2A_ESCROW_FEE_CONFIG_ID as A, type BalanceResponse as B, CLOCK_ID as C, DEFAULT_ACTIVITY_REPORT_URL as D, ETH_TYPE as E, SUI_TYPE as F, GAS_RESERVE_MIN as G, SUPPORTED_ASSETS as H, IKA_TYPE as I, JOB_STATES as J, KNOWN_TARGETS as K, LABEL_PATTERNS as L, MANIFEST_TYPE as M, NAVX_TYPE as N, OVERLAY_FEE_RATE as O, PREFLIGHT_MAX_AMOUNT as P, type SendResult as Q, type ServiceListing as R, STABLE_ASSETS as S, type SimulationResult as T, type StableAsset as U, type SuiHolding as V, type SuiRpcTxBlock as W, type SupportedAsset as X, type SwapRouteResult as Y, T2000Error as Z, type T2000ErrorCode as _, A2A_ESCROW_PACKAGE_ID as a, suiToMist as a$, T2000_OVERLAY_FEE_WALLET as a0, TOKEN_MAP as a1, type TransactionLeg as a2, type TransactionRecord as a3, type TransactionSigner as a4, type TxDirection as a5, USDC_DECIMALS as a6, USDC_TYPE as a7, USDE_TYPE as a8, USDSUI_TYPE as a9, formatAssetAmount as aA, formatSui as aB, formatUsd as aC, getDecimals as aD, getDecimalsForCoinType as aE, getJob as aF, getJobSpec as aG, jobActionsFor as aH, listServices as aI, mapMoveAbortCode as aJ, mapWalletError as aK, mistToSui as aL, parseSuiRpcTx as aM, payWithX402 as aN, preflightCreateJob as aO, preflightFail as aP, preflightPay as aQ, preflightSend as aR, preflightSwap as aS, putJobSpec as aT, rawToStable as aU, rawToUsdc as aV, refineLendingLabel as aW, reportX402Activity as aX, resolveSymbol as aY, resolveTokenType as aZ, stableToRaw as a_, USDT_TYPE as aa, WAL_TYPE as ab, WBTC_TYPE as ac, type X402ActivityPayload as ad, type ZkLoginProof as ae, ZkLoginSigner as af, buildCreateJobTx as ag, buildDeliverJobTx as ah, buildRefundJobTx as ai, buildRejectJobTx as aj, buildReleaseJobTx as ak, buildSendTx as al, buildSwapTx as am, checkPositiveAmount as an, checkSuiAddress as ao, classifyAction as ap, classifyLabel as aq, classifyTransaction as ar, executeTx as as, extractAllUserLegs as at, extractTransferDetails as au, extractTxCommands as av, extractTxSender as aw, fallbackLabel as ax, fetchService as ay, findSwapRoute as az, type ActivityReportConfig as b, truncateAddress as b0, usdcToRaw as b1, validateAddress as b2, verifyJobForSeller as b3, type T2000Options as b4, type X402Probe as b5, type SerializedCetusRoute as b6, type SwapResult as b7, type SwapQuoteResult as b8, type PaymentRequest as b9, isInRegistry as bA, normalizeAsset as bB, normalizeCoinType as bC, probeX402 as bD, queryHistory as bE, queryTransaction as bF, selectAndSplitCoin as bG, selectSuiCoin as bH, serializeCetusRoute as bI, simulateTransaction as bJ, throwIfSimulationFailed as bK, verifyCetusRouteCoinMatch as bL, type SuiCoreClient as ba, type SponsoredCoinMergeCache as bb, type SendableAsset as bc, CETUS_USDC_SUI_POOL as bd, type CoinPage as be, DEFAULT_GRPC_URL as bf, GASLESS_MIN_STABLE_AMOUNT as bg, GASLESS_STABLE_TYPES as bh, OPERATION_ASSETS as bi, type Operation as bj, SENDABLE_ASSETS as bk, type SelectAndSplitResult as bl, type SerializedCetusRoutePath as bm, type SerializedRouterDataV3 as bn, addSendToTx as bo, addSwapToTx as bp, assertAllowedAsset as bq, assertBuyerRequirements as br, buildDeclineJobTx as bs, deserializeCetusRoute as bt, fetchAllCoins as bu, getCoinMeta as bv, getSuiClient as bw, getSuiGrpcClient as bx, isAllowedAsset as by, isCetusRouteFresh as bz, COIN_REGISTRY as c, type ClassifyBalanceChange as d, type ClassifyResult as e, type CoinMeta as f, DEFAULT_COMMERCE_API_BASE as g, DEFAULT_NETWORK as h, type DepositInfo as i, type ExtractedTransfer as j, type Job as k, type JobState as l, type JobTerms as m, type JobVerification as n, KeypairSigner as o, LOFI_TYPE as p, MAX_DELIVER_HORIZON_MS as q, MAX_JOB_USDC as r, MAX_REVIEW_WINDOW_MS as s, MIST_PER_SUI as t, type OverlayFeeConfig as u, PREFLIGHT_OK as v, type PayOptions as w, type PayResult as x, type PreflightResult as y, SUI_DECIMALS as z };
|
|
@@ -938,6 +938,50 @@ declare function preflightPay(input: {
|
|
|
938
938
|
url: string;
|
|
939
939
|
maxPrice?: number;
|
|
940
940
|
}): PreflightResult;
|
|
941
|
+
/**
|
|
942
|
+
* What a paid call WOULD cost, without paying (S.919). Every branch mirrors
|
|
943
|
+
* a `payWithX402` outcome so the probe can never promise something the pay
|
|
944
|
+
* path then refuses — one dialect story, not two.
|
|
945
|
+
*/
|
|
946
|
+
type X402Probe = {
|
|
947
|
+
kind: 'free';
|
|
948
|
+
status: number;
|
|
949
|
+
note: string;
|
|
950
|
+
} | {
|
|
951
|
+
kind: 'payable';
|
|
952
|
+
priceUsdc: number;
|
|
953
|
+
asset: string;
|
|
954
|
+
payTo: string;
|
|
955
|
+
network: string;
|
|
956
|
+
} | {
|
|
957
|
+
kind: 'escrow';
|
|
958
|
+
priceUsdc: number;
|
|
959
|
+
payTo: string;
|
|
960
|
+
note: string;
|
|
961
|
+
} | {
|
|
962
|
+
kind: 'unsupported';
|
|
963
|
+
reason: string;
|
|
964
|
+
note: string;
|
|
965
|
+
} | {
|
|
966
|
+
kind: 'incomplete';
|
|
967
|
+
reason: string;
|
|
968
|
+
note: string;
|
|
969
|
+
} | {
|
|
970
|
+
kind: 'not-x402';
|
|
971
|
+
status: number;
|
|
972
|
+
note: string;
|
|
973
|
+
};
|
|
974
|
+
/**
|
|
975
|
+
* READ-ONLY x402 probe: issue the same request `pay()` would, read the 402,
|
|
976
|
+
* and report the terms. Never signs, never spends, never throws on a
|
|
977
|
+
* non-payable answer — an unpayable endpoint is information, not a failure.
|
|
978
|
+
* (Invalid input still throws, exactly as `pay()` would, so a caller can't
|
|
979
|
+
* probe a URL that could never be paid.)
|
|
980
|
+
*/
|
|
981
|
+
declare function probeX402(args: {
|
|
982
|
+
network: string;
|
|
983
|
+
options: PayOptions;
|
|
984
|
+
}): Promise<X402Probe>;
|
|
941
985
|
declare function payWithX402(args: {
|
|
942
986
|
signer: TransactionSigner;
|
|
943
987
|
client: SuiGrpcClient;
|
|
@@ -1556,4 +1600,4 @@ declare function putJobSpec(base: string, content: string): Promise<string>;
|
|
|
1556
1600
|
* the store is untrusted; the chain hash is the authority). */
|
|
1557
1601
|
declare function getJobSpec(base: string, hash: string): Promise<string>;
|
|
1558
1602
|
|
|
1559
|
-
export { type T2000ErrorData as $, A2A_ESCROW_FEE_CONFIG_ID as A, type BalanceResponse as B, CLOCK_ID as C, DEFAULT_ACTIVITY_REPORT_URL as D, ETH_TYPE as E, SUI_TYPE as F, GAS_RESERVE_MIN as G, SUPPORTED_ASSETS as H, IKA_TYPE as I, JOB_STATES as J, KNOWN_TARGETS as K, LABEL_PATTERNS as L, MANIFEST_TYPE as M, NAVX_TYPE as N, OVERLAY_FEE_RATE as O, PREFLIGHT_MAX_AMOUNT as P, type SendResult as Q, type ServiceListing as R, STABLE_ASSETS as S, type SimulationResult as T, type StableAsset as U, type SuiHolding as V, type SuiRpcTxBlock as W, type SupportedAsset as X, type SwapRouteResult as Y, T2000Error as Z, type T2000ErrorCode as _, A2A_ESCROW_PACKAGE_ID as a, suiToMist as a$, T2000_OVERLAY_FEE_WALLET as a0, TOKEN_MAP as a1, type TransactionLeg as a2, type TransactionRecord as a3, type TransactionSigner as a4, type TxDirection as a5, USDC_DECIMALS as a6, USDC_TYPE as a7, USDE_TYPE as a8, USDSUI_TYPE as a9, formatAssetAmount as aA, formatSui as aB, formatUsd as aC, getDecimals as aD, getDecimalsForCoinType as aE, getJob as aF, getJobSpec as aG, jobActionsFor as aH, listServices as aI, mapMoveAbortCode as aJ, mapWalletError as aK, mistToSui as aL, parseSuiRpcTx as aM, payWithX402 as aN, preflightCreateJob as aO, preflightFail as aP, preflightPay as aQ, preflightSend as aR, preflightSwap as aS, putJobSpec as aT, rawToStable as aU, rawToUsdc as aV, refineLendingLabel as aW, reportX402Activity as aX, resolveSymbol as aY, resolveTokenType as aZ, stableToRaw as a_, USDT_TYPE as aa, WAL_TYPE as ab, WBTC_TYPE as ac, type X402ActivityPayload as ad, type ZkLoginProof as ae, ZkLoginSigner as af, buildCreateJobTx as ag, buildDeliverJobTx as ah, buildRefundJobTx as ai, buildRejectJobTx as aj, buildReleaseJobTx as ak, buildSendTx as al, buildSwapTx as am, checkPositiveAmount as an, checkSuiAddress as ao, classifyAction as ap, classifyLabel as aq, classifyTransaction as ar, executeTx as as, extractAllUserLegs as at, extractTransferDetails as au, extractTxCommands as av, extractTxSender as aw, fallbackLabel as ax, fetchService as ay, findSwapRoute as az, type ActivityReportConfig as b, truncateAddress as b0, usdcToRaw as b1, validateAddress as b2, verifyJobForSeller as b3, type T2000Options as b4, type
|
|
1603
|
+
export { type T2000ErrorData as $, A2A_ESCROW_FEE_CONFIG_ID as A, type BalanceResponse as B, CLOCK_ID as C, DEFAULT_ACTIVITY_REPORT_URL as D, ETH_TYPE as E, SUI_TYPE as F, GAS_RESERVE_MIN as G, SUPPORTED_ASSETS as H, IKA_TYPE as I, JOB_STATES as J, KNOWN_TARGETS as K, LABEL_PATTERNS as L, MANIFEST_TYPE as M, NAVX_TYPE as N, OVERLAY_FEE_RATE as O, PREFLIGHT_MAX_AMOUNT as P, type SendResult as Q, type ServiceListing as R, STABLE_ASSETS as S, type SimulationResult as T, type StableAsset as U, type SuiHolding as V, type SuiRpcTxBlock as W, type SupportedAsset as X, type SwapRouteResult as Y, T2000Error as Z, type T2000ErrorCode as _, A2A_ESCROW_PACKAGE_ID as a, suiToMist as a$, T2000_OVERLAY_FEE_WALLET as a0, TOKEN_MAP as a1, type TransactionLeg as a2, type TransactionRecord as a3, type TransactionSigner as a4, type TxDirection as a5, USDC_DECIMALS as a6, USDC_TYPE as a7, USDE_TYPE as a8, USDSUI_TYPE as a9, formatAssetAmount as aA, formatSui as aB, formatUsd as aC, getDecimals as aD, getDecimalsForCoinType as aE, getJob as aF, getJobSpec as aG, jobActionsFor as aH, listServices as aI, mapMoveAbortCode as aJ, mapWalletError as aK, mistToSui as aL, parseSuiRpcTx as aM, payWithX402 as aN, preflightCreateJob as aO, preflightFail as aP, preflightPay as aQ, preflightSend as aR, preflightSwap as aS, putJobSpec as aT, rawToStable as aU, rawToUsdc as aV, refineLendingLabel as aW, reportX402Activity as aX, resolveSymbol as aY, resolveTokenType as aZ, stableToRaw as a_, USDT_TYPE as aa, WAL_TYPE as ab, WBTC_TYPE as ac, type X402ActivityPayload as ad, type ZkLoginProof as ae, ZkLoginSigner as af, buildCreateJobTx as ag, buildDeliverJobTx as ah, buildRefundJobTx as ai, buildRejectJobTx as aj, buildReleaseJobTx as ak, buildSendTx as al, buildSwapTx as am, checkPositiveAmount as an, checkSuiAddress as ao, classifyAction as ap, classifyLabel as aq, classifyTransaction as ar, executeTx as as, extractAllUserLegs as at, extractTransferDetails as au, extractTxCommands as av, extractTxSender as aw, fallbackLabel as ax, fetchService as ay, findSwapRoute as az, type ActivityReportConfig as b, truncateAddress as b0, usdcToRaw as b1, validateAddress as b2, verifyJobForSeller as b3, type T2000Options as b4, type X402Probe as b5, type SerializedCetusRoute as b6, type SwapResult as b7, type SwapQuoteResult as b8, type PaymentRequest as b9, isInRegistry as bA, normalizeAsset as bB, normalizeCoinType as bC, probeX402 as bD, queryHistory as bE, queryTransaction as bF, selectAndSplitCoin as bG, selectSuiCoin as bH, serializeCetusRoute as bI, simulateTransaction as bJ, throwIfSimulationFailed as bK, verifyCetusRouteCoinMatch as bL, type SuiCoreClient as ba, type SponsoredCoinMergeCache as bb, type SendableAsset as bc, CETUS_USDC_SUI_POOL as bd, type CoinPage as be, DEFAULT_GRPC_URL as bf, GASLESS_MIN_STABLE_AMOUNT as bg, GASLESS_STABLE_TYPES as bh, OPERATION_ASSETS as bi, type Operation as bj, SENDABLE_ASSETS as bk, type SelectAndSplitResult as bl, type SerializedCetusRoutePath as bm, type SerializedRouterDataV3 as bn, addSendToTx as bo, addSwapToTx as bp, assertAllowedAsset as bq, assertBuyerRequirements as br, buildDeclineJobTx as bs, deserializeCetusRoute as bt, fetchAllCoins as bu, getCoinMeta as bv, getSuiClient as bw, getSuiGrpcClient as bx, isAllowedAsset as by, isCetusRouteFresh as bz, COIN_REGISTRY as c, type ClassifyBalanceChange as d, type ClassifyResult as e, type CoinMeta as f, DEFAULT_COMMERCE_API_BASE as g, DEFAULT_NETWORK as h, type DepositInfo as i, type ExtractedTransfer as j, type Job as k, type JobState as l, type JobTerms as m, type JobVerification as n, KeypairSigner as o, LOFI_TYPE as p, MAX_DELIVER_HORIZON_MS as q, MAX_JOB_USDC as r, MAX_REVIEW_WINDOW_MS as s, MIST_PER_SUI as t, type OverlayFeeConfig as u, PREFLIGHT_OK as v, type PayOptions as w, type PayResult as x, type PreflightResult as y, SUI_DECIMALS as z };
|
package/dist/index.cjs
CHANGED
|
@@ -1140,11 +1140,65 @@ function preflightPay(input) {
|
|
|
1140
1140
|
}
|
|
1141
1141
|
return exports.PREFLIGHT_OK;
|
|
1142
1142
|
}
|
|
1143
|
-
async function
|
|
1144
|
-
const {
|
|
1145
|
-
|
|
1146
|
-
const pf = preflightPay({ url: options.url, maxPrice: options.maxPrice });
|
|
1143
|
+
async function probeX402(args) {
|
|
1144
|
+
const { network } = args;
|
|
1145
|
+
const pf = preflightPay({ url: args.options.url, maxPrice: args.options.maxPrice });
|
|
1147
1146
|
if (!pf.valid) throw new exports.T2000Error(pf.code, pf.error);
|
|
1147
|
+
const { reqInit } = normalizePayRequest(args.options);
|
|
1148
|
+
const probe = await fetch(args.options.url, reqInit);
|
|
1149
|
+
if (probe.status !== 402) {
|
|
1150
|
+
return {
|
|
1151
|
+
kind: "free",
|
|
1152
|
+
status: probe.status,
|
|
1153
|
+
note: "No payment required \u2014 this endpoint served without a 402."
|
|
1154
|
+
};
|
|
1155
|
+
}
|
|
1156
|
+
const pick = await pickSuiExactRequirements(probe, network);
|
|
1157
|
+
if (pick.kind === "payable") {
|
|
1158
|
+
const requirements = pick.requirements;
|
|
1159
|
+
const priceUsdc = atomicToHuman(
|
|
1160
|
+
BigInt(requirements.maxAmountRequired),
|
|
1161
|
+
await assetDecimals(requirements.asset)
|
|
1162
|
+
);
|
|
1163
|
+
const { isX402EscrowRequirements } = await import('@t2000/sui-x402');
|
|
1164
|
+
if (isX402EscrowRequirements(requirements)) {
|
|
1165
|
+
return {
|
|
1166
|
+
kind: "escrow",
|
|
1167
|
+
priceUsdc,
|
|
1168
|
+
payTo: requirements.payTo,
|
|
1169
|
+
note: "This endpoint sells deliverable work through on-chain escrow, not an instant call. Hire it as a job instead \u2014 funds lock in a Job object and release on delivery."
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
return {
|
|
1173
|
+
kind: "payable",
|
|
1174
|
+
priceUsdc,
|
|
1175
|
+
asset: requirements.asset,
|
|
1176
|
+
payTo: requirements.payTo,
|
|
1177
|
+
network
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
if (hasPaymentAuthenticateHeader(probe)) {
|
|
1181
|
+
return {
|
|
1182
|
+
kind: "unsupported",
|
|
1183
|
+
reason: "header-only-402-unsupported",
|
|
1184
|
+
note: "This seller answered a header-only 402 (WWW-Authenticate: Payment) with no payable x402 accepts[] envelope. That dialect is no longer supported \u2014 the seller must offer x402 (e.g. @t2000/serve emits it)."
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
if (pick.kind === "incomplete") {
|
|
1188
|
+
return {
|
|
1189
|
+
kind: "incomplete",
|
|
1190
|
+
reason: "incomplete-x402-accepts",
|
|
1191
|
+
note: "Seller's x402 challenge is incomplete (missing extra.suimpp) \u2014 the 402 advertises an exact/sui entry but carries no settlement challenge to bind a payment to."
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1194
|
+
return {
|
|
1195
|
+
kind: "not-x402",
|
|
1196
|
+
status: probe.status,
|
|
1197
|
+
note: `Endpoint returned 402 without an x402 'exact' / sui:${network} requirement in the body. Nothing this SDK can pay.`
|
|
1198
|
+
};
|
|
1199
|
+
}
|
|
1200
|
+
function normalizePayRequest(input) {
|
|
1201
|
+
let options = input;
|
|
1148
1202
|
const method = (options.method ?? "GET").toUpperCase();
|
|
1149
1203
|
const canHaveBody = method !== "GET" && method !== "HEAD";
|
|
1150
1204
|
if (canHaveBody && typeof options.body === "string" && isJsonText(options.body) && !hasContentType(options.headers)) {
|
|
@@ -1153,11 +1207,23 @@ async function payWithX402(args) {
|
|
|
1153
1207
|
headers: { ...options.headers ?? {}, "content-type": "application/json" }
|
|
1154
1208
|
};
|
|
1155
1209
|
}
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1210
|
+
return {
|
|
1211
|
+
options,
|
|
1212
|
+
reqInit: {
|
|
1213
|
+
method,
|
|
1214
|
+
headers: options.headers,
|
|
1215
|
+
body: canHaveBody ? options.body : void 0
|
|
1216
|
+
}
|
|
1160
1217
|
};
|
|
1218
|
+
}
|
|
1219
|
+
async function payWithX402(args) {
|
|
1220
|
+
const { signer, client } = args;
|
|
1221
|
+
let options = args.options;
|
|
1222
|
+
const pf = preflightPay({ url: options.url, maxPrice: options.maxPrice });
|
|
1223
|
+
if (!pf.valid) throw new exports.T2000Error(pf.code, pf.error);
|
|
1224
|
+
const normalized = normalizePayRequest(options);
|
|
1225
|
+
options = normalized.options;
|
|
1226
|
+
const reqInit = normalized.reqInit;
|
|
1161
1227
|
const probe = await fetch(options.url, reqInit);
|
|
1162
1228
|
if (probe.status !== 402) {
|
|
1163
1229
|
return finalize(probe, { paid: false });
|
|
@@ -1942,10 +2008,19 @@ var REVERSE_NAME_QUERY = `query ReverseSuins($address: SuiAddress!) {
|
|
|
1942
2008
|
var SUI_ADDRESS_REGEX = /^0x[a-fA-F0-9]{1,64}$/i;
|
|
1943
2009
|
var SUI_ADDRESS_STRICT_REGEX = /^0x[a-fA-F0-9]{64}$/i;
|
|
1944
2010
|
var SUINS_NAME_REGEX = /^[a-z0-9-]+(\.[a-z0-9-]+)*\.sui$/;
|
|
2011
|
+
var AUDRIC_HANDLE_RE = /^([a-z0-9-]+)@audric$/i;
|
|
2012
|
+
function canonicalizeRecipientInput(raw) {
|
|
2013
|
+
const trimmed = raw.trim();
|
|
2014
|
+
const m = AUDRIC_HANDLE_RE.exec(trimmed);
|
|
2015
|
+
if (m) {
|
|
2016
|
+
return `${m[1].toLowerCase()}.audric.sui`;
|
|
2017
|
+
}
|
|
2018
|
+
return trimmed;
|
|
2019
|
+
}
|
|
1945
2020
|
var InvalidAddressError = class extends Error {
|
|
1946
2021
|
constructor(raw) {
|
|
1947
2022
|
super(
|
|
1948
|
-
`"${raw}" isn't a valid Sui address or SuiNS name. Pass a 0x-prefixed hex address (e.g. 0x40cd\u20263e62)
|
|
2023
|
+
`"${raw}" isn't a valid Sui address or SuiNS name. Pass a 0x-prefixed hex address (e.g. 0x40cd\u20263e62), a SuiNS name ending in .sui (e.g. alex.sui), or a Passport handle (e.g. alex@audric).`
|
|
1949
2024
|
);
|
|
1950
2025
|
this.raw = raw;
|
|
1951
2026
|
this.name = "InvalidAddressError";
|
|
@@ -1969,10 +2044,10 @@ var SuinsRpcError = class extends Error {
|
|
|
1969
2044
|
};
|
|
1970
2045
|
function looksLikeSuiNs(value) {
|
|
1971
2046
|
if (!value) return false;
|
|
1972
|
-
return SUINS_NAME_REGEX.test(value
|
|
2047
|
+
return SUINS_NAME_REGEX.test(canonicalizeRecipientInput(value).toLowerCase());
|
|
1973
2048
|
}
|
|
1974
2049
|
async function resolveSuinsViaRpc(rawName, ctx = {}) {
|
|
1975
|
-
const name = rawName
|
|
2050
|
+
const name = canonicalizeRecipientInput(rawName).toLowerCase();
|
|
1976
2051
|
if (!SUINS_NAME_REGEX.test(name)) {
|
|
1977
2052
|
throw new InvalidAddressError(rawName);
|
|
1978
2053
|
}
|
|
@@ -2017,7 +2092,7 @@ async function resolveAddressToSuinsViaRpc(rawAddress, ctx = {}) {
|
|
|
2017
2092
|
return domain ? [domain] : [];
|
|
2018
2093
|
}
|
|
2019
2094
|
async function normalizeAddressInput(value, ctx = {}) {
|
|
2020
|
-
const trimmed = value
|
|
2095
|
+
const trimmed = canonicalizeRecipientInput(value);
|
|
2021
2096
|
if (SUI_ADDRESS_REGEX.test(trimmed)) {
|
|
2022
2097
|
return { address: trimmed.toLowerCase(), suinsName: null, raw: value };
|
|
2023
2098
|
}
|
|
@@ -2790,6 +2865,15 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2790
2865
|
return this._signer;
|
|
2791
2866
|
}
|
|
2792
2867
|
// -- MPP Payments --
|
|
2868
|
+
/**
|
|
2869
|
+
* READ-ONLY price probe for an x402 endpoint (S.919). Reports what `pay()`
|
|
2870
|
+
* would cost without signing or spending, so a caller (Connect's
|
|
2871
|
+
* `t2000_pay_probe`, the CLI, a UI) can show terms before committing.
|
|
2872
|
+
* No limit gate: nothing moves.
|
|
2873
|
+
*/
|
|
2874
|
+
async payProbe(options) {
|
|
2875
|
+
return await probeX402({ network: this.client.network, options });
|
|
2876
|
+
}
|
|
2793
2877
|
async pay(options) {
|
|
2794
2878
|
this.limits.assert({ operation: "pay", amountUsd: options.maxPrice ?? 0, force: options.force });
|
|
2795
2879
|
const result = await payWithX402({ signer: this._signer, client: this.client, options });
|
|
@@ -3080,7 +3164,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
3080
3164
|
* with the live execute path (never resolve the same input two ways).
|
|
3081
3165
|
*/
|
|
3082
3166
|
async resolveRecipient(input) {
|
|
3083
|
-
const trimmed = input
|
|
3167
|
+
const trimmed = canonicalizeRecipientInput(input);
|
|
3084
3168
|
if (SUI_ADDRESS_REGEX.test(trimmed)) {
|
|
3085
3169
|
return { address: trimmed.toLowerCase() };
|
|
3086
3170
|
}
|
|
@@ -3104,7 +3188,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
3104
3188
|
}
|
|
3105
3189
|
throw new exports.T2000Error(
|
|
3106
3190
|
"INVALID_ADDRESS",
|
|
3107
|
-
`Cannot resolve recipient "${input}". Provide a 0x address
|
|
3191
|
+
`Cannot resolve recipient "${input}". Provide a 0x address, a .sui name, or a Passport handle (name@audric).`
|
|
3108
3192
|
);
|
|
3109
3193
|
}
|
|
3110
3194
|
async balance() {
|
|
@@ -4277,6 +4361,7 @@ exports.buildRevokeLeafTx = buildRevokeLeafTx;
|
|
|
4277
4361
|
exports.buildSendTx = buildSendTx;
|
|
4278
4362
|
exports.buildSwapTx = buildSwapTx;
|
|
4279
4363
|
exports.cancelOpenJob = cancelOpenJob;
|
|
4364
|
+
exports.canonicalizeRecipientInput = canonicalizeRecipientInput;
|
|
4280
4365
|
exports.chatCompletion = chatCompletion;
|
|
4281
4366
|
exports.chatCompletionStream = chatCompletionStream;
|
|
4282
4367
|
exports.checkPositiveAmount = checkPositiveAmount;
|
|
@@ -4345,6 +4430,7 @@ exports.preflightFail = preflightFail;
|
|
|
4345
4430
|
exports.preflightPay = preflightPay;
|
|
4346
4431
|
exports.preflightSend = preflightSend;
|
|
4347
4432
|
exports.preflightSwap = preflightSwap;
|
|
4433
|
+
exports.probeX402 = probeX402;
|
|
4348
4434
|
exports.putJobSpec = putJobSpec;
|
|
4349
4435
|
exports.queryBalance = queryBalance;
|
|
4350
4436
|
exports.queryHistory = queryHistory;
|