How to use the base58.b58encode_int function in base58

To help you get started, we’ve selected a few base58 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github keis / base58 / test_base58.py View on Github external
def test_large_integer():
    number = 0x111d38e5fc9071ffcd20b4a763cc9ae4f252bb4e48fd66a835e252ada93ff480d6dd43dc62a641155a5  # noqa
    assert_that(b58decode_int(BITCOIN_ALPHABET), equal_to(number))
    assert_that(b58encode_int(number), equal_to(BITCOIN_ALPHABET[1:]))
github keis / base58 / test_base58.py View on Github external
def test_simple_integers():
    for idx, char in enumerate(BITCOIN_ALPHABET):
        charbytes = bytes([char])
        assert_that(b58decode_int(charbytes), equal_to(idx))
        assert_that(b58encode_int(idx), equal_to(charbytes))
github p2p-today / p2p-project / py_src / messages.py View on Github external
def time_58(self):
        # type: (InternalMessage) -> bytes
        """Returns this message's timestamp in base_58"""
        return b58encode_int(self.__time)
github p2p-today / p2p-project / py_src / base.py View on Github external
Args:
            *args: Each argument given is a packet you wish to send. This is
                       prefixed with base.flags.whisper, so the other end will
                       receive ``[base.flags.whisper, *args]``
        """
        self.server._logger.debug(
            'Initiating a direct reply to Message ID {}'.format(self.id))
        if self.server.routing_table.get(self.sender):
            self.server.routing_table.get(self.sender).send(
                flags.whisper, flags.whisper, *args)
        else:
            self.server._logger.debug('Requesting connection for direct reply'
                                      ' to Message ID {}'.format(self.id))
            request_hash = sha384(
                self.sender + b58encode_int(getUTC()).decode()).hexdigest()
            request_id = b58encode_int(int(request_hash, 16)).decode()
            self.server.send(request_id, self.sender, type=flags.request)
            to_send = (flags.whisper,
                       flags.whisper)  # type: Tuple[MsgPackable, ...]
            self.server.requests[request_id] = to_send + args
            self.server._logger.critical(
                "You aren't connected to the original sender. This reply is "
                "not guarunteed, but we're trying to make a connection and "
github p2p-today / p2p-project / py_src / base.py View on Github external
Args:
            *args: Each argument given is a packet you wish to send. This is
                       prefixed with base.flags.whisper, so the other end will
                       receive ``[base.flags.whisper, *args]``
        """
        self.server._logger.debug(
            'Initiating a direct reply to Message ID {}'.format(self.id))
        if self.server.routing_table.get(self.sender):
            self.server.routing_table.get(self.sender).send(
                flags.whisper, flags.whisper, *args)
        else:
            self.server._logger.debug('Requesting connection for direct reply'
                                      ' to Message ID {}'.format(self.id))
            request_hash = sha384(
                self.sender + b58encode_int(getUTC()).decode()).hexdigest()
            request_id = b58encode_int(int(request_hash, 16)).decode()
            self.server.send(request_id, self.sender, type=flags.request)
            to_send = (flags.whisper,
                       flags.whisper)  # type: Tuple[MsgPackable, ...]
            self.server.requests[request_id] = to_send + args
            self.server._logger.critical(
                "You aren't connected to the original sender. This reply is "
                "not guarunteed, but we're trying to make a connection and "
github p2p-today / p2p-project / py_src / base.py View on Github external
EventEmitter.__init__(self)
        self.protocol = prot
        self.debug_level = debug_level
        self.routing_table = {}  # type: Dict[bytes, BaseConnection]
        # In format {ID: handler}
        self.awaiting_ids = []  # type: List[BaseConnection]
        # Connected, but not handshook yet
        if out_addr:  # Outward facing address, if you're port forwarding
            self.out_addr = out_addr
        elif addr == '0.0.0.0':
            self.out_addr = get_lan_ip(), port
        else:
            self.out_addr = addr, port
        info = (str(self.out_addr).encode(), prot.id.encode(), user_salt)
        h = sha384(b''.join(info))
        self.id = b58encode_int(int(h.hexdigest(), 16)).encode()  # type: bytes
        self._logger = getLogger('{}.{}.{}'.format(
            self.__class__.__module__, self.__class__.__name__, self.id))
        self.__handlers = [
        ]  # type: List[Callable[[Message, BaseConnection], Union[bool, None]]]
        self.__closed = False
github p2p-today / p2p-project / py_src / base.py View on Github external
def id(self):
        # type: (Protocol) -> str
        """The SHA-256-based ID of the Protocol"""
        h = sha256(''.join(str(x) for x in self).encode())
        h.update(protocol_version.encode())
        return b58encode_int(int(h.hexdigest(), 16))