@dexterai/x402 3.18.1 → 4.1.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/README.md +19 -5
- package/dist/client/index.cjs +1 -1
- package/dist/client/index.d.cts +32 -70
- package/dist/client/index.d.ts +32 -70
- package/dist/client/index.js +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.d.cts +5 -107
- package/dist/react/index.d.ts +5 -107
- package/dist/react/index.js +1 -1
- package/dist/server/index.cjs +1 -286
- package/dist/server/index.d.cts +1 -724
- package/dist/server/index.d.ts +1 -724
- package/dist/server/index.js +1 -286
- package/dist/tab/adapters/solana/index.cjs +1 -1
- package/dist/tab/adapters/solana/index.d.cts +19 -24
- package/dist/tab/adapters/solana/index.d.ts +19 -24
- package/dist/tab/adapters/solana/index.js +1 -1
- package/dist/{x402-client-Ug0vrj74.d.ts → x402-client-BQKDeNxq.d.cts} +1 -123
- package/dist/{x402-client-DmRbvqoc.d.cts → x402-client-BQKDeNxq.d.ts} +1 -123
- package/package.json +2 -2
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as _solana_web3_js from '@solana/web3.js';
|
|
2
2
|
import { PublicKey, Connection, Signer, ConfirmOptions } from '@solana/web3.js';
|
|
3
3
|
import { V as VaultAdapter } from '../../../types-DuoL3s8n.js';
|
|
4
|
+
import { PasskeySignerWithPublicKey } from '@dexterai/vault/signers';
|
|
5
|
+
export { PasskeySignerWithPublicKey as PasskeySigner } from '@dexterai/vault/signers';
|
|
4
6
|
import '@dexterai/vault/types';
|
|
5
7
|
|
|
6
8
|
/**
|
|
@@ -53,29 +55,22 @@ interface P256Keypair {
|
|
|
53
55
|
/** 32-byte raw scalar. NEVER persist this anywhere user-readable. */
|
|
54
56
|
privateKey: Uint8Array;
|
|
55
57
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
signature: Uint8Array;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
interface PasskeySigner {
|
|
68
|
-
/** 33-byte SEC1 compressed P-256 public key. The vault stores this on
|
|
69
|
-
* init; the on-chain verifier compares against it on every passkey-
|
|
70
|
-
* signed instruction. */
|
|
58
|
+
/**
|
|
59
|
+
* Build a unified `PasskeySignerWithPublicKey` (vault's canonical shape)
|
|
60
|
+
* from a locally-held P-256 keypair — the node/CLI path. Returns
|
|
61
|
+
* `{ publicKey, sign(challenge) }`; the adapter computes the challenge and
|
|
62
|
+
* rebuilds the precompile message. Drop-in equivalent to vault's
|
|
63
|
+
* DexterApiBrowserPasskeySigner.
|
|
64
|
+
*/
|
|
65
|
+
declare function passkeySignerFromP256Keypair(kp: P256Keypair): {
|
|
71
66
|
publicKey: Uint8Array;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
67
|
+
sign(challenge: Uint8Array): Promise<{
|
|
68
|
+
signature: Uint8Array;
|
|
69
|
+
clientDataJSON: Uint8Array;
|
|
70
|
+
authenticatorData: Uint8Array;
|
|
71
|
+
}>;
|
|
72
|
+
};
|
|
73
|
+
|
|
79
74
|
interface CreateSolanaVaultAdapterOptions {
|
|
80
75
|
/** RPC the adapter uses to submit txs. The buyer can pass their own
|
|
81
76
|
* connection (browser wallet RPC, Helius URL, etc.) — the adapter has
|
|
@@ -89,7 +84,7 @@ interface CreateSolanaVaultAdapterOptions {
|
|
|
89
84
|
/** The buyer's vault PDA (gate account). */
|
|
90
85
|
vaultPda: string | PublicKey;
|
|
91
86
|
/** The passkey signing path. */
|
|
92
|
-
passkeySigner:
|
|
87
|
+
passkeySigner: PasskeySignerWithPublicKey;
|
|
93
88
|
/** Lamport-fee payer. In Phase 2 this is the buyer; later phases may
|
|
94
89
|
* route through a facilitator co-signer. Required because the buyer's
|
|
95
90
|
* vault account is not a signer for register/revoke (the passkey
|
|
@@ -121,4 +116,4 @@ declare function buildAdapterRegisterInstruction(p: AdapterRegisterIxParams): _s
|
|
|
121
116
|
/** Factory entry point. */
|
|
122
117
|
declare function createSolanaVaultAdapter(opts: CreateSolanaVaultAdapterOptions): VaultAdapter;
|
|
123
118
|
|
|
124
|
-
export { type AdapterRegisterIxParams, type CreateSolanaVaultAdapterOptions,
|
|
119
|
+
export { type AdapterRegisterIxParams, type CreateSolanaVaultAdapterOptions, buildAdapterRegisterInstruction, createSolanaVaultAdapter, deriveChannelId, passkeySignerFromP256Keypair };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{PublicKey as l,Transaction as
|
|
1
|
+
import{PublicKey as l,Transaction as q}from"@solana/web3.js";import{getAssociatedTokenAddressSync as pe}from"@solana/spl-token";var z="solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",j="solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",Z="solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";var x="eip155:8453",f="eip155:84532",P="eip155:42161",b="eip155:137",E="eip155:10",K="eip155:43114",v="eip155:56",w="eip155:1187947933",U="eip155:324705682",C="eip155:1";var _="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";var Q="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",ee="0x55d398326f99059fF775485246999027B3197955",I="0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",he={[v]:I,[x]:Q,[f]:"0x036CbD53842c5426634e7929541eC2318f3dCF7e",[P]:"0xaf88d065e77c8cC2239327C5EDb3A432268e5831",[b]:"0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",[E]:"0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",[K]:"0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",[w]:"0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",[U]:"0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",[C]:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},Se={[ee]:{symbol:"USDT",decimals:18},[I]:{symbol:"USDC",decimals:18}};var xe={[v]:56,[x]:8453,[f]:84532,[P]:42161,[b]:137,[E]:10,[K]:43114,[w]:1187947933,[U]:324705682,[C]:1},fe={[z]:"https://api.dexter.cash/api/solana/rpc",[j]:"https://api.devnet.solana.com",[Z]:"https://api.testnet.solana.com"},Pe={[v]:"https://api.dexter.cash/api/evm/bsc/rpc",[x]:"https://api.dexter.cash/api/base/rpc",[f]:"https://sepolia.base.org",[P]:"https://api.dexter.cash/api/evm/arbitrum/rpc",[b]:"https://api.dexter.cash/api/evm/polygon/rpc",[E]:"https://api.dexter.cash/api/evm/optimism/rpc",[K]:"https://api.dexter.cash/api/evm/avalanche/rpc",[w]:"https://skale-base.skalenodes.com/v1/base",[U]:"https://base-sepolia-testnet.skalenodes.com/v1/jubilant-horrible-ancha",[C]:"https://eth.llamarpc.com"};import{buildRegisterSessionKeyInstruction as k,buildRevokeSessionKeyInstruction as B,deriveSwigWalletAddress as M}from"@dexterai/vault/instructions";import{buildSecp256r1VerifyInstruction as R}from"@dexterai/vault/precompile";import{DEXTER_VAULT_PROGRAM_ID as O,SECP256R1_PROGRAM_ID as Ue,INSTRUCTIONS_SYSVAR_ID as Ce}from"@dexterai/vault/constants";import{sessionRegisterMessage as V,sessionRevokeMessage as L,voucherPayloadMessage as W,buildVoucherMessage as De}from"@dexterai/vault/messages";import F from"tweetnacl";import{sha256 as te}from"@noble/hashes/sha256";function J(){let e=F.sign.keyPair();return{publicKey:e.publicKey,privateKey:e.secretKey}}function H(e,t,n){return{publicKey:e.publicKey,privateKey:e.privateKey,scope:t,registration:n}}function G(e,t,n){if(n.length!==32)throw new Error(`channelIdBytes must be 32 bytes, got ${n.length}`);let i=BigInt(t.cumulativeAmount),r=BigInt(e.scope.maxAmountAtomic);if(i>r)throw new Error(`voucher cumulative ${i} exceeds session cap ${r}`);let s=Math.floor(Date.now()/1e3);if(s>=e.scope.expiresAtUnix)throw new Error(`session expired at ${e.scope.expiresAtUnix}, now ${s}`);let o=W({channelId:n,cumulativeAmount:i,sequenceNumber:t.sequenceNumber}),a=F.sign.detached(o,e.privateKey);return{payload:t,sessionPublicKey:e.publicKey,sessionRegistration:e.registration,sessionSignature:a}}function g(e){if(!/^\d+$/.test(e))throw new Error(`atomic amount must be a non-negative integer string, got "${e}"`);return BigInt(e)}function ne(e){let t=new Uint8Array(8);new DataView(t.buffer).setBigUint64(0,e.nonce,!0);let n=new TextEncoder().encode(e.sellerUrl),i=te.create();return i.update(e.vaultPda.toBytes()),i.update(n),i.update(t),i.digest()}import{fetchVaultSessionAccounts as le,sessionPdasOf as ue,waitForSession as ye}from"@dexterai/vault/session";import{sha256 as A}from"@noble/hashes/sha256";import{p256 as ie}from"@noble/curves/p256";import{sha256 as D}from"@noble/hashes/sha256";var $="dexter.cash";function re(e){return Buffer.from(e).toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function se(e,t=`https://${$}`){let i={type:"webauthn.get",challenge:re(e),origin:t,crossOrigin:!1};return new TextEncoder().encode(JSON.stringify(i))}function oe(e=1){let t=D(new TextEncoder().encode($)),n=new Uint8Array(37);return n.set(t,0),n[32]=5,new DataView(n.buffer).setUint32(33,e,!1),n}function ae(e,t){let n=se(t),i=oe(1),r=new Uint8Array(i.length+32);r.set(i,0),r.set(D(n),i.length);let s=D(r);return{signature:ie.sign(s,e.privateKey,{lowS:!0}).toCompactRawBytes(),clientDataJSON:n,authenticatorData:i}}function ce(e){return{publicKey:e.publicKey,sign:async t=>ae(e,t)}}function me(e){let t=M(e.swigAddress),n=pe(new l(_),t,!0);return k({vaultPda:e.vaultPda,sessionPubkey:e.sessionPubkey,maxAmount:e.maxAmount,maxRevolvingCapacity:e.maxRevolvingCapacity,expiresAt:e.expiresAt,allowedCounterparty:e.allowedCounterparty,nonce:e.nonce,swigAddress:e.swigAddress,vaultUsdcAta:n,clientDataJSON:e.clientDataJSON,authenticatorData:e.authenticatorData,payer:e.payer,siblingSessionPdas:e.siblingSessionPdas})}var N=class{network="solana:mainnet";swigAddress;vaultPda;connection;vaultPdaKey;passkey;feePayer;confirmOptions;constructor(t){this.connection=t.connection,this.swigAddress=typeof t.swigAddress=="string"?t.swigAddress:t.swigAddress.toBase58(),this.vaultPdaKey=typeof t.vaultPda=="string"?new l(t.vaultPda):t.vaultPda,this.vaultPda=this.vaultPdaKey.toBase58(),this.passkey=t.passkeySigner,this.feePayer=t.feePayer,this.confirmOptions=t.confirmOptions??{commitment:"confirmed"}}async authorizeSession(t){let n=new l(t.allowedCounterparty),i=g(t.revolvingCapacityAtomic??t.maxAmountAtomic),r=J(),s=de(),o=V({programId:O,vaultPda:this.vaultPdaKey,sessionPubkey:r.publicKey,maxAmount:g(t.maxAmountAtomic),maxRevolvingCapacity:i,expiresAt:BigInt(t.expiresAtUnix),allowedCounterparty:n,nonce:s}),a=A(o),{signature:u,clientDataJSON:y,authenticatorData:m}=await this.passkey.sign(a),h=X(m,A(y)),c=R(this.passkey.publicKey,u,h),d=ue(await le(this.connection,this.vaultPdaKey)),S=me({vaultPda:this.vaultPdaKey,swigAddress:new l(this.swigAddress),sessionPubkey:r.publicKey,maxAmount:g(t.maxAmountAtomic),maxRevolvingCapacity:i,expiresAt:BigInt(t.expiresAtUnix),allowedCounterparty:n,nonce:s,clientDataJSON:y,authenticatorData:m,payer:this.feePayer.publicKey,siblingSessionPdas:d}),p=new q().add(c,S);p.feePayer=this.feePayer.publicKey;let{blockhash:T}=await this.connection.getLatestBlockhash(this.confirmOptions.commitment);p.recentBlockhash=T,p.sign(this.feePayer);let Y=await this.connection.sendRawTransaction(p.serialize(),{skipPreflight:!1,preflightCommitment:this.confirmOptions.preflightCommitment??this.confirmOptions.commitment});return await this.connection.confirmTransaction({signature:Y,blockhash:T,lastValidBlockHeight:(await this.connection.getLatestBlockhash(this.confirmOptions.commitment)).lastValidBlockHeight},this.confirmOptions.commitment),await ye(this.connection,this.vaultPdaKey,n,{expectedSessionPubkey:r.publicKey,timeoutMs:2e4}),H(r,t,o)}async signWithSession(t,n){let i=await ge(n.channelId);return G(t,n,i)}async signOpenTab(t,n){return t.registration}async signCloseTab(t,n,i){let r=L({programId:O,vaultPda:this.vaultPdaKey,sessionPubkey:t.publicKey}),s=A(r),{signature:o,clientDataJSON:a,authenticatorData:u}=await this.passkey.sign(s),y=X(u,A(a)),m=R(this.passkey.publicKey,o,y),h=B({vaultPda:this.vaultPdaKey,allowedCounterparty:new l(t.scope.allowedCounterparty),clientDataJSON:a,authenticatorData:u}),c=new q().add(m,h);c.feePayer=this.feePayer.publicKey;let{blockhash:d,lastValidBlockHeight:S}=await this.connection.getLatestBlockhash(this.confirmOptions.commitment);c.recentBlockhash=d,c.sign(this.feePayer);let p=await this.connection.sendRawTransaction(c.serialize(),{skipPreflight:!1,preflightCommitment:this.confirmOptions.preflightCommitment??this.confirmOptions.commitment});return await this.connection.confirmTransaction({signature:p,blockhash:d,lastValidBlockHeight:S},this.confirmOptions.commitment),r}};function Xe(e){return new N(e)}function X(e,t){let n=new Uint8Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n}function de(){return Math.floor(Math.random()*4294967295)>>>0}async function ge(e){if(/^[0-9a-f]{64}$/i.test(e))return Ae(e);let{sha256:t}=await import("@noble/hashes/sha256");return t(new TextEncoder().encode(e))}function Ae(e){let t=new Uint8Array(e.length/2);for(let n=0;n<t.length;n++)t[n]=parseInt(e.substr(n*2,2),16);return t}export{me as buildAdapterRegisterInstruction,Xe as createSolanaVaultAdapter,ne as deriveChannelId,ce as passkeySignerFromP256Keypair};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { SponsoredRecommendation, SponsoredAccessSettlementInfo } from '@dexterai/x402-ads-types';
|
|
2
|
-
import { C as ChainAdapter, W as WalletSet, A as AccessPassClientConfig, P as PaymentAccept, S as SettlementProbe } from './types-xQu1U4xk.js';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Sponsored Access (Ads for Agents) — Client Helpers
|
|
@@ -130,104 +129,6 @@ interface PaymentReceipt {
|
|
|
130
129
|
* Get the x402 payment receipt from a response, or undefined if none.
|
|
131
130
|
*/
|
|
132
131
|
declare function getPaymentReceipt(response: Response): PaymentReceipt | undefined;
|
|
133
|
-
/**
|
|
134
|
-
* Client configuration
|
|
135
|
-
*
|
|
136
|
-
* @deprecated Slated for removal in `@dexterai/x402` 5.0 alongside
|
|
137
|
-
* `createX402Client` and `X402Client`. Use `PayAndFetchOptions` instead.
|
|
138
|
-
*/
|
|
139
|
-
interface X402ClientConfig {
|
|
140
|
-
/**
|
|
141
|
-
* Chain adapters to use for building transactions.
|
|
142
|
-
* If not provided, uses Solana and EVM adapters by default.
|
|
143
|
-
*/
|
|
144
|
-
adapters?: ChainAdapter[];
|
|
145
|
-
/**
|
|
146
|
-
* Wallets for each chain type.
|
|
147
|
-
* Can also pass a single wallet for backwards compatibility.
|
|
148
|
-
*/
|
|
149
|
-
wallets?: WalletSet;
|
|
150
|
-
/**
|
|
151
|
-
* Legacy: Single wallet (Solana).
|
|
152
|
-
* Use `wallets` for multi-chain support.
|
|
153
|
-
*/
|
|
154
|
-
wallet?: unknown;
|
|
155
|
-
/**
|
|
156
|
-
* Preferred network to use when multiple options are available.
|
|
157
|
-
* CAIP-2 format (e.g., 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp', 'eip155:8453')
|
|
158
|
-
*/
|
|
159
|
-
preferredNetwork?: string;
|
|
160
|
-
/**
|
|
161
|
-
* Custom RPC URLs by network
|
|
162
|
-
*/
|
|
163
|
-
rpcUrls?: Record<string, string>;
|
|
164
|
-
/**
|
|
165
|
-
* Maximum payment amount allowed (in atomic units).
|
|
166
|
-
* Rejects payments exceeding this amount.
|
|
167
|
-
*/
|
|
168
|
-
maxAmountAtomic?: string;
|
|
169
|
-
/**
|
|
170
|
-
* Custom fetch implementation
|
|
171
|
-
*/
|
|
172
|
-
fetch?: typeof globalThis.fetch;
|
|
173
|
-
/**
|
|
174
|
-
* Enable verbose logging
|
|
175
|
-
*/
|
|
176
|
-
verbose?: boolean;
|
|
177
|
-
/**
|
|
178
|
-
* Access pass configuration.
|
|
179
|
-
* When present, the client will prefer purchasing time-limited access passes
|
|
180
|
-
* over per-request payments. One payment grants unlimited requests for a duration.
|
|
181
|
-
*/
|
|
182
|
-
accessPass?: AccessPassClientConfig;
|
|
183
|
-
/**
|
|
184
|
-
* Called before signing a payment. Return true to proceed, false to reject.
|
|
185
|
-
* Use for budget controls, confirmation prompts, or logging.
|
|
186
|
-
*
|
|
187
|
-
* @example
|
|
188
|
-
* ```typescript
|
|
189
|
-
* const client = createX402Client({
|
|
190
|
-
* wallets,
|
|
191
|
-
* onPaymentRequired: async (requirements) => {
|
|
192
|
-
* const amount = Number(requirements.amount) / 1e6;
|
|
193
|
-
* if (amount > 1.0) return false; // Reject payments over $1
|
|
194
|
-
* console.log(`Paying $${amount} on ${requirements.network}`);
|
|
195
|
-
* return true;
|
|
196
|
-
* },
|
|
197
|
-
* });
|
|
198
|
-
* ```
|
|
199
|
-
*/
|
|
200
|
-
onPaymentRequired?: (requirements: PaymentAccept) => boolean | Promise<boolean>;
|
|
201
|
-
/**
|
|
202
|
-
* Called the instant the signed payment authorization is sent to the
|
|
203
|
-
* merchant — after `buildTransaction`, immediately before the paid retry
|
|
204
|
-
* fetch. This is the point past which a timeout can no longer be treated
|
|
205
|
-
* as "no money moved": the facilitator may settle at any time once the
|
|
206
|
-
* authorization is in its hands.
|
|
207
|
-
*
|
|
208
|
-
* The callback receives the `accept` it is paying against (network, asset,
|
|
209
|
-
* amount, payTo) and the `settlementProbe` the adapter produced (or
|
|
210
|
-
* `undefined` for schemes with no on-chain confirmation). `payAndFetch`
|
|
211
|
-
* uses this to mark a payment as dispatched — so a post-payment abort is
|
|
212
|
-
* not misreported as a plain timeout — and keeps the probe so it can
|
|
213
|
-
* confirm settlement on-chain if the merchant never responds.
|
|
214
|
-
*
|
|
215
|
-
* Fire-and-forget — the return value is ignored, and a throw is swallowed
|
|
216
|
-
* (the payment proceeds regardless). Do not do slow work here.
|
|
217
|
-
*/
|
|
218
|
-
onPaymentDispatched?: (accept: PaymentAccept, settlementProbe?: SettlementProbe) => void;
|
|
219
|
-
/**
|
|
220
|
-
* Maximum retry attempts for transient failures (network errors, 502/503).
|
|
221
|
-
* Does not cause double payments — EIP-3009 nonces prevent replay.
|
|
222
|
-
* @default 0 (no retry)
|
|
223
|
-
*/
|
|
224
|
-
maxRetries?: number;
|
|
225
|
-
/**
|
|
226
|
-
* Base delay between retries in milliseconds (doubles each attempt).
|
|
227
|
-
* @default 500
|
|
228
|
-
*/
|
|
229
|
-
retryDelayMs?: number;
|
|
230
|
-
}
|
|
231
132
|
/**
|
|
232
133
|
* x402 Client interface
|
|
233
134
|
*
|
|
@@ -241,28 +142,5 @@ interface X402Client {
|
|
|
241
142
|
*/
|
|
242
143
|
fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
243
144
|
}
|
|
244
|
-
/**
|
|
245
|
-
* Create an x402 v2 client
|
|
246
|
-
*
|
|
247
|
-
* @deprecated Slated for removal in `@dexterai/x402` 5.0 (~6 months out — long
|
|
248
|
-
* cycle because of real production consumers). Use `payAndFetch` from
|
|
249
|
-
* `@dexterai/x402/client` instead — it's version-agnostic across x402 v1 and
|
|
250
|
-
* v2 and returns a discriminated union for cleaner error handling.
|
|
251
|
-
*
|
|
252
|
-
* Migration:
|
|
253
|
-
* ```typescript
|
|
254
|
-
* // Before
|
|
255
|
-
* const client = createX402Client({ wallets });
|
|
256
|
-
* const res = await client.fetch(url);
|
|
257
|
-
*
|
|
258
|
-
* // After
|
|
259
|
-
* import { payAndFetch } from '@dexterai/x402/client';
|
|
260
|
-
* const result = await payAndFetch(url, undefined, wallets);
|
|
261
|
-
* if (result.ok) {
|
|
262
|
-
* const res = result.response;
|
|
263
|
-
* }
|
|
264
|
-
* ```
|
|
265
|
-
*/
|
|
266
|
-
declare function createX402Client(config: X402ClientConfig): X402Client;
|
|
267
145
|
|
|
268
|
-
export { type PaymentReceipt as P, type
|
|
146
|
+
export { type PaymentReceipt as P, type X402Client as X, getSponsoredAccessInfo as a, getPaymentReceipt as b, fireImpressionBeacon as f, getSponsoredRecommendations as g };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { SponsoredRecommendation, SponsoredAccessSettlementInfo } from '@dexterai/x402-ads-types';
|
|
2
|
-
import { C as ChainAdapter, W as WalletSet, A as AccessPassClientConfig, P as PaymentAccept, S as SettlementProbe } from './types-xQu1U4xk.cjs';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Sponsored Access (Ads for Agents) — Client Helpers
|
|
@@ -130,104 +129,6 @@ interface PaymentReceipt {
|
|
|
130
129
|
* Get the x402 payment receipt from a response, or undefined if none.
|
|
131
130
|
*/
|
|
132
131
|
declare function getPaymentReceipt(response: Response): PaymentReceipt | undefined;
|
|
133
|
-
/**
|
|
134
|
-
* Client configuration
|
|
135
|
-
*
|
|
136
|
-
* @deprecated Slated for removal in `@dexterai/x402` 5.0 alongside
|
|
137
|
-
* `createX402Client` and `X402Client`. Use `PayAndFetchOptions` instead.
|
|
138
|
-
*/
|
|
139
|
-
interface X402ClientConfig {
|
|
140
|
-
/**
|
|
141
|
-
* Chain adapters to use for building transactions.
|
|
142
|
-
* If not provided, uses Solana and EVM adapters by default.
|
|
143
|
-
*/
|
|
144
|
-
adapters?: ChainAdapter[];
|
|
145
|
-
/**
|
|
146
|
-
* Wallets for each chain type.
|
|
147
|
-
* Can also pass a single wallet for backwards compatibility.
|
|
148
|
-
*/
|
|
149
|
-
wallets?: WalletSet;
|
|
150
|
-
/**
|
|
151
|
-
* Legacy: Single wallet (Solana).
|
|
152
|
-
* Use `wallets` for multi-chain support.
|
|
153
|
-
*/
|
|
154
|
-
wallet?: unknown;
|
|
155
|
-
/**
|
|
156
|
-
* Preferred network to use when multiple options are available.
|
|
157
|
-
* CAIP-2 format (e.g., 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp', 'eip155:8453')
|
|
158
|
-
*/
|
|
159
|
-
preferredNetwork?: string;
|
|
160
|
-
/**
|
|
161
|
-
* Custom RPC URLs by network
|
|
162
|
-
*/
|
|
163
|
-
rpcUrls?: Record<string, string>;
|
|
164
|
-
/**
|
|
165
|
-
* Maximum payment amount allowed (in atomic units).
|
|
166
|
-
* Rejects payments exceeding this amount.
|
|
167
|
-
*/
|
|
168
|
-
maxAmountAtomic?: string;
|
|
169
|
-
/**
|
|
170
|
-
* Custom fetch implementation
|
|
171
|
-
*/
|
|
172
|
-
fetch?: typeof globalThis.fetch;
|
|
173
|
-
/**
|
|
174
|
-
* Enable verbose logging
|
|
175
|
-
*/
|
|
176
|
-
verbose?: boolean;
|
|
177
|
-
/**
|
|
178
|
-
* Access pass configuration.
|
|
179
|
-
* When present, the client will prefer purchasing time-limited access passes
|
|
180
|
-
* over per-request payments. One payment grants unlimited requests for a duration.
|
|
181
|
-
*/
|
|
182
|
-
accessPass?: AccessPassClientConfig;
|
|
183
|
-
/**
|
|
184
|
-
* Called before signing a payment. Return true to proceed, false to reject.
|
|
185
|
-
* Use for budget controls, confirmation prompts, or logging.
|
|
186
|
-
*
|
|
187
|
-
* @example
|
|
188
|
-
* ```typescript
|
|
189
|
-
* const client = createX402Client({
|
|
190
|
-
* wallets,
|
|
191
|
-
* onPaymentRequired: async (requirements) => {
|
|
192
|
-
* const amount = Number(requirements.amount) / 1e6;
|
|
193
|
-
* if (amount > 1.0) return false; // Reject payments over $1
|
|
194
|
-
* console.log(`Paying $${amount} on ${requirements.network}`);
|
|
195
|
-
* return true;
|
|
196
|
-
* },
|
|
197
|
-
* });
|
|
198
|
-
* ```
|
|
199
|
-
*/
|
|
200
|
-
onPaymentRequired?: (requirements: PaymentAccept) => boolean | Promise<boolean>;
|
|
201
|
-
/**
|
|
202
|
-
* Called the instant the signed payment authorization is sent to the
|
|
203
|
-
* merchant — after `buildTransaction`, immediately before the paid retry
|
|
204
|
-
* fetch. This is the point past which a timeout can no longer be treated
|
|
205
|
-
* as "no money moved": the facilitator may settle at any time once the
|
|
206
|
-
* authorization is in its hands.
|
|
207
|
-
*
|
|
208
|
-
* The callback receives the `accept` it is paying against (network, asset,
|
|
209
|
-
* amount, payTo) and the `settlementProbe` the adapter produced (or
|
|
210
|
-
* `undefined` for schemes with no on-chain confirmation). `payAndFetch`
|
|
211
|
-
* uses this to mark a payment as dispatched — so a post-payment abort is
|
|
212
|
-
* not misreported as a plain timeout — and keeps the probe so it can
|
|
213
|
-
* confirm settlement on-chain if the merchant never responds.
|
|
214
|
-
*
|
|
215
|
-
* Fire-and-forget — the return value is ignored, and a throw is swallowed
|
|
216
|
-
* (the payment proceeds regardless). Do not do slow work here.
|
|
217
|
-
*/
|
|
218
|
-
onPaymentDispatched?: (accept: PaymentAccept, settlementProbe?: SettlementProbe) => void;
|
|
219
|
-
/**
|
|
220
|
-
* Maximum retry attempts for transient failures (network errors, 502/503).
|
|
221
|
-
* Does not cause double payments — EIP-3009 nonces prevent replay.
|
|
222
|
-
* @default 0 (no retry)
|
|
223
|
-
*/
|
|
224
|
-
maxRetries?: number;
|
|
225
|
-
/**
|
|
226
|
-
* Base delay between retries in milliseconds (doubles each attempt).
|
|
227
|
-
* @default 500
|
|
228
|
-
*/
|
|
229
|
-
retryDelayMs?: number;
|
|
230
|
-
}
|
|
231
132
|
/**
|
|
232
133
|
* x402 Client interface
|
|
233
134
|
*
|
|
@@ -241,28 +142,5 @@ interface X402Client {
|
|
|
241
142
|
*/
|
|
242
143
|
fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
243
144
|
}
|
|
244
|
-
/**
|
|
245
|
-
* Create an x402 v2 client
|
|
246
|
-
*
|
|
247
|
-
* @deprecated Slated for removal in `@dexterai/x402` 5.0 (~6 months out — long
|
|
248
|
-
* cycle because of real production consumers). Use `payAndFetch` from
|
|
249
|
-
* `@dexterai/x402/client` instead — it's version-agnostic across x402 v1 and
|
|
250
|
-
* v2 and returns a discriminated union for cleaner error handling.
|
|
251
|
-
*
|
|
252
|
-
* Migration:
|
|
253
|
-
* ```typescript
|
|
254
|
-
* // Before
|
|
255
|
-
* const client = createX402Client({ wallets });
|
|
256
|
-
* const res = await client.fetch(url);
|
|
257
|
-
*
|
|
258
|
-
* // After
|
|
259
|
-
* import { payAndFetch } from '@dexterai/x402/client';
|
|
260
|
-
* const result = await payAndFetch(url, undefined, wallets);
|
|
261
|
-
* if (result.ok) {
|
|
262
|
-
* const res = result.response;
|
|
263
|
-
* }
|
|
264
|
-
* ```
|
|
265
|
-
*/
|
|
266
|
-
declare function createX402Client(config: X402ClientConfig): X402Client;
|
|
267
145
|
|
|
268
|
-
export { type PaymentReceipt as P, type
|
|
146
|
+
export { type PaymentReceipt as P, type X402Client as X, getSponsoredAccessInfo as a, getPaymentReceipt as b, fireImpressionBeacon as f, getSponsoredRecommendations as g };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dexterai/x402",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Full-stack x402 SDK - add paid API monetization to any endpoint. Express middleware, React hooks, Access Pass, dynamic pricing. Solana, Base, Polygon, Arbitrum, Optimism, Avalanche, SKALE.",
|
|
5
5
|
"author": "Dexter",
|
|
6
6
|
"license": "MIT",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"release:major": "npm version major && npm publish --access public"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@dexterai/vault": "^0.
|
|
79
|
+
"@dexterai/vault": "^0.13.0",
|
|
80
80
|
"@dexterai/x402-ads-types": "^0.2.0",
|
|
81
81
|
"@dexterai/x402-core": "^1.4.0",
|
|
82
82
|
"@noble/curves": "^1.9.7",
|