@medialane/sdk 0.42.1 → 0.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -12,20 +12,20 @@ var CHAINS = ["STARKNET", "ETHEREUM", "SOLANA", "BASE", "BITCOIN"];
12
12
  var COORDINATES = {
13
13
  STARKNET: {
14
14
  rpcUrl: "https://rpc.starknet.lava.build",
15
- marketplace721: "0x069cf5391077e3ebdd9cb6aebf90ed530d29f0d6aa34a43f5afae938c0fb565e",
16
- marketplace721ClassHash: "0x04c6f952d747ad7ead1b3dad4c1d587837d38f8ec29d6c095a4afa5b5ece5957",
17
- marketplace721StartBlock: 10350340,
18
- marketplace1155: "0x040cd7b3e73bb3c892166e34bdc01d1797f97ecbc356c23f1cf38033cacf0077",
19
- marketplace1155ClassHash: "0x02600bb720908f119afe482309d36c39d087587f0df9576454acfb6363e78cd8",
20
- marketplace1155StartBlock: 10350855,
21
- collection721: "0x0558c9b6ea4d403df6d765fb77be55702c572f0a811f037c6c4209fe1e5aeef2",
22
- collection721StartBlock: 11002817,
23
- ipNftClassHash: "0x040551f0d009a6d665ddff980a375dfccc71a8928c8bfcc9ab56244bc4464fab",
24
- ipCollectionClassHash: "0x063d4ac4ae317fd155216bf1b8a4d3a63172ff72965b9ac48dd5add0c2d32b70",
25
- collection1155: "0x0083543c3ee15040a419fc539fa6889f5b956e7d071bcfa97842cb0ae42ad6cc",
26
- collection1155FactoryClassHash: "0x331a69da8655a882ba1fbcb55188b8fa09116521db901bbbaafc9fead0689f8",
27
- collection1155ClassHash: "0x4e110b59af240ae6c7742999964c4eae13fb2ed935c47fe97653ec017ebea34",
28
- collection1155StartBlock: 10665319,
15
+ marketplace721: "0x03eda9a2b6ad90845a43591bac8083ebaf677d51fdf20f503b2c01889e3131fc",
16
+ marketplace721ClassHash: "0x0700d9230d07e5203e27778c0dc70f9134d2b25bf319f7cf8348dc66a6923e90",
17
+ marketplace721StartBlock: 11198146,
18
+ marketplace1155: "0x07c4ce1c19ea48cc11135ed22b19ff745f5aec508c3828593002e4f76fdb1b38",
19
+ marketplace1155ClassHash: "0x0242f5c388da7cee2d99e2a69453c8159bf927fbec4e797a3cfdcbbcb5b68328",
20
+ marketplace1155StartBlock: 11198267,
21
+ collection721: "0x0225c3ae09506b8d97adc39649ca740dad5aac195b7f5f0441cc1852947acaea",
22
+ collection721StartBlock: 11198496,
23
+ ipNftClassHash: "0x012d3ae40ba35c7e2be0946532dac60e48932447912fdf96b674da67c029b9cc",
24
+ ipCollectionClassHash: "0x022155a1a130a40e57aac4b89c07fab3f616bc351b1270fc40f756b963afe8b4",
25
+ collection1155: "0x015368976d46fae5bfa1c58600f641d5aa5dbbf53ebc6b78aa3922194aad3551",
26
+ collection1155FactoryClassHash: "0x04eb6b419770f13bd191f120b9fc9ee624c0613ad4490062d293ca2016b3b1d2",
27
+ collection1155ClassHash: "0x06cf3f5a2322dac35e07a6064a5b8802f19fda8aa3f4726f0cb7bc05dea1bd78",
28
+ collection1155StartBlock: 11199527,
29
29
  popFactory: "0x00b32c34b427d8f346b5843ada6a37bd3368d879fc752cd52b68a87287f60111",
30
30
  popCollectionClassHash: "0x077c421686f10851872561953ea16898d933364b7f8937a5d7e2b1ba0a36263f",
31
31
  dropFactory: "0x03587f42e29daee1b193f6cf83bf8627908ed6632d0d83fcb26225c50547d800",
@@ -151,8 +151,8 @@ var ORDER_CANCELLATION = [
151
151
  { name: "offerer", type: "ContractAddress" }
152
152
  ];
153
153
  var DOMAIN_VERSION = {
154
- erc721: "4",
155
- erc1155: "3"
154
+ erc721: "5",
155
+ erc1155: "4"
156
156
  };
157
157
  function buildDomain(standard, chainId) {
158
158
  return {
@@ -427,6 +427,10 @@ var IPMarketplaceABI = [
427
427
  {
428
428
  "name": "order_status",
429
429
  "type": "medialane_marketplace_erc721::core::types::OrderStatus"
430
+ },
431
+ {
432
+ "name": "counter",
433
+ "type": "core::felt252"
430
434
  }
431
435
  ]
432
436
  },
@@ -1305,6 +1309,10 @@ var Medialane1155ABI = [
1305
1309
  {
1306
1310
  "name": "remaining_amount",
1307
1311
  "type": "core::felt252"
1312
+ },
1313
+ {
1314
+ "name": "counter",
1315
+ "type": "core::felt252"
1308
1316
  }
1309
1317
  ]
1310
1318
  },
@@ -3163,10 +3171,6 @@ var IPCollectionABI = [
3163
3171
  "type": "function",
3164
3172
  "name": "batch_transfer",
3165
3173
  "inputs": [
3166
- {
3167
- "name": "from",
3168
- "type": "core::starknet::contract_address::ContractAddress"
3169
- },
3170
3174
  {
3171
3175
  "name": "to",
3172
3176
  "type": "core::starknet::contract_address::ContractAddress"
@@ -6821,6 +6825,95 @@ function parseAdminHeaders(get) {
6821
6825
  }
6822
6826
  }
6823
6827
 
6828
+ // src/siws/client.ts
6829
+ var STORAGE_PREFIX = "ml_siws_";
6830
+ function decodeBase64url(str) {
6831
+ const base64 = str.replace(/-/g, "+").replace(/_/g, "/");
6832
+ const padding = "=".repeat((4 - base64.length % 4) % 4);
6833
+ return atob(base64 + padding);
6834
+ }
6835
+ function readTokenExpiry(token) {
6836
+ try {
6837
+ if (!token.startsWith("siws_")) return null;
6838
+ const inner = token.slice(5);
6839
+ const dot = inner.lastIndexOf(".");
6840
+ if (dot === -1) return null;
6841
+ const data = JSON.parse(decodeBase64url(inner.slice(0, dot)));
6842
+ return typeof data.exp === "number" ? data.exp : null;
6843
+ } catch {
6844
+ return null;
6845
+ }
6846
+ }
6847
+ function getSiwsStorageKey(address) {
6848
+ return `${STORAGE_PREFIX}${address.toLowerCase()}`;
6849
+ }
6850
+ function isSiwsTokenValid(token) {
6851
+ if (!token?.startsWith("siws_")) return false;
6852
+ const expiry = readTokenExpiry(token);
6853
+ return Boolean(expiry && expiry > Math.floor(Date.now() / 1e3));
6854
+ }
6855
+ function getStoredSiwsToken(address) {
6856
+ if (typeof window === "undefined") return null;
6857
+ const key = getSiwsStorageKey(address);
6858
+ const token = localStorage.getItem(key);
6859
+ if (isSiwsTokenValid(token)) return token;
6860
+ localStorage.removeItem(key);
6861
+ return null;
6862
+ }
6863
+ function storeSiwsToken(address, token) {
6864
+ if (typeof window === "undefined") return;
6865
+ localStorage.setItem(getSiwsStorageKey(address), token);
6866
+ }
6867
+ function normalizeSiwsSignature(signature) {
6868
+ if (Array.isArray(signature)) {
6869
+ return signature.map(String);
6870
+ }
6871
+ if (signature && typeof signature === "object") {
6872
+ const { r, s } = signature;
6873
+ if (r !== void 0 && s !== void 0) {
6874
+ return [String(r), String(s)];
6875
+ }
6876
+ }
6877
+ return [String(signature)];
6878
+ }
6879
+ async function requestSiwsToken({
6880
+ backendUrl,
6881
+ walletAddress,
6882
+ signer
6883
+ }) {
6884
+ const base = backendUrl.replace(/\/$/, "");
6885
+ const nonceRes = await fetch(`${base}/v1/auth/siws/nonce`, {
6886
+ method: "POST",
6887
+ headers: { "Content-Type": "application/json" },
6888
+ body: JSON.stringify({ walletAddress })
6889
+ });
6890
+ if (!nonceRes.ok) {
6891
+ throw new Error("Failed to prepare wallet sign-in");
6892
+ }
6893
+ const { nonce, typedData } = await nonceRes.json();
6894
+ const signature = normalizeSiwsSignature(await signer.signMessage(typedData));
6895
+ const verifyRes = await fetch(`${base}/v1/auth/siws/verify`, {
6896
+ method: "POST",
6897
+ headers: { "Content-Type": "application/json" },
6898
+ body: JSON.stringify({ walletAddress, nonce, signature })
6899
+ });
6900
+ if (!verifyRes.ok) {
6901
+ let backendMessage;
6902
+ try {
6903
+ const body = await verifyRes.json();
6904
+ if (body?.message) backendMessage = body.message;
6905
+ } catch {
6906
+ }
6907
+ throw new Error(backendMessage ?? "Wallet sign-in failed");
6908
+ }
6909
+ const { token } = await verifyRes.json();
6910
+ if (!isSiwsTokenValid(token)) {
6911
+ throw new Error("Wallet sign-in returned an invalid token");
6912
+ }
6913
+ storeSiwsToken(walletAddress, token);
6914
+ return token;
6915
+ }
6916
+
6824
6917
  // src/types/api.ts
6825
6918
  var OPEN_LICENSES = ["CC0", "CC BY", "CC BY-SA", "CC BY-NC"];
6826
6919
 
@@ -7152,22 +7245,28 @@ exports.getCreatorCoinPrice = getCreatorCoinPrice;
7152
7245
  exports.getListableTokens = getListableTokens;
7153
7246
  exports.getService = getService;
7154
7247
  exports.getServicesByCapability = getServicesByCapability;
7248
+ exports.getSiwsStorageKey = getSiwsStorageKey;
7249
+ exports.getStoredSiwsToken = getStoredSiwsToken;
7155
7250
  exports.getTokenByAddress = getTokenByAddress;
7156
7251
  exports.getTokenBySymbol = getTokenBySymbol;
7157
7252
  exports.isServiceId = isServiceId;
7253
+ exports.isSiwsTokenValid = isSiwsTokenValid;
7158
7254
  exports.isTransientRpcError = isTransientRpcError;
7159
7255
  exports.listServices = listServices;
7160
7256
  exports.normalizeAddress = normalizeAddress;
7161
7257
  exports.normalizeHash = normalizeHash;
7258
+ exports.normalizeSiwsSignature = normalizeSiwsSignature;
7162
7259
  exports.parseAdminHeaders = parseAdminHeaders;
7163
7260
  exports.parseAmount = parseAmount;
7164
7261
  exports.parseCreatorCoinCreated = parseCreatorCoinCreated;
7165
7262
  exports.randomNonce = randomNonce;
7263
+ exports.requestSiwsToken = requestSiwsToken;
7166
7264
  exports.resolveConfig = resolveConfig;
7167
7265
  exports.resolveFeeConfig = resolveFeeConfig;
7168
7266
  exports.sessionKeyHashOf = sessionKeyHashOf;
7169
7267
  exports.shortenAddress = shortenAddress;
7170
7268
  exports.signAdminRequest = signAdminRequest;
7269
+ exports.storeSiwsToken = storeSiwsToken;
7171
7270
  exports.stringifyBigInts = stringifyBigInts;
7172
7271
  exports.teamCoinsRaw = teamCoinsRaw;
7173
7272
  exports.u256ToBigInt = u256ToBigInt;