@t2000/sdk 10.20.2 → 10.21.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 +10 -93
- 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 +11 -93
- package/dist/browser.js.map +1 -1
- package/dist/{commerce-BkSSPS1w.d.cts → commerce-sBVg9pVH.d.cts} +11 -29
- package/dist/{commerce-BkSSPS1w.d.ts → commerce-sBVg9pVH.d.ts} +11 -29
- package/dist/index.cjs +10 -95
- 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 +11 -95
- package/dist/index.js.map +1 -1
- package/package.json +2 -4
|
@@ -15,8 +15,8 @@ interface TransactionSigner {
|
|
|
15
15
|
signature: string;
|
|
16
16
|
}>;
|
|
17
17
|
/**
|
|
18
|
-
* Sign an arbitrary personal message
|
|
19
|
-
*
|
|
18
|
+
* Sign an arbitrary personal message — used for off-chain proofs bound to
|
|
19
|
+
* the wallet (e.g. signed job-review submissions).
|
|
20
20
|
*/
|
|
21
21
|
signPersonalMessage(messageBytes: Uint8Array): Promise<{
|
|
22
22
|
signature: string;
|
|
@@ -24,13 +24,9 @@ interface TransactionSigner {
|
|
|
24
24
|
}>;
|
|
25
25
|
/**
|
|
26
26
|
* Signature scheme marker. zkLogin personal-message signatures are ZK
|
|
27
|
-
* constructs
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* (live finding, JMPR 2026-07-17: charged, no delivery). `payWithMpp`
|
|
31
|
-
* fails closed on `'zklogin'` + header-only 402 BEFORE any money moves.
|
|
32
|
-
* Optional so external signer impls keep compiling; undefined = keypair
|
|
33
|
-
* semantics.
|
|
27
|
+
* constructs only Sui-aware verifiers can check — hosts use this to gate
|
|
28
|
+
* flows that depend on seller-side signature verification. Optional so
|
|
29
|
+
* external signer impls keep compiling; undefined = keypair semantics.
|
|
34
30
|
*/
|
|
35
31
|
readonly kind?: 'keypair' | 'zklogin';
|
|
36
32
|
}
|
|
@@ -899,13 +895,12 @@ interface PayResult {
|
|
|
899
895
|
body: unknown;
|
|
900
896
|
paid: boolean;
|
|
901
897
|
/**
|
|
902
|
-
* Which payment dialect settled the call
|
|
903
|
-
*
|
|
904
|
-
*
|
|
905
|
-
*
|
|
906
|
-
* SUIMPP_X402_SCHEME.md.
|
|
898
|
+
* Which payment dialect settled the call — always `'x402'` (sign-then-
|
|
899
|
+
* settle `sui-exact`; client signs, gateway settles) since the MPP header
|
|
900
|
+
* dialect was removed 2026-08-03. Undefined when nothing was paid
|
|
901
|
+
* (free/cached endpoint). See SUIMPP_X402_SCHEME.md.
|
|
907
902
|
*/
|
|
908
|
-
dialect?: 'x402'
|
|
903
|
+
dialect?: 'x402';
|
|
909
904
|
cost?: number;
|
|
910
905
|
/**
|
|
911
906
|
* SUI gas cost actually paid on chain. Zero for gasless payments —
|
|
@@ -937,19 +932,6 @@ declare function payWithMpp(args: {
|
|
|
937
932
|
client: SuiGrpcClient;
|
|
938
933
|
options: PayOptions;
|
|
939
934
|
}): Promise<PayResult>;
|
|
940
|
-
/**
|
|
941
|
-
* Parse the MPP header dialect from a 402 response: the
|
|
942
|
-
* `WWW-Authenticate: Payment …` challenge(s), looking for `method="sui"`.
|
|
943
|
-
* Returns the decoded `{ amount, currency, recipient }` request (amount is a
|
|
944
|
-
* decimal string, e.g. "0.02") or `undefined` when the response carries no
|
|
945
|
-
* sui challenge. Exported for the CLI's `t2 pay --estimate`.
|
|
946
|
-
*/
|
|
947
|
-
declare function parseMppSuiChallenge(response: Response): Promise<{
|
|
948
|
-
amount: string;
|
|
949
|
-
currency: string;
|
|
950
|
-
recipient: string;
|
|
951
|
-
description?: string;
|
|
952
|
-
} | undefined>;
|
|
953
935
|
|
|
954
936
|
type SuiTransactionEffects = SuiClientTypes.TransactionEffects;
|
|
955
937
|
type BuildClient = NonNullable<Parameters<Transaction['build']>[0]>['client'];
|
|
@@ -1543,4 +1525,4 @@ declare function putJobSpec(base: string, content: string): Promise<string>;
|
|
|
1543
1525
|
* the store is untrusted; the chain hash is the authority). */
|
|
1544
1526
|
declare function getJobSpec(base: string, hash: string): Promise<string>;
|
|
1545
1527
|
|
|
1546
|
-
export { TOKEN_MAP as $, A2A_ESCROW_FEE_CONFIG_ID as A, type BalanceResponse as B, CLOCK_ID as C, DEFAULT_COMMERCE_API_BASE as D, ETH_TYPE as E, type SendResult as F, GAS_RESERVE_MIN as G, type ServiceListing 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 SimulationResult as Q, type StableAsset as R, STABLE_ASSETS as S, type SuiHolding as T, type SuiRpcTxBlock as U, type SupportedAsset as V, type SwapRouteResult as W, T2000Error as X, type T2000ErrorCode as Y, type T2000ErrorData as Z, T2000_OVERLAY_FEE_WALLET as _, A2A_ESCROW_PACKAGE_ID as a,
|
|
1528
|
+
export { TOKEN_MAP as $, A2A_ESCROW_FEE_CONFIG_ID as A, type BalanceResponse as B, CLOCK_ID as C, DEFAULT_COMMERCE_API_BASE as D, ETH_TYPE as E, type SendResult as F, GAS_RESERVE_MIN as G, type ServiceListing 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 SimulationResult as Q, type StableAsset as R, STABLE_ASSETS as S, type SuiHolding as T, type SuiRpcTxBlock as U, type SupportedAsset as V, type SwapRouteResult as W, T2000Error as X, type T2000ErrorCode as Y, type T2000ErrorData as Z, T2000_OVERLAY_FEE_WALLET as _, A2A_ESCROW_PACKAGE_ID as a, verifyJobForSeller as a$, type TransactionLeg as a0, type TransactionRecord as a1, type TransactionSigner as a2, type TxDirection as a3, USDC_DECIMALS as a4, USDC_TYPE as a5, USDE_TYPE as a6, USDSUI_TYPE as a7, USDT_TYPE as a8, WAL_TYPE as a9, getDecimals as aA, getDecimalsForCoinType as aB, getJob as aC, getJobSpec as aD, jobActionsFor as aE, listServices as aF, mapMoveAbortCode as aG, mapWalletError as aH, mistToSui as aI, parseSuiRpcTx as aJ, payWithMpp as aK, preflightCreateJob as aL, preflightFail as aM, preflightPay as aN, preflightSend as aO, preflightSwap as aP, putJobSpec as aQ, rawToStable as aR, rawToUsdc as aS, refineLendingLabel as aT, resolveSymbol as aU, resolveTokenType as aV, stableToRaw as aW, suiToMist as aX, truncateAddress as aY, usdcToRaw as aZ, validateAddress as a_, WBTC_TYPE as aa, type ZkLoginProof as ab, ZkLoginSigner as ac, buildCreateJobTx as ad, buildDeliverJobTx as ae, buildRefundJobTx as af, buildRejectJobTx as ag, buildReleaseJobTx as ah, buildSendTx as ai, buildSwapTx as aj, checkPositiveAmount as ak, checkSuiAddress as al, classifyAction as am, classifyLabel as an, classifyTransaction as ao, executeTx as ap, extractAllUserLegs as aq, extractTransferDetails as ar, extractTxCommands as as, extractTxSender as at, fallbackLabel as au, fetchService as av, findSwapRoute as aw, formatAssetAmount as ax, formatSui as ay, formatUsd as az, COIN_REGISTRY as b, type T2000Options as b0, type SwapResult as b1, type SwapQuoteResult as b2, type PaymentRequest as b3, type SuiCoreClient as b4, type SponsoredCoinMergeCache as b5, type SendableAsset as b6, CETUS_USDC_SUI_POOL as b7, type CoinPage as b8, DEFAULT_GRPC_URL as b9, selectAndSplitCoin as bA, selectSuiCoin as bB, serializeCetusRoute as bC, simulateTransaction as bD, throwIfSimulationFailed as bE, verifyCetusRouteCoinMatch as bF, GASLESS_MIN_STABLE_AMOUNT as ba, GASLESS_STABLE_TYPES as bb, OPERATION_ASSETS as bc, type Operation as bd, SENDABLE_ASSETS as be, type SelectAndSplitResult as bf, type SerializedCetusRoute as bg, type SerializedCetusRoutePath as bh, type SerializedRouterDataV3 as bi, addSendToTx as bj, addSwapToTx as bk, assertAllowedAsset as bl, assertBuyerRequirements as bm, buildDeclineJobTx as bn, deserializeCetusRoute as bo, fetchAllCoins as bp, getCoinMeta as bq, getSuiClient as br, getSuiGrpcClient as bs, isAllowedAsset as bt, isCetusRouteFresh as bu, isInRegistry as bv, normalizeAsset as bw, normalizeCoinType as bx, queryHistory as by, queryTransaction as bz, type ClassifyBalanceChange as c, type ClassifyResult as d, type CoinMeta as e, DEFAULT_NETWORK as f, type DepositInfo as g, type ExtractedTransfer as h, type Job as i, type JobState as j, type JobTerms as k, type JobVerification as l, KeypairSigner as m, LOFI_TYPE as n, MAX_DELIVER_HORIZON_MS as o, MAX_JOB_USDC as p, MAX_REVIEW_WINDOW_MS as q, MIST_PER_SUI as r, type OverlayFeeConfig as s, PREFLIGHT_OK as t, type PayOptions as u, type PayResult as v, type PreflightResult as w, SUI_DECIMALS as x, SUI_TYPE as y, SUPPORTED_ASSETS as z };
|
|
@@ -15,8 +15,8 @@ interface TransactionSigner {
|
|
|
15
15
|
signature: string;
|
|
16
16
|
}>;
|
|
17
17
|
/**
|
|
18
|
-
* Sign an arbitrary personal message
|
|
19
|
-
*
|
|
18
|
+
* Sign an arbitrary personal message — used for off-chain proofs bound to
|
|
19
|
+
* the wallet (e.g. signed job-review submissions).
|
|
20
20
|
*/
|
|
21
21
|
signPersonalMessage(messageBytes: Uint8Array): Promise<{
|
|
22
22
|
signature: string;
|
|
@@ -24,13 +24,9 @@ interface TransactionSigner {
|
|
|
24
24
|
}>;
|
|
25
25
|
/**
|
|
26
26
|
* Signature scheme marker. zkLogin personal-message signatures are ZK
|
|
27
|
-
* constructs
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* (live finding, JMPR 2026-07-17: charged, no delivery). `payWithMpp`
|
|
31
|
-
* fails closed on `'zklogin'` + header-only 402 BEFORE any money moves.
|
|
32
|
-
* Optional so external signer impls keep compiling; undefined = keypair
|
|
33
|
-
* semantics.
|
|
27
|
+
* constructs only Sui-aware verifiers can check — hosts use this to gate
|
|
28
|
+
* flows that depend on seller-side signature verification. Optional so
|
|
29
|
+
* external signer impls keep compiling; undefined = keypair semantics.
|
|
34
30
|
*/
|
|
35
31
|
readonly kind?: 'keypair' | 'zklogin';
|
|
36
32
|
}
|
|
@@ -899,13 +895,12 @@ interface PayResult {
|
|
|
899
895
|
body: unknown;
|
|
900
896
|
paid: boolean;
|
|
901
897
|
/**
|
|
902
|
-
* Which payment dialect settled the call
|
|
903
|
-
*
|
|
904
|
-
*
|
|
905
|
-
*
|
|
906
|
-
* SUIMPP_X402_SCHEME.md.
|
|
898
|
+
* Which payment dialect settled the call — always `'x402'` (sign-then-
|
|
899
|
+
* settle `sui-exact`; client signs, gateway settles) since the MPP header
|
|
900
|
+
* dialect was removed 2026-08-03. Undefined when nothing was paid
|
|
901
|
+
* (free/cached endpoint). See SUIMPP_X402_SCHEME.md.
|
|
907
902
|
*/
|
|
908
|
-
dialect?: 'x402'
|
|
903
|
+
dialect?: 'x402';
|
|
909
904
|
cost?: number;
|
|
910
905
|
/**
|
|
911
906
|
* SUI gas cost actually paid on chain. Zero for gasless payments —
|
|
@@ -937,19 +932,6 @@ declare function payWithMpp(args: {
|
|
|
937
932
|
client: SuiGrpcClient;
|
|
938
933
|
options: PayOptions;
|
|
939
934
|
}): Promise<PayResult>;
|
|
940
|
-
/**
|
|
941
|
-
* Parse the MPP header dialect from a 402 response: the
|
|
942
|
-
* `WWW-Authenticate: Payment …` challenge(s), looking for `method="sui"`.
|
|
943
|
-
* Returns the decoded `{ amount, currency, recipient }` request (amount is a
|
|
944
|
-
* decimal string, e.g. "0.02") or `undefined` when the response carries no
|
|
945
|
-
* sui challenge. Exported for the CLI's `t2 pay --estimate`.
|
|
946
|
-
*/
|
|
947
|
-
declare function parseMppSuiChallenge(response: Response): Promise<{
|
|
948
|
-
amount: string;
|
|
949
|
-
currency: string;
|
|
950
|
-
recipient: string;
|
|
951
|
-
description?: string;
|
|
952
|
-
} | undefined>;
|
|
953
935
|
|
|
954
936
|
type SuiTransactionEffects = SuiClientTypes.TransactionEffects;
|
|
955
937
|
type BuildClient = NonNullable<Parameters<Transaction['build']>[0]>['client'];
|
|
@@ -1543,4 +1525,4 @@ declare function putJobSpec(base: string, content: string): Promise<string>;
|
|
|
1543
1525
|
* the store is untrusted; the chain hash is the authority). */
|
|
1544
1526
|
declare function getJobSpec(base: string, hash: string): Promise<string>;
|
|
1545
1527
|
|
|
1546
|
-
export { TOKEN_MAP as $, A2A_ESCROW_FEE_CONFIG_ID as A, type BalanceResponse as B, CLOCK_ID as C, DEFAULT_COMMERCE_API_BASE as D, ETH_TYPE as E, type SendResult as F, GAS_RESERVE_MIN as G, type ServiceListing 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 SimulationResult as Q, type StableAsset as R, STABLE_ASSETS as S, type SuiHolding as T, type SuiRpcTxBlock as U, type SupportedAsset as V, type SwapRouteResult as W, T2000Error as X, type T2000ErrorCode as Y, type T2000ErrorData as Z, T2000_OVERLAY_FEE_WALLET as _, A2A_ESCROW_PACKAGE_ID as a,
|
|
1528
|
+
export { TOKEN_MAP as $, A2A_ESCROW_FEE_CONFIG_ID as A, type BalanceResponse as B, CLOCK_ID as C, DEFAULT_COMMERCE_API_BASE as D, ETH_TYPE as E, type SendResult as F, GAS_RESERVE_MIN as G, type ServiceListing 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 SimulationResult as Q, type StableAsset as R, STABLE_ASSETS as S, type SuiHolding as T, type SuiRpcTxBlock as U, type SupportedAsset as V, type SwapRouteResult as W, T2000Error as X, type T2000ErrorCode as Y, type T2000ErrorData as Z, T2000_OVERLAY_FEE_WALLET as _, A2A_ESCROW_PACKAGE_ID as a, verifyJobForSeller as a$, type TransactionLeg as a0, type TransactionRecord as a1, type TransactionSigner as a2, type TxDirection as a3, USDC_DECIMALS as a4, USDC_TYPE as a5, USDE_TYPE as a6, USDSUI_TYPE as a7, USDT_TYPE as a8, WAL_TYPE as a9, getDecimals as aA, getDecimalsForCoinType as aB, getJob as aC, getJobSpec as aD, jobActionsFor as aE, listServices as aF, mapMoveAbortCode as aG, mapWalletError as aH, mistToSui as aI, parseSuiRpcTx as aJ, payWithMpp as aK, preflightCreateJob as aL, preflightFail as aM, preflightPay as aN, preflightSend as aO, preflightSwap as aP, putJobSpec as aQ, rawToStable as aR, rawToUsdc as aS, refineLendingLabel as aT, resolveSymbol as aU, resolveTokenType as aV, stableToRaw as aW, suiToMist as aX, truncateAddress as aY, usdcToRaw as aZ, validateAddress as a_, WBTC_TYPE as aa, type ZkLoginProof as ab, ZkLoginSigner as ac, buildCreateJobTx as ad, buildDeliverJobTx as ae, buildRefundJobTx as af, buildRejectJobTx as ag, buildReleaseJobTx as ah, buildSendTx as ai, buildSwapTx as aj, checkPositiveAmount as ak, checkSuiAddress as al, classifyAction as am, classifyLabel as an, classifyTransaction as ao, executeTx as ap, extractAllUserLegs as aq, extractTransferDetails as ar, extractTxCommands as as, extractTxSender as at, fallbackLabel as au, fetchService as av, findSwapRoute as aw, formatAssetAmount as ax, formatSui as ay, formatUsd as az, COIN_REGISTRY as b, type T2000Options as b0, type SwapResult as b1, type SwapQuoteResult as b2, type PaymentRequest as b3, type SuiCoreClient as b4, type SponsoredCoinMergeCache as b5, type SendableAsset as b6, CETUS_USDC_SUI_POOL as b7, type CoinPage as b8, DEFAULT_GRPC_URL as b9, selectAndSplitCoin as bA, selectSuiCoin as bB, serializeCetusRoute as bC, simulateTransaction as bD, throwIfSimulationFailed as bE, verifyCetusRouteCoinMatch as bF, GASLESS_MIN_STABLE_AMOUNT as ba, GASLESS_STABLE_TYPES as bb, OPERATION_ASSETS as bc, type Operation as bd, SENDABLE_ASSETS as be, type SelectAndSplitResult as bf, type SerializedCetusRoute as bg, type SerializedCetusRoutePath as bh, type SerializedRouterDataV3 as bi, addSendToTx as bj, addSwapToTx as bk, assertAllowedAsset as bl, assertBuyerRequirements as bm, buildDeclineJobTx as bn, deserializeCetusRoute as bo, fetchAllCoins as bp, getCoinMeta as bq, getSuiClient as br, getSuiGrpcClient as bs, isAllowedAsset as bt, isCetusRouteFresh as bu, isInRegistry as bv, normalizeAsset as bw, normalizeCoinType as bx, queryHistory as by, queryTransaction as bz, type ClassifyBalanceChange as c, type ClassifyResult as d, type CoinMeta as e, DEFAULT_NETWORK as f, type DepositInfo as g, type ExtractedTransfer as h, type Job as i, type JobState as j, type JobTerms as k, type JobVerification as l, KeypairSigner as m, LOFI_TYPE as n, MAX_DELIVER_HORIZON_MS as o, MAX_JOB_USDC as p, MAX_REVIEW_WINDOW_MS as q, MIST_PER_SUI as r, type OverlayFeeConfig as s, PREFLIGHT_OK as t, type PayOptions as u, type PayResult as v, type PreflightResult as w, SUI_DECIMALS as x, SUI_TYPE as y, SUPPORTED_ASSETS as z };
|
package/dist/index.cjs
CHANGED
|
@@ -1097,15 +1097,6 @@ async function executeTx(client, signer, buildTx, options = {}) {
|
|
|
1097
1097
|
|
|
1098
1098
|
// src/wallet/pay.ts
|
|
1099
1099
|
init_errors();
|
|
1100
|
-
|
|
1101
|
-
// src/mpp-cost.ts
|
|
1102
|
-
function parseChallengeAmount(challenge) {
|
|
1103
|
-
const raw = challenge?.request?.amount;
|
|
1104
|
-
const n = typeof raw === "string" ? Number(raw) : typeof raw === "number" ? raw : Number.NaN;
|
|
1105
|
-
return Number.isFinite(n) ? n : void 0;
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
// src/wallet/pay.ts
|
|
1109
1100
|
init_preflight();
|
|
1110
1101
|
function preflightPay(input) {
|
|
1111
1102
|
if (typeof input.url !== "string" || input.url.trim() === "") {
|
|
@@ -1171,18 +1162,12 @@ async function payWithMpp(args) {
|
|
|
1171
1162
|
const result = await payViaX402({ signer, client, options, reqInit, requirements });
|
|
1172
1163
|
return result;
|
|
1173
1164
|
}
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
{ dialect: "mpp-header", signerKind: "zklogin" }
|
|
1181
|
-
);
|
|
1182
|
-
}
|
|
1183
|
-
assertNotSelfPayment(signer.getAddress(), headerChallenge.recipient);
|
|
1184
|
-
const result = await payViaMppHeader({ signer, client, options });
|
|
1185
|
-
return result;
|
|
1165
|
+
if (hasPaymentAuthenticateHeader(probe)) {
|
|
1166
|
+
throw new exports.T2000Error(
|
|
1167
|
+
"DIALECT_UNSUPPORTED",
|
|
1168
|
+
"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).",
|
|
1169
|
+
{ dialect: "mpp-header", reason: "header-only-402-unsupported" }
|
|
1170
|
+
);
|
|
1186
1171
|
}
|
|
1187
1172
|
if (pick.kind === "incomplete") {
|
|
1188
1173
|
throw new exports.T2000Error(
|
|
@@ -1196,24 +1181,6 @@ async function payWithMpp(args) {
|
|
|
1196
1181
|
`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.`
|
|
1197
1182
|
);
|
|
1198
1183
|
}
|
|
1199
|
-
async function parseMppSuiChallenge(response) {
|
|
1200
|
-
try {
|
|
1201
|
-
const { Challenge } = await import('mppx');
|
|
1202
|
-
const challenges = Challenge.fromResponseList(response);
|
|
1203
|
-
const suiChallenge = challenges.find((c) => c.method === "sui" && c.intent === "charge");
|
|
1204
|
-
if (!suiChallenge) return void 0;
|
|
1205
|
-
const req = suiChallenge.request;
|
|
1206
|
-
if (typeof req?.amount !== "string" || typeof req?.recipient !== "string") return void 0;
|
|
1207
|
-
return {
|
|
1208
|
-
amount: req.amount,
|
|
1209
|
-
currency: typeof req.currency === "string" ? req.currency : "",
|
|
1210
|
-
recipient: req.recipient,
|
|
1211
|
-
description: suiChallenge.description
|
|
1212
|
-
};
|
|
1213
|
-
} catch {
|
|
1214
|
-
return void 0;
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
1184
|
function hasCompleteSuimppChallenge(entry) {
|
|
1218
1185
|
const s = entry.extra?.suimpp;
|
|
1219
1186
|
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";
|
|
@@ -1280,61 +1247,6 @@ async function payViaX402(args) {
|
|
|
1280
1247
|
receipt: digest ? { reference: digest, timestamp: (/* @__PURE__ */ new Date()).toISOString() } : result.receipt
|
|
1281
1248
|
};
|
|
1282
1249
|
}
|
|
1283
|
-
async function payViaMppHeader(args) {
|
|
1284
|
-
const { signer, client, options } = args;
|
|
1285
|
-
const { Mppx } = await import('mppx/client');
|
|
1286
|
-
const { sui, USDC, USDC_TESTNET } = await import('@suimpp/mpp/client');
|
|
1287
|
-
const signerAddress = signer.getAddress();
|
|
1288
|
-
const network = client.network === "testnet" ? "testnet" : "mainnet";
|
|
1289
|
-
const grpcClient = await makeGrpcBuildClient(client);
|
|
1290
|
-
let paymentDigest;
|
|
1291
|
-
let gasCostSui = 0;
|
|
1292
|
-
let chargedAmount;
|
|
1293
|
-
const mppx = Mppx.create({
|
|
1294
|
-
polyfill: false,
|
|
1295
|
-
onChallenge: async (challenge) => {
|
|
1296
|
-
const parsed = parseChallengeAmount(challenge);
|
|
1297
|
-
if (parsed !== void 0) {
|
|
1298
|
-
chargedAmount = parsed;
|
|
1299
|
-
assertWithinMaxPrice(parsed, options.maxPrice);
|
|
1300
|
-
}
|
|
1301
|
-
return void 0;
|
|
1302
|
-
},
|
|
1303
|
-
methods: [
|
|
1304
|
-
sui({
|
|
1305
|
-
client,
|
|
1306
|
-
currency: network === "testnet" ? USDC_TESTNET : USDC,
|
|
1307
|
-
signer: {
|
|
1308
|
-
toSuiAddress: () => signerAddress,
|
|
1309
|
-
signPersonalMessage: (bytes) => signer.signPersonalMessage(bytes)
|
|
1310
|
-
},
|
|
1311
|
-
execute: async (tx) => {
|
|
1312
|
-
const result2 = await executeTx(client, signer, () => tx, { buildClient: grpcClient });
|
|
1313
|
-
paymentDigest = result2.digest;
|
|
1314
|
-
gasCostSui = result2.gasCostSui;
|
|
1315
|
-
return { digest: result2.digest };
|
|
1316
|
-
}
|
|
1317
|
-
})
|
|
1318
|
-
]
|
|
1319
|
-
});
|
|
1320
|
-
const method = (options.method ?? "GET").toUpperCase();
|
|
1321
|
-
const canHaveBody = method !== "GET" && method !== "HEAD";
|
|
1322
|
-
const response = await mppx.fetch(options.url, {
|
|
1323
|
-
method,
|
|
1324
|
-
headers: options.headers,
|
|
1325
|
-
body: canHaveBody ? options.body : void 0
|
|
1326
|
-
});
|
|
1327
|
-
const paid = !!paymentDigest;
|
|
1328
|
-
const result = await finalize(response, { paid });
|
|
1329
|
-
if (!paid) return { ...result, dialect: "legacy" };
|
|
1330
|
-
return {
|
|
1331
|
-
...result,
|
|
1332
|
-
dialect: "legacy",
|
|
1333
|
-
cost: chargedAmount ?? options.maxPrice ?? void 0,
|
|
1334
|
-
gasCostSui,
|
|
1335
|
-
receipt: paymentDigest ? { reference: paymentDigest, timestamp: (/* @__PURE__ */ new Date()).toISOString() } : void 0
|
|
1336
|
-
};
|
|
1337
|
-
}
|
|
1338
1250
|
function assertNotSelfPayment(payer, payTo) {
|
|
1339
1251
|
if (utils.normalizeSuiAddress(payer) === utils.normalizeSuiAddress(payTo)) {
|
|
1340
1252
|
throw new exports.T2000Error(
|
|
@@ -1386,6 +1298,10 @@ async function ensureAddressBalanceCovers(args) {
|
|
|
1386
1298
|
const migration = await executeTx(client, signer, () => tx, { buildClient: grpcClient });
|
|
1387
1299
|
return migration.gasCostSui;
|
|
1388
1300
|
}
|
|
1301
|
+
function hasPaymentAuthenticateHeader(response) {
|
|
1302
|
+
const header = response.headers.get("www-authenticate") ?? "";
|
|
1303
|
+
return /(^|,)\s*Payment[\s,]/i.test(`${header},`);
|
|
1304
|
+
}
|
|
1389
1305
|
function isJsonText(text) {
|
|
1390
1306
|
try {
|
|
1391
1307
|
JSON.parse(text);
|
|
@@ -4741,7 +4657,6 @@ exports.mistToSui = mistToSui;
|
|
|
4741
4657
|
exports.normalizeAddressInput = normalizeAddressInput;
|
|
4742
4658
|
exports.normalizeAsset = normalizeAsset;
|
|
4743
4659
|
exports.normalizeCoinType = normalizeCoinType;
|
|
4744
|
-
exports.parseMppSuiChallenge = parseMppSuiChallenge;
|
|
4745
4660
|
exports.parseSuiRpcTx = parseSuiRpcTx;
|
|
4746
4661
|
exports.payWithMpp = payWithMpp;
|
|
4747
4662
|
exports.postOpenJob = postOpenJob;
|