Signature.verifyTypedData
Says whether an account signed EIP-712 typed data, as
Signer.signTypedData and eth_signTypedData_v4 sign
it: a permit, an order. The account can be a key or a contract, deployed or not yet.
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,); // trueIt needs a node, which it asks only when the signature is not the one of a key.
An address from a request
Section titled “An address from a request”An address that comes from outside goes through
Address.make first.
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
Section titled “Returns”Effect<boolean, Transport.Error, Transport.Transport>
true when the account signed the typed data, false when it did not.
Parameters
Section titled “Parameters”claim.address
Section titled “claim.address”- Type:
Address.Address
The account that is said to have signed.
claim.data
Section titled “claim.data”- Type:
Signer.TypedData
The typed data that was signed: domain, types, primaryType and message.
claim.signature
Section titled “claim.signature”- Type:
Hex | Signature.Signature
The signature: what the signer gave. See a signature.
Behavior
Section titled “Behavior”- The typed data is hashed as the signer hashed it:
EIP712Domainis built from the fields the domain has, and an integer is abigint, a safenumberor 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.recoverTypedDatasays which, in its failure. - A key’s signature costs no request. The node is asked only for what a key did not sign.
falseis an answer, a failure is not. A node that does not answer fails with aTransport.Error.
Signature.verify has the rest: the block that is
asked, what a contract account is asked, and the zero address.
Errors
Section titled “Errors”| Error | When |
|---|---|
Transport.Error |
the node does not answer, or answers something that is no answer about the signature |
Under the hood
Section titled “Under the hood”the signature recovers to the address: no requestgives
trueotherwise
- your node
eth_callone, with noto: the code of the ERC-6492 validator, with(address, digest, signature)
- your node
The digest is the EIP-712 hash of the typed data. The call is the one of
Signature.verify.