add ser and get_addr to public_key class
This commit is contained in:
parent
ef01a8ffe2
commit
0bc54205b4
16
pywallet.py
16
pywallet.py
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
#-*- coding: utf-8 -*-
|
#-*- coding: utf-8 -*-
|
||||||
pywversion="2.1.4"
|
pywversion="2.1.5"
|
||||||
never_update=False
|
never_update=False
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -986,10 +986,11 @@ class Signature( object ):
|
|||||||
self.s = s
|
self.s = s
|
||||||
|
|
||||||
class Public_key( object ):
|
class Public_key( object ):
|
||||||
def __init__( self, generator, point ):
|
def __init__( self, generator, point, c=None ):
|
||||||
self.curve = generator.curve()
|
self.curve = generator.curve()
|
||||||
self.generator = generator
|
self.generator = generator
|
||||||
self.point = point
|
self.point = point
|
||||||
|
self.compressed = c
|
||||||
n = generator.order()
|
n = generator.order()
|
||||||
if not n:
|
if not n:
|
||||||
raise RuntimeError, "Generator point must have order."
|
raise RuntimeError, "Generator point must have order."
|
||||||
@ -1012,6 +1013,17 @@ class Public_key( object ):
|
|||||||
v = xy.x() % n
|
v = xy.x() % n
|
||||||
return v == r
|
return v == r
|
||||||
|
|
||||||
|
def ser(self):
|
||||||
|
if self.compressed:
|
||||||
|
pk=('%02x'%(2+(self.point.y()&1))) + '%064x' % self.point.x()
|
||||||
|
else:
|
||||||
|
pk='04%064x%064x' % (self.point.x(), self.point.y())
|
||||||
|
|
||||||
|
return pk.decode('hex')
|
||||||
|
|
||||||
|
def get_addr(self, v=0):
|
||||||
|
return public_key_to_bc_address(self.ser(), v)
|
||||||
|
|
||||||
class Private_key( object ):
|
class Private_key( object ):
|
||||||
def __init__( self, public_key, secret_multiplier ):
|
def __init__( self, public_key, secret_multiplier ):
|
||||||
self.public_key = public_key
|
self.public_key = public_key
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user