@zubari/sdk 0.3.7 → 0.4.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.
Files changed (45) hide show
  1. package/dist/PayoutsProtocol-B5z8SEA-.d.ts +734 -0
  2. package/dist/PayoutsProtocol-CLiMFe54.d.mts +734 -0
  3. package/dist/{TransactionService-DuMJmrG3.d.mts → TransactionService-1Jt8ZRqO.d.mts} +1 -1
  4. package/dist/{TransactionService-DURp3bRL.d.ts → TransactionService-Djonkbp4.d.ts} +1 -1
  5. package/dist/{WalletManager-CmiNyapl.d.ts → WalletManager-DfvFJ-mk.d.ts} +12 -1
  6. package/dist/{WalletManager-DXt6vihp.d.mts → WalletManager-j0tgNIKi.d.mts} +12 -1
  7. package/dist/{index-CRsZrlN0.d.mts → index-BnlkQ9B6.d.ts} +5 -2
  8. package/dist/{index-DF0Gf8NK.d.mts → index-CTyZlHKg.d.mts} +7 -1
  9. package/dist/{index-DF0Gf8NK.d.ts → index-CTyZlHKg.d.ts} +7 -1
  10. package/dist/{index-VNzO49qu.d.ts → index-QLZi5YRN.d.mts} +5 -2
  11. package/dist/index.d.mts +21 -5
  12. package/dist/index.d.ts +21 -5
  13. package/dist/index.js +152 -38
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +152 -38
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/protocols/index.d.mts +102 -502
  18. package/dist/protocols/index.d.ts +102 -502
  19. package/dist/protocols/index.js +1849 -2
  20. package/dist/protocols/index.js.map +1 -1
  21. package/dist/protocols/index.mjs +1849 -3
  22. package/dist/protocols/index.mjs.map +1 -1
  23. package/dist/react/index.d.mts +7 -3
  24. package/dist/react/index.d.ts +7 -3
  25. package/dist/react/index.js +136 -21
  26. package/dist/react/index.js.map +1 -1
  27. package/dist/react/index.mjs +136 -21
  28. package/dist/react/index.mjs.map +1 -1
  29. package/dist/services/index.d.mts +2 -2
  30. package/dist/services/index.d.ts +2 -2
  31. package/dist/services/index.js +6 -6
  32. package/dist/services/index.js.map +1 -1
  33. package/dist/services/index.mjs +6 -6
  34. package/dist/services/index.mjs.map +1 -1
  35. package/dist/storage/index.js +61 -3
  36. package/dist/storage/index.js.map +1 -1
  37. package/dist/storage/index.mjs +61 -3
  38. package/dist/storage/index.mjs.map +1 -1
  39. package/dist/wallet/index.d.mts +3 -3
  40. package/dist/wallet/index.d.ts +3 -3
  41. package/dist/wallet/index.js +150 -36
  42. package/dist/wallet/index.js.map +1 -1
  43. package/dist/wallet/index.mjs +150 -36
  44. package/dist/wallet/index.mjs.map +1 -1
  45. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -35,7 +35,7 @@ var NETWORKS = {
35
35
  chainId: 1,
36
36
  coinType: 60,
37
37
  // m/44'/60'
38
- rpcUrl: "https://eth.llamarpc.com",
38
+ rpcUrl: "https://ethereum-rpc.publicnode.com",
39
39
  explorerUrl: "https://etherscan.io",
40
40
  nativeCurrency: {
41
41
  name: "Ether",
@@ -144,34 +144,47 @@ function getNetworkConfig(network, isTestnet = false) {
144
144
  var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
145
145
  var ZUBARI_CONTRACTS = {
146
146
  testnet: {
147
- // Ethereum Sepolia (11155111) - Deployed 2024-12-31
148
- registry: "0xe5CE1Eb986f58BE42EEDFe5C18ee5956803b2BDC",
149
- nft: "0xc165b8C6843e8f0B1489525D0f853d23f22c677B",
147
+ // Ethereum Sepolia (11155111) - Updated 2025-01-18
148
+ // Treasury: 0xAC2e22B5a99F0123319644A9bF0DF4FD72c9b001
149
+ // Platform Fee: 10% (1000 bps)
150
+ registry: "0xcEd503aeD6E2F6884A7eAB4226D15477d863B084",
151
+ nft: "0xc61497530E08897CCf518cbF9DA1A327983192E1",
150
152
  // ZubariNFT ERC-721 with payment
151
153
  nft1155: "0x5e618B5bEaE1dc41369E7aa235Cc3b9245905192",
152
154
  // Zubari1155 ERC-1155 multi-edition
153
- marketplace: "0xfcEfDa6C73aC357b8695E5F8F8d17820750BF207",
154
- tips: "0x86a9A306C7fCC9e0B8cd6859f6f15498d0046BB7",
155
- subscriptions: "0xaB7F17A85F61d9ab9f96bCB4e73e910D019978F7",
156
- payouts: "0x8aaB23Fb2a83A259E965Aae8Ee0938b1400B7E6b",
155
+ marketplace: "0x64B8fC45bB669a1bD672bD5ab76f82B7EE3B2e0f",
156
+ tips: "0xFDc353edC63Cd3D4bba35bB43861369516a9Dc85",
157
+ // ZubariTips - 10% fee
158
+ subscriptions: "0x8C05F8aD2F295fB7f3596043a7c37C98A5F7fAB8",
159
+ // ZubariSubscription - 10% fee
160
+ subscriptionsV2: ZERO_ADDRESS,
161
+ subscriptionsSimple: ZERO_ADDRESS,
162
+ creatorRegistry: ZERO_ADDRESS,
163
+ payouts: "0x804Fe503936E8b8d3D5Dbb62AF4fB6Fe7265Fb2c",
164
+ // ZubariPayouts
157
165
  entryPoint: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
158
166
  paymaster: ZERO_ADDRESS,
159
167
  // Deploy with: npx hardhat run deploy/deploy.ts --network ethereum-sepolia
160
168
  accountFactory: ZERO_ADDRESS,
161
169
  // Not yet deployed
162
- usdt: "0xaA8E23Fb1079EA71e0a56F48a2aA51851D8433D0",
163
- // USDT on Sepolia
170
+ usdt: "0x7169D38820dfd117C3FA1f22a697dBA58d90BA06",
171
+ // USDT on Sepolia (mintable test token)
164
172
  weth: "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14"
165
173
  },
166
174
  mainnet: {
167
- // Ethereum Mainnet (1)
168
- registry: ZERO_ADDRESS,
169
- nft: ZERO_ADDRESS,
170
- nft1155: ZERO_ADDRESS,
171
- marketplace: ZERO_ADDRESS,
172
- tips: ZERO_ADDRESS,
173
- subscriptions: ZERO_ADDRESS,
174
- payouts: ZERO_ADDRESS,
175
+ // Ethereum Mainnet (1) - Deployed 2025-01-22
176
+ // Owner/Treasury: Safe 0x436fE1eff6056aCc8c34d8ADe0C54B8AcF90DCAa
177
+ // Platform Fee: 10% (1000 bps)
178
+ registry: "0x1DA6880bc730e96cFA24d614D12012f9f81C3239",
179
+ nft: "0x19842D60a81bd65Bd9352A380C3b37dc2E0a5731",
180
+ nft1155: "0xDA824094c3ADdaC49e2480a699E2B21ca234BeD6",
181
+ marketplace: "0x8B0B3383644D0d374F4E047fC37e11F00f716b3A",
182
+ tips: "0x38D7Fc0592bCF094e1880c19a34f98c6A36b68D8",
183
+ subscriptions: "0xDA774d657B04Ab8744bfF09D18EeAce27E3F3DEa",
184
+ subscriptionsV2: "0x7abbaFe67941036bBF7dB7006855C55014d6012A",
185
+ subscriptionsSimple: "0xd0C07722a29D8aC7d137e59dCA114b031B4411E8",
186
+ creatorRegistry: "0xe5CE1Eb986f58BE42EEDFe5C18ee5956803b2BDC",
187
+ payouts: "0x74fc8cC0B5A92c90ae35caEB0E388Ea30424cc79",
175
188
  entryPoint: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
176
189
  paymaster: ZERO_ADDRESS,
177
190
  accountFactory: ZERO_ADDRESS,
@@ -284,7 +297,7 @@ var WdkApiClient = class {
284
297
  /**
285
298
  * Derive address for a specific chain using Tether WDK
286
299
  */
287
- async deriveAddress(seed, chain, network = "testnet") {
300
+ async deriveAddress(seed, chain, network = "mainnet") {
288
301
  try {
289
302
  const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-address`, {
290
303
  method: "POST",
@@ -304,7 +317,7 @@ var WdkApiClient = class {
304
317
  /**
305
318
  * Derive addresses for all chains using Tether WDK
306
319
  */
307
- async deriveAllAddresses(seed, network = "testnet") {
320
+ async deriveAllAddresses(seed, network = "mainnet") {
308
321
  try {
309
322
  const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-all`, {
310
323
  method: "POST",
@@ -324,7 +337,7 @@ var WdkApiClient = class {
324
337
  /**
325
338
  * Send a transaction on a specific chain using Tether WDK
326
339
  */
327
- async sendTransaction(seed, chain, to, amount, network = "testnet") {
340
+ async sendTransaction(seed, chain, to, amount, network = "mainnet") {
328
341
  try {
329
342
  const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/send`, {
330
343
  method: "POST",
@@ -345,7 +358,7 @@ var WdkApiClient = class {
345
358
  * Get transaction history for an address on a specific chain
346
359
  * Fetches from blockchain explorers (Etherscan, mempool.space, etc.)
347
360
  */
348
- async getTransactionHistory(seed, chain, network = "testnet", limit = 10) {
361
+ async getTransactionHistory(seed, chain, network = "mainnet", limit = 10) {
349
362
  try {
350
363
  const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/history`, {
351
364
  method: "POST",
@@ -366,7 +379,7 @@ var WdkApiClient = class {
366
379
  * Get transaction status by hash
367
380
  * Fetches from blockchain explorers to check confirmation status
368
381
  */
369
- async getTransactionStatus(txHash, chain, network = "testnet") {
382
+ async getTransactionStatus(txHash, chain, network = "mainnet") {
370
383
  try {
371
384
  const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/tx-status`, {
372
385
  method: "POST",
@@ -612,7 +625,7 @@ var ZubariWdkService = class {
612
625
  useNativeWdk = false;
613
626
  constructor(config = {}) {
614
627
  this.config = {
615
- network: config.network || "testnet",
628
+ network: config.network || "mainnet",
616
629
  apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || DEFAULT_API_URL2,
617
630
  forceApi: config.forceApi ?? false,
618
631
  timeout: config.timeout || 3e4
@@ -1559,13 +1572,71 @@ var KeyManager = class {
1559
1572
  ["encrypt", "decrypt"]
1560
1573
  );
1561
1574
  }
1575
+ /**
1576
+ * Normalize a seed phrase by removing extra whitespace and special characters
1577
+ */
1578
+ static normalizeSeedPhrase(seed) {
1579
+ return seed.toLowerCase().replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000]/g, " ").replace(/[^\w\s]/g, " ").trim().split(/\s+/).join(" ");
1580
+ }
1581
+ /**
1582
+ * Validate a BIP-39 seed phrase
1583
+ * Returns { valid: boolean, error?: string, invalidWordIndex?: number }
1584
+ */
1585
+ static validateSeedPhraseDetailed(seed) {
1586
+ const normalizedSeed = this.normalizeSeedPhrase(seed);
1587
+ const words = normalizedSeed.split(" ");
1588
+ const validWordCounts = [12, 15, 18, 21, 24];
1589
+ if (!validWordCounts.includes(words.length)) {
1590
+ return {
1591
+ valid: false,
1592
+ error: `Seed phrase must be 12, 15, 18, 21, or 24 words. Got ${words.length} words.`
1593
+ };
1594
+ }
1595
+ const commonInvalidWords = ["th", "a", "an", "is", "are", "the", "be", "to", "of", "and", "in"];
1596
+ for (let i = 0; i < words.length; i++) {
1597
+ const word = words[i];
1598
+ if (!word || word.length === 0) {
1599
+ return {
1600
+ valid: false,
1601
+ error: `Empty word at position ${i + 1}`,
1602
+ invalidWordIndex: i,
1603
+ invalidWord: word
1604
+ };
1605
+ }
1606
+ if (word.length < 3) {
1607
+ return {
1608
+ valid: false,
1609
+ error: `Word "${word}" at position ${i + 1} is too short. BIP-39 words are at least 3 characters.`,
1610
+ invalidWordIndex: i,
1611
+ invalidWord: word
1612
+ };
1613
+ }
1614
+ if (commonInvalidWords.includes(word)) {
1615
+ return {
1616
+ valid: false,
1617
+ error: `Word "${word}" at position ${i + 1} is not a valid BIP-39 word.`,
1618
+ invalidWordIndex: i,
1619
+ invalidWord: word
1620
+ };
1621
+ }
1622
+ if (!/^[a-z]+$/.test(word)) {
1623
+ return {
1624
+ valid: false,
1625
+ error: `Word "${word}" at position ${i + 1} contains invalid characters. Words should only contain letters.`,
1626
+ invalidWordIndex: i,
1627
+ invalidWord: word
1628
+ };
1629
+ }
1630
+ }
1631
+ return { valid: true, normalizedSeed };
1632
+ }
1562
1633
  /**
1563
1634
  * Validate a BIP-39 seed phrase (basic validation)
1635
+ * @deprecated Use validateSeedPhraseDetailed for better error messages
1564
1636
  */
1565
1637
  static validateSeedPhrase(seed) {
1566
- const words = seed.trim().split(/\s+/);
1567
- const validWordCounts = [12, 15, 18, 21, 24];
1568
- return validWordCounts.includes(words.length);
1638
+ const result = this.validateSeedPhraseDetailed(seed);
1639
+ return result.valid;
1569
1640
  }
1570
1641
  /**
1571
1642
  * Generate a random encryption key (for backup purposes)
@@ -1845,11 +1916,12 @@ var WalletManager = class _WalletManager {
1845
1916
  const isTestnet = config.network !== "mainnet";
1846
1917
  const ethereumConfig = getNetworkConfig("ethereum", isTestnet);
1847
1918
  this.config = {
1848
- network: config.network || "testnet",
1919
+ network: config.network || "mainnet",
1849
1920
  rpcUrl: config.rpcUrl || ethereumConfig.rpcUrl,
1850
1921
  storage: config.storage || createSecureStorage(),
1851
1922
  enabledChains: config.enabledChains || SUPPORTED_CHAINS,
1852
- apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com"
1923
+ apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com",
1924
+ accessToken: config.accessToken
1853
1925
  };
1854
1926
  this.storage = this.config.storage;
1855
1927
  this.wdkService = getZubariWdkService({
@@ -1926,13 +1998,30 @@ var WalletManager = class _WalletManager {
1926
1998
  * Import an existing wallet from seed phrase
1927
1999
  */
1928
2000
  async importWallet(seed, password) {
1929
- if (!_WalletManager.validateSeed(seed)) {
1930
- throw new Error("Invalid seed phrase");
2001
+ const normalizedSeed = KeyManager.normalizeSeedPhrase(seed);
2002
+ const validation = KeyManager.validateSeedPhraseDetailed(normalizedSeed);
2003
+ if (!validation.valid) {
2004
+ throw new Error(validation.error || "Invalid seed phrase");
1931
2005
  }
1932
- const address = _WalletManager.deriveAddress(seed);
1933
- const encrypted = await KeyManager.encryptSeed(seed, password);
2006
+ let address;
2007
+ try {
2008
+ address = _WalletManager.deriveAddress(normalizedSeed);
2009
+ } catch (error) {
2010
+ const errorMessage = error.message || "";
2011
+ const match = errorMessage.match(/invalid mnemonic word at index (\d+)/i);
2012
+ if (match) {
2013
+ const wordIndex = parseInt(match[1], 10);
2014
+ const words = normalizedSeed.split(" ");
2015
+ const invalidWord = words[wordIndex] || "unknown";
2016
+ throw new Error(
2017
+ `Invalid word "${invalidWord}" at position ${wordIndex + 1}. Please check your seed phrase for typos.`
2018
+ );
2019
+ }
2020
+ throw new Error(`Invalid seed phrase: ${errorMessage}`);
2021
+ }
2022
+ const encrypted = await KeyManager.encryptSeed(normalizedSeed, password);
1934
2023
  await this.storage.setItem(STORAGE_KEYS.ENCRYPTED_SEED, encrypted);
1935
- this.currentSeed = seed;
2024
+ this.currentSeed = normalizedSeed;
1936
2025
  this.derivedAddress = address;
1937
2026
  return { address };
1938
2027
  }
@@ -2068,6 +2157,19 @@ var WalletManager = class _WalletManager {
2068
2157
  const stored = await this.storage.getItem(STORAGE_KEYS.ACTIVE_WALLET);
2069
2158
  return stored === "metamask" || stored === "wdk" ? stored : "metamask";
2070
2159
  }
2160
+ /**
2161
+ * Set access token for authenticated API requests
2162
+ * This allows updating the token after initialization (e.g., after login)
2163
+ */
2164
+ setAccessToken(token) {
2165
+ this.config.accessToken = token;
2166
+ }
2167
+ /**
2168
+ * Get current access token
2169
+ */
2170
+ getAccessToken() {
2171
+ return this.config.accessToken;
2172
+ }
2071
2173
  // ==========================================
2072
2174
  // Multi-Chain Support Methods (Powered by Tether WDK)
2073
2175
  // ==========================================
@@ -2497,9 +2599,15 @@ var WalletManager = class _WalletManager {
2497
2599
  return { success: false, error: `No address for chain ${chain}` };
2498
2600
  }
2499
2601
  try {
2602
+ const headers = {
2603
+ "Content-Type": "application/json"
2604
+ };
2605
+ if (this.config.accessToken) {
2606
+ headers["Authorization"] = `Bearer ${this.config.accessToken}`;
2607
+ }
2500
2608
  const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/send`, {
2501
2609
  method: "POST",
2502
- headers: { "Content-Type": "application/json" },
2610
+ headers,
2503
2611
  body: JSON.stringify({
2504
2612
  seed: this.currentSeed,
2505
2613
  chain,
@@ -2546,9 +2654,15 @@ var WalletManager = class _WalletManager {
2546
2654
  */
2547
2655
  async estimateFee(chain, to, amount, token) {
2548
2656
  try {
2657
+ const headers = {
2658
+ "Content-Type": "application/json"
2659
+ };
2660
+ if (this.config.accessToken) {
2661
+ headers["Authorization"] = `Bearer ${this.config.accessToken}`;
2662
+ }
2549
2663
  const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/estimate-fee`, {
2550
2664
  method: "POST",
2551
- headers: { "Content-Type": "application/json" },
2665
+ headers,
2552
2666
  body: JSON.stringify({
2553
2667
  chain,
2554
2668
  to,
@@ -5188,7 +5302,7 @@ var ZubariTipsProtocol = class {
5188
5302
  const decoded = iface.decodeFunctionResult("platformFeeBps", result);
5189
5303
  return Number(decoded[0]);
5190
5304
  } catch {
5191
- return 300;
5305
+ return 1e3;
5192
5306
  }
5193
5307
  }
5194
5308
  /**
@@ -6428,7 +6542,7 @@ var ZubariSubscriptionProtocol = class {
6428
6542
  const decoded = iface.decodeFunctionResult("platformFeeBps", result);
6429
6543
  return Number(decoded[0]);
6430
6544
  } catch {
6431
- return 300;
6545
+ return 1e3;
6432
6546
  }
6433
6547
  }
6434
6548
  /**