"use strict"; /** * Withdrawal controller — HTTP handler for submitting on-chain withdrawal requests. */ 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 }); exports.withdraw = withdraw; const withdrawalService = __importStar(require("../services/withdrawalService")); const withdrawalService_1 = require("../services/withdrawalService"); /** * Submits a withdrawal request to send funds from the user's wallet to an external address. * May require a TOTP code when 2FA is enabled for the user. * @param req - Authenticated request. Body: `walletType`, `toAddress`, `amount`, optional `totpCode`. * @param res - JSON `{ transactionId, status }` on success, 400 on validation or withdrawal failure. */ async function withdraw(req, res) { try { const userId = req.user.userId; const { walletType, toAddress, amount } = req.body; if (!walletType || !toAddress || amount == null) { res.status(400).json({ error: 'walletType, toAddress and amount required' }); return; } const amountRaw = BigInt(amount); const result = await withdrawalService.requestWithdrawal(userId, walletType, toAddress, amountRaw, req.body.totpCode); res.json(result); } catch (e) { const msg = e instanceof Error ? e.message : 'Withdrawal failed'; const status = e instanceof withdrawalService_1.SecurityBlockedError ? 403 : 400; res.status(status).json({ error: msg }); } } //# sourceMappingURL=withdrawalController.js.map