Files
securebit-chat/test-lnbits-integration.html
lockbitchat 19e3047282 feat: rebrand to SecureBit.chat due to name conflict
BREAKING CHANGE: Project renamed from LockBit.chat to SecureBit.chat

- Changed project name to avoid confusion with LockBit ransomware group
- Updated all documentation, branding, and references
- Maintained all existing functionality and security features
- Domain migration planned to securebit.chat

Reason: The LockBit name became associated with a notorious ransomware
group, causing conflicts on platforms and potential confusion for users.
SecureBit better reflects our mission of providing secure P2P messaging
while avoiding negative associations.

This change affects:
- README.md and all documentation
- Package.json name field
- Brand assets and logos
- Website references
- Social media handles

Core functionality remains unchanged:
 12-layer military-grade security
 Lightning Network integration
 P2P WebRTC architecture
 Open source MIT license
2025-08-14 15:54:11 -04:00

555 lines
26 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LNbits Integration Test</title>
<style>
body {
font-family: 'Inter', sans-serif;
background: #2A2B2A;
color: #f1f5f9;
padding: 20px;
}
.test-container {
max-width: 800px;
margin: 0 auto;
background: #1a1a1a;
padding: 20px;
border-radius: 12px;
}
.test-section {
margin: 20px 0;
padding: 15px;
border: 1px solid #333;
border-radius: 8px;
}
.success { color: #34d399; }
.error { color: #f87171; }
.warning { color: #fbbf24; }
.info { color: #60a5fa; }
button {
background: #fb923c;
color: white;
border: none;
padding: 10px 20px;
border-radius: 6px;
cursor: pointer;
margin: 5px;
}
button:hover { background: #ea580c; }
.log {
background: #000;
padding: 10px;
border-radius: 4px;
font-family: monospace;
font-size: 12px;
max-height: 300px;
overflow-y: auto;
}
</style>
</head>
<body>
<div class="test-container">
<h1>🔧 Тест интеграции LNbits</h1>
<div class="test-section">
<h3>📋 Конфигурация</h3>
<p><strong>API URL:</strong> <span id="apiUrl">https://demo.lnbits.com</span></p>
<p><strong>API Key:</strong> <span id="apiKey">623515641d2e4ebcb1d5992d6d78419c</span></p>
<p><strong>Wallet ID:</strong> <span id="walletId">bcd00f561c7b46b4a7b118f069e68997</span></p>
</div>
<div class="test-section">
<h3>🧪 Тесты</h3>
<button onclick="testHealthCheck()">1. Проверка API</button>
<button onclick="testCreateInvoice()">2. Создание инвойса</button>
<button onclick="testPaymentStatus()">3. Проверка статуса</button>
<button onclick="testVerification()">4. Верификация платежа</button>
<button onclick="testRealPayment()">5. Тест реального платежа</button>
<button onclick="testDemoMode()">6. Тест Demo режима</button>
<button onclick="copyBOLT11()">📋 Копировать BOLT11</button>
<button onclick="runAllTests()">🚀 Запустить все тесты</button>
</div>
<div class="test-section">
<h3>📊 Результаты</h3>
<div id="results"></div>
</div>
<div class="test-section">
<h3>📝 Логи</h3>
<div id="logs" class="log"></div>
</div>
</div>
<script type="module">
let testResults = [];
let currentInvoice = null;
function log(message, type = 'info') {
const logsDiv = document.getElementById('logs');
const timestamp = new Date().toLocaleTimeString();
const logEntry = document.createElement('div');
logEntry.className = type;
logEntry.textContent = `[${timestamp}] ${message}`;
logsDiv.appendChild(logEntry);
logsDiv.scrollTop = logsDiv.scrollHeight;
console.log(`[${type.toUpperCase()}] ${message}`);
}
function addResult(testName, success, details = '') {
testResults.push({ testName, success, details, timestamp: Date.now() });
updateResults();
}
function updateResults() {
const resultsDiv = document.getElementById('results');
const passed = testResults.filter(r => r.success).length;
const total = testResults.length;
resultsDiv.innerHTML = `
<div class="info">✅ Пройдено: ${passed}/${total}</div>
${testResults.map(r => `
<div class="${r.success ? 'success' : 'error'}">
${r.success ? '✅' : '❌'} ${r.testName}
${r.details ? `<br><small>${r.details}</small>` : ''}
</div>
`).join('')}
`;
}
async function testHealthCheck() {
log('🔍 Тестирование доступности API...', 'info');
try {
const response = await fetch('https://demo.lnbits.com/api/v1/health', {
method: 'GET',
headers: {
'X-Api-Key': '623515641d2e4ebcb1d5992d6d78419c'
}
});
if (response.ok) {
const data = await response.json();
log('✅ API доступен', 'success');
log(`📊 Статус: ${JSON.stringify(data)}`, 'info');
addResult('Health Check', true, `Status: ${response.status}`);
} else {
log(`❌ API недоступен: ${response.status}`, 'error');
addResult('Health Check', false, `HTTP ${response.status}`);
}
} catch (error) {
log(`❌ Ошибка подключения: ${error.message}`, 'error');
addResult('Health Check', false, error.message);
}
}
async function testCreateInvoice() {
log('💰 Тестирование создания инвойса...', 'info');
try {
const response = await fetch('https://demo.lnbits.com/api/v1/payments', {
method: 'POST',
headers: {
'X-Api-Key': '623515641d2e4ebcb1d5992d6d78419c',
'Content-Type': 'application/json'
},
body: JSON.stringify({
out: false,
amount: 500,
memo: 'SecureBit.chat test invoice',
unit: 'sat',
expiry: 300
})
});
if (response.ok) {
const data = await response.json();
currentInvoice = data;
log('✅ Инвойс создан успешно', 'success');
log(`📋 Payment Request: ${data.bolt11 ? data.bolt11.substring(0, 50) + '...' : 'N/A'}`, 'info');
log(`🔑 Payment Hash: ${data.payment_hash || 'N/A'}`, 'info');
log(`💰 Amount: ${data.amount || 'N/A'} sats`, 'info');
log(`📋 BOLT11: ${data.bolt11 ? 'Доступен' : 'N/A'}`, 'info');
addResult('Create Invoice', true, `Amount: ${data.amount || 'N/A'} sats`);
} else {
const errorText = await response.text();
log(`❌ Ошибка создания инвойса: ${response.status}`, 'error');
log(`📄 Ответ: ${errorText}`, 'error');
addResult('Create Invoice', false, `HTTP ${response.status}: ${errorText}`);
}
} catch (error) {
log(`❌ Ошибка: ${error.message}`, 'error');
addResult('Create Invoice', false, error.message);
}
}
async function testPaymentStatus() {
if (!currentInvoice) {
log('⚠️ Сначала создайте инвойс', 'warning');
addResult('Payment Status', false, 'No invoice available');
return;
}
log('🔍 Проверка статуса платежа...', 'info');
try {
const response = await fetch(`https://demo.lnbits.com/api/v1/payments/${currentInvoice.checking_id}`, {
method: 'GET',
headers: {
'X-Api-Key': '623515641d2e4ebcb1d5992d6d78419c',
'Content-Type': 'application/json'
}
});
if (response.ok) {
const data = await response.json();
log('✅ Статус получен', 'success');
log(`📊 Оплачен: ${data.paid || false}`, 'info');
log(`💰 Сумма: ${data.details?.amount || 'N/A'} sats`, 'info');
log(`📋 Статус: ${data.status || 'N/A'}`, 'info');
log(`📋 BOLT11: ${data.details?.bolt11 ? 'Доступен' : 'N/A'}`, 'info');
addResult('Payment Status', true, `Paid: ${data.paid || false}, Amount: ${data.details?.amount || 'N/A'}`);
} else {
const errorText = await response.text();
log(`❌ Ошибка проверки статуса: ${response.status}`, 'error');
addResult('Payment Status', false, `HTTP ${response.status}: ${errorText}`);
}
} catch (error) {
log(`❌ Ошибка: ${error.message}`, 'error');
addResult('Payment Status', false, error.message);
}
}
async function testVerification() {
log('🔐 Тестирование верификации...', 'info');
// Создаем фиктивный preimage для теста
const testPreimage = Array.from(crypto.getRandomValues(new Uint8Array(32)))
.map(b => b.toString(16).padStart(2, '0')).join('');
log(`🔑 Тестовый preimage: ${testPreimage}`, 'info');
try {
// Криптографическая верификация
const preimageBytes = new Uint8Array(testPreimage.match(/.{2}/g).map(byte => parseInt(byte, 16)));
const hashBuffer = await crypto.subtle.digest('SHA-256', preimageBytes);
const computedHash = Array.from(new Uint8Array(hashBuffer))
.map(b => b.toString(16).padStart(2, '0')).join('');
log(`🔐 Вычисленный hash: ${computedHash}`, 'info');
log('✅ Криптографическая верификация работает', 'success');
addResult('Cryptographic Verification', true, 'SHA-256 hash computation OK');
} catch (error) {
log(`❌ Ошибка криптографической верификации: ${error.message}`, 'error');
addResult('Cryptographic Verification', false, error.message);
}
}
async function testRealPayment() {
log('💳 Тестирование реального платежа...', 'info');
if (!currentInvoice) {
log('⚠️ Сначала создайте инвойс', 'warning');
addResult('Real Payment Test', false, 'No invoice available');
return;
}
try {
// Создаем фиктивный preimage для теста (в реальности это придет от кошелька)
const testPreimage = Array.from(crypto.getRandomValues(new Uint8Array(32)))
.map(b => b.toString(16).padStart(2, '0')).join('');
log(`🔑 Тестовый preimage: ${testPreimage}`, 'info');
// Проверяем через LNbits API
const response = await fetch(`https://demo.lnbits.com/api/v1/payments/${currentInvoice.checking_id}`, {
method: 'GET',
headers: {
'X-Api-Key': '623515641d2e4ebcb1d5992d6d78419c',
'Content-Type': 'application/json'
}
});
if (response.ok) {
const data = await response.json();
log(`📊 Статус платежа: ${JSON.stringify(data)}`, 'info');
// Симулируем успешный платеж для демо
if (data.paid) {
log('✅ Платеж уже оплачен!', 'success');
addResult('Real Payment Test', true, 'Payment already paid');
} else {
log('⏳ Платеж ожидает оплаты', 'warning');
log('💡 Для тестирования оплатите инвойс через любой Lightning кошелек', 'info');
addResult('Real Payment Test', true, 'Payment pending - ready for testing');
}
} else {
throw new Error(`HTTP ${response.status}`);
}
} catch (error) {
log(`❌ Ошибка тестирования платежа: ${error.message}`, 'error');
addResult('Real Payment Test', false, error.message);
}
}
async function testDemoMode() {
log('🎮 Тестирование Demo режима...', 'info');
try {
// Симулируем PayPerSessionManager для тестирования
const mockSessionManager = {
sessionPrices: {
demo: { sats: 0, hours: 0.1, usd: 0.00 },
basic: { sats: 500, hours: 1, usd: 0.20 },
premium: { sats: 1000, hours: 4, usd: 0.40 },
extended: { sats: 2000, hours: 24, usd: 0.80 }
},
demoSessions: new Map(),
maxDemoSessionsPerUser: 3,
demoCooldownPeriod: 60 * 60 * 1000,
demoSessionCooldown: 5 * 60 * 1000,
demoSessionMaxDuration: 6 * 60 * 1000,
usedPreimages: new Set(),
generateUserFingerprint() {
const components = [
navigator.userAgent || '',
navigator.language || '',
screen.width + 'x' + screen.height,
Intl.DateTimeFormat().resolvedOptions().timeZone || '',
navigator.hardwareConcurrency || 0,
navigator.deviceMemory || 0,
navigator.platform || '',
navigator.cookieEnabled ? '1' : '0'
];
let hash = 0;
const str = components.join('|');
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash = hash & hash;
}
return Math.abs(hash).toString(36);
},
checkDemoSessionLimits(userFingerprint) {
const userData = this.demoSessions.get(userFingerprint);
const now = Date.now();
if (!userData) {
return {
allowed: true,
reason: 'first_demo_session',
remaining: this.maxDemoSessionsPerUser
};
}
const activeSessions = userData.sessions.filter(session =>
now - session.timestamp < this.demoCooldownPeriod
);
if (activeSessions.length >= this.maxDemoSessionsPerUser) {
const oldestSession = Math.min(...activeSessions.map(s => s.timestamp));
const timeUntilNext = this.demoCooldownPeriod - (now - oldestSession);
return {
allowed: false,
reason: 'demo_limit_exceeded',
timeUntilNext: timeUntilNext,
message: `Demo limit reached (${this.maxDemoSessionsPerUser}/day). Try again in ${Math.ceil(timeUntilNext / (60 * 1000))} minutes.`,
remaining: 0
};
}
if (userData.lastUsed && (now - userData.lastUsed) < this.demoSessionCooldown) {
const timeUntilNext = this.demoSessionCooldown - (now - userData.lastUsed);
return {
allowed: false,
reason: 'demo_cooldown',
timeUntilNext: timeUntilNext,
message: `Please wait ${Math.ceil(timeUntilNext / (60 * 1000))} minutes between demo sessions.`,
remaining: this.maxDemoSessionsPerUser - activeSessions.length
};
}
return {
allowed: true,
reason: 'within_limits',
remaining: this.maxDemoSessionsPerUser - activeSessions.length
};
},
createDemoSession() {
const userFingerprint = this.generateUserFingerprint();
const demoCheck = this.checkDemoSessionLimits(userFingerprint);
if (!demoCheck.allowed) {
return {
success: false,
reason: demoCheck.message,
timeUntilNext: demoCheck.timeUntilNext,
remaining: demoCheck.remaining
};
}
try {
const demoPreimage = this.generateSecureDemoPreimage();
const demoPaymentHash = 'demo_' + Array.from(crypto.getRandomValues(new Uint8Array(16)))
.map(b => b.toString(16).padStart(2, '0')).join('');
return {
success: true,
sessionType: 'demo',
preimage: demoPreimage,
paymentHash: demoPaymentHash,
duration: this.sessionPrices.demo.hours,
durationMinutes: Math.round(this.demoSessionMaxDuration / (60 * 1000)),
warning: `Demo session - limited to ${Math.round(this.demoSessionMaxDuration / (60 * 1000))} minutes`,
remaining: demoCheck.remaining - 1
};
} catch (error) {
return {
success: false,
reason: 'Failed to generate demo session. Please try again.',
remaining: demoCheck.remaining
};
}
},
generateSecureDemoPreimage() {
const timestamp = Date.now();
const randomBytes = crypto.getRandomValues(new Uint8Array(24));
const timestampBytes = new Uint8Array(4);
const versionBytes = new Uint8Array(4);
const timestampSeconds = Math.floor(timestamp / 1000);
timestampBytes[0] = (timestampSeconds >>> 24) & 0xFF;
timestampBytes[1] = (timestampSeconds >>> 16) & 0xFF;
timestampBytes[2] = (timestampSeconds >>> 8) & 0xFF;
timestampBytes[3] = timestampSeconds & 0xFF;
versionBytes[0] = 0xDE;
versionBytes[1] = 0xE0;
versionBytes[2] = 0x00;
versionBytes[3] = 0x01;
const combined = new Uint8Array(32);
combined.set(versionBytes, 0);
combined.set(timestampBytes, 4);
combined.set(randomBytes, 8);
return Array.from(combined).map(b => b.toString(16).padStart(2, '0')).join('');
}
};
// Тестируем demo режим
log('🔍 Тестирование лимитов demo сессий...', 'info');
const userFingerprint = mockSessionManager.generateUserFingerprint();
log(`👤 User fingerprint: ${userFingerprint.substring(0, 8)}...`, 'info');
const demoCheck = mockSessionManager.checkDemoSessionLimits(userFingerprint);
log(`📊 Demo check result: ${demoCheck.allowed ? 'Allowed' : 'Denied'}`, demoCheck.allowed ? 'success' : 'warning');
if (demoCheck.allowed) {
log(`✅ Demo session available. Remaining: ${demoCheck.remaining}`, 'success');
// Создаем demo сессию
const demoSession = mockSessionManager.createDemoSession();
if (demoSession.success) {
log('🎮 Demo session created successfully!', 'success');
log(`⏱️ Duration: ${demoSession.durationMinutes} minutes`, 'info');
log(`🔑 Preimage: ${demoSession.preimage.substring(0, 16)}...`, 'info');
log(`⚠️ Warning: ${demoSession.warning}`, 'warning');
log(`📊 Remaining: ${demoSession.remaining}`, 'info');
addResult('Demo Mode Test', true, `Session created: ${demoSession.durationMinutes}min, Remaining: ${demoSession.remaining}`);
} else {
log(`❌ Demo session creation failed: ${demoSession.reason}`, 'error');
addResult('Demo Mode Test', false, demoSession.reason);
}
} else {
log(`⏳ Demo session not available: ${demoCheck.message}`, 'warning');
addResult('Demo Mode Test', true, `Limits working: ${demoCheck.message}`);
}
} catch (error) {
log(`❌ Demo mode test failed: ${error.message}`, 'error');
addResult('Demo Mode Test', false, error.message);
}
}
function copyBOLT11() {
if (!currentInvoice) {
log('⚠️ Сначала создайте инвойс', 'warning');
return;
}
const bolt11 = currentInvoice.bolt11;
if (!bolt11) {
log('❌ BOLT11 недоступен', 'error');
return;
}
navigator.clipboard.writeText(bolt11).then(() => {
log('✅ BOLT11 скопирован в буфер обмена', 'success');
log(`📋 BOLT11: ${bolt11.substring(0, 50)}...`, 'info');
}).catch(err => {
log(`❌ Ошибка копирования: ${err.message}`, 'error');
});
}
async function runAllTests() {
log('🚀 Запуск всех тестов...', 'info');
testResults = [];
await testHealthCheck();
await new Promise(resolve => setTimeout(resolve, 1000));
await testCreateInvoice();
await new Promise(resolve => setTimeout(resolve, 1000));
await testPaymentStatus();
await new Promise(resolve => setTimeout(resolve, 1000));
await testVerification();
await new Promise(resolve => setTimeout(resolve, 1000));
await testRealPayment();
await new Promise(resolve => setTimeout(resolve, 1000));
await testDemoMode();
log('🎉 Все тесты завершены!', 'success');
}
// Экспортируем функции для использования в HTML
window.testHealthCheck = testHealthCheck;
window.testCreateInvoice = testCreateInvoice;
window.testPaymentStatus = testPaymentStatus;
window.testVerification = testVerification;
window.testRealPayment = testRealPayment;
window.testDemoMode = testDemoMode;
window.copyBOLT11 = copyBOLT11;
window.runAllTests = runAllTests;
// Автоматический запуск при загрузке
log('🔧 Тест интеграции LNbits загружен', 'info');
log('📋 Нажмите "Запустить все тесты" для проверки', 'info');
</script>
</body>
</html>