exchange.IO("signMessage", ...)
Signs messages according to the EIP-191 standard (personal_sign). The signature result is consistent with signMessage of ethers and personal_sign of wallets, and is commonly used in scenarios such as DApp login and off-chain authentication.
exchange.IO(k, message)
exchange.IO(k, message, key)Examples
Sign a message and recover the signer address through the ecrecover precompiled contract.
javascript
function main() {
// Sign text using UTF-8 encoding (the result is consistent with ethers signMessage and wallet
// personal_sign)
var sig = exchange.IO("signMessage", "hello fmz")
Log("digest:", sig.digest, "signature:", sig.signature)
// Raw bytes are passed in via {hex: ...}
var sig2 = exchange.IO("signMessage", { hex: "0x68656c6c6f20666d7a" })
Log("Consistent with text signature:", sig.signature === sig2.signature)
// Use the ecrecover precompiled contract to recover the signer address; the result should match
// the current wallet address
var ret = exchange.IO("call", "0x0000000000000000000000000000000000000001",
"0x" + sig.digest.slice(2) + exchange.IO("encode", "uint8,bytes32,bytes32", sig.v, sig.r,
sig.s))
Log("Recovered address:", "0x" + String(ret).slice(-40), "Wallet address:",
exchange.IO("address").toLowerCase())
}Returns
| Type | Description |
object | Returns a signature object whose fields are the same as the return value of |
Arguments
| Name | Type | Required | Description |
k | string | Yes | Function of the |
message | string / object | Yes | Message to be signed: when a string is passed in, it is signed using UTF-8 encoding; when raw bytes need to be signed, pass in an object in the format |
key | string | No | Private key used for signing. When this parameter is not passed in, the private key configured for the |
See Also