You are viewing a single comment's thread from:

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

in #dev7 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.

Sort:  

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

Coin Marketplace

STEEM 0.18
TRX 0.16
JST 0.029
BTC 62204.66
ETH 2437.96
USDT 1.00
SBD 2.64