Search in sources :

Example 1 with KeyRing

use of bisq.common.crypto.KeyRing in project bisq-core by bisq-network.

the class EncryptionTest method setup.

@Before
public void setup() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, CryptoException {
    Security.addProvider(new BouncyCastleProvider());
    dir = File.createTempFile("temp_tests", "");
    // noinspection ResultOfMethodCallIgnored
    dir.delete();
    // noinspection ResultOfMethodCallIgnored
    dir.mkdir();
    KeyStorage keyStorage = new KeyStorage(dir);
    keyRing = new KeyRing(keyStorage);
}
Also used : KeyRing(bisq.common.crypto.KeyRing) KeyStorage(bisq.common.crypto.KeyStorage) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Before(org.junit.Before)

Example 2 with KeyRing

use of bisq.common.crypto.KeyRing in project bisq-core by bisq-network.

the class SigTest method setup.

@Before
public void setup() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, CryptoException {
    Security.addProvider(new BouncyCastleProvider());
    dir = File.createTempFile("temp_tests", "");
    // noinspection ResultOfMethodCallIgnored
    dir.delete();
    // noinspection ResultOfMethodCallIgnored
    dir.mkdir();
    KeyStorage keyStorage = new KeyStorage(dir);
    keyRing = new KeyRing(keyStorage);
}
Also used : KeyRing(bisq.common.crypto.KeyRing) KeyStorage(bisq.common.crypto.KeyStorage) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Before(org.junit.Before)

Example 3 with KeyRing

use of bisq.common.crypto.KeyRing in project bisq-desktop by bisq-network.

the class TradesChartsViewModelTest method setup.

@Before
public void setup() throws IOException {
    Security.addProvider(new BouncyCastleProvider());
    dir = File.createTempFile("temp_tests1", "");
    // noinspection ResultOfMethodCallIgnored
    dir.delete();
    // noinspection ResultOfMethodCallIgnored
    dir.mkdir();
    keyRing = new KeyRing(new KeyStorage(dir));
}
Also used : KeyRing(bisq.common.crypto.KeyRing) KeyStorage(bisq.common.crypto.KeyStorage) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Before(org.junit.Before)

Example 4 with KeyRing

use of bisq.common.crypto.KeyRing in project bisq-desktop by bisq-network.

the class OfferDetailsWindow method addContent.

private void addContent() {
    int rows = 5;
    List<String> acceptedBanks = offer.getAcceptedBankIds();
    boolean showAcceptedBanks = acceptedBanks != null && !acceptedBanks.isEmpty();
    List<String> acceptedCountryCodes = offer.getAcceptedCountryCodes();
    boolean showAcceptedCountryCodes = acceptedCountryCodes != null && !acceptedCountryCodes.isEmpty();
    if (!takeOfferHandlerOptional.isPresent())
        rows++;
    if (showAcceptedBanks)
        rows++;
    if (showAcceptedCountryCodes)
        rows++;
    addTitledGroupBg(gridPane, ++rowIndex, rows, Res.get("shared.Offer"));
    String fiatDirectionInfo = ":";
    String btcDirectionInfo = ":";
    OfferPayload.Direction direction = offer.getDirection();
    String currencyCode = offer.getCurrencyCode();
    String offerTypeLabel = Res.getWithCol("shared.offerType");
    String toReceive = " " + Res.get("shared.toReceive");
    String toSpend = " " + Res.get("shared.toSpend");
    double firstRowDistance = Layout.FIRST_ROW_DISTANCE;
    if (takeOfferHandlerOptional.isPresent()) {
        addLabelTextField(gridPane, rowIndex, offerTypeLabel, formatter.getDirectionForTakeOffer(direction, currencyCode), firstRowDistance);
        fiatDirectionInfo = direction == OfferPayload.Direction.BUY ? toReceive : toSpend;
        btcDirectionInfo = direction == OfferPayload.Direction.SELL ? toReceive : toSpend;
    } else if (placeOfferHandlerOptional.isPresent()) {
        addLabelTextField(gridPane, rowIndex, offerTypeLabel, formatter.getOfferDirectionForCreateOffer(direction, currencyCode), firstRowDistance);
        fiatDirectionInfo = direction == OfferPayload.Direction.SELL ? toReceive : toSpend;
        btcDirectionInfo = direction == OfferPayload.Direction.BUY ? toReceive : toSpend;
    } else {
        addLabelTextField(gridPane, rowIndex, offerTypeLabel, formatter.getDirectionBothSides(direction, currencyCode), firstRowDistance);
    }
    String btcAmount = Res.get("shared.btcAmount");
    if (takeOfferHandlerOptional.isPresent()) {
        addLabelTextField(gridPane, ++rowIndex, btcAmount + btcDirectionInfo, formatter.formatCoinWithCode(tradeAmount));
        addLabelTextField(gridPane, ++rowIndex, formatter.formatVolumeLabel(currencyCode) + fiatDirectionInfo, formatter.formatVolumeWithCode(offer.getVolumeByAmount(tradeAmount)));
    } else {
        addLabelTextField(gridPane, ++rowIndex, btcAmount + btcDirectionInfo, formatter.formatCoinWithCode(offer.getAmount()));
        addLabelTextField(gridPane, ++rowIndex, Res.get("offerDetailsWindow.minBtcAmount"), formatter.formatCoinWithCode(offer.getMinAmount()));
        String volume = formatter.formatVolumeWithCode(offer.getVolume());
        String minVolume = "";
        if (offer.getVolume() != null && offer.getMinVolume() != null && !offer.getVolume().equals(offer.getMinVolume()))
            minVolume = " " + Res.get("offerDetailsWindow.min", formatter.formatVolumeWithCode(offer.getMinVolume()));
        addLabelTextField(gridPane, ++rowIndex, formatter.formatVolumeLabel(currencyCode) + fiatDirectionInfo, volume + minVolume);
    }
    String priceLabel = Res.getWithCol("shared.price");
    if (takeOfferHandlerOptional.isPresent()) {
        addLabelTextField(gridPane, ++rowIndex, priceLabel, formatter.formatPrice(tradePrice));
    } else {
        Price price = offer.getPrice();
        if (offer.isUseMarketBasedPrice()) {
            addLabelTextField(gridPane, ++rowIndex, priceLabel, formatter.formatPrice(price) + " " + Res.get("offerDetailsWindow.distance", formatter.formatPercentagePrice(offer.getMarketPriceMargin())));
        } else {
            addLabelTextField(gridPane, ++rowIndex, priceLabel, formatter.formatPrice(price));
        }
    }
    final PaymentMethod paymentMethod = offer.getPaymentMethod();
    final String makerPaymentAccountId = offer.getMakerPaymentAccountId();
    final PaymentAccount paymentAccount = user.getPaymentAccount(makerPaymentAccountId);
    String bankId = offer.getBankId();
    if (bankId == null || bankId.equals("null"))
        bankId = "";
    else
        bankId = " (" + bankId + ")";
    final boolean isSpecificBanks = paymentMethod.equals(PaymentMethod.SPECIFIC_BANKS);
    final boolean isNationalBanks = paymentMethod.equals(PaymentMethod.NATIONAL_BANK);
    final boolean isSepa = paymentMethod.equals(PaymentMethod.SEPA);
    if (offer.isMyOffer(keyRing) && makerPaymentAccountId != null && paymentAccount != null) {
        addLabelTextField(gridPane, ++rowIndex, Res.get("offerDetailsWindow.myTradingAccount"), paymentAccount.getAccountName());
    } else {
        final String method = Res.get(paymentMethod.getId());
        String paymentMethodLabel = Res.getWithCol("shared.paymentMethod");
        if (isNationalBanks || isSpecificBanks || isSepa) {
            String methodWithBankId = method + bankId;
            if (BankUtil.isBankIdRequired(offer.getCountryCode()))
                addLabelTextField(gridPane, ++rowIndex, paymentMethodLabel + " " + Res.get("offerDetailsWindow.offererBankId"), methodWithBankId);
            else if (BankUtil.isBankNameRequired(offer.getCountryCode()))
                addLabelTextField(gridPane, ++rowIndex, paymentMethodLabel + " " + Res.get("offerDetailsWindow.offerersBankName"), methodWithBankId);
        } else {
            addLabelTextField(gridPane, ++rowIndex, paymentMethodLabel, method);
        }
    }
    if (showAcceptedBanks) {
        if (paymentMethod.equals(PaymentMethod.SAME_BANK)) {
            addLabelTextField(gridPane, ++rowIndex, Res.get("offerDetailsWindow.bankId"), acceptedBanks.get(0));
        } else if (isSpecificBanks) {
            String value = Joiner.on(", ").join(acceptedBanks);
            String acceptedBanksLabel = Res.getWithCol("shared.acceptedBanks");
            Tooltip tooltip = new Tooltip(acceptedBanksLabel + " " + value);
            TextField acceptedBanksTextField = addLabelTextField(gridPane, ++rowIndex, acceptedBanksLabel, value).second;
            acceptedBanksTextField.setMouseTransparent(false);
            acceptedBanksTextField.setTooltip(tooltip);
        }
    }
    if (showAcceptedCountryCodes) {
        String countries;
        Tooltip tooltip = null;
        if (CountryUtil.containsAllSepaEuroCountries(acceptedCountryCodes)) {
            countries = Res.getWithCol("shared.allEuroCountries");
        } else {
            if (acceptedCountryCodes.size() == 1) {
                countries = CountryUtil.getNameAndCode(acceptedCountryCodes.get(0));
                tooltip = new Tooltip(countries);
            } else {
                countries = CountryUtil.getCodesString(acceptedCountryCodes);
                tooltip = new Tooltip(CountryUtil.getNamesByCodesString(acceptedCountryCodes));
            }
        }
        TextField acceptedCountries = addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.acceptedTakerCountries"), countries).second;
        if (tooltip != null) {
            acceptedCountries.setMouseTransparent(false);
            acceptedCountries.setTooltip(tooltip);
        }
    }
    rows = 5;
    String paymentMethodCountryCode = offer.getCountryCode();
    if (paymentMethodCountryCode != null)
        rows++;
    if (offer.getOfferFeePaymentTxId() != null)
        rows++;
    addTitledGroupBg(gridPane, ++rowIndex, rows, Res.get("shared.details"), Layout.GROUP_DISTANCE);
    addLabelTextFieldWithCopyIcon(gridPane, rowIndex, Res.getWithCol("shared.offerId"), offer.getId(), Layout.FIRST_ROW_AND_GROUP_DISTANCE);
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("offerDetailsWindow.makersOnion"), offer.getMakerNodeAddress().getFullAddress());
    addLabelTextField(gridPane, ++rowIndex, Res.get("offerDetailsWindow.creationDate"), formatter.formatDateTime(offer.getDate()));
    String value = Res.getWithColAndCap("shared.buyer") + " " + formatter.formatCoinWithCode(offer.getBuyerSecurityDeposit()) + " / " + Res.getWithColAndCap("shared.seller") + " " + formatter.formatCoinWithCode(offer.getSellerSecurityDeposit());
    addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.securityDeposit"), value);
    if (paymentMethodCountryCode != null)
        addLabelTextField(gridPane, ++rowIndex, Res.get("offerDetailsWindow.countryBank"), CountryUtil.getNameAndCode(paymentMethodCountryCode));
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("offerDetailsWindow.acceptedArbitrators"), formatter.arbitratorAddressesToString(offer.getArbitratorNodeAddresses()));
    if (offer.getOfferFeePaymentTxId() != null)
        addLabelTxIdTextField(gridPane, ++rowIndex, Res.get("shared.makerFeeTxId"), offer.getOfferFeePaymentTxId());
    if (placeOfferHandlerOptional.isPresent()) {
        addTitledGroupBg(gridPane, ++rowIndex, 1, Res.get("offerDetailsWindow.commitment"), Layout.GROUP_DISTANCE);
        addLabelTextField(gridPane, rowIndex, Res.get("offerDetailsWindow.agree"), Res.get("createOffer.tac"), Layout.FIRST_ROW_AND_GROUP_DISTANCE);
        addConfirmAndCancelButtons(true);
    } else if (takeOfferHandlerOptional.isPresent()) {
        addTitledGroupBg(gridPane, ++rowIndex, 1, Res.get("shared.contract"), Layout.GROUP_DISTANCE);
        addLabelTextField(gridPane, rowIndex, Res.get("offerDetailsWindow.tac"), Res.get("takeOffer.tac"), Layout.FIRST_ROW_AND_GROUP_DISTANCE);
        addConfirmAndCancelButtons(false);
    } else {
        Button closeButton = addButtonAfterGroup(gridPane, ++rowIndex, Res.get("shared.close"));
        closeButton.setOnAction(e -> {
            closeHandlerOptional.ifPresent(Runnable::run);
            hide();
        });
    }
}
Also used : Button(javafx.scene.control.Button) BusyAnimation(bisq.desktop.components.BusyAnimation) ArbitratorSelectionView(bisq.desktop.main.account.content.arbitratorselection.ArbitratorSelectionView) Coin(org.bitcoinj.core.Coin) LoggerFactory(org.slf4j.LoggerFactory) Layout(bisq.desktop.util.Layout) BSFormatter(bisq.desktop.util.BSFormatter) User(bisq.core.user.User) Inject(javax.inject.Inject) OfferPayload(bisq.core.offer.OfferPayload) Tuple3(bisq.common.util.Tuple3) Insets(javafx.geometry.Insets) Res(bisq.core.locale.Res) Overlay(bisq.desktop.main.overlays.Overlay) Tooltip(javafx.scene.control.Tooltip) AccountView(bisq.desktop.main.account.AccountView) Navigation(bisq.desktop.Navigation) Popup(bisq.desktop.main.overlays.popups.Popup) Offer(bisq.core.offer.Offer) TextField(javafx.scene.control.TextField) Label(javafx.scene.control.Label) Logger(org.slf4j.Logger) FormBuilder(bisq.desktop.util.FormBuilder) PaymentMethod(bisq.core.payment.payload.PaymentMethod) MainView(bisq.desktop.main.MainView) PaymentAccount(bisq.core.payment.PaymentAccount) List(java.util.List) ImageView(javafx.scene.image.ImageView) CountryUtil(bisq.core.locale.CountryUtil) Price(bisq.core.monetary.Price) AccountSettingsView(bisq.desktop.main.account.settings.AccountSettingsView) Optional(java.util.Optional) BankUtil(bisq.core.locale.BankUtil) KeyRing(bisq.common.crypto.KeyRing) Joiner(com.google.common.base.Joiner) PaymentAccount(bisq.core.payment.PaymentAccount) Tooltip(javafx.scene.control.Tooltip) Price(bisq.core.monetary.Price) Button(javafx.scene.control.Button) PaymentMethod(bisq.core.payment.payload.PaymentMethod) TextField(javafx.scene.control.TextField) OfferPayload(bisq.core.offer.OfferPayload)

Aggregations

KeyRing (bisq.common.crypto.KeyRing)4 KeyStorage (bisq.common.crypto.KeyStorage)3 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)3 Before (org.junit.Before)3 Tuple3 (bisq.common.util.Tuple3)1 BankUtil (bisq.core.locale.BankUtil)1 CountryUtil (bisq.core.locale.CountryUtil)1 Res (bisq.core.locale.Res)1 Price (bisq.core.monetary.Price)1 Offer (bisq.core.offer.Offer)1 OfferPayload (bisq.core.offer.OfferPayload)1 PaymentAccount (bisq.core.payment.PaymentAccount)1 PaymentMethod (bisq.core.payment.payload.PaymentMethod)1 User (bisq.core.user.User)1 Navigation (bisq.desktop.Navigation)1 BusyAnimation (bisq.desktop.components.BusyAnimation)1 MainView (bisq.desktop.main.MainView)1 AccountView (bisq.desktop.main.account.AccountView)1 ArbitratorSelectionView (bisq.desktop.main.account.content.arbitratorselection.ArbitratorSelectionView)1 AccountSettingsView (bisq.desktop.main.account.settings.AccountSettingsView)1