@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
@@ -1,6 +1,6 @@
1
- import { a as NetworkType } from '../index-DF0Gf8NK.mjs';
2
- import { W as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, b as WalletManager } from '../WalletManager-DXt6vihp.mjs';
3
- export { S as SUPPORTED_CHAINS } from '../WalletManager-DXt6vihp.mjs';
1
+ import { b as NetworkType } from '../index-CTyZlHKg.mjs';
2
+ import { W as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, b as WalletManager } from '../WalletManager-j0tgNIKi.mjs';
3
+ export { S as SUPPORTED_CHAINS } from '../WalletManager-j0tgNIKi.mjs';
4
4
  import 'abitype';
5
5
  import 'viem';
6
6
  import 'ethers';
@@ -15,6 +15,8 @@ import '../SecureStorage-jO783AhC.mjs';
15
15
 
16
16
  interface UseWalletManagerOptions extends WalletManagerConfig {
17
17
  autoCheckWallet?: boolean;
18
+ /** Access token for authenticated API requests (can be updated via setAccessToken) */
19
+ accessToken?: string;
18
20
  }
19
21
  /** Transaction result from sendTransaction */
20
22
  interface SendTransactionResult {
@@ -55,6 +57,8 @@ interface UseWalletManagerReturn {
55
57
  supportedChains: NetworkType[];
56
58
  sendTransaction: (chain: NetworkType, to: string, amount: string, token?: string) => Promise<SendTransactionResult>;
57
59
  estimateFee: (chain: NetworkType, to: string, amount: string, token?: string) => Promise<FeeEstimateResult>;
60
+ setAccessToken: (token: string | undefined) => void;
61
+ getAccessToken: () => string | undefined;
58
62
  hasWallet: () => Promise<boolean>;
59
63
  getSeed: () => string | null;
60
64
  manager: WalletManager;
@@ -1,6 +1,6 @@
1
- import { a as NetworkType } from '../index-DF0Gf8NK.js';
2
- import { W as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, b as WalletManager } from '../WalletManager-CmiNyapl.js';
3
- export { S as SUPPORTED_CHAINS } from '../WalletManager-CmiNyapl.js';
1
+ import { b as NetworkType } from '../index-CTyZlHKg.js';
2
+ import { W as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, b as WalletManager } from '../WalletManager-DfvFJ-mk.js';
3
+ export { S as SUPPORTED_CHAINS } from '../WalletManager-DfvFJ-mk.js';
4
4
  import 'abitype';
5
5
  import 'viem';
6
6
  import 'ethers';
@@ -15,6 +15,8 @@ import '../SecureStorage-jO783AhC.js';
15
15
 
16
16
  interface UseWalletManagerOptions extends WalletManagerConfig {
17
17
  autoCheckWallet?: boolean;
18
+ /** Access token for authenticated API requests (can be updated via setAccessToken) */
19
+ accessToken?: string;
18
20
  }
19
21
  /** Transaction result from sendTransaction */
20
22
  interface SendTransactionResult {
@@ -55,6 +57,8 @@ interface UseWalletManagerReturn {
55
57
  supportedChains: NetworkType[];
56
58
  sendTransaction: (chain: NetworkType, to: string, amount: string, token?: string) => Promise<SendTransactionResult>;
57
59
  estimateFee: (chain: NetworkType, to: string, amount: string, token?: string) => Promise<FeeEstimateResult>;
60
+ setAccessToken: (token: string | undefined) => void;
61
+ getAccessToken: () => string | undefined;
58
62
  hasWallet: () => Promise<boolean>;
59
63
  getSeed: () => string | null;
60
64
  manager: WalletManager;
@@ -34,7 +34,7 @@ var NETWORKS = {
34
34
  chainId: 1,
35
35
  coinType: 60,
36
36
  // m/44'/60'
37
- rpcUrl: "https://eth.llamarpc.com",
37
+ rpcUrl: "https://ethereum-rpc.publicnode.com",
38
38
  explorerUrl: "https://etherscan.io",
39
39
  nativeCurrency: {
40
40
  name: "Ether",
@@ -184,7 +184,7 @@ var WdkApiClient = class {
184
184
  /**
185
185
  * Derive address for a specific chain using Tether WDK
186
186
  */
187
- async deriveAddress(seed, chain, network = "testnet") {
187
+ async deriveAddress(seed, chain, network = "mainnet") {
188
188
  try {
189
189
  const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-address`, {
190
190
  method: "POST",
@@ -204,7 +204,7 @@ var WdkApiClient = class {
204
204
  /**
205
205
  * Derive addresses for all chains using Tether WDK
206
206
  */
207
- async deriveAllAddresses(seed, network = "testnet") {
207
+ async deriveAllAddresses(seed, network = "mainnet") {
208
208
  try {
209
209
  const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-all`, {
210
210
  method: "POST",
@@ -224,7 +224,7 @@ var WdkApiClient = class {
224
224
  /**
225
225
  * Send a transaction on a specific chain using Tether WDK
226
226
  */
227
- async sendTransaction(seed, chain, to, amount, network = "testnet") {
227
+ async sendTransaction(seed, chain, to, amount, network = "mainnet") {
228
228
  try {
229
229
  const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/send`, {
230
230
  method: "POST",
@@ -245,7 +245,7 @@ var WdkApiClient = class {
245
245
  * Get transaction history for an address on a specific chain
246
246
  * Fetches from blockchain explorers (Etherscan, mempool.space, etc.)
247
247
  */
248
- async getTransactionHistory(seed, chain, network = "testnet", limit = 10) {
248
+ async getTransactionHistory(seed, chain, network = "mainnet", limit = 10) {
249
249
  try {
250
250
  const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/history`, {
251
251
  method: "POST",
@@ -266,7 +266,7 @@ var WdkApiClient = class {
266
266
  * Get transaction status by hash
267
267
  * Fetches from blockchain explorers to check confirmation status
268
268
  */
269
- async getTransactionStatus(txHash, chain, network = "testnet") {
269
+ async getTransactionStatus(txHash, chain, network = "mainnet") {
270
270
  try {
271
271
  const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/tx-status`, {
272
272
  method: "POST",
@@ -498,7 +498,7 @@ var ZubariWdkService = class {
498
498
  useNativeWdk = false;
499
499
  constructor(config = {}) {
500
500
  this.config = {
501
- network: config.network || "testnet",
501
+ network: config.network || "mainnet",
502
502
  apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || DEFAULT_API_URL2,
503
503
  forceApi: config.forceApi ?? false,
504
504
  timeout: config.timeout || 3e4
@@ -941,13 +941,71 @@ var KeyManager = class {
941
941
  ["encrypt", "decrypt"]
942
942
  );
943
943
  }
944
+ /**
945
+ * Normalize a seed phrase by removing extra whitespace and special characters
946
+ */
947
+ static normalizeSeedPhrase(seed) {
948
+ return seed.toLowerCase().replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000]/g, " ").replace(/[^\w\s]/g, " ").trim().split(/\s+/).join(" ");
949
+ }
950
+ /**
951
+ * Validate a BIP-39 seed phrase
952
+ * Returns { valid: boolean, error?: string, invalidWordIndex?: number }
953
+ */
954
+ static validateSeedPhraseDetailed(seed) {
955
+ const normalizedSeed = this.normalizeSeedPhrase(seed);
956
+ const words = normalizedSeed.split(" ");
957
+ const validWordCounts = [12, 15, 18, 21, 24];
958
+ if (!validWordCounts.includes(words.length)) {
959
+ return {
960
+ valid: false,
961
+ error: `Seed phrase must be 12, 15, 18, 21, or 24 words. Got ${words.length} words.`
962
+ };
963
+ }
964
+ const commonInvalidWords = ["th", "a", "an", "is", "are", "the", "be", "to", "of", "and", "in"];
965
+ for (let i = 0; i < words.length; i++) {
966
+ const word = words[i];
967
+ if (!word || word.length === 0) {
968
+ return {
969
+ valid: false,
970
+ error: `Empty word at position ${i + 1}`,
971
+ invalidWordIndex: i,
972
+ invalidWord: word
973
+ };
974
+ }
975
+ if (word.length < 3) {
976
+ return {
977
+ valid: false,
978
+ error: `Word "${word}" at position ${i + 1} is too short. BIP-39 words are at least 3 characters.`,
979
+ invalidWordIndex: i,
980
+ invalidWord: word
981
+ };
982
+ }
983
+ if (commonInvalidWords.includes(word)) {
984
+ return {
985
+ valid: false,
986
+ error: `Word "${word}" at position ${i + 1} is not a valid BIP-39 word.`,
987
+ invalidWordIndex: i,
988
+ invalidWord: word
989
+ };
990
+ }
991
+ if (!/^[a-z]+$/.test(word)) {
992
+ return {
993
+ valid: false,
994
+ error: `Word "${word}" at position ${i + 1} contains invalid characters. Words should only contain letters.`,
995
+ invalidWordIndex: i,
996
+ invalidWord: word
997
+ };
998
+ }
999
+ }
1000
+ return { valid: true, normalizedSeed };
1001
+ }
944
1002
  /**
945
1003
  * Validate a BIP-39 seed phrase (basic validation)
1004
+ * @deprecated Use validateSeedPhraseDetailed for better error messages
946
1005
  */
947
1006
  static validateSeedPhrase(seed) {
948
- const words = seed.trim().split(/\s+/);
949
- const validWordCounts = [12, 15, 18, 21, 24];
950
- return validWordCounts.includes(words.length);
1007
+ const result = this.validateSeedPhraseDetailed(seed);
1008
+ return result.valid;
951
1009
  }
952
1010
  /**
953
1011
  * Generate a random encryption key (for backup purposes)
@@ -1227,11 +1285,12 @@ var WalletManager = class _WalletManager {
1227
1285
  const isTestnet = config.network !== "mainnet";
1228
1286
  const ethereumConfig = getNetworkConfig("ethereum", isTestnet);
1229
1287
  this.config = {
1230
- network: config.network || "testnet",
1288
+ network: config.network || "mainnet",
1231
1289
  rpcUrl: config.rpcUrl || ethereumConfig.rpcUrl,
1232
1290
  storage: config.storage || createSecureStorage(),
1233
1291
  enabledChains: config.enabledChains || SUPPORTED_CHAINS,
1234
- apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com"
1292
+ apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com",
1293
+ accessToken: config.accessToken
1235
1294
  };
1236
1295
  this.storage = this.config.storage;
1237
1296
  this.wdkService = getZubariWdkService({
@@ -1308,13 +1367,30 @@ var WalletManager = class _WalletManager {
1308
1367
  * Import an existing wallet from seed phrase
1309
1368
  */
1310
1369
  async importWallet(seed, password) {
1311
- if (!_WalletManager.validateSeed(seed)) {
1312
- throw new Error("Invalid seed phrase");
1370
+ const normalizedSeed = KeyManager.normalizeSeedPhrase(seed);
1371
+ const validation = KeyManager.validateSeedPhraseDetailed(normalizedSeed);
1372
+ if (!validation.valid) {
1373
+ throw new Error(validation.error || "Invalid seed phrase");
1313
1374
  }
1314
- const address = _WalletManager.deriveAddress(seed);
1315
- const encrypted = await KeyManager.encryptSeed(seed, password);
1375
+ let address;
1376
+ try {
1377
+ address = _WalletManager.deriveAddress(normalizedSeed);
1378
+ } catch (error) {
1379
+ const errorMessage = error.message || "";
1380
+ const match = errorMessage.match(/invalid mnemonic word at index (\d+)/i);
1381
+ if (match) {
1382
+ const wordIndex = parseInt(match[1], 10);
1383
+ const words = normalizedSeed.split(" ");
1384
+ const invalidWord = words[wordIndex] || "unknown";
1385
+ throw new Error(
1386
+ `Invalid word "${invalidWord}" at position ${wordIndex + 1}. Please check your seed phrase for typos.`
1387
+ );
1388
+ }
1389
+ throw new Error(`Invalid seed phrase: ${errorMessage}`);
1390
+ }
1391
+ const encrypted = await KeyManager.encryptSeed(normalizedSeed, password);
1316
1392
  await this.storage.setItem(STORAGE_KEYS.ENCRYPTED_SEED, encrypted);
1317
- this.currentSeed = seed;
1393
+ this.currentSeed = normalizedSeed;
1318
1394
  this.derivedAddress = address;
1319
1395
  return { address };
1320
1396
  }
@@ -1450,6 +1526,19 @@ var WalletManager = class _WalletManager {
1450
1526
  const stored = await this.storage.getItem(STORAGE_KEYS.ACTIVE_WALLET);
1451
1527
  return stored === "metamask" || stored === "wdk" ? stored : "metamask";
1452
1528
  }
1529
+ /**
1530
+ * Set access token for authenticated API requests
1531
+ * This allows updating the token after initialization (e.g., after login)
1532
+ */
1533
+ setAccessToken(token) {
1534
+ this.config.accessToken = token;
1535
+ }
1536
+ /**
1537
+ * Get current access token
1538
+ */
1539
+ getAccessToken() {
1540
+ return this.config.accessToken;
1541
+ }
1453
1542
  // ==========================================
1454
1543
  // Multi-Chain Support Methods (Powered by Tether WDK)
1455
1544
  // ==========================================
@@ -1879,9 +1968,15 @@ var WalletManager = class _WalletManager {
1879
1968
  return { success: false, error: `No address for chain ${chain}` };
1880
1969
  }
1881
1970
  try {
1971
+ const headers = {
1972
+ "Content-Type": "application/json"
1973
+ };
1974
+ if (this.config.accessToken) {
1975
+ headers["Authorization"] = `Bearer ${this.config.accessToken}`;
1976
+ }
1882
1977
  const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/send`, {
1883
1978
  method: "POST",
1884
- headers: { "Content-Type": "application/json" },
1979
+ headers,
1885
1980
  body: JSON.stringify({
1886
1981
  seed: this.currentSeed,
1887
1982
  chain,
@@ -1928,9 +2023,15 @@ var WalletManager = class _WalletManager {
1928
2023
  */
1929
2024
  async estimateFee(chain, to, amount, token) {
1930
2025
  try {
2026
+ const headers = {
2027
+ "Content-Type": "application/json"
2028
+ };
2029
+ if (this.config.accessToken) {
2030
+ headers["Authorization"] = `Bearer ${this.config.accessToken}`;
2031
+ }
1931
2032
  const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/estimate-fee`, {
1932
2033
  method: "POST",
1933
- headers: { "Content-Type": "application/json" },
2034
+ headers,
1934
2035
  body: JSON.stringify({
1935
2036
  chain,
1936
2037
  to,
@@ -1959,10 +2060,11 @@ var WalletManager = class _WalletManager {
1959
2060
 
1960
2061
  // src/react/useWalletManager.ts
1961
2062
  function useWalletManager(options = {}) {
1962
- const { autoCheckWallet = true, ...config } = options;
1963
- const manager = react.useMemo(() => new WalletManager(config), [
2063
+ const { autoCheckWallet = true, accessToken, ...config } = options;
2064
+ const manager = react.useMemo(() => new WalletManager({ ...config, accessToken }), [
1964
2065
  config.network,
1965
2066
  config.rpcUrl
2067
+ // Note: accessToken is handled separately via setAccessToken to avoid recreating manager
1966
2068
  ]);
1967
2069
  const [state, setState] = react.useState({
1968
2070
  isInitialized: false,
@@ -1990,6 +2092,16 @@ function useWalletManager(options = {}) {
1990
2092
  });
1991
2093
  }
1992
2094
  }, [manager, autoCheckWallet]);
2095
+ react.useEffect(() => {
2096
+ manager.setAccessToken(accessToken);
2097
+ }, [manager, accessToken]);
2098
+ const setAccessToken = react.useCallback(
2099
+ (token) => {
2100
+ manager.setAccessToken(token);
2101
+ },
2102
+ [manager]
2103
+ );
2104
+ const getAccessToken = react.useCallback(() => manager.getAccessToken(), [manager]);
1993
2105
  const createWallet = react.useCallback(
1994
2106
  async (password) => {
1995
2107
  setIsLoading(true);
@@ -2191,6 +2303,9 @@ function useWalletManager(options = {}) {
2191
2303
  // Transaction Actions (Powered by Tether WDK)
2192
2304
  sendTransaction,
2193
2305
  estimateFee,
2306
+ // Authentication
2307
+ setAccessToken,
2308
+ getAccessToken,
2194
2309
  // Utilities
2195
2310
  hasWallet,
2196
2311
  getSeed,