nim-chat-poc/library/declare_lib.nim
Arseniy Klempner 29c64b340d
feat: mix+LEZ+RLN chat over the testnet via 2-phase gifter
Chat-side integration of the LEZ-backed RLN mix protocol:
- src/chat/delivery/waku_client.nim: mount waku_mix with onchain
  RLN spam protection wired to logos_core_client fetchers; gate
  the first publish on (a) gifter status confirmation, (b)
  cushion of 2 poll intervals after confirmation, and (c) proof
  root stability in the local valid_roots window; wrap mix
  lightpush in withTimeout so vanished SURB replies surface as
  Err instead of pinning the send coroutine.
- src/chat/client.nim: surface sendBytes errors via asyncSpawn
  wrapped try/except instead of discarding the future (was
  hiding every mix-publish failure).
- chat-side gifter client invocation (RLN membership service
  wire format, EIP-191 ethereum-allowlist auth).
- Background membership status watcher that reconciles the
  optimistic leaf returned by the gifter against the chain's
  authoritative leaf via the status RPC.

Simulation harness (simulations/mix_lez_chat/):
- Spin up sequencer + run_setup + 4 mix nodes (one of which
  runs the gifter service) + chat sender + chat receiver.
- SIM_NETWORK={local,testnet}, SIM_SLIM for testnet (reuses
  shipped config_account + cached payment_account), Docker
  image + GHCR for cross-platform testing.
- Strict mix-pool readiness gate, kademlia + RLN root activity
  checks, gifter EIP-191 auth fixture, slim-mode submodule
  minimization.
- TREE_ID_HEX pinned to the canonical testnet deployment.

Submodule bumps:
- vendor/nwaku to 8e6ba04 (LEZ-backed RLN mix + 2-phase gifter).
- vendor/logos-lez-rln to 950f287 (SPEL RLN program + mix sim
  infrastructure + canonical testnet deploy).

Docs:
- RUN_SLIM_TESTNET.md: slim sim recipe.
- cleanup/MODE_A_GIFTER_SLOT_BUG.md: per-signer nonce collision
  postmortem driving the queue+worker fix.
2026-05-28 10:53:36 -06:00

52 lines
1.4 KiB
Nim

import ffi
import src/chat/client
import waku/waku_mix/logos_core_client as mix_rln_client
declareLibrary("logoschat")
proc set_event_callback(
ctx: ptr FFIContext[ChatClient],
callback: FFICallBack,
userData: pointer
) {.dynlib, exportc, cdecl.} =
ctx[].eventCallback = cast[pointer](callback)
ctx[].eventUserData = userData
proc chat_set_rln_fetcher(
ctx: ptr FFIContext[ChatClient], fetcher: mix_rln_client.RlnFetcherFunc, fetcherData: pointer
) {.dynlib, exportc, cdecl.} =
if fetcher.isNil:
echo "error: nil fetcher in chat_set_rln_fetcher"
return
mix_rln_client.setRlnFetcher(fetcher, fetcherData)
proc chat_set_rln_config(
ctx: ptr FFIContext[ChatClient], configAccountId: cstring, leafIndex: cint
): cint {.dynlib, exportc, cdecl.} =
if configAccountId.isNil:
return RET_ERR
mix_rln_client.setRlnConfig($configAccountId, leafIndex.int)
return RET_OK
proc chat_set_rln_identity(
ctx: ptr FFIContext[ChatClient], idSecretHashHex: cstring
) {.dynlib, exportc, cdecl.} =
if idSecretHashHex.isNil:
return
mix_rln_client.setRlnIdentity($idSecretHashHex)
proc chat_push_roots(
ctx: ptr FFIContext[ChatClient], rootsJson: cstring
) {.dynlib, exportc, cdecl.} =
if rootsJson.isNil:
return
mix_rln_client.pushRoots($rootsJson)
proc chat_push_proof(
ctx: ptr FFIContext[ChatClient], proofJson: cstring
) {.dynlib, exportc, cdecl.} =
if proofJson.isNil:
return
mix_rln_client.pushProof($proofJson)