crypto

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: GPL-3.0 Imports: 33 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// b64 encrypted key length is 256
	EncryptedKeyLength = 256
	// Signature len
	SignatureLength = 256
	// BLSWithdrawalPrefixByte is the BLS withdrawal prefix
	BLSWithdrawalPrefixByte  = byte(0)
	ETH1WithdrawalPrefixByte = byte(1)
)

Variables

This section is empty.

Functions

func BLSWithdrawalCredentialsHash

func BLSWithdrawalCredentialsHash(withdrawalPubKey []byte) []byte

withdrawalCredentialsHash forms a 32 byte hash of the withdrawal public address.

The specification is as follows:

withdrawal_credentials[:1] == BLS_WITHDRAWAL_PREFIX_BYTE
withdrawal_credentials[1:] == hash(withdrawal_pubkey)[1:]

where withdrawal_credentials is of type bytes32.

func ConvertPemToPrivateKey

func ConvertPemToPrivateKey(skPem string) (*rsa.PrivateKey, error)

ConvertPemToPrivateKey return rsa private key from secret key

func DepositData

func DepositData(masterSig, withdrawalPubKey, publicKey []byte, network e2m_core.Network, amount phase0.Gwei) (*phase0.DepositData, [32]byte, error)

DepositData crates and signs a ETH2 deposit message

func DepositDataRoot

func DepositDataRoot(withdrawalPubKey []byte, publicKey *bls.PublicKey, network e2m_core.Network, amount phase0.Gwei) ([]byte, error)

DepositDataRoot computes a deposit root used for ETH2 deposit message

func ETH1WithdrawalCredentialsHash

func ETH1WithdrawalCredentialsHash(withdrawalAddr []byte) []byte

func EncodePublicKey

func EncodePublicKey(pk *rsa.PublicKey) ([]byte, error)

func Encrypt

func Encrypt(pk *rsa.PublicKey, plainText []byte) ([]byte, error)

Encrypt with secret key (base64) the bytes, return the encrypted key string

func EncryptPrivateKey added in v1.1.0

func EncryptPrivateKey(priv []byte, keyStorePassword string) ([]byte, error)

func EncryptedPrivateKey

func EncryptedPrivateKey(path, pass string) (*rsa.PrivateKey, error)

EncryptedPrivateKey reads an encoded RSA priv key from path encrypted with password

func GenerateKeys

func GenerateKeys() (*rsa.PrivateKey, *rsa.PublicKey, error)

GenerateKeys creates a random RSA key pair

func GenerateSecurePassword

func GenerateSecurePassword() (string, error)

GenerateSecurePassword randomly generates a password consisting of digits + english letters

func GetPubCommitsFromSharesData added in v1.2.0

func GetPubCommitsFromSharesData(reshare *wire.Reshare) ([]kyber.Point, error)

func GetSecretShareFromSharesData added in v1.2.0

func GetSecretShareFromSharesData(keyshares, initiatorPublicKey, ceremonySigs []byte, oldOperators []*wire.Operator, opPrivateKey *rsa.PrivateKey, operatorID uint64) (*share.PriShare, error)

func KyberShareToBLSKey added in v1.0.0

func KyberShareToBLSKey(privShare *share.PriShare) (*bls.SecretKey, error)

KyberShareToBLSKey converts a kyber private share to github.com/herumi/bls-eth-go-binary/bls private key

func NewID

func NewID() [24]byte

NewID generates a random ID from 2 random concat UUIDs

func ParseRSAPubkey

func ParseRSAPubkey(pk []byte) (*rsa.PublicKey, error)

ParseRSAPubkey parses encoded to base64 x509 RSA public key

func ReadEncryptedPrivateKey added in v1.1.0

func ReadEncryptedPrivateKey(keyData []byte, password string) (*rsa.PrivateKey, error)

ReadEncryptedPrivateKey return rsa private key from secret key

func ReadEncryptedRSAKey added in v1.1.0

func ReadEncryptedRSAKey(privKeyPath, privKeyPassPath string) (*rsa.PrivateKey, error)

func ReconstructSignatures added in v1.0.0

func ReconstructSignatures(ids []uint64, signatures [][]byte) (*bls.Sign, error)

ReconstructSignatures receives a map of user indexes and serialized bls.Sign. It then reconstructs the original threshold signature using lagrange interpolation

func RecoverMasterSig

func RecoverMasterSig(ids []uint64, sigDepositShares []*bls.Sign) (*bls.Sign, error)

RecoverMasterSig recovers a BLS master signature from T-threshold partial signatures

func RecoverValidatorPublicKey

func RecoverValidatorPublicKey(ids []uint64, sharePks []*bls.PublicKey) (*bls.PublicKey, error)

RecoverValidatorPublicKey recovers a BLS master public key (validator pub key) from provided partial pub keys

func ResultToShareSecretKey

func ResultToShareSecretKey(result *drand_dkg.DistKeyShare) (*bls.SecretKey, error)

ResultToShareSecretKey converts a private share at kyber DKG result to github.com/herumi/bls-eth-go-binary/bls private key

func ResultToValidatorPK

func ResultToValidatorPK(result *drand_dkg.DistKeyShare, suite drand_dkg.Suite) (*bls.PublicKey, error)

ResultsToValidatorPK converts a public polynomial at kyber DKG result to github.com/herumi/bls-eth-go-binary/bls public key

func SignDepositData

func SignDepositData(validationKey *bls.SecretKey, withdrawalPubKey []byte, validatorPublicKey *bls.PublicKey, network e2m_core.Network, amount phase0.Gwei) (*bls.Sign, []byte, error)

SignDepositData creates a BLS signature for ETH2 deposit message

func SignRSA

func SignRSA(sk *rsa.PrivateKey, byts []byte) ([]byte, error)

SignRSA create a RSA signature for incoming bytes

func VerifyDepositData

func VerifyDepositData(depositData *phase0.DepositData, network e2m_core.Network) (bool, error)

VerifyDepositData reconstructs and checks BLS signatures for ETH2 deposit message

func VerifyOwnerNonceSignature added in v1.1.0

func VerifyOwnerNonceSignature(sig []byte, owner common.Address, pubKey []byte, nonce uint16) error

VerifyOwnerNonceSignature check that owner + nonce correctly signed

func VerifyPartialSigs

func VerifyPartialSigs(sigShares []*bls.Sign, sharePks []*bls.PublicKey, data []byte) error

VerifyPartialSigs verifies provided partial BLS signatures

func VerifyRSA

func VerifyRSA(pk *rsa.PublicKey, msg, signature []byte) error

VerifyRSA verifies RSA signature for incoming message

func VerifyReconstructedSignature added in v1.0.0

func VerifyReconstructedSignature(sig *bls.Sign, validatorPubKey, msg []byte) error

VerifyReconstructedSignature checks a reconstructed msg master signature against validator public key

Types

This section is empty.

Jump to

Keyboard shortcuts

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