mirror of https://github.com/waku-org/nwaku.git
Feat(Rln relay): Enables and integrates onchain rln into chat2 (#1029)
* adds wakunode2_types * removes unused imports * adds dynamic rln relay config options * deletes unused imports * replaces static rln-relay with both modes * introduces spamHandler parameter to mountRlnRelay * some debugging info * introduces the config option * adds the eth priv key to the register proc * refactors the code by adding eth private key to the relevant procs * revises config descriptions * minor wording fix * make a minor edit * further edits * adds Eth private key to the config options * calls spam handler when to rln credential is given * defaults to none for the spam handler * updates the membership fee to match the contract * fixes an issue for event subscription * adds eth private key to the transactions made in the tests * adds eth private key for the test of register process * adds comments * deletes lingering echo * displays registration info * removes an echo * removes Goerli testnet from the config descriptions * removes an excess space
This commit is contained in:
parent
2ca27ea898
commit
daaca4a4a3
|
@ -508,29 +508,11 @@ proc processInput(rfd: AsyncFD, rng: ref BrHmacDrbgContext) {.async.} =
|
|||
echo "A spam message is found and discarded"
|
||||
chat.prompt = false
|
||||
showChatPrompt(chat)
|
||||
|
||||
# set up rln relay inputs
|
||||
let (groupOpt, memKeyPairOpt, memIndexOpt) = rlnRelayStaticSetUp(conf.rlnRelayMemIndex)
|
||||
if memIndexOpt.isNone:
|
||||
error "failed to mount WakuRLNRelay"
|
||||
else:
|
||||
# mount rlnrelay in offline mode (for now)
|
||||
node.mountRlnRelayStatic(group = groupOpt.get(), memKeyPair = memKeyPairOpt.get(), memIndex = memIndexOpt.get(), pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic, spamHandler = some(spamHandler))
|
||||
|
||||
debug "membership id key", idkey=memKeyPairOpt.get().idKey.toHex
|
||||
debug "membership id commitment key", idCommitmentkey=memKeyPairOpt.get().idCommitment.toHex
|
||||
|
||||
# check the correct construction of the tree by comparing the calculated root against the expected root
|
||||
# no error should happen as it is already captured in the unit tests
|
||||
# TODO have added this check to account for unseen corner cases, will remove it later
|
||||
let
|
||||
root = node.wakuRlnRelay.rlnInstance.getMerkleRoot.value.toHex()
|
||||
expectedRoot = STATIC_GROUP_MERKLE_ROOT
|
||||
if root != expectedRoot:
|
||||
error "root mismatch: something went wrong not in Merkle tree construction"
|
||||
debug "the calculated root", root
|
||||
debug "WakuRLNRelay is mounted successfully", pubsubtopic=conf.rlnRelayPubsubTopic, contentTopic=conf.rlnRelayContentTopic
|
||||
|
||||
echo "rln-relay preparation is in progress ..."
|
||||
node.mountRlnRelay(conf, some(spamHandler))
|
||||
echo "your membership index is: ", node.wakuRlnRelay.membershipIndex
|
||||
echo "your rln identity key is: ", node.wakuRlnRelay.membershipKeyPair.idKey.toHex()
|
||||
echo "your rln identity commitment key is: ", node.wakuRlnRelay.membershipKeyPair.idCommitment.toHex()
|
||||
|
||||
await chat.readWriteLoop()
|
||||
|
||||
|
|
|
@ -249,6 +249,41 @@ type
|
|||
defaultValue: "/waku/2/default-waku/proto"
|
||||
name: "rln-relay-pubsub-topic" }: string
|
||||
|
||||
rlnRelayDynamic* {.
|
||||
desc: "Enable waku-rln-relay with on-chain dynamic group management: true|false",
|
||||
defaultValue: false
|
||||
name: "rln-relay-dynamic" }: bool
|
||||
|
||||
rlnRelayIdKey* {.
|
||||
desc: "Rln relay identity secret key as a Hex string",
|
||||
defaultValue: ""
|
||||
name: "rln-relay-id" }: string
|
||||
|
||||
rlnRelayIdCommitmentKey* {.
|
||||
desc: "Rln relay identity commitment key as a Hex string",
|
||||
defaultValue: ""
|
||||
name: "rln-relay-id-commitment" }: string
|
||||
|
||||
rlnRelayEthAccount* {.
|
||||
desc: "Ethereum account address for an Ethereum testnet",
|
||||
defaultValue: ""
|
||||
name: "eth-account-address" }: string
|
||||
|
||||
rlnRelayEthAccountPrivKey* {.
|
||||
desc: "Account private key for an Ethereum testnet",
|
||||
defaultValue: ""
|
||||
name: "eth-account-privatekey" }: string
|
||||
|
||||
rlnRelayEthClientAddress* {.
|
||||
desc: "Ethereum testnet client address e.g., ws://localhost:8540/",
|
||||
defaultValue: "ws://localhost:8540/"
|
||||
name: "eth-client-address" }: string
|
||||
|
||||
rlnRelayEthMemContractAddress* {.
|
||||
desc: "Address of membership contract on an Ethereum testnet",
|
||||
defaultValue: ""
|
||||
name: "eth-mem-contract-address" }: string
|
||||
|
||||
# NOTE: Keys are different in nim-libp2p
|
||||
proc parseCmdArg*(T: type crypto.PrivateKey, p: TaintedString): T =
|
||||
try:
|
||||
|
|
|
@ -14,6 +14,7 @@ import
|
|||
rln,
|
||||
waku_rln_relay_types,
|
||||
../../node/[wakunode2_types,config],
|
||||
../../../../../examples/v2/config_chat2,
|
||||
../waku_message
|
||||
|
||||
|
||||
|
@ -818,7 +819,7 @@ proc mountRlnRelayDynamic*(node: WakuNode,
|
|||
node.wakuRlnRelay = rlnPeer
|
||||
|
||||
|
||||
proc mountRlnRelay*(node: WakuNode, conf: WakuNodeConf) {.raises: [Defect, ValueError, IOError, CatchableError].} =
|
||||
proc mountRlnRelay*(node: WakuNode, conf: WakuNodeConf|Chat2Conf, spamHandler: Option[SpamHandler] = none(SpamHandler)) {.raises: [Defect, ValueError, IOError, CatchableError].} =
|
||||
if not conf.rlnRelayDynamic:
|
||||
info " setting up waku-rln-relay in on-chain mode... "
|
||||
# set up rln relay inputs
|
||||
|
@ -827,7 +828,7 @@ proc mountRlnRelay*(node: WakuNode, conf: WakuNodeConf) {.raises: [Defect, Value
|
|||
error "failed to mount WakuRLNRelay"
|
||||
else:
|
||||
# mount rlnrelay in off-chain mode with a static group of users
|
||||
node.mountRlnRelayStatic(group = groupOpt.get(), memKeyPair = memKeyPairOpt.get(), memIndex= memIndexOpt.get(), pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic)
|
||||
node.mountRlnRelayStatic(group = groupOpt.get(), memKeyPair = memKeyPairOpt.get(), memIndex= memIndexOpt.get(), pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic, spamHandler = spamHandler)
|
||||
|
||||
info "membership id key", idkey=memKeyPairOpt.get().idKey.toHex
|
||||
info "membership id commitment key", idCommitmentkey=memKeyPairOpt.get().idCommitment.toHex
|
||||
|
@ -860,9 +861,9 @@ proc mountRlnRelay*(node: WakuNode, conf: WakuNodeConf) {.raises: [Defect, Value
|
|||
let keyPair = @[(rlnRelayId, rlnRelayIdCommitmentKey)]
|
||||
let memKeyPair = keyPair.toMembershipKeyPairs()[0]
|
||||
# mount the rln relay protocol in the on-chain/dynamic mode
|
||||
waitFor node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress, ethClientAddr = ethClientAddr, memKeyPair = some(memKeyPair), memIndex = some(rlnRelayIndex), ethAccAddr = ethAccountAddr, ethAccountPrivKey = ethAccountPrivKey, pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic)
|
||||
waitFor node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress, ethClientAddr = ethClientAddr, memKeyPair = some(memKeyPair), memIndex = some(rlnRelayIndex), ethAccAddr = ethAccountAddr, ethAccountPrivKey = ethAccountPrivKey, pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic, spamHandler = spamHandler)
|
||||
else:
|
||||
# no rln credential is provided
|
||||
# mount the rln relay protocol in the on-chain/dynamic mode
|
||||
waitFor node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress, ethClientAddr = ethClientAddr, ethAccAddr = ethAccountAddr, ethAccountPrivKey = ethAccountPrivKey, pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic)
|
||||
waitFor node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress, ethClientAddr = ethClientAddr, ethAccAddr = ethAccountAddr, ethAccountPrivKey = ethAccountPrivKey, pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic, spamHandler = spamHandler)
|
||||
|
||||
|
|
Loading…
Reference in New Issue