games_app/backend/dist/scripts/seedHotWallets.js
2026-06-29 15:01:23 +02:00

86 lines
3.7 KiB
JavaScript

"use strict";
/**
* Seed hot wallet for USDT TRC20 withdrawals.
* Derives one TRON address from PLATFORM_MNEMONIC at a fixed high index.
*
* Usage (from backend/):
* npm run seed-hot-wallets
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
require("./loadEnv");
const connection_1 = require("../db/connection");
const hdWallet_1 = require("../services/hdWallet");
const hotWalletRepository = __importStar(require("../repositories/hotWalletRepository"));
const walletRepository = __importStar(require("../repositories/walletRepository"));
const walletCapabilities_1 = require("../services/walletCapabilities");
const HOT_DERIVATION_INDEX = 1000000;
async function main() {
const mnemonic = (process.env.PLATFORM_MNEMONIC || '').trim();
if (!mnemonic || mnemonic.split(/\s+/).length < 12) {
throw new Error('PLATFORM_MNEMONIC must be set in .env (12 or 24 words).');
}
if (!process.env.ENCRYPTION_KEY || process.env.ENCRYPTION_KEY.length !== 64) {
throw new Error('ENCRYPTION_KEY must be 32-byte hex (64 chars) in .env.');
}
const usdt = await walletRepository.getWalletTypeByCode(walletCapabilities_1.USDT_WALLET_CODE);
if (!usdt)
throw new Error('USDT_TRC20 wallet type not found — run migrations first.');
const existing = await (0, connection_1.query)('SELECT wallet_type_id FROM hot_wallets WHERE is_active = TRUE AND wallet_type_id = $1', [usdt.id]);
const tronDerived = (0, hdWallet_1.deriveTronFromMnemonic)(mnemonic, HOT_DERIVATION_INDEX);
const tronEncrypted = (0, hdWallet_1.encryptPrivateKey)(tronDerived.privateKey);
if (existing.length > 0) {
console.log('Hot wallet already exists for USDT_TRC20. Skipping.');
}
else {
await hotWalletRepository.create({
walletTypeId: usdt.id,
address: tronDerived.address,
encryptedPrivateKey: tronEncrypted,
derivationIndex: HOT_DERIVATION_INDEX,
});
console.log('Created hot wallet for USDT_TRC20:', tronDerived.address);
}
console.log('\nFund this address on your TRON network (Shasta testnet or mainnet):');
console.log(' ', tronDerived.address);
console.log('\nUsers need TRX on-chain for gas when sweeping; fund hot wallet with TRX + USDT.');
}
main()
.then(() => process.exit(0))
.catch((e) => {
console.error(e);
process.exit(1);
});
//# sourceMappingURL=seedHotWallets.js.map