SHA256
CORE/CONTENT test5593 и адаптация UI
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { readCoreBlock } from './core-content.js';
|
||||
import { parseAns104DataItem } from './ans104-data-item.js';
|
||||
import { base64ToBytes, bytesToBase64Url, sha256Bytes } from './crypto-utils.js';
|
||||
|
||||
@@ -117,7 +118,7 @@ function parseChannelMetaText(rawText) {
|
||||
};
|
||||
}
|
||||
|
||||
function parseTechBody(subType, body, frame) {
|
||||
function parseTechBody(subType, body, frame, coreLine) {
|
||||
const reader = new Reader(body);
|
||||
if (subType === 0) {
|
||||
const magic = reader.text(5, 'HEADER magic');
|
||||
@@ -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 = coreLine === undefined ? parseLinePrefix(reader) : coreLine;
|
||||
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 = coreLine === undefined ? parseLinePrefix(reader) : coreLine;
|
||||
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, coreLine) {
|
||||
const reader = new Reader(body);
|
||||
if ([10, 90, 92, 100, 110, 120, 130].includes(subType)) {
|
||||
const line = parseLinePrefix(reader);
|
||||
const line = coreLine === undefined ? parseLinePrefix(reader) : coreLine;
|
||||
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 = coreLine === undefined ? parseLinePrefix(reader) : coreLine;
|
||||
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 = coreLine === undefined ? parseLinePrefix(reader) : coreLine;
|
||||
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, coreLine) {
|
||||
const reader = new Reader(body);
|
||||
const line = parseFixedLinePrefix(reader, 'Connection');
|
||||
const line = coreLine === undefined ? parseFixedLinePrefix(reader, 'Connection') : coreLine;
|
||||
const target = parseTarget(reader);
|
||||
return { kind: 'connection', subType, line, target };
|
||||
}
|
||||
|
||||
function parseProfileBody(subType, body) {
|
||||
function parseProfileBody(subType, body, coreLine) {
|
||||
if (subType !== 1) return { kind: 'unknown', rawBodyLength: body.length };
|
||||
const reader = new Reader(body);
|
||||
const line = parseFixedLinePrefix(reader, 'Profile');
|
||||
const line = coreLine === undefined ? parseFixedLinePrefix(reader, 'Profile') : coreLine;
|
||||
const key = reader.textU16('paramKey');
|
||||
const value = reader.textU16('paramValue');
|
||||
return { kind: 'profile', line, key, value };
|
||||
@@ -237,16 +238,16 @@ function parseStatusBody(subType, body) {
|
||||
return { kind: 'status', subType, target, rawText, text: message.text, attachmentsCount: message.attachmentsCount };
|
||||
}
|
||||
|
||||
function parseBody(type, subType, version, body, frame) {
|
||||
function parseBody(type, subType, version, body, frame, coreLine) {
|
||||
// Only TECH HEADER subtype 0 has a second version; all other records stay v1.
|
||||
if (version !== 1 && !(type === 0 && subType === 0 && version === 2)) {
|
||||
return { kind: 'unsupported_version', rawBodyLength: body.length };
|
||||
}
|
||||
if (type === 0) return parseTechBody(subType, body, frame);
|
||||
if (type === 1) return parseTextBody(subType, body);
|
||||
if (type === 0) return parseTechBody(subType, body, frame, coreLine);
|
||||
if (type === 1) return parseTextBody(subType, body, coreLine);
|
||||
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, coreLine);
|
||||
if (type === 4) return parseProfileBody(subType, body, coreLine);
|
||||
if (type === 5) return parseStatusBody(subType, body);
|
||||
return { kind: 'unknown', rawBodyLength: body.length };
|
||||
}
|
||||
@@ -291,3 +292,18 @@ export const blockchainInspectorInternals = Object.freeze({
|
||||
FIXED_LINE_PREFIX_SIZE,
|
||||
ZERO_HASH,
|
||||
});
|
||||
|
||||
/** View model for the existing inspector; never synthesizes or signs a Frame. */
|
||||
export async function inspectCoreBlock(row) {
|
||||
const proof = await readCoreBlock(row);
|
||||
const { core, content } = proof;
|
||||
const timestampMs = Number(core.timestamp * 1000n);
|
||||
if (!Number.isSafeInteger(timestampMs)) throw new Error('Invalid CORE timestamp');
|
||||
const line = core.line ? { lineCode: core.line.lineCode, prevLineNumber: core.line.prevLineBlockNumber,
|
||||
prevLineHash: bytesToHex(core.line.prevLineCoreHash32) } : null;
|
||||
const frame = { blockNumber: core.blockNumber, timestampMs, prevHash: bytesToHex(core.prevCoreHash32),
|
||||
type: content?.type, subType: content?.subType, version: content?.version };
|
||||
frame.body = content && row.contentStatus === 'VALID' ? parseBody(content.type, content.subType, content.version, content.body, frame, line) : { kind: 'unknown' };
|
||||
return { frame, dataItemId: proof.actualId, contentDataItemId: bytesToBase64Url(core.contentDataItemId32),
|
||||
arweaveUrl: `https://arweave.net/${proof.actualId}`, owner: bytesToBase64Url(proof.owner32), contentStatus: row.contentStatus };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user