added encryption

This commit is contained in:
2026-03-09 10:54:07 +05:30
parent 6e184dc590
commit 6720e28d08
27 changed files with 2093 additions and 709 deletions

View File

@@ -2,10 +2,11 @@ import { useAuth } from '../contexts/AuthContext'
import { Link } from 'react-router-dom'
import { useState } from 'react'
import { createEntry } from '../lib/api'
import { encryptEntry } from '../lib/crypto'
import BottomNav from '../components/BottomNav'
export default function HomePage() {
const { user, userId, loading, signOut } = useAuth()
const { user, userId, secretKey, loading } = useAuth()
const [entry, setEntry] = useState('')
const [title, setTitle] = useState('')
const [saving, setSaving] = useState(false)
@@ -41,22 +42,45 @@ export default function HomePage() {
return
}
if (!secretKey) {
setMessage({ type: 'error', text: 'Encryption key not available. Please log in again.' })
return
}
setSaving(true)
setMessage(null)
try {
const token = await user.getIdToken()
// Combine title and content for encryption
const contentToEncrypt = `${title.trim()}\n\n${entry.trim()}`
// Encrypt the entry with master key
const { ciphertext, nonce } = await encryptEntry(
contentToEncrypt,
secretKey
)
// Send encrypted data to backend
// Note: title and content are null for encrypted entries
await createEntry(
userId,
{
title: title.trim(),
content: entry.trim(),
title: undefined,
content: undefined,
isPublic: false,
encryption: {
encrypted: true,
ciphertext,
nonce,
algorithm: 'XSalsa20-Poly1305',
},
},
token
)
setMessage({ type: 'success', text: 'Entry saved successfully!' })
setMessage({ type: 'success', text: 'Entry saved securely!' })
setTitle('')
setEntry('')