mirror of https://github.com/waku-org/nwaku.git
Feat(Rln relay): enables relay-mode only (#1051)
* makes eth private key optional * makes eth account private key field optional * clarifies a comment
This commit is contained in:
parent
6c28e3b837
commit
79459d29ce
|
@ -293,7 +293,7 @@ procSuite "Waku-rln-relay":
|
||||||
var rlnPeer = WakuRLNRelay(membershipKeyPair: membershipKeyPair.get(),
|
var rlnPeer = WakuRLNRelay(membershipKeyPair: membershipKeyPair.get(),
|
||||||
membershipIndex: MembershipIndex(0),
|
membershipIndex: MembershipIndex(0),
|
||||||
ethClientAddress: ETH_CLIENT,
|
ethClientAddress: ETH_CLIENT,
|
||||||
ethAccountPrivateKey: ethPrivKey,
|
ethAccountPrivateKey: some(ethPrivKey),
|
||||||
ethAccountAddress: ethacc,
|
ethAccountAddress: ethacc,
|
||||||
membershipContractAddress: contractAddress)
|
membershipContractAddress: contractAddress)
|
||||||
|
|
||||||
|
@ -430,7 +430,7 @@ procSuite "Waku-rln-relay":
|
||||||
node.mountRelay(@[RLNRELAY_PUBSUB_TOPIC])
|
node.mountRelay(@[RLNRELAY_PUBSUB_TOPIC])
|
||||||
await node.mountRlnRelayDynamic(ethClientAddr = EthClient,
|
await node.mountRlnRelayDynamic(ethClientAddr = EthClient,
|
||||||
ethAccAddr = ethacc,
|
ethAccAddr = ethacc,
|
||||||
ethAccountPrivKey = ethPrivKey,
|
ethAccountPrivKeyOpt = some(ethPrivKey),
|
||||||
memContractAddr = contractAddress,
|
memContractAddr = contractAddress,
|
||||||
memKeyPair = keyPair1,
|
memKeyPair = keyPair1,
|
||||||
memIndex = some(MembershipIndex(0)),
|
memIndex = some(MembershipIndex(0)),
|
||||||
|
@ -483,7 +483,7 @@ procSuite "Waku-rln-relay":
|
||||||
node.mountRelay(@[RLNRELAY_PUBSUB_TOPIC])
|
node.mountRelay(@[RLNRELAY_PUBSUB_TOPIC])
|
||||||
await node.mountRlnRelayDynamic(ethClientAddr = EthClient,
|
await node.mountRlnRelayDynamic(ethClientAddr = EthClient,
|
||||||
ethAccAddr = ethacc,
|
ethAccAddr = ethacc,
|
||||||
ethAccountPrivKey = ethPrivKey,
|
ethAccountPrivKeyOpt = some(ethPrivKey),
|
||||||
memContractAddr = contractAddress,
|
memContractAddr = contractAddress,
|
||||||
memKeyPair = none(MembershipKeyPair),
|
memKeyPair = none(MembershipKeyPair),
|
||||||
memIndex = none(MembershipIndex),
|
memIndex = none(MembershipIndex),
|
||||||
|
@ -496,7 +496,7 @@ procSuite "Waku-rln-relay":
|
||||||
node2.mountRelay(@[RLNRELAY_PUBSUB_TOPIC])
|
node2.mountRelay(@[RLNRELAY_PUBSUB_TOPIC])
|
||||||
await node2.mountRlnRelayDynamic(ethClientAddr = EthClient,
|
await node2.mountRlnRelayDynamic(ethClientAddr = EthClient,
|
||||||
ethAccAddr = ethacc,
|
ethAccAddr = ethacc,
|
||||||
ethAccountPrivKey = ethPrivKey,
|
ethAccountPrivKeyOpt = some(ethPrivKey),
|
||||||
memContractAddr = contractAddress,
|
memContractAddr = contractAddress,
|
||||||
memKeyPair = none(MembershipKeyPair),
|
memKeyPair = none(MembershipKeyPair),
|
||||||
memIndex = none(MembershipIndex),
|
memIndex = none(MembershipIndex),
|
||||||
|
@ -511,4 +511,4 @@ procSuite "Waku-rln-relay":
|
||||||
node2.wakuRlnRelay.membershipIndex == MembershipIndex(1)
|
node2.wakuRlnRelay.membershipIndex == MembershipIndex(1)
|
||||||
|
|
||||||
await node.stop()
|
await node.stop()
|
||||||
await node2.stop()
|
await node2.stop()
|
||||||
|
|
|
@ -75,7 +75,7 @@ type WakuRLNRelay* = ref object
|
||||||
# this field is required for signing transactions
|
# this field is required for signing transactions
|
||||||
# TODO may need to erase this ethAccountPrivateKey when is not used
|
# TODO may need to erase this ethAccountPrivateKey when is not used
|
||||||
# TODO may need to make ethAccountPrivateKey mandatory
|
# TODO may need to make ethAccountPrivateKey mandatory
|
||||||
ethAccountPrivateKey*: PrivateKey
|
ethAccountPrivateKey*: Option[PrivateKey]
|
||||||
rlnInstance*: RLN[Bn256]
|
rlnInstance*: RLN[Bn256]
|
||||||
pubsubTopic*: string # the pubsub topic for which rln relay is mounted
|
pubsubTopic*: string # the pubsub topic for which rln relay is mounted
|
||||||
# contentTopic should be of type waku_message.ContentTopic, however, due to recursive module dependency, the underlying type of ContentTopic is used instead
|
# contentTopic should be of type waku_message.ContentTopic, however, due to recursive module dependency, the underlying type of ContentTopic is used instead
|
||||||
|
|
|
@ -170,7 +170,7 @@ proc register*(rlnPeer: WakuRLNRelay): Future[bool] {.async.} =
|
||||||
## registers the public key of the rlnPeer which is rlnPeer.membershipKeyPair.publicKey
|
## registers the public key of the rlnPeer which is rlnPeer.membershipKeyPair.publicKey
|
||||||
## into the membership contract whose address is in rlnPeer.membershipContractAddress
|
## into the membership contract whose address is in rlnPeer.membershipContractAddress
|
||||||
let pk = rlnPeer.membershipKeyPair.idCommitment
|
let pk = rlnPeer.membershipKeyPair.idCommitment
|
||||||
discard await register(idComm = pk, ethAccountAddress = rlnPeer.ethAccountAddress, ethAccountPrivKey = rlnPeer.ethAccountPrivateKey, ethClientAddress = rlnPeer.ethClientAddress, membershipContractAddress = rlnPeer.membershipContractAddress )
|
discard await register(idComm = pk, ethAccountAddress = rlnPeer.ethAccountAddress, ethAccountPrivKey = rlnPeer.ethAccountPrivateKey.get(), ethClientAddress = rlnPeer.ethClientAddress, membershipContractAddress = rlnPeer.membershipContractAddress )
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
@ -745,7 +745,7 @@ proc mountRlnRelayStatic*(node: WakuNode,
|
||||||
proc mountRlnRelayDynamic*(node: WakuNode,
|
proc mountRlnRelayDynamic*(node: WakuNode,
|
||||||
ethClientAddr: string = "",
|
ethClientAddr: string = "",
|
||||||
ethAccAddr: web3.Address,
|
ethAccAddr: web3.Address,
|
||||||
ethAccountPrivKey: keys.PrivateKey,
|
ethAccountPrivKeyOpt: Option[keys.PrivateKey],
|
||||||
memContractAddr: web3.Address,
|
memContractAddr: web3.Address,
|
||||||
memKeyPair: Option[MembershipKeyPair] = none(MembershipKeyPair),
|
memKeyPair: Option[MembershipKeyPair] = none(MembershipKeyPair),
|
||||||
memIndex: Option[MembershipIndex] = none(MembershipIndex),
|
memIndex: Option[MembershipIndex] = none(MembershipIndex),
|
||||||
|
@ -773,17 +773,20 @@ proc mountRlnRelayDynamic*(node: WakuNode,
|
||||||
var
|
var
|
||||||
keyPair: MembershipKeyPair
|
keyPair: MembershipKeyPair
|
||||||
rlnIndex: MembershipIndex
|
rlnIndex: MembershipIndex
|
||||||
if memKeyPair.isNone: # if non provided, create one and register to the contract
|
if memKeyPair.isNone:
|
||||||
trace "no rln-relay key is provided, generating one"
|
if ethAccountPrivKeyOpt.isSome: # if no rln credentials provided, and an ethereum private key is supplied, then create rln credentials and register to the membership contract
|
||||||
let keyPairOpt = rln.membershipKeyGen()
|
trace "no rln-relay key is provided, generating one"
|
||||||
doAssert(keyPairOpt.isSome)
|
let keyPairOpt = rln.membershipKeyGen()
|
||||||
keyPair = keyPairOpt.get()
|
doAssert(keyPairOpt.isSome)
|
||||||
# register the rln-relay peer to the membership contract
|
keyPair = keyPairOpt.get()
|
||||||
let regIndexRes = await register(idComm = keyPair.idCommitment, ethAccountAddress = ethAccAddr, ethAccountPrivKey = ethAccountPrivKey, ethClientAddress = ethClientAddr, membershipContractAddress = memContractAddr)
|
# register the rln-relay peer to the membership contract
|
||||||
# check whether registration is done
|
let regIndexRes = await register(idComm = keyPair.idCommitment, ethAccountAddress = ethAccAddr, ethAccountPrivKey = ethAccountPrivKeyOpt.get(), ethClientAddress = ethClientAddr, membershipContractAddress = memContractAddr)
|
||||||
doAssert(regIndexRes.isOk())
|
# check whether registration is done
|
||||||
rlnIndex = regIndexRes.value
|
doAssert(regIndexRes.isOk())
|
||||||
debug "peer is successfully registered into the membership contract"
|
rlnIndex = regIndexRes.value
|
||||||
|
debug "peer is successfully registered into the membership contract"
|
||||||
|
else: # if no eth private key is available, skip registration
|
||||||
|
debug "running waku-rln-relay in relay-only mode"
|
||||||
else:
|
else:
|
||||||
keyPair = memKeyPair.get()
|
keyPair = memKeyPair.get()
|
||||||
rlnIndex = memIndex.get()
|
rlnIndex = memIndex.get()
|
||||||
|
@ -794,7 +797,7 @@ proc mountRlnRelayDynamic*(node: WakuNode,
|
||||||
membershipContractAddress: memContractAddr,
|
membershipContractAddress: memContractAddr,
|
||||||
ethClientAddress: ethClientAddr,
|
ethClientAddress: ethClientAddr,
|
||||||
ethAccountAddress: ethAccAddr,
|
ethAccountAddress: ethAccAddr,
|
||||||
ethAccountPrivateKey: ethAccountPrivKey,
|
ethAccountPrivateKey: ethAccountPrivKeyOpt,
|
||||||
rlnInstance: rln,
|
rlnInstance: rln,
|
||||||
pubsubTopic: pubsubTopic,
|
pubsubTopic: pubsubTopic,
|
||||||
contentTopic: contentTopic)
|
contentTopic: contentTopic)
|
||||||
|
@ -849,21 +852,23 @@ proc mountRlnRelay*(node: WakuNode, conf: WakuNodeConf|Chat2Conf, spamHandler: O
|
||||||
# read related inputs to run rln-relay in on-chain mode and do type conversion when needed
|
# read related inputs to run rln-relay in on-chain mode and do type conversion when needed
|
||||||
let
|
let
|
||||||
ethAccountAddr = web3.fromHex(web3.Address, conf.rlnRelayEthAccount)
|
ethAccountAddr = web3.fromHex(web3.Address, conf.rlnRelayEthAccount)
|
||||||
ethAccountPrivKey = keys.PrivateKey(SkSecretKey.fromHex(conf.rlnRelayEthAccountPrivKey).value)
|
|
||||||
ethClientAddr = conf.rlnRelayEthClientAddress
|
ethClientAddr = conf.rlnRelayEthClientAddress
|
||||||
ethMemContractAddress = web3.fromHex(web3.Address, conf.rlnRelayEthMemContractAddress)
|
ethMemContractAddress = web3.fromHex(web3.Address, conf.rlnRelayEthMemContractAddress)
|
||||||
rlnRelayId = conf.rlnRelayIdKey
|
rlnRelayId = conf.rlnRelayIdKey
|
||||||
rlnRelayIdCommitmentKey = conf.rlnRelayIdCommitmentKey
|
rlnRelayIdCommitmentKey = conf.rlnRelayIdCommitmentKey
|
||||||
rlnRelayIndex = conf.rlnRelayMemIndex
|
rlnRelayIndex = conf.rlnRelayMemIndex
|
||||||
|
var ethAccountPrivKeyOpt = none(keys.PrivateKey)
|
||||||
|
if conf.rlnRelayEthAccountPrivKey != "":
|
||||||
|
ethAccountPrivKeyOpt = some(keys.PrivateKey(SkSecretKey.fromHex(conf.rlnRelayEthAccountPrivKey).value))
|
||||||
# check if the peer has provided its rln credentials
|
# check if the peer has provided its rln credentials
|
||||||
if rlnRelayIdCommitmentKey != "" and rlnRelayId != "":
|
if rlnRelayIdCommitmentKey != "" and rlnRelayId != "":
|
||||||
# type conversation from hex strings to MembershipKeyPair
|
# type conversation from hex strings to MembershipKeyPair
|
||||||
let keyPair = @[(rlnRelayId, rlnRelayIdCommitmentKey)]
|
let keyPair = @[(rlnRelayId, rlnRelayIdCommitmentKey)]
|
||||||
let memKeyPair = keyPair.toMembershipKeyPairs()[0]
|
let memKeyPair = keyPair.toMembershipKeyPairs()[0]
|
||||||
# mount the rln relay protocol in the on-chain/dynamic mode
|
# 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, spamHandler = spamHandler)
|
waitFor node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress, ethClientAddr = ethClientAddr, memKeyPair = some(memKeyPair), memIndex = some(rlnRelayIndex), ethAccAddr = ethAccountAddr, ethAccountPrivKeyOpt = ethAccountPrivKeyOpt, pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic, spamHandler = spamHandler)
|
||||||
else:
|
else:
|
||||||
# no rln credential is provided
|
# no rln credential is provided
|
||||||
# mount the rln relay protocol in the on-chain/dynamic mode
|
# 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, spamHandler = spamHandler)
|
waitFor node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress, ethClientAddr = ethClientAddr, ethAccAddr = ethAccountAddr, ethAccountPrivKeyOpt = ethAccountPrivKeyOpt, pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic, spamHandler = spamHandler)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue