Othent
  • 👋Welcome to Othent
  • 🥪JS SDK
    • Getting Started
    • Events
    • Error Handling
    • Binary Data Types Utils
    • TypeScript Types
    • Config Constants
  • 🥪JS SDK API
    • constructor()
    • startTabSynching()
    • completeConnectionAfterRedirect()
    • connect()
    • disconnect()
    • requireAuth()
    • isAuthenticated
    • getActiveAddress()
    • getActivePublicKey()
    • getAllAddresses()
    • getWalletNames()
    • getUserDetails()
    • getSyncActiveAddress()
    • getSyncActivePublicKey()
    • getSyncAllAddresses()
    • getSyncWalletNames()
    • getSyncUserDetails()
    • sign() (transaction)
    • dispatch() (transaction)
    • encrypt()
    • decrypt()
    • signature()
    • signDataItem()
    • signMessage()
    • verifyMessage()
    • privateHash()
    • walletName
    • walletVersion
    • config
    • getArweaveConfig()
    • getPermissions()
  • Demos
    • 🍏SDK playground / demo
    • 🍏SDK playground / demo GitHub
    • 🍎File upload app example
    • 🍎File upload app example GitHub
  • 📚External libraries
    • arweave-js
    • Arweave Wallet Kit
  • Additional Links
    • 🌐Othent.io
    • 🌐Discord
    • 🌐GitHub
    • 🌐X
Powered by GitBook
On this page
  • API
  • data: string | BinaryDataType
  • options?: SignMessageOptions
  • return Promise<Uint8Array>
  • Example usage
  1. JS SDK API

signMessage()

Othent JS SDK signMessage() function

PrevioussignDataItem()NextverifyMessage()

Last updated 8 months ago

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 .

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 , or instead.

Tip: This function's implementation is compatible with ArConnect's signMessage() and verifyMessage()'s.

Tip: The function first hashes the input data for security reasons. We recommend using the built in function to validate the signature, or hashing the data the same way, before validation ().

API

signMessage(
  data: string | BinaryDataType,
  options?: SignMessageOptions,
): Promise<Uint8Array>;

data: string | BinaryDataType

The data to generate the signature for.

options?: SignMessageOptions

The 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>

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"}`);

A Promise containing an Uint8Array with the signed hash of the data, which can be verified with .

🥪
Othent.verifyMessage
requireAuth()
sign()
signDataItem()
dispatch()
verifyMessage()
example