SHA256
HEADER v3, primary аккаунты и подтверждения
This commit is contained in:
@@ -1930,16 +1930,41 @@ var solanaWeb3=function(exports){"use strict";function getDefaultExportFromCjs(x
|
||||
};
|
||||
}
|
||||
|
||||
function parseHeaderBody(bodyBytes) {
|
||||
function parseHeaderBody(bodyBytes, version) {
|
||||
const reader = makeBigEndianReader(bodyBytes, 'HEADER');
|
||||
const tag = readUtf8(reader.readBytes(5));
|
||||
if (tag !== MAGIC) {
|
||||
throw new Error(`HEADER: неожиданный tag ${tag}`);
|
||||
}
|
||||
const login = reader.readUtf8U8();
|
||||
let accountType = null, previousAccounts = [], license = null;
|
||||
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 initialBlockchainKey = base64Url(reader.readBytes(32));
|
||||
reader.ensureDone();
|
||||
return { kind: 'header', login, tag, initialBlockchainKey };
|
||||
return { kind: 'header', login, tag, initialBlockchainKey, accountType, previousAccounts, license };
|
||||
}
|
||||
|
||||
function parseCreateChannelBody(bodyBytes, line) {
|
||||
@@ -2026,11 +2051,11 @@ var solanaWeb3=function(exports){"use strict";function getDefaultExportFromCjs(x
|
||||
}
|
||||
|
||||
function parseBlockchainBody(type, subType, version, bodyBytes, line) {
|
||||
if (version !== 1) {
|
||||
if (version !== 1 && !(type === BCH_TYPE_TECH && subType === BCH_SUBTYPE_HEADER && [2,3].includes(version))) {
|
||||
return { kind: 'unsupported', reason: `Неподдерживаемая версия body ${version}` };
|
||||
}
|
||||
if (type === BCH_TYPE_TECH && subType === BCH_SUBTYPE_HEADER) {
|
||||
return parseHeaderBody(bodyBytes);
|
||||
return parseHeaderBody(bodyBytes, version);
|
||||
}
|
||||
if (type === BCH_TYPE_TECH && subType === BCH_SUBTYPE_CREATE_CHANNEL) {
|
||||
return parseCreateChannelBody(bodyBytes, line);
|
||||
@@ -2069,7 +2094,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)!==(core.blockNumber===0)) throw new Error('Invalid CONTENT version/HEADER');
|
||||
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');
|
||||
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');
|
||||
|
||||
Reference in New Issue
Block a user