Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 91
fix: ton/starknet/aleo address validation#1642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
a1757c3749db83f6cd76563845782d090798e1efc9e7491acc3583f756e7ee2679e7755c5d2849c44bfbFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const chainId = 'aleo'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const chainId = 'starknet'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const chainId = 'ton'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types'; | ||
| import { utils } from 'ethers'; | ||
| import { Address } from '@ton/core'; | ||
| import { validateAndParseAddress } from 'starknet'; | ||
PaulvanMotman marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| import addressValidator from 'multicoin-address-validator'; | ||
| import { bech32 } from 'bech32'; | ||
| import { getSupportedERC20Tokens } from './erc20'; | ||
| import { getSupportedERC777Tokens } from './erc777'; | ||
| import { getHash } from './getHash'; | ||
| @@ -264,6 +267,12 @@ export class CurrencyManager<TMeta = unknown> implements CurrencyTypes.ICurrency | ||
| return isValidNearAddress(address, currency.network); | ||
| } else if (currency.network === 'tron' || currency.network === 'solana') { | ||
| return addressValidator.validate(address, currency.network); | ||
| } else if (currency.network === 'ton') { | ||
| return this.validateTonAddress(address); | ||
| } else if (currency.network === 'starknet') { | ||
| return this.validateStarknetAddress(address); | ||
| } else if (currency.network === 'aleo') { | ||
| return this.validateAleoAddress(address); | ||
| } | ||
PaulvanMotman marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| return addressValidator.validate(address, 'ETH'); | ||
| case RequestLogicTypes.CURRENCY.BTC: | ||
| @@ -290,6 +299,54 @@ export class CurrencyManager<TMeta = unknown> implements CurrencyTypes.ICurrency | ||
| return this.validateAddress(currency.value, currency); | ||
| } | ||
| /** | ||
| * Validate a TON address. See https://ton-org.github.io/ton-core/classes/Address.html#parse for more details. | ||
| * @param address - The address to validate | ||
| * @returns True if the address is valid, false otherwise | ||
| */ | ||
| validateTonAddress(address: string): boolean { | ||
| try { | ||
| return !!Address.parse(address); | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
PaulvanMotman marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| /** | ||
| * Validate a Starknet address. See https://starknetjs.com/docs/next/API/modules/#validateandparseaddress for more details. | ||
| * @param address - The address to validate | ||
| * @returns True if the address is valid, false otherwise | ||
| */ | ||
| validateStarknetAddress(address: string): boolean { | ||
| try { | ||
| return !!validateAndParseAddress(address); | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
PaulvanMotman marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| /** | ||
| * Validate an Aleo address using proper Bech32 validation with checksum verification. | ||
| * Aleo addresses use Bech32 encoding with: | ||
| * - HRP (Human Readable Part): "aleo" | ||
| * - Separator: "1" | ||
| * - Data + checksum: 58 characters | ||
| * - Total length: 63 characters | ||
| * - Strict Bech32 character set with checksum validation | ||
| * | ||
| * See https://namespaces.chainagnostic.org/aleo/caip10 for more details. | ||
| * @param address - The address to validate | ||
| * @returns True if the address is valid, false otherwise | ||
| */ | ||
| validateAleoAddress(address: string): boolean { | ||
| try { | ||
| const { prefix } = bech32.decode(address); | ||
| return prefix === 'aleo'; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
| /** | ||
| * Returns the list of currencies supported by Request out of the box | ||
| * Contains: | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.