Commands

Sign Typed Data

Sign Typed Data lets you create an EIP-712 signature.

Sending the command

import type { TypedData, TypedDataDomain } from "abitype";

export type SignTypedDataInput = {
  types: TypedData;
  primaryType: string;
  message: Record<string, unknown>;
  domain?: TypedDataDomain;
};

app/page.tsx

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

  const onSignTypedData = () => {
    const payload = MiniKit.commands.signTypedData(
      somePayloadforEIP712 as SignTypedDataInput;
    );
  };

Receiving the response

Verifying the signature. Note permit2 payloads and safe operations are not permitted in this command.

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

app/page.tsx

import { MiniKit, ResponseEvent } from '@worldcoin/minikit-js'
useEffect(() => {
    if (!MiniKit.isInstalled()) {
      return;
    }

    MiniKit.subscribe(ResponseEvent.MiniAppSignTypedData,
      async (payload: MiniAppSignTypedDataPayload) => {
        if (payload.status === "success") {
         const messageHash = hashSafeMessage(signTypedDataPayload);

          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");
          }
        }
      }
    );
}, []);