forked from LBRYCommunity/lbry-sdk
Enable unencrypted wallet import and export
This commit is contained in:
parent
d0aad8ccaf
commit
e4e1600f51
3 changed files with 29 additions and 5 deletions
|
@ -1345,8 +1345,10 @@ class Daemon(metaclass=JSONRPCServerType):
|
|||
(str) data
|
||||
|
||||
"""
|
||||
assert password is not None, "passwordless use is not implemented yet"
|
||||
# assert password is not None, "passwordless use is not implemented yet"
|
||||
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
|
||||
if (password is None):
|
||||
return wallet.pack()
|
||||
encrypted = wallet.pack(password)
|
||||
return encrypted.decode()
|
||||
|
||||
|
@ -1370,7 +1372,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
|||
Returns:
|
||||
(str) data
|
||||
"""
|
||||
assert not data.strip().startswith("{"), "unencrypted wallet import is not implemented yet"
|
||||
# assert not data.strip().startswith("{"), "unencrypted wallet import is not implemented yet"
|
||||
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
|
||||
added_accounts, merged_accounts = wallet.merge(self.wallet_manager, password, data)
|
||||
for new_account in itertools.chain(added_accounts, merged_accounts):
|
||||
|
|
|
@ -163,15 +163,19 @@ class Wallet:
|
|||
h.update(account.hash)
|
||||
return h.digest()
|
||||
|
||||
def pack(self, password):
|
||||
def pack(self, password=None):
|
||||
assert not self.is_locked, "Cannot pack a wallet with locked/encrypted accounts."
|
||||
new_data = json.dumps(self.to_dict())
|
||||
if password is None:
|
||||
return new_data.encode()
|
||||
new_data_compressed = zlib.compress(new_data.encode())
|
||||
return better_aes_encrypt(password, new_data_compressed)
|
||||
|
||||
@classmethod
|
||||
def unpack(cls, password, encrypted):
|
||||
decrypted = better_aes_decrypt(password, encrypted)
|
||||
def unpack(cls, password, data):
|
||||
if password is None:
|
||||
return json.loads(data)
|
||||
decrypted = better_aes_decrypt(password, data)
|
||||
try:
|
||||
decompressed = zlib.decompress(decrypted)
|
||||
except zlib.error as e:
|
||||
|
|
|
@ -491,3 +491,21 @@ class WalletEncryptionAndSynchronization(CommandTestCase):
|
|||
daemon2.wallet_manager.default_account.channel_keys,
|
||||
daemon.wallet_manager.default_wallet.accounts[1].channel_keys
|
||||
)
|
||||
|
||||
# test without passwords
|
||||
daemon2.jsonrpc_preference_set("three", "3")
|
||||
jsondata = await daemon2.jsonrpc_wallet_export()
|
||||
await daemon.jsonrpc_wallet_import(data=jsondata, blocking=True)
|
||||
self.assertDictEqual(
|
||||
# "two" key added and "conflict" value changed to "2"
|
||||
daemon.jsonrpc_preference_get(),
|
||||
{
|
||||
"one": "1",
|
||||
"two": "2",
|
||||
"three": "3",
|
||||
"conflict": "2",
|
||||
"another": "B",
|
||||
"fruit": ["peach", "apricot"]
|
||||
}
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue