# Signature.verifyTypedData

Says whether an account signed EIP-712 typed data, as
[`Signer.signTypedData`](https://ethect.dev/reference/signer/sign-typed-data/) and `eth_signTypedData_v4` sign
it: a permit, an order. The account can be a key or a contract, deployed or not yet.

## Usage

```ts
import { Effect } from "effect";
import { FetchHttpClient } from "effect/http";
import { Address, Signature, Transport, type Signer } from "@ethect/core";

const OWNER = Address.makeUnsafe("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266");

const permit: Signer.TypedData = {
  domain: {
    name: "USD Coin",
    version: "2",
    chainId: 1,
    verifyingContract: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
  },
  types: {
    Permit: [
      { name: "owner", type: "address" },
      { name: "spender", type: "address" },
      { name: "value", type: "uint256" },
      { name: "nonce", type: "uint256" },
      { name: "deadline", type: "uint256" },
    ],
  },
  primaryType: "Permit",
  message: {
    owner: OWNER,
    spender: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
    value: 1_000_000n,
    nonce: 0n,
    deadline: 1_900_000_000n,
  },
};

const signed = await Signature.verifyTypedData({
  address: OWNER,
  data: permit,
  signature:
    "0x6b13efcf3f9fdce3e36de59e0208e5b91d85f17bfd9d7e6be21a74324d9be56b1794577252bbc1ea3bdc4fe5d3f9b8a00931fd7a07e02e4892c6acab1284e6011b",
}).pipe(
  Effect.provide(Transport.http("https://ethereum-rpc.publicnode.com")),
  Effect.provide(FetchHttpClient.layer),
  Effect.runPromise,
); // true
```

It needs a node, which it asks only when the signature is not the one of a key.

### An address from a request

An address that comes from outside goes through
[`Address.make`](https://ethect.dev/reference/primitives/address/#make) first.

```ts
import { Effect } from "effect";
import { Address, Signature, type Hex, type Signer } from "@ethect/core";

const signedBy = (maker: string, order: Signer.TypedData, signature: Hex.Hex) =>
  Effect.flatMap(Address.make(maker), (address) =>
    Signature.verifyTypedData({ address, data: order, signature }),
  );
```

## Returns

`Effect<boolean, Transport.Error, Transport.Transport>`

`true` when the account signed the typed data, `false` when it did not.

## Parameters

### claim.address

- **Type:** [`Address.Address`](https://ethect.dev/reference/primitives/address/)

The account that is said to have signed.

### claim.data

- **Type:** [`Signer.TypedData`](https://ethect.dev/reference/signer/sign-typed-data/#data)

The typed data that was signed: `domain`, `types`, `primaryType` and `message`.

### claim.signature

- **Type:** `Hex | Signature.Signature`

The signature: what the signer gave. See [a signature](https://ethect.dev/reference/signature/#a-signature).

## Behavior

- **The typed data is hashed as the signer hashed it**: `EIP712Domain` is built from the
  fields the domain has, and an integer is a `bigint`, a safe `number` or digits in a string.
- **Typed data that cannot be hashed is `false`.** A type that is not declared, a field that is
  missing, a value that does not fit its type: nobody signed it.
  [`recoverTypedData`](https://ethect.dev/reference/signature/recover-typed-data/) says which, in its failure.
- **A key's signature costs no request.** The node is asked only for what a key did not sign.
- **`false` is an answer, a failure is not.** A node that does not answer fails with a
  `Transport.Error`.

[`Signature.verify`](https://ethect.dev/reference/signature/verify/#behavior) has the rest: the block that is
asked, what a contract account is asked, and the zero address.

## Errors

| Error | When |
| --- | --- |
| [`Transport.Error`](https://ethect.dev/reference/transport/) | the node does not answer, or answers something that is no answer about the signature |

## Under the hood

- the signature recovers to the address: no request → `true`
- otherwise:
  - **your node** `eth_call`: one, with no `to`: the code of the ERC-6492 validator, with `(address, digest, signature)`

The digest is the EIP-712 hash of the typed data. The call is the one of
[`Signature.verify`](https://ethect.dev/reference/signature/verify/#under-the-hood).
