Documentation
¶
Index ¶
- Constants
- Variables
- func AutonityPOPProof(nodeKey, oracleKey *ecdsa.PrivateKey, treasuryHex string, ...) ([]byte, error)
- func BLSPOPProof(priKey blst.SecretKey, treasury []byte) ([]byte, error)
- func BLSPOPVerify(pubKey blst.PublicKey, sig blst.Signature, treasury []byte) error
- func CompressPubkey(pubkey *ecdsa.PublicKey) []byte
- func CreateAddress(b common.Address, nonce uint64) common.Address
- func CreateAddress2(b common.Address, salt [32]byte, inithash []byte) common.Address
- func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error)
- func Ecrecover(hash, sig []byte) ([]byte, error)
- func FromECDSA(priv *ecdsa.PrivateKey) []byte
- func FromECDSAPub(pub *ecdsa.PublicKey) []byte
- func GenAutonityKeys() (*ecdsa.PrivateKey, blst.SecretKey, error)
- func GenerateKey() (*ecdsa.PrivateKey, error)
- func Hash(data []byte) common.Hash
- func HashData(kh KeccakState, data []byte) (h common.Hash)
- func HashFromReader(payload *bytes.Reader) (common.Hash, error)
- func HexToAutonityKeys(hexKeys string) (*ecdsa.PrivateKey, blst.SecretKey, error)
- func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)
- func Keccak256(data ...[]byte) []byte
- func Keccak256Hash(data ...[]byte) (h common.Hash)
- func Keccak512(data ...[]byte) []byte
- func LoadAutonityKeys(file string) (*ecdsa.PrivateKey, blst.SecretKey, error)
- func LoadECDSA(file string) (*ecdsa.PrivateKey, error)
- func POPMsgHash(msg []byte) common.Hash
- func PrivECDSAFromHex(k []byte) (*ecdsa.PrivateKey, error)
- func PrivECDSAToHex(k *ecdsa.PrivateKey) []byte
- func PubECDSAToHex(k *ecdsa.PublicKey) []byte
- func PubkeyToAddress(p ecdsa.PublicKey) common.Address
- func S256() elliptic.Curve
- func SaveAutonityKeys(file string, ecdsaKey *ecdsa.PrivateKey, consensusKey blst.SecretKey) error
- func SaveECDSA(file string, key *ecdsa.PrivateKey) error
- func SigToAddr(hash, sig []byte) (common.Address, error)
- func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error)
- func Sign(digestHash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error)
- func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)
- func ToECDSAUnsafe(d []byte) *ecdsa.PrivateKey
- func UnmarshalPubkey(pub []byte) (*ecdsa.PublicKey, error)
- func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool
- func VerifySignature(pubkey, digestHash, signature []byte) bool
- type KeccakState
Constants ¶
const AutonityKeysLen = ECDSAKeyLen + blst.BLSSecretKeyLength
const AutonityKeysLenInChar = AutonityKeysLen * 2
const AutonityPOPLen = 2*SignatureLength + blst.BLSSignatureLength
const DigestLength = 32
DigestLength sets the signature digest exact length
const ECDSAKeyLen = 32
const ECDSAKeyLenInChar = ECDSAKeyLen * 2
const RecoveryIDOffset = 64
RecoveryIDOffset points to the byte offset within the signature that contains the recovery id.
const SignatureLength = 64 + 1 // 64 bytes ECDSA signature + 1 byte recovery id
SignatureLength indicates the byte length required to carry a signature with recovery id.
Variables ¶
var ( ErrorInvalidPOP = errors.New("invalid Autonity POP") ErrorInvalidSigner = errors.New("mismatched Autonity POP signer") )
Functions ¶
func AutonityPOPProof ¶ added in v1.1.1
func BLSPOPProof ¶ added in v1.1.1
BLSPOPProof generate POP of BLS private key of Autonity protocol, the hash input start with a prefix of treasury address and ended with the public key of the secrete key, since we don't want the POP being cloned during the propagation of the on-boarding TX. Thus, this POP generation is different from the spec of BLS, which means we have a compatibility issue with a standard POP generation/verification implementation.
func BLSPOPVerify ¶ added in v1.1.1
BLSPOPVerify verifies the POP provided by an on-boarding validator, it assumes the public key and signature was checked with infinite and group.
func CompressPubkey ¶
CompressPubkey encodes a public key to the 33-byte compressed format.
func CreateAddress ¶
CreateAddress creates an ethereum address given the bytes and the nonce
func CreateAddress2 ¶
CreateAddress2 creates an ethereum address given the address bytes, initial contract code hash and a salt.
func DecompressPubkey ¶
DecompressPubkey parses a public key in the 33-byte compressed format.
func FromECDSA ¶
func FromECDSA(priv *ecdsa.PrivateKey) []byte
FromECDSA exports a private key into a binary dump.
func FromECDSAPub ¶
func GenAutonityKeys ¶ added in v1.1.1
func GenAutonityKeys() (*ecdsa.PrivateKey, blst.SecretKey, error)
func GenerateKey ¶
func GenerateKey() (*ecdsa.PrivateKey, error)
GenerateKey generates a new private key.
func Hash ¶ added in v1.1.1
Note!: All the functions use by AutonityPOPProof and AutonityPOPVerify should be deterministic, and should be backward compatible since it is used by precompiled contract for on-boarding validators of the whole lifecycle of a blockchain.
func HashData ¶ added in v1.1.1
func HashData(kh KeccakState, data []byte) (h common.Hash)
HashData hashes the provided data using the KeccakState and returns a 32 byte hash
func HashFromReader ¶ added in v1.1.1
func HexToAutonityKeys ¶ added in v1.1.1
HexToAutonityKeys parse the hex string into a secp256k1 private key and a BLS private key.
func HexToECDSA ¶
func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)
HexToECDSA parses a secp256k1 private key.
func Keccak256Hash ¶
Keccak256Hash calculates and returns the Keccak256 hash of the input data, converting it to an internal Hash data structure.
func LoadAutonityKeys ¶ added in v1.1.1
LoadAutonityKeys loads a secp256k1 private key and a consensus private key from the given file.
func LoadECDSA ¶
func LoadECDSA(file string) (*ecdsa.PrivateKey, error)
LoadECDSA loads a secp256k1 private key from the given file.
func POPMsgHash ¶ added in v1.1.1
func PrivECDSAFromHex ¶ added in v1.1.1
func PrivECDSAFromHex(k []byte) (*ecdsa.PrivateKey, error)
func PrivECDSAToHex ¶ added in v1.1.1
func PrivECDSAToHex(k *ecdsa.PrivateKey) []byte
func PubECDSAToHex ¶ added in v1.1.1
func SaveAutonityKeys ¶ added in v1.1.1
SaveAutonityKeys saves a secp256k1 private key and the consensus key to the given file with restrictive permissions. The key data is saved hex-encoded.
func SaveECDSA ¶
func SaveECDSA(file string, key *ecdsa.PrivateKey) error
SaveECDSA saves a secp256k1 private key to the given file with restrictive permissions. The key data is saved hex-encoded.
func SigToAddr ¶ added in v1.1.1
SigToAddr returns the address associated to the public key that created the signature.
func Sign ¶
func Sign(digestHash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error)
Sign calculates an ECDSA signature.
This function is susceptible to chosen plaintext attacks that can leak information about the private key that is used for signing. Callers must be aware that the given digest cannot be chosen by an adversery. Common solution is to hash any input before calculating the signature.
The produced signature is in the [R || S || V] format where V is 0 or 1.
func ToECDSA ¶
func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)
ToECDSA creates a private key with the given D value.
func ToECDSAUnsafe ¶
func ToECDSAUnsafe(d []byte) *ecdsa.PrivateKey
ToECDSAUnsafe blindly converts a binary blob to a private key. It should almost never be used unless you are sure the input is valid and want to avoid hitting errors due to bad origin encoding (0 prefixes cut off).
func UnmarshalPubkey ¶
UnmarshalPubkey converts bytes to a secp256k1 public key.
func ValidateSignatureValues ¶
ValidateSignatureValues verifies whether the signature values are valid with the given chain rules. The v value is assumed to be either 0 or 1.
func VerifySignature ¶
VerifySignature checks that the given public key created signature over digest. The public key should be in compressed (33 bytes) or uncompressed (65 bytes) format. The signature should have the 64 byte [R || S] format.
Types ¶
type KeccakState ¶ added in v1.1.1
KeccakState wraps sha3.state. In addition to the usual hash methods, it also supports Read to get a variable amount of data from the hash state. Read is faster than Sum because it doesn't copy the internal state, but also modifies the internal state.
func NewKeccakState ¶ added in v1.1.1
func NewKeccakState() KeccakState
NewKeccakState creates a new KeccakState
Directories
¶
| Path | Synopsis |
|---|---|
|
Package blake2b implements the BLAKE2b hash algorithm defined by RFC 7693 and the extendable output function (XOF) BLAKE2Xb.
|
Package blake2b implements the BLAKE2b hash algorithm defined by RFC 7693 and the extendable output function (XOF) BLAKE2Xb. |
|
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
|
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve. |
|
cloudflare
Package bn256 implements a particular bilinear group at the 128-bit security level.
|
Package bn256 implements a particular bilinear group at the 128-bit security level. |
|
google
Package bn256 implements a particular bilinear group.
|
Package bn256 implements a particular bilinear group. |
|
Package secp256k1 wraps the bitcoin secp256k1 C library.
|
Package secp256k1 wraps the bitcoin secp256k1 C library. |