本文整理匯總了Python中base58.b58encode方法的典型用法代碼示例。如果您正苦於以下問題:Python base58.b58encode方法的具體用法?Python base58.b58encode怎麽用?Python base58.b58encode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類base58
的用法示例。
在下文中一共展示了base58.b58encode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: export_gcm_encrypted_private_key
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58encode [as 別名]
def export_gcm_encrypted_private_key(self, password: str, salt: str, n: int = 16384) -> str:
"""
This interface is used to export an AES algorithm encrypted private key with the mode of GCM.
:param password: the secret pass phrase to generate the keys from.
:param salt: A string to use for better protection from dictionary attacks.
This value does not need to be kept secret, but it should be randomly chosen for each derivation.
It is recommended to be at least 8 bytes long.
:param n: CPU/memory cost parameter. It must be a power of 2 and less than 2**32
:return: an gcm encrypted private key in the form of string.
"""
r = 8
p = 8
dk_len = 64
scrypt = Scrypt(n, r, p, dk_len)
derived_key = scrypt.generate_kd(password, salt)
iv = derived_key[0:12]
key = derived_key[32:64]
hdr = self.__address.b58encode().encode()
mac_tag, cipher_text = AESHandler.aes_gcm_encrypt_with_iv(self.__private_key, hdr, key, iv)
encrypted_key = bytes.hex(cipher_text) + bytes.hex(mac_tag)
encrypted_key_str = base64.b64encode(bytes.fromhex(encrypted_key))
return encrypted_key_str.decode('utf-8')
示例2: create_bls_multi_sig
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58encode [as 別名]
def create_bls_multi_sig(encoded_root_hash):
pool_state_root_hash = base58.b58encode(b"somefakepoolroothashsomefakepoolroothash").decode("utf-8")
txn_root_hash = base58.b58encode(b"somefaketxnroothashsomefaketxnroothash").decode("utf-8")
ledger_id = 1
timestamp = get_utc_epoch()
value = MultiSignatureValue(ledger_id=ledger_id,
state_root_hash=encoded_root_hash,
pool_state_root_hash=pool_state_root_hash,
txn_root_hash=txn_root_hash,
timestamp=timestamp)
sign = "1q" * 16
participants = ["q" * 32, "w" * 32, "e" * 32, "r" * 32]
return MultiSignature(sign, participants, value)
示例3: base58_encode
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58encode [as 別名]
def base58_encode(self):
"""Encode 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 encodes raw data
into an ASCII Base58 string.
Returns:
Chepy: The Chepy object.
Examples:
>>> Chepy("some data").base58_encode().output.decode()
"2UDrs31qcWSPi"
"""
self.state = base58.b58encode(self._convert_to_bytes())
return self
示例4: testSponsorDisclosesEncryptedAttribute
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58encode [as 別名]
def testSponsorDisclosesEncryptedAttribute(addedEncryptedAttribute, symEncData,
looper, userSignerA, sponsorSigner,
sponsor):
box = libnacl.public.Box(sponsorSigner.naclSigner.keyraw,
userSignerA.naclSigner.verraw)
data = json.dumps({SKEY: symEncData.secretKey,
TXN_ID: addedEncryptedAttribute[TXN_ID]})
nonce, boxedMsg = box.encrypt(data.encode(), pack_nonce=False)
op = {
TARGET_NYM: userSignerA.verstr,
TXN_TYPE: ATTRIB,
NONCE: base58.b58encode(nonce),
ENC: base58.b58encode(boxedMsg)
}
submitAndCheck(looper, sponsor, op,
identifier=sponsorSigner.verstr)
示例5: ss58_encode
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58encode [as 別名]
def ss58_encode(address, address_type=42):
checksum_prefix = b'SS58PRE'
if type(address) is bytes or type(address) is bytearray:
address_bytes = address
else:
address_bytes = bytes.fromhex(address)
if len(address_bytes) == 32:
# Checksum size is 2 bytes for public key
checksum_length = 2
elif len(address_bytes) in [1, 2, 4, 8]:
# Checksum size is 1 byte for account index
checksum_length = 1
else:
raise ValueError("Invalid length for address")
address_format = bytes([address_type]) + address_bytes
checksum = blake2b(checksum_prefix + address_format).digest()
return base58.b58encode(address_format + checksum[:checksum_length]).decode()
示例6: test_output_serialization
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58encode [as 別名]
def test_output_serialization(user_Ed25519, user_pub):
from bigchaindb.common.transaction import Output
expected = {
'condition': {
'uri': user_Ed25519.condition_uri,
'details': {
'type': 'ed25519-sha-256',
'public_key': b58encode(user_Ed25519.public_key).decode(),
},
},
'public_keys': [user_pub],
'amount': '1',
}
cond = Output(user_Ed25519, [user_pub], 1)
assert cond.to_dict() == expected
示例7: test_output_deserialization
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58encode [as 別名]
def test_output_deserialization(user_Ed25519, user_pub):
from bigchaindb.common.transaction import Output
expected = Output(user_Ed25519, [user_pub], 1)
cond = {
'condition': {
'uri': user_Ed25519.condition_uri,
'details': {
'type': 'ed25519-sha-256',
'public_key': b58encode(user_Ed25519.public_key).decode(),
},
},
'public_keys': [user_pub],
'amount': '1',
}
cond = Output.from_dict(cond)
assert cond == expected
示例8: _fulfillment_to_details
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58encode [as 別名]
def _fulfillment_to_details(fulfillment):
"""Encode a fulfillment as a details dictionary
Args:
fulfillment: Crypto-conditions Fulfillment object
"""
if fulfillment.type_name == 'ed25519-sha-256':
return {
'type': 'ed25519-sha-256',
'public_key': base58.b58encode(fulfillment.public_key).decode(),
}
if fulfillment.type_name == 'threshold-sha-256':
subconditions = [
_fulfillment_to_details(cond['body'])
for cond in fulfillment.subconditions
]
return {
'type': 'threshold-sha-256',
'threshold': fulfillment.threshold,
'subconditions': subconditions,
}
raise UnsupportedTypeError(fulfillment.type_name)
示例9: base58encode
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58encode [as 別名]
def base58encode(i):
return base58.b58encode(str(i).encode())
示例10: get_address_base58
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58encode [as 別名]
def get_address_base58(self) -> str:
"""
This interface is used to get the base58 encode account address.
:return:
"""
return self.__address.b58encode()
示例11: get_gcm_decoded_private_key
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58encode [as 別名]
def get_gcm_decoded_private_key(encrypted_key_str: str, password: str, b58_address: str, salt: str, n: int,
scheme: SignatureScheme) -> str:
"""
This interface is used to decrypt an private key which has been encrypted.
:param encrypted_key_str: an gcm encrypted private key in the form of string.
:param password: the secret pass phrase to generate the keys from.
:param b58_address: a base58 encode address which should be correspond with the private key.
:param salt: a string to use for better protection from dictionary attacks.
:param n: CPU/memory cost parameter.
:param scheme: the signature scheme.
:return: a private key in the form of string.
"""
r = 8
p = 8
dk_len = 64
scrypt = Scrypt(n, r, p, dk_len)
derived_key = scrypt.generate_kd(password, salt)
iv = derived_key[0:12]
key = derived_key[32:64]
encrypted_key = base64.b64decode(encrypted_key_str).hex()
mac_tag = bytes.fromhex(encrypted_key[64:96])
cipher_text = bytes.fromhex(encrypted_key[0:64])
private_key = AESHandler.aes_gcm_decrypt_with_iv(cipher_text, b58_address.encode(), mac_tag, key, iv)
if len(private_key) == 0:
raise SDKException(ErrorCode.decrypt_encrypted_private_key_error)
acct = Account(private_key, scheme)
if acct.get_address().b58encode() != b58_address:
raise SDKException(ErrorCode.other_error('Address error.'))
return private_key.hex()
示例12: export_wif
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58encode [as 別名]
def export_wif(self) -> str:
"""
This interface is used to get export ECDSA private key in the form of WIF which
is a way to encoding an ECDSA private key and make it easier to copy.
:return: a WIF encode private key.
"""
data = b''.join([b'\x80', self.__private_key, b'\01'])
checksum = Digest.hash256(data[0:34])
wif = base58.b58encode(b''.join([data, checksum[0:4]]))
return wif.decode('ascii')
示例13: b58encode
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58encode [as 別名]
def b58encode(self):
data = Address.__COIN_VERSION + self.ZERO
checksum = Digest.hash256(data)[0:4]
return base58.b58encode(data + checksum).decode('utf-8')
示例14: __verkey
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58encode [as 別名]
def __verkey(self):
return base58.b58encode(self._node.nodestack.verKey).decode("utf-8")
示例15: getCryptonym
# 需要導入模塊: import base58 [as 別名]
# 或者: from base58 import b58encode [as 別名]
def getCryptonym(identifier):
return base58.b58encode(unhexlify(identifier.encode())).decode() \
if isHexKey(identifier) else identifier