use of org.bitcoinj.crypto.DeterministicKey in project bisq-core by bisq-network.
the class BuyerAsMakerSignPayoutTx method run.
@Override
protected void run() {
try {
runInterceptHook();
Preconditions.checkNotNull(trade.getTradeAmount(), "trade.getTradeAmount() must not be null");
Preconditions.checkNotNull(trade.getDepositTx(), "trade.getDepositTx() must not be null");
BtcWalletService walletService = processModel.getBtcWalletService();
String id = processModel.getOffer().getId();
Coin buyerPayoutAmount = trade.getOffer().getBuyerSecurityDeposit().add(trade.getTradeAmount());
Coin sellerPayoutAmount = trade.getOffer().getSellerSecurityDeposit();
String buyerPayoutAddressString = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT).getAddressString();
final String sellerPayoutAddressString = processModel.getTradingPeer().getPayoutAddressString();
DeterministicKey buyerMultiSigKeyPair = walletService.getMultiSigKeyPair(id, processModel.getMyMultiSigPubKey());
byte[] buyerMultiSigPubKey = processModel.getMyMultiSigPubKey();
checkArgument(Arrays.equals(buyerMultiSigPubKey, walletService.getOrCreateAddressEntry(id, AddressEntry.Context.MULTI_SIG).getPubKey()), "buyerMultiSigPubKey from AddressEntry must match the one from the trade data. trade id =" + id);
final byte[] sellerMultiSigPubKey = processModel.getTradingPeer().getMultiSigPubKey();
byte[] payoutTxSignature = processModel.getTradeWalletService().buyerSignsPayoutTx(trade.getDepositTx(), buyerPayoutAmount, sellerPayoutAmount, buyerPayoutAddressString, sellerPayoutAddressString, buyerMultiSigKeyPair, buyerMultiSigPubKey, sellerMultiSigPubKey, trade.getArbitratorBtcPubKey());
processModel.setPayoutTxSignature(payoutTxSignature);
complete();
} catch (Throwable t) {
failed(t);
}
}
use of org.bitcoinj.crypto.DeterministicKey in project account-identity by cryptofiat.
the class HDKey method deriveAddressFromKey.
public static HdAddress deriveAddressFromKey(String pubkey, int index) {
while (index < 1 << 30) {
try {
DeterministicKey master = DeterministicKey.deserializeB58(null, pubkey, MainNetParams.get());
DeterministicKey child = HDKeyDerivation.deriveChildKey(master, index);
ECKey childkey = ECKey.fromPublicOnly(child.getPubKey());
HdAddress address = new HdAddress(index, "0x".concat(org.spongycastle.util.encoders.Hex.toHexString(childkey.getAddress())));
return address;
} catch (HDDerivationException e) {
index++;
}
}
throw new RuntimeException("Couldn't generate HD Key after max tries");
}
use of org.bitcoinj.crypto.DeterministicKey in project bitrafael_public by GENERALBYTESCOM.
the class MasterPrivateKeyBCH method serializePUB.
public static String serializePUB(DeterministicKey masterKey, int standard, int accountIndex, String cryptoCurrency) {
final DeterministicKey purposeKey = HDKeyDerivation.deriveChildKey(masterKey, new ChildNumber(standard, true));
final DeterministicKey coinKey = HDKeyDerivation.deriveChildKey(purposeKey, new ChildNumber(WalletTools.getCoinTypeByCryptoCurrency(cryptoCurrency), true));
final DeterministicKey accountKey = HDKeyDerivation.deriveChildKey(coinKey, new ChildNumber(accountIndex, true));
int header = 0x0488b21e;
switch(standard) {
case IWalletTools.STANDARD_BIP44:
// xpub
header = XPUB;
break;
}
ByteBuffer ser = ByteBuffer.allocate(78);
ser.putInt(header);
ser.put((byte) accountKey.getDepth());
ser.putInt(accountKey.getParentFingerprint());
ser.putInt(accountKey.getChildNumber().i());
ser.put(accountKey.getChainCode());
ser.put(accountKey.getPubKey());
checkState(ser.position() == 78);
return Base58.encode(addChecksum(ser.array()));
}
use of org.bitcoinj.crypto.DeterministicKey in project bitrafael_public by GENERALBYTESCOM.
the class MasterPrivateKeyETH method serializePUB.
public static String serializePUB(DeterministicKey masterKey, int standard, int accountIndex, String cryptoCurrency) {
final DeterministicKey purposeKey = HDKeyDerivation.deriveChildKey(masterKey, new ChildNumber(standard, true));
final DeterministicKey coinKey = HDKeyDerivation.deriveChildKey(purposeKey, new ChildNumber(WalletTools.getCoinTypeByCryptoCurrency(cryptoCurrency), true));
final DeterministicKey accountKey = HDKeyDerivation.deriveChildKey(coinKey, new ChildNumber(accountIndex, true));
int header = 0x0488b21e;
switch(standard) {
case IWalletTools.STANDARD_BIP44:
// xpub
header = XPUB;
break;
}
ByteBuffer ser = ByteBuffer.allocate(78);
ser.putInt(header);
ser.put((byte) accountKey.getDepth());
ser.putInt(accountKey.getParentFingerprint());
ser.putInt(accountKey.getChildNumber().i());
ser.put(accountKey.getChainCode());
ser.put(accountKey.getPubKey());
checkState(ser.position() == 78);
return Base58.encode(addChecksum(ser.array()));
}
Aggregations