Last active
September 18, 2022 00:32
-
-
Save kalloc/b64e735afe48eaf1e41fe52614551b56 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import tornado.ioloop | |
import tornado.web | |
from eth_account.messages import encode_defunct | |
from eth_account.account import Account | |
PRIVATE_KEY = os.environ.get("PRIVATE_KEY") | |
class EthSignHandler(tornado.web.RequestHandler): | |
def get(self, address): | |
max_per_mint = 1 | |
payload = f'{address.upper()}:{max_per_mint}' | |
msghash = encode_defunct(text=payload) | |
account = Account.from_key(PRIVATE_KEY) | |
sign = account.sign_message(msghash) | |
self.write({ | |
"permitted_amount": max_per_mint, | |
"signer_address": account.address, | |
"signature": sign.signature.hex(), | |
"address": address | |
}) | |
def make_app(): | |
return tornado.web.Application([ | |
(r"/api/v1/ethsign/(0[xX][0-9a-fA-F]{40})", EthSignHandler), | |
]) | |
if __name__ == "__main__": | |
app = make_app() | |
app.listen(3000) | |
tornado.ioloop.IOLoop.current().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for PHP also version https://gist.github.com/kalloc/021c895c2d137db1816df826a439fe15