mirror of
https://github.com/logos-messaging/go-zerokit-rln.git
synced 2026-01-04 06:03:09 +00:00
refactor: only expose tree config
This commit is contained in:
parent
f5dbeaf1a7
commit
eed6c087b3
26
rln/rln.go
26
rln/rln.go
@ -15,17 +15,19 @@ type RLN struct {
|
|||||||
w *link.RLNWrapper
|
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
|
// 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
|
// and Merkle tree data structure and operations. It uses a depth of 20 by default
|
||||||
func NewRLN() (*RLN, error) {
|
func NewRLN() (*RLN, error) {
|
||||||
return NewWithConfig(DefaultTreeDepth, &Config{
|
return NewWithConfig(DefaultTreeDepth, nil)
|
||||||
ResourcesFolder: "tree_height_20",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRLNWithParams generates an instance of RLN. An instance supports both zkSNARKs logics
|
// 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
|
// 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{}
|
r := &RLN{}
|
||||||
var err error
|
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
|
// 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
|
// 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{}
|
r := &RLN{}
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
configBytes := []byte{}
|
configBytes, err := json.Marshal(config{
|
||||||
if config != nil {
|
ResourcesFolder: getResourcesFolder(depth),
|
||||||
configBytes, err = json.Marshal(config)
|
TreeConfig: treeConfig,
|
||||||
if err != nil {
|
})
|
||||||
return nil, err
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
r.w, err = link.New(depth, configBytes)
|
r.w, err = link.New(int(depth), configBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,11 +25,7 @@ func (s *RLNSuite) TestNew() {
|
|||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
s.Len(root1, 32)
|
s.Len(root1, 32)
|
||||||
|
|
||||||
config := &Config{
|
rln2, err := NewWithConfig(DefaultTreeDepth, nil)
|
||||||
ResourcesFolder: "tree_height_20",
|
|
||||||
}
|
|
||||||
|
|
||||||
rln2, err := NewWithConfig(20, config)
|
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
|
|
||||||
root2, err := rln2.GetMerkleRoot()
|
root2, err := rln2.GetMerkleRoot()
|
||||||
|
|||||||
@ -62,7 +62,7 @@ type RateLimitProof struct {
|
|||||||
RLNIdentifier RLNIdentifier `json:"rlnIdentifier"`
|
RLNIdentifier RLNIdentifier `json:"rlnIdentifier"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TreeDepth = int
|
type TreeDepth int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TreeDepth20 TreeDepth = 20
|
TreeDepth20 TreeDepth = 20
|
||||||
@ -87,7 +87,7 @@ type TreeConfig struct {
|
|||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type config struct {
|
||||||
ResourcesFolder string `json:"resources_folder"`
|
ResourcesFolder string `json:"resources_folder"`
|
||||||
TreeConfig *TreeConfig `json:"tree_config,omitempty"`
|
TreeConfig *TreeConfig `json:"tree_config,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user