@stellar-snaps/sdk 0.2.0 → 0.3.1

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/dist/index.d.mts CHANGED
@@ -1,11 +1,29 @@
1
1
  import * as StellarSdk from '@stellar/stellar-sdk';
2
2
 
3
3
  /**
4
- * Create Shareable Snap
4
+ * Shareable Snap API
5
5
  *
6
- * Creates a snap on a Stellar Snaps server and returns the shareable URL.
7
- * This is different from createPaymentSnap which only creates SEP-0007 URIs.
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://stellarsnaps.com') */
33
- serverUrl?: string;
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 stored */
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,70 +68,79 @@ interface CreateSnapResult {
64
68
  * title: 'Coffee Payment',
65
69
  * destination: 'GDEST...',
66
70
  * amount: '5',
67
- * serverUrl: 'https://your-stellar-snaps-instance.com'
71
+ * baseUrl: 'https://stellar-snaps.vercel.app'
68
72
  * });
69
- *
70
73
  * console.log(result.url);
71
- * // https://your-stellar-snaps-instance.com/s/nk1VNcxo
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 an existing snap by ID from a Stellar Snaps server.
79
+ * Fetches a snap by ID from the Stellar Snaps server.
80
+ * Uses GET /api/snap/[id] (singular path, same as web app).
81
+ *
82
+ * @throws SnapNotFoundError if the snap does not exist
83
+ * @throws SnapApiError if the request fails
84
+ */
85
+ declare function getSnap(id: string, options?: {
86
+ baseUrl?: string;
87
+ }): Promise<Snap$1>;
88
+ /**
89
+ * Lists snaps created by a specific address (GET /api/snaps?creator=...).
90
+ */
91
+ declare function listSnaps(creator: string, options?: {
92
+ baseUrl?: string;
93
+ }): Promise<Snap$1[]>;
94
+ /**
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 ID Generation
107
+ *
108
+ * Generates unique, URL-safe IDs for snaps.
109
+ */
110
+ /**
111
+ * Generates a random snap ID.
112
+ *
113
+ * Uses a URL-safe alphabet similar to nanoid.
114
+ * Default length is 8 characters (similar to YouTube video IDs).
77
115
  *
78
116
  * @example
79
117
  * ```typescript
80
- * const snap = await getSnap('nk1VNcxo', {
81
- * serverUrl: 'https://your-stellar-snaps-instance.com'
82
- * });
118
+ * const id = generateSnapId(); // 'nk1VNcxo'
119
+ * const longId = generateSnapId(12); // 'nk1VNcxo4Abc'
83
120
  * ```
84
121
  */
85
- declare function getSnap(id: string, options?: {
86
- serverUrl?: string;
87
- }): Promise<CreateSnapResult['snap'] | null>;
122
+ declare function generateSnapId(length?: number): string;
88
123
  /**
89
- * Lists snaps created by a specific address.
124
+ * Validates a snap ID format.
90
125
  *
91
126
  * @example
92
127
  * ```typescript
93
- * const snaps = await listSnaps('GCREATOR...', {
94
- * serverUrl: 'https://your-stellar-snaps-instance.com'
95
- * });
128
+ * isValidSnapId('nk1VNcxo'); // true
129
+ * isValidSnapId(''); // false
130
+ * isValidSnapId('has spaces'); // false
96
131
  * ```
97
132
  */
98
- declare function listSnaps(creator: string, options?: {
99
- serverUrl?: string;
100
- }): Promise<CreateSnapResult['snap'][]>;
133
+ declare function isValidSnapId(id: string): boolean;
101
134
  /**
102
- * Deletes a snap by ID.
135
+ * Extracts a snap ID from a URL.
103
136
  *
104
137
  * @example
105
138
  * ```typescript
106
- * await deleteSnap('nk1VNcxo', {
107
- * serverUrl: 'https://your-stellar-snaps-instance.com'
108
- * });
139
+ * extractSnapId('https://stellarsnaps.com/s/nk1VNcxo'); // 'nk1VNcxo'
140
+ * extractSnapId('https://example.com/pay/abc123'); // 'abc123'
109
141
  * ```
110
142
  */
111
- declare function deleteSnap(id: string, options?: {
112
- serverUrl?: string;
113
- }): Promise<void>;
114
-
115
- interface PaymentSnapOptions {
116
- destination: string;
117
- amount?: string;
118
- assetCode?: string;
119
- assetIssuer?: string;
120
- memo?: string;
121
- memoType?: 'MEMO_TEXT' | 'MEMO_ID' | 'MEMO_HASH' | 'MEMO_RETURN';
122
- message?: string;
123
- network?: 'public' | 'testnet';
124
- callback?: string;
125
- }
126
- interface PaymentSnapResult {
127
- uri: string;
128
- params: Record<string, string>;
129
- }
130
- declare function createPaymentSnap(options: PaymentSnapOptions): PaymentSnapResult;
143
+ declare function extractSnapId(url: string, patterns?: string[]): string | null;
131
144
 
132
145
  /**
133
146
  * Stellar network passphrases used for transaction signing.
@@ -160,6 +173,132 @@ type Network = 'public' | 'testnet';
160
173
  */
161
174
  type MemoType = 'MEMO_TEXT' | 'MEMO_ID' | 'MEMO_HASH' | 'MEMO_RETURN';
162
175
 
176
+ /**
177
+ * Database Schema Types
178
+ *
179
+ * Type definitions for snap storage. These types can be used
180
+ * with any database (PostgreSQL, SQLite, MongoDB, etc.).
181
+ */
182
+
183
+ /**
184
+ * Snap record as stored in the database.
185
+ */
186
+ interface Snap {
187
+ /** Unique snap ID (e.g., 'nk1VNcxo') */
188
+ id: string;
189
+ /** Creator's Stellar address */
190
+ creator: string;
191
+ /** Display title */
192
+ title: string;
193
+ /** Optional description */
194
+ description?: string | null;
195
+ /** Optional image URL */
196
+ imageUrl?: string | null;
197
+ /** Payment destination address */
198
+ destination: string;
199
+ /** Asset code (default: 'XLM') */
200
+ assetCode: string;
201
+ /** Asset issuer (required for non-XLM) */
202
+ assetIssuer?: string | null;
203
+ /** Fixed amount (null = payer chooses) */
204
+ amount?: string | null;
205
+ /** Transaction memo */
206
+ memo?: string | null;
207
+ /** Memo type */
208
+ memoType: MemoType | string;
209
+ /** Network ('public' or 'testnet') */
210
+ network: Network | string;
211
+ /** Creation timestamp */
212
+ createdAt: Date | string;
213
+ /** Last update timestamp */
214
+ updatedAt: Date | string;
215
+ }
216
+ /**
217
+ * Input for creating a new snap.
218
+ */
219
+ interface CreateSnapInput {
220
+ /** Creator's Stellar address (required) */
221
+ creator: string;
222
+ /** Display title (required) */
223
+ title: string;
224
+ /** Payment destination address (required) */
225
+ destination: string;
226
+ /** Optional description */
227
+ description?: string;
228
+ /** Optional image URL */
229
+ imageUrl?: string;
230
+ /** Asset code (default: 'XLM') */
231
+ assetCode?: string;
232
+ /** Asset issuer (required for non-XLM) */
233
+ assetIssuer?: string;
234
+ /** Fixed amount */
235
+ amount?: string;
236
+ /** Transaction memo */
237
+ memo?: string;
238
+ /** Memo type (default: 'MEMO_TEXT') */
239
+ memoType?: MemoType;
240
+ /** Network (default: 'testnet') */
241
+ network?: Network;
242
+ }
243
+ /**
244
+ * Input for updating a snap.
245
+ */
246
+ interface UpdateSnapInput {
247
+ /** Display title */
248
+ title?: string;
249
+ /** Description */
250
+ description?: string | null;
251
+ /** Image URL */
252
+ imageUrl?: string | null;
253
+ /** Payment amount */
254
+ amount?: string | null;
255
+ /** Transaction memo */
256
+ memo?: string | null;
257
+ /** Memo type */
258
+ memoType?: MemoType;
259
+ }
260
+ /**
261
+ * Validates snap input data.
262
+ *
263
+ * @throws Error if validation fails
264
+ */
265
+ declare function validateSnapInput(input: CreateSnapInput): void;
266
+ /**
267
+ * Creates a snap object with defaults.
268
+ */
269
+ declare function createSnapObject(id: string, input: CreateSnapInput): Snap;
270
+ /**
271
+ * SQL schema for PostgreSQL.
272
+ *
273
+ * @example
274
+ * ```typescript
275
+ * // Run this SQL to create the snaps table:
276
+ * await db.execute(POSTGRES_SCHEMA);
277
+ * ```
278
+ */
279
+ declare const POSTGRES_SCHEMA = "\nCREATE TABLE IF NOT EXISTS snaps (\n id TEXT PRIMARY KEY,\n creator TEXT NOT NULL,\n title TEXT NOT NULL,\n description TEXT,\n image_url TEXT,\n destination TEXT NOT NULL,\n asset_code TEXT NOT NULL DEFAULT 'XLM',\n asset_issuer TEXT,\n amount TEXT,\n memo TEXT,\n memo_type TEXT NOT NULL DEFAULT 'MEMO_TEXT',\n network TEXT NOT NULL DEFAULT 'testnet',\n created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),\n updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()\n);\n\nCREATE INDEX IF NOT EXISTS idx_snaps_creator ON snaps(creator);\nCREATE INDEX IF NOT EXISTS idx_snaps_destination ON snaps(destination);\n";
280
+ /**
281
+ * SQL schema for SQLite.
282
+ */
283
+ declare const SQLITE_SCHEMA = "\nCREATE TABLE IF NOT EXISTS snaps (\n id TEXT PRIMARY KEY,\n creator TEXT NOT NULL,\n title TEXT NOT NULL,\n description TEXT,\n image_url TEXT,\n destination TEXT NOT NULL,\n asset_code TEXT NOT NULL DEFAULT 'XLM',\n asset_issuer TEXT,\n amount TEXT,\n memo TEXT,\n memo_type TEXT NOT NULL DEFAULT 'MEMO_TEXT',\n network TEXT NOT NULL DEFAULT 'testnet',\n created_at TEXT DEFAULT (datetime('now')),\n updated_at TEXT DEFAULT (datetime('now'))\n);\n\nCREATE INDEX IF NOT EXISTS idx_snaps_creator ON snaps(creator);\nCREATE INDEX IF NOT EXISTS idx_snaps_destination ON snaps(destination);\n";
284
+
285
+ interface PaymentSnapOptions {
286
+ destination: string;
287
+ amount?: string;
288
+ assetCode?: string;
289
+ assetIssuer?: string;
290
+ memo?: string;
291
+ memoType?: 'MEMO_TEXT' | 'MEMO_ID' | 'MEMO_HASH' | 'MEMO_RETURN';
292
+ message?: string;
293
+ network?: 'public' | 'testnet';
294
+ callback?: string;
295
+ }
296
+ interface PaymentSnapResult {
297
+ uri: string;
298
+ params: Record<string, string>;
299
+ }
300
+ declare function createPaymentSnap(options: PaymentSnapOptions): PaymentSnapResult;
301
+
163
302
  /**
164
303
  * Options for creating a transaction snap URI.
165
304
  * Used for advanced use cases where you need to sign arbitrary transactions,
@@ -594,6 +733,397 @@ declare function validateDiscoveryFile(file: unknown): file is DiscoveryFile;
594
733
  */
595
734
  declare function matchUrlToRule(pathname: string, rules: DiscoveryRule[]): string | null;
596
735
 
736
+ /**
737
+ * URL Resolution Utilities
738
+ *
739
+ * Handles shortened URL detection and resolution for snap links.
740
+ */
741
+ /** List of known URL shortener domains */
742
+ declare const SHORTENER_DOMAINS: readonly ["t.co", "bit.ly", "goo.gl", "tinyurl.com", "ow.ly", "is.gd", "buff.ly", "adf.ly", "bit.do", "mcaf.ee", "su.pr", "twit.ac", "tiny.cc", "lnkd.in", "db.tt", "qr.ae", "cur.lv", "ity.im", "q.gs", "po.st", "bc.vc", "u.to", "j.mp", "buzurl.com", "cutt.us", "u.bb", "yourls.org", "x.co", "prettylinkpro.com", "viralurl.com", "twitthis.com", "shorturl.at", "rb.gy", "shorturl.com"];
743
+ interface ResolvedUrl {
744
+ /** The final resolved URL after following redirects */
745
+ url: string;
746
+ /** The domain of the resolved URL */
747
+ domain: string;
748
+ /** The original URL before resolution */
749
+ originalUrl: string;
750
+ /** Whether the URL was shortened */
751
+ wasShortened: boolean;
752
+ }
753
+ /**
754
+ * Checks if a URL is from a known URL shortener.
755
+ *
756
+ * @example
757
+ * ```typescript
758
+ * isShortenerUrl('https://t.co/abc123'); // true
759
+ * isShortenerUrl('https://stellarsnaps.com/s/abc'); // false
760
+ * ```
761
+ */
762
+ declare function isShortenerUrl(url: string): boolean;
763
+ /**
764
+ * Extracts the domain from a URL.
765
+ *
766
+ * @example
767
+ * ```typescript
768
+ * extractDomain('https://stellarsnaps.com/s/abc123'); // 'stellarsnaps.com'
769
+ * ```
770
+ */
771
+ declare function extractDomain(url: string): string;
772
+ /**
773
+ * Extracts the path from a URL.
774
+ *
775
+ * @example
776
+ * ```typescript
777
+ * extractPath('https://stellarsnaps.com/s/abc123'); // '/s/abc123'
778
+ * ```
779
+ */
780
+ declare function extractPath(url: string): string;
781
+ /**
782
+ * Resolves a shortened URL by following redirects.
783
+ * This is a server-side function that requires fetch with redirect following.
784
+ *
785
+ * @example
786
+ * ```typescript
787
+ * const resolved = await resolveUrl('https://t.co/abc123');
788
+ * console.log(resolved.url); // 'https://stellarsnaps.com/s/xyz789'
789
+ * ```
790
+ */
791
+ declare function resolveUrl(url: string): Promise<ResolvedUrl>;
792
+ /**
793
+ * Batch resolve multiple URLs.
794
+ *
795
+ * @example
796
+ * ```typescript
797
+ * const urls = ['https://t.co/a', 'https://bit.ly/b'];
798
+ * const resolved = await resolveUrls(urls);
799
+ * ```
800
+ */
801
+ declare function resolveUrls(urls: string[]): Promise<ResolvedUrl[]>;
802
+
803
+ /**
804
+ * Domain Registry
805
+ *
806
+ * Manages trusted/verified domains for snap hosting.
807
+ */
808
+ type DomainStatus = 'verified' | 'unverified' | 'blocked';
809
+ interface DomainEntry {
810
+ /** The domain name */
811
+ domain: string;
812
+ /** Trust status */
813
+ status: DomainStatus;
814
+ /** Optional display name */
815
+ name?: string;
816
+ /** Optional description */
817
+ description?: string;
818
+ /** When the domain was added */
819
+ addedAt?: string;
820
+ /** When the domain was last verified */
821
+ verifiedAt?: string;
822
+ }
823
+ interface Registry {
824
+ /** List of all domain entries */
825
+ domains: DomainEntry[];
826
+ /** When the registry was last updated */
827
+ updatedAt: string;
828
+ /** Registry version */
829
+ version: string;
830
+ }
831
+ /**
832
+ * Creates a new registry.
833
+ *
834
+ * @example
835
+ * ```typescript
836
+ * const registry = createRegistry([
837
+ * { domain: 'stellarsnaps.com', status: 'verified', name: 'Stellar Snaps' },
838
+ * { domain: 'example.com', status: 'unverified' },
839
+ * ]);
840
+ * ```
841
+ */
842
+ declare function createRegistry(domains?: DomainEntry[]): Registry;
843
+ /**
844
+ * Adds a domain to the registry.
845
+ */
846
+ declare function addDomain(registry: Registry, entry: DomainEntry): Registry;
847
+ /**
848
+ * Removes a domain from the registry.
849
+ */
850
+ declare function removeDomain(registry: Registry, domain: string): Registry;
851
+ /**
852
+ * Gets the status of a domain.
853
+ *
854
+ * @example
855
+ * ```typescript
856
+ * const status = getDomainStatus(registry, 'stellarsnaps.com');
857
+ * // { domain: 'stellarsnaps.com', status: 'verified', ... }
858
+ * ```
859
+ */
860
+ declare function getDomainStatus(registry: Registry, domain: string): DomainEntry | null;
861
+ /**
862
+ * Checks if a domain is verified.
863
+ */
864
+ declare function isDomainVerified(registry: Registry, domain: string): boolean;
865
+ /**
866
+ * Checks if a domain is blocked.
867
+ */
868
+ declare function isDomainBlocked(registry: Registry, domain: string): boolean;
869
+ /**
870
+ * Gets all verified domains.
871
+ */
872
+ declare function getVerifiedDomains(registry: Registry): DomainEntry[];
873
+ /**
874
+ * Gets all blocked domains.
875
+ */
876
+ declare function getBlockedDomains(registry: Registry): DomainEntry[];
877
+ /**
878
+ * Validates a registry object.
879
+ */
880
+ declare function validateRegistry(registry: unknown): registry is Registry;
881
+
882
+ /**
883
+ * Blockchain Explorer Utilities
884
+ *
885
+ * Generate links to Stellar blockchain explorers.
886
+ */
887
+
888
+ /** Supported explorer types */
889
+ type ExplorerType = 'stellar.expert' | 'stellarchain' | 'horizon';
890
+ /** Explorer base URLs */
891
+ declare const EXPLORER_URLS: Record<ExplorerType, Record<Network, string>>;
892
+ /**
893
+ * Generates a transaction URL for a blockchain explorer.
894
+ *
895
+ * @example
896
+ * ```typescript
897
+ * getTransactionUrl('abc123...', 'testnet');
898
+ * // 'https://stellar.expert/explorer/testnet/tx/abc123...'
899
+ *
900
+ * getTransactionUrl('abc123...', 'public', 'stellarchain');
901
+ * // 'https://stellarchain.io/transactions/abc123...'
902
+ * ```
903
+ */
904
+ declare function getTransactionUrl(hash: string, network?: Network, explorer?: ExplorerType): string;
905
+ /**
906
+ * Generates an account URL for a blockchain explorer.
907
+ *
908
+ * @example
909
+ * ```typescript
910
+ * getAccountUrl('GABC...', 'testnet');
911
+ * // 'https://stellar.expert/explorer/testnet/account/GABC...'
912
+ * ```
913
+ */
914
+ declare function getAccountUrl(address: string, network?: Network, explorer?: ExplorerType): string;
915
+ /**
916
+ * Generates an asset URL for a blockchain explorer.
917
+ *
918
+ * @example
919
+ * ```typescript
920
+ * getAssetUrl('USDC', 'GCNY...', 'public');
921
+ * // 'https://stellar.expert/explorer/public/asset/USDC-GCNY...'
922
+ * ```
923
+ */
924
+ declare function getAssetUrl(code: string, issuer: string, network?: Network, explorer?: ExplorerType): string;
925
+ /**
926
+ * Generates an operation URL for a blockchain explorer.
927
+ */
928
+ declare function getOperationUrl(operationId: string, network?: Network, explorer?: ExplorerType): string;
929
+
930
+ /**
931
+ * Meta Tag Generation
932
+ *
933
+ * Generate OpenGraph and Twitter meta tags for snap pages.
934
+ */
935
+ interface SnapMetadata {
936
+ /** Snap title */
937
+ title: string;
938
+ /** Snap description */
939
+ description?: string;
940
+ /** Image URL */
941
+ imageUrl?: string;
942
+ /** Payment amount */
943
+ amount?: string;
944
+ /** Asset code */
945
+ assetCode?: string;
946
+ /** Full snap URL */
947
+ url: string;
948
+ /** Site name */
949
+ siteName?: string;
950
+ }
951
+ interface MetaTags {
952
+ /** OpenGraph tags */
953
+ og: Record<string, string>;
954
+ /** Twitter card tags */
955
+ twitter: Record<string, string>;
956
+ /** Standard meta tags */
957
+ standard: Record<string, string>;
958
+ }
959
+ /**
960
+ * Generates meta tags for a snap page.
961
+ *
962
+ * @example
963
+ * ```typescript
964
+ * const tags = generateMetaTags({
965
+ * title: 'Pay for Coffee',
966
+ * description: 'Send 5 XLM for coffee',
967
+ * amount: '5',
968
+ * assetCode: 'XLM',
969
+ * url: 'https://stellarsnaps.com/s/abc123',
970
+ * });
971
+ *
972
+ * // Use in Next.js metadata:
973
+ * export const metadata = {
974
+ * title: tags.standard.title,
975
+ * openGraph: tags.og,
976
+ * twitter: tags.twitter,
977
+ * };
978
+ * ```
979
+ */
980
+ declare function generateMetaTags(metadata: SnapMetadata): MetaTags;
981
+ /**
982
+ * Converts meta tags to HTML string.
983
+ *
984
+ * @example
985
+ * ```typescript
986
+ * const html = metaTagsToHtml(tags);
987
+ * // <meta property="og:title" content="Pay for Coffee" />
988
+ * // <meta property="og:description" content="..." />
989
+ * // ...
990
+ * ```
991
+ */
992
+ declare function metaTagsToHtml(tags: MetaTags): string;
993
+ /**
994
+ * Generates JSON-LD structured data for a snap.
995
+ *
996
+ * @example
997
+ * ```typescript
998
+ * const jsonLd = generateJsonLd({
999
+ * title: 'Pay for Coffee',
1000
+ * amount: '5',
1001
+ * assetCode: 'XLM',
1002
+ * url: 'https://stellarsnaps.com/s/abc123',
1003
+ * });
1004
+ * ```
1005
+ */
1006
+ declare function generateJsonLd(metadata: SnapMetadata): object;
1007
+
1008
+ /**
1009
+ * Server Utilities
1010
+ *
1011
+ * Helper functions for building Stellar Snaps API endpoints.
1012
+ */
1013
+ /**
1014
+ * Standard CORS headers for API responses.
1015
+ */
1016
+ declare const CORS_HEADERS: {
1017
+ readonly 'Access-Control-Allow-Origin': "*";
1018
+ readonly 'Access-Control-Allow-Methods': "GET, POST, PUT, DELETE, OPTIONS";
1019
+ readonly 'Access-Control-Allow-Headers': "Content-Type, Authorization";
1020
+ readonly 'Access-Control-Max-Age': "86400";
1021
+ };
1022
+ /**
1023
+ * Cache headers for different response types.
1024
+ */
1025
+ declare const CACHE_HEADERS: {
1026
+ /** No caching */
1027
+ readonly none: {
1028
+ readonly 'Cache-Control': "no-store, no-cache, must-revalidate";
1029
+ };
1030
+ /** Short cache (1 minute) */
1031
+ readonly short: {
1032
+ readonly 'Cache-Control': "public, max-age=60, stale-while-revalidate=30";
1033
+ };
1034
+ /** Medium cache (5 minutes) */
1035
+ readonly medium: {
1036
+ readonly 'Cache-Control': "public, max-age=300, stale-while-revalidate=60";
1037
+ };
1038
+ /** Long cache (1 hour) */
1039
+ readonly long: {
1040
+ readonly 'Cache-Control': "public, max-age=3600, stale-while-revalidate=300";
1041
+ };
1042
+ /** Immutable (1 year) */
1043
+ readonly immutable: {
1044
+ readonly 'Cache-Control': "public, max-age=31536000, immutable";
1045
+ };
1046
+ };
1047
+ interface ApiResponse<T = unknown> {
1048
+ success: boolean;
1049
+ data?: T;
1050
+ error?: string;
1051
+ code?: string;
1052
+ }
1053
+ /**
1054
+ * Creates a success API response.
1055
+ */
1056
+ declare function successResponse<T>(data: T): ApiResponse<T>;
1057
+ /**
1058
+ * Creates an error API response.
1059
+ */
1060
+ declare function errorResponse(message: string, code?: string): ApiResponse<never>;
1061
+ /**
1062
+ * Validates required fields in a request body.
1063
+ *
1064
+ * @throws Error if required fields are missing
1065
+ */
1066
+ declare function validateRequired(body: Record<string, unknown>, fields: string[]): void;
1067
+ /**
1068
+ * Extracts query parameters from a URL.
1069
+ */
1070
+ declare function parseQueryParams(url: string): Record<string, string>;
1071
+ /**
1072
+ * Builds a URL with query parameters.
1073
+ */
1074
+ declare function buildUrl(base: string, params: Record<string, string | undefined>): string;
1075
+ /**
1076
+ * Rate limiting bucket.
1077
+ */
1078
+ interface RateLimitBucket {
1079
+ count: number;
1080
+ resetAt: number;
1081
+ }
1082
+ /**
1083
+ * Simple in-memory rate limiter.
1084
+ *
1085
+ * @example
1086
+ * ```typescript
1087
+ * const limiter = createRateLimiter({ maxRequests: 100, windowMs: 60000 });
1088
+ *
1089
+ * // In your API handler:
1090
+ * if (!limiter.check(clientIp)) {
1091
+ * return { error: 'Rate limit exceeded' };
1092
+ * }
1093
+ * ```
1094
+ */
1095
+ declare function createRateLimiter(options: {
1096
+ maxRequests: number;
1097
+ windowMs: number;
1098
+ }): {
1099
+ /**
1100
+ * Checks if a key is within rate limits.
1101
+ * Returns true if allowed, false if rate limited.
1102
+ */
1103
+ check(key: string): boolean;
1104
+ /**
1105
+ * Gets remaining requests for a key.
1106
+ */
1107
+ remaining(key: string): number;
1108
+ /**
1109
+ * Resets the limiter for a key.
1110
+ */
1111
+ reset(key: string): void;
1112
+ /**
1113
+ * Clears all rate limit data.
1114
+ */
1115
+ clear(): void;
1116
+ };
1117
+ /**
1118
+ * Parses a Stellar address from various formats.
1119
+ * Handles federation addresses, muxed accounts, etc.
1120
+ */
1121
+ declare function parseAddress(input: string): {
1122
+ address: string;
1123
+ muxedId?: string;
1124
+ federation?: string;
1125
+ };
1126
+
597
1127
  /**
598
1128
  * Base error class for all Stellar Snaps SDK errors.
599
1129
  * Includes an error code for programmatic error handling.
@@ -629,5 +1159,24 @@ declare class InvalidAssetError extends StellarSnapError {
629
1159
  declare class InvalidUriError extends StellarSnapError {
630
1160
  constructor(message: string);
631
1161
  }
1162
+ /**
1163
+ * Thrown when a snap is not found (404 from API).
1164
+ */
1165
+ declare class SnapNotFoundError extends StellarSnapError {
1166
+ constructor(snapId: string);
1167
+ }
1168
+ /**
1169
+ * Thrown when the caller is not authorized to perform the action (e.g. delete another user's snap).
1170
+ */
1171
+ declare class SnapUnauthorizedError extends StellarSnapError {
1172
+ constructor(message?: string);
1173
+ }
1174
+ /**
1175
+ * Thrown when the Stellar Snaps API returns an error.
1176
+ */
1177
+ declare class SnapApiError extends StellarSnapError {
1178
+ statusCode?: number | undefined;
1179
+ constructor(message: string, statusCode?: number | undefined);
1180
+ }
632
1181
 
633
- export { type BuildPaymentOptions, type CreateDiscoveryFileOptions, type CreateSnapOptions, type CreateSnapResult, type DiscoveryFile, type DiscoveryRule, type FreighterConnectionResult, HORIZON_URLS, InvalidAddressError, InvalidAmountError, InvalidAssetError, InvalidUriError, type MemoType, NETWORK_PASSPHRASES, type Network, type ParsedSnap, type PaymentSnapOptions, type PaymentSnapResult, StellarSnapError, type TransactionSnapOptions, type TransactionSnapResult, type TransactionSubmitResult, buildPaymentTransaction, connectFreighter, createAsset, createDiscoveryFile, createPaymentSnap, createSnap, createTransactionSnap, deleteSnap, getFreighterNetwork, getSnap, isFreighterConnected, isValidAmount, isValidAssetCode, isValidStellarAddress, listSnaps, matchUrlToRule, parseSnapUri, signWithFreighter, submitTransaction, validateDiscoveryFile };
1182
+ 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$1 as Snap, SnapApiError, type SnapMetadata, SnapNotFoundError, type Snap as SnapRecord, SnapUnauthorizedError, 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 };