keystore

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2020 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StandardScryptN is the N parameter of Scrypt encryption algorithm, using 256MB
	// memory and taking approximately 1s CPU time on a modern processor.
	StandardScryptN = 1 << 18

	// StandardScryptP is the P parameter of Scrypt encryption algorithm, using 256MB
	// memory and taking approximately 1s CPU time on a modern processor.
	StandardScryptP = 1

	// LightScryptN is the N parameter of Scrypt encryption algorithm, using 4MB
	// memory and taking approximately 100ms CPU time on a modern processor.
	LightScryptN = 1 << 12

	// LightScryptP is the P parameter of Scrypt encryption algorithm, using 4MB
	// memory and taking approximately 100ms CPU time on a modern processor.
	LightScryptP = 6
)

Constants taken from https://github.com/ethereum/go-ethereum/blob/master/accounts/keystore/passphrase.go

Variables

View Source
var (
	ErrStorageLock     = fmt.Errorf("unable to acquire storage lock")
	ErrStorageUnlocked = fmt.Errorf("storage is not locked")
	ErrKeyNotInCache   = fmt.Errorf("public key not found in the cache.  Maybe it's not unlocked")
	ErrKeyNotFound     = fmt.Errorf("public key not found in the key store")
	ErrInvalidEncData  = fmt.Errorf("invalid encrypted data")
)
View Source
var LightKeyStoreParams = KeyStoreParams{
	ScryptN: LightScryptN,
	ScryptP: LightScryptP,
}

LightKeyStoreParams are parameters for fast key derivation

View Source
var (
	// PrefixMinorUpdate is for signatures related to update the root of an identity as minor update
	PrefixMinorUpdate = []byte("minorupdate")
)
View Source
var StandardKeyStoreParams = KeyStoreParams{
	ScryptN: StandardScryptN,
	ScryptP: StandardScryptP,
}

StandardKeyStoreParams are parameters for very secure derivation

Functions

func DecryptData

func DecryptData(encData *EncryptedData, pass []byte) ([]byte, error)

DecryptData decrypts the encData with the key derived from pass.

func VerifySignature

func VerifySignature(pkComp *babyjub.PublicKeyComp, sigComp *babyjub.SignatureComp, prefix PrefixType, date int64, rawMsg []byte) (bool, error)

VerifySignature verifies that the signature sigComp of the poseidon hash of the [prefix | date | msg] byte slice was signed with the public key pkComp.

func VerifySignatureElem

func VerifySignatureElem(pkComp *babyjub.PublicKeyComp, msg *big.Int, sigComp *babyjub.SignatureComp) (bool, error)

VerifySignatureElem verifies that the signature sigComp of the field element msg was signed with the public key pkComp.

func VerifySignatureRaw

func VerifySignatureRaw(pkComp *babyjub.PublicKeyComp, sigComp *babyjub.SignatureComp, msg []byte) (bool, error)

VerifySignatureRaw verifies that the signature sigComp of the poseidon hash of the msg byte slice was signed with the public key pkComp.

Types

type EncryptedData

type EncryptedData struct {
	Salt          common3.Hex
	ScryptN       int
	ScryptP       int
	Nonce         common3.Hex
	EncryptedData common3.Hex
}

EncryptedData contains the key derivation parameters and encryption parameters with the encrypted data.

func EncryptData

func EncryptData(data, pass []byte, scryptN, scryptP int) (*EncryptedData, error)

EncryptedData encrypts data with a key derived from pass

type FileStorage

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

FileStorage is a storage backed by a file.

func NewFileStorage

func NewFileStorage(path string) *FileStorage

NewFileStorage returns a new FileStorage backed by a file in path.

func (*FileStorage) Read

func (fs *FileStorage) Read() ([]byte, error)

Read reads the file contents.

func (*FileStorage) TryLock

func (fs *FileStorage) TryLock() (bool, error)

TryLocks the storage file with a .lock file.

func (*FileStorage) Unlock

func (fs *FileStorage) Unlock() error

Unlocks the storage file and removes the .lock file.

func (*FileStorage) Write

func (fs *FileStorage) Write(data []byte) error

Write writes the data to the file.

type KeyStore

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

KeyStore is the object used to access create keys and sign with them.

func NewKeyStore

func NewKeyStore(storage Storage, params KeyStoreParams) (*KeyStore, error)

NewKeyStore creates a new key store or opens it if it already exists.

func (*KeyStore) Close

func (ks *KeyStore) Close() error

func (*KeyStore) ExportKey

func (ks *KeyStore) ExportKey(pk *babyjub.PublicKeyComp) (*babyjub.PrivateKey, error)

func (*KeyStore) ImportKey

func (ks *KeyStore) ImportKey(sk babyjub.PrivateKey, pass []byte) (*babyjub.PublicKeyComp, error)

ImportKey imports a secret key into the storage and encrypts it with pass.

func (*KeyStore) Keys

func (ks *KeyStore) Keys() []babyjub.PublicKeyComp

Keys returns the compressed public keys of the key storage.

func (*KeyStore) NewKey

func (ks *KeyStore) NewKey(pass []byte) (*babyjub.PublicKeyComp, error)

NewKey creates a new key in the key store encrypted with pass.

func (*KeyStore) Sign

func (ks *KeyStore) Sign(pk *babyjub.PublicKeyComp, prefix PrefixType, rawMsg []byte) (*babyjub.SignatureComp, int64, error)

Sign uses the key corresponding to the public key pk to sign the mimc7 hash of the [prefix | date | msg] byte slice.

func (*KeyStore) SignElem

func (ks *KeyStore) SignElem(pk *babyjub.PublicKeyComp, msg *big.Int) (*babyjub.SignatureComp, error)

SignElem uses the key corresponding to the public key pk to sign the field element msg.

func (*KeyStore) SignRaw

func (ks *KeyStore) SignRaw(pk *babyjub.PublicKeyComp, msg []byte) (*babyjub.SignatureComp, error)

SignRaw uses the key corresponding to the public key pk to sign the mimc7/poseidon hash of the msg byte slice.

func (*KeyStore) UnlockKey

func (ks *KeyStore) UnlockKey(pk *babyjub.PublicKeyComp, pass []byte) error

UnlockKey decrypts the key corresponding to the public key pk and loads it into the cache.

type KeyStoreParams

type KeyStoreParams struct {
	ScryptN int
	ScryptP int
}

KeyStoreParams are the Key Store parameters

type KeysStored

type KeysStored map[babyjub.PublicKeyComp]EncryptedData

KeysStored is the datastructure of stored keys in the storage.

type MemStorage

type MemStorage []byte

MemStorage is a storage backed by a slice.

func (*MemStorage) Read

func (ms *MemStorage) Read() ([]byte, error)

Read reads the slice contents.

func (*MemStorage) TryLock

func (ms *MemStorage) TryLock() (bool, error)

TryLock does nothing.

func (*MemStorage) Unlock

func (ms *MemStorage) Unlock() error

Unlock does nothing.

func (*MemStorage) Write

func (ms *MemStorage) Write(data []byte) error

Write copies the data to the slice.

type PrefixType

type PrefixType []byte

prefixes for msg to be signed

type Storage

type Storage interface {
	Read() ([]byte, error)
	Write(data []byte) error
	TryLock() (bool, error)
	Unlock() error
}

Storage is an interface for a storage container.

Jump to

Keyboard shortcuts

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