2025-12-22 14:14:37 +02:00
|
|
|
## Identity API - FFI bindings for identity operations
|
|
|
|
|
## Uses the {.ffi.} pragma for async request handling
|
|
|
|
|
|
|
|
|
|
import std/json
|
|
|
|
|
import chronicles
|
|
|
|
|
import chronos
|
|
|
|
|
import ffi
|
|
|
|
|
import stew/byteutils
|
|
|
|
|
|
2026-01-09 11:29:14 +02:00
|
|
|
import src/chat
|
|
|
|
|
import library/utils
|
2025-12-22 14:14:37 +02:00
|
|
|
|
|
|
|
|
logScope:
|
|
|
|
|
topics = "chat ffi identity"
|
|
|
|
|
|
|
|
|
|
#################################################
|
|
|
|
|
# Identity Operations
|
|
|
|
|
#################################################
|
|
|
|
|
|
|
|
|
|
proc chat_get_identity(
|
2026-01-12 18:16:01 +02:00
|
|
|
ctx: ptr FFIContext[ChatClient],
|
2025-12-22 14:14:37 +02:00
|
|
|
callback: FFICallBack,
|
|
|
|
|
userData: pointer
|
|
|
|
|
) {.ffi.} =
|
|
|
|
|
## Get the client identity
|
2026-02-18 20:18:43 +01:00
|
|
|
## Returns JSON string: {"name": "..."}
|
2025-12-22 14:14:37 +02:00
|
|
|
let identJson = %*{
|
2026-02-18 20:18:43 +01:00
|
|
|
"name": ctx.myLib[].getId()
|
2025-12-22 14:14:37 +02:00
|
|
|
}
|
|
|
|
|
return ok($identJson)
|
|
|
|
|
|
|
|
|
|
#################################################
|
|
|
|
|
# IntroBundle Operations
|
|
|
|
|
#################################################
|
|
|
|
|
|
|
|
|
|
proc chat_create_intro_bundle(
|
2026-01-12 18:16:01 +02:00
|
|
|
ctx: ptr FFIContext[ChatClient],
|
2025-12-22 14:14:37 +02:00
|
|
|
callback: FFICallBack,
|
|
|
|
|
userData: pointer
|
|
|
|
|
) {.ffi.} =
|
|
|
|
|
## Create an IntroBundle for initiating private conversations
|
2026-02-18 20:18:43 +01:00
|
|
|
## Returns the intro bundle as an ASCII string (format: logos_chatintro_<version>_<base64url payload>)
|
2026-01-09 11:49:04 +02:00
|
|
|
let bundle = ctx.myLib[].createIntroBundle()
|
2026-02-18 20:18:43 +01:00
|
|
|
return ok(string.fromBytes(bundle))
|
2025-12-22 14:14:37 +02:00
|
|
|
|