account

package
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2022 License: BSD-3-Clause Imports: 26 Imported by: 8

Documentation

Index

Constants

View Source
const (
	AccPrefix       = "SV"
	AccIDLen        = 40
	SocketPortInit  = 23000
	SocketPortRange = 8888
)
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 EncryptWithIV

func EncryptWithIV(key, iv, 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

func (*PWallet) VerifySig

func (pw *PWallet) VerifySig(message, signature []byte) bool

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)
	VerifySig(message, signature []byte) bool
	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 LoadWalletByData

func LoadWalletByData(jsonStr string) (Wallet, error)

func NewWallet

func NewWallet(auth string, isLight bool) (Wallet, error)

func NewWalletFromPrivateBytes

func NewWalletFromPrivateBytes(auth string, hexpriv 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