[Steem-JS] Fix invalid sequence when disabling witness with null key

in utopian-io •  4 months ago

[Steem-JS] Fix invalid sequence when disabling witness with null key


Img Source


Description

This submission details a fix in the SteemJS library that would return an error when attempting to disable a witness by sending a null key. Upon sending the null key, users would receive an "Invalid sequence" error suggesting that their public key was malformed. Similar issues have appeared in bitshares and in the corresponding bitshares-js. Some of the knowledge of this issue and fix was adopted from bitshares.

Summary

When using SteemJS to send a witness update with STM1111111111111111111111111111111114T1Anm as the key an error occurred.

Changed files

  • src/auth/ecc/src/key_public.js
  • test/KeyFormats.js

Related code

     static fromBuffer(buffer) {
+        if (
+            buffer.toString("hex") ===
+            "000000000000000000000000000000000000000000000000000000000000000000"
+        )
+            return new PublicKey(null);
         return new PublicKey(ecurve.Point.decodeFrom(secp256k1, buffer));
     }
 
-    toBuffer(compressed = this.Q.compressed) {
+    toBuffer(compressed = this.Q ? this.Q.compressed : null) {
+        if (this.Q === null)
+            return Buffer.from(
+                "000000000000000000000000000000000000000000000000000000000000000000",
+                "hex"
+            );
         return this.Q.getEncoded(compressed);
     }

Links


Vote @netuoso as Witness


Posted on Utopian.io - Rewarding Open Source Contributors
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thanks for the contribution, @netuoso. A small, but relatively valuable fix - good work!

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Hey @netuoso
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Thank you!!!