wallet

package
v0.0.0-...-60ae506 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2019 License: MIT Imports: 21 Imported by: 4

Documentation

Index

Constants

View Source
const FILENAME = "wallet"

FILENAME is where the wallet file is stored

Variables

This section is empty.

Functions

func AESDecrypt

func AESDecrypt(data []byte, password string) ([]byte, error)

AESDecrypt when given some ciphertext concatted nonce and a password, returns the AES plaintext

func AESEncrypt

func AESEncrypt(plaintext []byte, password string) []byte

AESEncrypt when given some plaintext and a password, returns the AES ciphertext concatted with the nonce

func AddKeyPair

func AddKeyPair(wallet localWallet, publicKey ed25519.PublicKey, privateKey ed25519.PrivateKey) localWallet

AddKeyPair appends a given public and private key to the localWallet, ignoring them if they already exist

func Authenticate

func Authenticate(newPassword *string)

Authenticate stores the provided password for use when reading and writing to the encrypted wallet

func GenerateKeys

func GenerateKeys(seed *string) (ed25519.PrivateKey, ed25519.PublicKey, error)

GenerateKeys generates an ed25519 keypair from an optional seed

func ReadWallet

func ReadWallet() (localWallet, error)

ReadWallet reads the localWallet from disk

func WriteWallet

func WriteWallet(wallet localWallet)

WriteWallet writes the localWallet to disk

Types

type Account

type Account map[Currency]DecimalAmount

Account maps a range of currencies to a decimal amount

func (Account) Inverse

func (s Account) Inverse() Account

Inverse returns the inverse value for each currency in the bank

func (Account) Subtract

func (s Account) Subtract(s2 Account) Account

Subtract one bank of currencies from another (piecewise)

type Currency

type Currency string

Currency represents some currency string

type DecimalAmount

type DecimalAmount struct {
	Value   int64
	Decimal int8
}

DecimalAmount represents some decimal currency without using floating point

func (DecimalAmount) Inverse

func (d DecimalAmount) Inverse() DecimalAmount

Inverse returns the inverse decimal amount under addition

func (DecimalAmount) IsPositive

func (d DecimalAmount) IsPositive() bool

IsPositive returns whether the DecimalAmount is positive

func (DecimalAmount) String

func (d DecimalAmount) String() string

func (DecimalAmount) Subtract

func (d DecimalAmount) Subtract(d2 DecimalAmount) DecimalAmount

Subtract subtracts one DecimalAmount from another, accounting for integer rollover

type Store

type Store struct {
	WalletStore map[[ed25519.PublicKeySize]byte]Account // current wallets
	// contains filtered or unexported fields
}

Store maps public keys to accounts, representing the current state of the state machine

func NewStore

func NewStore(snapshotter *snap.Snapshotter, proposeC chan<- string, commitC <-chan *string, errorC <-chan error, wg *sync.WaitGroup) *Store

NewStore creates a new Store to hold currencies

func (*Store) CheckBalance

func (s *Store) CheckBalance(key ed25519.PublicKey, curr Currency, amount DecimalAmount) error

CheckBalance returns true if the wallet belonging to key has more of the given decimalAmount than requestedAmount

func (*Store) GetSnapshot

func (s *Store) GetSnapshot() ([]byte, error)

GetSnapshot marshals the store to be used by the snapshotter

func (*Store) Lookup

func (s *Store) Lookup(key ed25519.PublicKey) (Account, bool)

Lookup retrieves the currencies for a given public key

func (*Store) Propose

func (s *Store) Propose(trans Transaction) error

Propose when provided a destination wallet, a decimalAmount, a currency, and a valid signature on the transaction, requests a transfer from the src to the dest of the requested decimalAmount.

Performs a simple crypto check to make sure the transaction is signed by the src address.

func (*Store) Search

func (s *Store) Search(key string) (ed25519.PublicKey, bool)

Search gets a unique public key from the store, returning (key, true) if there is exactly one match, else (nil, false).

type Transaction

type Transaction struct {
	Src    ed25519.PublicKey
	Dest   ed25519.PublicKey
	Sig    [ed25519.SignatureSize]byte
	Curr   Currency
	Amount DecimalAmount
	Create bool
}

Transaction is a state change transferring an amount of some currency between wallets.

func NewTransaction

func NewTransaction(src ed25519.PublicKey, dest ed25519.PublicKey, curr Currency, amount DecimalAmount, create bool) (Transaction, error)

NewTransaction is the constructor for the transaction struct

func (Transaction) GetSignableRepresentation

func (t Transaction) GetSignableRepresentation() ([]byte, error)

GetSignableRepresentation gets a []byte representation that can be signed

func (*Transaction) IsVerified

func (t *Transaction) IsVerified() bool

IsVerified validates a request to pay somebody

func (*Transaction) Sign

func (t *Transaction) Sign(key ed25519.PrivateKey) error

Sign signs a request to pay somebody

Jump to

Keyboard shortcuts

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