@zubari/sdk 0.3.7 → 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 +14 -16
package/dist/react/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { W as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, b as WalletManager } from '../WalletManager-
|
|
3
|
-
export { S as SUPPORTED_CHAINS } from '../WalletManager-
|
|
4
|
-
import '
|
|
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-pVFpurEi.mjs';
|
|
3
|
+
export { S as SUPPORTED_CHAINS } from '../WalletManager-pVFpurEi.mjs';
|
|
4
|
+
import 'node_modules/viem/_types/actions/siwe/verifySiweMessage';
|
|
5
|
+
import 'node_modules/viem/_types/utils/ccip';
|
|
5
6
|
import 'viem';
|
|
6
7
|
import 'ethers';
|
|
7
8
|
import '../SecureStorage-jO783AhC.mjs';
|
|
@@ -15,6 +16,8 @@ import '../SecureStorage-jO783AhC.mjs';
|
|
|
15
16
|
|
|
16
17
|
interface UseWalletManagerOptions extends WalletManagerConfig {
|
|
17
18
|
autoCheckWallet?: boolean;
|
|
19
|
+
/** Access token for authenticated API requests (can be updated via setAccessToken) */
|
|
20
|
+
accessToken?: string;
|
|
18
21
|
}
|
|
19
22
|
/** Transaction result from sendTransaction */
|
|
20
23
|
interface SendTransactionResult {
|
|
@@ -55,6 +58,8 @@ interface UseWalletManagerReturn {
|
|
|
55
58
|
supportedChains: NetworkType[];
|
|
56
59
|
sendTransaction: (chain: NetworkType, to: string, amount: string, token?: string) => Promise<SendTransactionResult>;
|
|
57
60
|
estimateFee: (chain: NetworkType, to: string, amount: string, token?: string) => Promise<FeeEstimateResult>;
|
|
61
|
+
setAccessToken: (token: string | undefined) => void;
|
|
62
|
+
getAccessToken: () => string | undefined;
|
|
58
63
|
hasWallet: () => Promise<boolean>;
|
|
59
64
|
getSeed: () => string | null;
|
|
60
65
|
manager: WalletManager;
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { W as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, b as WalletManager } from '../WalletManager-
|
|
3
|
-
export { S as SUPPORTED_CHAINS } from '../WalletManager-
|
|
4
|
-
import '
|
|
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-BJaLBfX5.js';
|
|
3
|
+
export { S as SUPPORTED_CHAINS } from '../WalletManager-BJaLBfX5.js';
|
|
4
|
+
import 'node_modules/viem/_types/actions/siwe/verifySiweMessage';
|
|
5
|
+
import 'node_modules/viem/_types/utils/ccip';
|
|
5
6
|
import 'viem';
|
|
6
7
|
import 'ethers';
|
|
7
8
|
import '../SecureStorage-jO783AhC.js';
|
|
@@ -15,6 +16,8 @@ import '../SecureStorage-jO783AhC.js';
|
|
|
15
16
|
|
|
16
17
|
interface UseWalletManagerOptions extends WalletManagerConfig {
|
|
17
18
|
autoCheckWallet?: boolean;
|
|
19
|
+
/** Access token for authenticated API requests (can be updated via setAccessToken) */
|
|
20
|
+
accessToken?: string;
|
|
18
21
|
}
|
|
19
22
|
/** Transaction result from sendTransaction */
|
|
20
23
|
interface SendTransactionResult {
|
|
@@ -55,6 +58,8 @@ interface UseWalletManagerReturn {
|
|
|
55
58
|
supportedChains: NetworkType[];
|
|
56
59
|
sendTransaction: (chain: NetworkType, to: string, amount: string, token?: string) => Promise<SendTransactionResult>;
|
|
57
60
|
estimateFee: (chain: NetworkType, to: string, amount: string, token?: string) => Promise<FeeEstimateResult>;
|
|
61
|
+
setAccessToken: (token: string | undefined) => void;
|
|
62
|
+
getAccessToken: () => string | undefined;
|
|
58
63
|
hasWallet: () => Promise<boolean>;
|
|
59
64
|
getSeed: () => string | null;
|
|
60
65
|
manager: WalletManager;
|
package/dist/react/index.js
CHANGED
|
@@ -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
|
|
949
|
-
|
|
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)
|
|
@@ -1231,7 +1289,8 @@ var WalletManager = class _WalletManager {
|
|
|
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
|
-
|
|
1312
|
-
|
|
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
|
-
|
|
1315
|
-
|
|
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 =
|
|
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
|
|
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
|
|
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,
|