Documentation ¶
Index ¶
- Constants
- Variables
- func CompressPubkey(pubkey *secp256k1.PublicKey) []byte
- func DecompressPubkey(pubkey []byte) (*secp256k1.PublicKey, error)
- func Ecrecover(hash, sig []byte) ([]byte, error)
- func GenerateKey(rand io.Reader) (prv *secp256k1.PrivateKey, err error)
- func Keccak256(data ...[]byte) []byte
- func LoadECDSA(file string) (*secp256k1.PrivateKey, error)
- func SaveECDSA(file string, key *secp256k1.PrivateKey) error
- func SigToPub(hash, sig []byte) (*secp256k1.PublicKey, error)
- func Sign(hash []byte, prv *secp256k1.PrivateKey) ([]byte, error)
- func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool
- func VerifySignature(pubkey, hash, signature []byte) bool
- type ByteCode
- type CommonAddress
- func Big2Address(x *big.Int) CommonAddress
- func Bytes2Address(b []byte) CommonAddress
- func CreateAddress(b CommonAddress, nonce uint64) CommonAddress
- func CreateAddress2(b CommonAddress, salt [32]byte, code []byte) CommonAddress
- func GetByteCodeAddress(callerAddr CommonAddress, nonce int64) CommonAddress
- func Hex2Address(s string) CommonAddress
- func PubKey2Address(pubKey *secp256k1.PublicKey) CommonAddress
- func PubkeyToAddress(p *secp256k1.PublicKey) CommonAddress
- func (addr CommonAddress) Big() *big.Int
- func (addr CommonAddress) Bytes() []byte
- func (addr CommonAddress) Hex() string
- func (addr CommonAddress) IsEmpty() bool
- func (addr CommonAddress) MarshalText() ([]byte, error)
- func (addr *CommonAddress) SetBytes(b []byte)
- func (addr *CommonAddress) UnmarshalJSON(input []byte) error
- func (addr CommonAddress) UnmarshalText(input []byte) error
- type Hash
Constants ¶
const ( HashLength = 32 AddressLength = 20 )
Variables ¶
var (
ErrExceedHashLength = errors.New("bytes length exceed maximum hash length of 32")
)
Functions ¶
func CompressPubkey ¶
CompressPubkey encodes a public key to the 33-byte compressed format.
func DecompressPubkey ¶
DecompressPubkey parses a public key in the 33-byte compressed format.
func GenerateKey ¶
func GenerateKey(rand io.Reader) (prv *secp256k1.PrivateKey, err error)
Generate an elliptic curve public / private keypair. If params is nil, the recommended default parameters for the key will be chosen.
func LoadECDSA ¶
func LoadECDSA(file string) (*secp256k1.PrivateKey, error)
LoadECDSA loads a secp256k1 private key from the given file.
func SaveECDSA ¶
func SaveECDSA(file string, key *secp256k1.PrivateKey) error
SaveECDSA saves a secp256k1 private key to the given file with restrictive permissions. The key data is saved hex-encoded.
func Sign ¶
func Sign(hash []byte, prv *secp256k1.PrivateKey) ([]byte, 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 hash 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 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 hash. 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 CommonAddress ¶
type CommonAddress [AddressLength]byte
func Big2Address ¶
func Big2Address(x *big.Int) CommonAddress
func Bytes2Address ¶
func Bytes2Address(b []byte) CommonAddress
func CreateAddress ¶
func CreateAddress(b CommonAddress, nonce uint64) CommonAddress
CreateAddress creates an ethereum address given the bytes and the nonce
func CreateAddress2 ¶
func CreateAddress2(b CommonAddress, salt [32]byte, code []byte) CommonAddress
CreateAddress2 creates an ethereum address given the address bytes, initial contract code and a salt.
func GetByteCodeAddress ¶
func GetByteCodeAddress(callerAddr CommonAddress, nonce int64) CommonAddress
func Hex2Address ¶
func Hex2Address(s string) CommonAddress
func PubKey2Address ¶
func PubKey2Address(pubKey *secp256k1.PublicKey) CommonAddress
func PubkeyToAddress ¶
func PubkeyToAddress(p *secp256k1.PublicKey) CommonAddress
func (CommonAddress) Big ¶
func (addr CommonAddress) Big() *big.Int
func (CommonAddress) Bytes ¶
func (addr CommonAddress) Bytes() []byte
func (CommonAddress) Hex ¶
func (addr CommonAddress) Hex() string
func (CommonAddress) IsEmpty ¶
func (addr CommonAddress) IsEmpty() bool
func (CommonAddress) MarshalText ¶
func (addr CommonAddress) MarshalText() ([]byte, error)
MarshalText returns the hex representation of a.
func (*CommonAddress) SetBytes ¶
func (addr *CommonAddress) SetBytes(b []byte)
func (*CommonAddress) UnmarshalJSON ¶
func (addr *CommonAddress) UnmarshalJSON(input []byte) error
UnmarshalJSON parses a hash in hex syntax.
func (CommonAddress) UnmarshalText ¶
func (addr CommonAddress) UnmarshalText(input []byte) error
UnmarshalText parses a hash in hex syntax.
type Hash ¶
type Hash [HashLength]byte
func Bytes2Hash ¶
func GetByteCodeHash ¶
func Keccak256Hash ¶
Keccak256Hash calculates and returns the Keccak256 hash of the input data, converting it to an internal Hash data structure.
func (Hash) MarshalText ¶
MarshalText returns the hex representation of h.
func (*Hash) UnmarshalJSON ¶
UnmarshalJSON parses a hash in hex syntax.
func (*Hash) UnmarshalText ¶
UnmarshalText parses a hash in hex syntax.
Directories ¶
Path | Synopsis |
---|---|
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 sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
|
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202. |