A simple Golang solution for MetaMasks personal_sign method (https://docs.metamask.io/guide/signing-data.html#a-brief-history). Create a MetaMask signature for comparison: https://app.mycrypto.com/sign-message
Install:
go get github.com/etaaa/Golang-Ethereum-Personal-Sign
Usage:
package main
import (
"fmt"
"log"
"os"
"testing"
"github.com/ethereum/go-ethereum/crypto"
"github.com/joho/godotenv"
ps "github.com/etaaa/Golang-Ethereum-Personal-Sign"
)
func main() {
// Load private key from .env file
err := godotenv.Load()
if err != nil {
log.Fatal(err)
}
privateKeyString := os.Getenv("PRIVATE_KEY")
// Parse private key
privateKey, err := crypto.HexToECDSA(privateKeyString)
if err != nil {
log.Fatal(err)
}
// Sign message
signature, err := ps.PersonalSign("Hello World.", privateKey)
if err != nil {
log.Fatal(err)
}
fmt.Println(signature)
}
For any questions feel free to DM me on Discord (@itseta).
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.