version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
|
|
|
from lib.BitcoinECC import BitcoinECC
|
|
|
|
from lib.pybitcointools import bitcoin as btctools
|
2015-01-12 02:03:45 +01:00
|
|
|
|
|
|
|
|
2015-01-20 02:47:00 +01:00
|
|
|
def newPrivatekey(uncompressed=True): # Return new private key
|
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
2015-02-09 02:09:02 +01:00
|
|
|
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")
|
2015-01-12 02:03:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
def privatekeyToAddress(privatekey): # Return address from private key
|
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
2015-02-09 02:09:02 +01:00
|
|
|
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
|
2015-01-12 02:03:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
def sign(data, privatekey): # Return sign to data using private key
|
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
2015-02-09 02:09:02 +01:00
|
|
|
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)
|
2015-01-12 02:03:45 +01:00
|
|
|
bitcoin = BitcoinECC.Bitcoin()
|
|
|
|
bitcoin.BitcoinAddressFromPrivate(privatekey)
|
|
|
|
sign = bitcoin.SignECDSA(data)
|
|
|
|
return sign
|
|
|
|
|
|
|
|
|
|
|
|
def verify(data, address, sign): # Verify data using address and sign
|
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
2015-02-09 02:09:02 +01:00
|
|
|
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)
|