Skip to content

Commit

Permalink
fix: group chat editing (#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
agazso authored Nov 27, 2023
1 parent c935f04 commit c2f7534
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
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

1 comment on commit c2f7534

@vercel
Copy link

@vercel vercel bot commented on c2f7534 Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.