Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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)
"""
sha256 = hashlib.sha256()
sha256.update(key)
key_hash = sha256.digest()
ripemd = hashlib.new('ripemd')
ripemd.update(key_hash)
key_hash = ripemd.digest()
sha256 = hashlib.sha256()
sha256.update(FINGER_PREFIX)
sha256.update(key_hash)
checksum = sha256.digest()
result = FINGER_PREFIX+key_hash+checksum[:4]
return base58.b58encode(result)
def to_public_key(cls, election_id):
return base58.b58encode(bytes.fromhex(election_id)).decode()
: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
def multibase_b58encode(data):
"""
Follow forge's base58 encode convention to encode bytes.
Args:
data(bytes): data to be encoded
Returns:
string
Examples:
>>> multibase_b58encode(b'hello')
'zCn8eVZg'
"""
raw = base58.b58encode(data)
return 'z' + raw.decode()
async def decode_msg(msg):
return {
'from': base58.b58encode(msg.from_id),
'data': msg.data,
'seqno': base58.b58encode(msg.seqno),
'topicIDs': msg.topicIDs
}
def to_base58(family):
return base58.b58encode(family.encode('utf-8')).decode('utf-8')
def rawToFriendly(raw):
return base58.b58encode(raw).decode("utf-8")
def privateKeyGenerator():
hexstart = "80" + start[0:64]
bytehex = str(bytearray.fromhex(hexstart))
hash1 = hashlib.sha256(bytehex).hexdigest()
bytehex2 = str(bytearray.fromhex(hash1))
hash2 = hashlib.sha256(bytehex2).hexdigest()
checksum = hash2[0:8]
hexfinal = hexstart + checksum
unencoded_final = str(bytearray.fromhex(hexfinal))
encoded_final = base58.b58encode(unencoded_final)
privFile = encoded_final[-8:]
print("Private Key: " + encoded_final)
img = qrcode.make(encoded_final)
img.save("Key_" + privFile + ".png")
return