recoverPublicKey
Recovers the public key from a hash and signature
Loading...
Recovers the public key from a hash and signature
Recovers the public key from a hash and signature. Returns the uncompressed public key (65 bytes with 04 prefix).
import "github.com/ChefBingbong/viem-go/utils/signature"import "github.com/ChefBingbong/viem-go/utils/signature"
// Recover public key from hash and signaturepubKey, err := signature.RecoverPublicKey( "0xd9eba16ed0ecae432b71fe008c98cc872bb4cc214d3220a36f365326cf807d68", "0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c",)if err != nil { log.Fatal(err)}fmt.Printf("Public Key: %s", pubKey)// Public Key: 0x04bfcab88f42f8d0a...
// Get public key as bytespubKeyBytes, _ := signature.RecoverPublicKeyBytes( hash, sig,)// []byte{0x04, 0xbf, 0xca, ...}(string, error) for RecoverPublicKey, ([]byte, error) for RecoverPublicKeyBytesThe recovered public key. RecoverPublicKey returns a hex string with 0x prefix (65 bytes uncompressed format with 04 prefix), RecoverPublicKeyBytes returns raw bytes.
stringThe 32-byte hash that was signed. Must be a hex string with 0x prefix.
pubKey, _ := signature.RecoverPublicKey( "0xd9eba16ed0ecae432b71fe008c98cc872bb4cc214d3220a36f365326cf807d68", sig,)any (supports string, []byte, or *signature.Signature)The signature that was generated by signing the hash.
pubKey, _ := signature.RecoverPublicKey(hash, "0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c")Recovers the public key and returns it as a hex string:
pubKey, _ := signature.RecoverPublicKey(hash, sig)
// "0x04bfcab88f42f8d0a..." (65 bytes)
Recovers the public key and returns it as raw bytes:
pubKeyBytes, _ := signature.RecoverPublicKeyBytes(hash, sig)
// []byte{0x04, 0xbf, 0xca, ...} (65 bytes)
04 prefix)PublicKeyToAddressRecoverAddress or RecoverMessageAddress