@zubari/sdk 0.3.7 → 0.3.8

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 (43) 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-VNzO49qu.d.ts → index-BZDwdQUe.d.mts} +3 -2
  8. package/dist/{index-CRsZrlN0.d.mts → index-CTb2uJpD.d.ts} +3 -2
  9. package/dist/{index-DF0Gf8NK.d.mts → index-CTyZlHKg.d.mts} +7 -1
  10. package/dist/{index-DF0Gf8NK.d.ts → index-CTyZlHKg.d.ts} +7 -1
  11. package/dist/index.d.mts +21 -5
  12. package/dist/index.d.ts +21 -5
  13. package/dist/index.js +120 -17
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +120 -17
  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 +1829 -0
  20. package/dist/protocols/index.js.map +1 -1
  21. package/dist/protocols/index.mjs +1829 -1
  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 +128 -13
  26. package/dist/react/index.js.map +1 -1
  27. package/dist/react/index.mjs +128 -13
  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.map +1 -1
  32. package/dist/services/index.mjs.map +1 -1
  33. package/dist/storage/index.js +61 -3
  34. package/dist/storage/index.js.map +1 -1
  35. package/dist/storage/index.mjs +61 -3
  36. package/dist/storage/index.mjs.map +1 -1
  37. package/dist/wallet/index.d.mts +3 -3
  38. package/dist/wallet/index.d.ts +3 -3
  39. package/dist/wallet/index.js +120 -17
  40. package/dist/wallet/index.js.map +1 -1
  41. package/dist/wallet/index.mjs +120 -17
  42. package/dist/wallet/index.mjs.map +1 -1
  43. package/package.json +1 -1
@@ -141,15 +141,16 @@ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
141
141
  var ZUBARI_CONTRACTS = {
142
142
  testnet: {
143
143
  // Ethereum Sepolia (11155111) - Deployed 2024-12-31
144
- registry: "0xe5CE1Eb986f58BE42EEDFe5C18ee5956803b2BDC",
145
- nft: "0xc165b8C6843e8f0B1489525D0f853d23f22c677B",
144
+ registry: "0xcEd503aeD6E2F6884A7eAB4226D15477d863B084",
145
+ nft: "0xc61497530E08897CCf518cbF9DA1A327983192E1",
146
146
  // ZubariNFT ERC-721 with payment
147
147
  nft1155: "0x5e618B5bEaE1dc41369E7aa235Cc3b9245905192",
148
148
  // Zubari1155 ERC-1155 multi-edition
149
- marketplace: "0xfcEfDa6C73aC357b8695E5F8F8d17820750BF207",
150
- tips: "0x86a9A306C7fCC9e0B8cd6859f6f15498d0046BB7",
151
- subscriptions: "0xaB7F17A85F61d9ab9f96bCB4e73e910D019978F7",
152
- payouts: "0x8aaB23Fb2a83A259E965Aae8Ee0938b1400B7E6b",
149
+ marketplace: "0x64B8fC45bB669a1bD672bD5ab76f82B7EE3B2e0f",
150
+ tips: "0x5ff64D0311dF0E3Fdf4e65FB878E355531f47f3F",
151
+ subscriptions: "0x152a175FaC027236afC3E00f7c85af5DF30a6fe2",
152
+ subscriptionsV2: ZERO_ADDRESS,
153
+ payouts: "0x637f0fFF94baF4eD1fDcBdF69d6b0646e6B9e0bA",
153
154
  entryPoint: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
154
155
  paymaster: ZERO_ADDRESS,
155
156
  // Deploy with: npx hardhat run deploy/deploy.ts --network ethereum-sepolia
@@ -167,6 +168,7 @@ var ZUBARI_CONTRACTS = {
167
168
  marketplace: ZERO_ADDRESS,
168
169
  tips: ZERO_ADDRESS,
169
170
  subscriptions: ZERO_ADDRESS,
171
+ subscriptionsV2: ZERO_ADDRESS,
170
172
  payouts: ZERO_ADDRESS,
171
173
  entryPoint: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
172
174
  paymaster: ZERO_ADDRESS,
@@ -1489,13 +1491,71 @@ var KeyManager = class {
1489
1491
  ["encrypt", "decrypt"]
1490
1492
  );
1491
1493
  }
1494
+ /**
1495
+ * Normalize a seed phrase by removing extra whitespace and special characters
1496
+ */
1497
+ static normalizeSeedPhrase(seed) {
1498
+ return seed.toLowerCase().replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000]/g, " ").replace(/[^\w\s]/g, " ").trim().split(/\s+/).join(" ");
1499
+ }
1500
+ /**
1501
+ * Validate a BIP-39 seed phrase
1502
+ * Returns { valid: boolean, error?: string, invalidWordIndex?: number }
1503
+ */
1504
+ static validateSeedPhraseDetailed(seed) {
1505
+ const normalizedSeed = this.normalizeSeedPhrase(seed);
1506
+ const words = normalizedSeed.split(" ");
1507
+ const validWordCounts = [12, 15, 18, 21, 24];
1508
+ if (!validWordCounts.includes(words.length)) {
1509
+ return {
1510
+ valid: false,
1511
+ error: `Seed phrase must be 12, 15, 18, 21, or 24 words. Got ${words.length} words.`
1512
+ };
1513
+ }
1514
+ const commonInvalidWords = ["th", "a", "an", "is", "are", "the", "be", "to", "of", "and", "in"];
1515
+ for (let i = 0; i < words.length; i++) {
1516
+ const word = words[i];
1517
+ if (!word || word.length === 0) {
1518
+ return {
1519
+ valid: false,
1520
+ error: `Empty word at position ${i + 1}`,
1521
+ invalidWordIndex: i,
1522
+ invalidWord: word
1523
+ };
1524
+ }
1525
+ if (word.length < 3) {
1526
+ return {
1527
+ valid: false,
1528
+ error: `Word "${word}" at position ${i + 1} is too short. BIP-39 words are at least 3 characters.`,
1529
+ invalidWordIndex: i,
1530
+ invalidWord: word
1531
+ };
1532
+ }
1533
+ if (commonInvalidWords.includes(word)) {
1534
+ return {
1535
+ valid: false,
1536
+ error: `Word "${word}" at position ${i + 1} is not a valid BIP-39 word.`,
1537
+ invalidWordIndex: i,
1538
+ invalidWord: word
1539
+ };
1540
+ }
1541
+ if (!/^[a-z]+$/.test(word)) {
1542
+ return {
1543
+ valid: false,
1544
+ error: `Word "${word}" at position ${i + 1} contains invalid characters. Words should only contain letters.`,
1545
+ invalidWordIndex: i,
1546
+ invalidWord: word
1547
+ };
1548
+ }
1549
+ }
1550
+ return { valid: true, normalizedSeed };
1551
+ }
1492
1552
  /**
1493
1553
  * Validate a BIP-39 seed phrase (basic validation)
1554
+ * @deprecated Use validateSeedPhraseDetailed for better error messages
1494
1555
  */
1495
1556
  static validateSeedPhrase(seed) {
1496
- const words = seed.trim().split(/\s+/);
1497
- const validWordCounts = [12, 15, 18, 21, 24];
1498
- return validWordCounts.includes(words.length);
1557
+ const result = this.validateSeedPhraseDetailed(seed);
1558
+ return result.valid;
1499
1559
  }
1500
1560
  /**
1501
1561
  * Generate a random encryption key (for backup purposes)
@@ -1779,7 +1839,8 @@ var WalletManager = class _WalletManager {
1779
1839
  rpcUrl: config.rpcUrl || ethereumConfig.rpcUrl,
1780
1840
  storage: config.storage || createSecureStorage(),
1781
1841
  enabledChains: config.enabledChains || SUPPORTED_CHAINS,
1782
- apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com"
1842
+ apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com",
1843
+ accessToken: config.accessToken
1783
1844
  };
1784
1845
  this.storage = this.config.storage;
1785
1846
  this.wdkService = getZubariWdkService({
@@ -1856,13 +1917,30 @@ var WalletManager = class _WalletManager {
1856
1917
  * Import an existing wallet from seed phrase
1857
1918
  */
1858
1919
  async importWallet(seed, password) {
1859
- if (!_WalletManager.validateSeed(seed)) {
1860
- throw new Error("Invalid seed phrase");
1920
+ const normalizedSeed = KeyManager.normalizeSeedPhrase(seed);
1921
+ const validation = KeyManager.validateSeedPhraseDetailed(normalizedSeed);
1922
+ if (!validation.valid) {
1923
+ throw new Error(validation.error || "Invalid seed phrase");
1861
1924
  }
1862
- const address = _WalletManager.deriveAddress(seed);
1863
- const encrypted = await KeyManager.encryptSeed(seed, password);
1925
+ let address;
1926
+ try {
1927
+ address = _WalletManager.deriveAddress(normalizedSeed);
1928
+ } catch (error) {
1929
+ const errorMessage = error.message || "";
1930
+ const match = errorMessage.match(/invalid mnemonic word at index (\d+)/i);
1931
+ if (match) {
1932
+ const wordIndex = parseInt(match[1], 10);
1933
+ const words = normalizedSeed.split(" ");
1934
+ const invalidWord = words[wordIndex] || "unknown";
1935
+ throw new Error(
1936
+ `Invalid word "${invalidWord}" at position ${wordIndex + 1}. Please check your seed phrase for typos.`
1937
+ );
1938
+ }
1939
+ throw new Error(`Invalid seed phrase: ${errorMessage}`);
1940
+ }
1941
+ const encrypted = await KeyManager.encryptSeed(normalizedSeed, password);
1864
1942
  await this.storage.setItem(STORAGE_KEYS.ENCRYPTED_SEED, encrypted);
1865
- this.currentSeed = seed;
1943
+ this.currentSeed = normalizedSeed;
1866
1944
  this.derivedAddress = address;
1867
1945
  return { address };
1868
1946
  }
@@ -1998,6 +2076,19 @@ var WalletManager = class _WalletManager {
1998
2076
  const stored = await this.storage.getItem(STORAGE_KEYS.ACTIVE_WALLET);
1999
2077
  return stored === "metamask" || stored === "wdk" ? stored : "metamask";
2000
2078
  }
2079
+ /**
2080
+ * Set access token for authenticated API requests
2081
+ * This allows updating the token after initialization (e.g., after login)
2082
+ */
2083
+ setAccessToken(token) {
2084
+ this.config.accessToken = token;
2085
+ }
2086
+ /**
2087
+ * Get current access token
2088
+ */
2089
+ getAccessToken() {
2090
+ return this.config.accessToken;
2091
+ }
2001
2092
  // ==========================================
2002
2093
  // Multi-Chain Support Methods (Powered by Tether WDK)
2003
2094
  // ==========================================
@@ -2427,9 +2518,15 @@ var WalletManager = class _WalletManager {
2427
2518
  return { success: false, error: `No address for chain ${chain}` };
2428
2519
  }
2429
2520
  try {
2521
+ const headers = {
2522
+ "Content-Type": "application/json"
2523
+ };
2524
+ if (this.config.accessToken) {
2525
+ headers["Authorization"] = `Bearer ${this.config.accessToken}`;
2526
+ }
2430
2527
  const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/send`, {
2431
2528
  method: "POST",
2432
- headers: { "Content-Type": "application/json" },
2529
+ headers,
2433
2530
  body: JSON.stringify({
2434
2531
  seed: this.currentSeed,
2435
2532
  chain,
@@ -2476,9 +2573,15 @@ var WalletManager = class _WalletManager {
2476
2573
  */
2477
2574
  async estimateFee(chain, to, amount, token) {
2478
2575
  try {
2576
+ const headers = {
2577
+ "Content-Type": "application/json"
2578
+ };
2579
+ if (this.config.accessToken) {
2580
+ headers["Authorization"] = `Bearer ${this.config.accessToken}`;
2581
+ }
2479
2582
  const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/estimate-fee`, {
2480
2583
  method: "POST",
2481
- headers: { "Content-Type": "application/json" },
2584
+ headers,
2482
2585
  body: JSON.stringify({
2483
2586
  chain,
2484
2587
  to,