Exemple #1
0
    def test_bech32_decode(self):
        private, public = generate_keypair()

        witprog = hash160(public.encode(compressed=True))
        address = bech32.encode(self.hrp, self.witver, witprog)
        wv, decoded = bech32.decode(self.hrp, address)
        self.assertEqual(wv, self.witver)
        self.assertEqual(bytes(decoded), bytes(witprog))
Exemple #2
0
 def test_p2wpkh(self):
     """https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#examples"""
     pubkey = PublicKey.from_hex(
         '0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798'
     )
     self.assertEqual(
         bech32.encode(self.hrp, self.witver,
                       hash160(pubkey.encode(compressed=True))),
         'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4')
     address = pubkey_to_address(pubkey, version='P2WPKH')
     self.assertEqual(address, 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4')
     self.assertEqual(address_type(address), ADDRESS.P2WPKH)
Exemple #3
0
    def test_p2sh(self):
        script = secrets.token_bytes(32)
        scripthash = hash160(script)

        payload = {'RIPEMDWithHash': '05' + bytes_to_hex(scripthash)}
        data = urllib.parse.urlencode(payload).encode('ascii')
        req = urllib.request.Request(self.url, data)

        with urllib.request.urlopen(req) as response:
            html = response.read()

        tree = etree.HTML(html)
        address = tree.find('.//input[@name="Base58"]').attrib['value']

        self.assertEqual(script_to_address(script, 'P2SH'), address)
        self.assertEqual(address_type(address), ADDRESS.P2SH)