Skip to content

Instantly share code, notes, and snippets.

@memento
Last active May 17, 2023 12:23
Show Gist options
  • Save memento/0433dfb84d219fcae7172ea4090b2724 to your computer and use it in GitHub Desktop.
Save memento/0433dfb84d219fcae7172ea4090b2724 to your computer and use it in GitHub Desktop.
This script allows to you sign your loginToken the proper way to better authenticate to the Maiar DEX API.
"""
This script allows you to sign your loginToken the proper way
to better authenticate to the Maiar DEX API.
Prerequisite:
You need to install the pip package erdpy.
> pip3 install erdpy
"""
from erdpy.accounts import Account
from erdpy.wallet.signing import sign_message
from Cryptodome.Hash import keccak
PREFIX = "\x17Elrond Signed Message:\n"
def sign_access_token(login_token, account):
"""This function generates the signature of the login_token+public_key.
Args:
login_token (str): The loginToken your retrieved while requesting
(POST) {{maiar}}/login/init.
account (Account): The elrond account that's used to sign the
token.
Returns:
str: The signature to put in the Body of the next call to (POST) {{maiar}}/login
"""
wallet_address = str(account.address)
informations = wallet_address + login_token + "{}"
message_bytes = keccak.new(digest_bits=256).update(
str.encode(f"{PREFIX}{len(informations)}{informations}")).digest()
return sign_message(message_bytes, account)
if __name__ == "__main__":
key_file = "path/to/your/key/erdxxx.json"
password_file = "path/to/your/password/file.txt"
my_account = Account(key_file=key_file, pass_file=password_file)
login_token = "bff013b2d47ae5f0b176bac615fb3edb"
signed_message = sign_access_token(login_token, my_account)
print(signed_message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment