OSDN Git Service

add xpub_to_public_key
authorChengcheng Zhang <943420582@qq.com>
Fri, 21 Dec 2018 08:53:44 +0000 (16:53 +0800)
committerChengcheng Zhang <943420582@qq.com>
Fri, 21 Dec 2018 08:53:44 +0000 (16:53 +0800)
app/api/__init__.py
app/api/resources.py
app/model/key.py

index 5f7d0d0..a55057b 100644 (file)
@@ -9,6 +9,7 @@ from app.api.resources import Entropy_To_Mnemonic
 from app.api.resources import Mnemonic_To_Seed
 from app.api.resources import Seed_To_Root_Xprv
 from app.api.resources import Xprv_To_Expanded_Private_Key
+from app.api.resources import Xpub_To_Public_Key
 
 blueprint = Blueprint('api', __name__, url_prefix='/api/v1')
 api = Api(blueprint)
@@ -20,4 +21,5 @@ api.add_resource(Create_Entropy, '/create_entropy')
 api.add_resource(Entropy_To_Mnemonic, '/entropy_to_mnemonic')
 api.add_resource(Mnemonic_To_Seed, '/mnemonic_to_seed')
 api.add_resource(Seed_To_Root_Xprv, '/seed_to_root_xprv')
-api.add_resource(Xprv_To_Expanded_Private_Key, '/xprv_to_expanded_private_key')
\ No newline at end of file
+api.add_resource(Xprv_To_Expanded_Private_Key, '/xprv_to_expanded_private_key')
+api.add_resource(Xpub_To_Public_Key, '/xpub_to_public_key')
\ No newline at end of file
index d507e0b..76512de 100644 (file)
@@ -8,6 +8,7 @@ from app.model.key import entropy_to_mnemonic
 from app.model.key import mnemonic_to_seed
 from app.model.key import seed_to_root_xprv
 from app.model.key import xprv_to_expanded_private_key
+from app.model.key import xpub_to_public_key
 
 parser = reqparse.RequestParser()
 parser.add_argument('private_key_str', type=str)
@@ -18,6 +19,7 @@ parser.add_argument('entropy_str', type=str)
 parser.add_argument('mnemonic_str', type=str)
 parser.add_argument('seed_str', type=str)
 parser.add_argument('xprv_str', type=str)
+parser.add_argument('xpub_str', type=str)
 
 class Hello(Resource):
 
@@ -79,4 +81,12 @@ class Xprv_To_Expanded_Private_Key(Resource):
         args = parser.parse_args()
         xprv_str = args.get('xprv_str')
         expanded_private_key_str = xprv_to_expanded_private_key(xprv_str)
-        return expanded_private_key_str
\ No newline at end of file
+        return expanded_private_key_str
+
+class Xpub_To_Public_Key(Resource):
+
+    def post(self):
+        args = parser.parse_args()
+        xpub_str = args.get('xpub_str')
+        public_key_str = xpub_to_public_key(xpub_str)
+        return public_key_str
\ No newline at end of file
index 91bf004..cb90995 100644 (file)
@@ -117,6 +117,7 @@ def seed_to_root_xprv(seed_str):
 # public_key = private_key.get_verifying_key().to_ascii(encoding='hex')
 # xpub_str = public_key.decode() + xprv_str[64:]
 #     return xpub_str
+##################################################
 
 # xprv_to_expanded_private_key create expanded private key from xprv
 # You can verify or get more test data from: https://gist.github.com/zcc0721/ef0bf2e69f5e92b29d716981f2a8fe7d
@@ -135,3 +136,7 @@ def xprv_to_expanded_private_key(xprv_str):
 
     return expanded_private_key_str
 
+def xpub_to_public_key(xpub_str):
+    public_key_str = xpub_str[:64]
+
+    return public_key_str
\ No newline at end of file