Documentation ¶
Index ¶
- Constants
- Variables
- func CompressPubkey(pubkey *ecdsa.PublicKey) []byte
- 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 GenerateKey() (*ecdsa.PrivateKey, error)
- func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)
- func Keccak256(data ...[]byte) []byte
- func LoadECDSA(file string) (*ecdsa.PrivateKey, error)
- func New(opt crypto.KeyType) (crypto.PrivateKey, error)
- func NewWithCryptoKey(priv *ecdsa.PrivateKey) (crypto.PrivateKey, error)
- func PaddedBigBytes(bigint *big.Int, n int) []byte
- func ReadBits(bigint *big.Int, buf []byte)
- func RecoverPlain(hash []byte, R, S, Vb *big.Int, homestead bool) ([]byte, error)
- func S256() elliptic.Curve
- func SaveECDSA(file string, key *ecdsa.PrivateKey) 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 Unmarshal(data []byte) (crypto.PrivateKey, error)
- func UnmarshalPubkey(pub []byte) (*ecdsa.PublicKey, error)
- func UnmarshalPublicKey(data []byte, opt crypto.KeyType) (crypto.PublicKey, error)
- func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool
- func VerifySignature(pubkey, digestHash, signature []byte) bool
- type KeccakState
- type PrivateKey
- type PublicKey
- type Sig
Constants ¶
const ( //SignatureLength indicates the byte length required to carry a signature with recovery id. SignatureLength = 64 + 1 // 64 bytes ECDSA signature + 1 byte recovery id // RecoveryIDOffset points to the byte offset within the signature that contains the recovery id. RecoveryIDOffset = 64 // DigestLength sets the signature digest exact length DigestLength = 32 )
Variables ¶
var (
Big1 = big.NewInt(1)
)
Functions ¶
func CompressPubkey ¶ added in v1.0.1
CompressPubkey encodes a public key to the 33-byte compressed format.
func DecompressPubkey ¶ added in v1.0.1
DecompressPubkey parses a public key in the 33-byte compressed format.
func Ecrecover ¶ added in v1.0.1
Ecrecover returns the uncompressed public key that created the given signature.
func FromECDSA ¶ added in v1.0.1
func FromECDSA(priv *ecdsa.PrivateKey) []byte
FromECDSA exports a private key into a binary dump.
func FromECDSAPub ¶ added in v1.0.1
func GenerateKey ¶
func GenerateKey() (*ecdsa.PrivateKey, error)
GenerateKey generates a new private key.
func HexToECDSA ¶ added in v1.0.1
func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)
HexToECDSA parses a secp256k1 private key.
func Keccak256 ¶ added in v1.0.1
Keccak256 calculates and returns the Keccak256 hash of the input data.
func LoadECDSA ¶ added in v1.0.1
func LoadECDSA(file string) (*ecdsa.PrivateKey, error)
LoadECDSA loads a secp256k1 private key from the given file.
func New ¶ added in v1.0.1
func New(opt crypto.KeyType) (crypto.PrivateKey, error)
New generate a ecdsa private key,input is algorithm type
func NewWithCryptoKey ¶ added in v1.0.1
func NewWithCryptoKey(priv *ecdsa.PrivateKey) (crypto.PrivateKey, error)
func PaddedBigBytes ¶ added in v1.0.1
PaddedBigBytes encodes a big integer as a big-endian byte slice. The length of the slice is at least n bytes.
func ReadBits ¶ added in v1.0.1
ReadBits encodes the absolute value of bigint as big-endian bytes. Callers must ensure that buf has enough space. If buf is too short the result will be incomplete.
func RecoverPlain ¶ added in v1.20.0
func SaveECDSA ¶ added in v1.0.1
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 Sign ¶ added in v1.0.1
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 ¶ added in v1.0.1
func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)
ToECDSA creates a private key with the given D value.
func ToECDSAUnsafe ¶ added in v1.0.1
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 ¶ added in v1.0.1
UnmarshalPubkey converts bytes to a secp256k1 public key.
func UnmarshalPublicKey ¶
func ValidateSignatureValues ¶ added in v1.20.0
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 ¶ added in v1.0.1
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.0.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.
type PrivateKey ¶
type PrivateKey struct { K *ecdsa.PrivateKey // contains filtered or unexported fields }
PrivateKey ECDSA private key. never new(PrivateKey), use NewPrivateKey()
func UnmarshalPrivateKey ¶
func UnmarshalPrivateKey(data []byte, opt crypto.KeyType) (*PrivateKey, error)
func (*PrivateKey) Bytes ¶
func (priv *PrivateKey) Bytes() ([]byte, error)
Bytes returns a serialized, storable representation of this key
func (*PrivateKey) PublicKey ¶
func (priv *PrivateKey) PublicKey() crypto.PublicKey
func (*PrivateKey) Type ¶ added in v1.0.1
func (priv *PrivateKey) Type() crypto.KeyType