• Welcome to forex.pm forex forum binary options trade. Please login or sign up.
 

pokkst/litecoinj message verification problem - Address.fromKey() returning wrong address

Started by Bitcoin, Feb 24, 2022, 04:46 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bitcoin

pokkst/litecoinj message verification problem - Address.fromKey() returning wrong address

I have a problem with java library pokkst/litecoinj. I am using the regular bitcoinj library to verify signed messages with success. As pokkst/litecoinj is a fork of bitcoinj I have expected it to work in same or close manner.


I have a method:


private boolean isSignatureValid(NetworkParameters params, String address, String message, String signature) {
    try {
        Address signingAddress = Address.fromString(params, address);
        ECKey key = ECKey.signedMessageToKey(message, signature);
        Address addressFromKey = Address.fromKey(params, key, signingAddress.getOutputScriptType());
        return signingAddress.equals(addressFromKey);
    } catch (SignatureException | AddressFormatException exception) {
        LOGGER.error(exception.getMessage());
        return false;
    } catch (NullPointerException exception) {
        LOGGER.error("Address cannot be null!");
        return false;
    }
}

Given data (this is just a test wallet so I do not worry about it):


params -> MainNetParams.get();
address -> ltc1qhlnfnzc6djz92ylf89cvsw7jzyl98hx79ye5a5
message -> test-test-test-test-test
signature -> IC6AcfBff2TA1brwVneXPFtUyHCu1hffTvcaTyNM+i5IbNc7UgNIA4bdVu3mpr0awTsaIK7lpY4O5pS4+/SJDUw=

Important: this address and signature are generated using Electrum-LTC wallet, cause I haven't found any other litecoin wallet that will allow me to sign messages.


When I run a test against this method, i see that addressFromKey is different than signingAddress and it's value is ltc1qewvcwvf9ln6uypme8wskmg5khqwpss7v9zcrj7


My code for Bitcoin message verification is very similar, and it is working fine.


I don't have access to the wallet keys, a wallet address, message and signature is all I have.


What am I doing wrong? May this be a bug in the library? Or could it be something wrong with Electrum-LTC?


Source: pokkst/litecoinj message verification problem - Address.fromKey() returning wrong address