version 0.2.0, new lib for bitcoin ecc, dont display or track notify errors, dont reload again within 1 sec, null peer ip fix, signingmoved to ContentManager, content.json include support, content.json multisig ready, content.json proper bitcoincore compatible signing, content.json include permissions, multithreaded publish, publish timeout 60s, no exception on invalid bitcoin address, testcase for new lib, bip32 based persite privatekey generation, multiuser ready, simple json database query command, websocket api fileGet, wrapper loading title stuck bugfix
This commit is contained in:
parent
cfe2cfaf09
commit
639b9f4961
44 changed files with 4061 additions and 293 deletions
|
@ -1,21 +1,42 @@
|
|||
from src.lib.BitcoinECC import BitcoinECC
|
||||
from src.lib.pybitcointools import bitcoin as btctools
|
||||
|
||||
|
||||
def newPrivatekey(uncompressed=True): # Return new private key
|
||||
from src.lib.BitcoinECC import newBitcoinECC # Use new lib to generate WIF compatible addresses, but keep using the old yet for backward compatiblility issues
|
||||
bitcoin = newBitcoinECC.Bitcoin()
|
||||
d = bitcoin.GenerateD()
|
||||
bitcoin.AddressFromD(d, uncompressed)
|
||||
return bitcoin.PrivFromD(d, uncompressed)
|
||||
privatekey = btctools.encode_privkey(btctools.random_key(), "wif")
|
||||
return privatekey
|
||||
|
||||
|
||||
def newSeed():
|
||||
return btctools.random_key()
|
||||
|
||||
|
||||
def hdPrivatekey(seed, child):
|
||||
masterkey = btctools.bip32_master_key(seed)
|
||||
childkey = btctools.bip32_ckd(masterkey, child % 100000000) # Too large child id could cause problems
|
||||
key = btctools.bip32_extract_key(childkey)
|
||||
return btctools.encode_privkey(key, "wif")
|
||||
|
||||
|
||||
def privatekeyToAddress(privatekey): # Return address from private key
|
||||
bitcoin = BitcoinECC.Bitcoin()
|
||||
bitcoin.BitcoinAddressFromPrivate(privatekey)
|
||||
return bitcoin.BitcoinAddresFromPublicKey()
|
||||
if privatekey.startswith("23") and len(privatekey) > 52: # Backward compatibility to broken lib
|
||||
bitcoin = BitcoinECC.Bitcoin()
|
||||
bitcoin.BitcoinAddressFromPrivate(privatekey)
|
||||
return bitcoin.BitcoinAddresFromPublicKey()
|
||||
else:
|
||||
try:
|
||||
return btctools.privkey_to_address(privatekey)
|
||||
except Exception, err: # Invalid privatekey
|
||||
return False
|
||||
|
||||
|
||||
def sign(data, privatekey): # Return sign to data using private key
|
||||
if privatekey.startswith("23") and len(privatekey) > 52: return None # Old style private key not supported
|
||||
sign = btctools.ecdsa_sign(data, privatekey)
|
||||
return sign
|
||||
|
||||
|
||||
def signOld(data, privatekey): # Return sign to data using private key (backward compatible old style)
|
||||
bitcoin = BitcoinECC.Bitcoin()
|
||||
bitcoin.BitcoinAddressFromPrivate(privatekey)
|
||||
sign = bitcoin.SignECDSA(data)
|
||||
|
@ -23,5 +44,10 @@ def sign(data, privatekey): # Return sign to data using private key
|
|||
|
||||
|
||||
def verify(data, address, sign): # Verify data using address and sign
|
||||
bitcoin = BitcoinECC.Bitcoin()
|
||||
return bitcoin.VerifyMessageFromBitcoinAddress(address, data, sign)
|
||||
if hasattr(sign, "endswith"):
|
||||
pub = btctools.ecdsa_recover(data, sign)
|
||||
sign_address = btctools.pubtoaddr(pub)
|
||||
return sign_address == address
|
||||
else: # Backward compatible old style
|
||||
bitcoin = BitcoinECC.Bitcoin()
|
||||
return bitcoin.VerifyMessageFromBitcoinAddress(address, data, sign)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue