Documentation ¶
Index ¶
- Constants
- Variables
- func CompressPubkey(pubkey *secp256k1.PublicKey) []byte
- func DecompressPubkey(pubkey []byte) (*secp256k1.PublicKey, error)
- func Ecrecover(hash, sig []byte, compress bool) ([]byte, error)
- func GenerateKey(rand io.Reader) (prv *secp256k1.PrivateKey, err error)
- func IsHexAddress(s string) bool
- 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 ToPrivateKey(d []byte) (*secp256k1.PrivateKey, error)
- func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool
- func VerifySignature(pubkey, hash, signature []byte) bool
- type ByteCode
- type CommonAddress
- func BigToAddress(b *big.Int) CommonAddress
- func BytesToAddress(b []byte) CommonAddress
- func CreateAddress(b CommonAddress, nonce uint64) CommonAddress
- func CreateAddress2(b CommonAddress, salt [32]byte, code []byte) CommonAddress
- func HexToAddress(s string) CommonAddress
- func PubkeyToAddress(p *secp256k1.PublicKey) CommonAddress
- func (a CommonAddress) Big() *big.Int
- func (a CommonAddress) Bytes() []byte
- func (a CommonAddress) Format(s fmt.State, c rune)
- func (a CommonAddress) Hash() Hash
- func (a CommonAddress) Hex() string
- func (a CommonAddress) IsEmpty() bool
- func (a CommonAddress) MarshalText() ([]byte, error)
- func (a *CommonAddress) SetBytes(b []byte)
- func (a CommonAddress) String() string
- func (a *CommonAddress) UnmarshalJSON(input []byte) error
- func (a *CommonAddress) UnmarshalText(input []byte) error
- type Hash
- func (h Hash) Big() *big.Int
- func (h Hash) Bytes() []byte
- func (hash *Hash) IsEmpty() bool
- func (hash *Hash) IsEqual(target *Hash) bool
- func (h Hash) MarshalText() ([]byte, error)
- func (h *Hash) SetBytes(b []byte)
- func (h Hash) String() string
- func (h *Hash) UnmarshalJSON(input []byte) error
- func (h *Hash) UnmarshalText(input []byte) error
Constants ¶
const ( HashLength = 32 AddressLength = 20 )
Variables ¶
var ( ErrExceedHashLength = errors.New("bytes length exceed maximum hash length of 32") ZeroAddress = CommonAddress{} ZeroHash = Hash{} )
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 IsHexAddress ¶
IsHexAddress verifies whether a string can represent a valid hex-encoded Ethereum address or not.
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 ToPrivateKey ¶
func ToPrivateKey(d []byte) (*secp256k1.PrivateKey, error)
ToECDSA creates a private key with the given D value.
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
Address represents the 20 byte address of an Ethereum account.
func BigToAddress ¶
func BigToAddress(b *big.Int) CommonAddress
BigToAddress returns Address with byte values of b. If b is larger than len(h), b will be cropped from the left.
func BytesToAddress ¶
func BytesToAddress(b []byte) CommonAddress
BytesToAddress returns Address with value b. If b is larger than len(h), b will be cropped from the left.
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 HexToAddress ¶
func HexToAddress(s string) CommonAddress
HexToAddress returns Address with byte values of s. If s is larger than len(h), s will be cropped from the left.
func PubkeyToAddress ¶
func PubkeyToAddress(p *secp256k1.PublicKey) CommonAddress
func (CommonAddress) Bytes ¶
func (a CommonAddress) Bytes() []byte
Bytes gets the string representation of the underlying address.
func (CommonAddress) Format ¶
func (a CommonAddress) Format(s fmt.State, c rune)
Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.
func (CommonAddress) Hash ¶
func (a CommonAddress) Hash() Hash
Hash converts an address to a hash by left-padding it with zeros.
func (CommonAddress) Hex ¶
func (a CommonAddress) Hex() string
Hex returns an EIP55-compliant hex string representation of the address.
func (CommonAddress) IsEmpty ¶
func (a CommonAddress) IsEmpty() bool
String implements fmt.Stringer.
func (CommonAddress) MarshalText ¶
func (a CommonAddress) MarshalText() ([]byte, error)
MarshalText returns the hex representation of a.
func (*CommonAddress) SetBytes ¶
func (a *CommonAddress) SetBytes(b []byte)
SetBytes sets the address to the value of b. If b is larger than len(a) it will panic.
func (CommonAddress) String ¶
func (a CommonAddress) String() string
String implements fmt.Stringer.
func (*CommonAddress) UnmarshalJSON ¶
func (a *CommonAddress) UnmarshalJSON(input []byte) error
UnmarshalJSON parses a hash in hex syntax.
func (*CommonAddress) UnmarshalText ¶
func (a *CommonAddress) UnmarshalText(input []byte) error
UnmarshalText parses a hash in hex syntax.
type Hash ¶
type Hash [HashLength]byte
func BigToHash ¶
BigToHash sets byte representation of b to hash. If b is larger than len(h), b will be cropped from the left.
func Bytes2Hash ¶
func BytesToHash ¶
BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.
func GetByteCodeHash ¶
func HexToHash ¶
HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.
func Keccak256Hash ¶
Keccak256Hash calculates and returns the Keccak256 hash of the input data, converting it to an internal Hash data structure.
func RandomHash ¶
func RandomHash() Hash
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 secp256k1 implements support for the elliptic curves needed for decred.
|
Package secp256k1 implements support for the elliptic curves needed for decred. |
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. |