signer/core/apitypes: fix encoding of opening parenthesis (#33702)

This fixes a truncation bug that results in an invalid serialization of
empty EIP712.

For example:

```json
{
    "method": "eth_signTypedData_v4",
    "request": {
        "types": {
            "EIP712Domain": [
                {
                    "name": "version",
                    "type": "string"
                }
            ],
            "Empty": []
        },
        "primaryType": "Empty",
        "domain": {
            "version": "0"
        },
        "message": {}
    }
}
``` 

When calculating the type-hash for the stuct-hash, it will incorrectly
use `Empty)` instead of `Empty()`
This commit is contained in:
Conor Patrick 2026-04-13 09:30:36 -04:00 committed by GitHub
parent 289826fefb
commit 4da1e29320
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -454,7 +454,9 @@ func (typedData *TypedData) EncodeType(primaryType string) hexutil.Bytes {
buffer.WriteString(obj.Name)
buffer.WriteString(",")
}
buffer.Truncate(buffer.Len() - 1)
if len(typedData.Types[dep]) > 0 {
buffer.Truncate(buffer.Len() - 1)
}
buffer.WriteString(")")
}
return buffer.Bytes()