use of com.jd.blockchain.ledger.core.LedgerInitProposalData in project jdchain-core by blockchain-jd-com.
the class LedgerInitializeWebController method prepareLocalPermission.
public LedgerInitProposal prepareLocalPermission(int currentId, PrivKey privKey, LedgerInitConfiguration ledgerInitConfig) {
// 创建初始化配置;
ParticipantProperties[] participants = ledgerInitConfig.getParticipants();
if (currentId < 0 || currentId >= participants.length) {
throw new LedgerInitException("Your id is out of bound of participant list!");
}
this.currentId = currentId;
// 校验当前的公钥、私钥是否匹配;
byte[] testBytes = BytesUtils.toBytes(currentId);
SignatureFunction signatureFunction = Crypto.getSignatureFunction(privKey.getAlgorithm());
SignatureDigest testSign = signatureFunction.sign(privKey, testBytes);
PubKey myPubKey = participants[currentId].getPubKey();
if (!signatureFunction.verify(testSign, myPubKey, testBytes)) {
throw new LedgerInitException("Your pub-key specified in the init-settings isn't match your priv-key!");
}
this.initializerAddresses = new NetworkAddress[participants.length];
// 记录每个参与方的账本初始化服务地址;
for (int i = 0; i < participants.length; i++) {
initializerAddresses[i] = participants[i].getInitializerAddress();
}
// 初始化账本;
this.initializer = LedgerInitializer.create(ledgerInitConfig.getLedgerSettings(), ledgerInitConfig.getSecuritySettings());
// 对初始交易签名,生成当前参与者的账本初始化许可;
SignatureDigest permissionSign = initializer.signTransaction(privKey);
LedgerInitProposalData permission = new LedgerInitProposalData(currentId, permissionSign);
this.currentId = currentId;
this.permissions = new LedgerInitProposal[participants.length];
this.permissions[currentId] = permission;
this.localPermission = permission;
return permission;
}
Aggregations