Skip to content

Commit

Permalink
Sign data before sending to C-Chain
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas-Menzel committed May 13, 2023
1 parent e869ac7 commit 46e9f66
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion code/functions_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import requests
import time
import json
import hashlib
import hmac

# This file holds variables and functions that can / will be used by all modules

Expand Down Expand Up @@ -135,9 +137,20 @@ def check_argument_type(response, argument, argument_name, data_type, err_id=-1)
return response, argument


def sign_string(message):
key = 'secret_key'

key = key.encode('utf-8')
message = message.encode('utf-8')
signature = hmac.new(key, message, hashlib.sha256).hexdigest()
return signature


def save_data_in_blockchain(response, chain_uuid, payload):
transaction_uuid = None

signature = sign_string(payload)

if chain_uuid is None or chain_uuid == '':
response = add_error_to_response(
response,
Expand All @@ -152,7 +165,8 @@ def save_data_in_blockchain(response, chain_uuid, payload):
cchainlink_response = requests.get(
cchainlink_url + 'book_data?'
+ 'chain_uuid=' + chain_uuid
+ '&payload=' + payload)
+ '&payload=' + payload
+ '&signature=' + signature)
except:
response = add_error_to_response(
response,
Expand Down

0 comments on commit 46e9f66

Please sign in to comment.