The writer of this article https://pastebin.com/raw/jCDFcESz explains that
Sha256('sender') x 2
yields the address 18aMGf2AxQ3YXyNv9sKxiHYCXcBJeJv9d1
I am however getting the address 1DcTtaa37w971TmoafPpE9Pk16xc42YA87
What am I doing wrong?
Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It only takes a minute to sign up.
Sign up to join this communityThe writer of this article https://pastebin.com/raw/jCDFcESz explains that
Sha256('sender') x 2
yields the address 18aMGf2AxQ3YXyNv9sKxiHYCXcBJeJv9d1
I am however getting the address 1DcTtaa37w971TmoafPpE9Pk16xc42YA87
What am I doing wrong?
A few things to check:
HASH256
on the decoded byte values of the string. In other words, HASH256(0x73656e646572)
SHA256
P2PKH
address (prefix is 1) so the steps to generate the address from the public key are:
pubkeyhash = HASH160(compressed pubkey)
i.e.RIPEMD160(SHA256(compressed pubkey)
00
byte prefix for P2PKH
BASE58CHECK(pubkeyhash)
$ echo -n sender | openssl sha256
(stdin)= 0a367b92cf0b037dfd89960ee832d56f7fc151681bb41e53690e776f5786998a
$ echo 0a367b92cf0b037dfd89960ee832d56f7fc151681bb41e53690e776f5786998a | xxd -r -p | openssl sha256
(stdin)= 098f6d68ce86adb2d8ba672a06227f7d177baca3568092e4cda159acca5eb0c7
$ openssl ec -inform DER -text -noout -in <(cat <(echo -n "302e0201010420") <(echo -n "098f6d68ce86adb2d8ba672a06227f7d177baca3568092e4cda159acca5eb0c7") <(echo -n "a00706052b8104000a") | xxd -r -p) 2>/dev/null | tail -6 | head -5 | sed 's/[ :]//g' | tr -d '\n' && echo
04f4e5977bcb050452289ebc750b56be65086bfdf3411bb9c346430716545d66b8dede7516256f34fa362b10b3ec85ccdf58c25733e00e5d33120fb66a79e596f6
# result is even (ends in 0xf6) so prefix first 32 bytes with 02 (for odd use 03)
$ echo 02f4e5977bcb050452289ebc750b56be65086bfdf3411bb9c346430716545d66b8 | xxd -r -p | openssl sha256
(stdin)= cb59a26ae2e385719a66f568476bace40a8789c5fe91d74be6381e29feb20ecb
$ echo cb59a26ae2e385719a66f568476bace40a8789c5fe91d74be6381e29feb20ecb | xxd -r -p | openssl ripemd160
(stdin)= 53178717ab3d70c50fe8ec8598a9c2a8a703abc5
$ echo 0053178717ab3d70c50fe8ec8598a9c2a8a703abc5 | xxd -r -p | base58 -c && echo
18aMGf2AxQ3YXyNv9sKxiHYCXcBJeJv9d1
using base58
| openssl sha256
and output; you can combine the first two and save xxd
with echo -n sender | openssl sha256 -binary | openssl sha256
and similarly for the two from pubkey to address. Instead of cat
with three <(echo)
you can do one echo
-- or one herestring: -in <(xxd -r -p <<<"hexprefix""hexprivkey""hexsuffix")
– dave_thompson_085
Mar 8 '19 at 22:34
static void test ( )
{
const MyByteArray x ( QByteArray ( "sender" ) );
_trace ( x.sha256 ( ).getAddressHashCompressed ( ).toString ( ) );
_trace ( x.sha256d ( ).getAddressHashCompressed ( ).toString ( ) );
}
the output is:
1DcTtaa37w971TmoafPpE9Pk16xc42YA87
18aMGf2AxQ3YXyNv9sKxiHYCXcBJeJv9d1
So, your code runs sha256 only once, but not twice
% echo -n "sender" | bx base16-encode | bx sha256 | bx sha256 | bx ec-to-public | bx ec-to-address -v 0
18aMGf2AxQ3YXyNv9sKxiHYCXcBJeJv9d1
% echo -n "sender" | bx base16-encode | bx sha256 | bx ec-to-public | bx ec-to-address -v 0
1DcTtaa37w971TmoafPpE9Pk16xc42YA87