keystore

package
v1.0.19 Latest Latest
Warning

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

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

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/ChainSafe/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

View Source
var AliceSr25519 = sr25519.NewKeypairFromKRP(signature.KeyringPair{
	URI:       "//Alice",
	Address:   "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
	PublicKey: []byte{0xd4, 0x35, 0x93, 0xc7, 0x15, 0xfd, 0xd3, 0x1c, 0x61, 0x14, 0x1a, 0xbd, 0x4, 0xa9, 0x9f, 0xd6, 0x82, 0x2c, 0x85, 0x58, 0x85, 0x4c, 0xcd, 0xe3, 0x9a, 0x56, 0x84, 0xe7, 0xa5, 0x6d, 0xa2, 0x7d},
})
View Source
var BobSr25519 = sr25519.NewKeypairFromKRP(signature.KeyringPair{
	URI:       "//Bob",
	Address:   "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
	PublicKey: []byte{0x8e, 0xaf, 0x4, 0x15, 0x16, 0x87, 0x73, 0x63, 0x26, 0xc9, 0xfe, 0xa1, 0x7e, 0x25, 0xfc, 0x52, 0x87, 0x61, 0x36, 0x93, 0xc9, 0x12, 0x90, 0x9c, 0xb2, 0x26, 0xaa, 0x47, 0x94, 0xf2, 0x6a, 0x48},
})
View Source
var CharlieSr25519 = sr25519.NewKeypairFromKRP(signature.KeyringPair{
	URI:       "//Charlie",
	Address:   "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y",
	PublicKey: []byte{0x90, 0xb5, 0xab, 0x20, 0x5c, 0x69, 0x74, 0xc9, 0xea, 0x84, 0x1b, 0xe6, 0x88, 0x86, 0x46, 0x33, 0xdc, 0x9c, 0xa8, 0xa3, 0x57, 0x84, 0x3e, 0xea, 0xcf, 0x23, 0x14, 0x64, 0x99, 0x65, 0xfe, 0x22},
})
View Source
var DaveSr25519 = sr25519.NewKeypairFromKRP(signature.KeyringPair{
	URI:       "//Dave",
	Address:   "5DAAnrj7VHTznn2AWBemMuyBwZWs6FNFjdyVXUeYum3PTXFy",
	PublicKey: []byte{0x30, 0x67, 0x21, 0x21, 0x1d, 0x54, 0x4, 0xbd, 0x9d, 0xa8, 0x8e, 0x2, 0x4, 0x36, 0xa, 0x1a, 0x9a, 0xb8, 0xb8, 0x7c, 0x66, 0xc1, 0xbc, 0x2f, 0xcd, 0xd3, 0x7f, 0x3c, 0x22, 0x22, 0xcc, 0x20},
})
View Source
var EveSr25519 = sr25519.NewKeypairFromKRP(signature.KeyringPair{
	URI:       "//Eve",
	Address:   "5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw",
	PublicKey: []byte{0xe6, 0x59, 0xa7, 0xa1, 0x62, 0x8c, 0xdd, 0x93, 0xfe, 0xbc, 0x4, 0xa4, 0xe0, 0x64, 0x6e, 0xa2, 0xe, 0x9f, 0x5f, 0xc, 0xe0, 0x97, 0xd9, 0xa0, 0x52, 0x90, 0xd4, 0xa9, 0xe0, 0x54, 0xdf, 0x4e},
})

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(addr, chainType, path string, 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]*sr25519.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