Esempio n. 1
0
    def _do_test_crypto(self, message):
        G = generator_secp256k1
        _r = G.order()
        pvk = ecdsa.util.randrange(pow(2, 256)) % _r

        Pub = pvk * G
        pubkey_c = point_to_ser(Pub, True)
        # pubkey_u = point_to_ser(Pub,False)
        addr_c = public_key_to_bc_address(pubkey_c)
        # addr_u = public_key_to_bc_address(pubkey_u)

        # print "Private key            ", '%064x'%pvk
        eck = EC_KEY(number_to_string(pvk, _r))

        # print "Compressed public key  ", pubkey_c.encode('hex')
        enc = EC_KEY.encrypt_message(message, pubkey_c)
        dec = eck.decrypt_message(enc)
        assert dec == message

        # print "Uncompressed public key", pubkey_u.encode('hex')
        # enc2 = EC_KEY.encrypt_message(message, pubkey_u)
        dec2 = eck.decrypt_message(enc)
        assert dec2 == message

        signature = eck.sign_message(message, True, addr_c)
        # print signature
        EC_KEY.verify_message(addr_c, signature, message)
Esempio n. 2
0
 def decrypt_message(self, pubkey, message, password):
     address = public_key_to_bc_address(pubkey.decode('hex'))
     client = self.get_client()
     address_path = self.address_id(address)
     address_n = client.expand_path(address_path)
     payload = base64.b64decode(message)
     nonce, message, msg_hmac = payload[:33], payload[33:-8], payload[-8:]
     result = client.decrypt_message(address_n, nonce, message, msg_hmac)
     return result.message
Esempio n. 3
0
 def decrypt_message(self, pubkey, message, password):
     address = public_key_to_bc_address(pubkey.decode('hex'))
     client = self.get_client()
     address_path = self.address_id(address)
     address_n = client.expand_path(address_path)
     payload = base64.b64decode(message)
     nonce, message, msg_hmac = payload[:33], payload[33:-8], payload[-8:]
     result = client.decrypt_message(address_n, nonce, message, msg_hmac)
     return result.message
Esempio n. 4
0
 def get_outputs(self):
     """convert pubkeys to addresses"""
     o = []
     for type, x, v in self.outputs():
         if type & (TYPE_CLAIM | TYPE_UPDATE | TYPE_SUPPORT):
             x = x[1]
         if type & TYPE_ADDRESS:
             addr = x
         elif type & TYPE_PUBKEY:
             addr = public_key_to_bc_address(x.decode('hex'))
         else:
             addr = 'SCRIPT ' + x.encode('hex')
         o.append((addr, v))  # consider using yield (addr, v)
     return o
Esempio n. 5
0
def parse_xpub(x_pubkey):
    if x_pubkey[0:2] in ['02', '03', '04']:
        pubkey = x_pubkey
    elif x_pubkey[0:2] == 'ff':
        from lbryum.bip32 import BIP32_Account
        xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
        pubkey = BIP32_Account.derive_pubkey_from_xpub(xpub, s[0], s[1])
    elif x_pubkey[0:2] == 'fd':
        addrtype = ord(x_pubkey[2:4].decode('hex'))
        hash160 = x_pubkey[4:].decode('hex')
        pubkey = None
        address = hash_160_to_bc_address(hash160, addrtype)
    else:
        raise BaseException("Cannnot parse pubkey")
    if pubkey:
        address = public_key_to_bc_address(pubkey.decode('hex'))
    return pubkey, address
Esempio n. 6
0
 def pubkeys_to_address(self, pubkey):
     return public_key_to_bc_address(pubkey.decode('hex'))