signMessage()
Othent JS SDK signMessage() function
The signMessage() function creates a cryptographic signature of any data (after hashing it) for later validation, using the active (authenticated) user's private key.
This function assumes (and requires) a user is authenticated. See requireAuth().
Also, this function should only be used to allow data validation. It cannot be used for on-chain transactions, interactions or bundles, for security reasons. Consider using sign(), signDataItem() or dispatch() instead.
API
signMessage(
data: string | BinaryDataType,
options?: SignMessageOptions,
): Promise<Uint8Array>;data: string | BinaryDataType
data: string | BinaryDataTypeThe data to generate the signature for.
options?: SignMessageOptions
options?: SignMessageOptionsThe options argument is optional. If it is not provided, the extension will use the SHA-256 hash algorithm.
interface SignMessageOptions {
hashAlgorithm?: "SHA-256" | "SHA-384" | "SHA-512";
}return Promise<Uint8Array>
return Promise<Uint8Array>A Promise containing an Uint8Array with the signed hash of the data, which can be verified with Othent.verifyMessage.
Example usage
import { Othent } from "@othent/kms";
const othent = new Othent({ appInfo, throwErrors: false, ... });
// Make sure the user is authenticated, or prompt them to authenticate:
await othent.requireAuth();
// Message to be signed:
const data = "The hash of this msg will be signed.";
// Create signature:
const signature = await othent.signMessage(data);
// Verify signature:
const isValidSignature = await othent.verifyMessage(data, signature);
console.log(`The signature is ${isValidSignature ? "valid" : "invalid"}`);Last updated