Commands

Sign Message

Sign message lets you create an EIP-191 signature.

Sending the command

app/page.tsx

import { MiniKit, SignMessageInput } from '@worldcoin/minikit-js'

  const onSignMessage = () => {
    const signMessagePayload: SignMessageInput = {
      message: "Hello world",
    };

    MiniKit.commands.signMessage(signMessagePayload);
  };

Receiving the response

The response will include a signature compliant with EIP-191. You should verify the signature.

type MiniAppSignMessageSuccessPayload = {
  status: "success";
  signature: string;
  address: string;
  version: number;
};

app/page.tsx

import { MiniKit, ResponseEvent } from '@worldcoin/minikit-js'
import Safe, { hashSafeMessage } from "@safe-global/protocol-kit";

 MiniKit.subscribe(ResponseEvent.MiniAppSignMessage, async (payload) => {
      if (payload.status === "success") {
        const messageHash = hashSafeMessage(messageToSign);

        const isValid = await (
          await Safe.init({
            provider:
              "https://opt-mainnet.g.alchemy.com/v2/your-api-key",
            safeAddress: payload.address,
          })
        ).isValidSignature(messageHash, payload.signature);

        // Checks functionally if the signature is correct
        if (isValid) {
          console.log("Signature is valid");
        } 
      }

    return () => {
      MiniKit.unsubscribe(ResponseEvent.MiniAppSignMessage);
    };
  }, []);

Your message is verified!