30 lines
737 B
JavaScript
30 lines
737 B
JavaScript
/**
|
|
* 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
|
|
}
|