@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.
@@ -1,4 +1,5 @@
1
1
  // src/config/contracts.ts
2
+ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
2
3
  var PLATFORM_CONFIG = {
3
4
  // Platform fee in basis points (300 = 3%)
4
5
  tipFeeBps: 300,
@@ -16,37 +17,116 @@ var NFT_VOUCHER_TYPES = {
16
17
  { name: "uri", type: "string" },
17
18
  { name: "creator", type: "address" },
18
19
  { name: "royaltyBps", type: "uint256" },
19
- { name: "deadline", type: "uint256" }
20
+ { name: "deadline", type: "uint256" },
21
+ // Pricing fields
22
+ { name: "price", type: "uint256" },
23
+ { name: "currency", type: "address" },
24
+ { name: "nonce", type: "uint256" },
25
+ // Watermarking fields
26
+ { name: "contentHash", type: "bytes32" },
27
+ { name: "userId", type: "bytes32" },
28
+ { name: "watermarkTimestamp", type: "uint256" },
29
+ { name: "sessionId", type: "bytes32" }
20
30
  ]
21
31
  };
32
+ var CURRENCY_ADDRESSES = {
33
+ testnet: {
34
+ ETH: ZERO_ADDRESS,
35
+ USDT: "0xaA8E23Fb1079EA71e0a56F48a2aA51851D8433D0"
36
+ // USDT on Sepolia
37
+ },
38
+ mainnet: {
39
+ ETH: ZERO_ADDRESS,
40
+ USDT: "0xdAC17F958D2ee523a2206206994597C13D831ec7"
41
+ // USDT on Ethereum
42
+ }
43
+ };
22
44
 
23
45
  // src/protocols/NFTProtocol.ts
24
46
  var ZubariNFTProtocol = class {
25
47
  contractAddress;
26
48
  _marketplaceAddress;
27
49
  chainId;
28
- constructor(contractAddress, marketplaceAddress, chainId) {
50
+ network;
51
+ nonceCounter = 0;
52
+ constructor(contractAddress, marketplaceAddress, chainId, network = "testnet") {
29
53
  this.contractAddress = contractAddress;
30
54
  this._marketplaceAddress = marketplaceAddress;
31
55
  this.chainId = chainId;
56
+ this.network = network;
57
+ }
58
+ /**
59
+ * Convert human-readable price to wei
60
+ * @param price - Price in human-readable format (e.g., "1.5")
61
+ * @param currency - ETH (18 decimals) or USDT (6 decimals)
62
+ */
63
+ priceToWei(price, currency) {
64
+ const decimals = currency === "ETH" ? 18 : 6;
65
+ const [whole, fraction = ""] = price.split(".");
66
+ const paddedFraction = fraction.padEnd(decimals, "0").slice(0, decimals);
67
+ const wei = whole + paddedFraction;
68
+ return wei.replace(/^0+/, "") || "0";
69
+ }
70
+ /**
71
+ * Get currency address for the configured network
72
+ */
73
+ getCurrencyAddress(currency) {
74
+ return CURRENCY_ADDRESSES[this.network][currency];
75
+ }
76
+ /**
77
+ * Generate a unique nonce
78
+ */
79
+ generateNonce() {
80
+ return Date.now() * 1e3 + this.nonceCounter++;
81
+ }
82
+ /**
83
+ * Pad string to bytes32 format
84
+ */
85
+ toBytes32(value) {
86
+ if (value.startsWith("0x")) {
87
+ return value.padEnd(66, "0");
88
+ }
89
+ const hex = Buffer.from(value).toString("hex");
90
+ return "0x" + hex.padEnd(64, "0");
32
91
  }
33
92
  /**
34
93
  * Create a lazy mint voucher for off-chain NFT creation
35
94
  * The voucher can be redeemed on-chain when purchased
95
+ *
96
+ * @param params - Voucher creation parameters
97
+ * @param signer - Object with signTypedData method (ethers.js wallet or viem client)
36
98
  */
37
- async createLazyMintVoucher(metadata, creatorAddress, signer) {
99
+ async createLazyMintVoucher(params, signer) {
100
+ const { metadata, creatorAddress, price, currency, nonce, watermarking } = params;
38
101
  if (metadata.royaltyBps > PLATFORM_CONFIG.maxRoyaltyBps) {
39
102
  throw new Error(`Royalty cannot exceed ${PLATFORM_CONFIG.maxRoyaltyBps / 100}%`);
40
103
  }
104
+ if (!price || parseFloat(price) <= 0) {
105
+ throw new Error("Price must be greater than 0");
106
+ }
41
107
  const tokenId = this.generateTokenId();
42
108
  const deadline = Math.floor(Date.now() / 1e3) + PLATFORM_CONFIG.voucherValiditySecs;
109
+ const priceInWei = this.priceToWei(price, currency);
110
+ const currencyAddress = this.getCurrencyAddress(currency);
111
+ const voucherNonce = nonce ?? this.generateNonce();
112
+ const watermarkTimestamp = watermarking ? Math.floor(Date.now() / 1e3) : 0;
113
+ const contentHash = watermarking ? this.toBytes32(watermarking.contentHash) : ZERO_ADDRESS.replace("0x", "0x" + "0".repeat(64)).slice(0, 66);
114
+ const userId = watermarking ? this.toBytes32(watermarking.userId) : ZERO_ADDRESS.replace("0x", "0x" + "0".repeat(64)).slice(0, 66);
115
+ const sessionId = watermarking ? this.toBytes32(watermarking.sessionId) : ZERO_ADDRESS.replace("0x", "0x" + "0".repeat(64)).slice(0, 66);
43
116
  const voucherData = {
44
117
  tokenId,
45
118
  uri: metadata.image,
46
119
  // Will be IPFS URI
47
120
  creator: creatorAddress,
48
121
  royaltyBps: metadata.royaltyBps,
49
- deadline
122
+ deadline,
123
+ price: priceInWei,
124
+ currency: currencyAddress,
125
+ nonce: voucherNonce,
126
+ contentHash,
127
+ userId,
128
+ watermarkTimestamp,
129
+ sessionId
50
130
  };
51
131
  const domain = {
52
132
  ...NFT_VOUCHER_DOMAIN,
@@ -55,10 +135,36 @@ var ZubariNFTProtocol = class {
55
135
  };
56
136
  const signature = await signer.signTypedData(domain, NFT_VOUCHER_TYPES, voucherData);
57
137
  return {
58
- ...voucherData,
59
- signature
138
+ tokenId,
139
+ uri: metadata.image,
140
+ creator: creatorAddress,
141
+ royaltyBps: metadata.royaltyBps,
142
+ deadline,
143
+ signature,
144
+ price: priceInWei,
145
+ currency: currencyAddress,
146
+ nonce: voucherNonce,
147
+ contentHash: watermarking ? contentHash : void 0,
148
+ userId: watermarking ? userId : void 0,
149
+ watermarkTimestamp: watermarking ? watermarkTimestamp : void 0,
150
+ sessionId: watermarking ? sessionId : void 0
60
151
  };
61
152
  }
153
+ /**
154
+ * @deprecated Use createLazyMintVoucher(params, signer) instead
155
+ * Legacy method for backward compatibility
156
+ */
157
+ async createLazyMintVoucherLegacy(metadata, creatorAddress, signer) {
158
+ return this.createLazyMintVoucher(
159
+ {
160
+ metadata,
161
+ creatorAddress,
162
+ price: "0.01",
163
+ currency: "ETH"
164
+ },
165
+ signer
166
+ );
167
+ }
62
168
  /**
63
169
  * Redeem a lazy mint voucher to mint the NFT on-chain
64
170
  */