vault

package
Version: v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2021 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VersionV0 = iota // Only accounts
	VersionV1        // Accounts + organisations
	VersionV2        // Multi key
)

Vault versions

View Source
const LatestVaultVersion = VersionV2

LatestVaultVersion Everything below this version will be automatically migrated to this version

Variables

View Source
var (
	// VaultPassword is the given password through the commandline for opening the vault
	VaultPassword string
	// VaultPath is the default vault path
	VaultPath string
)

Functions

func DecryptContainer

func DecryptContainer(container *EncryptedContainer, pass string) ([]byte, error)

DecryptContainer decrypts an encrypted data container

func EncryptContainer

func EncryptContainer(data interface{}, pass, containerType string, version int) ([]byte, error)

EncryptContainer encrypts bytes into a data container

func Exists

func Exists(p string) bool

Exists will return true if the vault exists

Types

type AccountInfo

type AccountInfo struct {
	// Default bool             `json:"default"` // Is this the default account
	Address *address.Address `json:"address"` // The address of the account

	Name     string            `json:"name"`     // Full name of the user
	Settings map[string]string `json:"settings"` // Additional settings that can be user-defined

	Keys []KeyPair // Actual keys

	// Communication and encryption information
	Pow       *proofofwork.ProofOfWork `json:"proof,omitempty"` // Proof of work
	RoutingID string                   `json:"routing_id"`      // ID of the routing used

	StoreKey *bmcrypto.KeyPair `json:"store_key,omitempty"` // Keypair for the store
}

AccountInfo represents client account information

func GetAccount

func GetAccount(vault *Vault, a string) (*AccountInfo, error)

GetAccount returns the given account, or nil when not found

func (AccountInfo) FindKey

func (info AccountInfo) FindKey(fp string) (*KeyPair, error)

FindKey will try and retrieve a key based on the fingerprint

func (AccountInfo) GetActiveKey

func (info AccountInfo) GetActiveKey() KeyPair

GetActiveKey will return the currently active key from the list of keys in the info structure

func (AccountInfo) SetActiveKey

func (info AccountInfo) SetActiveKey(kp *bmcrypto.KeyPair)

SetActiveKey sets the active key in the info

type AccountInfoV1

type AccountInfoV1 struct {
	Address   *address.Address         `json:"address"`         // The address of the account
	Name      string                   `json:"name"`            // Full name of the user
	Settings  map[string]string        `json:"settings"`        // Additional settings that can be user-defined
	PrivKey   bmcrypto.PrivKey         `json:"priv_key"`        // PEM encoded private key
	PubKey    bmcrypto.PubKey          `json:"pub_key"`         // PEM encoded public key
	Pow       *proofofwork.ProofOfWork `json:"proof,omitempty"` // Proof of work
	RoutingID string                   `json:"routing_id"`      // ID of the routing used
}

AccountInfoV1 represents client account information

type EncryptedContainer

type EncryptedContainer struct {
	Type    string `json:"type"`    // Type of the data
	Version int    `json:"version"` // Version of the data
	Data    []byte `json:"data"`    // Actual data
	Salt    []byte `json:"salt"`    // Salt
	Iv      []byte `json:"iv"`      // IV for encryption
	Hmac    []byte `json:"hmac"`    // Hash MAC
}

EncryptedContainer is the on-disk structure for an encrypted blob.

type KeyPair

type KeyPair struct {
	bmcrypto.KeyPair
	Active bool `json:"active"` // This is the currently active key
}

KeyPair is a structure with key information

type OrganisationInfo

type OrganisationInfo struct {
	Addr        string                        `json:"addr"`          // org part from the bitmaelum address
	FullName    string                        `json:"name"`          // Full name of the organisation
	Keys        []KeyPair                     `json:"keys"`          // Organisation keys
	Pow         *proofofwork.ProofOfWork      `json:"pow,omitempty"` // Proof of work
	Validations []organisation.ValidationType `json:"validations"`   // Validations
}

OrganisationInfo represents a organisation configuration for a server

func (OrganisationInfo) GetActiveKey

func (info OrganisationInfo) GetActiveKey() KeyPair

GetActiveKey will return the currently active key from the list of keys in the info structure

func (OrganisationInfo) SetActiveKey

func (info OrganisationInfo) SetActiveKey(kp *KeyPair)

SetActiveKey sets the active key in the info

func (OrganisationInfo) ToOrg

ToOrg converts organisation info to an actual organisation structure

type OrganisationInfoV1

type OrganisationInfoV1 struct {
	Addr        string                        `json:"addr"`          // org part from the bitmaelum address
	FullName    string                        `json:"name"`          // Full name of the organisation
	PrivKey     bmcrypto.PrivKey              `json:"priv_key"`      // PEM encoded private key
	PubKey      bmcrypto.PubKey               `json:"pub_key"`       // PEM encoded public key
	Pow         *proofofwork.ProofOfWork      `json:"pow,omitempty"` // Proof of work
	Validations []organisation.ValidationType `json:"validations"`   // Validations
}

OrganisationInfoV1 is an older structure

type StoreType

type StoreType struct {
	Accounts      []AccountInfo      `json:"accounts"`
	Organisations []OrganisationInfo `json:"organisations"`
}

StoreType hold the actual data that is encrypted inside the vault

func MigrateVault

func MigrateVault(data []byte, fromVersion int) (*StoreType, error)

MigrateVault will migrate a vault from a specific version all the way to the latest version

type StoreTypeV1

type StoreTypeV1 struct {
	Accounts      []AccountInfoV1      `json:"accounts"`
	Organisations []OrganisationInfoV1 `json:"organisations"`
}

StoreTypeV1 hold the actual data that is encrypted inside the vault

type Vault

type Vault struct {
	Store   StoreType
	RawData []byte
	// contains filtered or unexported fields
}

Vault defines our vault with path and password. Only the accounts should be exported

func Create

func Create(p, pass string) (*Vault, error)

Create will create a new vault on the given path

func New

func New() *Vault

New instantiates a new vault

func NewPersistent

func NewPersistent(p, pass string) *Vault

NewPersistent instantiates a new vault and persists on disk

func Open

func Open(vp, pass string) (*Vault, error)

Open will open a specific vault with a specific password

func OpenDefaultVault

func OpenDefaultVault() *Vault

OpenDefaultVault returns an opened vault on vault.VaultPath and with password vault.VaultPath. Will die when incorrect vault or password

func OpenOrDie

func OpenOrDie(vp, pass string) *Vault

OpenOrDie will open a specific vault with a specific password

func (*Vault) AddAccount

func (v *Vault) AddAccount(account AccountInfo)

AddAccount adds a new account to the vault

func (*Vault) AddOrganisation

func (v *Vault) AddOrganisation(organisation OrganisationInfo)

AddOrganisation adds an organisation to the vault

func (*Vault) DecryptContainer

func (v *Vault) DecryptContainer(container *EncryptedContainer) error

DecryptContainer decrypts a container and fills the values in v.Store

func (*Vault) EncryptContainer

func (v *Vault) EncryptContainer() ([]byte, error)

EncryptContainer encrypts v.Store and returns the vault as encrypted JSON container

func (*Vault) FindShortRoutingID

func (v *Vault) FindShortRoutingID(id string) string

FindShortRoutingID will find a short routing ID in the vault and expand it to the full routing ID. So we can use "12345" instead of "1234567890123456789012345678901234567890". Will not return anything when multiple candidates are found.

func (*Vault) GetAccountInfo

func (v *Vault) GetAccountInfo(addr address.Address) (*AccountInfo, error)

GetAccountInfo tries to find the given address and returns the account from the vault

func (*Vault) GetOrganisationInfo

func (v *Vault) GetOrganisationInfo(orgHash hash.Hash) (*OrganisationInfo, error)

GetOrganisationInfo tries to find the given organisation and returns the organisation from the vault

func (*Vault) HasAccount

func (v *Vault) HasAccount(addr address.Address) bool

HasAccount returns true when the vault has an account for the given address

func (*Vault) HasOrganisation

func (v *Vault) HasOrganisation(org hash.Hash) bool

HasOrganisation returns true when the vault has an organisation for the given address

func (*Vault) Persist

func (v *Vault) Persist() error

Persist saves the vault data back to disk

func (*Vault) RemoveAccount

func (v *Vault) RemoveAccount(addr address.Address)

RemoveAccount removes the given account from the vault

func (*Vault) SetPassword

func (v *Vault) SetPassword(pass string)

SetPassword allows us to change the vault password. Will take effect on writing to disk

func (*Vault) SetPath

func (v *Vault) SetPath(p string)

SetPath sets the path of the vault.

Jump to

Keyboard shortcuts

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