SHA256
CORE/CONTENT test5593 и адаптация UI
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
import { verifyAns104DataItem } from './ans104-data-item.js';
|
||||
import { base64ToBytes, bytesToBase64Url } from './crypto-utils.js';
|
||||
import { readCoreBlock } from './core-content.js';
|
||||
import { readShineUserPda } from './shine-user-pda-service.js';
|
||||
|
||||
const HASH_RE = /^[0-9a-f]{64}$/iu;
|
||||
const DATA_ITEM_ID_RE = /^[A-Za-z0-9_-]{43}$/u;
|
||||
const MAX_SIGNED_BYTES = 8 * 1024 * 1024;
|
||||
|
||||
function hex(bytes) {
|
||||
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
function equalBytes(left, right) {
|
||||
return left.length === right.length && left.every((byte, index) => byte === right[index]);
|
||||
}
|
||||
@@ -28,16 +24,10 @@ export async function readSignedBlock({ authService, blockchainName, blockNumber
|
||||
if (!HASH_RE.test(String(body?.blockHash || '')) || String(body.blockHash).toLowerCase() !== String(blockHash).toLowerCase()) {
|
||||
throw new Error('Сервер вернул другой хеш блока');
|
||||
}
|
||||
const rawText = String(body?.blockBytesB64 || '');
|
||||
if (rawText.length > Math.ceil(MAX_SIGNED_BYTES * 4 / 3) + 8) throw new Error('Размер подписанного блока превышает лимит');
|
||||
const bytes = base64ToBytes(rawText);
|
||||
if (!bytes.length || bytes.length > MAX_SIGNED_BYTES) throw new Error('Некорректный размер блока');
|
||||
const proof = await verifyAns104DataItem(bytes);
|
||||
if (!proof.signatureValid) throw new Error('Недействительная подпись ANS-104');
|
||||
if (hex(proof.frameHashBytes) !== String(blockHash).toLowerCase()) throw new Error('Хеш содержимого блока не совпал');
|
||||
const actualId = bytesToBase64Url(proof.dataItemIdBytes);
|
||||
if (dataItemId && actualId !== dataItemId) throw new Error('Идентификатор Arweave отличается от ожидаемого');
|
||||
return { bytes, ...proof, actualId };
|
||||
const proof = await readCoreBlock(body, { requireContent: true });
|
||||
if (proof.core.blockNumber !== blockNumber || proof.coreHash !== String(blockHash).toLowerCase()) throw new Error('CORE reference mismatch');
|
||||
if (dataItemId && proof.actualId !== dataItemId) throw new Error('Arweave CORE ID mismatch');
|
||||
return proof;
|
||||
}
|
||||
|
||||
/** Вспомогательная независимая сверка: шлюз возвращает payload, а не ANS-104 оболочку. */
|
||||
|
||||
Reference in New Issue
Block a user