forked from UTSAVS26/PyVerse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
63 lines (45 loc) · 1.58 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import binascii
import Crypto
import Crypto.Random
from Crypto.PublicKey import RSA
from flask import Flask, jsonify, request, render_template
from .transaction import Transaction
# Initialize Flask app
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/make/transaction")
def make_transaction():
return render_template("make_transaction.html")
@app.route("/view/transactions")
def view_transaction():
return render_template("view_transactions.html")
@app.route("/wallet/new", methods=["GET"])
def new_wallet():
random_gen = Crypto.Random.new().read
private_key = RSA.generate(1024, random_gen)
public_key = private_key.publickey()
response = {
"private_key": binascii.hexlify(private_key.exportKey(format="DER")).decode(
"ascii"
),
"public_key": binascii.hexlify(public_key.exportKey(format="DER")).decode(
"ascii"
),
}
return jsonify(response), 200
@app.route("/generate/transaction", methods=["POST"])
def generate_transaction():
sender_address = request.form["sender_address"]
sender_private_key = request.form["sender_private_key"]
recipient_address = request.form["recipient_address"]
value = request.form["amount"]
transaction = Transaction(
sender_address, sender_private_key, recipient_address, value
)
response = {
"transaction": transaction.to_dict(),
"signature": transaction.sign_transaction(),
}
return jsonify(response), 200