Регистрация V2: не проверено end-to-end

This commit is contained in:
AidarKC
2026-10-23 19:21:52 +03:00
parent 6c8159c5f7
commit cab26bbf41
95 changed files with 4469 additions and 1088 deletions
@@ -0,0 +1,36 @@
#!/usr/bin/env node
import { readFileSync } from 'node:fs';
// Автономный декодер namespace 1.0 (без RPC и внешних пакетов).
export function decodeNamespace(data) {
const b=Buffer.from(data);
if(b.length<13) throw Error('namespace: payload слишком короткий');
if(b[0]!==1 || b[1]!==0) throw Error('namespace: неизвестная версия');
const type=b[2],minLocalLen=b[3],len=b[4];
if(type!==1 && type!==2)throw Error('namespace: неверный тип');
if(!len || !minLocalLen || len+1+minLocalLen>30) throw Error('namespace: некорректная длина');
let p=5;
if(p+len+8>b.length)throw Error('namespace: обрезанные поля');
const name=b.subarray(p,p+len).toString('utf8');p+=len;
if(!/^[a-z0-9_]+$/.test(name) || Buffer.byteLength(name)!==len) throw Error('namespace: некорректное название');
const fee=b.readBigUInt64LE(p).toString();p+=8;
let registrar=null,serverLogin=null;
if(type===2){
if(p+33>b.length)throw Error('namespace: отсутствуют ключ и логин сервера');
registrar=b.subarray(p,p+32).toString('hex');p+=32;
const serverLen=b[p++];
if(p+serverLen>b.length)throw Error('namespace: обрезан логин сервера');
serverLogin=b.subarray(p,p+serverLen).toString('utf8');p+=serverLen;
if(!/^[a-z0-9_]+@[a-z0-9_]+$/.test(serverLogin) || Buffer.byteLength(serverLogin)>30)throw Error('namespace: неверный логин сервера');
}
if(p!==b.length) throw Error('namespace: лишние байты запрещены');
return {major:1,minor:0,type,minLocalLen,name,registrationFeeLamports:fee,registrarPubkeyHex:registrar,serverLogin};
}
if(process.argv[1]?.endsWith('decode-namespace.mjs')){
const data=process.argv[2];
if(!data || !/^(?:[\da-fA-F]{2})+$/.test(data)){
console.error('Использование: node decode-namespace.mjs <hex-данные-аккаунта>');process.exit(2);
}
try{console.log(JSON.stringify(decodeNamespace(Buffer.from(data,'hex')),null,2));}
catch(e){console.error(e.message);process.exit(1);}
}