2022-08-12 08:44:13 -04:00
|
|
|
//go:build gowaku_rln
|
|
|
|
// +build gowaku_rln
|
|
|
|
|
|
|
|
package waku
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
|
|
|
"errors"
|
2022-09-11 17:08:58 -04:00
|
|
|
|
2022-08-12 08:44:13 -04:00
|
|
|
"github.com/status-im/go-waku/waku/v2/node"
|
2022-10-27 11:23:20 -04:00
|
|
|
"github.com/waku-org/go-zerokit-rln/rln"
|
2022-09-11 17:08:58 -04:00
|
|
|
"go.uber.org/zap"
|
2022-08-12 08:44:13 -04:00
|
|
|
)
|
|
|
|
|
2022-09-11 17:08:58 -04:00
|
|
|
func checkForRLN(logger *zap.Logger, options Options, nodeOpts *[]node.WakuNodeOption) {
|
2022-08-12 08:44:13 -04:00
|
|
|
if options.RLNRelay.Enable {
|
|
|
|
if !options.Relay.Enable {
|
|
|
|
failOnErr(errors.New("relay not available"), "Could not enable RLN Relay")
|
|
|
|
}
|
|
|
|
if !options.RLNRelay.Dynamic {
|
|
|
|
*nodeOpts = append(*nodeOpts, node.WithStaticRLNRelay(options.RLNRelay.PubsubTopic, options.RLNRelay.ContentTopic, rln.MembershipIndex(options.RLNRelay.MembershipIndex), nil))
|
|
|
|
} else {
|
|
|
|
|
|
|
|
var ethPrivKey *ecdsa.PrivateKey
|
2022-08-15 13:13:45 -04:00
|
|
|
if options.RLNRelay.ETHPrivateKey != nil {
|
|
|
|
ethPrivKey = options.RLNRelay.ETHPrivateKey
|
2022-08-12 08:44:13 -04:00
|
|
|
}
|
2022-11-08 16:20:08 -04:00
|
|
|
membershipCredentials, err := node.GetMembershipCredentials(
|
|
|
|
logger,
|
|
|
|
options.RLNRelay.CredentialsPath,
|
|
|
|
options.RLNRelay.CredentialsPassword,
|
|
|
|
options.RLNRelay.MembershipContractAddress,
|
|
|
|
uint(options.RLNRelay.MembershipIndex),
|
|
|
|
)
|
2022-08-12 08:44:13 -04:00
|
|
|
failOnErr(err, "Invalid membership credentials")
|
|
|
|
|
|
|
|
*nodeOpts = append(*nodeOpts, node.WithDynamicRLNRelay(
|
|
|
|
options.RLNRelay.PubsubTopic,
|
|
|
|
options.RLNRelay.ContentTopic,
|
2022-10-10 18:08:35 -04:00
|
|
|
membershipCredentials,
|
2022-08-12 08:44:13 -04:00
|
|
|
nil,
|
|
|
|
options.RLNRelay.ETHClientAddress,
|
|
|
|
ethPrivKey,
|
2022-09-11 17:08:58 -04:00
|
|
|
nil,
|
2022-08-12 08:44:13 -04:00
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func onStartRLN(wakuNode *node.WakuNode, options Options) {
|
2022-11-08 16:20:08 -04:00
|
|
|
if options.RLNRelay.Enable && options.RLNRelay.Dynamic && options.RLNRelay.CredentialsPath != "" {
|
|
|
|
err := node.WriteRLNMembershipCredentialsToFile(wakuNode.RLNRelay().MembershipKeyPair(), wakuNode.RLNRelay().MembershipIndex(), wakuNode.RLNRelay().MembershipContractAddress(), options.RLNRelay.CredentialsPath, []byte(options.RLNRelay.CredentialsPassword))
|
2022-08-12 08:44:13 -04:00
|
|
|
failOnErr(err, "Could not write membership credentials file")
|
|
|
|
}
|
|
|
|
}
|