nbd-wtf / dart-bip340

naïve implementation of BIP-340 Schnorr Signatures in Dart
MIT License
14 stars 10 forks source link

The function getPublicKey() does not pad the returned value with 0 if the calculated public key should have zeros at beginning #4

Closed vishalxl closed 1 year ago

vishalxl commented 2 years ago

The result is that the user gets wrong value.

In function getPublicKey(...)

  return P.x!.toBigInteger()!.toRadixString(16);

Should be

  return P.x!.toBigInteger()!.toRadixString(16).padLeft(64, '0');

@johnonchain

fiatjaf commented 2 years ago

Can you send a pull request? If not I can do it eventually, but inertia is a force.

vishalxl commented 2 years ago

will send soon.

vishalxl commented 2 years ago

Update: Once I pad the 0's to the returned value of public key, even then there seems to be a problem where the signed nostr message/event is not being accepted by the relays, so it indicates the messages using such secret key ( with leading 0's in its public key) aren't being generated correctly.

ethicnology commented 1 year ago

To give a sample for investigators

ea7daa0537b93aa3ae4495a274ecc05077e3dc168809d77a7afa4ec1db0fb3bd # private key
0ba0206887bd61579bf65ec09d7806bea32c64be1cf2c978cf031a811cd238db # public key
ryzizub commented 1 year ago

Trying to figure out whats wrong here. This is really huge issue for all dart/flutter client, cause its making signatures wrong as @vishalxl said . Unfortunately haven't been able to figure out where is the problem, but will continue next week trying

fiatjaf commented 1 year ago

Fixed in https://github.com/nbd-wtf/dart-bip340/commit/669a18d1670cdd6df36a54f4ba798fbc58c69410.

ryzizub commented 1 year ago

Had a discussion with @fiatjaf and we werent able reproduce failing events (so it was probably mistake on my site). In this case, just leading 0's were the issue