0

I have a typed signature generated by EIP712 V3. It is 132 characters long. I'm trying to recover it using recoverTypedSignature from eth-sig-util. This fails saying:

index.js:1 Error: Invalid signature length

because it relies on ethereumjs-util's fromRpcSig:

fromRpcSig = function (sig) {
  sig = exports.toBuffer(sig);

  // NOTE: with potential introduction of chainId this might need to be updated
  if (sig.length !== 65) {
    throw new Error('Invalid signature length');
  }

How can I recover the signature? Do I need to convert the 132 characters to 65 somehow?

  • It should be 130-character long (hexadecimal characters, which represent 65 bytes (which will be generated when you pass the 130-character string to toBuffer)). You probably have an extra "0x" or something like that. – goodvibration Dec 5 '19 at 12:36
1

Do I need to convert the 132 characters to 65 somehow?

No, the line sig = exports.toBuffer(sig) in function fromRpcSig does this for you.

However, in order for it to return a buffer of 65 bytes, toBuffer needs to receive an input string of 130 hexadecimal characters, because each character (0-9; A-F) represents 1/2 byte (4 bits).

So your 132-character string is a wrong input here.

Now, it is possible (I can't say for sure without checking this in depth) that toBuffer knows how to handle the "0x" prefix that your input string possibly starts with.

So to begin with, what you need to do is:

  1. Make sure that your string indeed starts with "0x"
  2. Make sure that the remaining character are all hexadecimal (0-9; A-F)
0

In my case, the answer was that I called the API incorrectly 🤦🏻‍♂️

recoverTypedSignature({ data: createPayload(message), sig: signature })

is correct. I accidentally called it with sign (note the extra "n").

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.