@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/{WalletManager-Du9oKIeu.d.mts → WalletManager-BuZgAr-D.d.mts} +13 -13
- package/dist/{WalletManager-Ry-PqMUp.d.ts → WalletManager-DrI2lvOM.d.ts} +13 -13
- package/dist/{index-6y3uV1Sh.d.mts → index-Be7yLGAO.d.mts} +31 -5
- package/dist/{index-6y3uV1Sh.d.ts → index-Be7yLGAO.d.ts} +31 -5
- package/dist/{index-BK6MH30q.d.ts → index-DTygRRZD.d.ts} +57 -3
- package/dist/{index-yA3Aorn-.d.mts → index-sHlchAWr.d.mts} +57 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +115 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +112 -7
- package/dist/index.mjs.map +1 -1
- package/dist/protocols/index.d.mts +33 -3
- package/dist/protocols/index.d.ts +33 -3
- package/dist/protocols/index.js +112 -6
- package/dist/protocols/index.js.map +1 -1
- package/dist/protocols/index.mjs +112 -6
- package/dist/protocols/index.mjs.map +1 -1
- package/dist/react/index.d.mts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/services/index.d.mts +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js.map +1 -1
- package/dist/services/index.mjs.map +1 -1
- package/dist/wallet/index.d.mts +3 -3
- package/dist/wallet/index.d.ts +3 -3
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -204,9 +204,30 @@ var NFT_VOUCHER_TYPES = {
|
|
|
204
204
|
{ name: "uri", type: "string" },
|
|
205
205
|
{ name: "creator", type: "address" },
|
|
206
206
|
{ name: "royaltyBps", type: "uint256" },
|
|
207
|
-
{ name: "deadline", type: "uint256" }
|
|
207
|
+
{ name: "deadline", type: "uint256" },
|
|
208
|
+
// Pricing fields
|
|
209
|
+
{ name: "price", type: "uint256" },
|
|
210
|
+
{ name: "currency", type: "address" },
|
|
211
|
+
{ name: "nonce", type: "uint256" },
|
|
212
|
+
// Watermarking fields
|
|
213
|
+
{ name: "contentHash", type: "bytes32" },
|
|
214
|
+
{ name: "userId", type: "bytes32" },
|
|
215
|
+
{ name: "watermarkTimestamp", type: "uint256" },
|
|
216
|
+
{ name: "sessionId", type: "bytes32" }
|
|
208
217
|
]
|
|
209
218
|
};
|
|
219
|
+
var CURRENCY_ADDRESSES = {
|
|
220
|
+
testnet: {
|
|
221
|
+
ETH: ZERO_ADDRESS,
|
|
222
|
+
USDT: "0xaA8E23Fb1079EA71e0a56F48a2aA51851D8433D0"
|
|
223
|
+
// USDT on Sepolia
|
|
224
|
+
},
|
|
225
|
+
mainnet: {
|
|
226
|
+
ETH: ZERO_ADDRESS,
|
|
227
|
+
USDT: "0xdAC17F958D2ee523a2206206994597C13D831ec7"
|
|
228
|
+
// USDT on Ethereum
|
|
229
|
+
}
|
|
230
|
+
};
|
|
210
231
|
function getContractAddresses(network) {
|
|
211
232
|
return ZUBARI_CONTRACTS[network];
|
|
212
233
|
}
|
|
@@ -2311,28 +2332,86 @@ var ZubariNFTProtocol = class {
|
|
|
2311
2332
|
contractAddress;
|
|
2312
2333
|
_marketplaceAddress;
|
|
2313
2334
|
chainId;
|
|
2314
|
-
|
|
2335
|
+
network;
|
|
2336
|
+
nonceCounter = 0;
|
|
2337
|
+
constructor(contractAddress, marketplaceAddress, chainId, network = "testnet") {
|
|
2315
2338
|
this.contractAddress = contractAddress;
|
|
2316
2339
|
this._marketplaceAddress = marketplaceAddress;
|
|
2317
2340
|
this.chainId = chainId;
|
|
2341
|
+
this.network = network;
|
|
2342
|
+
}
|
|
2343
|
+
/**
|
|
2344
|
+
* Convert human-readable price to wei
|
|
2345
|
+
* @param price - Price in human-readable format (e.g., "1.5")
|
|
2346
|
+
* @param currency - ETH (18 decimals) or USDT (6 decimals)
|
|
2347
|
+
*/
|
|
2348
|
+
priceToWei(price, currency) {
|
|
2349
|
+
const decimals = currency === "ETH" ? 18 : 6;
|
|
2350
|
+
const [whole, fraction = ""] = price.split(".");
|
|
2351
|
+
const paddedFraction = fraction.padEnd(decimals, "0").slice(0, decimals);
|
|
2352
|
+
const wei = whole + paddedFraction;
|
|
2353
|
+
return wei.replace(/^0+/, "") || "0";
|
|
2354
|
+
}
|
|
2355
|
+
/**
|
|
2356
|
+
* Get currency address for the configured network
|
|
2357
|
+
*/
|
|
2358
|
+
getCurrencyAddress(currency) {
|
|
2359
|
+
return CURRENCY_ADDRESSES[this.network][currency];
|
|
2360
|
+
}
|
|
2361
|
+
/**
|
|
2362
|
+
* Generate a unique nonce
|
|
2363
|
+
*/
|
|
2364
|
+
generateNonce() {
|
|
2365
|
+
return Date.now() * 1e3 + this.nonceCounter++;
|
|
2366
|
+
}
|
|
2367
|
+
/**
|
|
2368
|
+
* Pad string to bytes32 format
|
|
2369
|
+
*/
|
|
2370
|
+
toBytes32(value) {
|
|
2371
|
+
if (value.startsWith("0x")) {
|
|
2372
|
+
return value.padEnd(66, "0");
|
|
2373
|
+
}
|
|
2374
|
+
const hex = Buffer.from(value).toString("hex");
|
|
2375
|
+
return "0x" + hex.padEnd(64, "0");
|
|
2318
2376
|
}
|
|
2319
2377
|
/**
|
|
2320
2378
|
* Create a lazy mint voucher for off-chain NFT creation
|
|
2321
2379
|
* The voucher can be redeemed on-chain when purchased
|
|
2380
|
+
*
|
|
2381
|
+
* @param params - Voucher creation parameters
|
|
2382
|
+
* @param signer - Object with signTypedData method (ethers.js wallet or viem client)
|
|
2322
2383
|
*/
|
|
2323
|
-
async createLazyMintVoucher(
|
|
2384
|
+
async createLazyMintVoucher(params, signer) {
|
|
2385
|
+
const { metadata, creatorAddress, price, currency, nonce, watermarking } = params;
|
|
2324
2386
|
if (metadata.royaltyBps > PLATFORM_CONFIG.maxRoyaltyBps) {
|
|
2325
2387
|
throw new Error(`Royalty cannot exceed ${PLATFORM_CONFIG.maxRoyaltyBps / 100}%`);
|
|
2326
2388
|
}
|
|
2389
|
+
if (!price || parseFloat(price) <= 0) {
|
|
2390
|
+
throw new Error("Price must be greater than 0");
|
|
2391
|
+
}
|
|
2327
2392
|
const tokenId = this.generateTokenId();
|
|
2328
2393
|
const deadline = Math.floor(Date.now() / 1e3) + PLATFORM_CONFIG.voucherValiditySecs;
|
|
2394
|
+
const priceInWei = this.priceToWei(price, currency);
|
|
2395
|
+
const currencyAddress = this.getCurrencyAddress(currency);
|
|
2396
|
+
const voucherNonce = nonce ?? this.generateNonce();
|
|
2397
|
+
const watermarkTimestamp = watermarking ? Math.floor(Date.now() / 1e3) : 0;
|
|
2398
|
+
const contentHash = watermarking ? this.toBytes32(watermarking.contentHash) : ZERO_ADDRESS.replace("0x", "0x" + "0".repeat(64)).slice(0, 66);
|
|
2399
|
+
const userId = watermarking ? this.toBytes32(watermarking.userId) : ZERO_ADDRESS.replace("0x", "0x" + "0".repeat(64)).slice(0, 66);
|
|
2400
|
+
const sessionId = watermarking ? this.toBytes32(watermarking.sessionId) : ZERO_ADDRESS.replace("0x", "0x" + "0".repeat(64)).slice(0, 66);
|
|
2329
2401
|
const voucherData = {
|
|
2330
2402
|
tokenId,
|
|
2331
2403
|
uri: metadata.image,
|
|
2332
2404
|
// Will be IPFS URI
|
|
2333
2405
|
creator: creatorAddress,
|
|
2334
2406
|
royaltyBps: metadata.royaltyBps,
|
|
2335
|
-
deadline
|
|
2407
|
+
deadline,
|
|
2408
|
+
price: priceInWei,
|
|
2409
|
+
currency: currencyAddress,
|
|
2410
|
+
nonce: voucherNonce,
|
|
2411
|
+
contentHash,
|
|
2412
|
+
userId,
|
|
2413
|
+
watermarkTimestamp,
|
|
2414
|
+
sessionId
|
|
2336
2415
|
};
|
|
2337
2416
|
const domain = {
|
|
2338
2417
|
...NFT_VOUCHER_DOMAIN,
|
|
@@ -2341,10 +2420,36 @@ var ZubariNFTProtocol = class {
|
|
|
2341
2420
|
};
|
|
2342
2421
|
const signature = await signer.signTypedData(domain, NFT_VOUCHER_TYPES, voucherData);
|
|
2343
2422
|
return {
|
|
2344
|
-
|
|
2345
|
-
|
|
2423
|
+
tokenId,
|
|
2424
|
+
uri: metadata.image,
|
|
2425
|
+
creator: creatorAddress,
|
|
2426
|
+
royaltyBps: metadata.royaltyBps,
|
|
2427
|
+
deadline,
|
|
2428
|
+
signature,
|
|
2429
|
+
price: priceInWei,
|
|
2430
|
+
currency: currencyAddress,
|
|
2431
|
+
nonce: voucherNonce,
|
|
2432
|
+
contentHash: watermarking ? contentHash : void 0,
|
|
2433
|
+
userId: watermarking ? userId : void 0,
|
|
2434
|
+
watermarkTimestamp: watermarking ? watermarkTimestamp : void 0,
|
|
2435
|
+
sessionId: watermarking ? sessionId : void 0
|
|
2346
2436
|
};
|
|
2347
2437
|
}
|
|
2438
|
+
/**
|
|
2439
|
+
* @deprecated Use createLazyMintVoucher(params, signer) instead
|
|
2440
|
+
* Legacy method for backward compatibility
|
|
2441
|
+
*/
|
|
2442
|
+
async createLazyMintVoucherLegacy(metadata, creatorAddress, signer) {
|
|
2443
|
+
return this.createLazyMintVoucher(
|
|
2444
|
+
{
|
|
2445
|
+
metadata,
|
|
2446
|
+
creatorAddress,
|
|
2447
|
+
price: "0.01",
|
|
2448
|
+
currency: "ETH"
|
|
2449
|
+
},
|
|
2450
|
+
signer
|
|
2451
|
+
);
|
|
2452
|
+
}
|
|
2348
2453
|
/**
|
|
2349
2454
|
* Redeem a lazy mint voucher to mint the NFT on-chain
|
|
2350
2455
|
*/
|
|
@@ -6209,6 +6314,6 @@ function normalizeAddress(address) {
|
|
|
6209
6314
|
return address.toLowerCase();
|
|
6210
6315
|
}
|
|
6211
6316
|
|
|
6212
|
-
export { BrowserAddressDerivation_exports as BrowserAddressDerivation, DERIVATION_PATHS, KeyManager, MemoryStorageAdapter, NETWORKS, PLATFORM_CONFIG, SwapService, TESTNET_NETWORKS, TransactionService, WalletManager, WdkApiClient, WebEncryptedStorageAdapter, ZUBARI_CONTRACTS, ZubariError, ZubariMarketProtocol, ZubariNFTProtocol, ZubariPayoutsProtocol, ZubariSubscriptionProtocol, ZubariTipsProtocol, ZubariWallet, ZubariWdkService, createSecureStorage, createTransactionService, createZubariWdkService, formatAddress, formatBalance, getContractAddresses, getNetworkConfig, getTransactionService, getWdkApiClient, getZubariWdkService, isBrowser, isValidAddress, normalizeAddress, useWalletManager };
|
|
6317
|
+
export { BrowserAddressDerivation_exports as BrowserAddressDerivation, CURRENCY_ADDRESSES, DERIVATION_PATHS, KeyManager, MemoryStorageAdapter, NETWORKS, NFT_VOUCHER_DOMAIN, NFT_VOUCHER_TYPES, PLATFORM_CONFIG, SwapService, TESTNET_NETWORKS, TransactionService, WalletManager, WdkApiClient, WebEncryptedStorageAdapter, ZERO_ADDRESS, ZUBARI_CONTRACTS, ZubariError, ZubariMarketProtocol, ZubariNFTProtocol, ZubariPayoutsProtocol, ZubariSubscriptionProtocol, ZubariTipsProtocol, ZubariWallet, ZubariWdkService, createSecureStorage, createTransactionService, createZubariWdkService, formatAddress, formatBalance, getContractAddresses, getNetworkConfig, getTransactionService, getWdkApiClient, getZubariWdkService, isBrowser, isValidAddress, normalizeAddress, useWalletManager };
|
|
6213
6318
|
//# sourceMappingURL=index.mjs.map
|
|
6214
6319
|
//# sourceMappingURL=index.mjs.map
|