use pks[]

This commit is contained in:
Felicio Mununga 2023-04-26 15:19:08 +02:00
parent 524245b82c
commit 5d4d7e4b6e
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
1 changed files with 75 additions and 48 deletions

View File

@ -99,7 +99,9 @@ class RequestClient {
/** Uncompressed */
publicKey: string
): Promise<CommunityInfo | undefined> => {
const communityDescription = await this.fetchCommunityDescription(publicKey)
const communityDescription = await (
await this.fetchCommunityDescription([publicKey])
).get(publicKey)
if (!communityDescription) {
return
@ -113,7 +115,9 @@ class RequestClient {
publicKey: string,
uuid: string
): Promise<ChannelInfo | undefined> => {
const communityDescription = await this.fetchCommunityDescription(publicKey)
const communityDescription = await (
await this.fetchCommunityDescription([publicKey])
).get(publicKey)
if (!communityDescription) {
return
@ -139,17 +143,21 @@ class RequestClient {
return mapUser(contactCodeAdvertisement, publicKey)
}
private fetchCommunityDescription = async (
/** Uncompressed */
publicKey: string
): Promise<CommunityDescription | undefined> => {
public fetchCommunityDescription = async (
/** Compressed */
publicKeys: string[]
): Promise<Map<string, CommunityDescription>> => {
const decoderPromises = publicKeys.map(async publicKey => {
const contentTopic = idToContentTopic(publicKey)
const symmetricKey = await generateKeyFromPassword(publicKey)
let communityDescription: CommunityDescription | undefined = undefined
await this.waku.store.queryOrderedCallback(
[new SymDecoder(contentTopic, symmetricKey)],
wakuMessage => {
return new SymDecoder(contentTopic, symmetricKey)
})
const decoders = await Promise.all(decoderPromises)
const communityDescription: Map<string, CommunityDescription> = new Map()
await this.waku.store.queryOrderedCallback(decoders, wakuMessage => {
// handle
const message = this.handleWakuMessage(wakuMessage)
@ -178,18 +186,37 @@ class RequestClient {
return
}
if (publicKey !== `0x${compressPublicKey(message.signerPublicKey)}`) {
console.log(decodedCommunityDescription)
const decodedCommunityPublicKey = `0x${compressPublicKey(
message.signerPublicKey
)}`
if (!publicKeys.includes(decodedCommunityPublicKey)) {
return
}
if (!communityDescription) {
communityDescription = decodedCommunityDescription
if (!communityDescription.has(decodedCommunityPublicKey)) {
// todo?: ensure mapping back to original pk format if deserialized in this fn
communityDescription.set(
decodedCommunityPublicKey,
decodedCommunityDescription
)
}
// skip
// todo?: skip decoder if community is found; impossible?
// stop
return true
// todo?: stop when last community; if decoders/pks served in order
if (publicKeys.some(publicKey => !communityDescription.has(publicKey))) {
return
}
)
const stop = true
return stop
})
return communityDescription
}