account

package
v0.0.0-...-45a46c7 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2019 License: MIT Imports: 26 Imported by: 3

Documentation

Index

Constants

View Source
const (
	AccPrefix       = "HO"
	AccIDLen        = 40
	SocketPortInit  = 52000
	SocketPortRange = 12000
)
View Source
const ServeNodeSep = "@"
View Source
const (
	WalletVersion = 1
)

Variables

View Source
var (
	EConvertCurvePubKey = fmt.Errorf("convert ed25519 public key to curve25519 public key failed")
)
View Source
var (
	EInvalidID = fmt.Errorf("invalid ID")
)
View Source
var ErrInvalidID = fmt.Errorf("invalid node id")
View Source
var KP = struct {
	S int
	N int
	R int
	P int
	L int
}{
	S: 8,
	N: 1 << 15,
	R: 8,
	P: 1,
	L: 32,
}

Functions

func AESKey

func AESKey(salt []byte, password string) ([]byte, error)

func CheckID

func CheckID(address string) bool

func Decrypt

func Decrypt(key []byte, cipherTxt []byte) ([]byte, error)

func Encrypt

func Encrypt(key []byte, plainTxt []byte) ([]byte, error)

func GenerateAesKey

func GenerateAesKey(aesKey *PipeCryptKey, peerPub []byte, key ed25519.PrivateKey) error

func PrivateKeyToCurve25519

func PrivateKeyToCurve25519(curve25519Private *[32]byte, privateKey *[64]byte)

func PublicKeyToCurve25519

func PublicKeyToCurve25519(curve25519Public *[32]byte, publicKey *[32]byte) bool

func RecoverJson

func RecoverJson(sig []byte, v interface{}) common.Address

func VerifyAbiSig

func VerifyAbiSig(mainAddr common.Address, sig []byte, msg []byte) bool

func VerifyJsonSig

func VerifyJsonSig(mainAddr common.Address, sig []byte, v interface{}) bool

func VerifySubSig

func VerifySubSig(subAddr ID, sig []byte, v interface{}) bool

Types

type Account

type Account struct {
	sync.RWMutex
	Address ID
	Key     *Key
}

func AccFromString

func AccFromString(addr, cipher, password string) (*Account, error)

func (*Account) CreateAesKey

func (acc *Account) CreateAesKey(key *PipeCryptKey, peerAddr string) error

func (*Account) FormatShow

func (acc *Account) FormatShow() string

func (*Account) IsEmpty

func (acc *Account) IsEmpty() bool

func (*Account) Sign

func (acc *Account) Sign(data []byte) []byte

func (*Account) UnlockAcc

func (acc *Account) UnlockAcc(password string) bool

func (*Account) Verify

func (acc *Account) Verify(data, sig []byte) bool

type ID

type ID string

func ConvertToID

func ConvertToID(addr string) (ID, error)

func ConvertToID2

func ConvertToID2(key []byte) ID

func (ID) IsValid

func (id ID) IsValid() bool

func (ID) String

func (id ID) String() string

func (ID) ToArray

func (id ID) ToArray() [32]byte

func (ID) ToPubKey

func (id ID) ToPubKey() ed25519.PublicKey

func (ID) ToServerPort

func (id ID) ToServerPort() uint16

type Key

type Key struct {
	PriKey    ed25519.PrivateKey `json:"-"`
	PubKey    ed25519.PublicKey  `json:"pubKey"`
	LockedKey []byte             `json:"cipherTxt"`
}

func GenerateKey

func GenerateKey(password string) (*Key, error)

func (*Key) GenerateAesKey

func (k *Key) GenerateAesKey(aesKey *PipeCryptKey, peerPub []byte) error

func (*Key) ToNodeId

func (k *Key) ToNodeId() ID

type PWallet

type PWallet struct {
	Version   int                 `json:"version"`
	MainAddr  common.Address      `json:"mainAddress"`
	Crypto    keystore.CryptoJSON `json:"crypto"`
	SubAddr   ID                  `json:"subAddress"`
	SubCipher string              `json:"subCipher"`
	// contains filtered or unexported fields
}

func (*PWallet) Close

func (pw *PWallet) Close()

func (*PWallet) CryptKey

func (pw *PWallet) CryptKey() ed25519.PrivateKey

func (*PWallet) ExportEth

func (pw *PWallet) ExportEth(auth, eAuth, path string) error

func (*PWallet) IsOpen

func (pw *PWallet) IsOpen() bool

func (*PWallet) MainAddress

func (pw *PWallet) MainAddress() common.Address

func (*PWallet) Open

func (pw *PWallet) Open(auth string) error

func (*PWallet) SaveToPath

func (pw *PWallet) SaveToPath(wPath string) error

func (*PWallet) Sign

func (pw *PWallet) Sign(v []byte) ([]byte, error)

func (*PWallet) SignJSONSub

func (pw *PWallet) SignJSONSub(v interface{}) []byte

func (*PWallet) SignJson

func (pw *PWallet) SignJson(v interface{}) ([]byte, error)

func (*PWallet) SignKey

func (pw *PWallet) SignKey() *ecdsa.PrivateKey

func (*PWallet) SignSub

func (pw *PWallet) SignSub(v []byte) []byte

func (*PWallet) String

func (pw *PWallet) String() string

func (*PWallet) SubAddress

func (pw *PWallet) SubAddress() ID

type PeerID

type PeerID struct {
	ID      ID
	IP      string
	NetAddr string
	Ping    time.Duration
}

func ConvertPID

func ConvertPID(idStr string) (*PeerID, error)

func (*PeerID) String

func (pid *PeerID) String() string

func (*PeerID) TTL

func (pid *PeerID) TTL()

type PipeCryptKey

type PipeCryptKey [32]byte

type SafeAccount

type SafeAccount struct {
	Version string `json:"version"`
	Address ID     `json:"address"`
	Cipher  string `json:"cipher"`
}

func (*SafeAccount) Unlock

func (sa *SafeAccount) Unlock(auth string) (ed25519.PrivateKey, error)

type Wallet

type Wallet interface {
	SignKey() *ecdsa.PrivateKey
	CryptKey() ed25519.PrivateKey

	MainAddress() common.Address
	SubAddress() ID

	SignJson(v interface{}) ([]byte, error)
	Sign(v []byte) ([]byte, error)
	SignJSONSub(v interface{}) []byte
	SignSub(v []byte) []byte

	Open(auth string) error
	IsOpen() bool
	SaveToPath(wPath string) error
	String() string
	Close()
	ExportEth(auth, eAuth, path string) error
}

func LoadWallet

func LoadWallet(wPath string) (Wallet, error)

func NewWallet

func NewWallet(auth string) (Wallet, error)

type WalletKey

type WalletKey struct {
	SubPriKey  ed25519.PrivateKey
	MainPriKey *ecdsa.PrivateKey
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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