crypto

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: GPL-3.0 Imports: 26 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// b64 encrypted key length is 256
	EncryptedKeyLength = 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 ConvertEncryptedPemToPrivateKey

func ConvertEncryptedPemToPrivateKey(pemData []byte, password string) (*rsa.PrivateKey, error)

ConvertEncryptedPemToPrivateKey return rsa private key from secret key

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 EncryptedPrivateKey

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

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

func ExtractPrivateKey

func ExtractPrivateKey(sk *rsa.PrivateKey) string

ExtractPrivateKey gets private key and returns base64 encoded private key

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 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 PrivateKey

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

PrivateKey reads an encoded RSA priv key from path

func ReconstructSignatures added in v1.0.0

func ReconstructSignatures(signatures map[uint64][]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(sigDepositShares map[uint64]*bls.Sign) (*bls.Sign, error)

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

func RecoverValidatorPublicKey

func RecoverValidatorPublicKey(sharePks map[uint64]*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.Result) (*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.Result, 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 VerifyOwnerNoceSignature

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

func VerifyPartialSigs

func VerifyPartialSigs(sigShares map[uint64]*bls.Sign, sharePks map[uint64]*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