keystore

package
v0.0.0-...-c69f244 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2022 License: LGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidKeystoreName = errors.New("invalid keystore name")
)
View Source
var (
	ErrKeyTypeNotSupported = errors.New("given key type is not supported by this keystore")
)

Functions

func DecodeKeyPairFromHex

func DecodeKeyPairFromHex(keystr []byte, keytype crypto.KeyType) (kp crypto.Keypair, err error)

DecodeKeyPairFromHex turns an hex-encoded private key into a keypair

func DecodePrivateKey

func DecodePrivateKey(in []byte, keytype crypto.KeyType) (priv crypto.PrivateKey, err error)

DecodePrivateKey turns input bytes into a private key based on the specified key type

func Decrypt

func Decrypt(data, password []byte) ([]byte, error)

Decrypt uses AES to decrypt ciphertext with the symmetric key deterministically created from `password`

func DecryptPrivateKey

func DecryptPrivateKey(data, password []byte, keytype string) (crypto.PrivateKey, error)

DecryptPrivateKey uses AES to decrypt the ciphertext into a `crypto.PrivateKey` with a symmetric key deterministically created from `password`

func DetermineKeyType

func DetermineKeyType(t string) crypto.KeyType

DetermineKeyType takes string as defined in https://github.com/w3f/PSPs/blob/psp-rpc-api/psp-002.md#Key-types

and returns the crypto.KeyType

func Encrypt

func Encrypt(msg, password []byte) ([]byte, error)

Encrypt uses AES to encrypt `msg` with the symmetric key deterministically created from `password`

func EncryptAndWriteToFile

func EncryptAndWriteToFile(path string, pk crypto.PrivateKey, password []byte) error

EncryptAndWriteToFile encrypts the `crypto.PrivateKey` using the password and saves it to the specified file

func EncryptPrivateKey

func EncryptPrivateKey(pk crypto.PrivateKey, password []byte) ([]byte, error)

EncryptPrivateKey uses AES to encrypt an encoded `crypto.PrivateKey` with a symmetric key deterministically created from `password`

func GenerateKeypair

func GenerateKeypair(keytype string, kp crypto.Keypair, basepath string, password []byte) (string, error)

GenerateKeypair create a new keypair with the corresponding type and saves it to basepath/keystore/[public key].key in json format encrypted using the specified password and returns the resulting filepath of the new key

func HasKey

func HasKey(pubKeyStr, keyType string, keystore Keystore) (bool, error)

HasKey returns true if given hex encoded public key string is found in keystore, false otherwise, error if there are issues decoding string

func ImportKeypair

func ImportKeypair(fp, dir string) (string, error)

ImportKeypair imports a key specified by its filename into a subdirectory by the name "keystore" and saves it under the filename "[publickey].key", returns the absolute path of the imported key file

func ImportRawPrivateKey

func ImportRawPrivateKey(key, keytype, basepath string, password []byte) (string, error)

ImportRawPrivateKey imports a raw private key and saves it to the keystore directory

func LoadKeystore

func LoadKeystore(key string, ks Keystore) error

LoadKeystore loads a new keystore and inserts the test key into the keystore

func PrivateKeyToKeypair

func PrivateKeyToKeypair(priv crypto.PrivateKey) (kp crypto.Keypair, err error)

PrivateKeyToKeypair returns a public, private keypair given a private key

func ReadFromFileAndDecrypt

func ReadFromFileAndDecrypt(filename string, password []byte) (crypto.PrivateKey, error)

ReadFromFileAndDecrypt reads ciphertext from a file and decrypts it using the password into a `crypto.PrivateKey`

func UnlockKeys

func UnlockKeys(ks Keystore, dir, unlock, password string) error

UnlockKeys unlocks keys specified by the --unlock flag with the passwords given by --password and places them into the keystore

Types

type BasicKeystore

type BasicKeystore struct {
	// contains filtered or unexported fields
}

BasicKeystore holds keys of a certain type

func NewBasicKeystore

func NewBasicKeystore(name Name, typ crypto.KeyType) *BasicKeystore

NewBasicKeystore creates a new BasicKeystore with the given key type

func (*BasicKeystore) GetKeypair

func (ks *BasicKeystore) GetKeypair(pub crypto.PublicKey) crypto.Keypair

GetKeypair returns a keypair corresponding to the given public key, or nil if it doesn't exist

func (*BasicKeystore) GetKeypairFromAddress

func (ks *BasicKeystore) GetKeypairFromAddress(pub common.Address) crypto.Keypair

GetKeypairFromAddress returns a keypair corresponding to the given address, or nil if it doesn't exist

func (*BasicKeystore) Insert

func (ks *BasicKeystore) Insert(kp crypto.Keypair) error

Insert adds a keypair to the keystore

func (*BasicKeystore) Keypairs

func (ks *BasicKeystore) Keypairs() []crypto.Keypair

Keypairs returns all keypairs in the keystore

func (*BasicKeystore) Name

func (ks *BasicKeystore) Name() Name

Name returns the keystore's name

func (*BasicKeystore) PublicKeys

func (ks *BasicKeystore) PublicKeys() []crypto.PublicKey

PublicKeys returns all public keys in the keystore

func (*BasicKeystore) Size

func (ks *BasicKeystore) Size() int

Size returns the number of keys in the keystore

func (*BasicKeystore) Type

func (ks *BasicKeystore) Type() crypto.KeyType

Type returns the keystore's key type

type Ed25519Keyring

type Ed25519Keyring struct {
	KeyAlice   *ed25519.Keypair
	KeyBob     *ed25519.Keypair
	KeyCharlie *ed25519.Keypair
	KeyDave    *ed25519.Keypair
	KeyEve     *ed25519.Keypair
	KeyFerdie  *ed25519.Keypair
	KeyGeorge  *ed25519.Keypair
	KeyHeather *ed25519.Keypair
	KeyIan     *ed25519.Keypair

	Keys []*ed25519.Keypair
}

Ed25519Keyring represents a test ed25519 keyring

func NewEd25519Keyring

func NewEd25519Keyring() (*Ed25519Keyring, error)

NewEd25519Keyring returns an initialised ed25519 Keyring

func (*Ed25519Keyring) Alice

func (kr *Ed25519Keyring) Alice() crypto.Keypair

Alice returns Alice's key

func (*Ed25519Keyring) Bob

func (kr *Ed25519Keyring) Bob() crypto.Keypair

Bob returns Bob's key

func (*Ed25519Keyring) Charlie

func (kr *Ed25519Keyring) Charlie() crypto.Keypair

Charlie returns Charlie's key

func (*Ed25519Keyring) Dave

func (kr *Ed25519Keyring) Dave() crypto.Keypair

Dave returns Dave's key

func (*Ed25519Keyring) Eve

func (kr *Ed25519Keyring) Eve() crypto.Keypair

Eve returns Eve's key

func (*Ed25519Keyring) Ferdie

func (kr *Ed25519Keyring) Ferdie() crypto.Keypair

Ferdie returns Ferdie's key

func (*Ed25519Keyring) George

func (kr *Ed25519Keyring) George() crypto.Keypair

George returns George's key

func (*Ed25519Keyring) Heather

func (kr *Ed25519Keyring) Heather() crypto.Keypair

Heather returns Heather's key

func (*Ed25519Keyring) Ian

func (kr *Ed25519Keyring) Ian() crypto.Keypair

Ian returns Ian's key

type EncryptedKeystore

type EncryptedKeystore struct {
	Type       string
	PublicKey  string
	Ciphertext []byte
}

EncryptedKeystore holds Type PublicKey and Ciphertext

type GenericKeystore

type GenericKeystore struct {
	// contains filtered or unexported fields
}

GenericKeystore holds keys of any type

func NewGenericKeystore

func NewGenericKeystore(name Name) *GenericKeystore

NewGenericKeystore creates a new GenericKeystore

func (*GenericKeystore) Ed25519Keypairs

func (ks *GenericKeystore) Ed25519Keypairs() []crypto.Keypair

Ed25519Keypairs Keypair

func (*GenericKeystore) Ed25519PublicKeys

func (ks *GenericKeystore) Ed25519PublicKeys() []crypto.PublicKey

Ed25519PublicKeys keys

func (*GenericKeystore) GetKeypair

func (ks *GenericKeystore) GetKeypair(pub crypto.PublicKey) crypto.Keypair

GetKeypair returns a keypair corresponding to the given public key, or nil if it doesn't exist

func (*GenericKeystore) GetKeypairFromAddress

func (ks *GenericKeystore) GetKeypairFromAddress(pub common.Address) crypto.Keypair

GetKeypairFromAddress returns a keypair corresponding to the given address, or nil if it doesn't exist

func (*GenericKeystore) Insert

func (ks *GenericKeystore) Insert(kp crypto.Keypair) error

Insert adds a keypair to the keystore

func (*GenericKeystore) Keypairs

func (ks *GenericKeystore) Keypairs() []crypto.Keypair

Keypairs returns all keypairs in the keystore

func (*GenericKeystore) Name

func (ks *GenericKeystore) Name() Name

Name returns the keystore's name

func (*GenericKeystore) NumEd25519Keys

func (ks *GenericKeystore) NumEd25519Keys() int

NumEd25519Keys returns the number of ed25519 keys in the keystore

func (*GenericKeystore) NumSr25519Keys

func (ks *GenericKeystore) NumSr25519Keys() int

NumSr25519Keys returns the number of sr25519 keys in the keystore

func (*GenericKeystore) PublicKeys

func (ks *GenericKeystore) PublicKeys() []crypto.PublicKey

PublicKeys returns all public keys in the keystore

func (*GenericKeystore) Secp256k1Keypairs

func (ks *GenericKeystore) Secp256k1Keypairs() []crypto.Keypair

Secp256k1Keypairs Keypair

func (*GenericKeystore) Secp256k1PublicKeys

func (ks *GenericKeystore) Secp256k1PublicKeys() []crypto.PublicKey

Secp256k1PublicKeys PublicKey

func (*GenericKeystore) Size

func (ks *GenericKeystore) Size() int

Size returns the number of keys in the keystore

func (*GenericKeystore) Sr25519Keypairs

func (ks *GenericKeystore) Sr25519Keypairs() []crypto.Keypair

Sr25519Keypairs Keypair

func (*GenericKeystore) Sr25519PublicKeys

func (ks *GenericKeystore) Sr25519PublicKeys() []crypto.PublicKey

Sr25519PublicKeys PublicKey

func (*GenericKeystore) Type

func (ks *GenericKeystore) Type() crypto.KeyType

Type returns UnknownType since the keystore may contain keys of any type

type GlobalKeystore

type GlobalKeystore struct {
	Babe Keystore
	Gran Keystore
	Acco Keystore
	Aura Keystore
	Imon Keystore
	Audi Keystore
	Dumy Keystore
}

GlobalKeystore defines the various keystores used by the node

func NewGlobalKeystore

func NewGlobalKeystore() *GlobalKeystore

NewGlobalKeystore returns a new GlobalKeystore

func (*GlobalKeystore) GetKeystore

func (k *GlobalKeystore) GetKeystore(name []byte) (Keystore, error)

GetKeystore returns a keystore given its name

type Keyring

type Keyring interface {
	Alice() crypto.Keypair
	Bob() crypto.Keypair
	Charlie() crypto.Keypair
	Dave() crypto.Keypair
	Eve() crypto.Keypair
	Ferdie() crypto.Keypair
	George() crypto.Keypair
	Heather() crypto.Keypair
	Ian() crypto.Keypair
}

Keyring represents a test keyring

type Keystore

type Keystore interface {
	Name() Name
	Type() crypto.KeyType
	Insert(kp crypto.Keypair) error
	GetKeypairFromAddress(pub common.Address) crypto.Keypair
	GetKeypair(pub crypto.PublicKey) crypto.Keypair
	PublicKeys() []crypto.PublicKey
	Keypairs() []crypto.Keypair
	Size() int
}

Keystore provides key management functionality

type Name

type Name string

Name represents a defined keystore name

var (
	BabeName Name = "babe"
	GranName Name = "gran"
	AccoName Name = "acco"
	AuraName Name = "aura"
	ImonName Name = "imon"
	AudiName Name = "audi"
	DumyName Name = "dumy"
)

type Sr25519Keyring

type Sr25519Keyring struct {
	KeyAlice   *sr25519.Keypair
	KeyBob     *sr25519.Keypair
	KeyCharlie *sr25519.Keypair
	KeyDave    *sr25519.Keypair
	KeyEve     *sr25519.Keypair
	KeyFerdie  *sr25519.Keypair
	KeyGeorge  *sr25519.Keypair
	KeyHeather *sr25519.Keypair
	KeyIan     *sr25519.Keypair

	Keys []*sr25519.Keypair
}

Sr25519Keyring represents a test keyring

func NewSr25519Keyring

func NewSr25519Keyring() (*Sr25519Keyring, error)

NewSr25519Keyring returns an initialised sr25519 Keyring

func (*Sr25519Keyring) Alice

func (kr *Sr25519Keyring) Alice() crypto.Keypair

Alice returns Alice's key

func (*Sr25519Keyring) Bob

func (kr *Sr25519Keyring) Bob() crypto.Keypair

Bob returns Bob's key

func (*Sr25519Keyring) Charlie

func (kr *Sr25519Keyring) Charlie() crypto.Keypair

Charlie returns Charlie's key

func (*Sr25519Keyring) Dave

func (kr *Sr25519Keyring) Dave() crypto.Keypair

Dave returns Dave's key

func (*Sr25519Keyring) Eve

func (kr *Sr25519Keyring) Eve() crypto.Keypair

Eve returns Eve's key

func (*Sr25519Keyring) Ferdie

func (kr *Sr25519Keyring) Ferdie() crypto.Keypair

Ferdie returns Ferdie's key

func (*Sr25519Keyring) George

func (kr *Sr25519Keyring) George() crypto.Keypair

George returns George's key

func (*Sr25519Keyring) Heather

func (kr *Sr25519Keyring) Heather() crypto.Keypair

Heather returns Heather's key

func (*Sr25519Keyring) Ian

func (kr *Sr25519Keyring) Ian() crypto.Keypair

Ian returns Ian's key

Jump to

Keyboard shortcuts

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