Skip to content

Commit

Permalink
bls key script
Browse files Browse the repository at this point in the history
  • Loading branch information
metachris committed Apr 25, 2024
1 parent 256fd3c commit d7d89d6
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions scripts/create-bls-keypair/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,45 @@ import (
"fmt"
"log"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/flashbots/go-boost-utils/bls"
)

func main() {
sk := GenSecretKey()
// sk := SecretKeyFromHexString("0x")

// Convert secret key to public key
blsPubkey, err := bls.PublicKeyFromSecretKey(sk)
if err != nil {
log.Fatal(err.Error())
}

// Print secret key and public key
fmt.Printf("secret key: 0x%x\n", bls.SecretKeyToBytes(sk))
fmt.Printf("public key: 0x%x\n", bls.PublicKeyToBytes(blsPubkey))
}

// GenSecretKey generates a random secret key
func GenSecretKey() *bls.SecretKey {
sk, _, err := bls.GenerateNewKeypair()
if err != nil {
log.Fatal(err.Error())
}
return sk
}

blsPubkey, err := bls.PublicKeyFromSecretKey(sk)
// SecretKeyFromHexString converts a hex string to a BLS secret key
func SecretKeyFromHexString(secretKeyHex string) *bls.SecretKey {
skBytes, err := hexutil.Decode(secretKeyHex)
if err != nil {
log.Fatal(err.Error())
}

fmt.Printf("secret key: 0x%x\n", bls.SecretKeyToBytes(sk))
fmt.Printf("public key: 0x%x\n", bls.PublicKeyToBytes(blsPubkey))
blsSecretKey, err := bls.SecretKeyFromBytes(skBytes[:])
if err != nil {
log.Fatal(err.Error())
}

return blsSecretKey
}

0 comments on commit d7d89d6

Please sign in to comment.