Documentation
¶
Index ¶
- Constants
- Variables
- func AggregateVerify(publicKeys []*PublicKey, messages [][]byte, aggSignature *Signature) (bool, error)
- func BatchVerify(publicKeys []*PublicKey, message []byte, signatures []*Signature) (bool, error)
- func BatchVerifySolidityCompatible(publicKeys []*PublicKey, messageHash [32]byte, signatures []*Signature) (bool, error)
- func GenerateKeyPair() (*PrivateKey, *PublicKey, error)
- func GenerateKeyPairFromSeed(seed []byte) (*PrivateKey, *PublicKey, error)
- func SolidityHashToG1(hash [32]byte) (*bn254.G1Affine, error)
- func ValidateFieldOrder(n *big.Int) bool
- type G1Point
- type G2Point
- type PrivateKey
- func (pk *PrivateKey) Bytes() []byte
- func (pk *PrivateKey) Public() *PublicKey
- func (pk *PrivateKey) Sign(message []byte) (*Signature, error)
- func (pk *PrivateKey) SignG1Point(hashPoint *bn254.G1Affine) (*Signature, error)
- func (pk *PrivateKey) SignSolidityCompatible(messageHash [32]byte) (*Signature, error)
- func (pk *PrivateKey) ToHex() (string, error)
- type PublicKey
- type Scheme
- func (s *Scheme) AggregateSignatures(signatures []signing.Signature) (signing.Signature, error)
- func (s *Scheme) AggregateVerify(publicKeys []signing.PublicKey, messages [][]byte, ...) (bool, error)
- func (s *Scheme) BatchVerify(publicKeys []signing.PublicKey, message []byte, signatures []signing.Signature) (bool, error)
- func (s *Scheme) GenerateKeyPair() (signing.PrivateKey, signing.PublicKey, error)
- func (s *Scheme) GenerateKeyPairEIP2333(seed []byte, path []uint32) (signing.PrivateKey, signing.PublicKey, error)
- func (s *Scheme) GenerateKeyPairFromSeed(seed []byte) (signing.PrivateKey, signing.PublicKey, error)
- func (s *Scheme) NewPrivateKeyFromBytes(data []byte) (signing.PrivateKey, error)
- func (s *Scheme) NewPrivateKeyFromHexString(hex string) (signing.PrivateKey, error)
- func (s *Scheme) NewPublicKeyFromBytes(data []byte) (signing.PublicKey, error)
- func (s *Scheme) NewPublicKeyFromHexString(hex string) (signing.PublicKey, error)
- func (s *Scheme) NewSignatureFromBytes(data []byte) (signing.Signature, error)
- type Signature
- func (s *Signature) Add(other *Signature) *Signature
- func (s *Signature) Bytes() []byte
- func (s *Signature) GetG1Point() *bn254.G1Affine
- func (s *Signature) Sub(other *Signature) *Signature
- func (s *Signature) Verify(publicKey *PublicKey, message []byte) (bool, error)
- func (s *Signature) VerifySolidityCompatible(publicKey *PublicKey, messageHash [32]byte) (bool, error)
- type SolidityBN254G1Point
- type SolidityBN254G2Point
Constants ¶
const ( G1PointSize = 64 // 32 bytes for x, 32 bytes for y G2PointSize = 128 // 64 bytes for x, 64 bytes for y )
Precompile format constants
Variables ¶
var ( ErrInvalidPointFormat = errors.New("invalid point format for precompile") ErrPointNotInSubgroup = errors.New("point not in correct subgroup") ErrInvalidFieldOrder = errors.New("number not in valid field order") )
Error types for precompile compatibility
var FieldModulus = func() *big.Int { n, _ := new(big.Int).SetString("21888242871839275222246405745257275088696311157297823662689037894645226208583", 10) return n }()
FieldModulus is the BN254 field modulus
Functions ¶
func AggregateVerify ¶
func AggregateVerify(publicKeys []*PublicKey, messages [][]byte, aggSignature *Signature) (bool, error)
AggregateVerify verifies an aggregated signature against multiple public keys and multiple messages
func BatchVerify ¶
BatchVerify verifies multiple signatures in a single batch operation
func BatchVerifySolidityCompatible ¶ added in v0.0.3
func BatchVerifySolidityCompatible(publicKeys []*PublicKey, messageHash [32]byte, signatures []*Signature) (bool, error)
BatchVerifySolidityCompatible verifies multiple signatures in a single batch operation using the Solidity-compatible hash-to-curve method
func GenerateKeyPair ¶
func GenerateKeyPair() (*PrivateKey, *PublicKey, error)
GenerateKeyPair creates a new random private key and the corresponding public key
func GenerateKeyPairFromSeed ¶
func GenerateKeyPairFromSeed(seed []byte) (*PrivateKey, *PublicKey, error)
GenerateKeyPairFromSeed creates a deterministic private key and the corresponding public key from a seed
func SolidityHashToG1 ¶ added in v0.0.3
SolidityHashToG1 implements the same hash-to-curve algorithm as the Solidity BN254 library This uses the try-and-increment method that matches BN254.hashToG1() in Solidity
func ValidateFieldOrder ¶
ValidateFieldOrder checks if a number is in the correct field
Types ¶
type G1Point ¶
func G1PointFromPrecompileFormat ¶
FromPrecompileFormat creates a G1 point from the Ethereum precompile format
func NewG1Point ¶
func NewZeroG1Point ¶
func NewZeroG1Point() *G1Point
func (*G1Point) AddPublicKey ¶
AddPublicKey adds the G1 point from a public key to this point
func (*G1Point) ToPrecompileFormat ¶
ToPrecompileFormat converts a G1 point to the format expected by the Ethereum precompile
type G2Point ¶
func G2PointFromPrecompileFormat ¶
FromPrecompileFormat creates a G2 point from the Ethereum precompile format
func NewG2Point ¶
func NewZeroG2Point ¶
func NewZeroG2Point() *G2Point
func (*G2Point) AddPublicKey ¶
AddPublicKey adds the G2 point from a public key to this point
func (*G2Point) ToPrecompileFormat ¶
ToPrecompileFormat converts a G2 point to the format expected by the Ethereum precompile
type PrivateKey ¶
type PrivateKey struct {
ScalarBytes []byte
// contains filtered or unexported fields
}
PrivateKey represents a BLS private key
func NewPrivateKeyFromBytes ¶
func NewPrivateKeyFromBytes(data []byte) (*PrivateKey, error)
NewPrivateKeyFromBytes creates a private key from bytes
func NewPrivateKeyFromHexString ¶ added in v0.0.2
func NewPrivateKeyFromHexString(hexStr string) (*PrivateKey, error)
NewPrivateKeyFromHexString creates a private key from a hex string
func (*PrivateKey) Bytes ¶
func (pk *PrivateKey) Bytes() []byte
Bytes returns the private key as a byte slice
func (*PrivateKey) Public ¶
func (pk *PrivateKey) Public() *PublicKey
Public returns the public key corresponding to the private key
func (*PrivateKey) Sign ¶
func (pk *PrivateKey) Sign(message []byte) (*Signature, error)
Sign signs a message using the private key
func (*PrivateKey) SignG1Point ¶
func (pk *PrivateKey) SignG1Point(hashPoint *bn254.G1Affine) (*Signature, error)
func (*PrivateKey) SignSolidityCompatible ¶ added in v0.0.3
func (pk *PrivateKey) SignSolidityCompatible(messageHash [32]byte) (*Signature, error)
SignSolidityCompatible signs a message hash using the Solidity-compatible hash-to-curve method
func (*PrivateKey) ToHex ¶ added in v0.0.2
func (pk *PrivateKey) ToHex() (string, error)
ToHex returns the private key as a hex string
type PublicKey ¶
type PublicKey struct {
PointBytes []byte
// contains filtered or unexported fields
}
PublicKey represents a BLS public key
func AggregatePublicKeys ¶
AggregatePublicKeys combines multiple public keys into a single aggregated public key.
func NewPublicKeyFromBytes ¶
NewPublicKeyFromBytes creates a public key from bytes
func NewPublicKeyFromSolidity ¶
func NewPublicKeyFromSolidity(g1 *SolidityBN254G1Point, g2 *SolidityBN254G2Point) (*PublicKey, error)
NewPublicKeyFromSolidity creates a public key from a Solidity G1 and G2 points
func (*PublicKey) GetG1Point ¶
GetG1Point returns the G1 point of the public key
func (*PublicKey) GetG2Point ¶
GetG2Point returns the G2 point of the public key
type Scheme ¶
type Scheme struct{}
Scheme implements the SigningScheme interface for BN254
func (*Scheme) AggregateSignatures ¶
AggregateSignatures combines multiple signatures into a single signature
func (*Scheme) AggregateVerify ¶
func (s *Scheme) AggregateVerify(publicKeys []signing.PublicKey, messages [][]byte, aggSignature signing.Signature) (bool, error)
AggregateVerify verifies an aggregated signature against multiple public keys and multiple messages
func (*Scheme) BatchVerify ¶
func (s *Scheme) BatchVerify(publicKeys []signing.PublicKey, message []byte, signatures []signing.Signature) (bool, error)
BatchVerify verifies multiple signatures in a single batch operation
func (*Scheme) GenerateKeyPair ¶
GenerateKeyPair creates a new random private key and the corresponding public key
func (*Scheme) GenerateKeyPairEIP2333 ¶
func (s *Scheme) GenerateKeyPairEIP2333(seed []byte, path []uint32) (signing.PrivateKey, signing.PublicKey, error)
GenerateKeyPairEIP2333 creates a deterministic private key and the corresponding public key using the EIP-2333 standard
func (*Scheme) GenerateKeyPairFromSeed ¶
func (s *Scheme) GenerateKeyPairFromSeed(seed []byte) (signing.PrivateKey, signing.PublicKey, error)
GenerateKeyPairFromSeed creates a deterministic private key and the corresponding public key from a seed
func (*Scheme) NewPrivateKeyFromBytes ¶
func (s *Scheme) NewPrivateKeyFromBytes(data []byte) (signing.PrivateKey, error)
NewPrivateKeyFromBytes creates a private key from bytes
func (*Scheme) NewPrivateKeyFromHexString ¶ added in v0.0.2
func (s *Scheme) NewPrivateKeyFromHexString(hex string) (signing.PrivateKey, error)
func (*Scheme) NewPublicKeyFromBytes ¶
NewPublicKeyFromBytes creates a public key from bytes
func (*Scheme) NewPublicKeyFromHexString ¶
type Signature ¶
type Signature struct {
SigBytes []byte
// contains filtered or unexported fields
}
Signature represents a BLS signature
func AggregateSignatures ¶
AggregateSignatures combines multiple signatures into a single signature
func NewSignatureFromBytes ¶
NewSignatureFromBytes creates a signature from bytes