def test_bytes_to_passphrase_returns_expected_passphrases(): assert niceware.bytes_to_passphrase(b'') == [] assert niceware.bytes_to_passphrase([0, 0]) == ['a'] assert niceware.bytes_to_passphrase([0xff, 0xff]) == ['zyzzyva'] assert niceware.bytes_to_passphrase( [0, 0, 17, 212, 12, 140, 90, 247, 46, 83, 254, 60, 54, 169, 255, 255]) \ == \ ['a', 'bioengineering', 'balloted', 'gobbledegook', 'creneled', 'written', 'depriving', 'zyzzyva']
def add_vanity(): key_manager = keymanager.KeyManager() tell = lambda tell: logger.info(tell, terminal=True) words = '' length = len(sys.argv) - 2 if length == 0: return for i in range(2, len(sys.argv)): words += ' ' words += sys.argv[i] try: if length == 1: tell('Finding vanity, this should only take a few moments.') else: tell('Finding vanity, this will probably take a really long time.') try: vanity = vanityonionr.find_multiprocess(words) except ValueError: logger.warn('Vanity words must be valid english bip39', terminal=True) else: b32_pub = unpaddedbase32.b32encode(vanity[0]) tell('Found vanity address:\n' + niceware.bytes_to_passphrase(vanity[0])) tell('Base32 Public key: %s' % (b32_pub.decode(), )) key_manager.addKey(b32_pub, unpaddedbase32.b32encode(vanity[1])) except KeyboardInterrupt: pass
def get_human_readable_ID(pub=''): '''gets a human readable ID from a public key''' if pub == '': pub = onionrcrypto.pub_key if not len(pub) == onionrvalues.MAIN_PUBLIC_KEY_SIZE: pub = base64.b32decode(pub) return DELIMITER.join(niceware.bytes_to_passphrase(pub))
def test_bytes_to_passphrase_raises_when_not_a_byte_sequence(): with pytest.raises(TypeError): niceware.bytes_to_passphrase(1) with pytest.raises(ValueError): niceware.bytes_to_passphrase([255, 999]) with pytest.raises(TypeError): niceware.bytes_to_passphrase(iter(b'ab'))
def find_vanity_mnemonic(start_words: str, queue): key_pair = [b"", b""] vanity_key = "" check = 0 while not vanity_key.startswith(start_words): key = nacl.signing.SigningKey.generate() key_pair[1] = key.encode(nacl.encoding.RawEncoder) key_pair[0] = key.verify_key.encode(encoder=nacl.encoding.RawEncoder) vanity_key = '-'.join(niceware.bytes_to_passphrase(key_pair[0])) check += 1 else: queue.put(key_pair) return key_pair
def test_vanity(self): testargs = ["onionr.py"] with patch.object(sys, 'argv', testargs): try: parser.register() except SystemExit: pass testargs = ["onionr.py", "add-vanity", "jolt"] with patch.object(sys, 'argv', testargs): parser.register() with open(keys_file, 'r') as keys: key_list = keys.read().split('\n') print('vanity key list test key database contents:', key_list) if not niceware.bytes_to_passphrase(unpaddedbase32.b32decode(key_list[1].split(',')[0]))[0].startswith('jolt'): raise ValueError('Vanity generation failed')
def test_basic(self): pair = vanityonionr.find_multiprocess("onion") b = niceware.bytes_to_passphrase(pair[0]) self.assertTrue(b[0].startswith("onion"))
def test_bytes_to_passphrase_raises_when_odd_length(): with pytest.raises(ValueError): niceware.bytes_to_passphrase(bytearray(1))