Унифицировать HEADER в формате 1.0

This commit is contained in:
AidarKC
2026-12-02 17:57:28 +03:00
parent 58e4bac3c8
commit c61cbf239c
24 changed files with 230 additions and 394 deletions
+10 -13
View File
@@ -544,11 +544,11 @@ function extractContactsFromDialogs(dialogs) {
return out;
}
export const HEADER_VERSION = 3;
export const HEADER_VERSION = 1;
// Временное значение до утверждения лицензии проекта.
export const HEADER_DEFAULT_LICENSE = '';
function makeHeaderBodyBytes({ login, initialBlockchainKey32, license = '', accountType = null, previousAccounts = [] }) {
function makeHeaderBodyBytes({ login, initialBlockchainKey32, license = '', accountType = 1, previousAccounts = [] }) {
const cleanLogin = String(login || '').trim();
const loginBytes = utf8Bytes(cleanLogin);
const licenseBytes = utf8Bytes(license);
@@ -560,18 +560,15 @@ function makeHeaderBodyBytes({ login, initialBlockchainKey32, license = '', acco
if (keyBytes.length !== 32 || keyBytes.every((value) => value === 0)) {
throw new Error('HEADER initialBlockchainKey32 must be a non-zero 32-byte key');
}
let identityBytes = new Uint8Array(0);
if (accountType !== null) {
if (accountType !== 0 && accountType !== 1) throw new Error('Invalid HEADER account type');
if (!Array.isArray(previousAccounts) || previousAccounts.length > 10 || (accountType === 0 && previousAccounts.length)) throw new Error('Invalid HEADER previous accounts');
const seen = new Set([cleanLogin.toLowerCase()]);
for (const previous of previousAccounts) {
if (typeof previous !== 'string' || !(/^[A-Za-z0-9_]{1,255}$/.test(previous) || (previous.length <= 30 && /^[A-Za-z0-9_]+@[a-z0-9_]+$/.test(previous))) || seen.has(previous.toLowerCase())) throw new Error('Invalid or duplicate previous account');
seen.add(previous.toLowerCase());
}
const csv = utf8Bytes(previousAccounts.join(','));
identityBytes = accountType === 1 ? concatBytes(int8Byte(1), Uint8Array.of(csv.length >> 8, csv.length & 255), csv) : int8Byte(0);
if (accountType !== 0 && accountType !== 1) throw new Error('Invalid HEADER account type');
if (!Array.isArray(previousAccounts) || previousAccounts.length > 10 || (accountType === 0 && previousAccounts.length)) throw new Error('Invalid HEADER previous accounts');
const seen = new Set([cleanLogin.toLowerCase()]);
for (const previous of previousAccounts) {
if (typeof previous !== 'string' || !(/^[A-Za-z0-9_]{1,255}$/.test(previous) || (previous.length <= 30 && /^[A-Za-z0-9_]+@[a-z0-9_]+$/.test(previous))) || seen.has(previous.toLowerCase())) throw new Error('Invalid or duplicate previous account');
seen.add(previous.toLowerCase());
}
const csv = utf8Bytes(previousAccounts.join(','));
const identityBytes = accountType === 1 ? concatBytes(int8Byte(1), Uint8Array.of(csv.length >> 8, csv.length & 255), csv) : int8Byte(0);
return concatBytes(
utf8Bytes('SHiNE'),
int8Byte(loginBytes.length),