Skip to content

Commit

Permalink
Merge pull request #4112 from BitGo/WIN-1266-bech32-check-injective
Browse files Browse the repository at this point in the history
fix: add bech32 validation to cosmos address validation
  • Loading branch information
DinshawKothari authored Dec 4, 2023
2 parents 8ac4787 + f5008a7 commit 0e62960
Show file tree
Hide file tree
Showing 32 changed files with 98 additions and 68 deletions.
21 changes: 18 additions & 3 deletions modules/abstract-cosmos/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
TransactionType,
} from '@bitgo/sdk-core';
import { encodeSecp256k1Pubkey, encodeSecp256k1Signature } from '@cosmjs/amino';
import { fromBase64, fromHex, toHex } from '@cosmjs/encoding';
import { fromBase64, fromBech32, fromHex, toHex } from '@cosmjs/encoding';
import {
DecodedTxRaw,
EncodeObject,
Expand Down Expand Up @@ -707,19 +707,34 @@ export class CosmosUtils implements BaseUtils {
* @param {RegExp} regExp Regular expression to validate the root address against after trimming the memoId
* @returns {boolean} true if address is valid
*/
isValidCosmosLikeAddressWithMemoId(address: string, regExp: RegExp): boolean {
protected isValidCosmosLikeAddressWithMemoId(address: string, regExp: RegExp): boolean {
if (typeof address !== 'string') return false;
const addressArray = address.split('?memoId=');
if (
![1, 2].includes(addressArray.length) || // should have at most one occurrence of 'memoId='
!regExp.test(addressArray[0]) ||
!this.isValidBech32AddressMatchingRegex(addressArray[0], regExp) ||
(addressArray[1] && !this.isValidMemoId(addressArray[1]))
) {
return false;
}
return true;
}

/**
* Checks if address is valid Bech32 and matches given regular expression
* @param {string} address
* @param {RegExp} regExp Regular expression to validate the address against
* @returns {boolean} true if address is valid
*/
protected isValidBech32AddressMatchingRegex(address: string, regExp: RegExp): boolean {
try {
fromBech32(address);
} catch (e) {
return false;
}
return regExp.test(address);
}

/**
* Return boolean indicating whether a memo id is valid
*
Expand Down
23 changes: 19 additions & 4 deletions modules/sdk-coin-atom/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
TransactionType,
} from '@bitgo/sdk-core';
import { encodeSecp256k1Pubkey, encodeSecp256k1Signature } from '@cosmjs/amino';
import { fromBase64, fromHex, toHex } from '@cosmjs/encoding';
import { fromBase64, fromBech32, fromHex, toHex } from '@cosmjs/encoding';
import {
DecodedTxRaw,
decodePubkey,
Expand Down Expand Up @@ -89,19 +89,34 @@ export class Utils implements BaseUtils {
* @param {RegExp} regExp Regular expression to validate the root address against after trimming the memoId
* @returns {boolean} true if address is valid
*/
isValidCosmosLikeAddressWithMemoId(address: string, regExp: RegExp): boolean {
protected isValidCosmosLikeAddressWithMemoId(address: string, regExp: RegExp): boolean {
if (typeof address !== 'string') return false;
const addressArray = address.split('?memoId=');
if (
![1, 2].includes(addressArray.length) || // should have at most one occurrence of 'memoId='
!regExp.test(addressArray[0]) ||
!this.isValidBech32AddressMatchingRegex(addressArray[0], regExp) ||
(addressArray[1] && !this.isValidMemoId(addressArray[1]))
) {
return false;
}
return true;
}

/**
* Checks if address is valid Bech32 and matches given regular expression
* @param {string} address
* @param {RegExp} regExp Regular expression to validate the address against
* @returns {boolean} true if address is valid
*/
protected isValidBech32AddressMatchingRegex(address: string, regExp: RegExp): boolean {
try {
fromBech32(address);
} catch (e) {
return false;
}
return regExp.test(address);
}

/**
* Return boolean indicating whether a memo id is valid
*
Expand Down Expand Up @@ -135,7 +150,7 @@ export class Utils implements BaseUtils {
* @returns {boolean} - the validation result
*/
isValidValidatorAddress(address: string): boolean {
return constants.validatorAddressRegex.test(address);
return this.isValidBech32AddressMatchingRegex(address, constants.validatorAddressRegex);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions modules/sdk-coin-atom/test/resources/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ export const address = {
address1: 'cosmos1ut2w0m3xa7z2rvndv23pthv9qc7hksx6tkf9uq',
address2: 'cosmos12xt4x49p96n9aw4umjwyp3huct27nwr2g4r6p2',
address3: 'cosxyz1xxxz06yx0u3yjzjjjm02xyx3mh25akenzql3n8',
address4: 'cosmos16ghn9c6f5yua09zqw7y794mvc30h4y4md7ckuk',
address4: 'cosmos16ghn9c6f5yua09zqw7y794mvc30h4y4md7ckuu',
address6: 'cosmos1smefkq9yaxgw9c9fhym6qsp746q884czeacn32',
validatorAddress1: 'cosmosvaloper1ut2w0m3xa7z2rvndv23pthv9qc7hksx6tkf9uq',
validatorAddress2: 'cosmosvaloper12xt4x49p96n9aw4umjwyp3huct27nwr2g4r6p2',
validatorAddress1: 'cosmosvaloper1c4k24jzduc365kywrsvf5ujz4ya6mwympnc4en',
validatorAddress2: 'cosmosvaloper1tflk30mq5vgqjdly92kkhhq3raev2hnz6eete3',
validatorAddress3: 'cosxyzvaloper1xxxz06yx0u3yjzjjjm02xyx3mh25akenzql3n8',
validatorAddress4: 'cosmosvalopr16ghn9c6f5yua09zqw7y794mvc30h4y4md7ckuk',
validatorAddress4: 'cosmosvaloper1c4k24jzduc365kywrsvf5ujz4ya6mwympnc4ee',
noMemoIdAddress: 'cosmos12xt4x49p96n9aw4umjwyp3huct27nwr2g4r6p2',
validMemoIdAddress: 'cosmos12xt4x49p96n9aw4umjwyp3huct27nwr2g4r6p2?memoId=2',
invalidMemoIdAddress: 'cosmos12xt4x49p96n9aw4umjwyp3huct27nwr2g4r6p2?memoId=xyz',
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-atom/test/unit/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('ATOM', function () {
should.equal(utils.isValidAddress(address.address1), true);
should.equal(utils.isValidAddress(address.address2), true);
should.equal(utils.isValidAddress(address.address3), false);
should.equal(utils.isValidAddress(address.address4), true);
should.equal(utils.isValidAddress(address.address4), false);
should.equal(utils.isValidAddress('dfjk35y'), false);
should.equal(utils.isValidAddress(undefined as unknown as string), false);
should.equal(utils.isValidAddress(''), false);
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-atom/test/unit/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('utils', () => {
should.equal(utils.isValidAddress(address.address1), true);
should.equal(utils.isValidAddress(address.address2), true);
should.equal(utils.isValidAddress(address.address3), false);
should.equal(utils.isValidAddress(address.address4), true);
should.equal(utils.isValidAddress(address.address4), false);
should.equal(utils.isValidAddress('dfjk35y'), false);
should.equal(utils.isValidAddress(undefined as unknown as string), false);
should.equal(utils.isValidAddress(''), false);
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-bera/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class BeraUtils extends CosmosUtils {

/** @inheritdoc */
isValidValidatorAddress(address: string): boolean {
return constants.validatorAddressRegex.test(address);
return this.isValidBech32AddressMatchingRegex(address, constants.validatorAddressRegex);
}

/** @inheritdoc */
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-bld/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export class BldUtils extends CosmosUtils {

/** @inheritdoc */
isValidValidatorAddress(address: string): boolean {
return constants.validatorAddressRegex.test(address);
return this.isValidBech32AddressMatchingRegex(address, constants.validatorAddressRegex);
}

/** @inheritdoc */
isValidContractAddress(address: string): boolean {
return constants.contractAddressRegex.test(address);
return this.isValidBech32AddressMatchingRegex(address, constants.contractAddressRegex);
}

/** @inheritdoc */
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-bld/test/resources/bld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ export const address = {
address1: 'agoric1tkfnp4khzd0f7mgtznwrvr0lv2at3p8c8sz89p',
address2: 'agoric13fe0g5z8krh2zwzzynusvus5q8c0ea7hn0qy3m',
address3: 'agoxxx1xxxnp4khzd0f7mgtznwrvr0lv2at3p8c8sz89p',
address4: 'agoric1tkfnp4khzd0f7mgtznwrvr0lv2at3p8c8sz89p',
address4: 'agoric1tkfnp4khzd0f7mgtznwrvr0lv2at3p8c8sz899',
validatorAddress1: 'agoricvaloper1w5ayde694g7gyrya6t4vydc7gs59upkk8mkr76',
validatorAddress2: 'agoricvaloper1l59wfskgu2564m6e7wmd20e3wyn0d0h8qsyrc5',
validatorAddress3: 'agoxxxvaloper1xxxxde694g7gyrya6t4vydc7gs59upkk8mkr76',
validatorAddress4: 'agoricvalopxr1w5ayde694g7gyrya6t4vydc7gs59upkk8mkr76',
validatorAddress4: 'agoricvaloper1w5ayde694g7gyrya6t4vydc7gs59upkk8mkr77',
noMemoIdAddress: 'agoric1tkfnp4khzd0f7mgtznwrvr0lv2at3p8c8sz89p',
validMemoIdAddress: 'agoric1tkfnp4khzd0f7mgtznwrvr0lv2at3p8c8sz89p?memoId=2',
invalidMemoIdAddress: 'agoric1tkfnp4khzd0f7mgtznwrvr0lv2at3p8c8sz89p?memoId=xyz',
Expand Down
6 changes: 3 additions & 3 deletions modules/sdk-coin-bld/test/unit/bld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ describe('BLD', function () {

it('should validate wallet receive address', async function () {
const receiveAddress = {
address: 'agoric1yn3t8qujmtxjsnx7angjua3jhvkjxy5n5xgs0n?memoId=7',
address: 'agoric1tkfnp4khzd0f7mgtznwrvr0lv2at3p8c8sz89p?memoId=7',
coinSpecific: {
rootAddress: 'agoric1yn3t8qujmtxjsnx7angjua3jhvkjxy5n5xgs0n',
rootAddress: 'agoric1tkfnp4khzd0f7mgtznwrvr0lv2at3p8c8sz89p',
memoID: '7',
},
};
Expand All @@ -86,7 +86,7 @@ describe('BLD', function () {
should.equal(utils.isValidAddress(address.address1), true);
should.equal(utils.isValidAddress(address.address2), true);
should.equal(utils.isValidAddress(address.address3), false);
should.equal(utils.isValidAddress(address.address4), true);
should.equal(utils.isValidAddress(address.address4), false);
should.equal(utils.isValidAddress('dfjk35y'), false);
should.equal(utils.isValidAddress(undefined as unknown as string), false);
should.equal(utils.isValidAddress(''), false);
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-coreum/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export class CoreumUtils extends CosmosUtils {
/** @inheritdoc */
isValidValidatorAddress(address: string): boolean {
if (this.networkType === NetworkType.TESTNET) {
return constants.testnetValidatorAddressRegex.test(address);
return this.isValidBech32AddressMatchingRegex(address, constants.testnetValidatorAddressRegex);
}
return constants.mainnetValidatorAddressRegex.test(address);
return this.isValidBech32AddressMatchingRegex(address, constants.mainnetValidatorAddressRegex);
}

/** @inheritdoc */
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-coreum/test/resources/coreum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export const mainnetAddress = {
address1: 'core1v7n3mrjg58udt7cyhv9gs62t8wcf9sh8w604y5',
address2: 'core1ssh2d2ft6hzrgn9z6k7mmsamy2hfpxl9y8re5x',
address3: 'core35udp7m30va5njkdrguj27wvk9lnutfwkevk7n9',
address4: 'core13ku0s7gtzgxl2560l8ld7czmskvwcn5dkk4w29',
address4: 'core1v7n3mrjg58udt7cyhv9gs62t8wcf9sh8w604yy',
validatorAddress1: 'corevaloper1gsaxrwfu5glgw764mqhc4t8f3yxg2h07rmwt0k',
validatorAddress2: 'corevaloper1x9hd9r7duv2gagztvvqlw94v5gy4zd9xwhqnlm',
validatorAddress3: 'corevaloper2flaz3hzgg3tjszl372lu2zz5jsmxd8pvydl7gg',
validatorAddress4: 'corevaloder1xprcq3xdcuht0a8p082l3srgtwfgl57h2avmsq',
validatorAddress4: 'corevaloper1gsaxrwfu5glgw764mqhc4t8f3yxg2h07rmwt00',
noMemoIdAddress: 'core1v7n3mrjg58udt7cyhv9gs62t8wcf9sh8w604y5',
validMemoIdAddress: 'core1v7n3mrjg58udt7cyhv9gs62t8wcf9sh8w604y5?memoId=2',
invalidMemoIdAddress: 'core1v7n3mrjg58udt7cyhv9gs62t8wcf9sh8w604y5?memoId=xyz',
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-coreum/test/resources/tcoreum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ export const testnetAddress = {
address1: 'testcore12rqvuw3tp3zne7p9c6c6mcuxv8vmej23jl7acn',
address2: 'testcore1ecqgwd4whevrzjxrhrja54c5jg043j79xtz5a5',
address3: 'testcore2zackgzh7f2p980mhps48z6zm2tyl76a8r896nh',
address4: 'testcore1fl48vsnmsdzcv85q5d2q4z5ajdha8yu3sp2f36',
address4: 'testcore12rqvuw3tp3zne7p9c6c6mcuxv8vmej23jl7acc',
validatorAddress1: 'testcorevaloper1xjehmty2z5j7mfmpzxe8dgrf506c70n37lggga',
validatorAddress2: 'testcorevaloper1m569wc4z06sdntmcex6qxg8ds7l8e2ec7njj7d',
validatorAddress3: 'testcorevaloper207pd89u5x20wxucx9yjk5wysv5rttpvu8vnvsf',
validatorAddress4: 'testcorevaloder17udnpgy7sfam2rmeq5huumj0tqzfr0t4s49an9',
validatorAddress4: 'testcorevaloper1xjehmty2z5j7mfmpzxe8dgrf506c70n37lgggb',
noMemoIdAddress: 'testcore12rqvuw3tp3zne7p9c6c6mcuxv8vmej23jl7acn',
validMemoIdAddress: 'testcore12rqvuw3tp3zne7p9c6c6mcuxv8vmej23jl7acn?memoId=2',
invalidMemoIdAddress: 'testcore12rqvuw3tp3zne7p9c6c6mcuxv8vmej23jl7acn?memoId=xyz',
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-coreum/test/unit/coreum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('Coreum', function () {
should.equal(mainnetUtils.isValidAddress(mainnetAddress.address1), true);
should.equal(mainnetUtils.isValidAddress(mainnetAddress.address2), true);
should.equal(mainnetUtils.isValidAddress(mainnetAddress.address3), false);
should.equal(mainnetUtils.isValidAddress(mainnetAddress.address4), true);
should.equal(mainnetUtils.isValidAddress(mainnetAddress.address4), false);
should.equal(mainnetUtils.isValidAddress('dfjk35y'), false);
should.equal(mainnetUtils.isValidAddress(undefined as unknown as string), false);
should.equal(mainnetUtils.isValidAddress(''), false);
Expand All @@ -127,7 +127,7 @@ describe('Coreum', function () {
should.equal(testnetUtils.isValidAddress(testnetAddress.address1), true);
should.equal(testnetUtils.isValidAddress(testnetAddress.address2), true);
should.equal(testnetUtils.isValidAddress(testnetAddress.address3), false);
should.equal(testnetUtils.isValidAddress(testnetAddress.address4), true);
should.equal(testnetUtils.isValidAddress(testnetAddress.address4), false);
should.equal(testnetUtils.isValidAddress('dfjk35y'), false);
should.equal(testnetUtils.isValidAddress(undefined as unknown as string), false);
should.equal(testnetUtils.isValidAddress(''), false);
Expand Down
8 changes: 4 additions & 4 deletions modules/sdk-coin-hash/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ export class HashUtils extends CosmosUtils {
/** @inheritdoc */
isValidValidatorAddress(address: string): boolean {
if (this.networkType === NetworkType.TESTNET) {
return constants.testnetValidatorAddressRegex.test(address);
return this.isValidBech32AddressMatchingRegex(address, constants.testnetValidatorAddressRegex);
}
return constants.mainnetValidatorAddressRegex.test(address);
return this.isValidBech32AddressMatchingRegex(address, constants.mainnetValidatorAddressRegex);
}

/** @inheritdoc */
isValidContractAddress(address: string): boolean {
if (this.networkType === NetworkType.TESTNET) {
return constants.testnetContractAddressRegex.test(address);
return this.isValidBech32AddressMatchingRegex(address, constants.testnetContractAddressRegex);
}
return constants.mainnetContractAddressRegex.test(address);
return this.isValidBech32AddressMatchingRegex(address, constants.mainnetContractAddressRegex);
}

/** @inheritdoc */
Expand Down
8 changes: 4 additions & 4 deletions modules/sdk-coin-hash/test/resources/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ export const mainnetAddress = {
address1: 'pb1fmxzuzx5c4ja50vu94nt0aessnuedzmppde8qr',
address2: 'pb16vmp7sz28pnvgz6f3zm6q93y39jsd33aazwg4u',
address3: 'pb2xvd4k9jg5h0d4dhzr4z0txtwe9p5zxf58xcmxd',
address4: 'pb1xvd4k9jg5h0d4dhzr4z0txtwe9p5zxf58xcmxd',
address4: 'pb1fmxzuzx5c4ja50vu94nt0aessnuedzmppde8qq',
validatorAddress1: 'pbvaloper13905qnf0mc8f8h3dawsq0894ded0ct83f66l56',
validatorAddress2: 'pbvaloper1d7yum2cxwkhmmuxa096prlv5gawjxw0gc2sykq',
validatorAddress3: 'pbvaloder17yx96jtu0r24jp8gyxc8y8pj0lgvcz964w2gyg',
validatorAddress4: 'pbvaloper2v549f7d8f7junfga7yg04uz4zx0lwpqdl2f897',
validatorAddress4: 'pbvaloper13905qnf0mc8f8h3dawsq0894ded0ct83f66l55',
noMemoIdAddress: 'pb1fmxzuzx5c4ja50vu94nt0aessnuedzmppde8qr',
validMemoIdAddress: 'pb1fmxzuzx5c4ja50vu94nt0aessnuedzmppde8qr?memoId=2',
invalidMemoIdAddress: 'pb1fmxzuzx5c4ja50vu94nt0aessnuedzmppde8qr?memoId=xyz',
Expand All @@ -213,11 +213,11 @@ export const testnetAddress = {
address1: 'tp1umned7wx7le70ttvrcem3fsyhn343asr2k2pwe',
address2: 'tp1ytxha7lg002rzd4jxmahrdjzkd62mx99klgjcc',
address3: 'txp1x96r8u4a48k6khknrhzd6c8cm3c64ewxy5prj',
address4: 'tp1496r8u4a48k6khknrhzd6c8cm3c64ewxy5p2rj',
address4: 'tp1umned7wx7le70ttvrcem3fsyhn343asr2k2pww',
validatorAddress1: 'tpvaloper1tgq6cpu6hmsrvkvdu82j99tsxxw7qqajn843fe',
validatorAddress2: 'tpvaloper1tgq6cpu6hmsrvkvdu82j99tsxxw7qqajn843fe',
validatorAddress3: 'txvaloper1xxxxcpu6hmsrvkvdu82j99tsxxw7qqajn843fe',
validatorAddress4: 'tpvalopr1xtgq6cpu6hmsrvkvdu82j99tsxxw7qqajn843fe',
validatorAddress4: 'tpvaloper1tgq6cpu6hmsrvkvdu82j99tsxxw7qqajn843ff',
noMemoIdAddress: 'tp1ytxha7lg002rzd4jxmahrdjzkd62mx99klgjcc',
validMemoIdAddress: 'tp1ytxha7lg002rzd4jxmahrdjzkd62mx99klgjcc?memoId=2',
invalidMemoIdAddress: 'tp1ytxha7lg002rzd4jxmahrdjzkd62mx99klgjcc?memoId=xyz',
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-hash/test/unit/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('HASH', function () {
should.equal(mainnetUtils.isValidAddress(mainnetAddress.address1), true);
should.equal(mainnetUtils.isValidAddress(mainnetAddress.address2), true);
should.equal(mainnetUtils.isValidAddress(mainnetAddress.address3), false);
should.equal(mainnetUtils.isValidAddress(mainnetAddress.address4), true);
should.equal(mainnetUtils.isValidAddress(mainnetAddress.address4), false);
should.equal(mainnetUtils.isValidAddress('dfjk35y'), false);
should.equal(mainnetUtils.isValidAddress(undefined as unknown as string), false);
should.equal(mainnetUtils.isValidAddress(''), false);
Expand All @@ -118,7 +118,7 @@ describe('HASH', function () {
should.equal(testnetUtils.isValidAddress(testnetAddress.address1), true);
should.equal(testnetUtils.isValidAddress(testnetAddress.address2), true);
should.equal(testnetUtils.isValidAddress(testnetAddress.address3), false);
should.equal(testnetUtils.isValidAddress(testnetAddress.address4), true);
should.equal(testnetUtils.isValidAddress(testnetAddress.address4), false);
should.equal(testnetUtils.isValidAddress('dfjk35y'), false);
should.equal(testnetUtils.isValidAddress(undefined as unknown as string), false);
should.equal(testnetUtils.isValidAddress(''), false);
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-injective/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const validDenoms = ['ninj', 'uinj', 'minj', 'inj'];
export const accountAddressRegex = /^(inj)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l']+)$/;
export const validatorAddressRegex = /^(injvaloper)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l']+)$/;
export const accountAddressRegex = /^(inj)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l']{38})$/;
export const validatorAddressRegex = /^(injvaloper)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l']{38})$/;
export const contractAddressRegex = /^(inj)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l']+)$/;
4 changes: 2 additions & 2 deletions modules/sdk-coin-injective/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export class InjectiveUtils extends CosmosUtils {

/** @inheritdoc */
isValidValidatorAddress(address: string): boolean {
return constants.validatorAddressRegex.test(address);
return this.isValidBech32AddressMatchingRegex(address, constants.validatorAddressRegex);
}

/** @inheritdoc */
isValidContractAddress(address: string): boolean {
return constants.contractAddressRegex.test(address);
return this.isValidBech32AddressMatchingRegex(address, constants.contractAddressRegex);
}

/** @inheritdoc */
Expand Down
6 changes: 3 additions & 3 deletions modules/sdk-coin-injective/test/resources/injective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ export const address = {
address1: 'inj15pz6fq652cme0gx6dd2z9wtza3rwmz9j4ywksd',
address2: 'inj1drn3vzg6xep63ptaxsyhj6py5aj8fy3d4303p0',
address3: 'inx1xxn3vzg6xep63ptaxsyhj6py5aj8fy3d4303p0',
address4: 'inj1vftzm2nnlt0x8z9gq2hgxxywlk79m8k7k3ljgk',
address4: 'inj15pz6fq652cme0gx6dd2z9wtza3rwmz9j4ywkss',
validatorAddress1: 'injvaloper1kk523rsm9pey740cx4plalp40009ncs0wrchfe',
validatorAddress2: 'injvaloper15uad884tqeq9r76x3fvktmjge2r6kek55c2zpa',
validatorAddress2: 'injvaloper19a77dzm2lrxt2gehqca3nyzq077kq7qsgvmrp4',
validatorAddress3: 'inxvaloper1xxx23rsm9pey740cx4plalp40009ncs0wrchfe',
validatorAddress4: 'injvalopr1xkk523rsm9pey740cx4plalp40009ncs0wrchfe',
validatorAddress4: 'injvaloper1kk523rsm9pey740cx4plalp40009ncs0wrchff',
noMemoIdAddress: 'inj15uad884tqeq9r76x3fvktmjge2r6kek55c2zpa',
validMemoIdAddress: 'inj15uad884tqeq9r76x3fvktmjge2r6kek55c2zpa?memoId=2',
invalidMemoIdAddress: 'inj15uad884tqeq9r76x3fvktmjge2r6kek55c2zpa?memoId=xyz',
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-injective/test/unit/injective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('INJ', function () {
should.equal(utils.isValidAddress(address.address1), true);
should.equal(utils.isValidAddress(address.address2), true);
should.equal(utils.isValidAddress(address.address3), false);
should.equal(utils.isValidAddress(address.address4), true);
should.equal(utils.isValidAddress(address.address4), false);
should.equal(utils.isValidAddress('dfjk35y'), false);
should.equal(utils.isValidAddress(undefined as unknown as string), false);
should.equal(utils.isValidAddress(''), false);
Expand Down
Loading

0 comments on commit 0e62960

Please sign in to comment.