@zubari/sdk 0.3.1 → 0.3.3
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/README.md +7 -0
- package/dist/{WalletManager-CEjN-YBF.d.ts → WalletManager-CmiNyapl.d.ts} +1 -1
- package/dist/{WalletManager-bo35aHOJ.d.mts → WalletManager-DXt6vihp.d.mts} +1 -1
- package/dist/{index-BpjMiC3n.d.ts → index-CGsF4p5I.d.ts} +1 -1
- package/dist/{index-DJnsirV5.d.mts → index-DwC0brJU.d.mts} +1 -1
- package/dist/index.d.mts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.js +0 -241
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -241
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/dist/wallet/index.d.mts +2 -2
- package/dist/wallet/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,6 @@ import { sha256 } from '@noble/hashes/sha256';
|
|
|
7
7
|
import { ripemd160 } from '@noble/hashes/ripemd160';
|
|
8
8
|
import { createPublicClient, http, formatEther } from 'viem';
|
|
9
9
|
import { mainnet, sepolia } from 'viem/chains';
|
|
10
|
-
import { useMemo, useState, useCallback, useEffect } from 'react';
|
|
11
10
|
|
|
12
11
|
var __defProp = Object.defineProperty;
|
|
13
12
|
var __export = (target, all) => {
|
|
@@ -7450,245 +7449,6 @@ var ZubariError = class extends Error {
|
|
|
7450
7449
|
this.name = "ZubariError";
|
|
7451
7450
|
}
|
|
7452
7451
|
};
|
|
7453
|
-
function useWalletManager(options = {}) {
|
|
7454
|
-
const { autoCheckWallet = true, ...config } = options;
|
|
7455
|
-
const manager = useMemo(() => new WalletManager(config), [
|
|
7456
|
-
config.network,
|
|
7457
|
-
config.rpcUrl
|
|
7458
|
-
]);
|
|
7459
|
-
const [state, setState] = useState({
|
|
7460
|
-
isInitialized: false,
|
|
7461
|
-
isLocked: true,
|
|
7462
|
-
address: null,
|
|
7463
|
-
balance: null
|
|
7464
|
-
});
|
|
7465
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
7466
|
-
const [error, setError] = useState(null);
|
|
7467
|
-
const [selectedChain, setSelectedChainState] = useState("ethereum");
|
|
7468
|
-
const [chainBalances, setChainBalances] = useState([]);
|
|
7469
|
-
const updateState = useCallback(() => {
|
|
7470
|
-
setState(manager.getExtendedState());
|
|
7471
|
-
}, [manager]);
|
|
7472
|
-
useEffect(() => {
|
|
7473
|
-
if (autoCheckWallet) {
|
|
7474
|
-
manager.hasWallet().then((exists) => {
|
|
7475
|
-
if (exists) {
|
|
7476
|
-
setState((prev) => ({
|
|
7477
|
-
...prev,
|
|
7478
|
-
isInitialized: true,
|
|
7479
|
-
isLocked: true
|
|
7480
|
-
}));
|
|
7481
|
-
}
|
|
7482
|
-
});
|
|
7483
|
-
}
|
|
7484
|
-
}, [manager, autoCheckWallet]);
|
|
7485
|
-
const createWallet = useCallback(
|
|
7486
|
-
async (password) => {
|
|
7487
|
-
setIsLoading(true);
|
|
7488
|
-
setError(null);
|
|
7489
|
-
try {
|
|
7490
|
-
await manager.initializeStorage(password);
|
|
7491
|
-
const result = await manager.createWallet(password);
|
|
7492
|
-
try {
|
|
7493
|
-
await manager.deriveAllAddressesAsync();
|
|
7494
|
-
} catch {
|
|
7495
|
-
manager.deriveAllAddresses();
|
|
7496
|
-
}
|
|
7497
|
-
updateState();
|
|
7498
|
-
try {
|
|
7499
|
-
const balances = await manager.fetchAllBalances();
|
|
7500
|
-
setChainBalances(balances);
|
|
7501
|
-
} catch (err) {
|
|
7502
|
-
console.warn("Failed to fetch balances after create:", err);
|
|
7503
|
-
}
|
|
7504
|
-
return result;
|
|
7505
|
-
} catch (err) {
|
|
7506
|
-
const message = err instanceof Error ? err.message : "Failed to create wallet";
|
|
7507
|
-
setError(message);
|
|
7508
|
-
throw err;
|
|
7509
|
-
} finally {
|
|
7510
|
-
setIsLoading(false);
|
|
7511
|
-
}
|
|
7512
|
-
},
|
|
7513
|
-
[manager, updateState]
|
|
7514
|
-
);
|
|
7515
|
-
const importWallet = useCallback(
|
|
7516
|
-
async (seed, password) => {
|
|
7517
|
-
setIsLoading(true);
|
|
7518
|
-
setError(null);
|
|
7519
|
-
try {
|
|
7520
|
-
await manager.initializeStorage(password);
|
|
7521
|
-
await manager.importWallet(seed, password);
|
|
7522
|
-
try {
|
|
7523
|
-
await manager.deriveAllAddressesAsync();
|
|
7524
|
-
} catch {
|
|
7525
|
-
manager.deriveAllAddresses();
|
|
7526
|
-
}
|
|
7527
|
-
updateState();
|
|
7528
|
-
try {
|
|
7529
|
-
const balances = await manager.fetchAllBalances();
|
|
7530
|
-
setChainBalances(balances);
|
|
7531
|
-
} catch (err) {
|
|
7532
|
-
console.warn("Failed to fetch balances after import:", err);
|
|
7533
|
-
}
|
|
7534
|
-
} catch (err) {
|
|
7535
|
-
const message = err instanceof Error ? err.message : "Failed to import wallet";
|
|
7536
|
-
setError(message);
|
|
7537
|
-
throw err;
|
|
7538
|
-
} finally {
|
|
7539
|
-
setIsLoading(false);
|
|
7540
|
-
}
|
|
7541
|
-
},
|
|
7542
|
-
[manager, updateState]
|
|
7543
|
-
);
|
|
7544
|
-
const unlock = useCallback(
|
|
7545
|
-
async (password) => {
|
|
7546
|
-
setIsLoading(true);
|
|
7547
|
-
setError(null);
|
|
7548
|
-
try {
|
|
7549
|
-
await manager.initializeStorage(password);
|
|
7550
|
-
await manager.unlock(password);
|
|
7551
|
-
try {
|
|
7552
|
-
await manager.deriveAllAddressesAsync();
|
|
7553
|
-
} catch {
|
|
7554
|
-
manager.deriveAllAddresses();
|
|
7555
|
-
}
|
|
7556
|
-
updateState();
|
|
7557
|
-
try {
|
|
7558
|
-
const balances = await manager.fetchAllBalances();
|
|
7559
|
-
setChainBalances(balances);
|
|
7560
|
-
} catch (err) {
|
|
7561
|
-
console.warn("Failed to fetch balances after unlock:", err);
|
|
7562
|
-
}
|
|
7563
|
-
} catch (err) {
|
|
7564
|
-
const message = err instanceof Error ? err.message : "Invalid password";
|
|
7565
|
-
setError(message);
|
|
7566
|
-
throw err;
|
|
7567
|
-
} finally {
|
|
7568
|
-
setIsLoading(false);
|
|
7569
|
-
}
|
|
7570
|
-
},
|
|
7571
|
-
[manager, updateState]
|
|
7572
|
-
);
|
|
7573
|
-
const lock = useCallback(() => {
|
|
7574
|
-
manager.lock();
|
|
7575
|
-
setChainBalances([]);
|
|
7576
|
-
updateState();
|
|
7577
|
-
}, [manager, updateState]);
|
|
7578
|
-
const deleteWallet = useCallback(async () => {
|
|
7579
|
-
setIsLoading(true);
|
|
7580
|
-
setError(null);
|
|
7581
|
-
try {
|
|
7582
|
-
await manager.deleteWallet();
|
|
7583
|
-
setChainBalances([]);
|
|
7584
|
-
setState({
|
|
7585
|
-
isInitialized: false,
|
|
7586
|
-
isLocked: true,
|
|
7587
|
-
address: null,
|
|
7588
|
-
balance: null
|
|
7589
|
-
});
|
|
7590
|
-
} catch (err) {
|
|
7591
|
-
const message = err instanceof Error ? err.message : "Failed to delete wallet";
|
|
7592
|
-
setError(message);
|
|
7593
|
-
throw err;
|
|
7594
|
-
} finally {
|
|
7595
|
-
setIsLoading(false);
|
|
7596
|
-
}
|
|
7597
|
-
}, [manager]);
|
|
7598
|
-
const fetchBalance = useCallback(async () => {
|
|
7599
|
-
setIsLoading(true);
|
|
7600
|
-
try {
|
|
7601
|
-
const balance = await manager.fetchBalance();
|
|
7602
|
-
setState((prev) => ({ ...prev, balance }));
|
|
7603
|
-
return balance;
|
|
7604
|
-
} catch (err) {
|
|
7605
|
-
console.warn("Failed to fetch balance:", err);
|
|
7606
|
-
setState((prev) => ({ ...prev, balance: "0" }));
|
|
7607
|
-
return "0";
|
|
7608
|
-
} finally {
|
|
7609
|
-
setIsLoading(false);
|
|
7610
|
-
}
|
|
7611
|
-
}, [manager]);
|
|
7612
|
-
const fetchAllBalances = useCallback(async () => {
|
|
7613
|
-
setIsLoading(true);
|
|
7614
|
-
try {
|
|
7615
|
-
const balances = await manager.fetchAllBalances();
|
|
7616
|
-
setChainBalances(balances);
|
|
7617
|
-
return balances;
|
|
7618
|
-
} catch (err) {
|
|
7619
|
-
console.warn("Failed to fetch all balances:", err);
|
|
7620
|
-
return [];
|
|
7621
|
-
} finally {
|
|
7622
|
-
setIsLoading(false);
|
|
7623
|
-
}
|
|
7624
|
-
}, [manager]);
|
|
7625
|
-
const setSelectedChain = useCallback((chain) => {
|
|
7626
|
-
manager.setSelectedChain(chain);
|
|
7627
|
-
setSelectedChainState(chain);
|
|
7628
|
-
}, [manager]);
|
|
7629
|
-
const getAddressForChain = useCallback(
|
|
7630
|
-
(chain) => manager.getAddressForChain(chain),
|
|
7631
|
-
[manager]
|
|
7632
|
-
);
|
|
7633
|
-
const getAllAddresses = useCallback(
|
|
7634
|
-
() => manager.getAllAddresses(),
|
|
7635
|
-
[manager]
|
|
7636
|
-
);
|
|
7637
|
-
const hasWallet = useCallback(() => manager.hasWallet(), [manager]);
|
|
7638
|
-
const getSeed = useCallback(() => manager.getSeed(), [manager]);
|
|
7639
|
-
const sendTransaction = useCallback(
|
|
7640
|
-
async (chain, to, amount, token) => {
|
|
7641
|
-
setIsLoading(true);
|
|
7642
|
-
try {
|
|
7643
|
-
const result = await manager.sendTransaction(chain, to, amount, token);
|
|
7644
|
-
if (result.success) {
|
|
7645
|
-
try {
|
|
7646
|
-
const balances = await manager.fetchAllBalances();
|
|
7647
|
-
setChainBalances(balances);
|
|
7648
|
-
} catch (err) {
|
|
7649
|
-
console.warn("Failed to refresh balances after transaction:", err);
|
|
7650
|
-
}
|
|
7651
|
-
}
|
|
7652
|
-
return result;
|
|
7653
|
-
} finally {
|
|
7654
|
-
setIsLoading(false);
|
|
7655
|
-
}
|
|
7656
|
-
},
|
|
7657
|
-
[manager]
|
|
7658
|
-
);
|
|
7659
|
-
const estimateFee = useCallback(
|
|
7660
|
-
async (chain, to, amount, token) => {
|
|
7661
|
-
return manager.estimateFee(chain, to, amount, token);
|
|
7662
|
-
},
|
|
7663
|
-
[manager]
|
|
7664
|
-
);
|
|
7665
|
-
return {
|
|
7666
|
-
state,
|
|
7667
|
-
isLoading,
|
|
7668
|
-
error,
|
|
7669
|
-
createWallet,
|
|
7670
|
-
importWallet,
|
|
7671
|
-
unlock,
|
|
7672
|
-
lock,
|
|
7673
|
-
deleteWallet,
|
|
7674
|
-
fetchBalance,
|
|
7675
|
-
// Multi-chain
|
|
7676
|
-
selectedChain,
|
|
7677
|
-
setSelectedChain,
|
|
7678
|
-
chainBalances,
|
|
7679
|
-
fetchAllBalances,
|
|
7680
|
-
getAddressForChain,
|
|
7681
|
-
getAllAddresses,
|
|
7682
|
-
supportedChains: SUPPORTED_CHAINS,
|
|
7683
|
-
// Transaction Actions (Powered by Tether WDK)
|
|
7684
|
-
sendTransaction,
|
|
7685
|
-
estimateFee,
|
|
7686
|
-
// Utilities
|
|
7687
|
-
hasWallet,
|
|
7688
|
-
getSeed,
|
|
7689
|
-
manager
|
|
7690
|
-
};
|
|
7691
|
-
}
|
|
7692
7452
|
|
|
7693
7453
|
// src/utils/index.ts
|
|
7694
7454
|
function formatAddress(address, chars = 4) {
|
|
@@ -7712,6 +7472,6 @@ function normalizeAddress(address) {
|
|
|
7712
7472
|
return address.toLowerCase();
|
|
7713
7473
|
}
|
|
7714
7474
|
|
|
7715
|
-
export { BrowserAddressDerivation_exports as BrowserAddressDerivation, CURRENCY_ADDRESSES, DERIVATION_PATHS, KeyManager, MemoryStorageAdapter, NETWORKS, NFT_VOUCHER_DOMAIN, NFT_VOUCHER_TYPES, PLATFORM_CONFIG, SwapService, TESTNET_NETWORKS, TransactionService, WalletManager, WdkApiClient, WebEncryptedStorageAdapter, ZERO_ADDRESS, ZUBARI_CONTRACTS, ZubariError, ZubariMarketProtocol, ZubariNFTProtocol, ZubariPayoutsProtocol, ZubariSubscriptionProtocol, ZubariTipsProtocol, ZubariWallet, ZubariWdkService, createSecureStorage, createTransactionService, createZubariWdkService, formatAddress, formatBalance, getContractAddresses, getNetworkConfig, getTransactionService, getWdkApiClient, getZubariWdkService, isBrowser, isValidAddress, normalizeAddress
|
|
7475
|
+
export { BrowserAddressDerivation_exports as BrowserAddressDerivation, CURRENCY_ADDRESSES, DERIVATION_PATHS, KeyManager, MemoryStorageAdapter, NETWORKS, NFT_VOUCHER_DOMAIN, NFT_VOUCHER_TYPES, PLATFORM_CONFIG, SwapService, TESTNET_NETWORKS, TransactionService, WalletManager, WdkApiClient, WebEncryptedStorageAdapter, ZERO_ADDRESS, ZUBARI_CONTRACTS, ZubariError, ZubariMarketProtocol, ZubariNFTProtocol, ZubariPayoutsProtocol, ZubariSubscriptionProtocol, ZubariTipsProtocol, ZubariWallet, ZubariWdkService, createSecureStorage, createTransactionService, createZubariWdkService, formatAddress, formatBalance, getContractAddresses, getNetworkConfig, getTransactionService, getWdkApiClient, getZubariWdkService, isBrowser, isValidAddress, normalizeAddress };
|
|
7716
7476
|
//# sourceMappingURL=index.mjs.map
|
|
7717
7477
|
//# sourceMappingURL=index.mjs.map
|