stop fetching early (#539)
* stop fetching early * Create yellow-pets-invent.md
This commit is contained in:
parent
550774e291
commit
6b4e6b1566
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"@status-im/js": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
stop fetching early
|
|
@ -159,88 +159,93 @@ class RequestClient {
|
||||||
const symmetricKey = await generateKeyFromPassword(publicKey)
|
const symmetricKey = await generateKeyFromPassword(publicKey)
|
||||||
|
|
||||||
let communityDescription: CommunityDescription | undefined = undefined
|
let communityDescription: CommunityDescription | undefined = undefined
|
||||||
await this.waku.store.queryWithOrderedCallback(
|
try {
|
||||||
[
|
await this.waku.store.queryWithOrderedCallback(
|
||||||
createDecoder(contentTopic, symmetricKey, {
|
[
|
||||||
clusterId: 16,
|
createDecoder(contentTopic, symmetricKey, {
|
||||||
shard: 32,
|
clusterId: 16,
|
||||||
}),
|
shard: 32,
|
||||||
],
|
}),
|
||||||
wakuMessage => {
|
],
|
||||||
// handle
|
wakuMessage => {
|
||||||
const message = this.handleWakuMessage(wakuMessage)
|
// handle
|
||||||
|
const message = this.handleWakuMessage(wakuMessage)
|
||||||
|
|
||||||
if (!message) {
|
if (!message) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
message.type !== ApplicationMetadataMessage_Type.COMMUNITY_DESCRIPTION
|
message.type !==
|
||||||
) {
|
ApplicationMetadataMessage_Type.COMMUNITY_DESCRIPTION
|
||||||
return
|
) {
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// decode
|
// decode
|
||||||
const decodedCommunityDescription = CommunityDescription.fromBinary(
|
const decodedCommunityDescription = CommunityDescription.fromBinary(
|
||||||
message.payload
|
message.payload
|
||||||
)
|
|
||||||
|
|
||||||
// validate
|
|
||||||
if (
|
|
||||||
!isClockValid(
|
|
||||||
BigInt(decodedCommunityDescription.clock),
|
|
||||||
message.timestamp
|
|
||||||
)
|
)
|
||||||
) {
|
|
||||||
return
|
// validate
|
||||||
|
if (
|
||||||
|
!isClockValid(
|
||||||
|
BigInt(decodedCommunityDescription.clock),
|
||||||
|
message.timestamp
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!communityDescription) {
|
||||||
|
communityDescription = decodedCommunityDescription
|
||||||
|
}
|
||||||
|
|
||||||
|
// stop
|
||||||
|
throw new Error('stop')
|
||||||
}
|
}
|
||||||
|
)
|
||||||
const signerPublicKey = `0x${compressPublicKey(
|
} catch {
|
||||||
message.signerPublicKey
|
// eslint-disable-next-line no-empty
|
||||||
)}`
|
}
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!communityDescription) {
|
|
||||||
communityDescription = decodedCommunityDescription
|
|
||||||
}
|
|
||||||
|
|
||||||
// stop
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
return communityDescription
|
return communityDescription
|
||||||
}
|
}
|
||||||
|
@ -255,59 +260,63 @@ class RequestClient {
|
||||||
|
|
||||||
let contactCodeAdvertisement: ContactCodeAdvertisement | undefined =
|
let contactCodeAdvertisement: ContactCodeAdvertisement | undefined =
|
||||||
undefined
|
undefined
|
||||||
await this.waku.store.queryWithOrderedCallback(
|
try {
|
||||||
[
|
await this.waku.store.queryWithOrderedCallback(
|
||||||
createDecoder(contentTopic, symmetricKey, {
|
[
|
||||||
clusterId: 16,
|
createDecoder(contentTopic, symmetricKey, {
|
||||||
shard: 32,
|
clusterId: 16,
|
||||||
}),
|
shard: 32,
|
||||||
],
|
}),
|
||||||
wakuMessage => {
|
],
|
||||||
// handle
|
wakuMessage => {
|
||||||
const message = this.handleWakuMessage(wakuMessage)
|
// handle
|
||||||
|
const message = this.handleWakuMessage(wakuMessage)
|
||||||
|
|
||||||
if (!message) {
|
if (!message) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
message.type !==
|
message.type !==
|
||||||
ApplicationMetadataMessage_Type.CONTACT_CODE_ADVERTISEMENT
|
ApplicationMetadataMessage_Type.CONTACT_CODE_ADVERTISEMENT
|
||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// decode
|
// decode
|
||||||
const decodedContactCode = ContactCodeAdvertisement.fromBinary(
|
const decodedContactCode = ContactCodeAdvertisement.fromBinary(
|
||||||
message.payload
|
message.payload
|
||||||
)
|
|
||||||
|
|
||||||
// validate
|
|
||||||
if (!decodedContactCode.chatIdentity) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
!isClockValid(
|
|
||||||
BigInt(decodedContactCode.chatIdentity.clock),
|
|
||||||
message.timestamp
|
|
||||||
)
|
)
|
||||||
) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (publicKey !== message.signerPublicKey) {
|
// validate
|
||||||
return
|
if (!decodedContactCode.chatIdentity) {
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (!contactCodeAdvertisement) {
|
if (
|
||||||
contactCodeAdvertisement = decodedContactCode
|
!isClockValid(
|
||||||
}
|
BigInt(decodedContactCode.chatIdentity.clock),
|
||||||
|
message.timestamp
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// stop
|
if (publicKey !== message.signerPublicKey) {
|
||||||
return true
|
return
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
if (!contactCodeAdvertisement) {
|
||||||
|
contactCodeAdvertisement = decodedContactCode
|
||||||
|
}
|
||||||
|
|
||||||
|
// stop
|
||||||
|
throw new Error('stop')
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} catch {
|
||||||
|
// eslint-disable-next-line no-empty
|
||||||
|
}
|
||||||
|
|
||||||
return contactCodeAdvertisement
|
return contactCodeAdvertisement
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue