Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cyan-windows-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Handle 7702 accounts in verifyTypedData
22 changes: 20 additions & 2 deletions packages/thirdweb/src/auth/verify-typed-data.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type * as ox__Signature from "ox/Signature";
import * as ox__Secp256k1 from "ox/Secp256k1";
import * as ox__Signature from "ox/Signature";
import * as ox__TypedData from "ox/TypedData";
import type { Chain } from "../chains/types.js";
import type { ThirdwebClient } from "../client/client.js";
import type { Hex } from "../utils/encoding/hex.js";
import { type Hex, isHex } from "../utils/encoding/hex.js";
import type { HashTypedDataParams } from "../utils/hashing/hashTypedData.js";
import { type VerifyHashParams, verifyHash } from "./verify-hash.js";

Expand Down Expand Up @@ -101,6 +102,23 @@
primaryType,
types,
} as HashTypedDataParams);

if (!isHex(signature)) {
return false;
}

Check warning on line 108 in packages/thirdweb/src/auth/verify-typed-data.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/auth/verify-typed-data.ts#L107-L108

Added lines #L107 - L108 were not covered by tests

try {
const recoveredAddress = ox__Secp256k1.recoverAddress({
payload: messageHash,
signature: ox__Signature.fromHex(signature),
});

if (recoveredAddress.toLowerCase() === address.toLowerCase()) {
return true;
}
Comment on lines +106 to +118
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Do not short-circuit non-hex signatures

signature is still documented and typed as string | Uint8Array | ox__Signature.Signature, but the new isHex guard returns false for the latter two cases, so previously valid Uint8Array / structured signatures now always fail verification. We need to either convert non-string signatures to hex before the guard or bypass the early return and fall back to verifyHash just like before.

One option:

- if (!isHex(signature)) {
-   return false;
- }
-
- const recoveredAddress = ox__Secp256k1.recoverAddress({
-   payload: messageHash,
-   signature: ox__Signature.fromHex(signature),
- });
+ const signatureHex =
+   typeof signature === "string"
+     ? signature
+     : ox__Signature.toHex(signature);
+
+ if (!isHex(signatureHex)) {
+   return false;
+ }
+
+ const recoveredAddress = ox__Secp256k1.recoverAddress({
+   payload: messageHash,
+   signature: ox__Signature.fromHex(signatureHex),
+ });

(Or, if toHex isn’t available, short-circuit to the legacy verifyHash path when typeof signature !== "string".) Without this, we regress valid callers.

Committable suggestion skipped: line range outside the PR's diff.

} catch {
// no-op, we skip to contract signature check
}
return verifyHash({
accountFactory,
address,
Expand Down
Loading