How to use the base58.alphabet.decode 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 hyperledger / indy-plenum / plenum / common / messages / fields.py View on Github external
class LedgerIdField(ChooseField):
    _base_types = (int,)
    ledger_ids = VALID_LEDGER_IDS

    def __init__(self, **kwargs):
        self.ledger_ids = self.update_with_plugin_ledger_ids()
        super().__init__(self.ledger_ids, **kwargs)

    @staticmethod
    def update_with_plugin_ledger_ids():
        return VALID_LEDGER_IDS + tuple(PLUGIN_LEDGER_IDS)


class Base58Field(FieldBase):
    _base_types = (str,)
    _alphabet = set(base58.alphabet.decode("utf-8"))

    def __init__(self, byte_lengths=None, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.byte_lengths = byte_lengths

    def _specific_validation(self, val):
        invalid_chars = set(val) - self._alphabet
        if invalid_chars:
            # only 10 chars to shorten the output
            # TODO: Why does it need to be sorted
            to_print = sorted(invalid_chars)[:10]
            return 'should not contain the following chars {}{}'.format(
                to_print, ' (truncated)' if len(to_print) < len(invalid_chars) else '')
        if self.byte_lengths is not None:
            # TODO could impact performance, need to check
            b58len = len(base58.b58decode(val))
github hyperledger / aries-cloudagent-python / aries_cloudagent / messaging / valid.py View on Github external
"""Validators for schema fields."""

import json

from datetime import datetime

from base58 import alphabet
from marshmallow.validate import OneOf, Range, Regexp
from marshmallow.exceptions import ValidationError

from .util import epoch_to_str

B58 = alphabet if isinstance(alphabet, str) else alphabet.decode("ascii")


class IntEpoch(Range):
    """Validate value against (integer) epoch format."""

    EXAMPLE = int(datetime.now().timestamp())

    def __init__(self):
        """Initializer."""

        super().__init__(  # use 64-bit for Aries RFC compatibility
            min=-9223372036854775808,
            max=9223372036854775807,
            error="Value {input} is not a valid integer epoch time",
        )