Skip to content
ecdsa.com
viem (TypeScript)Web3 wallets and signatures

Error message

Invalid yParityOrV value

Also printed as

  • Error: Invalid yParityOrV value

Behaviour differs between libraries: ethers 6 normalises EIP-155 style values (35 and above) and recovers the same signature without complaint (shown in the reproduction); for other unexpected values such as 5 it throws "invalid v". Code that moves from ethers to viem can therefore start failing on signatures that used to verify.

viem (TypeScript) — recoverAddress / recoverMessageAddress / recoverPublicKey

What it means

The last byte of the signature (the recovery identifier) is not one of the values viem accepts: 0 or 1 (`yParity`) or 27 or 28 (legacy `v`). Message and typed-data signatures always use one of those; other values come from transaction-signing conventions or from byte-order mistakes. viem stops before recovery.

Why it happens

How to fix it

  1. 1.

    Normalise v before recovering

    Map EIP-155 values and 0/1 to 27/28 (or to yParity 0/1), and make sure the signature is assembled as r‖s‖v.

    ts
    import { hexToNumber, numberToHex, type Hex } from "viem";
    
    // Message signatures carry v = 27/28 (or 0/1); map EIP-155 style values back.
    function normaliseV(signature: Hex): Hex {
      let v = hexToNumber(`0x${signature.slice(130)}`);
      if (v >= 35) v = ((v - 35) % 2) + 27; // EIP-155: chainId * 2 + 35 + yParity
      if (v === 0 || v === 1) v += 27;
      return `${signature.slice(0, 130)}${numberToHex(v).slice(2)}` as Hex;
    }

Related errors

Browse the full signature error database