Ejemplo n.º 1
0
def sendAsset(pubKey, privKey, recipient, assetId, amount, txfee):
    timestamp = int(time.time() * 1000)
    sData = '\4' + base58.b58decode(
        pubKey) + '\1' + base58.b58decode(assetId) + '\0' + struct.pack(
            ">Q", timestamp) + struct.pack(">Q", amount) + struct.pack(
                ">Q", txfee) + base58.b58decode(recipient) + '\0\0'
    random64 = os.urandom(64)
    signature = base58.b58encode(
        curve.calculateSignature(random64, base58.b58decode(privKey), sData))

    data = json.dumps({
        "assetId": assetId,
        "senderPublicKey": pubKey,
        "recipient": recipient,
        "amount": amount,
        "fee": txfee,
        "timestamp": timestamp,
        "attachment": "",
        "signature": signature
    })

    c = pycurl.Curl()
    c.setopt(pycurl.URL,
             "http://%s:%s/assets/broadcast/transfer" % (NODE_IP, NODE_PORT))
    c.setopt(pycurl.HTTPHEADER,
             ['Content-Type: application/json', 'Accept: application/json'])
    c.setopt(pycurl.POST, 1)
    c.setopt(pycurl.POSTFIELDS, data)
    c.perform()
    c.close()
Ejemplo n.º 2
0
def signUid(private_key, uid):
    """
    Create an Ed25519 signature for UID
    :param private_key: Binary representation of Ed25519 key
    :param uid: UID, decoded to binary from hex
    :return: singature in binary format
    """
    random64 = os.urandom(64)
    signature = curve.calculateSignature(random64, private_key, uid)
    return signature
Ejemplo n.º 3
0
 def calculateSignature(privateSigningKey ,message):
     """
     :type privateSigningKey: ECPrivateKey
     :type  message: bytearray
     """
     if privateSigningKey.getType() == Curve.DJB_TYPE:
         rand = os.urandom(64)
         res = _curve.calculateSignature(rand, privateSigningKey.getPrivateKey(), message)
         return res
     else:
         raise InvalidKeyException("Unknown type: %s" % privateSigningKey.getType())
Ejemplo n.º 4
0
 def calculateSignature(privateSigningKey, message):
     """
     :type privateSigningKey: ECPrivateKey
     :type  message: bytearray
     """
     if privateSigningKey.getType() == Curve.DJB_TYPE:
         rand = os.urandom(64)
         res = _curve.calculateSignature(rand, privateSigningKey.getPrivateKey(), message)
         return res
     else:
         raise InvalidKeyException("Unknown type: %s" % privateSigningKey.getType())
Ejemplo n.º 5
0
def sign_with_private_key(private_key, data):
    """
    Sign data with private key

    :param private_key: private key value in base58
    :type private_key: str
    :param data: data to sign
    :type data: bytes
    :return: signed data
    :rtype: bytes
    """
    random_bytes = os.urandom(64)
    signed_data = base58.b58encode(
        axolotl_curve25519.calculateSignature(random_bytes, base58.b58decode(private_key), data)
    ).decode()
    return signed_data
Ejemplo n.º 6
0
def postOrder(pubKey, privateKey, spendAssetId, receiveAssetId, price, amount):
    sData = base58.b58decode(pubKey) + base58.b58decode(
        MATCHER_PUBLIC_KEY) + "\1" + base58.b58decode(
            spendAssetId) + "\1" + base58.b58decode(
                receiveAssetId) + struct.pack(">Q", price) + struct.pack(
                    ">Q", amount) + struct.pack(
                        ">Q", maxTimestamp) + struct.pack(">Q", MATCHER_FEE)
    random64 = os.urandom(64)
    id = base58.b58encode(hashlib.sha256(sData).digest())
    signature = base58.b58encode(
        curve.calculateSignature(random64, base58.b58decode(privateKey),
                                 sData))

    data = json.dumps({
        "id": id,
        "sender": pubKey,
        "matcher": MATCHER_PUBLIC_KEY,
        "spendAssetId": spendAssetId,
        "receiveAssetId": receiveAssetId,
        "price": price,
        "amount": amount,
        "maxTimestamp": maxTimestamp,
        "matcherFee": MATCHER_FEE,
        "signature": signature
    })

    c = pycurl.Curl()
    c.setopt(pycurl.URL,
             "http://%s:%s/matcher/orders/place" % (MATCHER_IP, MATCHER_PORT))
    c.setopt(pycurl.HTTPHEADER,
             ['Content-Type: application/json', 'Accept: application/json'])
    c.setopt(pycurl.POST, 1)
    c.setopt(pycurl.POSTFIELDS, data)
    c.perform()
    print
    print
Ejemplo n.º 7
0
        8, byteorder='big'
    ),  #'timestamp' : (1479287120875).to_bytes(8, byteorder='big')
    'amount': (1).to_bytes(8, byteorder='big'),  # amount = 1
    'fee': (1).to_bytes(8, byteorder='big'),  # fee = 1
    'recip_address': b58decode('3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8'),
    'att': (4).to_bytes(2, byteorder='big'),
    'att_bytes': b58decode('2VfUX')
}

tx = b''
for key, value in comp.items():
    #print("{0}: {1}".format(key, b58encode(value)))
    tx += value

randm64 = os.urandom(64)
sign = curve.calculateSignature(randm64, k_pr, tx)
#print(b58encode(sign))
#sign = crypto.sign(b58encode(k_pr), tx)
#print(sign)

#print('result')
#print(b58encode(tx + sign))

data = json.dumps({
    "senderPublicKey": b58encode(k_pub),
    "recipient": '3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8',
    "amount": 300000000,
    "fee": 100000,
    "timestamp": int(time.time() * 1000),
    "attachment": '2VfUX',
    "signature": b58encode(sign)
Ejemplo n.º 8
0
 def calculateSignature(self, private_key, message):
     return axolotl_curve25519.calculateSignature(os.urandom(32),
                                                  private_key, message)
Ejemplo n.º 9
0
def sign(privateKey, message):
    random64 = os.urandom(64)
    return curve_waveslib.calculateSignature(random64, privateKey, message)
Ejemplo n.º 10
0
def sign(privateKey, message):
    random64 = os.urandom(64)

    return base58.b58encode(
        curve.calculateSignature(random64, base58.b58decode(privateKey),
                                 message))
Ejemplo n.º 11
0
import base58
import binascii
import hashlib
import sys
import axolotl_curve25519 as curve
import os

randm32 = os.urandom(32)
randm64 = os.urandom(64)

private_key = base58.b58decode('3kMEhU5z3v8bmer1ERFUUhW58Dtuhyo9hE5vrhjqAWYT')
message = b'test'

signature = curve.calculateSignature(randm64, private_key, message)
print(signature)