accounts

package
v0.0.0-...-6fdbc3c Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIndex is thrown on an out of bounds index
	ErrIndex = errors.New("invalid account index")

	//ErrDuplicate is thrown on inserting a duplicate account
	ErrDuplicate = errors.New("duplicate account insert")
)
View Source
var (
	// ErrDelete is thrown on an unsuccessful account delete
	ErrDelete = errors.New("unsuccessful delete")

	// ErrAccount is thrown on an unsupported account type
	ErrAccount = errors.New("invalid account type")
)

Functions

This section is empty.

Types

type Account

type Account interface {
	Gen() error
	Export([]byte) ([]byte, error)
	Import([]byte, []byte) error
	String() string
}

Account represents a generic account

type Entry

type Entry struct {
	ID      primitive.ObjectID
	Account Account
}

Entry represents an account store entry

type Key

type Key struct {
	ID        primitive.ObjectID `bson:"_id,omitempty"`
	CreatedAt time.Time          `bson:"created_at,omitempty"`
	UpdatedAt time.Time          `bson:"updated_at,omitempty"`
	Raw       []byte             `bson:"raw"`
}

Key represents an encrypted member of the account store

type Master

type Master struct {
	Type     chain.Type
	Password []byte
	Entries  []Entry
	Store    Store
}

Master holds a chain's master key This Key:

  • Is responsible for encrypting/decrypting an account store
  • Is user-provided and loaded into memory at runtime
  • Should never touch disk

func (*Master) DumpAccounts

func (m *Master) DumpAccounts()

DumpAccounts to stdout

func (*Master) Init

func (m *Master) Init(db *mongo.Database) error

Init the master account store

func (*Master) InsertAccount

func (m *Master) InsertAccount(account Account) error

InsertAccount inserts a unique account into the store

func (*Master) NewAccount

func (m *Master) NewAccount() error

NewAccount generates a new account conditioned on the chain type

func (*Master) RemoveAccount

func (m *Master) RemoveAccount(index uint) error

RemoveAccount removes an account from the store by index

type Store

type Store struct {
	AccountType chain.Type        // the account type
	Ctx         ctx.Context       // calling context
	Accounts    *mongo.Collection // collection of encrypted accounts for this chain
}

Store wraps a mongo connection to an account store

func (*Store) AddEntry

func (s *Store) AddEntry(raw []byte) (primitive.ObjectID, error)

AddEntry adds an entry to the store and returns its id

func (*Store) DecryptAccount

func (s *Store) DecryptAccount(password, encryptedAccount []byte) (Account, error)

DecryptAccount decrypts a single account conditioned on the account type

func (*Store) GetEntries

func (s *Store) GetEntries(password []byte) ([]Entry, error)

GetEntries decrypts the account store

func (*Store) Init

func (s *Store) Init(db *mongo.Database) error

Init the account store for this chain

func (*Store) RemoveEntry

func (s *Store) RemoveEntry(id primitive.ObjectID) error

RemoveEntry removes an entry from the store by id

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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