@dexterai/x402 1.9.2 → 1.9.4
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/adapters/index.cjs +14 -5
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +5 -5
- package/dist/adapters/index.d.ts +5 -5
- package/dist/adapters/index.js +14 -5
- package/dist/adapters/index.js.map +1 -1
- package/dist/client/index.cjs +60 -24
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +22 -8
- package/dist/client/index.d.ts +22 -8
- package/dist/client/index.js +59 -24
- package/dist/client/index.js.map +1 -1
- package/dist/react/index.cjs +63 -30
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +10 -5
- package/dist/react/index.d.ts +10 -5
- package/dist/react/index.js +63 -30
- package/dist/react/index.js.map +1 -1
- package/dist/server/index.cjs +36 -10
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +48 -14
- package/dist/server/index.d.ts +48 -14
- package/dist/server/index.js +35 -10
- package/dist/server/index.js.map +1 -1
- package/dist/{solana-CfHuiW2H.d.cts → solana-BcOfK6Eq.d.cts} +2 -2
- package/dist/{solana-kZcwbUK9.d.ts → solana-Cxr5byPa.d.ts} +2 -2
- package/dist/{sponsored-access-H1EX6zpi.d.ts → sponsored-access-Br6YPA-m.d.cts} +20 -2
- package/dist/{sponsored-access-BCB2CxdG.d.cts → sponsored-access-D1_mINs4.d.ts} +20 -2
- package/dist/{types-ENcnkof8.d.ts → types-BIHhO2-I.d.ts} +1 -1
- package/dist/{types-DmqH9yD8.d.cts → types-CfKflCZO.d.cts} +1 -1
- package/dist/{types-BQvaF8lB.d.cts → types-CjLMR7qs.d.cts} +1 -1
- package/dist/{types-BQvaF8lB.d.ts → types-CjLMR7qs.d.ts} +1 -1
- package/dist/utils/index.cjs +8 -6
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.js +8 -6
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -1
package/dist/client/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export { P as PaymentReceipt, a as X402Client, X as X402ClientConfig, c as createX402Client, f as fireImpressionBeacon, g as getPaymentReceipt, d as getSponsoredAccessInfo, b as getSponsoredRecommendations } from '../sponsored-access-
|
|
2
|
-
import { A as AccessPassClientConfig } from '../types-
|
|
3
|
-
export { b as AccessPassInfo, a as AccessPassTier, D as DEXTER_FACILITATOR_URL, U as USDC_MINT, X as X402Error } from '../types-
|
|
1
|
+
export { P as PaymentReceipt, a as X402Client, X as X402ClientConfig, c as createX402Client, f as fireImpressionBeacon, g as getPaymentReceipt, d as getSponsoredAccessInfo, b as getSponsoredRecommendations } from '../sponsored-access-D1_mINs4.js';
|
|
2
|
+
import { A as AccessPassClientConfig } from '../types-CjLMR7qs.js';
|
|
3
|
+
export { b as AccessPassInfo, a as AccessPassTier, D as DEXTER_FACILITATOR_URL, U as USDC_MINT, X as X402Error } from '../types-CjLMR7qs.js';
|
|
4
4
|
import { Transaction, VersionedTransaction, Keypair } from '@solana/web3.js';
|
|
5
|
-
import { E as EvmWallet } from '../solana-
|
|
6
|
-
export { B as BASE_MAINNET, S as SOLANA_MAINNET, a as createEvmAdapter, c as createSolanaAdapter } from '../solana-
|
|
7
|
-
export { C as ChainAdapter, W as WalletSet } from '../types-
|
|
5
|
+
import { E as EvmWallet } from '../solana-Cxr5byPa.js';
|
|
6
|
+
export { B as BASE_MAINNET, S as SOLANA_MAINNET, a as createEvmAdapter, c as createSolanaAdapter } from '../solana-Cxr5byPa.js';
|
|
7
|
+
export { C as ChainAdapter, W as WalletSet } from '../types-BIHhO2-I.js';
|
|
8
8
|
export { SponsoredAccessSettlementInfo, SponsoredRecommendation } from '@dexterai/x402-ads-types';
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -135,6 +135,8 @@ declare function wrapFetch(fetchImpl: typeof globalThis.fetch, options: WrapFetc
|
|
|
135
135
|
* ```
|
|
136
136
|
*/
|
|
137
137
|
|
|
138
|
+
/** Symbol key for the underlying Keypair — prevents accidental exposure via console.log or JSON.stringify */
|
|
139
|
+
declare const KEYPAIR_SYMBOL: unique symbol;
|
|
138
140
|
/**
|
|
139
141
|
* Keypair wallet interface (compatible with SDK's SolanaWallet)
|
|
140
142
|
*/
|
|
@@ -145,9 +147,21 @@ interface KeypairWallet {
|
|
|
145
147
|
};
|
|
146
148
|
/** Sign a transaction */
|
|
147
149
|
signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T>;
|
|
148
|
-
/**
|
|
150
|
+
/**
|
|
151
|
+
* Get the underlying Keypair. Accessed via Symbol to prevent accidental
|
|
152
|
+
* exposure through console.log, JSON.stringify, or Object.keys.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* import { KEYPAIR_SYMBOL } from '@dexterai/x402/client';
|
|
157
|
+
* const kp = wallet[KEYPAIR_SYMBOL];
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
[KEYPAIR_SYMBOL]: Keypair;
|
|
161
|
+
/** @deprecated Use wallet[KEYPAIR_SYMBOL] instead — this will be removed in a future major version */
|
|
149
162
|
keypair: Keypair;
|
|
150
163
|
}
|
|
164
|
+
|
|
151
165
|
/**
|
|
152
166
|
* Create a wallet from a Solana private key
|
|
153
167
|
*
|
|
@@ -245,4 +259,4 @@ declare function createEvmKeypairWallet(privateKey: string): Promise<EvmWallet>;
|
|
|
245
259
|
*/
|
|
246
260
|
declare function isEvmKeypairWallet(wallet: unknown): wallet is EvmWallet;
|
|
247
261
|
|
|
248
|
-
export { AccessPassClientConfig, type KeypairWallet, type WrapFetchOptions, createEvmKeypairWallet, createKeypairWallet, isEvmKeypairWallet, isKeypairWallet, wrapFetch };
|
|
262
|
+
export { AccessPassClientConfig, KEYPAIR_SYMBOL, type KeypairWallet, type WrapFetchOptions, createEvmKeypairWallet, createKeypairWallet, isEvmKeypairWallet, isKeypairWallet, wrapFetch };
|
package/dist/client/index.js
CHANGED
|
@@ -266,8 +266,11 @@ var SolanaAdapter = class {
|
|
|
266
266
|
const account = await getAccount(connection, ata, void 0, programId);
|
|
267
267
|
const decimals = accept.extra?.decimals ?? 6;
|
|
268
268
|
return Number(account.amount) / Math.pow(10, decimals);
|
|
269
|
-
} catch {
|
|
270
|
-
|
|
269
|
+
} catch (err) {
|
|
270
|
+
if (err && typeof err === "object" && "name" in err && (err.name === "TokenAccountNotFoundError" || err.name === "TokenInvalidAccountOwnerError")) {
|
|
271
|
+
return 0;
|
|
272
|
+
}
|
|
273
|
+
throw err;
|
|
271
274
|
}
|
|
272
275
|
}
|
|
273
276
|
async buildTransaction(accept, wallet, rpcUrl) {
|
|
@@ -495,15 +498,21 @@ var EvmAdapter = class {
|
|
|
495
498
|
]
|
|
496
499
|
})
|
|
497
500
|
});
|
|
501
|
+
if (!response.ok) {
|
|
502
|
+
throw new Error(`RPC request failed: ${response.status}`);
|
|
503
|
+
}
|
|
498
504
|
const result = await response.json();
|
|
499
|
-
if (result.error
|
|
505
|
+
if (result.error) {
|
|
506
|
+
throw new Error(`RPC error: ${JSON.stringify(result.error)}`);
|
|
507
|
+
}
|
|
508
|
+
if (!result.result || result.result === "0x") {
|
|
500
509
|
return 0;
|
|
501
510
|
}
|
|
502
511
|
const balance = BigInt(result.result);
|
|
503
512
|
const decimals = accept.extra?.decimals ?? 6;
|
|
504
513
|
return Number(balance) / Math.pow(10, decimals);
|
|
505
|
-
} catch {
|
|
506
|
-
|
|
514
|
+
} catch (err) {
|
|
515
|
+
throw err;
|
|
507
516
|
}
|
|
508
517
|
}
|
|
509
518
|
encodeBalanceOf(address) {
|
|
@@ -619,7 +628,8 @@ function createX402Client(config) {
|
|
|
619
628
|
maxAmountAtomic,
|
|
620
629
|
fetch: customFetch = globalThis.fetch,
|
|
621
630
|
verbose = false,
|
|
622
|
-
accessPass: accessPassConfig
|
|
631
|
+
accessPass: accessPassConfig,
|
|
632
|
+
onPaymentRequired
|
|
623
633
|
} = config;
|
|
624
634
|
const log = verbose ? console.log.bind(console, "[x402]") : () => {
|
|
625
635
|
};
|
|
@@ -732,13 +742,17 @@ function createX402Client(config) {
|
|
|
732
742
|
const paymentAmount = accept.amount ?? accept.maxAmountRequired;
|
|
733
743
|
if (!paymentAmount) return null;
|
|
734
744
|
const rpcUrl = getRpcUrl(accept.network, adapter);
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
745
|
+
try {
|
|
746
|
+
const balance = await adapter.getBalance(accept, wallet, rpcUrl);
|
|
747
|
+
const requiredAmount = Number(paymentAmount) / Math.pow(10, decimals);
|
|
748
|
+
if (balance < requiredAmount) {
|
|
749
|
+
throw new X402Error(
|
|
750
|
+
"insufficient_balance",
|
|
751
|
+
`Insufficient balance for access pass. Have $${balance.toFixed(4)}, need $${requiredAmount.toFixed(4)}`
|
|
752
|
+
);
|
|
753
|
+
}
|
|
754
|
+
} catch (err) {
|
|
755
|
+
if (err instanceof X402Error) throw err;
|
|
742
756
|
}
|
|
743
757
|
const signedTx = await adapter.buildTransaction(accept, wallet, rpcUrl);
|
|
744
758
|
let payload;
|
|
@@ -751,13 +765,19 @@ function createX402Client(config) {
|
|
|
751
765
|
let resolvedResource = requirements.resource;
|
|
752
766
|
if (typeof requirements.resource === "string") {
|
|
753
767
|
try {
|
|
754
|
-
|
|
768
|
+
const resolved = new URL(requirements.resource, originalUrl);
|
|
769
|
+
if (["http:", "https:"].includes(resolved.protocol)) {
|
|
770
|
+
resolvedResource = resolved.toString();
|
|
771
|
+
}
|
|
755
772
|
} catch {
|
|
756
773
|
}
|
|
757
774
|
} else if (requirements.resource && typeof requirements.resource === "object" && "url" in requirements.resource) {
|
|
758
775
|
const rObj = requirements.resource;
|
|
759
776
|
try {
|
|
760
|
-
|
|
777
|
+
const resolved = new URL(rObj.url, originalUrl);
|
|
778
|
+
if (["http:", "https:"].includes(resolved.protocol)) {
|
|
779
|
+
resolvedResource = { ...rObj, url: resolved.toString() };
|
|
780
|
+
}
|
|
761
781
|
} catch {
|
|
762
782
|
}
|
|
763
783
|
}
|
|
@@ -885,16 +905,27 @@ function createX402Client(config) {
|
|
|
885
905
|
}
|
|
886
906
|
const rpcUrl = getRpcUrl(accept.network, adapter);
|
|
887
907
|
log("Checking balance...");
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
908
|
+
try {
|
|
909
|
+
const balance = await adapter.getBalance(accept, wallet, rpcUrl);
|
|
910
|
+
const requiredAmount = Number(paymentAmount) / Math.pow(10, decimals);
|
|
911
|
+
if (balance < requiredAmount) {
|
|
912
|
+
const network = adapter.name === "EVM" ? "Base" : "Solana";
|
|
913
|
+
throw new X402Error(
|
|
914
|
+
"insufficient_balance",
|
|
915
|
+
`Insufficient USDC balance on ${network}. Have $${balance.toFixed(4)}, need $${requiredAmount.toFixed(4)}`
|
|
916
|
+
);
|
|
917
|
+
}
|
|
918
|
+
log(`Balance OK: $${balance.toFixed(4)} >= $${requiredAmount.toFixed(4)}`);
|
|
919
|
+
} catch (err) {
|
|
920
|
+
if (err instanceof X402Error) throw err;
|
|
921
|
+
log("Balance check failed (RPC error), proceeding with transaction attempt");
|
|
922
|
+
}
|
|
923
|
+
if (onPaymentRequired) {
|
|
924
|
+
const approved = await onPaymentRequired(accept);
|
|
925
|
+
if (!approved) {
|
|
926
|
+
throw new X402Error("payment_rejected", "Payment rejected by onPaymentRequired callback");
|
|
927
|
+
}
|
|
896
928
|
}
|
|
897
|
-
log(`Balance OK: $${balance.toFixed(4)} >= $${requiredAmount.toFixed(4)}`);
|
|
898
929
|
log("Building transaction...");
|
|
899
930
|
const signedTx = await adapter.buildTransaction(accept, wallet, rpcUrl);
|
|
900
931
|
log("Transaction signed");
|
|
@@ -980,6 +1011,7 @@ function createX402Client(config) {
|
|
|
980
1011
|
|
|
981
1012
|
// src/client/keypair-wallet.ts
|
|
982
1013
|
import { Keypair, VersionedTransaction as VersionedTransaction2, Transaction } from "@solana/web3.js";
|
|
1014
|
+
var KEYPAIR_SYMBOL = /* @__PURE__ */ Symbol.for("x402:keypair");
|
|
983
1015
|
async function createKeypairWallet(privateKey) {
|
|
984
1016
|
let keypair;
|
|
985
1017
|
if (typeof privateKey === "string") {
|
|
@@ -1034,7 +1066,9 @@ async function createKeypairWallet(privateKey) {
|
|
|
1034
1066
|
}
|
|
1035
1067
|
throw new Error("Unknown transaction type");
|
|
1036
1068
|
},
|
|
1069
|
+
[KEYPAIR_SYMBOL]: keypair,
|
|
1037
1070
|
keypair
|
|
1071
|
+
// deprecated — kept for backwards compat
|
|
1038
1072
|
};
|
|
1039
1073
|
}
|
|
1040
1074
|
function isKeypairWallet(wallet) {
|
|
@@ -1147,6 +1181,7 @@ async function fireImpressionBeacon(response) {
|
|
|
1147
1181
|
export {
|
|
1148
1182
|
BASE_MAINNET,
|
|
1149
1183
|
DEXTER_FACILITATOR_URL,
|
|
1184
|
+
KEYPAIR_SYMBOL,
|
|
1150
1185
|
SOLANA_MAINNET,
|
|
1151
1186
|
USDC_MINT,
|
|
1152
1187
|
X402Error,
|