personal_sign
Requests a specified account to personally sign a message. The wallet will prepend the "\x19Ethereum Signed Message:\n" prefix to the message according to EIP-191 to reduce the risk of the signature being disguised as a transaction.
Inputs
| Index | Type | Description |
|---|---|---|
| 0 | string | The message to be signed must be hexadecimal encoded |
| 1 | string | The account address that initiated the signature |
return value
string - 65-byte signature, hexadecimal string format.
Demo
const message = "Hello, UKey Wallet!";
const hexMessage = "0x" + Buffer.from(message, "utf8").toString("hex");
const signature = await window.$ukey.ethereum.request({
method: "personal_sign",
requestParams: [hexMessage, accounts[0]],
});
console.log("Generated signature:", signature);
Using ethers.js
import { hashMessage, recoverAddress } from "ethers";
const message = "Hello, UKey Wallet!";
const hexMessage = "0x" + Buffer.from(message, "utf8").toString("hex");
const signature = await window.$ukey.ethereum.request({
method: "personal_sign",
requestParams: [hexMessage, accounts[0]],
});
// Validate signature
const recoveredAddress = recoverAddress(hashMessage(message), signature);
console.log("Verification result:", recoveredAddress === accounts[0]);
error code
| Code | Message | Details |
|---|---|---|
| 4001 | User rejected the request | Signature approval was rejected by the user |
| -32602 | Parameters failed validation | Message or address format is invalid |
illustrate
- Message parameters must be hex strings starting with
0x. - The content of the actual signature is:
"\x19Ethereum Signed Message:\n" + len(message) + message. - Add nonce, domain name and expiration time to the login signature to prevent replay.
- For structured authorization or order signature, please use eth_signTypedData_v4 first.
- Follows EIP-191 specification.