I need to convert a public key into a form suitable for use with BouncyCastle.
To do this I open the debugger and write:
ListAddressGroupings
I then pick an address and write
validateaddress 1HQCZTfr7V7WAMUcVHM21TLfLoeQWEtNmS
And I get the result:
{
"isvalid" : true,
"address" : "1HQCZTfr7V7WAMUcVHM21TLfLoeQWEtNmS",
"ismine" : true,
"isscript" : false,
"pubkey" : "020ba3ebc2f55152df5653bb7aba6548f0615d67b072379bdd19e72bc63c052c50",
"iscompressed" : true,
"account" : "testDONOTUSE"
}
However I'm not sure what format this is in.
- What is the encoding of JSON-RPC's validateaddress value named
pubkey
?
I am asking this question so that I can determine the "recId" value needed for signature recovery when a UTF8 message is signed. In other words, I need convert the public key below into an array that I can use for that purpose.
- Is there an easier or better way to get the pubkey from a given wallet?
Sample data
Base58: 1HQCZTfr7V7WAMUcVHM21TLfLoeQWEtNmS
Public: 020ba3ebc2f55152df5653bb7aba6548f0615d67b072379bdd19e72bc63c052c50
SignMessage: Test
Output: IITRv4NdcaIgXP7DDNOkOrShBiJkBFoBqjXJXozKNClHnwSmNK3+QbT7ypKTkcc0F5UPsUCef5+gqhTb8sBZLuQ=
Further attempts:
When I convert public value "020ba3ebc2f55152df5653bb7aba6548f0615d67b072379bdd19e72bc63c052c50" as hex to bytes using this method on SO, I get the column below on the left. This is incorrect. However when I extract the public key from the private key, I get a similar but different result on the right.
public static byte[] publicKeyFromPrivate(BigInteger privKey, bool compressed) { X9ECParameters ecParams = Org.BouncyCastle.Asn1.Sec.SecNamedCurves.GetByName("secp256k1"); ECPoint point1 = ecParams.G.Multiply(privKey); return point1.GetEncoded(compressed); }