Новый формат блоков CORE/CONTENT test5595

This commit is contained in:
AidarKC
2026-11-27 10:04:22 +03:00
parent d3a84dd451
commit f9e7c4ef94
180 changed files with 15365 additions and 1301 deletions
@@ -1,5 +1,6 @@
import { unpackCoreContent, verifyCoreContentPair } from './core-content.js';
import { parseAns104DataItem } from './ans104-data-item.js';
import { base64ToBytes, bytesToBase64Url, sha256Bytes } from './crypto-utils.js';
import { base64ToBytes, bytesToBase64Url } from './crypto-utils.js';
const FRAME_HEADER_SIZE = 88;
const LINE_PREFIX_SIZE = 44;
@@ -134,7 +135,7 @@ function parseTechBody(subType, body, frame) {
return { kind: 'header', magic, login, license, initialBlockchainKey };
}
if (subType === 1) {
const line = parseLinePrefix(reader);
const line = frame.signedLine ?? parseLinePrefix(reader);
const channelName = reader.textU8('channelName');
const channelDescription = reader.textU16('channelDescription');
const channelType = reader.u16('channelType');
@@ -146,7 +147,7 @@ function parseTechBody(subType, body, frame) {
};
}
if (subType === 2) {
const line = parseLinePrefix(reader);
const line = frame.signedLine ?? parseLinePrefix(reader);
const parentBlockchainKey = bytesToBase64Url(reader.raw(32, 'parentBlockchainKey'));
const forkPointBlockNumber = reader.i32('forkPointBlockNumber');
const forkPointBlockHash = reader.hash32('forkPointBlockHash');
@@ -166,10 +167,10 @@ function parseTechBody(subType, body, frame) {
return { kind: 'unknown', rawBodyLength: body.length };
}
function parseTextBody(subType, body) {
function parseTextBody(subType, body, frame) {
const reader = new Reader(body);
if ([10, 90, 92, 100, 110, 120, 130].includes(subType)) {
const line = parseLinePrefix(reader);
const line = frame.signedLine ?? parseLinePrefix(reader);
const rawText = parseTextTail(reader);
const message = splitMessageText(rawText);
return {
@@ -179,7 +180,7 @@ function parseTextBody(subType, body) {
};
}
if (subType === 11) {
const line = parseLinePrefix(reader);
const line = frame.signedLine ?? parseLinePrefix(reader);
const target = parseCompactTarget(reader);
const rawText = parseTextTail(reader);
const message = splitMessageText(rawText);
@@ -198,7 +199,7 @@ function parseTextBody(subType, body) {
return { kind: 'edit_reply', target, rawText, text: message.text, attachmentsCount: message.attachmentsCount };
}
if (subType === 50) {
const line = parseLinePrefix(reader);
const line = frame.signedLine ?? parseLinePrefix(reader);
const target = parseTarget(reader);
const rawText = parseTextTail(reader);
const message = splitMessageText(rawText);
@@ -213,17 +214,17 @@ function parseReactionBody(subType, body) {
return { kind: 'unknown', rawBodyLength: body.length };
}
function parseConnectionBody(subType, body) {
function parseConnectionBody(subType, body, frame) {
const reader = new Reader(body);
const line = parseFixedLinePrefix(reader, 'Connection');
const line = frame.signedLine ?? parseFixedLinePrefix(reader, 'Connection');
const target = parseTarget(reader);
return { kind: 'connection', subType, line, target };
}
function parseProfileBody(subType, body) {
function parseProfileBody(subType, body, frame) {
if (subType !== 1) return { kind: 'unknown', rawBodyLength: body.length };
const reader = new Reader(body);
const line = parseFixedLinePrefix(reader, 'Profile');
const line = frame.signedLine ?? parseFixedLinePrefix(reader, 'Profile');
const key = reader.textU16('paramKey');
const value = reader.textU16('paramValue');
return { kind: 'profile', line, key, value };
@@ -243,10 +244,10 @@ function parseBody(type, subType, version, body, frame) {
return { kind: 'unsupported_version', rawBodyLength: body.length };
}
if (type === 0) return parseTechBody(subType, body, frame);
if (type === 1) return parseTextBody(subType, body);
if (type === 1) return parseTextBody(subType, body, frame);
if (type === 2) return parseReactionBody(subType, body);
if (type === 3) return parseConnectionBody(subType, body);
if (type === 4) return parseProfileBody(subType, body);
if (type === 3) return parseConnectionBody(subType, body, frame);
if (type === 4) return parseProfileBody(subType, body, frame);
if (type === 5) return parseStatusBody(subType, body);
return { kind: 'unknown', rawBodyLength: body.length };
}
@@ -271,18 +272,21 @@ export function parseShineFrame(frameBytes) {
return { ...meta, body: parseBody(type, subType, version, bodyBytes, meta), bodyBytes };
}
export async function inspectBlockchainDataItem(blockBytesB64) {
export async function inspectBlockchainDataItem(blockBytesB64, thisLineNumber = null) {
const raw = base64ToBytes(String(blockBytesB64 || ''));
const dataItem = parseAns104DataItem(raw);
const frame = parseShineFrame(dataItem.data);
const dataItemId = bytesToBase64Url(await sha256Bytes(dataItem.signature));
return {
dataItemId,
arweaveUrl: `https://arweave.net/${dataItemId}`,
owner: bytesToBase64Url(dataItem.owner32),
signatureType: dataItem.sigType,
frame,
};
const { coreDataItem, contentDataItem } = unpackCoreContent(raw);
const dataItem = parseAns104DataItem(coreDataItem);
const { core, content, coreDataItemId32 } = await verifyCoreContentPair(coreDataItem, contentDataItem, dataItem.owner32);
const signedLine = core.line ? { lineCode: core.line.lineCode, prevLineNumber: core.line.prevLineBlockNumber,
prevLineHash: bytesToHex(core.line.prevLineCoreHash32), lineSequence: Number.isInteger(thisLineNumber) ? thisLineNumber : null } : null;
const { type, subType, version, body: bodyBytes } = content;
const meta = { frameCode: 1, prevHash: bytesToHex(core.prevCoreHash32), blockSize: raw.length,
blockNumber: core.blockNumber, timestampMs: Number(core.timestamp * 1000n), type, subType, version, signedLine };
const frame = { ...meta, body: parseBody(type, subType, version, bodyBytes, meta), bodyBytes };
const dataItemId = bytesToBase64Url(coreDataItemId32);
return { dataItemId, contentDataItemId: bytesToBase64Url(core.contentDataItemId32),
arweaveUrl: `https://arweave.net/${dataItemId}`, owner: bytesToBase64Url(dataItem.owner32),
signatureType: dataItem.sigType, frame };
}
export const blockchainInspectorInternals = Object.freeze({