vault

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PurposeBLS12381         = uint32(12381)
	PurposeBIP44            = uint32(44)
	PurposeImportPrivateKey = uint32(65535)

	PurposeBLS12381Hardened         = PurposeBLS12381 + addresspath.HardenedKeyStart
	PurposeBIP44Hardened            = PurposeBIP44 + addresspath.HardenedKeyStart
	PurposeImportPrivateKeyHardened = PurposeImportPrivateKey + addresspath.HardenedKeyStart
)
View Source
const AddressGapLimit = 8

AddressGapLimit is the maximum number of consecutive inactive addresses before stopping recovery.

Variables

View Source
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

func CheckMnemonic(mnemonic string) error

CheckMnemonic validates a mnemonic (seed phrase) based on BIP-39.

func GenerateMnemonic

func GenerateMnemonic(bitSize int) (string, error)

GenerateMnemonic generates a new mnemonic (seed phrase) based on BIP-39 https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki

func NewErrAddressNotFound

func NewErrAddressNotFound(addr string) error

Types

type AddressInfo

type AddressInfo struct {
	Address   string `json:"address"`    // Address in the wallet
	PublicKey string `json:"public_key"` // Public key associated with the address
	Label     string `json:"label"`      // Label for the address
	Path      string `json:"path"`       // Path for the address
}

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 CreateVaultFromMnemonic(mnemonic string, coinType uint32) (*Vault, error)

func (*Vault) AddressCount

func (v *Vault) AddressCount() int

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) Contains

func (v *Vault) Contains(addr string) bool

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 (v *Vault) IsEncrypted() bool

func (*Vault) IsNeutered

func (v *Vault) IsNeutered() bool

func (*Vault) Label

func (v *Vault) Label(addr string) string

func (*Vault) Mnemonic

func (v *Vault) Mnemonic(password string) (string, error)

func (*Vault) MnemonicSeed

func (v *Vault) MnemonicSeed(password string) ([]byte, error)

func (*Vault) Neuter

func (v *Vault) Neuter() *Vault

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

func (v *Vault) PrivateKeys(password string, addrs []string) ([]crypto.PrivateKey, error)

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.

func (*Vault) SetLabel

func (v *Vault) SetLabel(addr, label string) error

func (*Vault) UpdatePassword

func (v *Vault) UpdatePassword(oldPassword, newPassword string, opts ...encrypter.Option) error

type VaultType added in v0.2.0

type VaultType int

VaultType represents the type of vault.

const (
	TypeFull     VaultType = iota + 1 // Full vault with private keys.
	TypeNeutered                      // Neutered vault without private keys.
)

func (VaultType) String added in v0.2.0

func (vt VaultType) String() string

String returns the string representation of the VaultType.

Jump to

Keyboard shortcuts

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