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