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)
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))
def fast_hash(data: bytes): """ Hashing function used for Corner hashes. :param data: bytes :return: str """ return pycryptonight.cn_fast_hash(data).hex()
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)
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
def test_fast(self): self.tst_method('tests-fast.txt', lambda x, y: pycryptonight.cn_fast_hash(x))
def verify(self, signature, data): try: return self.vk.verify(signature, pycryptonight.cn_fast_hash(data)) except ecdsa.keys.BadSignatureError: return False
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)
def sign(self, data): return self._sk.sign(pycryptonight.cn_fast_hash(data))
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()
def hash(self): return pycryptonight.cn_fast_hash(self.encode_corner())
def header_hash(cls, header): import pycryptonight cnHeader = header[81:] return pycryptonight.cn_fast_hash(cnHeader)
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)
def sign(self, data): return Signature(self._sk.sign(pycryptonight.cn_fast_hash(data)), self.vk)
def fast_hash(b): return pycryptonight.cn_fast_hash(b).hex()
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