def test_base58encode(self):
     self.assertEqual(['5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ',
                       '5KYZdUEo39z3FPrtuX2QbbwGnNP5zTd7yyr2SC1j299sBCnWjss',
                       '5KfazyjBBtR2YeHjNqX5D6MXvqTUd2iZmWusrdDSUqoykTyWQZB'],
                      [base58encode('800c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d507a5b8d'),
                       base58encode('80e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8555c5bbb26'),
                       base58encode('80f3a375e00cc5147f30bee97bb5d54b31a12eee148a1ac31ac9edc4ecd13bc1f80cc8148e')])
def encode_memo(priv, pub, nonce, message) :
    """ Encode a message with a shared secret between Alice and Bob

        :param PrivateKey priv: Private Key (of Alice)
        :param PublicKey pub: Public Key (of Bob)
        :param int nonce: Random nonce
        :param str message: Memo message
        :return: Encrypted message
        :rtype: hex

    """
    from steembase import transactions
    shared_secret = get_shared_secret(priv, pub)
    aes, check    = init_aes(shared_secret, nonce)
    raw           = varint(len(message)) + bytes(message, 'utf8')
    " Padding "
    BS    = 16
    if len(raw) % BS:
        raw = _pad(raw, BS)
    " Encryption "
    cipher = hexlify(aes.encrypt(raw)).decode('ascii')
    s = {
        "from": format(priv.pubkey, prefix),
        "to": format(pub, prefix),
        "nonce": nonce,
        "check": check,
        "encrypted": cipher,
        "from_priv": repr(priv),
        "to_pub": repr(pub),
        "shared_secret": shared_secret,
    }
    tx = transactions.Memo(**s)
    return "#" + base58encode(hexlify(bytes(tx)).decode("ascii"))
Exemple #3
0
def pts_address(pubkey, compressed, ver, prefix):
    if compressed:
        pubkeybin = PublicKey(pubkey, **{"prefix": prefix}).__bytes__()
    else:
        pubkeybin = unhexlify(
            PublicKey(pubkey, **{
                "prefix": prefix
            }).unCompressed())

    #print(hexlify(pubkeybin),len(pubkeybin))
    bin = '%02x' % (ver) + hexlify(
        ripemd160(hexlify(hashlib.sha256(pubkeybin).digest()).decode(
            'ascii'))).decode("ascii")
    checksum = doublesha256(bin)

    #print('bin',bin)
    #print('csum1',checksum)
    hex = bin + hexlify(checksum[:4]).decode('ascii')
    #print('hex',hex)
    hash = hexlify(ripemd160(hex)).decode('ascii')
    #print('hash',hash)
    checksum2 = ripemd160(hash)
    #print('csum2',checksum2)
    b58 = prefix + base58encode(hash + hexlify(checksum2[:4]).decode('ascii'))
    #print('b58',b58)
    return b58
Exemple #4
0
def encode_memo(priv, pub, nonce, message) :
    """ Encode a message with a shared secret between Alice and Bob

        :param PrivateKey priv: Private Key (of Alice)
        :param PublicKey pub: Public Key (of Bob)
        :param int nonce: Random nonce
        :param str message: Memo message
        :return: Encrypted message
        :rtype: hex

    """
    from steembase import transactions
    from graphenebase.base58 import base58encode
    shared_secret = get_shared_secret(priv, pub)
    aes, check    = init_aes(shared_secret, nonce)
    raw           = bytes(message, 'utf8')
    " Padding "
    BS    = 16
    if len(raw) % BS:
        raw = _pad(raw, BS)
    " Encryption "
    cipher = hexlify(aes.encrypt(raw)).decode('ascii')
    s = {
        "from": format(priv.pubkey, prefix),
        "to": format(pub, prefix),
        "nonce": nonce,
        "check": check,
        "encrypted": cipher,
        "from_priv": repr(priv),
        "to_pub": repr(pub),
        "shared_secret": shared_secret,
    }
    tx = transactions.Memo(**s)
    return "#" + base58encode(hexlify(bytes(tx)).decode("ascii"))
Exemple #5
0
def encode_memo(priv, pub, nonce, message, **kwargs):
    """
    Encode a message with a shared secret between Alice and Bob.

    :param PrivateKey priv: Private Key (of Alice)
    :param PublicKey pub: Public Key (of Bob)
    :param int nonce: Random nonce
    :param str message: Memo message
    :return: Encrypted message
    :rtype: hex
    """
    shared_secret = get_shared_secret(priv, pub)
    aes, check = init_aes(shared_secret, nonce)
    raw = bytes(message, "utf8")

    " Padding "
    bs = 16
    if len(raw) % bs:
        raw = _pad(raw, bs)
    " Encryption "
    cipher = hexlify(aes.encrypt(raw)).decode("ascii")
    prefix = kwargs.pop("prefix")
    op = {
        "from": format(priv.pubkey, prefix),
        "to": format(pub, prefix),
        "nonce": nonce,
        "check": check,
        "encrypted": cipher,
    }

    tx = Memo(**op)

    return "#" + base58encode(hexlify(bytes(tx)).decode("ascii"))
Exemple #6
0
invoice = {
    "to":
    "bitshareseurope",
    "to_label":
    "BitShares Europre",
    "currency":
    "EUR",
    "memo":
    "Invoice #1234",
    "line_items": [{
        "label": "Something to Buy",
        "quantity": 1,
        "price": "10.00"
    }, {
        "label": "10 things to Buy",
        "quantity": 10,
        "price": "1.00"
    }],
    "note":
    "Payment for reading awesome documentation",
    "callback":
    "https://bitshares.eu/complete"
}

compressed = lzma.compress(bytes(json.dumps(invoice), 'utf-8'),
                           format=lzma.FORMAT_ALONE)
b58 = base58encode(hexlify(compressed).decode('utf-8'))
url = "https://bitshares.openledger.info/#/invoice/%s" % b58

print(url)
Exemple #7
0
import json
import lzma
from graphenebase.base58 import base58encode, base58decode
from binascii import hexlify, unhexlify

invoice = {
    "to": "bitshareseurope",
    "to_label": "BitShares Europre",
    "currency": "EUR",
    "memo": "Invoice #1234",
    "line_items": [
        {"label": "Something to Buy", "quantity": 1, "price": "10.00"},
        {"label": "10 things to Buy", "quantity": 10, "price": "1.00"}
    ],
    "note": "Payment for reading awesome documentation",
    "callback": "https://bitshares.eu/complete"
}

compressed = lzma.compress(bytes(json.dumps(invoice), 'utf-8'), format=lzma.FORMAT_ALONE)
b58 = base58encode(hexlify(compressed).decode('utf-8'))
url = "https://bitshares.openledger.info/#/invoice/%s" % b58

print(url)