Address-Generation

在大腦錢包上重複 sha256

  • March 8, 2019

本文作者<https://pastebin.com/raw/jCDFcESz>解釋說

Sha256('sender') x 2 產生地址 18aMGf2AxQ3YXyNv9sKxiHYCXcBJeJv9d1

但是我得到了地址1DcTtaa37w971TmoafPpE9Pk16xc42YA87

我究竟做錯了什麼?

需要檢查的幾件事:

  1. 確保您正在計算HASH256字元串的解碼字節值。換一種說法,HASH256(0x73656e646572)

  2. 確保你正在做 2 輪SHA256

  3. 使用 secp256k1 生成壓縮公鑰

  4. 這是一個P2PKH地址(前綴為 1),因此從公鑰生成地址的步驟是:

  5. pubkeyhash = HASH160(compressed pubkey)IERIPEMD160(SHA256(compressed pubkey)

  6. 00_P2PKH

  7. 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 &lt;(cat &lt;(echo -n "302e0201010420") &lt;(echo -n "098f6d68ce86adb2d8ba672a06227f7d177baca3568092e4cda159acca5eb0c7") &lt;(echo -n "a00706052b8104000a") | xxd -r -p) 2&gt;/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

使用base58

引用自:https://bitcoin.stackexchange.com/questions/85098