give 1059s a fuzzed time

This commit is contained in:
sam committed 2025-10-19 18:58:13 +07:00
1 parent 79b03dee38
commit cb50cbe137
2 files changed
+26 -16

No files matched your search

+15 -13
View File
@@ -371,10 +371,10 @@ export function DMProvider({ children, protocolMode = PROTOCOL_MODE.NIP17_ONLY,
} }
} else if (msg.kind === 1059) { } else if (msg.kind === 1059) {
const { processedMessage } = await processNIP17GiftWrap(msg); const { processedMessage } = await processNIP17GiftWrap(msg);
// Use the real message (kind 14) with real timestamp, not gift wrap
return { return {
...msg, ...processedMessage,
decryptedContent: processedMessage.decryptedContent, content: msg.content, // Keep original encrypted content
error: processedMessage.error,
} as NostrEvent & { decryptedContent?: string; error?: string }; } as NostrEvent & { decryptedContent?: string; error?: string };
} }
return msg; return msg;
@@ -480,13 +480,14 @@ export function DMProvider({ children, protocolMode = PROTOCOL_MODE.NIP17_ONLY,
for (const giftWrap of messages) { for (const giftWrap of messages) {
const { processedMessage, conversationPartner } = await processNIP17GiftWrap(giftWrap); const { processedMessage, conversationPartner } = await processNIP17GiftWrap(giftWrap);
// Use the real message (kind 14) timestamp, not the randomized gift wrap timestamp
const messageWithAnimation: DecryptedMessage = { const messageWithAnimation: DecryptedMessage = {
...giftWrap, ...processedMessage,
decryptedContent: processedMessage.decryptedContent, content: giftWrap.content, // Keep original encrypted content for storage
error: processedMessage.error,
}; };
const messageAge = Date.now() - (giftWrap.created_at * 1000); // Use real message timestamp for recency check
const messageAge = Date.now() - (processedMessage.created_at * 1000);
if (messageAge < 5000) { if (messageAge < 5000) {
messageWithAnimation.clientFirstSeen = Date.now(); messageWithAnimation.clientFirstSeen = Date.now();
} }
@@ -774,13 +775,14 @@ export function DMProvider({ children, protocolMode = PROTOCOL_MODE.NIP17_ONLY,
const { processedMessage, conversationPartner } = await processNIP17GiftWrap(event); const { processedMessage, conversationPartner } = await processNIP17GiftWrap(event);
// Use the real message (kind 14) timestamp, not the randomized gift wrap timestamp
const messageWithAnimation: DecryptedMessage = { const messageWithAnimation: DecryptedMessage = {
...event, ...processedMessage,
decryptedContent: processedMessage.decryptedContent, content: event.content, // Keep original encrypted content for storage
error: processedMessage.error,
}; };
const messageAge = Date.now() - (event.created_at * 1000); // Use real message timestamp for recency check
const messageAge = Date.now() - (processedMessage.created_at * 1000);
if (messageAge < 5000) { if (messageAge < 5000) {
messageWithAnimation.clientFirstSeen = Date.now(); messageWithAnimation.clientFirstSeen = Date.now();
} }
@@ -1083,9 +1085,9 @@ export function DMProvider({ children, protocolMode = PROTOCOL_MODE.NIP17_ONLY,
const optimisticId = `optimistic-${Date.now()}-${Math.random()}`; const optimisticId = `optimistic-${Date.now()}-${Math.random()}`;
const optimisticMessage: DecryptedMessage = { const optimisticMessage: DecryptedMessage = {
id: optimisticId, id: optimisticId,
kind: protocol === MESSAGE_PROTOCOL.NIP04 ? 4 : 1059, kind: protocol === MESSAGE_PROTOCOL.NIP04 ? 4 : 14, // Use kind 14 for NIP-17 (the real message kind)
pubkey: userPubkey, pubkey: userPubkey,
created_at: Math.floor(Date.now() / 1000), created_at: Math.floor(Date.now() / 1000), // Real timestamp
tags: [['p', recipientPubkey]], tags: [['p', recipientPubkey]],
content: '', content: '',
decryptedContent: content, decryptedContent: content,
+11 -3
View File
@@ -134,6 +134,14 @@ export function useSendDM(): UseSendDMReturn {
// Step 1: Create the inner Kind 14 Private Direct Message // Step 1: Create the inner Kind 14 Private Direct Message
const now = Math.floor(Date.now() / 1000); const now = Math.floor(Date.now() / 1000);
// Generate randomized timestamps for gift wraps (NIP-59 metadata privacy)
// Randomize within ±2 days to hide actual send time from relays
const randomizeTimestamp = (baseTime: number) => {
const twoDaysInSeconds = 2 * 24 * 60 * 60;
const randomOffset = Math.floor(Math.random() * twoDaysInSeconds * 2) - twoDaysInSeconds;
return baseTime + randomOffset;
};
// Prepare content with file URLs // Prepare content with file URLs
const messageContent = prepareMessageContent(content, attachments); const messageContent = prepareMessageContent(content, attachments);
@@ -176,19 +184,19 @@ export function useSendDM(): UseSendDMReturn {
const recipientRandomSigner = new NSecSigner(generateSecretKey()); const recipientRandomSigner = new NSecSigner(generateSecretKey());
const senderRandomSigner = new NSecSigner(generateSecretKey()); const senderRandomSigner = new NSecSigner(generateSecretKey());
// Sign both gift wraps with random keys // Sign both gift wraps with random keys and randomized timestamps
const [recipientGiftWrap, senderGiftWrap] = await Promise.all([ const [recipientGiftWrap, senderGiftWrap] = await Promise.all([
recipientRandomSigner.sign({ recipientRandomSigner.sign({
kind: 1059, kind: 1059,
pubkey: getPublicKey(recipientRandomSigner.privateKey), pubkey: getPublicKey(recipientRandomSigner.privateKey),
created_at: now, created_at: randomizeTimestamp(now), // Randomized to hide real send time
tags: [['p', recipientPubkey]], tags: [['p', recipientPubkey]],
content: await recipientRandomSigner.nip44!.encrypt(recipientPubkey, JSON.stringify(recipientSeal)), content: await recipientRandomSigner.nip44!.encrypt(recipientPubkey, JSON.stringify(recipientSeal)),
}), }),
senderRandomSigner.sign({ senderRandomSigner.sign({
kind: 1059, kind: 1059,
pubkey: getPublicKey(senderRandomSigner.privateKey), pubkey: getPublicKey(senderRandomSigner.privateKey),
created_at: now, created_at: randomizeTimestamp(now), // Randomized to hide real send time
tags: [['p', user.pubkey]], tags: [['p', user.pubkey]],
content: await senderRandomSigner.nip44!.encrypt(user.pubkey, JSON.stringify(senderSeal)), content: await senderRandomSigner.nip44!.encrypt(user.pubkey, JSON.stringify(senderSeal)),
}), }),