Skip to content

Commit

Permalink
organization #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo0 committed Oct 29, 2022
1 parent 37671fe commit c7639e1
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# npm
node_modules
.env

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
4 changes: 4 additions & 0 deletions SigningServer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Signing Server

Verifies deposits have been made to the escrow SC

93 changes: 93 additions & 0 deletions SigningServer/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#####################################################
# The Garlic Signing Server API
#
# Functionality:
# - internal cheques
# - issue external cheques
#####################################################

from flask import (
Flask,
Response,
jsonify,
make_response,
redirect,
request,
)
from werkzeug.exceptions import HTTPException
import requests
from Crypto.PublicKey import RSA


app = Flask(__name__)
SERVER_PRIVATE_KEY = "fijijf1939f3fd1yyt1yfyfy21f"
ETHERSCAN_API_KEY = "A5B6KPZ99R1DHF94EEAJMIUSW3DWJDQCM5"

# before request redirect to https
@app.before_request
def before_request():
if request.url.startswith("http://") and not "127.0." and not "192.168." in request.url:
return redirect(request.url.replace("http://", "https://", 301))



@app.route('/sign', methods=['POST'])
def sign():
"""
Signs a message if tx has been done on the blockchain
json params:
@txhash
@value
@recipient
@salt
@blockheight
returns:
@signature
"""
if request.method == 'POST':
data = request.get_json()
txhash = data['txhash']
value = data['value']
recipient = data['recipient']
salt = data['salt']
blockheight = data['blockheight']

blockexplorer_url = f"https://api.etherscan.io/api?module=proxy&action=eth_getTransactionByHash&txhash={txhash}&apikey={ETHERSCAN_API_KEY}"
r = requests.get(blockexplorer_url)
if r.status_code == 200:
# tx exists on blockchain
# TODO: further verification

# sign json object
message = {
"txhash": txhash,
"value": value,
"recipient": recipient,
"salt": salt,
"blockheight": blockheight
}
signature = sign_message(message)
return jsonify({"signature": signature})
else:
print(r.status_code)
return jsonify({"error": "tx not found"})
else:
return jsonify({"error": "invalid request"})


def sign_message(message):
"""
Signs a message with the server's private key
"""
key = RSA.importKey(SERVER_PRIVATE_KEY)
signature = key.sign(message, '')
return signature


if __name__ == '__main__':
app.run(debug=True)

# test with curl
# curl -H "Content-Type: application/json" -X POST -d '{"txhash":"0xadb037f6d8d2f31c39d3ac14ab2590956b74ddb8fbf9f0d74176ac3c43d709c0","value":"1000000000000000000","recipient":"0x2a1cb5fd815b0ec7628c2f70276b552c12921fd2032d11ca1423a939e51682eb","salt":"271721t ","blockheight":"111"}' http://127.0.0.1:5000/sign


18 changes: 18 additions & 0 deletions SigningServer/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
flask

### External Python libraries to install in venv
# TODO: add versions (maybe?)

# dev stuff
ipykernel
black
black[jupyter]

# blockchain stuff
# eth-brownie
web3
pysha3

# server stuff
flask
gunicorn
1 change: 1 addition & 0 deletions SmartContracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Alho Smart Contracts
1 change: 1 addition & 0 deletions dApp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Frontend for stuff

0 comments on commit c7639e1

Please sign in to comment.