keystore

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: LGPL-3.0 Imports: 21 Imported by: 1

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 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 PublicPrivater, 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 AddressKeypairGetter) (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 added in v0.2.0

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, keyStore TyperInserter, keyRing KeyRing) (err error)

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

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 Inserter, 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 AddressKeypairGetter added in v0.8.0

type AddressKeypairGetter interface {
	GetKeypairFromAddress(pub common.Address) KeyPair
}

AddressKeypairGetter gets a keypair from an address.

type BasicKeystore added in v0.2.0

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

BasicKeystore holds keys of a certain type

func NewBasicKeystore added in v0.2.0

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

NewBasicKeystore creates a new BasicKeystore with the given key type

func (*BasicKeystore) GetKeypair added in v0.2.0

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

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

func (*BasicKeystore) GetKeypairFromAddress added in v0.2.0

func (ks *BasicKeystore) GetKeypairFromAddress(pub common.Address) KeyPair

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

func (*BasicKeystore) Insert added in v0.2.0

func (ks *BasicKeystore) Insert(kp KeyPair) error

Insert adds a keypair to the keystore

func (*BasicKeystore) Keypairs added in v0.2.0

func (ks *BasicKeystore) Keypairs() (srkeys []KeyPair)

Keypairs returns all keypairs in the keystore

func (*BasicKeystore) Name added in v0.2.0

func (ks *BasicKeystore) Name() Name

Name returns the keystore's name

func (*BasicKeystore) PublicKeys added in v0.2.0

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

PublicKeys returns all public keys in the keystore

func (*BasicKeystore) Size added in v0.2.0

func (ks *BasicKeystore) Size() int

Size returns the number of keys in the keystore

func (*BasicKeystore) Type added in v0.2.0

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() KeyPair

Alice returns Alice's key

func (*Ed25519Keyring) Bob

func (kr *Ed25519Keyring) Bob() KeyPair

Bob returns Bob's key

func (*Ed25519Keyring) Charlie

func (kr *Ed25519Keyring) Charlie() KeyPair

Charlie returns Charlie's key

func (*Ed25519Keyring) Dave

func (kr *Ed25519Keyring) Dave() KeyPair

Dave returns Dave's key

func (*Ed25519Keyring) Eve

func (kr *Ed25519Keyring) Eve() KeyPair

Eve returns Eve's key

func (*Ed25519Keyring) Ferdie added in v0.2.0

func (kr *Ed25519Keyring) Ferdie() KeyPair

Ferdie returns Ferdie's key

func (*Ed25519Keyring) George

func (kr *Ed25519Keyring) George() KeyPair

George returns George's key

func (*Ed25519Keyring) Heather

func (kr *Ed25519Keyring) Heather() KeyPair

Heather returns Heather's key

func (*Ed25519Keyring) Ian

func (kr *Ed25519Keyring) Ian() 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 added in v0.2.0

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

GenericKeystore holds keys of any type

func NewGenericKeystore added in v0.2.0

func NewGenericKeystore(name Name) *GenericKeystore

NewGenericKeystore creates a new GenericKeystore

func (*GenericKeystore) Ed25519Keypairs added in v0.2.0

func (ks *GenericKeystore) Ed25519Keypairs() (edkeys []KeyPair)

Ed25519Keypairs Keypair

func (*GenericKeystore) Ed25519PublicKeys added in v0.2.0

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

Ed25519PublicKeys keys

func (*GenericKeystore) GetKeypair added in v0.2.0

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

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

func (*GenericKeystore) GetKeypairFromAddress added in v0.2.0

func (ks *GenericKeystore) GetKeypairFromAddress(pub common.Address) KeyPair

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

func (*GenericKeystore) Insert added in v0.2.0

func (ks *GenericKeystore) Insert(kp KeyPair) error

Insert adds a keypair to the keystore

func (*GenericKeystore) Keypairs added in v0.2.0

func (ks *GenericKeystore) Keypairs() (srkeys []KeyPair)

Keypairs returns all keypairs in the keystore

func (*GenericKeystore) Name added in v0.2.0

func (ks *GenericKeystore) Name() Name

Name returns the keystore's name

func (*GenericKeystore) NumEd25519Keys added in v0.2.0

func (ks *GenericKeystore) NumEd25519Keys() int

NumEd25519Keys returns the number of ed25519 keys in the keystore

func (*GenericKeystore) NumSr25519Keys added in v0.2.0

func (ks *GenericKeystore) NumSr25519Keys() int

NumSr25519Keys returns the number of sr25519 keys in the keystore

func (*GenericKeystore) PublicKeys added in v0.2.0

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

PublicKeys returns all public keys in the keystore

func (*GenericKeystore) Secp256k1Keypairs added in v0.2.0

func (ks *GenericKeystore) Secp256k1Keypairs() (sckeys []KeyPair)

Secp256k1Keypairs Keypair

func (*GenericKeystore) Secp256k1PublicKeys added in v0.2.0

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

Secp256k1PublicKeys PublicKey

func (*GenericKeystore) Size added in v0.2.0

func (ks *GenericKeystore) Size() int

Size returns the number of keys in the keystore

func (*GenericKeystore) Sr25519Keypairs added in v0.2.0

func (ks *GenericKeystore) Sr25519Keypairs() (srkeys []KeyPair)

Sr25519Keypairs Keypair

func (*GenericKeystore) Sr25519PublicKeys added in v0.2.0

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

Sr25519PublicKeys PublicKey

func (*GenericKeystore) Type added in v0.2.0

func (*GenericKeystore) Type() crypto.KeyType

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

type GlobalKeystore added in v0.2.0

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

GlobalKeystore defines the various keystores used by the node

func NewGlobalKeystore added in v0.2.0

func NewGlobalKeystore() *GlobalKeystore

NewGlobalKeystore returns a new GlobalKeystore

func (*GlobalKeystore) GetKeystore added in v0.3.1

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

GetKeystore returns a keystore given its name

type Inserter added in v0.8.0

type Inserter interface {
	Insert(kp KeyPair) error
}

Inserter inserts a keypair.

type KeyPair added in v0.8.0

type KeyPair interface {
	Sign(msg []byte) ([]byte, error)
	Publicer
	Typer
}

KeyPair is a key pair to sign messages and from which the public key and key type can be obtained.

func DecodeKeyPairFromHex added in v0.7.0

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

DecodeKeyPairFromHex turns an hex-encoded private key into a keypair

func PrivateKeyToKeypair

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

PrivateKeyToKeypair returns a public, private keypair given a private key

type KeyRing added in v0.8.0

type KeyRing interface {
	Alice() KeyPair
	Bob() KeyPair
	Charlie() KeyPair
	Dave() KeyPair
	Eve() KeyPair
	Ferdie() KeyPair
	George() KeyPair
	Heather() KeyPair
	Ian() KeyPair
}

KeyRing is the key ring with multiple named keypairs.

type Keystore

type Keystore interface {
	Name() Name
	Typer
	Inserter
	AddressKeypairGetter
	Keypairs() []KeyPair
	GetKeypair(pub crypto.PublicKey) KeyPair
	PublicKeys() []crypto.PublicKey
	Size() int
}

Keystore provides key management functionality

type Name added in v0.2.0

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"
	ParaName Name = "para"
	AsgnName Name = "asgn"
	AudiName Name = "audi"
	DumyName Name = "dumy"
)

type Privater added in v0.8.0

type Privater interface {
	Private() crypto.PrivateKey
}

Privater returns the private key of the keypair.

type PublicPrivater added in v0.8.0

type PublicPrivater interface {
	Publicer
	Privater
}

PublicPrivater can return the private or public key from the keypair.

type Publicer added in v0.8.0

type Publicer interface {
	Public() crypto.PublicKey
}

Publicer returns the public key of the keypair.

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() KeyPair

Alice returns Alice's key

func (*Sr25519Keyring) Bob

func (kr *Sr25519Keyring) Bob() KeyPair

Bob returns Bob's key

func (*Sr25519Keyring) Charlie

func (kr *Sr25519Keyring) Charlie() KeyPair

Charlie returns Charlie's key

func (*Sr25519Keyring) Dave

func (kr *Sr25519Keyring) Dave() KeyPair

Dave returns Dave's key

func (*Sr25519Keyring) Eve

func (kr *Sr25519Keyring) Eve() KeyPair

Eve returns Eve's key

func (*Sr25519Keyring) Ferdie added in v0.2.0

func (kr *Sr25519Keyring) Ferdie() KeyPair

Ferdie returns Ferdie's key

func (*Sr25519Keyring) George

func (kr *Sr25519Keyring) George() KeyPair

George returns George's key

func (*Sr25519Keyring) Heather

func (kr *Sr25519Keyring) Heather() KeyPair

Heather returns Heather's key

func (*Sr25519Keyring) Ian

func (kr *Sr25519Keyring) Ian() KeyPair

Ian returns Ian's key

type Typer added in v0.8.0

type Typer interface {
	Type() crypto.KeyType
}

Typer returns the key type.

type TyperInserter added in v0.8.0

type TyperInserter interface {
	Typer
	Inserter
}

TyperInserter has the Type and Insert methods.

Jump to

Keyboard shortcuts

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