@zubari/sdk 0.1.31 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- export { P as PLATFORM_CONFIG, a as ZUBARI_CONTRACTS, Z as ZubariWallet, g as getContractAddresses } from './index-BK6MH30q.js';
2
- export { D as DERIVATION_PATHS, N as NETWORKS, T as TESTNET_NETWORKS, W as WalletManager, b as WalletManagerConfig, a as WalletState, g as getNetworkConfig } from './WalletManager-Ry-PqMUp.js';
1
+ export { C as CURRENCY_ADDRESSES, N as NFT_VOUCHER_DOMAIN, c as NFT_VOUCHER_TYPES, P as PLATFORM_CONFIG, b as ZERO_ADDRESS, a as ZUBARI_CONTRACTS, Z as ZubariWallet, g as getContractAddresses } from './index-DTygRRZD.js';
2
+ export { D as DERIVATION_PATHS, N as NETWORKS, T as TESTNET_NETWORKS, W as WalletManager, b as WalletManagerConfig, a as WalletState, g as getNetworkConfig } from './WalletManager-DrI2lvOM.js';
3
3
  export { M as MemoryStorageAdapter, S as SecureStorageAdapter, W as WebEncryptedStorageAdapter, c as createSecureStorage } from './SecureStorage-jO783AhC.js';
4
4
  export { ZubariMarketProtocol, ZubariNFTProtocol, ZubariPayoutsProtocol, ZubariSubscriptionProtocol, ZubariTipsProtocol } from './protocols/index.js';
5
5
  export { BrowserAddressDerivation, ChainAddress, ChainBalance, FeeEstimate, FeeRates, MultiChainAddresses, SupportedChain, SwapService, TransactionHistoryItem, TransactionParams, TransactionResult, TransactionService, TransactionServiceConfig, WdkApiClient, ZubariWdkService, ZubariWdkServiceConfig, createTransactionService, createZubariWdkService, getTransactionService, getWdkApiClient, getZubariWdkService, isBrowser } from './services/index.js';
6
- export { A as Account, B as BuyParams, E as EarningsBreakdown, L as LazyMintVoucher, f as Listing, e as ListingParams, d as NFT, c as NFTMetadata, a as NetworkBalance, N as NetworkType, R as RevenueSplit, S as SendParams, l as Subscription, k as SubscriptionPlan, n as SwapParams, m as SwapQuote, j as Tip, g as TipData, h as TipResult, i as TipStats, T as TokenBalance, b as TxResult, p as ZubariError, o as ZubariErrorCode, Z as ZubariWalletConfig } from './index-6y3uV1Sh.js';
6
+ export { A as Account, B as BuyParams, C as CreateVoucherParams, E as EarningsBreakdown, L as LazyMintVoucher, h as Listing, g as ListingParams, f as NFT, d as NFTAttribute, c as NFTCurrency, e as NFTMetadata, a as NetworkBalance, N as NetworkType, R as RevenueSplit, S as SendParams, n as Subscription, m as SubscriptionPlan, p as SwapParams, o as SwapQuote, l as Tip, i as TipData, j as TipResult, k as TipStats, T as TokenBalance, b as TxResult, W as WatermarkingData, r as ZubariError, q as ZubariErrorCode, Z as ZubariWalletConfig } from './index-Be7yLGAO.js';
7
7
  export { FeeEstimateResult, SendTransactionResult, UseWalletManagerOptions, UseWalletManagerReturn, useWalletManager } from './react/index.js';
8
8
  import 'node_modules/viem/_types/actions/siwe/verifySiweMessage';
9
9
  import 'node_modules/viem/_types/utils/ccip';
package/dist/index.js CHANGED
@@ -206,9 +206,30 @@ var NFT_VOUCHER_TYPES = {
206
206
  { name: "uri", type: "string" },
207
207
  { name: "creator", type: "address" },
208
208
  { name: "royaltyBps", type: "uint256" },
209
- { name: "deadline", type: "uint256" }
209
+ { name: "deadline", type: "uint256" },
210
+ // Pricing fields
211
+ { name: "price", type: "uint256" },
212
+ { name: "currency", type: "address" },
213
+ { name: "nonce", type: "uint256" },
214
+ // Watermarking fields
215
+ { name: "contentHash", type: "bytes32" },
216
+ { name: "userId", type: "bytes32" },
217
+ { name: "watermarkTimestamp", type: "uint256" },
218
+ { name: "sessionId", type: "bytes32" }
210
219
  ]
211
220
  };
221
+ var CURRENCY_ADDRESSES = {
222
+ testnet: {
223
+ ETH: ZERO_ADDRESS,
224
+ USDT: "0xaA8E23Fb1079EA71e0a56F48a2aA51851D8433D0"
225
+ // USDT on Sepolia
226
+ },
227
+ mainnet: {
228
+ ETH: ZERO_ADDRESS,
229
+ USDT: "0xdAC17F958D2ee523a2206206994597C13D831ec7"
230
+ // USDT on Ethereum
231
+ }
232
+ };
212
233
  function getContractAddresses(network) {
213
234
  return ZUBARI_CONTRACTS[network];
214
235
  }
@@ -2313,28 +2334,86 @@ var ZubariNFTProtocol = class {
2313
2334
  contractAddress;
2314
2335
  _marketplaceAddress;
2315
2336
  chainId;
2316
- constructor(contractAddress, marketplaceAddress, chainId) {
2337
+ network;
2338
+ nonceCounter = 0;
2339
+ constructor(contractAddress, marketplaceAddress, chainId, network = "testnet") {
2317
2340
  this.contractAddress = contractAddress;
2318
2341
  this._marketplaceAddress = marketplaceAddress;
2319
2342
  this.chainId = chainId;
2343
+ this.network = network;
2344
+ }
2345
+ /**
2346
+ * Convert human-readable price to wei
2347
+ * @param price - Price in human-readable format (e.g., "1.5")
2348
+ * @param currency - ETH (18 decimals) or USDT (6 decimals)
2349
+ */
2350
+ priceToWei(price, currency) {
2351
+ const decimals = currency === "ETH" ? 18 : 6;
2352
+ const [whole, fraction = ""] = price.split(".");
2353
+ const paddedFraction = fraction.padEnd(decimals, "0").slice(0, decimals);
2354
+ const wei = whole + paddedFraction;
2355
+ return wei.replace(/^0+/, "") || "0";
2356
+ }
2357
+ /**
2358
+ * Get currency address for the configured network
2359
+ */
2360
+ getCurrencyAddress(currency) {
2361
+ return CURRENCY_ADDRESSES[this.network][currency];
2362
+ }
2363
+ /**
2364
+ * Generate a unique nonce
2365
+ */
2366
+ generateNonce() {
2367
+ return Date.now() * 1e3 + this.nonceCounter++;
2368
+ }
2369
+ /**
2370
+ * Pad string to bytes32 format
2371
+ */
2372
+ toBytes32(value) {
2373
+ if (value.startsWith("0x")) {
2374
+ return value.padEnd(66, "0");
2375
+ }
2376
+ const hex = Buffer.from(value).toString("hex");
2377
+ return "0x" + hex.padEnd(64, "0");
2320
2378
  }
2321
2379
  /**
2322
2380
  * Create a lazy mint voucher for off-chain NFT creation
2323
2381
  * The voucher can be redeemed on-chain when purchased
2382
+ *
2383
+ * @param params - Voucher creation parameters
2384
+ * @param signer - Object with signTypedData method (ethers.js wallet or viem client)
2324
2385
  */
2325
- async createLazyMintVoucher(metadata, creatorAddress, signer) {
2386
+ async createLazyMintVoucher(params, signer) {
2387
+ const { metadata, creatorAddress, price, currency, nonce, watermarking } = params;
2326
2388
  if (metadata.royaltyBps > PLATFORM_CONFIG.maxRoyaltyBps) {
2327
2389
  throw new Error(`Royalty cannot exceed ${PLATFORM_CONFIG.maxRoyaltyBps / 100}%`);
2328
2390
  }
2391
+ if (!price || parseFloat(price) <= 0) {
2392
+ throw new Error("Price must be greater than 0");
2393
+ }
2329
2394
  const tokenId = this.generateTokenId();
2330
2395
  const deadline = Math.floor(Date.now() / 1e3) + PLATFORM_CONFIG.voucherValiditySecs;
2396
+ const priceInWei = this.priceToWei(price, currency);
2397
+ const currencyAddress = this.getCurrencyAddress(currency);
2398
+ const voucherNonce = nonce ?? this.generateNonce();
2399
+ const watermarkTimestamp = watermarking ? Math.floor(Date.now() / 1e3) : 0;
2400
+ const contentHash = watermarking ? this.toBytes32(watermarking.contentHash) : ZERO_ADDRESS.replace("0x", "0x" + "0".repeat(64)).slice(0, 66);
2401
+ const userId = watermarking ? this.toBytes32(watermarking.userId) : ZERO_ADDRESS.replace("0x", "0x" + "0".repeat(64)).slice(0, 66);
2402
+ const sessionId = watermarking ? this.toBytes32(watermarking.sessionId) : ZERO_ADDRESS.replace("0x", "0x" + "0".repeat(64)).slice(0, 66);
2331
2403
  const voucherData = {
2332
2404
  tokenId,
2333
2405
  uri: metadata.image,
2334
2406
  // Will be IPFS URI
2335
2407
  creator: creatorAddress,
2336
2408
  royaltyBps: metadata.royaltyBps,
2337
- deadline
2409
+ deadline,
2410
+ price: priceInWei,
2411
+ currency: currencyAddress,
2412
+ nonce: voucherNonce,
2413
+ contentHash,
2414
+ userId,
2415
+ watermarkTimestamp,
2416
+ sessionId
2338
2417
  };
2339
2418
  const domain = {
2340
2419
  ...NFT_VOUCHER_DOMAIN,
@@ -2343,10 +2422,36 @@ var ZubariNFTProtocol = class {
2343
2422
  };
2344
2423
  const signature = await signer.signTypedData(domain, NFT_VOUCHER_TYPES, voucherData);
2345
2424
  return {
2346
- ...voucherData,
2347
- signature
2425
+ tokenId,
2426
+ uri: metadata.image,
2427
+ creator: creatorAddress,
2428
+ royaltyBps: metadata.royaltyBps,
2429
+ deadline,
2430
+ signature,
2431
+ price: priceInWei,
2432
+ currency: currencyAddress,
2433
+ nonce: voucherNonce,
2434
+ contentHash: watermarking ? contentHash : void 0,
2435
+ userId: watermarking ? userId : void 0,
2436
+ watermarkTimestamp: watermarking ? watermarkTimestamp : void 0,
2437
+ sessionId: watermarking ? sessionId : void 0
2348
2438
  };
2349
2439
  }
2440
+ /**
2441
+ * @deprecated Use createLazyMintVoucher(params, signer) instead
2442
+ * Legacy method for backward compatibility
2443
+ */
2444
+ async createLazyMintVoucherLegacy(metadata, creatorAddress, signer) {
2445
+ return this.createLazyMintVoucher(
2446
+ {
2447
+ metadata,
2448
+ creatorAddress,
2449
+ price: "0.01",
2450
+ currency: "ETH"
2451
+ },
2452
+ signer
2453
+ );
2454
+ }
2350
2455
  /**
2351
2456
  * Redeem a lazy mint voucher to mint the NFT on-chain
2352
2457
  */
@@ -6212,10 +6317,13 @@ function normalizeAddress(address) {
6212
6317
  }
6213
6318
 
6214
6319
  exports.BrowserAddressDerivation = BrowserAddressDerivation_exports;
6320
+ exports.CURRENCY_ADDRESSES = CURRENCY_ADDRESSES;
6215
6321
  exports.DERIVATION_PATHS = DERIVATION_PATHS;
6216
6322
  exports.KeyManager = KeyManager;
6217
6323
  exports.MemoryStorageAdapter = MemoryStorageAdapter;
6218
6324
  exports.NETWORKS = NETWORKS;
6325
+ exports.NFT_VOUCHER_DOMAIN = NFT_VOUCHER_DOMAIN;
6326
+ exports.NFT_VOUCHER_TYPES = NFT_VOUCHER_TYPES;
6219
6327
  exports.PLATFORM_CONFIG = PLATFORM_CONFIG;
6220
6328
  exports.SwapService = SwapService;
6221
6329
  exports.TESTNET_NETWORKS = TESTNET_NETWORKS;
@@ -6223,6 +6331,7 @@ exports.TransactionService = TransactionService;
6223
6331
  exports.WalletManager = WalletManager;
6224
6332
  exports.WdkApiClient = WdkApiClient;
6225
6333
  exports.WebEncryptedStorageAdapter = WebEncryptedStorageAdapter;
6334
+ exports.ZERO_ADDRESS = ZERO_ADDRESS;
6226
6335
  exports.ZUBARI_CONTRACTS = ZUBARI_CONTRACTS;
6227
6336
  exports.ZubariError = ZubariError;
6228
6337
  exports.ZubariMarketProtocol = ZubariMarketProtocol;