Skip to content

Commit

Permalink
fix: Account.isValidPair throwing on invalid seeds (#152)
Browse files Browse the repository at this point in the history
* fix(#151): stop `Account.isValidPair` from throwing

* feat: add `Account.isValidPair` tests for not throwing
  • Loading branch information
sno2 authored Apr 22, 2021
1 parent 5140c38 commit 1a18fad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ export class Account {
* @param accountNumber the given account number hex string
*/
static isValidPair(signingKey: string, accountNumber: string) {
return new Account(signingKey).accountNumberHex === accountNumber;
try {
return new Account(signingKey).accountNumberHex === accountNumber;
} catch (_) {
return false;
}
}

/** The 32 byte account number as a 32 byte hex string. */
Expand Down
9 changes: 9 additions & 0 deletions tests/account.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ describe("Account", () => {
expect(Account.isValidPair(defaultAccount.accountNumber, defaultAccount.signingKey)).toBeFalsy();
});

it("isValidPair doesn't throw errors", () => {
const results = [
Account.isValidPair("asdf", "asdf"),
Account.isValidPair(defaultAccount.signingKey, "asdf"),
Account.isValidPair("asdf", defaultAccount.accountNumber),
];
expect(results.every((val) => typeof val === "boolean")).toBeTruthy();
});

it("createSignature(message)", () => {
const account = createDefaultAccount();
assertAccountBasics(account);
Expand Down

0 comments on commit 1a18fad

Please sign in to comment.