Last active
October 13, 2018 20:54
-
-
Save antb123/c6c0f555caa42139a0213ed4736a4f31 to your computer and use it in GitHub Desktop.
stellarauth
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
import uuid, json, requests, hashlib, toml, base64, sys | |
from stellar_base.builder import Builder, HORIZON_TEST, HORIZON_LIVE | |
from stellar_base.keypair import Keypair | |
from stellar_base.address import Address | |
from stellar_addr_test import * | |
#test addresses | |
signing = {'addr': u'GCZF7CGJV75G2XNJOONJS5UZMASHPWUVJQMWTVDU5H3BS4OPXLSZ3AUH', 'seed': u'SA2HOOCG4L6NWZXS3HS5WR4RNB6K4Y3HMZUG7FP3CR3I5QCXRWE6XPMT'} | |
test_user= {'addr': u'GCWGEGQ5HT5NEFV7GMIGWZMZJVT6HZO5CQRBFXW3RXSFBKWH4XQZOQY7', 'seed': u'SA76APLWH7SI7IDEWUTUOBO3DUHFAELAPJZ2PX7P6XXUCLU5DIE3C62Y'} | |
def get_memo(FED, benef_name): | |
print('federation request for: ' + benef_name) | |
url = FED['FEDERATION_SERVER'] +'?type=name&q=%s' % benef_name | |
r = requests.get(url) | |
if r.ok: | |
res = r.json() | |
# returns something like :{"account_id":"GCKX3XVTPVNFXQWLQCIBZX6OOPOIUT7FOAZVNOFCNEIXEZFRFSPNZKZT","memo_type":"id","memo":"11"} | |
return res | |
else: | |
print('error on http request') | |
def make_attachment(route, tx): | |
""" | |
sender (stellar address like ant*tempo.eu.com) | |
need_info (do you need AML info of the receiver?) | |
tx: transaction blob | |
attachment: (stringified) | |
nonce | |
transaction: | |
route (memo_id here = 19, right?) | |
sender_info: | |
date_of_birth | |
first_name | |
last_name | |
sig (stringify data and sign it using your secret key, then base64 encode signature) | |
""" | |
# generate attachment and memo_id | |
nonce = uuid.uuid4().hex | |
send = {} | |
send['first_name'] = "FRANK JOE" | |
send['last_name'] = "Marcos" | |
send['date_of_birth'] = "1984-12-27" | |
send['country'] = "FR" | |
sendjs = json.dumps(send) | |
#trx['sender_info'] = send | |
attachment = """{"nonce": "%s", "route": "%s", "transaction": {"sender_info": %s }}""" % (nonce, route, sendjs) | |
sty_json = json.dumps(attachment) | |
memo_id = hashlib.sha256(attachment).digest() | |
return attachment,sty_json, memo_id | |
def sign_data(verifying_addr, sign_seed, data): | |
# ok lets sign the data | |
verify_key = Keypair.from_address(verifying_addr) | |
sign_key = Keypair.from_seed(sign_seed) | |
f = Keypair(verify_key.verifying_key, sign_key) | |
output = f.sign(data) | |
return output | |
#FED = toml.loads(requests.get('https://coins.asia/.well-known/stellar.toml').text) | |
FED = toml.loads(requests.get('https://gostellar.org/.well-known/stellar.toml').text) | |
print FED | |
print '------------' | |
benef_name = 'rkndexhlpd*gostellar.org' # update to new address from gostellar.org | |
res = get_memo(FED, benef_name) | |
print res | |
print '------------' | |
txn = '' | |
route = res['memo'] | |
attachment, sty_json, memo_id = make_attachment(route, txn) | |
print '++++++++++++++++++++++' | |
# generate data | |
orig_amount = '10' | |
send = Builder(test_user['seed'], network='TEST') | |
send.append_payment_op(res['account_id'], orig_amount) | |
send.add_hash_memo(memo_id) | |
# need to modify Builder to add get_compliance_xdr | |
tx = send.get_compliance_xdr() | |
# data | |
data = """{"sender": "sender*tempo.eu.com", "need_info": false, "tx": "%s", "attachment": %s }""" % (tx, sty_json) | |
signed_data = sign_data(FED['SIGNING_KEY'], signing['seed'], data) | |
send = {"data": data, "sig": base64.b64encode(signed_data)} | |
print send | |
r = requests.post(FED['AUTH_SERVER'], data=send) | |
print '+++++++++++++++++++++=' | |
print r.text | |
""" | |
add this to builder.py: | |
may be located | |
/usr/local/lib/python2.7/dist-packages/stellar_base/builder.py | |
def get_compliance_xdr(self): | |
from .stellarxdr import Xdr | |
import base64 | |
self.sequence = '-1' | |
tx = self.gen_tx() | |
tp = Xdr.StellarXDRPacker() | |
tp.pack_Transaction(tx.to_xdr_object()) | |
return base64.b64encode(tp.get_buffer()) | |
""" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment