Skip to content

Commit

Permalink
Merge branch 'main' into hardhat
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo0 authored Oct 29, 2022
2 parents b9d25db + 4730245 commit 43b6398
Show file tree
Hide file tree
Showing 15 changed files with 1,554 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ yarn-error.log*
# doc directory
/doc
node_modules

.env
coverage
coverage.json
Expand Down
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# Garlique 🧄
Soft privacy for public ledgers


## Bounties
# Garlic 🧄
Soft privacy for public ledgers

- Metamask Snap?
- Wallet Connect
- Public Good
- Best Mobile UX??
-
Tom, Hugo, Konrad
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

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

from flask import (
Flask,
Response,
jsonify,
make_response,
redirect,
request,
)
import json
from werkzeug.exceptions import HTTPException
import requests
from ecdsa import SigningKey
import ecdsa

# # generate ecdsa key pair
# signing_key = SigningKey.generate(curve=ecdsa.SECP256k1)
# verify_key = signing_key.get_verifying_key()
# SERVER_PRIVATE_KEY = signing_key.to_string().hex()
# SERVER_PUBLIC_KEY = verify_key.to_string().hex()
SERVER_PRIVATE_KEY = "badea878ddd6f34cd2d061f3a095f3dba6be10357d5c5ef0b7e5a64ced930809"
SERVER_PUBLIC_KEY = "63439c944f4a2680cb9cd13a45341241fb6bb22c9df5a3028aae5766d589464ddd084ef3f8f873217c200b1a8d66e39f17eaeb7a9a0b02c27a6e181ee7a729e1"
signing_key = SigningKey.from_string(bytes.fromhex(SERVER_PRIVATE_KEY), curve=ecdsa.SECP256k1)
verify_key = signing_key.get_verifying_key()
print(f"SERVER_PRIVATE_KEY: {SERVER_PRIVATE_KEY}")
print(f"SERVER_PUBLIC_KEY: {SERVER_PUBLIC_KEY}")

app = Flask(__name__)
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
@blocknumber
returns:
@signature
"""
if request.method == 'POST':
data = request.get_json()
txhash = data['txhash']
value = data['value']
recipient = data['recipient']
salt = data['salt']
blocknumber = data['blocknumber']

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:
return make_response(jsonify({'error': 'Could not get transaction from blockexplorer'}), 400)

if "result" not in r.json():
return make_response(jsonify({'error': 'tx not found'}), 400)

result = r.json()["result"]
print(result)
# TODO: some validation logic that makes sense here
if result["blockNumber"] != blocknumber:
return make_response(jsonify({'error': 'tx not confirmed'}), 400)


# sign json object
message = {
"txhash": txhash,
"value": value,
"recipient": recipient,
"salt": salt,
"blocknumber": blocknumber
}
signature = sign_message(message)
return jsonify({"signature": signature})
else:
return jsonify({"error": "invalid request"})


def sign_message(message):
"""
Signs a message with the server's private key
"""
message = json.dumps(message, sort_keys=True)
signature = signing_key.sign(message.encode())
return signature.hex()


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 ","blocknumber":"0xf0b04f"}' http://127.0.0.1:5000/sign


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

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

# dev stuff
ipykernel
black
black[jupyter]

# blockchain stuff
ecdsa
# eth-brownie
web3
pysha3

# server stuff
flask
gunicorn
1 change: 1 addition & 0 deletions SigningServer/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TESTS for SigningServer
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
3 changes: 3 additions & 0 deletions dApp/base.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* {
color: red;
}
58 changes: 58 additions & 0 deletions dApp/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html lang="en">


<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />

<title>Garlic</title>
<meta name="description" content="Garlic" />
<meta property="description" content="Garlic" />
<meta name="keywords" content="crypto, web3, privacy, ether" />
<meta property="og:title" content="Garlic" />
<meta property="og:url" content="" />
<meta property="og:type" content="website" />
<meta property="og:description" content="Garlic" />
<meta property="twitter:domain" content="" />
<meta property="twitter:title" content="Garlic" />
<meta property="twitter:description" content="Garlic" />
<meta property="twitter:image" content="" />

<head>

<link href="dist/output.css" rel="stylesheet">

<script src="https://cdn.tailwindcss.com/"></script>

<script src="src/js/colors.js"></script>

<script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>

<style>
[x-cloak] {display: none;}
</style>


</head>

<body>

test asdf

<main class="flex justify-center gap-5">
<div class="item w-full h-32">13</div>
<div class="item w-full h-32">2</div>
<div class="item w-full h-32">3</div>

</main>


<script>
console.log(" ✰ Garlic ✰ vaMpiRe sLaYeR ✰ ");
</script>


</body>

</html>
Loading

0 comments on commit 43b6398

Please sign in to comment.