Search in sources :

Example 1 with AuthResult

use of network.bisq.api.model.AuthResult in project bisq-api by mrosseel.

the class BisqProxy method changePassword.

public AuthResult changePassword(String oldPassword, String newPassword) {
    if (!btcWalletService.isWalletReady())
        throw new WalletNotReadyException("Wallet not ready yet");
    final WalletsManager walletsManager = injector.getInstance(WalletsManager.class);
    if (btcWalletService.isEncrypted()) {
        final KeyParameter aesKey = null == oldPassword ? null : getAESKey(oldPassword);
        if (!isWalletPasswordValid(aesKey))
            throw new UnauthorizedException();
        walletsManager.decryptWallets(aesKey);
    }
    if (null != newPassword && newPassword.length() > 0) {
        final Tuple2<KeyParameter, KeyCrypterScrypt> aesKeyAndScrypt = getAESKeyAndScrypt(newPassword);
        walletsManager.encryptWallets(aesKeyAndScrypt.second, aesKeyAndScrypt.first);
        final TokenRegistry tokenRegistry = injector.getInstance(TokenRegistry.class);
        tokenRegistry.clear();
        return new AuthResult(tokenRegistry.generateToken());
    }
    return null;
}
Also used : WalletsManager(bisq.core.btc.wallet.WalletsManager) TokenRegistry(network.bisq.api.service.TokenRegistry) KeyParameter(org.spongycastle.crypto.params.KeyParameter) AuthResult(network.bisq.api.model.AuthResult) KeyCrypterScrypt(org.bitcoinj.crypto.KeyCrypterScrypt)

Example 2 with AuthResult

use of network.bisq.api.model.AuthResult in project bisq-api by mrosseel.

the class BisqProxy method authenticate.

public AuthResult authenticate(String password) {
    final TokenRegistry tokenRegistry = injector.getInstance(TokenRegistry.class);
    final boolean isPasswordValid = btcWalletService.isWalletReady() && btcWalletService.isEncrypted() && isWalletPasswordValid(password);
    if (isPasswordValid) {
        return new AuthResult(tokenRegistry.generateToken());
    }
    throw new UnauthorizedException();
}
Also used : TokenRegistry(network.bisq.api.service.TokenRegistry) AuthResult(network.bisq.api.model.AuthResult)

Aggregations

AuthResult (network.bisq.api.model.AuthResult)2 TokenRegistry (network.bisq.api.service.TokenRegistry)2 WalletsManager (bisq.core.btc.wallet.WalletsManager)1 KeyCrypterScrypt (org.bitcoinj.crypto.KeyCrypterScrypt)1 KeyParameter (org.spongycastle.crypto.params.KeyParameter)1