예제 #1
0
    def PrivateKeyFromWIF(wif):
        """
        Get the private key from a WIF key

        Args:
            wif (str): The wif key

        Returns:
            bytes: The private key
        """
        if wif is None or len(wif) is not 52:
            raise ValueError(
                'Please provide a wif with a length of 52 bytes (LEN: {0:d})'.
                format(len(wif)))

        data = base58.b58decode(wif)

        length = len(data)

        if length is not 38 or data[0] is not 0x80 or data[33] is not 0x01:
            raise ValueError("Invalid format!")

        checksum = Crypto.Hash256(data[0:34])[0:4]

        if checksum != data[34:]:
            raise ValueError("Invalid WIF Checksum!")

        return data[1:33]
예제 #2
0
def create_offer_hash(neo_address, offer_asset_hash, offer_asset_amt, want_asset_hash, want_asset_amt, txn_uuid):
    reverse_user_hash = reverse_hex(neo_get_scripthash_from_address(neo_address))
    reverse_offer_asset_hash = reverse_hex(offer_asset_hash)
    reverse_offer_amount = num2hexstring(number=offer_asset_amt, size=8, little_endian=True)
    reverse_want_asset_hash = reverse_hex(want_asset_hash)
    reverse_want_amount = num2hexstring(number=want_asset_amt, size=8, little_endian=True)
    nonce_hex = txn_uuid.encode('utf-8').hex()
    offer_key_bytes = reverse_user_hash + reverse_offer_asset_hash + reverse_want_asset_hash + reverse_offer_amount +\
                      reverse_want_amount + nonce_hex
    offer_hash = reverse_hex(Crypto.Hash256(binascii.a2b_hex(offer_key_bytes)).hex())
    return offer_hash
예제 #3
0
    def Hash(self):
        """
        Get the hash of the transaction.

        Returns:
            UInt256:
        """
        if not self.__hash:
            ba = bytearray(binascii.unhexlify(self.GetHashData()))
            hash = Crypto.Hash256(ba)
            self.__hash = UInt256(data=hash)
        return self.__hash
예제 #4
0
def createTxid(txData):
    ba = binascii.unhexlify(txData)
    hash = Crypto.Hash256(ba)
    return UInt256(data=hash).ToString()