add scripts

This commit is contained in:
Felicio Mununga 2022-05-25 14:52:48 +02:00
parent ded4de8d9c
commit 99c595070f
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
8 changed files with 66 additions and 8 deletions

View File

@ -0,0 +1,21 @@
import { createClient } from "../src/client"
import { Community } from '../src/community'
import { Messenger } from '../src/messenger'
// const COMMUNITY_PUBLIC_KEY = '0x02cf13719c8b836bebd4e430c497ee38e798a43e4d8c4760c34bbd9bf4f2434d26'
const COMMUNITY_PUBLIC_KEY = '0x029dd5fecbd689dc11e2a5b399afed92cf1fab65d315b883efca753e8f3882f3bd' // compressed
;(async () => {
const client = await createClient()
// Retrieve Community's metadata (e.g. description)
const community = await Community.instantiateCommunity(COMMUNITY_PUBLIC_KEY, client) // decoded protobuf
// // Retrieve and subscribe to messages
// const messenger = await Messenger.create(, client)
// // TODO: Register observers/callbacks
// messenger.addObserver(() => {})
await client.stop()
})()

View File

@ -0,0 +1,23 @@
import { Waku } from 'js-waku'
// import { Fleet } from 'js-waku/build/main/lib/discovery/predefined'
// TOOD: params
// TODO?: reconnect/keep alive
// TODO?: error handling
// TOOD?: teardown
export async function createClient(): Promise<Waku> {
const waku = await Waku.create({
bootstrap: {
default: false,
// peers: ['/dns4/node-01.gc-us-central1-a.wakuv2.prod.statusim.net/tcp/443/wss/p2p/16Uiu2HAmVkKntsECaYfefR1V2yCR79CegLATuTPE6B9TxgxBiiiA']
peers: [
'/dns4/node-01.gc-us-central1-a.wakuv2.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmJb2e28qLXxT5kZxVUUoJt72EMzNGXB47Rxx5hw3q4YjS',
],
},
// TODO?: remove
libp2p: { config: { pubsub: { enabled: true, emitSelf: true } } },
})
await waku.waitForRemotePeer()
return waku
}

View File

@ -15,6 +15,7 @@ describe('Community [live data]', () => {
it('Retrieves community description For DappConnect Test from Waku prod fleet', async function () {
this.timeout(20000)
// FIXME?: mock
const waku = await Waku.create({ bootstrap: { default: true } })
await waku.waitForRemotePeer()

View File

@ -12,6 +12,7 @@ const dbg = debug('communities:community')
export class Community {
public publicKey: Uint8Array
private waku: Waku
// TODO?: rename to channels
public chats: Map<string, Chat> // Chat id, Chat
public description?: CommunityDescription
@ -21,6 +22,7 @@ export class Community {
this.chats = new Map()
}
// TODO: explain why init func instead of constructor
/**
* Instantiate a Community by retrieving its details from the Waku network.
*

View File

@ -1,5 +1,6 @@
import { waku_message, WakuMessage } from 'js-waku'
// FIXME?: import from 'js-waku' not /build
import { ChatMessage } from '.'
import { createSymKeyFromPassword } from './encryption'
import { MembershipUpdateEvent_EventType } from './proto/communities/v1/membership_update_message'

View File

@ -1,4 +1,5 @@
export { Chat } from './chat'
export { createClient } from './client'
export { Community } from './community'
export { Contacts } from './contacts'
export type { GroupChat, GroupChatsType } from './groupChats'

View File

@ -1,5 +1,5 @@
import debug from 'debug'
import { Waku, waku_message, WakuMessage } from 'js-waku'
import { waku_message, WakuMessage } from 'js-waku'
import { Chat } from './chat'
import { ApplicationMetadataMessage_Type } from './proto/status/v1/application_metadata_message'
@ -9,10 +9,11 @@ import { ChatMessage } from './wire/chat_message'
import type { Identity } from './identity'
import type { Content } from './wire/chat_message'
import type { waku } from 'js-waku'
import type { Waku } from 'js-waku'
const dbg = debug('communities:messenger')
// tood: pass waku client
export class Messenger {
waku: Waku
chatsById: Map<string, Chat>
@ -36,13 +37,16 @@ export class Messenger {
public static async create(
identity: Identity | undefined,
wakuOptions?: waku.CreateOptions
// wakuOptions?: waku.CreateOptions
// TODO: pass waku as client
// wakuOptions?: WakuCreateOptions
waku: Waku
): Promise<Messenger> {
const _wakuOptions = Object.assign(
{ bootstrap: { default: true } },
wakuOptions
)
const waku = await Waku.create(_wakuOptions)
// const _wakuOptions = Object.assign(
// { bootstrap: { default: true } },
// wakuOptions
// )
// const waku = await Waku.create(_wakuOptions)
return new Messenger(identity, waku)
}

View File

@ -3,6 +3,7 @@ import { Reader } from 'protobufjs'
import { idToContentTopic } from '../contentTopic'
import { createSymKeyFromPassword } from '../encryption'
// TODO: replace for 'packages/status-js/protos/communities.ts'
import * as proto from '../proto/communities/v1/communities'
import { bufToHex } from '../utils'
import { ApplicationMetadataMessage } from './application_metadata_message'
@ -34,12 +35,14 @@ export class CommunityDescription {
wakuStore: WakuStore
): Promise<CommunityDescription | undefined> {
const hexCommunityPublicKey = bufToHex(communityPublicKey)
// TEST: diff topic
const contentTopic = idToContentTopic(hexCommunityPublicKey)
let communityDescription: CommunityDescription | undefined
const callback = (messages: WakuMessage[]): void => {
// Value found, stop processing
// FIXME?: return true/false
if (communityDescription) return
// Process most recent message first
@ -64,6 +67,8 @@ export class CommunityDescription {
)
}
})
// FIXME?: return true/false
}
const symKey = await createSymKeyFromPassword(hexCommunityPublicKey)