Search in sources :

Example 1 with ISignature

use of org.aion.crypto.ISignature in project aion by aionnetwork.

the class AionTransaction method rlpParse.

public void rlpParse() {
    RLPList decodedTxList = RLP.decode2(rlpEncoded);
    RLPList tx = (RLPList) decodedTxList.get(0);
    this.nonce = tx.get(RLP_TX_NONCE).getRLPData();
    this.value = tx.get(RLP_TX_VALUE).getRLPData();
    this.data = tx.get(RLP_TX_DATA).getRLPData();
    if (tx.get(RLP_TX_TO).getRLPData() == null) {
        this.to = null;
    } else {
        this.to = Address.wrap(tx.get(RLP_TX_TO).getRLPData());
    }
    this.timeStamp = tx.get(RLP_TX_TIMESTAMP).getRLPData();
    this.nrg = new BigInteger(1, tx.get(RLP_TX_NRG).getRLPData()).longValue();
    this.nrgPrice = new BigInteger(1, tx.get(RLP_TX_NRGPRICE).getRLPData()).longValue();
    this.type = new BigInteger(1, tx.get(RLP_TX_TYPE).getRLPData()).byteValue();
    byte[] sigs = tx.get(RLP_TX_SIG).getRLPData();
    if (sigs != null) {
        // Singature Factory will decode the signature based on the algo
        // presetted in main() entry.
        ISignature is = SignatureFac.fromBytes(sigs);
        if (is != null) {
            this.signature = is;
        } else {
            // still ok if signature is null, but log it out.
            this.signature = null;
            LOG.error("tx -> unable to decode signature");
        }
    } else {
        LOG.error("tx -> no signature found");
    }
    this.parsed = true;
    this.hash = getHash();
}
Also used : BigInteger(java.math.BigInteger) RLPList(org.aion.rlp.RLPList) ISignature(org.aion.crypto.ISignature)

Example 2 with ISignature

use of org.aion.crypto.ISignature in project aion by aionnetwork.

the class TXValidator method isValid.

// TODO : MOVE ISignature to aionbase, and then use interface as an input
public static boolean isValid(AionTransaction tx) {
    byte[] check = tx.getNonce();
    if (check == null || check.length > DataWord.BYTES) {
        LOG.error("invalid tx nonce!");
        return false;
    }
    check = tx.getTimeStamp();
    if (check == null || check.length > Long.BYTES) {
        LOG.error("invalid tx timestamp!");
        return false;
    }
    check = tx.getValue();
    if (check == null || check.length > DataWord.BYTES) {
        LOG.error("invalid tx value!");
        return false;
    }
    check = tx.getData();
    if (check == null) {
        LOG.error("invalid tx data!");
        return false;
    }
    long nrg = tx.getNrg();
    if (nrg < 0 || nrg > Long.MAX_VALUE) {
        LOG.error("invalid tx nrg!");
        return false;
    }
    nrg = tx.getNrgPrice();
    if (nrg < 0 || nrg > Long.MAX_VALUE) {
        LOG.error("invalid tx nrgprice!");
        return false;
    }
    byte[] hash = tx.getRawHash();
    if (hash == null || hash.length != Hash256.BYTES) {
        LOG.error("invalid tx raw hash!");
        return false;
    }
    ISignature sig = tx.getSignature();
    if (sig == null) {
        LOG.error("invalid tx signature!");
        return false;
    }
    try {
        return SignatureFac.verify(hash, sig);
    } catch (Exception ex) {
        ex.printStackTrace();
        return false;
    }
}
Also used : ISignature(org.aion.crypto.ISignature)

Aggregations

ISignature (org.aion.crypto.ISignature)2 BigInteger (java.math.BigInteger)1 RLPList (org.aion.rlp.RLPList)1