Skip to content

Commit

Permalink
Merge pull request #6 from Polymarket/fix/hmac-chain-id
Browse files Browse the repository at this point in the history
Fix: Use chain_id when constructing EIP712 sigs
  • Loading branch information
JonathanAmenechi authored Mar 1, 2022
2 parents 0aedaef + 7ed2387 commit 2472715
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
10 changes: 8 additions & 2 deletions examples/create_api_key.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from dotenv import load_dotenv
import os

from py_clob_client.client import ClobClient

load_dotenv()

def main():
host = "http://localhost:8080"
key = "0x"
client = ClobClient(host, key=key, chain_id=42)
key = os.getenv("PK")
chain_id = 80001
client = ClobClient(host, key=key, chain_id=chain_id)

print(client.create_api_key())

Expand Down
7 changes: 4 additions & 3 deletions py_clob_client/signing/eip712.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
CLOB_VERSION = "1"
MSG_TO_SIGN = "This message attests that I control the given wallet"

def get_clob_auth_domain():
return make_domain(name=CLOB_DOMAIN_NAME, version=CLOB_VERSION, chainId=1)
def get_clob_auth_domain(chain_id:int):
return make_domain(name=CLOB_DOMAIN_NAME, version=CLOB_VERSION, chainId=chain_id)

def sign_clob_auth_message(signer: Signer, timestamp: int)-> str:
clob_auth_msg = ClobAuth(address=signer.address, timestamp=str(timestamp), message=MSG_TO_SIGN)
auth_struct_hash = Web3.keccak(clob_auth_msg.signable_bytes(get_clob_auth_domain()))
chain_id = signer.get_chain_id()
auth_struct_hash = Web3.keccak(clob_auth_msg.signable_bytes(get_clob_auth_domain(chain_id)))
return signer.sign(auth_struct_hash)


2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="py_clob_client",
version="0.0.5",
version="0.0.6",
author="Jonathan Amenechi",
author_email="[email protected]",
description="Python client for the Polymarket CLOB",
Expand Down

0 comments on commit 2472715

Please sign in to comment.