crypto

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2021 License: Apache-2.0 Imports: 24 Imported by: 0

README

crypto

import "github.com/neatio-project/go-crypto"

Overview

Index

Package files

armor.go hash.go priv_key.go pub_key.go random.go signature.go symmetric.go

Constants

const (
    TypeEd25519   = byte(0x01)
    TypeSecp256k1 = byte(0x02)
    NameEd25519   = "ed25519"
    NameSecp256k1 = "secp256k1"
)

Types of implementations

func CRandBytes

func CRandBytes(numBytes int) []byte

This uses the OS and the Seed(s).

func CRandHex

func CRandHex(numDigits int) string

RandHex(24) gives 96 bits of randomness, strong enough for most purposes.

func CReader

func CReader() io.Reader

Returns a crand.Reader mixed with user-supplied entropy

func DecodeArmor

func DecodeArmor(armorStr string) (blockType string, headers map[string]string, data []byte, err error)

func DecryptSymmetric

func DecryptSymmetric(ciphertext []byte, secret []byte) (plaintext []byte, err error)

secret must be 32 bytes long. Use something like Sha256(Bcrypt(passphrase)) The ciphertext is (secretbox.Overhead + 24) bytes longer than the plaintext.

func EncodeArmor

func EncodeArmor(blockType string, headers map[string]string, data []byte) string

func EncryptSymmetric

func EncryptSymmetric(plaintext []byte, secret []byte) (ciphertext []byte)

secret must be 32 bytes long. Use something like Sha256(Bcrypt(passphrase)) The ciphertext is (secretbox.Overhead + 24) bytes longer than the plaintext. NOTE: call crypto.MixEntropy() first.

func MixEntropy

func MixEntropy(seedBytes []byte)

Mix additional bytes of randomness, e.g. from hardware, user-input, etc. It is OK to call it multiple times. It does not diminish security.

func Ripemd160

func Ripemd160(bytes []byte) []byte

func Sha256

func Sha256(bytes []byte) []byte

type PrivKey

type PrivKey interface {
    Bytes() []byte
    Sign(msg []byte) Signature
    PubKey() PubKey
    Equals(PrivKey) bool
}

PrivKey is part of PrivAccount and state.PrivValidator.

func PrivKeyFromBytes
func PrivKeyFromBytes(privKeyBytes []byte) (privKey PrivKey, err error)

type PrivKeyEd25519

type PrivKeyEd25519 [64]byte

Implements PrivKey

func GenPrivKeyEd25519
func GenPrivKeyEd25519() PrivKeyEd25519
func GenPrivKeyEd25519FromSecret
func GenPrivKeyEd25519FromSecret(secret []byte) PrivKeyEd25519

NOTE: secret should be the output of a KDF like bcrypt, if it's derived from user input.

func (PrivKeyEd25519) Bytes
func (privKey PrivKeyEd25519) Bytes() []byte
func (PrivKeyEd25519) Equals
func (privKey PrivKeyEd25519) Equals(other PrivKey) bool
func (PrivKeyEd25519) Generate
func (privKey PrivKeyEd25519) Generate(index int) PrivKeyEd25519

Deterministically generates new priv-key bytes from key.

func (PrivKeyEd25519) MarshalJSON
func (p PrivKeyEd25519) MarshalJSON() ([]byte, error)
func (PrivKeyEd25519) PubKey
func (privKey PrivKeyEd25519) PubKey() PubKey
func (PrivKeyEd25519) Sign
func (privKey PrivKeyEd25519) Sign(msg []byte) Signature
func (PrivKeyEd25519) String
func (privKey PrivKeyEd25519) String() string
func (PrivKeyEd25519) ToCurve25519
func (privKey PrivKeyEd25519) ToCurve25519() *[32]byte
func (*PrivKeyEd25519) UnmarshalJSON
func (p *PrivKeyEd25519) UnmarshalJSON(enc []byte) error

type PrivKeyS

type PrivKeyS struct {
    PrivKey
}

PrivKeyS add json serialization to PrivKey

func (PrivKeyS) Empty
func (p PrivKeyS) Empty() bool
func (PrivKeyS) MarshalJSON
func (p PrivKeyS) MarshalJSON() ([]byte, error)
func (*PrivKeyS) UnmarshalJSON
func (p *PrivKeyS) UnmarshalJSON(data []byte) (err error)

type PrivKeySecp256k1

type PrivKeySecp256k1 [32]byte

Implements PrivKey

func GenPrivKeySecp256k1
func GenPrivKeySecp256k1() PrivKeySecp256k1
func GenPrivKeySecp256k1FromSecret
func GenPrivKeySecp256k1FromSecret(secret []byte) PrivKeySecp256k1

NOTE: secret should be the output of a KDF like bcrypt, if it's derived from user input.

func (PrivKeySecp256k1) Bytes
func (privKey PrivKeySecp256k1) Bytes() []byte
func (PrivKeySecp256k1) Equals
func (privKey PrivKeySecp256k1) Equals(other PrivKey) bool
func (PrivKeySecp256k1) MarshalJSON
func (p PrivKeySecp256k1) MarshalJSON() ([]byte, error)
func (PrivKeySecp256k1) PubKey
func (privKey PrivKeySecp256k1) PubKey() PubKey
func (PrivKeySecp256k1) Sign
func (privKey PrivKeySecp256k1) Sign(msg []byte) Signature
func (PrivKeySecp256k1) String
func (privKey PrivKeySecp256k1) String() string
func (*PrivKeySecp256k1) UnmarshalJSON
func (p *PrivKeySecp256k1) UnmarshalJSON(enc []byte) error

type PubKey

type PubKey interface {
    Address() []byte
    Bytes() []byte
    KeyString() string
    VerifyBytes(msg []byte, sig Signature) bool
    Equals(PubKey) bool
}

PubKey is part of Account and Validator.

func PubKeyFromBytes
func PubKeyFromBytes(pubKeyBytes []byte) (pubKey PubKey, err error)

type PubKeyEd25519

type PubKeyEd25519 [32]byte

Implements PubKey

func (PubKeyEd25519) Address
func (pubKey PubKeyEd25519) Address() []byte
func (PubKeyEd25519) Bytes
func (pubKey PubKeyEd25519) Bytes() []byte
func (PubKeyEd25519) Equals
func (pubKey PubKeyEd25519) Equals(other PubKey) bool
func (PubKeyEd25519) KeyString
func (pubKey PubKeyEd25519) KeyString() string

Must return the full bytes in hex. Used for map keying, etc.

func (PubKeyEd25519) MarshalJSON
func (p PubKeyEd25519) MarshalJSON() ([]byte, error)
func (PubKeyEd25519) String
func (pubKey PubKeyEd25519) String() string
func (PubKeyEd25519) ToCurve25519
func (pubKey PubKeyEd25519) ToCurve25519() *[32]byte

For use with golang/crypto/nacl/box If error, returns nil.

func (*PubKeyEd25519) UnmarshalJSON
func (p *PubKeyEd25519) UnmarshalJSON(enc []byte) error
func (PubKeyEd25519) VerifyBytes
func (pubKey PubKeyEd25519) VerifyBytes(msg []byte, sig_ Signature) bool

type PubKeyS

type PubKeyS struct {
    PubKey
}

PubKeyS add json serialization to PubKey

func (PubKeyS) Empty
func (p PubKeyS) Empty() bool
func (PubKeyS) MarshalJSON
func (p PubKeyS) MarshalJSON() ([]byte, error)
func (*PubKeyS) UnmarshalJSON
func (p *PubKeyS) UnmarshalJSON(data []byte) (err error)

type PubKeySecp256k1

type PubKeySecp256k1 [33]byte

Implements PubKey. Compressed pubkey (just the x-cord), prefixed with 0x02 or 0x03, depending on the y-cord.

func (PubKeySecp256k1) Address
func (pubKey PubKeySecp256k1) Address() []byte

Implements Bitcoin style addresses: RIPEMD160(SHA256(pubkey))

func (PubKeySecp256k1) Bytes
func (pubKey PubKeySecp256k1) Bytes() []byte
func (PubKeySecp256k1) Equals
func (pubKey PubKeySecp256k1) Equals(other PubKey) bool
func (PubKeySecp256k1) KeyString
func (pubKey PubKeySecp256k1) KeyString() string

Must return the full bytes in hex. Used for map keying, etc.

func (PubKeySecp256k1) MarshalJSON
func (p PubKeySecp256k1) MarshalJSON() ([]byte, error)
func (PubKeySecp256k1) String
func (pubKey PubKeySecp256k1) String() string
func (*PubKeySecp256k1) UnmarshalJSON
func (p *PubKeySecp256k1) UnmarshalJSON(enc []byte) error
func (PubKeySecp256k1) VerifyBytes
func (pubKey PubKeySecp256k1) VerifyBytes(msg []byte, sig_ Signature) bool

type Signature

type Signature interface {
    Bytes() []byte
    IsZero() bool
    String() string
    Equals(Signature) bool
}

Signature is a part of Txs and consensus Votes.

func SignatureFromBytes
func SignatureFromBytes(sigBytes []byte) (sig Signature, err error)

type SignatureEd25519

type SignatureEd25519 [64]byte

Implements Signature

func (SignatureEd25519) Bytes
func (sig SignatureEd25519) Bytes() []byte
func (SignatureEd25519) Equals
func (sig SignatureEd25519) Equals(other Signature) bool
func (SignatureEd25519) IsZero
func (sig SignatureEd25519) IsZero() bool
func (SignatureEd25519) MarshalJSON
func (p SignatureEd25519) MarshalJSON() ([]byte, error)
func (SignatureEd25519) String
func (sig SignatureEd25519) String() string
func (*SignatureEd25519) UnmarshalJSON
func (p *SignatureEd25519) UnmarshalJSON(enc []byte) error

type SignatureS

type SignatureS struct {
    Signature
}

SignatureS add json serialization to Signature

func (SignatureS) Empty
func (p SignatureS) Empty() bool
func (SignatureS) MarshalJSON
func (p SignatureS) MarshalJSON() ([]byte, error)
func (*SignatureS) UnmarshalJSON
func (p *SignatureS) UnmarshalJSON(data []byte) (err error)

type SignatureSecp256k1

type SignatureSecp256k1 []byte

Implements Signature

func (SignatureSecp256k1) Bytes
func (sig SignatureSecp256k1) Bytes() []byte
func (SignatureSecp256k1) Equals
func (sig SignatureSecp256k1) Equals(other Signature) bool
func (SignatureSecp256k1) IsZero
func (sig SignatureSecp256k1) IsZero() bool
func (SignatureSecp256k1) MarshalJSON
func (p SignatureSecp256k1) MarshalJSON() ([]byte, error)
func (SignatureSecp256k1) String
func (sig SignatureSecp256k1) String() string
func (*SignatureSecp256k1) UnmarshalJSON
func (p *SignatureSecp256k1) UnmarshalJSON(enc []byte) error

Generated by godoc2md

tendermint-go-crypto

Documentation

Index

Constants

View Source
const (
	TypeEd25519   = byte(0x01)
	TypeSecp256k1 = byte(0x02)
	TypeEthereum  = byte(0x03)
	TypeBls       = byte(0x04)
	NameEd25519   = "ed25519"
	NameSecp256k1 = "secp256k1"
	NameEthereum  = "ethereum"
	NameBls       = "bls"
)

Types of implementations

Variables

This section is empty.

Functions

func CRandBytes

func CRandBytes(numBytes int) []byte

This uses the OS and the Seed(s).

func CRandHex

func CRandHex(numDigits int) string

RandHex(24) gives 96 bits of randomness, strong enough for most purposes.

func CReader

func CReader() io.Reader

Returns a crand.Reader mixed with user-supplied entropy

func CheckConsensusPubKey

func CheckConsensusPubKey(from common.Address, consensusPubkey, signature []byte) error

func DecodeArmor

func DecodeArmor(armorStr string) (blockType string, headers map[string]string, data []byte, err error)

func DecryptSymmetric

func DecryptSymmetric(ciphertext []byte, secret []byte) (plaintext []byte, err error)

secret must be 32 bytes long. Use something like Sha256(Bcrypt(passphrase)) The ciphertext is (secretbox.Overhead + 24) bytes longer than the plaintext.

func EncodeArmor

func EncodeArmor(blockType string, headers map[string]string, data []byte) string

func EncryptSymmetric

func EncryptSymmetric(plaintext []byte, secret []byte) (ciphertext []byte)

secret must be 32 bytes long. Use something like Sha256(Bcrypt(passphrase)) The ciphertext is (secretbox.Overhead + 24) bytes longer than the plaintext. NOTE: call crypto.MixEntropy() first.

func MixEntropy

func MixEntropy(seedBytes []byte)

Mix additional bytes of randomness, e.g. from hardware, user-input, etc. It is OK to call it multiple times. It does not diminish security.

func Ripemd160

func Ripemd160(bytes []byte) []byte

func Sha256

func Sha256(bytes []byte) []byte

Types

type BLSPrivKey

type BLSPrivKey [32]byte

func (BLSPrivKey) Bytes

func (privKey BLSPrivKey) Bytes() []byte

func (BLSPrivKey) Equals

func (privKey BLSPrivKey) Equals(other PrivKey) bool

func (BLSPrivKey) MarshalJSON

func (privKey BLSPrivKey) MarshalJSON() ([]byte, error)

func (BLSPrivKey) PubKey

func (privKey BLSPrivKey) PubKey() PubKey

func (BLSPrivKey) Sign

func (privKey BLSPrivKey) Sign(msg []byte) Signature

func (*BLSPrivKey) UnmarshalJSON

func (privKey *BLSPrivKey) UnmarshalJSON(enc []byte) error

type BLSPubKey

type BLSPubKey [128]byte

//------------------------------------- // Implements PubKey. type BLSPubKey []byte

func (pubKey BLSPubKey) getElement() *pbc.Element {
	return pairing.NewG2().SetBytes(pubKey)
}
func (pubKey BLSPubKey) GetElement() *pbc.Element {
	return pairing.NewG2().SetBytes(pubKey)
}
func (pubKey BLSPubKey) Set1() {
	copy(pubKey, pairing.NewG1().Set1().Bytes())
}
func CreateBLSPubKey() BLSPubKey {
	pubKey := pairing.NewG2().Rand()
	return pubKey.Bytes()
}
func PubKeyMul(l, r BLSPubKey) BLSPubKey {
	el1 := l.getElement()
	el2 := r.getElement()
	rs := pairing.NewG2().Mul(el1, el2)
	return rs.Bytes()
}
func (pubKey BLSPubKey) Mul(other PubKey) bool {
	if otherPub, ok := other.(BLSPubKey); ok {
		el1 := pubKey.getElement()
		el2 := otherPub.getElement()
		rs := pairing.NewG2().Mul(el1, el2)
		copy(pubKey, rs.Bytes())
		return true
	} else {
		return false
	}
}
func (pubKey BLSPubKey) MulWithSet1(other PubKey) bool {
	if otherPub, ok := other.(BLSPubKey); ok {
		el1 := pubKey.getElement()
		el1.Set1()
		el2 := otherPub.getElement()
		rs := pairing.NewG2().Mul(el1, el2)
		copy(pubKey, rs.Bytes())
		return true
	} else {
		return false
	}
}
func (pubKey BLSPubKey) Bytes() []byte {
	return pubKey
}
func (pubKey BLSPubKey) Address() []byte {
	hasherSHA256 := sha256.New()
	hasherSHA256.Write(pubKey[:]) // does not error
	sha := hasherSHA256.Sum(nil)

	hasherRIPEMD160 := ripemd160.New()
	hasherRIPEMD160.Write(sha) // does not error
	return hasherRIPEMD160.Sum(nil)
}

func (pubKey BLSPubKey) KeyString() string {

	return Fmt("EthPubKey{%X}", pubKey[:])
}
func (pubKey BLSPubKey) VerifyBytes(msg []byte, sig_ Signature) bool {
	if otherSign, ok := sig_.(BLSSignature); ok {
		h := pairing.NewG1().SetFromStringHash(string(msg), sha256.New())
		temp1 := pairing.NewGT().Pair(h, pubKey.getElement())
		temp2 := pairing.NewGT().Pair(otherSign.getElement(), g)
		return temp1.Equals(temp2)
	} else {
		return false;
	}
}
func (pubKey BLSPubKey) Equals(other PubKey) bool {
	if otherBLS, ok := other.(BLSPubKey); ok {
		return pubKey.getElement().Equals(otherBLS.getElement())
	} else {
		return false
	}
}

func (pubKey BLSPubKey) MarshalJSON() ([]byte, error) {

	return data.Encoder.Marshal(pubKey)
}
func (p *BLSPubKey) UnmarshalJSON(enc []byte) error {
	var ref []byte
	err := data.Encoder.Unmarshal(&ref, enc)
	copy(*p, ref)
	return err
}

func BLSPubKeyAggregate

func BLSPubKeyAggregate(pks []*PubKey) *BLSPubKey

func (BLSPubKey) Address

func (pubKey BLSPubKey) Address() []byte

func (BLSPubKey) Bytes

func (pubKey BLSPubKey) Bytes() []byte

func (BLSPubKey) Equals

func (pubKey BLSPubKey) Equals(other PubKey) bool

func (BLSPubKey) KeyString

func (pubKey BLSPubKey) KeyString() string

func (BLSPubKey) MarshalJSON

func (pubKey BLSPubKey) MarshalJSON() ([]byte, error)

func (*BLSPubKey) UnmarshalJSON

func (pubKey *BLSPubKey) UnmarshalJSON(enc []byte) error

func (BLSPubKey) VerifyBytes

func (pubKey BLSPubKey) VerifyBytes(msg []byte, sig_ Signature) bool

type BLSSignature

type BLSSignature []byte

//------------------------------------- // Implements Signature type BLSSignature []byte

func CreateBLSSignature() BLSSignature {
	pubKey := pairing.NewG2().Rand()
	return pubKey.Bytes()
}
func (sig BLSSignature) getElement() *pbc.Element {
	return pairing.NewG2().SetBytes(sig)
}
func (sig BLSSignature) GetElement() *pbc.Element {
	return pairing.NewG2().SetBytes(sig)
}
func (sig BLSSignature) Set1() {
	copy(sig, pairing.NewG1().Set1().Bytes())
}
func BLSSignatureMul(l, r Signature) Signature {
	lSign,lok := l.(BLSSignature);
	rSign, rok := r.(BLSSignature);
	if  lok&&rok {
		el1 := lSign.getElement()
		el2 := rSign.getElement()
		rs := pairing.NewG2().Mul(el1, el2)
		return BLSSignature(rs.Bytes())
	} else {
		return nil
	}
}
func (sig BLSSignature) Mul(other Signature) bool {
	if otherSign,ok := other.(BLSSignature); ok {
		el1 := sig.getElement()
		fmt.Println(el1.Bytes()[:3])
		el2 := otherSign.getElement()
		fmt.Println(el2.Bytes()[:3])
		rs := el1.Mul(el1, el2)
		fmt.Println("el1",el1.Bytes()[:3])
		fmt.Println("rs", rs.Bytes()[:3])
		copy(sig, rs.Bytes())
		return true
	} else {
		return false
	}
}
func (sig BLSSignature) MulWithSet1(other Signature) bool {
	if otherSign,ok := other.(BLSSignature); ok {
		el1 := sig.getElement()
		el1.Set1()
		fmt.Println(el1.Bytes()[:3])
		el2 := otherSign.getElement()
		fmt.Println(el2.Bytes()[:3])
		rs := el1.Mul(el1, el2)
		fmt.Println("el1",el1.Bytes()[:3])
		fmt.Println("rs", rs.Bytes()[:3])
		copy(sig, rs.Bytes())
		return true
	} else {
		return false
	}
}
func (sig BLSSignature) Bytes() []byte {
	return sig
}

func (sig BLSSignature) IsZero() bool { return len(sig) == 0 }

func (sig BLSSignature) String() string { return fmt.Sprintf("/%X.../", Fingerprint(sig)) }

func (sig BLSSignature) Equals(other Signature) bool {
	if otherBLS, ok := other.(BLSSignature); ok {
		return sig.getElement().Equals(otherBLS.getElement())
	} else {
		return false
	}
}
func (p BLSSignature) MarshalJSON() ([]byte, error) {
	return data.Encoder.Marshal(p)
}
func (p *BLSSignature) UnmarshalJSON(enc []byte) error {
	var ref []byte
	err := data.Encoder.Unmarshal(&ref, enc)
	copy(*p, ref)
	return err
}

func BLSSignatureAggregate

func BLSSignatureAggregate(sigs []*Signature) BLSSignature

func (BLSSignature) Bytes

func (sig BLSSignature) Bytes() []byte

func (BLSSignature) Equals

func (sig BLSSignature) Equals(other Signature) bool

func (BLSSignature) IsZero

func (sig BLSSignature) IsZero() bool

func (BLSSignature) MarshalJSON

func (p BLSSignature) MarshalJSON() ([]byte, error)

func (BLSSignature) String

func (sig BLSSignature) String() string

func (*BLSSignature) UnmarshalJSON

func (p *BLSSignature) UnmarshalJSON(enc []byte) error

type EthereumPrivKey

type EthereumPrivKey []byte

func (EthereumPrivKey) Bytes

func (privKey EthereumPrivKey) Bytes() []byte

func (EthereumPrivKey) Equals

func (privKey EthereumPrivKey) Equals(other PrivKey) bool

func (EthereumPrivKey) MarshalJSON

func (privKey EthereumPrivKey) MarshalJSON() ([]byte, error)

func (EthereumPrivKey) PubKey

func (privKey EthereumPrivKey) PubKey() PubKey

func (EthereumPrivKey) Sign

func (privKey EthereumPrivKey) Sign(msg []byte) Signature

func (*EthereumPrivKey) UnmarshalJSON

func (privKey *EthereumPrivKey) UnmarshalJSON(enc []byte) error

type EthereumPubKey

type EthereumPubKey []byte

func (EthereumPubKey) Address

func (pubKey EthereumPubKey) Address() []byte

func (EthereumPubKey) Bytes

func (pubKey EthereumPubKey) Bytes() []byte

func (EthereumPubKey) Equals

func (pubKey EthereumPubKey) Equals(other PubKey) bool

func (EthereumPubKey) KeyString

func (pubKey EthereumPubKey) KeyString() string

func (EthereumPubKey) MarshalJSON

func (pubKey EthereumPubKey) MarshalJSON() ([]byte, error)

func (*EthereumPubKey) UnmarshalJSON

func (p *EthereumPubKey) UnmarshalJSON(enc []byte) error

func (EthereumPubKey) VerifyBytes

func (pubKey EthereumPubKey) VerifyBytes(msg []byte, sig_ Signature) bool

type EthereumSignature

type EthereumSignature []byte

func (EthereumSignature) Bytes

func (sig EthereumSignature) Bytes() []byte

func (EthereumSignature) Equals

func (sig EthereumSignature) Equals(other Signature) bool

func (EthereumSignature) IsZero

func (sig EthereumSignature) IsZero() bool

func (EthereumSignature) MarshalJSON

func (sig EthereumSignature) MarshalJSON() ([]byte, error)

func (EthereumSignature) SigByte

func (sig EthereumSignature) SigByte() []byte

func (EthereumSignature) String

func (sig EthereumSignature) String() string

func (*EthereumSignature) UnmarshalJSON

func (sig *EthereumSignature) UnmarshalJSON(enc []byte) error

type PrivKey

type PrivKey interface {
	Bytes() []byte
	Sign(msg []byte) Signature
	PubKey() PubKey
	Equals(PrivKey) bool
}

PrivKey is part of PrivAccount and state.PrivValidator.

func PrivKeyFromBytes

func PrivKeyFromBytes(privKeyBytes []byte) (privKey PrivKey, err error)

type PrivKeyEd25519

type PrivKeyEd25519 [64]byte

Implements PrivKey

func GenPrivKeyEd25519

func GenPrivKeyEd25519() PrivKeyEd25519

func GenPrivKeyEd25519FromSecret

func GenPrivKeyEd25519FromSecret(secret []byte) PrivKeyEd25519

NOTE: secret should be the output of a KDF like bcrypt, if it's derived from user input.

func (PrivKeyEd25519) Bytes

func (privKey PrivKeyEd25519) Bytes() []byte

func (PrivKeyEd25519) Equals

func (privKey PrivKeyEd25519) Equals(other PrivKey) bool

func (PrivKeyEd25519) Generate

func (privKey PrivKeyEd25519) Generate(index int) PrivKeyEd25519

Deterministically generates new priv-key bytes from key.

func (PrivKeyEd25519) MarshalJSON

func (p PrivKeyEd25519) MarshalJSON() ([]byte, error)

func (PrivKeyEd25519) PubKey

func (privKey PrivKeyEd25519) PubKey() PubKey

func (PrivKeyEd25519) Sign

func (privKey PrivKeyEd25519) Sign(msg []byte) Signature

func (PrivKeyEd25519) String

func (privKey PrivKeyEd25519) String() string

func (PrivKeyEd25519) ToCurve25519

func (privKey PrivKeyEd25519) ToCurve25519() *[32]byte

func (*PrivKeyEd25519) UnmarshalJSON

func (p *PrivKeyEd25519) UnmarshalJSON(enc []byte) error

type PrivKeyS

type PrivKeyS struct {
	PrivKey
}

PrivKeyS add json serialization to PrivKey

func WrapPrivKey

func WrapPrivKey(pk PrivKey) PrivKeyS

func (PrivKeyS) Empty

func (p PrivKeyS) Empty() bool

func (PrivKeyS) MarshalJSON

func (p PrivKeyS) MarshalJSON() ([]byte, error)

func (*PrivKeyS) UnmarshalJSON

func (p *PrivKeyS) UnmarshalJSON(data []byte) (err error)

type PrivKeySecp256k1

type PrivKeySecp256k1 [32]byte

Implements PrivKey

func GenPrivKeySecp256k1

func GenPrivKeySecp256k1() PrivKeySecp256k1

func GenPrivKeySecp256k1FromSecret

func GenPrivKeySecp256k1FromSecret(secret []byte) PrivKeySecp256k1

NOTE: secret should be the output of a KDF like bcrypt, if it's derived from user input.

func (PrivKeySecp256k1) Bytes

func (privKey PrivKeySecp256k1) Bytes() []byte

func (PrivKeySecp256k1) Equals

func (privKey PrivKeySecp256k1) Equals(other PrivKey) bool

func (PrivKeySecp256k1) MarshalJSON

func (p PrivKeySecp256k1) MarshalJSON() ([]byte, error)

func (PrivKeySecp256k1) PubKey

func (privKey PrivKeySecp256k1) PubKey() PubKey

func (PrivKeySecp256k1) Sign

func (privKey PrivKeySecp256k1) Sign(msg []byte) Signature

func (PrivKeySecp256k1) String

func (privKey PrivKeySecp256k1) String() string

func (*PrivKeySecp256k1) UnmarshalJSON

func (p *PrivKeySecp256k1) UnmarshalJSON(enc []byte) error

type PubKey

type PubKey interface {
	Address() []byte
	Bytes() []byte
	KeyString() string
	VerifyBytes(msg []byte, sig Signature) bool
	Equals(PubKey) bool
}

PubKey is part of Account and Validator.

func PubKeyFromBytes

func PubKeyFromBytes(pubKeyBytes []byte) (pubKey PubKey, err error)

type PubKeyEd25519

type PubKeyEd25519 [32]byte

Implements PubKey

func (PubKeyEd25519) Address

func (pubKey PubKeyEd25519) Address() []byte

func (PubKeyEd25519) Bytes

func (pubKey PubKeyEd25519) Bytes() []byte

func (PubKeyEd25519) Equals

func (pubKey PubKeyEd25519) Equals(other PubKey) bool

func (PubKeyEd25519) KeyString

func (pubKey PubKeyEd25519) KeyString() string

Must return the full bytes in hex. Used for map keying, etc.

func (PubKeyEd25519) MarshalJSON

func (p PubKeyEd25519) MarshalJSON() ([]byte, error)

func (PubKeyEd25519) String

func (pubKey PubKeyEd25519) String() string

func (PubKeyEd25519) ToCurve25519

func (pubKey PubKeyEd25519) ToCurve25519() *[32]byte

For use with golang/crypto/nacl/box If error, returns nil.

func (*PubKeyEd25519) UnmarshalJSON

func (p *PubKeyEd25519) UnmarshalJSON(enc []byte) error

func (PubKeyEd25519) VerifyBytes

func (pubKey PubKeyEd25519) VerifyBytes(msg []byte, sig_ Signature) bool

type PubKeyS

type PubKeyS struct {
	PubKey
}

PubKeyS add json serialization to PubKey

func WrapPubKey

func WrapPubKey(pk PubKey) PubKeyS

func (PubKeyS) Empty

func (p PubKeyS) Empty() bool

func (PubKeyS) MarshalJSON

func (p PubKeyS) MarshalJSON() ([]byte, error)

func (*PubKeyS) UnmarshalJSON

func (p *PubKeyS) UnmarshalJSON(data []byte) (err error)

type PubKeySecp256k1

type PubKeySecp256k1 [33]byte

Implements PubKey. Compressed pubkey (just the x-cord), prefixed with 0x02 or 0x03, depending on the y-cord.

func (PubKeySecp256k1) Address

func (pubKey PubKeySecp256k1) Address() []byte

Implements Bitcoin style addresses: RIPEMD160(SHA256(pubkey))

func (PubKeySecp256k1) Bytes

func (pubKey PubKeySecp256k1) Bytes() []byte

func (PubKeySecp256k1) Equals

func (pubKey PubKeySecp256k1) Equals(other PubKey) bool

func (PubKeySecp256k1) KeyString

func (pubKey PubKeySecp256k1) KeyString() string

Must return the full bytes in hex. Used for map keying, etc.

func (PubKeySecp256k1) MarshalJSON

func (p PubKeySecp256k1) MarshalJSON() ([]byte, error)

func (PubKeySecp256k1) String

func (pubKey PubKeySecp256k1) String() string

func (*PubKeySecp256k1) UnmarshalJSON

func (p *PubKeySecp256k1) UnmarshalJSON(enc []byte) error

func (PubKeySecp256k1) VerifyBytes

func (pubKey PubKeySecp256k1) VerifyBytes(msg []byte, sig_ Signature) bool

type Signature

type Signature interface {
	Bytes() []byte
	IsZero() bool
	String() string
	Equals(Signature) bool
}

Signature is a part of Txs and consensus Votes.

func SignatureFromBytes

func SignatureFromBytes(sigBytes []byte) (sig Signature, err error)

type SignatureEd25519

type SignatureEd25519 [64]byte

Implements Signature

func (SignatureEd25519) Bytes

func (sig SignatureEd25519) Bytes() []byte

func (SignatureEd25519) Equals

func (sig SignatureEd25519) Equals(other Signature) bool

func (SignatureEd25519) IsZero

func (sig SignatureEd25519) IsZero() bool

func (SignatureEd25519) MarshalJSON

func (p SignatureEd25519) MarshalJSON() ([]byte, error)

func (SignatureEd25519) String

func (sig SignatureEd25519) String() string

func (*SignatureEd25519) UnmarshalJSON

func (p *SignatureEd25519) UnmarshalJSON(enc []byte) error

type SignatureS

type SignatureS struct {
	Signature
}

SignatureS add json serialization to Signature

func WrapSignature

func WrapSignature(sig Signature) SignatureS

func (SignatureS) Empty

func (p SignatureS) Empty() bool

func (SignatureS) MarshalJSON

func (p SignatureS) MarshalJSON() ([]byte, error)

func (*SignatureS) UnmarshalJSON

func (p *SignatureS) UnmarshalJSON(data []byte) (err error)

type SignatureSecp256k1

type SignatureSecp256k1 []byte

Implements Signature

func (SignatureSecp256k1) Bytes

func (sig SignatureSecp256k1) Bytes() []byte

func (SignatureSecp256k1) Equals

func (sig SignatureSecp256k1) Equals(other Signature) bool

func (SignatureSecp256k1) IsZero

func (sig SignatureSecp256k1) IsZero() bool

func (SignatureSecp256k1) MarshalJSON

func (p SignatureSecp256k1) MarshalJSON() ([]byte, error)

func (SignatureSecp256k1) String

func (sig SignatureSecp256k1) String() string

func (*SignatureSecp256k1) UnmarshalJSON

func (p *SignatureSecp256k1) UnmarshalJSON(enc []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL