Documentation
¶
Index ¶
- Constants
- Variables
- func IsZero(sKey []byte) bool
- func Sort(hashes [][]byte, nonce uint64)
- func SortCandidates(candidates []string, epochNum uint64, cryptoSeed []byte)
- func UpdatePrivateKeyPasswordToPem(fileName string, oldPwd string, newPwd string) error
- func WritePrivateKeyToPem(file string, key *P256sm2PrvKey, pwd string) error
- func WritePublicKeyToPem(file string, key *P256sm2PubKey, pwd string) error
- type BLS12381PrivateKey
- type BLS12381PublicKey
- type BLSAggregateSignature
- type Merkle
- type P256sm2PrvKey
- func (k *P256sm2PrvKey) Bytes() []byte
- func (k *P256sm2PrvKey) D() []byte
- func (k *P256sm2PrvKey) EcdsaPrivateKey() interface{}
- func (k *P256sm2PrvKey) HexString() string
- func (k *P256sm2PrvKey) PublicKey() PublicKey
- func (k *P256sm2PrvKey) Sign(hash []byte) ([]byte, error)
- func (k *P256sm2PrvKey) Zero()
- type P256sm2PubKey
- type PrivateKey
- func BytesToPrivateKey(prvKey []byte) (PrivateKey, error)
- func GenerateKey() (PrivateKey, error)
- func GenerateKeySm2() (PrivateKey, error)
- func HexStringToPrivateKey(prvKey string) (PrivateKey, error)
- func KeystoreToPrivateKey(account accounts.Account, password string) (PrivateKey, error)
- func ReadPrivateKeyFromPem(file string, pwd string) (PrivateKey, error)
- type PublicKey
Constants ¶
const ( // BLSSecretKeyLength is the length of a BLS secret key in bytes BLSSecretKeyLength = 32 // BLSPubkeyLength is the length of a BLS public key in bytes BLSPubkeyLength = 48 // BLSAggregateSignatureLength is the length of a BLS aggregate signature in bytes BLSAggregateSignatureLength = 96 )
const ( // 64-byte (r, s) format Secp256k1SigSize = 64 // 65-byte (r, s, v) format, where v is the recovery id Secp256k1SigSizeWithRecID = 65 )
const
Variables ¶
var ( // ErrInvalidKey is the error that the key format is invalid ErrInvalidKey = errors.New("invalid key format") // ErrPublicKey indicates the error of public key ErrPublicKey = errors.New("invalid public key") // ErrPrivateKey indicates the error of private key ErrPrivateKey = errors.New("invalid private key") // ErrSignature indicates the error of signature ErrSignature = errors.New("invalid signature") )
var ( // CryptoSeed is a hardcoded seed that will be replaced by a seed produced dynamically. CryptoSeed = []byte{0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef} )
Functions ¶
func Sort ¶ added in v0.1.1
Sort sorts a given slices of hashes cryptographically using hash function
func SortCandidates ¶ added in v0.1.1
SortCandidates sorts a given slices of hashes cryptographically using hash function
func UpdatePrivateKeyPasswordToPem ¶ added in v0.1.2
UpdatePrivateKeyPasswordToPem updates private key's password for PEM file
func WritePrivateKeyToPem ¶ added in v0.1.2
func WritePrivateKeyToPem(file string, key *P256sm2PrvKey, pwd string) error
WritePrivateKeyToPem writes the private key to PEM file
func WritePublicKeyToPem ¶ added in v0.1.2
func WritePublicKeyToPem(file string, key *P256sm2PubKey, pwd string) error
WritePublicKeyToPem writes the public key to PEM file
Types ¶
type BLS12381PrivateKey ¶ added in v0.1.16
type BLS12381PrivateKey struct {
// contains filtered or unexported fields
}
BLS12381PrivateKey represents a BLS12381 private key
func BLS12381PrivateKeyFromBytes ¶ added in v0.1.16
func BLS12381PrivateKeyFromBytes(b []byte) (*BLS12381PrivateKey, error)
BLS12381PrivateKeyFromBytes creates a BLS12381 private key from the given byte slice.
func GenerateBLS12381PrivateKey ¶ added in v0.1.16
func GenerateBLS12381PrivateKey(ikm []byte) (*BLS12381PrivateKey, error)
GenerateBLS12381PrivateKey generates a new BLS12381 private key from the given input key material (ikm).
func (*BLS12381PrivateKey) Bytes ¶ added in v0.1.16
func (k *BLS12381PrivateKey) Bytes() []byte
Bytes returns the byte representation of the BLS12381 private key.
func (*BLS12381PrivateKey) HexString ¶ added in v0.1.16
func (k *BLS12381PrivateKey) HexString() string
HexString returns the hexadecimal string representation of the BLS12381 private key.
func (*BLS12381PrivateKey) PublicKey ¶ added in v0.1.16
func (k *BLS12381PrivateKey) PublicKey() *BLS12381PublicKey
PublicKey returns the public key corresponding to the BLS12381 private key.
func (*BLS12381PrivateKey) Sign ¶ added in v0.1.16
func (k *BLS12381PrivateKey) Sign(msg []byte) ([]byte, error)
Sign signs the given message using the BLS12381 private key.
func (*BLS12381PrivateKey) Zero ¶ added in v0.1.16
func (k *BLS12381PrivateKey) Zero()
Zero clears the BLS12381 private key, effectively zeroizing it.
type BLS12381PublicKey ¶ added in v0.1.16
type BLS12381PublicKey struct {
// contains filtered or unexported fields
}
BLS12381PublicKey represents a BLS12381 public key
func BLS12381PublicKeyFromBytes ¶ added in v0.1.16
func BLS12381PublicKeyFromBytes(b []byte) (*BLS12381PublicKey, error)
BLS12381PublicKeyFromBytes creates a BLS12381 public key from the given byte slice.
func (*BLS12381PublicKey) Bytes ¶ added in v0.1.16
func (k *BLS12381PublicKey) Bytes() []byte
Bytes returns the byte representation of the BLS12381 public key.
func (*BLS12381PublicKey) HexString ¶ added in v0.1.16
func (k *BLS12381PublicKey) HexString() string
HexString returns the hexadecimal string representation of the BLS12381 public key.
type BLSAggregateSignature ¶ added in v0.1.16
type BLSAggregateSignature struct {
// contains filtered or unexported fields
}
BLSAggregateSignature represents an aggregated BLS signature
func BLSAggregateSignatureFromBytes ¶ added in v0.1.16
func BLSAggregateSignatureFromBytes(b []byte) (*BLSAggregateSignature, error)
BLSAggregateSignatureFromBytes creates a BLS aggregate signature from the given byte slice.
func NewBLSAggregateSignature ¶ added in v0.1.16
func NewBLSAggregateSignature(sigs [][]byte) (*BLSAggregateSignature, error)
NewBLSAggregateSignature aggregates multiple BLS signatures into a single signature.
func (*BLSAggregateSignature) Bytes ¶ added in v0.1.16
func (s *BLSAggregateSignature) Bytes() []byte
Bytes returns the byte representation of the BLS aggregate signature.
func (*BLSAggregateSignature) HexString ¶ added in v0.1.16
func (s *BLSAggregateSignature) HexString() string
HexString returns the hexadecimal string representation of the BLS aggregate signature.
func (*BLSAggregateSignature) Verify ¶ added in v0.1.16
func (s *BLSAggregateSignature) Verify(pubKeys []*BLS12381PublicKey, msg []byte) bool
Verify verifies the aggregate signature against the given public keys and message.
type Merkle ¶ added in v0.1.1
type Merkle struct {
// contains filtered or unexported fields
}
Merkle tree struct
func NewMerkleTree ¶ added in v0.1.1
NewMerkleTree creates a merkle tree given hashed leaves
type P256sm2PrvKey ¶ added in v0.1.2
type P256sm2PrvKey struct {
*sm2.PrivateKey
}
P256sm2PrvKey implements the P256sm2 private key
func (*P256sm2PrvKey) Bytes ¶ added in v0.1.2
func (k *P256sm2PrvKey) Bytes() []byte
Bytes returns the private key in bytes representation
func (*P256sm2PrvKey) D ¶ added in v0.1.2
func (k *P256sm2PrvKey) D() []byte
D returns the secret D in big-endian
func (*P256sm2PrvKey) EcdsaPrivateKey ¶ added in v0.1.2
func (k *P256sm2PrvKey) EcdsaPrivateKey() interface{}
EcdsaPrivateKey returns the embedded ecdsa private key
func (*P256sm2PrvKey) HexString ¶ added in v0.1.2
func (k *P256sm2PrvKey) HexString() string
HexString returns the private key in hex string
func (*P256sm2PrvKey) PublicKey ¶ added in v0.1.2
func (k *P256sm2PrvKey) PublicKey() PublicKey
PublicKey returns the public key corresponding to private key
func (*P256sm2PrvKey) Sign ¶ added in v0.1.2
func (k *P256sm2PrvKey) Sign(hash []byte) ([]byte, error)
Sign signs the message/hash
func (*P256sm2PrvKey) Zero ¶ added in v0.1.2
func (k *P256sm2PrvKey) Zero()
Zero zeroes the private key data
type P256sm2PubKey ¶ added in v0.1.2
P256sm2PubKey implements the P256sm2 public key
func (*P256sm2PubKey) Address ¶ added in v0.1.5
func (k *P256sm2PubKey) Address() address.Address
Address returns the address object
func (*P256sm2PubKey) Bytes ¶ added in v0.1.2
func (k *P256sm2PubKey) Bytes() []byte
Bytes returns the public key in bytes representation
func (*P256sm2PubKey) EcdsaPublicKey ¶ added in v0.1.2
func (k *P256sm2PubKey) EcdsaPublicKey() interface{}
EcdsaPublicKey returns the embedded ecdsa publick key
func (*P256sm2PubKey) Hash ¶ added in v0.1.2
func (k *P256sm2PubKey) Hash() []byte
Hash is the last 20-byte of keccak hash of public key (X, Y) co-ordinate
func (*P256sm2PubKey) HexString ¶ added in v0.1.2
func (k *P256sm2PubKey) HexString() string
HexString returns the public key in hex string
func (*P256sm2PubKey) Verify ¶ added in v0.1.2
func (k *P256sm2PubKey) Verify(hash, sig []byte) bool
Verify verifies the signature
type PrivateKey ¶
type PrivateKey interface {
Bytes() []byte
HexString() string
EcdsaPrivateKey() interface{}
PublicKey() PublicKey
Sign([]byte) ([]byte, error)
Zero()
}
PrivateKey represents a private key
func BytesToPrivateKey ¶
func BytesToPrivateKey(prvKey []byte) (PrivateKey, error)
BytesToPrivateKey converts a byte slice to SECP256K1 PrivateKey
func GenerateKey ¶
func GenerateKey() (PrivateKey, error)
GenerateKey generates a SECP256k1 PrivateKey
func GenerateKeySm2 ¶ added in v0.1.2
func GenerateKeySm2() (PrivateKey, error)
GenerateKeySm2 generates a P256sm2 PrivateKey
func HexStringToPrivateKey ¶
func HexStringToPrivateKey(prvKey string) (PrivateKey, error)
HexStringToPrivateKey decodes a string to PrivateKey
func KeystoreToPrivateKey ¶
func KeystoreToPrivateKey(account accounts.Account, password string) (PrivateKey, error)
KeystoreToPrivateKey generates PrivateKey from Keystore account
func ReadPrivateKeyFromPem ¶ added in v0.1.2
func ReadPrivateKeyFromPem(file string, pwd string) (PrivateKey, error)
ReadPrivateKeyFromPem reads the private key from PEM file
type PublicKey ¶
type PublicKey interface {
Bytes() []byte
HexString() string
EcdsaPublicKey() interface{}
Hash() []byte
Verify([]byte, []byte) bool
Address() address.Address
}
PublicKey represents a public key
func BytesToPublicKey ¶
BytesToPublicKey converts a byte slice to SECP256K1 PublicKey
func HexStringToPublicKey ¶
HexStringToPublicKey decodes a string to PublicKey
func ReadPublicKeyFromPem ¶ added in v0.1.2
ReadPublicKeyFromPem reads the public key from PEM file
func RecoverPubkey ¶ added in v0.1.2
RecoverPubkey recovers the public key from signature