Skip to content

Commit

Permalink
fix: reject prefixes other then provided in isAddressValid
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed May 5, 2023
1 parent 1f8c70a commit 9462add
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/utils/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { concatBuffers } from './other';
import {
decode, encode, Encoded, Encoding,
} from './encoder';
import { ArgumentError } from './errors';

/**
* Generate address from secret key
Expand All @@ -32,6 +33,10 @@ export function isAddressValid(
): boolean {
try {
decode(address as Encoded.Generic<typeof prefix>);
const actualPrefix = address.split('_')[0];
if (actualPrefix !== prefix) {
throw new ArgumentError('Encoded string type', prefix, actualPrefix);
}
return true;
} catch (e) {
return false;
Expand Down
1 change: 1 addition & 0 deletions test/unit/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('crypto', () => {

it('isAddressValid', () => {
expect(isAddressValid('test')).to.be.equal(false);
expect(isAddressValid('th_11111111111111111111111111111111273Yts')).to.be.equal(false);
expect(isAddressValid('ak_11111111111111111111111111111111273Yts')).to.be.equal(true);
});

Expand Down

0 comments on commit 9462add

Please sign in to comment.