def get_data_to_sign(self, sender_pubkey: bytes, to_addr: str, nonce: Union[str, int], amount: Union[str, int], gas_price: Union[str, int], gas_limit: Union[str, int], code="", data=""): if not is_valid_checksum_address(to_addr): raise ValueError("invalid checksum address") txn_proto = pb2.ProtoTransactionCoreInfo() txn_proto.version = self.version txn_proto.nonce = int(nonce) txn_proto.toaddr = utils.hex_str_to_bytes(to_addr) txn_proto.senderpubkey.data = sender_pubkey txn_proto.amount.data = utils.int_to_bytes(int(amount), n_bytes=16) txn_proto.gasprice.data = utils.int_to_bytes(int(gas_price), n_bytes=16) txn_proto.gaslimit = int(gas_limit) if code: txn_proto.code = code.encode("utf-8") if data: txn_proto.data = data.encode("utf-8") data_to_sign = txn_proto.SerializeToString() return data_to_sign
def build_transaction_params(self, zil_key: ZilKey, to_addr: str, amount: Union[str, int], nonce: Union[str, int], gas_price: Union[str, int], gas_limit: Union[str, int], code="", data="", priority=False): if not is_valid_checksum_address(to_addr): raise ValueError("invalid checksum address") txn_proto = pb2.ProtoTransactionCoreInfo() txn_proto.version = self.version txn_proto.nonce = int(nonce) txn_proto.toaddr = utils.hex_str_to_bytes(to_addr) txn_proto.senderpubkey.data = zil_key.keypair_bytes.public txn_proto.amount.data = utils.int_to_bytes(int(amount), n_bytes=16) txn_proto.gasprice.data = utils.int_to_bytes(int(gas_price), n_bytes=16) txn_proto.gaslimit = int(gas_limit) if code: txn_proto.code = code.encode("utf-8") if data: txn_proto.data = data.encode("utf-8") data_to_sign = txn_proto.SerializeToString() signature = zil_key.sign_str(data_to_sign) # assert zil_key.verify(signature, data_to_sign) params = { "version": txn_proto.version, "nonce": txn_proto.nonce, "toAddr": to_addr, "amount": str(amount), "pubKey": zil_key.keypair_str.public, "gasPrice": str(gas_price), "gasLimit": str(gas_limit), "code": code or None, "data": data or None, "signature": signature, "priority": priority, } return params
def difficulty_to_boundary_divided(difficulty: int, n_divided: int = 8, n_divided_start: int = 32) -> bytes: """Zilliqa divided difficulty to boundary.""" if difficulty < n_divided_start: return difficulty_to_boundary(difficulty) n_level = (difficulty - n_divided_start) // n_divided m_sub_level = (difficulty - n_divided_start) % n_divided difficulty_level = n_divided_start + n_level int_boundary = utils.bytes_to_int(difficulty_to_boundary(difficulty_level)) boundary_change_step = (int_boundary >> 1) // n_divided int_boundary -= boundary_change_step * m_sub_level return utils.int_to_bytes(int_boundary, n_bytes=32)
def generate_new(cls): """Generate new zilliqa key""" zil_key = cls(private_key=utils.int_to_bytes(schnorr.gen_private_key())) return zil_key
def encoded_private_key(self): """bytes of private key.""" return self._private_key and utils.int_to_bytes(self._private_key)