Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,6 @@ public class CommonParameter {
@Setter
public boolean solidityNode = false;

// If you are running KeystoreFactory,
// this flag is set to true
@Getter
@Setter
public boolean keystoreFactory = false;

// -- RPC / HTTP --
@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.tron.keystore;
package org.tron.common.crypto.keystore;

import java.util.Objects;
import org.tron.common.crypto.SignInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.tron.keystore;
package org.tron.common.crypto.keystore;

import static java.nio.charset.StandardCharsets.UTF_8;

Expand All @@ -23,7 +23,6 @@
import org.tron.common.crypto.SignUtils;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.StringUtil;
import org.tron.core.config.args.Args;
import org.tron.core.exception.CipherException;

/**
Expand Down Expand Up @@ -212,7 +211,7 @@ public static SignInterface decrypt(String password, WalletFile walletFile)
byte[] encryptKey = Arrays.copyOfRange(derivedKey, 0, 16);
byte[] privateKey = performCipherOperation(Cipher.DECRYPT_MODE, iv, encryptKey, cipherText);

return SignUtils.fromPrivate(privateKey, Args.getInstance().isECKeyCryptoEngine());
return SignUtils.fromPrivate(privateKey, true);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Preserve crypto-engine selection in decrypt path.

At Line 214, forcing SignUtils.fromPrivate(privateKey, true) always reconstructs EC keys and drops SM2 compatibility. This propagates to credential loading paths that call Wallet.decrypt(...) directly.

💡 Proposed fix (make engine explicit instead of hardcoded)
-  public static SignInterface decrypt(String password, WalletFile walletFile)
+  public static SignInterface decrypt(String password, WalletFile walletFile,
+      boolean isECKeyCryptoEngine)
       throws CipherException {
@@
-    return SignUtils.fromPrivate(privateKey, true);
+    return SignUtils.fromPrivate(privateKey, isECKeyCryptoEngine);
   }

Please also update callers to pass the active engine selection explicitly (for example from runtime config) so SM2 deployments keep working.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crypto/src/main/java/org/tron/common/crypto/keystore/Wallet.java` at line
214, The decrypt path currently hardcodes EC reconstruction via
SignUtils.fromPrivate(privateKey, true) which breaks SM2; change Wallet.decrypt
to accept an explicit crypto-engine flag/enum (e.g., boolean isEc or
CryptoEngine engine) and call SignUtils.fromPrivate(privateKey, engineChoice)
instead of the hardcoded true, then update all callers that invoke
Wallet.decrypt(...) (credential loading paths and any direct calls) to pass the
active engine selection from runtime/config so SM2 deployments preserve their
engine choice.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Hardcoding true forces the EC key crypto engine and ignores the runtime configuration, which can cause decrypt/sign behavior to differ from configured expectations.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At crypto/src/main/java/org/tron/common/crypto/keystore/Wallet.java, line 214:

<comment>Hardcoding `true` forces the EC key crypto engine and ignores the runtime configuration, which can cause decrypt/sign behavior to differ from configured expectations.</comment>

<file context>
@@ -212,7 +211,7 @@ public static SignInterface decrypt(String password, WalletFile walletFile)
     byte[] privateKey = performCipherOperation(Cipher.DECRYPT_MODE, iv, encryptKey, cipherText);
 
-    return SignUtils.fromPrivate(privateKey, Args.getInstance().isECKeyCryptoEngine());
+    return SignUtils.fromPrivate(privateKey, true);
   }
 
</file context>
Fix with Cubic

}

static void validate(WalletFile walletFile) throws CipherException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.tron.keystore;
package org.tron.common.crypto.keystore;

import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.JsonSubTypes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.tron.keystore;
package org.tron.common.crypto.keystore;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationFeature;
Expand All @@ -17,7 +17,6 @@
import org.tron.common.crypto.SignInterface;
import org.tron.common.crypto.SignUtils;
import org.tron.common.utils.Utils;
import org.tron.core.config.args.Args;
import org.tron.core.exception.CipherException;

/**
Expand Down Expand Up @@ -48,11 +47,9 @@ public static String generateLightNewWalletFile(String password, File destinatio

public static String generateNewWalletFile(
String password, File destinationDirectory, boolean useFullScrypt)
throws CipherException, IOException, InvalidAlgorithmParameterException,
NoSuchAlgorithmException, NoSuchProviderException {
throws CipherException, IOException {

SignInterface ecKeyPair = SignUtils.getGeneratedRandomSign(Utils.getRandom(),
Args.getInstance().isECKeyCryptoEngine());
SignInterface ecKeyPair = SignUtils.getGeneratedRandomSign(Utils.getRandom(), true);
Comment on lines +50 to +52
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if generateNewWalletFile is called from production code paths
rg -n "generateNewWalletFile|generateFullNewWalletFile|generateLightNewWalletFile" --type java -g '!**/test/**'

Repository: Federico2014/java-tron

Length of output: 808


🏁 Script executed:

# Find all callers of the three methods across the entire codebase
rg -n "generateNewWalletFile|generateFullNewWalletFile|generateLightNewWalletFile" --type java

Repository: Federico2014/java-tron

Length of output: 1079


🏁 Script executed:

# Examine KeystoreFactory.java to verify the reference
find . -name "KeystoreFactory.java" -type f | head -5

Repository: Federico2014/java-tron

Length of output: 134


🏁 Script executed:

# Check the signature and usage of Args vs CommonParameter for crypto engine config
rg -n "isECKeyCryptoEngine" --type java -B 2 -A 2 | head -50

Repository: Federico2014/java-tron

Length of output: 5666


🏁 Script executed:

# Check KeystoreFactory.java around lines 62-63
sed -n '55,70p' ./plugins/src/main/java/common/org/tron/plugins/KeystoreFactory.java

Repository: Federico2014/java-tron

Length of output: 710


🏁 Script executed:

# Check WalletUtils.java imports and full context
head -60 crypto/src/main/java/org/tron/common/crypto/keystore/WalletUtils.java

Repository: Federico2014/java-tron

Length of output: 2357


🏁 Script executed:

# Check if Args class exists and is used for crypto engine config
rg -n "class Args|isECKeyCryptoEngine" --type java crypto/src/main/java | head -20

Repository: Federico2014/java-tron

Length of output: 1238


Hardcoded true breaks SM2 crypto engine support.

The hardcoded true in generateNewWalletFile() means this method always generates ECKey-based wallets, ignoring the node's configured crypto engine. This is inconsistent with the production pattern shown in KeystoreFactory.java (line 62), which correctly uses CommonParameter.getInstance().isECKeyCryptoEngine().

Although currently only used in tests, this method should respect the configured crypto engine for consistency and to support SM2-configured systems.

🔧 Proposed fix
 public static String generateNewWalletFile(
     String password, File destinationDirectory, boolean useFullScrypt)
     throws CipherException, IOException {
 
-  SignInterface ecKeyPair = SignUtils.getGeneratedRandomSign(Utils.getRandom(), true);
+  SignInterface ecKeyPair = SignUtils.getGeneratedRandomSign(Utils.getRandom(),
+      CommonParameter.getInstance().isECKeyCryptoEngine());
   return generateWalletFile(password, ecKeyPair, destinationDirectory, useFullScrypt);
 }

Requires adding: import org.tron.common.parameter.CommonParameter;

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
throws CipherException, IOException {
SignInterface ecKeyPair = SignUtils.getGeneratedRandomSign(Utils.getRandom(),
Args.getInstance().isECKeyCryptoEngine());
SignInterface ecKeyPair = SignUtils.getGeneratedRandomSign(Utils.getRandom(), true);
import org.tron.common.parameter.CommonParameter;
// ... other code ...
throws CipherException, IOException {
SignInterface ecKeyPair = SignUtils.getGeneratedRandomSign(Utils.getRandom(),
CommonParameter.getInstance().isECKeyCryptoEngine());
return generateWalletFile(password, ecKeyPair, destinationDirectory, useFullScrypt);
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crypto/src/main/java/org/tron/common/crypto/keystore/WalletUtils.java` around
lines 50 - 52, The generateNewWalletFile() call currently hardcodes
SignUtils.getGeneratedRandomSign(..., true) which forces ECKey wallets; change
it to consult the node crypto engine setting by replacing the literal true with
CommonParameter.getInstance().isECKeyCryptoEngine(), and add the required import
for org.tron.common.parameter.CommonParameter; ensure
SignUtils.getGeneratedRandomSign(...) now receives the dynamic boolean so
SM2-configured systems are respected.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Do not hardcode the crypto engine to ECKey here; it ignores runtime configuration and can generate keystores incompatible with SM2-configured environments.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At crypto/src/main/java/org/tron/common/crypto/keystore/WalletUtils.java, line 52:

<comment>Do not hardcode the crypto engine to ECKey here; it ignores runtime configuration and can generate keystores incompatible with SM2-configured environments.</comment>

<file context>
@@ -48,11 +47,9 @@ public static String generateLightNewWalletFile(String password, File destinatio
 
-    SignInterface ecKeyPair = SignUtils.getGeneratedRandomSign(Utils.getRandom(),
-        Args.getInstance().isECKeyCryptoEngine());
+    SignInterface ecKeyPair = SignUtils.getGeneratedRandomSign(Utils.getRandom(), true);
     return generateWalletFile(password, ecKeyPair, destinationDirectory, useFullScrypt);
   }
</file context>
Suggested change
SignInterface ecKeyPair = SignUtils.getGeneratedRandomSign(Utils.getRandom(), true);
SignInterface ecKeyPair = SignUtils.getGeneratedRandomSign(Utils.getRandom(), org.tron.common.parameter.CommonParameter.getInstance().isECKeyCryptoEngine());
Fix with Cubic

return generateWalletFile(password, ecKeyPair, destinationDirectory, useFullScrypt);
}

Expand Down
8 changes: 4 additions & 4 deletions framework/src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ public WitnessList getPaginatedNowWitnessList(long offset, long limit) throws
if (limit > WITNESS_COUNT_LIMIT_MAX) {
limit = WITNESS_COUNT_LIMIT_MAX;
}

/*
In the maintenance period, the VoteStores will be cleared.
To avoid the race condition of VoteStores deleted but Witness vote counts not updated,
Expand Down Expand Up @@ -1502,8 +1502,8 @@ public Protocol.ChainParameters getChainParameters() {
builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
.setKey("getAllowTvmSelfdestructRestriction")
.setValue(dbManager.getDynamicPropertiesStore().getAllowTvmSelfdestructRestriction())
.build());
.build());

builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
.setKey("getProposalExpireTime")
.setValue(dbManager.getDynamicPropertiesStore().getProposalExpireTime())
Expand Down Expand Up @@ -2603,7 +2603,7 @@ public DiversifierMessage getDiversifier() throws ZksnarkException {

byte[] d;
while (true) {
d = org.tron.keystore.Wallet.generateRandomBytes(Constant.ZC_DIVERSIFIER_SIZE);
d = org.tron.common.crypto.keystore.Wallet.generateRandomBytes(Constant.ZC_DIVERSIFIER_SIZE);
if (JLibrustzcash.librustzcashCheckDiversifier(d)) {
break;
}
Expand Down
5 changes: 1 addition & 4 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -1064,9 +1064,6 @@ private static void applyCLIParams(CLIParameter cmd, JCommander jc) {
if (assigned.contains("--solidity")) {
PARAMETER.solidityNode = cmd.solidityNode;
}
if (assigned.contains("--keystore-factory")) {
PARAMETER.keystoreFactory = cmd.keystoreFactory;
}
if (assigned.contains("--rpc-thread")) {
PARAMETER.rpcThreadNum = cmd.rpcThreadNum;
}
Expand Down Expand Up @@ -1733,7 +1730,7 @@ private static String getCommitIdAbbrev() {

private static Map<String, String[]> getOptionGroup() {
String[] tronOption = new String[] {"version", "help", "shellConfFileName", "logbackPath",
"eventSubscribe", "solidityNode", "keystoreFactory"};
"eventSubscribe", "solidityNode"};
String[] dbOption = new String[] {"outputDirectory"};
String[] witnessOption = new String[] {"witness", "privateKey"};
String[] vmOption = new String[] {"debug"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ public class CLIParameter {
@Parameter(names = {"--solidity"}, description = "running a solidity node for java tron")
public boolean solidityNode;

@Parameter(names = {"--keystore-factory"}, description = "running KeystoreFactory")
public boolean keystoreFactory;

@Parameter(names = {"--fast-forward"})
public boolean fastForward;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.tron.common.crypto.SignInterface;
import org.tron.common.crypto.keystore.Credentials;
import org.tron.common.crypto.keystore.WalletUtils;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.Commons;
import org.tron.common.utils.LocalWitnesses;
import org.tron.core.exception.CipherException;
import org.tron.core.exception.TronError;
import org.tron.keystore.Credentials;
import org.tron.keystore.WalletUtils;

@Slf4j
public class WitnessInitializer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.tron.common.crypto.keystore.Wallet;
import org.tron.common.zksnark.JLibrustzcash;
import org.tron.core.Constant;
import org.tron.core.exception.ZksnarkException;
import org.tron.keystore.Wallet;

@AllArgsConstructor
public class DiversifierT {
Expand Down
4 changes: 0 additions & 4 deletions framework/src/main/java/org/tron/program/FullNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ public static void main(String[] args) {
SolidityNode.start();
return;
}
if (parameter.isKeystoreFactory()) {
KeystoreFactory.start();
return;
}
logger.info("Full node running.");
if (Args.getInstance().isDebug()) {
logger.info("in debug mode, it won't check energy time");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.junit.Test;
import org.tron.api.GrpcAPI.ShieldedTRC20Parameters;
import org.tron.common.BaseTest;
import org.tron.common.crypto.keystore.Wallet;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.ByteUtil;
import org.tron.common.utils.FileUtil;
Expand All @@ -41,7 +42,6 @@
import org.tron.core.zen.address.PaymentAddress;
import org.tron.core.zen.address.SpendingKey;
import org.tron.core.zen.note.Note;
import org.tron.keystore.Wallet;
import org.tron.protos.contract.ShieldContract;

@Slf4j
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ public void get() {
Assert.assertEquals(address,
ByteArray.toHexString(Args.getLocalWitnesses()
.getWitnessAccountAddress()));

Assert.assertTrue(parameter.isKeystoreFactory());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import org.junit.Test;
import org.mockito.MockedStatic;
import org.tron.common.crypto.SignInterface;
import org.tron.common.crypto.keystore.Credentials;
import org.tron.common.crypto.keystore.WalletUtils;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.LocalWitnesses;
import org.tron.common.utils.PublicMethod;
import org.tron.common.utils.client.utils.Base58;
import org.tron.core.exception.TronError;
import org.tron.core.exception.TronError.ErrCode;
import org.tron.keystore.Credentials;
import org.tron.keystore.WalletUtils;

public class WitnessInitializerTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@ public void testTransactionApprovedList() {
transactionApprovedList = wallet.getTransactionApprovedList(transactionCapsule.getInstance());
Assert.assertEquals("", transactionApprovedList.getResult().getMessage());

byte[] randomSig = org.tron.keystore.Wallet.generateRandomBytes(64);
byte[] randomSig = org.tron.common.crypto.keystore.Wallet.generateRandomBytes(64);
Transaction transaction = transactionCapsule.getInstance().toBuilder().clearSignature()
.addSignature(ByteString.copyFrom(randomSig)).build();
transactionApprovedList = wallet.getTransactionApprovedList(transaction);
Assert.assertEquals(TransactionApprovedList.Result.response_code.SIGNATURE_FORMAT_ERROR,
transactionApprovedList.getResult().getCode());

randomSig = org.tron.keystore.Wallet.generateRandomBytes(65);
randomSig = org.tron.common.crypto.keystore.Wallet.generateRandomBytes(65);
transaction = transactionCapsule.getInstance().toBuilder().clearSignature()
.addSignature(ByteString.copyFrom(randomSig)).build();
transactionApprovedList = wallet.getTransactionApprovedList(transaction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.tron.common.TestConstants;
import org.tron.common.application.TronApplicationContext;
import org.tron.common.crypto.keystore.Wallet;
import org.tron.common.utils.ByteArray;
import org.tron.core.capsule.BytesCapsule;
import org.tron.core.config.DefaultConfig;
import org.tron.core.config.args.Args;
import org.tron.core.store.DynamicPropertiesStore;
import org.tron.keystore.Wallet;

@Slf4j
public class TxCacheDBInitTest {
Expand Down Expand Up @@ -100,4 +100,4 @@ private void queryTransaction() {
}
}

}
}
4 changes: 2 additions & 2 deletions framework/src/test/java/org/tron/core/db/TxCacheDBTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import org.junit.Test;
import org.tron.common.BaseTest;
import org.tron.common.TestConstants;
import org.tron.common.crypto.keystore.Wallet;
import org.tron.common.utils.ByteArray;
import org.tron.core.capsule.BytesCapsule;
import org.tron.core.config.args.Args;
import org.tron.keystore.Wallet;

public class TxCacheDBTest extends BaseTest {

Expand Down Expand Up @@ -48,4 +48,4 @@ public void putTransactionTest() {
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.tron.core.jsonrpc;

import static org.tron.common.crypto.keystore.Wallet.generateRandomBytes;
import static org.tron.common.utils.Commons.decodeFromBase58Check;
import static org.tron.keystore.Wallet.generateRandomBytes;

import com.google.protobuf.ByteString;
import org.junit.AfterClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void testGenerateSpendProof() throws Exception {
DiversifierT diversifierT = new DiversifierT();
byte[] d;
do {
d = org.tron.keystore.Wallet.generateRandomBytes(Constant.ZC_DIVERSIFIER_SIZE);
d = org.tron.common.crypto.keystore.Wallet.generateRandomBytes(Constant.ZC_DIVERSIFIER_SIZE);
} while (!JLibrustzcash.librustzcashCheckDiversifier(d));
diversifierT.setData(d);

Expand Down Expand Up @@ -331,7 +331,7 @@ public void testDecryptReceiveWithIvk() throws ZksnarkException {
PaymentAddress paymentAddress = optional.get();

long ctx = JLibrustzcash.librustzcashSaplingProvingCtxInit();
byte[] memo = org.tron.keystore.Wallet.generateRandomBytes(512);
byte[] memo = org.tron.common.crypto.keystore.Wallet.generateRandomBytes(512);
builder.addOutput(fullViewingKey.getOvk(), paymentAddress, 4000, memo);

ZenTransactionBuilder.ReceiveDescriptionInfo output = builder.getReceives().get(0);
Expand Down Expand Up @@ -401,7 +401,7 @@ public void testDecryptReceiveWithOvk() throws Exception {
Note note = new Note(paymentAddress2, 4000);//construct function:this.pkD = address.getPkD();
note.setRcm(ByteArray
.fromHexString("83d36fd4c8eebec516c3a8ce2fe4832e01eb57bd7f9f9c9e0bd68cc69a5b0f06"));
byte[] memo = org.tron.keystore.Wallet.generateRandomBytes(512);
byte[] memo = org.tron.common.crypto.keystore.Wallet.generateRandomBytes(512);
note.setMemo(memo);

byte[] cmuOpt = note.cm();
Expand Down Expand Up @@ -486,7 +486,7 @@ public void pushShieldedTransactionAndDecryptWithIvk()
Optional<PaymentAddress> optional = incomingViewingKey.address(new DiversifierT());
if (optional.isPresent()) {
PaymentAddress paymentAddress = optional.get();
byte[] memo = org.tron.keystore.Wallet.generateRandomBytes(512);
byte[] memo = org.tron.common.crypto.keystore.Wallet.generateRandomBytes(512);
builder.addOutput(senderOvk, paymentAddress,
1000 * 1000000L - wallet.getShieldedTransactionFee(), memo);

Expand Down Expand Up @@ -574,7 +574,7 @@ public void pushShieldedTransactionAndDecryptWithOvk()
Optional<PaymentAddress> optional = incomingViewingKey.address(new DiversifierT());
if (optional.isPresent()) {
PaymentAddress paymentAddress = optional.get();
byte[] memo = org.tron.keystore.Wallet.generateRandomBytes(512);
byte[] memo = org.tron.common.crypto.keystore.Wallet.generateRandomBytes(512);
builder.addOutput(senderOvk, paymentAddress,
1000 * 1000000L - wallet.getShieldedTransactionFee(), memo);

Expand Down Expand Up @@ -909,7 +909,8 @@ public void getSpendingKey() throws Exception {
DiversifierT diversifierT = new DiversifierT();
byte[] d;
do {
d = org.tron.keystore.Wallet.generateRandomBytes(Constant.ZC_DIVERSIFIER_SIZE);
d = org.tron.common.crypto.keystore.Wallet.generateRandomBytes(
Constant.ZC_DIVERSIFIER_SIZE);
} while (!JLibrustzcash.librustzcashCheckDiversifier(d));
diversifierT.setData(d);
System.out.println("d is: " + ByteArray.toHexString(d));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,19 @@ public void init() {
}

private static byte[] randomUint256() {
return org.tron.keystore.Wallet.generateRandomBytes(32);
return org.tron.common.crypto.keystore.Wallet.generateRandomBytes(32);
}

private static byte[] randomUint640() {
return org.tron.keystore.Wallet.generateRandomBytes(80);
return org.tron.common.crypto.keystore.Wallet.generateRandomBytes(80);
}

private static byte[] randomUint1536() {
return org.tron.keystore.Wallet.generateRandomBytes(192);
return org.tron.common.crypto.keystore.Wallet.generateRandomBytes(192);
}

private static byte[] randomUint4640() {
return org.tron.keystore.Wallet.generateRandomBytes(580);
return org.tron.common.crypto.keystore.Wallet.generateRandomBytes(580);
}

/**
Expand Down Expand Up @@ -2229,7 +2229,7 @@ public void testMemoTooLong() throws ContractValidateException, TooBigTransactio
FullViewingKey fullViewingKey = spendingKey.fullViewingKey();
IncomingViewingKey incomingViewingKey = fullViewingKey.inViewingKey();
PaymentAddress paymentAddress = incomingViewingKey.address(new DiversifierT()).get();
byte[] memo = org.tron.keystore.Wallet.generateRandomBytes(1024);
byte[] memo = org.tron.common.crypto.keystore.Wallet.generateRandomBytes(1024);
builder.addOutput(expsk.getOvk(), paymentAddress,
100 * 1000000L - wallet.getShieldedTransactionFee(), memo);

Expand Down Expand Up @@ -2311,7 +2311,7 @@ public void testMemoNotEnough() throws ContractValidateException, TooBigTransact
FullViewingKey fullViewingKey = spendingKey.fullViewingKey();
IncomingViewingKey incomingViewingKey = fullViewingKey.inViewingKey();
PaymentAddress paymentAddress = incomingViewingKey.address(new DiversifierT()).get();
byte[] memo = org.tron.keystore.Wallet.generateRandomBytes(128);
byte[] memo = org.tron.common.crypto.keystore.Wallet.generateRandomBytes(128);
builder.addOutput(expsk.getOvk(), paymentAddress,
100 * 1000000L - wallet.getShieldedTransactionFee(), memo);

Expand Down Expand Up @@ -2405,7 +2405,7 @@ public void pushSameSkAndScanAndSpend() throws Exception {
FullViewingKey fullViewingKey = sk2.fullViewingKey();
IncomingViewingKey incomingViewingKey = fullViewingKey.inViewingKey();

byte[] memo = org.tron.keystore.Wallet.generateRandomBytes(512);
byte[] memo = org.tron.common.crypto.keystore.Wallet.generateRandomBytes(512);

//send coin to 2 different address generated by same sk
DiversifierT d1 = DiversifierT.random();
Expand Down Expand Up @@ -2489,7 +2489,7 @@ public void pushSameSkAndScanAndSpend() throws Exception {

DiversifierT d3 = DiversifierT.random();
PaymentAddress paymentAddress3 = incomingViewingKey.address(d3).get();
byte[] memo3 = org.tron.keystore.Wallet.generateRandomBytes(512);
byte[] memo3 = org.tron.common.crypto.keystore.Wallet.generateRandomBytes(512);
builder2.addOutput(expsk2.getOvk(), paymentAddress3,
(1000 * 1000000L - wallet.getShieldedTransactionFee()) / 2 - wallet
.getShieldedTransactionFee(), memo3);
Expand Down
Loading