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 ¶
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 FromECDSA ¶
func FromECDSA(priv *ecdsa.PrivateKey) []byte
FromECDSA exports a private key into a binary dump.
func FromECDSAPub ¶
func GenerateKey ¶
func GenerateKey() (*ecdsa.PrivateKey, error)
GenerateKey generates a new private key.
func HexToECDSA ¶
func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)
HexToECDSA parses a secp256k1 private key.
func LoadECDSA ¶
func LoadECDSA(file string) (*ecdsa.PrivateKey, error)
LoadECDSA loads a secp256k1 private key from the given file.
func New ¶
func New(opt crypto.KeyType) (crypto.PrivateKey, error)
New generate a ecdsa private key,input is algorithm type
func NewWithCryptoKey ¶
func NewWithCryptoKey(priv *ecdsa.PrivateKey) (crypto.PrivateKey, error)
func PaddedBigBytes ¶
PaddedBigBytes encodes a big integer as a big-endian byte slice. The length of the slice is at least n bytes.
func ReadBits ¶
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 ¶
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 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 UnmarshalPublicKey ¶
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 ¶
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 ¶
func (priv *PrivateKey) Type() crypto.KeyType