urbit / urbit-key-generation

Key derivation and HD wallet generation functions for Urbit
MIT License
15 stars 8 forks source link

addressFromSecp256k1Public behaves incorrectly #36

Closed Fang- closed 5 years ago

Fang- commented 5 years ago

The addressFromSecp256k1Private function passes it the full, uncompressed, serialized public key.

That is sane. But, it turns out you need to cut off the first/leading/signing byte of the full public key before keccak-256ing it. This should be as simple as .slice(1)ing the pubkey Buffer?

Example correct values: (src 1, 2)

priv: 0000000000000000000000000000000000000000000000000000000000000001
publ: 0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8
addr: 7e5f4552091a69125d5dfcb7b8c2659029395bdf

priv: b205a1e03ddf50247d8483435cd91f9c732bad281ad420061ab4310c33166276
publ: 046cb84859e85b1d9a27e060fdede38bb818c93850fb6e42d9c7e4bd879f8b9153fd94ed48e1f63312dce58f4d778ff45a2e5abb08a39c1bc0241139f5e54de7df
addr: afdefc1937ae294C3bd55386a8b9775539d81653

(Also this still says pub, which is incorrect.)

jtobin commented 5 years ago

There is actually a bigger error, too -- addressFromSecp256k1Public Keccak-hashes the compressed public key, whereas it should be hashing the uncompressed key. Will clean it up and add some test cases.