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