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 */ /** Uncompressed */
publicKey: string publicKey: string
): Promise<CommunityInfo | undefined> => { ): Promise<CommunityInfo | undefined> => {
const communityDescription = await this.fetchCommunityDescription(publicKey) const communityDescription = await (
await this.fetchCommunityDescription([publicKey])
).get(publicKey)
if (!communityDescription) { if (!communityDescription) {
return return
@ -113,7 +115,9 @@ class RequestClient {
publicKey: string, publicKey: string,
uuid: string uuid: string
): Promise<ChannelInfo | undefined> => { ): Promise<ChannelInfo | undefined> => {
const communityDescription = await this.fetchCommunityDescription(publicKey) const communityDescription = await (
await this.fetchCommunityDescription([publicKey])
).get(publicKey)
if (!communityDescription) { if (!communityDescription) {
return return
@ -139,17 +143,21 @@ class RequestClient {
return mapUser(contactCodeAdvertisement, publicKey) return mapUser(contactCodeAdvertisement, publicKey)
} }
private fetchCommunityDescription = async ( public fetchCommunityDescription = async (
/** Uncompressed */ /** Compressed */
publicKey: string publicKeys: string[]
): Promise<CommunityDescription | undefined> => { ): Promise<Map<string, CommunityDescription>> => {
const decoderPromises = publicKeys.map(async publicKey => {
const contentTopic = idToContentTopic(publicKey) const contentTopic = idToContentTopic(publicKey)
const symmetricKey = await generateKeyFromPassword(publicKey) const symmetricKey = await generateKeyFromPassword(publicKey)
let communityDescription: CommunityDescription | undefined = undefined return new SymDecoder(contentTopic, symmetricKey)
await this.waku.store.queryOrderedCallback( })
[new SymDecoder(contentTopic, symmetricKey)],
wakuMessage => { const decoders = await Promise.all(decoderPromises)
const communityDescription: Map<string, CommunityDescription> = new Map()
await this.waku.store.queryOrderedCallback(decoders, wakuMessage => {
// handle // handle
const message = this.handleWakuMessage(wakuMessage) const message = this.handleWakuMessage(wakuMessage)
@ -178,18 +186,37 @@ class RequestClient {
return return
} }
if (publicKey !== `0x${compressPublicKey(message.signerPublicKey)}`) { console.log(decodedCommunityDescription)
const decodedCommunityPublicKey = `0x${compressPublicKey(
message.signerPublicKey
)}`
if (!publicKeys.includes(decodedCommunityPublicKey)) {
return return
} }
if (!communityDescription) { if (!communityDescription.has(decodedCommunityPublicKey)) {
communityDescription = decodedCommunityDescription // 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 // 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 return communityDescription
} }