account

package
v2.0.1-beta+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2019 License: Apache-2.0 Imports: 20 Imported by: 28

Documentation

Index

Constants

View Source
const (
	SCHEME = "did"
	METHOD = "dna"
	VER    = 0x41
)

Variables

This section is empty.

Functions

func CreateID

func CreateID(nonce []byte) (string, error)

func GenerateID

func GenerateID() (string, error)

func VerifyID

func VerifyID(id string) bool

Types

type Account

type Account struct {
	PrivateKey keypair.PrivateKey
	PublicKey  keypair.PublicKey
	Address    common.Address
	SigScheme  s.SignatureScheme
}

crypto object

func NewAccount

func NewAccount(encrypt string) *Account

func (*Account) PrivKey

func (this *Account) PrivKey() keypair.PrivateKey

func (*Account) PubKey

func (this *Account) PubKey() keypair.PublicKey

func (*Account) Scheme

func (this *Account) Scheme() s.SignatureScheme

type AccountData

type AccountData struct {
	keypair.ProtectedKey

	Label     string `json:"label"`
	PubKey    string `json:"publicKey"`
	SigSch    string `json:"signatureScheme"`
	IsDefault bool   `json:"isDefault"`
	Lock      bool   `json:"lock"`
}

* AccountData - for executor read and save, no crypto object included *

func (*AccountData) GetKeyPair

func (this *AccountData) GetKeyPair() *keypair.ProtectedKey

func (*AccountData) SetKeyPair

func (this *AccountData) SetKeyPair(keyinfo *keypair.ProtectedKey)

func (*AccountData) SetLabel

func (this *AccountData) SetLabel(label string)

type AccountMetadata

type AccountMetadata struct {
	IsDefault bool   //Is default account
	Label     string //Lable of account
	KeyType   string //KeyType ECDSA,SM2 or EDDSA
	Curve     string //Curve of key type
	Address   string //Address(base58) of account
	PubKey    string //Public  key
	SigSch    string //Signature scheme
	Salt      []byte //Salt
	Key       []byte //PrivateKey in encrypted
	EncAlg    string //Encrypt alg of private key
	Hash      string //Hash alg
}

AccountMetadata all account info without private key

type Client

type Client interface {
	//NewAccount create a new account.
	NewAccount(label string, typeCode keypair.KeyType, curveCode byte, sigScheme s.SignatureScheme, passwd []byte) (*Account, error)
	//ImportAccount import a already exist account to executor
	ImportAccount(accMeta *AccountMetadata) error
	//GetAccountByAddress return account object by address
	GetAccountByAddress(address string, passwd []byte) (*Account, error)
	//GetAccountByLabel return account object by label
	GetAccountByLabel(label string, passwd []byte) (*Account, error)
	//GetAccountByIndex return account object by index. Index start from 1
	GetAccountByIndex(index int, passwd []byte) (*Account, error)
	//GetDefaultAccount return default account
	GetDefaultAccount(passwd []byte) (*Account, error)
	//GetAccountMetadataByIndex return account Metadata info by address
	GetAccountMetadataByAddress(address string) *AccountMetadata
	//GetAccountMetadataByLabel return account Metadata info by label
	GetAccountMetadataByLabel(label string) *AccountMetadata
	//GetAccountMetadataByIndex return account Metadata info by index. Index start from 1
	GetAccountMetadataByIndex(index int) *AccountMetadata
	//GetDefaultAccountMetadata return default account Metadata info
	GetDefaultAccountMetadata() *AccountMetadata
	//GetAccountNum return total account number
	GetAccountNum() int
	//DeleteAccount delete account
	DeleteAccount(address string, passwd []byte) (*Account, error)
	//UnLockAccount can get account without password in expire time
	UnLockAccount(address string, expiredAt int, passwd []byte) error
	//LockAccount lock unlock account
	LockAccount(address string)
	//GetUnlockAccount return account which was unlock and in expired time
	GetUnlockAccount(address string) *Account
	//Set a new account to default account
	SetDefaultAccount(address string) error
	//Set a new label to accont
	SetLabel(address, label string) error
	//Change pasword to account
	ChangePassword(address string, oldPasswd, newPasswd []byte) error
	//Change sig scheme to account
	ChangeSigScheme(address string, sigScheme s.SignatureScheme) error
	//Get the underlying executor data
	GetExecutorData() *ExecutorData
}

Client of executor

func Open

func Open(path string) (Client, error)

type ClientImpl

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

func NewClientImpl

func NewClientImpl(path string) (*ClientImpl, error)

func (*ClientImpl) ChangePassword

func (this *ClientImpl) ChangePassword(address string, oldPasswd, newPasswd []byte) error

func (*ClientImpl) ChangeSigScheme

func (this *ClientImpl) ChangeSigScheme(address string, sigScheme s.SignatureScheme) error

func (*ClientImpl) DeleteAccount

func (this *ClientImpl) DeleteAccount(address string, passwd []byte) (*Account, error)

func (*ClientImpl) GetAccountByAddress

func (this *ClientImpl) GetAccountByAddress(address string, passwd []byte) (*Account, error)

func (*ClientImpl) GetAccountByIndex

func (this *ClientImpl) GetAccountByIndex(index int, passwd []byte) (*Account, error)

Index start from 1

func (*ClientImpl) GetAccountByLabel

func (this *ClientImpl) GetAccountByLabel(label string, passwd []byte) (*Account, error)

func (*ClientImpl) GetAccountMetadataByAddress

func (this *ClientImpl) GetAccountMetadataByAddress(address string) *AccountMetadata

func (*ClientImpl) GetAccountMetadataByIndex

func (this *ClientImpl) GetAccountMetadataByIndex(index int) *AccountMetadata

Index start from 1

func (*ClientImpl) GetAccountMetadataByLabel

func (this *ClientImpl) GetAccountMetadataByLabel(label string) *AccountMetadata

func (*ClientImpl) GetAccountNum

func (this *ClientImpl) GetAccountNum() int

func (*ClientImpl) GetDefaultAccount

func (this *ClientImpl) GetDefaultAccount(passwd []byte) (*Account, error)

func (*ClientImpl) GetDefaultAccountMetadata

func (this *ClientImpl) GetDefaultAccountMetadata() *AccountMetadata

func (*ClientImpl) GetExecutorData

func (this *ClientImpl) GetExecutorData() *ExecutorData

func (*ClientImpl) GetUnlockAccount

func (this *ClientImpl) GetUnlockAccount(address string) *Account

func (*ClientImpl) ImportAccount

func (this *ClientImpl) ImportAccount(accMeta *AccountMetadata) error

func (*ClientImpl) LockAccount

func (this *ClientImpl) LockAccount(address string)

func (*ClientImpl) NewAccount

func (this *ClientImpl) NewAccount(label string, typeCode keypair.KeyType, curveCode byte, sigScheme s.SignatureScheme, passwd []byte) (*Account, error)

func (*ClientImpl) SetDefaultAccount

func (this *ClientImpl) SetDefaultAccount(address string) error

func (*ClientImpl) SetLabel

func (this *ClientImpl) SetLabel(address, label string) error

func (*ClientImpl) UnLockAccount

func (this *ClientImpl) UnLockAccount(address string, expiredAt int, passwd []byte) error

type ClientStore

type ClientStore interface {
	BuildDatabase(path string)

	SaveStoredData(name string, value []byte)

	LoadStoredData(name string) []byte

	LoadAccount() map[common.Address]*Account
}

type Controller

type Controller struct {
	ID     string `json:"id"`
	Public string `json:"publicKey,omitempty"`
	keypair.ProtectedKey
}

type ExecutorData

type ExecutorData struct {
	Name       string               `json:"name"`
	Version    string               `json:"version"`
	Scrypt     *keypair.ScryptParam `json:"scrypt"`
	Identities []Identity           `json:"identities,omitempty"`
	Accounts   []*AccountData       `json:"accounts,omitempty"`
	Extra      string               `json:"extra,omitempty"`
}

func NewExecutorData

func NewExecutorData() *ExecutorData

func (*ExecutorData) AddAccount

func (this *ExecutorData) AddAccount(acc *AccountData)

func (*ExecutorData) AddIdentity

func (this *ExecutorData) AddIdentity(id *Identity)

func (*ExecutorData) Clone

func (this *ExecutorData) Clone() *ExecutorData

func (*ExecutorData) DelAccount

func (this *ExecutorData) DelAccount(address string)

func (*ExecutorData) GetAccountByAddress

func (this *ExecutorData) GetAccountByAddress(address string) (*AccountData, int)

func (*ExecutorData) GetAccountByIndex

func (this *ExecutorData) GetAccountByIndex(index int) *AccountData

func (*ExecutorData) Load

func (this *ExecutorData) Load(path string) error

func (*ExecutorData) Save

func (this *ExecutorData) Save(path string) error

func (*ExecutorData) ToDefaultSecurity

func (this *ExecutorData) ToDefaultSecurity(passwords [][]byte) error

func (*ExecutorData) ToLowSecurity

func (this *ExecutorData) ToLowSecurity(passwords [][]byte) error

type Identity

type Identity struct {
	ID      string       `json:"dnaid"`
	Label   string       `json:"label,omitempty"`
	Lock    bool         `json:"lock"`
	Control []Controller `json:"controls,omitempty"`
	Extra   interface{}  `json:"extra,omitempty"`
}

func NewIdentity

func NewIdentity(label string, keyType keypair.KeyType, param interface{}, password []byte) (*Identity, error)

Jump to

Keyboard shortcuts

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