thenewboston-blockchain / thenewboston-js

JavaScript library for thenewboston.
https://www.npmjs.com/package/thenewboston
MIT License
37 stars 18 forks source link

[Bug] `Account.isValidPair` throwing errors on invalid seed lengths and seed chars #151

Closed sno2 closed 3 years ago

sno2 commented 3 years ago

Describe the bug Account.isValidPair static method is throwing errors on invalid keys (i.e. bad length, invalid hex chars).

To Reproduce Steps to reproduce the behavior:

  1. Clone the project
  2. Go to tests/account.test.js
  3. Add the following line of code in the test labeled "isValidPair(signingKey, accountNumber)":
    expect(Account.isValidPair("asdf", "aasdf2")).toBeFalsy();
  4. Run npm test
  5. The following error happens:

    FAIL  tests/account.test.js (5.628 s)
    ● Account › isValidPair(signingKey, accountNumber)
    
    bad seed size
    
      2315 |     key: "fromSigningKey",
      2316 |     value: function fromSigningKey(signingKey) {
    > 2317 |       var _tweetnacl$sign$keyPa = tweetnacl.sign.keyPair.fromSeed(hexToUint8Array(signingKey)),
           |                                                          ^
      2318 |           accountNumber = _tweetnacl$sign$keyPa.publicKey,
      2319 |           signingKey_ = _tweetnacl$sign$keyPa.secretKey;
      2320 | 
    
      at Function.fromSeed (node_modules/tweetnacl/nacl-fast.js:2329:11)
      at Function.fromSigningKey (dist/index.js:2317:58)
      at new Account (dist/index.js:2228:29)
      at Function.isValidPair (dist/index.js:2350:14)
      at Object.<anonymous> (tests/account.test.js:47:20)

Expected behavior Account.isValidPair should just return whether the pair is valid or not, no matter whether the strings are the wrong size or don't include valid hex characters. It should not be throwing any errors at all.

sno2 commented 3 years ago

I've got this.