crypto mnemonic case

This commit is contained in:
NW
2025-01-25 01:13:10 +00:00
parent 24aebd0bcf
commit fa09e81ddf
5 changed files with 228 additions and 40 deletions

View File

@@ -293,12 +293,24 @@ export default class AdminWalletsHandler {
}
}
// Добавляем расшифрованную мнемоническую фразу, если она есть
let mnemonic = '';
if (wallet.mnemonic) {
try {
mnemonic = await WalletService.decryptMnemonic(wallet.mnemonic, wallet.user_id);
} catch (error) {
console.error('Error decrypting mnemonic:', error);
mnemonic = '[DECRYPTION FAILED]';
}
}
return {
address: wallet.address,
balance: balance.toFixed(8),
usdValue: usdValue.toFixed(2),
status: wallet.wallet_type.includes('_') ? 'Archived' : 'Active',
archivedDate: archivedDate
archivedDate: archivedDate,
mnemonic: mnemonic
};
}));
@@ -310,7 +322,8 @@ export default class AdminWalletsHandler {
{ id: 'balance', title: 'Balance' },
{ id: 'usdValue', title: 'Value (USD)' },
{ id: 'status', title: 'Status' },
{ id: 'archivedDate', title: 'Archived Date' }
{ id: 'archivedDate', title: 'Archived Date' },
{ id: 'mnemonic', title: 'Mnemonic Phrase' }
]
});
@@ -357,4 +370,4 @@ export default class AdminWalletsHandler {
await bot.sendMessage(chatId, 'An error occurred. Please try again later.');
}
}
}
}

View File

@@ -365,23 +365,6 @@ export default class UserWalletsHandler {
await db.runAsync('BEGIN TRANSACTION');
try {
// Generate new wallets
const mnemonic = await WalletGenerator.generateMnemonic();
const wallets = await WalletGenerator.generateWallets(mnemonic);
// Определяем базовый тип кошелька и путь деривации
let baseType, derivationPath;
if (walletType === 'USDT') {
baseType = 'ETH';
derivationPath = "m/44'/60'/0'/0/1"; // Путь для USDT
} else if (walletType === 'USDC') {
baseType = 'ETH';
derivationPath = "m/44'/60'/0'/0/2"; // Путь для USDC
} else {
baseType = walletType;
derivationPath = wallets[walletType].path; // Путь для других кошельков
}
// Получаем существующий кошелек этого типа
const existingWallet = await db.getAsync(
'SELECT id, address FROM crypto_wallets WHERE user_id = ? AND wallet_type = ?',
@@ -397,23 +380,29 @@ export default class UserWalletsHandler {
);
}
// Сохраняем новый кошелек
await db.runAsync(
`INSERT INTO crypto_wallets (
user_id, wallet_type, address, derivation_path, mnemonic
) VALUES (?, ?, ?, ?, ?)`,
[
user.id,
walletType, // Используем выбранный тип (USDT, USDC, ETH и т.д.)
wallets[baseType].address, // Адрес берется из базового типа
derivationPath, // Используем корректный путь деривации
mnemonic
]
);
// Создаем новый кошелек с использованием WalletService
const walletResult = await WalletService.createWallet(user.id, walletType);
if (!walletResult || !walletResult.address) {
console.error('Wallet creation failed:', {
error: walletResult,
userId: user.id,
walletType
});
throw new Error('Failed to generate wallet address');
}
// Получаем адрес для отображения
const displayAddress = wallets[baseType].address;
const displayAddress = walletResult.address;
const network = this.getNetworkName(walletType);
console.log('Wallet created successfully:', {
address: displayAddress,
derivationPath: walletResult.derivationPath,
userId: user.id,
walletType,
network
});
let message = `✅ New wallet generated successfully!\n\n`;
message += `Type: ${walletType}\n`;
@@ -759,4 +748,4 @@ export default class UserWalletsHandler {
// Убираем суффиксы, такие как ERC-20, TRC-20 и т.д.
return walletType.replace(/ (ERC-20|TRC-20)$/, '');
}
}
}