Search in sources :

Example 6 with ValidateSignatureException

use of org.tron.core.exception.ValidateSignatureException in project java-tron by tronprotocol.

the class TransactionCapsule method validateSignature.

/**
 * validate signature
 */
public boolean validateSignature() throws ValidateSignatureException {
    if (this.getInstance().getSignatureCount() != this.getInstance().getRawData().getContractCount()) {
        throw new ValidateSignatureException("miss sig or contract");
    }
    List<Transaction.Contract> listContract = this.transaction.getRawData().getContractList();
    for (int i = 0; i < this.transaction.getSignatureCount(); ++i) {
        try {
            Transaction.Contract contract = listContract.get(i);
            byte[] owner = getOwner(contract);
            byte[] address = ECKey.signatureToAddress(getRawHash().getBytes(), getBase64FromByteString(this.transaction.getSignature(i)));
            if (!Arrays.equals(owner, address)) {
                throw new ValidateSignatureException("sig error");
            }
        } catch (SignatureException e) {
            throw new ValidateSignatureException(e.getMessage());
        }
    }
    return true;
}
Also used : Transaction(org.tron.protos.Protocol.Transaction) ValidateSignatureException(org.tron.core.exception.ValidateSignatureException) SignatureException(java.security.SignatureException) ValidateSignatureException(org.tron.core.exception.ValidateSignatureException) DeployContract(org.tron.protos.Contract.DeployContract) WitnessUpdateContract(org.tron.protos.Contract.WitnessUpdateContract) AccountCreateContract(org.tron.protos.Contract.AccountCreateContract) AssetIssueContract(org.tron.protos.Contract.AssetIssueContract) VoteWitnessContract(org.tron.protos.Contract.VoteWitnessContract) VoteAssetContract(org.tron.protos.Contract.VoteAssetContract) TransferContract(org.tron.protos.Contract.TransferContract) TransferAssetContract(org.tron.protos.Contract.TransferAssetContract) WitnessCreateContract(org.tron.protos.Contract.WitnessCreateContract) ParticipateAssetIssueContract(org.tron.protos.Contract.ParticipateAssetIssueContract)

Aggregations

ValidateSignatureException (org.tron.core.exception.ValidateSignatureException)6 ContractExeException (org.tron.core.exception.ContractExeException)4 ContractValidateException (org.tron.core.exception.ContractValidateException)4 BlockCapsule (org.tron.core.capsule.BlockCapsule)3 Dialog (org.tron.core.db.AbstractRevokingStore.Dialog)3 RevokingStoreIllegalStateException (org.tron.core.exception.RevokingStoreIllegalStateException)3 UnLinkedBlockException (org.tron.core.exception.UnLinkedBlockException)2 ByteString (com.google.protobuf.ByteString)1 SignatureException (java.security.SignatureException)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1 NumberMessage (org.tron.api.GrpcAPI.NumberMessage)1 ECKey (org.tron.common.crypto.ECKey)1 Message (org.tron.common.overlay.message.Message)1 TransactionCapsule (org.tron.core.capsule.TransactionCapsule)1 WitnessCapsule (org.tron.core.capsule.WitnessCapsule)1 BalanceInsufficientException (org.tron.core.exception.BalanceInsufficientException)1 HighFreqException (org.tron.core.exception.HighFreqException)1 TransactionMessage (org.tron.core.net.message.TransactionMessage)1 AccountCreateContract (org.tron.protos.Contract.AccountCreateContract)1