Commands

Sign Typed Data

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

Using the command

Async handlersEvent listeners

Sending the command & handling the response

import type { TypedData, TypedDataDomain } from 'abitype'

export type SignTypedDataInput = {
  types: TypedData
  primaryType: string
  message: Record<string, unknown>
  domain?: TypedDataDomain
}
type MiniAppSignTypedDataSuccessPayload = {
  status: 'success'
  signature: string
  address: string
  version: number
}

app/page.tsx

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

  const signAndVerifyTypedData = async () => {
    if (!MiniKit.isInstalled()) {
      return
    }

    const {finalPayload} = await MiniKit.commandsAsync.signTypedData(
      somePayloadforEIP712 as SignTypedDataInput;
    );

    // Verifying the signature. Note permit2 payloads and safe operations are not permitted in this command.
    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')
      }
    }
  };