Privatri works locally.
This commit is contained in:
@@ -43,6 +43,7 @@ apx.crypto.decryptMessage = async (encryptedMessage, privateKey) => {
|
|||||||
decryptionKeys: privateKey,
|
decryptionKeys: privateKey,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
apx.crypto.isSignedby = async (
|
apx.crypto.isSignedby = async (
|
||||||
alias,
|
alias,
|
||||||
publicKey,
|
publicKey,
|
||||||
@@ -69,6 +70,7 @@ apx.crypto.isSignedby = async (
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
apx.crypto.sign = async (message, privateKey) => {
|
apx.crypto.sign = async (message, privateKey) => {
|
||||||
privateKey = await openpgp.readPrivateKey(
|
privateKey = await openpgp.readPrivateKey(
|
||||||
{
|
{
|
||||||
@@ -118,4 +120,19 @@ apx.crypto.verifySignature = async (message, signature, publicKey) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default apx;
|
apx.crypto.genUUID = () => {
|
||||||
|
const uuidTemplate = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
|
||||||
|
return uuidTemplate.replace(/[xy]/g, (char) => {
|
||||||
|
const random = Math.random() * 16 | 0;
|
||||||
|
|
||||||
|
let value;
|
||||||
|
|
||||||
|
if (char === "x") {
|
||||||
|
value = random;
|
||||||
|
} else {
|
||||||
|
value = (random & 0x3) | 0x8;
|
||||||
|
};
|
||||||
|
|
||||||
|
return value.toString(16);
|
||||||
|
});
|
||||||
|
};
|
@@ -15,7 +15,9 @@ apx.privatri.loadwco = async (id, dataObj = {}, ctx = null) => {
|
|||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
const template = JSON.parse(localStorage.getItem("admin")).tpl[`privatri${id}`];
|
const templatesObj = JSON.parse(localStorage.getItem("admin")).tpl;
|
||||||
|
|
||||||
|
const template = Object.entries(templatesObj).find(([key]) => key.toLowerCase() === `privatri${id}`.toLocaleLowerCase())?.[1];
|
||||||
|
|
||||||
return Mustache.render(template, dataObj);
|
return Mustache.render(template, dataObj);
|
||||||
};
|
};
|
||||||
@@ -44,9 +46,9 @@ apx.privatri.templates.scripts = {
|
|||||||
const { publicKey, privateKey } = await apx.crypto.genKey();
|
const { publicKey, privateKey } = await apx.crypto.genKey();
|
||||||
|
|
||||||
const messageObj = await (async (publicKey) => {
|
const messageObj = await (async (publicKey) => {
|
||||||
const uuid = crypto.randomUUID();
|
const uuid = apx.crypto.genUUID();
|
||||||
const timestamp = Date.now();
|
const timestamp = Date.now();
|
||||||
const alias = await apx.crypto.encryptMessage(JSON.parse(localStorage.getItem("apx")).data.headers.xalias, publicKey);
|
const alias = await apx.crypto.encryptMessage(JSON.parse(localStorage.getItem("admin")).headers.xalias, publicKey);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
privatriid: `${uuid}_${timestamp}`,
|
privatriid: `${uuid}_${timestamp}`,
|
||||||
@@ -153,7 +155,7 @@ apx.privatri.templates.scripts = {
|
|||||||
|
|
||||||
document.querySelectorAll("button.removeAliasBtn").forEach(btn => {
|
document.querySelectorAll("button.removeAliasBtn").forEach(btn => {
|
||||||
btn.addEventListener("click", async () => {
|
btn.addEventListener("click", async () => {
|
||||||
if (JSON.parse(localStorage.getItem("apx")).data.headers.xalias === (await apx.crypto.decryptMessage(ownerAlias, privateKey)).data) {
|
if (JSON.parse(localStorage.getItem("admin")).headers.xalias === (await apx.crypto.decryptMessage(ownerAlias, privateKey)).data) {
|
||||||
if (btn.getAttribute("data-alias") !== ownerAlias) {
|
if (btn.getAttribute("data-alias") !== ownerAlias) {
|
||||||
const alias = btn.getAttribute("data-alias");
|
const alias = btn.getAttribute("data-alias");
|
||||||
aliasesArray = aliasesArray.filter(a => a !== alias);
|
aliasesArray = aliasesArray.filter(a => a !== alias);
|
||||||
@@ -222,7 +224,7 @@ apx.privatri.templates.scripts = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
applyModificationsBtnEl.addEventListener("click", async () => {
|
applyModificationsBtnEl.addEventListener("click", async () => {
|
||||||
if (JSON.parse(localStorage.getItem("apx")).data.headers.xalias === (await apx.crypto.decryptMessage(ownerAlias, privateKey)).data) {
|
if (JSON.parse(localStorage.getItem("admin")).headers.xalias === (await apx.crypto.decryptMessage(ownerAlias, privateKey)).data) {
|
||||||
messageObj.title = await apx.crypto.encryptMessage(threadNameInputEl.value, privateKey);
|
messageObj.title = await apx.crypto.encryptMessage(threadNameInputEl.value, privateKey);
|
||||||
messageObj.dt_autodestruction = (() => {
|
messageObj.dt_autodestruction = (() => {
|
||||||
const selectedBtn = Array.from(autoDeletionBtnElArray).find(btn => btn.classList.contains("bg-base-200"));
|
const selectedBtn = Array.from(autoDeletionBtnElArray).find(btn => btn.classList.contains("bg-base-200"));
|
||||||
@@ -253,9 +255,26 @@ async function getOldestPrivatriids(dbName, storeName) {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const request = indexedDB.open(dbName, 1);
|
const request = indexedDB.open(dbName, 1);
|
||||||
|
|
||||||
|
request.onupgradeneeded = (event) => {
|
||||||
|
const db = event.target.result;
|
||||||
|
|
||||||
|
if (!db.objectStoreNames.contains("threads")) {
|
||||||
|
db.createObjectStore("threads", { keyPath: "uuid" });
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!db.objectStoreNames.contains("messages")) {
|
||||||
|
db.createObjectStore("messages", { keyPath: "privatriid" });
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
request.onsuccess = (event) => {
|
request.onsuccess = (event) => {
|
||||||
const db = event.target.result;
|
const db = event.target.result;
|
||||||
|
|
||||||
|
if (!db.objectStoreNames.contains(storeName)) {
|
||||||
|
resolve([]);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
const transaction = db.transaction(storeName, "readonly");
|
const transaction = db.transaction(storeName, "readonly");
|
||||||
const store = transaction.objectStore(storeName);
|
const store = transaction.objectStore(storeName);
|
||||||
const cursorRequest = store.openCursor();
|
const cursorRequest = store.openCursor();
|
||||||
@@ -288,10 +307,18 @@ async function getOldestPrivatriids(dbName, storeName) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
apx.ready(async () => {
|
apx.ready(async () => {
|
||||||
await (async () => {
|
document.querySelector("body").innerHTML = await apx.privatri.loadwco("main", JSON.parse(localStorage.getItem("admin")).tpldata.privatri_main_privatri);
|
||||||
console.log("ok")
|
|
||||||
document.querySelector("body").innerHTML = await apx.privatri.loadwco("main");
|
|
||||||
|
|
||||||
|
const bodyEl = document.querySelector("body");
|
||||||
|
const searchInputEl = document.querySelector("#threadSearchBar");
|
||||||
|
const threadFilterOptionsElArray = document.querySelector("#threadFilterOptions").querySelectorAll("li");
|
||||||
|
const threadsContainerEl = document.querySelector("#threadsContainer");
|
||||||
|
const threadPageEl = document.querySelector("#threadPage");
|
||||||
|
const messageInputEl = document.getElementById("messageInput");
|
||||||
|
const messagesContainerEl = document.querySelector("#messagesContainer");
|
||||||
|
const attachmentsInputEl = document.querySelector("#attachmentsInput");
|
||||||
|
|
||||||
|
await (async () => {
|
||||||
const lastConnection = JSON.parse(localStorage.getItem("lastConnection")) || Date.now();
|
const lastConnection = JSON.parse(localStorage.getItem("lastConnection")) || Date.now();
|
||||||
|
|
||||||
await apx.privatri.syncronizeBackend(apx.data.headers.xalias, lastConnection);
|
await apx.privatri.syncronizeBackend(apx.data.headers.xalias, lastConnection);
|
||||||
@@ -299,7 +326,7 @@ apx.ready(async () => {
|
|||||||
const privatriidArray = await getOldestPrivatriids("privatri", "messages");
|
const privatriidArray = await getOldestPrivatriids("privatri", "messages");
|
||||||
|
|
||||||
const thread = async (name, uuid) => {
|
const thread = async (name, uuid) => {
|
||||||
return await apx.privatri.loadwco("threadAliasList", { uuid, name });
|
return await apx.privatri.loadwco("thread", { uuid, name });
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const privatriid of privatriidArray) {
|
for (const privatriid of privatriidArray) {
|
||||||
@@ -387,6 +414,8 @@ apx.ready(async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
threadsContainerEl.children[0]?.click();
|
||||||
|
|
||||||
document.querySelectorAll("a").forEach(link => {
|
document.querySelectorAll("a").forEach(link => {
|
||||||
link.addEventListener("click", async (event) => {
|
link.addEventListener("click", async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -399,22 +428,13 @@ apx.ready(async () => {
|
|||||||
window.history.pushState({}, "", `${window.location.pathname}?uuid=${threadPageEl.getAttribute("data-uuid")}`);
|
window.history.pushState({}, "", `${window.location.pathname}?uuid=${threadPageEl.getAttribute("data-uuid")}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
bodyEl.firstElementChild.innerHTML = await apx.privatri.loadwco(templateName);
|
bodyEl.innerHTML = await apx.privatri.loadwco(templateName);
|
||||||
|
|
||||||
await apx.privatri.templates.scripts[templateName]();
|
await apx.privatri.templates.scripts[templateName]();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const bodyEl = document.querySelector("body");
|
|
||||||
const searchInputEl = document.querySelector("#threadSearchBar");
|
|
||||||
const threadFilterOptionsElArray = document.querySelector("#threadFilterOptions").querySelectorAll("li");
|
|
||||||
const threadsContainerEl = document.querySelector("#threadsContainer");
|
|
||||||
const threadPageEl = document.querySelector("#threadPage");
|
|
||||||
const messageInputEl = document.getElementById("messageInput");
|
|
||||||
const messagesContainerEl = document.querySelector("#messagesContainer");
|
|
||||||
const attachmentsInputEl = document.querySelector("#attachmentsInput");
|
|
||||||
|
|
||||||
function formatDate(timestamp) {
|
function formatDate(timestamp) {
|
||||||
const date = new Date(timestamp);
|
const date = new Date(timestamp);
|
||||||
const day = String(date.getDate()).padStart(2, "0");
|
const day = String(date.getDate()).padStart(2, "0");
|
||||||
@@ -486,7 +506,7 @@ apx.ready(async () => {
|
|||||||
if (message !== "") {
|
if (message !== "") {
|
||||||
const messageObj = await (async (publicKey) => {
|
const messageObj = await (async (publicKey) => {
|
||||||
const timestamp = Date.now();
|
const timestamp = Date.now();
|
||||||
const alias = await apx.crypto.encryptMessage(JSON.parse(localStorage.getItem("apx")).data.headers.xalias, publicKey);
|
const alias = await apx.crypto.encryptMessage(JSON.parse(localStorage.getItem("admin")).headers.xalias, publicKey);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
privatriid: `${threadPageEl.getAttribute("data-uuid")}_${timestamp}`,
|
privatriid: `${threadPageEl.getAttribute("data-uuid")}_${timestamp}`,
|
||||||
@@ -538,28 +558,28 @@ apx.ready(async () => {
|
|||||||
|
|
||||||
const privateKey = (await apx.indexedDB.get("privatri", "threads", threadPageEl.getAttribute("data-uuid"))).privateKey;
|
const privateKey = (await apx.indexedDB.get("privatri", "threads", threadPageEl.getAttribute("data-uuid"))).privateKey;
|
||||||
|
|
||||||
const signatureMessage = `${JSON.parse(localStorage.getItem("apx")).data.headers.xalias}_${threadPageEl.getAttribute("data-uuid")}_${messageEl.getAttribute("data-timestamp")}`;
|
const signatureMessage = `${JSON.parse(localStorage.getItem("admin")).headers.xalias}_${threadPageEl.getAttribute("data-uuid")}_${messageEl.getAttribute("data-timestamp")}`;
|
||||||
const signature = await apx.crypto.sign(signatureMessage, privateKey);
|
const signature = await apx.crypto.sign(signatureMessage, privateKey);
|
||||||
|
|
||||||
let verified = false;
|
let verified = false;
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
verified = await fetch("", {
|
// verified = await fetch("", {
|
||||||
method: "GET",
|
// method: "GET",
|
||||||
body: JSON.stringify({
|
// body: JSON.stringify({
|
||||||
message: signatureMessage,
|
// message: signatureMessage,
|
||||||
signature: signature,
|
// signature: signature,
|
||||||
uuid: threadPageEl.getAttribute("data-uuid"),
|
// uuid: threadPageEl.getAttribute("data-uuid"),
|
||||||
timestamp: messageEl.getAttribute("data-timestamp"),
|
// timestamp: messageEl.getAttribute("data-timestamp"),
|
||||||
})
|
// })
|
||||||
});
|
// });
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
console.error("Error while verifying signature:", error);
|
// console.error("Error while verifying signature:", error);
|
||||||
};
|
// };
|
||||||
|
|
||||||
const authorAlias = await apx.crypto.decryptMessage((await apx.indexedDB.get("privatri", "messages", `${threadPageEl.getAttribute("data-uuid")}_${messageEl.getAttribute("data-timestamp")}`)).sender_alias, privateKey).data;
|
const authorAlias = (await apx.crypto.decryptMessage((await apx.indexedDB.get("privatri", "messages", `${threadPageEl.getAttribute("data-uuid")}_${messageEl.getAttribute("data-timestamp")}`)).sender_alias, privateKey)).data;
|
||||||
|
|
||||||
if ((JSON.parse(localStorage.getItem("apx")).data.headers.xalias === authorAlias) && (verified === true)) {
|
if ((JSON.parse(localStorage.getItem("admin")).headers.xalias === authorAlias) && (verified === true)) {
|
||||||
await apx.indexedDB.del("privatri", "messages", `${threadPageEl.getAttribute("data-uuid")}_${messageEl.getAttribute("data-timestamp")}`);
|
await apx.indexedDB.del("privatri", "messages", `${threadPageEl.getAttribute("data-uuid")}_${messageEl.getAttribute("data-timestamp")}`);
|
||||||
|
|
||||||
messageEl.remove();
|
messageEl.remove();
|
||||||
@@ -577,7 +597,7 @@ apx.ready(async () => {
|
|||||||
|
|
||||||
const authorAlias = (await apx.crypto.decryptMessage((await apx.indexedDB.get("privatri", "messages", `${threadPageEl.getAttribute("data-uuid")}_${messageEl.getAttribute("data-timestamp")}`)).sender_alias, (await apx.indexedDB.get("privatri", "threads", threadPageEl.getAttribute("data-uuid"))).privateKey)).data;
|
const authorAlias = (await apx.crypto.decryptMessage((await apx.indexedDB.get("privatri", "messages", `${threadPageEl.getAttribute("data-uuid")}_${messageEl.getAttribute("data-timestamp")}`)).sender_alias, (await apx.indexedDB.get("privatri", "threads", threadPageEl.getAttribute("data-uuid"))).privateKey)).data;
|
||||||
|
|
||||||
if (JSON.parse(localStorage.getItem("apx")).data.headers.xalias === authorAlias) {
|
if (JSON.parse(localStorage.getItem("admin")).headers.xalias === authorAlias) {
|
||||||
const messageValue = messageEl.querySelector("div.message").innerText;
|
const messageValue = messageEl.querySelector("div.message").innerText;
|
||||||
|
|
||||||
const attachmentsArray = (() => {
|
const attachmentsArray = (() => {
|
||||||
|
@@ -45,6 +45,7 @@
|
|||||||
<script src="/apxtrilib/checkjson.js"></script>
|
<script src="/apxtrilib/checkjson.js"></script>
|
||||||
|
|
||||||
<script src="/api/apxtri/wwws/getwco/apx.js?wcotribe=apxtri&tribe=apxtri&xapp=admin&pagename=privatri&code=enjoy"></script>
|
<script src="/api/apxtri/wwws/getwco/apx.js?wcotribe=apxtri&tribe=apxtri&xapp=admin&pagename=privatri&code=enjoy"></script>
|
||||||
|
<script src="/api/apxtri/wwws/getwco/crypto.js?wcotribe=apxtri&tribe=apxtri&xapp=admin&pagename=privatri&code=enjoy"></script>
|
||||||
<script src="/api/apxtri/wwws/getwco/privatri.js?wcotribe=apxtri&tribe=apxtri&xapp=admin&pagename=privatri&code=enjoy&tagid=main"></script>
|
<script src="/api/apxtri/wwws/getwco/privatri.js?wcotribe=apxtri&tribe=apxtri&xapp=admin&pagename=privatri&code=enjoy&tagid=main"></script>
|
||||||
</head>
|
</head>
|
||||||
<body class="bg-base-100 flex items-center justify-center h-screen w-screen ">
|
<body class="bg-base-100 flex items-center justify-center h-screen w-screen ">
|
||||||
|
Reference in New Issue
Block a user