README

Package crypto provides all cryptography libraries and algorithms.

Expand ▾ Collapse ▴

Documentation

Overview

    Package crypto provides all cryptography libraries and algorithms.

    Index

    Constants

    View Source
    const (
    	// HashSize is length of digest
    	HashSize = 32
    )

    Variables

    View Source
    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

      View Source
      var (
      	// ZeroHash is a HashType full of 0
      	ZeroHash = HashType{}
      )

      Functions

      func Base58CheckDecode

      func Base58CheckDecode(in string) ([]byte, error)

        Base58CheckDecode converts a base58 format string to byte array, checks the checksum and returns the wrapped byte array content

        func Base58CheckEncode

        func Base58CheckEncode(in []byte) string

          Base58CheckEncode calculates the 4 bytes checksum of input bytes, append checksum to the input bytes, and convert to base58 format

          func Checksum

          func Checksum(input []byte) (cksum [4]byte)

            Checksum return input bytes checksum.

            func Hash160

            func Hash160(b []byte) []byte

              Hash160 calculates the hash ripemd160(sha256(b)).

              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 Ripemd160

                  func Ripemd160(buf []byte) []byte

                    Ripemd160 calculates the RIPEMD160 digest of buf

                    func Sha256

                    func Sha256(buf []byte) []byte

                      Sha256 calculates the sha256 digest of buf

                      func Sha256Multi

                      func Sha256Multi(data ...[]byte) []byte

                        Sha256Multi calculates the sha256 digest of buf array

                        func Sha3256

                        func Sha3256(args ...[]byte) []byte

                          Sha3256 returns the SHA3-256 digest of the data.

                          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

                            type HashType [HashSize]byte

                              HashType is renamed hash type

                              func BigToHash

                              func BigToHash(b *big.Int) HashType

                                BigToHash convert big to hash.

                                func BytesToHash

                                func BytesToHash(b []byte) HashType

                                  BytesToHash convert bytes to hash.

                                  func DoubleHashH

                                  func DoubleHashH(b []byte) HashType

                                    DoubleHashH calculates hash(hash(b)) and returns the resulting bytes as a hash.

                                    func (*HashType) Big

                                    func (hash *HashType) Big() *big.Int

                                      Big get big.

                                      func (HashType) Bytes

                                      func (hash HashType) Bytes() []byte

                                        Bytes get bytes.

                                        func (*HashType) GetBytes

                                        func (hash *HashType) GetBytes() []byte

                                          GetBytes convert type HashType to []byte

                                          func (*HashType) IsEqual

                                          func (hash *HashType) IsEqual(target *HashType) bool

                                            IsEqual returns true if target is the same as hash.

                                            func (HashType) MarshalJSON

                                            func (hash HashType) MarshalJSON() ([]byte, error)

                                              MarshalJSON returns hash of hex type as the JSON encoding of HashType

                                              func (*HashType) SetBytes

                                              func (hash *HashType) SetBytes(hashBytes []byte) error

                                                SetBytes convert type []byte to HashType

                                                func (*HashType) SetString

                                                func (hash *HashType) SetString(str string) error

                                                  SetString sets hash using bytes parsed from string returns error if input string is not valid hex string

                                                  func (HashType) String

                                                  func (hash HashType) String() string

                                                    String returns the Hash as the hexadecimal string of the byte-reversed hash.

                                                    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

                                                            type PublicKey btcec.PublicKey

                                                              PublicKey is a btcec.PublicKey wrapper

                                                              func PublicKeyFromBytes

                                                              func PublicKeyFromBytes(publicKeyStr []byte) (*PublicKey, error)

                                                                PublicKeyFromBytes returns public key from raw bytes

                                                                func RecoverCompact

                                                                func RecoverCompact(digest, sig []byte) (*PublicKey, bool)

                                                                  RecoverCompact tries to recover public key from message digest and signatures

                                                                  func (*PublicKey) Serialize

                                                                  func (p *PublicKey) Serialize() []byte

                                                                    Serialize get the serialized format of public key

                                                                    type Signature

                                                                    type Signature btcec.Signature

                                                                      Signature is a btcec.Signature wrapper

                                                                      func SigFromBytes

                                                                      func SigFromBytes(sigStr []byte) (*Signature, error)

                                                                        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.

                                                                          func (*Signature) IsEqual

                                                                          func (sig *Signature) IsEqual(otherSig *Signature) bool

                                                                            IsEqual returns if the passed signature is equivalent to this signature

                                                                            func (*Signature) Serialize

                                                                            func (sig *Signature) Serialize() []byte

                                                                              Serialize returns the ECDSA signature in the DER format.

                                                                              func (*Signature) VerifySignature

                                                                              func (sig *Signature) VerifySignature(pubKey *PublicKey, messageHash *HashType) bool

                                                                                VerifySignature verifies that the given public key created signature over messageHash.

                                                                                type Signer

                                                                                type Signer interface {
                                                                                	Sign(messageHash *HashType) (*Signature, error)
                                                                                }

                                                                                  Signer is the interface which will generate a Signature from HashType