full
This commit is contained in:
29
utils/e2ee.js
Normal file
29
utils/e2ee.js
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user