@medialane/sdk 0.198.0 → 0.200.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.
Files changed (92) hide show
  1. package/README.md +86 -41
  2. package/dist/chains-CmwjZVU7.d.cts +85 -0
  3. package/dist/chains-CmwjZVU7.d.ts +85 -0
  4. package/dist/chunk-3HPMEDYH.cjs +967 -0
  5. package/dist/chunk-3HPMEDYH.cjs.map +1 -0
  6. package/dist/{chunk-3ME5YKTW.js → chunk-5KY6P434.js} +2 -2
  7. package/dist/chunk-5KY6P434.js.map +1 -0
  8. package/dist/chunk-F7W6IWTL.js +660 -0
  9. package/dist/chunk-F7W6IWTL.js.map +1 -0
  10. package/dist/chunk-GIBIHGSV.js +916 -0
  11. package/dist/chunk-GIBIHGSV.js.map +1 -0
  12. package/dist/chunk-GV4A2WNO.js +444 -0
  13. package/dist/chunk-GV4A2WNO.js.map +1 -0
  14. package/dist/{chunk-7EYJC5CB.cjs → chunk-H2NJB3AK.cjs} +2 -2
  15. package/dist/chunk-H2NJB3AK.cjs.map +1 -0
  16. package/dist/chunk-KGAGWULG.js +932 -0
  17. package/dist/chunk-KGAGWULG.js.map +1 -0
  18. package/dist/chunk-MEJ47LC3.cjs +463 -0
  19. package/dist/chunk-MEJ47LC3.cjs.map +1 -0
  20. package/dist/chunk-W76AZ5WC.cjs +376 -0
  21. package/dist/chunk-W76AZ5WC.cjs.map +1 -0
  22. package/dist/chunk-WRBXQPRL.js +323 -0
  23. package/dist/chunk-WRBXQPRL.js.map +1 -0
  24. package/dist/chunk-ZLMIHQWM.cjs +975 -0
  25. package/dist/chunk-ZLMIHQWM.cjs.map +1 -0
  26. package/dist/chunk-ZVANOWIB.cjs +688 -0
  27. package/dist/chunk-ZVANOWIB.cjs.map +1 -0
  28. package/dist/contract/index.cjs +88 -261
  29. package/dist/contract/index.cjs.map +1 -1
  30. package/dist/contract/index.d.cts +139 -4
  31. package/dist/contract/index.d.ts +139 -4
  32. package/dist/contract/index.js +4 -220
  33. package/dist/contract/index.js.map +1 -1
  34. package/dist/evm/index.cjs +3 -3
  35. package/dist/evm/index.d.cts +2 -1
  36. package/dist/evm/index.d.ts +2 -1
  37. package/dist/evm/index.js +1 -1
  38. package/dist/fetch-Cx9Pr7-B.d.cts +3 -0
  39. package/dist/fetch-Cx9Pr7-B.d.ts +3 -0
  40. package/dist/index.cjs +177 -833
  41. package/dist/index.cjs.map +1 -1
  42. package/dist/index.d.cts +54 -132
  43. package/dist/index.d.ts +54 -132
  44. package/dist/index.js +6 -659
  45. package/dist/index.js.map +1 -1
  46. package/dist/passkey-errors-B0HGcjPc.d.ts +981 -0
  47. package/dist/passkey-errors-yndCFeHv.d.cts +981 -0
  48. package/dist/provisioning-CwRkCN8D.d.cts +14 -0
  49. package/dist/provisioning-CwRkCN8D.d.ts +14 -0
  50. package/dist/{provisioning-BUYiU8Tr.d.ts → responses-D3nBY71f.d.cts} +40 -48
  51. package/dist/{provisioning-BUYiU8Tr.d.cts → responses-D3nBY71f.d.ts} +40 -48
  52. package/dist/server/index.cjs +117 -0
  53. package/dist/server/index.cjs.map +1 -0
  54. package/dist/server/index.d.cts +98 -0
  55. package/dist/server/index.d.ts +98 -0
  56. package/dist/server/index.js +4 -0
  57. package/dist/server/index.js.map +1 -0
  58. package/dist/services-B15RJBSW.d.cts +728 -0
  59. package/dist/services-BAnTJhwt.d.ts +728 -0
  60. package/dist/solana/index.cjs +2 -2
  61. package/dist/solana/index.d.cts +2 -1
  62. package/dist/solana/index.d.ts +2 -1
  63. package/dist/solana/index.js +1 -1
  64. package/dist/starknet/index.cjs +898 -1729
  65. package/dist/starknet/index.cjs.map +1 -1
  66. package/dist/starknet/index.d.cts +98 -467
  67. package/dist/starknet/index.d.ts +98 -467
  68. package/dist/starknet/index.js +704 -1680
  69. package/dist/starknet/index.js.map +1 -1
  70. package/dist/stellar/index.cjs +2 -2
  71. package/dist/stellar/index.d.cts +2 -1
  72. package/dist/stellar/index.d.ts +2 -1
  73. package/dist/stellar/index.js +1 -1
  74. package/dist/types-BW6ktwcT.d.ts +71 -0
  75. package/dist/types-BftPOVEJ.d.cts +71 -0
  76. package/dist/wallet/index.cjs +240 -0
  77. package/dist/wallet/index.cjs.map +1 -0
  78. package/dist/wallet/index.d.cts +319 -0
  79. package/dist/wallet/index.d.ts +319 -0
  80. package/dist/wallet/index.js +7 -0
  81. package/dist/wallet/index.js.map +1 -0
  82. package/package.json +13 -2
  83. package/dist/chunk-2R7XBA34.cjs +0 -1938
  84. package/dist/chunk-2R7XBA34.cjs.map +0 -1
  85. package/dist/chunk-3ME5YKTW.js.map +0 -1
  86. package/dist/chunk-6WVUUBFI.js +0 -1853
  87. package/dist/chunk-6WVUUBFI.js.map +0 -1
  88. package/dist/chunk-7EYJC5CB.cjs.map +0 -1
  89. package/dist/errors-CZm-NZK0.d.cts +0 -1754
  90. package/dist/errors-h6H6cj3Q.d.ts +0 -1754
  91. package/dist/types-DC4jNPAF.d.cts +0 -153
  92. package/dist/types-DC4jNPAF.d.ts +0 -153
@@ -0,0 +1,932 @@
1
+ import { getCoordinates } from './chunk-5KY6P434.js';
2
+ import { intentPath, dropStateFromWire } from './chunk-WRBXQPRL.js';
3
+ import { keccak_256 } from '@noble/hashes/sha3.js';
4
+ import { base58, base32 } from '@scure/base';
5
+
6
+ // src/errors.ts
7
+ var UserFacingError = class extends Error {
8
+ constructor(message) {
9
+ super(message);
10
+ this.name = "UserFacingError";
11
+ }
12
+ };
13
+ var MedialaneError = class extends Error {
14
+ constructor(message, code = "UNKNOWN", cause) {
15
+ super(message);
16
+ this.code = code;
17
+ this.cause = cause;
18
+ this.name = "MedialaneError";
19
+ }
20
+ };
21
+ var RESOURCE_NOT_FOUND = [
22
+ ["/v1/orders", "ORDER_NOT_FOUND"],
23
+ ["/v1/tokens", "TOKEN_NOT_FOUND"],
24
+ ["/v1/collections", "COLLECTION_NOT_FOUND"],
25
+ ["/v1/intents", "INTENT_NOT_FOUND"]
26
+ ];
27
+ function errorCodeFor(status, path = "") {
28
+ if (status === 404) {
29
+ return RESOURCE_NOT_FOUND.find(([prefix]) => path.startsWith(prefix))?.[1] ?? "NOT_FOUND";
30
+ }
31
+ if (status === 429) return "RATE_LIMITED";
32
+ if (status === 410) return "INTENT_EXPIRED";
33
+ if (status === 401 || status === 403) return "UNAUTHORIZED";
34
+ if (status === 400) return "INVALID_PARAMS";
35
+ return "UNKNOWN";
36
+ }
37
+ var MedialaneApiError = class extends MedialaneError {
38
+ constructor(status, message, retryAfterMs, details, path, serverCode) {
39
+ super(message, errorCodeFor(status, path));
40
+ this.status = status;
41
+ this.retryAfterMs = retryAfterMs;
42
+ this.details = details;
43
+ this.serverCode = serverCode;
44
+ this.name = "MedialaneApiError";
45
+ }
46
+ };
47
+ function parseRetryAfter(value) {
48
+ if (!value) return void 0;
49
+ const seconds = Number(value);
50
+ if (Number.isFinite(seconds)) return Math.max(0, seconds * 1e3);
51
+ const date = Date.parse(value);
52
+ if (!Number.isNaN(date)) return Math.max(0, date - Date.now());
53
+ return void 0;
54
+ }
55
+ function normalizeAddress(chain, address) {
56
+ switch (chain) {
57
+ case "STARKNET":
58
+ return normalizeStarknet(address);
59
+ case "ETHEREUM":
60
+ case "BASE":
61
+ return normalizeEvm(address);
62
+ case "SOLANA":
63
+ return normalizeSolana(address);
64
+ case "STELLAR":
65
+ return normalizeStellar(address);
66
+ case "BITCOIN":
67
+ throw new Error("BITCOIN address normalization not implemented");
68
+ }
69
+ }
70
+ function normalizeStarknet(address) {
71
+ try {
72
+ const hex = BigInt(address).toString(16);
73
+ return "0x" + hex.padStart(64, "0").toLowerCase();
74
+ } catch {
75
+ throw new Error(`Invalid STARKNET address: "${address}"`);
76
+ }
77
+ }
78
+ function normalizeEvm(address) {
79
+ const m = /^0x([0-9a-fA-F]{40})$/.exec(address);
80
+ if (!m) throw new Error(`Invalid ETHEREUM/BASE address: "${address}"`);
81
+ const lower = m[1].toLowerCase();
82
+ const hash = keccak_256(new TextEncoder().encode(lower));
83
+ let out = "0x";
84
+ for (let i = 0; i < 40; i++) {
85
+ const nibble = hash[i >> 1] >> (i % 2 === 0 ? 4 : 0) & 15;
86
+ out += nibble >= 8 ? lower[i].toUpperCase() : lower[i];
87
+ }
88
+ return out;
89
+ }
90
+ function normalizeSolana(address) {
91
+ try {
92
+ const bytes = base58.decode(address);
93
+ if (bytes.length !== 32) throw new Error("not a 32-byte key");
94
+ return address;
95
+ } catch {
96
+ throw new Error(`Invalid SOLANA address: "${address}"`);
97
+ }
98
+ }
99
+ var STELLAR_VERSION_BYTES = /* @__PURE__ */ new Set([6 << 3, 2 << 3]);
100
+ function normalizeStellar(address) {
101
+ const upper = address.toUpperCase();
102
+ if (!/^[GC][A-Z2-7]{55}$/.test(upper)) {
103
+ throw new Error(`Invalid STELLAR address: "${address}"`);
104
+ }
105
+ let decoded;
106
+ try {
107
+ decoded = base32.decode(upper);
108
+ } catch {
109
+ throw new Error(`Invalid STELLAR address: "${address}"`);
110
+ }
111
+ if (decoded.length !== 35 || !STELLAR_VERSION_BYTES.has(decoded[0])) {
112
+ throw new Error(`Invalid STELLAR address: "${address}"`);
113
+ }
114
+ const payload = decoded.subarray(0, 33);
115
+ const checksum = decoded[33] | decoded[34] << 8;
116
+ if (crc16xmodem(payload) !== checksum) {
117
+ throw new Error(`Invalid STELLAR address: "${address}"`);
118
+ }
119
+ return upper;
120
+ }
121
+ function crc16xmodem(bytes) {
122
+ let crc = 0;
123
+ for (const byte of bytes) {
124
+ crc ^= byte << 8;
125
+ for (let i = 0; i < 8; i++) {
126
+ crc = crc & 32768 ? (crc << 1 ^ 4129) & 65535 : crc << 1 & 65535;
127
+ }
128
+ }
129
+ return crc;
130
+ }
131
+ function normalizeHash(hash) {
132
+ try {
133
+ const hex = BigInt(hash).toString(16);
134
+ return "0x" + hex.padStart(64, "0").toLowerCase();
135
+ } catch {
136
+ throw new Error(`Invalid hash: "${hash}"`);
137
+ }
138
+ }
139
+ function shortenAddress(chain, address, chars = 4) {
140
+ const norm = normalizeAddress(chain, address);
141
+ return `${norm.slice(0, chars + 2)}...${norm.slice(-chars)}`;
142
+ }
143
+
144
+ // src/utils/retry.ts
145
+ var DEFAULT_MAX_ATTEMPTS = 3;
146
+ var DEFAULT_BASE_DELAY_MS = 300;
147
+ var DEFAULT_MAX_DELAY_MS = 5e3;
148
+ function sleep(ms) {
149
+ return new Promise((resolve) => setTimeout(resolve, ms));
150
+ }
151
+ function isRetryableFor(method, err) {
152
+ if (err instanceof MedialaneApiError && err.status === 429) return true;
153
+ const isRead = method === "GET" || method === "HEAD";
154
+ if (!isRead) return false;
155
+ return err instanceof MedialaneApiError && err.status >= 500 || err instanceof TypeError;
156
+ }
157
+ async function withRetry(fn, opts, method = "GET") {
158
+ const maxAttempts = opts?.maxAttempts ?? DEFAULT_MAX_ATTEMPTS;
159
+ const baseDelayMs = opts?.baseDelayMs ?? DEFAULT_BASE_DELAY_MS;
160
+ const maxDelayMs = opts?.maxDelayMs ?? DEFAULT_MAX_DELAY_MS;
161
+ let lastError;
162
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
163
+ try {
164
+ return await fn();
165
+ } catch (err) {
166
+ lastError = err;
167
+ if (!isRetryableFor(method, err) || attempt === maxAttempts - 1) {
168
+ throw err;
169
+ }
170
+ const retryAfterMs = err instanceof MedialaneApiError ? err.retryAfterMs : void 0;
171
+ const backoff = baseDelayMs * Math.pow(2, attempt) + Math.random() * baseDelayMs;
172
+ const delay = Math.min(retryAfterMs ?? backoff, maxDelayMs);
173
+ await sleep(delay);
174
+ }
175
+ }
176
+ throw lastError;
177
+ }
178
+
179
+ // src/api/transport.ts
180
+ function queryString(query) {
181
+ if (!query) return "";
182
+ const params = new URLSearchParams();
183
+ for (const [key, value] of Object.entries(query)) {
184
+ if (value !== void 0 && value !== null && value !== "") params.set(key, String(value));
185
+ }
186
+ const qs = params.toString();
187
+ return qs ? `?${qs}` : "";
188
+ }
189
+ async function failureFrom(response, path) {
190
+ const text = await response.text().catch(() => response.statusText);
191
+ let message = `Request failed with status ${response.status}`;
192
+ let details = text;
193
+ let serverCode;
194
+ try {
195
+ const body = JSON.parse(text);
196
+ if (typeof body.error === "string" && body.error.trim() !== "") message = body.error;
197
+ if (typeof body.code === "string") serverCode = body.code;
198
+ details = body;
199
+ } catch {
200
+ details = text;
201
+ }
202
+ return new MedialaneApiError(
203
+ response.status,
204
+ message,
205
+ parseRetryAfter(response.headers.get("retry-after")),
206
+ details,
207
+ path,
208
+ serverCode
209
+ );
210
+ }
211
+ var Transport = class _Transport {
212
+ constructor(options) {
213
+ this.options = options;
214
+ this.baseUrl = options.baseUrl.replace(/\/$/, "");
215
+ this.headers = options.apiKey ? { "x-api-key": options.apiKey } : {};
216
+ this.chain = options.chain ?? "STARKNET";
217
+ }
218
+ withBearer(bearer) {
219
+ return new _Transport({ ...this.options, bearer });
220
+ }
221
+ settings() {
222
+ return this.options;
223
+ }
224
+ addr(address) {
225
+ return normalizeAddress(this.chain, address);
226
+ }
227
+ async request(path, opts = {}) {
228
+ const method = opts.method ?? "GET";
229
+ const url = `${this.baseUrl}${path}${queryString(opts.query)}`;
230
+ const headers = { ...this.headers };
231
+ const token = opts.bearer ?? this.defaultBearer();
232
+ if (token) headers.Authorization = `Bearer ${token}`;
233
+ let body;
234
+ if (opts.body instanceof FormData) {
235
+ body = opts.body;
236
+ } else if (opts.body !== void 0) {
237
+ headers["Content-Type"] = "application/json";
238
+ body = JSON.stringify(opts.body);
239
+ }
240
+ const absent = (status) => opts.absent?.includes(status) === true;
241
+ const response = await withRetry(
242
+ async () => {
243
+ const res = await (this.options.fetch ?? globalThis.fetch)(url, { method, headers, body });
244
+ if (!res.ok && !absent(res.status)) throw await failureFrom(res, path);
245
+ return res;
246
+ },
247
+ this.options.retry,
248
+ method
249
+ );
250
+ if (absent(response.status)) return null;
251
+ return response.json();
252
+ }
253
+ get(path, query) {
254
+ return this.request(path, { query });
255
+ }
256
+ post(path, body, opts = {}) {
257
+ return this.request(path, { ...opts, method: "POST", body: body ?? {} });
258
+ }
259
+ patch(path, body, opts = {}) {
260
+ return this.request(path, { ...opts, method: "PATCH", body });
261
+ }
262
+ delete(path, body, opts = {}) {
263
+ return this.request(path, { ...opts, method: "DELETE", body });
264
+ }
265
+ find(path, opts = {}) {
266
+ const { also, ...rest } = opts;
267
+ return this.request(path, { ...rest, absent: [404, ...also ?? []] });
268
+ }
269
+ defaultBearer() {
270
+ const source = this.options.bearer;
271
+ return typeof source === "function" ? source() : source;
272
+ }
273
+ };
274
+
275
+ // src/api/domains/orders.ts
276
+ function createOrdersApi(t) {
277
+ return {
278
+ list(query = {}) {
279
+ return t.get("/v1/orders", {
280
+ status: query.status,
281
+ collection: query.collection,
282
+ currency: query.currency,
283
+ sort: query.sort,
284
+ page: query.page,
285
+ limit: query.limit,
286
+ offerer: query.offerer ? t.addr(query.offerer) : void 0,
287
+ minPrice: query.minPrice,
288
+ maxPrice: query.maxPrice,
289
+ chain: query.chain
290
+ });
291
+ },
292
+ async get(orderHash) {
293
+ return (await t.get(`/v1/orders/${orderHash}`)).data;
294
+ },
295
+ forToken(contract, tokenId) {
296
+ return t.get(`/v1/orders/token/${t.addr(contract)}/${tokenId}`);
297
+ },
298
+ receivedBy(address, opts = {}) {
299
+ return t.get(`/v1/orders/received/${t.addr(address)}`, { page: opts.page ?? 1, limit: opts.limit ?? 50 });
300
+ },
301
+ byUser(address, opts = {}) {
302
+ return t.get(`/v1/orders/user/${t.addr(address)}`, { page: opts.page ?? 1, limit: opts.limit ?? 20 });
303
+ },
304
+ counterOffers(query) {
305
+ return t.get("/v1/orders/counter-offers", {
306
+ originalOrderHash: query.originalOrderHash,
307
+ sellerAddress: query.sellerAddress,
308
+ page: query.page,
309
+ limit: query.limit
310
+ });
311
+ }
312
+ };
313
+ }
314
+
315
+ // src/api/domains/tokens.ts
316
+ function createTokensApi(t) {
317
+ return {
318
+ list(query = {}) {
319
+ return t.get("/v1/tokens", {
320
+ page: query.page,
321
+ limit: query.limit,
322
+ sort: query.sort,
323
+ ipType: query.ipType,
324
+ derivatives: query.derivatives
325
+ });
326
+ },
327
+ async get(contract, tokenId, opts = {}) {
328
+ const res = await t.get(`/v1/tokens/${contract}/${tokenId}`, opts.wait ? { wait: "true" } : void 0);
329
+ return res.data;
330
+ },
331
+ async balance(contract, tokenId, owner) {
332
+ return (await t.get(`/v1/tokens/${contract}/${tokenId}/balances/${t.addr(owner)}`)).data;
333
+ },
334
+ ownedBy(address, opts = {}) {
335
+ return t.get(`/v1/tokens/owned/${t.addr(address)}`, { page: opts.page ?? 1, limit: opts.limit ?? 20 });
336
+ },
337
+ history(contract, tokenId, opts = {}) {
338
+ return t.get(`/v1/tokens/${contract}/${tokenId}/history`, { page: opts.page ?? 1, limit: opts.limit ?? 20 });
339
+ },
340
+ comments(contract, tokenId, opts = {}) {
341
+ return t.get(`/v1/tokens/${t.addr(contract)}/${tokenId}/comments`, { page: opts.page, limit: opts.limit });
342
+ },
343
+ remixes(contract, tokenId, opts = {}) {
344
+ return t.get(`/v1/tokens/${t.addr(contract)}/${tokenId}/remixes`, { page: opts.page, limit: opts.limit });
345
+ }
346
+ };
347
+ }
348
+
349
+ // src/api/domains/collections.ts
350
+ var slugOf = (slug) => encodeURIComponent(slug.toLowerCase().trim());
351
+ function createCollectionsApi(t) {
352
+ return {
353
+ list(query = {}) {
354
+ return t.get("/v1/collections", {
355
+ page: query.page,
356
+ limit: query.limit,
357
+ owner: query.owner ? t.addr(query.owner) : void 0,
358
+ service: query.service,
359
+ sort: query.sort,
360
+ isFeatured: query.isFeatured,
361
+ hideEmpty: query.hideEmpty,
362
+ standard: query.standard,
363
+ chain: query.chain
364
+ });
365
+ },
366
+ async get(contract) {
367
+ return (await t.get(`/v1/collections/${t.addr(contract)}`)).data;
368
+ },
369
+ async findBySlug(slug) {
370
+ const res = await t.find(`/v1/collections/by-slug/${slugOf(slug)}`);
371
+ return res?.data ?? null;
372
+ },
373
+ tokens(contract, opts = {}) {
374
+ return t.get(`/v1/collections/${t.addr(contract)}/tokens`, {
375
+ page: opts.page ?? 1,
376
+ limit: opts.limit ?? 20,
377
+ sort: opts.sort ?? "recent"
378
+ });
379
+ },
380
+ async register(contractAddress) {
381
+ return (await t.post("/v1/collections/register", { contractAddress })).data;
382
+ },
383
+ findProfile(contractAddress) {
384
+ return t.find(`/v1/collections/${t.addr(contractAddress)}/profile`);
385
+ },
386
+ updateProfile(contractAddress, data) {
387
+ return t.patch(`/v1/collections/${t.addr(contractAddress)}/profile`, data);
388
+ },
389
+ findGatedContent(contractAddress) {
390
+ return t.find(`/v1/collections/${t.addr(contractAddress)}/gated-content`, { also: [403] });
391
+ },
392
+ claim(contractAddress, walletAddress) {
393
+ return t.post("/v1/collections/claim", { contractAddress, walletAddress });
394
+ },
395
+ requestClaim(params) {
396
+ return t.post("/v1/collections/claim/request", params);
397
+ },
398
+ slugAvailability(slug) {
399
+ return t.get(`/v1/collection-slug-claims/check/${slugOf(slug)}`);
400
+ },
401
+ submitSlugClaim(contractAddress, slug, notifyEmail) {
402
+ return t.post("/v1/collection-slug-claims", { contractAddress, slug, notifyEmail });
403
+ },
404
+ mySlugClaims() {
405
+ return t.get("/v1/collection-slug-claims/me");
406
+ }
407
+ };
408
+ }
409
+
410
+ // src/api/domains/activity.ts
411
+ function createActivityApi(t) {
412
+ return {
413
+ list(query = {}) {
414
+ return t.get("/v1/activities", {
415
+ type: query.type,
416
+ contract: query.contract,
417
+ page: query.page,
418
+ limit: query.limit,
419
+ chain: query.chain
420
+ });
421
+ },
422
+ byAddress(address, opts = {}) {
423
+ return t.get(`/v1/activities/${t.addr(address)}`, { page: opts.page ?? 1, limit: opts.limit ?? 20 });
424
+ },
425
+ wallet(address, chain = "STARKNET") {
426
+ return t.get("/v1/wallet-activity", { address: t.addr(address), chain });
427
+ }
428
+ };
429
+ }
430
+ function createSearchApi(t) {
431
+ return (q, limit = 10, chain) => t.get("/v1/search", { q, limit, chain });
432
+ }
433
+
434
+ // src/api/domains/intents.ts
435
+ function createIntentsApi(t) {
436
+ return {
437
+ async create(kind, params, opts) {
438
+ const res = await t.post(intentPath(kind), params, { bearer: opts?.bearer });
439
+ return res.data;
440
+ },
441
+ async checkout(params) {
442
+ const res = await t.post(intentPath("checkout"), params);
443
+ return res.data;
444
+ },
445
+ async get(id) {
446
+ return (await t.get(`/v1/intents/${id}`)).data;
447
+ },
448
+ async submitSignature(id, signature) {
449
+ return (await t.patch(`/v1/intents/${id}/signature`, { signature })).data;
450
+ },
451
+ async confirm(id, txHash) {
452
+ return (await t.patch(`/v1/intents/${id}/confirm`, { txHash })).data;
453
+ },
454
+ async syncTransaction(txHash) {
455
+ return (await t.post("/v1/tx/sync", { txHash })).data;
456
+ }
457
+ };
458
+ }
459
+
460
+ // src/api/domains/metadata.ts
461
+ function createMetadataApi(t) {
462
+ return {
463
+ signedUrl(kind) {
464
+ return t.get("/v1/metadata/signed-url", { kind });
465
+ },
466
+ upload(metadata) {
467
+ return t.post("/v1/metadata/upload", metadata);
468
+ },
469
+ async uploadDirectory(files) {
470
+ return (await t.post("/v1/metadata/upload-directory", { files })).data;
471
+ },
472
+ resolve(uri) {
473
+ return t.get("/v1/metadata/resolve", { uri });
474
+ },
475
+ uploadFile(file) {
476
+ const formData = new FormData();
477
+ formData.append("file", file);
478
+ return t.request("/v1/metadata/upload-file", { method: "POST", body: formData });
479
+ }
480
+ };
481
+ }
482
+
483
+ // src/api/domains/creators.ts
484
+ function createCreatorsApi(t) {
485
+ return {
486
+ list(opts = {}) {
487
+ return t.get("/v1/creators", { search: opts.search, page: opts.page || void 0, limit: opts.limit || void 0 });
488
+ },
489
+ findProfile(walletAddress) {
490
+ return t.find(`/v1/creators/${t.addr(walletAddress)}/profile`);
491
+ },
492
+ findByUsername(username) {
493
+ return t.find(`/v1/creators/by-username/${encodeURIComponent(username.toLowerCase().trim())}`);
494
+ },
495
+ updateProfile(walletAddress, data) {
496
+ return t.patch(`/v1/creators/${t.addr(walletAddress)}/profile`, data);
497
+ },
498
+ async isHidden(wallet) {
499
+ return (await t.get(`/v1/creators/${t.addr(wallet)}/hidden`)).isHidden;
500
+ },
501
+ myUsernameClaim() {
502
+ return t.get("/v1/username-claims/me");
503
+ },
504
+ usernameAvailability(username) {
505
+ return t.get(`/v1/username-claims/check/${encodeURIComponent(username)}`);
506
+ },
507
+ async submitUsernameClaim(username, notifyEmail) {
508
+ const res = await t.post("/v1/username-claims", {
509
+ username,
510
+ ...notifyEmail ? { notifyEmail } : {}
511
+ });
512
+ return res.claim;
513
+ }
514
+ };
515
+ }
516
+
517
+ // src/api/domains/account.ts
518
+ function createAccountApi(t) {
519
+ return {
520
+ registerUser(params) {
521
+ return t.post("/v1/users/register", params);
522
+ },
523
+ upsertMyWallet(options = {}) {
524
+ const body = { walletType: options.walletType ?? "UNKNOWN" };
525
+ if (options.chain) body.chain = options.chain;
526
+ if (options.email) body.email = options.email;
527
+ return t.post("/v1/users/me", body);
528
+ },
529
+ findMyWallet() {
530
+ return t.find("/v1/users/me");
531
+ },
532
+ changeMyEmail(email) {
533
+ return t.post("/v1/users/me/email", { email });
534
+ },
535
+ async sessionWallet() {
536
+ const body = await t.post("/v1/users/me/wallet", {});
537
+ return body.walletAddress ? { walletAddress: body.walletAddress, needsKeySetup: body.needsKeySetup === true } : null;
538
+ },
539
+ setupWalletKey(params) {
540
+ return t.post("/v1/users/me/wallet/key", params);
541
+ },
542
+ generateWallet(newWalletSiwsToken) {
543
+ return t.post("/v1/users/me/generate-wallet", { newWalletSiwsToken });
544
+ },
545
+ async emailExists(email) {
546
+ return (await t.get("/v1/auth/email/exists", { email })).exists;
547
+ },
548
+ async requestEmailCode(email) {
549
+ await t.post("/v1/auth/email/request-code", { email });
550
+ },
551
+ async registerEmailAccount(email) {
552
+ await t.post("/v1/auth/email/register-account", { email });
553
+ },
554
+ async verifyEmailCode(email, code) {
555
+ await t.post("/v1/auth/email/verify-code", { email, code });
556
+ },
557
+ async confirmEmail(token) {
558
+ const body = await t.post("/v1/auth/email/confirm", { token });
559
+ return { email: body.email };
560
+ }
561
+ };
562
+ }
563
+
564
+ // src/api/domains/portal.ts
565
+ function createPortalApi(t) {
566
+ const data = async (promise) => (await promise).data;
567
+ const fundingPath = (id) => `/v1/portal/funding/${encodeURIComponent(id)}`;
568
+ return {
569
+ me: () => data(t.get("/v1/portal/me")),
570
+ apiKeys: () => data(t.get("/v1/portal/keys")),
571
+ createApiKey: (input, confirmation) => data(t.post("/v1/portal/keys", { ...input ?? {}, confirmation })),
572
+ deleteApiKey: (id, confirmation) => data(t.delete(`/v1/portal/keys/${id}`, { confirmation })),
573
+ creditHistory: () => data(t.get("/v1/portal/credits/history")),
574
+ spend: () => data(t.get("/v1/portal/credits/spend")),
575
+ checkDeposit: (txHash) => data(t.post("/v1/portal/credits/check", { txHash })),
576
+ pricing: () => t.get("/v1/pricing"),
577
+ funding: {
578
+ methods: () => data(t.get("/v1/portal/funding/methods")),
579
+ create: (input) => data(t.post("/v1/portal/funding", { method: input.method, params: input.params })),
580
+ get: (id) => data(t.get(fundingPath(id))),
581
+ challenge: (id, payer) => data(t.post(`${fundingPath(id)}/challenge`, { payer })),
582
+ authorize: (id, input) => data(t.post(`${fundingPath(id)}/authorize`, { payer: input.payer, signature: input.signature })),
583
+ submit: (id, txHash) => data(t.post(`${fundingPath(id)}/submit`, { txHash })),
584
+ cancel: (id) => data(t.post(`${fundingPath(id)}/cancel`, {}))
585
+ }
586
+ };
587
+ }
588
+
589
+ // src/api/domains/business.ts
590
+ function createBusinessApi(t) {
591
+ return {
592
+ async emit(params) {
593
+ return (await t.post("/v1/business/issuance/emission", params)).data;
594
+ },
595
+ registerProvisioning(params) {
596
+ return t.post("/v1/business/provisioning", { chain: params.chain ?? "STARKNET", email: params.email });
597
+ }
598
+ };
599
+ }
600
+
601
+ // src/api/domains/remix.ts
602
+ function createRemixApi(t) {
603
+ const one = async (promise) => (await promise).data;
604
+ return {
605
+ submit: (params) => one(t.post("/v1/remix-offers", params)),
606
+ submitAuto: (params) => one(t.post("/v1/remix-offers/auto", params)),
607
+ confirmSelf: (params) => one(t.post("/v1/remix-offers/self/confirm", params)),
608
+ list: (query) => t.get("/v1/remix-offers", { role: query.role, status: query.status, page: query.page, limit: query.limit }),
609
+ get: (id) => one(t.get(`/v1/remix-offers/${id}`)),
610
+ confirm: (id, params) => one(t.post(`/v1/remix-offers/${id}/confirm`, params)),
611
+ reject: (id) => one(t.post(`/v1/remix-offers/${id}/reject`, {})),
612
+ extend: (id, days) => one(t.post(`/v1/remix-offers/${id}/extend`, { days }))
613
+ };
614
+ }
615
+
616
+ // src/api/domains/coins.ts
617
+ function createCoinsApi(t) {
618
+ return {
619
+ list(opts = {}) {
620
+ return t.get("/v1/coins", {
621
+ page: opts.page || void 0,
622
+ limit: opts.limit || void 0,
623
+ service: opts.service,
624
+ sort: opts.sort,
625
+ creator: opts.creator ? t.addr(opts.creator) : void 0,
626
+ chain: opts.chain
627
+ });
628
+ },
629
+ async get(contract) {
630
+ return (await t.get(`/v1/coins/${t.addr(contract)}`)).data;
631
+ },
632
+ async prices() {
633
+ return (await t.get("/v1/coins/prices")).data;
634
+ },
635
+ claim(coinAddress) {
636
+ return t.post("/v1/coins/claim", { coinAddress });
637
+ },
638
+ claims(status = "PENDING") {
639
+ return t.get("/v1/coins/claims", { status });
640
+ },
641
+ async updateProfile(contract, data) {
642
+ return (await t.patch(`/v1/coins/${t.addr(contract)}`, data)).data;
643
+ },
644
+ async sync(coinAddress, owner) {
645
+ return (await t.post("/v1/coins/sync", { coinAddress, ...owner ? { owner } : {} })).data;
646
+ }
647
+ };
648
+ }
649
+
650
+ // src/api/domains/drops.ts
651
+ function createDropsApi(t) {
652
+ return {
653
+ async fee() {
654
+ return (await t.get("/v1/drops/fee")).data;
655
+ },
656
+ list(query = {}) {
657
+ return t.get("/v1/drops", {
658
+ status: query.status,
659
+ organizer: query.organizer ? t.addr(query.organizer) : void 0,
660
+ page: query.page,
661
+ limit: query.limit
662
+ });
663
+ },
664
+ async find(contract) {
665
+ const res = await t.find(`/v1/drops/${t.addr(contract)}`);
666
+ return res?.data ?? null;
667
+ },
668
+ mints(contract, opts = {}) {
669
+ return t.get(`/v1/drops/${t.addr(contract)}/mints`, { page: opts.page, limit: opts.limit });
670
+ }
671
+ };
672
+ }
673
+
674
+ // src/api/domains/sponsorship.ts
675
+ function createSponsorshipApi(t) {
676
+ return {
677
+ offers(query = {}) {
678
+ return t.get("/v1/sponsorship/offers", {
679
+ limit: query.limit ?? 50,
680
+ nftContract: query.nftContract,
681
+ author: query.author,
682
+ owner: query.owner,
683
+ open: query.open
684
+ });
685
+ },
686
+ async findOffer(offerId) {
687
+ const res = await t.find(`/v1/sponsorship/offers/${encodeURIComponent(offerId)}`);
688
+ return res?.data ?? null;
689
+ },
690
+ async bids(offerId) {
691
+ return (await t.get(`/v1/sponsorship/offers/${encodeURIComponent(offerId)}/bids`)).data;
692
+ },
693
+ proposals(query = {}) {
694
+ return t.get("/v1/sponsorship/proposals", {
695
+ limit: query.limit ?? 50,
696
+ nftContract: query.nftContract,
697
+ proposer: query.proposer,
698
+ owner: query.owner,
699
+ open: query.open
700
+ });
701
+ },
702
+ async findProposal(proposalId) {
703
+ const res = await t.find(`/v1/sponsorship/proposals/${encodeURIComponent(proposalId)}`);
704
+ return res?.data ?? null;
705
+ },
706
+ licenses(query = {}) {
707
+ return t.get("/v1/sponsorship/licenses", { limit: query.limit ?? 50, holder: query.holder, author: query.author });
708
+ }
709
+ };
710
+ }
711
+
712
+ // src/api/domains/rewards.ts
713
+ function createRewardsApi(t) {
714
+ return {
715
+ async get(address) {
716
+ return (await t.get(`/v1/rewards/${t.addr(address)}`)).data;
717
+ },
718
+ leaderboard(opts = {}) {
719
+ return t.get("/v1/rewards", { page: opts.page ?? 1, limit: opts.limit ?? 50 });
720
+ },
721
+ events(address, opts = {}) {
722
+ return t.get(`/v1/rewards/${t.addr(address)}/events`, { page: opts.page ?? 1, limit: opts.limit ?? 20 });
723
+ },
724
+ async config() {
725
+ return (await t.get("/v1/rewards/config")).data;
726
+ },
727
+ async batch(addresses) {
728
+ if (addresses.length === 0) return [];
729
+ const res = await t.get("/v1/rewards/batch", {
730
+ addresses: addresses.map((a) => t.addr(a)).join(",")
731
+ });
732
+ return res.data;
733
+ }
734
+ };
735
+ }
736
+
737
+ // src/api/domains/platform.ts
738
+ function createPlatformApi(t) {
739
+ return {
740
+ async stats() {
741
+ return (await t.get("/v1/stats")).data;
742
+ },
743
+ async swapQuote(body) {
744
+ return (await t.post("/v1/swap/quote", body)).quote;
745
+ },
746
+ async submitReport(report) {
747
+ const targetContract = report.targetContract ? t.addr(report.targetContract) : void 0;
748
+ const targetAddress = report.targetAddress ? t.addr(report.targetAddress) : void 0;
749
+ let targetKey = null;
750
+ if (report.targetType === "TOKEN" && targetContract && report.targetTokenId) {
751
+ targetKey = `TOKEN:${targetContract}:${report.targetTokenId}`;
752
+ } else if (report.targetType === "COLLECTION" && targetContract) {
753
+ targetKey = `COLLECTION:${targetContract}`;
754
+ } else if (report.targetType === "CREATOR" && targetAddress) {
755
+ targetKey = `CREATOR:${targetAddress}`;
756
+ } else if (report.targetType === "COMMENT" && report.targetId) {
757
+ targetKey = `COMMENT::${report.targetId}`;
758
+ }
759
+ if (!targetKey) throw new Error(`A ${report.targetType} report needs its target`);
760
+ await t.post("/v1/reports", { ...report, targetKey, targetContract, targetAddress });
761
+ }
762
+ };
763
+ }
764
+
765
+ // src/api/domains/chainReads.ts
766
+ function createChainReadsApi(t) {
767
+ const data = async (path) => (await t.get(path)).data;
768
+ return {
769
+ ticket: (contract, tokenId) => data(`/v1/tickets/${t.addr(contract)}/${tokenId}`),
770
+ ticketCount: async (contract) => (await data(`/v1/tickets/${t.addr(contract)}/count`)).count,
771
+ clubMembershipCount: async (contract) => (await data(`/v1/club/${t.addr(contract)}/count`)).count,
772
+ clubMembership: (contract, tokenId) => data(`/v1/club/${t.addr(contract)}/${tokenId}`),
773
+ isClubMember: async (contract, tokenId, wallet) => (await data(`/v1/club/${t.addr(contract)}/${tokenId}/member/${t.addr(wallet)}`)).isMember,
774
+ ipNftTokenData: (contract, tokenId) => data(`/v1/ipnft/${t.addr(contract)}/${tokenId}`),
775
+ coinGuarantees: (contract) => data(`/v1/coins/${t.addr(contract)}/guarantees`),
776
+ popClaimInfo: (collection) => data(`/v1/pop/${t.addr(collection)}/claim-info`),
777
+ async dropState(contract) {
778
+ const wire = await data(`/v1/drops/${t.addr(contract)}/state`);
779
+ return wire ? dropStateFromWire(wire) : null;
780
+ }
781
+ };
782
+ }
783
+
784
+ // src/api/client.ts
785
+ var ApiClient = class _ApiClient {
786
+ constructor(options) {
787
+ this.transport = new Transport(options);
788
+ const t = this.transport;
789
+ this.orders = createOrdersApi(t);
790
+ this.tokens = createTokensApi(t);
791
+ this.collections = createCollectionsApi(t);
792
+ this.activity = createActivityApi(t);
793
+ this.search = createSearchApi(t);
794
+ this.intents = createIntentsApi(t);
795
+ this.metadata = createMetadataApi(t);
796
+ this.creators = createCreatorsApi(t);
797
+ this.account = createAccountApi(t);
798
+ this.portal = createPortalApi(t);
799
+ this.business = createBusinessApi(t);
800
+ this.remix = createRemixApi(t);
801
+ this.coins = createCoinsApi(t);
802
+ this.drops = createDropsApi(t);
803
+ this.sponsorship = createSponsorshipApi(t);
804
+ this.rewards = createRewardsApi(t);
805
+ this.platform = createPlatformApi(t);
806
+ this.chainReads = createChainReadsApi(t);
807
+ }
808
+ withBearer(bearer) {
809
+ return new _ApiClient({ ...this.transport.settings(), bearer });
810
+ }
811
+ };
812
+
813
+ // src/wallet/passkey-errors.ts
814
+ var PasskeyCancelledError = class extends Error {
815
+ constructor(message = "Passkey prompt was cancelled.") {
816
+ super(message);
817
+ this.name = "PasskeyCancelledError";
818
+ }
819
+ };
820
+ var DeviceKeyMissingError = class extends Error {
821
+ constructor() {
822
+ super("This browser no longer holds the wallet key. Recover the wallet with its recovery key.");
823
+ this.name = "DeviceKeyMissingError";
824
+ }
825
+ };
826
+ var PasskeyUnsupportedError = class extends Error {
827
+ constructor(reason) {
828
+ super(
829
+ reason === "no-webauthn" ? "Passkeys are not available in this environment." : "This passkey did not return a PRF secret, so it cannot seal a wallet key."
830
+ );
831
+ this.name = "PasskeyUnsupportedError";
832
+ this.reason = reason;
833
+ }
834
+ };
835
+
836
+ // src/constants.ts
837
+ var SN = getCoordinates("STARKNET");
838
+ var STARKNET_MARKETPLACE_721_CONTRACT = SN.marketplace721;
839
+ var STARKNET_MARKETPLACE_1155_CONTRACT = SN.marketplace1155;
840
+ var STARKNET_COLLECTION_721_CONTRACT = SN.collection721;
841
+ var STARKNET_DATA_TOKENIZATION_721_CONTRACT = SN.dataTokenization721;
842
+ var STARKNET_COLLECTION_1155_CONTRACT = SN.collection1155;
843
+ var STARKNET_POP_FACTORY_CONTRACT = SN.popFactory;
844
+ var STARKNET_POP_FACTORY_START_BLOCK = SN.popFactoryStartBlock;
845
+ var STARKNET_DROP_FACTORY_CONTRACT = SN.dropFactory;
846
+ var STARKNET_DROP_FACTORY_START_BLOCK = SN.dropFactoryStartBlock;
847
+ var STARKNET_NFTCOMMENTS_CONTRACT = SN.nftComments;
848
+ var STARKNET_IP_TICKETS_FACTORY_CONTRACT = SN.ipTicketsFactory;
849
+ var STARKNET_IP_CLUB_FACTORY_CONTRACT = SN.ipClubFactory;
850
+ var STARKNET_IP_SPONSORSHIP_CONTRACT = SN.ipSponsorship;
851
+ var STARKNET_MEDIAWALLET_CLASS_HASH = SN.mediaWalletClassHash;
852
+ var STARKNET_CREATOR_COIN_FACTORY_CONTRACT = SN.creatorCoinFactory;
853
+ var STARKNET_GENESIS_MINT_CONTRACT = SN.genesisMint;
854
+ var STARKNET_GENESIS_NFT_URI = "ipfs://bafkreiag6wzov7migmxwx3wrtudvbx4ajrlbjopqw7uni7nn2nsxv4eykm";
855
+ var SUPPORTED_TOKENS = [
856
+ {
857
+ symbol: "USDC",
858
+ address: "0x033068f6539f8e6e6b131e6b2b814e6c34a5224bc66947c47dab9dfee93b35fb",
859
+ decimals: 6,
860
+ listable: true
861
+ },
862
+ {
863
+ symbol: "USDT",
864
+ address: "0x068f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8",
865
+ decimals: 6,
866
+ listable: true
867
+ },
868
+ {
869
+ symbol: "ETH",
870
+ address: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
871
+ decimals: 18,
872
+ listable: true
873
+ },
874
+ {
875
+ symbol: "STRK",
876
+ address: "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
877
+ decimals: 18,
878
+ listable: true
879
+ },
880
+ {
881
+ symbol: "WBTC",
882
+ address: "0x03fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac",
883
+ decimals: 8,
884
+ listable: true
885
+ }
886
+ ];
887
+ var DEFAULT_CURRENCY = "USDC";
888
+
889
+ // src/utils/token.ts
890
+ function parseAmount(human, decimals) {
891
+ const [whole, frac = ""] = human.split(".");
892
+ const fracPadded = frac.padEnd(decimals, "0").slice(0, decimals);
893
+ return (BigInt(whole) * BigInt(10) ** BigInt(decimals) + BigInt(fracPadded)).toString();
894
+ }
895
+ function formatAmount(raw, decimals) {
896
+ const value = BigInt(raw);
897
+ const factor = 10n ** BigInt(decimals);
898
+ const whole = value / factor;
899
+ const remainder = value % factor;
900
+ const fractional = remainder.toString().padStart(decimals, "0").replace(/0+$/, "");
901
+ return fractional ? `${whole}.${fractional}` : whole.toString();
902
+ }
903
+ function getTokenByAddress(address) {
904
+ if (typeof address !== "string" || address.trim() === "") return void 0;
905
+ let target = null;
906
+ try {
907
+ target = BigInt(address);
908
+ } catch {
909
+ target = null;
910
+ }
911
+ return SUPPORTED_TOKENS.find((t) => {
912
+ if (target !== null) {
913
+ try {
914
+ return BigInt(t.address) === target;
915
+ } catch {
916
+ }
917
+ }
918
+ return t.address.toLowerCase() === address.toLowerCase();
919
+ });
920
+ }
921
+ function getTokenBySymbol(symbol) {
922
+ if (typeof symbol !== "string") return void 0;
923
+ const upper = symbol.toUpperCase();
924
+ return SUPPORTED_TOKENS.find((t) => t.symbol === upper);
925
+ }
926
+ function getListableTokens() {
927
+ return SUPPORTED_TOKENS.filter((t) => t.listable);
928
+ }
929
+
930
+ export { ApiClient, DEFAULT_CURRENCY, DeviceKeyMissingError, MedialaneApiError, MedialaneError, PasskeyCancelledError, PasskeyUnsupportedError, STARKNET_COLLECTION_1155_CONTRACT, STARKNET_COLLECTION_721_CONTRACT, STARKNET_CREATOR_COIN_FACTORY_CONTRACT, STARKNET_DATA_TOKENIZATION_721_CONTRACT, STARKNET_DROP_FACTORY_CONTRACT, STARKNET_DROP_FACTORY_START_BLOCK, STARKNET_GENESIS_MINT_CONTRACT, STARKNET_GENESIS_NFT_URI, STARKNET_IP_CLUB_FACTORY_CONTRACT, STARKNET_IP_SPONSORSHIP_CONTRACT, STARKNET_IP_TICKETS_FACTORY_CONTRACT, STARKNET_MARKETPLACE_1155_CONTRACT, STARKNET_MARKETPLACE_721_CONTRACT, STARKNET_MEDIAWALLET_CLASS_HASH, STARKNET_NFTCOMMENTS_CONTRACT, STARKNET_POP_FACTORY_CONTRACT, STARKNET_POP_FACTORY_START_BLOCK, SUPPORTED_TOKENS, UserFacingError, formatAmount, getListableTokens, getTokenByAddress, getTokenBySymbol, normalizeAddress, normalizeHash, parseAmount, shortenAddress };
931
+ //# sourceMappingURL=chunk-KGAGWULG.js.map
932
+ //# sourceMappingURL=chunk-KGAGWULG.js.map