當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。