mirror of
https://github.com/logos-messaging/logos-chat.git
synced 2026-08-07 18:43:16 +00:00
Added Waku dependancies
This commit is contained in:
commit
adde56532b
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/waku_vibe_template
|
||||||
|
/waku_vibe_template.dSYM
|
||||||
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "vendor/waku"]
|
||||||
|
path = vendor/waku
|
||||||
|
url = git@github.com:waku-org/nwaku.git
|
||||||
65
README.md
Normal file
65
README.md
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
# Nim Chat POC
|
||||||
|
|
||||||
|
This is a technical proof of consuming the [chat_proto](https://github.com/waku-org/chat_proto/tree/base_types?tab=readme-ov-file) in nim.
|
||||||
|
|
||||||
|
|
||||||
|
## Message Flow
|
||||||
|
|
||||||
|
To establish a secure conversation, Saro and Raya need to:
|
||||||
|
1. Exchange key material
|
||||||
|
2. Agree on a secret key, and location to communicate
|
||||||
|
|
||||||
|
For this technical proof, recipient identity keys are exchanged out of bound via an invite link. More complex identity systems will be explored in the future.
|
||||||
|
|
||||||
|
Key derivation and message framing is defined by Inbox spec
|
||||||
|
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
actor S as Saro
|
||||||
|
participant SI as Saro Inbox
|
||||||
|
participant C as Convo
|
||||||
|
participant RI as Raya Inbox
|
||||||
|
actor R as Raya
|
||||||
|
|
||||||
|
|
||||||
|
Note over SI,RI: All clients subscribe to their default Inbox
|
||||||
|
|
||||||
|
SI ->> S: Subscribe
|
||||||
|
RI ->> R: Subscribe
|
||||||
|
|
||||||
|
Note over R: Key Information is exchanged OOB
|
||||||
|
|
||||||
|
Note over S: Conversation is created
|
||||||
|
C ->> S : Subscribe
|
||||||
|
S ->> RI : Send Invite `I1`
|
||||||
|
S ->> C : Send Message `M1`
|
||||||
|
|
||||||
|
RI --) R : Recv `I1`
|
||||||
|
Note over R: Conversation is joined
|
||||||
|
C ->> R : Subscribe
|
||||||
|
C --) R: Recv `M1`
|
||||||
|
|
||||||
|
R ->> C: Send M2
|
||||||
|
C -->> S: Recv M2
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
# Run the default binary
|
||||||
|
nimble run
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Limitations
|
||||||
|
|
||||||
|
1. `.proto` files are included in this repo due to complications in importing nested packages using `?subdir=`. Once resolved there will be a single definition of protocol types.
|
||||||
|
1. Currently messages are not sent over the wire. They are simulated using a `TransportMessage`.
|
||||||
|
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
[MIT](https://choosealicense.com/licenses/mit/)
|
||||||
13
nim.cfg
Normal file
13
nim.cfg
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Add custom paths to import modules
|
||||||
|
--path: "vendor/waku"
|
||||||
|
|
||||||
|
# Compile with debug symbols
|
||||||
|
--debuginfo
|
||||||
|
|
||||||
|
# Enable warnings
|
||||||
|
--warning[UnusedImport]: on
|
||||||
|
|
||||||
|
# Enable experimental features
|
||||||
|
--experimental
|
||||||
|
|
||||||
|
--passL: "./vendor/waku/librln_v0.7.0.a"
|
||||||
115
src/waku_vibe_template.nim
Normal file
115
src/waku_vibe_template.nim
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
import
|
||||||
|
std/[tables, sequtils],
|
||||||
|
stew/byteutils,
|
||||||
|
chronicles,
|
||||||
|
chronos,
|
||||||
|
confutils,
|
||||||
|
libp2p/crypto/crypto,
|
||||||
|
eth/keys,
|
||||||
|
eth/p2p/discoveryv5/enr
|
||||||
|
|
||||||
|
import
|
||||||
|
waku/[
|
||||||
|
common/logging,
|
||||||
|
node/peer_manager,
|
||||||
|
waku_core,
|
||||||
|
waku_node,
|
||||||
|
waku_enr,
|
||||||
|
discovery/waku_discv5,
|
||||||
|
factory/builder,
|
||||||
|
waku_relay,
|
||||||
|
waku_filter_v2/client,
|
||||||
|
]
|
||||||
|
|
||||||
|
# careful if running pub and sub in the same machine
|
||||||
|
const wakuPort = 50000
|
||||||
|
|
||||||
|
const clusterId = 1
|
||||||
|
const shardId = @[0'u16]
|
||||||
|
|
||||||
|
const
|
||||||
|
FilterPeer =
|
||||||
|
"/ip4/178.128.141.171/tcp/30303/p2p/16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W"
|
||||||
|
FilterPubsubTopic = PubsubTopic("/waku/2/rs/1/0")
|
||||||
|
FilterContentTopic = ContentTopic("/examples/1/light-pubsub-example/proto")
|
||||||
|
|
||||||
|
proc messagePushHandler(
|
||||||
|
pubsubTopic: PubsubTopic, message: WakuMessage
|
||||||
|
) {.async, gcsafe.} =
|
||||||
|
let payloadStr = string.fromBytes(message.payload)
|
||||||
|
notice "message received",
|
||||||
|
payload = payloadStr,
|
||||||
|
pubsubTopic = pubsubTopic,
|
||||||
|
contentTopic = message.contentTopic,
|
||||||
|
timestamp = message.timestamp
|
||||||
|
|
||||||
|
proc setupAndSubscribe(rng: ref HmacDrbgContext) {.async.} =
|
||||||
|
# use notice to filter all waku messaging
|
||||||
|
setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT)
|
||||||
|
|
||||||
|
notice "starting subscriber", wakuPort = wakuPort
|
||||||
|
let
|
||||||
|
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||||
|
ip = parseIpAddress("0.0.0.0")
|
||||||
|
flags = CapabilitiesBitfield.init(relay = true)
|
||||||
|
|
||||||
|
let relayShards = RelayShards.init(clusterId, shardId).valueOr:
|
||||||
|
error "Relay shards initialization failed", error = error
|
||||||
|
quit(QuitFailure)
|
||||||
|
|
||||||
|
var enrBuilder = EnrBuilder.init(nodeKey)
|
||||||
|
enrBuilder.withWakuRelaySharding(relayShards).expect(
|
||||||
|
"Building ENR with relay sharding failed"
|
||||||
|
)
|
||||||
|
|
||||||
|
let recordRes = enrBuilder.build()
|
||||||
|
let record =
|
||||||
|
if recordRes.isErr():
|
||||||
|
error "failed to create enr record", error = recordRes.error
|
||||||
|
quit(QuitFailure)
|
||||||
|
else:
|
||||||
|
recordRes.get()
|
||||||
|
|
||||||
|
var builder = WakuNodeBuilder.init()
|
||||||
|
builder.withNodeKey(nodeKey)
|
||||||
|
builder.withRecord(record)
|
||||||
|
builder.withNetworkConfigurationDetails(ip, Port(wakuPort)).tryGet()
|
||||||
|
let node = builder.build().tryGet()
|
||||||
|
|
||||||
|
node.mountMetadata(clusterId).expect("failed to mount waku metadata protocol")
|
||||||
|
await node.mountFilterClient()
|
||||||
|
|
||||||
|
await node.start()
|
||||||
|
|
||||||
|
node.peerManager.start()
|
||||||
|
|
||||||
|
node.wakuFilterClient.registerPushHandler(messagePushHandler)
|
||||||
|
|
||||||
|
let filterPeer = parsePeerInfo(FilterPeer).get()
|
||||||
|
|
||||||
|
while true:
|
||||||
|
notice "maintaining subscription"
|
||||||
|
# First use filter-ping to check if we have an active subscription
|
||||||
|
let pingRes = await node.wakuFilterClient.ping(filterPeer)
|
||||||
|
if pingRes.isErr():
|
||||||
|
# No subscription found. Let's subscribe.
|
||||||
|
notice "no subscription found. Sending subscribe request"
|
||||||
|
|
||||||
|
let subscribeRes = await node.wakuFilterClient.subscribe(
|
||||||
|
filterPeer, FilterPubsubTopic, @[FilterContentTopic]
|
||||||
|
)
|
||||||
|
|
||||||
|
if subscribeRes.isErr():
|
||||||
|
notice "subscribe request failed. Quitting.", err = subscribeRes.error
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
notice "subscribe request successful."
|
||||||
|
else:
|
||||||
|
notice "subscription found."
|
||||||
|
|
||||||
|
await sleepAsync(60.seconds) # Subscription maintenance interval
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
let rng = crypto.newRng()
|
||||||
|
asyncSpawn setupAndSubscribe(rng)
|
||||||
|
runForever()
|
||||||
1
vendor/waku
vendored
Submodule
1
vendor/waku
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 3fb21ae079f7c3390844c4f7a6841b5d34cb833a
|
||||||
24
waku_vibe_template.nimble
Normal file
24
waku_vibe_template.nimble
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Package
|
||||||
|
|
||||||
|
version = "0.1.0"
|
||||||
|
author = "jazzz"
|
||||||
|
description = "An example of the chat sdk in Nim"
|
||||||
|
license = "MIT"
|
||||||
|
srcDir = "src"
|
||||||
|
bin = @["waku_vibe_template"]
|
||||||
|
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
|
||||||
|
requires "nim >= 2.2.4"
|
||||||
|
|
||||||
|
requires "protobuf_serialization >= 0.1.0"
|
||||||
|
requires "secp256k1 >= 0.6.0.3.2"
|
||||||
|
requires "blake2"
|
||||||
|
requires "chronicles"
|
||||||
|
requires "libp2p >= 1.11.0"
|
||||||
|
requires "nimchacha20poly1305" # TODO: remove
|
||||||
|
requires "confutils >= 0.1.0"
|
||||||
|
requires "eth >= 0.8.0"
|
||||||
|
requires "regex >= 0.26.3"
|
||||||
|
requires "web3 >= 0.7.0"
|
||||||
Loading…
x
Reference in New Issue
Block a user