commit 5846f725d69815a25b88ecb2e9b320a33f3d69a0
parent 60cefeafcaddf64711c51f0cbc96db0d51f33e94
Author: thomasv <thomasv@gitorious>
Date: Sun, 3 Mar 2013 10:56:48 +0100
simplify Sequence class
Diffstat:
1 file changed, 8 insertions(+), 19 deletions(-)
diff --git a/lib/bitcoin.py b/lib/bitcoin.py
@@ -438,9 +438,9 @@ class DeterministicSequence:
seed = hashlib.sha256(seed + oldseed).digest()
return string_to_number( seed )
- def get_sequence(self, sequence):
+ def get_sequence(self, sequence, mpk):
for_change, n = sequence
- return string_to_number( Hash( "%d:%d:"%(n,for_change) + self.master_public_key.decode('hex') ) )
+ return string_to_number( Hash( "%d:%d:"%(n,for_change) + mpk.decode('hex') ) )
def get_address(self, sequence):
if not self.is_p2sh:
@@ -448,26 +448,15 @@ class DeterministicSequence:
address = public_key_to_bc_address( pubkey.decode('hex') )
else:
pubkey1 = self.get_pubkey(sequence)
- pubkey2 = self.get_pubkey2(sequence)
+ pubkey2 = self.get_pubkey(sequence, use_mpk2=True)
address = Transaction.multisig_script([pubkey1, pubkey2], 2)["address"]
return address
- #sec = self.p2sh_sequence.get_private_key(n, for_change, seed)
- #addr = hash_160_to_bc_address(hash_160(txin["redeemScript"].decode('hex')), 5)
-
- def get_pubkey2(self, sequence):
- for_change, n = sequence
- curve = SECP256k1
- z = string_to_number( Hash( "%d:%d:"%(n, for_change) + self.mpk2.decode('hex') ) )
- master_public_key = ecdsa.VerifyingKey.from_string( self.mpk2.decode('hex'), curve = SECP256k1 )
- pubkey_point = master_public_key.pubkey.point + z*curve.generator
- public_key2 = ecdsa.VerifyingKey.from_public_point( pubkey_point, curve = SECP256k1 )
- return '04' + public_key2.to_string().encode('hex')
-
- def get_pubkey(self, sequence):
+ def get_pubkey(self, sequence, use_mpk2=False):
curve = SECP256k1
- z = self.get_sequence(sequence)
- master_public_key = ecdsa.VerifyingKey.from_string( self.master_public_key.decode('hex'), curve = SECP256k1 )
+ mpk = self.mpk2 if use_mpk2 else self.master_public_key
+ z = self.get_sequence(sequence, mpk)
+ master_public_key = ecdsa.VerifyingKey.from_string( mpk.decode('hex'), curve = SECP256k1 )
pubkey_point = master_public_key.pubkey.point + z*curve.generator
public_key2 = ecdsa.VerifyingKey.from_public_point( pubkey_point, curve = SECP256k1 )
return '04' + public_key2.to_string().encode('hex')
@@ -506,7 +495,7 @@ class DeterministicSequence:
redeemScript = None
else:
pubkey1 = self.get_pubkey(sequence)
- pubkey2 = self.get_pubkey2(sequence)
+ pubkey2 = self.get_pubkey(sequence,use_mpk2=True)
pk_addr = public_key_to_bc_address( pubkey1.decode('hex') ) # we need to return that address to get the right private key
redeemScript = Transaction.multisig_script([pubkey1, pubkey2], 2)['redeemScript']