go-waku/waku/v2/node/wakuoptions_rln.go

55 lines
2.1 KiB
Go
Raw Normal View History

2022-08-12 12:44:13 +00:00
//go:build gowaku_rln
// +build gowaku_rln
package node
import (
"crypto/ecdsa"
"github.com/ethereum/go-ethereum/common"
"github.com/status-im/go-waku/waku/v2/protocol/rln"
r "github.com/waku-org/go-zerokit-rln/rln"
2022-08-12 12:44:13 +00:00
)
2022-08-18 14:42:18 +00:00
// WithStaticRLNRelay enables the Waku V2 RLN protocol in offchain mode
// Requires the `gowaku_rln` build constrain (or the env variable RLN=true if building go-waku)
2022-08-12 12:44:13 +00:00
func WithStaticRLNRelay(pubsubTopic string, contentTopic string, memberIndex r.MembershipIndex, spamHandler rln.SpamHandler) WakuNodeOption {
return func(params *WakuNodeParameters) error {
params.enableRLN = true
params.rlnRelayDynamic = false
params.rlnRelayMemIndex = memberIndex
params.rlnRelayPubsubTopic = pubsubTopic
params.rlnRelayContentTopic = contentTopic
params.rlnSpamHandler = spamHandler
return nil
}
}
2022-10-10 22:08:35 +00:00
type MembershipCredentials struct {
Contract common.Address `json:"contract"`
Keypair *r.MembershipKeyPair `json:"membershipKeyPair"`
Index r.MembershipIndex `json:"rlnIndex"`
}
2022-08-18 14:42:18 +00:00
// WithStaticRLNRelay enables the Waku V2 RLN protocol in onchain mode.
// Requires the `gowaku_rln` build constrain (or the env variable RLN=true if building go-waku)
2022-10-10 22:08:35 +00:00
func WithDynamicRLNRelay(pubsubTopic string, contentTopic string, membershipCredentials MembershipCredentials, spamHandler rln.SpamHandler, ethClientAddress string, ethPrivateKey *ecdsa.PrivateKey, registrationHandler rln.RegistrationHandler) WakuNodeOption {
2022-08-12 12:44:13 +00:00
return func(params *WakuNodeParameters) error {
params.enableRLN = true
params.rlnRelayDynamic = true
2022-10-10 22:08:35 +00:00
params.rlnRelayMemIndex = membershipCredentials.Index
if membershipCredentials.Keypair != nil {
params.rlnRelayIDKey = &membershipCredentials.Keypair.IDKey
params.rlnRelayIDCommitment = &membershipCredentials.Keypair.IDCommitment
}
2022-08-12 12:44:13 +00:00
params.rlnRelayPubsubTopic = pubsubTopic
params.rlnRelayContentTopic = contentTopic
params.rlnSpamHandler = spamHandler
params.rlnETHClientAddress = ethClientAddress
params.rlnETHPrivateKey = ethPrivateKey
2022-10-10 22:08:35 +00:00
params.rlnMembershipContractAddress = membershipCredentials.Contract
2022-09-11 21:08:58 +00:00
params.rlnRegistrationHandler = registrationHandler
2022-08-12 12:44:13 +00:00
return nil
}
}