diff --git a/bitcoinlib/keys.py b/bitcoinlib/keys.py index d0ea8eaf..45cde2d5 100644 --- a/bitcoinlib/keys.py +++ b/bitcoinlib/keys.py @@ -107,10 +107,10 @@ def get_key_format(key, is_private=None): This method does not validate if a key is valid. >>> get_key_format('L4dTuJf2ceEdWDvCPsLhYf8GiiuYqXtqfbcKdC21BPDvEM1ykJRC') - {'format': 'wif_compressed', 'networks': ['bitcoin', 'regtest'], 'is_private': True, 'script_types': [], 'witness_types': ['legacy'], 'multisig': [False]} + {'format': 'wif_compressed', 'networks': ['bitcoin', 'regtest'], 'is_private': True, 'script_types': [], 'witness_types': ['segwit'], 'multisig': [False]} >>> get_key_format('becc7ac3b383cd609bd644aa5f102a811bac49b6a34bbd8afe706e32a9ac5c5e') - {'format': 'hex', 'networks': None, 'is_private': True, 'script_types': [], 'witness_types': ['legacy'], 'multisig': [False]} + {'format': 'hex', 'networks': None, 'is_private': True, 'script_types': [], 'witness_types': ['segwit'], 'multisig': [False]} >>> get_key_format('Zpub6vZyhw1ShkEwNxtqfjk7jiwoEbZYMJdbWLHvEwo6Ns2fFc9rdQn3SerYFQXYxtZYbA8a1d83shW3g4WbsnVsymy2L8m7wpeApiuPxug3ARu') {'format': 'hdkey_public', 'networks': ['bitcoin', 'regtest'], 'is_private': False, 'script_types': ['p2wsh'], 'witness_types': ['segwit'], 'multisig': [True]} @@ -242,7 +242,7 @@ def deserialize_address(address, encoding=None, network=None): If more networks and or script types are found you can find these in the 'networks' field. >>> deserialize_address('1Khyc5eUddbhYZ8bEZi9wiN8TrmQ8uND4j') - {'address': '1Khyc5eUddbhYZ8bEZi9wiN8TrmQ8uND4j', 'encoding': 'base58', 'public_key_hash': 'cd322766c02e7c37c3e3f9b825cd41ffbdcd17d7', 'public_key_hash_bytes': b"\\xcd2'f\\xc0.|7\\xc3\\xe3\\xf9\\xb8%\\xcdA\\xff\\xbd\\xcd\\x17\\xd7", 'prefix': b'\\x00', 'network': 'bitcoin', 'script_type': 'p2pkh', 'witness_type': 'legacy', 'networks': ['bitcoin', 'regtest'], 'witver': None} + {'address': '1Khyc5eUddbhYZ8bEZi9wiN8TrmQ8uND4j', 'encoding': 'base58', 'public_key_hash': 'cd322766c02e7c37c3e3f9b825cd41ffbdcd17d7', 'public_key_hash_bytes': b"\\xcd2'f\\xc0.|7\\xc3\\xe3\\xf9\\xb8%\\xcdA\\xff\\xbd\\xcd\\x17\\xd7", 'prefix': b'\\x00', 'network': 'bitcoin', 'script_type': 'p2pkh', 'witness_type': 'legacy', 'networks': ['bitcoin', 'regtest'], 'checksum': b'\xcf\xa4I0', 'witver': None} :param address: A base58 or bech32 encoded address :type address: str @@ -1730,7 +1730,7 @@ def __init__(self, import_key=None, key=None, chain=None, depth=0, parent_finger >>> private_hex = '221ff330268a9bb5549a02c801764cffbc79d5c26f4041b26293a425fd5b557c' >>> k = HDKey(private_hex) >>> k - + :param import_key: HD Key to import in WIF format or as byte with key (32 bytes) and chain (32 bytes) :type import_key: str, bytes, int, tuple @@ -1980,7 +1980,7 @@ def wif(self, is_private=None, child_index=None, prefix=None, witness_type=None, >>> private_hex = '221ff330268a9bb5549a02c801764cffbc79d5c26f4041b26293a425fd5b557c' >>> k = HDKey(private_hex) >>> k.wif() - 'xpub661MyMwAqRbcEYS8w7XLSVeEsBXy79zSzH1J8vCdxAZningWLdN3zgtU6SmypHzZG2cYrwpGkWJqRxS6EAW77gd7CHFoXNpBd3LN8xjAyCW' + 'zpub6jftahH18ngZw8pNbq6arfqFD7przPySpW3jhhzQiBKYpzJxqwhBEpCk8rh9p7JQ5JrAMu1Pfq1wCXfDfZL8i9zJvxeehCTAAVTev5oZKCn' :param is_private: Return public or private key :type is_private: bool @@ -2149,7 +2149,7 @@ def public_master(self, account_id=0, purpose=None, multisig=None, witness_type= >>> k = HDKey(private_hex) >>> pm = k.public_master() >>> pm.wif() - 'xpub6CjFexgdDZEtHdW7V4LT8wS9rtG3m187pM9qhTpoZdViFhSv3tW9sWonQNtFN1TCkRGAQGKj1UC2ViHTqb7vJV3X67xSKuCDzv14tBHR3Y7' + 'zpub6qN4WhSaerCBXv28QdRXwY4EvnAUbCSLCWUF5ZNSsyrupWwBRv4irjjQ6vpz5WFM7Z7zyy3eQBzijfszpvqdoiyAVLc44MsL4mVQDTwSHpT' :param account_id: Account ID. Leave empty for account 0 :type account_id: int @@ -2221,7 +2221,7 @@ def child_private(self, index=0, hardened=False, network=None): >>> k = HDKey(private_hex) >>> ck = k.child_private(10) >>> ck.address() - '1FgHK5JUa87ASxz5mz3ypeaUV23z9yW654' + 'bc1q5rlenzyn95pt4rur6jcnrgx5s3u6kw0nnwjrtt' >>> ck.depth 1 >>> ck.child_index @@ -2272,7 +2272,7 @@ def child_public(self, index=0, network=None): >>> k = HDKey(private_hex) >>> ck = k.child_public(15) >>> ck.address() - '1PfLJJgKs8nUbMPpaQUucbGmr8qyNSMGeK' + 'bc1qlzf2a6tskk8g6g55nsda7akmwsevasv5p4muuf' >>> ck.depth 1 >>> ck.child_index diff --git a/bitcoinlib/networks.py b/bitcoinlib/networks.py index e8651a98..5695b0b6 100644 --- a/bitcoinlib/networks.py +++ b/bitcoinlib/networks.py @@ -72,9 +72,9 @@ def network_values_for(field): Return all prefixes for field, i.e.: prefix_wif, prefix_address_p2sh, etc >>> network_values_for('prefix_wif') - [b'\\x99', b'\\x80', b'\\xef', b'\\xb0', b'\\xcc', b'\\x9e', b'\\xf1'] + [b'\\x99', b'\\x80', b'\\xef', b'\\xb0', b'\\x9e', b'\\xf1'] >>> network_values_for('prefix_address_p2sh') - [b'\\x95', b'\\x05', b'\\xc4', b'2', b':', b'\\x10', b'\\x13', b'\\x16'] + [b'\\x95', b'\\x05', b'\\xc4', b'2', b':', b'\\x16'] :param field: Prefix name from networks definitions (networks.json) :type field: str diff --git a/bitcoinlib/scripts.py b/bitcoinlib/scripts.py index 720218c8..412a6968 100644 --- a/bitcoinlib/scripts.py +++ b/bitcoinlib/scripts.py @@ -155,7 +155,7 @@ def __init__(self, commands=None, message=None, script_types='', is_locking=True >>> s = Script([op.op_2, op.op_4, op.op_add]) >>> s - + >>> s.blueprint [82, 84, 147] >>> s.evaluate() @@ -259,7 +259,7 @@ def parse(cls, script, message=None, env_data=None, is_locking=None, strict=True Wrapper for the :func:`parse_bytesio` method. Convert hexadecimal string or bytes script to BytesIO. >>> Script.parse('76a914af8e14a2cecd715c363b3a72b55b59a31e2acac988ac') - + :param script: Raw script to parse in bytes, BytesIO or hexadecimal string format :type script: BytesIO, bytes, str @@ -449,7 +449,7 @@ def parse_hex(cls, script, message=None, env_data=None, is_locking=None, strict= Wrapper for the :func:`parse_bytesio` method. Convert hexadecimal string script to BytesIO. >>> Script.parse_hex('76a914af8e14a2cecd715c363b3a72b55b59a31e2acac988ac') - + :param script: Raw script to parse in hexadecimal string format :type script: str @@ -503,7 +503,7 @@ def parse_str(cls, script, message=None, env_data=None, is_locking=None, strict= >>> s = Script.parse_str("1 98 OP_ADD 99 OP_EQUAL") >>> s - data-1 data-1 OP_ADD data-1 OP_EQUAL + >>> s.evaluate() True @@ -539,7 +539,7 @@ def parse_str(cls, script, message=None, env_data=None, is_locking=None, strict= def __repr__(self): s_items = self.view(blueprint=True, as_list=True) - return '' + return '' def __str__(self): return self.view(blueprint=True) @@ -671,7 +671,7 @@ def evaluate(self, message=None, env_data=None, trace=False): >>> s = Script([op.op_2, op.op_4, op.op_add]) >>> s - + >>> s.blueprint [82, 84, 147] >>> s.evaluate() diff --git a/bitcoinlib/wallets.py b/bitcoinlib/wallets.py index 24f69b72..d9502eef 100644 --- a/bitcoinlib/wallets.py +++ b/bitcoinlib/wallets.py @@ -314,9 +314,9 @@ def from_key(name, wallet_id, session, key, account_id=0, network=None, change=0 >>> wif = 'xprv9s21ZrQH143K2mcs9jcK4EjALbu2z1N9qsMTUG1frmnXM3NNCSGR57yLhwTccfNCwdSQEDftgjCGm96P29wGGcbBsPqZH85iqpoHA7LrqVy' >>> wk = WalletKey.from_key('import_key', w.wallet_id, w.session, wif) >>> wk.address - '1MwVEhGq6gg1eeSrEdZom5bHyPqXtJSnPg' + 'bc1qukcgc3guzt0a27j7vdegtgwxsrv4khc4688ycs' >>> wk # doctest:+ELLIPSIS - + :param name: New key name :type name: str @@ -1886,7 +1886,7 @@ def new_keys(self, name='', account_id=None, change=0, cosigner_id=None, witness >>> w = Wallet('create_legacy_wallet_test') >>> w.new_key('my key') # doctest:+ELLIPSIS - + :param name: Key name. Does not have to be unique but if you use it at reference you might chooce to enforce this. If not specified 'Key #' with a unique sequence number will be used :type name: str @@ -2109,7 +2109,7 @@ def get_key(self, account_id=None, witness_type=None, network=None, cosigner_id= >>> w = Wallet('create_legacy_wallet_test') >>> w.get_key() # doctest:+ELLIPSIS - + :param account_id: Account ID. Default is last used or created account ID. :type account_id: int @@ -2253,11 +2253,11 @@ def path_expand(self, path, level_offset=None, account_id=None, cosigner_id=0, a >>> w = Wallet('create_legacy_wallet_test') >>> w.path_expand([0,1200]) - ['m', "44'", "0'", "0'", '0', '1200'] + ['m', "84'", "0'", "0'", '0', '1200'] >>> w = Wallet('create_legacy_multisig_wallet_test') >>> w.path_expand([0,2], cosigner_id=1) - ['m', "45'", '1', '0', '2'] + ['m', "48'", "0'", "0'", "2'", '0', '2'] :param path: Part of path, for example [0, 2] for change=0 and address_index=2 :type path: list, str @@ -2321,18 +2321,18 @@ def keys_for_path(self, path, level_offset=None, name=None, account_id=None, cos >>> w = wallet_create_or_open('key_for_path_example') >>> key = w.key_for_path([0, 0]) >>> key.path - "m/44'/0'/0'/0/0" + "m/84'/0'/0'/0/0" >>> w.key_for_path([], level_offset=-2).path - "m/44'/0'/0'" + "m/84'/0'/0'" >>> w.key_for_path([], w.depth_public_master + 1).path - "m/44'/0'/0'" + "m/84'/0'/0'" Arguments provided in 'path' take precedence over other arguments. The address_index argument is ignored: >>> key = w.key_for_path([0, 10], address_index=1000) >>> key.path - "m/44'/0'/0'/0/10" + "m/84'/0'/0'/0/10" >>> key.address_index 10 @@ -2589,9 +2589,6 @@ def keys_networks(self, used=None, as_dict=False): >>> w = Wallet('bitcoinlib_legacy_wallet_test') >>> network_key = w.keys_networks() - >>> # Address index of hardened key 0' is 2147483648 - >>> network_key[0].address_index - 2147483648 >>> network_key[0].path "m/44'/0'" diff --git a/tests/test_script.py b/tests/test_script.py index aac056ca..07e36bee 100644 --- a/tests/test_script.py +++ b/tests/test_script.py @@ -759,7 +759,7 @@ def test_script_add(self): def test_script_create_simple(self): script = Script([op.op_2, op.op_5, op.op_sub, op.op_1]) self.assertEqual(str(script), 'OP_2 OP_5 OP_SUB OP_1') - self.assertEqual(repr(script), '') + self.assertEqual(repr(script), '') self.assertEqual(script.serialize().hex(), '52559451') self.assertEqual(script.serialize_list(), [b'R', b'U', b'\x94', b'Q']) self.assertTrue(script.evaluate())