json rpc – Baffled by endianness: How do I compute the HASH160 of the public key of a base58 address?

I show You how To Make Huge Profits In A Short Time With Cryptos!

Given an address as follows:

> spend_address=$(btc-cli getnewaddress '' legacy)
> btc-cli getaddressinfo $spend_address

spend_address info {
  "address": "moHaAMoTLRZ7dCyP4SunTBRvSfdFxUNrCe",
  "scriptPubKey": "76a91455391f93c7409df890be2804aa3cf85b22a903c188ac",
  "isscript": false,
  "iswitness": false,
  "pubkey": "03a6a9b25d8cd811af3162222d5e6ddaf876f915ae37ccb4b4b3f2ba56c39e26d2",
  "iscompressed": true,
  ...<stuff not needed for example elided>...

So we have pubkey = 03a6a9b25d8cd811af3162222d5e6ddaf876f915ae37ccb4b4b3f2ba56c39e26d2.

And if we decode the ScriptPubKey we find the HASH160 embedded in it: 55391f93c7409df890be2804aa3cf85b22a903c1

Problem is I can’t get from pubkey to HASH160(pubkey). Somewhere I’m baffled by endianness. (I determined that by looking at intermediate results in the wallet’s getaddressinfo handler.)

I’ve tried:

(ripemd160 (sha256 spend_address_pubkey))
(ripemd160 (sha256 (reversebytes spend_address_pubkey)))
(ripemd160 (reversebytes (sha256 spend_address_pubkey)))
(reversebytes (ripemd160 (sha256 spend_address_pubkey)))
(ripemd160 (reversebytes (sha256 (reversebytes spend_address_pubkey))))

and none of those (or their byte reverses!) match the transactions HASH160(pubkey) in the vout[0].scriptPubKey.asm field. Help me find which end to work from please!

(I do know how to get the HASH160 straight from the address by stripping off the checksum. But I want to know how to get it from the pubkey, given the standard ways in which keys and hashes are displayed wrt endianness.)

Source link


All information contained on our website is published in good faith and for general information purposes only. Any action the reader takes based on the information contained on our website is at his own risk and expense.