Унифицировать 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
+14 -24
View File
@@ -1936,31 +1936,21 @@ var solanaWeb3=function(exports){"use strict";function getDefaultExportFromCjs(x
throw new Error(`HEADER: неожиданный tag ${tag}`);
}
const login = reader.readUtf8U8();
let accountType = null, previousAccounts = [], license = null;
let previousAccounts = [];
const strict = bytes => new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes);
if (version === 3) {
accountType = reader.readU8();
if (![0,1].includes(accountType)) throw new Error('Invalid HEADER account type');
if (accountType === 1) {
const csv = strict(reader.readBytes(reader.readU16()));
previousAccounts = csv ? csv.split(',') : [];
const seen = new Set([login.toLowerCase()]);
if (previousAccounts.length > 10) throw new Error('Too many previous accounts');
for (const previous of previousAccounts) {
if (!(/^[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 previous account');
seen.add(previous.toLowerCase());
}
}
license = strict(reader.readBytes(reader.readU8()));
} else if (version === 2) {
const field = bodyBytes.slice(6 + bodyBytes[5], -32);
if (field.length === 15 && field.every((b,i) => b === 'license:CC0-1.0'.charCodeAt(i))) {
reader.readBytes(15); license = 'CC0-1.0';
} else {
if (!field.length || field[0] !== field.length - 1) throw new Error('Invalid HEADER license length');
license = strict(reader.readBytes(reader.readU8()));
const accountType = reader.readU8();
if (![0,1].includes(accountType)) throw new Error('Invalid HEADER account type');
if (accountType === 1) {
const csv = strict(reader.readBytes(reader.readU16()));
previousAccounts = csv ? csv.split(',') : [];
const seen = new Set([login.toLowerCase()]);
if (previousAccounts.length > 10) throw new Error('Too many previous accounts');
for (const previous of previousAccounts) {
if (!(/^[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 previous account');
seen.add(previous.toLowerCase());
}
}
const license = strict(reader.readBytes(reader.readU8()));
const initialBlockchainKey = base64Url(reader.readBytes(32));
reader.ensureDone();
return { kind: 'header', login, tag, initialBlockchainKey, accountType, previousAccounts, license };
@@ -2050,7 +2040,7 @@ var solanaWeb3=function(exports){"use strict";function getDefaultExportFromCjs(x
}
function parseBlockchainBody(type, subType, version, bodyBytes, line) {
if (version !== 1 && !(type === BCH_TYPE_TECH && subType === BCH_SUBTYPE_HEADER && [2,3].includes(version))) {
if (version !== 1) {
return { kind: 'unsupported', reason: `Неподдерживаемая версия body ${version}` };
}
if (type === BCH_TYPE_TECH && subType === BCH_SUBTYPE_HEADER) {
@@ -2093,7 +2083,7 @@ var solanaWeb3=function(exports){"use strict";function getDefaultExportFromCjs(x
const core = parseCorePayload(coreBytes);
if (contentBytes.length < 7 || contentBytes.length > 8*1024*1024-117 || contentBytes[0] !== 1 || bytesToHex(await digestSha256(contentBytes)) !== core.contentHashHex) throw new Error('CONTENT hash/format mismatch');
const type=readUint16BE(contentBytes,1),subType=readUint16BE(contentBytes,3),version=readUint16BE(contentBytes,5);
if ((version !== 1 && !(type===0 && subType===0 && [2,3].includes(version))) || (type===0 && subType===0)!==(core.blockNumber===0)) throw new Error('Invalid CONTENT version/HEADER');
if (version !== 1 || (type===0 && subType===0)!==(core.blockNumber===0)) throw new Error('Invalid CONTENT version/HEADER');
const channelText=type===1 && [10,11,50,90,92,100,110,120,130].includes(subType);
const expectedLine=type===0&&subType!==0?2147483647:type===3?2147483646:type===4?2147483645:null;
if (channelText ? !core.line||core.line.lineCode>CORE_MAX_NUMBER : expectedLine===null ? !!core.line : core.line?.lineCode!==expectedLine) throw new Error('CONTENT/CORE line mismatch');