census

package
v0.0.0-...-5757dfe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2022 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCensusNotClosed is used when trying to do some action with the Census
	// that needs the Census to be closed
	ErrCensusNotClosed = errors.New("Census not closed yet")
	// ErrCensusClosed is used when trying to add keys to a census and the census
	// is already closed
	ErrCensusClosed = errors.New("Census closed, can not add more keys")
	// ErrMaxNLeafsReached is used when trying to add a number of new publicKeys
	// which would exceed the maximum number of keys in the census.
	ErrMaxNLeafsReached = fmt.Errorf("MaxNLeafs (%d) reached", types.MaxNLeafs)
)

Functions

func CheckProof

func CheckProof(root, proof []byte, index uint64, pubK *babyjub.PublicKey,
	weight *big.Int) (bool, error)

CheckProof checks a given MerkleProof of the given PublicKey (& index) for the given CensusRoot

Types

type Census

type Census struct {
	// contains filtered or unexported fields
}

Census contains the MerkleTree with the PublicKeys

func New

func New(opts Options) (*Census, error)

New loads the census

func (*Census) AddPublicKeys

func (c *Census) AddPublicKeys(pubKs []babyjub.PublicKey,
	weights []*big.Int) ([]arbo.Invalid, error)

AddPublicKeys adds the batch of given PublicKeys, assigning incremental indexes to each one.

func (*Census) Close

func (c *Census) Close() error

Close closes the census

func (*Census) GetErrMsg

func (c *Census) GetErrMsg() (string, error)

GetErrMsg returns the error message of the Census

func (*Census) GetProof

func (c *Census) GetProof(pubK *babyjub.PublicKey) (uint64, []byte, error)

GetProof returns the leaf Value and the MerkleProof compressed for the given PublicKey

func (*Census) Info

func (c *Census) Info() (*Info, error)

Info returns metadata about the Census

func (*Census) IntermediateRoot

func (c *Census) IntermediateRoot() ([]byte, error)

IntermediateRoot returns the CensusRoot even if the Census is not closed. WARNING: It should be used only for testing purposes.

func (*Census) IsClosed

func (c *Census) IsClosed() (bool, error)

IsClosed returns true if the census is closed, and false if the census is still open

func (*Census) Root

func (c *Census) Root() ([]byte, error)

Root returns the CensusRoot if the Census is closed.

func (*Census) SetErrMsg

func (c *Census) SetErrMsg(status string) error

SetErrMsg stores the given error message into the Census db

func (*Census) Size

func (c *Census) Size() (uint64, error)

Size returns the number of PublicKeys added to the Census.

type Info

type Info struct {
	// ErrMsg contains the stored error message stored for the last
	// operation that gave error
	ErrMsg string `json:"errMsg,omitempty"`
	Size   uint64 `json:"size"`
	Closed bool   `json:"closed"`
	Root   []byte `json:"root,omitempty"`
}

Info contains metadata about a Census

type Options

type Options struct {
	// DB defines the database that will be used for the census
	DB db.Database
}

Options is used to pass the parameters to load a new Census

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL