From 6f6641799196bf083b957c6d062092131883eb1d Mon Sep 17 00:00:00 2001 From: Artem Chystiakov Date: Thu, 21 Mar 2024 13:29:44 +0200 Subject: [PATCH 1/3] fixed zero padding --- composables/use-notifications.ts | 2 +- forms/HashFunctionForm.vue | 4 ++-- helpers/hash-functions.helpers.ts | 25 +++++++++++++++---------- helpers/validators.helpers.ts | 5 +++++ package.json | 8 ++++---- plugins/localization/resources/en.json | 1 + 6 files changed, 28 insertions(+), 17 deletions(-) diff --git a/composables/use-notifications.ts b/composables/use-notifications.ts index f6a0f5d..67bfd4c 100644 --- a/composables/use-notifications.ts +++ b/composables/use-notifications.ts @@ -77,7 +77,7 @@ export const useNotifications = () => { error: TYPE.ERROR, warning: TYPE.WARNING, }[messageType], - timeout: 30000, + timeout: 10000, closeOnClick: false, closeButton: false, }, diff --git a/forms/HashFunctionForm.vue b/forms/HashFunctionForm.vue index 33ee75c..0258348 100644 --- a/forms/HashFunctionForm.vue +++ b/forms/HashFunctionForm.vue @@ -60,7 +60,7 @@ import { RadioButtonField, TextareaField } from '@/fields' import { copyToClipboard, ErrorHandler, - hexadecimal, + hexadecimalOrEmpty, required, sleep, } from '@/helpers' @@ -88,7 +88,7 @@ const form = reactive({ const rules = computed(() => ({ type: { required }, text: { - ...(form.type === 'hex' && { required, hexadecimal }), + ...(form.type === 'hex' && { required, hexadecimalOrEmpty }), }, })) diff --git a/helpers/hash-functions.helpers.ts b/helpers/hash-functions.helpers.ts index d0a4939..b736aca 100644 --- a/helpers/hash-functions.helpers.ts +++ b/helpers/hash-functions.helpers.ts @@ -3,31 +3,36 @@ import { keccak256 as _keccak256, sha256 as _sha256, ripemd160 as _ripemd160, - toBeHex, toUtf8Bytes, } from 'ethers' import { type HashFunction } from '@/types' export const keccak256: HashFunction = (str, type) => { - const dataHexString = _keccak256( - type === 'text' ? toUtf8Bytes(str) : toBeHex(str), - ) + const dataHexString = _keccak256(getHashArg(str, type)); return hexlify(dataHexString) } export const sha256: HashFunction = (str, type) => { - const dataHexString = _sha256( - type === 'text' ? toUtf8Bytes(str) : toBeHex(str), - ) + const dataHexString = _sha256(getHashArg(str, type)); return hexlify(dataHexString) } export const ripemd160: HashFunction = (str, type) => { - const dataHexString = _ripemd160( - type === 'text' ? toUtf8Bytes(str) : toBeHex(str), - ) + const dataHexString = _ripemd160(getHashArg(str, type)); return hexlify(dataHexString) } + +const getHashArg = (str: string, type: "text" | "hex" ) => { + if (type === "text") { + return toUtf8Bytes(str); + } + + if (str.length % 2 == 1) { + str = "0x0" + str.slice(2); + } + + return hexlify(str); +} diff --git a/helpers/validators.helpers.ts b/helpers/validators.helpers.ts index 9561050..e9bcd6f 100644 --- a/helpers/validators.helpers.ts +++ b/helpers/validators.helpers.ts @@ -22,6 +22,7 @@ import { isAddress, isBytesLike } from 'ethers' const HASH_REGEX = /^0x[a-fA-F0-9]{64}$/ const HEX_REGEX = /^0x[a-fA-F0-9]*$/ const HEXADECIMAL_REGEX = /^0x[a-fA-F0-9]+$/ +const HEXADECIMAL_OR_EMPTY_REGEX = /^0x[a-fA-F0-9]*$/ const BINARY_REGEX = /^0b[01]+$/ const OCTAL_REGEX = /^0o?[0-7]+$/ const CONTRACT_FUNC_NAME_REGEXP = /^[a-zA-Z_][a-zA-Z0-9_]*$/ @@ -50,6 +51,10 @@ export const hexadecimal = ( withI18nMessage(helpers.regex(HEXADECIMAL_REGEX)) ) +export const hexadecimalOrEmpty = ( + withI18nMessage(helpers.regex(HEXADECIMAL_OR_EMPTY_REGEX)) +); + export const binary = ( withI18nMessage(helpers.regex(BINARY_REGEX)) ) diff --git a/package.json b/package.json index 20260bd..bf31f08 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,14 @@ { - "name": "solidity-landing", - "version": "1.0.0-rc.0", - "private": true, + "name": "@solarity/frontend", + "version": "1.0.0", + "private": false, "gitHooks": { "pre-commit": "yarn lint" }, "scripts": { "dev": "nuxt dev -o", "nuxt-build": "nuxt build", - "start": "cross-env VITE_APP_ENVIRONMENT=development yarn nuxt-dev-server", + "start": "cross-env VITE_APP_ENVIRONMENT=development yarn dev", "build": "cross-env VITE_APP_ENVIRONMENT=production yarn nuxt-build", "analyze": "cross-env VITE_APP_ENVIRONMENT=analyze yarn nuxt-build", "test": "", diff --git a/plugins/localization/resources/en.json b/plugins/localization/resources/en.json index e1d8b0c..4383b56 100644 --- a/plugins/localization/resources/en.json +++ b/plugins/localization/resources/en.json @@ -14,6 +14,7 @@ "field-error_maxLength": "Field must be less than {max} symbols", "field-error_binary": "Field must be a binary number with prefix \"0b\"", "field-error_hexadecimal": "Field must be a hexadecimal with prefix \"0x\"", + "field-error_hexadecimalOrEmpty": "Field must be a hexadecimal with prefix \"0x\"", "field-error_octal": "Field must be a octal number with prefix \"0o\"", "field-error_contractFuncName": "Field must be a valid function name", "field-error_functionSignature": "Field must be a valid function signature", From 8989ad1bb1077268ddc52688f8dc8f1d529294f5 Mon Sep 17 00:00:00 2001 From: Artem Chystiakov Date: Thu, 21 Mar 2024 13:32:35 +0200 Subject: [PATCH 2/3] readme --- README.md | 10 ++++------ helpers/hash-functions.helpers.ts | 16 ++++++++-------- helpers/validators.helpers.ts | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 73071ac..b289206 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) + # Solarity Front End +**Everything about Solarity ecosystem.** + ## Setup Make sure to install the dependencies: @@ -7,12 +11,6 @@ Make sure to install the dependencies: ```bash # yarn yarn install - -# npm -npm install - -# pnpm -pnpm install --shamefully-hoist ``` ## Development Server diff --git a/helpers/hash-functions.helpers.ts b/helpers/hash-functions.helpers.ts index b736aca..71192d5 100644 --- a/helpers/hash-functions.helpers.ts +++ b/helpers/hash-functions.helpers.ts @@ -8,31 +8,31 @@ import { import { type HashFunction } from '@/types' export const keccak256: HashFunction = (str, type) => { - const dataHexString = _keccak256(getHashArg(str, type)); + const dataHexString = _keccak256(getHashArg(str, type)) return hexlify(dataHexString) } export const sha256: HashFunction = (str, type) => { - const dataHexString = _sha256(getHashArg(str, type)); + const dataHexString = _sha256(getHashArg(str, type)) return hexlify(dataHexString) } export const ripemd160: HashFunction = (str, type) => { - const dataHexString = _ripemd160(getHashArg(str, type)); + const dataHexString = _ripemd160(getHashArg(str, type)) return hexlify(dataHexString) } -const getHashArg = (str: string, type: "text" | "hex" ) => { - if (type === "text") { - return toUtf8Bytes(str); +const getHashArg = (str: string, type: 'text' | 'hex') => { + if (type === 'text') { + return toUtf8Bytes(str) } if (str.length % 2 == 1) { - str = "0x0" + str.slice(2); + str = '0x0' + str.slice(2) } - return hexlify(str); + return hexlify(str) } diff --git a/helpers/validators.helpers.ts b/helpers/validators.helpers.ts index e9bcd6f..afb827c 100644 --- a/helpers/validators.helpers.ts +++ b/helpers/validators.helpers.ts @@ -53,7 +53,7 @@ export const hexadecimal = ( export const hexadecimalOrEmpty = ( withI18nMessage(helpers.regex(HEXADECIMAL_OR_EMPTY_REGEX)) -); +) export const binary = ( withI18nMessage(helpers.regex(BINARY_REGEX)) From 407f2fe680a62110fef98a86ed9759a9aaebc047 Mon Sep 17 00:00:00 2001 From: Artem Chystiakov <47551140+Arvolear@users.noreply.github.com> Date: Thu, 21 Mar 2024 14:00:46 +0200 Subject: [PATCH 3/3] Update helpers/hash-functions.helpers.ts Co-authored-by: Arthur Suslov <49021956+ArtSuslov@users.noreply.github.com> --- helpers/hash-functions.helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpers/hash-functions.helpers.ts b/helpers/hash-functions.helpers.ts index 71192d5..6d23df6 100644 --- a/helpers/hash-functions.helpers.ts +++ b/helpers/hash-functions.helpers.ts @@ -30,7 +30,7 @@ const getHashArg = (str: string, type: 'text' | 'hex') => { return toUtf8Bytes(str) } - if (str.length % 2 == 1) { + if (str.length % 2) { str = '0x0' + str.slice(2) }