account

package
v0.0.0-...-b6b96b9 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetaAddrLen    int    = 20
	PubPrefix      int    = 16
	CheckSumLen    int    = 4
	MetaChainMagic string = "0285446711860699"
	HashRound      int    = 3
)

Variables

View Source
var New = func() *Account {
	priv, pub := GenerateKey()

	a := &Account{
		priv: priv,
		pub:  pub,
	}
	addr, err := PubKey2Addr(pub)
	if err != nil {
		return nil
	}

	a.addr = addr

	return a
}

Functions

func Encode

func Encode(ma MetaAddr) (string, error)

func GenerateKey

func GenerateKey() (PrivKey, PubKey)

func ShareKey

func ShareKey(privKey PrivKey, peerPub PubKey) []byte

func Sign

func Sign(message []byte, priv *PrivKey) ([]byte, error)

func VerifySignature

func VerifySignature(message []byte, sig []byte, pk *PubKey) bool

Types

type Account

type Account struct {
	// contains filtered or unexported fields
}

func (*Account) Addr

func (a *Account) Addr() MetaAddr

func (*Account) GetPrivBytes

func (a *Account) GetPrivBytes() []byte

func (*Account) MetaChainAddr

func (a *Account) MetaChainAddr() string

func (*Account) SetPriv

func (a *Account) SetPriv(priv PrivKey)

func (*Account) ShareKey

func (a *Account) ShareKey(peer PubKey) []byte

func (*Account) Sign

func (a *Account) Sign(message []byte) ([]byte, error)

func (*Account) VerifySignature

func (a *Account) VerifySignature(message []byte, sig []byte) bool

type MetaAddr

type MetaAddr [MetaAddrLen]byte

func Decode

func Decode(sma string) (MetaAddr, error)

func PubKey2Addr

func PubKey2Addr(pk PubKey) (MetaAddr, error)

func (*MetaAddr) Encode

func (ma *MetaAddr) Encode() string

func (MetaAddr) MarshalText

func (ma MetaAddr) MarshalText() ([]byte, error)

FOR JSON MARSHAL

func (*MetaAddr) UnmarshalText

func (ma *MetaAddr) UnmarshalText(text []byte) error

FOR JSON UNMARSHAL

func (MetaAddr) Valid

func (ma MetaAddr) Valid() bool

type PrivKey

type PrivKey ecdsa.PrivateKey

func Bytes2Priv

func Bytes2Priv(privBytes []byte) (PrivKey, error)

func (PrivKey) Base58

func (priv PrivKey) Base58() string

func (PrivKey) Bytes

func (priv PrivKey) Bytes() []byte

func (PrivKey) Hex

func (priv PrivKey) Hex() string

func (PrivKey) ToPublic

func (priv PrivKey) ToPublic() PubKey

type PubKey

type PubKey ecdsa.PublicKey

func Bytes2Pub

func Bytes2Pub(pubBytes []byte) (PubKey, error)

func RecoverPubKey

func RecoverPubKey(message []byte, sig []byte) (*PubKey, error)

func (PubKey) Base58

func (pk PubKey) Base58() string

func (PubKey) Bytes

func (pk PubKey) Bytes() []byte

func (*PubKey) Cmp

func (pk *PubKey) Cmp(pk1 *PubKey) bool

func (PubKey) Hex

func (pk PubKey) Hex() string

Jump to

Keyboard shortcuts

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