@cosmosapp/pay_sdk 1.0.0 → 1.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.
@@ -0,0 +1,758 @@
1
+ import { X as WalletId, P as PaymentIntentData, h as CreatePayPaymentIntentOptions, g as CreateTxPaymentIntentOptions, V as ValidationOutcomeData } from '../intent-input-Caauq1Vl.js';
2
+ export { x as AddressBook, y as AddressRef, I as AssetDefinition, J as AssetRef, K as Assets, M as CosmosPayAPIError, N as CosmosPayRequestError, R as ResolvableIntentInput, S as ResolvedAsset, T as TestnetAssets, Y as Wallets, $ as addresses, a0 as assertAddress, a1 as defineAsset, a2 as isAddress, a3 as isContractAddress, a4 as isMuxedAddress, a5 as isNativeAsset, a6 as isStellarAddress, a7 as resolveAddress, a8 as resolveAsset, a9 as resolveIntentBody } from '../intent-input-Caauq1Vl.js';
3
+
4
+ /**
5
+ * Types for the browser ("web client") side of the SDK.
6
+ *
7
+ * The web client never talks to a Stellar wallet through SEP-7 deep links —
8
+ * Freighter, xBull, Albedo, Rabet & co. don't consume `web+stellar:` URIs from
9
+ * a dapp. Instead the SDK *adapts* the Cosmos Pay response into a concrete
10
+ * Stellar transaction (XDR) and asks the detected wallet to sign it. These
11
+ * types describe that flow.
12
+ */
13
+
14
+ /** The Stellar network a transaction targets. */
15
+ type StellarNetwork = 'public' | 'testnet';
16
+ /** Fully-resolved network parameters used to build, sign and submit. */
17
+ interface NetworkConfig {
18
+ /** `public` (mainnet) or `testnet`. */
19
+ network: StellarNetwork;
20
+ /** Network passphrase, e.g. `Public Global Stellar Network ; September 2015`. */
21
+ passphrase: string;
22
+ /** Horizon base URL used to load accounts and submit transactions. */
23
+ horizonUrl: string;
24
+ }
25
+ /**
26
+ * Parsed parameters of a SEP-7 `web+stellar:` URI. The Cosmos Pay API returns
27
+ * such a URI on every intent; the web client can act on either the structured
28
+ * {@link PaymentIntentData} or the raw URI string.
29
+ */
30
+ interface Sep7Request {
31
+ operation: 'tx' | 'pay';
32
+ /** `tx` only: base64 TransactionEnvelope XDR. */
33
+ xdr?: string;
34
+ /** `pay` only: payee account / muxed account. */
35
+ destination?: string;
36
+ /** `pay` only: amount the destination receives. */
37
+ amount?: string;
38
+ /** `pay` only: asset code (absent ⇒ native XLM). */
39
+ assetCode?: string;
40
+ /** `pay` only: issuer of a non-native asset. */
41
+ assetIssuer?: string;
42
+ /** Memo value. */
43
+ memo?: string;
44
+ /** `MEMO_ID` | `MEMO_TEXT` | `MEMO_HASH` | `MEMO_RETURN`. */
45
+ memoType?: string;
46
+ /** Human-readable message shown to the user (≤ 300 chars). */
47
+ msg?: string;
48
+ /** `url:https://…` callback the signed XDR should be POSTed to. */
49
+ callback?: string;
50
+ /** Network passphrase for non-public networks. */
51
+ networkPassphrase?: string;
52
+ originDomain?: string;
53
+ signature?: string;
54
+ }
55
+ /**
56
+ * A normalized, wallet-agnostic view of "what to pay". The web client coerces
57
+ * every accepted input — the server's {@link PaymentIntentData}, a parsed
58
+ * {@link Sep7Request}, or a raw SEP-7 URI string — into this shape before
59
+ * building a transaction.
60
+ */
61
+ interface NormalizedIntent {
62
+ /** `tx` (source known, XDR present) or `pay` (wallet supplies the source). */
63
+ kind: 'tx' | 'pay';
64
+ /** Intent id, when acting on a {@link PaymentIntentData}. */
65
+ id?: string;
66
+ /** Network hint carried by the intent, if any (passphrase or label). */
67
+ network: string | null;
68
+ /** Payer account. `null` for `pay` intents (the connected wallet supplies it). */
69
+ source: string | null;
70
+ destination: string;
71
+ /** Decimal amount string, or `null` when the user must enter it. */
72
+ amount: string | null;
73
+ /** Asset code, or `native` for XLM. */
74
+ asset: string;
75
+ assetIssuer: string | null;
76
+ /** Memo value (MEMO_ID by default). */
77
+ memo: string | null;
78
+ memoType: string | null;
79
+ msg: string | null;
80
+ callback: string | null;
81
+ /** Unsigned envelope (base64 XDR); `null` for `pay` intents. */
82
+ xdr: string | null;
83
+ /** The originating SEP-7 URI, when known. */
84
+ uri: string | null;
85
+ }
86
+ /**
87
+ * Anything the web client accepts as "the thing to pay": a server
88
+ * {@link PaymentIntentData}, an already-parsed {@link Sep7Request}, a raw SEP-7
89
+ * URI string, or any object exposing a `toJSON()` returning a
90
+ * {@link PaymentIntentData} (e.g. a {@link PaymentIntent} structure instance).
91
+ */
92
+ type PayableInput = PaymentIntentData | Sep7Request | string | {
93
+ toJSON(): PaymentIntentData;
94
+ };
95
+ /** Lightweight descriptor of a wallet, as surfaced by detection. */
96
+ interface WalletInfo {
97
+ /** Stable id, e.g. `freighter`, `xbull`, `albedo`, `rabet`, `lobstr`. */
98
+ id: string;
99
+ /** Human-readable name. */
100
+ name: string;
101
+ /** Optional icon (data URL or remote URL). */
102
+ icon?: string;
103
+ /** Whether the wallet is currently usable (extension injected / lib present). */
104
+ available: boolean;
105
+ }
106
+ /** Parameters passed to {@link WalletAdapter.signTransaction}. */
107
+ interface SignParams {
108
+ /** Network passphrase the wallet must sign for. */
109
+ networkPassphrase: string;
110
+ /** `public` / `testnet`, for wallets whose API takes a label not a passphrase. */
111
+ network: StellarNetwork;
112
+ /** Account expected to sign (helps multi-account wallets pick the right key). */
113
+ address?: string;
114
+ }
115
+ /**
116
+ * A pluggable wallet integration. The SDK ships adapters for the most common
117
+ * Stellar wallets and auto-detects the right one, but you can register your own
118
+ * (WalletConnect, Ledger, a custom signer…) via {@link WebClient.registerWallet}.
119
+ */
120
+ interface WalletAdapter {
121
+ /** Stable id (used for selection and {@link WalletInfo.id}). */
122
+ readonly id: string;
123
+ /** Human-readable name. */
124
+ readonly name: string;
125
+ /** Optional icon. */
126
+ readonly icon?: string;
127
+ /**
128
+ * Whether this wallet is usable right now (e.g. the browser extension injected
129
+ * its global, or the wallet's library was provided). Must never throw.
130
+ */
131
+ isAvailable(): Promise<boolean>;
132
+ /** Connect (requesting permission if needed) and return the user's `G…` address. */
133
+ getPublicKey(network: NetworkConfig): Promise<string>;
134
+ /** Sign an unsigned XDR and return the signed XDR (base64). */
135
+ signTransaction(xdr: string, params: SignParams): Promise<string>;
136
+ /** Optional: tear down any connection/session. */
137
+ disconnect?(): Promise<void>;
138
+ }
139
+ /** Result of {@link WebClient.connect}. */
140
+ interface ConnectResult {
141
+ /** Id of the wallet that connected. */
142
+ wallet: string;
143
+ /** Connected `G…` account. */
144
+ address: string;
145
+ /** Network the wallet reported / the client resolved. */
146
+ network: StellarNetwork;
147
+ }
148
+ /** Options for {@link WebClient.pay} (and the lower-level builders). */
149
+ interface PayOptions {
150
+ /**
151
+ * Force a specific wallet by id (e.g. `Wallets.FREIGHTER`). By default the
152
+ * client auto-detects — you don't need to pass this.
153
+ */
154
+ wallet?: WalletId;
155
+ /**
156
+ * Override / supply the amount for an open `pay` intent (one created without a
157
+ * fixed amount, e.g. a donation).
158
+ */
159
+ amount?: string;
160
+ /**
161
+ * For `pay` intents, the source account to build from. Defaults to the
162
+ * connected wallet's address — you normally never set this.
163
+ */
164
+ source?: string;
165
+ /** Skip Horizon submission and just return the signed XDR. */
166
+ sign?: boolean;
167
+ /**
168
+ * Whether to submit the signed transaction. Defaults to `true` unless the
169
+ * intent carries a SEP-7 `callback` (in which case the signed XDR is POSTed
170
+ * there instead).
171
+ */
172
+ submit?: boolean;
173
+ /** Per-call `AbortSignal`. */
174
+ signal?: AbortSignal;
175
+ }
176
+ /** Outcome of a full {@link WebClient.pay} flow. */
177
+ interface PayResult {
178
+ /** Intent id, when paying a {@link PaymentIntentData}. */
179
+ intentId?: string;
180
+ /** Id of the wallet that signed. */
181
+ wallet: string;
182
+ /** Account that signed (the source). */
183
+ account: string;
184
+ /** Network used. */
185
+ network: StellarNetwork;
186
+ /** The signed transaction envelope (base64 XDR). */
187
+ signedXdr: string;
188
+ /** The transaction hash (hex) — stable whether submitted to Horizon or a callback. */
189
+ txHash: string;
190
+ /** Whether the transaction was broadcast (to Horizon or the SEP-7 callback). */
191
+ submitted: boolean;
192
+ /** Raw Horizon (or callback) response, when submitted. */
193
+ response?: unknown;
194
+ }
195
+ /**
196
+ * A Stellar SDK module, structurally typed to just the surface the web client
197
+ * uses. Pass `@stellar/stellar-sdk` (or a compatible build) via
198
+ * `new WebClient({ stellarSdk })`, or install it and let the client import it.
199
+ */
200
+ interface StellarSdkLike {
201
+ TransactionBuilder: any;
202
+ Account: any;
203
+ Operation: any;
204
+ Asset: any;
205
+ Memo: any;
206
+ BASE_FEE?: string;
207
+ Networks?: Record<string, string>;
208
+ Horizon?: {
209
+ Server: any;
210
+ };
211
+ Server?: any;
212
+ [key: string]: any;
213
+ }
214
+
215
+ /**
216
+ * Freighter — https://www.freighter.app
217
+ *
218
+ * Talks to the extension's injected `window.freighterApi` directly (so the
219
+ * `@stellar/freighter-api` npm package is *not* required), and also accepts that
220
+ * package injected explicitly. Handles both the modern `{ value, error }`
221
+ * envelope API and the older bare-value API.
222
+ */
223
+
224
+ interface FreighterApi {
225
+ isConnected(): Promise<unknown>;
226
+ requestAccess?(): Promise<unknown>;
227
+ getAddress?(): Promise<unknown>;
228
+ getPublicKey?(): Promise<unknown>;
229
+ signTransaction(xdr: string, opts?: unknown): Promise<unknown>;
230
+ }
231
+ declare class FreighterAdapter implements WalletAdapter {
232
+ private readonly injected?;
233
+ readonly id = "freighter";
234
+ readonly name = "Freighter";
235
+ constructor(injected?: FreighterApi | undefined);
236
+ private api;
237
+ isAvailable(): Promise<boolean>;
238
+ getPublicKey(_network: NetworkConfig): Promise<string>;
239
+ signTransaction(xdr: string, params: SignParams): Promise<string>;
240
+ }
241
+
242
+ /**
243
+ * xBull — https://xbull.app
244
+ *
245
+ * Uses the extension-injected `window.xBullSDK` when present. You can also inject
246
+ * a compatible SDK instance (e.g. one obtained from
247
+ * `@creit.tech/xbull-wallet-connect`) for the web-app bridge fallback.
248
+ */
249
+
250
+ interface XBullSDK {
251
+ connect(permissions?: Record<string, boolean>): Promise<unknown>;
252
+ getPublicKey(): Promise<string>;
253
+ signXDR(xdr: string, options?: {
254
+ network?: string;
255
+ publicKey?: string;
256
+ }): Promise<string>;
257
+ closeConnections?(): void;
258
+ }
259
+ declare class XBullAdapter implements WalletAdapter {
260
+ private readonly injected?;
261
+ readonly id = "xbull";
262
+ readonly name = "xBull";
263
+ constructor(injected?: XBullSDK | undefined);
264
+ private sdk;
265
+ isAvailable(): Promise<boolean>;
266
+ getPublicKey(_network: NetworkConfig): Promise<string>;
267
+ signTransaction(xdr: string, params: SignParams): Promise<string>;
268
+ disconnect(): Promise<void>;
269
+ }
270
+
271
+ /**
272
+ * Rabet — https://rabet.io
273
+ *
274
+ * MetaMask-style injected provider at `window.rabet`. `connect()` returns the
275
+ * public key; `sign(xdr, network)` returns the signed XDR. Rabet uses the
276
+ * `mainnet` / `testnet` network labels.
277
+ */
278
+
279
+ interface RabetApi {
280
+ connect(): Promise<{
281
+ publicKey: string;
282
+ } | string>;
283
+ sign(xdr: string, network: string): Promise<{
284
+ xdr: string;
285
+ } | string>;
286
+ disconnect?(): Promise<void>;
287
+ }
288
+ declare class RabetAdapter implements WalletAdapter {
289
+ private readonly injected?;
290
+ readonly id = "rabet";
291
+ readonly name = "Rabet";
292
+ constructor(injected?: RabetApi | undefined);
293
+ private api;
294
+ isAvailable(): Promise<boolean>;
295
+ getPublicKey(_network: NetworkConfig): Promise<string>;
296
+ signTransaction(xdr: string, params: SignParams): Promise<string>;
297
+ disconnect(): Promise<void>;
298
+ }
299
+
300
+ /**
301
+ * LOBSTR — https://lobstr.co
302
+ *
303
+ * LOBSTR's vault extension is driven by the `@lobstrco/signer-extension-api`
304
+ * package (message-based, no simple injected global). Because of that it can't
305
+ * be reliably auto-detected from a global alone — pass the library in via
306
+ * `new WebClient({ lobstr: signerApi })` to enable it. LOBSTR signs for
307
+ * Stellar mainnet only.
308
+ */
309
+
310
+ interface LobstrApi {
311
+ isConnected(): Promise<boolean>;
312
+ getPublicKey(): Promise<string>;
313
+ signTransaction(xdr: string): Promise<string>;
314
+ }
315
+ declare class LobstrAdapter implements WalletAdapter {
316
+ private readonly api?;
317
+ readonly id = "lobstr";
318
+ readonly name = "LOBSTR";
319
+ constructor(api?: LobstrApi | undefined);
320
+ isAvailable(): Promise<boolean>;
321
+ getPublicKey(_network: NetworkConfig): Promise<string>;
322
+ signTransaction(xdr: string, _params: SignParams): Promise<string>;
323
+ }
324
+
325
+ /**
326
+ * Albedo — https://albedo.link
327
+ *
328
+ * Albedo has no browser extension; it works through a popup served from
329
+ * albedo.link, driven by the `@albedo-link/intent` library. It's therefore only
330
+ * "available" when that library is present — either as the UMD global
331
+ * `window.albedo` or injected explicitly via the constructor.
332
+ */
333
+
334
+ interface AlbedoIntent {
335
+ publicKey(params?: {
336
+ token?: string;
337
+ }): Promise<{
338
+ pubkey: string;
339
+ }>;
340
+ tx(params: {
341
+ xdr: string;
342
+ network?: string;
343
+ pubkey?: string;
344
+ submit?: boolean;
345
+ }): Promise<{
346
+ signed_envelope_xdr: string;
347
+ tx_hash?: string;
348
+ }>;
349
+ }
350
+ declare class AlbedoAdapter implements WalletAdapter {
351
+ private readonly injected?;
352
+ readonly id = "albedo";
353
+ readonly name = "Albedo";
354
+ constructor(injected?: AlbedoIntent | undefined);
355
+ private intent;
356
+ isAvailable(): Promise<boolean>;
357
+ getPublicKey(_network: NetworkConfig): Promise<string>;
358
+ signTransaction(xdr: string, params: SignParams): Promise<string>;
359
+ }
360
+
361
+ /**
362
+ * Built-in wallet adapters and the default registration set.
363
+ *
364
+ * Auto-detection order (first available wins): Freighter → xBull → Rabet →
365
+ * LOBSTR → Albedo. Freighter, xBull and Rabet inject browser globals so they're
366
+ * detected with zero configuration; LOBSTR and Albedo need their library passed
367
+ * in (no reliable global), so they only activate when injected.
368
+ */
369
+
370
+ /**
371
+ * Optional wallet libraries to enable wallets that have no auto-detectable
372
+ * global (LOBSTR, Albedo) or to use a non-extension transport (xBull web-app
373
+ * bridge). Everything here is optional — extension wallets need nothing.
374
+ */
375
+ interface InjectedWallets {
376
+ /** An `@stellar/freighter-api` module (otherwise `window.freighterApi`). */
377
+ freighter?: any;
378
+ /** An xBull SDK instance (otherwise `window.xBullSDK`). */
379
+ xBull?: any;
380
+ /** A Rabet provider (otherwise `window.rabet`). */
381
+ rabet?: any;
382
+ /** An `@albedo-link/intent` module/global (otherwise `window.albedo`). */
383
+ albedo?: any;
384
+ /** A `@lobstrco/signer-extension-api` module. */
385
+ lobstr?: any;
386
+ }
387
+ /**
388
+ * Build the default adapter set, honoring any injected wallet libraries. The
389
+ * order here is the auto-detection priority.
390
+ */
391
+ declare function defaultAdapters(injected?: InjectedWallets): WalletAdapter[];
392
+
393
+ /**
394
+ * Registry + auto-detection for wallet adapters.
395
+ *
396
+ * Holds adapters in priority order and picks the right one automatically — the
397
+ * caller never has to name a provider. Detection is just "ask each adapter if
398
+ * it's available, take the first that says yes," honoring an optional preference.
399
+ */
400
+
401
+ declare class WalletRegistry {
402
+ private readonly adapters;
403
+ constructor(adapters?: WalletAdapter[]);
404
+ /**
405
+ * Register (or replace, by id) a wallet adapter. By default it's appended at
406
+ * the lowest priority; pass `prepend` to make it win auto-detection.
407
+ */
408
+ register(adapter: WalletAdapter, prepend?: boolean): this;
409
+ /** Remove an adapter by id. */
410
+ unregister(id: string): this;
411
+ /** Get a registered adapter by id. */
412
+ get(id: string): WalletAdapter | undefined;
413
+ /** All registered adapter ids, in priority order. */
414
+ ids(): string[];
415
+ /** Probe every adapter and report which are available. */
416
+ list(): Promise<WalletInfo[]>;
417
+ /** The available adapters, in priority order. */
418
+ available(): Promise<WalletAdapter[]>;
419
+ /**
420
+ * Pick a wallet automatically. If `preferred` is given and available it wins;
421
+ * otherwise the first available adapter (in priority order) is returned.
422
+ * Throws {@link WalletNotFoundError} when nothing is available.
423
+ */
424
+ detect(preferred?: string): Promise<WalletAdapter>;
425
+ }
426
+
427
+ /**
428
+ * The browser ("web client") entry point of the SDK.
429
+ *
430
+ * Where the server-side {@link Client} just *creates* SEP-7 intents, the
431
+ * {@link WebClient} *completes* them in the browser: it auto-detects whichever
432
+ * Stellar wallet the user has (Freighter, xBull, Rabet, LOBSTR, Albedo, …),
433
+ * adapts the Cosmos Pay response into a concrete transaction the wallet can
434
+ * understand (these wallets don't consume SEP-7 URIs directly), asks for a
435
+ * signature, and optionally broadcasts it — all without you ever naming a
436
+ * provider.
437
+ *
438
+ * @example
439
+ * import { WebClient } from '@cosmosapp/pay_sdk/web';
440
+ *
441
+ * // `intent` is whatever your server returned from client.paymentIntents.createPay(...)
442
+ * const webClient = new WebClient();
443
+ * const result = await webClient.pay(intent); // detects the wallet, builds, signs, submits
444
+ * console.log(result.txHash, result.account);
445
+ */
446
+
447
+ /** Options for {@link WebClient}. Every field is optional. */
448
+ interface WebClientOptions extends InjectedWallets {
449
+ /**
450
+ * Replace the entire wallet adapter set. By default the common wallets are
451
+ * auto-registered; you rarely need this — use {@link WebClient.registerWallet}
452
+ * to add one instead.
453
+ */
454
+ wallets?: WalletAdapter[];
455
+ /** Reorder auto-detection priority by wallet id, e.g. `[Wallets.XBULL, Wallets.FREIGHTER]`. */
456
+ preferredWallets?: WalletId[];
457
+ /** Force the network instead of inferring it from the intent. */
458
+ network?: StellarNetwork;
459
+ /** Override the network passphrase. */
460
+ passphrase?: string;
461
+ /** Override the Horizon endpoint used to load accounts / submit. */
462
+ horizonUrl?: string;
463
+ /**
464
+ * Provide `@stellar/stellar-sdk` explicitly. Otherwise it's lazy-imported when
465
+ * needed (building a `pay` transaction, hashing, submitting to Horizon).
466
+ */
467
+ stellarSdk?: StellarSdkLike;
468
+ /** Base fee in stroops for built transactions (default: SDK `BASE_FEE`). */
469
+ baseFee?: string;
470
+ /** Validity window in seconds for built transactions (default 300). */
471
+ timeoutSeconds?: number;
472
+ /**
473
+ * Optional Cosmos Pay API key, enabling the convenience methods
474
+ * `createPay`/`createTx`/`validate` directly from the browser. ⚠️ Only use a
475
+ * key that's safe to expose client-side (e.g. a testnet `dv_` key); for
476
+ * production, create & validate intents on your server.
477
+ */
478
+ apiKey?: string;
479
+ /** Override the gateway base URL (advanced). */
480
+ baseURL?: string;
481
+ /** Override the API version segment (advanced). */
482
+ version?: string;
483
+ /** Per-request timeout in ms for the optional REST calls. */
484
+ timeout?: number;
485
+ /** Retries for the optional REST calls. */
486
+ retries?: number;
487
+ /** Extra headers for the optional REST calls. */
488
+ headers?: Record<string, string>;
489
+ /** Custom fetch implementation. */
490
+ fetch?: typeof fetch;
491
+ }
492
+ declare class WebClient {
493
+ /** The wallet adapter registry (auto-detection + custom registration). */
494
+ readonly wallets: WalletRegistry;
495
+ private readonly options;
496
+ private readonly injectedSdk?;
497
+ private readonly fetchFn;
498
+ private rest?;
499
+ /** The most recent successful connection (wallet + address + network). */
500
+ connection: ConnectResult | null;
501
+ constructor(options?: WebClientOptions);
502
+ /** Probe and list wallets, flagging which are currently available. */
503
+ getAvailableWallets(): Promise<WalletInfo[]>;
504
+ /** Register a custom wallet adapter (WalletConnect, Ledger, …). */
505
+ registerWallet(adapter: WalletAdapter, prepend?: boolean): this;
506
+ /**
507
+ * Auto-detect a wallet and connect, returning the account + network. You can
508
+ * skip this and call {@link pay} directly — it connects on demand.
509
+ */
510
+ connect(options?: {
511
+ wallet?: WalletId;
512
+ network?: StellarNetwork;
513
+ }): Promise<ConnectResult>;
514
+ /** Forget the current connection (and disconnect the adapter if it supports it). */
515
+ disconnect(): Promise<void>;
516
+ /**
517
+ * The one-call happy path: detect a wallet, adapt the intent into a
518
+ * transaction, sign it, and (unless told otherwise) broadcast it. Works for
519
+ * both `tx` intents (signs the returned XDR) and `pay` intents (builds the
520
+ * payment from the connected account).
521
+ */
522
+ pay(input: PayableInput, options?: PayOptions): Promise<PayResult>;
523
+ /**
524
+ * Adapt an intent into an unsigned transaction without signing it. Useful when
525
+ * you want to inspect/confirm the XDR before prompting the wallet.
526
+ */
527
+ buildTransaction(input: PayableInput, options?: PayOptions): Promise<{
528
+ xdr: string;
529
+ source: string;
530
+ intent: NormalizedIntent;
531
+ network: NetworkConfig;
532
+ }>;
533
+ /**
534
+ * Create a `pay` intent directly from the browser. Requires a browser-safe
535
+ * `apiKey` (trusted environments only). Accepts typed assets (`Assets.USDC`)
536
+ * and named addresses.
537
+ */
538
+ createPay(options: CreatePayPaymentIntentOptions): Promise<PaymentIntentData>;
539
+ /**
540
+ * Create a `tx` intent directly from the browser. Requires a browser-safe
541
+ * `apiKey` (trusted environments only). Accepts typed assets (`Assets.USDC`)
542
+ * and named addresses.
543
+ */
544
+ createTx(options: CreateTxPaymentIntentOptions): Promise<PaymentIntentData>;
545
+ /** Validate a submitted transaction against an intent. Requires an `apiKey`. */
546
+ validate(intentId: string, txHash: string): Promise<ValidationOutcomeData>;
547
+ /** Resolve the SDK (injected wins, else lazy-import). */
548
+ private sdk;
549
+ /** REST accessor that fails clearly when no apiKey was configured. */
550
+ private api;
551
+ /** Combine the intent's network hint with the client's overrides. */
552
+ private networkFor;
553
+ /** Turn a normalized intent into an unsigned XDR + the signing source. */
554
+ private prepare;
555
+ /** Best-effort transaction hash via the SDK (empty string if unavailable). */
556
+ private hashOf;
557
+ }
558
+
559
+ /**
560
+ * SEP-7 (`web+stellar:`) parsing and intent normalization.
561
+ *
562
+ * Cosmos Pay returns a SEP-7 URI for every intent. Browser wallets, however,
563
+ * don't ingest those URIs from a dapp — so the web client parses the URI (or
564
+ * the structured intent) into a {@link NormalizedIntent} it can turn into a
565
+ * concrete transaction and hand to a wallet for signing.
566
+ */
567
+
568
+ /** Whether a value is a SEP-7 `web+stellar:` URI string. */
569
+ declare function isSep7Uri(value: unknown): value is string;
570
+ /**
571
+ * Parse a `web+stellar:tx?…` / `web+stellar:pay?…` URI into its parameters.
572
+ * Throws {@link IntentError} on an unrecognized operation.
573
+ */
574
+ declare function parseSep7(uri: string): Sep7Request;
575
+ /**
576
+ * Coerce any accepted input — a {@link PaymentIntentData}, a structure with
577
+ * `toJSON()`, a parsed {@link Sep7Request}, or a raw SEP-7 URI string — into a
578
+ * {@link NormalizedIntent}. If the structured intent only exposes a URI, that
579
+ * URI is parsed and merged so callback/network details survive.
580
+ */
581
+ declare function normalizeIntent(input: PayableInput): NormalizedIntent;
582
+
583
+ /**
584
+ * Stellar network resolution.
585
+ *
586
+ * The web client has to figure out *which* network a payment targets (to pick
587
+ * the right passphrase, Horizon endpoint and wallet network label) without the
588
+ * integrator having to spell it out. It derives that from whatever the intent
589
+ * carries — a passphrase, a `PUBLIC`/`TESTNET` label, or a SEP-7
590
+ * `network_passphrase` — and falls back to public mainnet.
591
+ */
592
+
593
+ /** Canonical network passphrases. */
594
+ declare const PASSPHRASES: {
595
+ readonly public: "Public Global Stellar Network ; September 2015";
596
+ readonly testnet: "Test SDF Network ; September 2015";
597
+ };
598
+ /** Default Horizon endpoints maintained by SDF. */
599
+ declare const HORIZON_URLS: {
600
+ readonly public: "https://horizon.stellar.org";
601
+ readonly testnet: "https://horizon-testnet.stellar.org";
602
+ };
603
+ /**
604
+ * Best-effort classification of a free-form network hint into `public` /
605
+ * `testnet`. Accepts a passphrase, a label (`PUBLIC`, `mainnet`, `pubnet`…), or
606
+ * `null`. Defaults to `public`.
607
+ */
608
+ declare function classifyNetwork(hint: string | null | undefined): StellarNetwork;
609
+ /** Whether a string is a known full Stellar network passphrase. */
610
+ declare function isPassphrase(value: string | null | undefined): boolean;
611
+ /** Inputs that influence which {@link NetworkConfig} the client resolves to. */
612
+ interface ResolveNetworkInput {
613
+ /** Network hint from the intent (`network` field or SEP-7 passphrase). */
614
+ hint?: string | null;
615
+ /** Explicit override from the client options. */
616
+ network?: StellarNetwork;
617
+ /** Explicit passphrase override. */
618
+ passphrase?: string;
619
+ /** Explicit Horizon URL override. */
620
+ horizonUrl?: string;
621
+ }
622
+ /**
623
+ * Resolve a complete {@link NetworkConfig}. Explicit overrides win; otherwise we
624
+ * infer the network from the intent hint and fill in the canonical passphrase
625
+ * and Horizon endpoint.
626
+ */
627
+ declare function resolveNetwork(input?: ResolveNetworkInput): NetworkConfig;
628
+
629
+ /**
630
+ * The bridge to `@stellar/stellar-sdk`.
631
+ *
632
+ * The web client only needs the Stellar SDK for the cases a wallet can't do on
633
+ * its own: turning a Cosmos Pay `pay` intent into a concrete payment XDR,
634
+ * computing a transaction hash, and submitting to Horizon. To keep the package
635
+ * dependency-free for server users, the SDK is an *optional* peer dependency —
636
+ * it's lazy-imported on demand, or you can inject it via `new WebClient({
637
+ * stellarSdk })`.
638
+ */
639
+
640
+ /**
641
+ * Resolve the Stellar SDK: an injected module wins; otherwise we lazy-import
642
+ * `@stellar/stellar-sdk`. The specifier is assembled at runtime so bundlers and
643
+ * the type-checker don't treat the optional dependency as required.
644
+ */
645
+ declare function loadStellarSdk(injected?: StellarSdkLike): Promise<StellarSdkLike>;
646
+ /** Options for {@link buildPaymentXdr}. */
647
+ interface BuildPaymentInput {
648
+ intent: NormalizedIntent;
649
+ /** Source account (the connected wallet) the payment is built from. */
650
+ source: string;
651
+ /** Amount override (required when the intent has an open/null amount). */
652
+ amount?: string;
653
+ /** Base fee in stroops. Defaults to the SDK's `BASE_FEE`, then a Horizon probe. */
654
+ baseFee?: string;
655
+ /** Transaction validity window in seconds (default 300). */
656
+ timeoutSeconds?: number;
657
+ }
658
+ /**
659
+ * Build an unsigned payment transaction (base64 XDR) for a `pay` intent. Loads
660
+ * the source account from Horizon for the sequence number, then assembles a
661
+ * single `payment` operation with the intent's destination/asset/amount/memo.
662
+ */
663
+ declare function buildPaymentXdr(sdk: StellarSdkLike, network: NetworkConfig, input: BuildPaymentInput): Promise<string>;
664
+ /** Compute the canonical transaction hash (hex) of a signed envelope. */
665
+ declare function transactionHash(sdk: StellarSdkLike, signedXdr: string, passphrase: string): string;
666
+ /** Submit a signed envelope to Horizon. Returns the raw Horizon response. */
667
+ declare function submitToHorizon(sdk: StellarSdkLike, network: NetworkConfig, signedXdr: string): Promise<unknown>;
668
+ /**
669
+ * POST a signed envelope to a SEP-7 `callback` (`url:https://…`) as
670
+ * `application/x-www-form-urlencoded` with an `xdr` field, per SEP-7.
671
+ */
672
+ declare function postToCallback(callback: string, signedXdr: string, fetchFn?: typeof fetch): Promise<unknown>;
673
+
674
+ /**
675
+ * Errors surfaced by the browser ("web client") side of the SDK.
676
+ *
677
+ * These are intentionally kept separate from the server-side
678
+ * {@link CosmosPayAPIError}/{@link CosmosPayRequestError} so that bundling the
679
+ * web entry never pulls in Node-only code paths. They all extend
680
+ * {@link CosmosPayWebError} so a consumer can `catch (e) { if (e instanceof
681
+ * CosmosPayWebError) ... }`.
682
+ */
683
+ /** Base class for every error thrown by `@cosmosapp/pay_sdk/web`. */
684
+ declare class CosmosPayWebError extends Error {
685
+ constructor(message: string);
686
+ }
687
+ /** No compatible Stellar wallet could be detected in the current environment. */
688
+ declare class WalletNotFoundError extends CosmosPayWebError {
689
+ /** Ids of the wallets that were searched for. */
690
+ readonly searched: string[];
691
+ constructor(searched: string[]);
692
+ }
693
+ /** A wallet was found but the operation failed (user rejected, locked, etc.). */
694
+ declare class WalletError extends CosmosPayWebError {
695
+ /** Id of the wallet that produced the error (e.g. `freighter`). */
696
+ readonly wallet: string;
697
+ /** The underlying error, if any. */
698
+ readonly cause: unknown;
699
+ constructor(wallet: string, message: string, cause?: unknown);
700
+ }
701
+ /**
702
+ * Building a `pay` transaction (or submitting to Horizon) requires the Stellar
703
+ * SDK, which is an optional peer dependency. Thrown when it is neither installed
704
+ * nor injected.
705
+ */
706
+ declare class StellarSdkRequiredError extends CosmosPayWebError {
707
+ constructor(detail?: string);
708
+ }
709
+ /** The intent / SEP-7 request could not be interpreted or is missing data. */
710
+ declare class IntentError extends CosmosPayWebError {
711
+ constructor(message: string);
712
+ }
713
+
714
+ /**
715
+ * A tiny, browser-safe HTTP layer for the web client.
716
+ *
717
+ * Unlike the server-side {@link REST}, this one has zero Node dependencies (no
718
+ * `node:events`) so the web entry stays clean in any bundler. It reuses the
719
+ * shared error classes and powers the *optional* convenience methods of
720
+ * {@link WebClient} (`createPay`, `validate`, …) — the core sign/submit flow
721
+ * works without it.
722
+ */
723
+ /** Options for the browser REST client. */
724
+ interface WebRESTOptions {
725
+ baseURL: string;
726
+ apiKey?: string;
727
+ version?: string;
728
+ timeout?: number;
729
+ retries?: number;
730
+ headers?: Record<string, string>;
731
+ fetch?: typeof fetch;
732
+ }
733
+ /** Per-request options. */
734
+ interface WebRequestOptions {
735
+ query?: Record<string, string | number | boolean | undefined | null>;
736
+ body?: unknown;
737
+ headers?: Record<string, string>;
738
+ signal?: AbortSignal;
739
+ }
740
+ declare class WebREST {
741
+ baseURL: string;
742
+ readonly version: string;
743
+ private readonly timeout;
744
+ private readonly retries;
745
+ private readonly extraHeaders;
746
+ private readonly fetchFn;
747
+ private apiKey?;
748
+ constructor(options: WebRESTOptions);
749
+ setApiKey(apiKey: string): this;
750
+ get<T>(path: string, options?: WebRequestOptions): Promise<T>;
751
+ post<T>(path: string, options?: WebRequestOptions): Promise<T>;
752
+ patch<T>(path: string, options?: WebRequestOptions): Promise<T>;
753
+ private buildURL;
754
+ private buildHeaders;
755
+ request<T>(method: string, path: string, options?: WebRequestOptions): Promise<T>;
756
+ }
757
+
758
+ export { AlbedoAdapter, type BuildPaymentInput, type ConnectResult, CosmosPayWebError, FreighterAdapter, HORIZON_URLS, type InjectedWallets, IntentError, LobstrAdapter, type NetworkConfig, type NormalizedIntent, PASSPHRASES, type PayOptions, type PayResult, type PayableInput, PaymentIntentData, RabetAdapter, type ResolveNetworkInput, type Sep7Request, type SignParams, type StellarNetwork, type StellarSdkLike, StellarSdkRequiredError, type WalletAdapter, WalletError, WalletId, type WalletInfo, WalletNotFoundError, WalletRegistry, WebClient, type WebClientOptions, WebREST, type WebRESTOptions, type WebRequestOptions, XBullAdapter, buildPaymentXdr, classifyNetwork, defaultAdapters, isPassphrase, isSep7Uri, loadStellarSdk, normalizeIntent, parseSep7, postToCallback, resolveNetwork, submitToHorizon, transactionHash };