From 30b573b5fb54a36da193e14b374887398af82d68 Mon Sep 17 00:00:00 2001 From: Attila Gazso <230163+agazso@users.noreply.github.com> Date: Fri, 24 Nov 2023 16:56:05 +0100 Subject: [PATCH 1/2] fix: group chat editing --- src/lib/adapters/waku/crypto.ts | 4 ++++ src/lib/adapters/waku/index.ts | 14 +++++++------- src/routes/group/chat/[id]/edit/+page.svelte | 2 -- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/lib/adapters/waku/crypto.ts b/src/lib/adapters/waku/crypto.ts index b4a0be7d..fdedf384 100644 --- a/src/lib/adapters/waku/crypto.ts +++ b/src/lib/adapters/waku/crypto.ts @@ -82,3 +82,7 @@ export function privateKeyToPublicKey(privateKey: Hex | Uint8Array): Hex { const publicKeyBytes = getPublicKey(privateKey) return bytesToHex(publicKeyBytes) } + +export function arePublicKeysEqual(pkA: Hex, pkB: Hex): boolean { + return fixHex(pkA) === fixHex(pkB) +} diff --git a/src/lib/adapters/waku/index.ts b/src/lib/adapters/waku/index.ts index 182f20d8..3b907194 100644 --- a/src/lib/adapters/waku/index.ts +++ b/src/lib/adapters/waku/index.ts @@ -54,7 +54,7 @@ import { balanceStore } from '$lib/stores/balances' import type { ContentTopic } from './waku' import { installedObjectStore } from '$lib/stores/installed-objects' import { errorStore } from '$lib/stores/error' -import { compressPublicKey, fixHex, getSharedSecret, hash } from './crypto' +import { arePublicKeysEqual, compressPublicKey, fixHex, getSharedSecret, hash } from './crypto' import { bytesToHex, hexToBytes } from '@waku/utils/bytes' import { encrypt, decrypt } from './crypto' import { @@ -855,7 +855,9 @@ export default class WakuAdapter implements Adapter { return } - if (compressPublicKey(decodedMessage.signaturePublicKey) !== fixHex(profilePublicKey)) { + if ( + !arePublicKeysEqual(compressPublicKey(decodedMessage.signaturePublicKey), profilePublicKey) + ) { console.error('invalid signature', { decodedMessage, profilePublicKey, @@ -970,12 +972,10 @@ export default class WakuAdapter implements Adapter { return } + const signaturePublicKey = compressPublicKey(decodedMessage.signaturePublicKey) + // check if the signature matches a member of the group - if ( - !chat.users - .map((user) => user.publicKey) - .includes(bytesToHex(decodedMessage.signaturePublicKey)) - ) { + if (!chat.users.map((user) => fixHex(user.publicKey)).includes(signaturePublicKey)) { return } diff --git a/src/routes/group/chat/[id]/edit/+page.svelte b/src/routes/group/chat/[id]/edit/+page.svelte index 92c18985..6563dc1d 100644 --- a/src/routes/group/chat/[id]/edit/+page.svelte +++ b/src/routes/group/chat/[id]/edit/+page.svelte @@ -33,8 +33,6 @@ import { userDisplayName } from '$lib/utils/user' import { errorStore } from '$lib/stores/error' - $: console.log($chats) - $: chatId = $page.params.id $: groupChat = $chats.chats.get(chatId) let picture: string | undefined From fd2f9294945441d2015fc1113c0ebd2e1f05921d Mon Sep 17 00:00:00 2001 From: Attila Gazso <230163+agazso@users.noreply.github.com> Date: Fri, 24 Nov 2023 17:06:07 +0100 Subject: [PATCH 2/2] feat: better public key comparison --- src/lib/adapters/waku/crypto.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/adapters/waku/crypto.ts b/src/lib/adapters/waku/crypto.ts index fdedf384..b7e7d63a 100644 --- a/src/lib/adapters/waku/crypto.ts +++ b/src/lib/adapters/waku/crypto.ts @@ -83,6 +83,6 @@ export function privateKeyToPublicKey(privateKey: Hex | Uint8Array): Hex { return bytesToHex(publicKeyBytes) } -export function arePublicKeysEqual(pkA: Hex, pkB: Hex): boolean { - return fixHex(pkA) === fixHex(pkB) +export function arePublicKeysEqual(pkA: Hex | Uint8Array, pkB: Hex | Uint8Array): boolean { + return compressPublicKey(pkA) === compressPublicKey(pkB) }