mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
* wip * fixing tests * adding more tests especially to handle legacy * fixing linting * fixing deepsource issues and flags * fixing some deepsource issues,pathing issues, and logs * some review items * adding additional review feedback * updating to follow updates from https://github.com/ethereum/keymanager-APIs/pull/74 * adjusting functions to match changes in keymanagers PR * Update validator/rpc/auth_token.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/rpc/auth_token.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/rpc/auth_token.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * review feedback --------- Co-authored-by: Radosław Kapka <rkapka@wp.pl>
33 lines
948 B
Go
33 lines
948 B
Go
package api
|
|
|
|
import (
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/v5/crypto/rand"
|
|
)
|
|
|
|
// GenerateRandomHexString generates a random hex string that follows the standards for jwt token
|
|
// used for beacon node -> execution client
|
|
// used for web client -> validator client
|
|
func GenerateRandomHexString() (string, error) {
|
|
secret := make([]byte, 32)
|
|
randGen := rand.NewGenerator()
|
|
n, err := randGen.Read(secret)
|
|
if err != nil {
|
|
return "", err
|
|
} else if n != 32 {
|
|
return "", errors.New("rand: unexpected length")
|
|
}
|
|
return hexutil.Encode(secret), nil
|
|
}
|
|
|
|
// ValidateAuthToken validating auth token for web
|
|
func ValidateAuthToken(token string) error {
|
|
b, err := hexutil.Decode(token)
|
|
// token should be hex-encoded and at least 256 bits
|
|
if err != nil || len(b) < 32 {
|
|
return errors.New("invalid auth token: token should be hex-encoded and at least 256 bits")
|
|
}
|
|
return nil
|
|
}
|