Skip to content

Commit

Permalink
t
Browse files Browse the repository at this point in the history
  • Loading branch information
felicio committed Mar 18, 2024
1 parent faefa00 commit 63f4221
Showing 1 changed file with 51 additions and 3 deletions.
54 changes: 51 additions & 3 deletions packages/status-js/src/request-client/request-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@ import { createDecoder } from '@waku/message-encryption/symmetric'
import { createLightNode, waitForRemotePeer } from '@waku/sdk'
import { bytesToHex } from 'ethereum-cryptography/utils'

import { isEncrypted } from '../client/community/is-encrypted'
import { peers } from '../consts/peers'
import { EthereumClient } from '../ethereum-client/ethereum-client'
import {
ApplicationMetadataMessage,
ApplicationMetadataMessage_Type,
} 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 { ContactCodeAdvertisement } from '../protos/push-notifications_pb'
import { compressPublicKey } from '../utils/compress-public-key'
import { generateKeyFromPassword } from '../utils/generate-key-from-password'
import { idToContentTopic } from '../utils/id-to-content-topic'
import { isClockValid } from '../utils/is-clock-valid'
import { payloadToId } from '../utils/payload-to-id'
import { publicKeyToETHAddress } from '../utils/public-key-to-eth-address'
import { recoverPublicKey } from '../utils/recover-public-key'
import { mapChannel } from './map-channel'
import { mapCommunity } from './map-community'
Expand Down Expand Up @@ -189,7 +195,46 @@ class RequestClient {
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
}

Expand Down Expand Up @@ -300,7 +345,10 @@ class RequestClient {
let decodedProtocol
try {
decodedProtocol = ProtocolMessage.fromBinary(messageToDecode)
if (decodedProtocol) {

if (decodedProtocol.encryptedMessage.none) {
messageToDecode = decodedProtocol.encryptedMessage.none.payload
} else if (decodedProtocol) {
messageToDecode = decodedProtocol.publicMessage
}
} catch {
Expand Down

0 comments on commit 63f4221

Please sign in to comment.