Beispiel #1
0
def main():
    priv = key.generate_priv()
    priv_enc = key.encode_privkey(priv)
    priv_cmp_enc = key.encode_privkey_compressed(priv)
    pub = key.priv_to_pub(priv)
    addr = byte_util.base58_encode(key.pub_to_address(pub))
    addr_comp = byte_util.base58_encode(key.pub_to_address_compressed(pub))
    print 'Address: %s\nPrivate Key Encoded: %s\nAddress (compressed): %s\nPrivate Key Encoded (compressed): %s' % (addr, priv_enc, addr_comp, priv_cmp_enc)
Beispiel #2
0
def main():
    priv = key.generate_priv()
    priv_enc = key.encode_privkey(priv)
    priv_cmp_enc = key.encode_privkey_compressed(priv)
    pub = key.priv_to_pub(priv)
    addr = byte_util.base58_encode(key.pub_to_address(pub))
    addr_comp = byte_util.base58_encode(key.pub_to_address_compressed(pub))
    print 'Address: %s\nPrivate Key Encoded: %s\nAddress (compressed): %s\nPrivate Key Encoded (compressed): %s' % (
        addr, priv_enc, addr_comp, priv_cmp_enc)
Beispiel #3
0
 def test_priv_addition_is_pub_addition(self):
     # adding private keys gives the same address as adding their public keys
     key1 = key.generate_priv()
     key2 = key.generate_priv()
     self.assertEquals(
         byte_util.base58_encode(key.priv_to_address(key1 + key2)),
         byte_util.base58_encode(
             key.address_from_pubkey(
                 key.encode_pub(key.priv_to_pub(key1) + key.priv_to_pub(key2)))))
Beispiel #4
0
 def test_priv_addition_is_pub_addition(self):
     # adding private keys gives the same address as adding their public keys
     key1 = key.generate_priv()
     key2 = key.generate_priv()
     self.assertEquals(
         byte_util.base58_encode(key.priv_to_address(key1 + key2)),
         byte_util.base58_encode(
             key.address_from_pubkey(
                 key.encode_pub(
                     key.priv_to_pub(key1) + key.priv_to_pub(key2)))))
Beispiel #5
0
 def test_priv_key_to_address_compressed(self):
     self.assertEquals(
         byte_util.base58_encode(
             key.address_from_pubkey(
                 key.encode_pub_compressed(
                     key.priv_to_pub(
                         key.decode_privkey(
                             '5JnKZDMUAddiGgFjWiHNVrX5pxGcEJ1miscs2Xhy7f9BrGffrps'))))),
         '19ufHMz2mhGHhSSQEmqBsqZUTMHB79urP9')
     self.assertEquals(
         byte_util.base58_encode(
             key.priv_to_address_compressed(
                 key.decode_privkey('5JnKZDMUAddiGgFjWiHNVrX5pxGcEJ1miscs2Xhy7f9BrGffrps'))),
         '19ufHMz2mhGHhSSQEmqBsqZUTMHB79urP9')
Beispiel #6
0
 def test_priv_key_to_address(self):
     self.assertEquals(
         byte_util.base58_encode(
             key.address_from_pubkey(
                 key.encode_pub(
                     key.priv_to_pub(
                         key.decode_privkey(
                             '5JnKZDMUAddiGgFjWiHNVrX5pxGcEJ1miscs2Xhy7f9BrGffrps'))))),
         '1EEaiQ4DXxf8seerjdNR69by8pwZeBJ6mJ')
     self.assertEquals(
         byte_util.base58_encode(
             key.priv_to_address(
                 key.decode_privkey('5JnKZDMUAddiGgFjWiHNVrX5pxGcEJ1miscs2Xhy7f9BrGffrps'))),
         '1EEaiQ4DXxf8seerjdNR69by8pwZeBJ6mJ')
Beispiel #7
0
 def test_priv_key_to_address(self):
     self.assertEquals(
         byte_util.base58_encode(
             key.address_from_pubkey(
                 key.encode_pub(
                     key.priv_to_pub(
                         key.decode_privkey(
                             '5JnKZDMUAddiGgFjWiHNVrX5pxGcEJ1miscs2Xhy7f9BrGffrps'
                         ))))), '1EEaiQ4DXxf8seerjdNR69by8pwZeBJ6mJ')
     self.assertEquals(
         byte_util.base58_encode(
             key.priv_to_address(
                 key.decode_privkey(
                     '5JnKZDMUAddiGgFjWiHNVrX5pxGcEJ1miscs2Xhy7f9BrGffrps'))
         ), '1EEaiQ4DXxf8seerjdNR69by8pwZeBJ6mJ')
Beispiel #8
0
 def test_priv_key_to_address_compressed(self):
     self.assertEquals(
         byte_util.base58_encode(
             key.address_from_pubkey(
                 key.encode_pub_compressed(
                     key.priv_to_pub(
                         key.decode_privkey(
                             '5JnKZDMUAddiGgFjWiHNVrX5pxGcEJ1miscs2Xhy7f9BrGffrps'
                         ))))), '19ufHMz2mhGHhSSQEmqBsqZUTMHB79urP9')
     self.assertEquals(
         byte_util.base58_encode(
             key.priv_to_address_compressed(
                 key.decode_privkey(
                     '5JnKZDMUAddiGgFjWiHNVrX5pxGcEJ1miscs2Xhy7f9BrGffrps'))
         ), '19ufHMz2mhGHhSSQEmqBsqZUTMHB79urP9')
Beispiel #9
0
def mine(g_num, work):
    num = 0
    while True:
        try:
            priv = key.generate_priv()
            pub = key.priv_to_pub(priv)
            addr = byte_util.base58_encode(key.pub_to_address(pub))
            addr_comp = byte_util.base58_encode(
                key.pub_to_address_compressed(pub))
            num += 1
            if num % INC == 0:
                with g_num.get_lock():
                    g_num.value += INC
                # if g_num.value > 10000:
                #     return
            if any(VANITY_RE.match(a) for a in [addr, addr_comp]):
                try:
                    priv_enc = key.encode_privkey(priv)
                except Exception, e:
                    priv_enc = repr(e)
                try:
                    priv_cmp_enc = key.encode_privkey_compressed(priv)
                except Exception, e:
                    priv_cmp_enc = repr(e)
                msg = '\nI found one!\nAddress: %s\nAddress (compressed): %s\nPrivate Key (raw): %r\nPrivate Key Encoded: %s\nPrivate Key Encoded (compressed): %s\n' % (
                    addr, addr_comp, priv, priv_enc, priv_cmp_enc)
                print msg[:-1]
                with open('found_keys', 'a') as found_keys:
                    found_keys.write(msg)

            for rec in work:
                pub_sum = pub + rec['public_key']
                addr = byte_util.base58_encode(key.pub_to_address(pub_sum))
                addr_comp = byte_util.base58_encode(
                    key.pub_to_address_compressed(pub_sum))
                if not any(
                        a.startswith(rec['pattern'])
                        for a in [addr, addr_comp]):
                    continue

                try:
                    priv_hex = hex(priv)[2:].rstrip('L').upper()
                except Exception, e:
                    priv_hex = repr(e)
                try:
                    priv_enc = key.encode_privkey(priv)
                except Exception, e:
                    priv_enc = repr(e)
Beispiel #10
0
    def test_pks(self):
        script = '\x42' * 5
        pks = protocol.PubKeyScript(script)
        self.assertEquals(pks.bytes, script)
        self.assertEquals(repr(pks), binascii.hexlify(script))
        self.assertFalse(pks.is_standard_transaction)

        addr = '\x42' * 20
        script = '\x76\xa9\x14' + addr + '\x88\xac'
        pks = protocol.PubKeyScript(script)
        self.assertEquals(pks.bytes, script)
        self.assertEquals(
            repr(pks),
            'To Addr: ' + byte_util.base58_encode(key.address_from_pk_hash(addr)))
        self.assertTrue(pks.is_standard_transaction)

        self.assertEquals(pks, pks)
Beispiel #11
0
 def test_base58_encode_zero(self):
     self.assertEquals(byte_util.base58_encode('\x00'), '1')
Beispiel #12
0
 def test_decode_privkey_bad_version(self):
     priv_enc = '5JnKZDMUAddiGgFjWiHNVrX5pxGcEJ1miscs2Xhy7f9BrGffrps'
     priv = '\x08' + byte_util.base58_decode(priv_enc)[1:]
     with self.assertRaises(key.Error):
         key.decode_privkey(byte_util.base58_encode(priv))
Beispiel #13
0
 def test_decode_privkey_checksum_mismatch(self):
     priv_enc = '5JnKZDMUAddiGgFjWiHNVrX5pxGcEJ1miscs2Xhy7f9BrGffrps'
     priv = byte_util.base58_decode(priv_enc)[:-1] + '\x42'
     with self.assertRaises(key.Error):
         key.decode_privkey(byte_util.base58_encode(priv))
Beispiel #14
0
 def test_base58_encode_address(self):
     self.assertEquals(
         byte_util.base58_encode(
             key.address_from_pk_hash(
                 '\xe9\x9f\xaa\x1b\x12\x8f\x13w\x8d"#\xa9\xd1\xd3~\x88\x92\x0b]B')),
         '1NJHiNy5CS2heskf6bx3VuHm9zjXTGdtSt')
Beispiel #15
0
 def test_base58_encode_address(self):
     self.assertEquals(
         byte_util.base58_encode(
             key.address_from_pk_hash(
                 '\xe9\x9f\xaa\x1b\x12\x8f\x13w\x8d"#\xa9\xd1\xd3~\x88\x92\x0b]B'
             )), '1NJHiNy5CS2heskf6bx3VuHm9zjXTGdtSt')
Beispiel #16
0
 def test_decode_privkey_checksum_mismatch(self):
     priv_enc = '5JnKZDMUAddiGgFjWiHNVrX5pxGcEJ1miscs2Xhy7f9BrGffrps'
     priv = byte_util.base58_decode(priv_enc)[:-1] + '\x42'
     with self.assertRaises(key.Error):
         key.decode_privkey(byte_util.base58_encode(priv))
Beispiel #17
0
 def to_address(self):
     if self.is_standard_transaction:
         return byte_util.base58_encode(
             key.address_from_pk_hash(self.bytes[3:-2]))
     else:
         return None
Beispiel #18
0
 def to_address(self):
     if self.is_standard_transaction:
         return byte_util.base58_encode(
             key.address_from_pk_hash(self.bytes[3:-2]))
     else:
         return None
Beispiel #19
0
 def test_base58_encode_zero(self):
     self.assertEquals(byte_util.base58_encode('\x00'), '1')
Beispiel #20
0
 def test_decode_privkey_bad_version(self):
     priv_enc = '5JnKZDMUAddiGgFjWiHNVrX5pxGcEJ1miscs2Xhy7f9BrGffrps'
     priv = '\x08' + byte_util.base58_decode(priv_enc)[1:]
     with self.assertRaises(key.Error):
         key.decode_privkey(byte_util.base58_encode(priv))