当前位置: 首页>>代码示例>>Python>>正文


Python base58.b58decode_check方法代码示例

本文整理汇总了Python中base58.b58decode_check方法的典型用法代码示例。如果您正苦于以下问题:Python base58.b58decode_check方法的具体用法?Python base58.b58decode_check怎么用?Python base58.b58decode_check使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在base58的用法示例。


在下文中一共展示了base58.b58decode_check方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: guess_currency_from_address

# 需要导入模块: import base58 [as 别名]
# 或者: from base58 import b58decode_check [as 别名]
def guess_currency_from_address(address):
    """
    Given a crypto address, find which currency it likely belongs to.
    Raises an exception if it can't find a match. Raises exception if address
    is invalid.
    """
    if is_py2:
        fixer = lambda x: int(x.encode('hex'), 16)
    else:
        fixer = lambda x: x # does nothing

    first_byte = fixer(b58decode_check(address)[0])
    double_first_byte = fixer(b58decode_check(address)[:2])

    hits = []
    for currency, data in crypto_data.items():
        if hasattr(data, 'get'): # skip incomplete data listings
            version = data.get('address_version_byte', None)
            if version is not None and version in [double_first_byte, first_byte]:
                hits.append([currency, data['name']])

    if hits:
        return hits

    raise ValueError("Unknown Currency with first byte: %s" % first_byte) 
开发者ID:priestc,项目名称:moneywagon,代码行数:27,代码来源:__init__.py

示例2: change_version_byte

# 需要导入模块: import base58 [as 别名]
# 或者: from base58 import b58decode_check [as 别名]
def change_version_byte(address, new_version=None, new_crypto=None):
    """
    Convert the passed in address (or any base58 encoded string), and change the
    version byte to `new_version`.
    """
    if not new_version and new_crypto:
        try:
            new_version = crypto_data[new_crypto]['address_version_byte']
        except KeyError:
            raise CurrencyNotSupported("Unknown currency symbol: " + new_crypto)

        if not new_version:
            raise CurrencyNotSupported("Can't yet make %s addresses." % new_crypto)

    payload = b58decode_check(address)[1:]
    if is_py2:
        byte = chr(new_version)
    else:
        byte = bytes(chr(new_version), 'ascii')

    return b58encode_check(byte + payload) 
开发者ID:priestc,项目名称:moneywagon,代码行数:23,代码来源:__init__.py

示例3: __init__

# 需要导入模块: import base58 [as 别名]
# 或者: from base58 import b58decode_check [as 别名]
def __init__(self, b58check):
        self.lot = None
        self.sequence = None
        self.b58check = b58check
        if not b58check.startswith('passphrase'):
            raise Exception("Invalid intermediate point. Must start wth 'passphrase'.")
        payload = b58decode_check(str(b58check))
        self.ownerentropy = payload[8:16] # 8 bytes
        self.passpoint = payload[16:49] # 33 bytes

        flag = payload[7:8]

        if flag == b'\x51':
            self.has_lot_and_sequence = True
            self.ownersalt = self.ownerentropy[:4] # 4 bytes
            lotsequence = bytes_to_int(self.ownerentropy[4:]) # 4 bytes
            self.lot = lotsequence // self.lotseq_constant
            self.sequence = lotsequence % self.lot
        elif flag == b'\x53':
            self.has_lot_and_sequence = False
            self.ownersalt = self.ownerentropy # 8 bytes
        else:
            raise Exception("Unknown flag byte: %s, should be either \\x51 or \\x53" % flag) 
开发者ID:priestc,项目名称:moneywagon,代码行数:25,代码来源:bip38.py

示例4: b58decode

# 需要导入模块: import base58 [as 别名]
# 或者: from base58 import b58decode_check [as 别名]
def b58decode(cls, key: Union[str, bytes]):
        """ Decodes a Base58Check encoded key.

        The encoding must conform to the description in:
        https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#serialization-format
        """
        return cls.from_bytes(base58.b58decode_check(key)) 
开发者ID:ontio,项目名称:ontology-python-sdk,代码行数:9,代码来源:hd_public_key.py

示例5: b58decode

# 需要导入模块: import base58 [as 别名]
# 或者: from base58 import b58decode_check [as 别名]
def b58decode(cls, key):
        """
        Decodes a Base58Check encoding private-key.
        """
        return cls.from_bytes(base58.b58decode_check(key)) 
开发者ID:ontio,项目名称:ontology-python-sdk,代码行数:7,代码来源:hd_private_key.py

示例6: address_to_pubkey_hash

# 需要导入模块: import base58 [as 别名]
# 或者: from base58 import b58decode_check [as 别名]
def address_to_pubkey_hash(address):
    # return base58.b58decode_check(encode(address))[1:]
    return base58.base58CheckDecode(address) 
开发者ID:yummybian,项目名称:blockchain-py,代码行数:5,代码来源:utils.py

示例7: to_hex

# 需要导入模块: import base58 [as 别名]
# 或者: from base58 import b58decode_check [as 别名]
def to_hex(address):
        """Helper function that will convert a generic value to hex"""
        if is_hex(address):
            return address.lower().replace('0x', '41', 2)

        return base58.b58decode_check(address).hex().upper() 
开发者ID:iexbase,项目名称:tron-api-python,代码行数:8,代码来源:account.py

示例8: from_b58check

# 需要导入模块: import base58 [as 别名]
# 或者: from base58 import b58decode_check [as 别名]
def from_b58check(private_key):
        """ Decodes a Base58Check encoded private-key.

        Args:
            private_key (str): A Base58Check encoded private key.

        Returns:
            PrivateKey: A PrivateKey object
        """
        b58dec = base58.b58decode_check(private_key)
        version = b58dec[0]
        assert version in [PrivateKey.TESTNET_VERSION,
                           PrivateKey.MAINNET_VERSION]

        return PrivateKey(int.from_bytes(b58dec[1:], 'big')) 
开发者ID:ranaroussi,项目名称:pywallet,代码行数:17,代码来源:ethereum.py

示例9: base58_decode

# 需要导入模块: import base58 [as 别名]
# 或者: from base58 import b58decode_check [as 别名]
def base58_decode(v: bytes) -> bytes:
    try:
        prefix_len = next(
            len(encoding[2])
            for encoding in base58_encodings
            if len(v) == encoding[1] and v.startswith(encoding[0])
        )
    except StopIteration:
        raise ValueError('Invalid encoding, prefix or length mismatch.')

    return base58.b58decode_check(v)[prefix_len:] 
开发者ID:murbard,项目名称:pytezos,代码行数:13,代码来源:encoding.py

示例10: validateaddress

# 需要导入模块: import base58 [as 别名]
# 或者: from base58 import b58decode_check [as 别名]
def validateaddress(self, params):
        # check for [] parameter or [""]
        if not params or params[0] == '':
            raise JsonRpcError(-100, "Missing argument")

        isValid = False
        try:
            data = base58.b58decode_check(params[0])
            if len(data) == 21 and data[0] == settings.ADDRESS_VERSION:
                isValid = True
        except Exception as e:
            pass

        return {"address": params[0], "isvalid": isValid} 
开发者ID:CityOfZion,项目名称:neo-python,代码行数:16,代码来源:JsonRpcApi.py

示例11: isValidPublicAddress

# 需要导入模块: import base58 [as 别名]
# 或者: from base58 import b58decode_check [as 别名]
def isValidPublicAddress(address: str) -> bool:
    """Check if address is a valid NEO address"""
    valid = False

    if len(address) == 34 and address[0] == 'A':
        try:
            base58.b58decode_check(address.encode())
            valid = True
        except ValueError:
            # checksum mismatch
            valid = False

    return valid 
开发者ID:CityOfZion,项目名称:neo-python,代码行数:15,代码来源:Utils.py

示例12: wif_to_hex

# 需要导入模块: import base58 [as 别名]
# 或者: from base58 import b58decode_check [as 别名]
def wif_to_hex(wif):
    """
    Convert a WIF encded private key and return the raw hex encoded private key
    This function works for all bitcoin-API compatable coins.
    """
    return hexlify(b58decode_check(wif)[1:]).upper() 
开发者ID:priestc,项目名称:moneywagon,代码行数:8,代码来源:__init__.py

示例13: wif_to_address

# 需要导入模块: import base58 [as 别名]
# 或者: from base58 import b58decode_check [as 别名]
def wif_to_address(crypto, wif):
    if is_py2:
        wif_byte = int(hexlify(b58decode_check(wif)[0]), 16)
    else:
        wif_byte = b58decode_check(wif)[0]

    if not wif_byte == crypto_data[crypto.lower()]['private_key_prefix']:
        msg = 'WIF encoded with wrong prefix byte. Are you sure this is a %s address?' % crypto.upper()
        raise Exception(msg)

    address_byte = crypto_data[crypto.lower()]['address_version_byte']
    return privkey_to_address(wif, address_byte) 
开发者ID:priestc,项目名称:moneywagon,代码行数:14,代码来源:__init__.py

示例14: from_wif

# 需要导入模块: import base58 [as 别名]
# 或者: from base58 import b58decode_check [as 别名]
def from_wif(cls, wif, network=BitcoinMainNet):
        """Import a key in WIF format.

        WIF is Wallet Import Format. It is a base58 encoded checksummed key.
        See https://en.bitcoin.it/wiki/Wallet_import_format for a full
        description.

        This supports compressed WIFs - see this for an explanation:
        http://bitcoin.stackexchange.com/questions/7299/when-importing-private-keys-will-compressed-or-uncompressed-format-be-used  # nopep8
        (specifically http://bitcoin.stackexchange.com/a/7958)
        """
        # Decode the base58 string and ensure the checksum is valid
        wif = ensure_str(wif)
        try:
            extended_key_bytes = base58.b58decode_check(wif)
        except ValueError as e:
            # Invalid checksum!
            raise ChecksumException(e)

        # Verify we're on the right network
        network_bytes = extended_key_bytes[0]
        # py3k interprets network_byte as an int already
        if not isinstance(network_bytes, six.integer_types):
            network_bytes = ord(network_bytes)
        if (network_bytes != network.SECRET_KEY):
            raise incompatible_network_exception_factory(
                network_name=network.NAME,
                expected_prefix=network.SECRET_KEY,
                given_prefix=network_bytes)

        # Drop the network bytes
        extended_key_bytes = extended_key_bytes[1:]

        # Check for comprssed public key
        # This only affects the way in which addresses are generated.
        compressed = False
        if len(extended_key_bytes) == 33:
            # We are supposed to use compressed form!
            extended_key_bytes = extended_key_bytes[:-1]
            compressed = True

        # And we should finally have a valid key
        return cls(long_or_int(hexlify(extended_key_bytes), 16), network,
                   compressed=compressed) 
开发者ID:BlockIo,项目名称:multimerchant-python,代码行数:46,代码来源:keys.py

示例15: coinbaseMessage

# 需要导入模块: import base58 [as 别名]
# 或者: from base58 import b58decode_check [as 别名]
def coinbaseMessage(previous_output, receiver_address, my_address, private_key):
    receiver_hashed_pubkey= base58.b58decode_check(receiver_address)[1:].encode("hex")
    my_hashed_pubkey = base58.b58decode_check(my_address)[1:].encode("hex")

    # Transaction stuff
    version = struct.pack("<L", 1)
    lock_time = struct.pack("<L", 0)
    hash_code = struct.pack("<L", 1)

    # Transactions input
    tx_in_count = struct.pack("<B", 1)
    tx_in = {}
    tx_in["outpoint_hash"] = previous_output.decode('hex')[::-1]
    tx_in["outpoint_index"] = struct.pack("<L", 4294967295)
    tx_in["script"] = ("76a914%s88ac" % my_hashed_pubkey).decode("hex")
    tx_in["script_bytes"] = struct.pack("<B", (len(tx_in["script"])))
    tx_in["sequence"] = "ffffffff".decode("hex")

    # Transaction output
    tx_out_count = struct.pack("<B", 1)

    tx_out = {}
    tx_out["value"]= struct.pack("<Q", 100000000 * 12.50033629)
    tx_out["pk_script"]= ("76a914%s88ac" % receiver_hashed_pubkey).decode("hex")
    tx_out["pk_script_bytes"]= struct.pack("<B", (len(tx_out["pk_script"])))

    tx_to_sign = (version + tx_in_count + tx_in["outpoint_hash"] + tx_in["outpoint_index"] +
                  tx_in["script_bytes"] + tx_in["script"] + tx_in["sequence"] + tx_out_count +
                  tx_out["value"] + tx_out["pk_script_bytes"] + tx_out["pk_script"] + lock_time + hash_code)

    # Signing txn
    hashed_raw_tx = hashlib.sha256(hashlib.sha256(tx_to_sign).digest()).digest()
    sk = ecdsa.SigningKey.from_string(private_key.decode("hex"), curve = ecdsa.SECP256k1)
    vk = sk.verifying_key
    public_key = ('\04' + vk.to_string()).encode("hex")
    sign = sk.sign_digest(hashed_raw_tx, sigencode=ecdsa.util.sigencode_der)

    # Complete txn
    sigscript = sign + "\01" + struct.pack("<B", len(public_key.decode("hex"))) + public_key.decode("hex")

    real_tx = (version + tx_in_count + tx_in["outpoint_hash"] + tx_in["outpoint_index"] +
    struct.pack("<B", (len(sigscript) + 1)) + struct.pack("<B", len(sign) + 1) + sigscript +
    tx_in["sequence"] + tx_out_count + tx_out["value"] + tx_out["pk_script_bytes"] + tx_out["pk_script"] + lock_time)

    return real_tx 
开发者ID:pavlovdog,项目名称:bitcoin_in_a_nutshell,代码行数:47,代码来源:coinbase_txn.py


注:本文中的base58.b58decode_check方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。