Search in sources :

Example 16 with ECKey

use of io.nuls.core.tools.crypto.ECKey in project nuls by nuls-io.

the class Account method lock.

/**
 * 锁定账户
 * Lock account
 */
public void lock() {
    if (!isEncrypted()) {
        return;
    }
    if (this.getEcKey().getEncryptedPrivateKey() != null) {
        ECKey result = ECKey.fromEncrypted(getEcKey().getEncryptedPrivateKey(), getPubKey());
        this.setPriKey(new byte[0]);
        this.setEcKey(result);
    }
}
Also used : ECKey(io.nuls.core.tools.crypto.ECKey)

Example 17 with ECKey

use of io.nuls.core.tools.crypto.ECKey in project nuls by nuls-io.

the class TxSerializeTest method signTransaction.

protected void signTransaction(Transaction tx, ECKey ecKey) {
    NulsDigestData hash = null;
    try {
        hash = NulsDigestData.calcDigestData(tx.serializeForHash());
    } catch (IOException e) {
        Log.error(e);
    }
    tx.setHash(hash);
    List<ECKey> keys = new ArrayList<>();
    keys.add(ecKey);
    try {
        SignatureUtil.createTransactionSignture(tx, null, keys);
    } catch (Exception e) {
        Log.error(e);
    }
}
Also used : ArrayList(java.util.ArrayList) NulsDigestData(io.nuls.kernel.model.NulsDigestData) ECKey(io.nuls.core.tools.crypto.ECKey) IOException(java.io.IOException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) NulsException(io.nuls.kernel.exception.NulsException)

Example 18 with ECKey

use of io.nuls.core.tools.crypto.ECKey in project nuls by nuls-io.

the class CreateAgentTxValidatorTest method test.

@Test
public void test() {
    CreateAgentTransaction tx = new CreateAgentTransaction();
    CreateAgentTxValidator validator = new CreateAgentTxValidator();
    ValidateResult result = validator.validate(tx);
    assertFalse(result.isSuccess());
    Agent agent = new Agent();
    tx.setTxData(agent);
    result = validator.validate(tx);
    assertFalse(result.isSuccess());
    byte[] address = AddressTool.getAddress(ecKey.getPubKey());
    byte[] address1 = AddressTool.getAddress(new ECKey().getPubKey());
    byte[] address2 = AddressTool.getAddress(new ECKey().getPubKey());
    agent.setRewardAddress(address);
    agent.setPackingAddress(address1);
    agent.setAgentAddress(address2);
    result = validator.validate(tx);
    assertFalse(result.isSuccess());
    agent.setDeposit(PocConsensusProtocolConstant.AGENT_DEPOSIT_LOWER_LIMIT);
    tx.setTime(System.currentTimeMillis());
    result = validator.validate(tx);
    assertTrue(result.isSuccess());
}
Also used : Agent(io.nuls.consensus.poc.protocol.entity.Agent) CreateAgentTxValidator(io.nuls.consensus.poc.tx.validator.CreateAgentTxValidator) ValidateResult(io.nuls.kernel.validate.ValidateResult) CreateAgentTransaction(io.nuls.consensus.poc.protocol.tx.CreateAgentTransaction) ECKey(io.nuls.core.tools.crypto.ECKey) Test(org.junit.Test) BaseTest(io.nuls.consensus.poc.BaseTest)

Example 19 with ECKey

use of io.nuls.core.tools.crypto.ECKey in project nuls by nuls-io.

the class ScriptBuilder method createMultiSigOutputScript.

/**
 * Creates a program that requires at least N of the given keys to sign, using OP_CHECKMULTISIG.
 * 根据多个公钥创建多重签名的OutputScript/scriptPublicKry
 */
public static Script createMultiSigOutputScript(int threshold, List<ECKey> pubkeys) {
    checkArgument(threshold > 0);
    checkArgument(threshold <= pubkeys.size());
    // That's the max we can represent with a single opcode.这是我们可以用一个操作码来表示的最大值
    checkArgument(pubkeys.size() <= 16);
    ScriptBuilder builder = new ScriptBuilder();
    builder.smallNum(threshold);
    for (ECKey key : pubkeys) {
        builder.data(key.getPubKey());
    }
    builder.smallNum(pubkeys.size());
    builder.op(OP_CHECKMULTISIG);
    return builder.build();
}
Also used : ECKey(io.nuls.core.tools.crypto.ECKey)

Example 20 with ECKey

use of io.nuls.core.tools.crypto.ECKey in project nuls by nuls-io.

the class NulsSignData method sign.

public NulsSignData sign(NulsDigestData nulsDigestData, short signAlgType, BigInteger privkey) {
    if (signAlgType == NulsSignData.SIGN_ALG_ECC) {
        ECKey ecKey = ECKey.fromPrivate(privkey);
        byte[] signBytes = ecKey.sign(nulsDigestData.getDigestBytes(), privkey);
        NulsSignData signData = new NulsSignData();
        try {
            signData.parse(signBytes, 0);
        } catch (NulsException e) {
            Log.error(e);
        }
        return signData;
    }
    return null;
}
Also used : NulsException(io.nuls.kernel.exception.NulsException) ECKey(io.nuls.core.tools.crypto.ECKey)

Aggregations

ECKey (io.nuls.core.tools.crypto.ECKey)43 NulsException (io.nuls.kernel.exception.NulsException)26 IOException (java.io.IOException)20 CoinDataResult (io.nuls.account.ledger.model.CoinDataResult)15 BigInteger (java.math.BigInteger)14 Account (io.nuls.account.model.Account)12 ArrayList (java.util.ArrayList)11 TransferTransaction (io.nuls.protocol.model.tx.TransferTransaction)10 MultiSigAccount (io.nuls.account.model.MultiSigAccount)8 ValidateResult (io.nuls.kernel.validate.ValidateResult)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 TransactionDataResult (io.nuls.account.ledger.model.TransactionDataResult)6 CryptoException (io.nuls.core.tools.crypto.Exception.CryptoException)6 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)4 MultipleAddressTransferModel (io.nuls.account.ledger.model.MultipleAddressTransferModel)3 Alias (io.nuls.account.model.Alias)3 AliasTransaction (io.nuls.account.tx.AliasTransaction)3 Agent (io.nuls.consensus.poc.protocol.entity.Agent)3 ContractResult (io.nuls.contract.dto.ContractResult)3 Script (io.nuls.kernel.script.Script)3