OSDN Git Service

add get_gm_root_xprv
authorChengcheng Zhang <943420582@qq.com>
Tue, 29 Jan 2019 06:14:11 +0000 (14:14 +0800)
committerChengcheng Zhang <943420582@qq.com>
Tue, 29 Jan 2019 06:14:11 +0000 (14:14 +0800)
app/api/__init__.py
app/api/resources.py
app/model/key_gm.py

index f30c0a4..705157c 100644 (file)
@@ -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
index 88dd3b3..ed2120e 100644 (file)
@@ -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
index e69de29..bb9c44a 100644 (file)
@@ -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