Version 0.7.0

This commit is contained in:
Aslan 2026-01-20 14:09:05 -05:00
parent 64ad8498f5
commit 6b6bbdc142
112 changed files with 3828 additions and 188 deletions

View file

@ -4,15 +4,16 @@ import {
updateMessageApi,
removeMessageApi,
} from "../../api/message";
import { deleteChannelMessage, setChannelMessage } from "../../store/channel";
import { deleteAttachment } from "../../store/file";
import { deleteMessage, setMessage } from "../../store/message";
import { state } from "../../store/state";
import {
bytesToHex,
base64ToBuffer,
bufferToBase64,
decryptData,
encryptData,
generateIv,
hexToBytes,
} from "../crypto";
import { fetchMedia } from "../file";
@ -66,10 +67,10 @@ const createMessage = async (
if (typeof data.error === "string") {
return;
}
setMessage({
...data,
text: text,
decryptionStatus: true,
});
attachments.forEach((attachmentId) => {
@ -77,20 +78,31 @@ const createMessage = async (
});
};
const updateMessage = async (id: string, text: string) => {
const updateMessage = async (id: string, text: string, communityId: string) => {
const encrypted = await encryptMessage(communityId, text);
if (!encrypted) {
return;
}
const [encryptedMessage, iv] = encrypted;
const data = await updateMessageApi({
id: id,
text: text,
iv: iv,
text: encryptedMessage,
});
if (typeof data.error === "string") {
return;
}
setMessage(data);
setMessage({
...data,
text: text,
decryptionStatus: true,
});
};
const removeMessage = async (id: string) => {
const removeMessage = async (id: string, channelId?: string) => {
const data = await removeMessageApi({
id: id,
});
@ -100,6 +112,10 @@ const removeMessage = async (id: string) => {
}
deleteMessage();
if (channelId) {
deleteChannelMessage(channelId, id);
}
};
const encryptMessage = async (
@ -114,7 +130,7 @@ const encryptMessage = async (
const iv = generateIv();
if (text.length === 0) {
return ["", bytesToHex(iv.buffer)];
return ["", bufferToBase64(iv.buffer)];
}
const encrypted = await encryptData<string>({
@ -123,7 +139,7 @@ const encryptMessage = async (
data: text,
});
return [bytesToHex(encrypted), bytesToHex(iv.buffer)];
return [bufferToBase64(encrypted), bufferToBase64(iv.buffer)];
};
const decryptMessage = async (
@ -136,13 +152,13 @@ const decryptMessage = async (
return;
}
const ivBytes = hexToBytes(iv);
const textBytes = hexToBytes(text);
const ivBytes = base64ToBuffer(iv);
const textBytes = base64ToBuffer(text);
if (!ivBytes || !textBytes) {
return;
}
return await decryptData({
return await decryptData<string>({
key: key,
iv: new Uint8Array(ivBytes),
encryptedData: textBytes,