Skip to content

Commit

Permalink
fix: group chat editing
Browse files Browse the repository at this point in the history
  • Loading branch information
agazso committed Nov 24, 2023
1 parent c935f04 commit 30b573b
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, pkB: Hex): boolean {
return fixHex(pkA) === fixHex(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

0 comments on commit 30b573b

Please sign in to comment.