[Ethereum] Why doesn’t the private key’s public key generate the correct public address

addressesecdsakeccakprivate-keypublic-key

Private Key: 9ccbcabf23e271183dbed503b43277f4c6eee9ac918cd6cda75ebb73ceb35c7d

Corresponding Public Address: 0xa73Fb234B1773ed7b115D18A1f0a15579bA2C1e1 (check for yourself on MyCrypto, for example)

One can generate the Public Key from the Private Key: 25b867253fe38ac7ed594f54b4f55fa18c49ced332fc352991e48a77ab7816c759d46cab51a59d9833cd6d958cc752ad95f10bbe469b364db2de5d3535417966

This Public Key, however, does not seem to be produce the Public Address above. Instead, after running it through keccak256, then taking the last 20 bytes, we're left with: 0xaa72e09d258da5496a7e6628e09207ec382e478a

What am I doing wrong?

Best Answer

You need to hash the bytes of the public key (not the public key string).

In Javascript https://runkit.com/embed/2w4f7dvkz2lg

keccak256 = require('js-sha3').keccak256;

keccak256(new Buffer('25b867253fe38ac7ed594f54b4f55fa18c49ced332fc352991e48a77ab7816c759d46cab51a59d9833cd6d958cc752ad95f10bbe469b364db2de5d3535417966', 'hex')).slice(24)

"a73fb234b1773ed7b115d18a1f0a15579ba2c1e1"

Note how the public key is put in a Buffer.