@stellar-snaps/sdk 0.2.0 → 0.3.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/dist/index.d.mts +557 -17
- package/dist/index.d.ts +557 -17
- package/dist/index.js +627 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +589 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -112,22 +112,45 @@ declare function deleteSnap(id: string, options?: {
|
|
|
112
112
|
serverUrl?: string;
|
|
113
113
|
}): Promise<void>;
|
|
114
114
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Snap ID Generation
|
|
117
|
+
*
|
|
118
|
+
* Generates unique, URL-safe IDs for snaps.
|
|
119
|
+
*/
|
|
120
|
+
/**
|
|
121
|
+
* Generates a random snap ID.
|
|
122
|
+
*
|
|
123
|
+
* Uses a URL-safe alphabet similar to nanoid.
|
|
124
|
+
* Default length is 8 characters (similar to YouTube video IDs).
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* const id = generateSnapId(); // 'nk1VNcxo'
|
|
129
|
+
* const longId = generateSnapId(12); // 'nk1VNcxo4Abc'
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
declare function generateSnapId(length?: number): string;
|
|
133
|
+
/**
|
|
134
|
+
* Validates a snap ID format.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* isValidSnapId('nk1VNcxo'); // true
|
|
139
|
+
* isValidSnapId(''); // false
|
|
140
|
+
* isValidSnapId('has spaces'); // false
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
declare function isValidSnapId(id: string): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Extracts a snap ID from a URL.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* extractSnapId('https://stellarsnaps.com/s/nk1VNcxo'); // 'nk1VNcxo'
|
|
150
|
+
* extractSnapId('https://example.com/pay/abc123'); // 'abc123'
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
declare function extractSnapId(url: string, patterns?: string[]): string | null;
|
|
131
154
|
|
|
132
155
|
/**
|
|
133
156
|
* Stellar network passphrases used for transaction signing.
|
|
@@ -160,6 +183,132 @@ type Network = 'public' | 'testnet';
|
|
|
160
183
|
*/
|
|
161
184
|
type MemoType = 'MEMO_TEXT' | 'MEMO_ID' | 'MEMO_HASH' | 'MEMO_RETURN';
|
|
162
185
|
|
|
186
|
+
/**
|
|
187
|
+
* Database Schema Types
|
|
188
|
+
*
|
|
189
|
+
* Type definitions for snap storage. These types can be used
|
|
190
|
+
* with any database (PostgreSQL, SQLite, MongoDB, etc.).
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Snap record as stored in the database.
|
|
195
|
+
*/
|
|
196
|
+
interface Snap {
|
|
197
|
+
/** Unique snap ID (e.g., 'nk1VNcxo') */
|
|
198
|
+
id: string;
|
|
199
|
+
/** Creator's Stellar address */
|
|
200
|
+
creator: string;
|
|
201
|
+
/** Display title */
|
|
202
|
+
title: string;
|
|
203
|
+
/** Optional description */
|
|
204
|
+
description?: string | null;
|
|
205
|
+
/** Optional image URL */
|
|
206
|
+
imageUrl?: string | null;
|
|
207
|
+
/** Payment destination address */
|
|
208
|
+
destination: string;
|
|
209
|
+
/** Asset code (default: 'XLM') */
|
|
210
|
+
assetCode: string;
|
|
211
|
+
/** Asset issuer (required for non-XLM) */
|
|
212
|
+
assetIssuer?: string | null;
|
|
213
|
+
/** Fixed amount (null = payer chooses) */
|
|
214
|
+
amount?: string | null;
|
|
215
|
+
/** Transaction memo */
|
|
216
|
+
memo?: string | null;
|
|
217
|
+
/** Memo type */
|
|
218
|
+
memoType: MemoType | string;
|
|
219
|
+
/** Network ('public' or 'testnet') */
|
|
220
|
+
network: Network | string;
|
|
221
|
+
/** Creation timestamp */
|
|
222
|
+
createdAt: Date | string;
|
|
223
|
+
/** Last update timestamp */
|
|
224
|
+
updatedAt: Date | string;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Input for creating a new snap.
|
|
228
|
+
*/
|
|
229
|
+
interface CreateSnapInput {
|
|
230
|
+
/** Creator's Stellar address (required) */
|
|
231
|
+
creator: string;
|
|
232
|
+
/** Display title (required) */
|
|
233
|
+
title: string;
|
|
234
|
+
/** Payment destination address (required) */
|
|
235
|
+
destination: string;
|
|
236
|
+
/** Optional description */
|
|
237
|
+
description?: string;
|
|
238
|
+
/** Optional image URL */
|
|
239
|
+
imageUrl?: string;
|
|
240
|
+
/** Asset code (default: 'XLM') */
|
|
241
|
+
assetCode?: string;
|
|
242
|
+
/** Asset issuer (required for non-XLM) */
|
|
243
|
+
assetIssuer?: string;
|
|
244
|
+
/** Fixed amount */
|
|
245
|
+
amount?: string;
|
|
246
|
+
/** Transaction memo */
|
|
247
|
+
memo?: string;
|
|
248
|
+
/** Memo type (default: 'MEMO_TEXT') */
|
|
249
|
+
memoType?: MemoType;
|
|
250
|
+
/** Network (default: 'testnet') */
|
|
251
|
+
network?: Network;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Input for updating a snap.
|
|
255
|
+
*/
|
|
256
|
+
interface UpdateSnapInput {
|
|
257
|
+
/** Display title */
|
|
258
|
+
title?: string;
|
|
259
|
+
/** Description */
|
|
260
|
+
description?: string | null;
|
|
261
|
+
/** Image URL */
|
|
262
|
+
imageUrl?: string | null;
|
|
263
|
+
/** Payment amount */
|
|
264
|
+
amount?: string | null;
|
|
265
|
+
/** Transaction memo */
|
|
266
|
+
memo?: string | null;
|
|
267
|
+
/** Memo type */
|
|
268
|
+
memoType?: MemoType;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Validates snap input data.
|
|
272
|
+
*
|
|
273
|
+
* @throws Error if validation fails
|
|
274
|
+
*/
|
|
275
|
+
declare function validateSnapInput(input: CreateSnapInput): void;
|
|
276
|
+
/**
|
|
277
|
+
* Creates a snap object with defaults.
|
|
278
|
+
*/
|
|
279
|
+
declare function createSnapObject(id: string, input: CreateSnapInput): Snap;
|
|
280
|
+
/**
|
|
281
|
+
* SQL schema for PostgreSQL.
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```typescript
|
|
285
|
+
* // Run this SQL to create the snaps table:
|
|
286
|
+
* await db.execute(POSTGRES_SCHEMA);
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
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";
|
|
290
|
+
/**
|
|
291
|
+
* SQL schema for SQLite.
|
|
292
|
+
*/
|
|
293
|
+
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";
|
|
294
|
+
|
|
295
|
+
interface PaymentSnapOptions {
|
|
296
|
+
destination: string;
|
|
297
|
+
amount?: string;
|
|
298
|
+
assetCode?: string;
|
|
299
|
+
assetIssuer?: string;
|
|
300
|
+
memo?: string;
|
|
301
|
+
memoType?: 'MEMO_TEXT' | 'MEMO_ID' | 'MEMO_HASH' | 'MEMO_RETURN';
|
|
302
|
+
message?: string;
|
|
303
|
+
network?: 'public' | 'testnet';
|
|
304
|
+
callback?: string;
|
|
305
|
+
}
|
|
306
|
+
interface PaymentSnapResult {
|
|
307
|
+
uri: string;
|
|
308
|
+
params: Record<string, string>;
|
|
309
|
+
}
|
|
310
|
+
declare function createPaymentSnap(options: PaymentSnapOptions): PaymentSnapResult;
|
|
311
|
+
|
|
163
312
|
/**
|
|
164
313
|
* Options for creating a transaction snap URI.
|
|
165
314
|
* Used for advanced use cases where you need to sign arbitrary transactions,
|
|
@@ -594,6 +743,397 @@ declare function validateDiscoveryFile(file: unknown): file is DiscoveryFile;
|
|
|
594
743
|
*/
|
|
595
744
|
declare function matchUrlToRule(pathname: string, rules: DiscoveryRule[]): string | null;
|
|
596
745
|
|
|
746
|
+
/**
|
|
747
|
+
* URL Resolution Utilities
|
|
748
|
+
*
|
|
749
|
+
* Handles shortened URL detection and resolution for snap links.
|
|
750
|
+
*/
|
|
751
|
+
/** List of known URL shortener domains */
|
|
752
|
+
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"];
|
|
753
|
+
interface ResolvedUrl {
|
|
754
|
+
/** The final resolved URL after following redirects */
|
|
755
|
+
url: string;
|
|
756
|
+
/** The domain of the resolved URL */
|
|
757
|
+
domain: string;
|
|
758
|
+
/** The original URL before resolution */
|
|
759
|
+
originalUrl: string;
|
|
760
|
+
/** Whether the URL was shortened */
|
|
761
|
+
wasShortened: boolean;
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* Checks if a URL is from a known URL shortener.
|
|
765
|
+
*
|
|
766
|
+
* @example
|
|
767
|
+
* ```typescript
|
|
768
|
+
* isShortenerUrl('https://t.co/abc123'); // true
|
|
769
|
+
* isShortenerUrl('https://stellarsnaps.com/s/abc'); // false
|
|
770
|
+
* ```
|
|
771
|
+
*/
|
|
772
|
+
declare function isShortenerUrl(url: string): boolean;
|
|
773
|
+
/**
|
|
774
|
+
* Extracts the domain from a URL.
|
|
775
|
+
*
|
|
776
|
+
* @example
|
|
777
|
+
* ```typescript
|
|
778
|
+
* extractDomain('https://stellarsnaps.com/s/abc123'); // 'stellarsnaps.com'
|
|
779
|
+
* ```
|
|
780
|
+
*/
|
|
781
|
+
declare function extractDomain(url: string): string;
|
|
782
|
+
/**
|
|
783
|
+
* Extracts the path from a URL.
|
|
784
|
+
*
|
|
785
|
+
* @example
|
|
786
|
+
* ```typescript
|
|
787
|
+
* extractPath('https://stellarsnaps.com/s/abc123'); // '/s/abc123'
|
|
788
|
+
* ```
|
|
789
|
+
*/
|
|
790
|
+
declare function extractPath(url: string): string;
|
|
791
|
+
/**
|
|
792
|
+
* Resolves a shortened URL by following redirects.
|
|
793
|
+
* This is a server-side function that requires fetch with redirect following.
|
|
794
|
+
*
|
|
795
|
+
* @example
|
|
796
|
+
* ```typescript
|
|
797
|
+
* const resolved = await resolveUrl('https://t.co/abc123');
|
|
798
|
+
* console.log(resolved.url); // 'https://stellarsnaps.com/s/xyz789'
|
|
799
|
+
* ```
|
|
800
|
+
*/
|
|
801
|
+
declare function resolveUrl(url: string): Promise<ResolvedUrl>;
|
|
802
|
+
/**
|
|
803
|
+
* Batch resolve multiple URLs.
|
|
804
|
+
*
|
|
805
|
+
* @example
|
|
806
|
+
* ```typescript
|
|
807
|
+
* const urls = ['https://t.co/a', 'https://bit.ly/b'];
|
|
808
|
+
* const resolved = await resolveUrls(urls);
|
|
809
|
+
* ```
|
|
810
|
+
*/
|
|
811
|
+
declare function resolveUrls(urls: string[]): Promise<ResolvedUrl[]>;
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* Domain Registry
|
|
815
|
+
*
|
|
816
|
+
* Manages trusted/verified domains for snap hosting.
|
|
817
|
+
*/
|
|
818
|
+
type DomainStatus = 'verified' | 'unverified' | 'blocked';
|
|
819
|
+
interface DomainEntry {
|
|
820
|
+
/** The domain name */
|
|
821
|
+
domain: string;
|
|
822
|
+
/** Trust status */
|
|
823
|
+
status: DomainStatus;
|
|
824
|
+
/** Optional display name */
|
|
825
|
+
name?: string;
|
|
826
|
+
/** Optional description */
|
|
827
|
+
description?: string;
|
|
828
|
+
/** When the domain was added */
|
|
829
|
+
addedAt?: string;
|
|
830
|
+
/** When the domain was last verified */
|
|
831
|
+
verifiedAt?: string;
|
|
832
|
+
}
|
|
833
|
+
interface Registry {
|
|
834
|
+
/** List of all domain entries */
|
|
835
|
+
domains: DomainEntry[];
|
|
836
|
+
/** When the registry was last updated */
|
|
837
|
+
updatedAt: string;
|
|
838
|
+
/** Registry version */
|
|
839
|
+
version: string;
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Creates a new registry.
|
|
843
|
+
*
|
|
844
|
+
* @example
|
|
845
|
+
* ```typescript
|
|
846
|
+
* const registry = createRegistry([
|
|
847
|
+
* { domain: 'stellarsnaps.com', status: 'verified', name: 'Stellar Snaps' },
|
|
848
|
+
* { domain: 'example.com', status: 'unverified' },
|
|
849
|
+
* ]);
|
|
850
|
+
* ```
|
|
851
|
+
*/
|
|
852
|
+
declare function createRegistry(domains?: DomainEntry[]): Registry;
|
|
853
|
+
/**
|
|
854
|
+
* Adds a domain to the registry.
|
|
855
|
+
*/
|
|
856
|
+
declare function addDomain(registry: Registry, entry: DomainEntry): Registry;
|
|
857
|
+
/**
|
|
858
|
+
* Removes a domain from the registry.
|
|
859
|
+
*/
|
|
860
|
+
declare function removeDomain(registry: Registry, domain: string): Registry;
|
|
861
|
+
/**
|
|
862
|
+
* Gets the status of a domain.
|
|
863
|
+
*
|
|
864
|
+
* @example
|
|
865
|
+
* ```typescript
|
|
866
|
+
* const status = getDomainStatus(registry, 'stellarsnaps.com');
|
|
867
|
+
* // { domain: 'stellarsnaps.com', status: 'verified', ... }
|
|
868
|
+
* ```
|
|
869
|
+
*/
|
|
870
|
+
declare function getDomainStatus(registry: Registry, domain: string): DomainEntry | null;
|
|
871
|
+
/**
|
|
872
|
+
* Checks if a domain is verified.
|
|
873
|
+
*/
|
|
874
|
+
declare function isDomainVerified(registry: Registry, domain: string): boolean;
|
|
875
|
+
/**
|
|
876
|
+
* Checks if a domain is blocked.
|
|
877
|
+
*/
|
|
878
|
+
declare function isDomainBlocked(registry: Registry, domain: string): boolean;
|
|
879
|
+
/**
|
|
880
|
+
* Gets all verified domains.
|
|
881
|
+
*/
|
|
882
|
+
declare function getVerifiedDomains(registry: Registry): DomainEntry[];
|
|
883
|
+
/**
|
|
884
|
+
* Gets all blocked domains.
|
|
885
|
+
*/
|
|
886
|
+
declare function getBlockedDomains(registry: Registry): DomainEntry[];
|
|
887
|
+
/**
|
|
888
|
+
* Validates a registry object.
|
|
889
|
+
*/
|
|
890
|
+
declare function validateRegistry(registry: unknown): registry is Registry;
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* Blockchain Explorer Utilities
|
|
894
|
+
*
|
|
895
|
+
* Generate links to Stellar blockchain explorers.
|
|
896
|
+
*/
|
|
897
|
+
|
|
898
|
+
/** Supported explorer types */
|
|
899
|
+
type ExplorerType = 'stellar.expert' | 'stellarchain' | 'horizon';
|
|
900
|
+
/** Explorer base URLs */
|
|
901
|
+
declare const EXPLORER_URLS: Record<ExplorerType, Record<Network, string>>;
|
|
902
|
+
/**
|
|
903
|
+
* Generates a transaction URL for a blockchain explorer.
|
|
904
|
+
*
|
|
905
|
+
* @example
|
|
906
|
+
* ```typescript
|
|
907
|
+
* getTransactionUrl('abc123...', 'testnet');
|
|
908
|
+
* // 'https://stellar.expert/explorer/testnet/tx/abc123...'
|
|
909
|
+
*
|
|
910
|
+
* getTransactionUrl('abc123...', 'public', 'stellarchain');
|
|
911
|
+
* // 'https://stellarchain.io/transactions/abc123...'
|
|
912
|
+
* ```
|
|
913
|
+
*/
|
|
914
|
+
declare function getTransactionUrl(hash: string, network?: Network, explorer?: ExplorerType): string;
|
|
915
|
+
/**
|
|
916
|
+
* Generates an account URL for a blockchain explorer.
|
|
917
|
+
*
|
|
918
|
+
* @example
|
|
919
|
+
* ```typescript
|
|
920
|
+
* getAccountUrl('GABC...', 'testnet');
|
|
921
|
+
* // 'https://stellar.expert/explorer/testnet/account/GABC...'
|
|
922
|
+
* ```
|
|
923
|
+
*/
|
|
924
|
+
declare function getAccountUrl(address: string, network?: Network, explorer?: ExplorerType): string;
|
|
925
|
+
/**
|
|
926
|
+
* Generates an asset URL for a blockchain explorer.
|
|
927
|
+
*
|
|
928
|
+
* @example
|
|
929
|
+
* ```typescript
|
|
930
|
+
* getAssetUrl('USDC', 'GCNY...', 'public');
|
|
931
|
+
* // 'https://stellar.expert/explorer/public/asset/USDC-GCNY...'
|
|
932
|
+
* ```
|
|
933
|
+
*/
|
|
934
|
+
declare function getAssetUrl(code: string, issuer: string, network?: Network, explorer?: ExplorerType): string;
|
|
935
|
+
/**
|
|
936
|
+
* Generates an operation URL for a blockchain explorer.
|
|
937
|
+
*/
|
|
938
|
+
declare function getOperationUrl(operationId: string, network?: Network, explorer?: ExplorerType): string;
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* Meta Tag Generation
|
|
942
|
+
*
|
|
943
|
+
* Generate OpenGraph and Twitter meta tags for snap pages.
|
|
944
|
+
*/
|
|
945
|
+
interface SnapMetadata {
|
|
946
|
+
/** Snap title */
|
|
947
|
+
title: string;
|
|
948
|
+
/** Snap description */
|
|
949
|
+
description?: string;
|
|
950
|
+
/** Image URL */
|
|
951
|
+
imageUrl?: string;
|
|
952
|
+
/** Payment amount */
|
|
953
|
+
amount?: string;
|
|
954
|
+
/** Asset code */
|
|
955
|
+
assetCode?: string;
|
|
956
|
+
/** Full snap URL */
|
|
957
|
+
url: string;
|
|
958
|
+
/** Site name */
|
|
959
|
+
siteName?: string;
|
|
960
|
+
}
|
|
961
|
+
interface MetaTags {
|
|
962
|
+
/** OpenGraph tags */
|
|
963
|
+
og: Record<string, string>;
|
|
964
|
+
/** Twitter card tags */
|
|
965
|
+
twitter: Record<string, string>;
|
|
966
|
+
/** Standard meta tags */
|
|
967
|
+
standard: Record<string, string>;
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Generates meta tags for a snap page.
|
|
971
|
+
*
|
|
972
|
+
* @example
|
|
973
|
+
* ```typescript
|
|
974
|
+
* const tags = generateMetaTags({
|
|
975
|
+
* title: 'Pay for Coffee',
|
|
976
|
+
* description: 'Send 5 XLM for coffee',
|
|
977
|
+
* amount: '5',
|
|
978
|
+
* assetCode: 'XLM',
|
|
979
|
+
* url: 'https://stellarsnaps.com/s/abc123',
|
|
980
|
+
* });
|
|
981
|
+
*
|
|
982
|
+
* // Use in Next.js metadata:
|
|
983
|
+
* export const metadata = {
|
|
984
|
+
* title: tags.standard.title,
|
|
985
|
+
* openGraph: tags.og,
|
|
986
|
+
* twitter: tags.twitter,
|
|
987
|
+
* };
|
|
988
|
+
* ```
|
|
989
|
+
*/
|
|
990
|
+
declare function generateMetaTags(metadata: SnapMetadata): MetaTags;
|
|
991
|
+
/**
|
|
992
|
+
* Converts meta tags to HTML string.
|
|
993
|
+
*
|
|
994
|
+
* @example
|
|
995
|
+
* ```typescript
|
|
996
|
+
* const html = metaTagsToHtml(tags);
|
|
997
|
+
* // <meta property="og:title" content="Pay for Coffee" />
|
|
998
|
+
* // <meta property="og:description" content="..." />
|
|
999
|
+
* // ...
|
|
1000
|
+
* ```
|
|
1001
|
+
*/
|
|
1002
|
+
declare function metaTagsToHtml(tags: MetaTags): string;
|
|
1003
|
+
/**
|
|
1004
|
+
* Generates JSON-LD structured data for a snap.
|
|
1005
|
+
*
|
|
1006
|
+
* @example
|
|
1007
|
+
* ```typescript
|
|
1008
|
+
* const jsonLd = generateJsonLd({
|
|
1009
|
+
* title: 'Pay for Coffee',
|
|
1010
|
+
* amount: '5',
|
|
1011
|
+
* assetCode: 'XLM',
|
|
1012
|
+
* url: 'https://stellarsnaps.com/s/abc123',
|
|
1013
|
+
* });
|
|
1014
|
+
* ```
|
|
1015
|
+
*/
|
|
1016
|
+
declare function generateJsonLd(metadata: SnapMetadata): object;
|
|
1017
|
+
|
|
1018
|
+
/**
|
|
1019
|
+
* Server Utilities
|
|
1020
|
+
*
|
|
1021
|
+
* Helper functions for building Stellar Snaps API endpoints.
|
|
1022
|
+
*/
|
|
1023
|
+
/**
|
|
1024
|
+
* Standard CORS headers for API responses.
|
|
1025
|
+
*/
|
|
1026
|
+
declare const CORS_HEADERS: {
|
|
1027
|
+
readonly 'Access-Control-Allow-Origin': "*";
|
|
1028
|
+
readonly 'Access-Control-Allow-Methods': "GET, POST, PUT, DELETE, OPTIONS";
|
|
1029
|
+
readonly 'Access-Control-Allow-Headers': "Content-Type, Authorization";
|
|
1030
|
+
readonly 'Access-Control-Max-Age': "86400";
|
|
1031
|
+
};
|
|
1032
|
+
/**
|
|
1033
|
+
* Cache headers for different response types.
|
|
1034
|
+
*/
|
|
1035
|
+
declare const CACHE_HEADERS: {
|
|
1036
|
+
/** No caching */
|
|
1037
|
+
readonly none: {
|
|
1038
|
+
readonly 'Cache-Control': "no-store, no-cache, must-revalidate";
|
|
1039
|
+
};
|
|
1040
|
+
/** Short cache (1 minute) */
|
|
1041
|
+
readonly short: {
|
|
1042
|
+
readonly 'Cache-Control': "public, max-age=60, stale-while-revalidate=30";
|
|
1043
|
+
};
|
|
1044
|
+
/** Medium cache (5 minutes) */
|
|
1045
|
+
readonly medium: {
|
|
1046
|
+
readonly 'Cache-Control': "public, max-age=300, stale-while-revalidate=60";
|
|
1047
|
+
};
|
|
1048
|
+
/** Long cache (1 hour) */
|
|
1049
|
+
readonly long: {
|
|
1050
|
+
readonly 'Cache-Control': "public, max-age=3600, stale-while-revalidate=300";
|
|
1051
|
+
};
|
|
1052
|
+
/** Immutable (1 year) */
|
|
1053
|
+
readonly immutable: {
|
|
1054
|
+
readonly 'Cache-Control': "public, max-age=31536000, immutable";
|
|
1055
|
+
};
|
|
1056
|
+
};
|
|
1057
|
+
interface ApiResponse<T = unknown> {
|
|
1058
|
+
success: boolean;
|
|
1059
|
+
data?: T;
|
|
1060
|
+
error?: string;
|
|
1061
|
+
code?: string;
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* Creates a success API response.
|
|
1065
|
+
*/
|
|
1066
|
+
declare function successResponse<T>(data: T): ApiResponse<T>;
|
|
1067
|
+
/**
|
|
1068
|
+
* Creates an error API response.
|
|
1069
|
+
*/
|
|
1070
|
+
declare function errorResponse(message: string, code?: string): ApiResponse<never>;
|
|
1071
|
+
/**
|
|
1072
|
+
* Validates required fields in a request body.
|
|
1073
|
+
*
|
|
1074
|
+
* @throws Error if required fields are missing
|
|
1075
|
+
*/
|
|
1076
|
+
declare function validateRequired(body: Record<string, unknown>, fields: string[]): void;
|
|
1077
|
+
/**
|
|
1078
|
+
* Extracts query parameters from a URL.
|
|
1079
|
+
*/
|
|
1080
|
+
declare function parseQueryParams(url: string): Record<string, string>;
|
|
1081
|
+
/**
|
|
1082
|
+
* Builds a URL with query parameters.
|
|
1083
|
+
*/
|
|
1084
|
+
declare function buildUrl(base: string, params: Record<string, string | undefined>): string;
|
|
1085
|
+
/**
|
|
1086
|
+
* Rate limiting bucket.
|
|
1087
|
+
*/
|
|
1088
|
+
interface RateLimitBucket {
|
|
1089
|
+
count: number;
|
|
1090
|
+
resetAt: number;
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* Simple in-memory rate limiter.
|
|
1094
|
+
*
|
|
1095
|
+
* @example
|
|
1096
|
+
* ```typescript
|
|
1097
|
+
* const limiter = createRateLimiter({ maxRequests: 100, windowMs: 60000 });
|
|
1098
|
+
*
|
|
1099
|
+
* // In your API handler:
|
|
1100
|
+
* if (!limiter.check(clientIp)) {
|
|
1101
|
+
* return { error: 'Rate limit exceeded' };
|
|
1102
|
+
* }
|
|
1103
|
+
* ```
|
|
1104
|
+
*/
|
|
1105
|
+
declare function createRateLimiter(options: {
|
|
1106
|
+
maxRequests: number;
|
|
1107
|
+
windowMs: number;
|
|
1108
|
+
}): {
|
|
1109
|
+
/**
|
|
1110
|
+
* Checks if a key is within rate limits.
|
|
1111
|
+
* Returns true if allowed, false if rate limited.
|
|
1112
|
+
*/
|
|
1113
|
+
check(key: string): boolean;
|
|
1114
|
+
/**
|
|
1115
|
+
* Gets remaining requests for a key.
|
|
1116
|
+
*/
|
|
1117
|
+
remaining(key: string): number;
|
|
1118
|
+
/**
|
|
1119
|
+
* Resets the limiter for a key.
|
|
1120
|
+
*/
|
|
1121
|
+
reset(key: string): void;
|
|
1122
|
+
/**
|
|
1123
|
+
* Clears all rate limit data.
|
|
1124
|
+
*/
|
|
1125
|
+
clear(): void;
|
|
1126
|
+
};
|
|
1127
|
+
/**
|
|
1128
|
+
* Parses a Stellar address from various formats.
|
|
1129
|
+
* Handles federation addresses, muxed accounts, etc.
|
|
1130
|
+
*/
|
|
1131
|
+
declare function parseAddress(input: string): {
|
|
1132
|
+
address: string;
|
|
1133
|
+
muxedId?: string;
|
|
1134
|
+
federation?: string;
|
|
1135
|
+
};
|
|
1136
|
+
|
|
597
1137
|
/**
|
|
598
1138
|
* Base error class for all Stellar Snaps SDK errors.
|
|
599
1139
|
* Includes an error code for programmatic error handling.
|
|
@@ -630,4 +1170,4 @@ declare class InvalidUriError extends StellarSnapError {
|
|
|
630
1170
|
constructor(message: string);
|
|
631
1171
|
}
|
|
632
1172
|
|
|
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 };
|
|
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 };
|