mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-04-22 19:13:37 +08:00
WIP: remove all requirements for holding onto the data private key in core
This commit is contained in:
@@ -54,74 +54,6 @@ B40_REGEX = '^{}*$'.format(B40_CLASS)
|
||||
URLENCODED_CLASS = '[a-zA-Z0-9\-_.~%]'
|
||||
URLENCODED_PATH_CLASS = '[a-zA-Z0-9\-_.~%/]'
|
||||
|
||||
|
||||
def get_datastore_creds( master_data_privkey=None, app_domain=None, app_user_privkey=None, config_path=CONFIG_PATH ):
|
||||
"""
|
||||
Get datastore credentials
|
||||
Return {'status': True, 'datastore_privkey': ..., 'datastore_id': ...} on success
|
||||
Return {'error': ...} on error
|
||||
"""
|
||||
|
||||
assert app_user_privkey is not None or (master_data_privkey is not None and app_domain is not None), "Invalid creds: need app_domain and master_data_privkey, or app_user_privkey"
|
||||
|
||||
if app_user_privkey is None:
|
||||
app_user_privkey = data.datastore_get_privkey( master_data_privkey, app_domain, config_path=CONFIG_PATH )
|
||||
if app_user_privkey is None:
|
||||
return {'error': 'Failed to load app user private key', 'errno': errno.EPERM}
|
||||
|
||||
app_user_pubkey = get_pubkey_hex(app_user_privkey)
|
||||
datastore_id = data.datastore_get_id(app_user_pubkey)
|
||||
|
||||
ret = {
|
||||
'status': True,
|
||||
'datastore_privkey': app_user_privkey,
|
||||
'datastore_pubkey': app_user_pubkey,
|
||||
'datastore_id': datastore_id
|
||||
}
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
def get_datastore_info( datastore_id=None, app_user_privkey=None, master_data_privkey=None, app_domain=None, config_path=CONFIG_PATH, proxy=None ):
|
||||
"""
|
||||
Get information about an account datastore.
|
||||
At least, get the user and account owner.
|
||||
|
||||
Return {'status': True, 'datastore': ..., 'datastore_id': ..., ['datastore_privkey': ...}] on success.
|
||||
|
||||
Return {'error': ...} on failure
|
||||
"""
|
||||
|
||||
datastore_privkey = None
|
||||
|
||||
if app_user_privkey is not None or (master_data_privkey is not None and app_domain is not None):
|
||||
creds = get_datastore_creds(master_data_privkey, app_domain=app_domain, app_user_privkey=app_user_privkey, config_path=config_path)
|
||||
if 'error' in creds:
|
||||
return creds
|
||||
|
||||
if datastore_id is not None:
|
||||
assert datastore_id == creds['datastore_id'], "Datastore mismatch: {} != {}".format(datastore_id, creds['datastore_id'])
|
||||
|
||||
datastore_privkey = creds['datastore_privkey']
|
||||
datastore_id = creds['datastore_id']
|
||||
|
||||
assert datastore_id, 'No datastore ID given'
|
||||
|
||||
res = data.get_datastore(datastore_id, config_path=config_path, proxy=proxy )
|
||||
if 'error' in res:
|
||||
return res
|
||||
|
||||
if datastore_privkey is not None:
|
||||
res['datastore_privkey'] = datastore_privkey
|
||||
|
||||
if datastore_id is not None:
|
||||
res['datastore_id'] = datastore_id
|
||||
else:
|
||||
res['datastore_id'] = data.datastore_get_id(res['datastore']['pubkey'])
|
||||
|
||||
return res
|
||||
|
||||
|
||||
def blockstack_mutable_data_url(blockchain_id, data_id, version):
|
||||
"""
|
||||
Make a blockstack:// URL for mutable data
|
||||
|
||||
Reference in New Issue
Block a user