Skip to content

Commit

Permalink
fix(helpers): fix EOSIO address validator
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviera9 committed Oct 19, 2022
1 parent e0a20d7 commit d36ae0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 7 additions & 4 deletions packages/ptokens-helpers/src/validators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const validatorFunction =
(_address: string) =>
validate(_address, _blockchain, _network)

// https://developers.eos.io/welcome/v2.0/protocol-guides/accounts_and_permissions/#2-accounts
const eosioAddressValidator = (_address: string) => /(^[a-z1-5.]{0,11}[a-z1-5]$)/.test(_address)

// pNetwork also supports appIds as Algorand destination
const algorandAddressValidator = (_address: string) => validatorFunction('algo')(_address) || /^\d+$/.test(_address)

Expand All @@ -15,14 +18,14 @@ export const chainIdToAddressValidatorMap: Map<ChainId, (_address: string) => bo
[ChainId.BitcoinMainnet, validatorFunction('btc')],
[ChainId.BitcoinTestnet, validatorFunction('btc', 'testnet')],
[ChainId.BscMainnet, validatorFunction('bnb')],
[ChainId.EosMainnet, validatorFunction('eos')],
[ChainId.EosMainnet, eosioAddressValidator],
[ChainId.EthereumMainnet, validatorFunction('eth')],
[ChainId.FantomMainnet, validatorFunction('eth')],
[ChainId.LibreMainnet, validatorFunction('eos')],
[ChainId.LibreMainnet, eosioAddressValidator],
[ChainId.LuxochainMainnet, validatorFunction('eth')],
[ChainId.PolygonMainnet, validatorFunction('matic')],
[ChainId.TelosMainnet, validatorFunction('eos')],
[ChainId.UltraMainnet, validatorFunction('eos')],
[ChainId.TelosMainnet, eosioAddressValidator],
[ChainId.UltraMainnet, eosioAddressValidator],
[ChainId.XdaiMainnet, validatorFunction('eth')],
])

Expand Down
9 changes: 7 additions & 2 deletions packages/ptokens-helpers/test/validators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ describe('isValidAddressByChainId', () => {
]
const eosioAddresses: AddressCheck[] = [
{ address: 'bittrexacct1', expected: true },
{ address: 'bittrexacct.', expected: false },
{ address: 'bit.re.acct1', expected: true },
{ address: 'bittrexacct11', expected: false },
{ address: 'binancecleos', expected: true },
{ address: '123456789012', expected: true },
{ address: '12345678.012', expected: true },
{ address: '123456789012', expected: false },
{ address: '12345678.012', expected: false },
{ address: '1234567890123', expected: false },
{ address: '12345678901', expected: false },
{ address: '12345678901@', expected: false },
{ address: 'binancecleoS', expected: false },
{ address: 'pnettest1', expected: true },
{ address: 'a', expected: true },
]
const addressesToCheck = new Map<ChainId, { address: string; expected: boolean }[]>([
[
Expand Down

0 comments on commit d36ae0e

Please sign in to comment.