Documentation ¶
Index ¶
- Constants
- func AESDecrypt(data []byte, password string) ([]byte, error)
- func AESEncrypt(plaintext []byte, password string) []byte
- func AddKeyPair(wallet localWallet, publicKey ed25519.PublicKey, privateKey ed25519.PrivateKey) localWallet
- func Authenticate(newPassword *string)
- func GenerateKeys(seed *string) (ed25519.PrivateKey, ed25519.PublicKey, error)
- func ReadWallet() (localWallet, error)
- func WriteWallet(wallet localWallet)
- type Account
- type Currency
- type DecimalAmount
- type Store
- func (s *Store) CheckBalance(key ed25519.PublicKey, curr Currency, amount DecimalAmount) error
- func (s *Store) GetSnapshot() ([]byte, error)
- func (s *Store) Lookup(key ed25519.PublicKey) (Account, bool)
- func (s *Store) Propose(trans Transaction) error
- func (s *Store) Search(key string) (ed25519.PublicKey, bool)
- type Transaction
Constants ¶
const FILENAME = "wallet"
FILENAME is where the wallet file is stored
Variables ¶
This section is empty.
Functions ¶
func AESDecrypt ¶
AESDecrypt when given some ciphertext concatted nonce and a password, returns the AES plaintext
func AESEncrypt ¶
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 ¶
GenerateKeys generates an ed25519 keypair from an optional seed
Types ¶
type Account ¶
type Account map[Currency]DecimalAmount
Account maps a range of currencies to a decimal amount
type DecimalAmount ¶
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 ¶
CheckBalance returns true if the wallet belonging to key has more of the given decimalAmount than requestedAmount
func (*Store) GetSnapshot ¶
GetSnapshot marshals the store to be used by the snapshotter
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.
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