Documentation ¶
Index ¶
- Constants
- Variables
- type Account
- type AddressInfoReader
- type DerivationPath
- type Wallet
- type WalletEvent
- type WalletEventType
- type WalletIdentifier
- type WalletManager
- func (manager *WalletManager) FindWalletFromAddress(address common.Address) (Wallet, error)
- func (manager *WalletManager) FindWalletFromIdentifier(identifier WalletIdentifier) (Wallet, error)
- func (manager *WalletManager) ListWalletIdentifier() ([]WalletIdentifier, error)
- func (manager *WalletManager) Start() error
- func (manager *WalletManager) Stop()
- type WalletSigner
- func (signer *WalletSigner) Evaluate(account Account, seed []byte) (index [32]byte, proof []byte, err error)
- func (signer *WalletSigner) GetAddress() common.Address
- func (signer *WalletSigner) PublicKey() *ecdsa.PublicKey
- func (signer *WalletSigner) SetBaseAddress(address common.Address)
- func (signer *WalletSigner) SignHash(hash []byte) ([]byte, error)
- func (signer *WalletSigner) ValidSign(hash []byte, pubKey []byte, sign []byte) error
- type WalletType
Constants ¶
const ( Opened = "Opened" Closed = "Closed" )
wallet status
const (
RefreshWalletInfoDuration time.Duration = time.Second * 60
)
refresh wallet nonce in the wallet manager timely
Variables ¶
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.
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.
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.
var ErrAESDecryption = errors.New("AES decryption operation error")
var ErrAESInvalidParameter = errors.New("AES operation parameter error")
var ErrAddressBalanceNotEnough = errors.New("the address balance isn't enough when wallet send transaction")
var ErrAnalysisDerivedPath = errors.New("invalid Derived Path")
var ErrDeleteWalletFile = errors.New("delete wallet error")
var ErrDeriveKey = errors.New("symmetric key derivation error")
var ErrEmptySign = errors.New("empty sign")
var ErrInvalidAddress = errors.New("invalid address")
var ErrInvalidDerivedPath = errors.New("invalid derived path")
var ErrInvalidKDFParameter = errors.New("invalid KDFParameter")
var ErrMacAuthentication = errors.New("MAC authentication error")
var ErrNotFindWallet = errors.New("not find the wallet")
var ErrNotSupportUsbWallet = errors.New("not support USB wallet")
var ErrNotSupported = errors.New("not supported")
var ErrPasswordIsNil = errors.New("password is nil")
var ErrSignatureInvalid = errors.New("verify signature fail")
var ErrWalletFileExist = errors.New("wallet file exist")
var ErrWalletFileNotExist = errors.New("wallet file doesn't exist")
var ErrWalletNotOpen = errors.New("wallet isn't open")
var ErrWalletPasswordNotValid = errors.New("wallet password error")
var ErrWalletPathError = errors.New("the path should be in the home path")
var ErrWalletSendTransaction = errors.New("wallet send transaction error")
Functions ¶
This section is empty.
Types ¶
type AddressInfoReader ¶
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
type WalletSigner ¶
type WalletSigner struct {
// contains filtered or unexported fields
}
func MakeWalletSigner ¶
func MakeWalletSigner(addr common.Address, wm *WalletManager) *WalletSigner
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)
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 |