diff --git a/src.ts/ethers.ts b/src.ts/ethers.ts index ed311317b4..bf7a1f1416 100644 --- a/src.ts/ethers.ts +++ b/src.ts/ethers.ts @@ -51,7 +51,8 @@ export { ensNormalize, isValidName, namehash, dnsEncode, hashMessage, verifyMessage, solidityPacked, solidityPackedKeccak256, solidityPackedSha256, - TypedDataEncoder + TypedDataEncoder, + verifyTypedData } from "./hash/index.js"; export { @@ -149,7 +150,8 @@ export type { ConstantContractMethod, ContractEvent, ContractEventArgs, ContractEventName, ContractInterface, ContractMethod, ContractMethodArgs, ContractTransaction, DeferredTopicFilter, Overrides, - BaseContractMethod, ContractDeployTransaction, PostfixOverrides + BaseContractMethod, ContractDeployTransaction, PostfixOverrides, + WrappedFallback } from "./contract/index.js"; export type { ProgressCallback, SignatureLike } from "./crypto/index.js"; diff --git a/src.ts/hash/index.ts b/src.ts/hash/index.ts index a7a46a3d13..1ac1538a39 100644 --- a/src.ts/hash/index.ts +++ b/src.ts/hash/index.ts @@ -10,6 +10,6 @@ export { hashMessage, verifyMessage } from "./message.js"; export { solidityPacked, solidityPackedKeccak256, solidityPackedSha256 } from "./solidity.js"; -export { TypedDataEncoder } from "./typed-data.js"; +export { TypedDataEncoder, verifyTypedData } from "./typed-data.js"; export type { TypedDataDomain, TypedDataField } from "./typed-data.js"; diff --git a/src.ts/hash/typed-data.ts b/src.ts/hash/typed-data.ts index ba64957aef..8db4864092 100644 --- a/src.ts/hash/typed-data.ts +++ b/src.ts/hash/typed-data.ts @@ -1,6 +1,7 @@ //import { TypedDataDomain, TypedDataField } from "@ethersproject/providerabstract-signer"; import { getAddress } from "../address/index.js"; import { keccak256 } from "../crypto/index.js"; +import { recoverAddress } from "../transaction/index.js"; import { concat, defineProperties, getBigInt, getBytes, hexlify, isHexString, mask, toBeHex, toTwos, zeroPadValue, assertArgument @@ -8,6 +9,7 @@ import { import { id } from "./id.js"; +import type { SignatureLike } from "../crypto/index.js"; import type { BigNumberish, BytesLike } from "../utils/index.js"; @@ -487,3 +489,9 @@ export class TypedDataEncoder { } } +/** + * Compute the address used to sign the typed data for the %%signature%%. + */ +export function verifyTypedData(domain: TypedDataDomain, types: Record>, value: Record, signature: SignatureLike): string { + return recoverAddress(TypedDataEncoder.hash(domain, types, value), signature); +}