Documentation
¶
Index ¶
- func DecompressPublicKey(pubKey types.HexBytes) (*babyjub.PublicKey, error)
- func DecompressSignature(signature types.HexBytes) (*babyjub.Signature, error)
- func DefaultCSPIndexFn(processID types.ProcessID, address common.Address, weight *types.BigInt) uint64
- type BabyJubJubEdDSA
- func (c *BabyJubJubEdDSA) CensusOrigin() types.CensusOrigin
- func (c *BabyJubJubEdDSA) CensusRoot() *types.CensusRoot
- func (c *BabyJubJubEdDSA) GenerateProof(processID types.ProcessID, address common.Address, weight *types.BigInt) (*types.CensusProof, error)
- func (c *BabyJubJubEdDSA) PublicKey() (CompressedBytes, error)
- func (c *BabyJubJubEdDSA) SetIndexFn(indexFn types.CSPIndexFn)
- func (c *BabyJubJubEdDSA) VerifyProof(proof *types.CensusProof) error
- type CompressedBytes
- type Hash
- type Poseidon
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecompressPublicKey ¶ added in v0.0.2
DecompressPublicKey method returns the decompressed bytes from a Iden3 babyjubjub public key.
func DecompressSignature ¶ added in v0.0.2
DecompressSignature method returns the decompressed bytes from a Iden3 babyjubjub signature.
func DefaultCSPIndexFn ¶ added in v0.0.2
func DefaultCSPIndexFn(processID types.ProcessID, address common.Address, weight *types.BigInt) uint64
DefaultCSPIndexFn is the default function to compute the VoterIndex for a given process ID, address and weight. It uses the poseidon hash function to compute a deterministic index based on the inputs. It ensures that the result is in the VoterIndex range [0, params.VoterIndexMax].
Types ¶
type BabyJubJubEdDSA ¶ added in v0.0.2
type BabyJubJubEdDSA struct {
// contains filtered or unexported fields
}
BabyJubJubEdDSA struct implements the CSP interface for the BabyJubJubEdDSA over multiple curves.
func NewBabyJubJubKey ¶ added in v0.0.2
func NewBabyJubJubKey(hashFn Hash) (*BabyJubJubEdDSA, error)
NewBabyJubJubKey creates a new random BabyJubJubEdDSA for the bn254 curve using the hash function provided. It implements the CSP interface and can be used to generate and verify proofs for voters. If something goes wrong during the key generation, it returns an error.
func NewBabyJubJubKeyFromSeed ¶ added in v0.0.2
func NewBabyJubJubKeyFromSeed(hashFn Hash, seed []byte) (*BabyJubJubEdDSA, error)
NewBabyJubJubKeyFromSeed creates a new BabyJubJubEdDSA for the bn254 curve using the hash function provided and the provided seed. It implements the CSP interface and can be used to generate and verify proofs for voters. If something goes wrong during the key generation, it returns an error.
func (*BabyJubJubEdDSA) CensusOrigin ¶ added in v0.0.2
func (c *BabyJubJubEdDSA) CensusOrigin() types.CensusOrigin
CensusOrigin returns the origin of the credential service providers. It returns the type of the CSP, which is EdDSA in this case.
func (*BabyJubJubEdDSA) CensusRoot ¶ added in v0.0.2
func (c *BabyJubJubEdDSA) CensusRoot() *types.CensusRoot
CensusRoot returns the census root computed from the public key of the EdDSA instance. It uses the X and Y coordinates of the public key's point to compute the hash. If the EdDSA signer is not initialized or the public key can not be converted to censusRoot for the instance curve, it returns nil.
func (*BabyJubJubEdDSA) GenerateProof ¶ added in v0.0.2
func (c *BabyJubJubEdDSA) GenerateProof( processID types.ProcessID, address common.Address, weight *types.BigInt, ) (*types.CensusProof, error)
GenerateProof generates a census proof for the given process ID and address. It signs the message composed by the process ID and address using the private key of the CredentialServiceProviders. It returns a CensusProof struct that includes the hash of the public key as the root, the public key, the signature and the signed address and process ID. It returns an error if the EdDSA signer is not initialized, the process ID or address provided are not valid, or something fails during signature process.
func (*BabyJubJubEdDSA) PublicKey ¶ added in v0.0.2
func (c *BabyJubJubEdDSA) PublicKey() (CompressedBytes, error)
PublicKey returns the public key of the EdDSA instance. It returns the public key as a hex bytes.
func (*BabyJubJubEdDSA) SetIndexFn ¶ added in v0.0.2
func (c *BabyJubJubEdDSA) SetIndexFn(indexFn types.CSPIndexFn)
SetIndexFn sets the index function for the BabyJubJubEdDSA instance.
func (*BabyJubJubEdDSA) VerifyProof ¶ added in v0.0.2
func (c *BabyJubJubEdDSA) VerifyProof(proof *types.CensusProof) error
VerifyProof method verifies the proof provided for the current EdDSA curve. It also verifies that the census origin of the proof matches with the EdDSA instance one. It returns an error if the proof provided is nil, the census origins do not match or something fails during signature verification process.
type CompressedBytes ¶ added in v0.0.2
type CompressedBytes []byte
CompressedBytes represents the compressed bytes resulting of babyjubjub compress and marshal texts from public keys and signatures.
func CompressSignature ¶ added in v0.0.2
func CompressSignature(sig *babyjub.Signature) (CompressedBytes, error)
CompressSignature method returns the compressed bytes from a signature.
func CompressedPublicKey ¶ added in v0.0.2
func CompressedPublicKey(pubKey *babyjub.PublicKey) (CompressedBytes, error)
CompressedPublicKey method returns the compressed bytes from Iden3 babyjubjub public key.
func (CompressedBytes) Bytes ¶ added in v0.0.2
func (c CompressedBytes) Bytes() types.HexBytes
Bytes method returns the underlying byte slice of the CompressedBytes.
func (CompressedBytes) Decompress ¶ added in v0.0.2
func (c CompressedBytes) Decompress() (types.HexBytes, error)
Decompress method returns the decompressed bytes from compressed bytes. It revert the process of Compress method, by converting the compressed bytes into a big int string and then into a slice of bytes.
func (CompressedBytes) SetBytes ¶ added in v0.0.2
func (c CompressedBytes) SetBytes(b types.HexBytes) (CompressedBytes, error)
SetBytes method sets the resulting bytes of MarshalText and Compress functions from public keys and signatures of Iden3 Babyjubjub crypto.
func (CompressedBytes) SetCompressed ¶ added in v0.0.2
func (c CompressedBytes) SetCompressed(b types.HexBytes) (CompressedBytes, error)
SetCompressed method sets the resulting bytes of MarshalText and Compress functions from public keys and signatures of Iden3 Babyjubjub crypto. These bytes are slices of bytes of big numbers decimal strings. This method convert that bytes into a real hex bytes.
type Hash ¶ added in v0.0.2
Hash is an interface for a hash function that can be used by the BabyJubJubEdDSA.
var DefaultHashFn Hash
DefaultHashFn is the default hash function used by the BabyJubJubEdDSA
func NewPoseidon ¶ added in v0.0.2
NewPoseidon returns a new Poseidon extended hash function.
type Poseidon ¶ added in v0.0.2
type Poseidon struct {
// contains filtered or unexported fields
}
Poseidon is a hash function based on the Poseidon hash algorithm, it wraps the iden3-crypto implementation to conform the Hash interface (hash.Hash extended with the BigIntsSum method for BigInts).
func (*Poseidon) BigIntsSum ¶ added in v0.0.2
BigIntsSum method implements the additional method for the Hash interface that wraps the iden3-crypto Poseidon hasher for computing the Poseidon hash for a list of big integers.
func (*Poseidon) BlockSize ¶ added in v0.0.2
BlockSize method implements the hash.Hash interface. It wraps the iden3-crypto Poseidon hasher BlockSize method.
func (*Poseidon) Reset ¶ added in v0.0.2
func (p *Poseidon) Reset()
Reset method implements the hash.Hash interface. It wraps the iden3-crypto Poseidon hasher Reset method.
func (*Poseidon) Size ¶ added in v0.0.2
Size method implements the hash.Hash interface. It wraps the iden3-crypto Poseidon hasher Size method.