SHA256
HEADER v3, primary аккаунты и подтверждения
This commit is contained in:
@@ -125,14 +125,35 @@ function parseTechBody(subType, body, frame) {
|
||||
if (magic !== 'SHiNE') throw new Error('Неправильная сигнатура HEADER');
|
||||
const login = reader.textU8('HEADER login');
|
||||
let license = null;
|
||||
if (frame.version === 2) {
|
||||
const marker = reader.text(15, 'HEADER license');
|
||||
if (marker !== 'license:CC0-1.0') throw new Error('Неподдерживаемая лицензия HEADER');
|
||||
license = 'CC0-1.0';
|
||||
let accountType = null;
|
||||
let previousAccounts = [];
|
||||
if (frame.version === 3) {
|
||||
accountType = reader.u8('HEADER account type');
|
||||
if (accountType !== 0 && accountType !== 1) throw new Error('Invalid HEADER account type');
|
||||
if (accountType === 1) {
|
||||
const csv = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(reader.raw(reader.u16('HEADER previous accounts length'), 'HEADER previous accounts'));
|
||||
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 = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(reader.raw(reader.u8('HEADER license length'), 'HEADER license'));
|
||||
} else if (frame.version === 2) {
|
||||
const field = reader.raw(reader.remaining() - 32, 'HEADER license');
|
||||
const marker = 'license:CC0-1.0';
|
||||
if (field.length === marker.length && field.every((b, i) => b === marker.charCodeAt(i))) {
|
||||
license = 'CC0-1.0'; // исторический HEADER v2
|
||||
} else {
|
||||
if (!field.length || field[0] !== field.length - 1) throw new Error('Некорректная длина лицензии HEADER');
|
||||
license = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(field.slice(1));
|
||||
}
|
||||
}
|
||||
const initialBlockchainKey = bytesToBase64Url(reader.raw(32, 'initialBlockchainKey32'));
|
||||
if (reader.remaining() !== 0) throw new Error('Неожиданные данные после HEADER');
|
||||
return { kind: 'header', magic, login, license, initialBlockchainKey };
|
||||
return { kind: 'header', magic, login, license, accountType, previousAccounts, initialBlockchainKey };
|
||||
}
|
||||
if (subType === 1) {
|
||||
const line = frame.signedLine ?? parseLinePrefix(reader);
|
||||
@@ -240,7 +261,7 @@ function parseStatusBody(subType, body) {
|
||||
|
||||
function parseBody(type, subType, version, body, frame) {
|
||||
// Only TECH HEADER subtype 0 has a second version; all other records stay v1.
|
||||
if (version !== 1 && !(type === 0 && subType === 0 && version === 2)) {
|
||||
if (version !== 1 && !(type === 0 && subType === 0 && (version === 2 || version === 3))) {
|
||||
return { kind: 'unsupported_version', rawBodyLength: body.length };
|
||||
}
|
||||
if (type === 0) return parseTechBody(subType, body, frame);
|
||||
|
||||
Reference in New Issue
Block a user