delet TRON wallet type

This commit is contained in:
NW
2025-01-02 16:19:39 +00:00
parent c9bcb09221
commit 22f76c64a6
3 changed files with 17 additions and 94 deletions

View File

@@ -4,14 +4,13 @@ import { publicToAddress } from 'ethereumjs-util';
import * as bitcoin from 'bitcoinjs-lib';
import * as ecc from 'tiny-secp256k1';
import { ECPairFactory } from 'ecpair';
import CryptoJS from 'crypto-js';
const ECPair = ECPairFactory(ecc);
export default class WalletGenerator {
static async generateMnemonic() {
try {
return bip39.generateMnemonic(128); // 12 words for maximum security
return bip39.generateMnemonic(128); // 12 слов
} catch (error) {
console.error('Error generating mnemonic:', error);
throw new Error('Failed to generate mnemonic');
@@ -26,8 +25,8 @@ export default class WalletGenerator {
// Generate BTC wallet (BIP84 - Native SegWit)
const btcNode = hdkey.derive("m/84'/0'/0'/0/0");
const btcKeyPair = ECPair.fromPrivateKey(btcNode.privateKey);
const btcAddress = bitcoin.payments.p2wpkh({
pubkey: btcKeyPair.publicKey
const btcAddress = bitcoin.payments.p2wpkh({
pubkey: btcKeyPair.publicKey,
}).address;
// Generate ETH wallet (BIP44)
@@ -44,84 +43,31 @@ export default class WalletGenerator {
bech32: 'ltc',
bip32: {
public: 0x019da462,
private: 0x019d9cfe
private: 0x019d9cfe,
},
pubKeyHash: 0x30,
scriptHash: 0x32,
wif: 0xb0
}
wif: 0xb0,
},
}).address;
// Generate TRON address (BIP44)
const tronNode = hdkey.derive("m/44'/195'/0'/0/0");
const tronAddress = this.generateTronAddress(tronNode.publicKey);
return {
BTC: {
address: btcAddress,
path: "m/84'/0'/0'/0/0"
BTC: {
address: btcAddress,
path: "m/84'/0'/0'/0/0",
},
ETH: {
address: ethAddress,
path: "m/44'/60'/0'/0/0"
ETH: {
address: ethAddress,
path: "m/44'/60'/0'/0/0",
},
LTC: {
address: ltcAddress,
path: "m/84'/2'/0'/0/0"
LTC: {
address: ltcAddress,
path: "m/84'/2'/0'/0/0",
},
TRON: {
address: tronAddress,
path: "m/44'/195'/0'/0/0"
}
};
} catch (error) {
console.error('Error in generateWallets:', error);
throw new Error('Failed to generate cryptocurrency wallets: ' + error.message);
}
}
static generateTronAddress(publicKey) {
try {
const addressPrefix = '41'; // TRON mainnet prefix
const pubKeyHash = CryptoJS.SHA256(
CryptoJS.lib.WordArray.create(publicKey)
).toString();
const address = addressPrefix + pubKeyHash.substring(0, 40);
return this.base58Encode(Buffer.from(address, 'hex'));
} catch (error) {
console.error('Error generating TRON address:', error);
throw new Error('Failed to generate TRON address: ' + error.message);
}
}
static base58Encode(buffer) {
try {
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
let digits = [0];
for (let i = 0; i < buffer.length; i++) {
let carry = buffer[i];
for (let j = 0; j < digits.length; j++) {
carry += digits[j] << 8;
digits[j] = carry % 58;
carry = (carry / 58) | 0;
}
while (carry > 0) {
digits.push(carry % 58);
carry = (carry / 58) | 0;
}
}
// Add leading zeros
for (let i = 0; buffer[i] === 0 && i < buffer.length - 1; i++) {
digits.push(0);
}
return digits.reverse().map(digit => ALPHABET[digit]).join('');
} catch (error) {
console.error('Error in base58Encode:', error);
throw new Error('Failed to encode address: ' + error.message);
}
}
}