From f0a629dfdcc0a6f519aa41ea10d32388fba4f25b Mon Sep 17 00:00:00 2001 From: Felicio Mununga Date: Wed, 1 Jun 2022 07:39:47 +0200 Subject: [PATCH] fix test after rebase --- packages/status-js/.scripts/example copy 2.ts | 2 +- packages/status-js/package.json | 12 ++- packages/status-js/protos/communities.ts | 2 +- packages/status-js/src/client-v2.ts | 24 +++-- packages/status-js/src/client.ts | 5 +- packages/status-js/src/index.ts | 87 +++++++++++++------ packages/status-js/src/messenger.ts | 13 ++- packages/status-js/src/topics.ts | 2 +- yarn.lock | 20 +++++ 9 files changed, 119 insertions(+), 48 deletions(-) diff --git a/packages/status-js/.scripts/example copy 2.ts b/packages/status-js/.scripts/example copy 2.ts index f4e70dd7..0d199a4b 100644 --- a/packages/status-js/.scripts/example copy 2.ts +++ b/packages/status-js/.scripts/example copy 2.ts @@ -5,7 +5,7 @@ import { Community } from '../src/community' const COMMUNITY_PUBLIC_KEY = '0x029dd5fecbd689dc11e2a5b399afed92cf1fab65d315b883efca753e8f3882f3bd' // compressed; A catchy name - // '0x02c788e419b56c714460220bedadc9c5d401ea10eee48d25ac81fc9a06fb75162e' // compressed; A boring name +// '0x02c788e419b56c714460220bedadc9c5d401ea10eee48d25ac81fc9a06fb75162e' // compressed; A boring name // const COMMUNITY_CHANNEL_KEY = '0x029dd5fecbd689dc11e2a5b399afed92cf1fab65d315b883efca753e8f3882f3bd06935bce-a863-4827-9990-1652ae375c89' // 06935bce-a863-4827-9990-1652ae375c89; #channel const COMMUNITY_CHANNEL_KEY = '6102c603-3246-4b90-986d-43c1b87b165f' // #random; UUID diff --git a/packages/status-js/package.json b/packages/status-js/package.json index a67a0b74..0b2c2bf5 100644 --- a/packages/status-js/package.json +++ b/packages/status-js/package.json @@ -14,8 +14,17 @@ "main": "dist/index.js", "module": "dist/index.esm.js", "types": "dist/index.d.ts", + "targets": { + "main": { + "includeNodeModules": [ + "protons-runtime", + "uint8arraylist" + ] + } + }, "scripts": { "prebuild": "rm -rf dist", + "dev": "parcel", "build": "parcel build", "build:vite": "vite build", "build:types": "tsc --emitDeclarationOnly", @@ -37,7 +46,8 @@ "pbkdf2": "^3.1.2", "protons-runtime": "^1.0.4", "secp256k1": "^4.0.2", - "uuid": "^8.3.2" + "uuid": "^8.3.2", + "protobufjs": "^6.11.3" }, "devDependencies": { "@types/bn.js": "^5.1.0", diff --git a/packages/status-js/protos/communities.ts b/packages/status-js/protos/communities.ts index a857f4d1..e44467cd 100644 --- a/packages/status-js/protos/communities.ts +++ b/packages/status-js/protos/communities.ts @@ -117,7 +117,7 @@ export interface CommunityDescription { members: CommunityMember permissions: CommunityPermissions identity: ChatIdentity - chats: CommunityChat + chats: Record banList: string[] categories: CommunityCategory archiveMagnetlinkClock: bigint diff --git a/packages/status-js/src/client-v2.ts b/packages/status-js/src/client-v2.ts index defdf7c9..34f92ae9 100644 --- a/packages/status-js/src/client-v2.ts +++ b/packages/status-js/src/client-v2.ts @@ -1,17 +1,17 @@ import { getPredefinedBootstrapNodes, Waku } from 'js-waku' -import { ApplicationMetadataMessage } from '~/protos/application-metadata-message' -import { ChatMessage } from '~/protos/chat-message' -import { CommunityChat, CommunityDescription } from '~/protos/communities' - +import { ApplicationMetadataMessage } from '../protos/application-metadata-message' +import { ChatMessage } from '../protos/chat-message' +import { CommunityChat, CommunityDescription } from '../protos/communities' import { idToContentTopic } from './contentTopic' import { createSymKeyFromPassword } from './encryption' +import { hexToBuf } from './utils' import type { WakuMessage } from 'js-waku' export interface ClientOptions { publicKey: string - environement?: 'production' | 'test' + env?: 'production' | 'test' callback: (message: ChatMessage) => void } @@ -31,15 +31,21 @@ export class Client { } public async start() { + console.log(getPredefinedBootstrapNodes('test')) this.waku = await Waku.create( - this.options.environement === 'test' + this.options.env === 'test' ? { bootstrap: { - getPeers: getPredefinedBootstrapNodes('test'), + peers: [ + '/dns4/node-01.gc-us-central1-a.wakuv2.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmJb2e28qLXxT5kZxVUUoJt72EMzNGXB47Rxx5hw3q4YjS', + ], }, } : { bootstrap: { default: true } } ) + + console.log('here') + await this.waku.waitForRemotePeer() } @@ -100,7 +106,7 @@ export class Client { this.waku!.relay.addObserver(this.handleMessage, contentTopics) } - private handleMessage = (message: WakuMessage) => { + private async handleMessage(message: WakuMessage) { if (!message.payload || !message.timestamp) { return } @@ -128,6 +134,8 @@ export class Client { } } } + + async sendMessage(message: any) {} } export const createClient = async (options: ClientOptions) => { diff --git a/packages/status-js/src/client.ts b/packages/status-js/src/client.ts index 80e56e25..2af731d1 100644 --- a/packages/status-js/src/client.ts +++ b/packages/status-js/src/client.ts @@ -1,6 +1,6 @@ -import { Waku } from 'js-waku' -// import { Fleet } from 'js-waku/build/main/lib/discovery/predefined' +import { getPredefinedBootstrapNodes, Waku } from 'js-waku' +// import { Fleet } from 'js-waku/build/main/lib/discovery/predefined' // TOOD: params // TODO?: reconnect/keep alive // TODO?: error handling @@ -19,6 +19,5 @@ export async function createClient(): Promise { libp2p: { config: { pubsub: { enabled: true, emitSelf: true } } }, }) await waku.waitForRemotePeer() - return waku } diff --git a/packages/status-js/src/index.ts b/packages/status-js/src/index.ts index fc4e8254..73bc88f8 100644 --- a/packages/status-js/src/index.ts +++ b/packages/status-js/src/index.ts @@ -1,26 +1,61 @@ -export { Chat } from './chat' -export { createClient } from './client' -export { Community } from './community' -export { Contacts } from './contacts' -export type { GroupChat, GroupChatsType } from './groupChats' -export { GroupChats } from './groupChats' -export { Identity } from './identity' -export { Messenger } from './messenger' -export { - bufToHex, - compressPublicKey, - genPrivateKeyWithEntropy, - getLatestUserNickname, - hexToBuf, -} from './utils' -export { ApplicationMetadataMessage } from './wire/application_metadata_message' -export type { - AudioContent, - Content, - ContentType, - ImageContent, - StickerContent, - TextContent, -} from './wire/chat_message' -export { ChatMessage } from './wire/chat_message' -export { getPredefinedBootstrapNodes } from 'js-waku' +// export { Chat } from './chat' +// // export type { Client, ClientOptions } from './client' +// export { createClient } from './client' +// export { Community } from './community' +// export { Contacts } from './contacts' +// export type { GroupChat, GroupChatsType } from './groupChats' +// export { GroupChats } from './groupChats' +// export { Identity } from './identity' +// export { Messenger } from './messenger' +// export { +// bufToHex, +// compressPublicKey, +// genPrivateKeyWithEntropy, +// getLatestUserNickname, +// hexToBuf, +// } from './utils' +// export { ApplicationMetadataMessage } from './wire/application_metadata_message' +// export type { +// AudioContent, +// Content, +// ContentType, +// ImageContent, +// StickerContent, +// TextContent, +// } from './wire/chat_message' +// export { ChatMessage } from './wire/chat_message' +// export { getPredefinedBootstrapNodes } from 'js-waku' + +import { createClient } from './client-v2' + +const COMMUNITY_PUBLIC_KEY = + '0x029dd5fecbd689dc11e2a5b399afed92cf1fab65d315b883efca753e8f3882f3bd' // compressed +// const COMMUNITY_PUBLIC_KEY = +// '0x0403aeff2fdd0044b136e06afa6d69bb563bb7b3fd518bb30c0d5115a2e020840a2247966c2cc9953ed02cc391e8883b3319f63a31e5f5369d0fb72b62b23dfcbd' // compressed + +// import { Community } from '../src/community' +// import { Messenger } from '../src/messenger' + +console.log('🚀 > COMMUNITY_PUBLIC_KEY', COMMUNITY_PUBLIC_KEY) +;(async () => { + const client = await createClient({ + env: 'test', + publicKey: COMMUNITY_PUBLIC_KEY, + callback: msgs => {}, + }) + + const communityDescription = await client.getCommunityDescription() + + console.log('meow', communityDescription) + + // console.log(communityDescription) + // Retrieve Community's metadata (e.g. description) + // const community = await Community.instantiateCommunity(COMMUNITY_PUBLIC_KEY, client) + // // Retrieve and subscribe to messages + // const messenger = await Messenger.create(, client) + // // TODO: Register observers/callbacks + // messenger.addObserver(() => {}) + // await client.stop() +})() + +// export {} diff --git a/packages/status-js/src/messenger.ts b/packages/status-js/src/messenger.ts index a9ef7591..f3934b89 100644 --- a/packages/status-js/src/messenger.ts +++ b/packages/status-js/src/messenger.ts @@ -39,14 +39,13 @@ export class Messenger { identity: Identity | undefined, // wakuOptions?: waku.CreateOptions // TODO: pass waku as client - // wakuOptions?: WakuCreateOptions - waku: Waku + wakuOptions?: waku.CreateOptions ): Promise { - // 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) } diff --git a/packages/status-js/src/topics.ts b/packages/status-js/src/topics.ts index f197f7dc..2b635d0a 100644 --- a/packages/status-js/src/topics.ts +++ b/packages/status-js/src/topics.ts @@ -5,7 +5,7 @@ import { ec } from 'elliptic' import { idToContentTopic } from './contentTopic' import { bufToHex, hexToBuf } from './utils' -import type { Identity } from '.' +import type { Identity } from './identity' const EC = new ec('secp256k1') const partitionsNum = new BN(5000) diff --git a/yarn.lock b/yarn.lock index 92e48cfe..9c73fa11 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7597,6 +7597,7 @@ node-addon-api@^4.3.0: "node-fetch@https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz": version "2.6.7" + uid "1b5d62978f2ed07b99444f64f0df39f960a6d34d" resolved "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz#1b5d62978f2ed07b99444f64f0df39f960a6d34d" node-forge@^1.2.1: @@ -8437,6 +8438,25 @@ protobufjs@^6.10.2, protobufjs@^6.11.2, protobufjs@^6.8.8: "@types/node" ">=13.7.0" long "^4.0.0" +protobufjs@^6.11.3: + version "6.11.3" + resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-6.11.3.tgz#637a527205a35caa4f3e2a9a4a13ddffe0e7af74" + integrity sha512-xL96WDdCZYdU7Slin569tFX712BxsxslWwAfAhCYjQKGTq7dAU91Lomy6nLLhh/dyGhk/YH4TwTSRxTzhuHyZg== + dependencies: + "@protobufjs/aspromise" "^1.1.2" + "@protobufjs/base64" "^1.1.2" + "@protobufjs/codegen" "^2.0.4" + "@protobufjs/eventemitter" "^1.1.0" + "@protobufjs/fetch" "^1.1.0" + "@protobufjs/float" "^1.0.2" + "@protobufjs/inquire" "^1.1.0" + "@protobufjs/path" "^1.1.2" + "@protobufjs/pool" "^1.1.0" + "@protobufjs/utf8" "^1.1.0" + "@types/long" "^4.0.1" + "@types/node" ">=13.7.0" + long "^4.0.0" + protons-runtime@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/protons-runtime/-/protons-runtime-1.0.4.tgz#85db97f82fb03a1205eafb591904736ba34e2972"