wallet

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SecretKeyLength           = 32
	PBKDF2NbRound             = 600_000
	FileModeUserReadWriteOnly = 0o600
	Base58Version             = 0x00
	UserAddressPrefix         = "AU"
	PublicKeyPrefix           = "P"
	PrivateKeyPrefix          = "S"
	MaxNicknameLength         = 32
)

Variables

This section is empty.

Functions

func AddressIsUnique

func AddressIsUnique(address string) error

func CheckAlphanumeric

func CheckAlphanumeric(str string) bool

func DeleteAccount

func DeleteAccount(nickname string) error

func ErrorAccountNotFound

func ErrorAccountNotFound(nickname string) error

func FilePath

func FilePath(nickname string) (string, error)

FilePath returns the wallet file path base on the given nickname. Files are stored in

func Filename

func Filename(nickname string) string

filename returns the wallet filename based on the given nickname.

func Generate

func Generate(nickname string, password string) (*Wallet, *WalletError)

Generate instantiates a new wallet, protects its private key and persists it. Everything is dynamically generated except from the nickname.

func GetWalletDir

func GetWalletDir() (string, error)

GetWalletDir returns the path where the account yaml file are stored. Note: the wallet directory is the folder where the wallet plugin binary resides.

func GetWorkDir

func GetWorkDir() (string, error)

func Import

func Import(nickname string, privateKeyB58V string, password string) (*Wallet, *WalletError)

func LoadFile

func LoadFile(filePath string) (Wallet, *WalletError)

func NicknameIsUnique

func NicknameIsUnique(nickname string) error

func NicknameIsValid

func NicknameIsValid(nickname string) bool

NicknameIsValid validates the nickname using the following rules: - must have at least 1 character - must contain only alphanumeric characters, underscores and dashes - must not exceed MaxNicknameLength characters

func Xor

func Xor(a, b []byte) ([]byte, error)

Types

type AccountSerialized

type AccountSerialized struct {
	Version      *uint8   `yaml:"Version"`
	Nickname     string   `yaml:"Nickname"`
	Address      string   `yaml:"Address"`
	Salt         [16]byte `yaml:"Salt,flow"`
	Nonce        [12]byte `yaml:"Nonce,flow"`
	CipheredData []byte   `yaml:"CipheredData,flow"`
	PublicKey    []byte   `yaml:"PublicKey,flow"`
}

func (*AccountSerialized) ToAccount

func (accountSerialized *AccountSerialized) ToAccount() Wallet

type KeyPair

type KeyPair struct {
	PrivateKey []byte
	PublicKey  []byte
	Salt       [16]byte
	Nonce      [12]byte
}

KeyPair structure contains all the information necessary to save a key pair securely.

type Wallet

type Wallet struct {
	Version  uint8
	Nickname string
	Address  string
	KeyPair  KeyPair
}

Wallet structure allows to link a nickname, an address and a version to one or more key pairs.

func Load

func Load(nickname string) (*Wallet, error)

Load loads the wallet that match the given name in the working directory Note: `wallet_` prefix and a `.yaml` extension are automatically added.

func LoadAll

func LoadAll() ([]Wallet, error)

LoadAll loads all the wallets in the working directory. Note: a wallet must have: `wallet_` prefix and a `.yaml` extension.

func (*Wallet) DeleteFile

func (w *Wallet) DeleteFile() (err error)

Delete removes wallet from file system

func (*Wallet) FilePath

func (w *Wallet) FilePath() (string, error)

FilePath returns the wallet file path base.

func (*Wallet) Filename

func (w *Wallet) Filename() string

Filename returns the wallet filename.

func (*Wallet) GetNonce

func (wallet *Wallet) GetNonce() string

func (*Wallet) GetPrivKey

func (wallet *Wallet) GetPrivKey() string

GetPrivKey returns the private key of the wallet. This function requires that the private key is not protected.

func (*Wallet) GetPupKey

func (wallet *Wallet) GetPupKey() string

GetPupKey returns the public key of the wallet.

func (*Wallet) GetSalt

func (wallet *Wallet) GetSalt() string

func (*Wallet) Persist

func (w *Wallet) Persist() error

Persist stores the wallet on the file system. Note: the wallet is stored in YAML format and in Massa Station wallet directory.

func (*Wallet) Protect

func (w *Wallet) Protect(password string) error

Protect encrypts the private key using the given guiModal. The encryption algorithm used to protect the private key is AES-GCM and the secret key is derived from the given password using the PBKDF2 algorithm.

func (*Wallet) Sign

func (wallet *Wallet) Sign(operation []byte) ([]byte, error)

Sign signs the given operation with the wallet. The operation is a base64 encoded string.

func (*Wallet) ToAccountSerialized

func (account *Wallet) ToAccountSerialized() AccountSerialized

func (*Wallet) Unprotect

func (w *Wallet) Unprotect(password string) *WalletError

Unprotect decrypts the private key using the given GUI Modal. The encryption algorithm used to unprotect the private key is AES-GCM and the secret key is derived from the given password using the PBKDF2 algorithm.

func (*Wallet) UnprotectFromCorrelationId

func (w *Wallet) UnprotectFromCorrelationId(fromCache []byte, correlationId models.CorrelationID) error

type WalletError

type WalletError struct {
	Err     error
	CodeErr string // Sentinel error code from utils package, can be used as a translation key.
}

Jump to

Keyboard shortcuts

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