This commit is contained in:
payacom
2026-08-31 20:45:41 +03:30
parent fa9f23c61d
commit 3f416a7a60
367 changed files with 621895 additions and 6443 deletions

29
utils/e2ee.js Normal file
View File

@@ -0,0 +1,29 @@
/**
* E2EE helpers — server never decrypts; only detects envelopes and opaques previews.
*/
const E2EE_PREVIEW = '🔒 پیام رمزنگاری‌شده'
function isE2eeEnvelope(content) {
if (!content || typeof content !== 'string') return false
const trimmed = content.trim()
if (!trimmed.startsWith('{')) return false
try {
const parsed = JSON.parse(trimmed)
return Boolean(parsed && parsed.e2ee === true && parsed.ciphertext)
} catch {
return false
}
}
function opaquePreview(content, maxLen = 80) {
if (isE2eeEnvelope(content)) return E2EE_PREVIEW
const text = String(content || 'پیام')
return text.slice(0, maxLen)
}
module.exports = {
E2EE_PREVIEW,
isE2eeEnvelope,
opaquePreview
}