本文整理匯總了Python中base58.b58decode方法的典型用法代碼示例。如果您正苦於以下問題:Python base58.b58decode方法的具體用法?Python base58.b58decode怎麽用?Python base58.b58decode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類base58
的用法示例。
在下文中一共展示了base58.b58decode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_private_key_from_wif
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58decode [as 別名]
def get_private_key_from_wif(wif: str) -> bytes:
"""
This interface is used to decode a WIF encode ECDSA private key.
:param wif: a WIF encode private key.
:return: a ECDSA private key in the form of bytes.
"""
if wif is None or wif is "":
raise Exception("none wif")
data = base58.b58decode(wif)
if len(data) != 38 or data[0] != 0x80 or data[33] != 0x01:
raise Exception("wif wrong")
checksum = Digest.hash256(data[0:34])
for i in range(4):
if data[len(data) - 4 + i] != checksum[i]:
raise Exception("wif wrong")
return data[1:33]
示例2: _specific_validation
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58decode [as 別名]
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))
if b58len not in self.byte_lengths:
expected_length = list(self.byte_lengths)[0] if len(self.byte_lengths) == 1 \
else 'one of {}'.format(list(self.byte_lengths))
return 'b58 decoded value length {} should be {}' \
.format(b58len, expected_length)
示例3: __init__
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58decode [as 別名]
def __init__(self, verkey, identifier=None):
_verkey = verkey
self._verkey = None
self._vr = None
if identifier:
rawIdr = b58decode(identifier)
if len(rawIdr) == 32 and not verkey: # assume cryptonym
verkey = identifier
if not verkey:
raise ValueError("'verkey' should be a non-empty string")
if verkey[0] == '~': # abbreviated
verkey = b58encode(b58decode(identifier) +
b58decode(verkey[1:])).decode("utf-8")
try:
self.verkey = verkey
except Exception as ex:
raise InvalidKey("verkey {}".format(_verkey)) from ex
示例4: wif_to_privkey
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58decode [as 別名]
def wif_to_privkey(wif_key: str, dash_network: str):
"""
Based on project: https://github.com/chaeplin/dashmnb with some changes related to usage of bitcoin library.
"""
privkey_encoded = base58.b58decode(wif_key).hex()
wif_prefix_cur = privkey_encoded[:2]
wif_prefix_network = get_chain_params(dash_network).PREFIX_SECRET_KEY
wif_prefix_network_str = wif_prefix_network.to_bytes(1, byteorder='big').hex()
checksum_stored = privkey_encoded[-8:]
vs = bytes.fromhex(privkey_encoded[:-8])
checksum_actual = binascii.unhexlify(bitcoin.dbl_sha256(vs))[0:4]
checksum_actual_str = checksum_actual.hex()
if wif_prefix_cur == wif_prefix_network_str and checksum_stored == checksum_actual_str:
privkey = privkey_encoded[2:-8]
return privkey
else:
if wif_prefix_cur != wif_prefix_network_str:
logging.warning('Private key and network prefixes differ. PK prefix: %s, network prefix: %s', wif_prefix_cur,
wif_prefix_network_str)
if checksum_stored != checksum_actual_str:
logging.warning('Invalid private key checksum. PK checksum: %s, required: %s', checksum_stored,
checksum_actual_str)
return None
示例5: btc_addr_to_hash_160
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58decode [as 別名]
def btc_addr_to_hash_160(btc_addr):
""" Calculates the RIPEMD-160 hash from a given Bitcoin address
:param btc_addr: Bitcoin address.
:type btc_addr: str
:return: The corresponding RIPEMD-160 hash.
:rtype: hex str
"""
# Base 58 decode the Bitcoin address.
decoded_addr = b58decode(btc_addr)
# Covert the address from bytes to hex.
decoded_addr_hex = hexlify(decoded_addr)
# Obtain the RIPEMD-160 hash by removing the first and four last bytes of the decoded address, corresponding to
# the network version and the checksum of the address.
h160 = decoded_addr_hex[2:-8]
return h160
示例6: is_proof_verified
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58decode [as 別名]
def is_proof_verified(db_manager,
proof, path,
value, seq_no, txn_time):
encoded_value = domain.encode_state_value(value, seq_no, txn_time)
proof_nodes = base64.b64decode(proof[PROOF_NODES])
root_hash = base58.b58decode(proof[ROOT_HASH])
verified = db_manager.get_state(DOMAIN_LEDGER_ID).verify_state_proof(
root_hash,
path,
encoded_value,
proof_nodes,
serialized=True
)
return verified
# Similar tests for Rich Schema objects are in indy_node/test/request_handlers/rich_schema
示例7: base58_decode
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58decode [as 別名]
def base58_decode(self):
"""Decode as Base58
Base58 is a notation for encoding arbitrary byte data using a
restricted set of symbols that can be conveniently used by humans
and processed by computers.This property decodes raw data
into an ASCII Base58 string.
Returns:
Chepy: The Chepy object.
Examples:
>>> Chepy("2UDrs31qcWSPi").base58_decode().output.decode()
"some data"
"""
self.state = base58.b58decode(self.state)
return self
示例8: reissueAsset
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58decode [as 別名]
def reissueAsset(self, Asset, quantity, reissuable=False, txFee=pywaves.DEFAULT_TX_FEE):
timestamp = int(time.time() * 1000)
sData = b'\5' + \
base58.b58decode(self.publicKey) + \
base58.b58decode(Asset.assetId) + \
struct.pack(">Q", quantity) + \
(b'\1' if reissuable else b'\0') + \
struct.pack(">Q",txFee) + \
struct.pack(">Q", timestamp)
signature = crypto.sign(self.privateKey, sData)
data = json.dumps({
"senderPublicKey": self.publicKey,
"assetId": Asset.assetId,
"quantity": quantity,
"timestamp": timestamp,
"reissuable": reissuable,
"fee": txFee,
"signature": signature
})
req = self.pywaves.wrapper('/assets/broadcast/reissue', data)
if self.pywaves.OFFLINE:
return req
else:
return req.get('id', 'ERROR')
示例9: cancelOrderByID
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58decode [as 別名]
def cancelOrderByID(self, assetPair, orderId):
sData = base58.b58decode(self.publicKey) + \
base58.b58decode(orderId)
signature = crypto.sign(self.privateKey, sData)
data = json.dumps({
"sender": self.publicKey,
"orderId": orderId,
"signature": signature
})
req = self.pywaves.wrapper('/matcher/orderbook/%s/%s/cancel' % (pywaves.DEFAULT_CURRENCY if assetPair.asset1.assetId=='' else assetPair.asset1.assetId, pywaves.DEFAULT_CURRENCY if assetPair.asset2.assetId=='' else assetPair.asset2.assetId), data, host=self.pywaves.MATCHER)
if self.pywaves.OFFLINE:
return req
else:
id = -1
if req['status'] == 'OrderCanceled':
id = req['orderId']
logging.info('Order Cancelled - ID: %s' % id)
return id
示例10: get
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58decode [as 別名]
def get(self, address=None):
if address is None:
raise HTTPError(400, reason="No address")
try:
from_height = long(self.get_argument("from_height", 0))
except:
raise HTTPError(400)
address_decoded = base58.b58decode(address)
address_version = address_decoded[0]
address_hash = address_decoded[1:21]
request = {
"id": random_id_number(),
"command":"fetch_history",
"params": [address_version, address_hash, from_height]
}
self.application._obelisk_handler.handle_request(self, request)
示例11: _check_decode
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58decode [as 別名]
def _check_decode(self, key_string, key_type=None) :
''' '''
buffer = hexlify(base58.b58decode(key_string)).decode()
chksum = buffer[-8:]
key = buffer[:-8]
if key_type == 'sha256x2' :
# legacy
first_sha = sha256(unhexlify(key))
newChk = sha256(unhexlify(first_sha))[:8]
else :
check = key
if key_type :
check += hexlify(bytearray(key_type, 'utf-8')).decode()
newChk = ripemd160(unhexlify(check))[:8]
#print('newChk: '+newChk)
if chksum != newChk :
raise ValueError('checksums do not match: {0} != {1}'.format(chksum, newChk))
return key
示例12: is_address
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58decode [as 別名]
def is_address(address: str) -> bool:
raw_address = base58.b58decode(address)
if len(raw_address) != Address.DISPLAY_BYTE_LENGTH:
return False
# split the identity into address and checksum
address_raw = raw_address[:Address.BYTE_LENGTH]
checksum = raw_address[Address.BYTE_LENGTH:]
# calculate the expected checksum
expected_checksum = Address._calculate_checksum(address_raw)
if checksum != expected_checksum:
return False
return True
示例13: test_generate_output_split_half_recursive
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58decode [as 別名]
def test_generate_output_split_half_recursive(user_pub, user2_pub, user3_pub):
from bigchaindb.common.transaction import Output
from cryptoconditions import Ed25519Sha256, ThresholdSha256
expected_simple1 = Ed25519Sha256(public_key=b58decode(user_pub))
expected_simple2 = Ed25519Sha256(public_key=b58decode(user2_pub))
expected_simple3 = Ed25519Sha256(public_key=b58decode(user3_pub))
expected = ThresholdSha256(threshold=2)
expected.add_subfulfillment(expected_simple1)
expected_threshold = ThresholdSha256(threshold=2)
expected_threshold.add_subfulfillment(expected_simple2)
expected_threshold.add_subfulfillment(expected_simple3)
expected.add_subfulfillment(expected_threshold)
cond = Output.generate([user_pub, [user2_pub, expected_simple3]], 1)
assert cond.fulfillment.to_dict() == expected.to_dict()
示例14: test_generate_outputs_split_half_single_owner
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58decode [as 別名]
def test_generate_outputs_split_half_single_owner(user_pub,
user2_pub, user3_pub):
from bigchaindb.common.transaction import Output
from cryptoconditions import Ed25519Sha256, ThresholdSha256
expected_simple1 = Ed25519Sha256(public_key=b58decode(user_pub))
expected_simple2 = Ed25519Sha256(public_key=b58decode(user2_pub))
expected_simple3 = Ed25519Sha256(public_key=b58decode(user3_pub))
expected = ThresholdSha256(threshold=2)
expected_threshold = ThresholdSha256(threshold=2)
expected_threshold.add_subfulfillment(expected_simple2)
expected_threshold.add_subfulfillment(expected_simple3)
expected.add_subfulfillment(expected_threshold)
expected.add_subfulfillment(expected_simple1)
cond = Output.generate([[expected_simple2, user3_pub], user_pub], 1)
assert cond.fulfillment.to_dict() == expected.to_dict()
示例15: base58decode
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58decode [as 別名]
def base58decode(i):
return base58.b58decode(str(i)).decode()