Documentation ¶
Overview ¶
Package crypto provides all cryptography libraries and algorithms.
Index ¶
- Constants
- Variables
- func Base58CheckDecode(in string) ([]byte, error)
- func Base58CheckEncode(in []byte) string
- func Checksum(input []byte) (cksum [4]byte)
- func Hash160(b []byte) []byte
- func KeyPairFromBytes(privKeyBytes []byte) (*PrivateKey, *PublicKey, error)
- func NewKeyPair() (*PrivateKey, *PublicKey, error)
- func Ripemd160(buf []byte) []byte
- func Sha256(buf []byte) []byte
- func Sha256Multi(data ...[]byte) []byte
- func SignCompact(privKey *PrivateKey, digest []byte) ([]byte, error)
- type HashType
- type PrivateKey
- type PublicKey
- type Signature
- type Signer
Constants ¶
const (
// HashSize is length of digest
HashSize = 32
)
Variables ¶
var ( //base58.go ErrInvalidBase58Encoding = errors.New("Invalid base58 encoding") ErrInvalidBase58Checksum = errors.New("Invalid base58 checksum") ErrInvalidBase58StringLength = errors.New("Invalid base58 string length, not enough bytes for checksum") )
error
Functions ¶
func Base58CheckDecode ¶
Base58CheckDecode converts a base58 format string to byte array, checks the checksum and returns the wrapped byte array content
func Base58CheckEncode ¶
Base58CheckEncode calculates the 4 bytes checksum of input bytes, append checksum to the input bytes, and convert to base58 format
func KeyPairFromBytes ¶
func KeyPairFromBytes(privKeyBytes []byte) (*PrivateKey, *PublicKey, error)
KeyPairFromBytes returns a private and public key pair from private key passed as a byte slice privKeyBytes
func NewKeyPair ¶
func NewKeyPair() (*PrivateKey, *PublicKey, error)
NewKeyPair returns a new private and public key pair
func Sha256Multi ¶
Sha256Multi calculates the sha256 digest of buf array
func SignCompact ¶
func SignCompact(privKey *PrivateKey, digest []byte) ([]byte, error)
SignCompact sign a byte array message using private key, and generate a signature with recover params, which can be used to recover public key
Types ¶
type HashType ¶
HashType is renamed hash type
func DoubleHashH ¶
DoubleHashH calculates hash(hash(b)) and returns the resulting bytes as a hash.
func (HashType) MarshalJSON ¶ added in v0.3.0
MarshalJSON returns hash of hex type as the JSON encoding of HashType
type PrivateKey ¶
type PrivateKey btcec.PrivateKey
PrivateKey is a btcec.PrivateKey wrapper
func (*PrivateKey) Erase ¶
func (p *PrivateKey) Erase()
Erase destroys the private info of private key, and leaves only public info
func (*PrivateKey) PubKey ¶
func (p *PrivateKey) PubKey() *PublicKey
PubKey returns the PublicKey corresponding to this private key.
func (*PrivateKey) Serialize ¶
func (p *PrivateKey) Serialize() []byte
Serialize convert private key into byte array
type PublicKey ¶
PublicKey is a btcec.PublicKey wrapper
func PublicKeyFromBytes ¶
PublicKeyFromBytes returns public key from raw bytes
func RecoverCompact ¶
RecoverCompact tries to recover public key from message digest and signatures
type Signature ¶
Signature is a btcec.Signature wrapper
func SigFromBytes ¶
SigFromBytes returns signature from raw bytes in DER format
func Sign ¶
func Sign(privKey *PrivateKey, messageHash *HashType) (*Signature, error)
Sign calculates an ECDSA signature of messageHash using privateKey.