From acab92c5618d5c307cfd881a66e28259ab1109ab Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Sun, 14 Apr 2024 04:09:07 +0300 Subject: [PATCH 1/2] Add a test for random address generation --- src/tests/test_addressgenerator.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/tests/test_addressgenerator.py b/src/tests/test_addressgenerator.py index 236b4d8b..e48daef9 100644 --- a/src/tests/test_addressgenerator.py +++ b/src/tests/test_addressgenerator.py @@ -85,3 +85,17 @@ class TestAddressGenerator(TestPartialRun): self.config.getboolean(sample_deterministic_addr4, 'chan')) self.assertTrue( self.config.getboolean(sample_deterministic_addr4, 'enabled')) + + def test_random(self): + """Test random address""" + self.command_queue.put(( + 'createRandomAddress', 4, 1, 'test_random', 1, '', False, 0, 0)) + addr = self.return_queue.get() + self.assertRegexpMatches(addr, r'^BM-') + self.assertRegexpMatches(addr[3:], r'[a-zA-Z1-9]+$') + self.assertLessEqual(len(addr[3:]), 40) + + self.assertEqual( + self.worker_queue.get(), ('sendOutOrStoreMyV4Pubkey', addr)) + self.assertEqual(self.config.get(addr, 'label'), 'test_random') + self.assertTrue(self.config.getboolean(addr, 'enabled')) -- 2.45.1 From d547a8be2f2eb42bb7f05b104317dec2ef1df362 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Sun, 14 Apr 2024 04:31:02 +0300 Subject: [PATCH 2/2] Encode WIF string before passing to highlevelcrypto.decodeWalletImportFormat() --- src/class_singleWorker.py | 9 +++++---- src/shared.py | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/class_singleWorker.py b/src/class_singleWorker.py index 77583626..7077b697 100644 --- a/src/class_singleWorker.py +++ b/src/class_singleWorker.py @@ -201,10 +201,11 @@ class singleWorker(StoppableThread): 'Could not read or decode privkey for address %s', address) raise ValueError - privSigningKeyHex = hexlify( - highlevelcrypto.decodeWalletImportFormat(privSigningKeyBase58)) + privSigningKeyHex = hexlify(highlevelcrypto.decodeWalletImportFormat( + privSigningKeyBase58.encode())) privEncryptionKeyHex = hexlify( - highlevelcrypto.decodeWalletImportFormat(privEncryptionKeyBase58)) + highlevelcrypto.decodeWalletImportFormat( + privEncryptionKeyBase58.encode())) # The \x04 on the beginning of the public keys are not sent. # This way there is only one acceptable way to encode @@ -1113,7 +1114,7 @@ class singleWorker(StoppableThread): continue privEncryptionKeyHex = hexlify( highlevelcrypto.decodeWalletImportFormat( - privEncryptionKeyBase58)) + privEncryptionKeyBase58.encode())) pubEncryptionKeyBase256 = unhexlify(highlevelcrypto.privToPub( privEncryptionKeyHex))[1:] requiredAverageProofOfWorkNonceTrialsPerByte = \ diff --git a/src/shared.py b/src/shared.py index 3570864a..b85ddb20 100644 --- a/src/shared.py +++ b/src/shared.py @@ -102,8 +102,8 @@ def reloadMyAddressHashes(): # Returns a simple 32 bytes of information encoded in 64 Hex characters try: privEncryptionKey = hexlify( - highlevelcrypto.decodeWalletImportFormat( - config.get(addressInKeysFile, 'privencryptionkey') + highlevelcrypto.decodeWalletImportFormat(config.get( + addressInKeysFile, 'privencryptionkey').encode() )) except ValueError: logger.error( -- 2.45.1