SHA256
Полностью поддерживает английский язык
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { t } from '../i18n/index.js';
|
||||
import qrcode from '../vendor-qrcode-generator.js';
|
||||
|
||||
const TRANSFER_PREFIX = 'shine-key-transfer-v1:';
|
||||
@@ -22,15 +23,15 @@ function base64UrlToBytes(value) {
|
||||
}
|
||||
|
||||
export function keyLabel(id) {
|
||||
if (id === 'blockchain') return 'ключ блокчейна';
|
||||
if (id === 'device' || id === 'client') return 'ключ доступа';
|
||||
if (id === 'blockchain') return t('remaining.qr_keys.blockchain_key');
|
||||
if (id === 'device' || id === 'client') return t('remaining.qr_keys.access_key');
|
||||
return id;
|
||||
}
|
||||
|
||||
export function describeTransferKeys(keys = {}) {
|
||||
const out = [];
|
||||
if (keys.clientKey) out.push('ключ доступа');
|
||||
if (keys.blockchainKey) out.push('ключ блокчейна');
|
||||
if (keys.clientKey) out.push(t('remaining.qr_keys.access_key'));
|
||||
if (keys.blockchainKey) out.push(t('remaining.qr_keys.blockchain_key'));
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -38,7 +39,7 @@ export function makeKeyTransferText({ login, keys }) {
|
||||
const clientKey = String(keys?.clientKey || '').trim();
|
||||
const blockchainKey = String(keys?.blockchainKey || '').trim();
|
||||
if (!clientKey || !blockchainKey) {
|
||||
throw new Error('Для подключения нужны ключ доступа и ключ блокчейна');
|
||||
throw new Error(t('remaining.qr_keys.both_an_access_key_and_blockchain_key_are_required_to_conn'));
|
||||
}
|
||||
const payload = {
|
||||
v: 1,
|
||||
@@ -54,20 +55,20 @@ export function makeKeyTransferText({ login, keys }) {
|
||||
export function parseKeyTransferText(text) {
|
||||
const raw = String(text || '').trim();
|
||||
if (!raw.startsWith(TRANSFER_PREFIX)) {
|
||||
throw new Error('Это не QR-код переноса ключей Сияния');
|
||||
throw new Error(t('remaining.qr_keys.this_is_not_a_shine_key_transfer_qr_code'));
|
||||
}
|
||||
const json = decoder.decode(base64UrlToBytes(raw.slice(TRANSFER_PREFIX.length)));
|
||||
const payload = JSON.parse(json);
|
||||
if (payload?.v !== 1 || payload?.type !== 'shine-key-transfer') {
|
||||
throw new Error('Неподдерживаемый формат QR-кода');
|
||||
throw new Error(t('remaining.qr_keys.unsupported_qr_code_format'));
|
||||
}
|
||||
const login = String(payload.login || '').trim();
|
||||
if (!login) throw new Error('В QR-коде нет логина');
|
||||
if (!login) throw new Error(t('remaining.qr_keys.no_login_found_in_qr_code'));
|
||||
const keys = payload.keys && typeof payload.keys === 'object' ? payload.keys : {};
|
||||
const clientKey = String(keys.clientKey || '').trim();
|
||||
const blockchainKey = String(keys.blockchainKey || '').trim();
|
||||
if (!clientKey || !blockchainKey) {
|
||||
throw new Error('В QR-коде нет полного набора рабочих ключей');
|
||||
throw new Error(t('remaining.qr_keys.qr_code_does_not_contain_all_required_keys'));
|
||||
}
|
||||
return {
|
||||
login,
|
||||
|
||||
Reference in New Issue
Block a user