diff --git a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/client/BftsmartConsensusClient.java b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/client/BftsmartConsensusClient.java index 25a995c7..9561263d 100644 --- a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/client/BftsmartConsensusClient.java +++ b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/client/BftsmartConsensusClient.java @@ -20,8 +20,6 @@ public class BftsmartConsensusClient implements ConsensusClient { this.clientSettings = clientSettings; this.gatewayId = clientSettings.getClientId(); - - connect(); } @@ -45,7 +43,7 @@ public class BftsmartConsensusClient implements ConsensusClient { } @Override - public void connect() { + public synchronized void connect() { //consensus client pool BftsmartPeerProxyFactory peerProxyFactory = new BftsmartPeerProxyFactory((BftsmartClientSettings)clientSettings, gatewayId); diff --git a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/client/BftsmartMessageService.java b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/client/BftsmartMessageService.java index 1c2a5f0c..5ecf6596 100644 --- a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/client/BftsmartMessageService.java +++ b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/client/BftsmartMessageService.java @@ -27,16 +27,16 @@ public class BftsmartMessageService implements MessageService { AsynchServiceProxy asynchServiceProxy = null; try { asynchServiceProxy = asyncPeerProxyPool.borrowObject(); - //0: Transaction msg, 1: Commitblock msg - byte[] msgType = BytesUtils.toBytes(0); - byte[] wrapMsg = new byte[message.length + 4]; - System.arraycopy(message, 0, wrapMsg, 4, message.length); - System.arraycopy(msgType, 0, wrapMsg, 0, 4); - - System.out.printf("BftsmartMessageService invokeOrdered time = %s, id = %s threadId = %s \r\n", - System.currentTimeMillis(), asynchServiceProxy.getProcessId(), Thread.currentThread().getId()); - - byte[] result = asynchServiceProxy.invokeOrdered(wrapMsg); +// //0: Transaction msg, 1: Commitblock msg +// byte[] msgType = BytesUtils.toBytes(0); +// byte[] wrapMsg = new byte[message.length + 4]; +// System.arraycopy(message, 0, wrapMsg, 4, message.length); +// System.arraycopy(msgType, 0, wrapMsg, 0, 4); +// +// System.out.printf("BftsmartMessageService invokeOrdered time = %s, id = %s threadId = %s \r\n", +// System.currentTimeMillis(), asynchServiceProxy.getProcessId(), Thread.currentThread().getId()); + + byte[] result = asynchServiceProxy.invokeOrdered(message); asyncFuture.complete(result); } catch (Exception e) { diff --git a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartConsensusManageService.java b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartConsensusManageService.java index a91f3f16..215486d0 100644 --- a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartConsensusManageService.java +++ b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartConsensusManageService.java @@ -13,10 +13,16 @@ import com.jd.blockchain.utils.serialize.binary.BinarySerializeUtils; public class BftsmartConsensusManageService implements ConsensusManageService { - public static final int CLIENT_RANGE = 100 * 1000; + public static final int GATEWAY_SIZE = 100; + + public static final int CLIENT_SIZE_PER_GATEWAY = 1000; + + public static final int CLIENT_RANGE = GATEWAY_SIZE * CLIENT_SIZE_PER_GATEWAY; private BftsmartNodeServer nodeServer; + private int clientId; + private static final Lock authLock = new ReentrantLock(); public BftsmartConsensusManageService(BftsmartNodeServer nodeServer) { @@ -41,6 +47,7 @@ public class BftsmartConsensusManageService implements ConsensusManageService { try { authLock.lock(); ((BftsmartClientIncomingConfig) clientIncomingSettings).setClientId(clientId++); + clientId += CLIENT_SIZE_PER_GATEWAY; } finally { authLock.unlock(); } diff --git a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java index 635c0758..ce97797a 100644 --- a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java +++ b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java @@ -1,16 +1,13 @@ package com.jd.blockchain.consensus.bftsmart.service; import java.io.ByteArrayOutputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; +import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; - +import bftsmart.tom.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import com.jd.blockchain.consensus.ConsensusManageService; import com.jd.blockchain.consensus.NodeSettings; import com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider; @@ -26,13 +23,8 @@ import com.jd.blockchain.ledger.TransactionState; import com.jd.blockchain.utils.PropertiesUtils; import com.jd.blockchain.utils.concurrent.AsyncFuture; import com.jd.blockchain.utils.io.BytesUtils; - import bftsmart.reconfiguration.util.HostsConfig; import bftsmart.reconfiguration.util.TOMConfiguration; -import bftsmart.tom.MessageContext; -import bftsmart.tom.ReplyContext; -import bftsmart.tom.ReplyContextMessage; -import bftsmart.tom.ServiceReplica; import bftsmart.tom.core.messages.TOMMessage; import bftsmart.tom.server.defaultservices.DefaultRecoverable; @@ -42,15 +34,9 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer private List stateHandles = new CopyOnWriteArrayList<>(); -// private List batchConsensusListeners = new LinkedList<>(); - -// private Map> replyContextMessages = new ConcurrentHashMap<>(); - // TODO 暂不处理队列溢出问题 private ExecutorService notifyReplyExecutors = Executors.newSingleThreadExecutor(); -// private ExecutorService sendCommitExecutors = Executors.newFixedThreadPool(2); - private volatile Status status = Status.STOPPED; private final Object mutex = new Object(); @@ -81,28 +67,6 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer private int serverId; -// private volatile String batchId = null; -// -//// private List> replyMessages ; -// -// private boolean leader_has_makedicision = false; -// -// private boolean commit_block_condition = false; -// -// private final AtomicLong txIndex = new AtomicLong(); -// -// private final AtomicLong blockIndex = new AtomicLong(); -// -// private static final AtomicInteger incrementNum = new AtomicInteger(); -// -//// private final BlockingQueue txRequestQueue = new LinkedBlockingQueue(); -// -// private final ExecutorService queueExecutor = Executors.newSingleThreadExecutor(); -// -// private final ScheduledExecutorService timerEexecutorService = new ScheduledThreadPoolExecutor(10); -// private ServiceProxy peerProxy; - - public BftsmartNodeServer() { } @@ -113,28 +77,12 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer //used later this.stateMachineReplicate = stateMachineReplicate; this.messageHandle = messageHandler; - this.manageService = new BftsmartConsensusManageService(this); createConfig(); serverId = findServerId(); initConfig(serverId, systemConfig, hostsConfig); + this.manageService = new BftsmartConsensusManageService(this); } - //aim to send commit block message -// protected void createProxyClient() { -// BftsmartTopology topologyCopy = (BftsmartTopology) topology.copyOf(); -// -// MemoryBasedViewStorage viewStorage = new MemoryBasedViewStorage(topologyCopy.getView()); -// -// byte[] bytes = BinarySerializeUtils.serialize(tomConfig); -// -// TOMConfiguration decodeTomConfig = BinarySerializeUtils.deserialize(bytes); -// -// decodeTomConfig.setProcessId(0); -// -// peerProxy = new ServiceProxy(decodeTomConfig, viewStorage, null, null); -// -// } - protected int findServerId() { int serverId = 0; @@ -242,214 +190,12 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer return appExecuteBatch(commands, msgCtxs, fromConsensus, null); } -// private boolean checkLeaderId(MessageContext[] msgCtxs) { -// boolean result = false; -// -// for (int i = 0; i < msgCtxs.length - 1; i++) { -// if (msgCtxs[i].getLeader() != msgCtxs[i+1].getLeader()) -// return result; -// } -// -// result = true; -// -// return result; -// } -// -// //普通消息处理 -// private void normalMsgProcess(ReplyContextMessage replyContextMsg, byte[] msg, String realmName, String batchId) { -// AsyncFuture replyMsg = messageHandle.processOrdered(replyContextMsg.getMessageContext().getOperationId(), msg, realmName, batchId); -// replyContextMessages.put(replyContextMsg, replyMsg); -// } -// -// //结块消息处理 -// private void commitMsgProcess(ReplyContextMessage replyContextMsg, String realmName, String batchId) { -// try{ -// //receive messages before commitblock message, then execute commit -// if (replyContextMessages.size() != 0) { -// messageHandle.completeBatch(realmName, batchId); -// messageHandle.commitBatch(realmName, batchId); -// } -// -// // commit block msg need response too -// CompletableAsyncFuture asyncFuture = new CompletableAsyncFuture<>(); -// TransactionResponse transactionRespHandle = new TransactionRespHandle(newBlockCommitRequest(), -// TransactionState.SUCCESS, TransactionState.SUCCESS); -// -// asyncFuture.complete(BinaryEncodingUtils.encode(transactionRespHandle, TransactionResponse.class)); -// replyContextMessages.put(replyContextMsg, asyncFuture); -// }catch (Exception e){ -// LOGGER.error("Error occurred on commit batch transactions, so the new block is canceled! --" + e.getMessage(), e); -// messageHandle.rollbackBatch(realmName, batchId, -1); -// }finally{ -// this.batchId = null; -// } -// } - -// private void sendCommitMessage() { -// -// HashDigest ledgerHash = new HashDigest(Base58Utils.decode(realmName)); -// -// BlockchainKeyPair userKeyPeer = BlockchainKeyGenerator.getInstance().generate(); -// -// TxContentBlob txContentBlob = new TxContentBlob(ledgerHash); -// -// byte[] reqBytes = BinaryEncodingUtils.encode(txContentBlob, TransactionContent.class); -// -// HashDigest reqHash = CryptoUtils.hash(CryptoAlgorithm.SHA256).hash(reqBytes); -// -// txContentBlob.setHash(reqHash); -// -// TxRequestMessage transactionRequest = new TxRequestMessage(txContentBlob); -// -// byte[] msg = BinaryEncodingUtils.encode(transactionRequest, TransactionRequest.class); -// -// byte[] type = BytesUtils.toBytes(1); -// -// byte[] wrapMsg = new byte[msg.length + 4]; -// -// System.arraycopy(type, 0, wrapMsg, 0, 4); -// System.arraycopy(msg, 0, wrapMsg, 4, msg.length); -// -// peerProxy.invokeOrdered(wrapMsg); -// -// LOGGER.info("Send commit block msg success!"); -// } - -// private TransactionRequest newBlockCommitRequest() { -// -// HashDigest ledgerHash = new HashDigest(Base58Utils.decode(realmName)); -// -// TxContentBlob txContentBlob = new TxContentBlob(ledgerHash); -// -// byte[] reqBytes = BinaryEncodingUtils.encode(txContentBlob, TransactionContent.class); -// -// HashDigest reqHash = CryptoUtils.hash(CryptoAlgorithm.SHA256).hash(reqBytes); -// -// txContentBlob.setHash(reqHash); -// -// TxRequestMessage transactionRequest = new TxRequestMessage(txContentBlob); -// -// return transactionRequest; -// } - -// private void checkConsensusFinish() { -// BftsmartCommitBlockSettings commitBlockSettings = ((BftsmartServerSettings)serverSettings).getConsensusSettings().getCommitBlockSettings(); -// int txSize = commitBlockSettings.getTxSizePerBlock(); -// long maxDelay = commitBlockSettings.getMaxDelayMilliSecondsPerBlock(); -// -// long currIndex = txIndex.incrementAndGet(); -// if (currIndex == txSize) { -// txIndex.set(0); -// this.blockIndex.getAndIncrement(); -// sendCommitExecutors.execute(()-> { -// sendCommitMessage(); -// }); -// } else if (currIndex == 1) { -//// System.out.printf("checkConsensusFinish schedule blockIndex = %s \r\n", this.blockIndex.get()); -// timerEexecutorService.schedule(timeTask(this.blockIndex.get()), maxDelay, TimeUnit.MILLISECONDS); -// } -// -// return; -// } - -// @Override -// public byte[][] appExecuteBatch(byte[][] commands, MessageContext[] msgCtxs, boolean fromConsensus, List replyList) { -// -// if (!checkLeaderId(msgCtxs)) { -// throw new IllegalArgumentException(); -// } -// -// boolean isLeader = (msgCtxs[0].getLeader() == getId()); -// -// if (isLeader) { -// for (int i = 0; i < commands.length; i++) { -// byte[] wrapMsg = commands[i]; -// byte[] type = new byte[4]; -// byte[] msg= new byte[wrapMsg.length - 4]; -// -// System.arraycopy(wrapMsg, 0, type, 0, 4); -// System.arraycopy(wrapMsg, 4, msg, 0, wrapMsg.length - 4); -// -// MessageContext messageContext = msgCtxs[i]; -// ReplyContextMessage replyContextMessage = replyList.get(i); -// replyContextMessage.setMessageContext(messageContext); -// -// if (batchId == null) { -// batchId = messageHandle.beginBatch(realmName); -// } -// -// int msgType = BytesUtils.readInt(new ByteArrayInputStream(type)); -// -// if (msgType == 0) { -// -// //only leader do it -// checkConsensusFinish(); -// //normal message process -// normalMsgProcess(replyContextMessage, msg, realmName, batchId); -// } -// if (!leader_has_makedicision) { -// if (msgType == 1) { -// LOGGER.error("Error occurred on appExecuteBatch msg process, leader confilicting error!"); -// } -// -// if (commit_block_condition) { -// leader_has_makedicision = true; -// -//// sendCommitExecutors.execute(() -> { -// commit_block_condition = false; -// LOGGER.info("Txcount execute commit block!"); -// sendCommitMessage(); -//// }); -// -// } -// } else if (msgType == 1) { -// //commit block message -// commitMsgProcess(replyContextMessage, realmName, batchId); -// leader_has_makedicision = false; -// sendReplyMessage(); -// } -// } -// } else { -// for (int i = 0; i < commands.length; i++) { -// byte[] wrapMsg = commands[i]; -// byte[] type = new byte[4]; -// byte[] msg= new byte[wrapMsg.length - 4]; -// -// System.arraycopy(wrapMsg, 0, type, 0, 4); -// System.arraycopy(wrapMsg, 4, msg, 0, wrapMsg.length - 4); -// -// MessageContext messageContext = msgCtxs[i]; -// ReplyContextMessage replyContextMessage = replyList.get(i); -// replyContextMessage.setMessageContext(messageContext); -// -// if (batchId == null) { -// batchId = messageHandle.beginBatch(realmName); -// } -// -// int msgType = BytesUtils.readInt(new ByteArrayInputStream(type)); -// -// if (msgType == 0) { -// //normal message -// normalMsgProcess(replyContextMessage, msg, realmName, batchId); -// } else if (msgType == 1) { -// // commit block message -// commitMsgProcess(replyContextMessage, realmName, batchId); -// sendReplyMessage(); -// } -// } -// } -// -// return null; -// } - @Override public byte[][] appExecuteBatch(byte[][] commands, MessageContext[] msgCtxs, boolean fromConsensus, List replyList) { if (replyList == null || replyList.size() == 0) { throw new IllegalArgumentException(); } - - // todo 此部分需要重新改造 /** * 默认BFTSmart接口提供的commands是一个或多个共识结果的顺序集合 @@ -481,52 +227,6 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer if (!manageConsensusCmds.isEmpty()) { blockAndReply(manageConsensusCmds, manageReplyMsgs); } - - -//// if (!checkLeaderId(msgCtxs)) { -//// throw new IllegalArgumentException(); -//// } -// -// if (replyList == null || replyList.size() == 0) { -// throw new IllegalArgumentException(); -// } -// -// for (int i = 0; i < commands.length; i++) { -// byte[] wrapMsg = commands[i]; -// byte[] type = new byte[4]; -// byte[] msg= new byte[wrapMsg.length - 4]; -// // batch messages, maybe in different consensus instance, leader also maybe different -// boolean isLeader = (msgCtxs[i].getLeader() == getId()); -// -// System.arraycopy(wrapMsg, 0, type, 0, 4); -// System.arraycopy(wrapMsg, 4, msg, 0, wrapMsg.length - 4); -// -// MessageContext messageContext = msgCtxs[i]; -// ReplyContextMessage replyContextMessage = replyList.get(i); -// replyContextMessage.setMessageContext(messageContext); -// -// if (batchId == null) { -// batchId = messageHandle.beginBatch(realmName); -// } -// -// int msgType = BytesUtils.readInt(new ByteArrayInputStream(type)); -// -// if (msgType == 0) { -// -// //only leader do it -// if (isLeader) { -// checkConsensusFinish(); -// } -// //normal message process -// normalMsgProcess(replyContextMessage, msg, realmName, batchId); -// } -// else if (msgType == 1) { -// //commit block message -// commitMsgProcess(replyContextMessage, realmName, batchId); -// sendReplyMessage(); -// } -// } - return null; } @@ -574,46 +274,6 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer }); } -// private void sendReplyMessage() { -// for (ReplyContextMessage msg: replyContextMessages.keySet()) { -// byte[] reply = replyContextMessages.get(msg).get(); -// msg.setReply(reply); -// TOMMessage request = msg.getTomMessage(); -// ReplyContext replyContext = msg.getReplyContext(); -// request.reply = new TOMMessage(replyContext.getId(), request.getSession(), request.getSequence(), -// request.getOperationId(), msg.getReply(), replyContext.getCurrentViewId(), -// request.getReqType()); -// -// if (replyContext.getNumRepliers() > 0) { -// bftsmart.tom.util.Logger.println("(ServiceReplica.receiveMessages) sending reply to " -// + request.getSender() + " with sequence number " + request.getSequence() -// + " and operation ID " + request.getOperationId() + " via ReplyManager"); -// replyContext.getRepMan().send(request); -// } else { -// bftsmart.tom.util.Logger.println("(ServiceReplica.receiveMessages) sending reply to " -// + request.getSender() + " with sequence number " + request.getSequence() -// + " and operation ID " + request.getOperationId()); -// replyContext.getReplier().manageReply(request, msg.getMessageContext()); -// // cs.send(new int[]{request.getSender()}, request.reply); -// } -// } -// replyContextMessages.clear(); -// } - -// private Runnable timeTask(final long currBlockIndex) { -// Runnable task = () -> { -// boolean isAdd = this.blockIndex.compareAndSet(currBlockIndex, currBlockIndex + 1); -// if (isAdd) { -// LOGGER.info("TimerTask execute commit block! "); -// this.txIndex.set(0); -// timerEexecutorService.execute(()-> { -// sendCommitMessage(); -// }); -// } -// }; -// return task; -// } - //notice public byte[] getSnapshot() { LOGGER.debug("------- GetSnapshot...[replica.id=" + this.getId() + "]"); @@ -623,9 +283,6 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer for (StateHandle stateHandle : stateHandles) { // TODO: 测试代码; return stateHandle.takeSnapshot(); - - // byte[] state = stateHandle.takeSnapshot(); - // BytesEncoding.writeInNormal(state, out); } return out.toByteArray(); } @@ -693,33 +350,6 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer } } -// private static class ActionRequestExtend { -// -// -// ReplyContextMessage replyContextMessage; -// -// private byte[] message; -// -// private ActionRequest actionRequest; -// -// public ActionRequestExtend(byte[] message) { -// this.message = message; -// actionRequest = BinaryEncodingUtils.decode(message); -// } -// -// public byte[] getMessage() { -// return message; -// } -// -// public ReplyContextMessage getReplyContextMessage() { -// return replyContextMessage; -// } -// -// public ActionRequest getActionRequest() { -// return actionRequest; -// } -// } - enum Status { STARTING, diff --git a/source/crypto/crypto-classic/src/main/java/com/jd/blockchain/crypto/utils/classic/RSAUtils.java b/source/crypto/crypto-classic/src/main/java/com/jd/blockchain/crypto/utils/classic/RSAUtils.java index b69a271b..7ee6de3a 100644 --- a/source/crypto/crypto-classic/src/main/java/com/jd/blockchain/crypto/utils/classic/RSAUtils.java +++ b/source/crypto/crypto-classic/src/main/java/com/jd/blockchain/crypto/utils/classic/RSAUtils.java @@ -1,11 +1,31 @@ package com.jd.blockchain.crypto.utils.classic; -import com.jd.blockchain.utils.io.BytesUtils; -import org.bouncycastle.asn1.*; +import java.io.IOException; +import java.math.BigInteger; +import java.security.KeyFactory; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.interfaces.RSAPrivateCrtKey; +import java.security.interfaces.RSAPublicKey; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.spec.X509EncodedKeySpec; + +import org.bouncycastle.asn1.ASN1EncodableVector; +import org.bouncycastle.asn1.ASN1Encoding; +import org.bouncycastle.asn1.ASN1Integer; +import org.bouncycastle.asn1.ASN1Sequence; +import org.bouncycastle.asn1.DERNull; +import org.bouncycastle.asn1.DERSequence; import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; import org.bouncycastle.asn1.pkcs.RSAPrivateKey; import org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import org.bouncycastle.crypto.*; +import org.bouncycastle.crypto.AsymmetricBlockCipher; +import org.bouncycastle.crypto.AsymmetricCipherKeyPair; +import org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator; +import org.bouncycastle.crypto.CipherParameters; +import org.bouncycastle.crypto.CryptoException; +import org.bouncycastle.crypto.InvalidCipherTextException; import org.bouncycastle.crypto.digests.SHA256Digest; import org.bouncycastle.crypto.encodings.PKCS1Encoding; import org.bouncycastle.crypto.engines.RSAEngine; @@ -16,17 +36,8 @@ import org.bouncycastle.crypto.params.RSAKeyParameters; import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters; import org.bouncycastle.crypto.signers.RSADigestSigner; import org.bouncycastle.jcajce.provider.asymmetric.util.KeyUtil; -import sun.security.rsa.RSAPrivateCrtKeyImpl; -import java.io.IOException; -import java.math.BigInteger; -import java.security.KeyFactory; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.security.interfaces.RSAPublicKey; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.PKCS8EncodedKeySpec; -import java.security.spec.X509EncodedKeySpec; +import com.jd.blockchain.utils.io.BytesUtils; /** * @author zhanglin33 @@ -458,9 +469,9 @@ public class RSAUtils { throw new com.jd.blockchain.crypto.CryptoException(e.getMessage(), e); } - RSAPrivateCrtKeyImpl privateKey; + RSAPrivateCrtKey privateKey; try { - privateKey = (RSAPrivateCrtKeyImpl) keyFactory.generatePrivate(keySpec); + privateKey = (RSAPrivateCrtKey) keyFactory.generatePrivate(keySpec); } catch (InvalidKeySpecException e) { throw new com.jd.blockchain.crypto.CryptoException(e.getMessage(), e); } diff --git a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/AESEncryptionFunctionTest.java b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/AESEncryptionFunctionTest.java index dd5e9888..e250da7b 100644 --- a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/AESEncryptionFunctionTest.java +++ b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/AESEncryptionFunctionTest.java @@ -69,7 +69,7 @@ public class AESEncryptionFunctionTest { assertEquals(algorithm.code(), symmetricKey.getAlgorithm()); assertEquals(2 + 1 + 128 / 8, symmetricKey.toBytes().length); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] keyTypeBytes = new byte[] { SYMMETRIC.CODE }; byte[] rawKeyBytes = symmetricKey.getRawKeyBytes(); assertArrayEquals(BytesUtils.concat(algoBytes, keyTypeBytes, rawKeyBytes), symmetricKey.toBytes()); @@ -167,7 +167,7 @@ public class AESEncryptionFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = symmetricKey.getRawKeyBytes(); byte[] ripemd160KeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -197,7 +197,7 @@ public class AESEncryptionFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = symmetricKey.getRawKeyBytes(); byte[] ripemd160KeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -235,7 +235,7 @@ public class AESEncryptionFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.toBytes(); byte[] ripemd160CiphertextBytes = BytesUtils.concat(algoBytes, rawCiphertextBytes); @@ -275,7 +275,7 @@ public class AESEncryptionFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.getRawCiphertext(); byte[] ripemd160CiphertextBytes = BytesUtils.concat(algoBytes, rawCiphertextBytes); diff --git a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ECDSASignatureFunctionTest.java b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ECDSASignatureFunctionTest.java index 030f6f47..7e1120c1 100644 --- a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ECDSASignatureFunctionTest.java +++ b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ECDSASignatureFunctionTest.java @@ -66,7 +66,7 @@ public class ECDSASignatureFunctionTest { assertEquals(2 + 1 + 65, pubKey.toBytes().length); assertEquals(2 + 1 + 32, privKey.toBytes().length); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawPubKeyBytes = pubKey.getRawKeyBytes(); @@ -162,7 +162,7 @@ public class ECDSASignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = privKey.getRawKeyBytes(); byte[] ripemd160PubKeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -194,7 +194,7 @@ public class ECDSASignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = privKey.getRawKeyBytes(); byte[] ripemd160PubKeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -227,7 +227,7 @@ public class ECDSASignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawKeyBytes = pubKey.getRawKeyBytes(); byte[] ripemd160PrivKeyBytes = BytesUtils.concat(algoBytes, privKeyTypeBytes, rawKeyBytes); @@ -259,7 +259,7 @@ public class ECDSASignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawKeyBytes = pubKey.getRawKeyBytes(); byte[] ripemd160PrivKeyBytes = BytesUtils.concat(algoBytes, privKeyTypeBytes, rawKeyBytes); @@ -298,7 +298,7 @@ public class ECDSASignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = signatureDigest.toBytes(); byte[] ripemd160SignatureBytes = BytesUtils.concat(algoBytes, rawDigestBytes); @@ -335,7 +335,7 @@ public class ECDSASignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = signatureDigest.getRawDigest(); byte[] ripemd160SignatureDigestBytes = BytesUtils.concat(algoBytes, rawDigestBytes); diff --git a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ED25519SignatureFunctionTest.java b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ED25519SignatureFunctionTest.java index 9b3eb88c..5ef5ebe6 100644 --- a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ED25519SignatureFunctionTest.java +++ b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/ED25519SignatureFunctionTest.java @@ -93,7 +93,7 @@ public class ED25519SignatureFunctionTest { assertEquals(2 + 1 + 32, pubKey.toBytes().length); assertEquals(2 + 1 + 32, privKey.toBytes().length); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawPubKeyBytes = pubKey.getRawKeyBytes(); @@ -189,7 +189,7 @@ public class ED25519SignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = privKey.getRawKeyBytes(); byte[] ripemd160PubKeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -221,7 +221,7 @@ public class ED25519SignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = privKey.getRawKeyBytes(); byte[] ripemd160PubKeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -254,7 +254,7 @@ public class ED25519SignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawKeyBytes = pubKey.getRawKeyBytes(); byte[] ripemd160PrivKeyBytes = BytesUtils.concat(algoBytes, privKeyTypeBytes, rawKeyBytes); @@ -286,7 +286,7 @@ public class ED25519SignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawKeyBytes = pubKey.getRawKeyBytes(); byte[] ripemd160PrivKeyBytes = BytesUtils.concat(algoBytes, privKeyTypeBytes, rawKeyBytes); @@ -325,7 +325,7 @@ public class ED25519SignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = signatureDigest.toBytes(); byte[] ripemd160SignatureBytes = BytesUtils.concat(algoBytes, rawDigestBytes); @@ -362,7 +362,7 @@ public class ED25519SignatureFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = signatureDigest.getRawDigest(); byte[] ripemd160SignatureDigestBytes = BytesUtils.concat(algoBytes, rawDigestBytes); diff --git a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RIPEMD160HashFunctionTest.java b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RIPEMD160HashFunctionTest.java index c18bc462..402f4ce6 100644 --- a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RIPEMD160HashFunctionTest.java +++ b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RIPEMD160HashFunctionTest.java @@ -57,7 +57,7 @@ public class RIPEMD160HashFunctionTest { HashDigest digest = hashFunction.hash(data); byte[] rawDigestBytes = digest.getRawDigest(); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] digestBytes = digest.toBytes(); assertEquals(160 / 8 + 2, digestBytes.length); @@ -111,7 +111,7 @@ public class RIPEMD160HashFunctionTest { algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); System.arraycopy(algoBytes, 0, digestBytes, 0, algoBytes.length); assertFalse(hashFunction.supportHashDigest(digestBytes)); } @@ -140,7 +140,7 @@ public class RIPEMD160HashFunctionTest { algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = digest.getRawDigest(); byte[] aesDigestBytes = BytesUtils.concat(algoBytes, rawDigestBytes); @@ -156,7 +156,7 @@ public class RIPEMD160HashFunctionTest { algorithm = Crypto.getAlgorithm("sha256"); assertNotNull(algorithm); - algoBytes = CryptoAlgorithm.toBytes(algorithm); + algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); rawDigestBytes = digest.getRawDigest(); byte[] ripemd160DigestBytes = BytesUtils.concat(algoBytes, rawDigestBytes); diff --git a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RSACryptoFunctionTest.java b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RSACryptoFunctionTest.java index cff875f7..55101525 100644 --- a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RSACryptoFunctionTest.java +++ b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/RSACryptoFunctionTest.java @@ -65,7 +65,7 @@ public class RSACryptoFunctionTest { assertEquals(2 + 1 + 259, pubKey.toBytes().length); assertEquals(2 + 1 + 1155, privKey.toBytes().length); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawPubKeyBytes = pubKey.getRawKeyBytes(); @@ -219,7 +219,7 @@ public class RSACryptoFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = privKey.getRawKeyBytes(); byte[] ripemd160PubKeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -251,7 +251,7 @@ public class RSACryptoFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = privKey.getRawKeyBytes(); byte[] ripemd160PubKeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -284,7 +284,7 @@ public class RSACryptoFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawKeyBytes = pubKey.getRawKeyBytes(); byte[] ripemd160PrivKeyBytes = BytesUtils.concat(algoBytes, privKeyTypeBytes, rawKeyBytes); @@ -316,7 +316,7 @@ public class RSACryptoFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawKeyBytes = pubKey.getRawKeyBytes(); byte[] ripemd160PrivKeyBytes = BytesUtils.concat(algoBytes, privKeyTypeBytes, rawKeyBytes); @@ -355,7 +355,7 @@ public class RSACryptoFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = signatureDigest.toBytes(); byte[] ripemd160SignatureBytes = BytesUtils.concat(algoBytes, rawDigestBytes); @@ -392,7 +392,7 @@ public class RSACryptoFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = signatureDigest.getRawDigest(); byte[] ripemd160SignatureDigestBytes = BytesUtils.concat(algoBytes, rawDigestBytes); @@ -432,7 +432,7 @@ public class RSACryptoFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.toBytes(); byte[] ripemd160CiphertextBytes = BytesUtils.concat(algoBytes, rawCiphertextBytes); @@ -470,7 +470,7 @@ public class RSACryptoFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.getRawCiphertext(); byte[] ripemd160CiphertextBytes = BytesUtils.concat(algoBytes, rawCiphertextBytes); diff --git a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/SHA256HashFunctionTest.java b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/SHA256HashFunctionTest.java index aaf34fcc..0400c9f0 100644 --- a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/SHA256HashFunctionTest.java +++ b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/service/classic/SHA256HashFunctionTest.java @@ -57,7 +57,7 @@ public class SHA256HashFunctionTest { HashDigest digest = hashFunction.hash(data); byte[] rawDigestBytes = digest.getRawDigest(); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] digestBytes = digest.toBytes(); assertEquals(256 / 8 + 2, digestBytes.length); @@ -111,7 +111,7 @@ public class SHA256HashFunctionTest { algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); System.arraycopy(algoBytes, 0, digestBytes, 0, algoBytes.length); assertFalse(hashFunction.supportHashDigest(digestBytes)); } @@ -140,7 +140,7 @@ public class SHA256HashFunctionTest { algorithm = Crypto.getAlgorithm("aes"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = digest.getRawDigest(); byte[] aesDigestBytes = BytesUtils.concat(algoBytes, rawDigestBytes); @@ -156,7 +156,7 @@ public class SHA256HashFunctionTest { algorithm = Crypto.getAlgorithm("ripemd160"); assertNotNull(algorithm); - algoBytes = CryptoAlgorithm.toBytes(algorithm); + algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); rawDigestBytes = digest.getRawDigest(); byte[] ripemd160DigestBytes = BytesUtils.concat(algoBytes, rawDigestBytes); diff --git a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ECDSAUtilsTest.java b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ECDSAUtilsTest.java index 522b3584..71ccbee9 100644 --- a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ECDSAUtilsTest.java +++ b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ECDSAUtilsTest.java @@ -146,7 +146,7 @@ public class ECDSAUtilsTest { assertTrue(ECDSAUtils.verify(pubKey,signature,hashedMsg)); } - @Test +// @Test public void performanceTest(){ int count = 10000; diff --git a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ED25519UtilsTest.java b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ED25519UtilsTest.java index 8fa293a9..75b824d2 100644 --- a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ED25519UtilsTest.java +++ b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/ED25519UtilsTest.java @@ -109,7 +109,7 @@ public class ED25519UtilsTest { } - @Test +// @Test public void performanceTest(){ int count = 10000; diff --git a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/RSAUtilsTest.java b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/RSAUtilsTest.java index 114f8b55..3247be8f 100644 --- a/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/RSAUtilsTest.java +++ b/source/crypto/crypto-classic/src/test/java/test/com/jd/blockchain/crypto/utils/classic/RSAUtilsTest.java @@ -175,7 +175,7 @@ public class RSAUtilsTest { } - @Test +// @Test public void performanceTest(){ int count = 10000; @@ -241,7 +241,7 @@ public class RSAUtilsTest { } } - @Test +// @Test public void encryptionConsistencyTest(){ int count = 10000; @@ -339,7 +339,7 @@ public class RSAUtilsTest { assertArrayEquals(data,plaintext); } - @Test +// @Test public void signatureConsistencyTest() { int count = 10000; diff --git a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/BaseCryptoKey.java b/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/BaseCryptoKey.java index dd2726c7..95cfee3d 100644 --- a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/BaseCryptoKey.java +++ b/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/BaseCryptoKey.java @@ -7,9 +7,9 @@ public abstract class BaseCryptoKey extends BaseCryptoBytes implements CryptoKey public static final int KEY_TYPE_BYTES = 1; private static final long serialVersionUID = 4543074827807908363L; - // public BaseCryptoKey() { - // super(); - // } + public BaseCryptoKey() { + super(); + } protected BaseCryptoKey(short algorithm, byte[] rawKeyBytes, CryptoKeyType keyType) { super(algorithm, CryptoBytesEncoding.encodeKeyBytes(rawKeyBytes, keyType)); diff --git a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoAlgorithm.java b/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoAlgorithm.java index ec8ed272..4f505ba9 100644 --- a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoAlgorithm.java +++ b/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoAlgorithm.java @@ -9,7 +9,7 @@ import com.jd.blockchain.binaryproto.PrimitiveType; import com.jd.blockchain.consts.DataCodes; import com.jd.blockchain.utils.io.BytesUtils; -@DataContract(code = DataCodes.CRYPTO_ALGORITHM) +//@DataContract(code = DataCodes.CRYPTO_ALGORITHM) public interface CryptoAlgorithm { /** @@ -51,7 +51,7 @@ public interface CryptoAlgorithm { static final int SYMMETRIC_KEY = 0x0200; /** - * 算法编码的字节长度;等同于 {@link #toBytes(CryptoAlgorithm)} 返回的字节数组的长度; + * 算法编码的字节长度;等同于 {@link #getCodeBytes(CryptoAlgorithm)} 返回的字节数组的长度; */ static final int CODE_SIZE = 2; @@ -63,7 +63,7 @@ public interface CryptoAlgorithm { * {@link #EXT_ALGORITHM}) 5 种); 接下来4位标识密钥类型(包括:{@link #SYMMETRIC_KEY}, * {@link #ASYMMETRIC_KEY}); 最后8位是算法唯一ID; */ - @DataField(primitiveType = PrimitiveType.INT16, order = 0) +// @DataField(primitiveType = PrimitiveType.INT16, order = 0) short code(); /** @@ -81,16 +81,16 @@ public interface CryptoAlgorithm { * * @return */ - static byte[] toBytes(CryptoAlgorithm algorithm) { + static byte[] getCodeBytes(CryptoAlgorithm algorithm) { return BytesUtils.toBytes(algorithm.code()); } - static short resolveCode(byte[] algorithmBytes) { - return BytesUtils.toShort(algorithmBytes, 0); + static short resolveCode(byte[] codeBytes) { + return BytesUtils.toShort(codeBytes, 0); } - static short resolveCode(byte[] algorithmBytes, int offset) { - return BytesUtils.toShort(algorithmBytes, offset); + static short resolveCode(byte[] codeBytes, int offset) { + return BytesUtils.toShort(codeBytes, offset); } static short resolveCode(InputStream in) { diff --git a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoBytesEncoding.java b/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoBytesEncoding.java index 1cfea0b0..9bfd4567 100644 --- a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoBytesEncoding.java +++ b/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/CryptoBytesEncoding.java @@ -10,7 +10,7 @@ public final class CryptoBytesEncoding { } static byte[] encodeBytes(CryptoAlgorithm algorithm, byte[] rawCryptoBytes) { - return BytesUtils.concat(CryptoAlgorithm.toBytes(algorithm), rawCryptoBytes); + return BytesUtils.concat(CryptoAlgorithm.getCodeBytes(algorithm), rawCryptoBytes); } public static short decodeAlgorithm(byte[] cryptoBytes) { diff --git a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/PrivKey.java b/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/PrivKey.java index b15bb5e7..78af68c4 100644 --- a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/PrivKey.java +++ b/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/PrivKey.java @@ -7,6 +7,7 @@ package com.jd.blockchain.crypto; * */ public class PrivKey extends BaseCryptoKey { + private static final long serialVersionUID = 6265440395252295646L; public PrivKey(short algorithm, byte[] rawCryptoBytes) { diff --git a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/PubKey.java b/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/PubKey.java index ca5b43c8..3d59dd3a 100644 --- a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/PubKey.java +++ b/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/PubKey.java @@ -9,7 +9,11 @@ package com.jd.blockchain.crypto; public class PubKey extends BaseCryptoKey { private static final long serialVersionUID = -2055071197736385328L; - + + public PubKey() { + super(); + } + public PubKey(short algorithm, byte[] rawCryptoBytes) { super(algorithm, rawCryptoBytes, CryptoKeyType.PUBLIC); } diff --git a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/serialize/ByteArrayObjectDeserializer.java b/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/serialize/ByteArrayObjectDeserializer.java deleted file mode 100644 index 42654a66..00000000 --- a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/serialize/ByteArrayObjectDeserializer.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.jd.blockchain.crypto.serialize; - -import com.alibaba.fastjson.parser.DefaultJSONParser; -import com.alibaba.fastjson.parser.JSONToken; -import com.alibaba.fastjson.parser.ParserConfig; -import com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer; -import com.jd.blockchain.crypto.HashDigest; -import com.jd.blockchain.crypto.PubKey; -import com.jd.blockchain.crypto.SignatureDigest; -import com.jd.blockchain.utils.Bytes; -import com.jd.blockchain.utils.codec.Base58Utils; -import com.jd.blockchain.utils.io.BytesSlice; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Type; -import java.util.Map; - -public class ByteArrayObjectDeserializer extends JavaBeanDeserializer { - - private ByteArrayObjectDeserializer(Class clazz) { - super(ParserConfig.global, clazz); - } - - public static ByteArrayObjectDeserializer getInstance(Class clazz) { - return new ByteArrayObjectDeserializer(clazz); - } - - @SuppressWarnings("unchecked") - @Override - public T deserialze(DefaultJSONParser parser, Type type, Object fieldName) { - if (type instanceof Class && clazz.isAssignableFrom((Class) type)) { - String base58Str = parser.parseObject(String.class); - byte[] hashBytes = Base58Utils.decode(base58Str); - if (clazz == HashDigest.class) { - return (T) new HashDigest(hashBytes); - } else if (clazz == PubKey.class) { - return (T) new HashDigest(hashBytes); - } else if (clazz == SignatureDigest.class) { - return (T) new SignatureDigest(hashBytes); - } else if (clazz == Bytes.class) { - return (T) new Bytes(hashBytes); - } else if (clazz == BytesSlice.class) { - return (T) new BytesSlice(hashBytes); - } - } - return (T) parser.parse(fieldName); - } - - @Override - public Object createInstance(Map map, ParserConfig config) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { - if (map == null || map.isEmpty()) { - return null; - } - for (Map.Entry entry : map.entrySet()) { - Object value = entry.getValue(); - if (value instanceof String) { - byte[] hashBytes = Base58Utils.decode((String)value); - if (clazz == HashDigest.class) { - return new HashDigest(hashBytes); - } else if (clazz == PubKey.class) { - return new PubKey(hashBytes); - } else if (clazz == SignatureDigest.class) { - return new SignatureDigest(hashBytes); - } else if (clazz == Bytes.class) { - return new Bytes(hashBytes); - } else if (clazz == BytesSlice.class) { - return new BytesSlice(hashBytes); - } - } - } - return null; - } - - @Override - public int getFastMatchToken() { - return JSONToken.LBRACE; - } -} diff --git a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/serialize/ByteArrayObjectSerializer.java b/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/serialize/ByteArrayObjectSerializer.java deleted file mode 100644 index 282605ed..00000000 --- a/source/crypto/crypto-framework/src/main/java/com/jd/blockchain/crypto/serialize/ByteArrayObjectSerializer.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.jd.blockchain.crypto.serialize; - -import java.lang.reflect.Type; - -import com.alibaba.fastjson.serializer.JSONSerializer; -import com.alibaba.fastjson.serializer.ObjectSerializer; -import com.jd.blockchain.crypto.HashDigest; -import com.jd.blockchain.crypto.PubKey; -import com.jd.blockchain.crypto.SignatureDigest; -import com.jd.blockchain.utils.Bytes; -import com.jd.blockchain.utils.io.BytesSlice; - -public class ByteArrayObjectSerializer implements ObjectSerializer { - - private Class clazz; - - private ByteArrayObjectSerializer(Class clazz) { - this.clazz = clazz; - } - - public static ByteArrayObjectSerializer getInstance(Class clazz) { - return new ByteArrayObjectSerializer(clazz); - } - - @Override - public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) { - if (object.getClass() != clazz) { - serializer.writeNull(); - return; - } - if (object instanceof HashDigest) { - serializer.write(new HashDigestJson(((HashDigest) object).toBase58())); - } else if (object instanceof PubKey) { - serializer.write(new HashDigestJson(((PubKey) object).toBase58())); - } else if (object instanceof SignatureDigest) { - serializer.write(new HashDigestJson(((SignatureDigest) object).toBase58())); - } else if (object instanceof Bytes) { - serializer.write(new HashDigestJson(((Bytes) object).toBase58())); - } else if (object instanceof BytesSlice) { - byte[] bytes = ((BytesSlice) object).toBytes(); - serializer.write(new HashDigestJson(new String(bytes))); - } - } - - private static class HashDigestJson { - - String value; - - public HashDigestJson(String value) { - this.value = value; - } - - @SuppressWarnings("unused") - public String getValue() { - return value; - } - - @SuppressWarnings("unused") - public void setValue(String value) { - this.value = value; - } - } -} diff --git a/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM2CyptoFunctionTest.java b/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM2CyptoFunctionTest.java index d9e438f3..218b443d 100644 --- a/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM2CyptoFunctionTest.java +++ b/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM2CyptoFunctionTest.java @@ -65,7 +65,7 @@ public class SM2CyptoFunctionTest { assertEquals(2 + 1 + 65, pubKey.toBytes().length); assertEquals(2 + 1 + 32, privKey.toBytes().length); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawPubKeyBytes = pubKey.getRawKeyBytes(); @@ -219,7 +219,7 @@ public class SM2CyptoFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = privKey.getRawKeyBytes(); byte[] sm3PubKeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -251,7 +251,7 @@ public class SM2CyptoFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = privKey.getRawKeyBytes(); byte[] sm3PubKeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -284,7 +284,7 @@ public class SM2CyptoFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawKeyBytes = pubKey.getRawKeyBytes(); byte[] sm3PrivKeyBytes = BytesUtils.concat(algoBytes, privKeyTypeBytes, rawKeyBytes); @@ -316,7 +316,7 @@ public class SM2CyptoFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] privKeyTypeBytes = new byte[] { PRIVATE.CODE }; byte[] rawKeyBytes = pubKey.getRawKeyBytes(); byte[] sm3PrivKeyBytes = BytesUtils.concat(algoBytes, privKeyTypeBytes, rawKeyBytes); @@ -355,7 +355,7 @@ public class SM2CyptoFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = signatureDigest.toBytes(); byte[] sm3SignatureBytes = BytesUtils.concat(algoBytes, rawDigestBytes); @@ -392,7 +392,7 @@ public class SM2CyptoFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = signatureDigest.getRawDigest(); byte[] sm3SignatureDigestBytes = BytesUtils.concat(algoBytes, rawDigestBytes); @@ -432,7 +432,7 @@ public class SM2CyptoFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.toBytes(); byte[] sm3CiphertextBytes = BytesUtils.concat(algoBytes, rawCiphertextBytes); @@ -470,7 +470,7 @@ public class SM2CyptoFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.getRawCiphertext(); byte[] sm3CiphertextBytes = BytesUtils.concat(algoBytes, rawCiphertextBytes); diff --git a/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM3HashFunctionTest.java b/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM3HashFunctionTest.java index 5383bfce..f543bc68 100644 --- a/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM3HashFunctionTest.java +++ b/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM3HashFunctionTest.java @@ -55,7 +55,7 @@ public class SM3HashFunctionTest { HashDigest digest = hashFunction.hash(data); byte[] rawDigestBytes = digest.getRawDigest(); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] digestBytes = digest.toBytes(); assertEquals(256 / 8 + 2, digestBytes.length); @@ -109,7 +109,7 @@ public class SM3HashFunctionTest { algorithm = Crypto.getAlgorithm("sm4"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); System.arraycopy(algoBytes, 0, digestBytes, 0, algoBytes.length); assertFalse(hashFunction.supportHashDigest(digestBytes)); } @@ -138,7 +138,7 @@ public class SM3HashFunctionTest { algorithm = Crypto.getAlgorithm("sm4"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawDigestBytes = digest.getRawDigest(); byte[] aesDigestBytes = BytesUtils.concat(algoBytes, rawDigestBytes); diff --git a/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM4EncryptionFunctionTest.java b/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM4EncryptionFunctionTest.java index d8c4e86d..f2a8d3d0 100644 --- a/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM4EncryptionFunctionTest.java +++ b/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/service/sm/SM4EncryptionFunctionTest.java @@ -68,7 +68,7 @@ public class SM4EncryptionFunctionTest { assertEquals(algorithm.code(), symmetricKey.getAlgorithm()); assertEquals(2 + 1 + 128 / 8, symmetricKey.toBytes().length); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] keyTypeBytes = new byte[] { SYMMETRIC.CODE }; byte[] rawKeyBytes = symmetricKey.getRawKeyBytes(); assertArrayEquals(BytesUtils.concat(algoBytes, keyTypeBytes, rawKeyBytes), symmetricKey.toBytes()); @@ -165,7 +165,7 @@ public class SM4EncryptionFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = symmetricKey.getRawKeyBytes(); byte[] ripemd160KeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -194,7 +194,7 @@ public class SM4EncryptionFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] pubKeyTypeBytes = new byte[] { PUBLIC.CODE }; byte[] rawKeyBytes = symmetricKey.getRawKeyBytes(); byte[] ripemd160KeyBytes = BytesUtils.concat(algoBytes, pubKeyTypeBytes, rawKeyBytes); @@ -232,7 +232,7 @@ public class SM4EncryptionFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.toBytes(); byte[] sm3CiphertextBytes = BytesUtils.concat(algoBytes, rawCiphertextBytes); @@ -268,7 +268,7 @@ public class SM4EncryptionFunctionTest { algorithm = Crypto.getAlgorithm("sm3"); assertNotNull(algorithm); - byte[] algoBytes = CryptoAlgorithm.toBytes(algorithm); + byte[] algoBytes = CryptoAlgorithm.getCodeBytes(algorithm); byte[] rawCiphertextBytes = ciphertext.getRawCiphertext(); byte[] sm3CiphertextBytes = BytesUtils.concat(algoBytes, rawCiphertextBytes); diff --git a/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/utils/SM2UtilsTest.java b/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/utils/SM2UtilsTest.java index 014c1c31..04dd5ca5 100644 --- a/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/utils/SM2UtilsTest.java +++ b/source/crypto/crypto-sm/src/test/java/test/com/jd/blockchain/crypto/utils/SM2UtilsTest.java @@ -119,50 +119,50 @@ public class SM2UtilsTest { byte[] plaintext = SM2Utils.decrypt(ciphertext,privKeyBytes); assertArrayEquals(expectedMessage.getBytes(),plaintext); } -// + +// @Test + public void encryptingPerformace(){ + + byte[] data = new byte[1000]; + Random random = new Random(); + random.nextBytes(data); + + int count = 10000; + + byte[] ciphertext = null; + + AsymmetricCipherKeyPair keyPair = SM2Utils.generateKeyPair(); + ECPublicKeyParameters ecPub = (ECPublicKeyParameters) keyPair.getPublic(); + ECPrivateKeyParameters ecPriv = (ECPrivateKeyParameters) keyPair.getPrivate(); + + System.out.println("=================== do SM2 encrypt test ==================="); + + for (int r = 0; r < 5; r++) { + System.out.println("------------- round[" + r + "] --------------"); + long startTS = System.currentTimeMillis(); + for (int i = 0; i < count; i++) { + ciphertext = SM2Utils.encrypt(data,ecPub); + } + long elapsedTS = System.currentTimeMillis() - startTS; + System.out.println(String.format("SM2 Encrypting Count=%s; Elapsed Times=%s; KBPS=%.2f", count, elapsedTS, + (count * 1000.00D) / elapsedTS)); + } + + System.out.println("=================== do SM2 decrypt test ==================="); + for (int r = 0; r < 5; r++) { + System.out.println("------------- round[" + r + "] --------------"); + long startTS = System.currentTimeMillis(); + for (int i = 0; i < count; i++) { + SM2Utils.decrypt(ciphertext,ecPriv); + } + long elapsedTS = System.currentTimeMillis() - startTS; + System.out.println(String.format("SM2 Decrypting Count=%s; Elapsed Times=%s; KBPS=%.2f", count, elapsedTS, + (count * 1000.00D) / elapsedTS)); + } + } + + // @Test -// public void encryptingPerformace(){ -// -// byte[] data = new byte[1000]; -// Random random = new Random(); -// random.nextBytes(data); -// -// int count = 10000; -// -// byte[] ciphertext = null; -// -// AsymmetricCipherKeyPair keyPair = SM2Utils.generateKeyPair(); -// ECPublicKeyParameters ecPub = (ECPublicKeyParameters) keyPair.getPublic(); -// ECPrivateKeyParameters ecPriv = (ECPrivateKeyParameters) keyPair.getPrivate(); -// -// System.out.println("=================== do SM2 encrypt test ==================="); -// -// for (int r = 0; r < 5; r++) { -// System.out.println("------------- round[" + r + "] --------------"); -// long startTS = System.currentTimeMillis(); -// for (int i = 0; i < count; i++) { -// ciphertext = SM2Utils.encrypt(data,ecPub); -// } -// long elapsedTS = System.currentTimeMillis() - startTS; -// System.out.println(String.format("SM2 Encrypting Count=%s; Elapsed Times=%s; KBPS=%.2f", count, elapsedTS, -// (count * 1000.00D) / elapsedTS)); -// } -// -// System.out.println("=================== do SM2 decrypt test ==================="); -// for (int r = 0; r < 5; r++) { -// System.out.println("------------- round[" + r + "] --------------"); -// long startTS = System.currentTimeMillis(); -// for (int i = 0; i < count; i++) { -// SM2Utils.decrypt(ciphertext,ecPriv); -// } -// long elapsedTS = System.currentTimeMillis() - startTS; -// System.out.println(String.format("SM2 Decrypting Count=%s; Elapsed Times=%s; KBPS=%.2f", count, elapsedTS, -// (count * 1000.00D) / elapsedTS)); -// } -// } -// -// - @Test public void signingPerformace(){ byte[] data = new byte[1024]; diff --git a/source/deployment/deployment-peer/pom.xml b/source/deployment/deployment-peer/pom.xml index 9751b803..1d5f9fc5 100644 --- a/source/deployment/deployment-peer/pom.xml +++ b/source/deployment/deployment-peer/pom.xml @@ -25,6 +25,28 @@ runtime-modular-booter ${project.version} + + + com.jd.blockchain + storage-composite + ${project.version} + + + com.jd.blockchain + storage-service + ${project.version} + + + com.jd.blockchain + storage-redis + ${project.version} + + + com.jd.blockchain + storage-rocksdb + ${project.version} + + diff --git a/source/deployment/deployment-peer/src/main/resources/assembly.xml b/source/deployment/deployment-peer/src/main/resources/assembly.xml index d445b9cb..5e64c93e 100644 --- a/source/deployment/deployment-peer/src/main/resources/assembly.xml +++ b/source/deployment/deployment-peer/src/main/resources/assembly.xml @@ -62,15 +62,6 @@ true com.jd.blockchain:tools-initializer-booter - - - libs - false - - - - true - com.jd.blockchain:tools-keygen-booter diff --git a/source/gateway/pom.xml b/source/gateway/pom.xml index f21abfba..3150363e 100644 --- a/source/gateway/pom.xml +++ b/source/gateway/pom.xml @@ -15,6 +15,17 @@ consensus-framework ${project.version} + + com.jd.blockchain + consensus-bftsmart + ${project.version} + + + com.jd.blockchain + consensus-mq + ${project.version} + + com.jd.blockchain ledger-rpc @@ -43,11 +54,22 @@ ${project.version} + + com.jd.blockchain + crypto-framework + ${project.version} + + com.jd.blockchain crypto-classic ${project.version} - test + + + + com.jd.blockchain + crypto-sm + ${project.version} diff --git a/source/gateway/src/main/java/com/jd/blockchain/gateway/service/GatewayQueryService.java b/source/gateway/src/main/java/com/jd/blockchain/gateway/service/GatewayQueryService.java index 73b5d64e..6cd1828c 100644 --- a/source/gateway/src/main/java/com/jd/blockchain/gateway/service/GatewayQueryService.java +++ b/source/gateway/src/main/java/com/jd/blockchain/gateway/service/GatewayQueryService.java @@ -2,6 +2,7 @@ package com.jd.blockchain.gateway.service; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.ledger.ParticipantNode; +import com.jd.blockchain.sdk.LedgerInitSettings; /** * queryService only for gateway; @@ -24,4 +25,13 @@ public interface GatewayQueryService { * @return */ ParticipantNode[] getConsensusParticipants(HashDigest ledgerHash, int fromIndex, int count); + + /** + * 获取账本初始化配置信息 + * + * @param ledgerHash + * 账本Hash + * @return + */ + LedgerInitSettings getLedgerInitSettings(HashDigest ledgerHash); } diff --git a/source/gateway/src/main/java/com/jd/blockchain/gateway/service/GatewayQueryServiceHandler.java b/source/gateway/src/main/java/com/jd/blockchain/gateway/service/GatewayQueryServiceHandler.java new file mode 100644 index 00000000..71e34a7c --- /dev/null +++ b/source/gateway/src/main/java/com/jd/blockchain/gateway/service/GatewayQueryServiceHandler.java @@ -0,0 +1,144 @@ +package com.jd.blockchain.gateway.service; + +import com.jd.blockchain.consensus.ConsensusProvider; +import com.jd.blockchain.consensus.ConsensusProviders; +import com.jd.blockchain.consensus.ConsensusSettings; +import com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider; +import com.jd.blockchain.consensus.mq.MsgQueueConsensusProvider; +import com.jd.blockchain.crypto.HashDigest; +import com.jd.blockchain.gateway.PeerService; +import com.jd.blockchain.ledger.LedgerMetadata; +import com.jd.blockchain.ledger.ParticipantNode; +import com.jd.blockchain.sdk.LedgerInitSettings; +import com.jd.blockchain.utils.QueryUtil; +import com.jd.blockchain.utils.codec.HexUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import java.util.Arrays; + + +/** + * @Author zhaogw + * @Date 2019/2/22 10:39 + */ +@Component +public class GatewayQueryServiceHandler implements GatewayQueryService { + + @Autowired + private PeerService peerService; + + @Override + public HashDigest[] getLedgersHash(int fromIndex, int count) { + HashDigest ledgersHash[] = peerService.getQueryService().getLedgerHashs(); + int indexAndCount[] = QueryUtil.calFromIndexAndCount(fromIndex,count,ledgersHash.length); + HashDigest ledgersHashNew[] = Arrays.copyOfRange(ledgersHash,indexAndCount[0],indexAndCount[0]+indexAndCount[1]); + return ledgersHashNew; + } + + @Override + public ParticipantNode[] getConsensusParticipants(HashDigest ledgerHash, int fromIndex, int count) { + ParticipantNode participantNode[] = peerService.getQueryService().getConsensusParticipants(ledgerHash); + int indexAndCount[] = QueryUtil.calFromIndexAndCount(fromIndex,count,participantNode.length); + ParticipantNode participantNodesNew[] = Arrays.copyOfRange(participantNode,indexAndCount[0],indexAndCount[0]+indexAndCount[1]); + return participantNodesNew; + } + + @Override + public LedgerInitSettings getLedgerInitSettings(HashDigest ledgerHash) { + + ParticipantNode[] participantNodes = peerService.getQueryService().getConsensusParticipants(ledgerHash); + + LedgerMetadata ledgerMetadata = peerService.getQueryService().getLedgerMetadata(ledgerHash); + + return initLedgerInitSettings(participantNodes, ledgerMetadata); + } + + /** + * 初始化账本配置 + * + * @param participantNodes + * 参与方列表 + * @param ledgerMetadata + * 账本元数据 + * @return + */ + private LedgerInitSettings initLedgerInitSettings(ParticipantNode[] participantNodes, LedgerMetadata ledgerMetadata) { + LedgerInitSettings ledgerInitSettings = new LedgerInitSettings(); + + // 设置参与方 + ledgerInitSettings.setParticipantNodes(participantNodes); + + // 设置共识设置 + ledgerInitSettings.setConsensusSettings(initConsensusSettings(ledgerMetadata)); + + // 设置参与方根Hash + ledgerInitSettings.setParticipantsHash(ledgerMetadata.getParticipantsHash()); + + // 设置算法配置 + ledgerInitSettings.setCryptoSetting(ledgerMetadata.getSetting().getCryptoSetting()); + + // 设置种子 + ledgerInitSettings.setSeed(initSeed(ledgerMetadata.getSeed())); + + // 设置共识协议 + ledgerInitSettings.setConsensusProtocol(consensusProtocol(ledgerMetadata.getSetting().getConsensusProvider())); + + return ledgerInitSettings; + } + + /** + * 初始化账本种子信息 + * + * @param seedBytes + * 种子的字节数组显示 + * @return + * 种子以十六进制方式显示,为方便阅读,每隔八个字符中间以"-"分割 + */ + private String initSeed(byte[] seedBytes) { + String seedString = HexUtils.encode(seedBytes); + // 每隔八个字符中加入一个一个横线 + StringBuffer seed = new StringBuffer(); + + for( int i = 0; i < seedString.length(); i++) { + char c = seedString.charAt(i); + if (i != 0 && i % 8 == 0) { + seed.append("-"); + } + seed.append(c); + } + + return seed.toString(); + } + + /** + * 生成共识协议 + * + * @param consensusProvider + * 共识协议提提供者 + * @return + */ + private int consensusProtocol(String consensusProvider) { + + if (consensusProvider.equals(BftsmartConsensusProvider.NAME)) { + return LedgerInitSettings.CONSENSUS_PROTOCOL.BFTSMART.code(); + } else if (consensusProvider.equals(MsgQueueConsensusProvider.NAME)) { + return LedgerInitSettings.CONSENSUS_PROTOCOL.MSGQUEUE.code(); + } + + return LedgerInitSettings.CONSENSUS_PROTOCOL.UNKNOWN.code(); + } + + /** + * 初始化共识配置 + * + * @param ledgerMetadata + * 账本元数据 + * @return + */ + private ConsensusSettings initConsensusSettings(LedgerMetadata ledgerMetadata) { + String consensusProvider = ledgerMetadata.getSetting().getConsensusProvider(); + ConsensusProvider provider = ConsensusProviders.getProvider(consensusProvider); + byte[] consensusSettingsBytes = ledgerMetadata.getSetting().getConsensusSetting().toBytes(); + return provider.getSettingsFactory().getConsensusSettingsEncoder().decode(consensusSettingsBytes); + } +} diff --git a/source/gateway/src/main/java/com/jd/blockchain/gateway/service/GatewayQueryServiceImpl.java b/source/gateway/src/main/java/com/jd/blockchain/gateway/service/GatewayQueryServiceImpl.java index 4f3c5a36..24433b70 100644 --- a/source/gateway/src/main/java/com/jd/blockchain/gateway/service/GatewayQueryServiceImpl.java +++ b/source/gateway/src/main/java/com/jd/blockchain/gateway/service/GatewayQueryServiceImpl.java @@ -1,37 +1,37 @@ -package com.jd.blockchain.gateway.service; - -import com.jd.blockchain.crypto.HashDigest; -import com.jd.blockchain.gateway.PeerService; -import com.jd.blockchain.ledger.ParticipantNode; -import com.jd.blockchain.utils.QueryUtil; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import java.util.Arrays; - -import static com.jd.blockchain.utils.BaseConstant.QUERY_LIST_MAX; - -/** - * @Author zhaogw - * @Date 2019/2/22 10:39 - */ -@Component -public class GatewayQueryServiceImpl implements GatewayQueryService { - @Autowired - private PeerService peerService; - - @Override - public HashDigest[] getLedgersHash(int fromIndex, int count) { - HashDigest ledgersHash[] = peerService.getQueryService().getLedgerHashs(); - int indexAndCount[] = QueryUtil.calFromIndexAndCount(fromIndex,count,ledgersHash.length); - HashDigest ledgersHashNew[] = Arrays.copyOfRange(ledgersHash,indexAndCount[0],indexAndCount[0]+indexAndCount[1]); - return ledgersHashNew; - } - - @Override - public ParticipantNode[] getConsensusParticipants(HashDigest ledgerHash, int fromIndex, int count) { - ParticipantNode participantNode[] = peerService.getQueryService().getConsensusParticipants(ledgerHash); - int indexAndCount[] = QueryUtil.calFromIndexAndCount(fromIndex,count,participantNode.length); - ParticipantNode participantNodesNew[] = Arrays.copyOfRange(participantNode,indexAndCount[0],indexAndCount[0]+indexAndCount[1]); - return participantNodesNew; - } -} +//package com.jd.blockchain.gateway.service; +// +//import com.jd.blockchain.crypto.HashDigest; +//import com.jd.blockchain.gateway.PeerService; +//import com.jd.blockchain.ledger.ParticipantNode; +//import com.jd.blockchain.utils.QueryUtil; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.stereotype.Component; +//import java.util.Arrays; +// +//import static com.jd.blockchain.utils.BaseConstant.QUERY_LIST_MAX; +// +///** +// * @Author zhaogw +// * @Date 2019/2/22 10:39 +// */ +//@Component +//public class GatewayQueryServiceImpl implements GatewayQueryService { +// @Autowired +// private PeerService peerService; +// +// @Override +// public HashDigest[] getLedgersHash(int fromIndex, int count) { +// HashDigest ledgersHash[] = peerService.getQueryService().getLedgerHashs(); +// int indexAndCount[] = QueryUtil.calFromIndexAndCount(fromIndex,count,ledgersHash.length); +// HashDigest ledgersHashNew[] = Arrays.copyOfRange(ledgersHash,indexAndCount[0],indexAndCount[0]+indexAndCount[1]); +// return ledgersHashNew; +// } +// +// @Override +// public ParticipantNode[] getConsensusParticipants(HashDigest ledgerHash, int fromIndex, int count) { +// ParticipantNode participantNode[] = peerService.getQueryService().getConsensusParticipants(ledgerHash); +// int indexAndCount[] = QueryUtil.calFromIndexAndCount(fromIndex,count,participantNode.length); +// ParticipantNode participantNodesNew[] = Arrays.copyOfRange(participantNode,indexAndCount[0],indexAndCount[0]+indexAndCount[1]); +// return participantNodesNew; +// } +//} diff --git a/source/gateway/src/main/java/com/jd/blockchain/gateway/web/BlockBrowserController.java b/source/gateway/src/main/java/com/jd/blockchain/gateway/web/BlockBrowserController.java index 68243eb4..381cc50f 100644 --- a/source/gateway/src/main/java/com/jd/blockchain/gateway/web/BlockBrowserController.java +++ b/source/gateway/src/main/java/com/jd/blockchain/gateway/web/BlockBrowserController.java @@ -8,6 +8,7 @@ import com.jd.blockchain.gateway.service.DataRetrievalService; import com.jd.blockchain.gateway.service.GatewayQueryService; import com.jd.blockchain.ledger.*; import com.jd.blockchain.sdk.BlockchainExtendQueryService; +import com.jd.blockchain.sdk.LedgerInitSettings; import com.jd.blockchain.tools.keygen.KeyGenCommand; import com.jd.blockchain.utils.BaseConstant; import com.jd.blockchain.utils.ConsoleUtils; @@ -58,6 +59,17 @@ public class BlockBrowserController implements BlockchainExtendQueryService { return peerService.getQueryService().getConsensusParticipants(ledgerHash); } + @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/metadata") + @Override + public LedgerMetadata getLedgerMetadata(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) { + return peerService.getQueryService().getLedgerMetadata(ledgerHash); + } + + @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/settings") + public LedgerInitSettings getLedgerInitSettings(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) { + return gatewayQueryService.getLedgerInitSettings(ledgerHash); + } + @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks") public LedgerBlock[] getBlocks(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) { LedgerInfo ledgerInfo = peerService.getQueryService().getLedger(ledgerHash); diff --git a/source/gateway/src/main/java/com/jd/blockchain/gateway/web/GatewayWebServerConfigurer.java b/source/gateway/src/main/java/com/jd/blockchain/gateway/web/GatewayWebServerConfigurer.java index 5174950e..b93a8008 100644 --- a/source/gateway/src/main/java/com/jd/blockchain/gateway/web/GatewayWebServerConfigurer.java +++ b/source/gateway/src/main/java/com/jd/blockchain/gateway/web/GatewayWebServerConfigurer.java @@ -2,7 +2,7 @@ package com.jd.blockchain.gateway.web; import java.util.List; -import com.jd.blockchain.utils.io.BytesSlice; +import com.jd.blockchain.web.serializes.ByteArrayObjectUtil; import org.springframework.context.annotation.Configuration; import org.springframework.format.FormatterRegistry; import org.springframework.http.converter.HttpMessageConverter; @@ -11,12 +11,6 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import com.jd.blockchain.crypto.HashDigest; -import com.jd.blockchain.crypto.PubKey; -import com.jd.blockchain.crypto.SignatureDigest; -import com.jd.blockchain.crypto.serialize.ByteArrayObjectDeserializer; -import com.jd.blockchain.crypto.serialize.ByteArrayObjectSerializer; -import com.jd.blockchain.utils.Bytes; import com.jd.blockchain.utils.io.ByteArray; import com.jd.blockchain.utils.serialize.json.JSONSerializeUtils; import com.jd.blockchain.utils.web.model.JsonWebResponseMessageConverter; @@ -30,13 +24,6 @@ import com.jd.blockchain.web.converters.HashDigestInputConverter; @Configuration public class GatewayWebServerConfigurer implements WebMvcConfigurer { - private static final Class[] BYTEARRAY_JSON_SERIALIZE_CLASS = new Class[] { - HashDigest.class, - PubKey.class, - SignatureDigest.class, - Bytes.class, - BytesSlice.class}; - static { JSONSerializeUtils.disableCircularReferenceDetect(); JSONSerializeUtils.configStringSerializer(ByteArray.class); @@ -67,11 +54,11 @@ public class GatewayWebServerConfigurer implements WebMvcConfigurer { registry.addConverter(new HashDigestInputConverter()); } - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/webjars/**") .addResourceLocations("classpath:/META-INF/resources"); - } + } @Override public void addViewControllers(ViewControllerRegistry registry) { @@ -79,10 +66,6 @@ public class GatewayWebServerConfigurer implements WebMvcConfigurer { } private void initByteArrayJsonSerialize() { - for (Class byteArrayClass : BYTEARRAY_JSON_SERIALIZE_CLASS) { - JSONSerializeUtils.configSerialization(byteArrayClass, - ByteArrayObjectSerializer.getInstance(byteArrayClass), - ByteArrayObjectDeserializer.getInstance(byteArrayClass)); - } + ByteArrayObjectUtil.init(); } } diff --git a/source/gateway/src/main/resources/gateway.conf b/source/gateway/src/main/resources/gateway.conf index 84f00679..c8ceaf4e 100644 --- a/source/gateway/src/main/resources/gateway.conf +++ b/source/gateway/src/main/resources/gateway.conf @@ -1,28 +1,30 @@ #网关的HTTP服务地址; -http.host=127.0.0.1 +http.host=0.0.0.0 #网关的HTTP服务端口; http.port=8081 #网关的HTTP服务上下文路径,可选; #http.context-path= -#共识节点的服务地址; +#共识节点的服务地址(与该网关节点连接的Peer节点的IP地址); peer.host=127.0.0.1 -#共识节点的服务端口; -peer.port=7080 +#共识节点的服务端口(与该网关节点连接的Peer节点的端口); +peer.port=12000 #共识节点的服务是否启用安全证书; peer.secure=false #共识节点的服务提供解析器 +#BftSmart共识Provider:com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider +#简单消息共识Provider:com.jd.blockchain.consensus.mq.MsgQueueConsensusProvider peer.providers=com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider -#数据检索服务对应URL +#数据检索服务对应URL,格式:http://{ip}:{port},例如:http://127.0.0.1:10001 #若该值不配置或配置不正确,则浏览器模糊查询部分无法正常显示 -data.retrieval.url=http://192.168.1.1:10001 +data.retrieval.url=http://127.0.0.1:10001 #默认公钥的内容(Base58编码数据); -keys.default.pubkey=endPsK36g6bhgn5bj66uyX4uxqnkfGvdjpxWurAA5hbf8vVoVi8H +keys.default.pubkey=3snPdw7i7PapsDoW185c3kfK6p8s6SwiJAdEUzgnfeuUox12nxgzXu #默认私钥的路径;在 pk-path 和 pk 之间必须设置其一; keys.default.privkey-path= #默认私钥的内容(加密的Base58编码数据);在 pk-path 和 pk 之间必须设置其一; -keys.default.privkey=177gjwmuvDnccAvrvmJyCN1dgAqqGzfYpe3pZ8dWWNBneM5GgdsS96vgjvBP4fX61jWfohQ +keys.default.privkey=177gjyoEUhdD1NkQSxBVvfSyovMd1ha5H46zsb9kyErLNBuQkLRAf2ea6CNjStjCFJQN8S1 #默认私钥的解码密码; keys.default.privkey-password=DYu3G8aGTMBW1WrTw76zxQJQU4DHLw9MLyy7peG4LKkY \ No newline at end of file diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerAdminAccount.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerAdminAccount.java index 68f77f29..88ab790a 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerAdminAccount.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerAdminAccount.java @@ -1,5 +1,7 @@ package com.jd.blockchain.ledger.core; +import com.jd.blockchain.ledger.LedgerMetadata; +import com.jd.blockchain.ledger.LedgerSetting; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerAdministration.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerAdministration.java index 79632ae4..cc09138f 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerAdministration.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerAdministration.java @@ -1,5 +1,6 @@ package com.jd.blockchain.ledger.core; +import com.jd.blockchain.ledger.LedgerMetadata; import com.jd.blockchain.ledger.ParticipantNode; public interface LedgerAdministration { diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerConfiguration.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerConfiguration.java index ef34122b..5605003c 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerConfiguration.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerConfiguration.java @@ -1,6 +1,7 @@ package com.jd.blockchain.ledger.core; import com.jd.blockchain.ledger.CryptoSetting; +import com.jd.blockchain.ledger.LedgerSetting; import com.jd.blockchain.utils.Bytes; public class LedgerConfiguration implements LedgerSetting { diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerMetadata.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerMetadata.java index 4e8f05e5..68d51ae2 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerMetadata.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerMetadata.java @@ -1,36 +1,36 @@ -package com.jd.blockchain.ledger.core; - -import com.jd.blockchain.binaryproto.DataContract; -import com.jd.blockchain.binaryproto.DataField; -import com.jd.blockchain.binaryproto.PrimitiveType; -import com.jd.blockchain.consts.DataCodes; -import com.jd.blockchain.crypto.HashDigest; - -@DataContract(code = DataCodes.METADATA) -public interface LedgerMetadata { - - /** - * 账本的初始化种子; - * - * @return - */ - @DataField(order = 1, primitiveType = PrimitiveType.BYTES) - byte[] getSeed(); - - /** - * 共识参与方的默克尔树的根; - * - * @return - */ - @DataField(order = 2, primitiveType = PrimitiveType.BYTES) - HashDigest getParticipantsHash(); - - /** - * 账本配置; - * - * @return - */ - @DataField(order = 3, refContract = true) - LedgerSetting getSetting(); - -} +//package com.jd.blockchain.ledger.core; +// +//import com.jd.blockchain.binaryproto.DataContract; +//import com.jd.blockchain.binaryproto.DataField; +//import com.jd.blockchain.binaryproto.PrimitiveType; +//import com.jd.blockchain.consts.DataCodes; +//import com.jd.blockchain.crypto.HashDigest; +// +//@DataContract(code = DataCodes.METADATA) +//public interface LedgerMetadata { +// +// /** +// * 账本的初始化种子; +// * +// * @return +// */ +// @DataField(order = 1, primitiveType = PrimitiveType.BYTES) +// byte[] getSeed(); +// +// /** +// * 共识参与方的默克尔树的根; +// * +// * @return +// */ +// @DataField(order = 2, primitiveType = PrimitiveType.BYTES) +// HashDigest getParticipantsHash(); +// +// /** +// * 账本配置; +// * +// * @return +// */ +// @DataField(order = 3, refContract = true) +// LedgerSetting getSetting(); +// +//} diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerSetting.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerSetting.java index 21ce0565..6e9ad134 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerSetting.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerSetting.java @@ -1,24 +1,24 @@ -package com.jd.blockchain.ledger.core; - -import com.jd.blockchain.binaryproto.DataContract; -import com.jd.blockchain.binaryproto.DataField; -import com.jd.blockchain.binaryproto.PrimitiveType; -import com.jd.blockchain.consts.DataCodes; -import com.jd.blockchain.ledger.CryptoSetting; -import com.jd.blockchain.utils.Bytes; - -@DataContract(code = DataCodes.METADATA_LEDGER_SETTING) -public interface LedgerSetting { - - @DataField(order=0, primitiveType=PrimitiveType.TEXT) - String getConsensusProvider(); - - @DataField(order=1, primitiveType=PrimitiveType.BYTES) - Bytes getConsensusSetting(); - - @DataField(order=2, refContract=true) - CryptoSetting getCryptoSetting(); - -// PrivilegeModelSetting getPrivilegesModelSetting(); - -} \ No newline at end of file +//package com.jd.blockchain.ledger.core; +// +//import com.jd.blockchain.binaryproto.DataContract; +//import com.jd.blockchain.binaryproto.DataField; +//import com.jd.blockchain.binaryproto.PrimitiveType; +//import com.jd.blockchain.consts.DataCodes; +//import com.jd.blockchain.ledger.CryptoSetting; +//import com.jd.blockchain.utils.Bytes; +// +//@DataContract(code = DataCodes.METADATA_LEDGER_SETTING) +//public interface LedgerSetting { +// +// @DataField(order=0, primitiveType=PrimitiveType.TEXT) +// String getConsensusProvider(); +// +// @DataField(order=1, primitiveType=PrimitiveType.BYTES) +// Bytes getConsensusSetting(); +// +// @DataField(order=2, refContract=true) +// CryptoSetting getCryptoSetting(); +// +//// PrivilegeModelSetting getPrivilegesModelSetting(); +// +//} \ No newline at end of file diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerQueryService.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerQueryService.java index e7131c5a..086b18ff 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerQueryService.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerQueryService.java @@ -3,16 +3,7 @@ package com.jd.blockchain.ledger.core.impl; import com.jd.blockchain.binaryproto.BinaryProtocol; import com.jd.blockchain.binaryproto.PrimitiveType; import com.jd.blockchain.crypto.HashDigest; -import com.jd.blockchain.ledger.AccountHeader; -import com.jd.blockchain.ledger.BytesValue; -import com.jd.blockchain.ledger.KVDataEntry; -import com.jd.blockchain.ledger.KVDataObject; -import com.jd.blockchain.ledger.LedgerBlock; -import com.jd.blockchain.ledger.LedgerInfo; -import com.jd.blockchain.ledger.LedgerTransaction; -import com.jd.blockchain.ledger.ParticipantNode; -import com.jd.blockchain.ledger.TransactionState; -import com.jd.blockchain.ledger.UserInfo; +import com.jd.blockchain.ledger.*; import com.jd.blockchain.ledger.core.ContractAccountSet; import com.jd.blockchain.ledger.core.DataAccount; import com.jd.blockchain.ledger.core.DataAccountSet; @@ -50,10 +41,12 @@ public class LedgerQueryService implements BlockchainQueryService { @Override public ParticipantNode[] getConsensusParticipants(HashDigest ledgerHash) { - LedgerRepository ledger = ledgerService.getLedger(ledgerHash); - LedgerBlock block = ledger.getLatestBlock(); - LedgerAdministration administration = ledger.getAdminAccount(block); - return administration.getParticipants(); + return ledgerAdministration(ledgerHash).getParticipants(); + } + + @Override + public LedgerMetadata getLedgerMetadata(HashDigest ledgerHash) { + return ledgerAdministration(ledgerHash).getMetadata(); } @Override @@ -338,4 +331,11 @@ public class LedgerQueryService implements BlockchainQueryService { int pages[] = QueryUtil.calFromIndexAndCount(fromIndex,count,(int)contractAccountSet.getTotalCount()); return contractAccountSet.getAccounts(pages[0],pages[1]); } + + private LedgerAdministration ledgerAdministration(HashDigest ledgerHash) { + LedgerRepository ledger = ledgerService.getLedger(ledgerHash); + LedgerBlock block = ledger.getLatestBlock(); + LedgerAdministration administration = ledger.getAdminAccount(block); + return administration; + } } diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerRepositoryImpl.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerRepositoryImpl.java index 865f18d0..3182c736 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerRepositoryImpl.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerRepositoryImpl.java @@ -4,12 +4,7 @@ import com.jd.blockchain.binaryproto.BinaryProtocol; import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.HashFunction; -import com.jd.blockchain.ledger.BlockBody; -import com.jd.blockchain.ledger.CryptoSetting; -import com.jd.blockchain.ledger.LedgerBlock; -import com.jd.blockchain.ledger.LedgerDataSnapshot; -import com.jd.blockchain.ledger.LedgerInitSetting; -import com.jd.blockchain.ledger.TransactionRequest; +import com.jd.blockchain.ledger.*; import com.jd.blockchain.ledger.core.AccountAccessPolicy; import com.jd.blockchain.ledger.core.ContractAccountSet; import com.jd.blockchain.ledger.core.DataAccountSet; @@ -20,7 +15,6 @@ import com.jd.blockchain.ledger.core.LedgerDataSet; import com.jd.blockchain.ledger.core.LedgerEditor; import com.jd.blockchain.ledger.core.LedgerException; import com.jd.blockchain.ledger.core.LedgerRepository; -import com.jd.blockchain.ledger.core.LedgerSetting; import com.jd.blockchain.ledger.core.LedgerTransactionContext; import com.jd.blockchain.ledger.core.TransactionSet; import com.jd.blockchain.ledger.core.UserAccountSet; @@ -486,7 +480,7 @@ public class LedgerRepositoryImpl implements LedgerRepository { } static TransactionSet newTransactionSet(LedgerSetting ledgerSetting, String keyPrefix, - ExPolicyKVStorage ledgerExStorage, VersioningKVStorage ledgerVerStorage) { + ExPolicyKVStorage ledgerExStorage, VersioningKVStorage ledgerVerStorage) { // TransactionSet transactionSet = new // TransactionSet(ledgerSetting.getCryptoSetting(), // PrefixAppender.prefix(TRANSACTION_SET_PREFIX, ledgerExStorage), diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerTransactionalEditor.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerTransactionalEditor.java index 4277434d..5bb29512 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerTransactionalEditor.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerTransactionalEditor.java @@ -5,17 +5,9 @@ import java.util.Stack; import com.jd.blockchain.binaryproto.BinaryProtocol; import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.HashDigest; -import com.jd.blockchain.ledger.BlockBody; -import com.jd.blockchain.ledger.CryptoSetting; -import com.jd.blockchain.ledger.LedgerBlock; -import com.jd.blockchain.ledger.LedgerDataSnapshot; -import com.jd.blockchain.ledger.LedgerInitSetting; -import com.jd.blockchain.ledger.LedgerTransaction; -import com.jd.blockchain.ledger.TransactionRequest; -import com.jd.blockchain.ledger.TransactionState; +import com.jd.blockchain.ledger.*; import com.jd.blockchain.ledger.core.LedgerDataSet; import com.jd.blockchain.ledger.core.LedgerEditor; -import com.jd.blockchain.ledger.core.LedgerSetting; import com.jd.blockchain.ledger.core.LedgerTransactionContext; import com.jd.blockchain.ledger.core.TransactionSet; import com.jd.blockchain.storage.service.ExPolicyKVStorage; @@ -67,7 +59,7 @@ public class LedgerTransactionalEditor implements LedgerEditor { } public static LedgerTransactionalEditor createEditor(LedgerSetting ledgerSetting, LedgerBlock previousBlock, - String ledgerKeyPrefix, ExPolicyKVStorage ledgerExStorage, VersioningKVStorage ledgerVerStorage) { + String ledgerKeyPrefix, ExPolicyKVStorage ledgerExStorage, VersioningKVStorage ledgerVerStorage) { // new block; LedgerBlockData currBlock = new LedgerBlockData(previousBlock.getHeight() + 1, previousBlock.getLedgerHash(), previousBlock.getHash()); diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/ContractLedgerContext.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/ContractLedgerContext.java index 75d81904..2d51c185 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/ContractLedgerContext.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/ContractLedgerContext.java @@ -6,22 +6,7 @@ import java.util.List; import com.alibaba.fastjson.JSON; import com.jd.blockchain.contract.LedgerContext; import com.jd.blockchain.crypto.HashDigest; -import com.jd.blockchain.ledger.AccountHeader; -import com.jd.blockchain.ledger.BlockchainIdentity; -import com.jd.blockchain.ledger.BytesValue; -import com.jd.blockchain.ledger.BytesValueEntry; -import com.jd.blockchain.ledger.DataAccountKVSetOperation; -import com.jd.blockchain.ledger.DataAccountRegisterOperation; -import com.jd.blockchain.ledger.BytesValueType; -import com.jd.blockchain.ledger.KVDataEntry; -import com.jd.blockchain.ledger.LedgerBlock; -import com.jd.blockchain.ledger.LedgerInfo; -import com.jd.blockchain.ledger.LedgerTransaction; -import com.jd.blockchain.ledger.Operation; -import com.jd.blockchain.ledger.ParticipantNode; -import com.jd.blockchain.ledger.TransactionState; -import com.jd.blockchain.ledger.UserInfo; -import com.jd.blockchain.ledger.UserRegisterOperation; +import com.jd.blockchain.ledger.*; import com.jd.blockchain.ledger.core.impl.OperationHandleContext; import com.jd.blockchain.transaction.BlockchainQueryService; import com.jd.blockchain.transaction.DataAccountKVSetOperationBuilder; @@ -61,6 +46,11 @@ public class ContractLedgerContext implements LedgerContext { return innerQueryService.getConsensusParticipants(ledgerHash); } + @Override + public LedgerMetadata getLedgerMetadata(HashDigest ledgerHash) { + return innerQueryService.getLedgerMetadata(ledgerHash); + } + @Override public LedgerBlock getBlock(HashDigest ledgerHash, long height) { return innerQueryService.getBlock(ledgerHash, height); diff --git a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerAdminAccountTest.java b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerAdminAccountTest.java index af06d0b1..823b3397 100644 --- a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerAdminAccountTest.java +++ b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerAdminAccountTest.java @@ -9,6 +9,7 @@ import static org.junit.Assert.assertTrue; import java.util.Arrays; import java.util.Random; +import com.jd.blockchain.ledger.LedgerMetadata; import org.junit.Test; import com.jd.blockchain.crypto.AddressEncoding; @@ -20,7 +21,6 @@ import com.jd.blockchain.ledger.ParticipantNode; import com.jd.blockchain.ledger.core.CryptoConfig; import com.jd.blockchain.ledger.core.LedgerAdminAccount; import com.jd.blockchain.ledger.core.LedgerConfiguration; -import com.jd.blockchain.ledger.core.LedgerMetadata; import com.jd.blockchain.storage.service.utils.MemoryKVStorage; import com.jd.blockchain.transaction.ConsensusParticipantData; import com.jd.blockchain.transaction.LedgerInitSettingData; diff --git a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerMetaDataTest.java b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerMetaDataTest.java index 19886d4b..f744780d 100644 --- a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerMetaDataTest.java +++ b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerMetaDataTest.java @@ -7,6 +7,8 @@ import static org.junit.Assert.assertTrue; import java.util.Random; +import com.jd.blockchain.ledger.LedgerMetadata; +import com.jd.blockchain.ledger.LedgerSetting; import org.junit.Before; import org.junit.Test; @@ -21,8 +23,6 @@ import com.jd.blockchain.ledger.ParticipantNode; import com.jd.blockchain.ledger.core.CryptoConfig; import com.jd.blockchain.ledger.core.LedgerAdminAccount; import com.jd.blockchain.ledger.core.LedgerConfiguration; -import com.jd.blockchain.ledger.core.LedgerMetadata; -import com.jd.blockchain.ledger.core.LedgerSetting; import com.jd.blockchain.ledger.core.ParticipantCertData; import com.jd.blockchain.utils.Bytes; diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/CryptoProviderInfo.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/CryptoProviderInfo.java new file mode 100644 index 00000000..01527459 --- /dev/null +++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/CryptoProviderInfo.java @@ -0,0 +1,12 @@ +package com.jd.blockchain.ledger; + +import com.jd.blockchain.crypto.CryptoAlgorithm; + +public interface CryptoProviderInfo { + + String getName(); + + CryptoAlgorithm[] getAlgorithms(); + + +} diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/LedgerMetadata.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/LedgerMetadata.java new file mode 100644 index 00000000..4d7a57b0 --- /dev/null +++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/LedgerMetadata.java @@ -0,0 +1,36 @@ +package com.jd.blockchain.ledger; + +import com.jd.blockchain.binaryproto.DataContract; +import com.jd.blockchain.binaryproto.DataField; +import com.jd.blockchain.binaryproto.PrimitiveType; +import com.jd.blockchain.consts.DataCodes; +import com.jd.blockchain.crypto.HashDigest; + +@DataContract(code = DataCodes.METADATA) +public interface LedgerMetadata { + + /** + * 账本的初始化种子; + * + * @return + */ + @DataField(order = 1, primitiveType = PrimitiveType.BYTES) + byte[] getSeed(); + + /** + * 共识参与方的默克尔树的根; + * + * @return + */ + @DataField(order = 2, primitiveType = PrimitiveType.BYTES) + HashDigest getParticipantsHash(); + + /** + * 账本配置; + * + * @return + */ + @DataField(order = 3, refContract = true) + LedgerSetting getSetting(); + +} diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/LedgerSetting.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/LedgerSetting.java new file mode 100644 index 00000000..1a0441bd --- /dev/null +++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/LedgerSetting.java @@ -0,0 +1,24 @@ +package com.jd.blockchain.ledger; + +import com.jd.blockchain.binaryproto.DataContract; +import com.jd.blockchain.binaryproto.DataField; +import com.jd.blockchain.binaryproto.PrimitiveType; +import com.jd.blockchain.consts.DataCodes; +import com.jd.blockchain.ledger.CryptoSetting; +import com.jd.blockchain.utils.Bytes; + +@DataContract(code = DataCodes.METADATA_LEDGER_SETTING) +public interface LedgerSetting { + + @DataField(order=0, primitiveType=PrimitiveType.TEXT) + String getConsensusProvider(); + + @DataField(order=1, primitiveType=PrimitiveType.BYTES) + Bytes getConsensusSetting(); + + @DataField(order=2, refContract=true) + CryptoSetting getCryptoSetting(); + +// PrivilegeModelSetting getPrivilegesModelSetting(); + +} \ No newline at end of file diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/BlockchainQueryService.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/BlockchainQueryService.java index 3b33a720..45301f13 100644 --- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/BlockchainQueryService.java +++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/BlockchainQueryService.java @@ -36,6 +36,14 @@ public interface BlockchainQueryService { */ ParticipantNode[] getConsensusParticipants(HashDigest ledgerHash); + /** + * 返回当前账本的元数据 + * + * @param ledgerHash + * @return + */ + LedgerMetadata getLedgerMetadata(HashDigest ledgerHash); + /** * 返回指定账本序号的区块; * diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/ED25519SignatureTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/ED25519SignatureTest.java index 6d6113c6..11cc02d1 100644 --- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/ED25519SignatureTest.java +++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/ED25519SignatureTest.java @@ -11,7 +11,7 @@ import com.jd.blockchain.utils.security.Ed25519Utils; public class ED25519SignatureTest { - @Test +// @Test public void perfomanceTest() { Random rand = new Random(); byte[] data = new byte[64]; diff --git a/source/ledger/ledger-rpc/src/main/java/com/jd/blockchain/web/serializes/ByteArrayObjectJsonDeserializer.java b/source/ledger/ledger-rpc/src/main/java/com/jd/blockchain/web/serializes/ByteArrayObjectJsonDeserializer.java new file mode 100644 index 00000000..c0384183 --- /dev/null +++ b/source/ledger/ledger-rpc/src/main/java/com/jd/blockchain/web/serializes/ByteArrayObjectJsonDeserializer.java @@ -0,0 +1,101 @@ +package com.jd.blockchain.web.serializes; + +import com.alibaba.fastjson.parser.DefaultJSONParser; +import com.alibaba.fastjson.parser.JSONToken; +import com.alibaba.fastjson.parser.ParserConfig; +import com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer; +import com.jd.blockchain.crypto.HashDigest; +import com.jd.blockchain.crypto.PubKey; +import com.jd.blockchain.crypto.SignatureDigest; +import com.jd.blockchain.utils.Bytes; +import com.jd.blockchain.utils.codec.Base58Utils; +import com.jd.blockchain.utils.io.BytesSlice; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Type; +import java.util.Map; + +public class ByteArrayObjectJsonDeserializer extends JavaBeanDeserializer { + + private ByteArrayObjectJsonDeserializer(Class clazz) { + super(ParserConfig.global, clazz); + } + + public static ByteArrayObjectJsonDeserializer getInstance(Class clazz) { + return new ByteArrayObjectJsonDeserializer(clazz); + } + + @SuppressWarnings("unchecked") + @Override + public T deserialze(DefaultJSONParser parser, Type type, Object fieldName) { + if (type instanceof Class && clazz.isAssignableFrom((Class) type)) { + String parseText = parser.parseObject(String.class); + byte[] hashBytes = Base58Utils.decode(parseText); + if (clazz == HashDigest.class) { + return (T) new HashDigest(hashBytes); + } else if (clazz == PubKey.class) { + return (T) new HashDigest(hashBytes); + } else if (clazz == SignatureDigest.class) { + return (T) new SignatureDigest(hashBytes); + } else if (clazz == Bytes.class) { + return (T) new Bytes(hashBytes); + } else if (clazz == BytesSlice.class) { + return (T) new BytesSlice(hashBytes); + } + +// else if (clazz == BytesValue.class) { +// ByteArrayObjectJsonSerializer.BytesValueJson valueJson = JSON.parseObject(parseText, ByteArrayObjectJsonSerializer.BytesValueJson.class); +// DataType dataType = valueJson.getType(); +// Object dataVal = valueJson.getValue(); +// byte[] bytes = null; +// switch (dataType) { +// case BYTES: +// bytes = ByteArray.fromHex((String) dataVal); +// break; +// case TEXT: +// bytes = ((String) dataVal).getBytes(); +// break; +// case INT64: +// bytes = BytesUtils.toBytes((Long) dataVal); +// break; +// case JSON: +// bytes = ((String) dataVal).getBytes(); +// break; +// } +// BytesValue bytesValue = new BytesValueImpl(dataType, bytes); +// return (T) bytesValue; +// } + } + return (T) parser.parse(fieldName); + } + + @Override + public Object createInstance(Map map, ParserConfig config) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { + if (map == null || map.isEmpty()) { + return null; + } + for (Map.Entry entry : map.entrySet()) { + Object value = entry.getValue(); + if (value instanceof String) { + byte[] hashBytes = Base58Utils.decode((String) value); + if (clazz == HashDigest.class) { + return new HashDigest(hashBytes); + } else if (clazz == PubKey.class) { + return new PubKey(hashBytes); + } else if (clazz == SignatureDigest.class) { + return new SignatureDigest(hashBytes); + } else if (clazz == Bytes.class) { + return new Bytes(hashBytes); + } else if (clazz == BytesSlice.class) { + return new BytesSlice(hashBytes); + } + } + } + return null; + } + + @Override + public int getFastMatchToken() { + return JSONToken.LBRACE; + } +} diff --git a/source/ledger/ledger-rpc/src/main/java/com/jd/blockchain/web/serializes/ByteArrayObjectJsonSerializer.java b/source/ledger/ledger-rpc/src/main/java/com/jd/blockchain/web/serializes/ByteArrayObjectJsonSerializer.java new file mode 100644 index 00000000..896e1f4a --- /dev/null +++ b/source/ledger/ledger-rpc/src/main/java/com/jd/blockchain/web/serializes/ByteArrayObjectJsonSerializer.java @@ -0,0 +1,120 @@ +package com.jd.blockchain.web.serializes; + +import com.alibaba.fastjson.serializer.JSONSerializer; +import com.alibaba.fastjson.serializer.ObjectSerializer; +import com.jd.blockchain.binaryproto.DataType; +import com.jd.blockchain.crypto.HashDigest; +import com.jd.blockchain.crypto.PubKey; +import com.jd.blockchain.crypto.SignatureDigest; +import com.jd.blockchain.utils.Bytes; +import com.jd.blockchain.utils.codec.Base58Utils; +import com.jd.blockchain.utils.io.BytesSlice; + +import java.lang.reflect.Type; + +public class ByteArrayObjectJsonSerializer implements ObjectSerializer { + + private Class clazz; + + private ByteArrayObjectJsonSerializer(Class clazz) { + this.clazz = clazz; + } + + public static ByteArrayObjectJsonSerializer getInstance(Class clazz) { + return new ByteArrayObjectJsonSerializer(clazz); + } + + @Override + public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) { + if (object.getClass() != clazz) { + serializer.writeNull(); + return; + } + if (object instanceof HashDigest) { + serializer.write(new HashDigestJson(((HashDigest) object).toBase58())); + } else if (object instanceof PubKey) { + serializer.write(new HashDigestJson(((PubKey) object).toBase58())); + } else if (object instanceof SignatureDigest) { + serializer.write(new HashDigestJson(((SignatureDigest) object).toBase58())); + } else if (object instanceof Bytes) { + serializer.write(new HashDigestJson(((Bytes) object).toBase58())); + } else if (object instanceof BytesSlice) { + serializer.write(Base58Utils.encode(((BytesSlice) object).toBytes())); + } + +// else if (object instanceof BytesValue) { +// DataType dataType = ((BytesValue) object).getType(); +// BytesSlice bytesValue = ((BytesValue) object).getValue(); +// Object realVal; +// switch (dataType) { +// case NIL: +// realVal = null; +// break; +// case TEXT: +// realVal = bytesValue.getString(); +// break; +// case BYTES: +// realVal = ByteArray.toHex(bytesValue.toBytes()); +// break; +// case INT32: +// realVal = bytesValue.getInt(); +// break; +// case INT64: +// realVal = bytesValue.getLong(); +// break; +// case JSON: +// realVal = bytesValue.getString(); +// break; +// default: +// realVal = ByteArray.toHex(bytesValue.toBytes()); +// break; +// } +// serializer.write(new BytesValueJson(dataType, realVal)); +// } + } + + private static class HashDigestJson { + + String value; + + public HashDigestJson(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + public static class BytesValueJson { + + public BytesValueJson(DataType type, Object value) { + this.type = type; + this.value = value; + } + + DataType type; + + Object value; + + public DataType getType() { + return type; + } + + public void setType(DataType type) { + this.type = type; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + } +} diff --git a/source/ledger/ledger-rpc/src/main/java/com/jd/blockchain/web/serializes/ByteArrayObjectUtil.java b/source/ledger/ledger-rpc/src/main/java/com/jd/blockchain/web/serializes/ByteArrayObjectUtil.java new file mode 100644 index 00000000..e6d23910 --- /dev/null +++ b/source/ledger/ledger-rpc/src/main/java/com/jd/blockchain/web/serializes/ByteArrayObjectUtil.java @@ -0,0 +1,41 @@ +/** + * Copyright: Copyright 2016-2020 JD.COM All Right Reserved + * FileName: com.jd.blockchain.web.serializes.ByteArrayObjectUtil + * Author: shaozhuguang + * Department: Y事业部 + * Date: 2019/3/27 上午11:23 + * Description: + */ +package com.jd.blockchain.web.serializes; + +import com.jd.blockchain.crypto.HashDigest; +import com.jd.blockchain.crypto.PubKey; +import com.jd.blockchain.crypto.SignatureDigest; +import com.jd.blockchain.utils.Bytes; +import com.jd.blockchain.utils.io.BytesSlice; +import com.jd.blockchain.utils.serialize.json.JSONSerializeUtils; + +/** + * + * @author shaozhuguang + * @create 2019/3/27 + * @since 1.0.0 + */ + +public class ByteArrayObjectUtil { + + public static final Class[] BYTEARRAY_JSON_SERIALIZE_CLASS = new Class[] { + HashDigest.class, + PubKey.class, + SignatureDigest.class, + Bytes.class, + BytesSlice.class}; + + public static void init() { + for (Class byteArrayClass : BYTEARRAY_JSON_SERIALIZE_CLASS) { + JSONSerializeUtils.configSerialization(byteArrayClass, + ByteArrayObjectJsonSerializer.getInstance(byteArrayClass), + ByteArrayObjectJsonDeserializer.getInstance(byteArrayClass)); + } + } +} \ No newline at end of file diff --git a/source/peer/src/main/java/com/jd/blockchain/peer/web/LedgerQueryController.java b/source/peer/src/main/java/com/jd/blockchain/peer/web/LedgerQueryController.java index e221ba98..6db9674c 100644 --- a/source/peer/src/main/java/com/jd/blockchain/peer/web/LedgerQueryController.java +++ b/source/peer/src/main/java/com/jd/blockchain/peer/web/LedgerQueryController.java @@ -1,5 +1,7 @@ package com.jd.blockchain.peer.web; +import com.jd.blockchain.ledger.*; +import com.jd.blockchain.ledger.core.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -10,25 +12,6 @@ import org.springframework.web.bind.annotation.RestController; import com.jd.blockchain.binaryproto.BinaryProtocol; import com.jd.blockchain.binaryproto.PrimitiveType; import com.jd.blockchain.crypto.HashDigest; -import com.jd.blockchain.ledger.AccountHeader; -import com.jd.blockchain.ledger.BytesValue; -import com.jd.blockchain.ledger.KVDataEntry; -import com.jd.blockchain.ledger.KVDataObject; -import com.jd.blockchain.ledger.LedgerBlock; -import com.jd.blockchain.ledger.LedgerInfo; -import com.jd.blockchain.ledger.LedgerTransaction; -import com.jd.blockchain.ledger.ParticipantNode; -import com.jd.blockchain.ledger.TransactionState; -import com.jd.blockchain.ledger.UserInfo; -import com.jd.blockchain.ledger.core.ContractAccountSet; -import com.jd.blockchain.ledger.core.DataAccount; -import com.jd.blockchain.ledger.core.DataAccountSet; -import com.jd.blockchain.ledger.core.LedgerAdministration; -import com.jd.blockchain.ledger.core.LedgerRepository; -import com.jd.blockchain.ledger.core.LedgerService; -import com.jd.blockchain.ledger.core.ParticipantCertData; -import com.jd.blockchain.ledger.core.TransactionSet; -import com.jd.blockchain.ledger.core.UserAccountSet; import com.jd.blockchain.transaction.BlockchainQueryService; import com.jd.blockchain.utils.Bytes; import com.jd.blockchain.utils.QueryUtil; @@ -79,6 +62,15 @@ public class LedgerQueryController implements BlockchainQueryService { return null; } + @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/metadata") + @Override + public LedgerMetadata getLedgerMetadata(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) { + LedgerRepository ledger = ledgerService.getLedger(ledgerHash); + LedgerAdministration ledgerAdministration = ledger.getAdminInfo(); + LedgerMetadata ledgerMetadata = ledgerAdministration.getMetadata(); + return ledgerMetadata; + } + @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/height/{blockHeight}") @Override public LedgerBlock getBlock(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, diff --git a/source/peer/src/main/java/com/jd/blockchain/peer/web/PeerWebServerConfigurer.java b/source/peer/src/main/java/com/jd/blockchain/peer/web/PeerWebServerConfigurer.java index bc286117..f0d52ac5 100644 --- a/source/peer/src/main/java/com/jd/blockchain/peer/web/PeerWebServerConfigurer.java +++ b/source/peer/src/main/java/com/jd/blockchain/peer/web/PeerWebServerConfigurer.java @@ -2,22 +2,16 @@ package com.jd.blockchain.peer.web; import java.util.List; -import com.jd.blockchain.utils.io.BytesSlice; import com.jd.blockchain.web.converters.BinaryMessageConverter; import com.jd.blockchain.web.converters.HashDigestInputConverter; +import com.jd.blockchain.web.serializes.ByteArrayObjectUtil; import org.springframework.context.annotation.Configuration; import org.springframework.format.FormatterRegistry; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import com.jd.blockchain.crypto.HashDigest; -import com.jd.blockchain.crypto.PubKey; -import com.jd.blockchain.crypto.SignatureDigest; -import com.jd.blockchain.crypto.serialize.ByteArrayObjectDeserializer; -import com.jd.blockchain.crypto.serialize.ByteArrayObjectSerializer; -import com.jd.blockchain.utils.Bytes; import com.jd.blockchain.utils.io.ByteArray; import com.jd.blockchain.utils.serialize.json.JSONSerializeUtils; import com.jd.blockchain.utils.web.model.JsonWebResponseMessageConverter; @@ -25,13 +19,6 @@ import com.jd.blockchain.utils.web.model.JsonWebResponseMessageConverter; @Configuration public class PeerWebServerConfigurer implements WebMvcConfigurer { - private static final Class[] BYTEARRAY_JSON_SERIALIZE_CLASS = new Class[] { - HashDigest.class, - PubKey.class, - SignatureDigest.class, - Bytes.class, - BytesSlice.class}; - static { JSONSerializeUtils.disableCircularReferenceDetect(); JSONSerializeUtils.configStringSerializer(ByteArray.class); @@ -59,10 +46,6 @@ public class PeerWebServerConfigurer implements WebMvcConfigurer { } private void initByteArrayJsonSerialize() { - for (Class byteArrayClass : BYTEARRAY_JSON_SERIALIZE_CLASS) { - JSONSerializeUtils.configSerialization(byteArrayClass, - ByteArrayObjectSerializer.getInstance(byteArrayClass), - ByteArrayObjectDeserializer.getInstance(byteArrayClass)); - } + ByteArrayObjectUtil.init(); } } diff --git a/source/pom.xml b/source/pom.xml index 35de30f4..f8c9dfce 100644 --- a/source/pom.xml +++ b/source/pom.xml @@ -32,12 +32,10 @@ storage gateway peer - state-transfer sdk tools test deployment - stp @@ -281,12 +279,6 @@ bcprov-jdk15on 1.61 - - - org.bouncycastle - bcpkix-jdk15on - 1.61 - io.nats @@ -306,6 +298,19 @@ 4.1 + + + org.reflections + reflections + 0.9.10 + + + com.google.guava + guava + + + + com.google.guava guava diff --git a/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/LedgerInitSettings.java b/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/LedgerInitSettings.java new file mode 100644 index 00000000..fa3c2cd0 --- /dev/null +++ b/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/LedgerInitSettings.java @@ -0,0 +1,113 @@ +package com.jd.blockchain.sdk; + + +import com.jd.blockchain.consensus.ConsensusSettings; +import com.jd.blockchain.crypto.HashDigest; +import com.jd.blockchain.ledger.CryptoSetting; +import com.jd.blockchain.ledger.ParticipantNode; + +/** + * 账本初始化配置 + * + * @author shaozhuguang + * @date 2019-04-23 + * @since 1.0.0 + * + */ +public class LedgerInitSettings { + + /** + * 账本初始化种子 + */ + private String seed; + + /** + * 共识参与方的默克尔树的根; + */ + private HashDigest participantsHash; + + /** + * 算法配置 + */ + private CryptoSetting cryptoSetting; + + /** + * 共识协议 + */ + private int consensusProtocol; + + /** + * 共识配置 + */ + private ConsensusSettings consensusSettings; + + /** + * 共识参与方 + */ + private ParticipantNode[] participantNodes; + + public void setSeed(String seed) { + this.seed = seed; + } + + public String getSeed() { + return seed; + } + + public HashDigest getParticipantsHash() { + return participantsHash; + } + + public void setParticipantsHash(HashDigest participantsHash) { + this.participantsHash = participantsHash; + } + + public CryptoSetting getCryptoSetting() { + return cryptoSetting; + } + + public void setCryptoSetting(CryptoSetting cryptoSetting) { + this.cryptoSetting = cryptoSetting; + } + + public int getConsensusProtocol() { + return consensusProtocol; + } + + public void setConsensusProtocol(int consensusProtocol) { + this.consensusProtocol = consensusProtocol; + } + + public ConsensusSettings getConsensusSettings() { + return consensusSettings; + } + + public void setConsensusSettings(ConsensusSettings consensusSettings) { + this.consensusSettings = consensusSettings; + } + + public ParticipantNode[] getParticipantNodes() { + return participantNodes; + } + + public void setParticipantNodes(ParticipantNode[] participantNodes) { + this.participantNodes = participantNodes; + } + + public enum CONSENSUS_PROTOCOL { + UNKNOWN(0), + BFTSMART(1), + MSGQUEUE(2), + ; + + private int code; + + CONSENSUS_PROTOCOL(int code) { + this.code = code; + } + + public int code() { + return code; + } + } +} diff --git a/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/proxy/BlockchainServiceProxy.java b/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/proxy/BlockchainServiceProxy.java index da602b9b..4dbe7bc9 100644 --- a/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/proxy/BlockchainServiceProxy.java +++ b/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/proxy/BlockchainServiceProxy.java @@ -37,7 +37,12 @@ public abstract class BlockchainServiceProxy implements BlockchainService { return getQueryService(ledgerHash).getConsensusParticipants(ledgerHash); } - @Override + @Override + public LedgerMetadata getLedgerMetadata(HashDigest ledgerHash) { + return getQueryService(ledgerHash).getLedgerMetadata(ledgerHash); + } + + @Override public LedgerBlock getBlock(HashDigest ledgerHash, long height) { return getQueryService(ledgerHash).getBlock(ledgerHash, height); } diff --git a/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/proxy/HttpBlockchainQueryService.java b/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/proxy/HttpBlockchainQueryService.java index 19df6c9a..bfdc0baf 100644 --- a/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/proxy/HttpBlockchainQueryService.java +++ b/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/proxy/HttpBlockchainQueryService.java @@ -204,6 +204,17 @@ public interface HttpBlockchainQueryService extends BlockchainExtendQueryService @Override ParticipantNode[] getConsensusParticipants(@PathParam(name="ledgerHash", converter=HashDigestToStringConverter.class) HashDigest ledgerHash); + + /** + * 返回指定账本的元数据 + * + * @param ledgerHash + * @return + */ + @HttpAction(method=HttpMethod.GET, path="ledgers/{ledgerHash}/metadata") + @Override + LedgerMetadata getLedgerMetadata(@PathParam(name="ledgerHash", converter=HashDigestToStringConverter.class) HashDigest ledgerHash); + /** * 返回指定账本序号的区块; * diff --git a/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/service/NodeSigningAppender.java b/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/service/NodeSigningAppender.java index 52f289a8..17611678 100644 --- a/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/service/NodeSigningAppender.java +++ b/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/service/NodeSigningAppender.java @@ -72,7 +72,7 @@ public class NodeSigningAppender implements TransactionService { // 计算交易哈希; byte[] nodeRequestBytes = BinaryProtocol.encode(txMessage, TransactionRequest.class); - HashFunction hashFunc = Crypto.getHashFunction(signAlgorithm); + HashFunction hashFunc = Crypto.getHashFunction(this.hashAlgorithm); HashDigest txHash = hashFunc.hash(nodeRequestBytes); txMessage.setHash(txHash); diff --git a/source/sdk/sdk-client/pom.xml b/source/sdk/sdk-client/pom.xml index a33f309d..17ccdf88 100644 --- a/source/sdk/sdk-client/pom.xml +++ b/source/sdk/sdk-client/pom.xml @@ -14,5 +14,11 @@ sdk-base ${project.version} + + + com.jd.blockchain + ledger-rpc + ${project.version} + \ No newline at end of file diff --git a/source/sdk/sdk-client/src/main/java/com/jd/blockchain/sdk/client/GatewayServiceFactory.java b/source/sdk/sdk-client/src/main/java/com/jd/blockchain/sdk/client/GatewayServiceFactory.java index 49348b90..5396a430 100644 --- a/source/sdk/sdk-client/src/main/java/com/jd/blockchain/sdk/client/GatewayServiceFactory.java +++ b/source/sdk/sdk-client/src/main/java/com/jd/blockchain/sdk/client/GatewayServiceFactory.java @@ -3,15 +3,16 @@ package com.jd.blockchain.sdk.client; import java.io.Closeable; import com.jd.blockchain.binaryproto.BinaryProtocol; +import com.jd.blockchain.binaryproto.DataContractRegistry; +import com.jd.blockchain.consensus.ClientIdentification; +import com.jd.blockchain.consensus.ClientIdentifications; +import com.jd.blockchain.consensus.action.ActionRequest; +import com.jd.blockchain.consensus.action.ActionResponse; import com.jd.blockchain.crypto.Crypto; import com.jd.blockchain.crypto.PrivKey; import com.jd.blockchain.crypto.SignatureDigest; import com.jd.blockchain.crypto.SignatureFunction; -import com.jd.blockchain.ledger.BlockchainKeypair; -import com.jd.blockchain.ledger.DigitalSignature; -import com.jd.blockchain.ledger.TransactionContent; -import com.jd.blockchain.ledger.TransactionRequest; -import com.jd.blockchain.ledger.TransactionResponse; +import com.jd.blockchain.ledger.*; import com.jd.blockchain.sdk.BlockchainService; import com.jd.blockchain.sdk.BlockchainServiceFactory; import com.jd.blockchain.sdk.proxy.HttpBlockchainQueryService; @@ -24,6 +25,7 @@ import com.jd.blockchain.utils.http.agent.ServiceConnection; import com.jd.blockchain.utils.http.agent.ServiceConnectionManager; import com.jd.blockchain.utils.http.agent.ServiceEndpoint; import com.jd.blockchain.utils.net.NetworkAddress; +import com.jd.blockchain.web.serializes.ByteArrayObjectUtil; public class GatewayServiceFactory implements BlockchainServiceFactory, Closeable { @@ -33,6 +35,31 @@ public class GatewayServiceFactory implements BlockchainServiceFactory, Closeabl private BlockchainService blockchainService; + static { + DataContractRegistry.register(TransactionContent.class); + DataContractRegistry.register(TransactionContentBody.class); + DataContractRegistry.register(TransactionRequest.class); + DataContractRegistry.register(NodeRequest.class); + DataContractRegistry.register(EndpointRequest.class); + DataContractRegistry.register(TransactionResponse.class); + DataContractRegistry.register(DataAccountKVSetOperation.class); + DataContractRegistry.register(DataAccountKVSetOperation.KVWriteEntry.class); + + DataContractRegistry.register(Operation.class); + DataContractRegistry.register(ContractCodeDeployOperation.class); + DataContractRegistry.register(ContractEventSendOperation.class); + DataContractRegistry.register(DataAccountRegisterOperation.class); + DataContractRegistry.register(UserRegisterOperation.class); + + DataContractRegistry.register(ActionRequest.class); + DataContractRegistry.register(ActionResponse.class); + DataContractRegistry.register(ClientIdentifications.class); + DataContractRegistry.register(ClientIdentification.class); + + ByteArrayObjectUtil.init(); + } + + protected GatewayServiceFactory(ServiceEndpoint gatewayEndpoint, BlockchainKeypair userKey) { httpConnectionManager = new ServiceConnectionManager(); this.userKey = userKey; diff --git a/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_Query_Test_.java b/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_Query_Test_.java index a5343eb6..3851d6a7 100644 --- a/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_Query_Test_.java +++ b/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_Query_Test_.java @@ -19,8 +19,6 @@ import com.jd.blockchain.crypto.HashFunction; import com.jd.blockchain.crypto.PubKey; import com.jd.blockchain.crypto.SignatureDigest; import com.jd.blockchain.crypto.SignatureFunction; -import com.jd.blockchain.crypto.serialize.ByteArrayObjectDeserializer; -import com.jd.blockchain.crypto.serialize.ByteArrayObjectSerializer; import com.jd.blockchain.ledger.AccountHeader; import com.jd.blockchain.ledger.BlockchainKeyGenerator; import com.jd.blockchain.ledger.BlockchainKeypair; @@ -53,17 +51,6 @@ import com.jd.blockchain.utils.serialize.json.JSONSerializeUtils; public class SDK_GateWay_Query_Test_ { - private static Class[] byteArrayClasss = new Class[] { HashDigest.class, PubKey.class, - SignatureDigest.class }; - - static { - for (Class byteArrayClass : byteArrayClasss) { - JSONSerializeUtils.configSerialization(byteArrayClass, - ByteArrayObjectSerializer.getInstance(byteArrayClass), - ByteArrayObjectDeserializer.getInstance(byteArrayClass)); - } - } - private BlockchainKeypair CLIENT_CERT = null; private String GATEWAY_IPADDR = null; diff --git a/source/storage/storage-composite/pom.xml b/source/storage/storage-composite/pom.xml index a080704a..ca8012d2 100644 --- a/source/storage/storage-composite/pom.xml +++ b/source/storage/storage-composite/pom.xml @@ -14,7 +14,7 @@ storage-service ${project.version} - + + + org.reflections + reflections + + + + com.google.guava + guava + + + + org.springframework.boot + spring-boot + + + org.springframework.boot + spring-boot-autoconfigure + + + org.springframework.boot + spring-boot-configuration-processor + true + +