Ejemplo n.º 1
0
def sign_transfer(private_key: str, tx: TransferToken) -> dict:
    from lunespy.crypto import fast_signature
    from lunespy.crypto import b58_to_bytes, bytes_to_b58

    tx.message = bytes_to_b58(serialize_transfer(tx))

    return bytes_to_b58(
        fast_signature(b58_to_bytes(private_key), b58_to_bytes(tx.message)))
Ejemplo n.º 2
0
def sign_issue(private_key: str, tx: IssueToken) -> str:
    from lunespy.crypto import fast_signature
    from lunespy.crypto import b58_to_bytes, bytes_to_b58

    tx.message = bytes_to_b58(serialize_issue(tx))

    return bytes_to_b58(
        fast_signature(b58_to_bytes(private_key), b58_to_bytes(tx.message)))
Ejemplo n.º 3
0
def test_signature_of_transfer(sign_tx: TransferToken):
    from lunespy.crypto import validate_signature
    from lunespy.crypto import b58_to_bytes

    assert True == validate_signature(
        b58_to_bytes(sign_tx.senderPublicKey),
        b58_to_bytes(sign_tx.message),
        b58_to_bytes(sign_tx.signature),
    )
Ejemplo n.º 4
0
def serialize_sponsor(tx: SponsorToken) -> bytes:
    from lunespy.crypto import b58_to_bytes
    from struct import pack

    return (
        chr(tx.type).encode() + \
        b'\1' + \
        b58_to_bytes(tx.senderPublicKey) + \
        b58_to_bytes(tx.assetId) + \
        pack(">Q", tx.minSponsoredAssetFee) + \
        pack(">Q", tx.fee) + \
        pack(">Q", tx.timestamp)
    )
Ejemplo n.º 5
0
def serialize_transfer(tx: TransferToken) -> bytes:
    from lunespy.crypto import b58_to_bytes
    from struct import pack

    return (
        chr(tx.type).encode() + \
        b58_to_bytes(tx.senderPublicKey) + \
        (b'\1' + b58_to_bytes(tx.assetId) if tx.assetId != "" else b'\0') + \
        (b'\1' + b58_to_bytes(tx.feeAsset) if tx.feeAsset != "" else b'\0') + \
        pack(">Q", tx.timestamp) + \
        pack(">Q", tx.amount) + \
        pack(">Q", tx.fee) + \
        b58_to_bytes(tx.recipient)
    )
Ejemplo n.º 6
0
def from_private_key(private_key: str, chain: int = 1):
    from lunespy.crypto import bytes_to_b58, b58_to_bytes, to_address, to_private_key, to_public_key
    from lunespy.wallet import Wallet

    private_key: bytes = to_private_key(b58_to_bytes(private_key))
    public_key: bytes = to_public_key(private_key)
    address: bytes = to_address(public_key, chain, 1)

    return Wallet(private_key=bytes_to_b58(private_key),
                  public_key=bytes_to_b58(public_key),
                  address=bytes_to_b58(address),
                  seed_len=0,
                  nonce=0,
                  chain=chain,
                  seed="")
Ejemplo n.º 7
0
def transfer_token_factory(sender_public_key: str,
                           receiver_address: str,
                           amount: float,
                           chain: int = 1,
                           asset_id: str = "",
                           **kwargs: dict) -> TransferToken:
    from lunespy.crypto import b58_to_bytes, bytes_to_b58, to_address

    return TransferToken(sender=bytes_to_b58(
        to_address(b58_to_bytes(sender_public_key), chain, 1)),
                         amount=int(amount * 10e7),
                         senderPublicKey=sender_public_key,
                         recipient=receiver_address,
                         assetId=asset_id,
                         **kwargs)
Ejemplo n.º 8
0
def serialize_issue(tx: IssueToken) -> bytes:
    from lunespy.crypto import b58_to_bytes
    from struct import pack

    return (
        chr(tx.type).encode() + \
        b58_to_bytes(tx.senderPublicKey) + \
        pack(">H", len(tx.name)) + \
        tx.name.encode("latin-1") + \
        pack(">H", len(tx.description)) + \
        tx.description.encode("latin-1") + \
        pack(">Q", tx.quantity) + \
        pack(">B", tx.decimals) + \
        (b'\1' if tx.reissuable else b'\0') + \
        pack(">Q", tx.fee) + \
        pack(">Q", tx.timestamp)
    )