moltspay 1.4.1 → 1.6.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 +187 -0
- package/dist/cli/index.js +486 -152
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +483 -149
- package/dist/cli/index.mjs.map +1 -1
- package/dist/client/index.d.mts +5 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.js +245 -116
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +241 -114
- package/dist/client/index.mjs.map +1 -1
- package/dist/client/web/index.d.mts +418 -0
- package/dist/client/web/index.mjs +1289 -0
- package/dist/client/web/index.mjs.map +1 -0
- package/dist/facilitators/index.d.mts +24 -2
- package/dist/facilitators/index.d.ts +24 -2
- package/dist/facilitators/index.js +127 -13
- package/dist/facilitators/index.js.map +1 -1
- package/dist/facilitators/index.mjs +127 -13
- package/dist/facilitators/index.mjs.map +1 -1
- package/dist/index.js +463 -149
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +460 -146
- package/dist/index.mjs.map +1 -1
- package/dist/mcp/index.d.mts +1 -0
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.js +1623 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/index.mjs +1617 -0
- package/dist/mcp/index.mjs.map +1 -0
- package/dist/server/index.d.mts +43 -1
- package/dist/server/index.d.ts +43 -1
- package/dist/server/index.js +205 -18
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +205 -18
- package/dist/server/index.mjs.map +1 -1
- package/package.json +19 -4
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
import { PublicKey, Transaction } from '@solana/web3.js';
|
|
2
|
+
|
|
3
|
+
interface TypedDataDomain {
|
|
4
|
+
name?: string;
|
|
5
|
+
version?: string;
|
|
6
|
+
chainId?: number;
|
|
7
|
+
verifyingContract?: string;
|
|
8
|
+
salt?: string;
|
|
9
|
+
}
|
|
10
|
+
interface TypedDataField {
|
|
11
|
+
name: string;
|
|
12
|
+
type: string;
|
|
13
|
+
}
|
|
14
|
+
interface TypedDataEnvelope<TMessage = Record<string, unknown>> {
|
|
15
|
+
domain: TypedDataDomain;
|
|
16
|
+
types: Record<string, readonly TypedDataField[]>;
|
|
17
|
+
primaryType: string;
|
|
18
|
+
message: TMessage;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Chain identifier mapping — pure, runtime-agnostic.
|
|
23
|
+
*
|
|
24
|
+
* Translates between x402 `network` field values (CAIP-2 style, e.g.
|
|
25
|
+
* `eip155:8453`, `solana:mainnet`) and MoltsPay's internal chain names
|
|
26
|
+
* (e.g. `base`, `solana`, `tempo_moderato`).
|
|
27
|
+
*/
|
|
28
|
+
type ChainName = 'base' | 'polygon' | 'base_sepolia' | 'tempo_moderato' | 'bnb' | 'bnb_testnet' | 'solana' | 'solana_devnet';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Structured error classes used by both Node and Web clients.
|
|
32
|
+
*
|
|
33
|
+
* Every error carries a `code` field so callers can branch on the kind
|
|
34
|
+
* without string-matching `.message`.
|
|
35
|
+
*/
|
|
36
|
+
declare class MoltsPayError extends Error {
|
|
37
|
+
readonly code: string;
|
|
38
|
+
constructor(code: string, message: string);
|
|
39
|
+
}
|
|
40
|
+
declare class UnsupportedChainError extends MoltsPayError {
|
|
41
|
+
readonly chain: string;
|
|
42
|
+
constructor(chain: string, message?: string);
|
|
43
|
+
}
|
|
44
|
+
interface NeedsApprovalDetails {
|
|
45
|
+
chain: string;
|
|
46
|
+
spender: string;
|
|
47
|
+
token: string;
|
|
48
|
+
currentAllowance: string;
|
|
49
|
+
required: string;
|
|
50
|
+
}
|
|
51
|
+
declare class NeedsApprovalError extends MoltsPayError {
|
|
52
|
+
readonly details: NeedsApprovalDetails;
|
|
53
|
+
constructor(details: NeedsApprovalDetails, message?: string);
|
|
54
|
+
}
|
|
55
|
+
declare class InsufficientBalanceError extends MoltsPayError {
|
|
56
|
+
constructor(message: string);
|
|
57
|
+
}
|
|
58
|
+
declare class SpendingLimitExceededError extends MoltsPayError {
|
|
59
|
+
constructor(message: string);
|
|
60
|
+
}
|
|
61
|
+
declare class PaymentRejectedError extends MoltsPayError {
|
|
62
|
+
constructor(message: string);
|
|
63
|
+
}
|
|
64
|
+
declare class ServerError extends MoltsPayError {
|
|
65
|
+
readonly status: number;
|
|
66
|
+
constructor(status: number, message: string);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* PaymentSigner — runtime-agnostic signing interface.
|
|
71
|
+
*
|
|
72
|
+
* Implemented by:
|
|
73
|
+
* - `NodeSigner` (src/client/node/signer.ts) → wraps an ethers.Wallet + optional Solana Keypair
|
|
74
|
+
* - `eip1193Signer(provider)` (src/client/web/signers/eip1193.ts, Phase 4) → delegates to MetaMask / WalletConnect / etc.
|
|
75
|
+
* - `solanaSigner(adapter)` (src/client/web/signers/solana-adapter.ts, Phase 4) → delegates to @solana/wallet-adapter
|
|
76
|
+
* - `composeSigners(...)` (Phase 4) → routes per-method between multiple backing signers
|
|
77
|
+
*
|
|
78
|
+
* The interface is intentionally narrow:
|
|
79
|
+
* - `signTypedData` covers every EIP-712 signing path (EIP-3009 on Base/Polygon, EIP-2612 on Tempo, BNB PaymentIntent).
|
|
80
|
+
* - `sendEvmTransaction` covers BNB approve (and any future EVM writes). Optional because most signers only sign.
|
|
81
|
+
* - `signSolanaTransaction` covers Solana SPL transfer signing. Optional because not every signer supports Solana.
|
|
82
|
+
*
|
|
83
|
+
* Deliberately excluded: Tempo MPP's `Actions.token.transfer` path (uses viem's Tempo chain extension with custom
|
|
84
|
+
* `feeToken` semantics that do not map cleanly through a generic signer). The MPP flow stays Node-only and uses
|
|
85
|
+
* viem directly; the Web client does not implement MPP.
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
interface PaymentSigner {
|
|
89
|
+
/**
|
|
90
|
+
* Return the EVM address (0x-prefixed, checksummed or lowercase; callers should normalize as needed).
|
|
91
|
+
* Required for every EVM payment path (Base / Polygon / BNB).
|
|
92
|
+
*/
|
|
93
|
+
getEvmAddress(): Promise<string>;
|
|
94
|
+
/**
|
|
95
|
+
* Return the Solana address (base58). Required only when paying on `solana` or `solana_devnet`.
|
|
96
|
+
* Implementations that don't support Solana should omit or return `null`.
|
|
97
|
+
*/
|
|
98
|
+
getSolanaAddress?(): Promise<string | null>;
|
|
99
|
+
/**
|
|
100
|
+
* Sign an EIP-712 typed-data envelope. Used for:
|
|
101
|
+
* - EIP-3009 TransferWithAuthorization (Base / Polygon / Base Sepolia)
|
|
102
|
+
* - EIP-2612 Permit (Tempo Moderato)
|
|
103
|
+
* - BNB MoltsPay PaymentIntent
|
|
104
|
+
*
|
|
105
|
+
* Returns a 0x-prefixed 65-byte (r||s||v) signature.
|
|
106
|
+
*/
|
|
107
|
+
signTypedData<TMessage>(envelope: TypedDataEnvelope<TMessage>): Promise<string>;
|
|
108
|
+
/**
|
|
109
|
+
* Send a raw EVM transaction and return its hash. Used for the BNB `approve` flow only in the
|
|
110
|
+
* initial release; future versions may use it for other write paths.
|
|
111
|
+
*
|
|
112
|
+
* `chainId` allows the signer to switch chains (e.g. EIP-1193 `wallet_switchEthereumChain`).
|
|
113
|
+
* `value` is hex-encoded wei; omitted when zero.
|
|
114
|
+
*
|
|
115
|
+
* Optional — omit on signers that cannot submit transactions (e.g. a read-only Ledger).
|
|
116
|
+
*/
|
|
117
|
+
sendEvmTransaction?(args: {
|
|
118
|
+
chainId: number;
|
|
119
|
+
to: string;
|
|
120
|
+
data: string;
|
|
121
|
+
value?: string;
|
|
122
|
+
}): Promise<string>;
|
|
123
|
+
/**
|
|
124
|
+
* Sign a Solana transaction without submitting it. Server submits.
|
|
125
|
+
*
|
|
126
|
+
* `transactionBase64` is the serialized unsigned transaction (produced by
|
|
127
|
+
* `createSolanaPaymentTransaction` in core/solana-tx.ts).
|
|
128
|
+
* `partialSign` is `true` when the server specified a `feePayer` and the wallet is only signing
|
|
129
|
+
* for token-transfer authority (gasless Solana mode); `false` means the wallet is paying fees too.
|
|
130
|
+
*
|
|
131
|
+
* Returns the serialized signed transaction as base64.
|
|
132
|
+
*/
|
|
133
|
+
signSolanaTransaction?(args: {
|
|
134
|
+
transactionBase64: string;
|
|
135
|
+
partialSign: boolean;
|
|
136
|
+
}): Promise<string>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface ServiceInfo {
|
|
140
|
+
id: string;
|
|
141
|
+
name: string;
|
|
142
|
+
description?: string;
|
|
143
|
+
price: number;
|
|
144
|
+
currency: string;
|
|
145
|
+
input: Record<string, any>;
|
|
146
|
+
output: Record<string, any>;
|
|
147
|
+
available: boolean;
|
|
148
|
+
provider?: ProviderInfo;
|
|
149
|
+
endpoint?: string;
|
|
150
|
+
}
|
|
151
|
+
interface ProviderInfo {
|
|
152
|
+
name: string;
|
|
153
|
+
username?: string;
|
|
154
|
+
description?: string;
|
|
155
|
+
wallet: string;
|
|
156
|
+
chain?: string;
|
|
157
|
+
chains?: string[] | {
|
|
158
|
+
chain: string;
|
|
159
|
+
}[];
|
|
160
|
+
}
|
|
161
|
+
interface ServicesResponse {
|
|
162
|
+
provider?: ProviderInfo;
|
|
163
|
+
services: ServiceInfo[];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Browser-side spending limits — optional opt-in only. Mirrors the Node
|
|
168
|
+
* CLI's daily-reset ledger but persists to `localStorage` instead of
|
|
169
|
+
* `~/.moltspay/spending.json`.
|
|
170
|
+
*
|
|
171
|
+
* Default: disabled. Rationale (from docs/WEB-CLIENT-DESIGN.md §Spending
|
|
172
|
+
* Limits on Web): external wallets already enforce per-signature policy,
|
|
173
|
+
* per-browser localStorage limits don't sync, and the UX of silently
|
|
174
|
+
* blocking a payment without consulting the wallet is worse than just
|
|
175
|
+
* letting the wallet prompt. Apps that want session-level caps can still
|
|
176
|
+
* opt in.
|
|
177
|
+
*/
|
|
178
|
+
interface SpendingLimitsConfig {
|
|
179
|
+
/** Maximum per single transaction. Currency-agnostic; measured in service units (USD). */
|
|
180
|
+
maxPerTx: number;
|
|
181
|
+
/** Maximum aggregate across the current calendar day (local time). */
|
|
182
|
+
maxPerDay: number;
|
|
183
|
+
/** `localStorage` key. Default: `moltspay:spending`. */
|
|
184
|
+
storageKey?: string;
|
|
185
|
+
}
|
|
186
|
+
declare class SpendingLedger {
|
|
187
|
+
private readonly storageKey;
|
|
188
|
+
private readonly maxPerTx;
|
|
189
|
+
private readonly maxPerDay;
|
|
190
|
+
constructor(config: SpendingLimitsConfig);
|
|
191
|
+
/** Load the persisted total for today. Fails silently on parse errors. */
|
|
192
|
+
private read;
|
|
193
|
+
private write;
|
|
194
|
+
/**
|
|
195
|
+
* Throw `SpendingLimitExceededError` if the requested charge would push
|
|
196
|
+
* per-tx or per-day limits over. Does NOT mutate state — callers record
|
|
197
|
+
* only after the payment clears via {@link record}.
|
|
198
|
+
*/
|
|
199
|
+
check(amount: number): void;
|
|
200
|
+
/** Persist a successful charge. Silently no-ops in non-browser runtimes. */
|
|
201
|
+
record(amount: number): void;
|
|
202
|
+
/** Current aggregate for the active day. Intended for UI display. */
|
|
203
|
+
get todaySpending(): number;
|
|
204
|
+
/** Manually reset — mainly useful for tests. */
|
|
205
|
+
reset(): void;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* EIP-1193 signer adapter — wraps `window.ethereum`-style providers into the
|
|
210
|
+
* runtime-agnostic `PaymentSigner` interface.
|
|
211
|
+
*
|
|
212
|
+
* Works with any EIP-1193 provider: MetaMask, Coinbase Wallet, Rainbow,
|
|
213
|
+
* Frame, a WalletConnect transport, etc. The caller supplies the provider;
|
|
214
|
+
* this module never imports a specific wallet connector.
|
|
215
|
+
*
|
|
216
|
+
* Methods used:
|
|
217
|
+
* - `eth_requestAccounts` (getEvmAddress)
|
|
218
|
+
* - `eth_signTypedData_v4` (signTypedData)
|
|
219
|
+
* - `wallet_switchEthereumChain` (sendEvmTransaction pre-flight; EIP-3326)
|
|
220
|
+
* - `wallet_addEthereumChain` (fallback when target chain is unknown; EIP-3085)
|
|
221
|
+
* - `eth_sendTransaction` (sendEvmTransaction)
|
|
222
|
+
*/
|
|
223
|
+
|
|
224
|
+
/** Minimal EIP-1193 provider shape. */
|
|
225
|
+
interface Eip1193Provider {
|
|
226
|
+
request(args: {
|
|
227
|
+
method: string;
|
|
228
|
+
params?: unknown[] | object;
|
|
229
|
+
}): Promise<unknown>;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Chain metadata passed alongside `sendEvmTransaction` so the signer can add
|
|
233
|
+
* the chain to the wallet if it is not already known. Required for Tempo /
|
|
234
|
+
* BNB which MetaMask does not ship preconfigured.
|
|
235
|
+
*
|
|
236
|
+
* Keyed by decimal chainId. The signer consults this table only when
|
|
237
|
+
* `wallet_switchEthereumChain` returns the "unknown chain" error (code 4902).
|
|
238
|
+
*/
|
|
239
|
+
interface Eip1193ChainMetadata {
|
|
240
|
+
chainName: string;
|
|
241
|
+
rpcUrls: string[];
|
|
242
|
+
nativeCurrency: {
|
|
243
|
+
name: string;
|
|
244
|
+
symbol: string;
|
|
245
|
+
decimals: number;
|
|
246
|
+
};
|
|
247
|
+
blockExplorerUrls?: string[];
|
|
248
|
+
}
|
|
249
|
+
interface Eip1193SignerOptions {
|
|
250
|
+
/** Optional chain registry for `wallet_addEthereumChain` fallbacks. */
|
|
251
|
+
addChainMetadata?: Record<number, Eip1193ChainMetadata>;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Build an EIP-1193-backed `PaymentSigner`.
|
|
255
|
+
*
|
|
256
|
+
* The returned signer is stateless — every method issues a fresh provider
|
|
257
|
+
* request so account changes (user switches wallet, locks, etc.) are picked
|
|
258
|
+
* up on the next call. The caller is free to wrap this in their own cache if
|
|
259
|
+
* account drift mid-session is a concern.
|
|
260
|
+
*/
|
|
261
|
+
declare function eip1193Signer(provider: Eip1193Provider, options?: Eip1193SignerOptions): PaymentSigner;
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Solana wallet-adapter signer — wraps a wallet adapter (Phantom, Solflare,
|
|
265
|
+
* Backpack, any `@solana/wallet-adapter` compatible object) into a
|
|
266
|
+
* `PaymentSigner`.
|
|
267
|
+
*
|
|
268
|
+
* We intentionally accept only the subset of the WalletAdapter interface we
|
|
269
|
+
* actually use (`publicKey` + `signTransaction`) so the caller doesn't have
|
|
270
|
+
* to pull in the full `@solana/wallet-adapter-base` type transitively.
|
|
271
|
+
*
|
|
272
|
+
* Behavior matches `NodeSigner.signSolanaTransaction`:
|
|
273
|
+
* - The wallet signs the serialized transaction and returns it base64-encoded.
|
|
274
|
+
* - We never submit — the server does, after the x402 payload lands.
|
|
275
|
+
* - `partialSign: true` is passed through to the adapter so the server's fee
|
|
276
|
+
* payer signature is preserved (gasless Solana mode).
|
|
277
|
+
*/
|
|
278
|
+
|
|
279
|
+
/** Minimal Solana wallet-adapter shape the signer needs. */
|
|
280
|
+
interface SolanaSignerAdapter {
|
|
281
|
+
/** Connected account's public key, or `null` if disconnected. */
|
|
282
|
+
publicKey: PublicKey | null;
|
|
283
|
+
/**
|
|
284
|
+
* Signs a legacy Solana `Transaction` and returns the same transaction with
|
|
285
|
+
* signatures attached. Wallet adapters already implement this — we simply
|
|
286
|
+
* delegate. We do NOT use `signAllTransactions` or `signMessage`.
|
|
287
|
+
*/
|
|
288
|
+
signTransaction(tx: Transaction): Promise<Transaction>;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Build a `PaymentSigner` backed by a Solana wallet adapter.
|
|
292
|
+
*
|
|
293
|
+
* The returned signer exposes only Solana capabilities — `getEvmAddress`
|
|
294
|
+
* throws, because the Web Client dispatches by chain and never asks a Solana
|
|
295
|
+
* signer to sign EVM data. To support both EVM and Solana in one client,
|
|
296
|
+
* compose this with `eip1193Signer` via `composeSigners`.
|
|
297
|
+
*/
|
|
298
|
+
declare function solanaSigner(adapter: SolanaSignerAdapter): PaymentSigner;
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* `composeSigners` — merge multiple `PaymentSigner`s into one, routing each
|
|
302
|
+
* method to the first underlying signer that can service it.
|
|
303
|
+
*
|
|
304
|
+
* Typical use: a dApp wants to pay on both EVM chains (via MetaMask) and
|
|
305
|
+
* Solana (via Phantom) from the same `MoltsPayWebClient` instance. Rather
|
|
306
|
+
* than re-instantiating the client per chain, the app composes the two:
|
|
307
|
+
*
|
|
308
|
+
* const client = new MoltsPayWebClient({
|
|
309
|
+
* signer: composeSigners(
|
|
310
|
+
* eip1193Signer(window.ethereum),
|
|
311
|
+
* solanaSigner(phantomAdapter),
|
|
312
|
+
* ),
|
|
313
|
+
* });
|
|
314
|
+
*
|
|
315
|
+
* Routing rule: for each method (`getEvmAddress`, `signTypedData`,
|
|
316
|
+
* `sendEvmTransaction`, `getSolanaAddress`, `signSolanaTransaction`), pick
|
|
317
|
+
* the first signer in argument order whose method returns a successful
|
|
318
|
+
* result. "Successful" = the method is defined on the signer AND does not
|
|
319
|
+
* throw the sentinel `NOT_SUPPORTED` error the adapters emit for off-chain
|
|
320
|
+
* methods (`solanaSigner.getEvmAddress` throws plainly, and that throw is
|
|
321
|
+
* caught and tried on the next signer).
|
|
322
|
+
*
|
|
323
|
+
* Falls through to the last signer's error if none match, so callers still
|
|
324
|
+
* see an actionable message.
|
|
325
|
+
*/
|
|
326
|
+
|
|
327
|
+
declare function composeSigners(...signers: PaymentSigner[]): PaymentSigner;
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* MoltsPay Web Client
|
|
331
|
+
*
|
|
332
|
+
* Browser-native companion to `MoltsPayClient` (Node). The two share one
|
|
333
|
+
* protocol core (`src/client/core/`) — every x402 detail, typed-data builder,
|
|
334
|
+
* and chain mapping is identical. The Web Client differs only in that:
|
|
335
|
+
*
|
|
336
|
+
* - It never reads or writes a wallet file. All signing is delegated to an
|
|
337
|
+
* injected `PaymentSigner` (an EIP-1193 / wallet-adapter shim the app owns).
|
|
338
|
+
* - It always posts to `/execute` and consumes `X-Payment-Required`. It
|
|
339
|
+
* never negotiates MPP over `WWW-Authenticate` — Tempo is reached via the
|
|
340
|
+
* EIP-2612 permit branch instead. See docs/WEB-CLIENT-DESIGN.md §Tempo.
|
|
341
|
+
* - Spending limits are opt-in and backed by `localStorage` when enabled.
|
|
342
|
+
*/
|
|
343
|
+
|
|
344
|
+
interface MoltsPayWebClientOptions {
|
|
345
|
+
/** PaymentSigner to authorize every payment. Typically `eip1193Signer(window.ethereum)` or `composeSigners(...)`. */
|
|
346
|
+
signer: PaymentSigner;
|
|
347
|
+
/** Default chain for `pay()` when the server accepts multiple and the caller omits `options.chain`. */
|
|
348
|
+
defaultChain?: ChainName;
|
|
349
|
+
/** Enable `localStorage`-backed spending limits. Off by default. */
|
|
350
|
+
spendingLimits?: SpendingLimitsConfig;
|
|
351
|
+
/** Optional fetch override — useful for MSW tests or proxying. Defaults to `globalThis.fetch`. */
|
|
352
|
+
fetch?: typeof fetch;
|
|
353
|
+
/**
|
|
354
|
+
* Per-chain Solana RPC URL override. Required on mainnet in practice —
|
|
355
|
+
* the public `api.mainnet-beta.solana.com` endpoint returns 403 to browser
|
|
356
|
+
* requests. Point at Helius / QuickNode / Alchemy etc. Falls back to
|
|
357
|
+
* `SOLANA_CHAINS[chain].rpc` when omitted.
|
|
358
|
+
*/
|
|
359
|
+
solanaRpc?: {
|
|
360
|
+
solana?: string;
|
|
361
|
+
solana_devnet?: string;
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
interface WebPayOptions {
|
|
365
|
+
/** Chain to pay on. Required when the server accepts more than one. */
|
|
366
|
+
chain?: ChainName;
|
|
367
|
+
/** Send user params at top level (`{ service, ...params }`) instead of wrapped (`{ service, params }`). */
|
|
368
|
+
rawData?: boolean;
|
|
369
|
+
}
|
|
370
|
+
declare class MoltsPayWebClient {
|
|
371
|
+
private readonly signer;
|
|
372
|
+
private readonly defaultChain?;
|
|
373
|
+
private readonly ledger;
|
|
374
|
+
private readonly fetchImpl;
|
|
375
|
+
private readonly solanaRpc?;
|
|
376
|
+
constructor(options: MoltsPayWebClientOptions);
|
|
377
|
+
private getSolanaConnection;
|
|
378
|
+
/** Fetch a provider's service manifest. Mirrors `MoltsPayClient.getServices`. */
|
|
379
|
+
getServices(serverUrl: string): Promise<ServicesResponse>;
|
|
380
|
+
/**
|
|
381
|
+
* Pay for a service via x402. Returns the service `result` field (or the
|
|
382
|
+
* whole JSON body if the server doesn't wrap). Throws `NeedsApprovalError`
|
|
383
|
+
* for BNB when allowance is insufficient — call {@link approveBnb} and retry.
|
|
384
|
+
*/
|
|
385
|
+
pay(serverUrl: string, service: string, params: Record<string, unknown>, options?: WebPayOptions): Promise<Record<string, unknown>>;
|
|
386
|
+
/** Read-only balance check on the specified chain (or `defaultChain` if configured). */
|
|
387
|
+
getBalance(chain?: ChainName): Promise<{
|
|
388
|
+
usdc: number;
|
|
389
|
+
usdt?: number;
|
|
390
|
+
native: number;
|
|
391
|
+
}>;
|
|
392
|
+
/**
|
|
393
|
+
* Approve a spender for the BNB chain's USDC / USDT (one-time, costs BNB gas).
|
|
394
|
+
* The spender address is what the server advertised as `bnbSpender` in the
|
|
395
|
+
* 402 response. Amount defaults to `MaxUint256` so only one approval is ever
|
|
396
|
+
* needed per (chain, token, spender) tuple.
|
|
397
|
+
*/
|
|
398
|
+
approveBnb(args: {
|
|
399
|
+
chain: 'bnb' | 'bnb_testnet';
|
|
400
|
+
spender: string;
|
|
401
|
+
token: 'USDC' | 'USDT';
|
|
402
|
+
amount?: string;
|
|
403
|
+
}): Promise<string>;
|
|
404
|
+
private resolveExecuteUrl;
|
|
405
|
+
private buildRequestBody;
|
|
406
|
+
private chooseChain;
|
|
407
|
+
/**
|
|
408
|
+
* Submit the x402 payload and return the service result. Shared by all
|
|
409
|
+
* scheme branches — the only thing they vary is how they build `payload`.
|
|
410
|
+
*/
|
|
411
|
+
private submitPayment;
|
|
412
|
+
private payEIP3009;
|
|
413
|
+
private payTempoPermit;
|
|
414
|
+
private payBnb;
|
|
415
|
+
private paySolana;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
export { type ChainName, type Eip1193ChainMetadata, type Eip1193Provider, type Eip1193SignerOptions, InsufficientBalanceError, MoltsPayError, MoltsPayWebClient, type MoltsPayWebClientOptions, NeedsApprovalError, PaymentRejectedError, type PaymentSigner, ServerError, type SolanaSignerAdapter, SpendingLedger, SpendingLimitExceededError, type SpendingLimitsConfig, UnsupportedChainError, type WebPayOptions, composeSigners, eip1193Signer, solanaSigner };
|