@zubari/sdk 0.1.31 → 0.2.1
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-DKPzfA74.d.mts} +61 -144
- package/dist/{WalletManager-Ry-PqMUp.d.ts → WalletManager-IOHFgvpT.d.ts} +61 -144
- package/dist/{index-BK6MH30q.d.ts → index-BCX8EYxv.d.ts} +57 -3
- 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-yA3Aorn-.d.mts → index-BrLMTY29.d.mts} +57 -3
- package/dist/index.d.mts +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.js +120 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +117 -9
- 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 +117 -8
- package/dist/protocols/index.js.map +1 -1
- package/dist/protocols/index.mjs +117 -8
- package/dist/protocols/index.mjs.map +1 -1
- package/dist/react/index.d.mts +4 -5
- package/dist/react/index.d.ts +4 -5
- 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 +4 -5
- package/dist/wallet/index.d.ts +4 -5
- 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,88 @@ 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(
|
|
2324
|
-
|
|
2384
|
+
async createLazyMintVoucher(params, signer) {
|
|
2385
|
+
const { metadata, creatorAddress, price, currency, nonce, watermarking } = params;
|
|
2386
|
+
const royaltyBps = metadata.royaltyBps ?? 500;
|
|
2387
|
+
if (royaltyBps > PLATFORM_CONFIG.maxRoyaltyBps) {
|
|
2325
2388
|
throw new Error(`Royalty cannot exceed ${PLATFORM_CONFIG.maxRoyaltyBps / 100}%`);
|
|
2326
2389
|
}
|
|
2390
|
+
if (!price || parseFloat(price) <= 0) {
|
|
2391
|
+
throw new Error("Price must be greater than 0");
|
|
2392
|
+
}
|
|
2327
2393
|
const tokenId = this.generateTokenId();
|
|
2328
2394
|
const deadline = Math.floor(Date.now() / 1e3) + PLATFORM_CONFIG.voucherValiditySecs;
|
|
2395
|
+
const priceInWei = this.priceToWei(price, currency);
|
|
2396
|
+
const currencyAddress = this.getCurrencyAddress(currency);
|
|
2397
|
+
const voucherNonce = nonce ?? this.generateNonce();
|
|
2398
|
+
const watermarkTimestamp = watermarking ? Math.floor(Date.now() / 1e3) : 0;
|
|
2399
|
+
const contentHash = watermarking ? this.toBytes32(watermarking.contentHash) : ZERO_ADDRESS.replace("0x", "0x" + "0".repeat(64)).slice(0, 66);
|
|
2400
|
+
const userId = watermarking ? this.toBytes32(watermarking.userId) : ZERO_ADDRESS.replace("0x", "0x" + "0".repeat(64)).slice(0, 66);
|
|
2401
|
+
const sessionId = watermarking ? this.toBytes32(watermarking.sessionId) : ZERO_ADDRESS.replace("0x", "0x" + "0".repeat(64)).slice(0, 66);
|
|
2329
2402
|
const voucherData = {
|
|
2330
2403
|
tokenId,
|
|
2331
2404
|
uri: metadata.image,
|
|
2332
2405
|
// Will be IPFS URI
|
|
2333
2406
|
creator: creatorAddress,
|
|
2334
|
-
royaltyBps
|
|
2335
|
-
|
|
2407
|
+
royaltyBps,
|
|
2408
|
+
// Use the validated/defaulted value
|
|
2409
|
+
deadline,
|
|
2410
|
+
price: priceInWei,
|
|
2411
|
+
currency: currencyAddress,
|
|
2412
|
+
nonce: voucherNonce,
|
|
2413
|
+
contentHash,
|
|
2414
|
+
userId,
|
|
2415
|
+
watermarkTimestamp,
|
|
2416
|
+
sessionId
|
|
2336
2417
|
};
|
|
2337
2418
|
const domain = {
|
|
2338
2419
|
...NFT_VOUCHER_DOMAIN,
|
|
@@ -2341,10 +2422,37 @@ var ZubariNFTProtocol = class {
|
|
|
2341
2422
|
};
|
|
2342
2423
|
const signature = await signer.signTypedData(domain, NFT_VOUCHER_TYPES, voucherData);
|
|
2343
2424
|
return {
|
|
2344
|
-
|
|
2345
|
-
|
|
2425
|
+
tokenId,
|
|
2426
|
+
uri: metadata.image,
|
|
2427
|
+
creator: creatorAddress,
|
|
2428
|
+
royaltyBps,
|
|
2429
|
+
// Use the validated/defaulted value
|
|
2430
|
+
deadline,
|
|
2431
|
+
signature,
|
|
2432
|
+
price: priceInWei,
|
|
2433
|
+
currency: currencyAddress,
|
|
2434
|
+
nonce: voucherNonce,
|
|
2435
|
+
contentHash: watermarking ? contentHash : void 0,
|
|
2436
|
+
userId: watermarking ? userId : void 0,
|
|
2437
|
+
watermarkTimestamp: watermarking ? watermarkTimestamp : void 0,
|
|
2438
|
+
sessionId: watermarking ? sessionId : void 0
|
|
2346
2439
|
};
|
|
2347
2440
|
}
|
|
2441
|
+
/**
|
|
2442
|
+
* @deprecated Use createLazyMintVoucher(params, signer) instead
|
|
2443
|
+
* Legacy method for backward compatibility
|
|
2444
|
+
*/
|
|
2445
|
+
async createLazyMintVoucherLegacy(metadata, creatorAddress, signer) {
|
|
2446
|
+
return this.createLazyMintVoucher(
|
|
2447
|
+
{
|
|
2448
|
+
metadata,
|
|
2449
|
+
creatorAddress,
|
|
2450
|
+
price: "0.01",
|
|
2451
|
+
currency: "ETH"
|
|
2452
|
+
},
|
|
2453
|
+
signer
|
|
2454
|
+
);
|
|
2455
|
+
}
|
|
2348
2456
|
/**
|
|
2349
2457
|
* Redeem a lazy mint voucher to mint the NFT on-chain
|
|
2350
2458
|
*/
|
|
@@ -6209,6 +6317,6 @@ function normalizeAddress(address) {
|
|
|
6209
6317
|
return address.toLowerCase();
|
|
6210
6318
|
}
|
|
6211
6319
|
|
|
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 };
|
|
6320
|
+
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
6321
|
//# sourceMappingURL=index.mjs.map
|
|
6214
6322
|
//# sourceMappingURL=index.mjs.map
|