OSDN Git Service

add get_gm_xprv
authorChengcheng Zhang <943420582@qq.com>
Tue, 29 Jan 2019 09:01:22 +0000 (17:01 +0800)
committerChengcheng Zhang <943420582@qq.com>
Tue, 29 Jan 2019 09:01:22 +0000 (17:01 +0800)
app/api/__init__.py
app/api/resources.py
app/model/key_gm.py

index 1f161fd..1a20e3d 100644 (file)
@@ -25,6 +25,7 @@ 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
 from app.api.resources import Get_Gm_Xpub
+from app.api.resources import Get_Gm_Xprv
 
 blueprint = Blueprint('api', __name__, url_prefix='/api/v1')
 api = Api(blueprint)
@@ -52,4 +53,5 @@ 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')
 api.add_resource(Get_Gm_Root_Xprv, '/get_gm_root_xprv')
-api.add_resource(Get_Gm_Xpub, '/get_gm_xpub')
\ No newline at end of file
+api.add_resource(Get_Gm_Xpub, '/get_gm_xpub')
+api.add_resource(Get_Gm_Xprv, '/get_gm_xprv')
\ No newline at end of file
index 9ee2db1..58fbed4 100644 (file)
@@ -25,6 +25,7 @@ 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
 from app.model.key_gm import get_gm_xpub
+from app.model.key_gm import get_gm_xprv
 
 
 parser = reqparse.RequestParser()
@@ -250,4 +251,12 @@ class Get_Gm_Xpub(Resource):
         args = parser.parse_args()
         xprv = args.get('xprv_str')
         xpub = get_gm_xpub(xprv)
-        return xpub
\ No newline at end of file
+        return xpub
+
+class Get_Gm_Xprv(Resource):
+
+    def post(self):
+        args = parser.parse_args()
+        xprv = args.get('xprv_str')
+        xprv = get_gm_xprv(xprv)
+        return xprv
\ No newline at end of file
index 45094d0..002f456 100644 (file)
@@ -22,6 +22,7 @@ def get_gm_root_xprv(seed_str):
         "root_xprv": root_xprv_str
     }
 
+
 # get_gm_xpub derives new xpub from xprv
 # xprv length is 64 bytes.
 # xpub length is 65 bytes.
@@ -43,4 +44,25 @@ def get_gm_xpub(xprv_str):
     xpub_str = pc + public_key_str[:64] + xprv_str[64:]
     return {
         "xpub": xpub_str
-    }
\ No newline at end of file
+    }
+
+
+# get_gm_xprv create expanded private key from xprv
+# You can get more test data from: https://gist.github.com/zcc0721/ef0bf2e69f5e92b29d716981f2a8fe7d
+# test data 1:
+#   xprv_str: 406c82307bf7978d17f3ecfeea7705370e9faef2027affa86c8027c6e11a8a50e231e65bd97048850ae6c39d0f46b63ae70aa24f5aac7877727c430c2201e6d6
+#   expanded_private_key_str_xprv: 406c82307bf7978d17f3ecfeea7705370e9faef2027affa86c8027c6e11a8a50d828bf44b1a109c2bbb4c72685858e2f2ab8b405beef1e4ecc12d1ed8511e8eb
+# test data 2:
+#   xprv_str: 6032adeb967ac5ccbf988cf8190817bf9040c8cfd9cdfe3d5e400effb2946946d478b61cc6be936f367ae769eb1dc65c473ee73cac2eb43cf6d5e7c62b7f0062
+#   expanded_private_key_str_xprv: 6032adeb967ac5ccbf988cf8190817bf9040c8cfd9cdfe3d5e400effb2946946ddbb71e7a76595c6bc24937d76085d24315713764cbdf1364ab9091953009cd8
+# test data 3:
+#   xprv_str: 509a095ad862322641b8d66e84561aae1d4816045167e2c4dfadf464928e114300c0a162d41c0cdf196d61f4492f546e50bfff253b9d5d930d1bb89197cd333d
+#   expanded_private_key_str_xprv: 509a095ad862322641b8d66e84561aae1d4816045167e2c4dfadf464928e11432787f5e10f9598f80fb41e4a648b609463c06e625641366f3279658b2b0f5268
+def get_gm_xprv(xprv_str):
+    hc_str = hmac.HMAC(b'Expand', bytes.fromhex(xprv_str), digestmod=hashlib.sha512).hexdigest()
+    expanded_private_key_str = xprv_str[:64] + hc_str[64:]
+    return {
+        "expanded_private_key": expanded_private_key_str
+    }
+
\ No newline at end of file