signature test
This commit is contained in:
commit
fa7642c93d
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
|
50
test.py
Executable file
50
test.py
Executable file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from os import getenv
|
||||
from eth_account import Account
|
||||
from eth_account.messages import encode_defunct
|
||||
from sha3 import keccak_256
|
||||
from eth_abi.packed import encode_packed
|
||||
from eth_utils import to_bytes
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
def signer_check(message, signature):
|
||||
|
||||
message_hash = encode_defunct(message)
|
||||
signer_address = Account.recover_message(message_hash, signature=signature)
|
||||
|
||||
return signer_address
|
||||
|
||||
signature = 1
|
||||
|
||||
def sign_message(message, private_key):
|
||||
account = Account.from_key(private_key)
|
||||
message_hash = encode_defunct(message)
|
||||
signature = account.sign_message(message_hash)
|
||||
return signature.signature.hex()
|
||||
|
||||
def generate_hash(pix_target, amount, pix_timestamp):
|
||||
# Concatenate the bytes
|
||||
concatenated_bytes = encode_packed(
|
||||
['bytes32', 'uint80', 'uint256'],
|
||||
[to_bytes(text=pix_target), amount, pix_timestamp])
|
||||
|
||||
# Return the keccak256 hash
|
||||
return keccak_256(concatenated_bytes).digest()
|
||||
|
||||
# Example usage
|
||||
pix_target = '1234'
|
||||
amount = 10
|
||||
pix_timestamp = 162
|
||||
|
||||
message = generate_hash(pix_target, amount, pix_timestamp)
|
||||
print("Message:", message.hex())
|
||||
signature = sign_message(message, getenv('PRIVATE_KEY'))
|
||||
print("Signature:", signature)
|
||||
signer = signer_check(message, signature)
|
||||
print("Signer: ", signer)
|
||||
account = Account.from_key(getenv('PRIVATE_KEY'))
|
||||
print("Account:", account.address)
|
55
test_api.py
Normal file
55
test_api.py
Normal file
@ -0,0 +1,55 @@
|
||||
import requests
|
||||
from dotenv import load_dotenv
|
||||
from os import getenv
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
url = "https://sandbox.openfinance.celcoin.dev/v5/token"
|
||||
data = {
|
||||
"client_id": getenv("CLIENT_ID"),
|
||||
"grant_type": "client_credentials",
|
||||
"client_secret": getenv("CLIENT_SECRET"),
|
||||
}
|
||||
response = requests.post(url, data=data)
|
||||
token = response.json()["access_token"]
|
||||
print("token:", token)
|
||||
|
||||
url = "https://sandbox.openfinance.celcoin.dev/pix/v1/payment/endToEnd"
|
||||
payload = { "dpp": "2024-11-12" }
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"content-type": "application/json",
|
||||
"authorization": "Bearer " + token
|
||||
}
|
||||
response = requests.post(url, json=payload, headers=headers)
|
||||
e2ee = response.json()["body"]["endToEndId"]
|
||||
print("e2e:", e2ee)
|
||||
|
||||
|
||||
# alternate DICT method for obtaining e2ee
|
||||
url = "https://sandbox.openfinance.celcoin.dev/pix/v1/dict/v2/key"
|
||||
payload = {
|
||||
"payerId": "13935893000370",
|
||||
"key": "93981962-9505-474d-9899-dcb0be3d40c4"
|
||||
}
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"content-type": "application/json",
|
||||
"authorization": "Bearer " + token
|
||||
}
|
||||
#response = requests.post(url, json=payload, headers=headers)
|
||||
#print(response.text)
|
||||
|
||||
|
||||
url = "https://sandbox.openfinance.celcoin.dev/pix/v1/payment"
|
||||
payload = { "initiationType": "DICT" }
|
||||
# headers = {
|
||||
# "accept": "application/json",
|
||||
# "content-type": "application/json",
|
||||
# "authorization": "Bearer $beare"
|
||||
# }
|
||||
|
||||
# response = requests.post(url, json=payload, headers=headers)
|
||||
|
||||
# print(response.text)
|
Loading…
x
Reference in New Issue
Block a user