chore: add nostr service
This commit is contained in:
@@ -24,7 +24,7 @@ kotlin {
|
||||
|
||||
sourceSets {
|
||||
commonMain.dependencies {
|
||||
// put your Multiplatform dependencies here
|
||||
implementation("org.rust-nostr:nostr-sdk-kmp:0.44.3")
|
||||
}
|
||||
commonTest.dependencies {
|
||||
implementation(libs.kotlin.test)
|
||||
|
||||
28
shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt
Normal file
28
shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt
Normal file
@@ -0,0 +1,28 @@
|
||||
package su.reya.coop
|
||||
|
||||
import rust.nostr.sdk.Client
|
||||
import rust.nostr.sdk.ClientBuilder
|
||||
import rust.nostr.sdk.ClientOptions
|
||||
import rust.nostr.sdk.NostrDatabase
|
||||
import rust.nostr.sdk.NostrGossip
|
||||
import rust.nostr.sdk.RelayUrl
|
||||
|
||||
class Nostr {
|
||||
var client: Client? = null
|
||||
private set
|
||||
|
||||
fun init(dbPath: String) {
|
||||
val lmdb = NostrDatabase.lmdb(dbPath)
|
||||
val gossip = NostrGossip.inMemory()
|
||||
val opts = ClientOptions().automaticAuthentication(false)
|
||||
|
||||
client = ClientBuilder().database(lmdb).gossip(gossip).opts(opts).build()
|
||||
}
|
||||
|
||||
suspend fun connect() {
|
||||
this.client?.addRelay(RelayUrl.parse("wss://relay.damus.io"))
|
||||
this.client?.addRelay(RelayUrl.parse("wss://relay.primal.net"))
|
||||
this.client?.addRelay(RelayUrl.parse("wss://user.kindpag.es"))
|
||||
this.client?.connect()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user