Documentation ¶
Index ¶
- Constants
- Variables
- 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 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 ( // 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") )
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 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