Commands
Sign Typed Data
Sign Typed Data lets you create an EIP-712 signature.
Use Case: This command is essential for applications that require structured data to be signed.
Example: An insurance platform that requires users to sign typed data to confirm the terms of their insurance policy.
Note: The
EIP712Domain
must always includechainId
.On Worldchain, only custom typed data is permitted.
- SafeTx and Permit/Permit2 types are not allowed.
On all other chains, any valid EIP-712 structure is supported, including SafeTx and Permit types.
{
types: {
YourTypes: [
{ type: 'bytes', name: 'data' },
{ type: 'uint8', name: 'operation' },
],
EIP712Domain: [
{ type: 'uint256', name: 'chainId' },
{ type: 'address', name: 'verifyingContract' },
],
},
domain: {
chainId: 480,
verifyingContract: "0x1234...",
},
primaryType: 'YourTypes',
message:{ data: '0xffffffff', operation: 15}
}
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;
);
if (payload.status === 'success') {
const messageHash = hashSafeMessage(signTypedDataPayload)
const isValid = await (
await Safe.init({
provider: 'https://worldchain-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')
}
}
};