Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: validate asset id from deeplinks (#5973)
* feat: adds validateAssetId function * enhancement: adds base token id validation --------- Co-authored-by: MarkNerdi <105642810+MarkNerdi@users.noreply.github.com>
- Loading branch information
1 parent
4d764da
commit 895324d
Showing
6 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/shared/lib/auxiliary/deep-link/errors/invalid-asset-id.error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { BaseError } from '@core/error' | ||
import { localize } from '@core/i18n' | ||
|
||
export class InvalidAssetIdError extends BaseError { | ||
constructor() { | ||
const message = localize('error.send.invalidAssetId') | ||
super({ | ||
message, | ||
showNotification: true, | ||
saveToErrorLog: false, | ||
logToConsole: true, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './validateAssetId' | ||
export * from './validateBech32Address' | ||
export * from './validateEthereumAddress' |
11 changes: 11 additions & 0 deletions
11
packages/shared/lib/core/utils/crypto/utils/validateAssetId.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { InvalidAssetIdError } from '@auxiliary/deep-link' | ||
import { COIN_TYPE } from '@core/network' | ||
|
||
export function validateAssetId(id: string): void { | ||
const isHex = id.startsWith('0x') | ||
if (isHex && !/^(0x08)?[0-9a-f]{64}?(?:0[1-9]|[1-5][0-9]|6[0-4])?0{8}$/i.test(id)) { | ||
throw new InvalidAssetIdError() | ||
} else if (!isHex && !Object.values(COIN_TYPE).includes(Number(id))) { | ||
throw new InvalidAssetIdError() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters