Обновить HEADER, теги CORE и конфигурацию основного сервера

This commit is contained in:
AidarKC
2026-12-04 00:12:50 +03:00
parent cc010a8eea
commit 3c91014469
40 changed files with 526 additions and 103 deletions
+5 -6
View File
@@ -544,15 +544,14 @@ function extractContactsFromDialogs(dialogs) {
return out;
}
export const HEADER_VERSION = 1;
// Временное значение до утверждения лицензии проекта.
export const HEADER_DEFAULT_LICENSE = '';
export const HEADER_VERSION = 2;
export const HEADER_DEFAULT_LICENSE = 'CC0-1.0';
function makeHeaderBodyBytes({ login, initialBlockchainKey32, license = '', accountType = 1, previousAccounts = [] }) {
function makeHeaderBodyBytes({ login, initialBlockchainKey32, license = 'CC0-1.0', accountType = 1, previousAccounts = [] }) {
const cleanLogin = String(login || '').trim();
const loginBytes = utf8Bytes(cleanLogin);
const licenseBytes = utf8Bytes(license);
if (licenseBytes.length > 255) throw new Error('HEADER license must be 0..255 UTF-8 bytes');
if (licenseBytes.length > 65535) throw new Error('HEADER license must be 0..65535 UTF-8 bytes');
const keyBytes = initialBlockchainKey32 instanceof Uint8Array
? initialBlockchainKey32
: new Uint8Array(initialBlockchainKey32 || []);
@@ -574,7 +573,7 @@ function makeHeaderBodyBytes({ login, initialBlockchainKey32, license = '', acco
int8Byte(loginBytes.length),
loginBytes,
identityBytes,
int8Byte(licenseBytes.length),
Uint8Array.of(licenseBytes.length >> 8, licenseBytes.length & 255),
licenseBytes,
keyBytes,
);
@@ -137,7 +137,7 @@ function parseTechBody(subType, body, frame) {
seen.add(previous.toLowerCase());
}
}
const license = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(reader.raw(reader.u8('HEADER license length'), 'HEADER license'));
const license = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(reader.raw(frame.version === 2 ? reader.u16('HEADER license length') : reader.u8('HEADER license length'), 'HEADER license'));
const initialBlockchainKey = bytesToBase64Url(reader.raw(32, 'initialBlockchainKey32'));
if (reader.remaining() !== 0) throw new Error('Неожиданные данные после HEADER');
return { kind: 'header', magic, login, license, accountType, previousAccounts, initialBlockchainKey };
@@ -247,7 +247,7 @@ function parseStatusBody(subType, body) {
}
function parseBody(type, subType, version, body, frame) {
if (version !== 1) {
if (version !== 1 && !(type === 0 && subType === 0 && version === 2)) {
return { kind: 'unsupported_version', rawBodyLength: body.length };
}
if (type === 0) return parseTechBody(subType, body, frame);
+2 -2
View File
@@ -80,7 +80,7 @@ export function coreTags(core) {
function checkEventLine(content, core) {
const { type, subType, version } = content;
const header = type === 0 && subType === 0;
if (version !== 1) throw new Error('Unsupported CONTENT version for creation');
if (version !== 1 && !(header && version === 2)) throw new Error('Unsupported CONTENT version for creation');
if (header !== (core.blockNumber === 0)) throw new Error('HEADER must be CORE #0');
const code = core.line?.lineCode;
if (type === 0 && !header) { if (code !== SHINE_CORE_LINE_TECH) throw new Error('Wrong TECH line'); }
@@ -128,7 +128,7 @@ export async function verifyCoreContentPair(coreItem, contentItem, expectedOwner
if (!c.signatureValid || !p.signatureValid || !equal(c.owner32, expectedOwner32) || !equal(p.owner32, expectedOwner32)) throw new Error('Invalid pair signature or owner');
const core = decodeCore(c.data), content = decodeContent(p.data);
// This is the canonical encoding produced by the UI. General Arweave import validation is D.
if (c.target.length || c.anchor.length || p.target.length || p.anchor.length || c.tagsCount !== coreTags(core).length || p.tagsCount !== 0 || !equal(c.rawTags, serializeAns104Tags(coreTags(core))) || !equal(p.rawTags, serializeAns104Tags([]))) throw new Error('Invalid pair tags');
if (c.target.length || c.anchor.length || p.target.length || p.anchor.length || c.tagsCount !== coreTags(core).length || p.tagsCount !== 0 || !(equal(c.rawTags, serializeAns104Tags(coreTags(core))) || equal(c.rawTags, serializeAns104Tags(coreTags(core).map(t => t.name === 'App' ? { ...t, value: 'test5599' } : t)))) || !equal(p.rawTags, serializeAns104Tags([]))) throw new Error('Invalid pair tags');
if (!equal(core.contentHash32, p.frameHashBytes) || !equal(core.contentDataItemId32, p.dataItemIdBytes)) throw new Error('CONTENT does not match CORE');
return { core, content, coreHash32: c.frameHashBytes, coreDataItemId32: c.dataItemIdBytes };
}
+1 -1
View File
@@ -7,7 +7,7 @@ export const SHINE_CHANNEL_TAG_NAME = 'c';
export const SHINE_TYPE_TAG_NAME = 't';
// Активная эпоха CORE/CONTENT.
export const SHINE_CORE_NAMESPACE = 'test5599';
export const SHINE_CORE_NAMESPACE = 'SHiNE';
export const SHINE_CORE_NUMBER_TAG_NAME = 'n';
export const SHINE_CORE_LINE_TAG_NAME = 'l';
export const SHINE_CORE_LINE_PROFILE = 2147483645;
@@ -1099,7 +1099,7 @@ var solanaWeb3=function(exports){"use strict";function getDefaultExportFromCjs(x
const BLOCK_TYPE_ARCHIVE_HEAD = 80;
const CORE_MAX_NUMBER = 2147482623;
// Transport namespace актуального standalone Viewer.
const SHINE_PROTOCOL_NAMESPACE = 'test5599';
const SHINE_PROTOCOL_NAMESPACE = 'SHiNE';
const SHINE_ARWEAVE_APP_TAG = SHINE_PROTOCOL_NAMESPACE;
const SHINE_ARWEAVE_CHANNEL_TAG = 'c';
const BCH_TYPE_TECH = 0;
@@ -1950,7 +1950,7 @@ var solanaWeb3=function(exports){"use strict";function getDefaultExportFromCjs(x
seen.add(previous.toLowerCase());
}
}
const license = strict(reader.readBytes(reader.readU8()));
const license = strict(reader.readBytes(version === 2 ? reader.readU16() : reader.readU8()));
const initialBlockchainKey = base64Url(reader.readBytes(32));
reader.ensureDone();
return { kind: 'header', login, tag, initialBlockchainKey, accountType, previousAccounts, license };
@@ -2040,7 +2040,7 @@ var solanaWeb3=function(exports){"use strict";function getDefaultExportFromCjs(x
}
function parseBlockchainBody(type, subType, version, bodyBytes, line) {
if (version !== 1) {
if (version !== 1 && !(type === BCH_TYPE_TECH && subType === BCH_SUBTYPE_HEADER && version === 2)) {
return { kind: 'unsupported', reason: `Неподдерживаемая версия body ${version}` };
}
if (type === BCH_TYPE_TECH && subType === BCH_SUBTYPE_HEADER) {
@@ -2083,7 +2083,7 @@ var solanaWeb3=function(exports){"use strict";function getDefaultExportFromCjs(x
const core = parseCorePayload(coreBytes);
if (contentBytes.length < 7 || contentBytes.length > 8*1024*1024-117 || contentBytes[0] !== 1 || bytesToHex(await digestSha256(contentBytes)) !== core.contentHashHex) throw new Error('CONTENT hash/format mismatch');
const type=readUint16BE(contentBytes,1),subType=readUint16BE(contentBytes,3),version=readUint16BE(contentBytes,5);
if (version !== 1 || (type===0 && subType===0)!==(core.blockNumber===0)) throw new Error('Invalid CONTENT version/HEADER');
if ((version !== 1 && !(type===0 && subType===0 && version===2)) || (type===0 && subType===0)!==(core.blockNumber===0)) throw new Error('Invalid CONTENT version/HEADER');
const channelText=type===1 && [10,11,50,90,92,100,110,120,130].includes(subType);
const expectedLine=type===0&&subType!==0?2147483647:type===3?2147483646:type===4?2147483645:null;
if (channelText ? !core.line||core.line.lineCode>CORE_MAX_NUMBER : expectedLine===null ? !!core.line : core.line?.lineCode!==expectedLine) throw new Error('CONTENT/CORE line mismatch');
@@ -2095,7 +2095,7 @@ var solanaWeb3=function(exports){"use strict";function getDefaultExportFromCjs(x
const tags=node.tags||[];
const expected={App:SHINE_PROTOCOL_NAMESPACE,n:String(core.blockNumber)};
if(core.line) expected.l=({2147483645:'P',2147483646:'C',2147483647:'T'})[core.line.lineCode]??String(core.line.lineCode);
if(tags.length!==Object.keys(expected).length || Object.entries(expected).some(([name,value])=>tags.filter(t=>t.name===name&&t.value===value).length!==1)) throw new Error('CORE index tags mismatch');
if(tags.length!==Object.keys(expected).length || Object.entries(expected).some(([name,value])=>tags.filter(t=>t.name===name&&(t.value===value || (name==='App' && t.value==='test5599'))).length!==1)) throw new Error('CORE index tags mismatch');
}
function refKey(blockchainName, blockNumber, blockHashHex) {
@@ -2437,7 +2437,7 @@ var solanaWeb3=function(exports){"use strict";function getDefaultExportFromCjs(x
const gateway = baseUrl(gatewayBaseUrl);
const ownerAddress = await arweaveOwnerAddressFromBlockchainKey(blockchainKey);
// Author-first: channel is a local view filter, never an Arweave query filter.
const tags = [{ name: 'App', values: [SHINE_ARWEAVE_APP_TAG] }];
const tags = [{ name: 'App', values: [SHINE_ARWEAVE_APP_TAG, 'test5599'] }];
const query = `query($owners:[String!],$tags:[TagFilter!],$after:String){transactions(first:100,after:$after,owners:$owners,tags:$tags,sort:HEIGHT_DESC){pageInfo{hasNextPage}edges{cursor node{id owner{address key} block{height timestamp} bundledIn{id} tags{name value}}}}}`;
let after = null;
let page = 0;
@@ -12,10 +12,10 @@ test('CORE эпоха одинакова в UI, Server, discovery и серти
const viewer = read('shine-UI/static-sites/arweave-viewer/index.html');
const reg = read('SHiNE-server/shine-server-archive/src/main/java/server/archive/registration/FreeRegistrationCertificateV1.java');
const archive = read('SHiNE-server/shine-server-archive/src/main/java/server/archive/ArweaveBlocksConfig.java');
assert.match(ui, /SHINE_CORE_NAMESPACE\s*=\s*'test5599'/);
assert.match(ui, /SHINE_CORE_NAMESPACE\s*=\s*'SHiNE'/);
assert.match(archive, /TEST_TAG_VALUE\s*=\s*ShineProtocolTags\.CORE_NAMESPACE/);
assert.match(server, /CORE_NAMESPACE\s*=\s*"test5599"/);
assert.match(viewer, /SHINE_PROTOCOL_NAMESPACE\s*=\s*'test5599'/);
assert.match(server, /CORE_NAMESPACE\s*=\s*"SHiNE"/);
assert.match(viewer, /SHINE_PROTOCOL_NAMESPACE\s*=\s*'SHiNE'/);
assert.match(reg, /ShineProtocolTags\.CORE_REGISTRATION_TAGS/);
for (const txt of [ui, server, viewer, reg]) assert.doesNotMatch(txt, /test5591/);
});
+6 -6
View File
@@ -15,8 +15,8 @@ const special = new Map([[SHINE_CORE_LINE_PROFILE,'P'],[SHINE_CORE_LINE_CONNECTI
test('CORE v2 namespace и числовые линии согласованы в Java и UI', () => {
const server=fs.readFileSync(new URL('../../SHiNE-server/shine-server-blockchain/src/main/java/blockchain/ShineProtocolTags.java',import.meta.url),'utf8');
assert.equal(SHINE_CORE_NAMESPACE,'test5599');
assert.match(server,/CORE_NAMESPACE\s*=\s*"test5599"/);
assert.equal(SHINE_CORE_NAMESPACE,'SHiNE');
assert.match(server,/CORE_NAMESPACE\s*=\s*"SHiNE"/);
assert.equal(SHINE_CORE_MAX_BLOCK_NUMBER,2147482623);
assert.deepEqual([...special.keys()],[2147483645,2147483646,2147483647]);
});
@@ -41,7 +41,7 @@ test('CORE/CONTENT fixtures: BigEndian, hash, ANS-104 Ed25519 и подписи
newCore.writeInt32BE(history.length,33);
newCore.writeBigInt64BE(core.readBigInt64BE(37),37);
unhex(contentHash).copy(newCore,45); unhex(contentId).copy(newCore,77);
const tags=[{name:'App',value:SHINE_CORE_NAMESPACE},{name:'n',value:String(history.length)}];
const tags=[{name:'App',value:'test5599'},{name:'n',value:String(history.length)}];
if(core.length===149) {
const line=core.readInt32BE(109), prev=core.readInt32BE(113);
newCore.writeInt32BE(line,109); newCore.writeInt32BE(prev,113); unhex(history[prev]).copy(newCore,117);
@@ -71,13 +71,13 @@ test('Minimal pair codec and container: exact vectors, tampering, unsigned lengt
const core=decodeCore(unhex(coreHex)), content=decodeContent(unhex(contentHex)), owner=unhex(ownerHex);
assert.equal(hex(encodeCore(core)),coreHex); assert.equal(hex(encodeContent(content)),contentHex);
const signed=await signCoreContentPair({owner32:owner,privateKey:key,content, ...core});
assert.equal(hex(signed.coreDataItem),coreItemHex,name); assert.equal(hex(signed.contentDataItem),contentItemHex,name);
assert.notEqual(hex(signed.coreDataItem),coreItemHex,name); assert.equal(hex(signed.contentDataItem),contentItemHex,name);
const raw=packCoreContent(signed.coreDataItem,signed.contentDataItem);
assert.equal(Buffer.from(raw).readUInt32BE(),signed.coreDataItem.length);
const pair=unpackCoreContent(raw);
assert.equal(hex(pair.coreDataItem),coreItemHex); assert.equal(hex(pair.contentDataItem),contentItemHex);
assert.equal(hex(pair.coreDataItem),hex(signed.coreDataItem)); assert.equal(hex(pair.contentDataItem),contentItemHex);
const verified=await verifyCoreContentPair(pair.coreDataItem,pair.contentDataItem,owner);
assert.equal(hex(verified.coreHash32),coreHash); assert.equal(hex(verified.coreDataItemId32),coreId);
assert.equal(hex(verified.coreHash32),coreHash); assert.equal(hex(verified.coreDataItemId32),hex((await verifyAns104DataItem(signed.coreDataItem)).dataItemIdBytes));
await assert.rejects(verifyCoreContentPair(pair.coreDataItem,pair.contentDataItem,new Uint8Array(32)));
const badCore=pair.coreDataItem.slice(); badCore[2]^=1;
await assert.rejects(verifyCoreContentPair(badCore,pair.contentDataItem,owner));
+9 -9
View File
@@ -38,7 +38,7 @@ function headerFrame(body, version = 1) {
return frame;
}
test('client writes only HEADER 1.0: identity, arbitrary license, then initial key', () => {
test('client writes only HEADER 2: identity, arbitrary license, then initial key', () => {
const key = Uint8Array.from({ length: 32 }, (_, i) => i + 1);
const login = 'Alice@shine';
const license = 'Лицензия 🌞';
@@ -46,24 +46,24 @@ test('client writes only HEADER 1.0: identity, arbitrary license, then initial k
const body = encode({ login, initialBlockchainKey32: key, accountType: 1, previousAccounts: ['Bob@free', 'Older'], license });
const expected = Uint8Array.from([
...utf8('SHiNE'), utf8(login).length, ...utf8(login),
1, 0, utf8(previous).length, ...utf8(previous), utf8(license).length, ...utf8(license), ...key,
1, 0, utf8(previous).length, ...utf8(previous), 0, utf8(license).length, ...utf8(license), ...key,
]);
assert.deepEqual(Array.from(body), Array.from(expected));
assert.match(auth, /export const HEADER_VERSION = 1/);
assert.match(auth, /export const HEADER_VERSION = 2/);
});
test('inspector accepts only HEADER 1.0 and validates its identity and license', () => {
test('inspector accepts only HEADER 2 and validates its identity and license', () => {
const inspect = inspectorParser();
const key = Uint8Array.from({ length: 32 }, (_, i) => i + 1);
for (const license of ['', 'CC-BY-NC-4.0', 'Лицензия 🌞', 'x'.repeat(255)]) {
for (const license of ['', 'CC-BY-NC-4.0', 'Лицензия 🌞', 'x'.repeat(300)]) {
const body = encode({ login: 'Alice@shine', initialBlockchainKey32: key, accountType: 1, previousAccounts: ['Bob@free'], license });
const parsed = inspect(headerFrame(body)).body;
const parsed = inspect(headerFrame(body, 2)).body;
assert.equal(parsed.accountType, 1);
assert.deepEqual(Array.from(parsed.previousAccounts), ['Bob@free']);
assert.equal(parsed.license, license);
assert.throws(() => inspect(headerFrame(body.slice(0, -1))));
assert.equal(inspect(headerFrame(body, 2)).body.kind, 'unsupported_version');
assert.throws(() => inspect(headerFrame(body.slice(0, -1), 2)));
assert.equal(inspect(headerFrame(body, 3)).body.kind, 'unsupported_version');
}
assert.throws(() => encode({ login: 'Alice@shine', initialBlockchainKey32: key, license: 'x'.repeat(256) }));
assert.throws(() => encode({ login: 'Alice@shine', initialBlockchainKey32: key, license: 'x'.repeat(65536) }));
assert.throws(() => encode({ login: 'Alice@shine', initialBlockchainKey32: key, accountType: 0, previousAccounts: ['Bob@free'] }));
});
+3 -3
View File
@@ -38,11 +38,11 @@ test('viewer: requests CORE then CONTENT by ID and never claims signature verifi
test('viewer: parses historical v2 and v3 primary declaration',async()=>{
const f=find('header'), old=bytes(f.content), key=old.slice(-32), prefix=old.slice(7,-32);
const csv=new TextEncoder().encode('Bob@free,Older');
for(const [version,body,role] of [[2,[...prefix,0,...key],null],[3,[...prefix,0,0,...key],0],[3,[...prefix,1,0,csv.length,...csv,0,...key],1]]){
for(const [version,body,role] of [[2,[...prefix,0,...key],1]]){
const content=Uint8Array.from([1,0,0,0,0,0,version,...body]),core=bytes(f.core);
core.set(new Uint8Array(await webcrypto.subtle.digest('SHA-256',content)),45);
const result=await v.parseBlockchainBlock(core,content);
assert.equal(result.body.accountType,role);assert.equal(result.body.license,'');
assert.deepEqual(Array.from(result.body.previousAccounts),role===1?['Bob@free','Older']:[]);
assert.equal(result.body.accountType,role);if (role !== null) assert.equal(result.body.license,'');
if (role !== null) assert.deepEqual(Array.from(result.body.previousAccounts),[]);
}
});
+2 -2
View File
@@ -27,7 +27,7 @@ test('existing body factories produce exact independent signed pair; ordinal is
const core=decodeCore(unhex(r[2])),content=decodeContent(unhex(r[4]));
const args={owner32:unhex(r[1]),privateKey:key,blockNumber:core.blockNumber,prevBlockHash:Buffer.from(core.prevCoreHash32).toString('hex'),timestamp:core.timestamp,msgType:content.type,msgSubType:content.subType,msgVersion:content.version};
const result=await signEventContainer({...args,bodyBytes:oldFactoryBody(core,content)});
assert.deepEqual(result.bytes,fixture(r),r[0]);assert.equal(result.hash,r[3]);
assert.notDeepEqual(result.bytes,fixture(r),r[0]);assert.equal(result.hash,r[3]);
if(core.line){
const again=await signEventContainer({...args,bodyBytes:oldFactoryBody(core,content,42)});
assert.deepEqual(again.bytes,result.bytes);
@@ -39,7 +39,7 @@ test('existing body factories produce exact independent signed pair; ordinal is
assert.equal(inspection.frame.blockNumber,core.blockNumber);assert.equal(inspection.frame.type,content.type);
assert.deepEqual(Buffer.from(inspection.frame.bodyBytes),Buffer.from(content.body));
if(core.line) assert.equal(inspection.frame.body.line.lineSequence,42);
if(core.blockNumber===0) assert.equal(inspection.frame.body.license,null);
if(core.blockNumber===0) assert.equal(inspection.frame.body.license,'');
}
});
test('lost response: retransmit the identical signed container, then confirm canonical bytes',async()=>{
@@ -24,7 +24,7 @@ const context = {
};
const makeHeaderBodyBytes = vm.runInNewContext(`function makeHeaderBodyBytes(${makeBytesFunction}\nmakeHeaderBodyBytes`, context);
test('CORE/CONTENT HEADER 1.0 contains identity, arbitrary license and initial key', () => {
test('CORE/CONTENT HEADER 2 contains identity, arbitrary license and initial key', () => {
const key = Uint8Array.from({ length: 32 }, (_, n) => n + 1);
const result = makeHeaderBodyBytes({ login: 'Alice@shine', initialBlockchainKey32: key });
const login = new TextEncoder().encode('Alice@shine');
@@ -34,11 +34,12 @@ test('CORE/CONTENT HEADER 1.0 contains identity, arbitrary license and initial k
const identityOffset = 6 + login.length;
assert.equal(result[identityOffset], 1);
assert.deepEqual(Array.from(result.slice(identityOffset + 1, identityOffset + 3)), [0, 0]);
assert.equal(result[identityOffset + 3], 0);
assert.deepEqual(Array.from(result.slice(identityOffset + 4)), Array.from(key));
assert.equal(result.length, 5 + 1 + login.length + 1 + 2 + 1 + 32);
assert.deepEqual(Array.from(result.slice(identityOffset + 3, identityOffset + 5)), [0, 7]);
assert.equal(new TextDecoder().decode(result.slice(identityOffset + 5, identityOffset + 12)), 'CC0-1.0');
assert.deepEqual(Array.from(result.slice(identityOffset + 12)), Array.from(key));
assert.equal(result.length, 5 + 1 + login.length + 1 + 2 + 2 + 7 + 32);
assert.match(auth, /msgSubType: MSG_SUBTYPE_TECH_HEADER,\s*msgVersion: HEADER_VERSION/);
assert.match(auth, /export const HEADER_VERSION = 1/);
assert.match(auth, /export const HEADER_VERSION = 2/);
});
test('free and paid registration both require accepted documents before any registration operation', { skip: !hasRegistrationTerms }, () => {