RE: [Steem-js] How to validate Username and Private Keys.

You are viewing a single comment's thread from:

[Steem-js] How to validate Username and Private Keys.

in dev •  7 years ago  (edited)

Thanks for this post, it's awesome to see the community giving detailed examples of how to use the steem JS API. I did, however, notice that running this example with an invalid WIF on my machine returns a warning for a node.js unhandled promise rejection. This is due to the fact that I replaced your console.log with a thrown Error. I will go ahead and post my code in case anyone else plans to throw errors from invalid WIFs

    steem.api.getAccountsAsync([username])
      .then(result => {
        var publicWif = result[0].posting.key_auths[0][0];
        let validWif = true;
        try {
          validWif = steem.auth.wifIsValid(wif, publicWif);
        }
        catch(e) {
          validWif = false;
        }
        if(!validWif)
          throw new Error('Invalid Wif provided');
      })
      .catch(error => console.log('Sign in failed: ' + error.message));

    this.wif = wif;

I'm also currently working on using the steem.auth.toWif(username, password, 'posting') call to retrieve the wif instead and could post that solution if there is any interest.

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:  

Of course, you can modify that code according to your needs. That was just an example.