keystore

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2023 License: GPL-3.0 Imports: 17 Imported by: 1

Documentation

Overview

The keystore package is used to load keys from keystore files, both for live use and for testing.

The Keystore

The keystore file is used as a file representation of a key. It contains 4 parts: - The key type (secp256k1, sr25519) - The PublicKey - The Address - The ciphertext

This keystore also requires a password to decrypt into a usable key. The keystore library can be used to both encrypt keys into keystores, and decrypt keystore into keys. For more information on how to encrypt and decrypt from the command line, reference the README: https://github.com/elastos/Elastos.ELA.SideChain.EID/ChainBridge

The Keyring

The keyring provides predefined secp256k1 and srr25519 keys to use in testing. These keys are automatically provided during runtime and stored in memory rather than being stored on disk. There are 5 keys currenty supported: Alice, Bob, Charlie, Dave, and Eve.

Index

Constants

View Source
const AliceKey = "alice"

The Constant "keys". These are the name that the keys are based on. This can be expanded, but any additions must be added to Keys and to insecureKeyFromAddress

View Source
const BobKey = "bob"
View Source
const CharlieKey = "charlie"
View Source
const DaveKey = "dave"
View Source
const EnvPassword = "KEYSTORE_PASSWORD"
View Source
const EthChain = "ethereum"

The Chain type Constants

View Source
const EveKey = "eve"
View Source
const SubChain = "substrate"

Variables

Functions

func DecodeKeypair

func DecodeKeypair(in []byte, keytype crypto.KeyType) (kp crypto.Keypair, err error)

DecodeKeypair turns input bytes into a keypair 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 DecryptKeypair

func DecryptKeypair(expectedPubK string, data, password []byte, keytype string) (crypto.Keypair, error)

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

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(file *os.File, kp crypto.Keypair, password []byte) error

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

func EncryptKeypair

func EncryptKeypair(kp crypto.Keypair, password []byte) ([]byte, error)

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

func GetPassword

func GetPassword(msg string) []byte

prompt user to enter password for encrypted keystore

func KeypairFromAddress

func KeypairFromAddress(chainType, path string, password []byte, insecure bool) (crypto.Keypair, error)

KeypairFromAddress attempts to load the encrypted key file for the provided address, prompting the user for the password.

func ReadFromFileAndDecrypt

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

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

Types

type EncryptedKeystore

type EncryptedKeystore struct {
	Type       string `json:"type"`
	PublicKey  string `json:"publicKey"`
	Address    string `json:"address"`
	Ciphertext []byte `json:"ciphertext"`
}

type TestKeyRingHolder

type TestKeyRingHolder struct {
	EthereumKeys  map[string]*secp256k1.Keypair
	SubstrateKeys map[string]*secp256k1.Keypair
}

TestKeyStore is a struct that holds a Keystore of all the test keys

var TestKeyRing *TestKeyRingHolder

Jump to

Keyboard shortcuts

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