handle updates for encrypted communities (#537)

* a

* t

* t

* f

* c

* c

* r
This commit is contained in:
Felicio Mununga 2024-03-18 21:47:54 +09:00 committed by GitHub
parent 70de4ec769
commit 9a495fd902
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 69 additions and 3 deletions

View File

@ -0,0 +1,5 @@
---
'@status-im/components': patch
---
export `Tooltip`

View File

@ -0,0 +1,5 @@
---
'@status-im/js': minor
---
handle updates for encrypted communities

View File

@ -0,0 +1,13 @@
import {
type CommunityDescription,
CommunityTokenPermission_Type,
} from '../../protos/communities_pb'
export function isEncrypted(
tokenPermissions: CommunityDescription['tokenPermissions']
): boolean {
return Object.values(tokenPermissions).some(
permission =>
permission.type === CommunityTokenPermission_Type.BECOME_MEMBER
)
}

View File

@ -4,12 +4,17 @@ import { createDecoder } from '@waku/message-encryption/symmetric'
import { createLightNode, waitForRemotePeer } from '@waku/sdk' import { createLightNode, waitForRemotePeer } from '@waku/sdk'
import { bytesToHex } from 'ethereum-cryptography/utils' import { bytesToHex } from 'ethereum-cryptography/utils'
import { isEncrypted } from '../client/community/is-encrypted'
import { peers } from '../consts/peers' import { peers } from '../consts/peers'
// import { EthereumClient } from '../ethereum-client/ethereum-client'
import { import {
ApplicationMetadataMessage, ApplicationMetadataMessage,
ApplicationMetadataMessage_Type, ApplicationMetadataMessage_Type,
} from '../protos/application-metadata-message_pb' } from '../protos/application-metadata-message_pb'
import { CommunityDescription } from '../protos/communities_pb' import {
CommunityDescription,
// CommunityTokenPermission_Type,
} from '../protos/communities_pb'
import { ProtocolMessage } from '../protos/protocol-message_pb' import { ProtocolMessage } from '../protos/protocol-message_pb'
import { ContactCodeAdvertisement } from '../protos/push-notifications_pb' import { ContactCodeAdvertisement } from '../protos/push-notifications_pb'
import { compressPublicKey } from '../utils/compress-public-key' import { compressPublicKey } from '../utils/compress-public-key'
@ -17,6 +22,7 @@ import { generateKeyFromPassword } from '../utils/generate-key-from-password'
import { idToContentTopic } from '../utils/id-to-content-topic' import { idToContentTopic } from '../utils/id-to-content-topic'
import { isClockValid } from '../utils/is-clock-valid' import { isClockValid } from '../utils/is-clock-valid'
import { payloadToId } from '../utils/payload-to-id' import { payloadToId } from '../utils/payload-to-id'
// import { publicKeyToETHAddress } from '../utils/public-key-to-eth-address'
import { recoverPublicKey } from '../utils/recover-public-key' import { recoverPublicKey } from '../utils/recover-public-key'
import { mapChannel } from './map-channel' import { mapChannel } from './map-channel'
import { mapCommunity } from './map-community' import { mapCommunity } from './map-community'
@ -189,7 +195,41 @@ class RequestClient {
return return
} }
if (publicKey !== `0x${compressPublicKey(message.signerPublicKey)}`) { const signerPublicKey = `0x${compressPublicKey(
message.signerPublicKey
)}`
// isSignatureValid
if (isEncrypted(decodedCommunityDescription.tokenPermissions)) {
// const permission = Object.values(
// decodedCommunityDescription.tokenPermissions
// ).find(
// permission =>
// permission.type ===
// CommunityTokenPermission_Type.BECOME_TOKEN_OWNER
// )
// if (!permission) {
// return
// }
// const criteria = permission.tokenCriteria[0]
// const contracts = criteria?.contractAddresses
// const chainId = Object.keys(contracts)[0]
// if (!chainId) {
// return
// }
// // get client config based on chainId
// // get client
// const client = new EthereumClient(
// `https://mainnet.infura.io/v3/${process.env.KEY}`
// )
// // call status contract for chainId
// const address = publicKeyToETHAddress(publicKey)
// // call contracts from previous call with address
// const ownerPublicKey = '0x0'
// if (ownerPublicKey !== signerPublicKey) {
// return
// }
} else if (publicKey !== signerPublicKey) {
return return
} }
@ -300,7 +340,10 @@ class RequestClient {
let decodedProtocol let decodedProtocol
try { try {
decodedProtocol = ProtocolMessage.fromBinary(messageToDecode) decodedProtocol = ProtocolMessage.fromBinary(messageToDecode)
if (decodedProtocol) {
if (decodedProtocol.encryptedMessage.none) {
messageToDecode = decodedProtocol.encryptedMessage.none.payload
} else if (decodedProtocol) {
messageToDecode = decodedProtocol.publicMessage messageToDecode = decodedProtocol.publicMessage
} }
} catch { } catch {