@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.
@@ -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,118 @@ 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) {
40
- if (metadata.royaltyBps > PLATFORM_CONFIG.maxRoyaltyBps) {
101
+ async createLazyMintVoucher(params, signer) {
102
+ const { metadata, creatorAddress, price, currency, nonce, watermarking } = params;
103
+ const royaltyBps = metadata.royaltyBps ?? 500;
104
+ if (royaltyBps > PLATFORM_CONFIG.maxRoyaltyBps) {
41
105
  throw new Error(`Royalty cannot exceed ${PLATFORM_CONFIG.maxRoyaltyBps / 100}%`);
42
106
  }
107
+ if (!price || parseFloat(price) <= 0) {
108
+ throw new Error("Price must be greater than 0");
109
+ }
43
110
  const tokenId = this.generateTokenId();
44
111
  const deadline = Math.floor(Date.now() / 1e3) + PLATFORM_CONFIG.voucherValiditySecs;
112
+ const priceInWei = this.priceToWei(price, currency);
113
+ const currencyAddress = this.getCurrencyAddress(currency);
114
+ const voucherNonce = nonce ?? this.generateNonce();
115
+ const watermarkTimestamp = watermarking ? Math.floor(Date.now() / 1e3) : 0;
116
+ const contentHash = watermarking ? this.toBytes32(watermarking.contentHash) : ZERO_ADDRESS.replace("0x", "0x" + "0".repeat(64)).slice(0, 66);
117
+ const userId = watermarking ? this.toBytes32(watermarking.userId) : ZERO_ADDRESS.replace("0x", "0x" + "0".repeat(64)).slice(0, 66);
118
+ const sessionId = watermarking ? this.toBytes32(watermarking.sessionId) : ZERO_ADDRESS.replace("0x", "0x" + "0".repeat(64)).slice(0, 66);
45
119
  const voucherData = {
46
120
  tokenId,
47
121
  uri: metadata.image,
48
122
  // Will be IPFS URI
49
123
  creator: creatorAddress,
50
- royaltyBps: metadata.royaltyBps,
51
- deadline
124
+ royaltyBps,
125
+ // Use the validated/defaulted value
126
+ deadline,
127
+ price: priceInWei,
128
+ currency: currencyAddress,
129
+ nonce: voucherNonce,
130
+ contentHash,
131
+ userId,
132
+ watermarkTimestamp,
133
+ sessionId
52
134
  };
53
135
  const domain = {
54
136
  ...NFT_VOUCHER_DOMAIN,
@@ -57,10 +139,37 @@ var ZubariNFTProtocol = class {
57
139
  };
58
140
  const signature = await signer.signTypedData(domain, NFT_VOUCHER_TYPES, voucherData);
59
141
  return {
60
- ...voucherData,
61
- signature
142
+ tokenId,
143
+ uri: metadata.image,
144
+ creator: creatorAddress,
145
+ royaltyBps,
146
+ // Use the validated/defaulted value
147
+ deadline,
148
+ signature,
149
+ price: priceInWei,
150
+ currency: currencyAddress,
151
+ nonce: voucherNonce,
152
+ contentHash: watermarking ? contentHash : void 0,
153
+ userId: watermarking ? userId : void 0,
154
+ watermarkTimestamp: watermarking ? watermarkTimestamp : void 0,
155
+ sessionId: watermarking ? sessionId : void 0
62
156
  };
63
157
  }
158
+ /**
159
+ * @deprecated Use createLazyMintVoucher(params, signer) instead
160
+ * Legacy method for backward compatibility
161
+ */
162
+ async createLazyMintVoucherLegacy(metadata, creatorAddress, signer) {
163
+ return this.createLazyMintVoucher(
164
+ {
165
+ metadata,
166
+ creatorAddress,
167
+ price: "0.01",
168
+ currency: "ETH"
169
+ },
170
+ signer
171
+ );
172
+ }
64
173
  /**
65
174
  * Redeem a lazy mint voucher to mint the NFT on-chain
66
175
  */