Documentation ¶
Overview ¶
Package keystore provides key creation and management functionalities.
Index ¶
- Constants
- Variables
- type AskPassOnceFunc
- type Keystore
- func (ks *Keystore) AskForPassword(prompt ...string) (string, error)
- func (ks *Keystore) AskForPasswordOnce(prompt ...string) (string, error)
- func (ks *Keystore) CreateCmd(keyType types.KeyType, seed int64, passphrase string, nopass bool) (*ed25519.Key, error)
- func (ks *Keystore) CreateKey(key *ed25519.Key, keyType types.KeyType, passphrase string) error
- func (ks *Keystore) Exist(address string) (bool, error)
- func (ks *Keystore) GetByAddress(addr string) (types2.StoredKey, error)
- func (ks *Keystore) GetByIndex(i int) (types2.StoredKey, error)
- func (ks *Keystore) GetByIndexOrAddress(idxOrAddr string) (types2.StoredKey, error)
- func (ks *Keystore) GetCmd(addrOrIdx, pass string, showPrivKey bool) error
- func (ks *Keystore) ImportCmd(keyfile string, keyType types.KeyType, pass string) error
- func (ks *Keystore) List() (accounts []types.StoredKey, err error)
- func (ks *Keystore) ListCmd(out io.Writer) error
- func (ks *Keystore) SetOutput(out io.Writer)
- func (ks *Keystore) UnlockKeyUI(addressOrIndex, passphrase, promptMsg string) (types.StoredKey, string, error)
- func (ks *Keystore) UpdateCmd(addressOrIndex, passphrase string) error
- type StoredKey
- func (sk *StoredKey) GetCreatedAt() time.Time
- func (sk *StoredKey) GetFilename() string
- func (sk *StoredKey) GetKey() *ed25519.Key
- func (sk *StoredKey) GetMeta() types2.StoredKeyMeta
- func (sk *StoredKey) GetPayload() *types2.KeyPayload
- func (sk *StoredKey) GetPushKeyAddress() string
- func (sk *StoredKey) GetType() types2.KeyType
- func (sk *StoredKey) GetUnlockedData() []byte
- func (sk *StoredKey) GetUserAddress() string
- func (sk *StoredKey) IsUnprotected() bool
- func (sk *StoredKey) Unlock(passphrase string) error
Constants ¶
const (
DefaultPassphrase = "passphrase"
)
Variables ¶
var (
Version = "0.0.1"
)
Functions ¶
This section is empty.
Types ¶
type AskPassOnceFunc ¶
type Keystore ¶
type Keystore struct {
// contains filtered or unexported fields
}
Keystore implements Keystore. It provides the ability to create, update, fetch and import keys and accounts.
func New ¶
New creates an instance of Keystore. dir is where encrypted key files are stored. EXPECTS: - dir to have been created
func (*Keystore) AskForPassword ¶
AskForPassword starts an interactive prompt to collect passphrase. Returns error if passphrase and repeated passphrases do not match
func (*Keystore) AskForPasswordOnce ¶
AskForPasswordOnce is like askForPassword but it does not ask to confirm passphrase.
func (*Keystore) CreateCmd ¶
func (ks *Keystore) CreateCmd( keyType types.KeyType, seed int64, passphrase string, nopass bool) (*ed25519.Key, error)
CreateCmd creates a new key in the keystore. It will prompt the user to obtain encryption passphrase if one is not provided. If seed is non-zero, it is used as the seed for key generation, otherwise, one will be randomly generated. If passphrase is a file path, the file is read and its content is used as the passphrase. If nopass is true, the default encryption passphrase is used and the key will be marked 'unprotected'
func (*Keystore) GetByAddress ¶
GetByAddress finds a key where its user address or push key address matches addr
func (*Keystore) GetByIndex ¶
GetByIndex returns a key by its current position in the list of accounts which is ordered by the time of creation.
func (*Keystore) GetByIndexOrAddress ¶
GetByIndexOrAddress gets a key by either its address or index
func (*Keystore) GetCmd ¶
GetCmd decrypts a key and prints all information about the key. If pass is provide and it is not a file path, it is used as the passphrase. Otherwise, the file content is used as the passphrase. When pass is not set, the user is prompted to provide their passphrase. If showPrivKey is true, the private key will be printed out.
func (*Keystore) ImportCmd ¶
ImportCmd creates a new key from a private key stored in a file. If pass is provide and it is not a file path, it is used as the passphrase. Otherwise, the file is read and used as the passphrase. When pass is not set, the user is prompted to provide the passphrase.
func (*Keystore) UnlockKeyUI ¶
func (ks *Keystore) UnlockKeyUI(addressOrIndex, passphrase, promptMsg string) (types.StoredKey, string, error)
UnlockKeyUI unlocks a target key by rendering prompt to collect a passphrase. addressOrIndex: The address or index of the key. passphrase: The user supplied passphrase. If not provided, an interactive session will be started to collect the passphrase Onsuccess, it returns the unlocked key and the passphrase used to unlock it.
type StoredKey ¶
type StoredKey struct { // Type indicates the key type Type types2.KeyType // Address is the user address encoding of the key UserAddress string // PushAddress is the push address encoding of the key PushAddress string // Cipher includes the encryption data Cipher []byte // Data contains the decrypted data. // Only available after account is unlocked. Data []byte // CreatedAt represents the time the key was created and stored on disk CreatedAt time.Time // Unprotected indicates that the key is encrypted with a default passphrase. // An unprotected key is equivalent to a key that has no passphrase. Unprotected bool // The filename of the key file Filename string // contains filtered or unexported fields }
StoredKey represents an encrypted key stored on disk
func (*StoredKey) GetCreatedAt ¶
GetUnlockedData returns the locked data. Only available when key is unlocked.
func (*StoredKey) GetFilename ¶
GetFilename returns the filename of the key file
func (*StoredKey) GetKey ¶
GetKey returns the underlying Ed25519 key. Unlock() must be called first.
func (*StoredKey) GetMeta ¶
func (sk *StoredKey) GetMeta() types2.StoredKeyMeta
GetMeta returns the meta information of the key
func (*StoredKey) GetPayload ¶
func (sk *StoredKey) GetPayload() *types2.KeyPayload
GetKey returns the key object that is serialized and persisted.
func (*StoredKey) GetPushKeyAddress ¶
GetPushKeyAddress returns the push address of the key
func (*StoredKey) GetUnlockedData ¶
GetUnlockedData returns the locked data. Only available when key is unlocked.
func (*StoredKey) GetUserAddress ¶
GetUserAddress returns the address of the key
func (*StoredKey) IsUnprotected ¶
IsUnprotected checks whether the key is encrypted using the default passphrase