Created
July 13, 2022 07:32
-
-
Save domob1812/9c39969658e773bc14035b67f4b3d43b to your computer and use it in GitHub Desktop.
Script for generating XID passwords on EVM chains like Polygon
This file contains 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
#!/usr/bin/env python3 | |
# Copyright (C) 2022 The Xaya developers | |
# Distributed under the MIT software license, see the accompanying | |
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | |
""" | |
CLI script to generate a XID password for a Polygon (or other EVM) | |
Xaya identity. | |
""" | |
import base64 | |
import codecs | |
import jsonrpclib | |
import os | |
from eth_account import Account, messages | |
from web3 import Web3 | |
w3 = Web3 (Web3.HTTPProvider ("https://polygon-rpc.com")) | |
xid = jsonrpclib.ServerProxy ("https://xid.xaya.io/polygon/rpc") | |
name = "domob" | |
app = "polygon.xaya.io" | |
key = os.getenv ("PRIVKEY") | |
acc = Account.from_key (key) | |
addr = acc.address | |
print ("Own address: %s" % addr) | |
data = xid.getnamestate (name=name)["data"] | |
found = False | |
for s in data["signers"]: | |
# We only look for global signers for simplicity. | |
if len (s) > 1 or "addresses" not in s: | |
continue | |
if addr in s["addresses"]: | |
found = True | |
assert found, "own address is not a signer" | |
msg = xid.getauthmessage (name=name, application=app, data={}) | |
fullMsg = "Xaya signature for chain %d:\n\n%s" \ | |
% (w3.eth.chainId, msg["authmessage"]) | |
encoded = messages.encode_defunct (text=fullMsg) | |
signed = acc.sign_message (encoded) | |
sgn = codecs.decode (base64.b64encode (signed.signature), "ascii") | |
fullPwd = xid.setauthsignature (password=msg["password"], signature=sgn) | |
print ("Password:\n%s" % fullPwd) | |
verify = xid.verifyauth (name=name, application=app, password=fullPwd) | |
print (verify["data"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment