• R/O
  • HTTP
  • SSH
  • HTTPS

pybtm: 提交

Python3 implementation of the Bytom protocol. https://pypi.org/project/pybtm/


Commit MetaInfo

修订版779ddc047d820e119fdaf6cdb9c910fed3a0a58a (tree)
时间2019-03-26 20:07:22
作者Chengcheng Zhang <943420582@qq.c...>
CommiterChengcheng Zhang

Log Message

fix bug

更改概述

差异

--- a/pybtm/__init__.py
+++ b/pybtm/__init__.py
@@ -1,2 +1,2 @@
11 name = "pybtm"
2-version = "0.0.9"
\ No newline at end of file
2+version = "0.0.14"
\ No newline at end of file
--- a/pybtm/key.py
+++ b/pybtm/key.py
@@ -206,7 +206,7 @@ def prune_intermediate_scalar(f):
206206 def get_child_xprv(xprv_hexstr, path_list):
207207 for i in range(len(path_list)):
208208 selector_bytes = bytes.fromhex(path_list[i])
209- xpub_hexstr = xprv_to_xpub(xprv_hexstr)['xpub']
209+ xpub_hexstr = get_xpub(xprv_hexstr)
210210 xpub_bytes = bytes.fromhex(xpub_hexstr)
211211 xprv_bytes = bytes.fromhex(xprv_hexstr)
212212 hc_bytes = hmac.HMAC(xpub_bytes[32:], b'N'+xpub_bytes[:32]+selector_bytes, digestmod=hashlib.sha512).digest()
@@ -305,7 +305,7 @@ def get_child_xpub(xpub_hexstr, path_list):
305305 # message_hexstr: 1246b84985e1ab5f83f4ec2bdf271114666fd3d9e24d12981a3c861b9ed523c6
306306 # signature_hexstr: ab18f49b23d03295bc2a3f2a7d5bb53a2997bed733e1fc408b50ec834ae7e43f7da40fe5d9d50f6ef2d188e1d27f976aa2586cef1ba00dd098b5c9effa046306
307307 def xprv_sign(xprv_hexstr, message_hexstr):
308- xprv_hexstr = xprv_to_expanded_private_key(xprv_hexstr)['expanded_private_key']
308+ xprv_hexstr = get_expanded_private_key(xprv_hexstr)
309309 xprv_bytes = bytes.fromhex(xprv_hexstr)
310310 message_bytes = bytes.fromhex(message_hexstr)
311311 data_bytes = xprv_bytes[32:64] + message_bytes
@@ -317,7 +317,7 @@ def xprv_sign(xprv_hexstr, message_hexstr):
317317
318318 scalar = decodeint(message_digest_reduced)
319319 encoded_r = encodepoint(scalarmultbase(scalar))
320- xpub_hexstr = xprv_to_xpub(xprv_hexstr)['xpub']
320+ xpub_hexstr = get_xpub(xprv_hexstr)
321321 xpub_bytes = bytes.fromhex(xpub_hexstr)
322322 hram_digest_data = encoded_r + xpub_bytes[:32] + message_bytes
323323
@@ -357,16 +357,16 @@ def xprv_sign(xprv_hexstr, message_hexstr):
357357 # signature_hexstr: ab18f49b23d03295bc2a3f2a7d5bb53a2997bed733e1fc408b50ec834ae7e43f7da40fe5d9d50f6ef2d188e1d27f976aa2586cef1ba00dd098b5c9effa046306
358358 def xpub_verify(xpub_hexstr, message_hexstr, signature_hexstr):
359359 result = False
360- result = verify(xpub_to_public_key(xpub_hexstr)['public_key'], signature_hexstr, message_hexstr)['result']
360+ result = verify(get_public_key(xpub_hexstr), signature_hexstr, message_hexstr)
361361 return result
362362
363363
364-def get_new_key(entropy_hexstr=None, mnemonic_hexstr=None):
364+def get_new_key(entropy_hexstr=None, mnemonic_str=None):
365365 if (entropy_hexstr is None) and (mnemonic_str is None):
366366 entropy_hexstr = get_entropy()
367367 mnemonic_str = get_mnemonic(entropy_hexstr)
368368 if (entropy_hexstr is None) and (mnemonic_str is not None):
369- pass
369+ entropy_hexstr = ''
370370 if entropy_hexstr is not None:
371371 mnemonic_str = get_mnemonic(entropy_hexstr)
372372 seed_hexstr = get_seed(mnemonic_str)
--- a/pybtm/signature.py
+++ b/pybtm/signature.py
@@ -33,6 +33,4 @@ def verify(public_key_str, signature_str, message_str):
3333 result = True
3434 except ed25519.BadSignatureError:
3535 result = False
36- return {
37- "result": result
38- }
36+ return result
\ No newline at end of file
--- a/pybtm/utils.py
+++ b/pybtm/utils.py
@@ -1,6 +1,14 @@
11 import qrcode
22 import pybase64
3+import six
4+import hmac
5+import hashlib
6+import sha3
37 from io import BytesIO
8+from binascii import hexlify
9+from binascii import unhexlify
10+from .edwards25519 import *
11+# from bytom.signatures import ed25519
412
513 # create_qrcode_base64 create qrcode, then encode it to base64
614 # type(s) is str
@@ -11,4 +19,62 @@ def create_qrcode_base64(s):
1119 base64_str = pybase64.b64encode(buffered.getvalue()).decode("utf-8")
1220 return {
1321 "base64": base64_str
14- }
\ No newline at end of file
22+ }
23+
24+
25+if six.PY3:
26+ def byte2int(b):
27+ return b
28+ def int2byte(i):
29+ return bytes(chr(i % 256), encoding="UTF-8")
30+
31+elif six.PY2:
32+ def byte2int(b):
33+ return ord(b)
34+ def int2byte(i):
35+ return chr(i % 256)
36+
37+L = 2 ** 252 + 27742317777372353535851937790883648493
38+
39+def sha3_digest_256(data):
40+ s = sha3.sha3_256()
41+ s.update(data)
42+ return s.digest()
43+
44+def hmac_sha_512(data, key):
45+ digest = hmac.new(key, msg=data, digestmod=hashlib.sha512).digest()
46+ return digest
47+
48+def sha_512(data):
49+ md = hashlib.sha512()
50+ md.update(data)
51+ return md.digest()
52+
53+def hex2int(hex):
54+ ## converts a hex string to integer
55+ unhex = unhexlify(hex)
56+ s = 0
57+ for i in range(len(unhex)):
58+ s += 256 ** i * byte2int(unhex[i])
59+ return s
60+
61+def int2hex(int):
62+ ## converts an integer to a little endian encoded hex string
63+ return hexlify(encodeint(int))
64+
65+def sc_reduce32(input):
66+ ## convert hex string input to integer
67+ int = hex2int(input)
68+ ## reduce mod l
69+ modulo = int % L
70+ ## convert back to hex string for return value
71+ return int2hex(modulo)
72+
73+def sc_muladd(a, b, c):
74+ a_int = hex2int(a)
75+ b_int = hex2int(b)
76+ c_int = hex2int(c)
77+
78+ s = a_int * b_int + c_int
79+ modulo = s % L
80+ return int2hex(modulo)
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
55
66 setuptools.setup(
77 name="pybtm",
8- version="0.0.9",
8+ version="0.0.14",
99 author="zcc0721",
1010 author_email="zcc0721@foxmail.com",
1111 description="Python3 implementation of the Bytom protocol.",
Show on old repository browser