-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.py
33 lines (25 loc) · 870 Bytes
/
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
# Don't trust me with cryptography.
from secp import PublicKey
from flask import Flask, request
from ledger import Ledger
# Ledger pubkey
ledger = Ledger("supersecretprivatekey")
app = Flask(__name__)
@app.route("/keys")
def keys():
return ledger.get_pubkeys()
@app.route("/mint", methods=["POST"])
def mint():
B_ = PublicKey(bytes.fromhex(request.json["x"]), raw=True) # pubkey is compressed
promise = ledger.mint(B_)
return promise
@app.route("/split", methods=["POST"])
def split():
proofs = request.json["proofs"]
amount = request.json["amount"]
output_data = request.json["output_data"]
try:
fst_promises, snd_promises = ledger.split(proofs, amount, output_data)
return {"fst": fst_promises, "snd": snd_promises}
except Exception as exc:
return {"error": str(exc)}