From ba6cdc485f146c2243f80c460e69387aa9abfc61 Mon Sep 17 00:00:00 2001 From: Chengcheng Zhang <943420582@qq.com> Date: Tue, 29 Jan 2019 14:14:11 +0800 Subject: [PATCH] add get_gm_root_xprv --- app/api/__init__.py | 4 +++- app/api/resources.py | 11 ++++++++++- app/model/key_gm.py | 22 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/app/api/__init__.py b/app/api/__init__.py index f30c0a4..705157c 100644 --- a/app/api/__init__.py +++ b/app/api/__init__.py @@ -23,6 +23,7 @@ from app.api.resources import Create_QRcode_Base64 from app.api.resources import Create_New_Key from app.api.resources import Create_New_Address from app.api.resources import Decode_Raw_Transaction +from app.api.resources import Get_Gm_Root_Xprv blueprint = Blueprint('api', __name__, url_prefix='/api/v1') api = Api(blueprint) @@ -48,4 +49,5 @@ api.add_resource(Submit_Transaction, '/submit_transaction') api.add_resource(Create_QRcode_Base64, '/create_qrcode_base64') api.add_resource(Create_New_Key, '/create_new_key') api.add_resource(Create_New_Address, '/create_new_address') -api.add_resource(Decode_Raw_Transaction, '/decode_raw_transaction') \ No newline at end of file +api.add_resource(Decode_Raw_Transaction, '/decode_raw_transaction') +api.add_resource(Get_Gm_Root_Xprv, '/get_gm_root_xprv') \ No newline at end of file diff --git a/app/api/resources.py b/app/api/resources.py index 88dd3b3..ed2120e 100644 --- a/app/api/resources.py +++ b/app/api/resources.py @@ -23,6 +23,7 @@ from app.model.transaction import submit_transaction from app.model.key import create_new_key from app.model.receiver import create_new_address from app.model.transaction import decode_raw_transaction +from app.model.key_gm import get_gm_root_xprv parser = reqparse.RequestParser() @@ -232,4 +233,12 @@ class Decode_Raw_Transaction(Resource): args = parser.parse_args() raw_transaction = args.get('raw_transaction_str') response = decode_raw_transaction(raw_transaction) - return response \ No newline at end of file + return response + +class Get_Gm_Root_Xprv(Resource): + + def post(self): + args = parser.parse_args() + seed = args.get('seed_str') + root_xprv = get_gm_root_xprv(seed) + return root_xprv \ No newline at end of file diff --git a/app/model/key_gm.py b/app/model/key_gm.py index e69de29..bb9c44a 100644 --- a/app/model/key_gm.py +++ b/app/model/key_gm.py @@ -0,0 +1,22 @@ +import hmac +import hashlib + +# get_gm_root_xprv create rootxprv from seed +# seed_str length is 512 bits. +# root_xprv length is 512 bits. +# You can get more test data from: +# test data 1: +# seed_str: ecc2bbb6c0492873cdbc81edf56bd896d3b644047879840e357be735b7fa7b6f4af1be7b8d71cc649ac4ca3816f9ccaf11bf49f4effb845f3c19e16eaf8bfcda +# root_xprv_str: a61d6b741b0e74b8d0836ac22b675bbf8e108148ef018d1b000aef1a899a136bd316c0f59e7333520ae1a429504073b2773869e95aa95bb3a4fa0ec76744025c +# test data 2: +# seed_str: afa3a86bbec2f40bb32833fc6324593824c4fc7821ed32eac1f762b5893e56745f66a6c6f2588b3d627680aa4e0e50efd25065097b3daa8c6a19d606838fe7d4 +# root_xprv_str: 302a25c7c0a68a83fa043f594a2db8b44bc871fced553a8a33144b31bc7fb88887c9e75915bb6ba3fd0b9f94a60b7a5897ab9db6a48f888c2559132dba9152b0 +# test data 3: +# seed_str: b435f948bd3748ede8f9d6f59728d669939e79c6c885667a5c138e05bbabde1de0dcfcbe0c6112022fbbf0da522f4e224a9c2381016380688b51886248b3156f +# root_xprv_str: 6532adeb967ac5ccbf988cf8190817bf9040c8cfd9cdfe3d5e400effb29469e6d478b61cc6be936f367ae769eb1dc65c473ee73cac2eb43cf6d5e7c62b7f0062 +def get_gm_root_xprv(seed_str): + hc_str = hmac.HMAC(b'Root', bytes.fromhex(seed_str), digestmod=hashlib.sha512).hexdigest() + root_xprv_str = hc_str + return { + "root_xprv": root_xprv_str + } \ No newline at end of file -- 2.11.0