accounts

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2019 License: LGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Opened = "Opened"
	Closed = "Closed"
)

wallet status

View Source
const (
	RefreshWalletInfoDuration time.Duration = time.Second * 60
)

refresh wallet nonce in the wallet manager timely

Variables

View Source
var DefaultBaseDerivationPath = DerivationPath{0x80000000 + 44, 0x80000000 + 60, 0x80000000 + 0, 0, 0}

DefaultBaseDerivationPath is the base path from which custom derivation endpoints are incremented. As such, the first account will be at m/44'/60'/0'/0, the second at m/44'/60'/0'/1, etc.

View Source
var DefaultLedgerBaseDerivationPath = DerivationPath{0x80000000 + 44, 0x80000000 + 60, 0x80000000 + 0, 0}

DefaultLedgerBaseDerivationPath is the base path from which custom derivation endpoints are incremented. As such, the first account will be at m/44'/60'/0'/0, the second at m/44'/60'/0'/1, etc.

View Source
var DefaultRootDerivationPath = DerivationPath{0x80000000 + 44, 0x80000000 + 60, 0x80000000 + 0, 0}

DefaultRootDerivationPath is the root path to which custom derivation endpoints are appended. As such, the first account will be at m/44'/60'/0'/0, the second at m/44'/60'/0'/1, etc.

View Source
var ErrAESDecryption = errors.New("AES decryption operation error")
View Source
var ErrAESInvalidParameter = errors.New("AES operation parameter error")
View Source
var ErrAddressBalanceNotEnough = errors.New("the address balance isn't enough when wallet send transaction")
View Source
var ErrAnalysisDerivedPath = errors.New("invalid Derived Path")
View Source
var ErrDeleteWalletFile = errors.New("delete wallet error")
View Source
var ErrDeriveKey = errors.New("symmetric key derivation error")
View Source
var ErrEmptySign = errors.New("empty sign")
View Source
var ErrInvalidAddress = errors.New("invalid address")
View Source
var ErrInvalidDerivedPath = errors.New("invalid derived path")
View Source
var ErrInvalidKDFParameter = errors.New("invalid KDFParameter")
View Source
var ErrMacAuthentication = errors.New("MAC authentication error")
View Source
var ErrNotFindWallet = errors.New("not find the wallet")
View Source
var ErrNotSupportUsbWallet = errors.New("not support USB wallet")
View Source
var ErrNotSupported = errors.New("not supported")
View Source
var ErrPasswordIsNil = errors.New("password is nil")
View Source
var ErrSignatureInvalid = errors.New("verify signature fail")
View Source
var ErrWalletFileExist = errors.New("wallet file exist")
View Source
var ErrWalletFileNotExist = errors.New("wallet file doesn't exist")
View Source
var ErrWalletNotOpen = errors.New("wallet isn't open")
View Source
var ErrWalletPasswordNotValid = errors.New("wallet password error")
View Source
var ErrWalletPathError = errors.New("the path should be in the home path")
View Source
var ErrWalletSendTransaction = errors.New("wallet send transaction error")

Functions

This section is empty.

Types

type Account

type Account struct {
	Address common.Address
}

type AddressInfoReader

type AddressInfoReader interface {
	CurrentBalance(address common.Address) *big.Int
	GetTransactionNonce(addr common.Address) (nonce uint64, err error)
}

type DerivationPath

type DerivationPath []uint32

DerivationPath represents the computer friendly version of a hierarchical deterministic wallet account derivaion path.

The BIP-32 spec https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki defines derivation paths to be of the form:

m / purpose' / coin_type' / account' / change / address_index

The BIP-44 spec https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki defines that the `purpose` be 44' (or 0x8000002C) for crypto currencies, and SLIP-44 https://github.com/satoshilabs/slips/blob/master/slip-0044.md assigns the `coin_type` 60' (or 0x8000003C) to Ethereum.

The root path for Ethereum is m/44'/60'/0'/0 according to the specification from https://github.com/ethereum/EIPs/issues/84, albeit it's not set in stone yet whether accounts should increment the last component or the children of that. We will go with the simpler approach of incrementing the last component.

func ParseDerivationPath

func ParseDerivationPath(path string) (DerivationPath, error)

ParseDerivationPath converts a user specified derivation path string to the internal binary representation.

Full derivation paths need to start with the `m/` prefix, relative derivation paths (which will get appended to the default root path) must not have prefixes in front of the first element. Whitespace is ignored.

func (DerivationPath) String

func (path DerivationPath) String() string

String implements the stringer interface, converting a binary derivation path to its canonical representation.

type Wallet

type Wallet interface {

	//get wallet identifier include type and file path
	GetWalletIdentifier() (WalletIdentifier, error)

	//get wallet status to judge if is locked
	Status() (string, error)

	//establish wallet according to password,return mnemonic
	Establish(path, name, password, passPhrase string) (string, error)

	//restore wallet from mnemonic
	RestoreWallet(path, name, password, passPhrase, mnemonic string, GetAddressRelatedInfo AddressInfoReader) (err error)

	//open
	Open(path, name, password string) error

	//close
	Close() error

	//padding address nonce
	PaddingAddressNonce(GetAddressRelatedInfo AddressInfoReader) (err error)

	//get address nonce
	GetAddressNonce(address common.Address) (nonce uint64, err error)

	//set address nonce
	SetAddressNonce(address common.Address, nonce uint64) (err error)

	//return the accounts in the wallet
	Accounts() ([]Account, error)

	//check if the account is in the wallet
	Contains(account Account) (bool, error)

	//generate new account according to the derived path
	Derive(path DerivationPath, pin bool) (Account, error)

	//find the used account of base and add to the wallet
	SelfDerive(base DerivationPath) error

	//sign hash
	SignHash(account Account, hash []byte) ([]byte, error)

	//get pk form account
	GetPKFromAddress(account Account) (*ecdsa.PublicKey, error)

	//get sk form address
	GetSKFromAddress(address common.Address) (*ecdsa.PrivateKey, error)

	//sign transaction
	SignTx(account Account, tx *model.Transaction, chainID *big.Int) (*model.Transaction, error)

	//generate vrf proof
	Evaluate(account Account, seed []byte) (index [32]byte, proof []byte, err error)
}

type WalletEvent

type WalletEvent struct {
	Wallet Wallet          // Wallet instance arrived or departed
	Type   WalletEventType // Event type that happened in the system
}

record wallet backend event

type WalletEventType

type WalletEventType int

wallet event type

const (
	//establish wallet
	//default wallet event channel is 0, so there will be an problem if it is 0
	WalletArrived WalletEventType = 1 + iota

	//open wallet
	WalletOpened

	//remove wallet
	WalletDropped
)

type WalletIdentifier

type WalletIdentifier struct {
	WalletType `json:"walletType"`
	//wallet file path
	Path       string `json:"path"`
	WalletName string `json:"walletName"`
}

type WalletManager

type WalletManager struct {
	Wallets               []Wallet          //wallets
	GetAddressRelatedInfo AddressInfoReader //get nonce and balance of the account
	Event                 chan WalletEvent  //listen wallet event
	HandleResult          chan bool         //event handle result
	ManagerClose          chan bool         //listen the manger close

	Lock sync.RWMutex
	// contains filtered or unexported fields
}

func NewWalletManager

func NewWalletManager(getAddressInfo AddressInfoReader, wallets ...Wallet) (*WalletManager, error)

new wallet manager

func (*WalletManager) FindWalletFromAddress

func (manager *WalletManager) FindWalletFromAddress(address common.Address) (Wallet, error)

get wallet from account address

func (*WalletManager) FindWalletFromIdentifier

func (manager *WalletManager) FindWalletFromIdentifier(identifier WalletIdentifier) (Wallet, error)

get wallet according to he wallet id

func (*WalletManager) ListWalletIdentifier

func (manager *WalletManager) ListWalletIdentifier() ([]WalletIdentifier, error)

list all wallet identifier in the wallet manager

func (*WalletManager) Start

func (manager *WalletManager) Start() error

func (*WalletManager) Stop

func (manager *WalletManager) Stop()

close wallet manager

type WalletSigner

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

func MakeWalletSigner

func MakeWalletSigner(addr common.Address, wm *WalletManager) *WalletSigner

func (*WalletSigner) Evaluate

func (signer *WalletSigner) Evaluate(account Account, seed []byte) (index [32]byte, proof []byte, err error)

func (*WalletSigner) GetAddress

func (signer *WalletSigner) GetAddress() common.Address

func (*WalletSigner) PublicKey

func (signer *WalletSigner) PublicKey() *ecdsa.PublicKey

func (*WalletSigner) SetBaseAddress

func (signer *WalletSigner) SetBaseAddress(address common.Address)

func (*WalletSigner) SignHash

func (signer *WalletSigner) SignHash(hash []byte) ([]byte, error)

func (*WalletSigner) ValidSign

func (signer *WalletSigner) ValidSign(hash []byte, pubKey []byte, sign []byte) error

type WalletType

type WalletType int
const (
	SoftWallet WalletType = iota

	LedgerWallet

	TrezorWallet
)

Directories

Path Synopsis
copy form "btcutil/hdkeychain/extendedkey.go", delete some unused function and change some functions to adapt Dipperin
copy form "btcutil/hdkeychain/extendedkey.go", delete some unused function and change some functions to adapt Dipperin

Jump to

Keyboard shortcuts

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