recoverMessageAddress
Recovers the Ethereum address that signed a message
recoverMessageAddress
Recovers the Ethereum address that signed a message from the message and signature.
Import
import "github.com/ChefBingbong/viem-go/utils/signature"Usage
import "github.com/ChefBingbong/viem-go/utils/signature"
address, err := signature.RecoverMessageAddress( signature.NewSignableMessage("hello world"), "0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c",)if err != nil { log.Fatal(err)}fmt.Printf("Signer: %s", address)// Signer: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266Returns
- Type:
(string, error)
The Ethereum address that signed the message, as a hex string with 0x prefix.
Parameters
message (required)
- Type:
signature.SignableMessage
The message that was signed. Use signature.NewSignableMessage() for string messages or signature.NewSignableMessageHex() for hex data.
// Recover from string messageaddress, _ := signature.RecoverMessageAddress( signature.NewSignableMessage("hello world"), sig,)
// Recover from hex dataaddress, _ = signature.RecoverMessageAddress( signature.NewSignableMessageHex("0x68656c6c6f20776f726c64"), sig,)signature (required)
- Type:
any(supportsstring,[]byte, or*signature.Signature)
The signature that was generated by signing the message.
// Hex string signatureaddress, _ := signature.RecoverMessageAddress( message, "0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c",)
// Signature structsig, _ := signature.ParseSignature("0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c")address, _ = signature.RecoverMessageAddress(message, sig)Implementation
This function:
- Hashes the message using
HashMessage(EIP-191 format) - Recovers the public key from the hash and signature
- Derives the Ethereum address from the public key
- Returns the address as a hex string