Documentation ¶
Index ¶
- Variables
- func NewMnemonic(bits int) (string, error)
- func NewSeed() ([]byte, error)
- func NewSeedFromMnemonic(mnemonic string) ([]byte, error)
- func ParseDerivationPath(path string) (accounts.DerivationPath, error)
- func StrictParseDerivationPath(path string) accounts.DerivationPath
- type Wallet
- func (w *Wallet) Accounts() []accounts.Account
- func (w *Wallet) Address(account accounts.Account) (common.Address, error)
- func (w *Wallet) AddressBytes(account accounts.Account) ([]byte, error)
- func (w *Wallet) AddressHex(account accounts.Account) (string, error)
- func (w *Wallet) Close() error
- func (w *Wallet) Contains(account accounts.Account) bool
- func (w *Wallet) Derive(path accounts.DerivationPath, pin bool) (accounts.Account, error)
- func (w *Wallet) Open(passphrase string) error
- func (w *Wallet) Path(account accounts.Account) (string, error)
- func (w *Wallet) PrivateKey(account accounts.Account) (*ecdsa.PrivateKey, error)
- func (w *Wallet) PrivateKeyBytes(account accounts.Account) ([]byte, error)
- func (w *Wallet) PrivateKeyHex(account accounts.Account) (string, error)
- func (w *Wallet) PublicKey(account accounts.Account) (*ecdsa.PublicKey, error)
- func (w *Wallet) PublicKeyBytes(account accounts.Account) ([]byte, error)
- func (w *Wallet) PublicKeyHex(account accounts.Account) (string, error)
- func (w *Wallet) SelfDerive(base accounts.DerivationPath, chain ethereum.ChainStateReader)
- func (w *Wallet) SignHash(account accounts.Account, hash []byte) ([]byte, error)
- func (w *Wallet) SignHashWithPassphrase(account accounts.Account, passphrase string, hash []byte) ([]byte, error)
- func (w *Wallet) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)
- func (w *Wallet) SignTxWithPassphrase(account accounts.Account, passphrase string, tx *types.Transaction, ...) (*types.Transaction, error)
- func (w *Wallet) Status() (string, error)
- func (w *Wallet) URL() accounts.URL
- func (w *Wallet) Unpin(account accounts.Account) error
Constants ¶
This section is empty.
Variables ¶
var DefaultBaseDerivationPath = accounts.DefaultBaseDerivationPath
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/0, the second at m/44'/60'/0'/0/1, etc.
var DefaultRootDerivationPath = accounts.DefaultRootDerivationPath
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.
Functions ¶
func NewMnemonic ¶
Returns a randomly generated mnemonic phrase based on BIP-39. The following table describes the relation between the initial entropy length (ENT), which range from 128 to 256, the checksum length (CS) and the length of the generated mnemonic sentence (MS) in words.
CS = ENT / 32 MS = (ENT + CS) / 11
| ENT | CS | ENT+CS | MS | +-------+----+--------+------+ | 128 | 4 | 132 | 12 | | 160 | 5 | 165 | 15 | | 192 | 6 | 198 | 18 | | 224 | 7 | 231 | 21 | | 256 | 8 | 264 | 24 |
References: BIP-39:
https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
Wordlist:
https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md Note: indexed from 1 to 2^11 = 2048 Mnemonic phrases options for eight different langauges
func NewSeedFromMnemonic ¶
Returns a new seed from BIP-39 mnemonic phrases.
func ParseDerivationPath ¶
func ParseDerivationPath(path string) (accounts.DerivationPath, error)
Convert the derivation path string to []uint32
func StrictParseDerivationPath ¶
func StrictParseDerivationPath(path string) accounts.DerivationPath
Same as the ParseDerivationPath(path string), but will be panic to any error
Types ¶
type Wallet ¶
type Wallet struct {
// contains filtered or unexported fields
}
---------------- Define the Wallet structure ---------------- FILEDS: @mnemonic: a string of mnemonic phrase separated by spaces. @masterKey: ExtendedKey houses all the information needed to support a hierarchical deterministic extended key. See the package overview documentation for more details on how to use extended keys. We can use the IsPrivate function in hdkeychain package to determine whether an extended key is a private or public key. A private extended key can be used to derive both hardened and non-hardened (normal) child private and public extented key. Which can be used to prevent the case that exploiting one child key leads to the exploitation of all of its siblings. @seed: the byte array seed. @url: type URL struct { Scheme string // Protocol scheme to identify a capable account backend Path string // Path for the backend to identify a unique entity } // Note: it doesn't do any URL encoding/decoding of special characters. @paths: map from common go-ethereum address type to derivation path type. type DerivationPath []uint32 5 levels of hierarchies: m / purpose' / coin_type' / account' / change / address_index Note: see the "address structure" note above. type Address [AddressLength]byte Note: Address represents the 20 byte address of an Ethereum account. @accounts: type Account struct { Address common.Address `json:"address"` // Ethereum account address derived from the key URL URL `json:"url"` // Optional resource locator within a backend } @stateLock: reader/writer mutual exclusion lock that can be held by an arbitrary number of readers or a single writer. The zero value for a RWMutex is an unlocked mutex. Note: A RWMutex must not be copied after first use.
func NewFromMnemonic ¶
INPUT: @mnemonic: the mnemonic phrases string seperated by whitespaces.
OUTPUT: Returns a new wallet from a BIP-39 mnemonic.
func NewFromSeed ¶
INPUT: @seed: an array of seeds used for generating a new wallet
OUTPUT: Returns a new wallet based on the given seed
func (*Wallet) Accounts ¶
Retrieves the list of signing accounts the wallet currently holds. For the hierarchical deterministic wallets, this list will only display the accounts be explicitly pinned during account derivation.
func (*Wallet) AddressBytes ¶
Return the address in byte format.
func (*Wallet) AddressHex ¶
Return the address in hexadecimal format.
func (*Wallet) Derive ¶
@path: the path to be used to derive a hierarchical deterministic account. @pin: determine if this new account will be pinned to the wallet's tracking
account list.
func (*Wallet) Open ¶
Open the wallet instance and build access. Not used for unlocking or decrypting account keys.
@passphrase: In the hard ware wallet implementation, the pass phrase in here is optional, and can be empty.
Note: need to be manually closed to free the allocated resources, esp. for hardware wallets.
func (*Wallet) PrivateKey ¶
@account: using this account to derivate the private key. Obtain the private key through the ECDSA (Elliptic Curve Digital Signature Algorithm)
func (*Wallet) PrivateKeyBytes ¶
@account: using this account to derivate the private key. Returns the ECDSA private key in bytes format.
func (*Wallet) PrivateKeyHex ¶
@account: using this account to derivate the private key. Returns the ECDSA private key in hexadecimal format.
func (*Wallet) PublicKeyBytes ¶
Returns the public key of the account based on the ECDSA in bytes format.
func (*Wallet) PublicKeyHex ¶
Returns the public key of the account based on the ECDSA in hexadecimal format.
func (*Wallet) SelfDerive ¶
func (w *Wallet) SelfDerive(base accounts.DerivationPath, chain ethereum.ChainStateReader)
@path: the path to be used to derive a hierarchical deterministic account. @chain: ChainStateReader wraps access to the state trie of the canonical blockchain. Reference to the interface:
https://github.com/ethereum/go-ethereum/blob/master/interfaces.go
Sets a base account derivation path from which the wallet tries to discover non zero accounts and automatically add them to the list of tracking accounts.
func (*Wallet) SignHashWithPassphrase ¶
func (w *Wallet) SignHashWithPassphrase(account accounts.Account, passphrase string, hash []byte) ([]byte, error)
Request the wallet to sign the given hash with the account. Using the passphrase as an extra layer of authetication information.
func (*Wallet) SignTx ¶
func (w *Wallet) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)
Using the account and chainID to sign the given transaction tx.
func (*Wallet) SignTxWithPassphrase ¶
func (w *Wallet) SignTxWithPassphrase(account accounts.Account, passphrase string, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)
Requests the wallet to sign the given transaction with the given passphrase as an extra layer of authetication information.
func (*Wallet) Status ¶
Returning a custom status message to help the user in the current state of the wallet.