Function isTypedDataSignatureCorrect

  • Returns whether the account abstraction EIP712 signature is correct.

    Parameters

    • context: Web3Context<unknown, any>

      The web3 context.

    • address: string

      The sender address.

    • domain: Record<string, string | number>

      The domain data.

    • types: {
          EIP712Domain: Eip712TypeDetails[];
          [key: string]: Eip712TypeDetails[];
      }

      A map of records pointing from field name to field type.

      • [key: string]: Eip712TypeDetails[]
      • EIP712Domain: Eip712TypeDetails[]
    • value: Record<string, any>

      A single record value.

    • signature: SignatureLike

      The Ethers signature.

    Returns Promise<boolean>

    import { Wallet, utils, constants, Provider, EIP712Signer } from "web3-plugin-zksync";

    const ADDRESS = "<WALLET_ADDRESS>";
    const PRIVATE_KEY = "<WALLET_PRIVATE_KEY>";
    const context = Provider.getDefaultProvider(types.Network.Sepolia);

    const tx: types.TransactionRequest = {
    type: 113,
    chainId: 270,
    from: ADDRESS,
    to: "0xa61464658AfeAf65CccaaFD3a512b69A83B77618",
    value: BigInt(7_000_000),
    };

    const eip712Signer = new EIP712Signer(
    new Wallet(PRIVATE_KEY), // or web3Accounts.privateKeyToAccount(PRIVATE_KEY),
    Number((await context.getNetwork()).chainId)
    );

    const signature = await eip712Signer.sign(tx);

    const isValidSignature = await utils.isTypedDataSignatureCorrect(context, ADDRESS, await eip712Signer.getDomain(), constants.EIP712_TYPES, 'Transaction', EIP712Signer.getSignInput(tx), signature);
    // isValidSignature = true