Documentation
¶
Overview ¶
csp package provides the basic methods to create and verify certificates of voters eligibility of a Credential Service Providers (CSP). This package includes the definition of the CSP interface and a general functions to create a new CSP based on the given origin of the census and verify the census proofs generated by the CSP.
The CSP interface defines methods to set a seed, retrieve census origin and root, generate and verify census proofs. The package currently supports the EdDSA BN254 origin for census proofs.
- The `New` function creates a new CSP based on the provided origin and seed.
- The `VerifyCensusProof` function verifies a given CensusProof using the appropriate CSP based on its origin.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func VerifyCensusProof ¶
func VerifyCensusProof(proof *types.CensusProof) error
VerifyCensusProof verifies the given CensusProof using the appropriate CSP. It checks the origin of the proof and uses the corresponding CSP to verify it. If the origin is not supported, it returns an error.
Types ¶
type CSP ¶
type CSP interface {
SetIndexFn(indexFunc types.CSPIndexFn)
CensusOrigin() types.CensusOrigin
CensusRoot() *types.CensusRoot
GenerateProof(processID types.ProcessID, address common.Address, weight *types.BigInt) (*types.CensusProof, error)
VerifyProof(proof *types.CensusProof) error
}
CSP defines the interface for a Credential Service Providers (CSP). It provides methods to set a function to calculate the VoterIndex (must be deterministic), retrieve census origin and root, and generate and verify census proofs. The CSP is responsible for handling cryptographic operations related to census proofs, which are used to verify the integrity and authenticity of census data in an external system.
func New ¶
func New(origin types.CensusOrigin, seed []byte) (CSP, error)
New creates a new CredentialServiceProviders (CSP) based on the given origin. If a seed is provided, it initializes the CSP with that seed. It returns an error if the CSP cannot be created for the given origin or if the seed cannot be set.
type CSPProof ¶
type CSPProof struct {
Signature eddsa.Signature
PublicKey eddsa.PublicKey
VoterIndex frontend.Variable
}
CSPProof struct represents a proof generated by the CredentialServiceProviders to be used in the circuits. It includes the signature, public key, process ID and address as variables. The IsValid method checks if the signature is valid or not using the gnark API.
func CensusProofToCSPProof ¶
func CensusProofToCSPProof(curveID ecc_twedwards.ID, censusProof *types.CensusProof) (*CSPProof, error)
CensusProofToCSPProof converts a types.CensusProof to a CSPProof to be used in Gnark circuits. It unmarshals the public key and signature from the CensusProof and converts them to gnark circuit types.
func (*CSPProof) IsValid ¶
func (proof *CSPProof) IsValid( api frontend.API, censusRoot, processID, address, weight frontend.Variable, ) frontend.Variable
IsValid method checks if the signature is valid or not using the gnark API. It initializes the poseidon hash function, checks if the public key is valid, recomputes the message hash with the voter index, the process ID, the address and the weight, and finally checks if the signature is valid using the eddsa verifier with poseidon hash.