v0.4.10 - api
This commit is contained in:
4095
api/index copy.html
4095
api/index copy.html
File diff suppressed because it is too large
Load Diff
113
api/index.js
113
api/index.js
@@ -1191,22 +1191,20 @@
|
||||
console.log('Sending config query command...');
|
||||
|
||||
// Create command array for getting configuration
|
||||
const command_array = '["config_query", "all"]';
|
||||
const command_array = ["config_query", "all"];
|
||||
|
||||
// Encrypt the command content using NIP-44
|
||||
const encrypted_content = await encryptForRelay(command_array);
|
||||
// Encrypt the command array directly using NIP-44
|
||||
const encrypted_content = await encryptForRelay(JSON.stringify(command_array));
|
||||
if (!encrypted_content) {
|
||||
throw new Error('Failed to encrypt config query command');
|
||||
throw new Error('Failed to encrypt command array');
|
||||
}
|
||||
|
||||
// Create kind 23456 admin event
|
||||
// Create single kind 23456 admin event
|
||||
const configEvent = {
|
||||
kind: 23456,
|
||||
pubkey: userPubkey,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: [
|
||||
["p", getRelayPubkey()]
|
||||
],
|
||||
tags: [["p", getRelayPubkey()]],
|
||||
content: encrypted_content
|
||||
};
|
||||
|
||||
@@ -1478,10 +1476,12 @@
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Sending config_update command with ${configObjects.length} configuration objects...`);
|
||||
|
||||
// Send single config_update command with all config objects
|
||||
await sendConfigUpdateCommand(configObjects);
|
||||
console.log(`Sending config_update commands for ${configObjects.length} configuration objects...`);
|
||||
|
||||
// Send config_update commands one at a time to avoid large event size
|
||||
for (const configObj of configObjects) {
|
||||
await sendConfigUpdateCommand([configObj]);
|
||||
}
|
||||
|
||||
console.log('Configuration update command sent successfully');
|
||||
|
||||
@@ -1494,31 +1494,30 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Send config update command using kind 23456 with new config_update format
|
||||
// Send config update command using kind 23456 with Administrator API (inner events)
|
||||
async function sendConfigUpdateCommand(configObjects) {
|
||||
try {
|
||||
if (!relayPool) {
|
||||
throw new Error('SimplePool connection not available');
|
||||
}
|
||||
|
||||
console.log(`Sending config_update command with ${configObjects.length} configuration objects`);
|
||||
console.log(`Sending config_update command with ${configObjects.length} configuration object(s)`);
|
||||
|
||||
// Create command array for config update (per README.md spec)
|
||||
// Format: ["config_update", [config_objects_array]]
|
||||
const command_array = JSON.stringify(["config_update", configObjects]);
|
||||
// Create command array for config update
|
||||
const command_array = ["config_update", configObjects];
|
||||
|
||||
// Encrypt using NIP-44
|
||||
const encrypted_content = await encryptForRelay(command_array);
|
||||
// Encrypt the command array directly using NIP-44
|
||||
const encrypted_content = await encryptForRelay(JSON.stringify(command_array));
|
||||
if (!encrypted_content) {
|
||||
throw new Error('Failed to encrypt config_update command');
|
||||
throw new Error('Failed to encrypt command array');
|
||||
}
|
||||
|
||||
// Create kind 23456 admin event (unified admin API)
|
||||
// Create single kind 23456 admin event
|
||||
const configEvent = {
|
||||
kind: 23456,
|
||||
pubkey: userPubkey,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: [["p", getRelayPubkey()]], // Per README.md spec
|
||||
tags: [["p", getRelayPubkey()]],
|
||||
content: encrypted_content
|
||||
};
|
||||
|
||||
@@ -1528,7 +1527,7 @@
|
||||
throw new Error('Event signing failed');
|
||||
}
|
||||
|
||||
console.log(`Config update event signed with ${configObjects.length} objects`);
|
||||
console.log(`Config update event signed with ${configObjects.length} object(s)`);
|
||||
|
||||
// Publish via SimplePool with detailed error diagnostics
|
||||
const url = relayConnectionUrl.value.trim();
|
||||
@@ -1560,11 +1559,11 @@
|
||||
throw new Error(`All relays rejected config update event. Details: ${errorDetails}`);
|
||||
}
|
||||
|
||||
console.log(`Config update command sent successfully with ${configObjects.length} configuration objects`);
|
||||
console.log(`Config update command sent successfully with ${configObjects.length} configuration object(s)`);
|
||||
|
||||
// Log for testing
|
||||
if (typeof logTestEvent === 'function') {
|
||||
logTestEvent('SENT', `Config update command: ${configObjects.length} objects`, 'CONFIG_UPDATE');
|
||||
logTestEvent('SENT', `Config update command: ${configObjects.length} object(s)`, 'CONFIG_UPDATE');
|
||||
configObjects.forEach((config, index) => {
|
||||
logTestEvent('SENT', `Config ${index + 1}: ${config.key} = ${config.value} (${config.data_type})`, 'CONFIG');
|
||||
});
|
||||
@@ -1750,22 +1749,20 @@
|
||||
}
|
||||
|
||||
// Create command array for getting all auth rules
|
||||
const command_array = '["auth_query", "all"]';
|
||||
const command_array = ["auth_query", "all"];
|
||||
|
||||
// Encrypt the command content using NIP-44
|
||||
const encrypted_content = await encryptForRelay(command_array);
|
||||
// Encrypt the command array directly using NIP-44
|
||||
const encrypted_content = await encryptForRelay(JSON.stringify(command_array));
|
||||
if (!encrypted_content) {
|
||||
throw new Error('Failed to encrypt auth query command');
|
||||
throw new Error('Failed to encrypt command array');
|
||||
}
|
||||
|
||||
// Create kind 23456 admin event
|
||||
// Create single kind 23456 admin event
|
||||
const authEvent = {
|
||||
kind: 23456,
|
||||
pubkey: userPubkey,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: [
|
||||
["p", getRelayPubkey()]
|
||||
],
|
||||
tags: [["p", getRelayPubkey()]],
|
||||
content: encrypted_content
|
||||
};
|
||||
|
||||
@@ -1930,7 +1927,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Delete auth rule using admin API
|
||||
// Delete auth rule using Administrator API (inner events)
|
||||
async function deleteAuthRule(index) {
|
||||
if (index < 0 || index >= currentAuthRules.length) return;
|
||||
|
||||
@@ -1956,22 +1953,20 @@
|
||||
const pattern_type = rule.pattern_type || 'pubkey';
|
||||
const pattern_value = rule.pattern_value || rule.rule_target;
|
||||
|
||||
const command_array = `["system_command", "delete_auth_rule", "${rule_type}", "${pattern_type}", "${pattern_value}"]`;
|
||||
const command_array = ["system_command", "delete_auth_rule", rule_type, pattern_type, pattern_value];
|
||||
|
||||
// Encrypt the command content using NIP-44
|
||||
const encrypted_content = await encryptForRelay(command_array);
|
||||
// Encrypt the command array directly using NIP-44
|
||||
const encrypted_content = await encryptForRelay(JSON.stringify(command_array));
|
||||
if (!encrypted_content) {
|
||||
throw new Error('Failed to encrypt delete auth rule command');
|
||||
throw new Error('Failed to encrypt command array');
|
||||
}
|
||||
|
||||
// Create kind 23456 admin event
|
||||
// Create single kind 23456 admin event
|
||||
const authEvent = {
|
||||
kind: 23456,
|
||||
pubkey: userPubkey,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: [
|
||||
["p", getRelayPubkey()]
|
||||
],
|
||||
tags: [["p", getRelayPubkey()]],
|
||||
content: encrypted_content
|
||||
};
|
||||
|
||||
@@ -2335,34 +2330,32 @@
|
||||
|
||||
// Create command array in the same format as working tests
|
||||
// Format: ["blacklist", "pubkey", "abc123..."] or ["whitelist", "pubkey", "def456..."]
|
||||
const command_array = `["${commandRuleType}", "${commandPatternType}", "${ruleData.pattern_value}"]`;
|
||||
const command_array = [commandRuleType, commandPatternType, ruleData.pattern_value];
|
||||
|
||||
// Encrypt the command content using NIP-44 (same as working tests)
|
||||
const encrypted_content = await encryptForRelay(command_array);
|
||||
// Encrypt the command array directly using NIP-44
|
||||
const encrypted_content = await encryptForRelay(JSON.stringify(command_array));
|
||||
if (!encrypted_content) {
|
||||
throw new Error('Failed to encrypt auth rule command');
|
||||
throw new Error('Failed to encrypt command array');
|
||||
}
|
||||
|
||||
// Create kind 23456 admin event with encrypted content (same as working tests)
|
||||
// Create single kind 23456 admin event
|
||||
const authEvent = {
|
||||
kind: 23456,
|
||||
pubkey: userPubkey,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: [
|
||||
["p", getRelayPubkey()]
|
||||
],
|
||||
tags: [["p", getRelayPubkey()]],
|
||||
content: encrypted_content
|
||||
};
|
||||
|
||||
// DEBUG: Log the complete event structure being sent
|
||||
console.log('=== AUTH RULE EVENT DEBUG (FIXED FORMAT) ===');
|
||||
console.log('=== AUTH RULE EVENT DEBUG (Administrator API) ===');
|
||||
console.log('Original Rule Data:', ruleData);
|
||||
console.log('Command Array:', command_array);
|
||||
console.log('Encrypted Content:', encrypted_content.substring(0, 50) + '...');
|
||||
console.log('Auth Event (before signing):', JSON.stringify(authEvent, null, 2));
|
||||
console.log('=== END AUTH RULE EVENT DEBUG ===');
|
||||
|
||||
// Sign the event using the standard NIP-07 interface
|
||||
// Sign the event
|
||||
const signedEvent = await window.nostr.signEvent(authEvent);
|
||||
if (!signedEvent || !signedEvent.sig) {
|
||||
throw new Error('Event signing failed');
|
||||
@@ -2988,7 +2981,7 @@
|
||||
// DATABASE STATISTICS FUNCTIONS
|
||||
// ================================
|
||||
|
||||
// Send stats_query command to get database statistics
|
||||
// Send stats_query command to get database statistics using Administrator API (inner events)
|
||||
async function sendStatsQuery() {
|
||||
if (!isLoggedIn || !userPubkey) {
|
||||
log('Must be logged in to query database statistics', 'ERROR');
|
||||
@@ -3006,22 +2999,20 @@
|
||||
updateStatsStatus('loading', 'Querying database...');
|
||||
|
||||
// Create command array for stats query
|
||||
const command_array = '["stats_query", "all"]';
|
||||
const command_array = ["stats_query", "all"];
|
||||
|
||||
// Encrypt the command content using NIP-44
|
||||
const encrypted_content = await encryptForRelay(command_array);
|
||||
// Encrypt the command array directly using NIP-44
|
||||
const encrypted_content = await encryptForRelay(JSON.stringify(command_array));
|
||||
if (!encrypted_content) {
|
||||
throw new Error('Failed to encrypt stats query command');
|
||||
throw new Error('Failed to encrypt command array');
|
||||
}
|
||||
|
||||
// Create kind 23456 admin event
|
||||
// Create single kind 23456 admin event
|
||||
const statsEvent = {
|
||||
kind: 23456,
|
||||
pubkey: userPubkey,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: [
|
||||
["p", getRelayPubkey()]
|
||||
],
|
||||
tags: [["p", getRelayPubkey()]],
|
||||
content: encrypted_content
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user