v0.7.16 - Fixed blacklist authentication system - removed redundant action/parameters columns, added active=1 filtering, added comprehensive debug tracing, and identified that auth must be enabled for blacklist to work
This commit is contained in:
79
api/index.js
79
api/index.js
@@ -808,7 +808,7 @@
|
||||
|
||||
// Add to inbox
|
||||
const timestamp = new Date(event.created_at * 1000).toLocaleString();
|
||||
addMessageToInbox('received', decryptedContent, timestamp);
|
||||
addMessageToInbox('received', decryptedContent, timestamp, event.pubkey);
|
||||
|
||||
// Log for testing
|
||||
if (typeof logTestEvent === 'function') {
|
||||
@@ -845,7 +845,7 @@
|
||||
|
||||
// Add to inbox
|
||||
const timestamp = new Date(event.created_at * 1000).toLocaleString();
|
||||
addMessageToInbox('received', rumor.content, timestamp);
|
||||
addMessageToInbox('received', rumor.content, timestamp, rumor.pubkey);
|
||||
|
||||
// Log for testing
|
||||
if (typeof logTestEvent === 'function') {
|
||||
@@ -1848,7 +1848,6 @@
|
||||
<td>${rule.rule_type}</td>
|
||||
<td>${rule.pattern_type || rule.operation || '-'}</td>
|
||||
<td style="font-family: 'Courier New', monospace; font-size: 12px; word-break: break-all; max-width: 200px;">${rule.pattern_value || rule.rule_target || '-'}</td>
|
||||
<td>${rule.action || 'allow'}</td>
|
||||
<td>${rule.enabled !== false ? 'Active' : 'Inactive'}</td>
|
||||
<td>
|
||||
<div class="inline-buttons">
|
||||
@@ -2159,7 +2158,7 @@
|
||||
// STREAMLINED AUTH RULE FUNCTIONS
|
||||
// ================================
|
||||
|
||||
// Utility function to convert nsec to hex pubkey
|
||||
// Utility function to convert nsec to hex pubkey or npub to hex pubkey
|
||||
function nsecToHex(input) {
|
||||
if (!input || input.trim().length === 0) {
|
||||
return null;
|
||||
@@ -2178,11 +2177,17 @@
|
||||
if (window.NostrTools && window.NostrTools.nip19 && window.NostrTools.nip19.decode) {
|
||||
const decoded = window.NostrTools.nip19.decode(trimmed);
|
||||
if (decoded.type === 'nsec') {
|
||||
// Convert bytes to hex
|
||||
const hexPubkey = Array.from(decoded.data)
|
||||
.map(b => b.toString(16).padStart(2, '0'))
|
||||
.join('');
|
||||
return hexPubkey;
|
||||
// Handle different versions of nostr-tools
|
||||
if (typeof decoded.data === 'string') {
|
||||
// v1 style - data is already hex
|
||||
return decoded.data;
|
||||
} else {
|
||||
// v2 style - data is Uint8Array
|
||||
const hexPubkey = Array.from(decoded.data)
|
||||
.map(b => b.toString(16).padStart(2, '0'))
|
||||
.join('');
|
||||
return hexPubkey;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -2191,6 +2196,31 @@
|
||||
}
|
||||
}
|
||||
|
||||
// If it starts with npub1, try to decode to hex
|
||||
if (trimmed.startsWith('npub1')) {
|
||||
try {
|
||||
if (window.NostrTools && window.NostrTools.nip19 && window.NostrTools.nip19.decode) {
|
||||
const decoded = window.NostrTools.nip19.decode(trimmed);
|
||||
if (decoded.type === 'npub') {
|
||||
// Handle different versions of nostr-tools
|
||||
if (typeof decoded.data === 'string') {
|
||||
// v1 style - data is already hex
|
||||
return decoded.data;
|
||||
} else {
|
||||
// v2 style - data is Uint8Array
|
||||
const hexPubkey = Array.from(decoded.data)
|
||||
.map(b => b.toString(16).padStart(2, '0'))
|
||||
.join('');
|
||||
return hexPubkey;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to decode npub:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null; // Invalid format
|
||||
}
|
||||
|
||||
@@ -2206,10 +2236,10 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert nsec to hex if needed
|
||||
// Convert nsec or npub to hex if needed
|
||||
const hexPubkey = nsecToHex(inputValue);
|
||||
if (!hexPubkey) {
|
||||
log('Invalid pubkey format. Please enter nsec1... or 64-character hex', 'ERROR');
|
||||
log('Invalid pubkey format. Please enter nsec1..., npub1..., or 64-character hex', 'ERROR');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2258,10 +2288,10 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert nsec to hex if needed
|
||||
// Convert nsec or npub to hex if needed
|
||||
const hexPubkey = nsecToHex(inputValue);
|
||||
if (!hexPubkey) {
|
||||
log('Invalid pubkey format. Please enter nsec1... or 64-character hex', 'ERROR');
|
||||
log('Invalid pubkey format. Please enter nsec1..., npub1..., or 64-character hex', 'ERROR');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3065,21 +3095,32 @@
|
||||
}
|
||||
|
||||
// Add message to inbox display
|
||||
function addMessageToInbox(direction, message, timestamp) {
|
||||
function addMessageToInbox(direction, message, timestamp, pubkey = null) {
|
||||
if (!dmInbox) return;
|
||||
|
||||
const messageDiv = document.createElement('div');
|
||||
messageDiv.className = 'log-entry';
|
||||
|
||||
const directionColor = direction === 'sent' ? '#007bff' : '#28a745';
|
||||
|
||||
|
||||
// Convert newlines to <br> tags for proper HTML display
|
||||
const formattedMessage = message.replace(/\n/g, '<br>');
|
||||
|
||||
|
||||
// Add pubkey display for received messages
|
||||
let pubkeyDisplay = '';
|
||||
if (pubkey && direction === 'received') {
|
||||
try {
|
||||
const npub = window.NostrTools.nip19.npubEncode(pubkey);
|
||||
pubkeyDisplay = ` <span style="color: #666; font-size: 11px;">(${npub})</span>`;
|
||||
} catch (error) {
|
||||
console.error('Failed to encode pubkey to npub:', error);
|
||||
}
|
||||
}
|
||||
|
||||
messageDiv.innerHTML = `
|
||||
<span class="log-timestamp">${timestamp}</span>
|
||||
<span style="color: ${directionColor}; font-weight: bold;">[${direction.toUpperCase()}]</span>
|
||||
<span style="white-space: pre-wrap;">${formattedMessage}</span>
|
||||
<span style="white-space: pre-wrap;">${formattedMessage}${pubkeyDisplay}</span>
|
||||
`;
|
||||
|
||||
// Remove the "No messages received yet" placeholder if it exists
|
||||
@@ -3399,10 +3440,10 @@
|
||||
|
||||
data.top_pubkeys.forEach((pubkey, index) => {
|
||||
const row = document.createElement('tr');
|
||||
const shortPubkey = pubkey.pubkey ? pubkey.pubkey.substring(0, 16) + '...' : '-';
|
||||
const npub = pubkey.pubkey ? window.NostrTools.nip19.npubEncode(pubkey.pubkey) : '-';
|
||||
row.innerHTML = `
|
||||
<td>${index + 1}</td>
|
||||
<td style="font-family: 'Courier New', monospace; font-size: 12px;">${shortPubkey}</td>
|
||||
<td style="font-family: 'Courier New', monospace; font-size: 12px; word-break: break-all;">${npub}</td>
|
||||
<td>${pubkey.event_count}</td>
|
||||
<td>${pubkey.percentage}%</td>
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user