signature test
This commit is contained in:
66
celcoin.py
Normal file
66
celcoin.py
Normal file
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
from dotenv import load_dotenv
|
||||
from os import getenv
|
||||
import eth_account
|
||||
from web3.auto import w3
|
||||
from flask import Flask, request, jsonify
|
||||
from credentials import payload
|
||||
import json
|
||||
import pprint
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
BASEURL = "https://sandbox.openfinance.celcoin.dev"
|
||||
global headers
|
||||
|
||||
# eb066b56-6864-4ef0-ad2a-6b38d4363185
|
||||
@app.route('/api/status/<payment_id>', methods=['GET'])
|
||||
def sign_message(payment_id):
|
||||
#message = request.get_data() # extract request data as bytes
|
||||
api_response = requests.get(BASEURL+payment_id+"/status", headers=headers).text
|
||||
|
||||
from eth_account.messages import encode_defunct
|
||||
from eth_abi.packed import encode_packed
|
||||
from Crypto.Hash import keccak
|
||||
|
||||
k = keccak.new(digest_bits=256)
|
||||
k.update(encode_packed(['string'],[payment_id]))
|
||||
print('HASHED MESSAGE: ', k.hexdigest())
|
||||
|
||||
message = encode_defunct(text=k.hexdigest())
|
||||
ret = (w3.eth.account.sign_message(message, private_key=getenv('PRIVATE_KEY'))).signature.hex()
|
||||
print (ret)
|
||||
return ret
|
||||
|
||||
#message = eth_account.messages.encode_structured_data(api_response)
|
||||
#signature = eth_account.Account.sign_message(api_response, private_key='0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef').signature.hex()
|
||||
#signature = (w3.eth.account.sign_message(message, private_key=credentials.private_key)).signature.hex()
|
||||
|
||||
return "bla"
|
||||
#return jsonify({'signature': signature}), 200
|
||||
|
||||
if __name__ == '__main__':
|
||||
url = "https://consumer.sandbox.inic.dev/v1/auth/interface"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"content-type": "application/json"
|
||||
}
|
||||
|
||||
response = requests.post(url, json=payload, headers=headers)
|
||||
|
||||
token = json.loads(response.text)['accessToken']
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"authorization": "Bearer " + token
|
||||
}
|
||||
|
||||
app.run(debug=True)
|
||||
|
||||
|
||||
#pip install flask requests web3
|
||||
Reference in New Issue
Block a user