Created
November 27, 2021 20:44
-
-
Save memento/e6094b30b0bcd0676eb02d5fa165bb98 to your computer and use it in GitHub Desktop.
When This script is useful to sign your login token
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
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: | |
The signature to put in the Body of the next call to (POST) {{maiar}}/login | |
""" | |
wallet_address = str(my_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/erd1XXXX.json" | |
password_file = "path/to/your/password/file.txt" | |
my_account = Account(key_file=key_file, pass_file=password_file) | |
login_token = "bff013b2d47abc123456kac615fb3edb" | |
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