forked from flashbots/mev-boost-relay
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BLS key script improvement: allow hex string input (flashbots#611)
* bls key script * https://github.com/dvush/bls-vanity
- Loading branch information
Showing
1 changed file
with
30 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,50 @@ | ||
package main | ||
|
||
// See also https://github.com/dvush/bls-vanity for creating vanity BLS keys! | ||
|
||
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 | ||
} |