Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: group chat editing #499

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/lib/adapters/waku/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,7 @@ export function privateKeyToPublicKey(privateKey: Hex | Uint8Array): Hex {
const publicKeyBytes = getPublicKey(privateKey)
return bytesToHex(publicKeyBytes)
}

export function arePublicKeysEqual(pkA: Hex | Uint8Array, pkB: Hex | Uint8Array): boolean {
return compressPublicKey(pkA) === compressPublicKey(pkB)
}
14 changes: 7 additions & 7 deletions src/lib/adapters/waku/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 0 additions & 2 deletions src/routes/group/chat/[id]/edit/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down