mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-03 08:07:21 +00:00
give 1059s a fuzzed time
This commit is contained in:
1 parent
79b03dee38
commit
cb50cbe137
2 files changed
+26
-16
No files matched your search
+15
-13
@@ -371,10 +371,10 @@ export function DMProvider({ children, protocolMode = PROTOCOL_MODE.NIP17_ONLY,
|
||||
}
|
||||
} else if (msg.kind === 1059) {
|
||||
const { processedMessage } = await processNIP17GiftWrap(msg);
|
||||
// Use the real message (kind 14) with real timestamp, not gift wrap
|
||||
return {
|
||||
...msg,
|
||||
decryptedContent: processedMessage.decryptedContent,
|
||||
error: processedMessage.error,
|
||||
...processedMessage,
|
||||
content: msg.content, // Keep original encrypted content
|
||||
} as NostrEvent & { decryptedContent?: string; error?: string };
|
||||
}
|
||||
return msg;
|
||||
@@ -480,13 +480,14 @@ export function DMProvider({ children, protocolMode = PROTOCOL_MODE.NIP17_ONLY,
|
||||
for (const giftWrap of messages) {
|
||||
const { processedMessage, conversationPartner } = await processNIP17GiftWrap(giftWrap);
|
||||
|
||||
// Use the real message (kind 14) timestamp, not the randomized gift wrap timestamp
|
||||
const messageWithAnimation: DecryptedMessage = {
|
||||
...giftWrap,
|
||||
decryptedContent: processedMessage.decryptedContent,
|
||||
error: processedMessage.error,
|
||||
...processedMessage,
|
||||
content: giftWrap.content, // Keep original encrypted content for storage
|
||||
};
|
||||
|
||||
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) {
|
||||
messageWithAnimation.clientFirstSeen = Date.now();
|
||||
}
|
||||
@@ -774,13 +775,14 @@ export function DMProvider({ children, protocolMode = PROTOCOL_MODE.NIP17_ONLY,
|
||||
|
||||
const { processedMessage, conversationPartner } = await processNIP17GiftWrap(event);
|
||||
|
||||
// Use the real message (kind 14) timestamp, not the randomized gift wrap timestamp
|
||||
const messageWithAnimation: DecryptedMessage = {
|
||||
...event,
|
||||
decryptedContent: processedMessage.decryptedContent,
|
||||
error: processedMessage.error,
|
||||
...processedMessage,
|
||||
content: event.content, // Keep original encrypted content for storage
|
||||
};
|
||||
|
||||
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) {
|
||||
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 optimisticMessage: DecryptedMessage = {
|
||||
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,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
created_at: Math.floor(Date.now() / 1000), // Real timestamp
|
||||
tags: [['p', recipientPubkey]],
|
||||
content: '',
|
||||
decryptedContent: content,
|
||||
|
||||
+11
-3
@@ -134,6 +134,14 @@ export function useSendDM(): UseSendDMReturn {
|
||||
// Step 1: Create the inner Kind 14 Private Direct Message
|
||||
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
|
||||
const messageContent = prepareMessageContent(content, attachments);
|
||||
|
||||
@@ -176,19 +184,19 @@ export function useSendDM(): UseSendDMReturn {
|
||||
const recipientRandomSigner = 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([
|
||||
recipientRandomSigner.sign({
|
||||
kind: 1059,
|
||||
pubkey: getPublicKey(recipientRandomSigner.privateKey),
|
||||
created_at: now,
|
||||
created_at: randomizeTimestamp(now), // Randomized to hide real send time
|
||||
tags: [['p', recipientPubkey]],
|
||||
content: await recipientRandomSigner.nip44!.encrypt(recipientPubkey, JSON.stringify(recipientSeal)),
|
||||
}),
|
||||
senderRandomSigner.sign({
|
||||
kind: 1059,
|
||||
pubkey: getPublicKey(senderRandomSigner.privateKey),
|
||||
created_at: now,
|
||||
created_at: randomizeTimestamp(now), // Randomized to hide real send time
|
||||
tags: [['p', user.pubkey]],
|
||||
content: await senderRandomSigner.nip44!.encrypt(user.pubkey, JSON.stringify(senderSeal)),
|
||||
}),
|
||||
|
||||
Reference in new issue
Block a user