@stellar-snaps/sdk 0.3.0 → 0.3.2
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 +168 -1
- package/dist/index.d.mts +95 -52
- package/dist/index.d.ts +95 -52
- package/dist/index.js +165 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +161 -61
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -14
package/README.md
CHANGED
|
@@ -14,6 +14,22 @@ npm install @stellar-snaps/sdk
|
|
|
14
14
|
pnpm add @stellar-snaps/sdk
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
+
**Peer dependencies** (install if you use transaction building or Freighter):
|
|
18
|
+
`@stellar/freighter-api`, `@stellar/stellar-sdk`
|
|
19
|
+
|
|
20
|
+
## How it works
|
|
21
|
+
|
|
22
|
+
- **Shareable Snap API** (`createSnap`, `getSnap`, `listSnaps`, `deleteSnap`)
|
|
23
|
+
Calls the Stellar Snaps web app at `https://stellar-snaps.vercel.app` by default. Snaps are stored there; you get back shareable URLs (e.g. `https://stellar-snaps.vercel.app/s/abc123`). Works in **Node.js** and **browser** (CORS is enabled on the API). Use `baseUrl` to point at your own deployment.
|
|
24
|
+
|
|
25
|
+
- **SEP-0007 URIs** (`createPaymentSnap`, `createTransactionSnap`, `parseSnapUri`)
|
|
26
|
+
Pure logic, no network. Build or parse `web+stellar:...` payment/transaction links.
|
|
27
|
+
|
|
28
|
+
- **Transactions & Freighter** (`buildPaymentTransaction`, `signWithFreighter`, `submitTransaction`, etc.)
|
|
29
|
+
Run in a **browser** with the [Freighter](https://www.freighter.app/) extension installed. Uses `@stellar/freighter-api` and `@stellar/stellar-sdk`.
|
|
30
|
+
|
|
31
|
+
So: install the package, use the Shareable Snap API from any environment; use Freighter-related APIs only in a browser with Freighter installed.
|
|
32
|
+
|
|
17
33
|
## Quick Start
|
|
18
34
|
|
|
19
35
|
### 1. Create a Payment Link
|
|
@@ -79,7 +95,60 @@ if (result.successful) {
|
|
|
79
95
|
}
|
|
80
96
|
```
|
|
81
97
|
|
|
82
|
-
### 4.
|
|
98
|
+
### 4. Create Shareable Snaps (Web App API)
|
|
99
|
+
|
|
100
|
+
Create, fetch, list, and delete database-backed snaps—same behavior as the web dashboard. Uses `https://stellar-snaps.vercel.app` by default.
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
import { createSnap, getSnap, listSnaps, deleteSnap } from '@stellar-snaps/sdk';
|
|
104
|
+
|
|
105
|
+
// Create a snap (stores on server, returns shareable URL)
|
|
106
|
+
const { url, snap } = await createSnap({
|
|
107
|
+
creator: 'GCNZMNUTQ5UMQ5QL0FUAW3CUADWB...',
|
|
108
|
+
title: 'Buy me a coffee',
|
|
109
|
+
destination: 'GCNZMNUTQ5UMQ5QL0FUAW3CUADWB...',
|
|
110
|
+
amount: '5',
|
|
111
|
+
network: 'testnet',
|
|
112
|
+
});
|
|
113
|
+
console.log(url);
|
|
114
|
+
// => https://stellar-snaps.vercel.app/s/u8oYHLhl
|
|
115
|
+
|
|
116
|
+
// Fetch a snap by ID
|
|
117
|
+
const fetchedSnap = await getSnap('u8oYHLhl');
|
|
118
|
+
|
|
119
|
+
// List all snaps for a creator
|
|
120
|
+
const snaps = await listSnaps('GCNZMNUTQ5UMQ5QL0FUAW3CUADWB...');
|
|
121
|
+
|
|
122
|
+
// Delete a snap (requires creator address)
|
|
123
|
+
await deleteSnap('u8oYHLhl', 'GCNZMNUTQ5UMQ5QL0FUAW3CUADWB...');
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Use `baseUrl` to point at your own Stellar Snaps instance:
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
const { url } = await createSnap({
|
|
130
|
+
creator: 'G...',
|
|
131
|
+
title: 'Test',
|
|
132
|
+
destination: 'G...',
|
|
133
|
+
baseUrl: 'https://your-stellar-snaps.vercel.app',
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Show the same modal overlay as the web app** (browser only): open the snap URL in a modal so users can pay without leaving your page:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import { createSnap, openSnapModal, closeSnapModal } from '@stellar-snaps/sdk';
|
|
141
|
+
|
|
142
|
+
const { url } = await createSnap({ creator: 'G...', title: 'Tip', destination: 'G...' });
|
|
143
|
+
openSnapModal(url, {
|
|
144
|
+
width: 420,
|
|
145
|
+
height: 560,
|
|
146
|
+
onClose: () => console.log('Modal closed'),
|
|
147
|
+
});
|
|
148
|
+
// User sees the same payment UI as stellar-snaps.vercel.app/s/xxx in an overlay
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### 5. Host Your Own Snap Endpoints
|
|
83
152
|
|
|
84
153
|
Create a discovery file to enable the browser extension to find your snaps:
|
|
85
154
|
|
|
@@ -99,6 +168,93 @@ const discovery = createDiscoveryFile({
|
|
|
99
168
|
|
|
100
169
|
## API Reference
|
|
101
170
|
|
|
171
|
+
### Shareable Snap API (Web App)
|
|
172
|
+
|
|
173
|
+
These functions mirror the Stellar Snaps web app API. Use them to create and manage snaps that are stored on a server and get shareable URLs.
|
|
174
|
+
|
|
175
|
+
#### `createSnap(options)`
|
|
176
|
+
|
|
177
|
+
Creates a snap on the server and returns the shareable URL.
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
interface CreateSnapOptions {
|
|
181
|
+
creator: string; // Creator's Stellar address (required)
|
|
182
|
+
title: string; // Display title (required)
|
|
183
|
+
destination: string; // Payment destination (required)
|
|
184
|
+
description?: string;
|
|
185
|
+
amount?: string; // Omit for open amount
|
|
186
|
+
assetCode?: string; // Default: 'XLM'
|
|
187
|
+
assetIssuer?: string; // Required for non-XLM
|
|
188
|
+
memo?: string;
|
|
189
|
+
memoType?: MemoType;
|
|
190
|
+
network?: 'public' | 'testnet'; // Default: 'testnet'
|
|
191
|
+
imageUrl?: string;
|
|
192
|
+
baseUrl?: string; // Default: 'https://stellar-snaps.vercel.app'
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
interface CreateSnapResult {
|
|
196
|
+
id: string;
|
|
197
|
+
url: string; // Full shareable URL
|
|
198
|
+
snap: Snap;
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
#### `getSnap(id, options?)`
|
|
203
|
+
|
|
204
|
+
Fetches a snap by ID. Uses `GET /api/snap/[id]`.
|
|
205
|
+
|
|
206
|
+
- **Throws** `SnapNotFoundError` if the snap does not exist.
|
|
207
|
+
- **Throws** `SnapApiError` on other API errors.
|
|
208
|
+
|
|
209
|
+
#### `listSnaps(creator, options?)`
|
|
210
|
+
|
|
211
|
+
Lists all snaps for a creator. Uses `GET /api/snaps?creator=...`.
|
|
212
|
+
|
|
213
|
+
#### `deleteSnap(id, creator, options?)`
|
|
214
|
+
|
|
215
|
+
Deletes a snap. Requires the creator's address (ownership). Uses `DELETE /api/snaps?id=...&creator=...`.
|
|
216
|
+
|
|
217
|
+
- **Throws** `SnapNotFoundError` if the snap does not exist.
|
|
218
|
+
- **Throws** `SnapUnauthorizedError` if the creator does not own the snap.
|
|
219
|
+
- **Throws** `SnapApiError` on other API errors.
|
|
220
|
+
|
|
221
|
+
#### `Snap` type
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
interface Snap {
|
|
225
|
+
id: string;
|
|
226
|
+
creator?: string; // Omitted in GET /api/snap/[id] response
|
|
227
|
+
title: string;
|
|
228
|
+
description?: string | null;
|
|
229
|
+
destination: string;
|
|
230
|
+
amount?: string | null;
|
|
231
|
+
assetCode: string;
|
|
232
|
+
assetIssuer?: string | null;
|
|
233
|
+
memo?: string | null;
|
|
234
|
+
memoType?: string;
|
|
235
|
+
network: string;
|
|
236
|
+
imageUrl?: string | null;
|
|
237
|
+
createdAt?: string;
|
|
238
|
+
updatedAt?: string;
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
#### `openSnapModal(snapUrl, options?)`
|
|
243
|
+
|
|
244
|
+
Opens a snap URL in a full-screen modal overlay (iframe). Same payment UI as opening the link on the Stellar Snaps web app. **Browser only**; no-op in Node.
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
interface OpenSnapModalOptions {
|
|
248
|
+
width?: number; // Default: 420
|
|
249
|
+
height?: number; // Default: 560
|
|
250
|
+
onClose?: () => void;
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
#### `closeSnapModal()`
|
|
255
|
+
|
|
256
|
+
Closes the snap modal if one is open. Safe to call anytime.
|
|
257
|
+
|
|
102
258
|
### SEP-0007 URI Functions
|
|
103
259
|
|
|
104
260
|
#### `createPaymentSnap(options)`
|
|
@@ -260,6 +416,9 @@ All errors extend `StellarSnapError` with a `code` property for programmatic han
|
|
|
260
416
|
- `InvalidAmountError` - Invalid amount
|
|
261
417
|
- `InvalidAssetError` - Invalid asset configuration
|
|
262
418
|
- `InvalidUriError` - Invalid SEP-0007 URI
|
|
419
|
+
- `SnapNotFoundError` - Snap not found (404 from API)
|
|
420
|
+
- `SnapUnauthorizedError` - Not authorized to perform action (e.g. delete another user's snap)
|
|
421
|
+
- `SnapApiError` - Stellar Snaps API returned an error (includes optional `statusCode`)
|
|
263
422
|
|
|
264
423
|
```typescript
|
|
265
424
|
try {
|
|
@@ -269,6 +428,14 @@ try {
|
|
|
269
428
|
console.log(error.code); // 'INVALID_ADDRESS'
|
|
270
429
|
}
|
|
271
430
|
}
|
|
431
|
+
|
|
432
|
+
try {
|
|
433
|
+
const snap = await getSnap('missing-id');
|
|
434
|
+
} catch (error) {
|
|
435
|
+
if (error instanceof SnapNotFoundError) {
|
|
436
|
+
console.log(error.code); // 'SNAP_NOT_FOUND'
|
|
437
|
+
}
|
|
438
|
+
}
|
|
272
439
|
```
|
|
273
440
|
|
|
274
441
|
### Constants
|
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
import * as StellarSdk from '@stellar/stellar-sdk';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Shareable Snap API
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Functions that mirror the Stellar Snaps web app API. Create, fetch, list,
|
|
7
|
+
* and delete database-backed snaps so developers get the same behavior as
|
|
8
|
+
* the dashboard. Uses https://stellar-snaps.vercel.app by default.
|
|
8
9
|
*/
|
|
10
|
+
/** Snap as returned by the web app API (GET /api/snap/[id] omits creator; list/create include it). */
|
|
11
|
+
interface Snap$1 {
|
|
12
|
+
id: string;
|
|
13
|
+
creator?: string;
|
|
14
|
+
title: string;
|
|
15
|
+
description?: string | null;
|
|
16
|
+
destination: string;
|
|
17
|
+
amount?: string | null;
|
|
18
|
+
assetCode: string;
|
|
19
|
+
assetIssuer?: string | null;
|
|
20
|
+
memo?: string | null;
|
|
21
|
+
memoType?: string;
|
|
22
|
+
network: string;
|
|
23
|
+
imageUrl?: string | null;
|
|
24
|
+
createdAt?: string;
|
|
25
|
+
updatedAt?: string;
|
|
26
|
+
}
|
|
9
27
|
interface CreateSnapOptions {
|
|
10
28
|
/** Creator's Stellar address (required) */
|
|
11
29
|
creator: string;
|
|
@@ -29,30 +47,16 @@ interface CreateSnapOptions {
|
|
|
29
47
|
network?: 'public' | 'testnet';
|
|
30
48
|
/** Optional image URL for the snap */
|
|
31
49
|
imageUrl?: string;
|
|
32
|
-
/** Stellar Snaps server URL (default: 'https://
|
|
33
|
-
|
|
50
|
+
/** Stellar Snaps server base URL (default: 'https://stellar-snaps.vercel.app') */
|
|
51
|
+
baseUrl?: string;
|
|
34
52
|
}
|
|
35
53
|
interface CreateSnapResult {
|
|
36
54
|
/** The created snap ID */
|
|
37
55
|
id: string;
|
|
38
|
-
/** Full shareable URL */
|
|
56
|
+
/** Full shareable URL (e.g. https://stellar-snaps.vercel.app/s/abc123) */
|
|
39
57
|
url: string;
|
|
40
|
-
/** The snap data as
|
|
41
|
-
snap:
|
|
42
|
-
id: string;
|
|
43
|
-
creator: string;
|
|
44
|
-
title: string;
|
|
45
|
-
description?: string;
|
|
46
|
-
destination: string;
|
|
47
|
-
amount?: string;
|
|
48
|
-
assetCode: string;
|
|
49
|
-
assetIssuer?: string;
|
|
50
|
-
memo?: string;
|
|
51
|
-
memoType: string;
|
|
52
|
-
network: string;
|
|
53
|
-
imageUrl?: string;
|
|
54
|
-
createdAt: string;
|
|
55
|
-
};
|
|
58
|
+
/** The snap data as returned by the API */
|
|
59
|
+
snap: Snap$1;
|
|
56
60
|
}
|
|
57
61
|
/**
|
|
58
62
|
* Creates a shareable snap on a Stellar Snaps server.
|
|
@@ -64,53 +68,73 @@ interface CreateSnapResult {
|
|
|
64
68
|
* title: 'Coffee Payment',
|
|
65
69
|
* destination: 'GDEST...',
|
|
66
70
|
* amount: '5',
|
|
67
|
-
*
|
|
71
|
+
* baseUrl: 'https://stellar-snaps.vercel.app'
|
|
68
72
|
* });
|
|
69
|
-
*
|
|
70
73
|
* console.log(result.url);
|
|
71
|
-
* // https://
|
|
74
|
+
* // https://stellar-snaps.vercel.app/s/abc12345
|
|
72
75
|
* ```
|
|
73
76
|
*/
|
|
74
77
|
declare function createSnap(options: CreateSnapOptions): Promise<CreateSnapResult>;
|
|
75
78
|
/**
|
|
76
|
-
* Fetches
|
|
79
|
+
* Fetches a snap by ID from the Stellar Snaps server.
|
|
80
|
+
* Uses GET /api/snap/[id] (singular path, same as web app).
|
|
77
81
|
*
|
|
78
|
-
* @
|
|
79
|
-
*
|
|
80
|
-
* const snap = await getSnap('nk1VNcxo', {
|
|
81
|
-
* serverUrl: 'https://your-stellar-snaps-instance.com'
|
|
82
|
-
* });
|
|
83
|
-
* ```
|
|
82
|
+
* @throws SnapNotFoundError if the snap does not exist
|
|
83
|
+
* @throws SnapApiError if the request fails
|
|
84
84
|
*/
|
|
85
85
|
declare function getSnap(id: string, options?: {
|
|
86
|
-
|
|
87
|
-
}): Promise<
|
|
86
|
+
baseUrl?: string;
|
|
87
|
+
}): Promise<Snap$1>;
|
|
88
88
|
/**
|
|
89
|
-
* Lists snaps created by a specific address.
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* ```typescript
|
|
93
|
-
* const snaps = await listSnaps('GCREATOR...', {
|
|
94
|
-
* serverUrl: 'https://your-stellar-snaps-instance.com'
|
|
95
|
-
* });
|
|
96
|
-
* ```
|
|
89
|
+
* Lists snaps created by a specific address (GET /api/snaps?creator=...).
|
|
97
90
|
*/
|
|
98
91
|
declare function listSnaps(creator: string, options?: {
|
|
99
|
-
|
|
100
|
-
}): Promise<
|
|
92
|
+
baseUrl?: string;
|
|
93
|
+
}): Promise<Snap$1[]>;
|
|
101
94
|
/**
|
|
102
|
-
* Deletes a snap by ID.
|
|
95
|
+
* Deletes a snap by ID. Requires the creator's address (same as web app: DELETE /api/snaps?id=...&creator=...).
|
|
96
|
+
*
|
|
97
|
+
* @throws SnapNotFoundError if the snap does not exist
|
|
98
|
+
* @throws SnapUnauthorizedError if the creator does not own the snap
|
|
99
|
+
* @throws SnapApiError if the request fails
|
|
100
|
+
*/
|
|
101
|
+
declare function deleteSnap(id: string, creator: string, options?: {
|
|
102
|
+
baseUrl?: string;
|
|
103
|
+
}): Promise<void>;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Snap Modal Overlay
|
|
107
|
+
*
|
|
108
|
+
* Opens a snap URL (e.g. from createSnap) in a modal overlay so users can pay
|
|
109
|
+
* without leaving the page. Same payment UI as the web app, loaded in an iframe.
|
|
110
|
+
* Browser-only; no-op in Node.
|
|
111
|
+
*/
|
|
112
|
+
interface OpenSnapModalOptions {
|
|
113
|
+
/** Width of the iframe content area (default: 420) */
|
|
114
|
+
width?: number;
|
|
115
|
+
/** Height of the iframe (default: 560) */
|
|
116
|
+
height?: number;
|
|
117
|
+
/** Called when the user closes the modal */
|
|
118
|
+
onClose?: () => void;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Opens a snap URL in a modal overlay (iframe). Same experience as opening
|
|
122
|
+
* the link on the Stellar Snaps web app—payment form, Freighter, etc.
|
|
123
|
+
* Use the URL returned from createSnap(), e.g. result.url.
|
|
124
|
+
*
|
|
125
|
+
* Browser-only; does nothing in Node.
|
|
103
126
|
*
|
|
104
127
|
* @example
|
|
105
128
|
* ```typescript
|
|
106
|
-
* await
|
|
107
|
-
*
|
|
108
|
-
* });
|
|
129
|
+
* const { url } = await createSnap({ ... });
|
|
130
|
+
* openSnapModal(url, { onClose: () => console.log('Closed') });
|
|
109
131
|
* ```
|
|
110
132
|
*/
|
|
111
|
-
declare function
|
|
112
|
-
|
|
113
|
-
|
|
133
|
+
declare function openSnapModal(snapUrl: string, options?: OpenSnapModalOptions): void;
|
|
134
|
+
/**
|
|
135
|
+
* Closes the snap modal if one is open. Safe to call anytime.
|
|
136
|
+
*/
|
|
137
|
+
declare function closeSnapModal(): void;
|
|
114
138
|
|
|
115
139
|
/**
|
|
116
140
|
* Snap ID Generation
|
|
@@ -1169,5 +1193,24 @@ declare class InvalidAssetError extends StellarSnapError {
|
|
|
1169
1193
|
declare class InvalidUriError extends StellarSnapError {
|
|
1170
1194
|
constructor(message: string);
|
|
1171
1195
|
}
|
|
1196
|
+
/**
|
|
1197
|
+
* Thrown when a snap is not found (404 from API).
|
|
1198
|
+
*/
|
|
1199
|
+
declare class SnapNotFoundError extends StellarSnapError {
|
|
1200
|
+
constructor(snapId: string);
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Thrown when the caller is not authorized to perform the action (e.g. delete another user's snap).
|
|
1204
|
+
*/
|
|
1205
|
+
declare class SnapUnauthorizedError extends StellarSnapError {
|
|
1206
|
+
constructor(message?: string);
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Thrown when the Stellar Snaps API returns an error.
|
|
1210
|
+
*/
|
|
1211
|
+
declare class SnapApiError extends StellarSnapError {
|
|
1212
|
+
statusCode?: number | undefined;
|
|
1213
|
+
constructor(message: string, statusCode?: number | undefined);
|
|
1214
|
+
}
|
|
1172
1215
|
|
|
1173
|
-
export { type ApiResponse, type BuildPaymentOptions, CACHE_HEADERS, CORS_HEADERS, type CreateDiscoveryFileOptions, type CreateSnapInput, type CreateSnapOptions, type CreateSnapResult, type DiscoveryFile, type DiscoveryRule, type DomainEntry, type DomainStatus, EXPLORER_URLS, type ExplorerType, type FreighterConnectionResult, HORIZON_URLS, InvalidAddressError, InvalidAmountError, InvalidAssetError, InvalidUriError, type MemoType, type MetaTags, NETWORK_PASSPHRASES, type Network, POSTGRES_SCHEMA, type ParsedSnap, type PaymentSnapOptions, type PaymentSnapResult, type RateLimitBucket, type Registry, type ResolvedUrl, SHORTENER_DOMAINS, SQLITE_SCHEMA, type Snap, type SnapMetadata, StellarSnapError, type TransactionSnapOptions, type TransactionSnapResult, type TransactionSubmitResult, type UpdateSnapInput, addDomain, buildPaymentTransaction, buildUrl, connectFreighter, createAsset, createDiscoveryFile, createPaymentSnap, createRateLimiter, createRegistry, createSnap, createSnapObject, createTransactionSnap, deleteSnap, errorResponse, extractDomain, extractPath, extractSnapId, generateJsonLd, generateMetaTags, generateSnapId, getAccountUrl, getAssetUrl, getBlockedDomains, getDomainStatus, getFreighterNetwork, getOperationUrl, getSnap, getTransactionUrl, getVerifiedDomains, isDomainBlocked, isDomainVerified, isFreighterConnected, isShortenerUrl, isValidAmount, isValidAssetCode, isValidSnapId, isValidStellarAddress, listSnaps, matchUrlToRule, metaTagsToHtml, parseAddress, parseQueryParams, parseSnapUri, removeDomain, resolveUrl, resolveUrls, signWithFreighter, submitTransaction, successResponse, validateDiscoveryFile, validateRegistry, validateRequired, validateSnapInput };
|
|
1216
|
+
export { type ApiResponse, type BuildPaymentOptions, CACHE_HEADERS, CORS_HEADERS, type CreateDiscoveryFileOptions, type CreateSnapInput, type CreateSnapOptions, type CreateSnapResult, type DiscoveryFile, type DiscoveryRule, type DomainEntry, type DomainStatus, EXPLORER_URLS, type ExplorerType, type FreighterConnectionResult, HORIZON_URLS, InvalidAddressError, InvalidAmountError, InvalidAssetError, InvalidUriError, type MemoType, type MetaTags, NETWORK_PASSPHRASES, type Network, type OpenSnapModalOptions, POSTGRES_SCHEMA, type ParsedSnap, type PaymentSnapOptions, type PaymentSnapResult, type RateLimitBucket, type Registry, type ResolvedUrl, SHORTENER_DOMAINS, SQLITE_SCHEMA, type Snap$1 as Snap, SnapApiError, type SnapMetadata, SnapNotFoundError, type Snap as SnapRecord, SnapUnauthorizedError, StellarSnapError, type TransactionSnapOptions, type TransactionSnapResult, type TransactionSubmitResult, type UpdateSnapInput, addDomain, buildPaymentTransaction, buildUrl, closeSnapModal, connectFreighter, createAsset, createDiscoveryFile, createPaymentSnap, createRateLimiter, createRegistry, createSnap, createSnapObject, createTransactionSnap, deleteSnap, errorResponse, extractDomain, extractPath, extractSnapId, generateJsonLd, generateMetaTags, generateSnapId, getAccountUrl, getAssetUrl, getBlockedDomains, getDomainStatus, getFreighterNetwork, getOperationUrl, getSnap, getTransactionUrl, getVerifiedDomains, isDomainBlocked, isDomainVerified, isFreighterConnected, isShortenerUrl, isValidAmount, isValidAssetCode, isValidSnapId, isValidStellarAddress, listSnaps, matchUrlToRule, metaTagsToHtml, openSnapModal, parseAddress, parseQueryParams, parseSnapUri, removeDomain, resolveUrl, resolveUrls, signWithFreighter, submitTransaction, successResponse, validateDiscoveryFile, validateRegistry, validateRequired, validateSnapInput };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
import * as StellarSdk from '@stellar/stellar-sdk';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Shareable Snap API
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Functions that mirror the Stellar Snaps web app API. Create, fetch, list,
|
|
7
|
+
* and delete database-backed snaps so developers get the same behavior as
|
|
8
|
+
* the dashboard. Uses https://stellar-snaps.vercel.app by default.
|
|
8
9
|
*/
|
|
10
|
+
/** Snap as returned by the web app API (GET /api/snap/[id] omits creator; list/create include it). */
|
|
11
|
+
interface Snap$1 {
|
|
12
|
+
id: string;
|
|
13
|
+
creator?: string;
|
|
14
|
+
title: string;
|
|
15
|
+
description?: string | null;
|
|
16
|
+
destination: string;
|
|
17
|
+
amount?: string | null;
|
|
18
|
+
assetCode: string;
|
|
19
|
+
assetIssuer?: string | null;
|
|
20
|
+
memo?: string | null;
|
|
21
|
+
memoType?: string;
|
|
22
|
+
network: string;
|
|
23
|
+
imageUrl?: string | null;
|
|
24
|
+
createdAt?: string;
|
|
25
|
+
updatedAt?: string;
|
|
26
|
+
}
|
|
9
27
|
interface CreateSnapOptions {
|
|
10
28
|
/** Creator's Stellar address (required) */
|
|
11
29
|
creator: string;
|
|
@@ -29,30 +47,16 @@ interface CreateSnapOptions {
|
|
|
29
47
|
network?: 'public' | 'testnet';
|
|
30
48
|
/** Optional image URL for the snap */
|
|
31
49
|
imageUrl?: string;
|
|
32
|
-
/** Stellar Snaps server URL (default: 'https://
|
|
33
|
-
|
|
50
|
+
/** Stellar Snaps server base URL (default: 'https://stellar-snaps.vercel.app') */
|
|
51
|
+
baseUrl?: string;
|
|
34
52
|
}
|
|
35
53
|
interface CreateSnapResult {
|
|
36
54
|
/** The created snap ID */
|
|
37
55
|
id: string;
|
|
38
|
-
/** Full shareable URL */
|
|
56
|
+
/** Full shareable URL (e.g. https://stellar-snaps.vercel.app/s/abc123) */
|
|
39
57
|
url: string;
|
|
40
|
-
/** The snap data as
|
|
41
|
-
snap:
|
|
42
|
-
id: string;
|
|
43
|
-
creator: string;
|
|
44
|
-
title: string;
|
|
45
|
-
description?: string;
|
|
46
|
-
destination: string;
|
|
47
|
-
amount?: string;
|
|
48
|
-
assetCode: string;
|
|
49
|
-
assetIssuer?: string;
|
|
50
|
-
memo?: string;
|
|
51
|
-
memoType: string;
|
|
52
|
-
network: string;
|
|
53
|
-
imageUrl?: string;
|
|
54
|
-
createdAt: string;
|
|
55
|
-
};
|
|
58
|
+
/** The snap data as returned by the API */
|
|
59
|
+
snap: Snap$1;
|
|
56
60
|
}
|
|
57
61
|
/**
|
|
58
62
|
* Creates a shareable snap on a Stellar Snaps server.
|
|
@@ -64,53 +68,73 @@ interface CreateSnapResult {
|
|
|
64
68
|
* title: 'Coffee Payment',
|
|
65
69
|
* destination: 'GDEST...',
|
|
66
70
|
* amount: '5',
|
|
67
|
-
*
|
|
71
|
+
* baseUrl: 'https://stellar-snaps.vercel.app'
|
|
68
72
|
* });
|
|
69
|
-
*
|
|
70
73
|
* console.log(result.url);
|
|
71
|
-
* // https://
|
|
74
|
+
* // https://stellar-snaps.vercel.app/s/abc12345
|
|
72
75
|
* ```
|
|
73
76
|
*/
|
|
74
77
|
declare function createSnap(options: CreateSnapOptions): Promise<CreateSnapResult>;
|
|
75
78
|
/**
|
|
76
|
-
* Fetches
|
|
79
|
+
* Fetches a snap by ID from the Stellar Snaps server.
|
|
80
|
+
* Uses GET /api/snap/[id] (singular path, same as web app).
|
|
77
81
|
*
|
|
78
|
-
* @
|
|
79
|
-
*
|
|
80
|
-
* const snap = await getSnap('nk1VNcxo', {
|
|
81
|
-
* serverUrl: 'https://your-stellar-snaps-instance.com'
|
|
82
|
-
* });
|
|
83
|
-
* ```
|
|
82
|
+
* @throws SnapNotFoundError if the snap does not exist
|
|
83
|
+
* @throws SnapApiError if the request fails
|
|
84
84
|
*/
|
|
85
85
|
declare function getSnap(id: string, options?: {
|
|
86
|
-
|
|
87
|
-
}): Promise<
|
|
86
|
+
baseUrl?: string;
|
|
87
|
+
}): Promise<Snap$1>;
|
|
88
88
|
/**
|
|
89
|
-
* Lists snaps created by a specific address.
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* ```typescript
|
|
93
|
-
* const snaps = await listSnaps('GCREATOR...', {
|
|
94
|
-
* serverUrl: 'https://your-stellar-snaps-instance.com'
|
|
95
|
-
* });
|
|
96
|
-
* ```
|
|
89
|
+
* Lists snaps created by a specific address (GET /api/snaps?creator=...).
|
|
97
90
|
*/
|
|
98
91
|
declare function listSnaps(creator: string, options?: {
|
|
99
|
-
|
|
100
|
-
}): Promise<
|
|
92
|
+
baseUrl?: string;
|
|
93
|
+
}): Promise<Snap$1[]>;
|
|
101
94
|
/**
|
|
102
|
-
* Deletes a snap by ID.
|
|
95
|
+
* Deletes a snap by ID. Requires the creator's address (same as web app: DELETE /api/snaps?id=...&creator=...).
|
|
96
|
+
*
|
|
97
|
+
* @throws SnapNotFoundError if the snap does not exist
|
|
98
|
+
* @throws SnapUnauthorizedError if the creator does not own the snap
|
|
99
|
+
* @throws SnapApiError if the request fails
|
|
100
|
+
*/
|
|
101
|
+
declare function deleteSnap(id: string, creator: string, options?: {
|
|
102
|
+
baseUrl?: string;
|
|
103
|
+
}): Promise<void>;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Snap Modal Overlay
|
|
107
|
+
*
|
|
108
|
+
* Opens a snap URL (e.g. from createSnap) in a modal overlay so users can pay
|
|
109
|
+
* without leaving the page. Same payment UI as the web app, loaded in an iframe.
|
|
110
|
+
* Browser-only; no-op in Node.
|
|
111
|
+
*/
|
|
112
|
+
interface OpenSnapModalOptions {
|
|
113
|
+
/** Width of the iframe content area (default: 420) */
|
|
114
|
+
width?: number;
|
|
115
|
+
/** Height of the iframe (default: 560) */
|
|
116
|
+
height?: number;
|
|
117
|
+
/** Called when the user closes the modal */
|
|
118
|
+
onClose?: () => void;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Opens a snap URL in a modal overlay (iframe). Same experience as opening
|
|
122
|
+
* the link on the Stellar Snaps web app—payment form, Freighter, etc.
|
|
123
|
+
* Use the URL returned from createSnap(), e.g. result.url.
|
|
124
|
+
*
|
|
125
|
+
* Browser-only; does nothing in Node.
|
|
103
126
|
*
|
|
104
127
|
* @example
|
|
105
128
|
* ```typescript
|
|
106
|
-
* await
|
|
107
|
-
*
|
|
108
|
-
* });
|
|
129
|
+
* const { url } = await createSnap({ ... });
|
|
130
|
+
* openSnapModal(url, { onClose: () => console.log('Closed') });
|
|
109
131
|
* ```
|
|
110
132
|
*/
|
|
111
|
-
declare function
|
|
112
|
-
|
|
113
|
-
|
|
133
|
+
declare function openSnapModal(snapUrl: string, options?: OpenSnapModalOptions): void;
|
|
134
|
+
/**
|
|
135
|
+
* Closes the snap modal if one is open. Safe to call anytime.
|
|
136
|
+
*/
|
|
137
|
+
declare function closeSnapModal(): void;
|
|
114
138
|
|
|
115
139
|
/**
|
|
116
140
|
* Snap ID Generation
|
|
@@ -1169,5 +1193,24 @@ declare class InvalidAssetError extends StellarSnapError {
|
|
|
1169
1193
|
declare class InvalidUriError extends StellarSnapError {
|
|
1170
1194
|
constructor(message: string);
|
|
1171
1195
|
}
|
|
1196
|
+
/**
|
|
1197
|
+
* Thrown when a snap is not found (404 from API).
|
|
1198
|
+
*/
|
|
1199
|
+
declare class SnapNotFoundError extends StellarSnapError {
|
|
1200
|
+
constructor(snapId: string);
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Thrown when the caller is not authorized to perform the action (e.g. delete another user's snap).
|
|
1204
|
+
*/
|
|
1205
|
+
declare class SnapUnauthorizedError extends StellarSnapError {
|
|
1206
|
+
constructor(message?: string);
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Thrown when the Stellar Snaps API returns an error.
|
|
1210
|
+
*/
|
|
1211
|
+
declare class SnapApiError extends StellarSnapError {
|
|
1212
|
+
statusCode?: number | undefined;
|
|
1213
|
+
constructor(message: string, statusCode?: number | undefined);
|
|
1214
|
+
}
|
|
1172
1215
|
|
|
1173
|
-
export { type ApiResponse, type BuildPaymentOptions, CACHE_HEADERS, CORS_HEADERS, type CreateDiscoveryFileOptions, type CreateSnapInput, type CreateSnapOptions, type CreateSnapResult, type DiscoveryFile, type DiscoveryRule, type DomainEntry, type DomainStatus, EXPLORER_URLS, type ExplorerType, type FreighterConnectionResult, HORIZON_URLS, InvalidAddressError, InvalidAmountError, InvalidAssetError, InvalidUriError, type MemoType, type MetaTags, NETWORK_PASSPHRASES, type Network, POSTGRES_SCHEMA, type ParsedSnap, type PaymentSnapOptions, type PaymentSnapResult, type RateLimitBucket, type Registry, type ResolvedUrl, SHORTENER_DOMAINS, SQLITE_SCHEMA, type Snap, type SnapMetadata, StellarSnapError, type TransactionSnapOptions, type TransactionSnapResult, type TransactionSubmitResult, type UpdateSnapInput, addDomain, buildPaymentTransaction, buildUrl, connectFreighter, createAsset, createDiscoveryFile, createPaymentSnap, createRateLimiter, createRegistry, createSnap, createSnapObject, createTransactionSnap, deleteSnap, errorResponse, extractDomain, extractPath, extractSnapId, generateJsonLd, generateMetaTags, generateSnapId, getAccountUrl, getAssetUrl, getBlockedDomains, getDomainStatus, getFreighterNetwork, getOperationUrl, getSnap, getTransactionUrl, getVerifiedDomains, isDomainBlocked, isDomainVerified, isFreighterConnected, isShortenerUrl, isValidAmount, isValidAssetCode, isValidSnapId, isValidStellarAddress, listSnaps, matchUrlToRule, metaTagsToHtml, parseAddress, parseQueryParams, parseSnapUri, removeDomain, resolveUrl, resolveUrls, signWithFreighter, submitTransaction, successResponse, validateDiscoveryFile, validateRegistry, validateRequired, validateSnapInput };
|
|
1216
|
+
export { type ApiResponse, type BuildPaymentOptions, CACHE_HEADERS, CORS_HEADERS, type CreateDiscoveryFileOptions, type CreateSnapInput, type CreateSnapOptions, type CreateSnapResult, type DiscoveryFile, type DiscoveryRule, type DomainEntry, type DomainStatus, EXPLORER_URLS, type ExplorerType, type FreighterConnectionResult, HORIZON_URLS, InvalidAddressError, InvalidAmountError, InvalidAssetError, InvalidUriError, type MemoType, type MetaTags, NETWORK_PASSPHRASES, type Network, type OpenSnapModalOptions, POSTGRES_SCHEMA, type ParsedSnap, type PaymentSnapOptions, type PaymentSnapResult, type RateLimitBucket, type Registry, type ResolvedUrl, SHORTENER_DOMAINS, SQLITE_SCHEMA, type Snap$1 as Snap, SnapApiError, type SnapMetadata, SnapNotFoundError, type Snap as SnapRecord, SnapUnauthorizedError, StellarSnapError, type TransactionSnapOptions, type TransactionSnapResult, type TransactionSubmitResult, type UpdateSnapInput, addDomain, buildPaymentTransaction, buildUrl, closeSnapModal, connectFreighter, createAsset, createDiscoveryFile, createPaymentSnap, createRateLimiter, createRegistry, createSnap, createSnapObject, createTransactionSnap, deleteSnap, errorResponse, extractDomain, extractPath, extractSnapId, generateJsonLd, generateMetaTags, generateSnapId, getAccountUrl, getAssetUrl, getBlockedDomains, getDomainStatus, getFreighterNetwork, getOperationUrl, getSnap, getTransactionUrl, getVerifiedDomains, isDomainBlocked, isDomainVerified, isFreighterConnected, isShortenerUrl, isValidAmount, isValidAssetCode, isValidSnapId, isValidStellarAddress, listSnaps, matchUrlToRule, metaTagsToHtml, openSnapModal, parseAddress, parseQueryParams, parseSnapUri, removeDomain, resolveUrl, resolveUrls, signWithFreighter, submitTransaction, successResponse, validateDiscoveryFile, validateRegistry, validateRequired, validateSnapInput };
|