@@ -20,9 +20,9 @@ import com.jd.blockchain.consensus.mq.settings.MsgQueueConsensusSettings; | |||
import com.jd.blockchain.consensus.mq.settings.MsgQueueNetworkSettings; | |||
import com.jd.blockchain.consensus.mq.settings.MsgQueueNodeSettings; | |||
import com.jd.blockchain.crypto.AddressEncoding; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.ParticipantNode; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.PropertiesUtils; | |||
import com.jd.blockchain.utils.codec.Base58Utils; | |||
@@ -129,7 +129,7 @@ public class MsgQueueConsensusSettingsBuilder implements ConsensusSettingsBuilde | |||
String keyOfPubkey = nodeKey(PUBKEY_PATTERN, id); | |||
String base58PubKey = PropertiesUtils.getRequiredProperty(resolvingProps, keyOfPubkey); | |||
PubKey pubKey = KeyGenCommand.decodePubKey(base58PubKey); | |||
PubKey pubKey = KeyGenUtils.decodePubKey(base58PubKey); | |||
// PubKey pubKey = new PubKey(Base58Utils.decode(base58PubKey)); | |||
resolvingProps.remove(keyOfPubkey); | |||
@@ -7,6 +7,7 @@ import java.io.InputStream; | |||
import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
@@ -29,7 +30,6 @@ import com.jd.blockchain.ledger.TransactionTemplate; | |||
import com.jd.blockchain.ledger.UserRegisterOperation; | |||
import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.codec.Base58Utils; | |||
import com.jd.blockchain.utils.net.NetworkAddress; | |||
@@ -47,8 +47,8 @@ public enum ContractDeployExeUtil { | |||
PubKey pub = null; | |||
PrivKey prv = null; | |||
try { | |||
prv = KeyGenCommand.readPrivKey(prvPath, KeyGenCommand.encodePassword(rawPassword)); | |||
pub = KeyGenCommand.readPubKey(pubPath); | |||
prv = KeyGenUtils.readPrivKey(prvPath, KeyGenUtils.encodePassword(rawPassword)); | |||
pub = KeyGenUtils.readPubKey(pubPath); | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
@@ -64,7 +64,7 @@ public enum ContractDeployExeUtil { | |||
BlockchainKeypair contractKeyPair = BlockchainKeyGenerator.getInstance().generate(); | |||
pub = contractKeyPair.getPubKey(); | |||
}else { | |||
pub = KeyGenCommand.readPubKey(pubPath); | |||
pub = KeyGenUtils.readPubKey(pubPath); | |||
} | |||
} catch (Exception e) { | |||
@@ -1,10 +1,10 @@ | |||
package com.jd.blockchain; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.BlockchainKeypair; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.StringUtils; | |||
import com.jd.blockchain.utils.codec.Base58Utils; | |||
import com.jd.blockchain.utils.io.FileUtils; | |||
@@ -102,8 +102,8 @@ public class ContractDeployMojo extends AbstractMojo { | |||
byte[] contractBytes = FileUtils.readBytes(contractPath); | |||
PrivKey prv = KeyGenCommand.decodePrivKeyWithRawPassword(prvKey, password); | |||
PubKey pub = KeyGenCommand.decodePubKey(pubKey); | |||
PrivKey prv = KeyGenUtils.decodePrivKeyWithRawPassword(prvKey, password); | |||
PubKey pub = KeyGenUtils.decodePubKey(pubKey); | |||
BlockchainKeypair blockchainKeyPair = new BlockchainKeypair(pub, prv); | |||
HashDigest ledgerHash = new HashDigest(Base58Utils.decode(ledger)); | |||
@@ -0,0 +1,187 @@ | |||
package com.jd.blockchain.crypto; | |||
import java.util.Arrays; | |||
import javax.crypto.SecretKey; | |||
import com.jd.blockchain.utils.ConsoleUtils; | |||
import com.jd.blockchain.utils.codec.Base58Utils; | |||
import com.jd.blockchain.utils.io.BytesUtils; | |||
import com.jd.blockchain.utils.io.FileUtils; | |||
import com.jd.blockchain.utils.security.AESUtils; | |||
import com.jd.blockchain.utils.security.DecryptionException; | |||
import com.jd.blockchain.utils.security.ShaUtils; | |||
public class KeyGenUtils { | |||
private static final byte[] PUB_KEY_FILE_MAGICNUM = { (byte) 0xFF, 112, 117, 98 }; | |||
private static final byte[] PRIV_KEY_FILE_MAGICNUM = { (byte) 0x00, 112, 114, 118 }; | |||
/** | |||
* 公钥编码输出为 Base58 字符; | |||
* | |||
* @param pubKey | |||
* @return | |||
*/ | |||
public static String encodePubKey(PubKey pubKey) { | |||
byte[] pubKeyBytes = BytesUtils.concat(PUB_KEY_FILE_MAGICNUM, pubKey.toBytes()); | |||
String base58PubKey = Base58Utils.encode(pubKeyBytes); | |||
return base58PubKey; | |||
} | |||
public static PubKey decodePubKey(String base58PubKey) { | |||
byte[] keyBytes = Base58Utils.decode(base58PubKey); | |||
return decodePubKey(keyBytes); | |||
} | |||
public static String encodePrivKey(PrivKey privKey, String base58Pwd) { | |||
byte[] pwdBytes = Base58Utils.decode(base58Pwd); | |||
return encodePrivKey(privKey, pwdBytes); | |||
} | |||
public static String encodePrivKey(PrivKey privKey, byte[] pwdBytes) { | |||
byte[] encodedPrivKeyBytes = encryptPrivKey(privKey, pwdBytes); | |||
String base58PrivKey = Base58Utils.encode(encodedPrivKeyBytes); | |||
return base58PrivKey; | |||
} | |||
public static byte[] encryptPrivKey(PrivKey privKey, byte[] pwdBytes) { | |||
SecretKey userKey = AESUtils.generateKey128(pwdBytes); | |||
byte[] encryptedPrivKeyBytes = AESUtils.encrypt(privKey.toBytes(), userKey); | |||
return BytesUtils.concat(PRIV_KEY_FILE_MAGICNUM, encryptedPrivKeyBytes); | |||
} | |||
/** | |||
* @param encodedPubKeyBytes | |||
* @return | |||
*/ | |||
private static PubKey decodePubKeyBytes(byte[] encodedPubKeyBytes) { | |||
byte[] pubKeyBytes = Arrays.copyOfRange(encodedPubKeyBytes, PUB_KEY_FILE_MAGICNUM.length, | |||
encodedPubKeyBytes.length); | |||
return new PubKey(pubKeyBytes); | |||
} | |||
public static PrivKey decryptedPrivKeyBytes(byte[] encodedPrivKeyBytes, byte[] pwdBytes) { | |||
// Read privKye; | |||
SecretKey userKey = AESUtils.generateKey128(pwdBytes); | |||
byte[] encryptedKeyBytes = Arrays.copyOfRange(encodedPrivKeyBytes, PRIV_KEY_FILE_MAGICNUM.length, | |||
encodedPrivKeyBytes.length); | |||
try { | |||
byte[] plainKeyBytes = AESUtils.decrypt(encryptedKeyBytes, userKey); | |||
return new PrivKey(plainKeyBytes); | |||
} catch (DecryptionException e) { | |||
throw new DecryptionException("Invalid password!", e); | |||
} | |||
} | |||
public static PubKey readPubKey(String keyFile) { | |||
String base58KeyString = FileUtils.readText(keyFile); | |||
return decodePubKey(base58KeyString); | |||
} | |||
/** | |||
* 解码公钥; | |||
* | |||
* @param encodedPubKeyBytes 从公钥; | |||
* @return | |||
*/ | |||
public static PubKey decodePubKey(byte[] encodedPubKeyBytes) { | |||
if (BytesUtils.startsWith(encodedPubKeyBytes, PUB_KEY_FILE_MAGICNUM)) { | |||
// Read pubKey; | |||
return decodePubKeyBytes(encodedPubKeyBytes); | |||
} | |||
throw new IllegalArgumentException("The specified bytes is not valid PubKey generated by the KeyGen tool!"); | |||
} | |||
/** | |||
* 从控制台读取加密口令,以二进制数组形式返回原始口令的一次SHA256的结果; | |||
* | |||
* @return | |||
*/ | |||
public static byte[] readPassword() { | |||
byte[] pwdBytes = ConsoleUtils.readPassword(); | |||
return ShaUtils.hash_256(pwdBytes); | |||
} | |||
/** | |||
* 对指定的原始密码进行编码生成用于加解密的密码; | |||
* | |||
* @param rawPassword | |||
* @return | |||
*/ | |||
public static byte[] encodePassword(String rawPassword) { | |||
byte[] pwdBytes = BytesUtils.toBytes(rawPassword, "UTF-8"); | |||
return ShaUtils.hash_256(pwdBytes); | |||
} | |||
/** | |||
* 对指定的原始密码进行编码生成用于加解密的密码; | |||
* | |||
* @param rawPassword | |||
* @return | |||
*/ | |||
public static String encodePasswordAsBase58(String rawPassword) { | |||
return Base58Utils.encode(encodePassword(rawPassword)); | |||
} | |||
/** | |||
* 从控制台读取加密口令,以Base58字符串形式返回口令的一次SHA256的结果; | |||
* | |||
* @return | |||
*/ | |||
public static String readPasswordString() { | |||
return Base58Utils.encode(readPassword()); | |||
} | |||
public static PrivKey readPrivKey(String keyFile, String base58Pwd) { | |||
return readPrivKey(keyFile, Base58Utils.decode(base58Pwd)); | |||
} | |||
/** | |||
* 从文件读取私钥; | |||
* | |||
* @param keyFile | |||
* @param pwdBytes | |||
* @return | |||
*/ | |||
public static PrivKey readPrivKey(String keyFile, byte[] pwdBytes) { | |||
String base58KeyString = FileUtils.readText(keyFile); | |||
byte[] keyBytes = Base58Utils.decode(base58KeyString); | |||
if (!BytesUtils.startsWith(keyBytes, PRIV_KEY_FILE_MAGICNUM)) { | |||
throw new IllegalArgumentException("The specified file is not a private key file!"); | |||
} | |||
return decryptedPrivKeyBytes(keyBytes, pwdBytes); | |||
} | |||
public static PrivKey decodePrivKey(String base58Key, String base58Pwd) { | |||
byte[] decryptedKey = Base58Utils.decode(base58Pwd); | |||
return decodePrivKey(base58Key, decryptedKey); | |||
} | |||
public static PrivKey decodePrivKey(String base58Key, byte[] pwdBytes) { | |||
byte[] keyBytes = Base58Utils.decode(base58Key); | |||
if (!BytesUtils.startsWith(keyBytes, PRIV_KEY_FILE_MAGICNUM)) { | |||
throw new IllegalArgumentException("The specified file is not a private key file!"); | |||
} | |||
return decryptedPrivKeyBytes(keyBytes, pwdBytes); | |||
} | |||
public static PrivKey decodePrivKeyWithRawPassword(String base58Key, String rawPassword) { | |||
byte[] pwdBytes = encodePassword(rawPassword); | |||
byte[] keyBytes = Base58Utils.decode(base58Key); | |||
if (!BytesUtils.startsWith(keyBytes, PRIV_KEY_FILE_MAGICNUM)) { | |||
throw new IllegalArgumentException("The specified file is not a private key file!"); | |||
} | |||
return decryptedPrivKeyBytes(keyBytes, pwdBytes); | |||
} | |||
public static boolean isPubKeyBytes(byte[] keyBytes) { | |||
return BytesUtils.startsWith(keyBytes, PUB_KEY_FILE_MAGICNUM); | |||
} | |||
public static boolean isPrivKeyBytes(byte[] keyBytes) { | |||
return BytesUtils.startsWith(keyBytes, PRIV_KEY_FILE_MAGICNUM); | |||
} | |||
} |
@@ -5,20 +5,20 @@ import java.io.InputStream; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import com.jd.blockchain.gateway.web.BlockBrowserController; | |||
import org.apache.commons.io.FileUtils; | |||
import org.springframework.boot.SpringApplication; | |||
import org.springframework.context.ConfigurableApplicationContext; | |||
import org.springframework.core.io.ClassPathResource; | |||
import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.gateway.web.BlockBrowserController; | |||
import com.jd.blockchain.utils.ArgumentSet; | |||
import com.jd.blockchain.utils.ArgumentSet.ArgEntry; | |||
import com.jd.blockchain.utils.BaseConstant; | |||
import com.jd.blockchain.utils.ConsoleUtils; | |||
import com.jd.blockchain.utils.ArgumentSet.ArgEntry; | |||
public class GatewayServerBooter { | |||
@@ -88,19 +88,19 @@ public class GatewayServerBooter { | |||
String base58Pwd = config.keys().getDefault().getPrivKeyPassword(); | |||
if (base58Pwd == null || base58Pwd.length() == 0) { | |||
base58Pwd = KeyGenCommand.readPasswordString(); | |||
base58Pwd = KeyGenUtils.readPasswordString(); | |||
} | |||
// 加载密钥; | |||
PubKey pubKey = KeyGenCommand.decodePubKey(config.keys().getDefault().getPubKeyValue()); | |||
PubKey pubKey = KeyGenUtils.decodePubKey(config.keys().getDefault().getPubKeyValue()); | |||
PrivKey privKey = null; | |||
String base58PrivKey = config.keys().getDefault().getPrivKeyValue(); | |||
if (base58PrivKey == null) { | |||
//注:GatewayConfigProperties 确保了 PrivKeyValue 和 PrivKeyPath 必有其一; | |||
privKey = KeyGenCommand.readPrivKey(config.keys().getDefault().getPrivKeyPath(), base58Pwd); | |||
privKey = KeyGenUtils.readPrivKey(config.keys().getDefault().getPrivKeyPath(), base58Pwd); | |||
} else { | |||
privKey = KeyGenCommand.decodePrivKey(base58PrivKey, base58Pwd); | |||
privKey = KeyGenUtils.decodePrivKey(base58PrivKey, base58Pwd); | |||
} | |||
defaultKeyPair = new AsymmetricKeypair(pubKey, privKey); | |||
} | |||
@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.RestController; | |||
import com.jd.blockchain.crypto.AddressEncoding; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.gateway.PeerService; | |||
import com.jd.blockchain.gateway.decompiler.utils.DecompilerUtils; | |||
@@ -34,7 +35,6 @@ import com.jd.blockchain.ledger.TransactionState; | |||
import com.jd.blockchain.ledger.UserInfo; | |||
import com.jd.blockchain.sdk.BlockchainExtendQueryService; | |||
import com.jd.blockchain.sdk.ContractSettings; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.BaseConstant; | |||
import com.jd.blockchain.utils.ConsoleUtils; | |||
@@ -482,7 +482,7 @@ public class BlockBrowserController implements BlockchainExtendQueryService { | |||
@RequestMapping(method = RequestMethod.GET, path = "utils/pubkey/{pubkey}/addr") | |||
public String getAddrByPubKey(@PathVariable(name = "pubkey") String strPubKey) { | |||
PubKey pubKey = KeyGenCommand.decodePubKey(strPubKey); | |||
PubKey pubKey = KeyGenUtils.decodePubKey(strPubKey); | |||
return AddressEncoding.generateAddress(pubKey).toBase58(); | |||
} | |||
@@ -0,0 +1,154 @@ | |||
package com.jd.blockchain.ledger.core; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.SignatureDigest; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.BlockchainIdentityData; | |||
import com.jd.blockchain.ledger.DigitalSignature; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.LedgerInitException; | |||
import com.jd.blockchain.ledger.LedgerInitSetting; | |||
import com.jd.blockchain.ledger.Operation; | |||
import com.jd.blockchain.ledger.ParticipantNode; | |||
import com.jd.blockchain.ledger.TransactionBuilder; | |||
import com.jd.blockchain.ledger.TransactionContent; | |||
import com.jd.blockchain.ledger.TransactionRequest; | |||
import com.jd.blockchain.ledger.TransactionState; | |||
import com.jd.blockchain.ledger.UserRegisterOperation; | |||
import com.jd.blockchain.storage.service.KVStorageService; | |||
import com.jd.blockchain.transaction.SignatureUtils; | |||
import com.jd.blockchain.transaction.TxBuilder; | |||
import com.jd.blockchain.transaction.TxRequestBuilder; | |||
public class LedgerInitializer { | |||
private LedgerInitSetting initSetting; | |||
private TransactionContent initTxContent; | |||
private volatile LedgerBlock genesisBlock; | |||
private volatile LedgerEditor ledgerEditor; | |||
private volatile boolean committed = false; | |||
private volatile boolean canceled = false; | |||
/** | |||
* 初始化生成的账本hash; <br> | |||
* | |||
* 在成功执行 {@link #prepareLedger(KVStorageService, DigitalSignature...)} 之前总是返回 | |||
* null; | |||
* | |||
* @return | |||
*/ | |||
public HashDigest getLedgerHash() { | |||
return genesisBlock == null ? null : genesisBlock.getHash(); | |||
} | |||
/** | |||
* @param initSetting | |||
* @param initTxContent | |||
*/ | |||
private LedgerInitializer(LedgerInitSetting initSetting, TransactionContent initTxContent) { | |||
this.initSetting = initSetting; | |||
this.initTxContent = initTxContent; | |||
} | |||
public TransactionContent getTransactionContent() { | |||
return initTxContent; | |||
} | |||
public static LedgerInitializer create(LedgerInitSetting initSetting) { | |||
// 生成初始化交易,并签署许可; | |||
TransactionBuilder initTxBuilder = new TxBuilder(null);// 账本初始化交易的账本 hash 为 null; | |||
initTxBuilder.ledgers().create(initSetting); | |||
for (ParticipantNode p : initSetting.getConsensusParticipants()) { | |||
// TODO:暂时只支持注册用户的初始化操作; | |||
BlockchainIdentity superUserId = new BlockchainIdentityData(p.getPubKey()); | |||
initTxBuilder.users().register(superUserId); | |||
} | |||
// 账本初始化配置声明的创建时间来初始化交易时间戳;注:不能用本地时间,因为共识节点之间的本地时间系统不一致; | |||
TransactionContent initTxContent = initTxBuilder.prepareContent(initSetting.getCreatedTime()); | |||
return new LedgerInitializer(initSetting, initTxContent); | |||
} | |||
public SignatureDigest signTransaction(PrivKey privKey) { | |||
return SignatureUtils.sign(initTxContent, privKey); | |||
} | |||
/** | |||
* 准备创建账本; | |||
* | |||
* @param storageService 存储服务; | |||
* @param nodeSignatures 节点签名列表; | |||
* @return | |||
*/ | |||
public LedgerBlock prepareLedger(KVStorageService storageService, DigitalSignature... nodeSignatures) { | |||
if (genesisBlock != null) { | |||
throw new LedgerInitException("The ledger has been prepared!"); | |||
} | |||
// 生成账本; | |||
this.ledgerEditor = createLedgerEditor(this.initSetting, storageService); | |||
this.genesisBlock = prepareLedger(ledgerEditor, nodeSignatures); | |||
return genesisBlock; | |||
} | |||
public void commit() { | |||
if (committed) { | |||
throw new LedgerInitException("The ledger has been committed!"); | |||
} | |||
if (canceled) { | |||
throw new LedgerInitException("The ledger has been canceled!"); | |||
} | |||
committed = true; | |||
this.ledgerEditor.commit(); | |||
} | |||
public void cancel() { | |||
if (canceled) { | |||
throw new LedgerInitException("The ledger has been canceled!"); | |||
} | |||
if (committed) { | |||
throw new LedgerInitException("The ledger has been committed!"); | |||
} | |||
this.ledgerEditor.cancel(); | |||
} | |||
public static LedgerEditor createLedgerEditor(LedgerInitSetting initSetting, KVStorageService storageService) { | |||
LedgerEditor genesisBlockEditor = LedgerTransactionalEditor.createEditor(initSetting, | |||
LedgerManage.LEDGER_PREFIX, storageService.getExPolicyKVStorage(), | |||
storageService.getVersioningKVStorage()); | |||
return genesisBlockEditor; | |||
} | |||
/** | |||
* 初始化账本数据,返回创始区块; | |||
* | |||
* @param ledgerEditor | |||
* @return | |||
*/ | |||
private LedgerBlock prepareLedger(LedgerEditor ledgerEditor, DigitalSignature... nodeSignatures) { | |||
// 初始化时,自动将参与方注册为账本的用户; | |||
TxRequestBuilder txReqBuilder = new TxRequestBuilder(this.initTxContent); | |||
txReqBuilder.addNodeSignature(nodeSignatures); | |||
TransactionRequest txRequest = txReqBuilder.buildRequest(); | |||
LedgerTransactionContext txCtx = ledgerEditor.newTransaction(txRequest); | |||
Operation[] ops = txRequest.getTransactionContent().getOperations(); | |||
// 注册用户; 注:第一个操作是 LedgerInitOperation; | |||
// TODO:暂时只支持注册用户的初始化操作; | |||
for (int i = 1; i < ops.length; i++) { | |||
UserRegisterOperation userRegOP = (UserRegisterOperation) ops[i]; | |||
txCtx.getDataset().getUserAccountSet().register(userRegOP.getUserID().getAddress(), | |||
userRegOP.getUserID().getPubKey()); | |||
} | |||
txCtx.commit(TransactionState.SUCCESS, null); | |||
return ledgerEditor.prepare(); | |||
} | |||
} |
@@ -12,19 +12,21 @@ import com.jd.blockchain.storage.service.KVStorageService; | |||
*/ | |||
public interface LedgerManage extends LedgerService { | |||
static final String LEDGER_PREFIX = "LDG://"; | |||
LedgerRepository register(HashDigest ledgerHash, KVStorageService storageService); | |||
void unregister(HashDigest ledgerHash); | |||
/** | |||
* 创建新账本; | |||
* | |||
* @param initSetting | |||
* 初始化配置; | |||
* @param initPermissions | |||
* 参与者的初始化授权列表;与参与者列表一致; | |||
* @return | |||
*/ | |||
LedgerEditor newLedger(LedgerInitSetting initSetting, KVStorageService storageService); | |||
// /** | |||
// * 创建新账本; | |||
// * | |||
// * @param initSetting | |||
// * 初始化配置; | |||
// * @param initPermissions | |||
// * 参与者的初始化授权列表;与参与者列表一致; | |||
// * @return | |||
// */ | |||
// LedgerEditor newLedger(LedgerInitSetting initSetting, KVStorageService storageService); | |||
} |
@@ -9,7 +9,6 @@ import com.jd.blockchain.crypto.CryptoProvider; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.CryptoSetting; | |||
import com.jd.blockchain.ledger.LedgerException; | |||
import com.jd.blockchain.ledger.LedgerInitSetting; | |||
import com.jd.blockchain.storage.service.ExPolicyKVStorage; | |||
import com.jd.blockchain.storage.service.KVStorageService; | |||
import com.jd.blockchain.storage.service.VersioningKVStorage; | |||
@@ -23,8 +22,6 @@ import com.jd.blockchain.utils.codec.Base58Utils; | |||
*/ | |||
public class LedgerManager implements LedgerManage { | |||
private static final String LEDGER_PREFIX = "LDG://"; | |||
// @Autowired | |||
// private ExistentialKVStorage exPolicyStorage; | |||
// | |||
@@ -138,18 +135,18 @@ public class LedgerManager implements LedgerManage { | |||
} | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.jd.blockchain.ledger.core.LedgerManager#newLedger(com.jd.blockchain. | |||
* ledger.core.ConsensusConfig, com.jd.blockchain.ledger.core.CryptoConfig) | |||
*/ | |||
@Override | |||
public LedgerEditor newLedger(LedgerInitSetting initSetting, KVStorageService storageService) { | |||
LedgerEditor genesisBlockEditor = LedgerTransactionalEditor.createEditor(initSetting, LEDGER_PREFIX, | |||
storageService.getExPolicyKVStorage(), storageService.getVersioningKVStorage()); | |||
return genesisBlockEditor; | |||
} | |||
// /* | |||
// * (non-Javadoc) | |||
// * | |||
// * @see com.jd.blockchain.ledger.core.LedgerManager#newLedger(com.jd.blockchain. | |||
// * ledger.core.ConsensusConfig, com.jd.blockchain.ledger.core.CryptoConfig) | |||
// */ | |||
// @Override | |||
// public LedgerEditor newLedger(LedgerInitSetting initSetting, KVStorageService storageService) { | |||
// LedgerEditor genesisBlockEditor = LedgerTransactionalEditor.createEditor(initSetting, LEDGER_PREFIX, | |||
// storageService.getExPolicyKVStorage(), storageService.getVersioningKVStorage()); | |||
// return genesisBlockEditor; | |||
// } | |||
static String getLedgerStoragePrefix(HashDigest ledgerHash) { | |||
String base58LedgerHash = Base58Utils.encode(ledgerHash.toBytes()); | |||
@@ -37,6 +37,7 @@ import com.jd.blockchain.ledger.core.CryptoConfig; | |||
import com.jd.blockchain.ledger.core.DataAccountSet; | |||
import com.jd.blockchain.ledger.core.LedgerDataset; | |||
import com.jd.blockchain.ledger.core.LedgerEditor; | |||
import com.jd.blockchain.ledger.core.LedgerInitializer; | |||
import com.jd.blockchain.ledger.core.LedgerManager; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.LedgerTransactionContext; | |||
@@ -81,13 +82,12 @@ public class LedgerManagerTest { | |||
public void testLedgerInit() { | |||
// 创建账本初始化配置; | |||
LedgerInitSetting initSetting = createLedgerInitSetting(); | |||
// 采用基于内存的 Storage; | |||
MemoryKVStorage storage = new MemoryKVStorage(); | |||
// 新建账本; | |||
LedgerManager ledgerManager = new LedgerManager(); | |||
LedgerEditor ldgEdt = ledgerManager.newLedger(initSetting, storage); | |||
LedgerEditor ldgEdt = LedgerInitializer.createLedgerEditor(initSetting, storage); | |||
// 创建一个模拟的创世交易; | |||
TransactionRequest genesisTxReq = LedgerTestUtils.createLedgerInitTxRequest(participants); | |||
@@ -1,6 +1,4 @@ | |||
package com.jd.blockchain.tools.initializer; | |||
import com.jd.blockchain.ledger.LedgerException; | |||
package com.jd.blockchain.ledger; | |||
public class LedgerInitException extends LedgerException{ | |||
@@ -1,4 +1,4 @@ | |||
package com.jd.blockchain.tools.initializer; | |||
package com.jd.blockchain.ledger; | |||
import java.io.File; | |||
import java.io.FileNotFoundException; | |||
@@ -13,14 +13,8 @@ import java.util.TreeMap; | |||
import com.jd.blockchain.consts.Global; | |||
import com.jd.blockchain.crypto.AddressEncoding; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.LedgerPermission; | |||
import com.jd.blockchain.ledger.ParticipantNode; | |||
import com.jd.blockchain.ledger.RoleInitData; | |||
import com.jd.blockchain.ledger.RoleInitSettings; | |||
import com.jd.blockchain.ledger.RolesPolicy; | |||
import com.jd.blockchain.ledger.TransactionPermission; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.PropertiesUtils; | |||
import com.jd.blockchain.utils.StringUtils; | |||
@@ -156,6 +150,11 @@ public class LedgerInitProperties { | |||
return null; | |||
} | |||
/** | |||
* 私有的构造器; | |||
* | |||
* @param ledgerSeed | |||
*/ | |||
private LedgerInitProperties(byte[] ledgerSeed) { | |||
this.ledgerSeed = ledgerSeed; | |||
} | |||
@@ -232,7 +231,7 @@ public class LedgerInitProperties { | |||
RoleInitData[] rolesInitDatas = rolesInitSettingMap.values() | |||
.toArray(new RoleInitData[rolesInitSettingMap.size()]); | |||
initProps.setRoles(rolesInitDatas); | |||
// 解析共识相关的属性; | |||
initProps.consensusProvider = PropertiesUtils.getRequiredProperty(props, CONSENSUS_SERVICE_PROVIDER); | |||
String consensusConfigFilePath = PropertiesUtils.getRequiredProperty(props, CONSENSUS_CONFIG); | |||
@@ -274,10 +273,10 @@ public class LedgerInitProperties { | |||
String pubkeyKey = getKeyOfParticipant(i, PART_PUBKEY); | |||
String base58PubKey = PropertiesUtils.getProperty(props, pubkeyKey, false); | |||
if (base58PubKey != null) { | |||
PubKey pubKey = KeyGenCommand.decodePubKey(base58PubKey); | |||
PubKey pubKey = KeyGenUtils.decodePubKey(base58PubKey); | |||
parti.setPubKey(pubKey); | |||
} else if (pubkeyPath != null) { | |||
PubKey pubKey = KeyGenCommand.readPubKey(pubkeyPath); | |||
PubKey pubKey = KeyGenUtils.readPubKey(pubkeyPath); | |||
parti.setPubKey(pubKey); | |||
} else { | |||
throw new IllegalArgumentException( |
@@ -60,7 +60,7 @@ public interface TransactionRequestBuilder extends HashObject { | |||
* Base64格式的签名摘要; | |||
* @return | |||
*/ | |||
void addEndpointSignature(DigitalSignature signature); | |||
void addEndpointSignature(DigitalSignature... signature); | |||
/** | |||
* 加入签名; | |||
@@ -71,7 +71,7 @@ public interface TransactionRequestBuilder extends HashObject { | |||
* Base64格式的签名摘要; | |||
* @return | |||
*/ | |||
void addNodeSignature(DigitalSignature signature); | |||
void addNodeSignature(DigitalSignature... signatures); | |||
/** | |||
* 生成交易请求; | |||
@@ -52,13 +52,21 @@ public class TxRequestBuilder implements TransactionRequestBuilder { | |||
} | |||
@Override | |||
public void addNodeSignature(DigitalSignature signature) { | |||
nodeSignatures.add(signature); | |||
public void addNodeSignature(DigitalSignature... signatures) { | |||
if (signatures != null) { | |||
for (DigitalSignature s : signatures) { | |||
nodeSignatures.add(s); | |||
} | |||
} | |||
} | |||
@Override | |||
public void addEndpointSignature(DigitalSignature signature) { | |||
endpointSignatures.add(signature); | |||
public void addEndpointSignature(DigitalSignature... signatures) { | |||
if (signatures != null) { | |||
for (DigitalSignature s : signatures) { | |||
endpointSignatures.add(s); | |||
} | |||
} | |||
} | |||
// public static DigitalSignature sign(TransactionContent txContent, AsymmetricKeypair keyPair) { | |||
@@ -8,9 +8,9 @@ | |||
*/ | |||
package com.jd.blockchain.sdk.samples; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
/** | |||
* | |||
@@ -33,13 +33,13 @@ public class SDKDemo_Params { | |||
"177gk2FpjufgEon92mf2oRRFXDBZkRy8SkFci7Jxc5pApZEJz3oeCoxieWatDD3Xg7i1QEN", | |||
"177gjvv7qvfCAXroFezSn23UFXLVLFofKS3y6DXkJ2DwVWS4LcRNtxRgiqWmQEeWNz4KQ3J" }; | |||
public static PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD); | |||
public static PrivKey privkey1 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD); | |||
public static PrivKey privkey2 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD); | |||
public static PrivKey privkey3 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD); | |||
public static PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD); | |||
public static PrivKey privkey1 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD); | |||
public static PrivKey privkey2 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD); | |||
public static PrivKey privkey3 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD); | |||
public static PubKey pubKey0 = KeyGenCommand.decodePubKey(PUB_KEYS[0]); | |||
public static PubKey pubKey1 = KeyGenCommand.decodePubKey(PUB_KEYS[1]); | |||
public static PubKey pubKey2 = KeyGenCommand.decodePubKey(PUB_KEYS[2]); | |||
public static PubKey pubKey3 = KeyGenCommand.decodePubKey(PUB_KEYS[3]); | |||
public static PubKey pubKey0 = KeyGenUtils.decodePubKey(PUB_KEYS[0]); | |||
public static PubKey pubKey1 = KeyGenUtils.decodePubKey(PUB_KEYS[1]); | |||
public static PubKey pubKey2 = KeyGenUtils.decodePubKey(PUB_KEYS[2]); | |||
public static PubKey pubKey3 = KeyGenUtils.decodePubKey(PUB_KEYS[3]); | |||
} |
@@ -1,6 +1,7 @@ | |||
package com.jd.blockchain.sdk.samples; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.BlockchainKeypair; | |||
@@ -9,7 +10,6 @@ import com.jd.blockchain.ledger.TransactionResponse; | |||
import com.jd.blockchain.ledger.TransactionTemplate; | |||
import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
public abstract class SDK_Base_Demo { | |||
@@ -25,9 +25,9 @@ public abstract class SDK_Base_Demo { | |||
public void init() { | |||
// 生成连接网关的账号 | |||
PrivKey privKey = KeyGenCommand.decodePrivKeyWithRawPassword(SDKDemo_Constant.PRIV_KEYS[0], SDKDemo_Constant.PASSWORD); | |||
PrivKey privKey = KeyGenUtils.decodePrivKeyWithRawPassword(SDKDemo_Constant.PRIV_KEYS[0], SDKDemo_Constant.PASSWORD); | |||
PubKey pubKey = KeyGenCommand.decodePubKey(SDKDemo_Constant.PUB_KEYS[0]); | |||
PubKey pubKey = KeyGenUtils.decodePubKey(SDKDemo_Constant.PUB_KEYS[0]); | |||
adminKey = new BlockchainKeypair(pubKey, privKey); | |||
@@ -8,6 +8,7 @@ import org.junit.Test; | |||
import com.jd.blockchain.contract.TransferContract; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.BlockchainKeyGenerator; | |||
@@ -18,9 +19,8 @@ import com.jd.blockchain.ledger.TransactionTemplate; | |||
import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.sdk.samples.SDKDemo_Constant; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.transaction.LongValueHolder; | |||
import com.jd.blockchain.transaction.GenericValueHolder; | |||
import com.jd.blockchain.transaction.LongValueHolder; | |||
import com.jd.blockchain.utils.Bytes; | |||
public class SDKDemo_Contract_Test_ { | |||
@@ -34,10 +34,10 @@ public class SDKDemo_Contract_Test_ { | |||
@Before | |||
public void init() { | |||
// 生成连接网关的账号 | |||
PrivKey privKey = KeyGenCommand.decodePrivKeyWithRawPassword(SDKDemo_Constant.PRIV_KEYS[0], | |||
PrivKey privKey = KeyGenUtils.decodePrivKeyWithRawPassword(SDKDemo_Constant.PRIV_KEYS[0], | |||
SDKDemo_Constant.PASSWORD); | |||
PubKey pubKey = KeyGenCommand.decodePubKey(SDKDemo_Constant.PUB_KEYS[0]); | |||
PubKey pubKey = KeyGenUtils.decodePubKey(SDKDemo_Constant.PUB_KEYS[0]); | |||
adminKey = new BlockchainKeypair(pubKey, privKey); | |||
@@ -1,8 +1,8 @@ | |||
package test.com.jd.blockchain.sdk.test; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
/** | |||
* Created by zhangshuang3 on 2018/10/17. | |||
@@ -21,14 +21,14 @@ public class SDK_GateWay_KeyPair_Para { | |||
"177gjtwLgmSx5v1hFb46ijh7L9kdbKUpJYqdKVf9afiEmAuLgo8Rck9yu5UuUcHknWJuWaF", | |||
"177gk1pudweTq5zgJTh8y3ENCTwtSFsKyX7YnpuKPo7rKgCkCBXVXh5z2syaTCPEMbuWRns" }; | |||
public static PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD); | |||
public static PrivKey privkey1 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD); | |||
public static PrivKey privkey2 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD); | |||
public static PrivKey privkey3 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD); | |||
public static PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD); | |||
public static PrivKey privkey1 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD); | |||
public static PrivKey privkey2 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD); | |||
public static PrivKey privkey3 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD); | |||
public static PubKey pubKey0 = KeyGenCommand.decodePubKey(PUB_KEYS[0]); | |||
public static PubKey pubKey1 = KeyGenCommand.decodePubKey(PUB_KEYS[1]); | |||
public static PubKey pubKey2 = KeyGenCommand.decodePubKey(PUB_KEYS[2]); | |||
public static PubKey pubKey3 = KeyGenCommand.decodePubKey(PUB_KEYS[3]); | |||
public static PubKey pubKey0 = KeyGenUtils.decodePubKey(PUB_KEYS[0]); | |||
public static PubKey pubKey1 = KeyGenUtils.decodePubKey(PUB_KEYS[1]); | |||
public static PubKey pubKey2 = KeyGenUtils.decodePubKey(PUB_KEYS[2]); | |||
public static PubKey pubKey3 = KeyGenUtils.decodePubKey(PUB_KEYS[3]); | |||
} |
@@ -17,6 +17,7 @@ import com.jd.blockchain.crypto.AddressEncoding; | |||
import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
import com.jd.blockchain.crypto.Crypto; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.gateway.GatewayConfigProperties.KeyPairConfig; | |||
@@ -28,6 +29,7 @@ import com.jd.blockchain.ledger.DataAccountKVSetOperation; | |||
import com.jd.blockchain.ledger.KVDataEntry; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.LedgerInfo; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.ParticipantNode; | |||
import com.jd.blockchain.ledger.PreparedTransaction; | |||
import com.jd.blockchain.ledger.TransactionResponse; | |||
@@ -42,9 +44,7 @@ import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.storage.service.KVStorageService; | |||
import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerBindingConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||
import com.jd.blockchain.tools.initializer.Prompter; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.codec.HexUtils; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker.AsyncCallback; | |||
@@ -110,7 +110,7 @@ public class IntegrationTest { | |||
peerStarting2.waitReturn(); | |||
peerStarting3.waitReturn(); | |||
String encodedBase58Pwd = KeyGenCommand.encodePasswordAsBase58(LedgerInitializeWebTest.PASSWORD); | |||
String encodedBase58Pwd = KeyGenUtils.encodePasswordAsBase58(LedgerInitializeWebTest.PASSWORD); | |||
KeyPairConfig gwkey0 = new KeyPairConfig(); | |||
gwkey0.setPubKeyValue(LedgerInitializeWebTest.PUB_KEYS[0]); | |||
@@ -452,16 +452,16 @@ public class IntegrationTest { | |||
NetworkAddress initAddr3 = initSetting.getConsensusParticipant(3).getInitializerAddress(); | |||
LedgerInitializeWebTest.NodeWebContext nodeCtx3 = new LedgerInitializeWebTest.NodeWebContext(3, initAddr3); | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeWebTest.PRIV_KEYS[0], | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeWebTest.PRIV_KEYS[0], | |||
LedgerInitializeWebTest.PASSWORD); | |||
PrivKey privkey1 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeWebTest.PRIV_KEYS[1], | |||
PrivKey privkey1 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeWebTest.PRIV_KEYS[1], | |||
LedgerInitializeWebTest.PASSWORD); | |||
PrivKey privkey2 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeWebTest.PRIV_KEYS[2], | |||
PrivKey privkey2 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeWebTest.PRIV_KEYS[2], | |||
LedgerInitializeWebTest.PASSWORD); | |||
PrivKey privkey3 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeWebTest.PRIV_KEYS[3], | |||
PrivKey privkey3 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeWebTest.PRIV_KEYS[3], | |||
LedgerInitializeWebTest.PASSWORD); | |||
String encodedPassword = KeyGenCommand.encodePasswordAsBase58(LedgerInitializeWebTest.PASSWORD); | |||
String encodedPassword = KeyGenUtils.encodePasswordAsBase58(LedgerInitializeWebTest.PASSWORD); | |||
CountDownLatch quitLatch = new CountDownLatch(4); | |||
@@ -16,12 +16,14 @@ import com.jd.blockchain.consensus.ConsensusProviders; | |||
import com.jd.blockchain.consensus.ConsensusSettings; | |||
import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.SignatureDigest; | |||
import com.jd.blockchain.gateway.GatewayConfigProperties.KeyPairConfig; | |||
import com.jd.blockchain.ledger.BlockchainKeyGenerator; | |||
import com.jd.blockchain.ledger.BlockchainKeypair; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.PreparedTransaction; | |||
import com.jd.blockchain.ledger.TransactionContent; | |||
import com.jd.blockchain.ledger.TransactionTemplate; | |||
@@ -37,10 +39,8 @@ import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerBindingConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitCommand; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProcess; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||
import com.jd.blockchain.tools.initializer.Prompter; | |||
import com.jd.blockchain.tools.initializer.web.LedgerInitializeWebController; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.ConsoleUtils; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker.AsyncCallback; | |||
@@ -90,7 +90,7 @@ public class ConsensusTest { | |||
peerStarting2.waitReturn(); | |||
peerStarting3.waitReturn(); | |||
String encodedBase58Pwd = KeyGenCommand.encodePasswordAsBase58(Utils.PASSWORD); | |||
String encodedBase58Pwd = KeyGenUtils.encodePasswordAsBase58(Utils.PASSWORD); | |||
KeyPairConfig gwkey0 = new KeyPairConfig(); | |||
gwkey0.setPubKeyValue(Utils.PUB_KEYS[0]); | |||
@@ -205,12 +205,12 @@ public class ConsensusTest { | |||
NetworkAddress initAddr3 = initSetting.getConsensusParticipant(3).getInitializerAddress(); | |||
NodeInitContext nodeCtx3 = new NodeInitContext(3, initAddr3); | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[0], Utils.PASSWORD); | |||
PrivKey privkey1 = KeyGenCommand.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[1], Utils.PASSWORD); | |||
PrivKey privkey2 = KeyGenCommand.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[2], Utils.PASSWORD); | |||
PrivKey privkey3 = KeyGenCommand.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[3], Utils.PASSWORD); | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[0], Utils.PASSWORD); | |||
PrivKey privkey1 = KeyGenUtils.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[1], Utils.PASSWORD); | |||
PrivKey privkey2 = KeyGenUtils.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[2], Utils.PASSWORD); | |||
PrivKey privkey3 = KeyGenUtils.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[3], Utils.PASSWORD); | |||
String encodedPassword = KeyGenCommand.encodePasswordAsBase58(Utils.PASSWORD); | |||
String encodedPassword = KeyGenUtils.encodePasswordAsBase58(Utils.PASSWORD); | |||
CountDownLatch quitLatch = new CountDownLatch(4); | |||
@@ -18,12 +18,14 @@ import com.jd.blockchain.consensus.ConsensusProviders; | |||
import com.jd.blockchain.consensus.ConsensusSettings; | |||
import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.SignatureDigest; | |||
import com.jd.blockchain.gateway.GatewayConfigProperties.KeyPairConfig; | |||
import com.jd.blockchain.ledger.BlockchainKeyGenerator; | |||
import com.jd.blockchain.ledger.BlockchainKeypair; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.PreparedTransaction; | |||
import com.jd.blockchain.ledger.TransactionContent; | |||
import com.jd.blockchain.ledger.TransactionTemplate; | |||
@@ -38,10 +40,8 @@ import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerBindingConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitCommand; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProcess; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||
import com.jd.blockchain.tools.initializer.Prompter; | |||
import com.jd.blockchain.tools.initializer.web.LedgerInitializeWebController; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.ConsoleUtils; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker.AsyncCallback; | |||
@@ -88,7 +88,7 @@ public class GlobalPerformanceTest { | |||
peerStarting2.waitReturn(); | |||
peerStarting3.waitReturn(); | |||
String encodedBase58Pwd = KeyGenCommand.encodePasswordAsBase58(Utils.PASSWORD); | |||
String encodedBase58Pwd = KeyGenUtils.encodePasswordAsBase58(Utils.PASSWORD); | |||
KeyPairConfig gwkey0 = new KeyPairConfig(); | |||
gwkey0.setPubKeyValue(Utils.PUB_KEYS[0]); | |||
@@ -203,12 +203,12 @@ public class GlobalPerformanceTest { | |||
NetworkAddress initAddr3 = initSetting.getConsensusParticipant(3).getInitializerAddress(); | |||
NodeInitContext nodeCtx3 = new NodeInitContext(3, initAddr3); | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[0], Utils.PASSWORD); | |||
PrivKey privkey1 = KeyGenCommand.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[1], Utils.PASSWORD); | |||
PrivKey privkey2 = KeyGenCommand.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[2], Utils.PASSWORD); | |||
PrivKey privkey3 = KeyGenCommand.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[3], Utils.PASSWORD); | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[0], Utils.PASSWORD); | |||
PrivKey privkey1 = KeyGenUtils.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[1], Utils.PASSWORD); | |||
PrivKey privkey2 = KeyGenUtils.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[2], Utils.PASSWORD); | |||
PrivKey privkey3 = KeyGenUtils.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[3], Utils.PASSWORD); | |||
String encodedPassword = KeyGenCommand.encodePasswordAsBase58(Utils.PASSWORD); | |||
String encodedPassword = KeyGenUtils.encodePasswordAsBase58(Utils.PASSWORD); | |||
CountDownLatch quitLatch = new CountDownLatch(4); | |||
@@ -15,10 +15,12 @@ import com.jd.blockchain.crypto.AddressEncoding; | |||
import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
import com.jd.blockchain.crypto.Crypto; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.crypto.SignatureDigest; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.core.CryptoConfig; | |||
import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
@@ -30,12 +32,10 @@ import com.jd.blockchain.storage.service.utils.MemoryDBConnFactory; | |||
//import com.jd.blockchain.storage.service.utils.MemoryBasedDb; | |||
import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProcess; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||
import com.jd.blockchain.tools.initializer.Prompter; | |||
import com.jd.blockchain.tools.initializer.web.InitConsensusServiceFactory; | |||
import com.jd.blockchain.tools.initializer.web.LedgerInitConsensusService; | |||
import com.jd.blockchain.tools.initializer.web.LedgerInitializeWebController; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker.AsyncCallback; | |||
@@ -81,22 +81,22 @@ public class LedgerInitializeTest { | |||
String[] memoryConnString = new String[] { "memory://local/0", "memory://local/1", "memory://local/2", | |||
"memory://local/3" }; | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD); | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD); | |||
DBConnectionConfig testDb0 = new DBConnectionConfig(); | |||
testDb0.setConnectionUri(memoryConnString[0]); | |||
AsyncCallback<HashDigest> callback0 = node0.startInit(0, privkey0, initSetting, testDb0, consolePrompter); | |||
PrivKey privkey1 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD); | |||
PrivKey privkey1 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD); | |||
DBConnectionConfig testDb1 = new DBConnectionConfig(); | |||
testDb1.setConnectionUri(memoryConnString[1]); | |||
AsyncCallback<HashDigest> callback1 = node1.startInit(1, privkey1, initSetting, testDb1, consolePrompter); | |||
PrivKey privkey2 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD); | |||
PrivKey privkey2 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD); | |||
DBConnectionConfig testDb2 = new DBConnectionConfig(); | |||
testDb2.setConnectionUri(memoryConnString[2]); | |||
AsyncCallback<HashDigest> callback2 = node2.startInit(2, privkey2, initSetting, testDb2, consolePrompter); | |||
PrivKey privkey3 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD); | |||
PrivKey privkey3 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD); | |||
DBConnectionConfig testDb03 = new DBConnectionConfig(); | |||
testDb03.setConnectionUri(memoryConnString[3]); | |||
AsyncCallback<HashDigest> callback3 = node3.startInit(3, privkey3, initSetting, testDb03, consolePrompter); | |||
@@ -115,19 +115,19 @@ public class LedgerInitializeTest { | |||
UserAccountSet userset0 = ledger0.getUserAccountSet(genesisBlock); | |||
PubKey pubKey0 = KeyGenCommand.decodePubKey(PUB_KEYS[0]); | |||
PubKey pubKey0 = KeyGenUtils.decodePubKey(PUB_KEYS[0]); | |||
Bytes address0 = AddressEncoding.generateAddress(pubKey0); | |||
UserAccount user0_0 = userset0.getUser(address0); | |||
PubKey pubKey1 = KeyGenCommand.decodePubKey(PUB_KEYS[1]); | |||
PubKey pubKey1 = KeyGenUtils.decodePubKey(PUB_KEYS[1]); | |||
Bytes address1 = AddressEncoding.generateAddress(pubKey1); | |||
UserAccount user1_0 = userset0.getUser(address1); | |||
PubKey pubKey2 = KeyGenCommand.decodePubKey(PUB_KEYS[2]); | |||
PubKey pubKey2 = KeyGenUtils.decodePubKey(PUB_KEYS[2]); | |||
Bytes address2 = AddressEncoding.generateAddress(pubKey2); | |||
UserAccount user2_0 = userset0.getUser(address2); | |||
PubKey pubKey3 = KeyGenCommand.decodePubKey(PUB_KEYS[3]); | |||
PubKey pubKey3 = KeyGenUtils.decodePubKey(PUB_KEYS[3]); | |||
Bytes address3 = AddressEncoding.generateAddress(pubKey3); | |||
UserAccount user3_0 = userset0.getUser(address3); | |||
} | |||
@@ -182,8 +182,8 @@ public class LedgerInitializeTest { | |||
public NodeContext(NetworkAddress address, Map<NetworkAddress, LedgerInitConsensusService> serviceRegisterMap) { | |||
this.initCsServiceFactory = new MultiThreadInterInvokerFactory(serviceRegisterMap); | |||
LedgerInitializeWebController initController = new LedgerInitializeWebController(ledgerManager, | |||
memoryDBConnFactory, initCsServiceFactory); | |||
LedgerInitializeWebController initController = new LedgerInitializeWebController(memoryDBConnFactory, | |||
initCsServiceFactory); | |||
serviceRegisterMap.put(address, initController); | |||
this.initProcess = initController; | |||
} | |||
@@ -16,12 +16,14 @@ import com.jd.blockchain.consensus.ConsensusSettings; | |||
import com.jd.blockchain.crypto.AddressEncoding; | |||
import com.jd.blockchain.crypto.Crypto; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.crypto.SignatureDigest; | |||
import com.jd.blockchain.crypto.SignatureFunction; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.LedgerInitOperation; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.Operation; | |||
import com.jd.blockchain.ledger.TransactionContent; | |||
import com.jd.blockchain.ledger.UserRegisterOperation; | |||
@@ -38,12 +40,10 @@ import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerBindingConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitCommand; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProcess; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||
import com.jd.blockchain.tools.initializer.Prompter; | |||
import com.jd.blockchain.tools.initializer.web.HttpInitConsensServiceFactory; | |||
import com.jd.blockchain.tools.initializer.web.LedgerInitConsensusService; | |||
import com.jd.blockchain.tools.initializer.web.LedgerInitializeWebController; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker.AsyncCallback; | |||
@@ -101,15 +101,15 @@ public class LedgerInitializeWebTest { | |||
node2.setPrompter(prompter); | |||
node3.setPrompter(prompter); | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD); | |||
PrivKey privkey1 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD); | |||
PrivKey privkey2 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD); | |||
PrivKey privkey3 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD); | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD); | |||
PrivKey privkey1 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD); | |||
PrivKey privkey2 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD); | |||
PrivKey privkey3 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD); | |||
PubKey pubKey0 = KeyGenCommand.decodePubKey(PUB_KEYS[0]); | |||
PubKey pubKey1 = KeyGenCommand.decodePubKey(PUB_KEYS[1]); | |||
PubKey pubKey2 = KeyGenCommand.decodePubKey(PUB_KEYS[2]); | |||
PubKey pubKey3 = KeyGenCommand.decodePubKey(PUB_KEYS[3]); | |||
PubKey pubKey0 = KeyGenUtils.decodePubKey(PUB_KEYS[0]); | |||
PubKey pubKey1 = KeyGenUtils.decodePubKey(PUB_KEYS[1]); | |||
PubKey pubKey2 = KeyGenUtils.decodePubKey(PUB_KEYS[2]); | |||
PubKey pubKey3 = KeyGenUtils.decodePubKey(PUB_KEYS[3]); | |||
// 测试生成“账本初始化许可”; | |||
LedgerInitProposal permission0 = testPreparePermisssion(node0, privkey0, initSetting, csProps); | |||
@@ -259,10 +259,10 @@ public class LedgerInitializeWebTest { | |||
NetworkAddress initAddr3 = initSetting.getConsensusParticipant(3).getInitializerAddress(); | |||
NodeWebContext node3 = new NodeWebContext(3, initAddr3); | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD); | |||
PrivKey privkey1 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD); | |||
PrivKey privkey2 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD); | |||
PrivKey privkey3 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD); | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD); | |||
PrivKey privkey1 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD); | |||
PrivKey privkey2 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD); | |||
PrivKey privkey3 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD); | |||
CountDownLatch quitLatch = new CountDownLatch(4); | |||
@@ -300,19 +300,19 @@ public class LedgerInitializeWebTest { | |||
UserAccountSet userset0 = ledger0.getUserAccountSet(genesisBlock); | |||
PubKey pubKey0 = KeyGenCommand.decodePubKey(PUB_KEYS[0]); | |||
PubKey pubKey0 = KeyGenUtils.decodePubKey(PUB_KEYS[0]); | |||
Bytes address0 = AddressEncoding.generateAddress(pubKey0); | |||
UserAccount user0_0 = userset0.getUser(address0); | |||
PubKey pubKey1 = KeyGenCommand.decodePubKey(PUB_KEYS[1]); | |||
PubKey pubKey1 = KeyGenUtils.decodePubKey(PUB_KEYS[1]); | |||
Bytes address1 = AddressEncoding.generateAddress(pubKey1); | |||
UserAccount user1_0 = userset0.getUser(address1); | |||
PubKey pubKey2 = KeyGenCommand.decodePubKey(PUB_KEYS[2]); | |||
PubKey pubKey2 = KeyGenUtils.decodePubKey(PUB_KEYS[2]); | |||
Bytes address2 = AddressEncoding.generateAddress(pubKey2); | |||
UserAccount user2_0 = userset0.getUser(address2); | |||
PubKey pubKey3 = KeyGenCommand.decodePubKey(PUB_KEYS[3]); | |||
PubKey pubKey3 = KeyGenUtils.decodePubKey(PUB_KEYS[3]); | |||
Bytes address3 = AddressEncoding.generateAddress(pubKey3); | |||
UserAccount user3_0 = userset0.getUser(address3); | |||
} | |||
@@ -21,6 +21,7 @@ import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
import com.jd.blockchain.crypto.Crypto; | |||
import com.jd.blockchain.crypto.CryptoAlgorithm; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.BlockchainKeyGenerator; | |||
@@ -30,6 +31,7 @@ import com.jd.blockchain.ledger.DataAccountKVSetOperation; | |||
import com.jd.blockchain.ledger.DataAccountRegisterOperation; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.LedgerInitOperation; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.LedgerPermission; | |||
import com.jd.blockchain.ledger.LedgerSecurityException; | |||
import com.jd.blockchain.ledger.TransactionPermission; | |||
@@ -54,10 +56,8 @@ import com.jd.blockchain.storage.service.impl.redis.RedisStorageService; | |||
import com.jd.blockchain.storage.service.impl.rocksdb.RocksDBConnectionFactory; | |||
import com.jd.blockchain.storage.service.utils.MemoryDBConnFactory; | |||
import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||
import com.jd.blockchain.tools.initializer.Prompter; | |||
import com.jd.blockchain.tools.initializer.web.LedgerInitConsensusService; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.transaction.TxBuilder; | |||
import com.jd.blockchain.utils.ArgumentSet; | |||
import com.jd.blockchain.utils.Bytes; | |||
@@ -559,19 +559,19 @@ public class LedgerPerformanceTest { | |||
NodeContext node3 = new NodeContext(initSetting.getConsensusParticipant(3).getInitializerAddress(), | |||
serviceRegisterMap, dbsetting3.connectionFactory); | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[0], Utils.PASSWORD); | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[0], Utils.PASSWORD); | |||
AsyncCallback<HashDigest> callback0 = node0.startInit(0, privkey0, initSetting, csProps, csProvider, | |||
dbsetting0.connectionConfig, consolePrompter, !optimized, hashAlg); | |||
PrivKey privkey1 = KeyGenCommand.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[1], Utils.PASSWORD); | |||
PrivKey privkey1 = KeyGenUtils.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[1], Utils.PASSWORD); | |||
AsyncCallback<HashDigest> callback1 = node1.startInit(1, privkey1, initSetting, csProps, csProvider, | |||
dbsetting1.connectionConfig, consolePrompter, !optimized, hashAlg); | |||
PrivKey privkey2 = KeyGenCommand.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[2], Utils.PASSWORD); | |||
PrivKey privkey2 = KeyGenUtils.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[2], Utils.PASSWORD); | |||
AsyncCallback<HashDigest> callback2 = node2.startInit(2, privkey2, initSetting, csProps, csProvider, | |||
dbsetting2.connectionConfig, consolePrompter, !optimized, hashAlg); | |||
PrivKey privkey3 = KeyGenCommand.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[3], Utils.PASSWORD); | |||
PrivKey privkey3 = KeyGenUtils.decodePrivKeyWithRawPassword(Utils.PRIV_KEYS[3], Utils.PASSWORD); | |||
AsyncCallback<HashDigest> callback3 = node3.startInit(3, privkey3, initSetting, csProps, csProvider, | |||
dbsetting3.connectionConfig, consolePrompter, !optimized, hashAlg); | |||
@@ -16,12 +16,14 @@ import com.jd.blockchain.crypto.Crypto; | |||
import com.jd.blockchain.crypto.CryptoAlgorithm; | |||
import com.jd.blockchain.crypto.CryptoProvider; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.crypto.SignatureDigest; | |||
import com.jd.blockchain.crypto.service.classic.ClassicCryptoService; | |||
import com.jd.blockchain.crypto.service.sm.SMCryptoService; | |||
import com.jd.blockchain.ledger.CryptoSetting; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.ParticipantNode; | |||
import com.jd.blockchain.ledger.core.CryptoConfig; | |||
import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
@@ -31,12 +33,10 @@ import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.storage.service.DbConnectionFactory; | |||
import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProcess; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||
import com.jd.blockchain.tools.initializer.Prompter; | |||
import com.jd.blockchain.tools.initializer.web.InitConsensusServiceFactory; | |||
import com.jd.blockchain.tools.initializer.web.LedgerInitConsensusService; | |||
import com.jd.blockchain.tools.initializer.web.LedgerInitializeWebController; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker.AsyncCallback; | |||
@@ -47,8 +47,7 @@ public class Utils { | |||
public static final String PASSWORD = "abc"; | |||
public static final String[] PUB_KEYS = { | |||
"3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9", | |||
public static final String[] PUB_KEYS = { "3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9", | |||
"3snPdw7i7PajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX", | |||
"3snPdw7i7PZi6TStiyc6mzjprnNhgs2atSGNS8wPYzhbKaUWGFJt7x", | |||
"3snPdw7i7PifPuRX7fu3jBjsb3rJRfDe9GtbDfvFJaJ4V4hHXQfhwk" }; | |||
@@ -86,7 +85,7 @@ public class Utils { | |||
public static ParticipantNode[] loadParticipantNodes() { | |||
ParticipantNode[] participantNodes = new ParticipantNode[PUB_KEYS.length]; | |||
for (int i = 0; i < PUB_KEYS.length; i++) { | |||
participantNodes[i] = new PartNode(i, KeyGenCommand.decodePubKey(PUB_KEYS[i])); | |||
participantNodes[i] = new PartNode(i, KeyGenUtils.decodePubKey(PUB_KEYS[i])); | |||
} | |||
return participantNodes; | |||
} | |||
@@ -119,8 +118,8 @@ public class Utils { | |||
DbConnectionFactory dbConnFactory) { | |||
this.dbConnFactory = dbConnFactory; | |||
this.initCsServiceFactory = new MultiThreadInterInvokerFactory(serviceRegisterMap); | |||
LedgerInitializeWebController initController = new LedgerInitializeWebController(ledgerManager, | |||
dbConnFactory, initCsServiceFactory); | |||
LedgerInitializeWebController initController = new LedgerInitializeWebController(dbConnFactory, | |||
initCsServiceFactory); | |||
serviceRegisterMap.put(address, initController); | |||
this.initProcess = initController; | |||
} | |||
@@ -14,15 +14,15 @@ import com.jd.blockchain.consensus.ConsensusProvider; | |||
import com.jd.blockchain.consensus.ConsensusSettings; | |||
import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.gateway.GatewayConfigProperties.KeyPairConfig; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerBindingConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||
import com.jd.blockchain.tools.initializer.Prompter; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker.AsyncCallback; | |||
import com.jd.blockchain.utils.net.NetworkAddress; | |||
@@ -68,7 +68,7 @@ public class IntegrationBaseTest { | |||
peerStarting2.waitReturn(); | |||
peerStarting3.waitReturn(); | |||
String encodedBase58Pwd = KeyGenCommand.encodePasswordAsBase58(LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
String encodedBase58Pwd = KeyGenUtils.encodePasswordAsBase58(LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
KeyPairConfig gwkey0 = new KeyPairConfig(); | |||
gwkey0.setPubKeyValue(LedgerInitializeWeb4SingleStepsTest.PUB_KEYS[0]); | |||
@@ -140,16 +140,16 @@ public class IntegrationBaseTest { | |||
NetworkAddress initAddr3 = initSetting.getConsensusParticipant(3).getInitializerAddress(); | |||
NodeWebContext nodeCtx3 = new NodeWebContext(3, initAddr3); | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[0], | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[0], | |||
LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
PrivKey privkey1 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[1], | |||
PrivKey privkey1 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[1], | |||
LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
PrivKey privkey2 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[2], | |||
PrivKey privkey2 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[2], | |||
LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
PrivKey privkey3 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[3], | |||
PrivKey privkey3 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[3], | |||
LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
String encodedPassword = KeyGenCommand.encodePasswordAsBase58(LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
String encodedPassword = KeyGenUtils.encodePasswordAsBase58(LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
CountDownLatch quitLatch = new CountDownLatch(4); | |||
@@ -18,12 +18,14 @@ import com.jd.blockchain.consensus.ConsensusProvider; | |||
import com.jd.blockchain.consensus.ConsensusSettings; | |||
import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.gateway.GatewayConfigProperties.KeyPairConfig; | |||
import com.jd.blockchain.ledger.BlockchainKeyGenerator; | |||
import com.jd.blockchain.ledger.BlockchainKeypair; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.LedgerInfo; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.PreparedTransaction; | |||
import com.jd.blockchain.ledger.TransactionResponse; | |||
import com.jd.blockchain.ledger.TransactionTemplate; | |||
@@ -32,9 +34,7 @@ import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerBindingConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||
import com.jd.blockchain.tools.initializer.Prompter; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker.AsyncCallback; | |||
import com.jd.blockchain.utils.net.NetworkAddress; | |||
@@ -85,7 +85,7 @@ public class IntegrationTest2 { | |||
peerStarting2.waitReturn(); | |||
peerStarting3.waitReturn(); | |||
String encodedBase58Pwd = KeyGenCommand.encodePasswordAsBase58(LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
String encodedBase58Pwd = KeyGenUtils.encodePasswordAsBase58(LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
KeyPairConfig gwkey0 = new KeyPairConfig(); | |||
gwkey0.setPubKeyValue(LedgerInitializeWeb4SingleStepsTest.PUB_KEYS[0]); | |||
@@ -178,16 +178,16 @@ public class IntegrationTest2 { | |||
NetworkAddress initAddr3 = initSetting.getConsensusParticipant(3).getInitializerAddress(); | |||
NodeWebContext nodeCtx3 = new NodeWebContext(3, initAddr3); | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[0], | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[0], | |||
LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
PrivKey privkey1 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[1], | |||
PrivKey privkey1 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[1], | |||
LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
PrivKey privkey2 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[2], | |||
PrivKey privkey2 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[2], | |||
LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
PrivKey privkey3 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[3], | |||
PrivKey privkey3 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[3], | |||
LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
String encodedPassword = KeyGenCommand.encodePasswordAsBase58(LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
String encodedPassword = KeyGenUtils.encodePasswordAsBase58(LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
CountDownLatch quitLatch = new CountDownLatch(4); | |||
@@ -2,6 +2,7 @@ package test.com.jd.blockchain.intgr; | |||
import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.gateway.GatewayConfigProperties; | |||
@@ -11,7 +12,6 @@ import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.storage.service.DbConnectionFactory; | |||
import com.jd.blockchain.tools.initializer.LedgerBindingConfig; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker; | |||
import org.junit.Test; | |||
@@ -65,7 +65,7 @@ public class IntegrationTest4Bftsmart { | |||
DbConnectionFactory dbConnectionFactory2 = peerNodes[2].getDBConnectionFactory(); | |||
DbConnectionFactory dbConnectionFactory3 = peerNodes[3].getDBConnectionFactory(); | |||
String encodedBase58Pwd = KeyGenCommand.encodePasswordAsBase58(LedgerInitializeTest.PASSWORD); | |||
String encodedBase58Pwd = KeyGenUtils.encodePasswordAsBase58(LedgerInitializeTest.PASSWORD); | |||
GatewayConfigProperties.KeyPairConfig gwkey0 = new GatewayConfigProperties.KeyPairConfig(); | |||
gwkey0.setPubKeyValue(IntegrationBase.PUB_KEYS[0]); | |||
@@ -97,9 +97,9 @@ public class IntegrationTest4Bftsmart { | |||
GatewayServiceFactory gwsrvFact = GatewayServiceFactory.connect(gateway.getServiceAddress()); | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(IntegrationBase.PRIV_KEYS[0], IntegrationBase.PASSWORD); | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(IntegrationBase.PRIV_KEYS[0], IntegrationBase.PASSWORD); | |||
PubKey pubKey0 = KeyGenCommand.decodePubKey(IntegrationBase.PUB_KEYS[0]); | |||
PubKey pubKey0 = KeyGenUtils.decodePubKey(IntegrationBase.PUB_KEYS[0]); | |||
AsymmetricKeypair adminKey = new AsymmetricKeypair(pubKey0, privkey0); | |||
@@ -2,6 +2,7 @@ package test.com.jd.blockchain.intgr; | |||
import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.gateway.GatewayConfigProperties; | |||
@@ -11,7 +12,6 @@ import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.storage.service.DbConnectionFactory; | |||
import com.jd.blockchain.tools.initializer.LedgerBindingConfig; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker; | |||
import org.junit.Test; | |||
@@ -46,7 +46,7 @@ public class IntegrationTest4Contract { | |||
DbConnectionFactory dbConnectionFactory2 = peerNodes[2].getDBConnectionFactory(); | |||
DbConnectionFactory dbConnectionFactory3 = peerNodes[3].getDBConnectionFactory(); | |||
String encodedBase58Pwd = KeyGenCommand.encodePasswordAsBase58(LedgerInitializeTest.PASSWORD); | |||
String encodedBase58Pwd = KeyGenUtils.encodePasswordAsBase58(LedgerInitializeTest.PASSWORD); | |||
GatewayConfigProperties.KeyPairConfig gwkey0 = new GatewayConfigProperties.KeyPairConfig(); | |||
gwkey0.setPubKeyValue(IntegrationBase.PUB_KEYS[0]); | |||
@@ -78,9 +78,9 @@ public class IntegrationTest4Contract { | |||
GatewayServiceFactory gwsrvFact = GatewayServiceFactory.connect(gateway.getServiceAddress()); | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(IntegrationBase.PRIV_KEYS[0], IntegrationBase.PASSWORD); | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(IntegrationBase.PRIV_KEYS[0], IntegrationBase.PASSWORD); | |||
PubKey pubKey0 = KeyGenCommand.decodePubKey(IntegrationBase.PUB_KEYS[0]); | |||
PubKey pubKey0 = KeyGenUtils.decodePubKey(IntegrationBase.PUB_KEYS[0]); | |||
AsymmetricKeypair adminKey = new AsymmetricKeypair(pubKey0, privkey0); | |||
@@ -2,6 +2,7 @@ package test.com.jd.blockchain.intgr; | |||
import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.gateway.GatewayConfigProperties.KeyPairConfig; | |||
@@ -11,7 +12,6 @@ import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.storage.service.DbConnectionFactory; | |||
import com.jd.blockchain.tools.initializer.LedgerBindingConfig; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker.AsyncCallback; | |||
import com.jd.blockchain.utils.io.FileUtils; | |||
@@ -72,7 +72,7 @@ public class IntegrationTest4MQ { | |||
DbConnectionFactory dbConnectionFactory2 = peerNodes[2].getDBConnectionFactory(); | |||
DbConnectionFactory dbConnectionFactory3 = peerNodes[3].getDBConnectionFactory(); | |||
String encodedBase58Pwd = KeyGenCommand.encodePasswordAsBase58(LedgerInitializeTest.PASSWORD); | |||
String encodedBase58Pwd = KeyGenUtils.encodePasswordAsBase58(LedgerInitializeTest.PASSWORD); | |||
KeyPairConfig gwkey0 = new KeyPairConfig(); | |||
gwkey0.setPubKeyValue(IntegrationBase.PUB_KEYS[0]); | |||
@@ -107,9 +107,9 @@ public class IntegrationTest4MQ { | |||
GatewayServiceFactory gwsrvFact = GatewayServiceFactory.connect(gateway.getServiceAddress()); | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(IntegrationBase.PRIV_KEYS[0], IntegrationBase.PASSWORD); | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(IntegrationBase.PRIV_KEYS[0], IntegrationBase.PASSWORD); | |||
PubKey pubKey0 = KeyGenCommand.decodePubKey(IntegrationBase.PUB_KEYS[0]); | |||
PubKey pubKey0 = KeyGenUtils.decodePubKey(IntegrationBase.PUB_KEYS[0]); | |||
AsymmetricKeypair adminKey = new AsymmetricKeypair(pubKey0, privkey0); | |||
@@ -2,7 +2,6 @@ package test.com.jd.blockchain.intgr; | |||
import com.jd.blockchain.crypto.*; | |||
import com.jd.blockchain.gateway.GatewayConfigProperties.KeyPairConfig; | |||
import com.jd.blockchain.ledger.BytesValue; | |||
import com.jd.blockchain.ledger.*; | |||
import com.jd.blockchain.ledger.core.DataAccount; | |||
import com.jd.blockchain.ledger.core.DataAccountSet; | |||
@@ -14,8 +13,6 @@ import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.storage.service.DbConnection; | |||
import com.jd.blockchain.storage.service.DbConnectionFactory; | |||
import com.jd.blockchain.tools.initializer.LedgerBindingConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.codec.HexUtils; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker.AsyncCallback; | |||
@@ -99,7 +96,7 @@ public class IntegrationTestAll4Redis { | |||
DbConnectionFactory dbConnectionFactory2 = peer2.getDBConnectionFactory(); | |||
DbConnectionFactory dbConnectionFactory3 = peer3.getDBConnectionFactory(); | |||
String encodedBase58Pwd = KeyGenCommand.encodePasswordAsBase58(LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
String encodedBase58Pwd = KeyGenUtils.encodePasswordAsBase58(LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
KeyPairConfig gwkey0 = new KeyPairConfig(); | |||
gwkey0.setPubKeyValue(PUB_KEYS[0]); | |||
@@ -118,15 +115,15 @@ public class IntegrationTestAll4Redis { | |||
dbConnectionFactory3 }); | |||
testConsistencyAmongNodes(ledgers); | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD); | |||
PrivKey privkey1 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD); | |||
PrivKey privkey2 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD); | |||
PrivKey privkey3 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD); | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD); | |||
PrivKey privkey1 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD); | |||
PrivKey privkey2 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD); | |||
PrivKey privkey3 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD); | |||
PubKey pubKey0 = KeyGenCommand.decodePubKey(PUB_KEYS[0]); | |||
PubKey pubKey1 = KeyGenCommand.decodePubKey(PUB_KEYS[1]); | |||
PubKey pubKey2 = KeyGenCommand.decodePubKey(PUB_KEYS[2]); | |||
PubKey pubKey3 = KeyGenCommand.decodePubKey(PUB_KEYS[3]); | |||
PubKey pubKey0 = KeyGenUtils.decodePubKey(PUB_KEYS[0]); | |||
PubKey pubKey1 = KeyGenUtils.decodePubKey(PUB_KEYS[1]); | |||
PubKey pubKey2 = KeyGenUtils.decodePubKey(PUB_KEYS[2]); | |||
PubKey pubKey3 = KeyGenUtils.decodePubKey(PUB_KEYS[3]); | |||
AsymmetricKeypair adminKey = new AsymmetricKeypair(pubKey0, privkey0); | |||
@@ -16,6 +16,7 @@ import com.jd.blockchain.consensus.ConsensusProvider; | |||
import com.jd.blockchain.consensus.ConsensusSettings; | |||
import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.gateway.GatewayConfigProperties.KeyPairConfig; | |||
@@ -24,6 +25,7 @@ import com.jd.blockchain.ledger.BlockchainKeypair; | |||
import com.jd.blockchain.ledger.DataAccountKVSetOperation; | |||
import com.jd.blockchain.ledger.KVDataEntry; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.PreparedTransaction; | |||
import com.jd.blockchain.ledger.TransactionResponse; | |||
import com.jd.blockchain.ledger.TransactionTemplate; | |||
@@ -35,9 +37,7 @@ import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.storage.service.DbConnection; | |||
import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerBindingConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||
import com.jd.blockchain.tools.initializer.Prompter; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker.AsyncCallback; | |||
import com.jd.blockchain.utils.io.BytesUtils; | |||
@@ -99,7 +99,7 @@ public class IntegrationTestDataAccount { | |||
peerStarting2.waitReturn(); | |||
peerStarting3.waitReturn(); | |||
String encodedBase58Pwd = KeyGenCommand.encodePasswordAsBase58(LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
String encodedBase58Pwd = KeyGenUtils.encodePasswordAsBase58(LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
KeyPairConfig gwkey0 = new KeyPairConfig(); | |||
gwkey0.setPubKeyValue(LedgerInitializeWeb4SingleStepsTest.PUB_KEYS[0]); | |||
@@ -123,9 +123,9 @@ public class IntegrationTestDataAccount { | |||
testConsistencyAmongNodes(context); | |||
// temp test add | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[0], | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[0], | |||
LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
PubKey pubKey0 = KeyGenCommand.decodePubKey(LedgerInitializeWeb4SingleStepsTest.PUB_KEYS[0]); | |||
PubKey pubKey0 = KeyGenUtils.decodePubKey(LedgerInitializeWeb4SingleStepsTest.PUB_KEYS[0]); | |||
AsymmetricKeypair adminKey = new AsymmetricKeypair(pubKey0, privkey0); | |||
// regist data account | |||
@@ -275,16 +275,16 @@ public class IntegrationTestDataAccount { | |||
NetworkAddress initAddr3 = initSetting.getConsensusParticipant(3).getInitializerAddress(); | |||
NodeWebContext nodeCtx3 = new NodeWebContext(3, initAddr3); | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[0], | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[0], | |||
LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
PrivKey privkey1 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[1], | |||
PrivKey privkey1 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[1], | |||
LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
PrivKey privkey2 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[2], | |||
PrivKey privkey2 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[2], | |||
LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
PrivKey privkey3 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[3], | |||
PrivKey privkey3 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeWeb4SingleStepsTest.PRIV_KEYS[3], | |||
LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
String encodedPassword = KeyGenCommand.encodePasswordAsBase58(LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
String encodedPassword = KeyGenUtils.encodePasswordAsBase58(LedgerInitializeWeb4SingleStepsTest.PASSWORD); | |||
CountDownLatch quitLatch = new CountDownLatch(4); | |||
@@ -10,6 +10,7 @@ package test.com.jd.blockchain.intgr.batch.bftsmart; | |||
import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.gateway.GatewayConfigProperties; | |||
@@ -21,7 +22,6 @@ import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.storage.service.DbConnectionFactory; | |||
import com.jd.blockchain.tools.initializer.LedgerBindingConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitCommand; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker; | |||
import com.jd.blockchain.utils.io.FileUtils; | |||
import com.jd.blockchain.utils.net.NetworkAddress; | |||
@@ -177,9 +177,9 @@ public class BftsmartLedgerInit { | |||
GatewayServiceFactory gwsrvFact = GatewayServiceFactory.connect(gateway.getServiceAddress()); | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(BftsmartConfig.PRIV_KEY[0], IntegrationBase.PASSWORD); | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(BftsmartConfig.PRIV_KEY[0], IntegrationBase.PASSWORD); | |||
PubKey pubKey0 = KeyGenCommand.decodePubKey(BftsmartConfig.PUB_KEY[0]); | |||
PubKey pubKey0 = KeyGenUtils.decodePubKey(BftsmartConfig.PUB_KEY[0]); | |||
AsymmetricKeypair adminKey = new AsymmetricKeypair(pubKey0, privkey0); | |||
@@ -233,7 +233,7 @@ public class BftsmartLedgerInit { | |||
} | |||
public GatewayTestRunner initGateWay(PeerTestRunner peerNode) { | |||
String encodedBase58Pwd = KeyGenCommand.encodePasswordAsBase58(LedgerInitializeTest.PASSWORD); | |||
String encodedBase58Pwd = KeyGenUtils.encodePasswordAsBase58(LedgerInitializeTest.PASSWORD); | |||
GatewayConfigProperties.KeyPairConfig gwkey0 = new GatewayConfigProperties.KeyPairConfig(); | |||
gwkey0.setPubKeyValue(BftsmartConfig.PUB_KEY[0]); | |||
@@ -8,8 +8,8 @@ | |||
*/ | |||
package test.com.jd.blockchain.intgr.batch.bftsmart; | |||
import static com.jd.blockchain.tools.keygen.KeyGenCommand.encodePrivKey; | |||
import static com.jd.blockchain.tools.keygen.KeyGenCommand.encodePubKey; | |||
import static com.jd.blockchain.crypto.KeyGenUtils.encodePrivKey; | |||
import static com.jd.blockchain.crypto.KeyGenUtils.encodePubKey; | |||
import org.junit.Test; | |||
@@ -18,6 +18,7 @@ import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
import com.jd.blockchain.crypto.Crypto; | |||
import com.jd.blockchain.crypto.CryptoProvider; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.crypto.SignatureDigest; | |||
@@ -25,6 +26,7 @@ import com.jd.blockchain.crypto.service.classic.ClassicCryptoService; | |||
import com.jd.blockchain.crypto.service.sm.SMCryptoService; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.LedgerInitOperation; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.UserRegisterOperation; | |||
import com.jd.blockchain.ledger.core.CryptoConfig; | |||
import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
@@ -36,12 +38,10 @@ import com.jd.blockchain.ledger.core.UserAccountSet; | |||
import com.jd.blockchain.storage.service.utils.MemoryDBConnFactory; | |||
import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProcess; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||
import com.jd.blockchain.tools.initializer.Prompter; | |||
import com.jd.blockchain.tools.initializer.web.InitConsensusServiceFactory; | |||
import com.jd.blockchain.tools.initializer.web.LedgerInitConsensusService; | |||
import com.jd.blockchain.tools.initializer.web.LedgerInitializeWebController; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker.AsyncCallback; | |||
@@ -99,22 +99,22 @@ public class LedgerInitializeTest { | |||
NodeContext node3 = new NodeContext(initSetting.getConsensusParticipant(3).getInitializerAddress(), | |||
serviceRegisterMap); | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD); | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD); | |||
DBConnectionConfig testDb0 = new DBConnectionConfig(); | |||
testDb0.setConnectionUri(dbConnections[0]); | |||
AsyncCallback<HashDigest> callback0 = node0.startInit(0, privkey0, initSetting, testDb0, consolePrompter); | |||
PrivKey privkey1 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD); | |||
PrivKey privkey1 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD); | |||
DBConnectionConfig testDb1 = new DBConnectionConfig(); | |||
testDb1.setConnectionUri(dbConnections[1]); | |||
AsyncCallback<HashDigest> callback1 = node1.startInit(1, privkey1, initSetting, testDb1, consolePrompter); | |||
PrivKey privkey2 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD); | |||
PrivKey privkey2 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD); | |||
DBConnectionConfig testDb2 = new DBConnectionConfig(); | |||
testDb2.setConnectionUri(dbConnections[2]); | |||
AsyncCallback<HashDigest> callback2 = node2.startInit(2, privkey2, initSetting, testDb2, consolePrompter); | |||
PrivKey privkey3 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD); | |||
PrivKey privkey3 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD); | |||
DBConnectionConfig testDb03 = new DBConnectionConfig(); | |||
testDb03.setConnectionUri(dbConnections[3]); | |||
AsyncCallback<HashDigest> callback3 = node3.startInit(3, privkey3, initSetting, testDb03, consolePrompter); | |||
@@ -145,22 +145,22 @@ public class LedgerInitializeTest { | |||
UserAccountSet userset0 = ledger0.getUserAccountSet(genesisBlock); | |||
PubKey pubKey0 = KeyGenCommand.decodePubKey(PUB_KEYS[0]); | |||
PubKey pubKey0 = KeyGenUtils.decodePubKey(PUB_KEYS[0]); | |||
Bytes address0 = AddressEncoding.generateAddress(pubKey0); | |||
UserAccount user0_0 = userset0.getUser(address0); | |||
assertNotNull(user0_0); | |||
PubKey pubKey1 = KeyGenCommand.decodePubKey(PUB_KEYS[1]); | |||
PubKey pubKey1 = KeyGenUtils.decodePubKey(PUB_KEYS[1]); | |||
Bytes address1 = AddressEncoding.generateAddress(pubKey1); | |||
UserAccount user1_0 = userset0.getUser(address1); | |||
assertNotNull(user1_0); | |||
PubKey pubKey2 = KeyGenCommand.decodePubKey(PUB_KEYS[2]); | |||
PubKey pubKey2 = KeyGenUtils.decodePubKey(PUB_KEYS[2]); | |||
Bytes address2 = AddressEncoding.generateAddress(pubKey2); | |||
UserAccount user2_0 = userset0.getUser(address2); | |||
assertNotNull(user2_0); | |||
PubKey pubKey3 = KeyGenCommand.decodePubKey(PUB_KEYS[3]); | |||
PubKey pubKey3 = KeyGenUtils.decodePubKey(PUB_KEYS[3]); | |||
Bytes address3 = AddressEncoding.generateAddress(pubKey3); | |||
UserAccount user3_0 = userset0.getUser(address3); | |||
assertNotNull(user3_0); | |||
@@ -225,7 +225,7 @@ public class LedgerInitializeTest { | |||
public NodeContext(NetworkAddress address, Map<NetworkAddress, LedgerInitConsensusService> serviceRegisterMap) { | |||
this.initCsServiceFactory = new MultiThreadInterInvokerFactory(serviceRegisterMap); | |||
LedgerInitializeWebController initController = new LedgerInitializeWebController(ledgerManager, storageDb, | |||
LedgerInitializeWebController initController = new LedgerInitializeWebController(storageDb, | |||
initCsServiceFactory); | |||
serviceRegisterMap.put(address, initController); | |||
this.initProcess = initController; | |||
@@ -4,6 +4,7 @@ import com.jd.blockchain.consensus.ConsensusProvider; | |||
import com.jd.blockchain.consensus.ConsensusSettings; | |||
import com.jd.blockchain.crypto.AddressEncoding; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.*; | |||
@@ -12,7 +13,6 @@ import com.jd.blockchain.storage.service.DbConnection; | |||
import com.jd.blockchain.storage.service.impl.composite.CompositeConnectionFactory; | |||
import com.jd.blockchain.tools.initializer.*; | |||
import com.jd.blockchain.tools.initializer.web.LedgerInitializeWebController; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker.AsyncCallback; | |||
@@ -87,10 +87,10 @@ public class LedgerInitializeWeb4Nodes { | |||
NetworkAddress initAddr3 = initSetting.getConsensusParticipant(3).getInitializerAddress(); | |||
NodeWebContext node3 = new NodeWebContext(3, initAddr3); | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD); | |||
PrivKey privkey1 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD); | |||
PrivKey privkey2 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD); | |||
PrivKey privkey3 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD); | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD); | |||
PrivKey privkey1 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD); | |||
PrivKey privkey2 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD); | |||
PrivKey privkey3 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD); | |||
CountDownLatch quitLatch = new CountDownLatch(4); | |||
@@ -140,25 +140,25 @@ public class LedgerInitializeWeb4Nodes { | |||
UserAccountSet userset0 = ledger0.getUserAccountSet(genesisBlock); | |||
PubKey pubKey0 = KeyGenCommand.decodePubKey(PUB_KEYS[0]); | |||
PubKey pubKey0 = KeyGenUtils.decodePubKey(PUB_KEYS[0]); | |||
Bytes address0 = AddressEncoding.generateAddress(pubKey0); | |||
System.out.printf("localNodeAddress0 = %s \r\n", address0.toBase58()); | |||
UserAccount user0_0 = userset0.getUser(address0); | |||
assertNotNull(user0_0); | |||
PubKey pubKey1 = KeyGenCommand.decodePubKey(PUB_KEYS[1]); | |||
PubKey pubKey1 = KeyGenUtils.decodePubKey(PUB_KEYS[1]); | |||
Bytes address1 = AddressEncoding.generateAddress(pubKey1); | |||
UserAccount user1_0 = userset0.getUser(address1); | |||
assertNotNull(user1_0); | |||
System.out.printf("localNodeAddress1 = %s \r\n", address1.toBase58()); | |||
PubKey pubKey2 = KeyGenCommand.decodePubKey(PUB_KEYS[2]); | |||
PubKey pubKey2 = KeyGenUtils.decodePubKey(PUB_KEYS[2]); | |||
Bytes address2 = AddressEncoding.generateAddress(pubKey2); | |||
UserAccount user2_0 = userset0.getUser(address2); | |||
assertNotNull(user2_0); | |||
System.out.printf("localNodeAddress2 = %s \r\n", address2.toBase58()); | |||
PubKey pubKey3 = KeyGenCommand.decodePubKey(PUB_KEYS[3]); | |||
PubKey pubKey3 = KeyGenUtils.decodePubKey(PUB_KEYS[3]); | |||
Bytes address3 = AddressEncoding.generateAddress(pubKey3); | |||
UserAccount user3_0 = userset0.getUser(address3); | |||
assertNotNull(user3_0); | |||
@@ -19,10 +19,12 @@ import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
import com.jd.blockchain.consensus.ConsensusProvider; | |||
import com.jd.blockchain.consensus.ConsensusSettings; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.crypto.SignatureDigest; | |||
import com.jd.blockchain.ledger.LedgerInitOperation; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.Operation; | |||
import com.jd.blockchain.ledger.TransactionContent; | |||
import com.jd.blockchain.ledger.UserRegisterOperation; | |||
@@ -36,12 +38,10 @@ import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerBindingConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitCommand; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProcess; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||
import com.jd.blockchain.tools.initializer.Prompter; | |||
import com.jd.blockchain.tools.initializer.web.HttpInitConsensServiceFactory; | |||
import com.jd.blockchain.tools.initializer.web.LedgerInitConsensusService; | |||
import com.jd.blockchain.tools.initializer.web.LedgerInitializeWebController; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.transaction.TxRequestBuilder; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker.AsyncCallback; | |||
@@ -105,15 +105,15 @@ public class LedgerInitializeWeb4SingleStepsTest { | |||
node2.setPrompter(prompter); | |||
node3.setPrompter(prompter); | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD); | |||
PrivKey privkey1 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD); | |||
PrivKey privkey2 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD); | |||
PrivKey privkey3 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD); | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD); | |||
PrivKey privkey1 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD); | |||
PrivKey privkey2 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD); | |||
PrivKey privkey3 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD); | |||
PubKey pubKey0 = KeyGenCommand.decodePubKey(PUB_KEYS[0]); | |||
PubKey pubKey1 = KeyGenCommand.decodePubKey(PUB_KEYS[1]); | |||
PubKey pubKey2 = KeyGenCommand.decodePubKey(PUB_KEYS[2]); | |||
PubKey pubKey3 = KeyGenCommand.decodePubKey(PUB_KEYS[3]); | |||
PubKey pubKey0 = KeyGenUtils.decodePubKey(PUB_KEYS[0]); | |||
PubKey pubKey1 = KeyGenUtils.decodePubKey(PUB_KEYS[1]); | |||
PubKey pubKey2 = KeyGenUtils.decodePubKey(PUB_KEYS[2]); | |||
PubKey pubKey3 = KeyGenUtils.decodePubKey(PUB_KEYS[3]); | |||
// 测试生成“账本初始化许可”; | |||
LedgerInitProposal permission0 = testPreparePermisssion(node0, privkey0, initSetting, csProps); | |||
@@ -18,10 +18,12 @@ import com.jd.blockchain.consensus.ConsensusProviders; | |||
import com.jd.blockchain.consensus.ConsensusSettings; | |||
import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.ledger.BlockchainKeyGenerator; | |||
import com.jd.blockchain.ledger.BlockchainKeypair; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.TransactionRequest; | |||
import com.jd.blockchain.ledger.TransactionRequestBuilder; | |||
import com.jd.blockchain.ledger.core.DefaultOperationHandleRegisteration; | |||
@@ -32,10 +34,8 @@ import com.jd.blockchain.ledger.core.LedgerRepository; | |||
import com.jd.blockchain.ledger.core.TransactionBatchProcessor; | |||
import com.jd.blockchain.service.TransactionBatchResultHandle; | |||
import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||
import com.jd.blockchain.tools.initializer.Prompter; | |||
import com.jd.blockchain.tools.initializer.web.LedgerInitConsensusService; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.transaction.TxBuilder; | |||
import com.jd.blockchain.utils.ConsoleUtils; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker.AsyncCallback; | |||
@@ -146,28 +146,28 @@ public class LedgerBlockGeneratingTest { | |||
String[] memConns = new String[] { "memory://local/0", "memory://local/1", "memory://local/2", | |||
"memory://local/3" }; | |||
PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeTest.PRIV_KEYS[0], | |||
PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeTest.PRIV_KEYS[0], | |||
LedgerInitializeTest.PASSWORD); | |||
DBConnectionConfig testDb0 = new DBConnectionConfig(); | |||
testDb0.setConnectionUri(memConns[0]); | |||
AsyncCallback<HashDigest> callback0 = node0.startInit(0, privkey0, initSetting, testDb0, consolePrompter, | |||
!optimized); | |||
PrivKey privkey1 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeTest.PRIV_KEYS[1], | |||
PrivKey privkey1 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeTest.PRIV_KEYS[1], | |||
LedgerInitializeTest.PASSWORD); | |||
DBConnectionConfig testDb1 = new DBConnectionConfig(); | |||
testDb1.setConnectionUri(memConns[1]); | |||
AsyncCallback<HashDigest> callback1 = node1.startInit(1, privkey1, initSetting, testDb1, consolePrompter, | |||
!optimized); | |||
PrivKey privkey2 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeTest.PRIV_KEYS[2], | |||
PrivKey privkey2 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeTest.PRIV_KEYS[2], | |||
LedgerInitializeTest.PASSWORD); | |||
DBConnectionConfig testDb2 = new DBConnectionConfig(); | |||
testDb2.setConnectionUri(memConns[2]); | |||
AsyncCallback<HashDigest> callback2 = node2.startInit(2, privkey2, initSetting, testDb2, consolePrompter, | |||
!optimized); | |||
PrivKey privkey3 = KeyGenCommand.decodePrivKeyWithRawPassword(LedgerInitializeTest.PRIV_KEYS[3], | |||
PrivKey privkey3 = KeyGenUtils.decodePrivKeyWithRawPassword(LedgerInitializeTest.PRIV_KEYS[3], | |||
LedgerInitializeTest.PASSWORD); | |||
DBConnectionConfig testDb03 = new DBConnectionConfig(); | |||
testDb03.setConnectionUri(memConns[3]); | |||
@@ -15,6 +15,7 @@ import com.jd.blockchain.consensus.bftsmart.BftsmartConsensusSettings; | |||
import com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings; | |||
import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.ContractCodeDeployOperation; | |||
@@ -30,7 +31,6 @@ import com.jd.blockchain.ledger.TransactionContentBody; | |||
import com.jd.blockchain.ledger.TransactionRequest; | |||
import com.jd.blockchain.ledger.TransactionResponse; | |||
import com.jd.blockchain.ledger.UserRegisterOperation; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.codec.Base58Utils; | |||
/** | |||
@@ -116,8 +116,8 @@ public class SettingsInit { | |||
CapabilitySettings.ledgerHash = hash; | |||
// 处理用户 | |||
PrivKey privKey = KeyGenCommand.decodePrivKeyWithRawPassword(settings.getPrivKey(), settings.getPwd()); | |||
PubKey pubKey = KeyGenCommand.decodePubKey(settings.getPubKey()); | |||
PrivKey privKey = KeyGenUtils.decodePrivKeyWithRawPassword(settings.getPrivKey(), settings.getPwd()); | |||
PubKey pubKey = KeyGenUtils.decodePubKey(settings.getPubKey()); | |||
CapabilitySettings.adminKey = new AsymmetricKeypair(pubKey, privKey); | |||
} | |||
@@ -2,8 +2,12 @@ package com.jd.blockchain.tools.initializer; | |||
import org.springframework.context.annotation.Configuration; | |||
/** | |||
* Spring Boot 项目的配置类; | |||
* | |||
* @author huanghaiquan | |||
* | |||
*/ | |||
@Configuration | |||
public interface InitializerConfiguration { | |||
} |
@@ -12,12 +12,13 @@ import org.springframework.context.ConfigurableApplicationContext; | |||
import com.jd.blockchain.crypto.AddressEncoding; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.LedgerInitProperties.ConsensusParticipantConfig; | |||
import com.jd.blockchain.ledger.core.LedgerManager; | |||
import com.jd.blockchain.tools.initializer.LedgerBindingConfig.BindingConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties.ConsensusParticipantConfig; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.ArgumentSet; | |||
import com.jd.blockchain.utils.ArgumentSet.ArgEntry; | |||
import com.jd.blockchain.utils.ArgumentSet.Setting; | |||
@@ -86,7 +87,7 @@ public class LedgerInitCommand { | |||
// load ledger init setting; | |||
LedgerInitProperties ledgerInitProperties = LedgerInitProperties.resolve(iniArg.getValue()); | |||
String localNodePubKeyString = localConf.getLocal().getPubKeyString(); | |||
PubKey localNodePubKey = KeyGenCommand.decodePubKey(localNodePubKeyString); | |||
PubKey localNodePubKey = KeyGenUtils.decodePubKey(localNodePubKeyString); | |||
// 地址根据公钥生成 | |||
String localNodeAddress = AddressEncoding.generateAddress(localNodePubKey).toBase58(); | |||
@@ -97,7 +98,7 @@ public class LedgerInitCommand { | |||
// String partiAddress = partiConf.getAddress(); | |||
// if (partiAddress == null) { | |||
// if (partiConf.getPubKeyPath() != null) { | |||
// PubKey pubKey = KeyGenCommand.readPubKey(partiConf.getPubKeyPath()); | |||
// PubKey pubKey = KeyGenUtils.readPubKey(partiConf.getPubKeyPath()); | |||
// partiConf.setPubKey(pubKey); | |||
// partiAddress = partiConf.getAddress(); | |||
// } | |||
@@ -114,9 +115,9 @@ public class LedgerInitCommand { | |||
// 加载当前节点的私钥; | |||
String base58Pwd = localConf.getLocal().getPassword(); | |||
if (base58Pwd == null) { | |||
base58Pwd = KeyGenCommand.readPasswordString(); | |||
base58Pwd = KeyGenUtils.readPasswordString(); | |||
} | |||
PrivKey privKey = KeyGenCommand.decodePrivKey(localConf.getLocal().getPrivKeyString(), base58Pwd); | |||
PrivKey privKey = KeyGenUtils.decodePrivKey(localConf.getLocal().getPrivKeyString(), base58Pwd); | |||
// Output ledger binding config of peer; | |||
if (!FileUtils.existDirectory(localConf.getBindingOutDir())) { | |||
@@ -189,7 +190,7 @@ public class LedgerInitCommand { | |||
// 设置参与方名称 | |||
bindingConf.getParticipant().setName(ledgerInitProperties.getConsensusParticipant(currId).getName()); | |||
String encodedPrivKey = KeyGenCommand.encodePrivKey(privKey, base58Pwd); | |||
String encodedPrivKey = KeyGenUtils.encodePrivKey(privKey, base58Pwd); | |||
bindingConf.getParticipant().setPk(encodedPrivKey); | |||
bindingConf.getParticipant().setPassword(base58Pwd); | |||
@@ -3,6 +3,7 @@ package com.jd.blockchain.tools.initializer; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.ledger.CryptoSetting; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
/** | |||
* | |||
@@ -3,7 +3,7 @@ package com.jd.blockchain.tools.initializer.web; | |||
import java.io.InputStream; | |||
import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
import com.jd.blockchain.tools.initializer.LedgerInitException; | |||
import com.jd.blockchain.ledger.LedgerInitException; | |||
import com.jd.blockchain.utils.http.HttpServiceContext; | |||
import com.jd.blockchain.utils.http.ResponseConverter; | |||
import com.jd.blockchain.utils.http.agent.ServiceRequest; | |||
@@ -10,7 +10,6 @@ import java.util.Random; | |||
import java.util.concurrent.CountDownLatch; | |||
import java.util.concurrent.TimeUnit; | |||
import com.jd.blockchain.transaction.*; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.PathVariable; | |||
import org.springframework.web.bind.annotation.RequestBody; | |||
@@ -31,34 +30,29 @@ import com.jd.blockchain.crypto.SignatureDigest; | |||
import com.jd.blockchain.crypto.SignatureFunction; | |||
import com.jd.blockchain.crypto.service.classic.ClassicCryptoService; | |||
import com.jd.blockchain.crypto.service.sm.SMCryptoService; | |||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||
import com.jd.blockchain.ledger.BlockchainIdentityData; | |||
import com.jd.blockchain.ledger.CryptoSetting; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.DigitalSignature; | |||
import com.jd.blockchain.ledger.LedgerInitException; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.LedgerInitProperties.ConsensusParticipantConfig; | |||
import com.jd.blockchain.ledger.LedgerInitSetting; | |||
import com.jd.blockchain.ledger.Operation; | |||
import com.jd.blockchain.ledger.ParticipantNode; | |||
import com.jd.blockchain.ledger.TransactionBuilder; | |||
import com.jd.blockchain.ledger.TransactionContent; | |||
import com.jd.blockchain.ledger.TransactionRequest; | |||
import com.jd.blockchain.ledger.TransactionState; | |||
import com.jd.blockchain.ledger.UserRegisterOperation; | |||
import com.jd.blockchain.ledger.core.CryptoConfig; | |||
import com.jd.blockchain.ledger.core.LedgerEditor; | |||
import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
import com.jd.blockchain.ledger.core.LedgerInitProposalData; | |||
import com.jd.blockchain.ledger.core.LedgerManage; | |||
import com.jd.blockchain.ledger.core.LedgerTransactionContext; | |||
import com.jd.blockchain.ledger.core.LedgerInitializer; | |||
import com.jd.blockchain.storage.service.DbConnection; | |||
import com.jd.blockchain.storage.service.DbConnectionFactory; | |||
import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.InitializingStep; | |||
import com.jd.blockchain.tools.initializer.LedgerInitException; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProcess; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties.ConsensusParticipantConfig; | |||
import com.jd.blockchain.tools.initializer.Prompter; | |||
import com.jd.blockchain.transaction.DigitalSignatureBlob; | |||
import com.jd.blockchain.transaction.LedgerInitData; | |||
import com.jd.blockchain.transaction.SignatureUtils; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.concurrent.InvocationResult; | |||
import com.jd.blockchain.utils.io.BytesUtils; | |||
@@ -86,7 +80,7 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
private volatile LedgerInitProposal localPermission; | |||
private TransactionContent initTxContent; | |||
private volatile LedgerInitializer initializer; | |||
private volatile int currentId = -1; | |||
@@ -100,19 +94,12 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
private volatile ConsensusProvider consensusProvider; | |||
private volatile LedgerBlock genesisBlock; | |||
private volatile LedgerInitDecision localDecision; | |||
private volatile DecisionResultHandle[] decisions; | |||
private volatile DbConnection dbConn; | |||
private volatile LedgerEditor ledgerEditor; | |||
@Autowired | |||
private LedgerManage ledgerManager; | |||
@Autowired | |||
private DbConnectionFactory dbConnFactory; | |||
@@ -123,11 +110,10 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
this.SIGN_FUNC = Crypto.getSignatureFunction(DEFAULT_SIGN_ALGORITHM); | |||
} | |||
public LedgerInitializeWebController(LedgerManage ledgerManager, DbConnectionFactory dbConnFactory, | |||
public LedgerInitializeWebController(DbConnectionFactory dbConnFactory, | |||
InitConsensusServiceFactory initCsServiceFactory) { | |||
this.SIGN_FUNC = Crypto.getSignatureFunction(DEFAULT_SIGN_ALGORITHM); | |||
this.ledgerManager = ledgerManager; | |||
this.dbConnFactory = dbConnFactory; | |||
this.initCsServiceFactory = initCsServiceFactory; | |||
} | |||
@@ -137,7 +123,7 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
} | |||
public TransactionContent getInitTxContent() { | |||
return initTxContent; | |||
return initializer.getTransactionContent(); | |||
} | |||
public LedgerInitProposal getLocalPermission() { | |||
@@ -152,10 +138,6 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
this.prompter = prompter; | |||
} | |||
// private ConsensusProvider getConsensusProvider() { | |||
// return consensusProvider; | |||
// } | |||
private void setConsensusProvider(ConsensusProvider consensusProvider) { | |||
this.consensusProvider = consensusProvider; | |||
} | |||
@@ -226,11 +208,10 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
public LedgerInitDecision makeLocalDecision(PrivKey privKey) { | |||
// 生成账本; | |||
this.ledgerEditor = ledgerManager.newLedger(this.ledgerInitSetting, dbConn.getStorageService()); | |||
this.genesisBlock = initLedgerDataset(ledgerEditor); | |||
initializer.prepareLedger(dbConn.getStorageService(), getNodesSignatures()); | |||
// 生成签名决定; | |||
this.localDecision = makeDecision(currentId, genesisBlock.getHash(), privKey); | |||
this.localDecision = makeDecision(currentId, initializer.getLedgerHash(), privKey); | |||
this.decisions = new DecisionResultHandle[this.ledgerInitSetting.getConsensusParticipants().length]; | |||
for (int i = 0; i < decisions.length; i++) { | |||
// 参与者的 id 是依次递增的; | |||
@@ -241,6 +222,18 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
return localDecision; | |||
} | |||
private DigitalSignature[] getNodesSignatures() { | |||
ParticipantNode[] parties = this.ledgerInitSetting.getConsensusParticipants(); | |||
DigitalSignature[] signatures = new DigitalSignature[parties.length]; | |||
for (int i = 0; i < parties.length; i++) { | |||
PubKey pubKey = parties[i].getPubKey(); | |||
SignatureDigest signDigest = this.permissions[i].getTransactionSignature(); | |||
signatures[i] = new DigitalSignatureBlob(pubKey, signDigest); | |||
} | |||
return signatures; | |||
} | |||
public HashDigest consensusDecisions(PrivKey privKey) { | |||
// 获取其它参与方的账本生成结果; | |||
boolean allDecided = startRequestDecisions(privKey, prompter); | |||
@@ -248,13 +241,13 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
prompter.error( | |||
"Rollback ledger initialization because of not all nodes make same decision! --[Current Participant=%s]", | |||
currentId); | |||
ledgerEditor.cancel(); | |||
initializer.cancel(); | |||
return null; | |||
} | |||
// 执行提交提交; | |||
ledgerEditor.commit(); | |||
return genesisBlock.getHash(); | |||
initializer.commit(); | |||
return initializer.getLedgerHash(); | |||
} | |||
public void closeDb() { | |||
@@ -334,7 +327,6 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
List<ConsensusParticipantConfig> partiList = ledgerProps.getConsensusParticipants(); | |||
ConsensusParticipantConfig[] parties = new ConsensusParticipantConfig[partiList.size()]; | |||
parties = partiList.toArray(parties); | |||
// ConsensusParticipantConfig[] parties = partiList.toArray(new ConsensusParticipantConfig[partiList.size()]); | |||
ConsensusParticipantConfig[] orderedParties = sortAndVerify(parties); | |||
initSetting.setConsensusParticipants(orderedParties); | |||
initSetting.setCreatedTime(ledgerProps.getCreatedTime()); | |||
@@ -369,19 +361,11 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
initializerAddresses[i] = orderedParties[i].getInitializerAddress(); | |||
} | |||
// 生成初始化交易,并签署许可; | |||
TransactionBuilder initTxBuilder = new TxBuilder(null);// 账本初始化交易的账本 hash 为 null; | |||
initTxBuilder.ledgers().create(initSetting); | |||
for (ParticipantNode p : initSetting.getConsensusParticipants()) { | |||
// TODO:暂时只支持注册用户的初始化操作; | |||
BlockchainIdentity superUserId = new BlockchainIdentityData(p.getPubKey()); | |||
initTxBuilder.users().register(superUserId); | |||
} | |||
// 账本初始化配置声明的创建时间来初始化交易时间戳;注:不能用本地时间,因为共识节点之间的本地时间系统不一致; | |||
this.initTxContent = initTxBuilder.prepareContent(initSetting.getCreatedTime()); | |||
// 初始化账本; | |||
this.initializer = LedgerInitializer.create(ledgerInitSetting); | |||
// 对初始交易签名,生成当前参与者的账本初始化许可; | |||
SignatureDigest permissionSign = SignatureUtils.sign(initTxContent, privKey); | |||
SignatureDigest permissionSign = initializer.signTransaction(privKey); | |||
LedgerInitProposalData permission = new LedgerInitProposalData(currentId, permissionSign); | |||
this.currentId = currentId; | |||
@@ -405,39 +389,6 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
} | |||
/** | |||
* 初始化账本数据,返回创始区块; | |||
* | |||
* @param ledgerEditor | |||
* @return | |||
*/ | |||
private LedgerBlock initLedgerDataset(LedgerEditor ledgerEditor) { | |||
// 初始化时,自动将参与方注册为账本的用户; | |||
TxRequestBuilder txReqBuilder = new TxRequestBuilder(this.initTxContent); | |||
ParticipantNode[] parties = this.ledgerInitSetting.getConsensusParticipants(); | |||
for (int i = 0; i < parties.length; i++) { | |||
PubKey pubKey = parties[i].getPubKey(); | |||
SignatureDigest signDigest = this.permissions[i].getTransactionSignature(); | |||
DigitalSignatureBlob digitalSignature = new DigitalSignatureBlob(pubKey, signDigest); | |||
txReqBuilder.addNodeSignature(digitalSignature); | |||
} | |||
TransactionRequest txRequest = txReqBuilder.buildRequest(); | |||
LedgerTransactionContext txCtx = ledgerEditor.newTransaction(txRequest); | |||
Operation[] ops = txRequest.getTransactionContent().getOperations(); | |||
// 注册用户; 注:第一个操作是 LedgerInitOperation; | |||
// TODO:暂时只支持注册用户的初始化操作; | |||
for (int i = 1; i < ops.length; i++) { | |||
UserRegisterOperation userRegOP = (UserRegisterOperation) ops[i]; | |||
txCtx.getDataset().getUserAccountSet().register(userRegOP.getUserID().getAddress(), | |||
userRegOP.getUserID().getPubKey()); | |||
} | |||
txCtx.commit(TransactionState.SUCCESS, null); | |||
return ledgerEditor.prepare(); | |||
} | |||
/** | |||
* 请求所有其它参与方的账本创建许可; | |||
* | |||
* @param privKey | |||
@@ -506,7 +457,7 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
continue; | |||
} | |||
if (!SignatureUtils.verifySignature(this.initTxContent, permission.getTransactionSignature(), pubKey)) { | |||
if (!SignatureUtils.verifySignature(initializer.getTransactionContent(), permission.getTransactionSignature(), pubKey)) { | |||
prompter.error("Invalid permission from participant! --[Id=%s][name=%s]", participants[i].getAddress(), | |||
participants[i].getName()); | |||
allPermitted = false; | |||
@@ -753,7 +704,7 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
String.format("Reject decision because of self-synchronization! --[Id=%s]", remoteId)); | |||
} | |||
if (this.genesisBlock == null) { | |||
if (this.initializer == null) { | |||
// 当前参与者尚未准备就绪,返回 null; | |||
prompter.info("Not ready for genesis block! --[RemoteId=%s][CurrentId=%s]", remoteId, currentId); | |||
return null; | |||
@@ -3,8 +3,8 @@ package com.jd.blockchain.tools.initializer.web; | |||
import java.io.InputStream; | |||
import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
import com.jd.blockchain.ledger.LedgerInitException; | |||
import com.jd.blockchain.ledger.core.LedgerInitProposalData; | |||
import com.jd.blockchain.tools.initializer.LedgerInitException; | |||
import com.jd.blockchain.utils.http.HttpServiceContext; | |||
import com.jd.blockchain.utils.http.ResponseConverter; | |||
import com.jd.blockchain.utils.http.agent.ServiceRequest; | |||
@@ -19,14 +19,14 @@ import org.junit.Test; | |||
import org.springframework.core.io.ClassPathResource; | |||
import com.jd.blockchain.crypto.AddressEncoding; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.LedgerPermission; | |||
import com.jd.blockchain.ledger.RoleInitData; | |||
import com.jd.blockchain.ledger.RolesPolicy; | |||
import com.jd.blockchain.ledger.TransactionPermission; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties.ConsensusParticipantConfig; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.ledger.LedgerInitProperties.ConsensusParticipantConfig; | |||
import com.jd.blockchain.utils.codec.HexUtils; | |||
public class LedgerInitPropertiesTest { | |||
@@ -133,7 +133,7 @@ public class LedgerInitPropertiesTest { | |||
ConsensusParticipantConfig part0 = initProps.getConsensusParticipant(0); | |||
assertEquals("jd.com", part0.getName()); | |||
PubKey pubKey0 = KeyGenCommand.decodePubKey("3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9"); | |||
PubKey pubKey0 = KeyGenUtils.decodePubKey("3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9"); | |||
assertEquals(pubKey0, part0.getPubKey()); | |||
assertEquals("127.0.0.1", part0.getInitializerAddress().getHost()); | |||
assertEquals(8800, part0.getInitializerAddress().getPort()); | |||
@@ -143,7 +143,7 @@ public class LedgerInitPropertiesTest { | |||
ConsensusParticipantConfig part1 = initProps.getConsensusParticipant(1); | |||
assertEquals(false, part1.getInitializerAddress().isSecure()); | |||
PubKey pubKey1 = KeyGenCommand.decodePubKey("3snPdw7i7PajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX"); | |||
PubKey pubKey1 = KeyGenUtils.decodePubKey("3snPdw7i7PajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX"); | |||
assertEquals(pubKey1, part1.getPubKey()); | |||
assertArrayEquals(new String[] { "MANAGER" }, part1.getRoles()); | |||
assertEquals(RolesPolicy.UNION, part1.getRolesPolicy()); | |||
@@ -154,7 +154,7 @@ public class LedgerInitPropertiesTest { | |||
assertEquals(RolesPolicy.UNION, part2.getRolesPolicy()); | |||
ConsensusParticipantConfig part3 = initProps.getConsensusParticipant(3); | |||
PubKey pubKey3 = KeyGenCommand.decodePubKey("3snPdw7i7PifPuRX7fu3jBjsb3rJRfDe9GtbDfvFJaJ4V4hHXQfhwk"); | |||
PubKey pubKey3 = KeyGenUtils.decodePubKey("3snPdw7i7PifPuRX7fu3jBjsb3rJRfDe9GtbDfvFJaJ4V4hHXQfhwk"); | |||
assertEquals(pubKey3, part3.getPubKey()); | |||
assertArrayEquals(new String[] { "GUEST" }, part3.getRoles()); | |||
assertEquals(RolesPolicy.INTERSECT, part3.getRolesPolicy()); | |||
@@ -170,7 +170,7 @@ public class LedgerInitPropertiesTest { | |||
int index = 0; | |||
for (String pubKeyStr : pubKeys) { | |||
System.out.println("[" + index + "][配置] = " + pubKeyStr); | |||
PubKey pubKey = KeyGenCommand.decodePubKey(pubKeyStr); | |||
PubKey pubKey = KeyGenUtils.decodePubKey(pubKeyStr); | |||
System.out.println("[" + index + "][公钥Base58] = " + pubKey.toBase58()); | |||
System.out.println("[" + index + "][地址] = " + AddressEncoding.generateAddress(pubKey).toBase58()); | |||
System.out.println("--------------------------------------------------------------------"); | |||
@@ -1,15 +1,19 @@ | |||
package com.jd.blockchain.tools.keygen; | |||
import static com.jd.blockchain.crypto.KeyGenUtils.decodePubKey; | |||
import static com.jd.blockchain.crypto.KeyGenUtils.decryptedPrivKeyBytes; | |||
import static com.jd.blockchain.crypto.KeyGenUtils.encodePrivKey; | |||
import static com.jd.blockchain.crypto.KeyGenUtils.encodePubKey; | |||
import static com.jd.blockchain.crypto.KeyGenUtils.readPassword; | |||
import java.io.File; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
import javax.crypto.SecretKey; | |||
import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
import com.jd.blockchain.crypto.Crypto; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.utils.ArgumentSet; | |||
@@ -17,18 +21,11 @@ import com.jd.blockchain.utils.ArgumentSet.ArgEntry; | |||
import com.jd.blockchain.utils.ArgumentSet.Setting; | |||
import com.jd.blockchain.utils.ConsoleUtils; | |||
import com.jd.blockchain.utils.codec.Base58Utils; | |||
import com.jd.blockchain.utils.io.BytesUtils; | |||
import com.jd.blockchain.utils.io.FileUtils; | |||
import com.jd.blockchain.utils.security.AESUtils; | |||
import com.jd.blockchain.utils.security.DecryptionException; | |||
import com.jd.blockchain.utils.security.ShaUtils; | |||
public class KeyGenCommand { | |||
public static final byte[] PUB_KEY_FILE_MAGICNUM = { (byte) 0xFF, 112, 117, 98 }; | |||
public static final byte[] PRIV_KEY_FILE_MAGICNUM = { (byte) 0x00, 112, 114, 118 }; | |||
// 指定 -r 参数时为“读取模式”,显示密钥文件; -r 参数之后紧跟着指定要读取的公钥或者私钥文件的路径; | |||
private static final String READ_ARG = "-r"; | |||
@@ -172,34 +169,6 @@ public class KeyGenCommand { | |||
} | |||
} | |||
public static String encodePubKey(PubKey pubKey) { | |||
byte[] pubKeyBytes = BytesUtils.concat(PUB_KEY_FILE_MAGICNUM, pubKey.toBytes()); | |||
String base58PubKey = Base58Utils.encode(pubKeyBytes); | |||
return base58PubKey; | |||
} | |||
public static PubKey decodePubKey(String base58PubKey) { | |||
byte[] keyBytes = Base58Utils.decode(base58PubKey); | |||
return decodePubKey(keyBytes); | |||
} | |||
public static String encodePrivKey(PrivKey privKey, String base58Pwd) { | |||
byte[] pwdBytes = Base58Utils.decode(base58Pwd); | |||
return encodePrivKey(privKey, pwdBytes); | |||
} | |||
public static String encodePrivKey(PrivKey privKey, byte[] pwdBytes) { | |||
byte[] encodedPrivKeyBytes = encryptPrivKey(privKey, pwdBytes); | |||
String base58PrivKey = Base58Utils.encode(encodedPrivKeyBytes); | |||
return base58PrivKey; | |||
} | |||
public static byte[] encryptPrivKey(PrivKey privKey, byte[] pwdBytes) { | |||
SecretKey userKey = AESUtils.generateKey128(pwdBytes); | |||
byte[] encryptedPrivKeyBytes = AESUtils.encrypt(privKey.toBytes(), userKey); | |||
return BytesUtils.concat(PRIV_KEY_FILE_MAGICNUM, encryptedPrivKeyBytes); | |||
} | |||
/** | |||
* 读取密钥; <br> | |||
* 如果是私钥,则需要输入密码; | |||
@@ -209,10 +178,10 @@ public class KeyGenCommand { | |||
public static void readKey(String keyFile, boolean decrypting) { | |||
String base58KeyString = FileUtils.readText(keyFile); | |||
byte[] keyBytes = Base58Utils.decode(base58KeyString); | |||
if (BytesUtils.startsWith(keyBytes, PUB_KEY_FILE_MAGICNUM)) { | |||
if (KeyGenUtils.isPubKeyBytes(keyBytes)) { | |||
if (decrypting) { | |||
// Try reading pubKey; | |||
PubKey pubKey = doDecodePubKeyBytes(keyBytes); | |||
PubKey pubKey = decodePubKey(keyBytes); | |||
ConsoleUtils.info( | |||
"======================== pub key ========================\r\n" + "[%s]\r\n" | |||
+ "Raw:[%s][%s]\r\n", | |||
@@ -222,7 +191,7 @@ public class KeyGenCommand { | |||
base58KeyString); | |||
} | |||
return; | |||
} else if (BytesUtils.startsWith(keyBytes, PRIV_KEY_FILE_MAGICNUM)) { | |||
} else if (KeyGenUtils.isPrivKeyBytes(keyBytes)) { | |||
// Try reading privKye; | |||
try { | |||
if (decrypting) { | |||
@@ -246,119 +215,4 @@ public class KeyGenCommand { | |||
} | |||
} | |||
private static PubKey doDecodePubKeyBytes(byte[] encodedPubKeyBytes) { | |||
byte[] pubKeyBytes = Arrays.copyOfRange(encodedPubKeyBytes, PUB_KEY_FILE_MAGICNUM.length, | |||
encodedPubKeyBytes.length); | |||
return new PubKey(pubKeyBytes); | |||
} | |||
public static PrivKey decryptedPrivKeyBytes(byte[] encodedPrivKeyBytes, byte[] pwdBytes) { | |||
// Read privKye; | |||
SecretKey userKey = AESUtils.generateKey128(pwdBytes); | |||
byte[] encryptedKeyBytes = Arrays.copyOfRange(encodedPrivKeyBytes, PRIV_KEY_FILE_MAGICNUM.length, | |||
encodedPrivKeyBytes.length); | |||
try { | |||
byte[] plainKeyBytes = AESUtils.decrypt(encryptedKeyBytes, userKey); | |||
return new PrivKey(plainKeyBytes); | |||
} catch (DecryptionException e) { | |||
throw new DecryptionException("Invalid password!", e); | |||
} | |||
} | |||
public static PubKey readPubKey(String keyFile) { | |||
String base58KeyString = FileUtils.readText(keyFile); | |||
return decodePubKey(base58KeyString); | |||
} | |||
public static PubKey decodePubKey(byte[] encodedPubKeyBytes) { | |||
if (BytesUtils.startsWith(encodedPubKeyBytes, PUB_KEY_FILE_MAGICNUM)) { | |||
// Read pubKey; | |||
return doDecodePubKeyBytes(encodedPubKeyBytes); | |||
} | |||
throw new IllegalArgumentException("The specified bytes is not valid PubKey generated by the KeyGen tool!"); | |||
} | |||
/** | |||
* 从控制台读取加密口令,以二进制数组形式返回原始口令的一次SHA256的结果; | |||
* | |||
* @return | |||
*/ | |||
public static byte[] readPassword() { | |||
byte[] pwdBytes = ConsoleUtils.readPassword(); | |||
return ShaUtils.hash_256(pwdBytes); | |||
} | |||
/** | |||
* 对指定的原始密码进行编码生成用于加解密的密码; | |||
* | |||
* @param rawPassword | |||
* @return | |||
*/ | |||
public static byte[] encodePassword(String rawPassword) { | |||
byte[] pwdBytes = BytesUtils.toBytes(rawPassword, "UTF-8"); | |||
return ShaUtils.hash_256(pwdBytes); | |||
} | |||
/** | |||
* 对指定的原始密码进行编码生成用于加解密的密码; | |||
* | |||
* @param rawPassword | |||
* @return | |||
*/ | |||
public static String encodePasswordAsBase58(String rawPassword) { | |||
return Base58Utils.encode(encodePassword(rawPassword)); | |||
} | |||
/** | |||
* 从控制台读取加密口令,以Base58字符串形式返回口令的一次SHA256的结果; | |||
* | |||
* @return | |||
*/ | |||
public static String readPasswordString() { | |||
return Base58Utils.encode(readPassword()); | |||
} | |||
public static PrivKey readPrivKey(String keyFile, String base58Pwd) { | |||
return readPrivKey(keyFile, Base58Utils.decode(base58Pwd)); | |||
} | |||
/** | |||
* 从文件读取私钥; | |||
* | |||
* @param keyFile | |||
* @param pwdBytes | |||
* @return | |||
*/ | |||
public static PrivKey readPrivKey(String keyFile, byte[] pwdBytes) { | |||
String base58KeyString = FileUtils.readText(keyFile); | |||
byte[] keyBytes = Base58Utils.decode(base58KeyString); | |||
if (!BytesUtils.startsWith(keyBytes, PRIV_KEY_FILE_MAGICNUM)) { | |||
throw new IllegalArgumentException("The specified file is not a private key file!"); | |||
} | |||
return decryptedPrivKeyBytes(keyBytes, pwdBytes); | |||
} | |||
public static PrivKey decodePrivKey(String base58Key, String base58Pwd) { | |||
byte[] decryptedKey = Base58Utils.decode(base58Pwd); | |||
return decodePrivKey(base58Key, decryptedKey); | |||
} | |||
public static PrivKey decodePrivKey(String base58Key, byte[] pwdBytes) { | |||
byte[] keyBytes = Base58Utils.decode(base58Key); | |||
if (!BytesUtils.startsWith(keyBytes, PRIV_KEY_FILE_MAGICNUM)) { | |||
throw new IllegalArgumentException("The specified file is not a private key file!"); | |||
} | |||
return decryptedPrivKeyBytes(keyBytes, pwdBytes); | |||
} | |||
public static PrivKey decodePrivKeyWithRawPassword(String base58Key, String rawPassword) { | |||
byte[] pwdBytes = encodePassword(rawPassword); | |||
byte[] keyBytes = Base58Utils.decode(base58Key); | |||
if (!BytesUtils.startsWith(keyBytes, PRIV_KEY_FILE_MAGICNUM)) { | |||
throw new IllegalArgumentException("The specified file is not a private key file!"); | |||
} | |||
return decryptedPrivKeyBytes(keyBytes, pwdBytes); | |||
} | |||
} |
@@ -1,28 +1,53 @@ | |||
package com.jd.blockchain.mocker; | |||
import java.io.IOException; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
import java.util.Random; | |||
import org.springframework.web.bind.annotation.RequestBody; | |||
import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
import com.jd.blockchain.consensus.ConsensusProvider; | |||
import com.jd.blockchain.consensus.ConsensusProviders; | |||
import com.jd.blockchain.consensus.ConsensusSettings; | |||
import com.jd.blockchain.crypto.*; | |||
import com.jd.blockchain.crypto.Crypto; | |||
import com.jd.blockchain.crypto.CryptoProvider; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.crypto.SignatureDigest; | |||
import com.jd.blockchain.crypto.SignatureFunction; | |||
import com.jd.blockchain.crypto.service.classic.ClassicCryptoService; | |||
import com.jd.blockchain.crypto.service.sm.SMCryptoService; | |||
import com.jd.blockchain.ledger.*; | |||
import com.jd.blockchain.ledger.core.*; | |||
import com.jd.blockchain.ledger.CryptoSetting; | |||
import com.jd.blockchain.ledger.DigitalSignature; | |||
import com.jd.blockchain.ledger.LedgerInitException; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.LedgerInitProperties.ConsensusParticipantConfig; | |||
import com.jd.blockchain.ledger.LedgerInitSetting; | |||
import com.jd.blockchain.ledger.ParticipantNode; | |||
import com.jd.blockchain.ledger.TransactionContent; | |||
import com.jd.blockchain.ledger.TransactionRequest; | |||
import com.jd.blockchain.ledger.core.CryptoConfig; | |||
import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
import com.jd.blockchain.ledger.core.LedgerInitProposalData; | |||
import com.jd.blockchain.ledger.core.LedgerInitializer; | |||
import com.jd.blockchain.ledger.core.LedgerManager; | |||
import com.jd.blockchain.storage.service.DbConnection; | |||
import com.jd.blockchain.storage.service.DbConnectionFactory; | |||
import com.jd.blockchain.tools.initializer.*; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties.ConsensusParticipantConfig; | |||
import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProcess; | |||
import com.jd.blockchain.tools.initializer.Prompter; | |||
import com.jd.blockchain.tools.initializer.web.LedgerInitConsensusService; | |||
import com.jd.blockchain.tools.initializer.web.LedgerInitDecisionData; | |||
import com.jd.blockchain.transaction.*; | |||
import com.jd.blockchain.transaction.DigitalSignatureBlob; | |||
import com.jd.blockchain.transaction.LedgerInitData; | |||
import com.jd.blockchain.transaction.SignatureUtils; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.concurrent.InvocationResult; | |||
import com.jd.blockchain.utils.io.BytesUtils; | |||
import org.springframework.web.bind.annotation.*; | |||
import java.io.IOException; | |||
import java.util.*; | |||
/** | |||
* 账本初始化控制器; | |||
@@ -36,8 +61,7 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon | |||
DataContractRegistry.register(TransactionRequest.class); | |||
} | |||
private static final String[] SUPPORTED_PROVIDERS = { | |||
ClassicCryptoService.class.getName(), | |||
private static final String[] SUPPORTED_PROVIDERS = { ClassicCryptoService.class.getName(), | |||
SMCryptoService.class.getName() }; | |||
private static final String DEFAULT_SIGN_ALGORITHM = "ED25519"; | |||
@@ -46,7 +70,7 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon | |||
private volatile LedgerInitProposal localPermission; | |||
private TransactionContent initTxContent; | |||
private volatile LedgerInitializer initializer; | |||
private volatile int currentId = -1; | |||
@@ -59,16 +83,12 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon | |||
private volatile ConsensusProvider consensusProvider; | |||
private volatile LedgerBlock genesisBlock; | |||
private volatile LedgerInitDecision localDecision; | |||
private volatile DecisionResultHandle[] decisions; | |||
private volatile DbConnection dbConn; | |||
private volatile LedgerEditor ledgerEditor; | |||
private LedgerManager ledgerManager; | |||
private DbConnectionFactory dbConnFactory; | |||
@@ -88,7 +108,7 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon | |||
} | |||
public TransactionContent getInitTxContent() { | |||
return initTxContent; | |||
return initializer.getTransactionContent(); | |||
} | |||
public LedgerInitProposal getLocalPermission() { | |||
@@ -154,11 +174,12 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon | |||
public LedgerInitDecision makeLocalDecision(PrivKey privKey) { | |||
// 生成账本; | |||
this.ledgerEditor = ledgerManager.newLedger(this.ledgerInitSetting, dbConn.getStorageService()); | |||
this.genesisBlock = initLedgerDataset(ledgerEditor); | |||
// this.ledgerEditor = ledgerManager.newLedger(this.ledgerInitSetting, dbConn.getStorageService()); | |||
// this.genesisBlock = initLedgerDataset(ledgerEditor); | |||
initializer.prepareLedger(dbConn.getStorageService(), getNodeSignatures()); | |||
// 生成签名决定; | |||
this.localDecision = makeDecision(currentId, genesisBlock.getHash(), privKey); | |||
this.localDecision = makeDecision(currentId, initializer.getLedgerHash(), privKey); | |||
this.decisions = new DecisionResultHandle[this.ledgerInitSetting.getConsensusParticipants().length]; | |||
for (int i = 0; i < decisions.length; i++) { | |||
// 参与者的 id 是依次递增的; | |||
@@ -169,10 +190,19 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon | |||
return localDecision; | |||
} | |||
private DigitalSignature getNodeSignatures() { | |||
ParticipantNode parti = this.ledgerInitSetting.getConsensusParticipants()[currentId]; | |||
PubKey pubKey = parti.getPubKey(); | |||
SignatureDigest signDigest = this.localPermission.getTransactionSignature(); | |||
DigitalSignatureBlob digitalSignature = new DigitalSignatureBlob(pubKey, signDigest); | |||
return digitalSignature; | |||
} | |||
public HashDigest consensusDecisions() { | |||
// 执行提交提交; | |||
ledgerEditor.commit(); | |||
return genesisBlock.getHash(); | |||
initializer.commit(); | |||
return initializer.getLedgerHash(); | |||
} | |||
public void closeDb() { | |||
@@ -236,18 +266,11 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon | |||
if (!SIGN_FUNC.verify(testSign, myPubKey, testBytes)) { | |||
throw new LedgerInitException("Your pub-key specified in the init-settings isn't match your priv-key!"); | |||
} | |||
// 生成初始化交易,并签署许可; | |||
TransactionBuilder initTxBuilder = new TxBuilder(null);// 账本初始化交易的账本 hash 为 null; | |||
initTxBuilder.ledgers().create(initSetting); | |||
for (ParticipantNode p : initSetting.getConsensusParticipants()) { | |||
// TODO:暂时只支持注册用户的初始化操作; | |||
BlockchainIdentity superUserId = new BlockchainIdentityData(p.getPubKey()); | |||
initTxBuilder.users().register(superUserId); | |||
} | |||
this.initTxContent = initTxBuilder.prepareContent(); | |||
// 初始化; | |||
this.initializer = LedgerInitializer.create(ledgerInitSetting); | |||
// 对初始交易签名,生成当前参与者的账本初始化许可; | |||
SignatureDigest permissionSign = SignatureUtils.sign(initTxContent, privKey); | |||
SignatureDigest permissionSign = SignatureUtils.sign(initializer.getTransactionContent(), privKey); | |||
localPermission = new LedgerInitProposalData(currentId, permissionSign); | |||
this.currentId = currentId; | |||
@@ -266,33 +289,33 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon | |||
return decision; | |||
} | |||
private LedgerBlock initLedgerDataset(LedgerEditor ledgerEditor) { | |||
// 初始化时,自动将参与方注册为账本的用户; | |||
TxRequestBuilder txReqBuilder = new TxRequestBuilder(this.initTxContent); | |||
// ParticipantNode[] parties = this.ledgerInitSetting.getConsensusParticipants(); | |||
ParticipantNode parti = this.ledgerInitSetting.getConsensusParticipants()[currentId]; | |||
PubKey pubKey = parti.getPubKey(); | |||
SignatureDigest signDigest = this.localPermission.getTransactionSignature(); | |||
DigitalSignatureBlob digitalSignature = new DigitalSignatureBlob(pubKey, signDigest); | |||
txReqBuilder.addNodeSignature(digitalSignature); | |||
TransactionRequest txRequest = txReqBuilder.buildRequest(); | |||
LedgerTransactionContext txCtx = ledgerEditor.newTransaction(txRequest); | |||
Operation[] ops = txRequest.getTransactionContent().getOperations(); | |||
// 注册用户; 注:第一个操作是 LedgerInitOperation; | |||
// TODO:暂时只支持注册用户的初始化操作; | |||
for (int i = 1; i < ops.length; i++) { | |||
UserRegisterOperation userRegOP = (UserRegisterOperation) ops[i]; | |||
txCtx.getDataset().getUserAccountSet().register(userRegOP.getUserID().getAddress(), | |||
userRegOP.getUserID().getPubKey()); | |||
} | |||
txCtx.commit(TransactionState.SUCCESS, null); | |||
return ledgerEditor.prepare(); | |||
} | |||
// private LedgerBlock initLedgerDataset(LedgerEditor ledgerEditor) { | |||
// // 初始化时,自动将参与方注册为账本的用户; | |||
// TxRequestBuilder txReqBuilder = new TxRequestBuilder(this.initTxContent); | |||
//// ParticipantNode[] parties = this.ledgerInitSetting.getConsensusParticipants(); | |||
// ParticipantNode parti = this.ledgerInitSetting.getConsensusParticipants()[currentId]; | |||
// | |||
// PubKey pubKey = parti.getPubKey(); | |||
// SignatureDigest signDigest = this.localPermission.getTransactionSignature(); | |||
// DigitalSignatureBlob digitalSignature = new DigitalSignatureBlob(pubKey, signDigest); | |||
// txReqBuilder.addNodeSignature(digitalSignature); | |||
// | |||
// TransactionRequest txRequest = txReqBuilder.buildRequest(); | |||
// | |||
// LedgerTransactionContext txCtx = ledgerEditor.newTransaction(txRequest); | |||
// Operation[] ops = txRequest.getTransactionContent().getOperations(); | |||
// // 注册用户; 注:第一个操作是 LedgerInitOperation; | |||
// // TODO:暂时只支持注册用户的初始化操作; | |||
// for (int i = 1; i < ops.length; i++) { | |||
// UserRegisterOperation userRegOP = (UserRegisterOperation) ops[i]; | |||
// txCtx.getDataset().getUserAccountSet().register(userRegOP.getUserID().getAddress(), | |||
// userRegOP.getUserID().getPubKey()); | |||
// } | |||
// | |||
// txCtx.commit(TransactionState.SUCCESS, null); | |||
// | |||
// return ledgerEditor.prepare(); | |||
// } | |||
private byte[] getDecisionBytes(int participantId, HashDigest ledgerHash) { | |||
return BytesUtils.concat(BytesUtils.toBytes(participantId), ledgerHash.toBytes()); | |||
@@ -20,6 +20,7 @@ import com.jd.blockchain.consensus.action.ActionResponse; | |||
import com.jd.blockchain.crypto.Crypto; | |||
import com.jd.blockchain.crypto.CryptoProvider; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.crypto.service.classic.ClassicAlgorithm; | |||
@@ -40,6 +41,7 @@ import com.jd.blockchain.ledger.KVInfoVO; | |||
import com.jd.blockchain.ledger.LedgerAdminInfo; | |||
import com.jd.blockchain.ledger.LedgerBlock; | |||
import com.jd.blockchain.ledger.LedgerInfo; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.LedgerMetadata; | |||
import com.jd.blockchain.ledger.LedgerPermission; | |||
import com.jd.blockchain.ledger.LedgerTransaction; | |||
@@ -75,8 +77,6 @@ import com.jd.blockchain.service.TransactionBatchResultHandle; | |||
import com.jd.blockchain.storage.service.DbConnectionFactory; | |||
import com.jd.blockchain.storage.service.utils.MemoryDBConnFactory; | |||
import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.transaction.BlockchainQueryService; | |||
import com.jd.blockchain.transaction.TxBuilder; | |||
import com.jd.blockchain.utils.Bytes; | |||
@@ -164,16 +164,16 @@ public class MockerNodeContext implements BlockchainQueryService { | |||
boolean isExist = false; | |||
// 通过公钥进行判断 | |||
for (Map.Entry<String, BlockchainKeypair> entry : participants.entrySet()) { | |||
String existPubKey = KeyGenCommand.encodePubKey(entry.getValue().getPubKey()); | |||
String existPubKey = KeyGenUtils.encodePubKey(entry.getValue().getPubKey()); | |||
if (pubKeyString.equals(existPubKey)) { | |||
isExist = true; | |||
} | |||
} | |||
if (!isExist) { | |||
// 加入系统中 | |||
PrivKey privKey = KeyGenCommand.decodePrivKeyWithRawPassword(MockerConstant.PRIVATE_KEYS[i], | |||
PrivKey privKey = KeyGenUtils.decodePrivKeyWithRawPassword(MockerConstant.PRIVATE_KEYS[i], | |||
MockerConstant.PASSWORD); | |||
PubKey pubKey = KeyGenCommand.decodePubKey(MockerConstant.PUBLIC_KEYS[i]); | |||
PubKey pubKey = KeyGenUtils.decodePubKey(MockerConstant.PUBLIC_KEYS[i]); | |||
participants(new BlockchainKeypair(pubKey, privKey)); | |||
} | |||
if (participants.size() >= 4) { | |||
@@ -524,7 +524,7 @@ public class MockerNodeContext implements BlockchainQueryService { | |||
ledgerProp.put(partiPrefix + LedgerInitProperties.PART_NAME, name); | |||
ledgerProp.put(partiPrefix + LedgerInitProperties.PART_PUBKEY_PATH, ""); | |||
ledgerProp.put(partiPrefix + LedgerInitProperties.PART_PUBKEY, | |||
KeyGenCommand.encodePubKey(keypair.getPubKey())); | |||
KeyGenUtils.encodePubKey(keypair.getPubKey())); | |||
ledgerProp.put(partiPrefix + LedgerInitProperties.PART_INITIALIZER_HOST, MockerConstant.LOCAL_ADDRESS); | |||
ledgerProp.put(partiPrefix + LedgerInitProperties.PART_INITIALIZER_PORT, | |||
String.valueOf(MockerConstant.LEDGER_INIT_PORT_START + partiIndex * 10)); | |||
@@ -1,8 +1,10 @@ | |||
package com.jd.blockchain.mocker.handler; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.gateway.GatewayConfigProperties; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.mocker.config.MockerConstant; | |||
import com.jd.blockchain.mocker.config.PresetAnswerPrompter; | |||
import com.jd.blockchain.mocker.node.GatewayNodeRunner; | |||
@@ -10,9 +12,7 @@ import com.jd.blockchain.mocker.node.NodeWebContext; | |||
import com.jd.blockchain.mocker.node.PeerNodeRunner; | |||
import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerBindingConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||
import com.jd.blockchain.tools.initializer.Prompter; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker; | |||
import com.jd.blockchain.utils.net.NetworkAddress; | |||
import org.springframework.util.ResourceUtils; | |||
@@ -93,7 +93,7 @@ public class MockerNodeHandler { | |||
// 启动服务器; | |||
NetworkAddress initAddr = initSetting.getConsensusParticipant(nodeIndex).getInitializerAddress(); | |||
NodeWebContext node = new NodeWebContext(nodeIndex, initAddr); | |||
PrivKey privkey = KeyGenCommand.decodePrivKeyWithRawPassword(PRIVATE_KEYS[nodeIndex], PASSWORD); | |||
PrivKey privkey = KeyGenUtils.decodePrivKeyWithRawPassword(PRIVATE_KEYS[nodeIndex], PASSWORD); | |||
DBConnectionConfig dbConn = new DBConnectionConfig(); | |||
dbConn.setConnectionUri(MockerConstant.DB_MEMS[nodeIndex]); | |||
ThreadInvoker.AsyncCallback<HashDigest> nodeCallback = node.startInit(privkey, initSetting, dbConn, consolePrompter, | |||
@@ -1,6 +1,7 @@ | |||
package com.jd.blockchain.mocker.handler; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.KeyGenUtils; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.crypto.PubKey; | |||
import com.jd.blockchain.ledger.*; | |||
@@ -9,7 +10,6 @@ import com.jd.blockchain.mocker.data.KvData; | |||
import com.jd.blockchain.mocker.data.ResponseData; | |||
import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
public class MockerServiceHandler { | |||
@@ -115,8 +115,8 @@ public class MockerServiceHandler { | |||
} | |||
private BlockchainKeypair defaultParticipant() { | |||
PrivKey privKey = KeyGenCommand.decodePrivKeyWithRawPassword(MockerConstant.PRIVATE_KEYS[0], MockerConstant.PASSWORD); | |||
PubKey pubKey = KeyGenCommand.decodePubKey(MockerConstant.PUBLIC_KEYS[0]); | |||
PrivKey privKey = KeyGenUtils.decodePrivKeyWithRawPassword(MockerConstant.PRIVATE_KEYS[0], MockerConstant.PASSWORD); | |||
PubKey pubKey = KeyGenUtils.decodePubKey(MockerConstant.PUBLIC_KEYS[0]); | |||
return new BlockchainKeypair(pubKey, privKey); | |||
} | |||
@@ -2,6 +2,7 @@ package com.jd.blockchain.mocker.node; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.PrivKey; | |||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||
import com.jd.blockchain.ledger.TransactionContent; | |||
import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
@@ -12,7 +13,6 @@ import com.jd.blockchain.storage.service.DbConnection; | |||
import com.jd.blockchain.storage.service.impl.composite.CompositeConnectionFactory; | |||
import com.jd.blockchain.tools.initializer.DBConnectionConfig; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProcess; | |||
import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||
import com.jd.blockchain.tools.initializer.Prompter; | |||
import com.jd.blockchain.tools.initializer.web.LedgerInitializeWebController; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker; | |||