@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/react/index.mjs
CHANGED
|
@@ -939,13 +939,71 @@ var KeyManager = class {
|
|
|
939
939
|
["encrypt", "decrypt"]
|
|
940
940
|
);
|
|
941
941
|
}
|
|
942
|
+
/**
|
|
943
|
+
* Normalize a seed phrase by removing extra whitespace and special characters
|
|
944
|
+
*/
|
|
945
|
+
static normalizeSeedPhrase(seed) {
|
|
946
|
+
return seed.toLowerCase().replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000]/g, " ").replace(/[^\w\s]/g, " ").trim().split(/\s+/).join(" ");
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* Validate a BIP-39 seed phrase
|
|
950
|
+
* Returns { valid: boolean, error?: string, invalidWordIndex?: number }
|
|
951
|
+
*/
|
|
952
|
+
static validateSeedPhraseDetailed(seed) {
|
|
953
|
+
const normalizedSeed = this.normalizeSeedPhrase(seed);
|
|
954
|
+
const words = normalizedSeed.split(" ");
|
|
955
|
+
const validWordCounts = [12, 15, 18, 21, 24];
|
|
956
|
+
if (!validWordCounts.includes(words.length)) {
|
|
957
|
+
return {
|
|
958
|
+
valid: false,
|
|
959
|
+
error: `Seed phrase must be 12, 15, 18, 21, or 24 words. Got ${words.length} words.`
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
const commonInvalidWords = ["th", "a", "an", "is", "are", "the", "be", "to", "of", "and", "in"];
|
|
963
|
+
for (let i = 0; i < words.length; i++) {
|
|
964
|
+
const word = words[i];
|
|
965
|
+
if (!word || word.length === 0) {
|
|
966
|
+
return {
|
|
967
|
+
valid: false,
|
|
968
|
+
error: `Empty word at position ${i + 1}`,
|
|
969
|
+
invalidWordIndex: i,
|
|
970
|
+
invalidWord: word
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
if (word.length < 3) {
|
|
974
|
+
return {
|
|
975
|
+
valid: false,
|
|
976
|
+
error: `Word "${word}" at position ${i + 1} is too short. BIP-39 words are at least 3 characters.`,
|
|
977
|
+
invalidWordIndex: i,
|
|
978
|
+
invalidWord: word
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
if (commonInvalidWords.includes(word)) {
|
|
982
|
+
return {
|
|
983
|
+
valid: false,
|
|
984
|
+
error: `Word "${word}" at position ${i + 1} is not a valid BIP-39 word.`,
|
|
985
|
+
invalidWordIndex: i,
|
|
986
|
+
invalidWord: word
|
|
987
|
+
};
|
|
988
|
+
}
|
|
989
|
+
if (!/^[a-z]+$/.test(word)) {
|
|
990
|
+
return {
|
|
991
|
+
valid: false,
|
|
992
|
+
error: `Word "${word}" at position ${i + 1} contains invalid characters. Words should only contain letters.`,
|
|
993
|
+
invalidWordIndex: i,
|
|
994
|
+
invalidWord: word
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
return { valid: true, normalizedSeed };
|
|
999
|
+
}
|
|
942
1000
|
/**
|
|
943
1001
|
* Validate a BIP-39 seed phrase (basic validation)
|
|
1002
|
+
* @deprecated Use validateSeedPhraseDetailed for better error messages
|
|
944
1003
|
*/
|
|
945
1004
|
static validateSeedPhrase(seed) {
|
|
946
|
-
const
|
|
947
|
-
|
|
948
|
-
return validWordCounts.includes(words.length);
|
|
1005
|
+
const result = this.validateSeedPhraseDetailed(seed);
|
|
1006
|
+
return result.valid;
|
|
949
1007
|
}
|
|
950
1008
|
/**
|
|
951
1009
|
* Generate a random encryption key (for backup purposes)
|
|
@@ -1229,7 +1287,8 @@ var WalletManager = class _WalletManager {
|
|
|
1229
1287
|
rpcUrl: config.rpcUrl || ethereumConfig.rpcUrl,
|
|
1230
1288
|
storage: config.storage || createSecureStorage(),
|
|
1231
1289
|
enabledChains: config.enabledChains || SUPPORTED_CHAINS,
|
|
1232
|
-
apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com"
|
|
1290
|
+
apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com",
|
|
1291
|
+
accessToken: config.accessToken
|
|
1233
1292
|
};
|
|
1234
1293
|
this.storage = this.config.storage;
|
|
1235
1294
|
this.wdkService = getZubariWdkService({
|
|
@@ -1306,13 +1365,30 @@ var WalletManager = class _WalletManager {
|
|
|
1306
1365
|
* Import an existing wallet from seed phrase
|
|
1307
1366
|
*/
|
|
1308
1367
|
async importWallet(seed, password) {
|
|
1309
|
-
|
|
1310
|
-
|
|
1368
|
+
const normalizedSeed = KeyManager.normalizeSeedPhrase(seed);
|
|
1369
|
+
const validation = KeyManager.validateSeedPhraseDetailed(normalizedSeed);
|
|
1370
|
+
if (!validation.valid) {
|
|
1371
|
+
throw new Error(validation.error || "Invalid seed phrase");
|
|
1311
1372
|
}
|
|
1312
|
-
|
|
1313
|
-
|
|
1373
|
+
let address;
|
|
1374
|
+
try {
|
|
1375
|
+
address = _WalletManager.deriveAddress(normalizedSeed);
|
|
1376
|
+
} catch (error) {
|
|
1377
|
+
const errorMessage = error.message || "";
|
|
1378
|
+
const match = errorMessage.match(/invalid mnemonic word at index (\d+)/i);
|
|
1379
|
+
if (match) {
|
|
1380
|
+
const wordIndex = parseInt(match[1], 10);
|
|
1381
|
+
const words = normalizedSeed.split(" ");
|
|
1382
|
+
const invalidWord = words[wordIndex] || "unknown";
|
|
1383
|
+
throw new Error(
|
|
1384
|
+
`Invalid word "${invalidWord}" at position ${wordIndex + 1}. Please check your seed phrase for typos.`
|
|
1385
|
+
);
|
|
1386
|
+
}
|
|
1387
|
+
throw new Error(`Invalid seed phrase: ${errorMessage}`);
|
|
1388
|
+
}
|
|
1389
|
+
const encrypted = await KeyManager.encryptSeed(normalizedSeed, password);
|
|
1314
1390
|
await this.storage.setItem(STORAGE_KEYS.ENCRYPTED_SEED, encrypted);
|
|
1315
|
-
this.currentSeed =
|
|
1391
|
+
this.currentSeed = normalizedSeed;
|
|
1316
1392
|
this.derivedAddress = address;
|
|
1317
1393
|
return { address };
|
|
1318
1394
|
}
|
|
@@ -1448,6 +1524,19 @@ var WalletManager = class _WalletManager {
|
|
|
1448
1524
|
const stored = await this.storage.getItem(STORAGE_KEYS.ACTIVE_WALLET);
|
|
1449
1525
|
return stored === "metamask" || stored === "wdk" ? stored : "metamask";
|
|
1450
1526
|
}
|
|
1527
|
+
/**
|
|
1528
|
+
* Set access token for authenticated API requests
|
|
1529
|
+
* This allows updating the token after initialization (e.g., after login)
|
|
1530
|
+
*/
|
|
1531
|
+
setAccessToken(token) {
|
|
1532
|
+
this.config.accessToken = token;
|
|
1533
|
+
}
|
|
1534
|
+
/**
|
|
1535
|
+
* Get current access token
|
|
1536
|
+
*/
|
|
1537
|
+
getAccessToken() {
|
|
1538
|
+
return this.config.accessToken;
|
|
1539
|
+
}
|
|
1451
1540
|
// ==========================================
|
|
1452
1541
|
// Multi-Chain Support Methods (Powered by Tether WDK)
|
|
1453
1542
|
// ==========================================
|
|
@@ -1877,9 +1966,15 @@ var WalletManager = class _WalletManager {
|
|
|
1877
1966
|
return { success: false, error: `No address for chain ${chain}` };
|
|
1878
1967
|
}
|
|
1879
1968
|
try {
|
|
1969
|
+
const headers = {
|
|
1970
|
+
"Content-Type": "application/json"
|
|
1971
|
+
};
|
|
1972
|
+
if (this.config.accessToken) {
|
|
1973
|
+
headers["Authorization"] = `Bearer ${this.config.accessToken}`;
|
|
1974
|
+
}
|
|
1880
1975
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/send`, {
|
|
1881
1976
|
method: "POST",
|
|
1882
|
-
headers
|
|
1977
|
+
headers,
|
|
1883
1978
|
body: JSON.stringify({
|
|
1884
1979
|
seed: this.currentSeed,
|
|
1885
1980
|
chain,
|
|
@@ -1926,9 +2021,15 @@ var WalletManager = class _WalletManager {
|
|
|
1926
2021
|
*/
|
|
1927
2022
|
async estimateFee(chain, to, amount, token) {
|
|
1928
2023
|
try {
|
|
2024
|
+
const headers = {
|
|
2025
|
+
"Content-Type": "application/json"
|
|
2026
|
+
};
|
|
2027
|
+
if (this.config.accessToken) {
|
|
2028
|
+
headers["Authorization"] = `Bearer ${this.config.accessToken}`;
|
|
2029
|
+
}
|
|
1929
2030
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/estimate-fee`, {
|
|
1930
2031
|
method: "POST",
|
|
1931
|
-
headers
|
|
2032
|
+
headers,
|
|
1932
2033
|
body: JSON.stringify({
|
|
1933
2034
|
chain,
|
|
1934
2035
|
to,
|
|
@@ -1957,10 +2058,11 @@ var WalletManager = class _WalletManager {
|
|
|
1957
2058
|
|
|
1958
2059
|
// src/react/useWalletManager.ts
|
|
1959
2060
|
function useWalletManager(options = {}) {
|
|
1960
|
-
const { autoCheckWallet = true, ...config } = options;
|
|
1961
|
-
const manager = useMemo(() => new WalletManager(config), [
|
|
2061
|
+
const { autoCheckWallet = true, accessToken, ...config } = options;
|
|
2062
|
+
const manager = useMemo(() => new WalletManager({ ...config, accessToken }), [
|
|
1962
2063
|
config.network,
|
|
1963
2064
|
config.rpcUrl
|
|
2065
|
+
// Note: accessToken is handled separately via setAccessToken to avoid recreating manager
|
|
1964
2066
|
]);
|
|
1965
2067
|
const [state, setState] = useState({
|
|
1966
2068
|
isInitialized: false,
|
|
@@ -1988,6 +2090,16 @@ function useWalletManager(options = {}) {
|
|
|
1988
2090
|
});
|
|
1989
2091
|
}
|
|
1990
2092
|
}, [manager, autoCheckWallet]);
|
|
2093
|
+
useEffect(() => {
|
|
2094
|
+
manager.setAccessToken(accessToken);
|
|
2095
|
+
}, [manager, accessToken]);
|
|
2096
|
+
const setAccessToken = useCallback(
|
|
2097
|
+
(token) => {
|
|
2098
|
+
manager.setAccessToken(token);
|
|
2099
|
+
},
|
|
2100
|
+
[manager]
|
|
2101
|
+
);
|
|
2102
|
+
const getAccessToken = useCallback(() => manager.getAccessToken(), [manager]);
|
|
1991
2103
|
const createWallet = useCallback(
|
|
1992
2104
|
async (password) => {
|
|
1993
2105
|
setIsLoading(true);
|
|
@@ -2189,6 +2301,9 @@ function useWalletManager(options = {}) {
|
|
|
2189
2301
|
// Transaction Actions (Powered by Tether WDK)
|
|
2190
2302
|
sendTransaction,
|
|
2191
2303
|
estimateFee,
|
|
2304
|
+
// Authentication
|
|
2305
|
+
setAccessToken,
|
|
2306
|
+
getAccessToken,
|
|
2192
2307
|
// Utilities
|
|
2193
2308
|
hasWallet,
|
|
2194
2309
|
getSeed,
|