• R/O
  • HTTP
  • SSH
  • HTTPS

pybtm: 提交

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


Commit MetaInfo

修订版765c7da228fd54bc3f848eb9695499050a40949d (tree)
时间2019-03-27 18:21:22
作者Chengcheng Zhang <943420582@qq.c...>
CommiterChengcheng Zhang

Log Message

update readme.md

更改概述

差异

--- a/README.md
+++ b/README.md
@@ -8,6 +8,13 @@ pybtm
88 - [2.3 Create seed](#23-create-seed)
99 - [2.4 Create root expanded private key](#24-create-root-expanded-private-key)
1010 - [2.5 Create expanded public key](#25-create-expanded-public-key)
11+ - [2.6 Create expanded private key](#26-create-expanded-private-key)
12+ - [2.7 Create public key](#27-create-public-key)
13+ - [2.8 Create child expanded private key](#28-create-child-expanded-private-key)
14+ - [2.9 Create child expanded public key](#29-create-child-expanded-public-key)
15+ - [Sign message](#sign-message)
16+ - [Verify signature](#verify-signature)
17+ - [Create new key](#create-new-key)
1118
1219 Python3 implementation of the Bytom protocol.
1320
@@ -70,8 +77,178 @@ get_root_xprv create root expanded private key.
7077
7178 get_xpub create expanded public key.
7279
80+Parameter:
81+
82+- xprv_hexstr: 512 bits expanded private key, type is hex string.
83+
84+Return:
85+
86+- xpub_hexstr: 512 bits expanded public key, type is hex string.
87+
7388 ```python
7489 >>> from pybtm import key
75->>> key.get_xpub('c003f4bcccf9ad6f05ad2c84fa5ff98430eb8e73de5de232bc29334c7d074759d513bc370335cac51d77f0be5dfe84de024cfee562530b4d873b5f5e2ff4f57c')
90+>>> xprv_hexstr = 'c003f4bcccf9ad6f05ad2c84fa5ff98430eb8e73de5de232bc29334c7d074759d513bc370335cac51d77f0be5dfe84de024cfee562530b4d873b5f5e2ff4f57c'
91+>>> key.get_xpub(xprv_hexstr)
7692 '1b0541a7664cee929edb54d9ef21996b90546918a920a77e1cd6015d97c56563d513bc370335cac51d77f0be5dfe84de024cfee562530b4d873b5f5e2ff4f57c'
77-```
\ No newline at end of file
93+```
94+
95+### 2.6 Create expanded private key
96+
97+get_expanded_private_key create expanded private key.
98+
99+Parameter:
100+
101+- xprv_hexstr: 512 bits expanded private key, type is hex string.
102+
103+Return:
104+
105+- expanded_private_key_hexstr: 512 bits expanded private key, type is hex string.
106+
107+```python
108+>>> from pybtm import key
109+>>> xprv_hexstr = '406c82307bf7978d17f3ecfeea7705370e9faef2027affa86c8027c6e11a8a50e231e65bd97048850ae6c39d0f46b63ae70aa24f5aac7877727c430c2201e6d6'
110+>>> key.get_expanded_private_key(xprv_hexstr)
111+'406c82307bf7978d17f3ecfeea7705370e9faef2027affa86c8027c6e11a8a50d828bf44b1a109c2bbb4c72685858e2f2ab8b405beef1e4ecc12d1ed8511e8eb'
112+```
113+
114+### 2.7 Create public key
115+
116+get_public_key create 32 bytes public key.
117+
118+Parameter:
119+
120+- xpub_hexstr: 512 bits expanded public key, type is hex string.
121+
122+Return:
123+
124+- public_key_hexstr: 256 bits public key, type is hex string.
125+
126+```python
127+>>> from pybtm import key
128+>>> xpub_hexstr = 'ecc2bbb6c0492873cdbc81edf56bd896d3b644047879840e357be735b7fa7b6f4af1be7b8d71cc649ac4ca3816f9ccaf11bf49f4effb845f3c19e16eaf8bfcda'
129+>>> key.get_public_key(xpub_hexstr)
130+'ecc2bbb6c0492873cdbc81edf56bd896d3b644047879840e357be735b7fa7b6f'
131+```
132+
133+### 2.8 Create child expanded private key
134+
135+get_child_xprv create child private key.
136+
137+Parameter:
138+
139+- xprv_hexstr: 512 bits expanded private key, type is hex string.
140+- path_list: 010203 7906a1
141+
142+Return:
143+
144+- child_xprv_hexstr: 512 bits private key, type is hex string.
145+
146+```python
147+>>> from pybtm import key
148+>>> xprv_hexstr = 'c003f4bcccf9ad6f05ad2c84fa5ff98430eb8e73de5de232bc29334c7d074759d513bc370335cac51d77f0be5dfe84de024cfee562530b4d873b5f5e2ff4f57c'
149+>>> path_list = ['010203', '7906a1']
150+>>> key.get_child_xprv(xprv_hexstr, path_list)
151+'4853a0b00bdcb139e85855d9594e5f641b65218db7c50426946511397e094759bd9de7f2dcad9d7d45389bc94baecaec88aabf58f6e1d832b1f9995a93ec37ea'
152+```
153+
154+### 2.9 Create child expanded public key
155+
156+get_child_xpub create child public key.
157+
158+Parameter:
159+
160+- xpub_hexstr: 512 bits expanded public key, type is hex string.
161+- path_list: 010203 7906a1
162+
163+Return:
164+
165+- child_xpub_hexstr: 512 bits public key, type is hex string.
166+
167+```python
168+>>> from pybtm import key
169+>>> xpub_hexstr = '1b0541a7664cee929edb54d9ef21996b90546918a920a77e1cd6015d97c56563d513bc370335cac51d77f0be5dfe84de024cfee562530b4d873b5f5e2ff4f57c'
170+>>> path_list = ['010203', '7906a1']
171+>>> key.get_child_xpub(xpub_hexstr, path_list)
172+'e65c1a9714e2116c6e5d57dee188a53b98dc901a21def5a5ca46fcf78303f4f2bd9de7f2dcad9d7d45389bc94baecaec88aabf58f6e1d832b1f9995a93ec37ea'
173+```
174+
175+### Sign message
176+
177+xprv_sign sign message.
178+
179+Parameter:
180+
181+- xprv_hexstr: 512 bits expanded private key, type is hex string.
182+- message_hexstr: message, type is hex string.
183+
184+Return:
185+
186+- signature_hexstr: 512 bits signature, type is hex string.
187+
188+```python
189+>>> from pybtm import key
190+>>> xprv_hexstr = '88c0c40fb54ef9c1b90af8cce8dc4c9d54f915074dde93f79ab61cedae03444101ff37ac4a07869214c2735bba0175e001abe608db18538e083e1e44430a273b'
191+>>> message_hexstr = '1246b84985e1ab5f83f4ec2bdf271114666fd3d9e24d12981a3c861b9ed523c6'
192+>>> key.xprv_sign(xprv_hexstr, message_hexstr)
193+'ab18f49b23d03295bc2a3f2a7d5bb53a2997bed733e1fc408b50ec834ae7e43f7da40fe5d9d50f6ef2d188e1d27f976aa2586cef1ba00dd098b5c9effa046306'
194+```
195+
196+### Verify signature
197+
198+xpub_verify verify signature.
199+
200+Parameter:
201+
202+- xpub_hexstr: 512 bits expanded public key, type is hex string.
203+- message_hexstr: message, type is hex string.
204+- signature_hexstr: 512 bits signature, type is hex string.
205+
206+Return:
207+
208+- result: True or False.
209+
210+```python
211+>>> from pybtm import key
212+>>> xpub_hexstr = 'cb22ce197d342d6bb440b0bf13ddd674f367275d28a00f893d7f0b10817690fd01ff37ac4a07869214c2735bba0175e001abe608db18538e083e1e44430a273b'
213+>>> message_hexstr = '1246b84985e1ab5f83f4ec2bdf271114666fd3d9e24d12981a3c861b9ed523c6'
214+>>> signature_hexstr = 'ab18f49b23d03295bc2a3f2a7d5bb53a2997bed733e1fc408b50ec834ae7e43f7da40fe5d9d50f6ef2d188e1d27f976aa2586cef1ba00dd098b5c9effa046306'
215+>>> key.xpub_verify(xpub_hexstr, message_hexstr, signature_hexstr)
216+True
217+```
218+
219+### Create new key
220+
221+get_new_key create new key.
222+
223+Parameter:
224+
225+- entropy_hexstr(optional): 128 bits entropy, type is hex string.
226+- mnemonic_str(optional): 12 mnemonics.
227+
228+Return:
229+
230+- entropy: 128 bits entropy.
231+- mnemonic: 12 mnemonics.
232+- seed: 512 bits seed.
233+- xprv: 512 bits expaneded private key.
234+- xpub: 512 bits expaneded public key.
235+- xprv_base64: xprv hex string qrcode base64.
236+
237+```python
238+>>> from pybtm import key
239+>>> r = key.get_new_key()
240+>>> r['entropy']
241+'8466b1128f92051361c9aa2de52d1bb0'
242+>>> r['mnemonic']
243+'love culture dwarf busy cake meadow mango crystal combine city eight genuine'
244+>>> r['seed']
245+'4d15bf0f72bad754987fdcd0628ea37af03ac24666019c6d362e0200c9b49bee35aa0a788ed09e3a86cd529df0a1c20ea6aa719cf1e0da4ffb15efbc38fba498'
246+>>> r['xprv']
247+'f09ad64c2714b45e23c75e4541ad771def99b97e6da16b0cc6bcdac045f4d34745b62093173fd8f9a67e1da4b81233bc947880b6ed4b9641cf8f5223212fa18d'
248+>>> r['xpub']
249+'ebcc4b14444adb207dd53fd89b2881b21e839de42a1b6687a5a9d83b82c1b5b645b62093173fd8f9a67e1da4b81233bc947880b6ed4b9641cf8f5223212fa18d'
250+>>> r['xprv_base64']
251+{'base64': '/9j/4AAQSkZJRgABAQAAAQABAAD...'}
252+```
253+
254+
--- a/pybtm/key.py
+++ b/pybtm/key.py
@@ -365,9 +365,9 @@ 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)
368- if (entropy_hexstr is None) and (mnemonic_str is not None):
368+ elif (entropy_hexstr is None) and (mnemonic_str is not None):
369369 entropy_hexstr = ''
370- if entropy_hexstr is not None:
370+ elif entropy_hexstr is not None:
371371 mnemonic_str = get_mnemonic(entropy_hexstr)
372372 seed_hexstr = get_seed(mnemonic_str)
373373 root_xprv_hexstr = get_root_xprv(seed_hexstr)
Show on old repository browser