From 430955b98e8503da3bfcb20a18d3e77770ac266b Mon Sep 17 00:00:00 2001 From: pie <429224280@qq.com> Date: Tue, 2 Jun 2020 18:44:21 +0800 Subject: [PATCH] dsa --- .../transaction/BitcoinTransaction.java | 42 +++++++------------ 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/consenlabs/tokencore/wallet/transaction/BitcoinTransaction.java b/src/main/java/org/consenlabs/tokencore/wallet/transaction/BitcoinTransaction.java index 5f2f670..d26879a 100755 --- a/src/main/java/org/consenlabs/tokencore/wallet/transaction/BitcoinTransaction.java +++ b/src/main/java/org/consenlabs/tokencore/wallet/transaction/BitcoinTransaction.java @@ -349,9 +349,9 @@ public TxSignResult signUsdtCollectTransaction(String chainID, String password, int startIdx = outputs.size(); outputs.addAll(feeProviderUtxos); collectPrvKeysAndAddress(Metadata.NONE, password, wallet); - List feeProviderPrvKeys = getPrvKeysByAddress(Metadata.NONE, password, feeProviderWallet); + BigInteger feeProviderPrvKey = getPrvKeysByAddress(Metadata.NONE, password, feeProviderWallet,0,0); for (int i = startIdx; i < outputs.size(); i++) { - prvKeys.set(i, feeProviderPrvKeys.get(0)); + prvKeys.set(i, feeProviderPrvKey); } Transaction tran = new Transaction(network); long totalAmount = 0L; @@ -602,14 +602,12 @@ public TxSignResult signSegWitTransaction(String chainId, String password, Walle public TxSignResult signMultiTransaction(String chainID, String password, List wallets) { - wallets.forEach(wallet -> { - collectPrvKeysAndAddress(Metadata.NONE, password, wallet); - }); HashMap ecKeyMap = new HashMap<>(); - prvKeys.forEach(prvKey -> { - ECKey ecKey=ECKey.fromPrivate(prvKey); + wallets.forEach(wallet -> { + BigInteger prvKey=getPrvKeysByAddress(Metadata.NONE, password, wallet,0,0); + ECKey ecKey = ECKey.fromPrivate(prvKey); String address = ecKey.toAddress(network).toBase58(); - ecKeyMap.put(address,ecKey); + ecKeyMap.put(address, ecKey); }); Transaction tran = new Transaction(network); long totalAmount = 0L; @@ -636,8 +634,8 @@ public TxSignResult signMultiTransaction(String chainID, String password, List getPrvKeysByAddress(String segWit, String password, Wallet wallet) { - List prvKeys; + private BigInteger getPrvKeysByAddress(String segWit, String password, Wallet wallet, int accountIdx, int changeIdx) { + BigInteger prvKey; this.network = MetaUtil.getNetWork(wallet.getMetadata()); if (wallet.getMetadata().getSource().equals(Metadata.FROM_WIF)) { changeAddress = Address.fromBase58(network, wallet.getAddress()); - BigInteger prvKey = DumpedPrivateKey.fromBase58(network, wallet.exportPrivateKey(password)).getKey().getPrivKey(); - prvKeys = Collections.singletonList(prvKey); + prvKey = DumpedPrivateKey.fromBase58(network, wallet.exportPrivateKey(password)).getKey().getPrivKey(); } else { - prvKeys = new ArrayList<>(getOutputs().size()); String xprv = new String(wallet.decryptMainKey(password), Charset.forName("UTF-8")); DeterministicKey xprvKey = DeterministicKey.deserializeB58(xprv, network); - - for (UTXO output : getOutputs()) { - String derivedPath = output.getDerivedPath().trim(); - String[] pathIdxs = derivedPath.replace('/', ' ').split(" "); - int accountIdx = Integer.parseInt(pathIdxs[0]); - int changeIdx = Integer.parseInt(pathIdxs[1]); - - DeterministicKey accountKey = HDKeyDerivation.deriveChildKey(xprvKey, new ChildNumber(accountIdx, false)); - DeterministicKey externalChangeKey = HDKeyDerivation.deriveChildKey(accountKey, new ChildNumber(changeIdx, false)); - prvKeys.add(externalChangeKey.getPrivKey()); - } + DeterministicKey accountKey = HDKeyDerivation.deriveChildKey(xprvKey, new ChildNumber(accountIdx, false)); + DeterministicKey externalChangeKey = HDKeyDerivation.deriveChildKey(accountKey, new ChildNumber(changeIdx, false)); + prvKey=externalChangeKey.getPrivKey(); } - return prvKeys; + return prvKey; }