Skip to content

Commit

Permalink
Clarify eip1271 consts
Browse files Browse the repository at this point in the history
  • Loading branch information
sbihel committed Sep 16, 2022
1 parent ddd6026 commit 78c4d5d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions siwe/siwe.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import secrets
import string
from datetime import datetime
from typing import List, Optional, Union
from typing import List, Optional, Union, Final

import eth_utils
import rfc3987
Expand All @@ -13,7 +13,7 @@

from .parsed import ABNFParsedMessage, RegExpParsedMessage

CONTRACT_ABI = [
EIP1271_CONTRACT_ABI: Final = [
{
"inputs": [
{"internalType": "bytes32", "name": " _message", "type": "bytes32"},
Expand All @@ -25,6 +25,7 @@
"type": "function",
}
]
EIP1271_MAGICVALUE: Final = "1626ba7e"


class VerificationError(Exception):
Expand Down Expand Up @@ -305,11 +306,11 @@ def check_contract_wallet_signature(
:param w3: A Web3 provider able to perform a contract check.
:return: True if the signature is valid per EIP-1271.
"""
contract = w3.eth.contract(address=address, abi=CONTRACT_ABI)
contract = w3.eth.contract(address=address, abi=EIP1271_CONTRACT_ABI)
hash_ = _hash_eip191_message(message)
try:
response = contract.caller.isValidSignature(hash_, bytes.fromhex(signature[2:]))
return response.hex() == "1626ba7e"
return response.hex() == EIP1271_MAGICVALUE
except BadFunctionCallOutput:
return False

Expand Down

0 comments on commit 78c4d5d

Please sign in to comment.