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

35 lines
1.8 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getActiveHotWallet = getActiveHotWallet;
exports.listActiveHotWallets = listActiveHotWallets;
exports.create = create;
const connection_1 = require("../db/connection");
/**
* Repository for hot wallet management.
* Provides access to active signing wallets used for outbound blockchain transactions.
*/
/**
* Returns the active hot wallet for a given wallet type.
* @param walletTypeId - ID of the wallet type to look up.
* @returns The active hot wallet record, or null if none is configured.
*/
async function getActiveHotWallet(walletTypeId) {
const rows = await (0, connection_1.query)('SELECT id, wallet_type_id, address, encrypted_private_key, is_active FROM hot_wallets WHERE wallet_type_id = $1 AND is_active = TRUE LIMIT 1', [walletTypeId]);
return rows[0] || null;
}
async function listActiveHotWallets() {
return (0, connection_1.query)('SELECT id, wallet_type_id, address, encrypted_private_key, is_active FROM hot_wallets WHERE is_active = TRUE ORDER BY wallet_type_id');
}
/**
* Inserts a new hot wallet record.
* @param data - Hot wallet fields to persist.
* @param data.walletTypeId - Wallet type this hot wallet serves.
* @param data.address - On-chain address of the hot wallet.
* @param data.encryptedPrivateKey - Encrypted private key for signing transactions.
* @param data.derivationIndex - Optional HD derivation index used to generate the wallet.
* @returns Resolves when the row has been inserted.
*/
async function create(data) {
await (0, connection_1.query)('INSERT INTO hot_wallets (wallet_type_id, address, encrypted_private_key, derivation_index) VALUES ($1, $2, $3, $4)', [data.walletTypeId, data.address, data.encryptedPrivateKey, data.derivationIndex ?? null]);
}
//# sourceMappingURL=hotWalletRepository.js.map