Полностью поддерживает английский язык

This commit is contained in:
AidarKC
2026-11-10 14:02:34 +03:00
parent 405b9a91a7
commit 9c30b33b39
71 changed files with 2658 additions and 1445 deletions
+24 -22
View File
@@ -1,3 +1,5 @@
import { t } from '../i18n/index.js';
import { formatNumber } from '../i18n/format.js';
import { loadEncryptedUserSecrets, updateEncryptedUserSecrets } from './key-vault.js';
import { extractEd25519Seed32FromStoredValue } from './client-key-utils.js';
import { deriveArweaveWalletFromBlockchainKey32 } from './sawd-v1.js';
@@ -15,10 +17,10 @@ function normalizeGateway(rawGateway) {
try {
parsed = new URL(raw);
} catch {
throw new Error('Некорректный Arweave gateway URL');
throw new Error(t('remaining.arweave_wallet_errors.invalid_arweave_gateway_url'));
}
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
throw new Error('Arweave gateway должен использовать http или https');
throw new Error(t('remaining.arweave_wallet_errors.arweave_gateway_must_use_http_or_https'));
}
const normalized = `${parsed.protocol}//${parsed.host}${parsed.pathname}`.replace(/\/+$/g, '');
return normalized || DEFAULT_ARWEAVE_GATEWAY;
@@ -29,11 +31,11 @@ function parseGatewayForArweaveInit(gateway) {
try {
parsed = new URL(gateway);
} catch {
throw new Error('Некорректный Arweave gateway URL');
throw new Error(t('remaining.arweave_wallet_errors.invalid_arweave_gateway_url'));
}
const protocol = parsed.protocol.replace(':', '');
if (protocol !== 'http' && protocol !== 'https') {
throw new Error('Arweave gateway должен использовать http или https');
throw new Error(t('remaining.arweave_wallet_errors.arweave_gateway_must_use_http_or_https'));
}
const port = parsed.port
? Number(parsed.port)
@@ -49,18 +51,18 @@ function parseArToWinston(amountAr) {
const raw = String(amountAr ?? '').trim().replace(',', '.');
const match = raw.match(/^(\d+)(?:\.(\d+))?$/);
if (!match) {
throw new Error('Сумма перевода должна быть числом');
throw new Error(t('remaining.arweave_wallet.the_transfer_amount_must_be_a_number'));
}
const intPart = BigInt(match[1] || '0');
const frac = String(match[2] || '');
if (frac.length > 12) {
throw new Error('Слишком много знаков после запятой (максимум 12)');
throw new Error(t('remaining.arweave_wallet.too_many_decimal_places_maximum_12'));
}
const fracPadded = `${frac}${'0'.repeat(12 - frac.length)}`;
const winston = (intPart * WINSTON_PER_AR) + BigInt(fracPadded || '0');
if (winston <= 0n) {
throw new Error('Сумма перевода должна быть больше 0');
throw new Error(t('remaining.arweave_wallet.the_transfer_amount_must_be_greater_than_zero'));
}
return winston.toString();
}
@@ -112,12 +114,12 @@ function normalizeExtraWallets(secrets) {
function parseJwkSecretString(secret) {
const raw = String(secret || '').trim();
if (!raw) throw new Error('Введите секрет Arweave-кошелька.');
if (!raw) throw new Error(t('remaining.arweave_wallet.enter_your_arweave_wallet_secret'));
const tryParse = (value) => {
const parsed = JSON.parse(value);
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
throw new Error('Некорректный JWK Arweave.');
throw new Error(t('remaining.arweave_wallet.invalid_arweave_jwk'));
}
return parsed;
};
@@ -131,12 +133,12 @@ function parseJwkSecretString(secret) {
try {
return tryParse(atob(normalized));
} catch {
throw new Error('Секрет должен быть JSON JWK или base64url(JSON JWK).');
throw new Error(t('remaining.arweave_wallet.the_secret_must_be_json_jwk_or_base64url_json_jwk'));
}
}
function validateArweaveJwk(jwk) {
if (!jwk || typeof jwk !== 'object') throw new Error('Некорректный JWK Arweave.');
if (!jwk || typeof jwk !== 'object') throw new Error(t('remaining.arweave_wallet.invalid_arweave_jwk'));
['kty', 'e', 'n', 'd', 'p', 'q', 'dp', 'dq', 'qi'].forEach((key) => {
if (!String(jwk[key] || '').trim()) throw new Error(`В JWK Arweave нет поля ${key}.`);
});
@@ -158,7 +160,7 @@ export async function getArweaveWalletChoices({ login, storagePwd, onStatus } =
return [
{
id: 'derived-blockchain-key',
label: 'Стандартный из ключа блокчейна',
label: t('remaining.arweave_wallet.derived_from_blockchain_key'),
address: derived.address,
owner: derived.owner,
jwk: derived.jwk,
@@ -175,7 +177,7 @@ export async function getArweaveWalletChoices({ login, storagePwd, onStatus } =
export async function addArweaveWalletSecret({ login, storagePwd, secret, label = '' } = {}) {
const cleanLogin = String(login || '').trim();
const cleanPwd = String(storagePwd || '').trim();
if (!cleanLogin || !cleanPwd) throw new Error('Нет активной сессии.');
if (!cleanLogin || !cleanPwd) throw new Error(t('remaining.arweave_wallet.no_active_session'));
const jwk = parseJwkSecretString(secret);
validateArweaveJwk(jwk);
@@ -212,21 +214,21 @@ export async function getArweaveWalletFromStoredBlockchainKey({ login, storagePw
const cleanLogin = String(login || '').trim();
const cleanPwd = String(storagePwd || '').trim();
if (!cleanLogin || !cleanPwd) {
throw new Error('Нет активной сессии для доступа к blockchain key');
throw new Error(t('remaining.arweave_wallet_errors.no_active_session_to_access_blockchain_key'));
}
const secrets = await loadEncryptedUserSecrets(cleanLogin, cleanPwd);
const cached = pickCachedWallet(secrets);
if (cached) {
safeStatus(onStatus, 'Arweave-кошелёк загружен.');
safeStatus(onStatus, t('remaining.arweave_wallet.arweave_wallet_loaded'));
return cached;
}
safeStatus(onStatus, 'Сейчас мы впервые получаем Arweave-кошелёк из вашего ключа блокчейна. Это может занять немного времени.');
safeStatus(onStatus, t('remaining.arweave_wallet.your_arweave_wallet_is_being_derived_from_the_blockchain_k'));
const storedBlockchainKey = String(secrets?.blockchainKey || '').trim();
if (!storedBlockchainKey) {
throw new Error('На устройстве не найден blockchain key');
throw new Error(t('remaining.arweave_wallet_errors.blockchain_key_not_found_on_this_device'));
}
const blockchainKey32 = extractEd25519Seed32FromStoredValue(storedBlockchainKey);
@@ -263,7 +265,7 @@ export async function getArweaveBalance({ gateway, address }) {
const normalizedGateway = normalizeGateway(gateway);
const cleanAddress = String(address || '').trim();
if (!cleanAddress) {
throw new Error('Не указан адрес Arweave');
throw new Error(t('remaining.arweave_wallet.arweave_address_missing'));
}
const url = `${normalizedGateway}/wallet/${encodeURIComponent(cleanAddress)}/balance`;
@@ -274,7 +276,7 @@ export async function getArweaveBalance({ gateway, address }) {
throw new Error(`Не удалось получить баланс Arweave (${response.status} ${response.statusText})`);
}
if (!/^\d+$/.test(rawText)) {
throw new Error('Arweave gateway вернул некорректный баланс');
throw new Error(t('remaining.arweave_wallet.arweave_gateway_returned_an_invalid_balance'));
}
const winstonBig = BigInt(rawText);
@@ -289,7 +291,7 @@ export async function getArweaveBalance({ gateway, address }) {
export function formatAr(value, digits = 6) {
const n = Number(value);
if (!Number.isFinite(n)) return '0';
return n.toLocaleString('ru-RU', {
return formatNumber(n, {
minimumFractionDigits: 0,
maximumFractionDigits: digits,
});
@@ -301,8 +303,8 @@ export function getArweaveTopupSiteUrl() {
export async function transferAr({ gateway, jwk, toAddress, amountAr }) {
const cleanTo = String(toAddress || '').trim();
if (!cleanTo) throw new Error('Не указан адрес получателя Arweave');
if (!jwk || typeof jwk !== 'object') throw new Error('Кошелёк Arweave не инициализирован');
if (!cleanTo) throw new Error(t('remaining.arweave_wallet.arweave_recipient_address_missing'));
if (!jwk || typeof jwk !== 'object') throw new Error(t('remaining.arweave_wallet.arweave_wallet_is_not_initialized'));
const normalizedGateway = normalizeGateway(gateway);
const { host, port, protocol } = parseGatewayForArweaveInit(normalizedGateway);