wallet

package
v0.0.0-...-7abacdd Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: Unlicense Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatBalance

func FormatBalance(balance int, unit string) string

FormatBalance converts the balance to the denomination specified and returns a string with the value and the unit.

Initially, balance is represented in satoshis.

func ValidateAddress

func ValidateAddress(address string) error

ValidateAddress checks if address is valid.

Types

type Account

type Account struct {
	// Use one mutex for both maps as they are accessed
	PrivKey            *Key
	PubKey             *Key
	ChangeAddresses    map[string]struct{}
	ReceivingAddresses map[string]struct{}
	NextKeyIndex       uint32
}

Account contains a master key and the name the user has chosen to identify it.

func NewAccount

func NewAccount(masterKey *Key) *Account

NewAccount returns a new account with the key provided.

func (*Account) NewAddress

func (a *Account) NewAddress(receiving bool) (string, error)

NewAddress returns an address corresponding to the account that hasn't been used before.

If receiving is false, the address will be marked as a change address.

func (*Account) NewAddresses

func (a *Account) NewAddresses() ([]string, error)

NewAddresses returns a list of receiving addresses. Change addresses are handled internally.

func (*Account) PrivateKey

func (a *Account) PrivateKey() *ecdsa.PrivateKey

PrivateKey returns the private key of an account.

func (*Account) PublicKey

func (a *Account) PublicKey() []byte

PublicKey returns the public key of an account.

func (*Account) UsedAddresses

func (a *Account) UsedAddresses() []string

UsedAddresses returns receiving and change addresses that were utilizied.

type Key

type Key struct {
	// Version bytes (4 bytes)
	Vbytes []byte
	// Fingerprint of the parent's key (4 bytes)
	Fingerprint []byte
	// Child number (4 bytes)
	ChildNumber []byte
	// Chain code (32 bytes)
	Chaincode []byte
	// Public/Private key data (33 bytes)
	Key []byte
	// Depth (1 byte)
	Depth uint16
}

Key defines the components of a hierarchical deterministic wallet master key.

func DeserializeKey

func DeserializeKey(data []byte) (*Key, error)

DeserializeKey takes a byte slice and creates a Key.

func NewMasterKey

func NewMasterKey(seed []byte) (*Key, error)

NewMasterKey returns a new master key given a random seed.

func (*Key) Address

func (k *Key) Address() string

Address returns the wallet's address.

func (*Key) Child

func (k *Key) Child(i uint32) (*Key, error)

Child returns the ith child of a key.

func (*Key) Public

func (k *Key) Public() *Key

Public returns the public key version of the key.

func (*Key) Serialize

func (k *Key) Serialize() []byte

Serialize returns the encoded version of Key.

type Wallet

type Wallet struct {
	MasterKey *Key
	// map[name]Account
	Accounts       map[string]*Account
	NextChildIndex uint32
}

Wallet represents a hierarchical deterministic wallet.

func Load

func Load() (*Wallet, error)

Load loads the wallet from persistent storage.

Call Save to write the Wallet's changes to persistent storage when done.

func NewWallet

func NewWallet(mnemonic, passphrase string) (*Wallet, error)

NewWallet creates a new wallet.

func (*Wallet) Account

func (w *Wallet) Account(name string) *Account

Account returns an account with the given name.

func (*Wallet) AccountExists

func (w *Wallet) AccountExists(name string) bool

AccountExists returns whether the account exists or not.

func (*Wallet) AccountNames

func (w *Wallet) AccountNames() []string

AccountNames returns the wallet accounts.

func (*Wallet) NewAccount

func (w *Wallet) NewAccount(name string) (*Account, error)

NewAccount creates a new account.

func (*Wallet) Save

func (w *Wallet) Save() error

Save stores the wallet structure into persistent storage. The file is left unencrypted on purpose so it's easier to read its content.

Save should be always called after a change in it or in an account.

Jump to

Keyboard shortcuts

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