def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.hash = PublicKey.unhexlify( "02c08786d63f78bd0a6777ffe9c978cf5899756cfc32bfad09a89e211aeb926242" ).hash() self.locked_script = P2shScript( P2pkhScript( PublicKey.unhexlify( "02c08786d63f78bd0a6777ffe9c978cf5899756cfc32bf" "ad09a89e211aeb926242")))
def P2WPKHAddress(self): "Return P2WPKH segwit address" pk_bytes = self.PublicKey() assert len(pk_bytes) == 33 and (pk_bytes.startswith(b"\x02") or pk_bytes.startswith(b"\x03")), \ "Only compressed public keys are compatible with p2sh-p2wpkh addresses. " \ "See https://github.com/bitcoin/bips/blob/master/bip-0049.mediawiki." from btcpy.structs.address import P2wpkhAddress from btcpy.structs.crypto import PublicKey pk = PublicKey(pk_bytes) pk_hash = pk.hash() return str(P2wpkhAddress(pk_hash, 0, mainnet=not self.testnet))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.inner_script = MultisigScript( 2, PublicKey.unhexlify( "02c08786d63f78bd0a6777ffe9c978cf5899756cfc32bfad09a89e2" "11aeb926242"), PublicKey.unhexlify( "033e81519ecf373ea3a5c7e1c051b71a898fb3438c9550e274d980f" "147eb4d069d"), PublicKey.unhexlify( "036d568125a969dc78b963b494fa7ed5f20ee9c2f2fc2c57f86c5df" "63089f2ed3a"), 3)
def __init__(self, network: str, privkey: bytearray=None, from_string: str=None, from_wif: str=None) -> None: ''' High level helper class for handling public key cryptography. : privkey - privatekey bytes : from_wif - <WIF> import private key from your wallet in WIF format : from_bytes - import private key in binary format : network - specify network [ppc, tppc, btc] : from_string - specify seed (string) to make the privkey from ''' self.network = network self.btcpy_constants = net_query(self.network).btcpy_constants if privkey is not None: self._private_key = PrivateKey(privkey) if from_string is not None: self._private_key = PrivateKey(sha256( from_string.encode()).digest()) if from_wif is not None: self._private_key = PrivateKey.from_wif(wif=from_wif, network=self.btcpy_constants, ) if not privkey: if from_string == from_wif is None: # generate a new privkey self._private_key = PrivateKey(bytearray(urandom(32))) self.privkey = str(self._private_key) self._public_key = PublicKey.from_priv(self._private_key) self.pubkey = str(self._public_key)
def test(self): for data in priv_pub_hash_addr_p2pkh_segwit: priv = PrivateKey.from_wif(data['privkey']) pub = PublicKey.unhexlify(data['pubkey']) pubhash = bytearray(unhexlify(data['pubkeyhash'])) address = Address.from_string(data['address'], check_network=False) p2pkhhex = data['scriptpubkey'] segwit_addr = data['segwit'] self.assertEqual(priv.pub(), pub) self.assertEqual(pub.hash(), pubhash) self.assertEqual(address.hash, pubhash) self.assertEqual(P2pkhScript(pub).hexlify(), p2pkhhex) self.assertEqual(P2pkhScript(address).hexlify(), p2pkhhex) self.assertEqual(P2pkhScript(pubhash).hexlify(), p2pkhhex) self.assertEqual(str(P2shScript(P2wpkhV0Script(pub)).address()), segwit_addr) self.assertEqual( str(P2shScript(P2wpkhV0Script(pubhash)).address()), segwit_addr) self.assertEqual( P2shScript(P2wpkhV0Script(pub)).scripthash, Address.from_string(segwit_addr).hash) self.assertEqual( P2shScript(P2wpkhV0Script(pubhash)).scripthash, Address.from_string(segwit_addr).hash)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.pubk = PublicKey.unhexlify( '0384478d41e71dc6c3f9edde0f928a47d1b724c05984ebfb4e7d0422e80abe95ff' ) self.pubkh = self.pubk.hash() self.address = Address.from_string( 'mquvJWnJJwTDUcdneQkUbrfN2wm9uiXd1p')
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.redeem_script = P2pkhScript( PublicKey.unhexlify('0384478d41e71dc6c3f9edde0f928a47d1b724c' '05984ebfb4e7d0422e80abe95ff')) self.as_data = StackData.from_bytes(self.redeem_script.p2sh_hash()) self.address = self.redeem_script.to_address()
def __init__(self, txo, mainnet): self.n = -1 self.value = -1 self.address = '' self.tx_idx = -1 self.isMainNet = mainnet if self.isMainNet == True: setup('mainnet') else: setup('testnet') if txo is not None: if 'vout' in txo: self.n = txo['vout'] elif 'n' in txo: self.n = txo['n'] if 'value_int' in txo: self.value = txo['value_int'] # Gets the address or the scriptpubkey (if an address isn't associated to the txo) if 'addresses' in txo: addresses = txo['addresses'] if len(addresses) > 0: self.address = addresses[0] elif 'type' in txo: if txo['type'] == 'witness_v0_keyhash': if 'script_pub_key' in txo: script_pub_key = txo['script_pub_key'] hex = script_pub_key['hex'] if self.isMainNet == True: self.address = boltzmann.utils.segwit_addr.encode( 'bc', 0, bytes.fromhex(hex[4:])) else: self.address = boltzmann.utils.segwit_addr.encode( 'tb', 0, bytes.fromhex(hex[4:])) elif 'witness' in txo: witness = txo['witness'] if len(witness) >= 1: pubkey_hex = witness[1] pubkey = PublicKey.unhexlify(pubkey_hex) segwit_address = P2wpkhAddress(pubkey.hash(), version=0) self.address = str(segwit_address) else: self.address = txo['type'] else: self.address = txo['type'] elif 'script_sig' in txo: script_sig = txo['script_sig'] self.address = script_sig['hex'] elif 'script_pub_key' in txo: script_pub_key = txo['script_pub_key'] self.address = script_pub_key['hex'] else: raise ValueError("Could not assign address to txo") self.tx_idx = None
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.m = 2 self.pubkeys = [ PublicKey.unhexlify( "02c08786d63f78bd0a6777ffe9c978cf5899756cfc32bfad09a89e211aeb926242" ), PublicKey.unhexlify( "033e81519ecf373ea3a5c7e1c051b71a898fb3438c9550e274d980f147eb4d069d" ), PublicKey.unhexlify( "036d568125a969dc78b963b494fa7ed5f20ee9c2f2fc2c57f86c5df63089f2ed3a" ) ] self.n = 3 self.hex_template = '{:02x}{}{:02x}ae'.format( self.m + 80, ''.join('{:02x}{}'.format(len(pk), pk) for pk in self.pubkeys), self.n + 80)
def public_key(self, private_key=None, compressed=COMPRESSED): """ Get Bitcoin wallet public key. :param private_key: Bitcoin private key, default is None. :type private_key: str :param compressed: Bitcoin public key compressed, default is True. :type compressed: bool :return: str -- Bitcoin public key. >>> from shuttle.providers.bitcoin.wallet import Wallet >>> wallet = Wallet(network="testnet") >>> wallet.from_passphrase("meherett", compressed=False) >>> wallet.public_key() "04afa8301b068c2c184e0a3e77183dc95ec1130371c02ed172bec8f3bfbad6b17334244f64fe877d5e4839690c62b9d1f4095608f2ac29235e4b0299b6b96f6f35" """ if private_key is None: return self._public_key.hexlify() public_key = self.bitcoin.privtopub(private_key) return PublicKey.unhexlify(public_key).compressed.hex() if compressed else \ PublicKey.unhexlify(public_key).uncompressed.hex()
def from_private_key(self, private_key, compressed=COMPRESSED): """ Initiate Bitcoin wallet from private key. :param private_key: Bitcoin wallet private key. :type private_key: str. :param compressed: Bitcoin public key compressed, default is True. :type compressed: bool :returns: Wallet -- Bitcoin wallet instance. >>> from shuttle.providers.bitcoin.wallet import Wallet >>> wallet = Wallet(network="mainnet") >>> wallet.from_private_key("92cbbc5990cb5090326a76feeb321cad01048635afe5756523bbf9f7a75bf38b") <shuttle.providers.bitcoin.wallet.Wallet object at 0x040DA268> """ self.is_compressed = compressed self._private_key = PrivateKey.unhexlify(private_key) public_key = self.bitcoin.privtopub(self._private_key.hexlify()) self._compressed = PublicKey.unhexlify(public_key).compressed.hex() self._uncompressed = PublicKey.unhexlify(public_key).uncompressed.hex() self._public_key = PublicKey.unhexlify(self._compressed) if self.is_compressed \ else PublicKey.unhexlify(self._uncompressed) self._address = self._public_key.to_address(mainnet=self.mainnet) return self
def from_passphrase(self, passphrase, compressed=COMPRESSED): """ Initiate Bitcoin wallet from passphrase. :param passphrase: Bitcoin wallet passphrase. :type passphrase: str. :param compressed: Bitcoin public key compressed, default is True. :type compressed: bool :returns: Wallet -- Bitcoin wallet instance. >>> from shuttle.providers.bitcoin.wallet import Wallet >>> wallet = Wallet(network="mainnet") >>> wallet.from_passphrase("meherett") """ self.is_compressed = compressed private_key = hashlib.sha256(passphrase.encode()).hexdigest() self._private_key = PrivateKey.unhexlify(private_key) public_key = self.bitcoin.privtopub(self._private_key.hexlify()) self._compressed = PublicKey.unhexlify(public_key).compressed.hex() self._uncompressed = PublicKey.unhexlify(public_key).uncompressed.hex() self._public_key = PublicKey.unhexlify(self._compressed) if self.is_compressed \ else PublicKey.unhexlify(self._uncompressed) self._address = self._public_key.to_address(mainnet=self.mainnet) return self
def test_p2wpkh_over_p2sh(self): for spend in p2wpkh_over_p2sh: pubkey = PublicKey.unhexlify(spend['pubkey']) self.assertEqual( str( P2shAddress.from_script(P2wpkhScript.get( spend['witness_version'])(pubkey), mainnet=True)), spend['address']) self.assertEqual( P2wpkhScript.get(spend['witness_version'])(pubkey).hexlify(), spend['redeem_script']) self.assertEqual( str( P2shScript( P2wpkhScript.get(spend['witness_version'])(pubkey))), spend['script_pubkey'])
def hash(self) -> str: """ Get Bitcoin wallet public key/address hash. :return: str -- Bitcoin wallet public key/address hash. >>> from swap.providers.bitcoin.wallet import Wallet >>> wallet = Wallet(network="testnet") >>> wallet.from_entropy("72fee73846f2d1a5807dc8c953bf79f1") >>> wallet.from_path("m/44'/0'/0'/0/0") >>> wallet.hash() "33ecab3d67f0e2bde43e52f41ec1ecbdc73f11f8" """ return PublicKey.unhexlify(self.public_key()).to_address( mainnet=True if self._network == "mainnet" else False).hash.hex()
def uncompressed(self, public_key=None): """ Get Bitcoin wallet uncompressed public key. :param public_key: Bitcoin public key, default is None. :type public_key: str :return: str -- Bitcoin uncompressed public key. >>> from shuttle.providers.bitcoin.wallet import Wallet >>> wallet = Wallet(network="testnet") >>> wallet.from_passphrase("meherett") >>> wallet.uncompressed() "04afa8301b068c2c184e0a3e77183dc95ec1130371c02ed172bec8f3bfbad6b17334244f64fe877d5e4839690c62b9d1f4095608f2ac29235e4b0299b6b96f6f35" """ if public_key is None: return self._uncompressed return PublicKey.unhexlify(public_key).uncompressed.hex()
def compressed(self, public_key=None): """ Get Bitcoin wallet compressed public key. :param public_key: Bitcoin public key, default is None. :type public_key: str :return: str -- Bitcoin compressed public key. >>> from shuttle.providers.bitcoin.wallet import Wallet >>> wallet = Wallet(network="testnet") >>> wallet.from_passphrase("meherett") >>> wallet.compressed() "03afa8301b068c2c184e0a3e77183dc95ec1130371c02ed172bec8f3bfbad6b173" """ if public_key is None: return self._compressed return PublicKey.unhexlify(public_key).compressed.hex()
def address(self, public_key=None): """ Get Bitcoin wallet address. :param public_key: Bitcoin address, default is None. :type public_key: str :return: str -- Bitcoin address. >>> from shuttle.providers.bitcoin.wallet import Wallet >>> wallet = Wallet(network="testnet") >>> wallet.from_passphrase("meherett") >>> wallet.address() "mm357rHaKqVmhEhFFwUhz6mRVAHkJaDTKt" """ if public_key is None: return str(self._address) return str( PublicKey.unhexlify(public_key).to_address(mainnet=self.mainnet))
def hash(self, public_key=None): """ Get Bitcoin wallet hash. :param public_key: Bitcoin hash, default is None. :type public_key: str :return: str -- Bitcoin hash. >>> from shuttle.providers.bitcoin.wallet import Wallet >>> wallet = Wallet(network="testnet") >>> wallet.from_passphrase("meherett") >>> wallet.hash() "3c8acde1c7cf370d970725f13eff03bf74b3fc61" """ if public_key is None: return self._address.hash.hex() return PublicKey.unhexlify(public_key)\ .to_address(mainnet=self.mainnet).hash.hex()
def __init__(self, pubk, privk=None, api_key=None): self.api_key = api_key if isinstance(pubk, str): self.pubk = PublicKey.unhexlify(pubk) elif isinstance(pubk, PublicKey): self.pubk = pubk else: raise ValueError('pubk should be str or PublicKey') if privk is None: self.privk = None elif isinstance(privk, str): self.privk = PrivateKey.unhexlify(privk) elif isinstance(privk, PrivateKey): self.privk = privk else: raise ValueError('privk should be str or PrivateKey') self.address = P2pkhAddress(self.pubk.hash())
def __init__(self, network: str, privkey: bytearray = None, from_string: str = None, from_wif: str = None) -> None: ''' High level helper class for handling public key cryptography. : privkey - privatekey bytes : from_wif - <WIF> import private key from your wallet in WIF format : from_bytes - import private key in binary format : network - specify network [ppc, tppc, btc] : from_string - specify seed (string) to make the privkey from ''' self.network = network try: if self.network.startswith('t') or self.network.endswith( '-testnet'): setup('testnet') else: setup('mainnet') except ValueError: pass if privkey is not None: self._private_key = PrivateKey(privkey) if from_string is not None: self._private_key = PrivateKey( sha256(from_string.encode()).digest()) if from_wif is not None: self._private_key = PrivateKey.from_wif(from_wif) if not privkey: if from_string == from_wif is None: # generate a new privkey self._private_key = PrivateKey(bytearray(urandom(32))) self.privkey = str(self._private_key) self._public_key = PublicKey.from_priv(self._private_key) self.pubkey = str(self._public_key)
def test_script_pubkey_fail(self): # nonstandard types self.assertFalse( eval(scripts['if_else_timelock']['code']).is_standard()) self.assertFalse( eval(scripts['relativetimelock']['code']).is_standard()) # n > 3 self.assertFalse( MultisigScript( 2, PublicKey.unhexlify( "02c08786d63f78bd0a6777ffe9c978cf5899756cfc32bfad09a89e211aeb926242" ), PublicKey.unhexlify( "033e81519ecf373ea3a5c7e1c051b71a898fb3438c9550e274d980f147eb4d069d" ), PublicKey.unhexlify( "036d568125a969dc78b963b494fa7ed5f20ee9c2f2fc2c57f86c5df63089f2ed3a" ), PublicKey.unhexlify( "036d568125a969dc78b963b494fa7ed5f20ee9c2f2fc2c57f86c5df63089f2ed3a" ), 4).is_standard()) # m > n self.assertFalse( MultisigScript( 4, PublicKey.unhexlify( "02c08786d63f78bd0a6777ffe9c978cf5899756cfc32bfad09a89e211aeb926242" ), PublicKey.unhexlify( "033e81519ecf373ea3a5c7e1c051b71a898fb3438c9550e274d980f147eb4d069d" ), PublicKey.unhexlify( "036d568125a969dc78b963b494fa7ed5f20ee9c2f2fc2c57f86c5df63089f2ed3a" ), 3).is_standard()) # >80-byte data self.assertFalse( NulldataScript( StackData.unhexlify( '444f4350524f4f463832bd18ceb0a7861f2a8198013047a3fb861261523c0fc4164abc044e517702444f4350524f4f463832bd18ce' 'b0a7861f2a8198013047a3fb861261523c0fc4164abc044e51770211') ).is_standard())
def seek(r): while True: ran = secrets.SystemRandom().randrange( 1, 115792089237316195423570985008687907852837564279074904382605163141518161494337 ) #Puzzle 1-20 #Use Examples key1 = Key.from_int(ran) wif = bytes_to_wif(key1.to_bytes(), compressed=False) #Uncompressed WIF wif2 = bytes_to_wif(key1.to_bytes(), compressed=True) #compressed WIF key2 = Key(wif) caddr = key1.address #Legacy compressed address uaddr = key2.address #Legacy uncompressed address saddr = key1.segwit_address #Segwit address pub1 = hexlify(key1.public_key).decode() pub2 = hexlify(key2.public_key).decode() pubk1 = PublicKey.unhexlify(pub1) pubk2 = PublicKey.unhexlify(pub2) bcaddr = P2wpkhAddress( pubk1.hash(), version=0, mainnet=True) #Segwit (bech32) compressed address buaddr = P2wpkhAddress( pubk2.hash(), version=0, mainnet=True) #Segwit (bech32) uncompressed address myhex = "%064x" % ran private_key = myhex[:64] private_key_bytes = bytes.fromhex(private_key) public_key_hex = keys.PrivateKey(private_key_bytes).public_key public_key_bytes = bytes.fromhex(str(public_key_hex)[2:]) eaddr = keys.PublicKey(public_key_bytes).to_address() #Eth address if caddr in add: print("Nice One Found!!!", ran, caddr, wif2, private_key) #Legacy compressed address s1 = str(ran) s2 = caddr s3 = wif2 s4 = private_key f = open(u"CompressedWinner.txt", "a") #Output File of Legacy compressed Wallet Found f.write(s1 + ":" + s2 + ":" + s3 + ":" + s4) f.write("\n") f.close() continue #break or continue if uaddr in add: print("Nice One Found!!!", ran, uaddr, wif, private_key) #Legacy uncompressed address s1 = str(ran) s2 = uaddr s3 = wif s4 = private_key f = open(u"UncompressedWinner.txt", "a") #Output File of Legacy uncompressed Wallet Found f.write(s1 + ":" + s2 + ":" + s3 + ":" + s4) f.write("\n") f.close() continue #break or continue if saddr in add: print("Nice One Found!!!", ran, saddr, wif, private_key) #Segwit address s1 = str(ran) s2 = saddr s3 = wif s4 = private_key f = open(u"Winner3.txt", "a") #Output File of Segwit Wallet Found f.write(s1 + ":" + s2 + ":" + s3 + ":" + s4) f.write("\n") f.close() continue #break or continue if str(bcaddr) in add: print("Nice One Found!!!", ran, str(bcaddr)) #Segwit (bech32) compressed address s1 = str(ran) s2 = str(bcaddr) s3 = wif s4 = private_key f = open( u"bech32CompressedWinner.txt", "a") #Output File of Segwit (bech32) compressed Wallet Found f.write(s1 + ":" + s2 + ":" + s3 + ":" + s4) f.write("\n") f.close() continue #break or continue if str(buaddr) in add: print("Nice One Found!!!", ran, str(buaddr)) #Segwit (bech32) uncompressed address s1 = str(ran) s2 = str(buaddr) s3 = wif s4 = private_key f = open( u"bechUncompressedWinner.txt", "a") #Output File of Segwit (bech32) uncompressed Wallet Found f.write(s1 + ":" + s2 + ":" + s3 + ":" + s4) f.write("\n") f.close() continue #break or continue if eaddr in add: print("Nice One Found!!!", ran, private_key, eaddr) #Eth address s1 = str(ran) s2 = eaddr s3 = wif s4 = private_key f = open(u"EthWinner.txt", "a") #Output File of Eth Wallet Found f.write(s1 + ":" + s2 + ":" + s3 + ":" + s4) f.write("\n") f.close() continue #break or continue else: colour_cyan = '\033[36m' colour_reset = '\033[0;0;39m' colour_red = '\033[31m' print("\n " + colour_cyan + "ProjectR---" + colour_red + "---Good--Luck--Happy--Hunting--Mizogg.co.uk&Chad---" + colour_cyan + "---ProjectR" + colour_reset) # Running Display Output print(myhex) print(caddr) print(uaddr) print(saddr) print(bcaddr) print(buaddr) print(eaddr) print("\n ") print(colour_cyan + seconds_to_str())
def seek(r): while True: c1 = str(random.choice("01")) c2 = str(random.choice("01")) c3 = str(random.choice("01")) c4 = str(random.choice("01")) c5 = str(random.choice("01")) c6 = str(random.choice("01")) c7 = str(random.choice("01")) c8 = str(random.choice("01")) c9 = str(random.choice("01")) c10 = str(random.choice("01")) c11 = str(random.choice("01")) c12 = str(random.choice("01")) c13 = str(random.choice("01")) c14 = str(random.choice("01")) c15 = str(random.choice("01")) c16 = str(random.choice("01")) c17 = str(random.choice("01")) c18 = str(random.choice("01")) c19 = str(random.choice("01")) c20 = str(random.choice("01")) c21 = str(random.choice("01")) c22 = str(random.choice("01")) c23 = str(random.choice("01")) c24 = str(random.choice("01")) c25 = str(random.choice("01")) c26 = str(random.choice("01")) c27 = str(random.choice("01")) c28 = str(random.choice("01")) c29 = str(random.choice("01")) c30 = str(random.choice("01")) c31 = str(random.choice("01")) c32 = str(random.choice("01")) c33 = str(random.choice("01")) c34 = str(random.choice("01")) c35 = str(random.choice("01")) c36 = str(random.choice("01")) c37 = str(random.choice("01")) c38 = str(random.choice("01")) c39 = str(random.choice("01")) c40 = str(random.choice("01")) c41 = str(random.choice("01")) c42 = str(random.choice("01")) c43 = str(random.choice("01")) c44 = str(random.choice("01")) c45 = str(random.choice("01")) c46 = str(random.choice("01")) c47 = str(random.choice("01")) c48 = str(random.choice("01")) c49 = str(random.choice("01")) c50 = str(random.choice("01")) c51 = str(random.choice("01")) c52 = str(random.choice("01")) c53 = str(random.choice("01")) c54 = str(random.choice("01")) c55 = str(random.choice("01")) c56 = str(random.choice("01")) c57 = str(random.choice("01")) c58 = str(random.choice("01")) c59 = str(random.choice("01")) c60 = str(random.choice("01")) c61 = str(random.choice("01")) c62 = str(random.choice("01")) c63 = str(random.choice("01")) c64 = str(random.choice("01")) c65 = str(random.choice("01")) c66 = str(random.choice("01")) c67 = str(random.choice("01")) c68 = str(random.choice("01")) c69 = str(random.choice("01")) c70 = str(random.choice("01")) c71 = str(random.choice("01")) c72 = str(random.choice("01")) c73 = str(random.choice("01")) c74 = str(random.choice("01")) c75 = str(random.choice("01")) c76 = str(random.choice("01")) c77 = str(random.choice("01")) c78 = str(random.choice("01")) c79 = str(random.choice("01")) c80 = str(random.choice("01")) c81 = str(random.choice("01")) c82 = str(random.choice("01")) c83 = str(random.choice("01")) c84 = str(random.choice("01")) c85 = str(random.choice("01")) c86 = str(random.choice("01")) c87 = str(random.choice("01")) c88 = str(random.choice("01")) c89 = str(random.choice("01")) c90 = str(random.choice("01")) c91 = str(random.choice("01")) c92 = str(random.choice("01")) c93 = str(random.choice("01")) c94 = str(random.choice("01")) c95 = str(random.choice("01")) c96 = str(random.choice("01")) c97 = str(random.choice("01")) c98 = str(random.choice("01")) c99 = str(random.choice("01")) c100 = str(random.choice("01")) c101 = str(random.choice("01")) c102 = str(random.choice("01")) c103 = str(random.choice("01")) c104 = str(random.choice("01")) c105 = str(random.choice("01")) c106 = str(random.choice("01")) c107 = str(random.choice("01")) c108 = str(random.choice("01")) c109 = str(random.choice("01")) c110 = str(random.choice("01")) c111 = str(random.choice("01")) c112 = str(random.choice("01")) c113 = str(random.choice("01")) c114 = str(random.choice("01")) c115 = str(random.choice("01")) c116 = str(random.choice("01")) c117 = str(random.choice("01")) c118 = str(random.choice("01")) c119 = str(random.choice("01")) c120 = str(random.choice("01")) c121 = str(random.choice("01")) c122 = str(random.choice("01")) c123 = str(random.choice("01")) c124 = str(random.choice("01")) c125 = str(random.choice("01")) c126 = str(random.choice("01")) c127 = str(random.choice("01")) c128 = str(random.choice("01")) c129 = str(random.choice("01")) c130 = str(random.choice("01")) c131 = str(random.choice("01")) c132 = str(random.choice("01")) c133 = str(random.choice("01")) c134 = str(random.choice("01")) c135 = str(random.choice("01")) c136 = str(random.choice("01")) c137 = str(random.choice("01")) c138 = str(random.choice("01")) c139 = str(random.choice("01")) c140 = str(random.choice("01")) c141 = str(random.choice("01")) c142 = str(random.choice("01")) c143 = str(random.choice("01")) c144 = str(random.choice("01")) c145 = str(random.choice("01")) c146 = str(random.choice("01")) c147 = str(random.choice("01")) c148 = str(random.choice("01")) c149 = str(random.choice("01")) c150 = str(random.choice("01")) c151 = str(random.choice("01")) c152 = str(random.choice("01")) c153 = str(random.choice("01")) c154 = str(random.choice("01")) c155 = str(random.choice("01")) c156 = str(random.choice("01")) c157 = str(random.choice("01")) c158 = str(random.choice("01")) c159 = str(random.choice("01")) c160 = str(random.choice("01")) c161 = str(random.choice("01")) c162 = str(random.choice("01")) c163 = str(random.choice("01")) c164 = str(random.choice("01")) c165 = str(random.choice("01")) c166 = str(random.choice("01")) c167 = str(random.choice("01")) c168 = str(random.choice("01")) c169 = str(random.choice("01")) c170 = str(random.choice("01")) c171 = str(random.choice("01")) c172 = str(random.choice("01")) c173 = str(random.choice("01")) c174 = str(random.choice("01")) c175 = str(random.choice("01")) c176 = str(random.choice("01")) c177 = str(random.choice("01")) c178 = str(random.choice("01")) c179 = str(random.choice("01")) c180 = str(random.choice("01")) c181 = str(random.choice("01")) c182 = str(random.choice("01")) c183 = str(random.choice("01")) c184 = str(random.choice("01")) c185 = str(random.choice("01")) c186 = str(random.choice("01")) c187 = str(random.choice("01")) c188 = str(random.choice("01")) c189 = str(random.choice("01")) c190 = str(random.choice("01")) c191 = str(random.choice("01")) c192 = str(random.choice("01")) c193 = str(random.choice("01")) c194 = str(random.choice("01")) c195 = str(random.choice("01")) c196 = str(random.choice("01")) c197 = str(random.choice("01")) c198 = str(random.choice("01")) c199 = str(random.choice("01")) c200 = str(random.choice("01")) c201 = str(random.choice("01")) c202 = str(random.choice("01")) c203 = str(random.choice("01")) c204 = str(random.choice("01")) c205 = str(random.choice("01")) c206 = str(random.choice("01")) c207 = str(random.choice("01")) c208 = str(random.choice("01")) c209 = str(random.choice("01")) c210 = str(random.choice("01")) c211 = str(random.choice("01")) c212 = str(random.choice("01")) c213 = str(random.choice("01")) c214 = str(random.choice("01")) c215 = str(random.choice("01")) c216 = str(random.choice("01")) c217 = str(random.choice("01")) c218 = str(random.choice("01")) c219 = str(random.choice("01")) c220 = str(random.choice("01")) c221 = str(random.choice("01")) c222 = str(random.choice("01")) c223 = str(random.choice("01")) c224 = str(random.choice("01")) c225 = str(random.choice("01")) c226 = str(random.choice("01")) c227 = str(random.choice("01")) c228 = str(random.choice("01")) c229 = str(random.choice("01")) c230 = str(random.choice("01")) c231 = str(random.choice("01")) c232 = str(random.choice("01")) c233 = str(random.choice("01")) c234 = str(random.choice("01")) c235 = str(random.choice("01")) c236 = str(random.choice("01")) c237 = str(random.choice("01")) c238 = str(random.choice("01")) c239 = str(random.choice("01")) c240 = str(random.choice("01")) c241 = str(random.choice("01")) c242 = str(random.choice("01")) c243 = str(random.choice("01")) c244 = str(random.choice("01")) c245 = str(random.choice("01")) c246 = str(random.choice("01")) c247 = str(random.choice("01")) c248 = str(random.choice("01")) c249 = str(random.choice("01")) c250 = str(random.choice("01")) c251 = str(random.choice("01")) c252 = str(random.choice("01")) c253 = str(random.choice("01")) c254 = str(random.choice("01")) c255 = str(random.choice("01")) c256 = str(random.choice("01")) magic = (c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9 + c10 + c11 + c12 + c13 + c14 + c15 + c16 + c17 + c18 + c19 + c20 + c21 + c22 + c23 + c24 + c25 + c26 + c27 + c28 + c29 + c30 + c31 + c32 + c33 + c34 + c35 + c36 + c37 + c38 + c39 + c40 + c41 + c42 + c43 + c44 + c45 + c46 + c47 + c48 + c49 + c50 + c51 + c52 + c53 + c54 + c55 + c56 + c57 + c58 + c59 + c60 + c61 + c62 + c63 + c64 + c65 + c66 + c67 + c68 + c69 + c70 + c71 + c72 + c73 + c74 + c75 + c76 + c77 + c78 + c79 + c80 + c81 + c82 + c83 + c84 + c85 + c86 + c87 + c88 + c89 + c90 + c91 + c92 + c93 + c94 + c95 + c96 + c97 + c98 + c99 + c100 + c101 + c102 + c103 + c104 + c105 + c106 + c107 + c108 + c109 + c110 + c111 + c112 + c113 + c114 + c115 + c116 + c117 + c118 + c119 + c120 + c121 + c122 + c123 + c124 + c125 + c126 + c127 + c128 + c129 + c130 + c131 + c132 + c133 + c134 + c135 + c136 + c137 + c138 + c139 + c140 + c141 + c142 + c143 + c144 + c145 + c146 + c147 + c148 + c149 + c150 + c151 + c152 + c153 + c154 + c155 + c156 + c157 + c158 + c159 + c160 + c161 + c162 + c163 + c164 + c165 + c166 + c167 + c168 + c169 + c170 + c171 + c172 + c173 + c174 + c175 + c176 + c177 + c178 + c179 + c180 + c181 + c182 + c183 + c184 + c185 + c186 + c187 + c188 + c189 + c190 + c191 + c192 + c193 + c194 + c195 + c196 + c197 + c198 + c199 + c200 + c201 + c202 + c203 + c204 + c205 + c206 + c207 + c208 + c209 + c210 + c211 + c212 + c213 + c214 + c215 + c216 + c217 + c218 + c219 + c220 + c221 + c222 + c223 + c224 + c225 + c226 + c227 + c228 + c229 + c230 + c231 + c232 + c233 + c234 + c235 + c236 + c237 + c238 + c239 + c240 + c241 + c242 + c243 + c244 + c245 + c246 + c247 + c248 + c249 + c250 + c251 + c252 + c253 + c254 + c255 + c256) dec = int(magic, 2) key1 = Key.from_int(dec) wif = bytes_to_wif(key1.to_bytes(), compressed=False) #Uncompressed WIF wif2 = bytes_to_wif(key1.to_bytes(), compressed=True) #compressed WIF key2 = Key(wif) caddr = key1.address #Legacy compressed address uaddr = key2.address #Legacy uncompressed address saddr = key1.segwit_address pub1 = hexlify(key1.public_key).decode() pub2 = hexlify(key2.public_key).decode() pubk1 = PublicKey.unhexlify(pub1) pubk2 = PublicKey.unhexlify(pub2) bcaddr = P2wpkhAddress( pubk1.hash(), version=0, mainnet=True) #Segwit (bech32) compressed address buaddr = P2wpkhAddress( pubk2.hash(), version=0, mainnet=True) #Segwit (bech32) uncompressed address myhex = "%064x" % dec private_key = myhex[:64] private_key_bytes = bytes.fromhex(private_key) public_key_hex = keys.PrivateKey(private_key_bytes).public_key public_key_bytes = bytes.fromhex(str(public_key_hex)[2:]) eaddr = keys.PublicKey(public_key_bytes).to_address() #Eth address if caddr in add: print("Nice One Found!!!", dec, caddr, wif2, private_key) #Legacy compressed address s1 = str(dec) s2 = caddr s3 = wif2 s4 = private_key f = open(u"CompressedWinner.txt", "a") #Output File of Legacy compressed Wallet Found f.write(s1 + ":" + s2 + ":" + s3 + ":" + s4) f.write("\n") f.close() break #break or continue if uaddr in add: print("Nice One Found!!!", dec, uaddr, wif, private_key) #Legacy uncompressed address s1 = str(dec) s2 = uaddr s3 = wif s4 = private_key f = open(u"UncompressedWinner.txt", "a") #Output File of Legacy uncompressed Wallet Found f.write(s1 + ":" + s2 + ":" + s3 + ":" + s4) f.write("\n") f.close() break #break or continue if saddr in add: print("Nice One Found!!!", dec, saddr, wif, private_key) #Segwit address s1 = str(dec) s2 = saddr s3 = wif s4 = private_key f = open(u"Winner3.txt", "a") #Output File of Segwit Wallet Found f.write(s1 + ":" + s2 + ":" + s3 + ":" + s4) f.write("\n") f.close() break #break or continue if str(bcaddr) in add: print("Nice One Found!!!", dec, str(bcaddr)) #Segwit (bech32) compressed address s1 = str(dec) s2 = str(bcaddr) s3 = wif s4 = private_key f = open( u"bech32CompressedWinner.txt", "a") #Output File of Segwit (bech32) compressed Wallet Found f.write(s1 + ":" + s2 + ":" + s3 + ":" + s4) f.write("\n") f.close() break #break or continue if str(buaddr) in add: print("Nice One Found!!!", dec, str(buaddr)) #Segwit (bech32) uncompressed address s1 = str(dec) s2 = str(buaddr) s3 = wif s4 = private_key f = open( u"bechUncompressedWinner.txt", "a") #Output File of Segwit (bech32) uncompressed Wallet Found f.write(s1 + ":" + s2 + ":" + s3 + ":" + s4) f.write("\n") f.close() break #break or continue if eaddr in add: print("Nice One Found!!!", dec, private_key, eaddr) #Eth address s1 = str(dec) s2 = eaddr s3 = wif s4 = private_key f = open(u"EthWinner.txt", "a") #Output File of Eth Wallet Found f.write(s1 + ":" + s2 + ":" + s3 + ":" + s4) f.write("\n") f.close() break #break or continue else: colour_cyan = '\033[36m' colour_reset = '\033[0;0;39m' colour_red = '\033[31m' print("\n " + colour_cyan + "ProjectHex---" + colour_red + "---Good--Luck--Happy--Hunting--Mizogg.co.uk&Chad---" + colour_cyan + "---ProjectHex" + colour_reset) # Running Display Output print(myhex) print(caddr) print(uaddr) print(saddr) print(bcaddr) print(buaddr) print(eaddr) print(colour_cyan + seconds_to_str())
def __init__(self, *args, **kwargs): global keys super().__init__(*args, **kwargs) pubs = [PublicKey.from_bip32(pair[0]) for pair in keys] privs = [PrivateKey.from_bip32(pair[1]) for pair in keys] all_embedders = { 'p2sh', 'p2wsh', 'ifelse', 'absolutetime', 'relativetime', 'hash160', 'hash256' } self.scripts = [ { 'name': 'p2pkh', 'script': P2pkhScript(pubs[0]), 'solver': partial(P2pkhSolver, privs[0]), 'embeddable_by': all_embedders }, { 'name': 'p2wpkh', 'script': P2wpkhV0Script(pubs[1]), 'solver': partial(P2wpkhV0Solver, privs[1]), 'embeddable_by': {'p2sh'} }, { 'name': 'p2pk', 'script': P2pkScript(pubs[2]), 'solver': partial(P2pkSolver, privs[2]), 'embeddable_by': all_embedders }, { 'name': 'multisig', 'script': MultisigScript(2, pubs[3], pubs[4], pubs[5], 3), 'solver': partial(MultisigSolver, privs[3], privs[4]), 'embeddable_by': all_embedders }, ] self.sighashed_scripts = [] for script in self.scripts: for args in (('ALL', False), ('ALL', True), ('NONE', False), ('NONE', True), ('SINGLE', False), ('SINGLE', True)): scriptcpy = copy.deepcopy(script) scriptcpy['sighash'] = Sighash(*args) try: scriptcpy['solver'] = scriptcpy['solver'](sighash=Sighash( *args)) except TypeError: scriptcpy['solver'] = scriptcpy['solver']( sighashes=[Sighash( *args), Sighash(*args)]) self.sighashed_scripts.append(scriptcpy) self.scripts = self.sighashed_scripts self.scripts = self.sighashed_scripts self.final = { 'name': 'nulldata', 'script': NulldataScript(StackData.unhexlify('deadbeef')), 'solver': None, 'embeddable_by': {} } self.preimage_streams = [ Stream(TestSpends.rand_bytes()), Stream(TestSpends.rand_bytes()), Stream(TestSpends.rand_bytes()), # Stream(TestSpends.rand_bytes()), # Stream(TestSpends.rand_bytes()), Stream(TestSpends.rand_bytes()) ] self.preimages = [pre.serialize() for pre in self.preimage_streams] self.hashes160 = [ preimage.hash160() for preimage in self.preimage_streams ] self.hashes256 = [ preimage.hash() for preimage in self.preimage_streams ] # self.embedders = [{'name': 'p2sh', # 'wrapper': P2shScript}, # {'name': 'p2wsh', # 'wrapper': P2wshV0Script}, # {'name': 'ifelse', # 'wrapper': IfElseScript}, # {'name': 'time', # 'wrapper': TimelockScript, # 'data': {'time': Locktime(100)}}, # {'name': 'relativetime', # 'wrapper': RelativeTimelockScript, # 'data': {'time': Sequence(10)}}, # {'name': 'hash256', # 'wrapper': Hashlock256Script}, # {'name': 'hash160', # 'wrapper': Hashlock160Script}] self.all = [(s['script'], (s['solver'], s['script']), s['name']) for s in self.scripts] self.embedders = [ TimelockEmbedder, Relativetimelockembedder, Hashlock160Embedder, Hashlock256Embedder ] self.double_embedders = [IfElseEmbedder] embedded = [] for embedder in self.embedders: if embedder.get_name() != 'ifelse': for script in self.scripts: if embedder.get_name() in script['embeddable_by']: if embedder.get_name() == 'hash160': for preimage, phash in zip(self.preimages, self.hashes160): emb = embedder(phash, scripts=[script['script']]) embedded.append( (emb.instance, (HashlockSolver( preimage, script['solver']), emb.instance), '{}({})'.format(embedder.get_name(), script['name']))) elif embedder.get_name() == 'hash256': for preimage, phash in zip(self.preimages, self.hashes256): emb = embedder(phash, scripts=[script['script']]) embedded.append( (emb.instance, (HashlockSolver( preimage, script['solver']), emb.instance), '{}({})'.format(embedder.get_name(), script['name']))) else: emb = embedder(scripts=[script['script']]) embedded.append( (emb.instance, (TimelockSolver(script['solver']), emb.instance), '{}({})'.format(embedder.get_name(), script['name']))) self.all += [s for s in embedded] # print(self.all) # print(TestSpends.pairwise(self.all)[0]) for embedder in self.double_embedders: included = [(x, y, t) for (x, y, t) in self.all if t != 'p2wpkh'] for ((if_script, (if_solver, _), if_type), (else_script, (else_solver, _), else_type)) in TestSpends.pairwise(included): for branch in [Branch.IF, Branch.ELSE]: inst = embedder(scripts=[if_script, else_script]).instance # print(type(if_script), type(if_keys), type(if_spend), type(if_type)) # if 'hash' in else_type: # print(else_spend) self.all.append( (inst, (IfElseSolver( branch, if_solver if branch == Branch.IF else else_solver), inst), 'ifelse({}, {})'.format(if_type, else_type))) for script, (solver, _), stype in [s for s in self.all]: if 'p2wpkh' not in stype: inst = P2wshEmbedder(scripts=[script]).instance self.all.append((inst, (P2wshV0Solver(script, solver), script), 'p2wsh({})'.format(stype))) for script, (solver, prev), stype in [s for s in self.all]: inst = P2shEmbedder(scripts=[script]).instance self.all.append( (inst, (P2shSolver(script, solver), prev), 'p2sh({})'.format(stype)))
def get_hexPubkey(decPubkey): pubk = PublicKey( bytearray([0x04]) + decPubkey.get_x().to_bytes(32, 'big') + decPubkey.get_y().to_bytes(32, 'big')) pubk = pubk.compress() return pubk
from btcpy.structs.script import Hashlock256Script from btcpy.structs.sig import * from btcpy.structs.transaction import TransactionFactory, HeightBasedSequence, TimeBasedSequence from btcpy.structs.transaction import TxIn, Sequence, TxOut, Locktime, MutableTransaction from utils import * import hashlib import datetime # global setup('testnet', strict=True) coin_symbol = 'btc-testnet' api_key = 'fe4a832ab7d14936b5731aa79cfa58ae' # committer pubk_hex = '0380557a219119218f7830bf3cdb2bb3c8220cac15db97e255498fb992e68c04a9' pubk = PublicKey.unhexlify(pubk_hex) address = P2pkhAddress(pubk.hash()) privk_hex = '385acd25450e50ecd5ad0fffec7b871c8f75eb3ba9ecded8d35a0765f4763d7e' privk = PrivateKey.unhexlify(privk_hex) # recipient pubk_hex2 = '03fb2cd4d0b5248c5f62296e55ce59eab79d68b90fc1d9865bafbcaa556e1c766c' pubk2 = PublicKey.unhexlify(pubk_hex2) # a sample of secret secret = 'I have an apple'.encode() secret_hash = hashlib.sha256(hashlib.sha256(secret).digest()).digest() secret_hash = StackData.from_bytes(secret_hash) print("秘密经hash256加密结果:", secret_hash)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.pubk = PublicKey.unhexlify( '0384478d41e71dc6c3f9edde0f928a47d1b724c05984ebfb4e7d0422e80abe95ff' ) self.pubkh = self.pubk.hash()
def test_uncompression(self): pubk = PublicKey.unhexlify(self.compressed) self.assertTrue( hexlify(pubk.uncompressed).decode() == self.uncompressed)
def test_success(self): script = P2pkScript(PublicKey.unhexlify(self.pubk)) self.assertTrue( script.decompile() == '{} OP_CHECKSIG'.format(self.pubk)) self.assertTrue(script.hexlify() == '21{}ac'.format(self.pubk))
def test_address_generation(self): pubk = PublicKey.unhexlify(self.uncompressed) self.assertTrue(str(pubk.to_address(True)) == self.address)