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
|
|
|
import logging, json, time
|
|
|
|
from Crypt import CryptBitcoin
|
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 Plugin import PluginManager
|
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
|
|
|
|
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
|
|
|
@PluginManager.acceptPlugins
|
|
|
|
class User(object):
|
|
|
|
def __init__(self, master_address=None, master_seed=None):
|
|
|
|
if master_seed:
|
|
|
|
self.master_seed = master_seed
|
|
|
|
self.master_address = CryptBitcoin.privatekeyToAddress(self.master_seed)
|
|
|
|
elif master_address:
|
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
|
|
|
self.master_address = master_address
|
|
|
|
self.master_seed = None
|
|
|
|
else:
|
|
|
|
self.master_seed = CryptBitcoin.newSeed()
|
|
|
|
self.master_address = CryptBitcoin.privatekeyToAddress(self.master_seed)
|
|
|
|
self.sites = {}
|
|
|
|
self.log = logging.getLogger("User:%s" % self.master_address)
|
|
|
|
|
|
|
|
|
|
|
|
# Save to data/users.json
|
|
|
|
def save(self):
|
|
|
|
users = json.load(open("data/users.json"))
|
|
|
|
if not self.master_address in users: users[self.master_address] = {} # Create if not exits
|
|
|
|
|
|
|
|
user_data = users[self.master_address]
|
|
|
|
if self.master_seed: user_data["master_seed"] = self.master_seed
|
|
|
|
user_data["sites"] = self.sites
|
|
|
|
open("data/users.json", "w").write(json.dumps(users, indent=2, sort_keys=True))
|
|
|
|
self.log.debug("Saved")
|
|
|
|
|
|
|
|
|
2015-02-17 01:48:15 +01:00
|
|
|
# Get user site data
|
|
|
|
# Return: {"auth_address": "xxx", "auth_privatekey": "xxx"}
|
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
|
|
|
def getSiteData(self, address, create=True):
|
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 not address in self.sites: # Genreate new BIP32 child key based on site address
|
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
|
|
|
if not create: return {"auth_address": None, "auth_privatekey": None} # Dont create user yet
|
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
|
|
|
s = time.time()
|
|
|
|
address_id = int(address.encode("hex"), 16) # Convert site address to int
|
|
|
|
auth_privatekey = CryptBitcoin.hdPrivatekey(self.master_seed, address_id)
|
|
|
|
self.sites[address] = {
|
|
|
|
"auth_address": CryptBitcoin.privatekeyToAddress(auth_privatekey),
|
|
|
|
"auth_privatekey": auth_privatekey
|
|
|
|
}
|
|
|
|
self.save()
|
|
|
|
self.log.debug("Added new site: %s in %.3fs" % (address, time.time()-s))
|
2015-02-17 01:48:15 +01:00
|
|
|
return self.sites[address]
|
|
|
|
|
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
|
|
|
|
2015-02-17 01:48:15 +01:00
|
|
|
# Get BIP32 address from site address
|
|
|
|
# Return: BIP32 auth address
|
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
|
|
|
def getAuthAddress(self, address, create=True):
|
|
|
|
return self.getSiteData(address, create)["auth_address"]
|
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
|
|
|
|
|
|
|
|
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
|
|
|
def getAuthPrivatekey(self, address, create=True):
|
|
|
|
return self.getSiteData(address, create)["auth_privatekey"]
|
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
|
|
|
|
|
|
|
|
|
|
|
# Set user attributes from dict
|
|
|
|
def setData(self, data):
|
|
|
|
for key, val in data.items():
|
|
|
|
setattr(self, key, val)
|