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);
}
}
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);
}
}
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());
}
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();
}
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;
}
Aggregations