OSDN Git Service

add xpub_to_public_key test data
authorChengcheng Zhang <943420582@qq.com>
Mon, 24 Dec 2018 03:02:12 +0000 (11:02 +0800)
committerChengcheng Zhang <943420582@qq.com>
Mon, 24 Dec 2018 03:02:12 +0000 (11:02 +0800)
app/model/key.py

index cb90995..8c8bd07 100644 (file)
@@ -15,6 +15,7 @@ def create_entropy():
 
     return entropy_str
 
+
 # entropy_to_mnemonic create mnemonic from 128 bits entropy(the entropy_str length is 32)
 # return 12 mnemonics
 # verify or get more test data, please ref: https://gist.github.com/zcc0721/63aeb5143807950f7b7051fadc08cef0
@@ -57,6 +58,7 @@ def entropy_to_mnemonic(entropy_str):
 
     return mnemonic_str[:-1]
 
+
 # mnemonic_to_seed create seed from mnemonic
 # You can find more details from: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki#from-mnemonic-to-seed
 # You can verify or get more test data from: https://gist.github.com/zcc0721/4918e891073a9ca6c444ec7490298e82
@@ -76,6 +78,7 @@ def mnemonic_to_seed(mnemonic_str):
 
     return seed_str
 
+
 # s_str must be >= 32 bytes long and gets rewritten in place.
 # This is NOT the same pruning as in Ed25519: it additionally clears the third
 # highest bit to ensure subkeys do not overflow the second highest bit.
@@ -92,25 +95,27 @@ def prune_root_scalar(s_str):
     
     return new_s_str
 
+
 # seed_to_root_xprv create rootxprv from seed
 # seed_str length is 512 bits.
 # root_xprv length is 512 bits.
 # You can verify or get more test data from: https://gist.github.com/zcc0721/0aa1b971f4bf93d8f67e25f57b8b97ee
 # test data 1:
 #   seed_str: afa3a86bbec2f40bb32833fc6324593824c4fc7821ed32eac1f762b5893e56745f66a6c6f2588b3d627680aa4e0e50efd25065097b3daa8c6a19d606838fe7d4
-#   root_xprv: 302a25c7c0a68a83fa043f594a2db8b44bc871fced553a8a33144b31bc7fb84887c9e75915bb6ba3fd0b9f94a60b7a5897ab9db6a48f888c2559132dba9152b0
+#   root_xprv_str: 302a25c7c0a68a83fa043f594a2db8b44bc871fced553a8a33144b31bc7fb84887c9e75915bb6ba3fd0b9f94a60b7a5897ab9db6a48f888c2559132dba9152b0
 # test data 2:
 #   seed_str: b435f948bd3748ede8f9d6f59728d669939e79c6c885667a5c138e05bbabde1de0dcfcbe0c6112022fbbf0da522f4e224a9c2381016380688b51886248b3156f
-#   root_xprv: 6032adeb967ac5ccbf988cf8190817bf9040c8cfd9cdfe3d5e400effb2946946d478b61cc6be936f367ae769eb1dc65c473ee73cac2eb43cf6d5e7c62b7f0062
+#   root_xprv_str: 6032adeb967ac5ccbf988cf8190817bf9040c8cfd9cdfe3d5e400effb2946946d478b61cc6be936f367ae769eb1dc65c473ee73cac2eb43cf6d5e7c62b7f0062
 # test data 3:
 #   seed_str: ecc2bbb6c0492873cdbc81edf56bd896d3b644047879840e357be735b7fa7b6f4af1be7b8d71cc649ac4ca3816f9ccaf11bf49f4effb845f3c19e16eaf8bfcda
-#   root_xprv: a01d6b741b0e74b8d0836ac22b675bbf8e108148ef018d1b000aef1a899a134bd316c0f59e7333520ae1a429504073b2773869e95aa95bb3a4fa0ec76744025c
+#   root_xprv_str: a01d6b741b0e74b8d0836ac22b675bbf8e108148ef018d1b000aef1a899a134bd316c0f59e7333520ae1a429504073b2773869e95aa95bb3a4fa0ec76744025c
 def seed_to_root_xprv(seed_str):
     hc_str = hmac.HMAC(b'Root', bytes.fromhex(seed_str), digestmod=hashlib.sha512).hexdigest()
-    root_xprv_str = prune_root_scalar(hc_str[:64])
+    root_xprv_str = prune_root_scalar(hc_str[:64]) + hc_str[64:]
 
     return root_xprv_str
 
+
 ##################################################
 # def xprv_to_xpub(xprv_str):
 # private_key = ed25519.SigningKey(bytes.fromhex(xprv_str[:64]))
@@ -136,7 +141,25 @@ def xprv_to_expanded_private_key(xprv_str):
 
     return expanded_private_key_str
 
+
+# xpub_to_public_key create 32 bytes public key from xpub
+# xpub length is 64 bytes.
+# You can verify or get more test data from: 
+# test data 1:
+#   xpub_str: ecc2bbb6c0492873cdbc81edf56bd896d3b644047879840e357be735b7fa7b6f4af1be7b8d71cc649ac4ca3816f9ccaf11bf49f4effb845f3c19e16eaf8bfcda
+#   public_key_str: ecc2bbb6c0492873cdbc81edf56bd896d3b644047879840e357be735b7fa7b6f
+# test data 2:
+#   xprv_str: 406c82307bf7978d17f3ecfeea7705370e9faef2027affa86c8027c6e11a8a50e231e65bd97048850ae6c39d0f46b63ae70aa24f5aac7877727c430c2201e6d6
+#   public_key_str: 406c82307bf7978d17f3ecfeea7705370e9faef2027affa86c8027c6e11a8a50
+# test data 3:
+#   xprv_str: b435f948bd3748ede8f9d6f59728d669939e79c6c885667a5c138e05bbabde1de0dcfcbe0c6112022fbbf0da522f4e224a9c2381016380688b51886248b3156f
+#   public_key_str: b435f948bd3748ede8f9d6f59728d669939e79c6c885667a5c138e05bbabde1d
 def xpub_to_public_key(xpub_str):
     public_key_str = xpub_str[:64]
 
-    return public_key_str
\ No newline at end of file
+    return public_key_str
+
+
+# def xprv_sign(xprv_str, message_str):
+    
+#     return signature_str
\ No newline at end of file