Перевести вложения DM на R2 и обновить файловый API

This commit is contained in:
AidarKC
2026-11-15 14:33:52 +03:00
parent 3ecec25fce
commit 70540ff041
23 changed files with 770 additions and 202 deletions
@@ -0,0 +1,22 @@
import { base58ToBytes, bytesToBase58 } from './crypto-utils.js';
// Публичные вложения: PR — 32 байта корня BitTorrent v2 в каноническом Base58.
// Длина строки переменная (обычно 43–44 символа); DM v2 и Arweave TX ID не затрагиваются.
const PUBLIC_PR_BASE58 = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
export function encodePublicPiecesRoot(rootBytes) {
if (!(rootBytes instanceof Uint8Array) || rootBytes.byteLength !== 32) {
throw new Error('Некорректный 32-байтный Pieces Root');
}
return bytesToBase58(rootBytes);
}
export function validatePublicPiecesRoot(pr) {
if (typeof pr !== 'string' || !PUBLIC_PR_BASE58.test(pr)) return false;
try {
const bytes = base58ToBytes(pr);
return bytes.byteLength === 32 && bytesToBase58(bytes) === pr;
} catch {
return false;
}
}