Python base58.b58encode() Examples
The following are 30
code examples of base58.b58encode().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
base58
, or try the search function
.
Example #1
Source File: utils.py From btcposbal2csv with BSD 3-Clause "New" or "Revised" License | 6 votes |
def hash_160_to_btc_address(h160, v): """ Calculates the Bitcoin address of a given RIPEMD-160 hash from an elliptic curve public key. :param h160: RIPEMD-160 hash. :type h160: bytes :param v: version (prefix) used to calculate the Bitcoin address. Possible values: - 0 for main network (PUBKEY_HASH). - 111 For testnet (TESTNET_PUBKEY_HASH). :type v: int :return: The corresponding Bitcoin address. :rtype: hex str """ # If h160 is passed as hex str, the value is converted into bytes. if match('^[0-9a-fA-F]*$', h160): h160 = unhexlify(h160) # Add the network version leading the previously calculated RIPEMD-160 hash. vh160 = chr(v) + h160 # Double sha256. h = sha256(sha256(vh160).digest()).digest() # Add the two first bytes of the result as a checksum tailing the RIPEMD-160 hash. addr = vh160 + h[0:4] # Obtain the Bitcoin address by Base58 encoding the result addr = b58encode(addr) return addr
Example #2
Source File: test_client.py From old-sovrin with Apache License 2.0 | 6 votes |
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)
Example #3
Source File: dataformat.py From chepy with GNU General Public License v3.0 | 6 votes |
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
Example #4
Source File: test_get_value_from_state.py From indy-plenum with Apache License 2.0 | 6 votes |
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)
Example #5
Source File: ss58.py From py-scale-codec with GNU General Public License v3.0 | 6 votes |
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()
Example #6
Source File: test_transaction.py From bigchaindb with Apache License 2.0 | 6 votes |
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
Example #7
Source File: test_transaction.py From bigchaindb with Apache License 2.0 | 6 votes |
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
Example #8
Source File: transaction.py From bigchaindb with Apache License 2.0 | 6 votes |
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)
Example #9
Source File: transaction.py From Decentralized-Internet with MIT License | 6 votes |
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)
Example #10
Source File: test_transaction.py From Decentralized-Internet with MIT License | 6 votes |
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
Example #11
Source File: test_transaction.py From Decentralized-Internet with MIT License | 6 votes |
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
Example #12
Source File: account.py From ontology-python-sdk with GNU Lesser General Public License v3.0 | 6 votes |
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')
Example #13
Source File: address.py From PyWaves with MIT License | 5 votes |
def _generate(self, publicKey='', privateKey='', seed='', nonce=0): self.seed = seed self.nonce = nonce if not publicKey and not privateKey and not seed: wordCount = 2048 words = [] for i in range(5): r = crypto.bytes2str(os.urandom(4)) x = (ord(r[3])) + (ord(r[2]) << 8) + (ord(r[1]) << 16) + (ord(r[0]) << 24) w1 = x % wordCount w2 = ((int(x / wordCount) >> 0) + w1) % wordCount w3 = ((int((int(x / wordCount) >> 0) / wordCount) >> 0) + w2) % wordCount words.append(wordList[w1]) words.append(wordList[w2]) words.append(wordList[w3]) self.seed = ' '.join(words) if publicKey: pubKey = base58.b58decode(publicKey) privKey = "" else: seedHash = crypto.hashChain(struct.pack(">L", nonce) + crypto.str2bytes(self.seed)) accountSeedHash = crypto.sha256(seedHash) if not privateKey: privKey = curve.generatePrivateKey(accountSeedHash) else: privKey = base58.b58decode(privateKey) pubKey = curve.generatePublicKey(privKey) unhashedAddress = chr(1) + str(self.pywaves.CHAIN_ID) + crypto.hashChain(pubKey)[0:20] addressHash = crypto.hashChain(crypto.str2bytes(unhashedAddress))[0:4] self.address = base58.b58encode(crypto.str2bytes(unhashedAddress + addressHash)) self.publicKey = base58.b58encode(pubKey) if privKey != "": self.privateKey = base58.b58encode(privKey)
Example #14
Source File: election.py From Decentralized-Internet with MIT License | 5 votes |
def to_public_key(cls, election_id): return base58.b58encode(bytes.fromhex(election_id)).decode()
Example #15
Source File: utils_ipfs.py From snet-cli with MIT License | 5 votes |
def get_from_ipfs_and_checkhash(ipfs_client, ipfs_hash_base58, validate=True): """ Get file from ipfs We must check the hash becasue we cannot believe that ipfs_client wasn't been compromise """ if validate: from snet.snet_cli.resources.proto.unixfs_pb2 import Data from snet.snet_cli.resources.proto.merckledag_pb2 import MerkleNode # No nice Python library to parse ipfs blocks, so do it ourselves. block_data = ipfs_client.block_get(ipfs_hash_base58) mn = MerkleNode() mn.ParseFromString(block_data) unixfs_data = Data() unixfs_data.ParseFromString(mn.Data) assert unixfs_data.Type == unixfs_data.DataType.Value( 'File'), "IPFS hash must be a file" data = unixfs_data.Data # multihash has a badly registered base58 codec, overwrite it... multihash.CodecReg.register( 'base58', base58.b58encode, base58.b58decode) # create a multihash object from our ipfs hash mh = multihash.decode(ipfs_hash_base58.encode('ascii'), 'base58') # Convenience method lets us directly use a multihash to verify data if not mh.verify(block_data): raise Exception("IPFS hash mismatch with data") else: data = ipfs_client.cat(ipfs_hash_base58) return data
Example #16
Source File: util.py From ontology-python-compiler with GNU Lesser General Public License v3.0 | 5 votes |
def b58encode(self): script_builder = Address.__COIN_VERSION + self.ZERO c256 = Digest.hash256(script_builder)[0:4] out_byte_array = script_builder + bytearray(c256) return base58.b58encode(bytes(out_byte_array)).decode('utf-8')
Example #17
Source File: encodings.py From claimchain-core with MIT License | 5 votes |
def pet2ascii(p): """ >>> from petlib.ec import EcGroup, EcPt >>> G = EcGroup() >>> pt = EcPt(G) >>> pet2ascii(pt) '3Xw3vNAdCmDLs' """ return ensure_text(b58encode(encode(p)))
Example #18
Source File: election.py From bigchaindb with Apache License 2.0 | 5 votes |
def to_public_key(cls, election_id): return base58.b58encode(bytes.fromhex(election_id)).decode()
Example #19
Source File: client.py From old-sovrin with Apache License 2.0 | 5 votes |
def doAttrDisclose(self, origin, target, txnId, key): box = libnacl.public.Box(b58decode(origin), b58decode(target)) data = json.dumps({TXN_ID: txnId, SKEY: key}) nonce, boxedMsg = box.encrypt(data.encode(), pack_nonce=False) op = { TARGET_NYM: target, TXN_TYPE: DISCLO, NONCE: b58encode(nonce), DATA: b58encode(boxedMsg) } self.submit(op, identifier=origin)
Example #20
Source File: test_address.py From ledger-api-py with Apache License 2.0 | 5 votes |
def _calc_address(public_key_bytes): bytes = sha256_hash(public_key_bytes) display_bytes = bytes + sha256_hash(bytes)[:4] display = base58.b58encode(display_bytes).decode() return bytes, display
Example #21
Source File: keys.py From eospy with MIT License | 5 votes |
def _check_encode(self, key_buffer, key_type=None) : ''' ''' if isinstance(key_buffer, bytes) : key_buffer = key_buffer.decode() check = key_buffer if key_type == 'sha256x2' : first_sha = sha256(unhexlify(check)) chksum = sha256(unhexlify(first_sha))[:8] else : if key_type : check += hexlify(bytearray(key_type,'utf-8')).decode() chksum = ripemd160(unhexlify(check))[:8] return base58.b58encode(unhexlify(key_buffer+chksum))
Example #22
Source File: base.py From agents-aea with Apache License 2.0 | 5 votes |
def _generate_multihash(self, pb_data: bytes) -> str: """ Generate an IPFS multihash. Uses the default IPFS hashing function: sha256 :param pb_data: the data to be hashed :return: string representing the hash """ sha256_hash = hashlib.sha256(pb_data).hexdigest() multihash_hex = SHA256_ID + LEN_SHA256 + sha256_hash multihash_bytes = codecs.decode(str.encode(multihash_hex), "hex") ipfs_hash = base58.b58encode(multihash_bytes) return str(ipfs_hash, "utf-8")
Example #23
Source File: format.py From PBinCLI with MIT License | 5 votes |
def getHash(self): if self._version == 2: from base58 import b58encode return b58encode(self._key).decode() else: return b64encode(self._key).decode()
Example #24
Source File: utils.py From indy-node with Apache License 2.0 | 5 votes |
def random_seed_and_json(): return base58.b58encode(random_string(23)).decode(),\ json.dumps({'seed': base58.b58encode(random_string(23)).decode()})
Example #25
Source File: crypto.py From PyWaves with MIT License | 5 votes |
def id(message): return base58.b58encode(hashlib.sha256(message).digest())
Example #26
Source File: crypto.py From PyWaves with MIT License | 5 votes |
def sign(privateKey, message): random64 = os.urandom(64) return base58.b58encode(curve.calculateSignature(random64, base58.b58decode(privateKey), message))
Example #27
Source File: components.py From lbry-sdk with MIT License | 5 votes |
def get_node_id(self): node_id_filename = os.path.join(self.conf.data_dir, "node_id") if os.path.isfile(node_id_filename): with open(node_id_filename, "r") as node_id_file: return base58.b58decode(str(node_id_file.read()).strip()) node_id = utils.generate_id() with open(node_id_filename, "w") as node_id_file: node_id_file.write(base58.b58encode(node_id).decode()) return node_id
Example #28
Source File: utils.py From indy-node with Apache License 2.0 | 5 votes |
def random_did_and_json(): return base58.b58encode(random_string(16)).decode(),\ json.dumps({'did': base58.b58encode(random_string(16)).decode()})
Example #29
Source File: crypto.py From deadlock with GNU Affero General Public License v3.0 | 5 votes |
def userID(self): return base58.b58encode( self.public_key.encode() + pyblake2.blake2s(self.public_key.encode(), 1).digest() )
Example #30
Source File: perf_utils.py From indy-node with Apache License 2.0 | 5 votes |
def rawToFriendly(raw): return base58.b58encode(raw).decode("utf-8") # Copied from Plenum