refactor: only expose tree config

This commit is contained in:
Richard Ramos 2023-08-10 18:25:06 -04:00
parent f5dbeaf1a7
commit eed6c087b3
No known key found for this signature in database
GPG Key ID: 1CE87DB518195760
3 changed files with 17 additions and 19 deletions

View File

@ -15,17 +15,19 @@ type RLN struct {
w *link.RLNWrapper
}
func getResourcesFolder(depth TreeDepth) string {
return fmt.Sprintf("tree_height_%d", depth)
}
// NewRLN generates an instance of RLN. An instance supports both zkSNARKs logics
// and Merkle tree data structure and operations. It uses a depth of 20 by default
func NewRLN() (*RLN, error) {
return NewWithConfig(DefaultTreeDepth, &Config{
ResourcesFolder: "tree_height_20",
})
return NewWithConfig(DefaultTreeDepth, nil)
}
// NewRLNWithParams generates an instance of RLN. An instance supports both zkSNARKs logics
// and Merkle tree data structure and operations. The parameter `depth“ indicates the depth of Merkle tree
func NewRLNWithParams(depth TreeDepth, wasm []byte, zkey []byte, verifKey []byte, treeConfig *TreeConfig) (*RLN, error) {
func NewRLNWithParams(depth int, wasm []byte, zkey []byte, verifKey []byte, treeConfig *TreeConfig) (*RLN, error) {
r := &RLN{}
var err error
@ -47,19 +49,19 @@ func NewRLNWithParams(depth TreeDepth, wasm []byte, zkey []byte, verifKey []byte
// NewWithConfig generates an instance of RLN. An instance supports both zkSNARKs logics
// and Merkle tree data structure and operations. The parameter `depth` indicates the depth of Merkle tree
func NewWithConfig(depth TreeDepth, config *Config) (*RLN, error) {
func NewWithConfig(depth TreeDepth, treeConfig *TreeConfig) (*RLN, error) {
r := &RLN{}
var err error
configBytes := []byte{}
if config != nil {
configBytes, err = json.Marshal(config)
configBytes, err := json.Marshal(config{
ResourcesFolder: getResourcesFolder(depth),
TreeConfig: treeConfig,
})
if err != nil {
return nil, err
}
}
r.w, err = link.New(depth, configBytes)
r.w, err = link.New(int(depth), configBytes)
if err != nil {
return nil, err
}

View File

@ -25,11 +25,7 @@ func (s *RLNSuite) TestNew() {
s.NoError(err)
s.Len(root1, 32)
config := &Config{
ResourcesFolder: "tree_height_20",
}
rln2, err := NewWithConfig(20, config)
rln2, err := NewWithConfig(DefaultTreeDepth, nil)
s.NoError(err)
root2, err := rln2.GetMerkleRoot()

View File

@ -62,7 +62,7 @@ type RateLimitProof struct {
RLNIdentifier RLNIdentifier `json:"rlnIdentifier"`
}
type TreeDepth = int
type TreeDepth int
const (
TreeDepth20 TreeDepth = 20
@ -87,7 +87,7 @@ type TreeConfig struct {
Path string `json:"path"`
}
type Config struct {
type config struct {
ResourcesFolder string `json:"resources_folder"`
TreeConfig *TreeConfig `json:"tree_config,omitempty"`
}