Related eBooks

I need to get pubkeyhash of string pubkey. I try the following code with Bitcoinj :

public static String convertP2pkToP2pkh(String p2pk, NetworkParameters np) {
    return LegacyAddress.fromKey(np, ECKey.fromPublicOnly(Converter.hexToBytes(p2pk))).toString();

It works ok for valid pubkeys, but some strings should not be converted to pubkeyhash,
for example:

pubkey 0431415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446
got from output 1 of tx with txId=c94f41c1177b22ffff461808e62e31b3211352c78b6d550d445583c721eb48ca
should not be converted (checked with other convert libs and on website: )

but actual result of convertion with above code returns pubkeyhash 1EXpM1kseQJSudJEhMUT1SGzNrGtJADjp4 without any error.

I also used bitoicnj BitcoinCoreFileReader to read blocks, and result block gives the same result when use it with String address = blkOut.getScriptPubKey().getToAddress(np, true).toString()

But I need to get null or some exception if pubkey can not be converted.

If there is other possibility to get proper convertion of pubkey to pubkeyhash with java?


By pplny

답글 남기기

이메일 주소는 공개되지 않습니다.

Translate »