diff --git a/packages/desktop/components/popups/AddProposalPopup.svelte b/packages/desktop/components/popups/AddProposalPopup.svelte index 059e50e013..dceb13fdf0 100644 --- a/packages/desktop/components/popups/AddProposalPopup.svelte +++ b/packages/desktop/components/popups/AddProposalPopup.svelte @@ -6,7 +6,7 @@ import { localize } from '@core/i18n' import { updateActiveAccountPersistedData } from '@core/profile/actions' import { activeAccounts } from '@core/profile/stores' - import { HEXADECIMAL_PREFIX } from '@core/utils' + import { HEX_PREFIX } from '@core/utils' import { truncateString } from '@core/utils/string' import { closePopup, openPopup, PopupId } from '@desktop/auxiliary/popup' import type { Auth } from '@iota/wallet' @@ -102,7 +102,7 @@ } async function validateEventId(checkIfAlreadyRegistered: boolean): Promise { - const startsWith0x = eventId?.substring(0, 2) === HEXADECIMAL_PREFIX + const startsWith0x = eventId?.substring(0, 2) === HEX_PREFIX if (!startsWith0x) { eventIdError = localize('error.eventId.doesNotStartWith0x') return Promise.reject(eventIdError) diff --git a/packages/desktop/components/popups/ImportErc20TokenFormPopup.svelte b/packages/desktop/components/popups/ImportErc20TokenFormPopup.svelte index 549aaa6a7a..1c6fe8a9e1 100644 --- a/packages/desktop/components/popups/ImportErc20TokenFormPopup.svelte +++ b/packages/desktop/components/popups/ImportErc20TokenFormPopup.svelte @@ -5,7 +5,7 @@ import { ERC20_TOKEN_ADDRESS_LENGTH } from '@core/layer-2' import { getErc20TokenMetadata } from '@core/layer-2/utils' import { NetworkId, network } from '@core/network' - import { HEXADECIMAL_PREFIX, HEXADECIMAL_REGEXP } from '@core/utils' + import { HEX_PREFIX, HEXADECIMAL_REGEXP } from '@core/utils' import { closePopup } from '@desktop/auxiliary/popup' import { showNotification } from '@auxiliary/notification' @@ -57,7 +57,7 @@ } function validateTokenAddress(): string { - const hasHexPrefix = tokenAddress?.startsWith(HEXADECIMAL_PREFIX) + const hasHexPrefix = tokenAddress?.startsWith(HEX_PREFIX) const isValidHex = HEXADECIMAL_REGEXP.test(tokenAddress) if (!hasHexPrefix || !isValidHex) { return localize('error.erc20Token.invalidAddressFormat') diff --git a/packages/desktop/lib/electron/utils/ledger.utils.ts b/packages/desktop/lib/electron/utils/ledger.utils.ts index d14f78507f..46f30bbf41 100644 --- a/packages/desktop/lib/electron/utils/ledger.utils.ts +++ b/packages/desktop/lib/electron/utils/ledger.utils.ts @@ -1,5 +1,5 @@ import { IEvmTransactionSignature } from '@core/layer-2/interfaces' -import { HEXADECIMAL_PREFIX } from '@core/utils' +import { HEX_PREFIX } from '@core/utils' import AppEth from '@ledgerhq/hw-app-eth' import TransportNodeHid from '@ledgerhq/hw-transport-node-hid' import { listen } from '@ledgerhq/logs' @@ -37,9 +37,9 @@ export async function signTransactionData( const appEth = new AppEth(transport) const signature = await appEth.signTransaction(bip32Path, transactionHex, null) return { - r: HEXADECIMAL_PREFIX + signature.r, - v: HEXADECIMAL_PREFIX + signature.v, - s: HEXADECIMAL_PREFIX + signature.s, + r: HEX_PREFIX + signature.r, + v: HEX_PREFIX + signature.v, + s: HEX_PREFIX + signature.s, } } catch (error) { return { diff --git a/packages/shared/src/components/inputs/NftInput.svelte b/packages/shared/src/components/inputs/NftInput.svelte index 3b46284947..ea39f260aa 100644 --- a/packages/shared/src/components/inputs/NftInput.svelte +++ b/packages/shared/src/components/inputs/NftInput.svelte @@ -4,7 +4,7 @@ import { localize } from '@core/i18n' import { getNftByIdFromAllAccountNfts } from '@core/nfts/actions' import { ownedNfts } from '@core/nfts/stores' - import { HEXADECIMAL_PREFIX } from '@core/utils' + import { HEX_PREFIX } from '@core/utils' import { IOption, Modal, NftImageOrIconBox, SelectorInput } from '@ui' export let nftId: string = '' @@ -27,7 +27,7 @@ if (!nftId) { error = localize('error.send.nftRequired') return Promise.reject(error) - } else if (!nftId.startsWith(HEXADECIMAL_PREFIX)) { + } else if (!nftId.startsWith(HEX_PREFIX)) { error = localize('error.send.nftNotInHex') return Promise.reject(error) } else if (!isNftInPossession()) { diff --git a/packages/shared/src/lib/core/layer-2/actions/getLayer2MetadataForTransfer.ts b/packages/shared/src/lib/core/layer-2/actions/getLayer2MetadataForTransfer.ts index d8261ae04d..d00634732e 100644 --- a/packages/shared/src/lib/core/layer-2/actions/getLayer2MetadataForTransfer.ts +++ b/packages/shared/src/lib/core/layer-2/actions/getLayer2MetadataForTransfer.ts @@ -1,4 +1,4 @@ -import { HEXADECIMAL_PREFIX } from '@core/utils' +import { HEX_PREFIX } from '@core/utils' import type { SendFlowParameters, TokenSendFlowParameters } from '@core/wallet/types' import BigInteger from 'big-integer' import { SpecialStream } from '../classes' @@ -28,5 +28,5 @@ export async function getLayer2MetadataForTransfer(sendFlowParameters: SendFlowP const allowance = encodeAssetAllowance(sendFlowParameters) metadataStream.writeBytes('allowance', allowance.length, allowance) - return HEXADECIMAL_PREFIX + metadataStream.finalHex() + return HEX_PREFIX + metadataStream.finalHex() } diff --git a/packages/shared/src/lib/core/layer-2/actions/signEvmTransactionWithStronghold.ts b/packages/shared/src/lib/core/layer-2/actions/signEvmTransactionWithStronghold.ts index d9900b4271..bc6a1110f0 100644 --- a/packages/shared/src/lib/core/layer-2/actions/signEvmTransactionWithStronghold.ts +++ b/packages/shared/src/lib/core/layer-2/actions/signEvmTransactionWithStronghold.ts @@ -1,7 +1,7 @@ import { IAccountState } from '@core/account' import { prepareEvmTransaction } from '@core/layer-2/utils' import { EvmChainId, getEvmTransactionOptions } from '@core/network' -import { HEXADECIMAL_PREFIX } from '@core/utils' +import { HEX_PREFIX } from '@core/utils' import { removeLeadingZeros } from '@core/utils/buffer' import { Transaction, TxData } from '@ethereumjs/tx' import { ECDSASignature, fromRpcSig } from '@ethereumjs/util' @@ -13,7 +13,7 @@ export async function signEvmTransactionWithStronghold( chainId: EvmChainId, account: IAccountState ): Promise { - const unsignedTransactionMessageHex = HEXADECIMAL_PREFIX + prepareEvmTransaction(txData, chainId) + const unsignedTransactionMessageHex = HEX_PREFIX + prepareEvmTransaction(txData, chainId) const transaction = Transaction.fromTxData(txData, getEvmTransactionOptions(chainId)) const { signature } = await account.signSecp256k1Ecdsa(unsignedTransactionMessageHex, bip44Path) @@ -44,7 +44,7 @@ function createSignedTransaction( function getHexEncodedTransaction(transaction: Transaction): string { const serializedTransaction = transaction.serialize() - const hexEncodedTransaction = HEXADECIMAL_PREFIX + serializedTransaction.toString('hex') + const hexEncodedTransaction = HEX_PREFIX + serializedTransaction.toString('hex') return hexEncodedTransaction } diff --git a/packages/shared/src/lib/core/layer-2/helpers/getEvmTransactionValueFromAmount.ts b/packages/shared/src/lib/core/layer-2/helpers/getEvmTransactionValueFromAmount.ts index 2117dae9dd..1e9c8103f0 100644 --- a/packages/shared/src/lib/core/layer-2/helpers/getEvmTransactionValueFromAmount.ts +++ b/packages/shared/src/lib/core/layer-2/helpers/getEvmTransactionValueFromAmount.ts @@ -1,6 +1,6 @@ -import { HEXADECIMAL_PREFIX } from '@core/utils' +import { HEX_PREFIX } from '@core/utils' import { WEI_PER_GLOW } from '../constants' export function getEvmTransactionValueFromAmount(amount: number | string): string { - return HEXADECIMAL_PREFIX + BigInt(BigInt(amount) * WEI_PER_GLOW).toString(16) + return HEX_PREFIX + BigInt(BigInt(amount) * WEI_PER_GLOW).toString(16) } diff --git a/packages/shared/src/lib/core/layer-2/utils/parseLayer2MetadataForTransfer.ts b/packages/shared/src/lib/core/layer-2/utils/parseLayer2MetadataForTransfer.ts index e643b1fa7c..c1bdf545df 100644 --- a/packages/shared/src/lib/core/layer-2/utils/parseLayer2MetadataForTransfer.ts +++ b/packages/shared/src/lib/core/layer-2/utils/parseLayer2MetadataForTransfer.ts @@ -2,7 +2,7 @@ import { ReadSpecialStream } from '@core/layer-2/classes' import { Allowance } from '@core/layer-2/enums' import { NFT_ID_BYTE_LENGTH } from '@core/nfts/constants' import { TOKEN_ID_BYTE_LENGTH } from '@core/token/constants' -import { Converter, HEXADECIMAL_PREFIX } from '@core/utils' +import { Converter, HEX_PREFIX } from '@core/utils' import { CONTRACT_FUNCTIONS, TARGET_CONTRACTS } from '../constants' import { ILayer2AssetAllowance, ILayer2TransferAllowanceMetadata } from '../interfaces' @@ -16,7 +16,7 @@ export function parseLayer2MetadataForTransfer(metadata: Uint8Array): ILayer2Tra const gasLimit = readStream.readUIntNSpecialEncoding('gasLimit', 3) const smartContractParameters = parseSmartContractParameters(readStream) - const ethereumAddress = HEXADECIMAL_PREFIX + smartContractParameters['a'].substring(4) + const ethereumAddress = HEX_PREFIX + smartContractParameters['a'].substring(4) const allowance = parseAssetAllowance(readStream) diff --git a/packages/shared/src/lib/core/layer-2/utils/prepareEvmTransaction.ts b/packages/shared/src/lib/core/layer-2/utils/prepareEvmTransaction.ts index fc65a9b82e..dee5b53efa 100644 --- a/packages/shared/src/lib/core/layer-2/utils/prepareEvmTransaction.ts +++ b/packages/shared/src/lib/core/layer-2/utils/prepareEvmTransaction.ts @@ -1,5 +1,5 @@ import { EvmChainId, getEvmTransactionOptions } from '@core/network' -import { HEXADECIMAL_PREFIX } from '@core/utils' +import { HEX_PREFIX } from '@core/utils' import { RLP } from '@ethereumjs/rlp' import { Transaction } from '@ethereumjs/tx' import { bufArrToArr } from '@ethereumjs/util' @@ -17,5 +17,5 @@ export function prepareEvmTransaction( const transaction = Transaction.fromTxData(preparedTransactionData, getEvmTransactionOptions(chainId)) const transactionBuffer = isSigned ? transaction.raw() : transaction.getMessageToSign(false) const transactionHex = Buffer.from(RLP.encode(bufArrToArr(transactionBuffer))).toString('hex') - return isSigned ? HEXADECIMAL_PREFIX + transactionHex : transactionHex + return isSigned ? HEX_PREFIX + transactionHex : transactionHex } diff --git a/packages/shared/src/lib/core/token/utils/validateTokenId.ts b/packages/shared/src/lib/core/token/utils/validateTokenId.ts index ef8543e7c0..125a27630c 100644 --- a/packages/shared/src/lib/core/token/utils/validateTokenId.ts +++ b/packages/shared/src/lib/core/token/utils/validateTokenId.ts @@ -1,9 +1,9 @@ import { InvalidTokenIdError } from '@auxiliary/deep-link' import { DEFAULT_COIN_TYPE } from '@core/network' -import { HEXADECIMAL_PREFIX } from '@core/utils' +import { HEX_PREFIX } from '@core/utils' export function validateTokenId(id: string): void { - const isHex = id.startsWith(HEXADECIMAL_PREFIX) + const isHex = id.startsWith(HEX_PREFIX) if (isHex && !/^(0x08)?[0-9a-f]{64}?(?:0[1-9]|[1-5][0-9]|6[0-4])?0{8}$/i.test(id)) { throw new InvalidTokenIdError() } else if (!isHex && !Object.values(DEFAULT_COIN_TYPE).includes(Number(id))) { diff --git a/packages/shared/src/lib/core/utils/constants/hex.constants.ts b/packages/shared/src/lib/core/utils/constants/hex.constants.ts index f661b7de6d..7143d14392 100644 --- a/packages/shared/src/lib/core/utils/constants/hex.constants.ts +++ b/packages/shared/src/lib/core/utils/constants/hex.constants.ts @@ -1,3 +1,3 @@ -export const HEXADECIMAL_PREFIX = '0x' +export const HEX_PREFIX = '0x' export const HEXADECIMAL_REGEXP = /(0x)?[0-9a-fA-F]+$/i diff --git a/packages/shared/src/lib/core/utils/convert.ts b/packages/shared/src/lib/core/utils/convert.ts index ef9d96dda2..a67f6b1f9d 100644 --- a/packages/shared/src/lib/core/utils/convert.ts +++ b/packages/shared/src/lib/core/utils/convert.ts @@ -1,6 +1,6 @@ /* eslint-disable no-bitwise */ -import { HEXADECIMAL_PREFIX, MILLISECONDS_PER_SECOND } from './constants' +import { HEX_PREFIX, MILLISECONDS_PER_SECOND } from './constants' import { isValidDate } from './date' import { Base64 } from './encode' import { clamp } from './math' @@ -30,7 +30,7 @@ export function convertUnixTimestampToDate(timestamp: number): Date { export function convertUInt16NumberToLittleEndianHex(num: number, withHexPrefix = true): string { const littleEndianNumber = ((num & 0xff) << 8) | ((num >> 8) & 0xff) const hex = ('0000' + littleEndianNumber.toString(16).toUpperCase()).slice(-4) - return withHexPrefix ? HEXADECIMAL_PREFIX + hex : hex + return withHexPrefix ? HEX_PREFIX + hex : hex } export function convertBytesToHexString(bytes: number[], withHexPrefix = true): string { @@ -43,7 +43,7 @@ export function convertBytesToHexString(bytes: number[], withHexPrefix = true): } const hex = bytes.map((byte) => ('0' + (byte & 0xff).toString(16)).slice(-2)).join('') - return withHexPrefix ? HEXADECIMAL_PREFIX + hex : hex + return withHexPrefix ? HEX_PREFIX + hex : hex } /** @@ -205,7 +205,7 @@ export class Converter { } } } - return prefix ? HEXADECIMAL_PREFIX + hex : hex + return prefix ? HEX_PREFIX + hex : hex } /** @@ -215,7 +215,7 @@ export class Converter { * @returns The array. */ public static hexToBytes(hex: string, reverse?: boolean): Uint8Array { - if (hex.startsWith(HEXADECIMAL_PREFIX)) { + if (hex.startsWith(HEX_PREFIX)) { hex = hex.substring(2) } @@ -263,11 +263,11 @@ export class Converter { } public static decimalToHex(number: number, prefix = true): string { - return prefix ? HEXADECIMAL_PREFIX + number.toString(16) : number.toString(16) + return prefix ? HEX_PREFIX + number.toString(16) : number.toString(16) } public static bigIntToHex(bigInt: bigint, prefix = true): string { - return prefix ? HEXADECIMAL_PREFIX + bigInt.toString(16) : bigInt.toString(16) + return prefix ? HEX_PREFIX + bigInt.toString(16) : bigInt.toString(16) } /** diff --git a/packages/shared/src/lib/core/utils/crypto/utils/isValidHexAddress.ts b/packages/shared/src/lib/core/utils/crypto/utils/isValidHexAddress.ts index a938f42fe4..cba1081e88 100644 --- a/packages/shared/src/lib/core/utils/crypto/utils/isValidHexAddress.ts +++ b/packages/shared/src/lib/core/utils/crypto/utils/isValidHexAddress.ts @@ -1,6 +1,6 @@ -import { HEXADECIMAL_PREFIX } from '@core/utils/constants' +import { HEX_PREFIX } from '@core/utils/constants' export function isValidHexAddress(text: string): boolean { - const isHex = text.startsWith(HEXADECIMAL_PREFIX) + const isHex = text.startsWith(HEX_PREFIX) return isHex && /^(0x)?[0-9a-f]{64}/i.test(text) } diff --git a/packages/shared/src/lib/core/utils/crypto/utils/validateEthereumAddress.ts b/packages/shared/src/lib/core/utils/crypto/utils/validateEthereumAddress.ts index 6960c45ad5..c0ccaf9061 100644 --- a/packages/shared/src/lib/core/utils/crypto/utils/validateEthereumAddress.ts +++ b/packages/shared/src/lib/core/utils/crypto/utils/validateEthereumAddress.ts @@ -1,12 +1,12 @@ import { localize } from '@core/i18n' import { Keccak } from 'sha3' -import { HEXADECIMAL_PREFIX } from '../../constants' +import { HEX_PREFIX } from '../../constants' import { KECCAK_HASH_SIZE } from '../constants' export function validateEthereumAddress(address: string): void { // 1. Check prefix if (!/^(0x)*/i.test(address)) { - throw new Error(localize('error.send.wrongAddressPrefix', { prefix: HEXADECIMAL_PREFIX })) + throw new Error(localize('error.send.wrongAddressPrefix', { prefix: HEX_PREFIX })) // 2. Check hex format } else if (!/^(0x)?[0-9a-f]*/i.test(address)) { throw new Error(localize('error.send.wrongAddressFormat')) @@ -21,7 +21,7 @@ export function validateEthereumAddress(address: string): void { // Check if EIP-55 mixed-case checksum address encoding is followed (https://eips.ethereum.org/EIPS/eip-55) function validateEthereumAddressChecksum(address: string): void { - address = address.replace(HEXADECIMAL_PREFIX, '') + address = address.replace(HEX_PREFIX, '') const keccak256 = new Keccak(KECCAK_HASH_SIZE) const addressHash = keccak256.update(address.toLowerCase()).digest('hex') for (let i = 0; i < address.length; i++) { diff --git a/packages/shared/src/lib/core/utils/format.ts b/packages/shared/src/lib/core/utils/format.ts index 5aeffe3fa7..dee8f904f6 100644 --- a/packages/shared/src/lib/core/utils/format.ts +++ b/packages/shared/src/lib/core/utils/format.ts @@ -1,6 +1,6 @@ import { formatDate } from '@core/i18n' -import { HEXADECIMAL_PREFIX, HEXADECIMAL_REGEXP } from './constants' +import { HEX_PREFIX, HEXADECIMAL_REGEXP } from './constants' export function formatHexString( hex: string, @@ -11,11 +11,11 @@ export function formatHexString( return '00' } - hex = hex.replace(HEXADECIMAL_PREFIX, '') + hex = hex.replace(HEX_PREFIX, '') let result = '' if (shouldIncludePrefix) { - result += HEXADECIMAL_PREFIX + result += HEX_PREFIX } result += shouldBeUppercase ? hex.toUpperCase() : hex.toLowerCase()