@medialane/sdk 0.155.0 → 0.156.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/chunk-3PZUSEAW.js +63 -0
- package/dist/chunk-3PZUSEAW.js.map +1 -0
- package/dist/chunk-ASDN46XU.js +1778 -0
- package/dist/chunk-ASDN46XU.js.map +1 -0
- package/dist/chunk-OUPVVMLK.cjs +68 -0
- package/dist/chunk-OUPVVMLK.cjs.map +1 -0
- package/dist/chunk-ZFRHADHR.cjs +1854 -0
- package/dist/chunk-ZFRHADHR.cjs.map +1 -0
- package/dist/evm/index.cjs +3 -55
- package/dist/evm/index.cjs.map +1 -1
- package/dist/evm/index.js +1 -53
- package/dist/evm/index.js.map +1 -1
- package/dist/index.cjs +275 -1718
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -1651
- package/dist/index.js.map +1 -1
- package/dist/solana/index.cjs +2 -56
- package/dist/solana/index.cjs.map +1 -1
- package/dist/solana/index.js +1 -55
- package/dist/solana/index.js.map +1 -1
- package/dist/starknet/index.cjs +113 -1967
- package/dist/starknet/index.cjs.map +1 -1
- package/dist/starknet/index.d.cts +1 -111
- package/dist/starknet/index.d.ts +1 -111
- package/dist/starknet/index.js +9 -1887
- package/dist/starknet/index.js.map +1 -1
- package/dist/stellar/index.cjs +2 -56
- package/dist/stellar/index.cjs.map +1 -1
- package/dist/stellar/index.js +1 -55
- package/dist/stellar/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,1854 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkOUPVVMLK_cjs = require('./chunk-OUPVVMLK.cjs');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
var sha3_js = require('@noble/hashes/sha3.js');
|
|
6
|
+
var base = require('@scure/base');
|
|
7
|
+
var starknet = require('starknet');
|
|
8
|
+
|
|
9
|
+
var FeeConfigSchema = zod.z.object({
|
|
10
|
+
enabled: zod.z.boolean().default(true),
|
|
11
|
+
fundAddress: zod.z.string().min(1).optional(),
|
|
12
|
+
marketplaceBps: zod.z.number().int().min(0).max(1e4).default(100),
|
|
13
|
+
launchpadBps: zod.z.number().int().min(0).max(1e4).default(100),
|
|
14
|
+
sponsorshipBps: zod.z.number().int().min(0).max(1e4).default(100)
|
|
15
|
+
});
|
|
16
|
+
function resolveFeeConfig(raw) {
|
|
17
|
+
const p = FeeConfigSchema.parse(raw ?? {});
|
|
18
|
+
return {
|
|
19
|
+
enabled: p.enabled,
|
|
20
|
+
fundAddress: p.fundAddress,
|
|
21
|
+
marketplaceBps: p.marketplaceBps,
|
|
22
|
+
launchpadBps: p.launchpadBps,
|
|
23
|
+
sponsorshipBps: p.sponsorshipBps
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/fee/app-config.ts
|
|
28
|
+
var DEFAULT_BPS = 100;
|
|
29
|
+
function bps(raw) {
|
|
30
|
+
if (!raw) return DEFAULT_BPS;
|
|
31
|
+
const n = Number(raw);
|
|
32
|
+
return Number.isFinite(n) ? n : DEFAULT_BPS;
|
|
33
|
+
}
|
|
34
|
+
function resolveAppFeeConfig(env = {}) {
|
|
35
|
+
return resolveFeeConfig({
|
|
36
|
+
enabled: env.NEXT_PUBLIC_FEE_ENABLED !== "false",
|
|
37
|
+
fundAddress: env.NEXT_PUBLIC_FEE_FUND_ADDRESS || void 0,
|
|
38
|
+
marketplaceBps: bps(env.NEXT_PUBLIC_FEE_MARKETPLACE_BPS),
|
|
39
|
+
launchpadBps: bps(env.NEXT_PUBLIC_FEE_LAUNCHPAD_BPS)
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
var MedialaneConfigSchema = zod.z.object({
|
|
43
|
+
chain: zod.z.enum(chunkOUPVVMLK_cjs.CHAINS).default(chunkOUPVVMLK_cjs.DEFAULT_CHAIN),
|
|
44
|
+
rpcUrl: zod.z.string().url().optional(),
|
|
45
|
+
backendUrl: zod.z.string().url().optional(),
|
|
46
|
+
apiKey: zod.z.string().optional(),
|
|
47
|
+
marketplace721Contract: zod.z.string().optional(),
|
|
48
|
+
marketplaceContract: zod.z.string().optional(),
|
|
49
|
+
marketplace1155Contract: zod.z.string().optional(),
|
|
50
|
+
collection721Contract: zod.z.string().optional(),
|
|
51
|
+
collectionContract: zod.z.string().optional(),
|
|
52
|
+
collection1155Contract: zod.z.string().optional(),
|
|
53
|
+
retryOptions: zod.z.object({
|
|
54
|
+
maxAttempts: zod.z.number().int().min(1).max(10).optional(),
|
|
55
|
+
baseDelayMs: zod.z.number().int().min(0).optional(),
|
|
56
|
+
maxDelayMs: zod.z.number().int().min(0).optional()
|
|
57
|
+
}).optional(),
|
|
58
|
+
feeConfig: FeeConfigSchema.optional()
|
|
59
|
+
});
|
|
60
|
+
function resolveConfig(raw) {
|
|
61
|
+
const parsed = MedialaneConfigSchema.parse(raw);
|
|
62
|
+
const coords = chunkOUPVVMLK_cjs.getCoordinates(parsed.chain);
|
|
63
|
+
const sn = parsed.chain === "STARKNET" ? coords : {};
|
|
64
|
+
const marketplace721Contract = parsed.marketplace721Contract ?? parsed.marketplaceContract ?? sn.marketplace721;
|
|
65
|
+
const collection721Contract = parsed.collection721Contract ?? parsed.collectionContract ?? sn.collection721;
|
|
66
|
+
return {
|
|
67
|
+
chain: parsed.chain,
|
|
68
|
+
rpcUrl: parsed.rpcUrl ?? coords.rpcUrl,
|
|
69
|
+
backendUrl: parsed.backendUrl,
|
|
70
|
+
apiKey: parsed.apiKey,
|
|
71
|
+
marketplace721Contract,
|
|
72
|
+
marketplaceContract: marketplace721Contract,
|
|
73
|
+
marketplace1155Contract: parsed.marketplace1155Contract ?? sn.marketplace1155,
|
|
74
|
+
collection721Contract,
|
|
75
|
+
collectionContract: collection721Contract,
|
|
76
|
+
collection1155Contract: parsed.collection1155Contract ?? sn.collection1155,
|
|
77
|
+
retryOptions: parsed.retryOptions,
|
|
78
|
+
feeConfig: resolveFeeConfig(parsed.feeConfig)
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function normalizeAddress(chain, address) {
|
|
82
|
+
switch (chain) {
|
|
83
|
+
case "STARKNET":
|
|
84
|
+
return normalizeStarknet(address);
|
|
85
|
+
case "ETHEREUM":
|
|
86
|
+
case "BASE":
|
|
87
|
+
return normalizeEvm(address);
|
|
88
|
+
case "SOLANA":
|
|
89
|
+
return normalizeSolana(address);
|
|
90
|
+
case "STELLAR":
|
|
91
|
+
return normalizeStellar(address);
|
|
92
|
+
case "BITCOIN":
|
|
93
|
+
throw new Error("BITCOIN address normalization not implemented");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function normalizeStarknet(address) {
|
|
97
|
+
try {
|
|
98
|
+
const hex = BigInt(address).toString(16);
|
|
99
|
+
return "0x" + hex.padStart(64, "0").toLowerCase();
|
|
100
|
+
} catch {
|
|
101
|
+
throw new Error(`Invalid STARKNET address: "${address}"`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function normalizeEvm(address) {
|
|
105
|
+
const m = /^0x([0-9a-fA-F]{40})$/.exec(address);
|
|
106
|
+
if (!m) throw new Error(`Invalid ETHEREUM/BASE address: "${address}"`);
|
|
107
|
+
const lower = m[1].toLowerCase();
|
|
108
|
+
const hash2 = sha3_js.keccak_256(new TextEncoder().encode(lower));
|
|
109
|
+
let out = "0x";
|
|
110
|
+
for (let i = 0; i < 40; i++) {
|
|
111
|
+
const nibble = hash2[i >> 1] >> (i % 2 === 0 ? 4 : 0) & 15;
|
|
112
|
+
out += nibble >= 8 ? lower[i].toUpperCase() : lower[i];
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
function normalizeSolana(address) {
|
|
117
|
+
try {
|
|
118
|
+
const bytes = base.base58.decode(address);
|
|
119
|
+
if (bytes.length !== 32) throw new Error("not a 32-byte key");
|
|
120
|
+
return address;
|
|
121
|
+
} catch {
|
|
122
|
+
throw new Error(`Invalid SOLANA address: "${address}"`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
var STELLAR_VERSION_BYTES = /* @__PURE__ */ new Set([6 << 3, 2 << 3]);
|
|
126
|
+
function normalizeStellar(address) {
|
|
127
|
+
const upper = address.toUpperCase();
|
|
128
|
+
if (!/^[GC][A-Z2-7]{55}$/.test(upper)) {
|
|
129
|
+
throw new Error(`Invalid STELLAR address: "${address}"`);
|
|
130
|
+
}
|
|
131
|
+
let decoded;
|
|
132
|
+
try {
|
|
133
|
+
decoded = base.base32.decode(upper);
|
|
134
|
+
} catch {
|
|
135
|
+
throw new Error(`Invalid STELLAR address: "${address}"`);
|
|
136
|
+
}
|
|
137
|
+
if (decoded.length !== 35 || !STELLAR_VERSION_BYTES.has(decoded[0])) {
|
|
138
|
+
throw new Error(`Invalid STELLAR address: "${address}"`);
|
|
139
|
+
}
|
|
140
|
+
const payload = decoded.subarray(0, 33);
|
|
141
|
+
const checksum = decoded[33] | decoded[34] << 8;
|
|
142
|
+
if (crc16xmodem(payload) !== checksum) {
|
|
143
|
+
throw new Error(`Invalid STELLAR address: "${address}"`);
|
|
144
|
+
}
|
|
145
|
+
return upper;
|
|
146
|
+
}
|
|
147
|
+
function crc16xmodem(bytes) {
|
|
148
|
+
let crc = 0;
|
|
149
|
+
for (const byte of bytes) {
|
|
150
|
+
crc ^= byte << 8;
|
|
151
|
+
for (let i = 0; i < 8; i++) {
|
|
152
|
+
crc = crc & 32768 ? (crc << 1 ^ 4129) & 65535 : crc << 1 & 65535;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return crc;
|
|
156
|
+
}
|
|
157
|
+
function normalizeHash(hash2) {
|
|
158
|
+
try {
|
|
159
|
+
const hex = BigInt(hash2).toString(16);
|
|
160
|
+
return "0x" + hex.padStart(64, "0").toLowerCase();
|
|
161
|
+
} catch {
|
|
162
|
+
throw new Error(`Invalid hash: "${hash2}"`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function shortenAddress(chain, address, chars = 4) {
|
|
166
|
+
const norm = normalizeAddress(chain, address);
|
|
167
|
+
return `${norm.slice(0, chars + 2)}...${norm.slice(-chars)}`;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// src/utils/retry.ts
|
|
171
|
+
var DEFAULT_MAX_ATTEMPTS = 3;
|
|
172
|
+
var DEFAULT_BASE_DELAY_MS = 300;
|
|
173
|
+
var DEFAULT_MAX_DELAY_MS = 5e3;
|
|
174
|
+
function sleep(ms) {
|
|
175
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
176
|
+
}
|
|
177
|
+
function isRetryableFor(method, err) {
|
|
178
|
+
if (err instanceof MedialaneApiError && err.status === 429) return true;
|
|
179
|
+
const isRead = method === "GET" || method === "HEAD";
|
|
180
|
+
if (!isRead) return false;
|
|
181
|
+
return err instanceof MedialaneApiError && err.status >= 500 || err instanceof TypeError;
|
|
182
|
+
}
|
|
183
|
+
async function withRetry(fn, opts, method = "GET") {
|
|
184
|
+
const maxAttempts = opts?.maxAttempts ?? DEFAULT_MAX_ATTEMPTS;
|
|
185
|
+
const baseDelayMs = opts?.baseDelayMs ?? DEFAULT_BASE_DELAY_MS;
|
|
186
|
+
const maxDelayMs = opts?.maxDelayMs ?? DEFAULT_MAX_DELAY_MS;
|
|
187
|
+
let lastError;
|
|
188
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
189
|
+
try {
|
|
190
|
+
return await fn();
|
|
191
|
+
} catch (err) {
|
|
192
|
+
lastError = err;
|
|
193
|
+
if (!isRetryableFor(method, err) || attempt === maxAttempts - 1) {
|
|
194
|
+
throw err;
|
|
195
|
+
}
|
|
196
|
+
const retryAfterMs = err instanceof MedialaneApiError ? err.retryAfterMs : void 0;
|
|
197
|
+
const backoff = baseDelayMs * Math.pow(2, attempt) + Math.random() * baseDelayMs;
|
|
198
|
+
const delay = Math.min(retryAfterMs ?? backoff, maxDelayMs);
|
|
199
|
+
await sleep(delay);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
throw lastError;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// src/api/client.ts
|
|
206
|
+
function deriveErrorCode(status) {
|
|
207
|
+
if (status === 404) return "TOKEN_NOT_FOUND";
|
|
208
|
+
if (status === 429) return "RATE_LIMITED";
|
|
209
|
+
if (status === 410) return "INTENT_EXPIRED";
|
|
210
|
+
if (status === 401 || status === 403) return "UNAUTHORIZED";
|
|
211
|
+
if (status === 400) return "INVALID_PARAMS";
|
|
212
|
+
return "UNKNOWN";
|
|
213
|
+
}
|
|
214
|
+
var MedialaneApiError = class extends Error {
|
|
215
|
+
constructor(status, message, retryAfterMs, details) {
|
|
216
|
+
super(message);
|
|
217
|
+
this.status = status;
|
|
218
|
+
this.retryAfterMs = retryAfterMs;
|
|
219
|
+
this.details = details;
|
|
220
|
+
this.name = "MedialaneApiError";
|
|
221
|
+
this.code = deriveErrorCode(status);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
function parseRetryAfter(value) {
|
|
225
|
+
if (!value) return void 0;
|
|
226
|
+
const seconds = Number(value);
|
|
227
|
+
if (Number.isFinite(seconds)) return Math.max(0, seconds * 1e3);
|
|
228
|
+
const date = Date.parse(value);
|
|
229
|
+
if (!Number.isNaN(date)) return Math.max(0, date - Date.now());
|
|
230
|
+
return void 0;
|
|
231
|
+
}
|
|
232
|
+
var ApiClient = class {
|
|
233
|
+
constructor(baseUrl, apiKey, retryOptions, chain = "STARKNET") {
|
|
234
|
+
this.baseUrl = baseUrl;
|
|
235
|
+
this.chain = chain;
|
|
236
|
+
this.baseHeaders = apiKey ? { "x-api-key": apiKey } : {};
|
|
237
|
+
this.retryOptions = retryOptions;
|
|
238
|
+
}
|
|
239
|
+
addr(a) {
|
|
240
|
+
return normalizeAddress(this.chain, a);
|
|
241
|
+
}
|
|
242
|
+
async request(path, init, opts) {
|
|
243
|
+
const url = `${this.baseUrl.replace(/\/$/, "")}${path}`;
|
|
244
|
+
const headers = { ...this.baseHeaders };
|
|
245
|
+
if (init?.body != null && !(init.body instanceof FormData)) {
|
|
246
|
+
headers["Content-Type"] = "application/json";
|
|
247
|
+
}
|
|
248
|
+
const allowed = (status) => opts?.allow404 === true && status === 404 || opts?.allow403 === true && status === 403;
|
|
249
|
+
const res = await withRetry(async () => {
|
|
250
|
+
const response = await fetch(url, {
|
|
251
|
+
...init,
|
|
252
|
+
headers: { ...headers, ...init?.headers }
|
|
253
|
+
});
|
|
254
|
+
if (!response.ok && !allowed(response.status)) {
|
|
255
|
+
const text = await response.text().catch(() => response.statusText);
|
|
256
|
+
let message = `Request failed with status ${response.status}`;
|
|
257
|
+
let details = text;
|
|
258
|
+
try {
|
|
259
|
+
const body = JSON.parse(text);
|
|
260
|
+
if (typeof body.error === "string" && body.error.trim() !== "") {
|
|
261
|
+
message = body.error;
|
|
262
|
+
}
|
|
263
|
+
details = body;
|
|
264
|
+
} catch {
|
|
265
|
+
}
|
|
266
|
+
throw new MedialaneApiError(
|
|
267
|
+
response.status,
|
|
268
|
+
message,
|
|
269
|
+
parseRetryAfter(response.headers.get("retry-after")),
|
|
270
|
+
details
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
return response;
|
|
274
|
+
}, this.retryOptions, (init?.method ?? "GET").toUpperCase());
|
|
275
|
+
if (allowed(res.status)) return null;
|
|
276
|
+
return res.json();
|
|
277
|
+
}
|
|
278
|
+
get(path) {
|
|
279
|
+
return this.request(path, { method: "GET" });
|
|
280
|
+
}
|
|
281
|
+
post(path, body) {
|
|
282
|
+
return this.request(path, { method: "POST", body: JSON.stringify(body) });
|
|
283
|
+
}
|
|
284
|
+
patch(path, body) {
|
|
285
|
+
return this.request(path, { method: "PATCH", body: JSON.stringify(body) });
|
|
286
|
+
}
|
|
287
|
+
bearer(siwsToken) {
|
|
288
|
+
return { Authorization: `Bearer ${siwsToken}` };
|
|
289
|
+
}
|
|
290
|
+
asSubject(siwsToken) {
|
|
291
|
+
return siwsToken ? this.bearer(siwsToken) : void 0;
|
|
292
|
+
}
|
|
293
|
+
getOrders(query = {}) {
|
|
294
|
+
const params = new URLSearchParams();
|
|
295
|
+
if (query.status) params.set("status", query.status);
|
|
296
|
+
if (query.collection) params.set("collection", query.collection);
|
|
297
|
+
if (query.currency) params.set("currency", query.currency);
|
|
298
|
+
if (query.sort) params.set("sort", query.sort);
|
|
299
|
+
if (query.page !== void 0) params.set("page", String(query.page));
|
|
300
|
+
if (query.limit !== void 0) params.set("limit", String(query.limit));
|
|
301
|
+
if (query.offerer) params.set("offerer", this.addr(query.offerer));
|
|
302
|
+
if (query.minPrice) params.set("minPrice", query.minPrice);
|
|
303
|
+
if (query.maxPrice) params.set("maxPrice", query.maxPrice);
|
|
304
|
+
if (query.chain) params.set("chain", query.chain);
|
|
305
|
+
const qs = params.toString();
|
|
306
|
+
return this.get(`/v1/orders${qs ? `?${qs}` : ""}`);
|
|
307
|
+
}
|
|
308
|
+
getOrder(orderHash) {
|
|
309
|
+
return this.get(`/v1/orders/${orderHash}`);
|
|
310
|
+
}
|
|
311
|
+
getActiveOrdersForToken(contract, tokenId) {
|
|
312
|
+
return this.get(`/v1/orders/token/${this.addr(contract)}/${tokenId}`);
|
|
313
|
+
}
|
|
314
|
+
getReceivedOffers(address, opts = {}) {
|
|
315
|
+
const params = new URLSearchParams({ page: String(opts.page ?? 1), limit: String(opts.limit ?? 50) });
|
|
316
|
+
return this.get(`/v1/orders/received/${this.addr(address)}?${params}`);
|
|
317
|
+
}
|
|
318
|
+
getOrdersByUser(address, page = 1, limit = 20) {
|
|
319
|
+
return this.get(
|
|
320
|
+
`/v1/orders/user/${this.addr(address)}?page=${page}&limit=${limit}`
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
getToken(contract, tokenId, wait = false) {
|
|
324
|
+
return this.get(
|
|
325
|
+
`/v1/tokens/${contract}/${tokenId}${wait ? "?wait=true" : ""}`
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
getTokensByOwner(address, page = 1, limit = 20) {
|
|
329
|
+
return this.get(
|
|
330
|
+
`/v1/tokens/owned/${this.addr(address)}?page=${page}&limit=${limit}`
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
getTokenHistory(contract, tokenId, page = 1, limit = 20) {
|
|
334
|
+
return this.get(
|
|
335
|
+
`/v1/tokens/${contract}/${tokenId}/history?page=${page}&limit=${limit}`
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
getCollection(contract) {
|
|
339
|
+
return this.get(`/v1/collections/${this.addr(contract)}`);
|
|
340
|
+
}
|
|
341
|
+
getCollectionTokens(contract, page = 1, limit = 20, sort = "recent") {
|
|
342
|
+
return this.get(
|
|
343
|
+
`/v1/collections/${this.addr(contract)}/tokens?page=${page}&limit=${limit}&sort=${sort}`
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
getActivities(query = {}) {
|
|
347
|
+
const params = new URLSearchParams();
|
|
348
|
+
if (query.type) params.set("type", query.type);
|
|
349
|
+
if (query.contract) params.set("contract", query.contract);
|
|
350
|
+
if (query.page !== void 0) params.set("page", String(query.page));
|
|
351
|
+
if (query.limit !== void 0) params.set("limit", String(query.limit));
|
|
352
|
+
if (query.chain) params.set("chain", query.chain);
|
|
353
|
+
const qs = params.toString();
|
|
354
|
+
return this.get(`/v1/activities${qs ? `?${qs}` : ""}`);
|
|
355
|
+
}
|
|
356
|
+
getActivitiesByAddress(address, page = 1, limit = 20) {
|
|
357
|
+
return this.get(
|
|
358
|
+
`/v1/activities/${this.addr(address)}?page=${page}&limit=${limit}`
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
getTokenComments(contract, tokenId, opts = {}) {
|
|
362
|
+
const params = new URLSearchParams();
|
|
363
|
+
if (opts.page !== void 0) params.set("page", String(opts.page));
|
|
364
|
+
if (opts.limit !== void 0) params.set("limit", String(opts.limit));
|
|
365
|
+
const qs = params.toString();
|
|
366
|
+
return this.get(
|
|
367
|
+
`/v1/tokens/${this.addr(contract)}/${tokenId}/comments${qs ? `?${qs}` : ""}`
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
search(q, limit = 10, chain) {
|
|
371
|
+
const params = new URLSearchParams({ q, limit: String(limit) });
|
|
372
|
+
if (chain) params.set("chain", chain);
|
|
373
|
+
return this.get(
|
|
374
|
+
`/v1/search?${params.toString()}`
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
createListingIntent(params) {
|
|
378
|
+
return this.post("/v1/intents/listing", params);
|
|
379
|
+
}
|
|
380
|
+
createOfferIntent(params) {
|
|
381
|
+
return this.post("/v1/intents/offer", params);
|
|
382
|
+
}
|
|
383
|
+
createFulfillIntent(params) {
|
|
384
|
+
return this.post("/v1/intents/fulfill", params);
|
|
385
|
+
}
|
|
386
|
+
createCancelIntent(params) {
|
|
387
|
+
return this.post("/v1/intents/cancel", params);
|
|
388
|
+
}
|
|
389
|
+
createCheckoutIntent(params) {
|
|
390
|
+
return this.post("/v1/intents/checkout", params);
|
|
391
|
+
}
|
|
392
|
+
getIntent(id) {
|
|
393
|
+
return this.get(`/v1/intents/${id}`);
|
|
394
|
+
}
|
|
395
|
+
submitIntentSignature(id, signature) {
|
|
396
|
+
return this.patch(`/v1/intents/${id}/signature`, { signature });
|
|
397
|
+
}
|
|
398
|
+
confirmIntent(id, txHash) {
|
|
399
|
+
return this.patch(`/v1/intents/${id}/confirm`, { txHash });
|
|
400
|
+
}
|
|
401
|
+
syncTransaction(txHash) {
|
|
402
|
+
return this.post("/v1/tx/sync", { txHash });
|
|
403
|
+
}
|
|
404
|
+
createMintIntent(params) {
|
|
405
|
+
return this.post("/v1/intents/mint", params);
|
|
406
|
+
}
|
|
407
|
+
createCollectionIntent(params) {
|
|
408
|
+
return this.post("/v1/intents/create-collection", params);
|
|
409
|
+
}
|
|
410
|
+
createTierIntent(params) {
|
|
411
|
+
return this.post("/v1/intents/create-tier", params);
|
|
412
|
+
}
|
|
413
|
+
emitToRecipients(params) {
|
|
414
|
+
return this.post("/v1/business/issuance/emission", params);
|
|
415
|
+
}
|
|
416
|
+
createCoinIntent(params) {
|
|
417
|
+
return this.post("/v1/intents/create-coin", params);
|
|
418
|
+
}
|
|
419
|
+
launchCoinIntent(params) {
|
|
420
|
+
return this.post("/v1/intents/launch-coin", params);
|
|
421
|
+
}
|
|
422
|
+
createSponsorshipOfferIntent(params) {
|
|
423
|
+
return this.post("/v1/intents/sponsorship-offer", params);
|
|
424
|
+
}
|
|
425
|
+
setSponsorshipOfferOpenIntent(params) {
|
|
426
|
+
return this.post("/v1/intents/sponsorship-offer-open", params);
|
|
427
|
+
}
|
|
428
|
+
placeSponsorshipBidIntent(params) {
|
|
429
|
+
return this.post("/v1/intents/sponsorship-bid", params);
|
|
430
|
+
}
|
|
431
|
+
retractSponsorshipBidIntent(params) {
|
|
432
|
+
return this.post("/v1/intents/sponsorship-bid-retract", params);
|
|
433
|
+
}
|
|
434
|
+
acceptSponsorshipBidIntent(params) {
|
|
435
|
+
return this.post("/v1/intents/sponsorship-bid-accept", params);
|
|
436
|
+
}
|
|
437
|
+
createSponsorshipProposalIntent(params) {
|
|
438
|
+
return this.post("/v1/intents/sponsorship-proposal", params);
|
|
439
|
+
}
|
|
440
|
+
withdrawSponsorshipProposalIntent(params) {
|
|
441
|
+
return this.post("/v1/intents/sponsorship-proposal-withdraw", params);
|
|
442
|
+
}
|
|
443
|
+
acceptSponsorshipProposalIntent(params) {
|
|
444
|
+
return this.post("/v1/intents/sponsorship-proposal-accept", params);
|
|
445
|
+
}
|
|
446
|
+
rejectSponsorshipProposalIntent(params) {
|
|
447
|
+
return this.post("/v1/intents/sponsorship-proposal-reject", params);
|
|
448
|
+
}
|
|
449
|
+
createCounterOfferIntent(params, siwsToken) {
|
|
450
|
+
const extraHeaders = siwsToken ? { "Authorization": `Bearer ${siwsToken}` } : {};
|
|
451
|
+
return this.request("/v1/intents/counter-offer", {
|
|
452
|
+
method: "POST",
|
|
453
|
+
body: JSON.stringify(params),
|
|
454
|
+
headers: extraHeaders
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
getCounterOffers(query) {
|
|
458
|
+
const params = new URLSearchParams();
|
|
459
|
+
if (query.originalOrderHash) params.set("originalOrderHash", query.originalOrderHash);
|
|
460
|
+
if (query.sellerAddress) params.set("sellerAddress", query.sellerAddress);
|
|
461
|
+
if (query.page !== void 0) params.set("page", String(query.page));
|
|
462
|
+
if (query.limit !== void 0) params.set("limit", String(query.limit));
|
|
463
|
+
return this.get(`/v1/orders/counter-offers?${params}`);
|
|
464
|
+
}
|
|
465
|
+
getMetadataSignedUrl(kind) {
|
|
466
|
+
const params = kind ? `?kind=${kind}` : "";
|
|
467
|
+
return this.get(`/v1/metadata/signed-url${params}`);
|
|
468
|
+
}
|
|
469
|
+
uploadMetadata(metadata) {
|
|
470
|
+
return this.post("/v1/metadata/upload", metadata);
|
|
471
|
+
}
|
|
472
|
+
async uploadMetadataDirectory(files) {
|
|
473
|
+
const res = await this.post("/v1/metadata/upload-directory", { files });
|
|
474
|
+
return res.data;
|
|
475
|
+
}
|
|
476
|
+
resolveMetadata(uri) {
|
|
477
|
+
const params = new URLSearchParams({ uri });
|
|
478
|
+
return this.get(`/v1/metadata/resolve?${params.toString()}`);
|
|
479
|
+
}
|
|
480
|
+
uploadFile(file) {
|
|
481
|
+
const formData = new FormData();
|
|
482
|
+
formData.append("file", file);
|
|
483
|
+
return this.request("/v1/metadata/upload-file", {
|
|
484
|
+
method: "POST",
|
|
485
|
+
body: formData
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
getMe(siwsToken) {
|
|
489
|
+
return this.request("/v1/portal/me", {
|
|
490
|
+
method: "GET",
|
|
491
|
+
headers: this.asSubject(siwsToken)
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
getApiKeys(siwsToken) {
|
|
495
|
+
return this.request("/v1/portal/keys", {
|
|
496
|
+
method: "GET",
|
|
497
|
+
headers: this.asSubject(siwsToken)
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
createApiKey(input, siwsToken) {
|
|
501
|
+
return this.request("/v1/portal/keys", {
|
|
502
|
+
method: "POST",
|
|
503
|
+
body: JSON.stringify(input ?? {}),
|
|
504
|
+
headers: this.asSubject(siwsToken)
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
deleteApiKey(id, siwsToken) {
|
|
508
|
+
return this.request(`/v1/portal/keys/${id}`, {
|
|
509
|
+
method: "DELETE",
|
|
510
|
+
headers: this.asSubject(siwsToken)
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
getCreditHistory(siwsToken) {
|
|
514
|
+
return this.request("/v1/portal/credits/history", {
|
|
515
|
+
method: "GET",
|
|
516
|
+
headers: this.asSubject(siwsToken)
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
getSpend(siwsToken) {
|
|
520
|
+
return this.request("/v1/portal/credits/spend", {
|
|
521
|
+
method: "GET",
|
|
522
|
+
headers: this.asSubject(siwsToken)
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
checkDeposit(txHash, siwsToken) {
|
|
526
|
+
return this.request("/v1/portal/credits/check", {
|
|
527
|
+
method: "POST",
|
|
528
|
+
body: JSON.stringify({ txHash }),
|
|
529
|
+
headers: this.asSubject(siwsToken)
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
getFundingMethods(siwsToken) {
|
|
533
|
+
return this.request("/v1/portal/funding/methods", {
|
|
534
|
+
method: "GET",
|
|
535
|
+
headers: this.asSubject(siwsToken)
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
createFunding(input, siwsToken) {
|
|
539
|
+
return this.request("/v1/portal/funding", {
|
|
540
|
+
method: "POST",
|
|
541
|
+
body: JSON.stringify({ method: input.method, params: input.params }),
|
|
542
|
+
headers: this.asSubject(siwsToken)
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
getFunding(id, siwsToken) {
|
|
546
|
+
return this.request(`/v1/portal/funding/${encodeURIComponent(id)}`, {
|
|
547
|
+
method: "GET",
|
|
548
|
+
headers: this.asSubject(siwsToken)
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
getFundingChallenge(id, payer, siwsToken) {
|
|
552
|
+
return this.request(`/v1/portal/funding/${encodeURIComponent(id)}/challenge`, {
|
|
553
|
+
method: "POST",
|
|
554
|
+
body: JSON.stringify({ payer }),
|
|
555
|
+
headers: this.asSubject(siwsToken)
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
authorizeFunding(id, input, siwsToken) {
|
|
559
|
+
return this.request(
|
|
560
|
+
`/v1/portal/funding/${encodeURIComponent(id)}/authorize`,
|
|
561
|
+
{ method: "POST", body: JSON.stringify({ payer: input.payer, signature: input.signature }), headers: this.asSubject(siwsToken) }
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
submitFunding(id, txHash, siwsToken) {
|
|
565
|
+
return this.request(`/v1/portal/funding/${encodeURIComponent(id)}/submit`, {
|
|
566
|
+
method: "POST",
|
|
567
|
+
body: JSON.stringify({ txHash }),
|
|
568
|
+
headers: this.asSubject(siwsToken)
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
cancelFunding(id, siwsToken) {
|
|
572
|
+
return this.request(`/v1/portal/funding/${encodeURIComponent(id)}/cancel`, {
|
|
573
|
+
method: "POST",
|
|
574
|
+
body: JSON.stringify({}),
|
|
575
|
+
headers: this.asSubject(siwsToken)
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
async claimCollection(contractAddress, walletAddress, siwsToken) {
|
|
579
|
+
return this.request("/v1/collections/claim", {
|
|
580
|
+
method: "POST",
|
|
581
|
+
body: JSON.stringify({ contractAddress, walletAddress }),
|
|
582
|
+
headers: this.bearer(siwsToken)
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
requestCollectionClaim(params) {
|
|
586
|
+
return this.request("/v1/collections/claim/request", {
|
|
587
|
+
method: "POST",
|
|
588
|
+
body: JSON.stringify(params)
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
registerBusinessProvisioning(params) {
|
|
592
|
+
return this.post(
|
|
593
|
+
"/v1/business/provisioning",
|
|
594
|
+
{ chain: params.chain ?? "STARKNET", email: params.email }
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
getCollectionProfile(contractAddress) {
|
|
598
|
+
return this.request(
|
|
599
|
+
`/v1/collections/${this.addr(contractAddress)}/profile`,
|
|
600
|
+
{ method: "GET" },
|
|
601
|
+
{ allow404: true }
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
updateCollectionProfile(contractAddress, data, siwsToken) {
|
|
605
|
+
return this.request(
|
|
606
|
+
`/v1/collections/${this.addr(contractAddress)}/profile`,
|
|
607
|
+
{ method: "PATCH", body: JSON.stringify(data), headers: this.bearer(siwsToken) }
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
getWalletActivity(address, chain = "STARKNET") {
|
|
611
|
+
return this.get(
|
|
612
|
+
`/v1/wallet-activity?address=${this.addr(address)}&chain=${chain}`
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
getGatedContent(contractAddress, siwsToken) {
|
|
616
|
+
return this.request(
|
|
617
|
+
`/v1/collections/${this.addr(contractAddress)}/gated-content`,
|
|
618
|
+
{ method: "GET", headers: this.bearer(siwsToken) },
|
|
619
|
+
{ allow404: true, allow403: true }
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
getCreators(opts = {}) {
|
|
623
|
+
const params = new URLSearchParams();
|
|
624
|
+
if (opts.search) params.set("search", opts.search);
|
|
625
|
+
if (opts.page) params.set("page", String(opts.page));
|
|
626
|
+
if (opts.limit) params.set("limit", String(opts.limit));
|
|
627
|
+
const qs = params.toString();
|
|
628
|
+
return this.get(`/v1/creators${qs ? `?${qs}` : ""}`);
|
|
629
|
+
}
|
|
630
|
+
getCreatorProfile(walletAddress) {
|
|
631
|
+
return this.request(
|
|
632
|
+
`/v1/creators/${this.addr(walletAddress)}/profile`,
|
|
633
|
+
{ method: "GET" },
|
|
634
|
+
{ allow404: true }
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
getCreatorByUsername(username) {
|
|
638
|
+
return this.request(
|
|
639
|
+
`/v1/creators/by-username/${encodeURIComponent(username.toLowerCase().trim())}`,
|
|
640
|
+
{ method: "GET" },
|
|
641
|
+
{ allow404: true }
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
updateCreatorProfile(walletAddress, data, siwsToken) {
|
|
645
|
+
return this.request(
|
|
646
|
+
`/v1/creators/${this.addr(walletAddress)}/profile`,
|
|
647
|
+
{ method: "PATCH", body: JSON.stringify(data), headers: this.bearer(siwsToken) }
|
|
648
|
+
);
|
|
649
|
+
}
|
|
650
|
+
checkCollectionSlugAvailability(slug) {
|
|
651
|
+
return this.get(
|
|
652
|
+
`/v1/collection-slug-claims/check/${encodeURIComponent(slug.toLowerCase().trim())}`
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
submitCollectionSlugClaim(contractAddress, slug, siwsToken, notifyEmail) {
|
|
656
|
+
return this.request("/v1/collection-slug-claims", {
|
|
657
|
+
method: "POST",
|
|
658
|
+
body: JSON.stringify({ contractAddress, slug, notifyEmail }),
|
|
659
|
+
headers: this.bearer(siwsToken)
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
getMyCollectionSlugClaims(siwsToken) {
|
|
663
|
+
return this.request("/v1/collection-slug-claims/me", {
|
|
664
|
+
method: "GET",
|
|
665
|
+
headers: this.bearer(siwsToken)
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
async getCollectionBySlug(slug) {
|
|
669
|
+
const res = await this.request(
|
|
670
|
+
`/v1/collections/by-slug/${encodeURIComponent(slug.toLowerCase().trim())}`,
|
|
671
|
+
{ method: "GET" },
|
|
672
|
+
{ allow404: true }
|
|
673
|
+
);
|
|
674
|
+
return res?.data ?? null;
|
|
675
|
+
}
|
|
676
|
+
async registerUser(params) {
|
|
677
|
+
return this.post("/v1/users/register", params);
|
|
678
|
+
}
|
|
679
|
+
async upsertMyWallet(siwsToken, options = {}) {
|
|
680
|
+
const body = {
|
|
681
|
+
walletType: options.walletType ?? "UNKNOWN"
|
|
682
|
+
};
|
|
683
|
+
if (options.chain) body.chain = options.chain;
|
|
684
|
+
if (options.email) body.email = options.email;
|
|
685
|
+
if (options.accountToken) body.accountToken = options.accountToken;
|
|
686
|
+
return this.request("/v1/users/me", {
|
|
687
|
+
method: "POST",
|
|
688
|
+
body: JSON.stringify(body),
|
|
689
|
+
headers: this.bearer(siwsToken)
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
async checkEmail(email) {
|
|
693
|
+
const body = await this.get(`/v1/auth/email/exists?email=${encodeURIComponent(email)}`);
|
|
694
|
+
return { exists: body.exists };
|
|
695
|
+
}
|
|
696
|
+
async requestEmailCode(email) {
|
|
697
|
+
await this.post("/v1/auth/email/request-code", { email });
|
|
698
|
+
}
|
|
699
|
+
async registerEmailAccount(email) {
|
|
700
|
+
await this.post("/v1/auth/email/register-account", { email });
|
|
701
|
+
}
|
|
702
|
+
async verifyEmailCode(email, code) {
|
|
703
|
+
await this.post("/v1/auth/email/verify-code", { email, code });
|
|
704
|
+
}
|
|
705
|
+
async confirmEmail(token) {
|
|
706
|
+
const body = await this.post("/v1/auth/email/confirm", { token });
|
|
707
|
+
return { email: body.email };
|
|
708
|
+
}
|
|
709
|
+
setupWalletKey(params) {
|
|
710
|
+
return this.post("/v1/users/me/wallet/key", params);
|
|
711
|
+
}
|
|
712
|
+
async getSessionWallet() {
|
|
713
|
+
const body = await this.post("/v1/users/me/wallet", {});
|
|
714
|
+
return body.walletAddress ? { walletAddress: body.walletAddress, needsKeySetup: body.needsKeySetup === true } : null;
|
|
715
|
+
}
|
|
716
|
+
getMyWallet(siwsToken) {
|
|
717
|
+
return this.request(
|
|
718
|
+
"/v1/users/me",
|
|
719
|
+
{ method: "GET", headers: this.bearer(siwsToken) },
|
|
720
|
+
{ allow404: true }
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
changeMyEmail(email, siwsToken) {
|
|
724
|
+
return this.request("/v1/users/me/email", {
|
|
725
|
+
method: "POST",
|
|
726
|
+
headers: this.bearer(siwsToken),
|
|
727
|
+
body: JSON.stringify({ email })
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
getTokenRemixes(contract, tokenId, opts = {}) {
|
|
731
|
+
const params = new URLSearchParams();
|
|
732
|
+
if (opts.page !== void 0) params.set("page", String(opts.page));
|
|
733
|
+
if (opts.limit !== void 0) params.set("limit", String(opts.limit));
|
|
734
|
+
const qs = params.toString();
|
|
735
|
+
return this.get(
|
|
736
|
+
`/v1/tokens/${this.addr(contract)}/${tokenId}/remixes${qs ? `?${qs}` : ""}`
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
submitRemixOffer(params, siwsToken) {
|
|
740
|
+
return this.request("/v1/remix-offers", {
|
|
741
|
+
method: "POST",
|
|
742
|
+
body: JSON.stringify(params),
|
|
743
|
+
headers: { "Authorization": `Bearer ${siwsToken}` }
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
submitAutoRemixOffer(params, siwsToken) {
|
|
747
|
+
return this.request("/v1/remix-offers/auto", {
|
|
748
|
+
method: "POST",
|
|
749
|
+
body: JSON.stringify(params),
|
|
750
|
+
headers: { "Authorization": `Bearer ${siwsToken}` }
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
confirmSelfRemix(params, siwsToken) {
|
|
754
|
+
return this.request("/v1/remix-offers/self/confirm", {
|
|
755
|
+
method: "POST",
|
|
756
|
+
body: JSON.stringify(params),
|
|
757
|
+
headers: { "Authorization": `Bearer ${siwsToken}` }
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
getRemixOffers(query, siwsToken) {
|
|
761
|
+
const params = new URLSearchParams({ role: query.role });
|
|
762
|
+
if (query.status) params.set("status", query.status);
|
|
763
|
+
if (query.page !== void 0) params.set("page", String(query.page));
|
|
764
|
+
if (query.limit !== void 0) params.set("limit", String(query.limit));
|
|
765
|
+
return this.request(`/v1/remix-offers?${params}`, {
|
|
766
|
+
method: "GET",
|
|
767
|
+
headers: this.bearer(siwsToken)
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
getRemixOffer(id, siwsToken) {
|
|
771
|
+
return this.request(`/v1/remix-offers/${id}`, {
|
|
772
|
+
method: "GET",
|
|
773
|
+
headers: siwsToken ? this.bearer(siwsToken) : void 0
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
confirmRemixOffer(id, params, siwsToken) {
|
|
777
|
+
return this.request(`/v1/remix-offers/${id}/confirm`, {
|
|
778
|
+
method: "POST",
|
|
779
|
+
body: JSON.stringify(params),
|
|
780
|
+
headers: { "Authorization": `Bearer ${siwsToken}` }
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
rejectRemixOffer(id, siwsToken) {
|
|
784
|
+
return this.request(`/v1/remix-offers/${id}/reject`, {
|
|
785
|
+
method: "POST",
|
|
786
|
+
body: JSON.stringify({}),
|
|
787
|
+
headers: { "Authorization": `Bearer ${siwsToken}` }
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
extendRemixOffer(id, days, siwsToken) {
|
|
791
|
+
return this.request(`/v1/remix-offers/${id}/extend`, {
|
|
792
|
+
method: "POST",
|
|
793
|
+
body: JSON.stringify({ days }),
|
|
794
|
+
headers: { "Authorization": `Bearer ${siwsToken}` }
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
async getPopEligibility(collection, wallet) {
|
|
798
|
+
const res = await this.get(
|
|
799
|
+
`/v1/pop/eligibility/${this.addr(collection)}/${this.addr(wallet)}`
|
|
800
|
+
);
|
|
801
|
+
return res.data;
|
|
802
|
+
}
|
|
803
|
+
async getPopEligibilityBatch(collection, wallets) {
|
|
804
|
+
const params = new URLSearchParams({ wallets: wallets.map((w) => this.addr(w)).join(",") });
|
|
805
|
+
const res = await this.get(
|
|
806
|
+
`/v1/pop/eligibility/${this.addr(collection)}?${params}`
|
|
807
|
+
);
|
|
808
|
+
return res.data;
|
|
809
|
+
}
|
|
810
|
+
getCoins(opts = {}) {
|
|
811
|
+
const params = new URLSearchParams();
|
|
812
|
+
if (opts.page) params.set("page", String(opts.page));
|
|
813
|
+
if (opts.limit) params.set("limit", String(opts.limit));
|
|
814
|
+
if (opts.service) params.set("service", opts.service);
|
|
815
|
+
if (opts.sort) params.set("sort", opts.sort);
|
|
816
|
+
if (opts.creator) params.set("creator", this.addr(opts.creator));
|
|
817
|
+
if (opts.chain) params.set("chain", opts.chain);
|
|
818
|
+
const qs = params.toString();
|
|
819
|
+
return this.get(`/v1/coins${qs ? `?${qs}` : ""}`);
|
|
820
|
+
}
|
|
821
|
+
getCoin(contract) {
|
|
822
|
+
return this.get(`/v1/coins/${this.addr(contract)}`);
|
|
823
|
+
}
|
|
824
|
+
getCoinPrices() {
|
|
825
|
+
return this.get("/v1/coins/prices");
|
|
826
|
+
}
|
|
827
|
+
claimCoin(coinAddress, siwsToken) {
|
|
828
|
+
return this.request("/v1/coins/claim", {
|
|
829
|
+
method: "POST",
|
|
830
|
+
headers: { Authorization: `Bearer ${siwsToken}` },
|
|
831
|
+
body: JSON.stringify({ coinAddress })
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
getCoinClaims(status = "PENDING") {
|
|
835
|
+
return this.get(
|
|
836
|
+
`/v1/coins/claims?status=${encodeURIComponent(status)}`
|
|
837
|
+
);
|
|
838
|
+
}
|
|
839
|
+
updateCoinProfile(contract, data, siwsToken) {
|
|
840
|
+
return this.request(`/v1/coins/${this.addr(contract)}`, {
|
|
841
|
+
method: "PATCH",
|
|
842
|
+
body: JSON.stringify(data),
|
|
843
|
+
headers: this.bearer(siwsToken)
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
async getDropMintStatus(collection, wallet) {
|
|
847
|
+
const res = await this.get(
|
|
848
|
+
`/v1/drop/mint-status/${this.addr(collection)}/${this.addr(wallet)}`
|
|
849
|
+
);
|
|
850
|
+
return res.data;
|
|
851
|
+
}
|
|
852
|
+
async getDropInfo(contract) {
|
|
853
|
+
const res = await this.request(
|
|
854
|
+
`/v1/drop/${this.addr(contract)}/info`,
|
|
855
|
+
{ method: "GET" },
|
|
856
|
+
{ allow404: true }
|
|
857
|
+
);
|
|
858
|
+
return res?.data ?? null;
|
|
859
|
+
}
|
|
860
|
+
async getDropState(contract) {
|
|
861
|
+
const res = await this.get(`/v1/drop/${this.addr(contract)}/state`);
|
|
862
|
+
return res.data;
|
|
863
|
+
}
|
|
864
|
+
async getTicket(contract, tokenId) {
|
|
865
|
+
const res = await this.get(`/v1/tickets/${this.addr(contract)}/${tokenId}`);
|
|
866
|
+
return res.data;
|
|
867
|
+
}
|
|
868
|
+
async getTicketCount(contract) {
|
|
869
|
+
const res = await this.get(`/v1/tickets/${this.addr(contract)}/count`);
|
|
870
|
+
return res.data.count;
|
|
871
|
+
}
|
|
872
|
+
async getClubMembershipCount(contract) {
|
|
873
|
+
const res = await this.get(`/v1/club/${this.addr(contract)}/count`);
|
|
874
|
+
return res.data.count;
|
|
875
|
+
}
|
|
876
|
+
async getClubMembership(contract, tokenId) {
|
|
877
|
+
const res = await this.get(`/v1/club/${this.addr(contract)}/${tokenId}`);
|
|
878
|
+
return res.data;
|
|
879
|
+
}
|
|
880
|
+
async isClubMember(contract, tokenId, wallet) {
|
|
881
|
+
const res = await this.get(
|
|
882
|
+
`/v1/club/${this.addr(contract)}/${tokenId}/member/${this.addr(wallet)}`
|
|
883
|
+
);
|
|
884
|
+
return res.data.isMember;
|
|
885
|
+
}
|
|
886
|
+
async getIpNftTokenData(contract, tokenId) {
|
|
887
|
+
const res = await this.get(`/v1/ipnft/${this.addr(contract)}/${tokenId}`);
|
|
888
|
+
return res.data;
|
|
889
|
+
}
|
|
890
|
+
async getPlatformStats() {
|
|
891
|
+
const res = await this.get("/v1/stats");
|
|
892
|
+
return res.data;
|
|
893
|
+
}
|
|
894
|
+
getTokens(query = {}) {
|
|
895
|
+
const params = new URLSearchParams();
|
|
896
|
+
if (query.page !== void 0) params.set("page", String(query.page));
|
|
897
|
+
if (query.limit !== void 0) params.set("limit", String(query.limit));
|
|
898
|
+
if (query.sort) params.set("sort", query.sort);
|
|
899
|
+
if (query.ipType) params.set("ipType", query.ipType);
|
|
900
|
+
if (query.derivatives) params.set("derivatives", query.derivatives);
|
|
901
|
+
const qs = params.toString();
|
|
902
|
+
return this.get(`/v1/tokens${qs ? `?${qs}` : ""}`);
|
|
903
|
+
}
|
|
904
|
+
async isCreatorHidden(wallet) {
|
|
905
|
+
const res = await this.get(`/v1/creators/${this.addr(wallet)}/hidden`);
|
|
906
|
+
return res.isHidden;
|
|
907
|
+
}
|
|
908
|
+
getMyUsernameClaim(siwsToken) {
|
|
909
|
+
return this.request("/v1/username-claims/me", {
|
|
910
|
+
method: "GET",
|
|
911
|
+
headers: this.bearer(siwsToken)
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
checkUsernameAvailability(username) {
|
|
915
|
+
return this.get(
|
|
916
|
+
`/v1/username-claims/check/${encodeURIComponent(username)}`
|
|
917
|
+
);
|
|
918
|
+
}
|
|
919
|
+
async submitUsernameClaim(username, siwsToken, notifyEmail) {
|
|
920
|
+
const res = await this.request("/v1/username-claims", {
|
|
921
|
+
method: "POST",
|
|
922
|
+
headers: this.bearer(siwsToken),
|
|
923
|
+
body: JSON.stringify({ username, ...notifyEmail ? { notifyEmail } : {} })
|
|
924
|
+
});
|
|
925
|
+
return res.claim;
|
|
926
|
+
}
|
|
927
|
+
async submitReport(report, siwsToken) {
|
|
928
|
+
const targetContract = report.targetContract ? this.addr(report.targetContract) : void 0;
|
|
929
|
+
const targetAddress = report.targetAddress ? this.addr(report.targetAddress) : void 0;
|
|
930
|
+
let targetKey = null;
|
|
931
|
+
if (report.targetType === "TOKEN" && targetContract && report.targetTokenId) {
|
|
932
|
+
targetKey = `TOKEN:${targetContract}:${report.targetTokenId}`;
|
|
933
|
+
} else if (report.targetType === "COLLECTION" && targetContract) {
|
|
934
|
+
targetKey = `COLLECTION:${targetContract}`;
|
|
935
|
+
} else if (report.targetType === "CREATOR" && targetAddress) {
|
|
936
|
+
targetKey = `CREATOR:${targetAddress}`;
|
|
937
|
+
} else if (report.targetType === "COMMENT" && report.targetId) {
|
|
938
|
+
targetKey = `COMMENT::${report.targetId}`;
|
|
939
|
+
}
|
|
940
|
+
if (!targetKey) throw new Error(`A ${report.targetType} report needs its target`);
|
|
941
|
+
await this.request("/v1/reports", {
|
|
942
|
+
method: "POST",
|
|
943
|
+
headers: this.bearer(siwsToken),
|
|
944
|
+
body: JSON.stringify({ ...report, targetKey, targetContract, targetAddress })
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
getPricing() {
|
|
948
|
+
return this.get("/v1/pricing");
|
|
949
|
+
}
|
|
950
|
+
listCollections(query = {}) {
|
|
951
|
+
const params = new URLSearchParams();
|
|
952
|
+
if (query.page !== void 0) params.set("page", String(query.page));
|
|
953
|
+
if (query.limit !== void 0) params.set("limit", String(query.limit));
|
|
954
|
+
if (query.owner) params.set("owner", this.addr(query.owner));
|
|
955
|
+
if (query.service) params.set("service", query.service);
|
|
956
|
+
if (query.sort) params.set("sort", query.sort);
|
|
957
|
+
if (query.isFeatured !== void 0) params.set("isFeatured", String(query.isFeatured));
|
|
958
|
+
if (query.hideEmpty !== void 0) params.set("hideEmpty", String(query.hideEmpty));
|
|
959
|
+
if (query.standard) params.set("standard", query.standard);
|
|
960
|
+
if (query.chain) params.set("chain", query.chain);
|
|
961
|
+
const qs = params.toString();
|
|
962
|
+
return this.get(`/v1/collections${qs ? `?${qs}` : ""}`);
|
|
963
|
+
}
|
|
964
|
+
generateWallet(newWalletSiwsToken, siwsToken) {
|
|
965
|
+
return this.request("/v1/users/me/generate-wallet", {
|
|
966
|
+
method: "POST",
|
|
967
|
+
headers: this.bearer(siwsToken),
|
|
968
|
+
body: JSON.stringify({ newWalletSiwsToken })
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
syncCoin(coinAddress, owner) {
|
|
972
|
+
return this.post("/v1/coins/sync", { coinAddress, ...owner ? { owner } : {} });
|
|
973
|
+
}
|
|
974
|
+
registerCollection(contractAddress) {
|
|
975
|
+
return this.post("/v1/collections/register", { contractAddress });
|
|
976
|
+
}
|
|
977
|
+
getSponsorshipOffers(query = {}) {
|
|
978
|
+
const params = new URLSearchParams({ limit: String(query.limit ?? 50) });
|
|
979
|
+
if (query.nftContract) params.set("nftContract", query.nftContract);
|
|
980
|
+
if (query.author) params.set("author", query.author);
|
|
981
|
+
if (query.owner) params.set("owner", query.owner);
|
|
982
|
+
if (query.open !== void 0) params.set("open", String(query.open));
|
|
983
|
+
return this.get(`/v1/sponsorship/offers?${params}`);
|
|
984
|
+
}
|
|
985
|
+
async getSponsorshipOffer(offerId) {
|
|
986
|
+
const res = await this.request(
|
|
987
|
+
`/v1/sponsorship/offers/${encodeURIComponent(offerId)}`,
|
|
988
|
+
{ method: "GET" },
|
|
989
|
+
{ allow404: true }
|
|
990
|
+
);
|
|
991
|
+
return res?.data ?? null;
|
|
992
|
+
}
|
|
993
|
+
async getSponsorshipProposal(proposalId) {
|
|
994
|
+
const res = await this.request(
|
|
995
|
+
`/v1/sponsorship/proposals/${encodeURIComponent(proposalId)}`,
|
|
996
|
+
{ method: "GET" },
|
|
997
|
+
{ allow404: true }
|
|
998
|
+
);
|
|
999
|
+
return res?.data ?? null;
|
|
1000
|
+
}
|
|
1001
|
+
async getSponsorshipBids(offerId) {
|
|
1002
|
+
const res = await this.get(`/v1/sponsorship/offers/${encodeURIComponent(offerId)}/bids`);
|
|
1003
|
+
return res.data;
|
|
1004
|
+
}
|
|
1005
|
+
getSponsorshipProposals(query = {}) {
|
|
1006
|
+
const params = new URLSearchParams({ limit: String(query.limit ?? 50) });
|
|
1007
|
+
if (query.nftContract) params.set("nftContract", query.nftContract);
|
|
1008
|
+
if (query.proposer) params.set("proposer", query.proposer);
|
|
1009
|
+
if (query.owner) params.set("owner", query.owner);
|
|
1010
|
+
if (query.open !== void 0) params.set("open", String(query.open));
|
|
1011
|
+
return this.get(`/v1/sponsorship/proposals?${params}`);
|
|
1012
|
+
}
|
|
1013
|
+
getSponsorshipLicenses(query = {}) {
|
|
1014
|
+
const params = new URLSearchParams({ limit: String(query.limit ?? 50) });
|
|
1015
|
+
if (query.holder) params.set("holder", query.holder);
|
|
1016
|
+
if (query.author) params.set("author", query.author);
|
|
1017
|
+
return this.get(`/v1/sponsorship/licenses?${params}`);
|
|
1018
|
+
}
|
|
1019
|
+
async getRewards(address) {
|
|
1020
|
+
const res = await this.get(`/v1/rewards/${this.addr(address)}`);
|
|
1021
|
+
return res.data;
|
|
1022
|
+
}
|
|
1023
|
+
getRewardsLeaderboard(page = 1, limit = 50) {
|
|
1024
|
+
return this.get(`/v1/rewards?page=${page}&limit=${limit}`);
|
|
1025
|
+
}
|
|
1026
|
+
getRewardsEvents(address, page = 1, limit = 20) {
|
|
1027
|
+
return this.get(
|
|
1028
|
+
`/v1/rewards/${this.addr(address)}/events?page=${page}&limit=${limit}`
|
|
1029
|
+
);
|
|
1030
|
+
}
|
|
1031
|
+
async getRewardsConfig() {
|
|
1032
|
+
const res = await this.get(`/v1/rewards/config`);
|
|
1033
|
+
return res.data;
|
|
1034
|
+
}
|
|
1035
|
+
async getRewardsBatch(addresses) {
|
|
1036
|
+
if (addresses.length === 0) return [];
|
|
1037
|
+
const params = new URLSearchParams({ addresses: addresses.map((a) => this.addr(a)).join(",") });
|
|
1038
|
+
const res = await this.get(`/v1/rewards/batch?${params}`);
|
|
1039
|
+
return res.data;
|
|
1040
|
+
}
|
|
1041
|
+
};
|
|
1042
|
+
async function deriveAesKey(prfSecret, hkdfInfo) {
|
|
1043
|
+
const hkdf = await crypto.subtle.importKey("raw", prfSecret, "HKDF", false, ["deriveKey"]);
|
|
1044
|
+
return crypto.subtle.deriveKey(
|
|
1045
|
+
{ name: "HKDF", hash: "SHA-256", salt: new Uint8Array(0), info: hkdfInfo },
|
|
1046
|
+
hkdf,
|
|
1047
|
+
{ name: "AES-GCM", length: 256 },
|
|
1048
|
+
false,
|
|
1049
|
+
["encrypt", "decrypt"]
|
|
1050
|
+
);
|
|
1051
|
+
}
|
|
1052
|
+
function generateStarkKeyPair() {
|
|
1053
|
+
const privateKeyHex = "0x" + Array.from(starknet.ec.starkCurve.utils.randomPrivateKey()).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1054
|
+
return { privateKeyHex, publicKeyHex: starknet.ec.starkCurve.getStarkKey(privateKeyHex) };
|
|
1055
|
+
}
|
|
1056
|
+
var InvalidStarkPrivateKeyError = class extends Error {
|
|
1057
|
+
constructor(reason) {
|
|
1058
|
+
super(`Not a valid Starknet private key: ${reason}`);
|
|
1059
|
+
this.name = "InvalidStarkPrivateKeyError";
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
function starkKeyPairFromPrivateKey(input) {
|
|
1063
|
+
const trimmed = input.trim().replace(/\s+/g, "");
|
|
1064
|
+
const body = trimmed.startsWith("0x") || trimmed.startsWith("0X") ? trimmed.slice(2) : trimmed;
|
|
1065
|
+
if (body.length === 0) throw new InvalidStarkPrivateKeyError("it is empty");
|
|
1066
|
+
if (!/^[0-9a-fA-F]+$/.test(body)) throw new InvalidStarkPrivateKeyError("it is not hexadecimal");
|
|
1067
|
+
if (body.length > 64) throw new InvalidStarkPrivateKeyError("it is too long");
|
|
1068
|
+
const value = BigInt("0x" + body);
|
|
1069
|
+
if (value === 0n) throw new InvalidStarkPrivateKeyError("it is zero");
|
|
1070
|
+
if (value >= starknet.ec.starkCurve.CURVE.n) throw new InvalidStarkPrivateKeyError("it is outside the curve order");
|
|
1071
|
+
const privateKeyHex = "0x" + value.toString(16).padStart(64, "0");
|
|
1072
|
+
return { privateKeyHex, publicKeyHex: starknet.ec.starkCurve.getStarkKey(privateKeyHex) };
|
|
1073
|
+
}
|
|
1074
|
+
async function sealPrivateKey(aesKey, iv, privateKeyHex) {
|
|
1075
|
+
return crypto.subtle.encrypt(
|
|
1076
|
+
{ name: "AES-GCM", iv },
|
|
1077
|
+
aesKey,
|
|
1078
|
+
new TextEncoder().encode(privateKeyHex)
|
|
1079
|
+
);
|
|
1080
|
+
}
|
|
1081
|
+
async function unsealPrivateKey(aesKey, iv, ciphertext) {
|
|
1082
|
+
const buf = await crypto.subtle.decrypt({ name: "AES-GCM", iv }, aesKey, ciphertext);
|
|
1083
|
+
return new TextDecoder().decode(buf);
|
|
1084
|
+
}
|
|
1085
|
+
function signWithPrivateKey(privateKeyHex, msgHash) {
|
|
1086
|
+
const sig = starknet.ec.starkCurve.sign(msgHash, privateKeyHex);
|
|
1087
|
+
return [starknet.num.toHex(sig.r), starknet.num.toHex(sig.s)];
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
// src/constants.ts
|
|
1091
|
+
var SN = chunkOUPVVMLK_cjs.getCoordinates("STARKNET");
|
|
1092
|
+
var STARKNET_MARKETPLACE_721_CONTRACT = SN.marketplace721;
|
|
1093
|
+
var STARKNET_MARKETPLACE_721_CLASS_HASH = SN.marketplace721ClassHash;
|
|
1094
|
+
var STARKNET_MARKETPLACE_721_START_BLOCK = SN.marketplace721StartBlock;
|
|
1095
|
+
var STARKNET_MARKETPLACE_1155_CONTRACT = SN.marketplace1155;
|
|
1096
|
+
var STARKNET_MARKETPLACE_1155_CLASS_HASH = SN.marketplace1155ClassHash;
|
|
1097
|
+
var STARKNET_MARKETPLACE_1155_START_BLOCK = SN.marketplace1155StartBlock;
|
|
1098
|
+
var STARKNET_COLLECTION_721_CONTRACT = SN.collection721;
|
|
1099
|
+
var STARKNET_DATA_TOKENIZATION_721_CONTRACT = SN.dataTokenization721;
|
|
1100
|
+
var STARKNET_COLLECTION_721_START_BLOCK = SN.collection721StartBlock;
|
|
1101
|
+
var STARKNET_IPNFT_CLASS_HASH = SN.ipNftClassHash;
|
|
1102
|
+
var STARKNET_IPCOLLECTION_CLASS_HASH = SN.ipCollectionClassHash;
|
|
1103
|
+
var STARKNET_COLLECTION_1155_CONTRACT = SN.collection1155;
|
|
1104
|
+
var STARKNET_COLLECTION_1155_FACTORY_CLASS_HASH = SN.collection1155FactoryClassHash;
|
|
1105
|
+
var STARKNET_COLLECTION_1155_CLASS_HASH = SN.collection1155ClassHash;
|
|
1106
|
+
var STARKNET_COLLECTION_1155_START_BLOCK = SN.collection1155StartBlock;
|
|
1107
|
+
var STARKNET_POP_FACTORY_CONTRACT = SN.popFactory;
|
|
1108
|
+
var STARKNET_POP_COLLECTION_CLASS_HASH = SN.popCollectionClassHash;
|
|
1109
|
+
var STARKNET_DROP_FACTORY_CONTRACT = SN.dropFactory;
|
|
1110
|
+
var STARKNET_DROP_COLLECTION_CLASS_HASH = SN.dropCollectionClassHash;
|
|
1111
|
+
var STARKNET_NFTCOMMENTS_CONTRACT = SN.nftComments;
|
|
1112
|
+
var STARKNET_IP_TICKETS_FACTORY_CONTRACT = SN.ipTicketsFactory;
|
|
1113
|
+
var STARKNET_IP_TICKET_COLLECTION_CLASS_HASH = SN.ipTicketCollectionClassHash;
|
|
1114
|
+
var STARKNET_IP_CLUB_FACTORY_CONTRACT = SN.ipClubFactory;
|
|
1115
|
+
var STARKNET_IP_CLUB_COLLECTION_CLASS_HASH = SN.ipClubCollectionClassHash;
|
|
1116
|
+
var STARKNET_IP_SPONSORSHIP_CONTRACT = SN.ipSponsorship;
|
|
1117
|
+
var STARKNET_IP_SPONSORSHIP_CLASS_HASH = SN.ipSponsorshipClassHash;
|
|
1118
|
+
var STARKNET_MEDIAWALLET_CLASS_HASH = SN.mediaWalletClassHash;
|
|
1119
|
+
var STARKNET_CREATOR_COIN_FACTORY_CONTRACT = SN.creatorCoinFactory;
|
|
1120
|
+
var STARKNET_CREATOR_COIN_EKUBO_LAUNCHER = SN.creatorCoinEkuboLauncher;
|
|
1121
|
+
var STARKNET_CREATOR_COIN_CLASS_HASH = SN.creatorCoinClassHash;
|
|
1122
|
+
var STARKNET_CREATOR_COIN_FACTORY_CLASS_HASH = SN.creatorCoinFactoryClassHash;
|
|
1123
|
+
var STARKNET_CREATOR_COIN_START_BLOCK = SN.creatorCoinStartBlock;
|
|
1124
|
+
var STARKNET_GENESIS_MINT_CONTRACT = SN.genesisMint;
|
|
1125
|
+
var STARKNET_GENESIS_NFT_URI = "ipfs://bafkreiag6wzov7migmxwx3wrtudvbx4ajrlbjopqw7uni7nn2nsxv4eykm";
|
|
1126
|
+
var STARKNET_EKUBO_CORE = SN.ekuboCore;
|
|
1127
|
+
var SUPPORTED_TOKENS = [
|
|
1128
|
+
{
|
|
1129
|
+
symbol: "USDC",
|
|
1130
|
+
address: "0x033068f6539f8e6e6b131e6b2b814e6c34a5224bc66947c47dab9dfee93b35fb",
|
|
1131
|
+
decimals: 6,
|
|
1132
|
+
listable: true
|
|
1133
|
+
},
|
|
1134
|
+
{
|
|
1135
|
+
symbol: "USDT",
|
|
1136
|
+
address: "0x068f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8",
|
|
1137
|
+
decimals: 6,
|
|
1138
|
+
listable: true
|
|
1139
|
+
},
|
|
1140
|
+
{
|
|
1141
|
+
symbol: "ETH",
|
|
1142
|
+
address: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
|
|
1143
|
+
decimals: 18,
|
|
1144
|
+
listable: true
|
|
1145
|
+
},
|
|
1146
|
+
{
|
|
1147
|
+
symbol: "STRK",
|
|
1148
|
+
address: "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
|
|
1149
|
+
decimals: 18,
|
|
1150
|
+
listable: true
|
|
1151
|
+
},
|
|
1152
|
+
{
|
|
1153
|
+
symbol: "WBTC",
|
|
1154
|
+
address: "0x03fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac",
|
|
1155
|
+
decimals: 8,
|
|
1156
|
+
listable: true
|
|
1157
|
+
}
|
|
1158
|
+
];
|
|
1159
|
+
var DEFAULT_CURRENCY = "USDC";
|
|
1160
|
+
function ownerConstructorCalldata(ownerPubkey) {
|
|
1161
|
+
return ["0x0", starknet.num.toHex(ownerPubkey), "0x1"];
|
|
1162
|
+
}
|
|
1163
|
+
function computeAccountAddress(ownerPubkey, salt = 0) {
|
|
1164
|
+
return starknet.hash.calculateContractAddressFromHash(
|
|
1165
|
+
starknet.num.toHex(salt),
|
|
1166
|
+
STARKNET_MEDIAWALLET_CLASS_HASH,
|
|
1167
|
+
ownerConstructorCalldata(ownerPubkey),
|
|
1168
|
+
0
|
|
1169
|
+
);
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
// src/wallet/passkey.ts
|
|
1173
|
+
var PasskeyCancelledError = class extends Error {
|
|
1174
|
+
constructor(message = "Passkey prompt was cancelled.") {
|
|
1175
|
+
super(message);
|
|
1176
|
+
this.name = "PasskeyCancelledError";
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
var encodeBase64 = (buf) => {
|
|
1180
|
+
const bytes = buf instanceof Uint8Array ? buf : new Uint8Array(buf);
|
|
1181
|
+
let binary = "";
|
|
1182
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
1183
|
+
return btoa(binary);
|
|
1184
|
+
};
|
|
1185
|
+
var decodeBase64 = (value) => {
|
|
1186
|
+
const binary = atob(value);
|
|
1187
|
+
const bytes = new Uint8Array(binary.length);
|
|
1188
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
1189
|
+
return bytes;
|
|
1190
|
+
};
|
|
1191
|
+
function isPasskeyCancellation(err) {
|
|
1192
|
+
const name = err?.name;
|
|
1193
|
+
return name === "NotAllowedError" || name === "AbortError";
|
|
1194
|
+
}
|
|
1195
|
+
function createPasskeyOwner(config) {
|
|
1196
|
+
const randomBytes = config.randomBytes ?? ((length) => crypto.getRandomValues(new Uint8Array(length)));
|
|
1197
|
+
const credentialsApi = () => {
|
|
1198
|
+
const api = config.credentials ?? (typeof navigator === "undefined" ? void 0 : navigator.credentials);
|
|
1199
|
+
if (!api) throw new Error("Passkeys are only available in a browser.");
|
|
1200
|
+
return api;
|
|
1201
|
+
};
|
|
1202
|
+
const prfUnsupportedMessage = () => {
|
|
1203
|
+
const isBrave = typeof navigator !== "undefined" && "brave" in navigator;
|
|
1204
|
+
const cause = isBrave ? "Brave doesn't currently support the WebAuthn PRF extension." : "This browser didn't return a passkey PRF secret.";
|
|
1205
|
+
return `${cause} ${config.appName} needs it to seal your key. Your device passkey (Touch ID) is fine, the limitation is the browser. Please open this in Safari or Chrome on an up-to-date OS.`;
|
|
1206
|
+
};
|
|
1207
|
+
async function registerPasskey() {
|
|
1208
|
+
let credential;
|
|
1209
|
+
try {
|
|
1210
|
+
credential = await credentialsApi().create({
|
|
1211
|
+
publicKey: {
|
|
1212
|
+
challenge: randomBytes(32),
|
|
1213
|
+
rp: { name: config.relyingPartyName, id: config.relyingPartyId() },
|
|
1214
|
+
user: await config.passkeyUser(),
|
|
1215
|
+
excludeCredentials: config.knownCredentials(),
|
|
1216
|
+
pubKeyCredParams: [
|
|
1217
|
+
{ type: "public-key", alg: -7 },
|
|
1218
|
+
{ type: "public-key", alg: -257 }
|
|
1219
|
+
],
|
|
1220
|
+
authenticatorSelection: {
|
|
1221
|
+
residentKey: "required",
|
|
1222
|
+
userVerification: "required",
|
|
1223
|
+
authenticatorAttachment: "platform"
|
|
1224
|
+
},
|
|
1225
|
+
extensions: { prf: { eval: { first: config.prfSalt } } }
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
} catch (err) {
|
|
1229
|
+
if (isPasskeyCancellation(err)) throw new PasskeyCancelledError();
|
|
1230
|
+
throw err;
|
|
1231
|
+
}
|
|
1232
|
+
const prf = credential.getClientExtensionResults().prf;
|
|
1233
|
+
return { credentialId: encodeBase64(credential.rawId), prfFirst: prf?.results?.first ?? null };
|
|
1234
|
+
}
|
|
1235
|
+
async function prfSecret(credentialId) {
|
|
1236
|
+
let assertion;
|
|
1237
|
+
try {
|
|
1238
|
+
assertion = await credentialsApi().get({
|
|
1239
|
+
publicKey: {
|
|
1240
|
+
challenge: randomBytes(32),
|
|
1241
|
+
rpId: config.relyingPartyId(),
|
|
1242
|
+
allowCredentials: [{ type: "public-key", id: decodeBase64(credentialId) }],
|
|
1243
|
+
userVerification: "required",
|
|
1244
|
+
extensions: { prf: { eval: { first: config.prfSalt } } }
|
|
1245
|
+
}
|
|
1246
|
+
});
|
|
1247
|
+
} catch (err) {
|
|
1248
|
+
if (isPasskeyCancellation(err)) throw new PasskeyCancelledError();
|
|
1249
|
+
throw err;
|
|
1250
|
+
}
|
|
1251
|
+
const result = assertion.getClientExtensionResults().prf?.results?.first;
|
|
1252
|
+
if (!result) throw new Error("Passkey PRF unavailable on this device/browser.");
|
|
1253
|
+
return new Uint8Array(result);
|
|
1254
|
+
}
|
|
1255
|
+
async function secretFromRegistration(registration) {
|
|
1256
|
+
if (registration.prfFirst) return new Uint8Array(registration.prfFirst);
|
|
1257
|
+
try {
|
|
1258
|
+
return await prfSecret(registration.credentialId);
|
|
1259
|
+
} catch {
|
|
1260
|
+
throw new Error(prfUnsupportedMessage());
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
async function seal(secret, privateKeyHex) {
|
|
1264
|
+
const aes = await deriveAesKey(secret, config.hkdfInfo);
|
|
1265
|
+
const iv = randomBytes(12);
|
|
1266
|
+
const ciphertext = await sealPrivateKey(aes, iv, privateKeyHex);
|
|
1267
|
+
return { iv: encodeBase64(iv), ciphertext: encodeBase64(ciphertext) };
|
|
1268
|
+
}
|
|
1269
|
+
return {
|
|
1270
|
+
async createOwnerKey() {
|
|
1271
|
+
const registration = await registerPasskey();
|
|
1272
|
+
const secret = await secretFromRegistration(registration);
|
|
1273
|
+
const { privateKeyHex, publicKeyHex } = generateStarkKeyPair();
|
|
1274
|
+
const { iv, ciphertext } = await seal(secret, privateKeyHex);
|
|
1275
|
+
return {
|
|
1276
|
+
sealed: {
|
|
1277
|
+
credentialId: registration.credentialId,
|
|
1278
|
+
ownerPubKey: publicKeyHex,
|
|
1279
|
+
address: computeAccountAddress(publicKeyHex, 0),
|
|
1280
|
+
iv,
|
|
1281
|
+
ciphertext
|
|
1282
|
+
},
|
|
1283
|
+
privateKeyHex
|
|
1284
|
+
};
|
|
1285
|
+
},
|
|
1286
|
+
async unlockOwnerKey(sealed) {
|
|
1287
|
+
const secret = await prfSecret(sealed.credentialId);
|
|
1288
|
+
const aes = await deriveAesKey(secret, config.hkdfInfo);
|
|
1289
|
+
return unsealPrivateKey(aes, decodeBase64(sealed.iv), decodeBase64(sealed.ciphertext));
|
|
1290
|
+
},
|
|
1291
|
+
async sealImportedOwnerKey(recovery) {
|
|
1292
|
+
const { privateKeyHex, publicKeyHex } = starkKeyPairFromPrivateKey(recovery.privateKey);
|
|
1293
|
+
const registration = await registerPasskey();
|
|
1294
|
+
const secret = await secretFromRegistration(registration);
|
|
1295
|
+
const { iv, ciphertext } = await seal(secret, privateKeyHex);
|
|
1296
|
+
return {
|
|
1297
|
+
credentialId: registration.credentialId,
|
|
1298
|
+
ownerPubKey: publicKeyHex,
|
|
1299
|
+
address: recovery.walletAddress,
|
|
1300
|
+
iv,
|
|
1301
|
+
ciphertext
|
|
1302
|
+
};
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
// src/services/registry.ts
|
|
1308
|
+
var SN2 = chunkOUPVVMLK_cjs.getStarknetCoordinates("STARKNET");
|
|
1309
|
+
var SERVICES = {
|
|
1310
|
+
"mip-erc721": {
|
|
1311
|
+
id: "mip-erc721",
|
|
1312
|
+
displayName: "IP Collection",
|
|
1313
|
+
description: "Tokenize intellectual property as a per-creator ERC-721 collection.",
|
|
1314
|
+
standard: "ERC721",
|
|
1315
|
+
provenance: "MEDIALANE",
|
|
1316
|
+
onchain: {
|
|
1317
|
+
STARKNET: {
|
|
1318
|
+
factoryAddress: SN2.collection721,
|
|
1319
|
+
startBlock: SN2.collection721StartBlock
|
|
1320
|
+
}
|
|
1321
|
+
},
|
|
1322
|
+
uiVariant: "standard",
|
|
1323
|
+
capabilities: ["list", "buy", "make_offer", "cancel", "transfer", "mint", "remix", "license"],
|
|
1324
|
+
events: [
|
|
1325
|
+
{ name: "CollectionCreated", emittedBy: "factory" }
|
|
1326
|
+
],
|
|
1327
|
+
metadataSchema: { licenseDefault: "CC BY-SA" }
|
|
1328
|
+
},
|
|
1329
|
+
"ip-erc721": {
|
|
1330
|
+
id: "ip-erc721",
|
|
1331
|
+
displayName: "Programmable IP",
|
|
1332
|
+
description: "One shared ERC-721 contract any wallet can mint into.",
|
|
1333
|
+
standard: "ERC721",
|
|
1334
|
+
provenance: "MEDIALANE",
|
|
1335
|
+
uiVariant: "standard",
|
|
1336
|
+
capabilities: ["list", "buy", "make_offer", "cancel", "transfer", "mint", "remix", "license"],
|
|
1337
|
+
metadataSchema: { licenseDefault: "CC BY-SA" }
|
|
1338
|
+
},
|
|
1339
|
+
"data-tokenization-erc721": {
|
|
1340
|
+
id: "data-tokenization-erc721",
|
|
1341
|
+
displayName: "Data Tokenization",
|
|
1342
|
+
description: "Establish verifiable ownership of your data, with licensing terms that hold up wherever it travels.",
|
|
1343
|
+
standard: "ERC721",
|
|
1344
|
+
provenance: "MEDIALANE",
|
|
1345
|
+
onchain: {
|
|
1346
|
+
STARKNET: {
|
|
1347
|
+
factoryAddress: SN2.dataTokenization721,
|
|
1348
|
+
startBlock: SN2.dataTokenization721StartBlock
|
|
1349
|
+
}
|
|
1350
|
+
},
|
|
1351
|
+
uiVariant: "standard",
|
|
1352
|
+
capabilities: ["list", "buy", "make_offer", "cancel", "transfer", "mint", "remix", "license"],
|
|
1353
|
+
events: [
|
|
1354
|
+
{ name: "CollectionCreated", emittedBy: "factory" }
|
|
1355
|
+
],
|
|
1356
|
+
metadataSchema: { licenseDefault: "CC BY-SA" }
|
|
1357
|
+
},
|
|
1358
|
+
"mip-erc1155": {
|
|
1359
|
+
id: "mip-erc1155",
|
|
1360
|
+
displayName: "NFT Editions",
|
|
1361
|
+
description: "Per-creator ERC-1155 collection; creator mints editions.",
|
|
1362
|
+
standard: "ERC1155",
|
|
1363
|
+
provenance: "MEDIALANE",
|
|
1364
|
+
onchain: {
|
|
1365
|
+
STARKNET: {
|
|
1366
|
+
factoryAddress: SN2.collection1155,
|
|
1367
|
+
classHash: SN2.collection1155ClassHash,
|
|
1368
|
+
startBlock: SN2.collection1155StartBlock
|
|
1369
|
+
}
|
|
1370
|
+
},
|
|
1371
|
+
uiVariant: "edition",
|
|
1372
|
+
capabilities: ["list", "buy", "make_offer", "cancel", "transfer", "mint", "remix", "license"],
|
|
1373
|
+
events: [
|
|
1374
|
+
{ name: "CollectionDeployed", emittedBy: "factory" }
|
|
1375
|
+
],
|
|
1376
|
+
metadataSchema: { licenseDefault: "CC BY-SA" }
|
|
1377
|
+
},
|
|
1378
|
+
"pop-protocol": {
|
|
1379
|
+
id: "pop-protocol",
|
|
1380
|
+
displayName: "POP Protocol",
|
|
1381
|
+
description: "Soulbound proof-of-presence collectibles per event.",
|
|
1382
|
+
standard: "ERC721",
|
|
1383
|
+
provenance: "MEDIALANE",
|
|
1384
|
+
onchain: {
|
|
1385
|
+
STARKNET: {
|
|
1386
|
+
factoryAddress: SN2.popFactory,
|
|
1387
|
+
classHash: SN2.popCollectionClassHash
|
|
1388
|
+
}
|
|
1389
|
+
},
|
|
1390
|
+
uiVariant: "pop",
|
|
1391
|
+
capabilities: ["claim", "mint"],
|
|
1392
|
+
events: [
|
|
1393
|
+
{ name: "CollectionCreated", emittedBy: "factory" },
|
|
1394
|
+
{ name: "AllowlistUpdated", emittedBy: "instance", poll: "slow" }
|
|
1395
|
+
],
|
|
1396
|
+
metadataSchema: { licenseDefault: "CC BY-SA" }
|
|
1397
|
+
},
|
|
1398
|
+
"certificate-emission": {
|
|
1399
|
+
id: "certificate-emission",
|
|
1400
|
+
displayName: "Certificate Emission",
|
|
1401
|
+
description: "Issue a soulbound credential to a list of recipients in one run \u2014 everyone gets a wallet and their certificate.",
|
|
1402
|
+
standard: "ERC721",
|
|
1403
|
+
provenance: "MEDIALANE",
|
|
1404
|
+
onchain: {
|
|
1405
|
+
STARKNET: {
|
|
1406
|
+
factoryAddress: SN2.popFactory,
|
|
1407
|
+
classHash: SN2.popCollectionClassHash
|
|
1408
|
+
}
|
|
1409
|
+
},
|
|
1410
|
+
uiVariant: "pop",
|
|
1411
|
+
capabilities: ["mint", "airdrop"],
|
|
1412
|
+
events: [
|
|
1413
|
+
{ name: "CollectionCreated", emittedBy: "factory" }
|
|
1414
|
+
],
|
|
1415
|
+
metadataSchema: { licenseDefault: "CC BY-SA" }
|
|
1416
|
+
},
|
|
1417
|
+
"drop-collection": {
|
|
1418
|
+
id: "drop-collection",
|
|
1419
|
+
displayName: "Collection Drop",
|
|
1420
|
+
description: "Sequential mint with claim windows + allowlist.",
|
|
1421
|
+
standard: "ERC721",
|
|
1422
|
+
provenance: "MEDIALANE",
|
|
1423
|
+
onchain: {
|
|
1424
|
+
STARKNET: {
|
|
1425
|
+
factoryAddress: SN2.dropFactory,
|
|
1426
|
+
classHash: SN2.dropCollectionClassHash
|
|
1427
|
+
}
|
|
1428
|
+
},
|
|
1429
|
+
uiVariant: "drop",
|
|
1430
|
+
capabilities: ["claim", "list", "buy", "make_offer", "cancel", "transfer"],
|
|
1431
|
+
events: [
|
|
1432
|
+
{ name: "DropCreated", emittedBy: "factory" },
|
|
1433
|
+
{ name: "AllowlistUpdated", emittedBy: "instance", poll: "slow" }
|
|
1434
|
+
],
|
|
1435
|
+
metadataSchema: { licenseDefault: "CC BY-SA" }
|
|
1436
|
+
},
|
|
1437
|
+
"ip-tickets": {
|
|
1438
|
+
id: "ip-tickets",
|
|
1439
|
+
displayName: "IP Tickets",
|
|
1440
|
+
description: "Create verifiable on-chain tickets \u2014 mint to attendees, trade like any collection.",
|
|
1441
|
+
standard: "ERC1155",
|
|
1442
|
+
provenance: "MEDIALANE",
|
|
1443
|
+
onchain: {
|
|
1444
|
+
STARKNET: {
|
|
1445
|
+
factoryAddress: SN2.ipTicketsFactory,
|
|
1446
|
+
classHash: SN2.ipTicketCollectionClassHash
|
|
1447
|
+
}
|
|
1448
|
+
},
|
|
1449
|
+
uiVariant: "ticket",
|
|
1450
|
+
capabilities: ["mint", "redeem", "list", "buy", "make_offer", "cancel", "transfer"],
|
|
1451
|
+
events: [
|
|
1452
|
+
{ name: "CollectionDeployed", emittedBy: "factory" },
|
|
1453
|
+
{ name: "TicketCreated", emittedBy: "instance" }
|
|
1454
|
+
],
|
|
1455
|
+
metadataSchema: { licenseDefault: "CC BY-SA" }
|
|
1456
|
+
},
|
|
1457
|
+
"ip-ticketing": {
|
|
1458
|
+
id: "ip-ticketing",
|
|
1459
|
+
displayName: "IP Ticketing",
|
|
1460
|
+
description: "Distribute verifiable on-chain tickets to a list of recipients in one run \u2014 everyone gets a wallet and their ticket.",
|
|
1461
|
+
standard: "ERC1155",
|
|
1462
|
+
provenance: "MEDIALANE",
|
|
1463
|
+
onchain: {
|
|
1464
|
+
STARKNET: {
|
|
1465
|
+
factoryAddress: SN2.ipTicketsFactory,
|
|
1466
|
+
classHash: SN2.ipTicketCollectionClassHash
|
|
1467
|
+
}
|
|
1468
|
+
},
|
|
1469
|
+
uiVariant: "ticket",
|
|
1470
|
+
capabilities: ["mint", "airdrop", "redeem", "list", "buy", "make_offer", "cancel", "transfer"],
|
|
1471
|
+
events: [
|
|
1472
|
+
{ name: "CollectionDeployed", emittedBy: "factory" },
|
|
1473
|
+
{ name: "TicketCreated", emittedBy: "instance" }
|
|
1474
|
+
],
|
|
1475
|
+
metadataSchema: { licenseDefault: "CC BY-SA" }
|
|
1476
|
+
},
|
|
1477
|
+
"ip-club": {
|
|
1478
|
+
id: "ip-club",
|
|
1479
|
+
displayName: "IP Club",
|
|
1480
|
+
description: "Membership clubs \u2014 create tiers, mint membership cards, trade like any collection.",
|
|
1481
|
+
standard: "ERC1155",
|
|
1482
|
+
provenance: "MEDIALANE",
|
|
1483
|
+
onchain: {
|
|
1484
|
+
STARKNET: {
|
|
1485
|
+
factoryAddress: SN2.ipClubFactory,
|
|
1486
|
+
classHash: SN2.ipClubCollectionClassHash
|
|
1487
|
+
}
|
|
1488
|
+
},
|
|
1489
|
+
uiVariant: "club",
|
|
1490
|
+
capabilities: ["mint", "list", "buy", "make_offer", "cancel", "transfer"],
|
|
1491
|
+
events: [
|
|
1492
|
+
{ name: "ClubDeployed", emittedBy: "factory" },
|
|
1493
|
+
{ name: "MembershipCreated", emittedBy: "instance" }
|
|
1494
|
+
],
|
|
1495
|
+
metadataSchema: { licenseDefault: "CC BY-SA" }
|
|
1496
|
+
},
|
|
1497
|
+
"ip-sponsorship": {
|
|
1498
|
+
id: "ip-sponsorship",
|
|
1499
|
+
displayName: "IP Sponsorship",
|
|
1500
|
+
description: "Sponsorship offers and licenses anchored to an existing Medialane asset.",
|
|
1501
|
+
standard: "ERC721",
|
|
1502
|
+
provenance: "MEDIALANE",
|
|
1503
|
+
onchain: {
|
|
1504
|
+
STARKNET: {
|
|
1505
|
+
factoryAddress: SN2.ipSponsorship,
|
|
1506
|
+
classHash: SN2.ipSponsorshipClassHash,
|
|
1507
|
+
startBlock: SN2.ipSponsorshipStartBlock
|
|
1508
|
+
}
|
|
1509
|
+
},
|
|
1510
|
+
uiVariant: "standard",
|
|
1511
|
+
capabilities: ["sponsor", "transfer"],
|
|
1512
|
+
events: [
|
|
1513
|
+
{ name: "OfferCreated", emittedBy: "factory" },
|
|
1514
|
+
{ name: "ProposalCreated", emittedBy: "factory" },
|
|
1515
|
+
{ name: "LicenseMinted", emittedBy: "factory" }
|
|
1516
|
+
],
|
|
1517
|
+
metadataSchema: { licenseDefault: "CC BY-SA" }
|
|
1518
|
+
},
|
|
1519
|
+
"creator-coin": {
|
|
1520
|
+
id: "creator-coin",
|
|
1521
|
+
displayName: "Creator Coin",
|
|
1522
|
+
description: "Launch a fixed-supply social token with permanently-locked Ekubo liquidity.",
|
|
1523
|
+
standard: "ERC20",
|
|
1524
|
+
provenance: "MEDIALANE",
|
|
1525
|
+
onchain: {
|
|
1526
|
+
STARKNET: {
|
|
1527
|
+
factoryAddress: SN2.creatorCoinFactory,
|
|
1528
|
+
classHash: SN2.creatorCoinFactoryClassHash,
|
|
1529
|
+
startBlock: SN2.creatorCoinStartBlock
|
|
1530
|
+
}
|
|
1531
|
+
},
|
|
1532
|
+
uiVariant: "coin",
|
|
1533
|
+
capabilities: ["launch", "swap", "transfer"],
|
|
1534
|
+
events: [
|
|
1535
|
+
{ name: "CreatorCoinCreated", emittedBy: "factory" },
|
|
1536
|
+
{ name: "CreatorCoinLaunched", emittedBy: "factory" }
|
|
1537
|
+
]
|
|
1538
|
+
},
|
|
1539
|
+
"medialane-marketplace-erc721": {
|
|
1540
|
+
id: "medialane-marketplace-erc721",
|
|
1541
|
+
displayName: "Medialane Marketplace (ERC-721)",
|
|
1542
|
+
description: "ERC-721 order matching venue.",
|
|
1543
|
+
standard: "ERC721",
|
|
1544
|
+
provenance: "MEDIALANE",
|
|
1545
|
+
onchain: {
|
|
1546
|
+
STARKNET: {
|
|
1547
|
+
factoryAddress: SN2.marketplace721,
|
|
1548
|
+
classHash: SN2.marketplace721ClassHash,
|
|
1549
|
+
startBlock: SN2.marketplace721StartBlock
|
|
1550
|
+
}
|
|
1551
|
+
},
|
|
1552
|
+
uiVariant: "standard",
|
|
1553
|
+
capabilities: ["list", "buy", "make_offer", "cancel"],
|
|
1554
|
+
events: [
|
|
1555
|
+
{ name: "OrderCreated", emittedBy: "factory" },
|
|
1556
|
+
{ name: "OrderFulfilled", emittedBy: "factory" },
|
|
1557
|
+
{ name: "OrderCancelled", emittedBy: "factory" }
|
|
1558
|
+
]
|
|
1559
|
+
},
|
|
1560
|
+
"medialane-marketplace-erc1155": {
|
|
1561
|
+
id: "medialane-marketplace-erc1155",
|
|
1562
|
+
displayName: "Medialane Marketplace (ERC-1155)",
|
|
1563
|
+
description: "ERC-1155 order matching venue.",
|
|
1564
|
+
standard: "ERC1155",
|
|
1565
|
+
provenance: "MEDIALANE",
|
|
1566
|
+
onchain: {
|
|
1567
|
+
STARKNET: {
|
|
1568
|
+
factoryAddress: SN2.marketplace1155,
|
|
1569
|
+
classHash: SN2.marketplace1155ClassHash,
|
|
1570
|
+
startBlock: SN2.marketplace1155StartBlock
|
|
1571
|
+
}
|
|
1572
|
+
},
|
|
1573
|
+
uiVariant: "edition",
|
|
1574
|
+
capabilities: ["list", "buy", "make_offer", "cancel"],
|
|
1575
|
+
events: [
|
|
1576
|
+
{ name: "OrderCreated", emittedBy: "factory" },
|
|
1577
|
+
{ name: "OrderFulfilled", emittedBy: "factory" },
|
|
1578
|
+
{ name: "OrderCancelled", emittedBy: "factory" }
|
|
1579
|
+
]
|
|
1580
|
+
},
|
|
1581
|
+
"unruggable-erc20": {
|
|
1582
|
+
id: "unruggable-erc20",
|
|
1583
|
+
displayName: "Unruggable",
|
|
1584
|
+
description: "An ERC-20 launched through the unruggable.meme protocol, the same contract Medialane's Creator Coin is forked from. Not deployed via a Medialane service, but exposes the same on-chain guarantees: capped team allocation, permanently locked liquidity, fixed supply. Brought in by owner claim or admin/partnership \u2014 never bulk-indexed.",
|
|
1585
|
+
standard: "ERC20",
|
|
1586
|
+
provenance: "EXTERNAL",
|
|
1587
|
+
uiVariant: "coin",
|
|
1588
|
+
capabilities: ["swap", "transfer"]
|
|
1589
|
+
},
|
|
1590
|
+
"external-erc20": {
|
|
1591
|
+
id: "external-erc20",
|
|
1592
|
+
displayName: "Memecoin",
|
|
1593
|
+
description: "A plain ERC-20 not deployed via a Medialane service and carrying no protocol-level guarantees. Brought in by owner claim or admin/partnership \u2014 never bulk-indexed. Generalizes to future chains.",
|
|
1594
|
+
standard: "ERC20",
|
|
1595
|
+
provenance: "EXTERNAL",
|
|
1596
|
+
uiVariant: "coin",
|
|
1597
|
+
capabilities: ["swap", "transfer"]
|
|
1598
|
+
},
|
|
1599
|
+
"external-erc721": {
|
|
1600
|
+
id: "external-erc721",
|
|
1601
|
+
displayName: "External ERC-721",
|
|
1602
|
+
description: "ERC-721 contract not deployed via a Medialane service.",
|
|
1603
|
+
standard: "ERC721",
|
|
1604
|
+
provenance: "EXTERNAL",
|
|
1605
|
+
uiVariant: "standard",
|
|
1606
|
+
capabilities: ["list", "buy", "make_offer", "cancel", "transfer"]
|
|
1607
|
+
},
|
|
1608
|
+
"external-erc1155": {
|
|
1609
|
+
id: "external-erc1155",
|
|
1610
|
+
displayName: "External ERC-1155",
|
|
1611
|
+
description: "ERC-1155 contract not deployed via a Medialane service.",
|
|
1612
|
+
standard: "ERC1155",
|
|
1613
|
+
provenance: "EXTERNAL",
|
|
1614
|
+
uiVariant: "edition",
|
|
1615
|
+
capabilities: ["list", "buy", "make_offer", "cancel", "transfer"]
|
|
1616
|
+
}
|
|
1617
|
+
};
|
|
1618
|
+
function isServiceId(id) {
|
|
1619
|
+
return typeof id === "string" && id in SERVICES;
|
|
1620
|
+
}
|
|
1621
|
+
function getService(id) {
|
|
1622
|
+
return id && id in SERVICES ? SERVICES[id] : void 0;
|
|
1623
|
+
}
|
|
1624
|
+
function listServices() {
|
|
1625
|
+
return Object.values(SERVICES);
|
|
1626
|
+
}
|
|
1627
|
+
function getServicesByCapability(cap) {
|
|
1628
|
+
return Object.values(SERVICES).filter(
|
|
1629
|
+
(s) => s.capabilities.includes(cap)
|
|
1630
|
+
);
|
|
1631
|
+
}
|
|
1632
|
+
function hasCapability(id, cap) {
|
|
1633
|
+
return getService(id)?.capabilities.includes(cap) ?? false;
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
// src/utils/token.ts
|
|
1637
|
+
function parseAmount(human, decimals) {
|
|
1638
|
+
const [whole, frac = ""] = human.split(".");
|
|
1639
|
+
const fracPadded = frac.padEnd(decimals, "0").slice(0, decimals);
|
|
1640
|
+
return (BigInt(whole) * BigInt(10) ** BigInt(decimals) + BigInt(fracPadded)).toString();
|
|
1641
|
+
}
|
|
1642
|
+
function formatAmount(raw, decimals) {
|
|
1643
|
+
const value = BigInt(raw);
|
|
1644
|
+
const factor = 10n ** BigInt(decimals);
|
|
1645
|
+
const whole = value / factor;
|
|
1646
|
+
const remainder = value % factor;
|
|
1647
|
+
const fractional = remainder.toString().padStart(decimals, "0").replace(/0+$/, "");
|
|
1648
|
+
return fractional ? `${whole}.${fractional}` : whole.toString();
|
|
1649
|
+
}
|
|
1650
|
+
function getTokenByAddress(address) {
|
|
1651
|
+
if (typeof address !== "string" || address.trim() === "") return void 0;
|
|
1652
|
+
let target = null;
|
|
1653
|
+
try {
|
|
1654
|
+
target = BigInt(address);
|
|
1655
|
+
} catch {
|
|
1656
|
+
target = null;
|
|
1657
|
+
}
|
|
1658
|
+
return SUPPORTED_TOKENS.find((t) => {
|
|
1659
|
+
if (target !== null) {
|
|
1660
|
+
try {
|
|
1661
|
+
return BigInt(t.address) === target;
|
|
1662
|
+
} catch {
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
return t.address.toLowerCase() === address.toLowerCase();
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
function getTokenBySymbol(symbol) {
|
|
1669
|
+
if (typeof symbol !== "string") return void 0;
|
|
1670
|
+
const upper = symbol.toUpperCase();
|
|
1671
|
+
return SUPPORTED_TOKENS.find((t) => t.symbol === upper);
|
|
1672
|
+
}
|
|
1673
|
+
function getListableTokens() {
|
|
1674
|
+
return SUPPORTED_TOKENS.filter((t) => t.listable);
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
// src/utils/bigint.ts
|
|
1678
|
+
function stringifyBigInts(obj) {
|
|
1679
|
+
if (typeof obj === "bigint") {
|
|
1680
|
+
return obj.toString();
|
|
1681
|
+
}
|
|
1682
|
+
if (Array.isArray(obj)) {
|
|
1683
|
+
return obj.map(stringifyBigInts);
|
|
1684
|
+
}
|
|
1685
|
+
if (obj !== null && typeof obj === "object") {
|
|
1686
|
+
return Object.fromEntries(
|
|
1687
|
+
Object.entries(obj).map(([key, value]) => [
|
|
1688
|
+
key,
|
|
1689
|
+
stringifyBigInts(value)
|
|
1690
|
+
])
|
|
1691
|
+
);
|
|
1692
|
+
}
|
|
1693
|
+
return obj;
|
|
1694
|
+
}
|
|
1695
|
+
function u256ToBigInt(low, high) {
|
|
1696
|
+
return BigInt(low) + (BigInt(high) << 128n);
|
|
1697
|
+
}
|
|
1698
|
+
function encodeU256(n) {
|
|
1699
|
+
return [
|
|
1700
|
+
(n & 0xffffffffffffffffffffffffffffffffn).toString(),
|
|
1701
|
+
(n >> 128n).toString()
|
|
1702
|
+
];
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
// src/utils/rpc.ts
|
|
1706
|
+
var TRANSIENT_BODY_RE = /"code"\s*:\s*-32001|"code"\s*:\s*-32603|unable to complete|rate.?limit|too many|throttl|exceed.*quota|temporarily unavailable|service unavailable|overload|gateway.*time|upstream.*time|backend.*error/i;
|
|
1707
|
+
var POLICY_REFUSAL_CODES = [-32003, -32005, -32600];
|
|
1708
|
+
function isPolicyRefusal(input) {
|
|
1709
|
+
let body = input.body;
|
|
1710
|
+
if (typeof body === "string") {
|
|
1711
|
+
try {
|
|
1712
|
+
body = JSON.parse(body);
|
|
1713
|
+
} catch {
|
|
1714
|
+
return false;
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
const err = body?.error;
|
|
1718
|
+
const code = err && typeof err === "object" ? err.code : void 0;
|
|
1719
|
+
return typeof code === "number" && POLICY_REFUSAL_CODES.includes(code);
|
|
1720
|
+
}
|
|
1721
|
+
function isTransientRpcError(input) {
|
|
1722
|
+
const { status, body } = input;
|
|
1723
|
+
if (isPolicyRefusal({ body })) return false;
|
|
1724
|
+
if (typeof status === "number" && (status === 429 || status >= 500)) return true;
|
|
1725
|
+
if (body == null) return false;
|
|
1726
|
+
if (typeof body === "object") {
|
|
1727
|
+
const err = body.error;
|
|
1728
|
+
if (!err || typeof err !== "object") return false;
|
|
1729
|
+
const code = err.code;
|
|
1730
|
+
if (typeof code === "number") {
|
|
1731
|
+
if (code === 429) return true;
|
|
1732
|
+
if (code >= -32099 && code <= -32e3) return true;
|
|
1733
|
+
if (code === -32603) return true;
|
|
1734
|
+
}
|
|
1735
|
+
const message = err.message;
|
|
1736
|
+
return typeof message === "string" ? TRANSIENT_BODY_RE.test(message) : false;
|
|
1737
|
+
}
|
|
1738
|
+
return TRANSIENT_BODY_RE.test(String(body));
|
|
1739
|
+
}
|
|
1740
|
+
function createFailoverFetch(urls, options = {}) {
|
|
1741
|
+
const endpoints = urls.filter((u) => Boolean(u));
|
|
1742
|
+
if (endpoints.length === 0) {
|
|
1743
|
+
throw new Error("createFailoverFetch: at least one RPC URL is required");
|
|
1744
|
+
}
|
|
1745
|
+
const doFetch = options.baseFetch ?? fetch;
|
|
1746
|
+
const failover = async (_input, init) => {
|
|
1747
|
+
let lastError;
|
|
1748
|
+
for (let i = 0; i < endpoints.length; i++) {
|
|
1749
|
+
const url = endpoints[i];
|
|
1750
|
+
const isLast = i === endpoints.length - 1;
|
|
1751
|
+
try {
|
|
1752
|
+
const res = await doFetch(url, init);
|
|
1753
|
+
const text = await res.text();
|
|
1754
|
+
const rebuilt = () => new Response(text, { status: res.status, statusText: res.statusText, headers: res.headers });
|
|
1755
|
+
if (isLast || !isTransientRpcError({ status: res.status, body: text })) {
|
|
1756
|
+
return rebuilt();
|
|
1757
|
+
}
|
|
1758
|
+
options.onFailover?.({ url, status: res.status });
|
|
1759
|
+
} catch (err) {
|
|
1760
|
+
lastError = err;
|
|
1761
|
+
if (isLast) throw err;
|
|
1762
|
+
options.onFailover?.({ url, error: err });
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
throw lastError ?? new Error("createFailoverFetch: all endpoints failed");
|
|
1766
|
+
};
|
|
1767
|
+
return failover;
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
// src/errors.ts
|
|
1771
|
+
var UserFacingError = class extends Error {
|
|
1772
|
+
constructor(message) {
|
|
1773
|
+
super(message);
|
|
1774
|
+
this.name = "UserFacingError";
|
|
1775
|
+
}
|
|
1776
|
+
};
|
|
1777
|
+
|
|
1778
|
+
exports.ApiClient = ApiClient;
|
|
1779
|
+
exports.DEFAULT_CURRENCY = DEFAULT_CURRENCY;
|
|
1780
|
+
exports.FeeConfigSchema = FeeConfigSchema;
|
|
1781
|
+
exports.InvalidStarkPrivateKeyError = InvalidStarkPrivateKeyError;
|
|
1782
|
+
exports.MedialaneApiError = MedialaneApiError;
|
|
1783
|
+
exports.POLICY_REFUSAL_CODES = POLICY_REFUSAL_CODES;
|
|
1784
|
+
exports.PasskeyCancelledError = PasskeyCancelledError;
|
|
1785
|
+
exports.STARKNET_COLLECTION_1155_CLASS_HASH = STARKNET_COLLECTION_1155_CLASS_HASH;
|
|
1786
|
+
exports.STARKNET_COLLECTION_1155_CONTRACT = STARKNET_COLLECTION_1155_CONTRACT;
|
|
1787
|
+
exports.STARKNET_COLLECTION_1155_FACTORY_CLASS_HASH = STARKNET_COLLECTION_1155_FACTORY_CLASS_HASH;
|
|
1788
|
+
exports.STARKNET_COLLECTION_1155_START_BLOCK = STARKNET_COLLECTION_1155_START_BLOCK;
|
|
1789
|
+
exports.STARKNET_COLLECTION_721_CONTRACT = STARKNET_COLLECTION_721_CONTRACT;
|
|
1790
|
+
exports.STARKNET_COLLECTION_721_START_BLOCK = STARKNET_COLLECTION_721_START_BLOCK;
|
|
1791
|
+
exports.STARKNET_CREATOR_COIN_CLASS_HASH = STARKNET_CREATOR_COIN_CLASS_HASH;
|
|
1792
|
+
exports.STARKNET_CREATOR_COIN_EKUBO_LAUNCHER = STARKNET_CREATOR_COIN_EKUBO_LAUNCHER;
|
|
1793
|
+
exports.STARKNET_CREATOR_COIN_FACTORY_CLASS_HASH = STARKNET_CREATOR_COIN_FACTORY_CLASS_HASH;
|
|
1794
|
+
exports.STARKNET_CREATOR_COIN_FACTORY_CONTRACT = STARKNET_CREATOR_COIN_FACTORY_CONTRACT;
|
|
1795
|
+
exports.STARKNET_CREATOR_COIN_START_BLOCK = STARKNET_CREATOR_COIN_START_BLOCK;
|
|
1796
|
+
exports.STARKNET_DATA_TOKENIZATION_721_CONTRACT = STARKNET_DATA_TOKENIZATION_721_CONTRACT;
|
|
1797
|
+
exports.STARKNET_DROP_COLLECTION_CLASS_HASH = STARKNET_DROP_COLLECTION_CLASS_HASH;
|
|
1798
|
+
exports.STARKNET_DROP_FACTORY_CONTRACT = STARKNET_DROP_FACTORY_CONTRACT;
|
|
1799
|
+
exports.STARKNET_EKUBO_CORE = STARKNET_EKUBO_CORE;
|
|
1800
|
+
exports.STARKNET_GENESIS_MINT_CONTRACT = STARKNET_GENESIS_MINT_CONTRACT;
|
|
1801
|
+
exports.STARKNET_GENESIS_NFT_URI = STARKNET_GENESIS_NFT_URI;
|
|
1802
|
+
exports.STARKNET_IPCOLLECTION_CLASS_HASH = STARKNET_IPCOLLECTION_CLASS_HASH;
|
|
1803
|
+
exports.STARKNET_IPNFT_CLASS_HASH = STARKNET_IPNFT_CLASS_HASH;
|
|
1804
|
+
exports.STARKNET_IP_CLUB_COLLECTION_CLASS_HASH = STARKNET_IP_CLUB_COLLECTION_CLASS_HASH;
|
|
1805
|
+
exports.STARKNET_IP_CLUB_FACTORY_CONTRACT = STARKNET_IP_CLUB_FACTORY_CONTRACT;
|
|
1806
|
+
exports.STARKNET_IP_SPONSORSHIP_CLASS_HASH = STARKNET_IP_SPONSORSHIP_CLASS_HASH;
|
|
1807
|
+
exports.STARKNET_IP_SPONSORSHIP_CONTRACT = STARKNET_IP_SPONSORSHIP_CONTRACT;
|
|
1808
|
+
exports.STARKNET_IP_TICKETS_FACTORY_CONTRACT = STARKNET_IP_TICKETS_FACTORY_CONTRACT;
|
|
1809
|
+
exports.STARKNET_IP_TICKET_COLLECTION_CLASS_HASH = STARKNET_IP_TICKET_COLLECTION_CLASS_HASH;
|
|
1810
|
+
exports.STARKNET_MARKETPLACE_1155_CLASS_HASH = STARKNET_MARKETPLACE_1155_CLASS_HASH;
|
|
1811
|
+
exports.STARKNET_MARKETPLACE_1155_CONTRACT = STARKNET_MARKETPLACE_1155_CONTRACT;
|
|
1812
|
+
exports.STARKNET_MARKETPLACE_1155_START_BLOCK = STARKNET_MARKETPLACE_1155_START_BLOCK;
|
|
1813
|
+
exports.STARKNET_MARKETPLACE_721_CLASS_HASH = STARKNET_MARKETPLACE_721_CLASS_HASH;
|
|
1814
|
+
exports.STARKNET_MARKETPLACE_721_CONTRACT = STARKNET_MARKETPLACE_721_CONTRACT;
|
|
1815
|
+
exports.STARKNET_MARKETPLACE_721_START_BLOCK = STARKNET_MARKETPLACE_721_START_BLOCK;
|
|
1816
|
+
exports.STARKNET_MEDIAWALLET_CLASS_HASH = STARKNET_MEDIAWALLET_CLASS_HASH;
|
|
1817
|
+
exports.STARKNET_NFTCOMMENTS_CONTRACT = STARKNET_NFTCOMMENTS_CONTRACT;
|
|
1818
|
+
exports.STARKNET_POP_COLLECTION_CLASS_HASH = STARKNET_POP_COLLECTION_CLASS_HASH;
|
|
1819
|
+
exports.STARKNET_POP_FACTORY_CONTRACT = STARKNET_POP_FACTORY_CONTRACT;
|
|
1820
|
+
exports.SUPPORTED_TOKENS = SUPPORTED_TOKENS;
|
|
1821
|
+
exports.UserFacingError = UserFacingError;
|
|
1822
|
+
exports.computeAccountAddress = computeAccountAddress;
|
|
1823
|
+
exports.createFailoverFetch = createFailoverFetch;
|
|
1824
|
+
exports.createPasskeyOwner = createPasskeyOwner;
|
|
1825
|
+
exports.deriveAesKey = deriveAesKey;
|
|
1826
|
+
exports.encodeU256 = encodeU256;
|
|
1827
|
+
exports.formatAmount = formatAmount;
|
|
1828
|
+
exports.generateStarkKeyPair = generateStarkKeyPair;
|
|
1829
|
+
exports.getListableTokens = getListableTokens;
|
|
1830
|
+
exports.getService = getService;
|
|
1831
|
+
exports.getServicesByCapability = getServicesByCapability;
|
|
1832
|
+
exports.getTokenByAddress = getTokenByAddress;
|
|
1833
|
+
exports.getTokenBySymbol = getTokenBySymbol;
|
|
1834
|
+
exports.hasCapability = hasCapability;
|
|
1835
|
+
exports.isPolicyRefusal = isPolicyRefusal;
|
|
1836
|
+
exports.isServiceId = isServiceId;
|
|
1837
|
+
exports.isTransientRpcError = isTransientRpcError;
|
|
1838
|
+
exports.listServices = listServices;
|
|
1839
|
+
exports.normalizeAddress = normalizeAddress;
|
|
1840
|
+
exports.normalizeHash = normalizeHash;
|
|
1841
|
+
exports.ownerConstructorCalldata = ownerConstructorCalldata;
|
|
1842
|
+
exports.parseAmount = parseAmount;
|
|
1843
|
+
exports.resolveAppFeeConfig = resolveAppFeeConfig;
|
|
1844
|
+
exports.resolveConfig = resolveConfig;
|
|
1845
|
+
exports.resolveFeeConfig = resolveFeeConfig;
|
|
1846
|
+
exports.sealPrivateKey = sealPrivateKey;
|
|
1847
|
+
exports.shortenAddress = shortenAddress;
|
|
1848
|
+
exports.signWithPrivateKey = signWithPrivateKey;
|
|
1849
|
+
exports.starkKeyPairFromPrivateKey = starkKeyPairFromPrivateKey;
|
|
1850
|
+
exports.stringifyBigInts = stringifyBigInts;
|
|
1851
|
+
exports.u256ToBigInt = u256ToBigInt;
|
|
1852
|
+
exports.unsealPrivateKey = unsealPrivateKey;
|
|
1853
|
+
//# sourceMappingURL=chunk-ZFRHADHR.cjs.map
|
|
1854
|
+
//# sourceMappingURL=chunk-ZFRHADHR.cjs.map
|