Exemplo n.º 1
0
def get_script_hash_from_wif(wif):
    """Fetch the script hash of the public key from a wif represented in string format.

    Args:
        wif (str) : wif from which we need to extract the public key script hash

    Returns:
        public key script hash in string format
    """
    pk = KeyPair.PrivateKeyFromWIF(wif)
    keypair = KeyPair(pk)
    logger.debug("Public Address is {}".format(keypair.GetAddress()))
    return get_script_hash_from_address(keypair.GetAddress())
Exemplo n.º 2
0
def create_wallet():
    private_key = bytes(Random.get_random_bytes(32))
    keypair = KeyPair(priv_key=private_key)
    return {
        "private_key": keypair.Export(),
        "address": keypair.GetAddress()
    }
    def test_should_export_valid_nep2_key_with_emoji_pwd(self):
        pwd = "hellö♥️"
        privkey = "03eb20a711f93c04459000c62cc235f9e9da82382206b812b07fd2f81779aa42"

        # expected outputs
        target_address = "AXQUduANGZF4e7wDazVAtyRLHwMounaUMA"
        target_encrypted_key = "6PYWdv8bP9vbfGsNnjzDawCoXCYpk4rnWG8xTZrvdzx6FjB6jv4H9MM586"

        kp = KeyPair(binascii.unhexlify(privkey))
        nep2_key = kp.ExportNEP2(pwd)
        self.assertEqual(nep2_key, target_encrypted_key)
        self.assertEqual(kp.GetAddress(), target_address)
Exemplo n.º 4
0
def create_wallet():
    private_key = bytes(Random.get_random_bytes(32))
    keypair = KeyPair(priv_key=private_key)
    public_key = keypair.PublicKey.encode_point(True)
    address = keypair.GetAddress()
    script_hash = address_to_scripthash(address)
    return {
        "private_key": keypair.Export(),
        "address": address,
        "script_hash": "0x{}".format(script_hash[::-1].hex()),
        "public_key": public_key.decode("utf-8")
    }
Exemplo n.º 5
0
def nep2_to_wallet(NEP2, passphrase):
    private_key = KeyPair.PrivateKeyFromNEP2(NEP2, passphrase)
    keypair = KeyPair(priv_key=private_key)
    public_key = keypair.PublicKey.encode_point(True)
    address = keypair.GetAddress()
    script_hash = address_to_scripthash(address)
    return {
        "private_key": keypair.Export(),
        "address": address,
        "script_hash": "0x{}".format(script_hash[::-1].hex()),
        "public_key": public_key.decode("utf-8")
    }
Exemplo n.º 6
0
 def new_wallet(self, request):
     request.setHeader('Content-Type', 'application/json')
     private_key = bytes(Random.get_random_bytes(32))
     key = KeyPair(priv_key=private_key)
     return json.dumps(
         {
             'public_key': str(key.PublicKey.encode_point(True), 'utf-8'),
             'public_key_hash': key.PublicKeyHash.ToString(),
             'private_key': key.PrivateKey.hex(),
             'wif': key.Export(),
             'address': key.GetAddress()
         },
         indent=4,
         sort_keys=True)
Exemplo n.º 7
0
 def get_data_from_wif(self, request, wif):
     request.setHeader('Content-Type', 'application/json')
     try:
         print("get_data_from_wif ", wif)
         private_key = KeyPair.PrivateKeyFromWIF(wif)
         key = KeyPair(priv_key=private_key)
         return json.dumps(
             {
                 'public_key': str(key.PublicKey.encode_point(True),
                                   'utf-8'),
                 'public_key_hash': key.PublicKeyHash.ToString(),
                 'private_key': key.PrivateKey.hex(),
                 'wif': key.Export(),
                 'address': key.GetAddress()
             },
             indent=4,
             sort_keys=True)
     except Exception as e:
         return self.format_message(
             "Error: Could not get data from wif %s " % (wif))
     return self.format_message("Could not get data from wif %s " % (wif))
 def test_should_return_valid_address(self):
     kp = KeyPair(
         binascii.unhexlify(
             "cbf4b9f70470856bb4f40f80b87edb90865997ffee6df315ab166d713af433a5"
         ))
     self.assertEqual(kp.GetAddress(), "AStZHy8E6StCqYQbzMqi4poH7YNDHQKxvt")
Exemplo n.º 9
0
c.execute("SELECT name, value from Key")
for tup in c.fetchall():
    name = tup[0]
    value = tup[1]
    if name == 'PasswordHash':
        PasswordHash = value
    elif name == 'MasterKey':
        MasterKey = value
    elif name == 'IV':
        IV = value

passwordKey = to_aes_key(password)

if hashlib.sha256(passwordKey).digest() != PasswordHash:
    print("Wrong password")
else:
    aes = AES.new(passwordKey, AES.MODE_CBC, IV)
    mk = aes.decrypt(MasterKey)

    c.execute("SELECT PublicKeyHash, PrivateKeyEncrypted from Account")

    for tup in c.fetchall():
        PublicKeyHash = tup[0]
        PrivateKeyEncrypted = tup[1]
        aes = AES.new(mk, AES.MODE_CBC, IV)
        decrypted = aes.decrypt(PrivateKeyEncrypted)
        kp = KeyPair(decrypted)
        print("{} : {}".format(kp.GetAddress(), kp.Export()))

conn.close()
Exemplo n.º 10
0
def wif_to_address(wif):
    private_key = KeyPair.PrivateKeyFromWIF(wif)
    keypair = KeyPair(priv_key=private_key)
    address = keypair.GetAddress()
    return address
Exemplo n.º 11
0
def nep2_to_scripthash(nep2, passphrase):
    private_key = KeyPair.PrivateKeyFromNEP2(nep2, passphrase)
    keypair = KeyPair(priv_key=private_key)
    address = keypair.GetAddress()
    script_hash = address_to_scripthash(address)
    return "0x{}".format(script_hash[::-1].hex())
Exemplo n.º 12
0
def nep2_to_address(nep2, passphrase):
    private_key = KeyPair.PrivateKeyFromNEP2(nep2, passphrase)
    keypair = KeyPair(priv_key=private_key)
    address = keypair.GetAddress()
    return address
Exemplo n.º 13
0
def wif_to_scripthash(wif):
    private_key = KeyPair.PrivateKeyFromWIF(wif)
    keypair = KeyPair(priv_key=private_key)
    address = keypair.GetAddress()
    script_hash = address_to_scripthash(address)
    return "0x{}".format(script_hash[::-1].hex())