Skip to content

Commit 46e9f66

Browse files
Sign data before sending to C-Chain
1 parent e869ac7 commit 46e9f66

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

code/functions_collection.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import requests
33
import time
44
import json
5+
import hashlib
6+
import hmac
57

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

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

137139

140+
def sign_string(message):
141+
key = 'secret_key'
142+
143+
key = key.encode('utf-8')
144+
message = message.encode('utf-8')
145+
signature = hmac.new(key, message, hashlib.sha256).hexdigest()
146+
return signature
147+
148+
138149
def save_data_in_blockchain(response, chain_uuid, payload):
139150
transaction_uuid = None
140151

152+
signature = sign_string(payload)
153+
141154
if chain_uuid is None or chain_uuid == '':
142155
response = add_error_to_response(
143156
response,
@@ -152,7 +165,8 @@ def save_data_in_blockchain(response, chain_uuid, payload):
152165
cchainlink_response = requests.get(
153166
cchainlink_url + 'book_data?'
154167
+ 'chain_uuid=' + chain_uuid
155-
+ '&payload=' + payload)
168+
+ '&payload=' + payload
169+
+ '&signature=' + signature)
156170
except:
157171
response = add_error_to_response(
158172
response,

0 commit comments

Comments
 (0)