wallet

package
v0.0.7-alphanet Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: GPL-3.0 Imports: 24 Imported by: 6

Documentation

Index

Constants

View Source
const (
	ZenonAccountPathFormat = "m/44'/73404'/%d'"
	FirstHardenedIndex     = uint32(0x80000000)
)
View Source
const (
	DefaultMaxIndex = 128
)

Variables

View Source
var (
	ErrKeyFileInvalidVersion = errors.New("unable to read KeyFile. Invalid version")
	ErrKeyFileInvalidCipher  = errors.New("unable to read KeyFile. Invalid cipherName")
	ErrKeyFileInvalidKDF     = errors.New("unable to read KeyFile. Invalid key derivation function (KDF)")

	ErrAddressNotFound = errors.New("the provided address could not be derived from the key store")
	ErrWrongPassword   = errors.New("the key store could not be decrypted with the provided password")

	ErrKeyStoreLocked   = errors.New("the key store is locked")
	ErrKeyStoreNotFound = errors.New("the provided key store could not be found in the data directory")

	ErrInvalidPath        = errors.New("invalid derivation path")
	ErrNoPublicDerivation = errors.New("no public derivation for ed25519")
)

Functions

func GetEntropyCSPRNG

func GetEntropyCSPRNG(n int) []byte

func VerifySignature

func VerifySignature(pubkey ed25519.PublicKey, message, sig []byte) (bool, error)

Types

type Config

type Config struct {
	WalletDir      string
	MaxSearchIndex uint32
}

type KeyFile

type KeyFile struct {
	Path string

	BaseAddress types.Address `json:"baseAddress"`
	Crypto      cryptoParams  `json:"crypto"`
	Version     int           `json:"version"`
	Timestamp   int64         `json:"timestamp"`
}

func ReadKeyFile

func ReadKeyFile(path string) (*KeyFile, error)

func (*KeyFile) Decrypt

func (kf *KeyFile) Decrypt(password string) (*KeyStore, error)

func (*KeyFile) Write

func (kf *KeyFile) Write() error

type KeyPair

type KeyPair struct {
	Public  ed25519.PublicKey
	Private ed25519.PrivateKey
	Address types.Address
}

func DeriveForPath

func DeriveForPath(path string, seed []byte) (*KeyPair, error)

DeriveForPath derives key for chain path in BIP-44 format and chain seed. Ed25119 derivation operated on hardened keys only.

func DeriveWithIndex

func DeriveWithIndex(i uint32, seed []byte) (*KeyPair, error)

func (*KeyPair) Sign

func (kp *KeyPair) Sign(message []byte) []byte

func (*KeyPair) Signer

func (kp *KeyPair) Signer(data []byte) (signedData []byte, address *types.Address, pubkey []byte, err error)

type KeyStore

type KeyStore struct {
	Entropy  []byte
	Seed     []byte
	Mnemonic string

	BaseAddress types.Address
}

func (*KeyStore) DeriveForFullPath

func (ks *KeyStore) DeriveForFullPath(ipath string) (path string, key *KeyPair, err error)

func (*KeyStore) DeriveForIndexPath

func (ks *KeyStore) DeriveForIndexPath(index uint32) (path string, key *KeyPair, err error)

func (*KeyStore) Encrypt

func (ks *KeyStore) Encrypt(password string) (*KeyFile, error)

func (*KeyStore) FindAddress

func (ks *KeyStore) FindAddress(address types.Address) (key *KeyPair, index uint32, err error)

func (*KeyStore) Zero

func (ks *KeyStore) Zero()

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func New

func New(config *Config) *Manager

func (*Manager) GetKeyFile

func (m *Manager) GetKeyFile(path string) (*KeyFile, error)

func (*Manager) GetKeyFileAndDecrypt

func (m *Manager) GetKeyFileAndDecrypt(path, password string) (*KeyStore, error)

func (*Manager) GetKeyStore

func (m *Manager) GetKeyStore(path string) (*KeyStore, error)

func (*Manager) IsUnlocked

func (m *Manager) IsUnlocked(path string) (bool, error)

func (*Manager) ListEntropyFilesInStandardDir

func (m *Manager) ListEntropyFilesInStandardDir() ([]*KeyFile, error)

ListEntropyFilesInStandardDir reads them from the disk

func (*Manager) Lock

func (m *Manager) Lock(path string)

func (*Manager) MakePathAbsolut

func (m *Manager) MakePathAbsolut(path string) string

func (*Manager) Start

func (m *Manager) Start() error

func (*Manager) Stop

func (m *Manager) Stop()

func (*Manager) Unlock

func (m *Manager) Unlock(path, password string) error

Unlock also adds keyFile to encrypted if not present

Jump to

Keyboard shortcuts

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