diff --git a/src/lib/commands/chatlog.ts b/src/lib/commands/chatlog.ts
index 1a2b507..7e34de6 100644
--- a/src/lib/commands/chatlog.ts
+++ b/src/lib/commands/chatlog.ts
@@ -18,7 +18,11 @@ const command: Command = {
reply('(wip) Here are the chat logs:');
- reply(lines.join('\n'));
+ reply({
+ message: lines.join('\n'),
+ type: 'text',
+ encrypted: true
+ });
}
};
diff --git a/src/lib/commands/components/ChatMessage.svelte b/src/lib/commands/components/ChatMessage.svelte
index dd0b5eb..864a247 100644
--- a/src/lib/commands/components/ChatMessage.svelte
+++ b/src/lib/commands/components/ChatMessage.svelte
@@ -67,6 +67,28 @@
}
}
+ function getMeta() {
+ if (message.encrypted) {
+ // Tries to decrypt the message, if failed, return error message
+ const key = localStorage.getItem('chat-os-encryption-key');
+
+ if (!key) {
+ return '[no encryption key set]';
+ }
+
+ try {
+ const decrypted = decryptMessage(message.meta as string, key);
+
+ return decrypted;
+ } catch (e) {
+ console.info(e);
+ return '[decryption failed]';
+ }
+ } else {
+ return message.meta;
+ }
+ }
+
const decryptMessage = (messageWithNonce: string, key: string) => {
const keyUint8Array = decodeBase64(key);
const messageWithNonceAsUint8Array = decodeBase64(messageWithNonce);
@@ -194,13 +216,13 @@
{/if}
{#if message.type == 'image'}
-
+
{:else if message.type == 'link'}
{getMessage()}
{:else if message.type == 'component'}
{#if getMessage() in components}
-
+
{/if}
{:else}
{#each getMessage().split('\n') as line}
diff --git a/src/lib/commands/promptpay-qr.ts b/src/lib/commands/promptpay-qr.ts
index 87bdeec..31bad36 100644
--- a/src/lib/commands/promptpay-qr.ts
+++ b/src/lib/commands/promptpay-qr.ts
@@ -27,7 +27,8 @@ const command: Command = {
message: await QRCode.toDataURL(ppqr(args[1], { amount: args[3] ? +args[3] : undefined }), {
scale: 6
}),
- options: { alt }
+ options: { alt },
+ encrypted: true
});
}
};
diff --git a/src/lib/commands/qr.ts b/src/lib/commands/qr.ts
index d8af37b..e668543 100644
--- a/src/lib/commands/qr.ts
+++ b/src/lib/commands/qr.ts
@@ -21,7 +21,8 @@ const command: Command = {
reply({
type: 'image',
message: await QRCode.toDataURL(args[1], { scale: 6 }),
- options: { alt: args[1] }
+ options: { alt: args[1] },
+ encrypted: true
});
}
};
diff --git a/src/lib/commands/timer.ts b/src/lib/commands/timer.ts
index 25ba47c..994837f 100644
--- a/src/lib/commands/timer.ts
+++ b/src/lib/commands/timer.ts
@@ -21,6 +21,7 @@ const command: Command = {
reply({
type: 'component',
message: 'timer',
+ encrypted: true,
options: { seconds, startAt: Date.now(), name: args.name || null }
});
}
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index b6f6ac9..53a21c2 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -1,12 +1,13 @@