コード例 #1
0
    def __init__(self, vk: ecdsa.VerifyingKey):
        """
        Initialise a Verifying Key instance.

        :param vk: ecdsa.VerifyingKey
        """
        self._vk = vk
        address = get_hash(pycryptonight.cn_fast_hash(self._vk.to_string()),
                           RIPEMD160.new)
        self.address = address + pycryptonight.cn_fast_hash(address)[:8]
        self.b58 = base58.b58encode(self.address, base58.BITCOIN_ALPHABET)
コード例 #2
0
    def calc_sha256(self):
        if self.sha256 is None:
            r = b""
            r += struct.pack("<i", self.nVersion)
            r += ser_uint256(self.hashPrevBlock)
            r += ser_uint256(self.hashMerkleRoot)
            r += struct.pack("<I", self.nTime)
            r += struct.pack("<I", self.nBits)
            r += struct.pack("<I", self.nNonce)
            # For kevacoin, self.sha256 doesn't actually store the sha256 value.
            # It stores the cn_fast hash instead.
            self.sha256_actual = uint256_from_str(hash256(r))
            #self.hash = encode(hash256(r)[::-1], 'hex_codec').decode('ascii')

            # Cryptonote cn hash
            c = b""
            c += struct.pack("<B", self.major_version)
            c += struct.pack("<B", self.minor_version)
            c += ser_varint(self.timestamp)
            # prev_id is used to store sha256 value of the blockhash for Proof-of-Work
            self.prev_id = self.sha256_actual

            c += ser_uint256(self.prev_id)
            c += struct.pack("<I", self.nonce)
            c += ser_uint256(self.merkle_root)
            c += struct.pack("<B", self.nTxes)
            # self.sha256 stores the cn_fast hash.
            cn_hash = pycryptonight.cn_fast_hash(c)
            self.sha256 = uint256_from_str(cn_hash)
            self.hash = encode(cn_hash[::-1], 'hex_codec').decode('ascii')
            # nNonce is used to store block height.
            self.scrypt256 = uint256_from_str(pycryptonight.cn_slow_hash(c, self.major_version - 6, 0, self.nNonce))
コード例 #3
0
def fast_hash(data: bytes):
    """
    Hashing function used for Corner hashes.

    :param data: bytes
    :return: str
    """
    return pycryptonight.cn_fast_hash(data).hex()
コード例 #4
0
    def sign(self, data: bytes):
        """
        Generates a Signature for the given data.

        :param data: bytes
        :return: Signature
        """
        return Signature(self._sk.sign(pycryptonight.cn_fast_hash(data)),
                         self.vk)
コード例 #5
0
    def verify(self, signature: bytes, data: bytes):
        """
        Verifies raw signature.

        :param signature: bytes
        :param data: bytes
        :return: bool
        """
        try:
            return self._vk.verify(signature, pycryptonight.cn_fast_hash(data))
        except ecdsa.keys.BadSignatureError:
            return False
コード例 #6
0
ファイル: test.py プロジェクト: ph4r05/py-cryptonight
 def test_fast(self):
     self.tst_method('tests-fast.txt', lambda x, y: pycryptonight.cn_fast_hash(x))
コード例 #7
0
 def verify(self, signature, data):
     try:
         return self.vk.verify(signature, pycryptonight.cn_fast_hash(data))
     except ecdsa.keys.BadSignatureError:
         return False
コード例 #8
0
 def __init__(self, vk):
     self._vk = vk
     self.string = self._vk.to_string()
     self.address = get_hash(pycryptonight.cn_fast_hash(self._vk.to_string()), RIPEMD160.new)
コード例 #9
0
 def sign(self, data):
     return self._sk.sign(pycryptonight.cn_fast_hash(data))
コード例 #10
0
 def __init__(self, previous_hash):
     self.version = (0).to_bytes(1, 'big')
     self.merkle_root = pycryptonight.cn_fast_hash(b'')
     self.previous_hash = previous_hash
     self.nonce = (0).to_bytes(4, 'big')
     self.header = self.encode_header()
コード例 #11
0
 def hash(self):
     return pycryptonight.cn_fast_hash(self.encode_corner())
コード例 #12
0
ファイル: coins.py プロジェクト: kevacoin-project/electrumx
 def header_hash(cls, header):
     import pycryptonight
     cnHeader = header[81:]
     return pycryptonight.cn_fast_hash(cnHeader)
コード例 #13
0
ファイル: _blockchain.py プロジェクト: busybox11/Discorn
 def __init__(self, vk):
     self._vk = vk
     self.string = self._vk.to_string()
     self.address = get_hash(
         pycryptonight.cn_fast_hash(self._vk.to_string()), RIPEMD160.new)
     self.b58 = base58.b58encode(self.address, base58.BITCOIN_ALPHABET)
コード例 #14
0
ファイル: _blockchain.py プロジェクト: busybox11/Discorn
 def sign(self, data):
     return Signature(self._sk.sign(pycryptonight.cn_fast_hash(data)),
                      self.vk)
コード例 #15
0
ファイル: _blockchain.py プロジェクト: busybox11/Discorn
def fast_hash(b):
    return pycryptonight.cn_fast_hash(b).hex()
コード例 #16
0
ファイル: _blockchain.py プロジェクト: busybox11/Discorn
 def __init__(self, version=0, event_hash=pycryptonight.cn_fast_hash(b'')):
     self.flag = 1
     self.version = version
     self.event_hash = event_hash
     self.authority_flag = -1