Skip to content

Instantly share code, notes, and snippets.

@Librechain
Created February 17, 2023 18:05
Show Gist options
  • Save Librechain/ad0a5dc921f47604baf830fc478ceaa4 to your computer and use it in GitHub Desktop.
Save Librechain/ad0a5dc921f47604baf830fc478ceaa4 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/hex"
"fmt"
"github.com/ava-labs/avalanchego/utils/crypto"
)
func main() {
// Hexadecimal private key
privateKeyHex := "eeac0e3d8f0fcc32a553cc5ab8dad48a435bb4c047d95b06eb7a29a4a823e87c"
// Parse the private key
privateKeyBytes, _ := hex.DecodeString(privateKeyHex)
// Create a new private key object from the parsed bytes
// factory := &FactorySECP256K1R{}
factory := &crypto.FactorySECP256K1R{}
privateKey, err := factory.ToPrivateKey(privateKeyBytes)
if err != nil {
panic(err)
}
// Print the private key in hex format
fmt.Printf("Private key: %x\n", privateKeyBytes)
// Derive the public key from the private key
publicKey := privateKey.PublicKey()
// Print the public key in hex format
fmt.Printf("Public key: %x\n", publicKey.Bytes())
// Sign a message using the private key
message := []byte("avalanchesignature")
signature, err := privateKey.Sign(message)
if err != nil {
panic(err)
}
// Parse the signature
// r, s, v, err := parseSignature(signature)
// if err != nil {
// panic(err)
// }
// Print the signature and its components
fmt.Printf("Signature: %x\n", signature)
// fmt.Printf("r: %d\n", r)
// fmt.Printf("s: %x\n", s)
// fmt.Printf("v: %d\n", v)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment