v0.7.39 - Set dm's back 2 days to adjust for timestamp ramdomization of giftwraps.
This commit is contained in:
28
api/index.js
28
api/index.js
@@ -1064,7 +1064,7 @@ async function subscribeToConfiguration() {
|
||||
"#p": [userPubkey], // Only DMs directed to this user
|
||||
limit: 50
|
||||
}, {
|
||||
since: Math.floor(Date.now() / 1000), // Start from current time
|
||||
since: Math.floor(Date.now() / 1000) - (2 * 24 * 60 * 60), // Look back 2 days for NIP-59 randomized timestamps
|
||||
kinds: [1059], // NIP-17 GiftWrap events
|
||||
"#p": [userPubkey], // Only GiftWrap events addressed to this user
|
||||
limit: 50
|
||||
@@ -1080,7 +1080,7 @@ async function subscribeToConfiguration() {
|
||||
if (event.kind === 24567) {
|
||||
const dTag = event.tags.find(tag => tag[0] === 'd');
|
||||
const dataType = dTag ? dTag[1] : 'unknown';
|
||||
console.log(`📊 Monitoring event: ${dataType}`);
|
||||
// console.log(`📊 Monitoring event: ${dataType}`);
|
||||
} else {
|
||||
console.log(`📨 Event received: kind ${event.kind}`);
|
||||
}
|
||||
@@ -1111,20 +1111,32 @@ async function subscribeToConfiguration() {
|
||||
|
||||
// Handle NIP-17 GiftWrap DMs
|
||||
if (event.kind === 1059) {
|
||||
console.log(`📨 RECEIVED KIND 1059 EVENT:`, {
|
||||
id: event.id,
|
||||
pubkey: event.pubkey,
|
||||
created_at: event.created_at,
|
||||
content: event.content.substring(0, 100) + '...',
|
||||
tags: event.tags
|
||||
});
|
||||
|
||||
try {
|
||||
// Step 1: Unwrap gift wrap to get seal
|
||||
const sealJson = await window.nostr.nip44.decrypt(event.pubkey, event.content);
|
||||
console.log(`🔓 STEP 1 - Unwrapped gift wrap:`, sealJson.substring(0, 100) + '...');
|
||||
const seal = safeJsonParse(sealJson);
|
||||
if (!seal || seal.kind !== 13) {
|
||||
throw new Error('Unwrapped content is not a valid seal (kind 13)');
|
||||
}
|
||||
console.log(`✅ Seal validated:`, { kind: seal.kind, pubkey: seal.pubkey.substring(0, 16) + '...' });
|
||||
|
||||
// Step 2: Unseal to get rumor
|
||||
const rumorJson = await window.nostr.nip44.decrypt(seal.pubkey, seal.content);
|
||||
console.log(`🔓 STEP 2 - Unsealed rumor:`, rumorJson.substring(0, 100) + '...');
|
||||
const rumor = safeJsonParse(rumorJson);
|
||||
if (!rumor || rumor.kind !== 14) {
|
||||
throw new Error('Unsealed content is not a valid rumor (kind 14)');
|
||||
}
|
||||
console.log(`✅ Rumor validated:`, { kind: rumor.kind, pubkey: rumor.pubkey.substring(0, 16) + '...', content: rumor.content.substring(0, 50) + '...' });
|
||||
|
||||
log(`Received NIP-17 DM from relay: ${rumor.content.substring(0, 50)}...`, 'INFO');
|
||||
|
||||
@@ -1137,6 +1149,7 @@ async function subscribeToConfiguration() {
|
||||
logTestEvent('RECV', `NIP-17 DM: ${rumor.content}`, 'DM');
|
||||
}
|
||||
} catch (unwrapError) {
|
||||
console.error(`❌ NIP-17 DM UNWRAP FAILED:`, unwrapError);
|
||||
log(`Failed to unwrap NIP-17 DM: ${unwrapError.message}`, 'ERROR');
|
||||
if (typeof logTestEvent === 'function') {
|
||||
logTestEvent('ERROR', `Failed to unwrap DM: ${unwrapError.message}`, 'DM');
|
||||
@@ -2106,8 +2119,8 @@ if (relayPubkeyContainer) {
|
||||
const relayPubkeyElement = document.getElementById('relay-pubkey');
|
||||
if (relayPubkeyElement && relayPubkeyElement.textContent !== 'Loading...') {
|
||||
try {
|
||||
// Get the full npub (remove line breaks for clipboard)
|
||||
const fullNpub = relayPubkeyElement.textContent.replace(/\n/g, '');
|
||||
// Get the full npub (remove all whitespace for continuous string)
|
||||
const fullNpub = relayPubkeyElement.textContent.replace(/\s/g, '');
|
||||
|
||||
await navigator.clipboard.writeText(fullNpub);
|
||||
|
||||
@@ -3536,6 +3549,13 @@ async function sendNIP17DM() {
|
||||
throw new Error('Failed to sign gift wrap event');
|
||||
}
|
||||
|
||||
// DEBUG: Log NIP-17 event details when created
|
||||
console.log('=== NIP-17 EVENT CREATED ===');
|
||||
console.log('Full event:', JSON.stringify(signedGiftWrap, null, 2));
|
||||
console.log('Timestamp:', signedGiftWrap.created_at);
|
||||
console.log('Local date time:', new Date(signedGiftWrap.created_at * 1000).toLocaleString());
|
||||
console.log('=== END NIP-17 EVENT DEBUG ===');
|
||||
|
||||
log('NIP-17 DM event created and signed with ephemeral key, publishing...', 'INFO');
|
||||
|
||||
// Publish via SimplePool
|
||||
|
||||
Reference in New Issue
Block a user