signMessage
Sign a message using the connected wallet. Supports UTF-8, Base64, and Hex encoding formats.
Usage
ts
const result = await Turing.signMessage({
message: "hello world",
encoding: "utf-8",
});Parameters
ts
interface SignMessageParams {
message: string; // The message to sign
encoding: "utf-8" | "base64" | "hex"; // Encoding format
}| Parameter | Type | Required | Description |
|---|---|---|---|
message | string | Yes | The message content to sign |
encoding | "utf-8" | "base64" | "hex" | Yes | Encoding format for the message |
Returns
ts
interface SignMessageResponse {
address: string; // Wallet address that signed
pubkey: string; // Public key used for signing
sig: string; // The generated signature
message: string; // The original message
}| Field | Type | Description |
|---|---|---|
address | string | The wallet address |
pubkey | string | The public key |
sig | string | The signature |
message | string | The original message |
Error Handling
This method throws an exception on failure. Use try-catch:
ts
try {
const { address, pubkey, sig, message } = await Turing.signMessage({
message: "hello world",
encoding: "base64",
});
console.log("Signed by:", address);
console.log("Signature:", sig);
} catch (error) {
console.error("Signing failed:", error);
}Verify Signature
You can verify the signature using tbc-lib-js:
ts
import * as tbc from "tbc-lib-js";
const msg_buf = Buffer.from(message, encoding);
const isValid = tbc.Message.verify(msg_buf, address, sig);
console.log("Signature valid:", isValid);