Skip to content

Commit

Permalink
use @waku/sdk (#507)
Browse files Browse the repository at this point in the history
* u `@bufbuild`

* use `@waku/sdk`

* Create eleven-experts-cough.md
  • Loading branch information
felicio committed Nov 9, 2023
1 parent 23e727b commit 51df6db
Show file tree
Hide file tree
Showing 21 changed files with 1,052 additions and 1,257 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-experts-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@status-im/js": patch
---

use `@waku/sdk`
9 changes: 6 additions & 3 deletions packages/status-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,19 @@
"clean": "rimraf dist node_modules .turbo"
},
"dependencies": {
"@bufbuild/protobuf": "^1.0.0",
"@bufbuild/protobuf": "1.4.2",
"@libp2p/bootstrap": "^9.0.10",
"@scure/base": "^1.1.1",
"@waku/message-encryption": "^0.0.23",
"@waku/sdk": "^0.0.21",
"ethereum-cryptography": "^1.0.3",
"ethers": "^6.2.1",
"js-waku": "^0.30.0",
"multiformats": "^11.0.1"
},
"devDependencies": {
"@bufbuild/protoc-gen-es": "^1.0.0",
"@bufbuild/protoc-gen-es": "1.4.2",
"@status-im/eslint-config": "*",
"@waku/interfaces": "^0.0.20",
"happy-dom": "^9.1.7"
},
"files": [
Expand Down
8 changes: 4 additions & 4 deletions packages/status-js/src/client/chat.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PageDirection } from 'js-waku'
import { SymDecoder } from 'js-waku/lib/waku_message/version_1'
import { PageDirection } from '@waku/interfaces'
import { createDecoder } from '@waku/message-encryption/symmetric'

import { containsOnlyEmoji } from '../helpers/contains-only-emoji'
import { ApplicationMetadataMessage_Type } from '../protos/application-metadata-message_pb'
Expand Down Expand Up @@ -207,8 +207,8 @@ export class Chat {
endTime = new Date()
}

await this.client.waku.store.queryOrderedCallback(
[new SymDecoder(this.contentTopic, this.symmetricKey)],
await this.client.waku.store.queryWithOrderedCallback(
[createDecoder(this.contentTopic, this.symmetricKey)],
wakuMessage => {
this.#fetchingMessages = true
this.client.handleWakuMessage(wakuMessage)
Expand Down
39 changes: 19 additions & 20 deletions packages/status-js/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
* @see https://specs.status.im/spec/1
*/

import { bootstrap } from '@libp2p/bootstrap'
import { Protocols } from '@waku/interfaces'
import { createEncoder } from '@waku/message-encryption/symmetric'
import { createLightNode, waitForRemotePeer } from '@waku/sdk'
import { hexToBytes } from 'ethereum-cryptography/utils'
import { Protocols } from 'js-waku'
import { createLightNode } from 'js-waku/lib/create_waku'
import { PeerDiscoveryStaticPeers } from 'js-waku/lib/peer_discovery_static_list'
import { waitForRemotePeer } from 'js-waku/lib/wait_for_remote_peer'
import { SymEncoder } from 'js-waku/lib/waku_message/version_1'

import { peers } from '../consts/peers'
import { ApplicationMetadataMessage } from '../protos/application-metadata-message_pb'
Expand All @@ -19,8 +18,8 @@ import { LocalStorage } from './storage'

import type { ApplicationMetadataMessage_Type } from '../protos/application-metadata-message_pb'
import type { Storage } from './storage'
import type { WakuLight } from 'js-waku/lib/interfaces'
import type { MessageV1 as WakuMessage } from 'js-waku/lib/waku_message/version_1'
import type { LightNode } from '@waku/interfaces'
import type { DecodedMessage } from '@waku/message-encryption/symmetric'

const THROWAWAY_ACCOUNT_STORAGE_KEY = 'throwaway_account'

Expand All @@ -38,7 +37,7 @@ export interface ClientOptions {
}

class Client {
public waku: WakuLight
public waku: LightNode
public readonly wakuMessages: Set<string>
/**
* Tracks open connections which had their streams silently destroyed
Expand All @@ -64,7 +63,7 @@ class Client {

storage: Storage

constructor(waku: WakuLight, options: ClientOptions) {
constructor(waku: LightNode, options: ClientOptions) {
// Waku
/**
* Waku should be connected and protocols awaited at this point, thus connected.
Expand All @@ -76,9 +75,9 @@ class Client {
this.#wakuDisconnectionTimer = setInterval(async () => {
const connectionsToClose: Promise<void>[] = []

for (const connection of this.waku.libp2p.connectionManager.getConnections()) {
for (const connection of this.waku.libp2p.getConnections()) {
try {
await this.waku.libp2p.ping(connection.remoteAddr)
await this.waku.libp2p.services.ping.ping(connection.remoteAddr)

if (!this.connected) {
this.connected = true
Expand All @@ -96,7 +95,7 @@ class Client {
* Note: Assumes 1 remote node and that the diconnection does not require calling
* `waitForRemotePeer` again to ensure protocols/codecs.
*/
this.waku.libp2p.connectionManager.addEventListener('peer:connect', () => {
this.waku.libp2p.addEventListener('peer:connect', () => {
this.connected = true // reconnect

this.emitConnection(this.connected)
Expand All @@ -105,7 +104,7 @@ class Client {
* >This event will **only** be triggered when the last connection is closed.
* @see https://github.com/libp2p/js-libp2p/blob/bad9e8c0ff58d60a78314077720c82ae331cc55b/doc/API.md?plain=1#L2100
*/
waku.libp2p.connectionManager.addEventListener('peer:disconnect', () => {
waku.libp2p.addEventListener('peer:disconnect', () => {
this.connected = false

this.emitConnection(this.connected)
Expand Down Expand Up @@ -135,7 +134,7 @@ class Client {
static async start(options: ClientOptions): Promise<Client> {
const { environment = 'production' } = options

let waku: WakuLight | undefined
let waku: LightNode | undefined
let client: Client | undefined

try {
Expand All @@ -161,7 +160,7 @@ class Client {
* >
* >@see https://forum.vac.dev/t/waku-v2-scalability-studies/142/2
*/
new PeerDiscoveryStaticPeers(peers[environment], { maxPeers: 1 }),
bootstrap({ list: peers[environment] }),
],
},
})
Expand Down Expand Up @@ -260,17 +259,17 @@ class Client {
payload,
}).toBinary()

await this.waku.lightPush.push(
new SymEncoder(
await this.waku.lightPush.send(
createEncoder({
contentTopic,
symKey,
hexToBytes(this.#account.privateKey)
),
sigPrivKey: hexToBytes(this.#account.privateKey),
}),
{ payload: message }
)
}

public handleWakuMessage = (wakuMessage: WakuMessage): void => {
public handleWakuMessage = (wakuMessage: DecodedMessage): void => {
handleWakuMessage(wakuMessage, this, this.community, this.#account)
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/status-js/src/client/community/community.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createDecoder } from '@waku/message-encryption/symmetric'
import { hexToBytes } from 'ethereum-cryptography/utils'
import { SymDecoder } from 'js-waku/lib/waku_message/version_1'

import { getDifferenceByKeys } from '../../helpers/get-difference-by-keys'
import { getObjectsDifference } from '../../helpers/get-objects-difference'
Expand Down Expand Up @@ -93,8 +93,8 @@ export class Community {

public fetch = async () => {
// most recent page first
await this.client.waku.store.queryOrderedCallback(
[new SymDecoder(this.contentTopic, this.symmetricKey)],
await this.client.waku.store.queryWithOrderedCallback(
[createDecoder(this.contentTopic, this.symmetricKey)],
wakuMessage => {
this.client.handleWakuMessage(wakuMessage)

Expand All @@ -109,7 +109,7 @@ export class Community {

private observe = async () => {
await this.client.waku.filter.subscribe(
[new SymDecoder(this.contentTopic, this.symmetricKey)],
[createDecoder(this.contentTopic, this.symmetricKey)],
this.client.handleWakuMessage
)
}
Expand All @@ -130,7 +130,7 @@ export class Community {
this.chats.set(chatUuid, chat)

const unobserveFn = await this.client.waku.filter.subscribe(
[new SymDecoder(chat.contentTopic, chat.symmetricKey)],
[createDecoder(chat.contentTopic, chat.symmetricKey)],
this.client.handleWakuMessage
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import { mapChatMessage } from './map-chat-message'
import type { Account } from '../account'
import type { Client } from '../client'
import type { Community } from './community'
import type { MessageV1 as WakuMessage } from 'js-waku/lib/waku_message/version_1'
import type { DecodedMessage } from '@waku/message-encryption/symmetric'

export function handleWakuMessage(
wakuMessage: WakuMessage,
wakuMessage: DecodedMessage,
// state
client: Client,
community: Community,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @generated by protoc-gen-es v1.0.0 with parameter "target=ts"
// @generated by protoc-gen-es v1.4.2 with parameter "target=ts"
// @generated from file application-metadata-message.proto (syntax proto3)
/* eslint-disable */
// @ts-nocheck
Expand Down Expand Up @@ -43,7 +43,7 @@ export class ApplicationMetadataMessage extends Message<ApplicationMetadataMessa
proto3.util.initPartial(data, this)
}

static readonly runtime = proto3
static readonly runtime: typeof proto3 = proto3
static readonly typeName = 'ApplicationMetadataMessage'
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: 'signature', kind: 'scalar', T: 12 /* ScalarType.BYTES */ },
Expand Down
8 changes: 4 additions & 4 deletions packages/status-js/src/protos/chat-identity_pb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @generated by protoc-gen-es v1.0.0 with parameter "target=ts"
// @generated by protoc-gen-es v1.4.2 with parameter "target=ts"
// @generated from file chat-identity.proto (syntax proto3)
/* eslint-disable */
// @ts-nocheck
Expand Down Expand Up @@ -84,7 +84,7 @@ export class ChatIdentity extends Message<ChatIdentity> {
proto3.util.initPartial(data, this)
}

static readonly runtime = proto3
static readonly runtime: typeof proto3 = proto3
static readonly typeName = 'ChatIdentity'
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: 'clock', kind: 'scalar', T: 4 /* ScalarType.UINT64 */ },
Expand Down Expand Up @@ -201,7 +201,7 @@ export class IdentityImage extends Message<IdentityImage> {
proto3.util.initPartial(data, this)
}

static readonly runtime = proto3
static readonly runtime: typeof proto3 = proto3
static readonly typeName = 'IdentityImage'
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: 'payload', kind: 'scalar', T: 12 /* ScalarType.BYTES */ },
Expand Down Expand Up @@ -312,7 +312,7 @@ export class SocialLink extends Message<SocialLink> {
proto3.util.initPartial(data, this)
}

static readonly runtime = proto3
static readonly runtime: typeof proto3 = proto3
static readonly typeName = 'SocialLink'
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: 'text', kind: 'scalar', T: 9 /* ScalarType.STRING */ },
Expand Down
14 changes: 7 additions & 7 deletions packages/status-js/src/protos/chat-message_pb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @generated by protoc-gen-es v1.0.0 with parameter "target=ts"
// @generated by protoc-gen-es v1.4.2 with parameter "target=ts"
// @generated from file chat-message.proto (syntax proto3)
/* eslint-disable */
// @ts-nocheck
Expand Down Expand Up @@ -33,7 +33,7 @@ export class StickerMessage extends Message<StickerMessage> {
proto3.util.initPartial(data, this)
}

static readonly runtime = proto3
static readonly runtime: typeof proto3 = proto3
static readonly typeName = 'StickerMessage'
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: 'hash', kind: 'scalar', T: 9 /* ScalarType.STRING */ },
Expand Down Expand Up @@ -88,7 +88,7 @@ export class ImageMessage extends Message<ImageMessage> {
proto3.util.initPartial(data, this)
}

static readonly runtime = proto3
static readonly runtime: typeof proto3 = proto3
static readonly typeName = 'ImageMessage'
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: 'payload', kind: 'scalar', T: 12 /* ScalarType.BYTES */ },
Expand Down Expand Up @@ -148,7 +148,7 @@ export class AudioMessage extends Message<AudioMessage> {
proto3.util.initPartial(data, this)
}

static readonly runtime = proto3
static readonly runtime: typeof proto3 = proto3
static readonly typeName = 'AudioMessage'
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: 'payload', kind: 'scalar', T: 12 /* ScalarType.BYTES */ },
Expand Down Expand Up @@ -266,7 +266,7 @@ export class EditMessage extends Message<EditMessage> {
proto3.util.initPartial(data, this)
}

static readonly runtime = proto3
static readonly runtime: typeof proto3 = proto3
static readonly typeName = 'EditMessage'
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: 'clock', kind: 'scalar', T: 4 /* ScalarType.UINT64 */ },
Expand Down Expand Up @@ -349,7 +349,7 @@ export class DeleteMessage extends Message<DeleteMessage> {
proto3.util.initPartial(data, this)
}

static readonly runtime = proto3
static readonly runtime: typeof proto3 = proto3
static readonly typeName = 'DeleteMessage'
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: 'clock', kind: 'scalar', T: 4 /* ScalarType.UINT64 */ },
Expand Down Expand Up @@ -510,7 +510,7 @@ export class ChatMessage extends Message<ChatMessage> {
proto3.util.initPartial(data, this)
}

static readonly runtime = proto3
static readonly runtime: typeof proto3 = proto3
static readonly typeName = 'ChatMessage'
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: 'clock', kind: 'scalar', T: 4 /* ScalarType.UINT64 */ },
Expand Down
Loading

2 comments on commit 51df6db

@vercel
Copy link

@vercel vercel bot commented on 51df6db Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

status-web – ./apps/web

status-web-git-main-status-im-web.vercel.app
status-web-status-im-web.vercel.app
status-web.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 51df6db Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

status-components – ./packages/components

status-components.vercel.app
status-components-status-im-web.vercel.app
status-components-git-main-status-im-web.vercel.app

Please sign in to comment.