research-lab/source-code/MiniNero/SimpleRequester.py

58 lines
1.7 KiB
Python
Raw Normal View History

2016-02-05 20:20:44 +00:00
import MiniNero
import os
import ed25519
import binascii
import PaperWallet
import json, hmac, hashlib, time, requests
def HexSigningPubKey(s):
return binascii.hexlify(ed25519.publickey(ed25519.encodeint(MiniNero.hexToInt(s))))
def Signature(m, sk):
sk2 = ed25519.encodeint(MiniNero.hexToInt(sk))
pk = ed25519.publickey(sk2)
return binascii.hexlify(ed25519.signature(m, sk2, pk))
def Verify(sig, m, pk):
return ed25519.checkvalid(binascii.unhexlify(sig), m, binascii.unhexlify(pk))
def offset(ip):
timestamp = str(int(time.time()))
r = requests.get("http://"+ip +'/api/mininero/')
print r.text
print("your time - server time is:", int(time.time()) - int(r.text))
return int(time.time()) - int(r.text)
#get saved access pubkey
from MiniNeroPubKey import *
pubkey = MiniNeroPk
#ip = raw_input('ip of your server\n')
ip = '192.168.2.112:8080' #hopefully you save this in your app...
ip = '192.168.137.235:8080'
ip = raw_input('your ip?\n')
ip = ip + ':8080'
sec = raw_input('you secret key?\n')
timestamp = str(int(time.time()) - offset(ip))
Type = "send"
amount = "0.1"
destination="1em2WCg9QKxRxbo6S3xKF2K4UDvdu6hMc" #just a random one, I think it's the hash of mininero.py
#this should be base 64...
message = Type+amount.replace('.', 'd')+timestamp+destination
sig = Signature(message, sec)
tx = {
'Type': Type,
'timestamp' : timestamp,
'destination': destination,
'signature': sig,
'amount': amount,
}
#print("curl -d Type='"+Type+"' -d signature='"+sig+"' -d timestamp='"+timestamp+"' -d destination='"+destination+"' -d amount='"+amount+"' -X POST '"+ip+"/api/mininero/'")
r = requests.post("http://"+ip +'/api/mininero/', data=tx)
print r.text