account

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const AccountFileName = "accounts.db"

Variables

View Source
var (
	ErrInvalidPassword = errors.New("invalid password")
)

Functions

func NewDerivationPath

func NewDerivationPath(accountIndex uint64) string

NewDerivationPath returns derivation path for given account index

Types

type Account

type Account struct {
	AccountIndex uint64
	AccountKeys  KeyHashes
}

func NewAccount

func NewAccount(idx uint64, key AccountKey) *Account

type AccountKey

type AccountKey struct {
	PubKey         []byte     `json:"pubKey"` // compressed secp256k1 key 33 bytes
	PrivKey        []byte     `json:"privKey"`
	PubKeyHash     *KeyHashes `json:"pubKeyHash"`
	DerivationPath []byte     `json:"derivationPath"`
}

func NewAccountKey

func NewAccountKey(masterKey *hdkeychain.ExtendedKey, derivationPath string) (*AccountKey, error)

NewAccountKey generates new account key from given master key and derivation path

type Db

type Db interface {
	Do() TxContext
	WithTransaction(func(tx TxContext) error) error
	Close() error
}

type KeyHashes

type KeyHashes struct {
	Sha256 []byte `json:"sha256"`
}

func NewKeyHash

func NewKeyHash(key []byte) *KeyHashes

NewKeyHash creates sha256/sha512 hash pair from given key

type Keys

type Keys struct {
	Mnemonic   string
	MasterKey  *hdkeychain.ExtendedKey
	AccountKey *AccountKey
}

func NewKeys

func NewKeys(mnemonic string) (*Keys, error)

NewKeys generates new wallet keys from given mnemonic seed, or generates mnemonic first if empty string is provided

type Manager

type Manager interface {
	GetAll() []Account
	CreateKeys(mnemonic string) error
	AddAccount() (uint64, []byte, error)
	GetMnemonic() (string, error)
	GetAccountKey(uint64) (*AccountKey, error)
	GetAccountKeys() ([]*AccountKey, error)
	GetMaxAccountIndex() (uint64, error)
	GetPublicKey(accountIndex uint64) ([]byte, error)
	GetPublicKeys() ([][]byte, error)
	Close()
}

Manager manages accounts

func NewManager

func NewManager(dir string, password string, create bool) (Manager, error)

type TxContext

type TxContext interface {
	AddAccount(accountIndex uint64, key *AccountKey) error
	GetAccountKey(accountIndex uint64) (*AccountKey, error)
	GetAccountKeys() ([]*AccountKey, error)
	GetMaxAccountIndex() (uint64, error)
	SetMaxAccountIndex(accountIndex uint64) error

	GetMasterKey() (string, error)
	SetMasterKey(masterKey string) error

	GetMnemonic() (string, error)
	SetMnemonic(mnemonic string) error

	IsEncrypted() (bool, error)
	SetEncrypted(encrypted bool) error
	VerifyPassword() (bool, error)
}

Jump to

Keyboard shortcuts

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