@cosmosapp/pay_sdk 2.3.2 → 2.4.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/CHANGELOG.md +19 -0
- package/README.md +97 -61
- package/dist/{chunk-U3WDM2FJ.js → chunk-6FIALX2E.js} +3 -3
- package/dist/{chunk-U3WDM2FJ.js.map → chunk-6FIALX2E.js.map} +1 -1
- package/dist/chunk-ALFITFBN.js +105 -0
- package/dist/chunk-ALFITFBN.js.map +1 -0
- package/dist/chunk-PAQHOXQ6.js +392 -0
- package/dist/chunk-PAQHOXQ6.js.map +1 -0
- package/dist/errors-CZu5mmz1.d.cts +293 -0
- package/dist/errors-Cqh7UdUO.d.ts +293 -0
- package/dist/index.cjs +18 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -7
- package/dist/index.d.ts +12 -7
- package/dist/index.js +19 -6
- package/dist/index.js.map +1 -1
- package/dist/intent-input-BybnwL83.d.ts +126 -0
- package/dist/intent-input-C2PTr2XH.d.cts +126 -0
- package/dist/swk/index.js +1 -103
- package/dist/swk/index.js.map +1 -1
- package/dist/wallets/index.cjs +1043 -0
- package/dist/wallets/index.cjs.map +1 -0
- package/dist/wallets/index.d.cts +384 -0
- package/dist/wallets/index.d.ts +384 -0
- package/dist/wallets/index.js +629 -0
- package/dist/wallets/index.js.map +1 -0
- package/dist/{intent-input-CP5bkBYI.d.cts → wallets-CeIjESt5.d.cts} +39 -126
- package/dist/{intent-input-CP5bkBYI.d.ts → wallets-CeIjESt5.d.ts} +39 -126
- package/dist/web/index.cjs +1 -1
- package/dist/web/index.cjs.map +1 -1
- package/dist/web/index.d.cts +7 -292
- package/dist/web/index.d.ts +7 -292
- package/dist/web/index.js +5 -391
- package/dist/web/index.js.map +1 -1
- package/llms/07-webhooks.md +2 -0
- package/llms/15-swaps.md +2 -0
- package/llms/18-wallets.md +94 -0
- package/llms/llms-full.txt +101 -0
- package/llms/llms.txt +1 -0
- package/package.json +22 -8
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { cJ as WalletId, aG as PaymentIntentData } from './wallets-CeIjESt5.cjs';
|
|
2
|
+
import { a as CosmosWalletProvider, C as CosmosProviderOptions } from './cosmosProvider-BrpOdL_b.cjs';
|
|
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
|
+
* Built-in wallet adapters and the default registration set.
|
|
217
|
+
*
|
|
218
|
+
* Auto-detection order (first available wins): Freighter → xBull → Rabet →
|
|
219
|
+
* LOBSTR → Albedo → Cosmos Pay Wallet. Freighter, xBull and Rabet inject browser globals so they're
|
|
220
|
+
* detected with zero configuration; LOBSTR and Albedo need their library passed
|
|
221
|
+
* in (no reliable global), so they only activate when injected.
|
|
222
|
+
*/
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Optional wallet libraries to enable wallets that have no auto-detectable
|
|
226
|
+
* global (LOBSTR, Albedo) or to use a non-extension transport (xBull web-app
|
|
227
|
+
* bridge). Everything here is optional — extension wallets need nothing.
|
|
228
|
+
*/
|
|
229
|
+
interface InjectedWallets {
|
|
230
|
+
/** An `@stellar/freighter-api` module (otherwise `window.freighterApi`). */
|
|
231
|
+
freighter?: any;
|
|
232
|
+
/** An xBull SDK instance (otherwise `window.xBullSDK`). */
|
|
233
|
+
xBull?: any;
|
|
234
|
+
/** A Rabet provider (otherwise `window.rabet`). */
|
|
235
|
+
rabet?: any;
|
|
236
|
+
/** An `@albedo-link/intent` module/global (otherwise `window.albedo`). */
|
|
237
|
+
albedo?: any;
|
|
238
|
+
/** A `@lobstrco/signer-extension-api` module. */
|
|
239
|
+
lobstr?: any;
|
|
240
|
+
/**
|
|
241
|
+
* A Cosmos Pay Wallet provider, or `{ walletUrl }` to reach the HOSTED wallet when
|
|
242
|
+
* the extension is absent (otherwise `window.cosmosWallet`).
|
|
243
|
+
*/
|
|
244
|
+
cosmos?: CosmosWalletProvider | CosmosProviderOptions;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Build the default adapter set, honoring any injected wallet libraries. The
|
|
248
|
+
* order here is the auto-detection priority.
|
|
249
|
+
*/
|
|
250
|
+
declare function defaultAdapters(injected?: InjectedWallets): WalletAdapter[];
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Errors surfaced by the browser ("web client") side of the SDK.
|
|
254
|
+
*
|
|
255
|
+
* These are intentionally kept separate from the server-side
|
|
256
|
+
* {@link CosmosPayAPIError}/{@link CosmosPayRequestError} so that bundling the
|
|
257
|
+
* web entry never pulls in Node-only code paths. They all extend
|
|
258
|
+
* {@link CosmosPayWebError} so a consumer can `catch (e) { if (e instanceof
|
|
259
|
+
* CosmosPayWebError) ... }`.
|
|
260
|
+
*/
|
|
261
|
+
/** Base class for every error thrown by `@cosmosapp/pay_sdk/web`. */
|
|
262
|
+
declare class CosmosPayWebError extends Error {
|
|
263
|
+
constructor(message: string);
|
|
264
|
+
}
|
|
265
|
+
/** No compatible Stellar wallet could be detected in the current environment. */
|
|
266
|
+
declare class WalletNotFoundError extends CosmosPayWebError {
|
|
267
|
+
/** Ids of the wallets that were searched for. */
|
|
268
|
+
readonly searched: string[];
|
|
269
|
+
constructor(searched: string[]);
|
|
270
|
+
}
|
|
271
|
+
/** A wallet was found but the operation failed (user rejected, locked, etc.). */
|
|
272
|
+
declare class WalletError extends CosmosPayWebError {
|
|
273
|
+
/** Id of the wallet that produced the error (e.g. `freighter`). */
|
|
274
|
+
readonly wallet: string;
|
|
275
|
+
/** The underlying error, if any. */
|
|
276
|
+
readonly cause: unknown;
|
|
277
|
+
constructor(wallet: string, message: string, cause?: unknown);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Building a `pay` transaction (or submitting to Horizon) requires the Stellar
|
|
281
|
+
* SDK, which is an optional peer dependency. Thrown when it is neither installed
|
|
282
|
+
* nor injected.
|
|
283
|
+
*/
|
|
284
|
+
declare class StellarSdkRequiredError extends CosmosPayWebError {
|
|
285
|
+
constructor(detail?: string);
|
|
286
|
+
}
|
|
287
|
+
/** The intent / SEP-7 request could not be interpreted or is missing data. */
|
|
288
|
+
declare class IntentError extends CosmosPayWebError {
|
|
289
|
+
constructor(message: string);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export { WalletError as a, CosmosPayWebError as i, IntentError as j, StellarSdkRequiredError as k, WalletNotFoundError as l, defaultAdapters as m };
|
|
293
|
+
export type { ConnectResult as C, InjectedWallets as I, NetworkConfig as N, PayableInput as P, StellarNetwork as S, WalletAdapter as W, SignParams as b, WalletInfo as c, StellarSdkLike as d, PayOptions as e, PayResult as f, NormalizedIntent as g, Sep7Request as h };
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { cJ as WalletId, aG as PaymentIntentData } from './wallets-CeIjESt5.js';
|
|
2
|
+
import { a as CosmosWalletProvider, C as CosmosProviderOptions } from './cosmosProvider-BrpOdL_b.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
|
+
* Built-in wallet adapters and the default registration set.
|
|
217
|
+
*
|
|
218
|
+
* Auto-detection order (first available wins): Freighter → xBull → Rabet →
|
|
219
|
+
* LOBSTR → Albedo → Cosmos Pay Wallet. Freighter, xBull and Rabet inject browser globals so they're
|
|
220
|
+
* detected with zero configuration; LOBSTR and Albedo need their library passed
|
|
221
|
+
* in (no reliable global), so they only activate when injected.
|
|
222
|
+
*/
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Optional wallet libraries to enable wallets that have no auto-detectable
|
|
226
|
+
* global (LOBSTR, Albedo) or to use a non-extension transport (xBull web-app
|
|
227
|
+
* bridge). Everything here is optional — extension wallets need nothing.
|
|
228
|
+
*/
|
|
229
|
+
interface InjectedWallets {
|
|
230
|
+
/** An `@stellar/freighter-api` module (otherwise `window.freighterApi`). */
|
|
231
|
+
freighter?: any;
|
|
232
|
+
/** An xBull SDK instance (otherwise `window.xBullSDK`). */
|
|
233
|
+
xBull?: any;
|
|
234
|
+
/** A Rabet provider (otherwise `window.rabet`). */
|
|
235
|
+
rabet?: any;
|
|
236
|
+
/** An `@albedo-link/intent` module/global (otherwise `window.albedo`). */
|
|
237
|
+
albedo?: any;
|
|
238
|
+
/** A `@lobstrco/signer-extension-api` module. */
|
|
239
|
+
lobstr?: any;
|
|
240
|
+
/**
|
|
241
|
+
* A Cosmos Pay Wallet provider, or `{ walletUrl }` to reach the HOSTED wallet when
|
|
242
|
+
* the extension is absent (otherwise `window.cosmosWallet`).
|
|
243
|
+
*/
|
|
244
|
+
cosmos?: CosmosWalletProvider | CosmosProviderOptions;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Build the default adapter set, honoring any injected wallet libraries. The
|
|
248
|
+
* order here is the auto-detection priority.
|
|
249
|
+
*/
|
|
250
|
+
declare function defaultAdapters(injected?: InjectedWallets): WalletAdapter[];
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Errors surfaced by the browser ("web client") side of the SDK.
|
|
254
|
+
*
|
|
255
|
+
* These are intentionally kept separate from the server-side
|
|
256
|
+
* {@link CosmosPayAPIError}/{@link CosmosPayRequestError} so that bundling the
|
|
257
|
+
* web entry never pulls in Node-only code paths. They all extend
|
|
258
|
+
* {@link CosmosPayWebError} so a consumer can `catch (e) { if (e instanceof
|
|
259
|
+
* CosmosPayWebError) ... }`.
|
|
260
|
+
*/
|
|
261
|
+
/** Base class for every error thrown by `@cosmosapp/pay_sdk/web`. */
|
|
262
|
+
declare class CosmosPayWebError extends Error {
|
|
263
|
+
constructor(message: string);
|
|
264
|
+
}
|
|
265
|
+
/** No compatible Stellar wallet could be detected in the current environment. */
|
|
266
|
+
declare class WalletNotFoundError extends CosmosPayWebError {
|
|
267
|
+
/** Ids of the wallets that were searched for. */
|
|
268
|
+
readonly searched: string[];
|
|
269
|
+
constructor(searched: string[]);
|
|
270
|
+
}
|
|
271
|
+
/** A wallet was found but the operation failed (user rejected, locked, etc.). */
|
|
272
|
+
declare class WalletError extends CosmosPayWebError {
|
|
273
|
+
/** Id of the wallet that produced the error (e.g. `freighter`). */
|
|
274
|
+
readonly wallet: string;
|
|
275
|
+
/** The underlying error, if any. */
|
|
276
|
+
readonly cause: unknown;
|
|
277
|
+
constructor(wallet: string, message: string, cause?: unknown);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Building a `pay` transaction (or submitting to Horizon) requires the Stellar
|
|
281
|
+
* SDK, which is an optional peer dependency. Thrown when it is neither installed
|
|
282
|
+
* nor injected.
|
|
283
|
+
*/
|
|
284
|
+
declare class StellarSdkRequiredError extends CosmosPayWebError {
|
|
285
|
+
constructor(detail?: string);
|
|
286
|
+
}
|
|
287
|
+
/** The intent / SEP-7 request could not be interpreted or is missing data. */
|
|
288
|
+
declare class IntentError extends CosmosPayWebError {
|
|
289
|
+
constructor(message: string);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export { WalletError as a, CosmosPayWebError as i, IntentError as j, StellarSdkRequiredError as k, WalletNotFoundError as l, defaultAdapters as m };
|
|
293
|
+
export type { ConnectResult as C, InjectedWallets as I, NetworkConfig as N, PayableInput as P, StellarNetwork as S, WalletAdapter as W, SignParams as b, WalletInfo as c, StellarSdkLike as d, PayOptions as e, PayResult as f, NormalizedIntent as g, Sep7Request as h };
|
package/dist/index.cjs
CHANGED
|
@@ -390,7 +390,18 @@ var WebhookEventType = {
|
|
|
390
390
|
CrossChainSwapFailed: "CROSS_CHAIN_SWAP_FAILED",
|
|
391
391
|
CrossChainSwapExpired: "CROSS_CHAIN_SWAP_EXPIRED",
|
|
392
392
|
// Private payments (client.privatePayments).
|
|
393
|
-
PrivatePaymentSucceeded: "ZK_PAYMENT_SUCCEEDED"
|
|
393
|
+
PrivatePaymentSucceeded: "ZK_PAYMENT_SUCCEEDED",
|
|
394
|
+
// Protected payments: held in a contract until the order is delivered, then released.
|
|
395
|
+
ProtectedPaymentCreated: "PROTECTED_PAYMENT_CREATED",
|
|
396
|
+
ProtectedPaymentFunded: "PROTECTED_PAYMENT_FUNDED",
|
|
397
|
+
ProtectedPaymentShipped: "PROTECTED_PAYMENT_SHIPPED",
|
|
398
|
+
ProtectedPaymentApproved: "PROTECTED_PAYMENT_APPROVED",
|
|
399
|
+
ProtectedPaymentReleased: "PROTECTED_PAYMENT_RELEASED",
|
|
400
|
+
ProtectedPaymentDisputed: "PROTECTED_PAYMENT_DISPUTED",
|
|
401
|
+
ProtectedPaymentResolved: "PROTECTED_PAYMENT_RESOLVED",
|
|
402
|
+
ProtectedPaymentDeadlinePassed: "PROTECTED_PAYMENT_DEADLINE_PASSED",
|
|
403
|
+
ProtectedPaymentExpired: "PROTECTED_PAYMENT_EXPIRED",
|
|
404
|
+
ProtectedPaymentCancelled: "PROTECTED_PAYMENT_CANCELLED"
|
|
394
405
|
};
|
|
395
406
|
var WebhookDeliveryStatus = {
|
|
396
407
|
Pending: "PENDING",
|
|
@@ -1916,8 +1927,9 @@ var ChainSwap = class extends Base {
|
|
|
1916
1927
|
return await this.client.swaps.fetch(this.id);
|
|
1917
1928
|
}
|
|
1918
1929
|
/**
|
|
1919
|
-
* Relay the signed transaction
|
|
1920
|
-
*
|
|
1930
|
+
* Relay the signed transaction (`{ signedTransaction }`), or, on Monad, report
|
|
1931
|
+
* the one the wallet already sent (`{ txHash }`). Mutates this instance from
|
|
1932
|
+
* the refreshed swap in the outcome and returns the outcome.
|
|
1921
1933
|
*/
|
|
1922
1934
|
async submit(options) {
|
|
1923
1935
|
const outcome = await this.client.swaps.submit(
|
|
@@ -2098,7 +2110,8 @@ var SwapManager = class extends BaseManager {
|
|
|
2098
2110
|
}
|
|
2099
2111
|
/**
|
|
2100
2112
|
* Relay a signed swap transaction to its network: `{ signedXdr }` for a
|
|
2101
|
-
* Stellar swap, `{ signedTransaction }` for a Solana or Monad one
|
|
2113
|
+
* Stellar swap, `{ signedTransaction }` for a Solana or Monad one, or
|
|
2114
|
+
* `{ txHash }` for a Monad one the wallet already sent.
|
|
2102
2115
|
*/
|
|
2103
2116
|
async submit(id, options) {
|
|
2104
2117
|
const data = await this.rest.post(`${this.route}/${id}/submit`, { body: options });
|
|
@@ -2431,7 +2444,7 @@ var WebhookEndpoint = class extends Base {
|
|
|
2431
2444
|
};
|
|
2432
2445
|
|
|
2433
2446
|
// src/util/Constants.ts
|
|
2434
|
-
var version = "2.
|
|
2447
|
+
var version = "2.4.0";
|
|
2435
2448
|
var DEFAULT_BASE_URL = "https://api.cosmospay.lat/cosmos-api";
|
|
2436
2449
|
var DEFAULT_VERSION = "v1";
|
|
2437
2450
|
var DEFAULT_TIMEOUT = 3e4;
|