Documentation
¶
Index ¶
- Constants
- Variables
- func CheckMnemonic(mnemonic string) error
- func GenerateMnemonic(bitSize int) (string, error)
- func NewErrAddressNotFound(addr string) error
- type AddressInfo
- type AddressNotFoundError
- type Vault
- func (v *Vault) AddressCount() int
- func (v *Vault) AddressFromPath(p string) *AddressInfo
- func (v *Vault) AddressInfo(addr string) *AddressInfo
- func (v *Vault) AddressInfos() []AddressInfo
- func (v *Vault) AllAccountAddresses() []AddressInfo
- func (v *Vault) AllValidatorAddresses() []AddressInfo
- func (v *Vault) Contains(addr string) bool
- func (v *Vault) ImportBLSPrivateKey(password string, prv *bls.PrivateKey) error
- func (v *Vault) ImportEd25519PrivateKey(password string, prv *ed25519.PrivateKey) error
- func (v *Vault) IsEncrypted() bool
- func (v *Vault) IsNeutered() bool
- func (v *Vault) Label(addr string) string
- func (v *Vault) Mnemonic(password string) (string, error)
- func (v *Vault) MnemonicSeed(password string) ([]byte, error)
- func (v *Vault) Neuter() *Vault
- func (v *Vault) NewBLSAccountAddress(label string) (*AddressInfo, error)
- func (v *Vault) NewEd25519AccountAddress(label, password string) (*AddressInfo, error)
- func (v *Vault) NewValidatorAddress(label string) (*AddressInfo, error)
- func (v *Vault) PrivateKeys(password string, addrs []string) ([]crypto.PrivateKey, error)
- func (v *Vault) RecoverAddresses(ctx context.Context, password string, ...) error
- func (v *Vault) SetLabel(addr, label string) error
- func (v *Vault) UpdatePassword(oldPassword, newPassword string, opts ...encrypter.Option) error
- type VaultType
Constants ¶
const ( PurposeBLS12381 = uint32(12381) PurposeBIP44 = uint32(44) PurposeImportPrivateKey = uint32(65535) PurposeBLS12381Hardened = PurposeBLS12381 + addresspath.HardenedKeyStart PurposeBIP44Hardened = PurposeBIP44 + addresspath.HardenedKeyStart PurposeImportPrivateKeyHardened = PurposeImportPrivateKey + addresspath.HardenedKeyStart )
const AddressGapLimit = 8
AddressGapLimit is the maximum number of consecutive inactive addresses before stopping recovery.
Variables ¶
var ( // ErrAddressExists describes an error in which the address already exist // in wallet. ErrAddressExists = errors.New("address already exists") // ErrInvalidPath describes an error in which the key path is invalid. ErrInvalidPath = errors.New("the key path is invalid") // ErrNeutered describes an error in which the wallet is neutered. ErrNeutered = errors.New("wallet is neutered") // ErrInvalidCoinType describes an error in which the coin type is not valid. ErrInvalidCoinType = errors.New("invalid coin type") // ErrUnsupportedPurpose describes an error in which the purpose is not supported. ErrUnsupportedPurpose = errors.New("unsupported purpose") )
Functions ¶
func CheckMnemonic ¶
CheckMnemonic validates a mnemonic (seed phrase) based on BIP-39.
func GenerateMnemonic ¶
GenerateMnemonic generates a new mnemonic (seed phrase) based on BIP-39 https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
func NewErrAddressNotFound ¶
Types ¶
type AddressInfo ¶
type AddressNotFoundError ¶
type AddressNotFoundError struct {
// contains filtered or unexported fields
}
AddressNotFoundError describes an error in which the address doesn't exist in wallet.
func (AddressNotFoundError) Error ¶
func (e AddressNotFoundError) Error() string
type Vault ¶
type Vault struct {
Type VaultType `json:"type"` // Vault type: Full or Neutered
CoinType uint32 `json:"coin_type"` // Coin type: 21888 for Mainnet, 21777 for Testnet
DefaultFee amount.Amount `json:"default_fee"` // The Vault's default fee
Addresses map[string]AddressInfo `json:"addresses"` // All addresses that are stored in the vault
Encrypter encrypter.Encrypter `json:"encrypter"` // Encryption algorithm
KeyStore string `json:"key_store"` // KeyStore that stores the secrets and encrypts using Encrypter
Purposes purposes `json:"purposes"` // Contains Purposes of the vault
}
func CreateVaultFromMnemonic ¶
func (*Vault) AddressCount ¶
func (*Vault) AddressFromPath ¶
func (v *Vault) AddressFromPath(p string) *AddressInfo
func (*Vault) AddressInfo ¶
func (v *Vault) AddressInfo(addr string) *AddressInfo
AddressInfo like it can return bls.PublicKey instead of string.
func (*Vault) AddressInfos ¶
func (v *Vault) AddressInfos() []AddressInfo
func (*Vault) AllAccountAddresses ¶
func (v *Vault) AllAccountAddresses() []AddressInfo
func (*Vault) AllValidatorAddresses ¶
func (v *Vault) AllValidatorAddresses() []AddressInfo
func (*Vault) ImportBLSPrivateKey ¶
func (v *Vault) ImportBLSPrivateKey(password string, prv *bls.PrivateKey) error
func (*Vault) ImportEd25519PrivateKey ¶
func (v *Vault) ImportEd25519PrivateKey(password string, prv *ed25519.PrivateKey) error
func (*Vault) IsEncrypted ¶
func (*Vault) IsNeutered ¶
func (*Vault) NewBLSAccountAddress ¶
func (v *Vault) NewBLSAccountAddress(label string) (*AddressInfo, error)
func (*Vault) NewEd25519AccountAddress ¶
func (v *Vault) NewEd25519AccountAddress(label, password string) (*AddressInfo, error)
func (*Vault) NewValidatorAddress ¶
func (v *Vault) NewValidatorAddress(label string) (*AddressInfo, error)
func (*Vault) PrivateKeys ¶
PrivateKeys retrieves the private keys for the given addresses using the provided password.
func (*Vault) RecoverAddresses ¶ added in v0.2.0
func (v *Vault) RecoverAddresses(ctx context.Context, password string, hasActivity func(addr string) (bool, error), ) error
RecoverAddresses restores all previously used addresses when a wallet is recovered from a mnemonic phrase. This function attempts to recover both BLS and Ed25519 account addresses. If the wallet is empty, Ed25519 is used as the default address type.
An address is considered active if its public key is present in the blockchain database. The hasActivity callback should return true if the address has been used previously.
Limitation: If more than 8 consecutive unused addresses exist between used addresses, automatic recovery will stop at the gap. In such cases, manual address creation is required to recover additional addresses.